agent-diary 4.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. agent_diary-4.3.0.dist-info/METADATA +599 -0
  2. agent_diary-4.3.0.dist-info/RECORD +59 -0
  3. agent_diary-4.3.0.dist-info/WHEEL +5 -0
  4. agent_diary-4.3.0.dist-info/entry_points.txt +4 -0
  5. agent_diary-4.3.0.dist-info/licenses/LICENSE +21 -0
  6. agent_diary-4.3.0.dist-info/top_level.txt +1 -0
  7. claude_diary/__init__.py +3 -0
  8. claude_diary/__main__.py +5 -0
  9. claude_diary/cli/__init__.py +213 -0
  10. claude_diary/cli/config.py +190 -0
  11. claude_diary/cli/maintenance.py +146 -0
  12. claude_diary/cli/notion_common.py +30 -0
  13. claude_diary/cli/notion_ensure.py +190 -0
  14. claude_diary/cli/notion_init.py +148 -0
  15. claude_diary/cli/notion_ops.py +553 -0
  16. claude_diary/cli/notion_push/__init__.py +397 -0
  17. claude_diary/cli/notion_push/artifacts.py +146 -0
  18. claude_diary/cli/notion_push/ordinals.py +70 -0
  19. claude_diary/cli/notion_push/preview.py +59 -0
  20. claude_diary/cli/notion_push/properties.py +234 -0
  21. claude_diary/cli/notion_push/relations.py +119 -0
  22. claude_diary/cli/notion_push/tasks.py +75 -0
  23. claude_diary/cli/notion_push/validate.py +97 -0
  24. claude_diary/cli/notion_review.py +147 -0
  25. claude_diary/cli/search.py +158 -0
  26. claude_diary/cli/setup.py +675 -0
  27. claude_diary/cli/stats.py +216 -0
  28. claude_diary/cli/team.py +72 -0
  29. claude_diary/cli/write.py +309 -0
  30. claude_diary/config.py +112 -0
  31. claude_diary/core.py +227 -0
  32. claude_diary/dashboard.py +308 -0
  33. claude_diary/exporters/__init__.py +0 -0
  34. claude_diary/exporters/base.py +30 -0
  35. claude_diary/exporters/discord.py +73 -0
  36. claude_diary/exporters/github.py +100 -0
  37. claude_diary/exporters/loader.py +154 -0
  38. claude_diary/exporters/notion.py +77 -0
  39. claude_diary/exporters/notion_hierarchical.py +680 -0
  40. claude_diary/exporters/notion_views.py +996 -0
  41. claude_diary/exporters/obsidian.py +80 -0
  42. claude_diary/exporters/slack.py +60 -0
  43. claude_diary/formatter.py +710 -0
  44. claude_diary/hook.py +80 -0
  45. claude_diary/i18n.py +172 -0
  46. claude_diary/indexer.py +141 -0
  47. claude_diary/lib/__init__.py +0 -0
  48. claude_diary/lib/audit.py +127 -0
  49. claude_diary/lib/categorizer.py +64 -0
  50. claude_diary/lib/git_info.py +212 -0
  51. claude_diary/lib/notion_cache.py +126 -0
  52. claude_diary/lib/parser.py +216 -0
  53. claude_diary/lib/secret_scanner.py +85 -0
  54. claude_diary/lib/stats.py +80 -0
  55. claude_diary/lib/team_security.py +210 -0
  56. claude_diary/log.py +42 -0
  57. claude_diary/team.py +336 -0
  58. claude_diary/types.py +63 -0
  59. claude_diary/writer.py +45 -0
