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.
- agent_diary-4.3.0.dist-info/METADATA +599 -0
- agent_diary-4.3.0.dist-info/RECORD +59 -0
- agent_diary-4.3.0.dist-info/WHEEL +5 -0
- agent_diary-4.3.0.dist-info/entry_points.txt +4 -0
- agent_diary-4.3.0.dist-info/licenses/LICENSE +21 -0
- agent_diary-4.3.0.dist-info/top_level.txt +1 -0
- claude_diary/__init__.py +3 -0
- claude_diary/__main__.py +5 -0
- claude_diary/cli/__init__.py +213 -0
- claude_diary/cli/config.py +190 -0
- claude_diary/cli/maintenance.py +146 -0
- claude_diary/cli/notion_common.py +30 -0
- claude_diary/cli/notion_ensure.py +190 -0
- claude_diary/cli/notion_init.py +148 -0
- claude_diary/cli/notion_ops.py +553 -0
- claude_diary/cli/notion_push/__init__.py +397 -0
- claude_diary/cli/notion_push/artifacts.py +146 -0
- claude_diary/cli/notion_push/ordinals.py +70 -0
- claude_diary/cli/notion_push/preview.py +59 -0
- claude_diary/cli/notion_push/properties.py +234 -0
- claude_diary/cli/notion_push/relations.py +119 -0
- claude_diary/cli/notion_push/tasks.py +75 -0
- claude_diary/cli/notion_push/validate.py +97 -0
- claude_diary/cli/notion_review.py +147 -0
- claude_diary/cli/search.py +158 -0
- claude_diary/cli/setup.py +675 -0
- claude_diary/cli/stats.py +216 -0
- claude_diary/cli/team.py +72 -0
- claude_diary/cli/write.py +309 -0
- claude_diary/config.py +112 -0
- claude_diary/core.py +227 -0
- claude_diary/dashboard.py +308 -0
- claude_diary/exporters/__init__.py +0 -0
- claude_diary/exporters/base.py +30 -0
- claude_diary/exporters/discord.py +73 -0
- claude_diary/exporters/github.py +100 -0
- claude_diary/exporters/loader.py +154 -0
- claude_diary/exporters/notion.py +77 -0
- claude_diary/exporters/notion_hierarchical.py +680 -0
- claude_diary/exporters/notion_views.py +996 -0
- claude_diary/exporters/obsidian.py +80 -0
- claude_diary/exporters/slack.py +60 -0
- claude_diary/formatter.py +710 -0
- claude_diary/hook.py +80 -0
- claude_diary/i18n.py +172 -0
- claude_diary/indexer.py +141 -0
- claude_diary/lib/__init__.py +0 -0
- claude_diary/lib/audit.py +127 -0
- claude_diary/lib/categorizer.py +64 -0
- claude_diary/lib/git_info.py +212 -0
- claude_diary/lib/notion_cache.py +126 -0
- claude_diary/lib/parser.py +216 -0
- claude_diary/lib/secret_scanner.py +85 -0
- claude_diary/lib/stats.py +80 -0
- claude_diary/lib/team_security.py +210 -0
- claude_diary/log.py +42 -0
- claude_diary/team.py +336 -0
- claude_diary/types.py +63 -0
- claude_diary/writer.py +45 -0
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
"""`agent-diary diary-notion ops` -- read-only Notion operations report."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from claude_diary.config import load_config
|
|
8
|
+
from claude_diary.log import configure_from_config
|
|
9
|
+
from claude_diary.cli.notion_common import (
|
|
10
|
+
date_start_value as _date_start,
|
|
11
|
+
plain_text as _plain_text,
|
|
12
|
+
resolve_year_and_today as _resolve_year_and_today,
|
|
13
|
+
select_value as _select,
|
|
14
|
+
title_value as _title,
|
|
15
|
+
)
|
|
16
|
+
from claude_diary.cli.notion_push import _resolve_credentials, _print_setup_hint
|
|
17
|
+
from claude_diary.exporters.notion_hierarchical import (
|
|
18
|
+
NotionHierarchicalExporter,
|
|
19
|
+
NotionAuthError,
|
|
20
|
+
NotionBadRequest,
|
|
21
|
+
NotionNotFound,
|
|
22
|
+
detect_subitem_relation,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
DONE_STATUSES = {"Deployed"}
|
|
27
|
+
ACTIVE_STATUSES = {"Discussion", "Design", "Implementation", "Testing"}
|
|
28
|
+
PRIORITY_RANK = {"P0": 0, "P1": 1, "P2": 2, "P3": 3, "": 9}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def cmd_notion_ops(args):
|
|
32
|
+
"""Print a read-only operations report for the yearly Entries database."""
|
|
33
|
+
config = load_config()
|
|
34
|
+
configure_from_config(config)
|
|
35
|
+
|
|
36
|
+
token, root_page_id = _resolve_credentials(config)
|
|
37
|
+
if not token or not root_page_id:
|
|
38
|
+
_print_setup_hint()
|
|
39
|
+
sys.exit(1)
|
|
40
|
+
|
|
41
|
+
year, today = _resolve_year_and_today(config, getattr(args, "year", None))
|
|
42
|
+
stale_days = getattr(args, "stale_days", None)
|
|
43
|
+
if stale_days is None:
|
|
44
|
+
stale_days = 7
|
|
45
|
+
json_output = getattr(args, "json_output", False) is True
|
|
46
|
+
|
|
47
|
+
exporter = NotionHierarchicalExporter({
|
|
48
|
+
"api_token": token,
|
|
49
|
+
"root_page_id": root_page_id,
|
|
50
|
+
})
|
|
51
|
+
exporter.load_cache()
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
db_id = exporter.resolve_existing_database(year)
|
|
55
|
+
if not db_id:
|
|
56
|
+
_print_missing_database(year, json_output)
|
|
57
|
+
sys.exit(1)
|
|
58
|
+
rows = exporter.query_database_rows(db_id)
|
|
59
|
+
prop_map = exporter.get_database_property_map(db_id)
|
|
60
|
+
except NotionAuthError as e:
|
|
61
|
+
print("[agent-diary diary-notion ops] Auth error: %s" % e, file=sys.stderr)
|
|
62
|
+
print(" Check: agent-diary config or run `agent-diary diary-notion init`", file=sys.stderr)
|
|
63
|
+
sys.exit(1)
|
|
64
|
+
except NotionNotFound as e:
|
|
65
|
+
print("[agent-diary diary-notion ops] Not found: %s" % e, file=sys.stderr)
|
|
66
|
+
print(" Check that the root page/database is shared with the integration.", file=sys.stderr)
|
|
67
|
+
sys.exit(1)
|
|
68
|
+
except NotionBadRequest as e:
|
|
69
|
+
print("[agent-diary diary-notion ops] Bad request: %s" % e, file=sys.stderr)
|
|
70
|
+
sys.exit(1)
|
|
71
|
+
except Exception as e:
|
|
72
|
+
print("[agent-diary diary-notion ops] Failed: %s" % e, file=sys.stderr)
|
|
73
|
+
sys.exit(1)
|
|
74
|
+
|
|
75
|
+
native = detect_subitem_relation(prop_map)
|
|
76
|
+
parent_property_name = native["parent_name"] if native else "Parent Task"
|
|
77
|
+
report = build_ops_report(rows, today, stale_days, parent_property_name)
|
|
78
|
+
if json_output:
|
|
79
|
+
print(json.dumps(report, ensure_ascii=False, indent=2))
|
|
80
|
+
else:
|
|
81
|
+
_print_ops_report(year, db_id, report)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def build_ops_report(rows, today, stale_days=7, parent_property_name="Parent Task"):
|
|
85
|
+
"""Build a read-only operations report from Notion page rows."""
|
|
86
|
+
items = [_row_to_item(row, parent_property_name) for row in rows if not row.get("archived")]
|
|
87
|
+
active = [item for item in items if not _is_done(item)]
|
|
88
|
+
|
|
89
|
+
blocked = [item for item in active if item["blocked"]]
|
|
90
|
+
needs_review = [item for item in active if item["review_status"] == "Needs Review"]
|
|
91
|
+
missing_next_action = [
|
|
92
|
+
item for item in active
|
|
93
|
+
if item["status"] in ("Implementation", "Testing") and not item["next_action"]
|
|
94
|
+
]
|
|
95
|
+
stale = [
|
|
96
|
+
item for item in active
|
|
97
|
+
if _days_since(item["work_period_start"] or item["date"], today) is not None
|
|
98
|
+
and _days_since(item["work_period_start"] or item["date"], today) >= stale_days
|
|
99
|
+
]
|
|
100
|
+
verification_candidates = _verification_candidates(active)
|
|
101
|
+
today_plan_candidates = _today_plan_candidates(active, today)
|
|
102
|
+
|
|
103
|
+
parent_status_suggestions = _parent_status_suggestions(items)
|
|
104
|
+
parent_progress = _parent_progress(items)
|
|
105
|
+
task_groups = {}
|
|
106
|
+
projects = {}
|
|
107
|
+
for item in items:
|
|
108
|
+
_accumulate_group(task_groups, item["task_group"] or "(no task group)", item)
|
|
109
|
+
_accumulate_group(projects, item["project"] or "(no project)", item)
|
|
110
|
+
|
|
111
|
+
task_groups = _finalize_groups(task_groups)
|
|
112
|
+
projects = _finalize_groups(projects)
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
"today": today,
|
|
116
|
+
"stale_days": stale_days,
|
|
117
|
+
"counts": {
|
|
118
|
+
"total": len(items),
|
|
119
|
+
"active": len(active),
|
|
120
|
+
"blocked": len(blocked),
|
|
121
|
+
"needs_review": len(needs_review),
|
|
122
|
+
"missing_next_action": len(missing_next_action),
|
|
123
|
+
"stale": len(stale),
|
|
124
|
+
"verification_candidates": len(verification_candidates),
|
|
125
|
+
"today_plan_candidates": len(today_plan_candidates),
|
|
126
|
+
"parent_status_suggestions": len(parent_status_suggestions),
|
|
127
|
+
},
|
|
128
|
+
"blocked": _compact_items(blocked),
|
|
129
|
+
"needs_review": _compact_items(needs_review),
|
|
130
|
+
"missing_next_action": _compact_items(missing_next_action),
|
|
131
|
+
"stale": _compact_items(stale),
|
|
132
|
+
"verification_candidates": _compact_items(verification_candidates, include_reason=True),
|
|
133
|
+
"today_plan_candidates": _compact_items(today_plan_candidates),
|
|
134
|
+
"parent_status_suggestions": parent_status_suggestions,
|
|
135
|
+
"parent_progress": parent_progress,
|
|
136
|
+
"task_groups": task_groups,
|
|
137
|
+
"projects": projects,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _row_to_item(row, parent_property_name="Parent Task"):
|
|
142
|
+
props = row.get("properties") or {}
|
|
143
|
+
return {
|
|
144
|
+
"id": row.get("id", ""),
|
|
145
|
+
"title": _title(props.get("Name")),
|
|
146
|
+
"project": _select(props.get("Project")),
|
|
147
|
+
"purpose": _select(props.get("Purpose")),
|
|
148
|
+
"status": _select(props.get("Status")),
|
|
149
|
+
"priority": _select(props.get("Priority")),
|
|
150
|
+
"task_group": _select(props.get("Task Group")),
|
|
151
|
+
"review_status": _select(props.get("Review Status")),
|
|
152
|
+
"next_action": _rich_text(props.get("Next Action")),
|
|
153
|
+
"blocked": _checkbox(props.get("Blocked")),
|
|
154
|
+
"block_reason": _rich_text(props.get("Block Reason")),
|
|
155
|
+
"date": _date_start(props.get("Date")),
|
|
156
|
+
"work_period_start": _date_start(props.get("Work Period")),
|
|
157
|
+
"parent_ids": _relation_ids(props.get(parent_property_name)),
|
|
158
|
+
"url": row.get("url", ""),
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _compact_items(items, limit=10, include_reason=False):
|
|
163
|
+
result = []
|
|
164
|
+
for item in items[:limit]:
|
|
165
|
+
compact = {
|
|
166
|
+
"title": item["title"],
|
|
167
|
+
"project": item["project"],
|
|
168
|
+
"task_group": item["task_group"],
|
|
169
|
+
"status": item["status"],
|
|
170
|
+
"priority": item["priority"],
|
|
171
|
+
"next_action": item["next_action"],
|
|
172
|
+
"block_reason": item["block_reason"],
|
|
173
|
+
"work_period_start": item["work_period_start"],
|
|
174
|
+
"url": item["url"],
|
|
175
|
+
}
|
|
176
|
+
if include_reason:
|
|
177
|
+
compact["reason"] = item.get("reason", "")
|
|
178
|
+
result.append(compact)
|
|
179
|
+
return result
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _is_done(item):
|
|
183
|
+
return item["status"] in DONE_STATUSES
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _accumulate_group(groups, name, item):
|
|
187
|
+
entry = groups.setdefault(name, {
|
|
188
|
+
"total": 0,
|
|
189
|
+
"active": 0,
|
|
190
|
+
"blocked": 0,
|
|
191
|
+
"needs_review": 0,
|
|
192
|
+
"done": 0,
|
|
193
|
+
"first_worked_on": "",
|
|
194
|
+
"last_worked_on": "",
|
|
195
|
+
"_work_days": set(),
|
|
196
|
+
})
|
|
197
|
+
entry["total"] += 1
|
|
198
|
+
if _is_done(item):
|
|
199
|
+
entry["done"] += 1
|
|
200
|
+
else:
|
|
201
|
+
entry["active"] += 1
|
|
202
|
+
if item["blocked"]:
|
|
203
|
+
entry["blocked"] += 1
|
|
204
|
+
if item["review_status"] == "Needs Review":
|
|
205
|
+
entry["needs_review"] += 1
|
|
206
|
+
work_day = (item["work_period_start"] or item["date"])[:10]
|
|
207
|
+
if work_day:
|
|
208
|
+
entry["_work_days"].add(work_day)
|
|
209
|
+
if not entry["first_worked_on"] or work_day < entry["first_worked_on"]:
|
|
210
|
+
entry["first_worked_on"] = work_day
|
|
211
|
+
if not entry["last_worked_on"] or work_day > entry["last_worked_on"]:
|
|
212
|
+
entry["last_worked_on"] = work_day
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _finalize_groups(groups):
|
|
216
|
+
result = {}
|
|
217
|
+
for name, entry in groups.items():
|
|
218
|
+
finalized = dict(entry)
|
|
219
|
+
work_days = finalized.pop("_work_days", set())
|
|
220
|
+
finalized["work_days"] = len(work_days)
|
|
221
|
+
finalized["done_ratio"] = _ratio(finalized["done"], finalized["total"])
|
|
222
|
+
result[name] = finalized
|
|
223
|
+
return result
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _parent_progress(items):
|
|
227
|
+
by_id = {
|
|
228
|
+
item["id"]: item
|
|
229
|
+
for item in items
|
|
230
|
+
if item["id"]
|
|
231
|
+
}
|
|
232
|
+
children_by_parent = {}
|
|
233
|
+
for item in items:
|
|
234
|
+
for parent_id in item["parent_ids"]:
|
|
235
|
+
children_by_parent.setdefault(parent_id, []).append(item)
|
|
236
|
+
|
|
237
|
+
progress = []
|
|
238
|
+
for parent_id, children in children_by_parent.items():
|
|
239
|
+
parent = by_id.get(parent_id)
|
|
240
|
+
if not parent or not children:
|
|
241
|
+
continue
|
|
242
|
+
done = sum(1 for child in children if _is_done(child))
|
|
243
|
+
blocked = sum(1 for child in children if child["blocked"])
|
|
244
|
+
progress.append({
|
|
245
|
+
"title": parent["title"],
|
|
246
|
+
"project": parent["project"],
|
|
247
|
+
"task_group": parent["task_group"],
|
|
248
|
+
"status": parent["status"],
|
|
249
|
+
"children": len(children),
|
|
250
|
+
"done": done,
|
|
251
|
+
"active": len(children) - done,
|
|
252
|
+
"blocked": blocked,
|
|
253
|
+
"done_ratio": _ratio(done, len(children)),
|
|
254
|
+
"url": parent["url"],
|
|
255
|
+
})
|
|
256
|
+
return sorted(
|
|
257
|
+
progress,
|
|
258
|
+
key=lambda item: (
|
|
259
|
+
item["done_ratio"],
|
|
260
|
+
item["title"],
|
|
261
|
+
),
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def _parent_status_suggestions(items):
|
|
266
|
+
by_id = {
|
|
267
|
+
item["id"]: item
|
|
268
|
+
for item in items
|
|
269
|
+
if item["id"]
|
|
270
|
+
}
|
|
271
|
+
children_by_parent = {}
|
|
272
|
+
for item in items:
|
|
273
|
+
for parent_id in item["parent_ids"]:
|
|
274
|
+
children_by_parent.setdefault(parent_id, []).append(item)
|
|
275
|
+
|
|
276
|
+
suggestions = []
|
|
277
|
+
for parent_id, children in children_by_parent.items():
|
|
278
|
+
parent = by_id.get(parent_id)
|
|
279
|
+
if not parent or not children:
|
|
280
|
+
continue
|
|
281
|
+
suggestion = _suggest_parent_status(parent, children)
|
|
282
|
+
if suggestion:
|
|
283
|
+
suggestions.append(suggestion)
|
|
284
|
+
return suggestions
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _suggest_parent_status(parent, children):
|
|
288
|
+
child_statuses = {child["status"] for child in children}
|
|
289
|
+
if all(_is_done(child) for child in children):
|
|
290
|
+
return _parent_suggestion(parent, "Deployed", "all child tasks are Deployed", children)
|
|
291
|
+
if any(child["blocked"] for child in children):
|
|
292
|
+
if parent["blocked"]:
|
|
293
|
+
return None
|
|
294
|
+
return _parent_suggestion(parent, parent["status"] or "Implementation",
|
|
295
|
+
"at least one child task is blocked", children)
|
|
296
|
+
if "Testing" in child_statuses and parent["status"] not in ("Testing", "Deployed"):
|
|
297
|
+
return _parent_suggestion(parent, "Testing", "at least one child task is in Testing", children)
|
|
298
|
+
if "Implementation" in child_statuses and parent["status"] in ("", "Discussion", "Design"):
|
|
299
|
+
return _parent_suggestion(parent, "Implementation", "at least one child task is in Implementation", children)
|
|
300
|
+
return None
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
def _parent_suggestion(parent, suggested_status, reason, children):
|
|
304
|
+
return {
|
|
305
|
+
"title": parent["title"],
|
|
306
|
+
"project": parent["project"],
|
|
307
|
+
"task_group": parent["task_group"],
|
|
308
|
+
"status": parent["status"],
|
|
309
|
+
"suggested_status": suggested_status,
|
|
310
|
+
"reason": reason,
|
|
311
|
+
"child_count": len(children),
|
|
312
|
+
"url": parent["url"],
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def _ratio(part, total):
|
|
317
|
+
if not total:
|
|
318
|
+
return 0.0
|
|
319
|
+
return round(float(part) / float(total), 4)
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def _today_plan_candidates(items, today):
|
|
323
|
+
candidates = []
|
|
324
|
+
for item in items:
|
|
325
|
+
if item["blocked"] or not item["next_action"]:
|
|
326
|
+
continue
|
|
327
|
+
age = _days_since(item["work_period_start"] or item["date"], today)
|
|
328
|
+
if age is None or age <= 0:
|
|
329
|
+
continue
|
|
330
|
+
candidate = dict(item)
|
|
331
|
+
candidate["age_days"] = age
|
|
332
|
+
candidates.append(candidate)
|
|
333
|
+
return sorted(
|
|
334
|
+
candidates,
|
|
335
|
+
key=lambda item: (
|
|
336
|
+
PRIORITY_RANK.get(item["priority"], 9),
|
|
337
|
+
-item["age_days"],
|
|
338
|
+
item["title"],
|
|
339
|
+
),
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
def _verification_candidates(items):
|
|
344
|
+
candidates = []
|
|
345
|
+
for item in items:
|
|
346
|
+
if item["blocked"] or item["status"] not in ("Implementation", "Testing"):
|
|
347
|
+
continue
|
|
348
|
+
reasons = []
|
|
349
|
+
if item["review_status"] != "Reviewed":
|
|
350
|
+
reasons.append("review_status_not_reviewed")
|
|
351
|
+
if item["status"] == "Testing" and not item["next_action"]:
|
|
352
|
+
reasons.append("testing_without_next_action")
|
|
353
|
+
if item["status"] == "Implementation" and item["review_status"] in ("", "Deferred"):
|
|
354
|
+
reasons.append("implementation_review_deferred")
|
|
355
|
+
if not reasons:
|
|
356
|
+
continue
|
|
357
|
+
candidate = dict(item)
|
|
358
|
+
candidate["reason"] = ", ".join(reasons)
|
|
359
|
+
candidates.append(candidate)
|
|
360
|
+
return sorted(
|
|
361
|
+
candidates,
|
|
362
|
+
key=lambda item: (
|
|
363
|
+
item["status"] != "Testing",
|
|
364
|
+
PRIORITY_RANK.get(item["priority"], 9),
|
|
365
|
+
item["title"],
|
|
366
|
+
),
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def _days_since(date_str, today):
|
|
371
|
+
if not date_str:
|
|
372
|
+
return None
|
|
373
|
+
try:
|
|
374
|
+
start = datetime.strptime(date_str[:10], "%Y-%m-%d").date()
|
|
375
|
+
end = datetime.strptime(today[:10], "%Y-%m-%d").date()
|
|
376
|
+
except ValueError:
|
|
377
|
+
return None
|
|
378
|
+
return (end - start).days
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def _rich_text(prop):
|
|
382
|
+
values = (prop or {}).get("rich_text") or []
|
|
383
|
+
return "".join(_plain_text(item) for item in values).strip()
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
def _checkbox(prop):
|
|
387
|
+
return bool((prop or {}).get("checkbox"))
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def _relation_ids(prop):
|
|
391
|
+
return [
|
|
392
|
+
item.get("id")
|
|
393
|
+
for item in (prop or {}).get("relation") or []
|
|
394
|
+
if item.get("id")
|
|
395
|
+
]
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def _print_missing_database(year, json_output):
|
|
399
|
+
if json_output:
|
|
400
|
+
print(json.dumps({
|
|
401
|
+
"year": year,
|
|
402
|
+
"error": "database_missing",
|
|
403
|
+
}, ensure_ascii=False, indent=2))
|
|
404
|
+
return
|
|
405
|
+
print("[agent-diary diary-notion ops]")
|
|
406
|
+
print("Year: %s" % year)
|
|
407
|
+
print("Database: missing")
|
|
408
|
+
print("Run `agent-diary diary-notion ensure --year %s` first." % year)
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def _print_ops_report(year, db_id, report):
|
|
412
|
+
counts = report["counts"]
|
|
413
|
+
print("[agent-diary diary-notion ops]")
|
|
414
|
+
print("Year: %s" % year)
|
|
415
|
+
print("Database: %s" % db_id)
|
|
416
|
+
print("Rows: %d total, %d active" % (counts["total"], counts["active"]))
|
|
417
|
+
print("Signals:")
|
|
418
|
+
print(" Blocked: %d" % counts["blocked"])
|
|
419
|
+
print(" Needs review: %d" % counts["needs_review"])
|
|
420
|
+
print(" Missing next action: %d" % counts["missing_next_action"])
|
|
421
|
+
print(" Stale >= %d day(s): %d" % (report["stale_days"], counts["stale"]))
|
|
422
|
+
print(" Verification candidates: %d" % counts["verification_candidates"])
|
|
423
|
+
print(" Today-plan candidates: %d" % counts["today_plan_candidates"])
|
|
424
|
+
print(" Parent status suggestions: %d" % counts["parent_status_suggestions"])
|
|
425
|
+
_print_section("Blocked", report["blocked"])
|
|
426
|
+
_print_section("Needs Review", report["needs_review"])
|
|
427
|
+
_print_section("Missing Next Action", report["missing_next_action"])
|
|
428
|
+
_print_section("Stale Work", report["stale"])
|
|
429
|
+
_print_section("Today Plan Candidates", report["today_plan_candidates"])
|
|
430
|
+
_print_parent_progress(report["parent_progress"])
|
|
431
|
+
_print_parent_status_suggestions(report["parent_status_suggestions"])
|
|
432
|
+
_print_group_summary(report["task_groups"])
|
|
433
|
+
_print_project_summary(report["projects"])
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def _print_section(name, items):
|
|
437
|
+
if not items:
|
|
438
|
+
return
|
|
439
|
+
print("%s:" % name)
|
|
440
|
+
for item in items:
|
|
441
|
+
suffix = []
|
|
442
|
+
if item["project"]:
|
|
443
|
+
suffix.append(item["project"])
|
|
444
|
+
if item["task_group"]:
|
|
445
|
+
suffix.append(item["task_group"])
|
|
446
|
+
if item["status"]:
|
|
447
|
+
suffix.append(item["status"])
|
|
448
|
+
detail = " | ".join(suffix)
|
|
449
|
+
print(" - %s%s" % (item["title"], " (%s)" % detail if detail else ""))
|
|
450
|
+
if item.get("reason"):
|
|
451
|
+
print(" reason: %s" % item["reason"])
|
|
452
|
+
if item["next_action"]:
|
|
453
|
+
print(" next: %s" % item["next_action"])
|
|
454
|
+
if item["block_reason"]:
|
|
455
|
+
print(" blocked: %s" % item["block_reason"])
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
def _print_group_summary(groups):
|
|
459
|
+
if not groups:
|
|
460
|
+
return
|
|
461
|
+
print("Task Groups:")
|
|
462
|
+
for name in sorted(groups):
|
|
463
|
+
data = groups[name]
|
|
464
|
+
print(
|
|
465
|
+
" - %s: %d total, %d active, %d done, %d blocked, %d review, %d work day(s)%s" %
|
|
466
|
+
(
|
|
467
|
+
name,
|
|
468
|
+
data["total"],
|
|
469
|
+
data["active"],
|
|
470
|
+
data["done"],
|
|
471
|
+
data["blocked"],
|
|
472
|
+
data["needs_review"],
|
|
473
|
+
data["work_days"],
|
|
474
|
+
_period_suffix(data),
|
|
475
|
+
)
|
|
476
|
+
)
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def _print_project_summary(projects):
|
|
480
|
+
if not projects:
|
|
481
|
+
return
|
|
482
|
+
print("Projects:")
|
|
483
|
+
for name in sorted(projects):
|
|
484
|
+
data = projects[name]
|
|
485
|
+
print(
|
|
486
|
+
" - %s: %d total, %d active, %d done, %d work day(s)%s" %
|
|
487
|
+
(
|
|
488
|
+
name,
|
|
489
|
+
data["total"],
|
|
490
|
+
data["active"],
|
|
491
|
+
data["done"],
|
|
492
|
+
data["work_days"],
|
|
493
|
+
_period_suffix(data),
|
|
494
|
+
)
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def _print_parent_status_suggestions(items):
|
|
499
|
+
if not items:
|
|
500
|
+
return
|
|
501
|
+
print("Parent Status Suggestions:")
|
|
502
|
+
for item in items:
|
|
503
|
+
detail = []
|
|
504
|
+
if item["project"]:
|
|
505
|
+
detail.append(item["project"])
|
|
506
|
+
if item["task_group"]:
|
|
507
|
+
detail.append(item["task_group"])
|
|
508
|
+
suffix = " (%s)" % " | ".join(detail) if detail else ""
|
|
509
|
+
print(
|
|
510
|
+
" - %s%s: %s -> %s (%s, %d child task(s))" %
|
|
511
|
+
(
|
|
512
|
+
item["title"],
|
|
513
|
+
suffix,
|
|
514
|
+
item["status"] or "(unset)",
|
|
515
|
+
item["suggested_status"],
|
|
516
|
+
item["reason"],
|
|
517
|
+
item["child_count"],
|
|
518
|
+
)
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
def _print_parent_progress(items):
|
|
523
|
+
if not items:
|
|
524
|
+
return
|
|
525
|
+
print("Parent Progress:")
|
|
526
|
+
for item in items:
|
|
527
|
+
detail = []
|
|
528
|
+
if item["project"]:
|
|
529
|
+
detail.append(item["project"])
|
|
530
|
+
if item["task_group"]:
|
|
531
|
+
detail.append(item["task_group"])
|
|
532
|
+
suffix = " (%s)" % " | ".join(detail) if detail else ""
|
|
533
|
+
percent = int(round(item["done_ratio"] * 100))
|
|
534
|
+
print(
|
|
535
|
+
" - %s%s: %d/%d done, %d active, %d blocked (%d%%)" %
|
|
536
|
+
(
|
|
537
|
+
item["title"],
|
|
538
|
+
suffix,
|
|
539
|
+
item["done"],
|
|
540
|
+
item["children"],
|
|
541
|
+
item["active"],
|
|
542
|
+
item["blocked"],
|
|
543
|
+
percent,
|
|
544
|
+
)
|
|
545
|
+
)
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
def _period_suffix(data):
|
|
549
|
+
if not data.get("first_worked_on"):
|
|
550
|
+
return ""
|
|
551
|
+
if data.get("first_worked_on") == data.get("last_worked_on"):
|
|
552
|
+
return ", %s" % data["first_worked_on"]
|
|
553
|
+
return ", %s..%s" % (data["first_worked_on"], data["last_worked_on"])
|