@@ -0,0 +1,190 @@
1
+ """`agent-diary diary-notion ensure` -- ensure Notion DB schema and core views."""
2
+
3
+ import sys
4
+
5
+ from claude_diary.config import load_config
6
+ from claude_diary.log import configure_from_config
7
+ from claude_diary.cli.notion_common import resolve_year_and_today as _resolve_year_and_today
8
+ from claude_diary.cli.notion_push import _resolve_credentials, _print_setup_hint
9
+ from claude_diary.exporters.notion_hierarchical import (
10
+ NotionHierarchicalExporter,
11
+ NotionAuthError,
12
+ NotionBadRequest,
13
+ NotionNotFound,
14
+ SCHEMA_VERSION,
15
+ )
16
+ from claude_diary.exporters.notion_views import (
17
+ CORE_VIEW_NAMES,
18
+ OPERATION_VIEW_NAMES,
19
+ CoreViewsEnsurer,
20
+ NotionViewsClient,
21
+ )
22
+
23
+
24
+ def cmd_notion_ensure(args):
25
+ """Ensure the current year's hierarchical Notion DB and guaranteed views."""
26
+ config = load_config()
27
+ configure_from_config(config)
28
+
29
+ token, root_page_id = _resolve_credentials(config)
30
+ if not token or not root_page_id:
31
+ _print_setup_hint()
32
+ sys.exit(1)
33
+
34
+ year, today = _resolve_year_and_today(config, getattr(args, "year", None))
35
+ dry_run = getattr(args, "dry_run", False) is True
36
+
37
+ exporter = NotionHierarchicalExporter({
38
+ "api_token": token,
39
+ "root_page_id": root_page_id,
40
+ })
41
+ exporter.load_cache()
42
+
43
+ try:
44
+ if dry_run:
45
+ db_id = exporter.resolve_existing_database(year)
46
+ if not db_id:
47
+ _print_missing_database_plan(root_page_id, year)
48
+ return
49
+ schema_status = "%s would be verified" % SCHEMA_VERSION
50
+ else:
51
+ db_id = exporter.ensure_database(year, force_schema=True)
52
+ exporter.save_cache()
53
+ schema_status = "%s ensured" % SCHEMA_VERSION
54
+
55
+ client = NotionViewsClient({"api_token": token})
56
+ result = CoreViewsEnsurer(client).ensure(db_id, today, dry_run=dry_run)
57
+ except NotionAuthError as e:
58
+ print("[agent-diary diary-notion ensure] Auth error: %s" % e, file=sys.stderr)
59
+ print(" Check: agent-diary config or run `agent-diary diary-notion init`", file=sys.stderr)
60
+ sys.exit(1)
61
+ except NotionNotFound as e:
62
+ print("[agent-diary diary-notion ensure] Not found: %s" % e, file=sys.stderr)
63
+ print(" Check that the root page/database is shared with the integration.", file=sys.stderr)
64
+ sys.exit(1)
65
+ except NotionBadRequest as e:
66
+ print("[agent-diary diary-notion ensure] Bad request: %s" % e, file=sys.stderr)
67
+ sys.exit(1)
68
+ except Exception as e:
69
+ print("[agent-diary diary-notion ensure] Failed: %s" % e, file=sys.stderr)
70
+ sys.exit(1)
71
+
72
+ _print_ensure_report(root_page_id, year, db_id, schema_status, result, dry_run)
73
+ if not result.ok():
74
+ sys.exit(1)
75
+
76
+
77
+ def _print_missing_database_plan(root_page_id, year):
78
+ print("[agent-diary diary-notion ensure --dry-run]")
79
+ print("Root page: %s" % root_page_id)
80
+ print("Year: %s" % year)
81
+ print("Database: missing")
82
+ print("Plan:")
83
+ print(" + create year page if missing")
84
+ print(" + create Entries DB")
85
+ print(" + ensure schema %s" % SCHEMA_VERSION)
86
+ print(" + create %d core views" % len(CORE_VIEW_NAMES))
87
+ print(" + create %d operating views" % len(OPERATION_VIEW_NAMES))
88
+
89
+
90
+ def _print_ensure_report(root_page_id, year, db_id, schema_status, result, dry_run):
91
+ suffix = " --dry-run" if dry_run else ""
92
+ print("[agent-diary diary-notion ensure%s]" % suffix)
93
+ print("Root page: %s" % root_page_id)
94
+ print("Year: %s" % year)
95
+ print("Database: %s" % db_id)
96
+ print("Schema: %s" % schema_status)
97
+ print("Views:")
98
+ for name in result.created:
99
+ print(" + %s" % name)
100
+ for name in result.updated:
101
+ print(" ~ %s (updated)" % name)
102
+ for name in result.planned:
103
+ print(" + %s (planned)" % name)
104
+ for name in result.updates_planned:
105
+ print(" ~ %s (update planned)" % name)
106
+ for name in result.verified:
107
+ print(" = %s (verified)" % name)
108
+ for conflict in result.conflicts:
109
+ plan = build_conflict_plan(conflict.name, conflict.reason)
110
+ print(" x %s -- conflict[%s]: %s" % (
111
+ conflict.name,
112
+ plan["category"],
113
+ conflict.reason,
114
+ ))
115
+ print(" action: %s" % plan["action"])
116
+ print(" apply: %s" % ("yes" if plan["apply_supported"] else "manual"))
117
+ for failure in result.failed:
118
+ plan = build_conflict_plan(failure.name, failure.reason)
119
+ print(" ! %s -- %s [%s]" % (
120
+ failure.name,
121
+ failure.reason,
122
+ plan["category"],
123
+ ))
124
+ print(" action: %s" % plan["action"])
125
+ print(" apply: %s" % ("yes" if plan["apply_supported"] else "manual"))
126
+ if result.repaired:
127
+ print("Sub-item sync:")
128
+ for entry in result.repaired:
129
+ print(" ~ %s" % entry)
130
+ if result.warnings:
131
+ print("Warnings:")
132
+ for warning in result.warnings:
133
+ plan = build_conflict_plan("warning", warning)
134
+ print(" ! %s [%s]" % (warning, plan["category"]))
135
+ print(" action: %s" % plan["action"])
136
+ print(" apply: %s" % ("yes" if plan["apply_supported"] else "manual"))
137
+
138
+
139
+ def build_conflict_plan(name, reason):
140
+ """Return a structured read-only repair plan for an ensure problem."""
141
+ category = classify_conflict_reason(reason)
142
+ if category == "missing_filter":
143
+ return _plan(name, reason, category,
144
+ "rerun `agent-diary diary-notion ensure` to repair the view filter", True)
145
+ if category == "missing_property":
146
+ return _plan(name, reason, category,
147
+ "rerun `agent-diary diary-notion ensure` to add the missing schema property", True)
148
+ if category == "subitem_missing":
149
+ return _plan(name, reason, category, "enable Notion Sub-items in the Entries DB UI, then rerun ensure", False)
150
+ if category == "retired_view":
151
+ return _plan(name, reason, category,
152
+ "delete the listed views in Notion if you no longer use them; rerun changes nothing", False)
153
+ if category == "permission_or_auth":
154
+ return _plan(name, reason, category,
155
+ "share the root page/database with the integration or refresh the token", False)
156
+ if category == "api_failure":
157
+ return _plan(name, reason, category,
158
+ "inspect the Notion API error, then rerun ensure after fixing the payload"
159
+ " or permission issue", False)
160
+ return _plan(name, reason, category, "inspect the reported issue, then rerun ensure", False)
161
+
162
+
163
+ def _plan(name, reason, category, action, apply_supported):
164
+ return {
165
+ "name": name,
166
+ "reason": reason,
167
+ "category": category,
168
+ "action": action,
169
+ "apply_supported": apply_supported,
170
+ }
171
+
172
+
173
+ def classify_conflict_reason(reason):
174
+ """Return a stable Phase 3 conflict category for ensure diagnostics."""
175
+ text = (reason or "").lower()
176
+ # Checked before the sub-item rules: the retired list contains view names,
177
+ # not a schema problem, and one of them would otherwise match "sub-items".
178
+ if "no longer managed" in text:
179
+ return "retired_view"
180
+ if "native sub-items not enabled" in text or "sub-items" in text or "subitem" in text:
181
+ return "subitem_missing"
182
+ if "missing" in text and "filter" in text:
183
+ return "missing_filter"
184
+ if "missing" in text and ("property" in text or "column" in text):
185
+ return "missing_property"
186
+ if "permission" in text or "403" in text or "unauthorized" in text or "auth" in text:
187
+ return "permission_or_auth"
188
+ if "api" in text or "400" in text or "failed" in text:
189
+ return "api_failure"
190
+ return "unknown"
@@ -0,0 +1,148 @@
1
+ """`agent-diary diary-notion init` — interactive Notion setup.
2
+
3
+ Walks the user through:
4
+ 1. Pasting their integration token (https://www.notion.so/my-integrations)
5
+ 2. Pasting the root page URL or ID
6
+ 3. Verifying token + read access via the Notion API
7
+ 4. Saving credentials to <config_dir>/config.json under
8
+ exporters.notion_hierarchical
9
+
10
+ Write permission is NOT verified at init time — it follows from read access
11
+ when the user shares the page with their integration. If the first push 404s,
12
+ the error message points them back to the share dialog.
13
+ """
14
+
15
+ import getpass
16
+ import re
17
+ import sys
18
+
19
+ from claude_diary.config import load_config, save_config, get_config_path
20
+ from claude_diary.exporters.notion_hierarchical import (
21
+ NotionHierarchicalExporter,
22
+ NotionAuthError,
23
+ NotionNotFound,
24
+ )
25
+
26
+
27
+ PAGE_ID_RE = re.compile(
28
+ r"([0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12})"
29
+ )
30
+
31
+
32
+ def cmd_notion_init(args):
33
+ """Run the interactive setup. Returns 0 on success, non-zero on failure."""
34
+ print("─" * 56)
35
+ print("Notion hierarchical export setup")
36
+ print("─" * 56)
37
+
38
+ token = _prompt_token()
39
+ if not token:
40
+ print("\nAborted (no token).", file=sys.stderr)
41
+ sys.exit(1)
42
+
43
+ page_input = _prompt_page()
44
+ if not page_input:
45
+ print("\nAborted (no page URL/ID).", file=sys.stderr)
46
+ sys.exit(1)
47
+
48
+ page_id = parse_page_id(page_input)
49
+ if not page_id:
50
+ print(
51
+ "\n[agent-diary] Could not parse a page ID from input.\n"
52
+ " Expected: a Notion URL or a 32-character page ID.",
53
+ file=sys.stderr,
54
+ )
55
+ sys.exit(1)
56
+ print(" Parsed page_id: %s" % page_id)
57
+
58
+ print("\nStep 3/3: Verifying access...")
59
+ ok, error = _verify_access(token, page_id)
60
+ if not ok:
61
+ print(" %s" % error, file=sys.stderr)
62
+ sys.exit(1)
63
+
64
+ _save_credentials(token, page_id)
65
+ print("\nSaved to: %s" % get_config_path())
66
+ print(" exporters.notion_hierarchical.api_token = secret_***")
67
+ print(" exporters.notion_hierarchical.root_page_id = %s" % page_id)
68
+ print("\nTry it: type /diary-notion in Claude Code or $diary-notion in Codex.")
69
+
70
+
71
+ def parse_page_id(input_str):
72
+ """Extract a Notion page ID from a URL or raw ID string.
73
+
74
+ Accepts the 8-4-4-4-12 UUID form (with or without dashes). Returns the
75
+ canonical undashed 32-char hex, or None on parse failure.
76
+ """
77
+ if not input_str:
78
+ return None
79
+ m = PAGE_ID_RE.search(input_str.strip())
80
+ if not m:
81
+ return None
82
+ return m.group(1).replace("-", "").lower()
83
+
84
+
85
+ def _prompt_token():
86
+ print("\nStep 1/3: Integration token")
87
+ print(" Get it from: https://www.notion.so/my-integrations")
88
+ try:
89
+ return getpass.getpass(" Token (secret_...): ").strip()
90
+ except (EOFError, KeyboardInterrupt):
91
+ return ""
92
+
93
+
94
+ def _prompt_page():
95
+ print("\nStep 2/3: Root page URL or ID")
96
+ print(" Paste a Notion URL or page ID:")
97
+ try:
98
+ return input(" > ").strip()
99
+ except (EOFError, KeyboardInterrupt):
100
+ return ""
101
+
102
+
103
+ def _verify_access(token, page_id):
104
+ """Verify token is valid and the integration can read the root page.
105
+
106
+ Returns (ok: bool, error_message: str).
107
+ """
108
+ exporter = NotionHierarchicalExporter({
109
+ "api_token": token,
110
+ "root_page_id": page_id,
111
+ })
112
+ try:
113
+ exporter._request("GET", "/users/me")
114
+ except NotionAuthError:
115
+ return False, (
116
+ "✗ Token invalid (401/403).\n"
117
+ " Get a new token at https://www.notion.so/my-integrations"
118
+ )
119
+ except Exception as e:
120
+ return False, "✗ Could not verify token: %s" % e
121
+ print(" ✓ Token valid")
122
+
123
+ try:
124
+ exporter._request("GET", "/blocks/%s" % page_id)
125
+ except NotionNotFound:
126
+ return False, (
127
+ "✗ Page not found, or not shared with the integration.\n"
128
+ " In Notion: open the page → top-right ⋯ → Connections → add your integration."
129
+ )
130
+ except NotionAuthError:
131
+ return False, (
132
+ "✗ Page exists but the integration has no access.\n"
133
+ " In Notion: open the page → top-right ⋯ → Connections → add your integration."
134
+ )
135
+ except Exception as e:
136
+ return False, "✗ Could not verify page access: %s" % e
137
+ print(" ✓ Integration can read root page")
138
+ return True, ""
139
+
140
+
141
+ def _save_credentials(token, page_id):
142
+ """Merge token + root_page_id into config.json under notion_hierarchical."""
143
+ config = load_config()
144
+ exporters = config.setdefault("exporters", {})
145
+ nh = exporters.setdefault("notion_hierarchical", {})
146
+ nh["api_token"] = token
147
+ nh["root_page_id"] = page_id
148
+ save_config(config)