@event4u/agent-config 1.18.0 → 1.20.0

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 (181) hide show
  1. package/.agent-src/commands/agent-handoff.md +14 -10
  2. package/.agent-src/commands/chat-history/import.md +170 -0
  3. package/.agent-src/commands/chat-history/learn.md +178 -0
  4. package/.agent-src/commands/chat-history/show.md +17 -18
  5. package/.agent-src/commands/chat-history.md +26 -25
  6. package/.agent-src/commands/council/default.md +77 -82
  7. package/.agent-src/commands/create-pr.md +28 -8
  8. package/.agent-src/commands/feature/roadmap.md +22 -0
  9. package/.agent-src/commands/roadmap/create.md +38 -6
  10. package/.agent-src/commands/roadmap/execute.md +36 -9
  11. package/.agent-src/commands/sync-gitignore.md +1 -1
  12. package/.agent-src/contexts/communication/rules-auto/skill-quality-mechanics.md +76 -0
  13. package/.agent-src/contexts/communication/rules-auto/slash-command-routing-policy-mechanics.md +3 -3
  14. package/.agent-src/contexts/communication/rules-auto/user-interaction-mechanics.md +5 -12
  15. package/.agent-src/rules/agent-authority.md +1 -0
  16. package/.agent-src/rules/agent-docs.md +1 -0
  17. package/.agent-src/rules/analysis-skill-routing.md +1 -0
  18. package/.agent-src/rules/architecture.md +1 -0
  19. package/.agent-src/rules/artifact-drafting-protocol.md +1 -0
  20. package/.agent-src/rules/artifact-engagement-recording.md +1 -0
  21. package/.agent-src/rules/ask-when-uncertain.md +1 -0
  22. package/.agent-src/rules/augment-portability.md +1 -0
  23. package/.agent-src/rules/augment-source-of-truth.md +1 -0
  24. package/.agent-src/rules/autonomous-execution.md +1 -0
  25. package/.agent-src/rules/capture-learnings.md +1 -0
  26. package/.agent-src/rules/cli-output-handling.md +2 -2
  27. package/.agent-src/rules/command-suggestion-policy.md +1 -0
  28. package/.agent-src/rules/commit-conventions.md +1 -0
  29. package/.agent-src/rules/commit-policy.md +1 -0
  30. package/.agent-src/rules/context-hygiene.md +22 -0
  31. package/.agent-src/rules/direct-answers.md +11 -2
  32. package/.agent-src/rules/docker-commands.md +1 -0
  33. package/.agent-src/rules/docs-sync.md +1 -0
  34. package/.agent-src/rules/downstream-changes.md +1 -0
  35. package/.agent-src/rules/e2e-testing.md +1 -0
  36. package/.agent-src/rules/guidelines.md +1 -0
  37. package/.agent-src/rules/improve-before-implement.md +1 -0
  38. package/.agent-src/rules/language-and-tone.md +38 -6
  39. package/.agent-src/rules/laravel-translations.md +1 -0
  40. package/.agent-src/rules/markdown-safe-codeblocks.md +1 -0
  41. package/.agent-src/rules/minimal-safe-diff.md +1 -0
  42. package/.agent-src/rules/missing-tool-handling.md +1 -0
  43. package/.agent-src/rules/model-recommendation.md +1 -0
  44. package/.agent-src/rules/no-attribution-footers.md +48 -0
  45. package/.agent-src/rules/no-cheap-questions.md +1 -0
  46. package/.agent-src/rules/no-roadmap-references.md +2 -1
  47. package/.agent-src/rules/non-destructive-by-default.md +1 -0
  48. package/.agent-src/rules/onboarding-gate.md +26 -0
  49. package/.agent-src/rules/package-ci-checks.md +1 -0
  50. package/.agent-src/rules/php-coding.md +1 -0
  51. package/.agent-src/rules/preservation-guard.md +1 -0
  52. package/.agent-src/rules/review-routing-awareness.md +1 -0
  53. package/.agent-src/rules/reviewer-awareness.md +1 -0
  54. package/.agent-src/rules/roadmap-progress-sync.md +22 -0
  55. package/.agent-src/rules/role-mode-adherence.md +2 -2
  56. package/.agent-src/rules/rule-type-governance.md +1 -0
  57. package/.agent-src/rules/runtime-safety.md +1 -0
  58. package/.agent-src/rules/scope-control.md +1 -0
  59. package/.agent-src/rules/security-sensitive-stop.md +1 -0
  60. package/.agent-src/rules/size-enforcement.md +1 -0
  61. package/.agent-src/rules/skill-improvement-trigger.md +1 -0
  62. package/.agent-src/rules/skill-quality.md +50 -0
  63. package/.agent-src/rules/slash-command-routing-policy.md +39 -0
  64. package/.agent-src/rules/think-before-action.md +1 -0
  65. package/.agent-src/rules/token-efficiency.md +1 -0
  66. package/.agent-src/rules/tool-safety.md +1 -0
  67. package/.agent-src/rules/ui-audit-gate.md +1 -0
  68. package/.agent-src/rules/upstream-proposal.md +1 -0
  69. package/.agent-src/rules/user-interaction.md +22 -5
  70. package/.agent-src/rules/verify-before-complete.md +1 -0
  71. package/.agent-src/skills/ai-council/SKILL.md +4 -5
  72. package/.agent-src/skills/dcf-modeling/SKILL.md +89 -0
  73. package/.agent-src/skills/funnel-analysis/SKILL.md +100 -0
  74. package/.agent-src/skills/md-language-check/SKILL.md +1 -1
  75. package/.agent-src/skills/okr-tree-modeling/SKILL.md +93 -0
  76. package/.agent-src/skills/rice-prioritization/SKILL.md +100 -0
  77. package/.agent-src/skills/roadmap-management/SKILL.md +29 -4
  78. package/.agent-src/skills/subagent-orchestration/SKILL.md +34 -2
  79. package/.agent-src/skills/unit-economics-modeling/SKILL.md +104 -0
  80. package/.agent-src/skills/using-git-worktrees/SKILL.md +1 -0
  81. package/.agent-src/skills/verify-completion-evidence/SKILL.md +8 -1
  82. package/.agent-src/templates/agent-settings.md +21 -26
  83. package/.agent-src/templates/roadmaps.md +8 -3
  84. package/.agent-src/templates/scripts/work_engine/hook_bootstrap.py +16 -5
  85. package/.agent-src/templates/scripts/work_engine/hooks/__init__.py +4 -4
  86. package/.agent-src/templates/scripts/work_engine/hooks/builtin/__init__.py +4 -4
  87. package/.agent-src/templates/scripts/work_engine/hooks/builtin/_chat_history_base.py +7 -51
  88. package/.agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_append.py +1 -2
  89. package/.agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_halt_append.py +1 -2
  90. package/.agent-src/templates/scripts/work_engine/hooks/builtin/decision_trace.py +163 -0
  91. package/.agent-src/templates/scripts/work_engine/hooks/builtin/memory_visibility.py +110 -0
  92. package/.agent-src/templates/scripts/work_engine/hooks/settings.py +36 -0
  93. package/.agent-src/templates/scripts/work_engine/scoring/decision_trace.py +141 -0
  94. package/.agent-src/templates/scripts/work_engine/scoring/memory_visibility.py +125 -0
  95. package/.agent-src/templates/skill.md +30 -1
  96. package/.claude-plugin/marketplace.json +8 -4
  97. package/AGENTS.md +44 -3
  98. package/CHANGELOG.md +173 -0
  99. package/README.md +22 -22
  100. package/config/agent-settings.template.yml +42 -13
  101. package/config/gitignore-block.txt +4 -4
  102. package/docs/architecture.md +3 -3
  103. package/docs/catalog.md +18 -13
  104. package/docs/contracts/adr-chat-history-split.md +10 -1
  105. package/docs/contracts/adr-settings-sync-engine.md +127 -0
  106. package/docs/contracts/command-clusters.md +1 -1
  107. package/docs/contracts/cross-wing-handoff.md +133 -0
  108. package/docs/contracts/decision-trace-v1.md +146 -0
  109. package/docs/contracts/file-ownership-matrix.json +348 -126
  110. package/docs/contracts/hook-architecture-v1.md +220 -0
  111. package/docs/contracts/memory-visibility-v1.md +122 -0
  112. package/docs/contracts/one-off-script-lifecycle.md +109 -0
  113. package/docs/contracts/rule-interactions.yml +22 -0
  114. package/docs/customization.md +2 -1
  115. package/docs/development.md +4 -1
  116. package/docs/getting-started.md +21 -29
  117. package/docs/guidelines/agent-infra/ask-when-uncertain-demos.md +1 -1
  118. package/docs/guidelines/agent-infra/layered-settings.md +32 -13
  119. package/docs/hook-payload-capture.md +221 -0
  120. package/docs/migrations/commands-1.15.0.md +17 -12
  121. package/docs/skills-catalog.md +5 -4
  122. package/llms.txt +4 -3
  123. package/package.json +1 -1
  124. package/scripts/agent-config +45 -1
  125. package/scripts/ai_council/_default_prices.py +4 -4
  126. package/scripts/ai_council/bundler.py +3 -3
  127. package/scripts/ai_council/clients.py +25 -9
  128. package/scripts/ai_council/modes.py +3 -4
  129. package/scripts/ai_council/one_off_archive/2026-05/README.md +22 -0
  130. package/scripts/ai_council/one_off_archive/2026-05/_one_off_roundtrip.py +13 -8
  131. package/scripts/ai_council/one_off_archive/2026-05/_one_off_tier_retrofit.py +180 -0
  132. package/scripts/ai_council/pricing.py +10 -9
  133. package/scripts/ai_council/session.py +92 -0
  134. package/scripts/build_rule_trigger_matrix.py +1 -9
  135. package/scripts/capture_showcase_session.py +361 -0
  136. package/scripts/chat_history.py +963 -597
  137. package/scripts/check_always_budget.py +7 -2
  138. package/scripts/check_references.py +12 -2
  139. package/scripts/context_hygiene_hook.py +14 -6
  140. package/scripts/council_cli.py +407 -0
  141. package/scripts/hook_manifest.yaml +217 -0
  142. package/scripts/hooks/__init__.py +1 -0
  143. package/scripts/hooks/augment-chat-history.sh +10 -0
  144. package/scripts/hooks/augment-dispatcher.sh +72 -0
  145. package/scripts/hooks/cline-dispatcher.sh +86 -0
  146. package/scripts/hooks/cowork-dispatcher.sh +98 -0
  147. package/scripts/hooks/cursor-dispatcher.sh +76 -0
  148. package/scripts/hooks/dispatch_hook.py +383 -0
  149. package/scripts/hooks/envelope.py +98 -0
  150. package/scripts/hooks/gemini-dispatcher.sh +117 -0
  151. package/scripts/hooks/state_io.py +122 -0
  152. package/scripts/hooks/windsurf-dispatcher.sh +123 -0
  153. package/scripts/hooks_status.py +157 -0
  154. package/scripts/install-hooks.sh +2 -2
  155. package/scripts/install.py +725 -87
  156. package/scripts/install.sh +38 -1
  157. package/scripts/lint_handoffs.py +214 -0
  158. package/scripts/lint_hook_manifest.py +217 -0
  159. package/scripts/lint_one_off_age.py +184 -0
  160. package/scripts/lint_rule_tiers.py +78 -0
  161. package/scripts/lint_showcase_sessions.py +148 -0
  162. package/scripts/minimal_safe_diff_hook.py +245 -0
  163. package/scripts/onboarding_gate_hook.py +13 -8
  164. package/scripts/readme_linter.py +12 -3
  165. package/scripts/redact_hook_capture.py +148 -0
  166. package/scripts/roadmap_progress_hook.py +5 -0
  167. package/scripts/schemas/skill.schema.json +5 -0
  168. package/scripts/skill_linter.py +163 -1
  169. package/scripts/sync_agent_settings.py +32 -129
  170. package/scripts/sync_yaml_rt.py +734 -0
  171. package/scripts/update_prices.py +3 -3
  172. package/scripts/verify_before_complete_hook.py +216 -0
  173. package/.agent-src/commands/chat-history/checkpoint.md +0 -126
  174. package/.agent-src/commands/chat-history/clear.md +0 -103
  175. package/.agent-src/commands/chat-history/resume.md +0 -183
  176. package/.agent-src/rules/chat-history-cadence.md +0 -109
  177. package/.agent-src/rules/chat-history-ownership.md +0 -123
  178. package/.agent-src/rules/chat-history-visibility.md +0 -96
  179. package/.agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_heartbeat.py +0 -50
  180. package/.agent-src/templates/scripts/work_engine/hooks/builtin/chat_history_turn_check.py +0 -49
  181. package/scripts/check_phase_coupling.py +0 -148
@@ -0,0 +1,361 @@
1
+ #!/usr/bin/env python3
2
+ """capture_showcase_session.py — wrap and measure showcase sessions.
3
+
4
+ Phase 1.2 deliverable for `road-to-feedback-consolidation.md`.
5
+
6
+ Two subcommands:
7
+
8
+ capture Read a raw chat-log (file or stdin) and write a session under
9
+ `docs/showcase/sessions/<slug>.log` with a YAML frontmatter
10
+ block (commit_sha, host_agent, model, started, ended,
11
+ task_class, metrics).
12
+
13
+ metrics Compute one or all of the four outcome metrics defined in
14
+ `agents/contexts/outcome-baseline.md` from a captured session
15
+ file. Output as text table or JSON.
16
+
17
+ The four metrics:
18
+ (a) tool-call-count — number of <tool_use ...> blocks in body
19
+ (b) reply-chars — mean chars of agent replies (excl. fences)
20
+ (c) memory-hit-ratio — hits / (hits + misses) from memory traces
21
+ (d) verify-pass-rate — first-try done-claims / total done-claims
22
+
23
+ Exit codes: 0 success, 1 user error (bad args, missing file), 2 metric
24
+ gate not yet wired (downstream phase pending).
25
+ """
26
+ from __future__ import annotations
27
+
28
+ import argparse
29
+ import datetime as _dt
30
+ import json
31
+ import re
32
+ import subprocess
33
+ import sys
34
+ from dataclasses import dataclass, asdict
35
+ from pathlib import Path
36
+ from typing import Any, Dict, List, Optional
37
+
38
+ ROOT = Path(__file__).resolve().parent.parent
39
+ SESSIONS_DIR = ROOT / "docs" / "showcase" / "sessions"
40
+
41
+ # Tool-call markers across host agents (Augment, Claude Code, Cursor, …).
42
+ # Union, not branch — a session log may carry multiple shapes.
43
+ TOOL_USE_PATTERNS = [
44
+ re.compile(r"<tool_use[\s>]"),
45
+ re.compile(r"<function_calls>"),
46
+ re.compile(r"<invoke\b"),
47
+ ]
48
+
49
+ # Memory-retrieve trace shape, per memory-visibility-v1.md (Phase 4.1).
50
+ # Until Phase 4.1 lands, fall back to counting `memory_retrieve` invocations
51
+ # without hit/miss disambiguation (returns ratio=None).
52
+ MEMORY_HIT_RE = re.compile(r"memory_retrieve\b.*?hits=(\d+)", re.IGNORECASE)
53
+ MEMORY_MISS_RE = re.compile(
54
+ r"memory_retrieve\b.*?(misses=(\d+)|hits=0)", re.IGNORECASE
55
+ )
56
+ MEMORY_CALL_RE = re.compile(r"\bmemory_retrieve(?:_\w+)?\b")
57
+
58
+ # Done-claim markers — agent says work is complete.
59
+ DONE_CLAIM_PATTERNS = [
60
+ re.compile(r"\b(done|complete|ready for review|fertig|abgeschlossen)\b",
61
+ re.IGNORECASE),
62
+ re.compile(r"^\s*(✅|✓)", re.MULTILINE),
63
+ ]
64
+
65
+ # Correction phrasings — user re-prompts with a complaint, signalling
66
+ # the verify-gate let bad work through. Optimistic: anything not on this
67
+ # list is treated as scope expansion, not failure.
68
+ CORRECTION_PHRASES = [
69
+ "das passt nicht", "das stimmt nicht", "passt so nicht",
70
+ "that's wrong", "this is wrong", "missing", "fehlt",
71
+ "didn't work", "doesn't work", "geht nicht", "broken",
72
+ "you missed", "du hast", "das ist falsch",
73
+ ]
74
+
75
+
76
+ @dataclass
77
+ class SessionMetrics:
78
+ tool_call_count: Optional[int] = None
79
+ reply_chars_mean: Optional[float] = None
80
+ memory_hit_ratio: Optional[float] = None
81
+ verify_pass_rate: Optional[float] = None
82
+ notes: List[str] = None # populated when a metric is degraded
83
+
84
+ def to_dict(self) -> Dict[str, Any]:
85
+ d = asdict(self)
86
+ # Drop notes when empty so frontmatter stays compact.
87
+ if not self.notes:
88
+ d.pop("notes", None)
89
+ return d
90
+
91
+
92
+ def _git_sha() -> str:
93
+ try:
94
+ out = subprocess.run(
95
+ ["git", "rev-parse", "HEAD"],
96
+ capture_output=True, text=True, check=True, cwd=ROOT,
97
+ )
98
+ return out.stdout.strip()
99
+ except (subprocess.CalledProcessError, FileNotFoundError):
100
+ return "unknown"
101
+
102
+
103
+ def _now_iso() -> str:
104
+ return _dt.datetime.now(_dt.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
105
+
106
+
107
+ def _strip_fences(text: str) -> str:
108
+ """Remove fenced code blocks so they don't pollute char counts."""
109
+ return re.sub(r"```.*?```", "", text, flags=re.DOTALL)
110
+
111
+
112
+ def _split_body(content: str) -> str:
113
+ """Strip a leading YAML frontmatter block if present."""
114
+ if content.startswith("---\n"):
115
+ end = content.find("\n---\n", 4)
116
+ if end != -1:
117
+ return content[end + 5:]
118
+ return content
119
+
120
+
121
+ def _read_session(path: Path) -> str:
122
+ if str(path) == "-":
123
+ return sys.stdin.read()
124
+ if not path.is_file():
125
+ raise SystemExit(f"❌ session file not found: {path}")
126
+ return path.read_text(encoding="utf-8")
127
+
128
+
129
+ def _split_turns(body: str) -> List[Dict[str, str]]:
130
+ """Heuristic turn split — `## User` / `## Agent` headings, falls back
131
+ to whole-body as a single agent turn when no markers exist.
132
+ """
133
+ turn_re = re.compile(
134
+ r"^##\s+(User|Agent|Assistant|Matze|Du)\b.*?$", re.MULTILINE | re.IGNORECASE
135
+ )
136
+ matches = list(turn_re.finditer(body))
137
+ if not matches:
138
+ return [{"role": "agent", "text": body}]
139
+ turns: List[Dict[str, str]] = []
140
+ for i, m in enumerate(matches):
141
+ role_raw = m.group(1).lower()
142
+ role = "user" if role_raw in {"user", "matze", "du"} else "agent"
143
+ start = m.end()
144
+ end = matches[i + 1].start() if i + 1 < len(matches) else len(body)
145
+ turns.append({"role": role, "text": body[start:end].strip()})
146
+ return turns
147
+
148
+
149
+ def _metric_tool_call_count(body: str) -> int:
150
+ return sum(len(p.findall(body)) for p in TOOL_USE_PATTERNS)
151
+
152
+
153
+ def _metric_reply_chars(body: str) -> Optional[float]:
154
+ turns = _split_turns(body)
155
+ agent_turns = [t["text"] for t in turns if t["role"] == "agent"]
156
+ if not agent_turns:
157
+ return None
158
+ lengths = [len(_strip_fences(t).strip()) for t in agent_turns]
159
+ return round(sum(lengths) / len(lengths), 1)
160
+
161
+
162
+ def _metric_memory_hit_ratio(body: str) -> tuple[Optional[float], List[str]]:
163
+ """Returns (ratio, notes). Ratio is None when no memory calls found."""
164
+ notes: List[str] = []
165
+ hits_total = sum(int(m.group(1)) for m in MEMORY_HIT_RE.finditer(body))
166
+ miss_blocks = MEMORY_MISS_RE.findall(body)
167
+ miss_total = 0
168
+ for raw, count in miss_blocks:
169
+ if count:
170
+ miss_total += int(count)
171
+ else:
172
+ miss_total += 1 # `hits=0` case
173
+ calls = len(MEMORY_CALL_RE.findall(body))
174
+ if calls == 0:
175
+ return None, ["no memory_retrieve calls found"]
176
+ if hits_total + miss_total == 0:
177
+ notes.append("memory-visibility-v1 trace not present; "
178
+ "counted calls only (Phase 4.1 pending)")
179
+ return None, notes
180
+ return round(hits_total / (hits_total + miss_total), 3), notes
181
+
182
+
183
+ def _metric_verify_pass_rate(body: str) -> tuple[Optional[float], List[str]]:
184
+ turns = _split_turns(body)
185
+ if len(turns) < 2:
186
+ return None, ["session has no user/agent split — cannot measure"]
187
+ total_claims = 0
188
+ failed_claims = 0
189
+ for i, turn in enumerate(turns):
190
+ if turn["role"] != "agent":
191
+ continue
192
+ if not any(p.search(turn["text"]) for p in DONE_CLAIM_PATTERNS):
193
+ continue
194
+ total_claims += 1
195
+ next_user = next(
196
+ (t for t in turns[i + 1:] if t["role"] == "user"), None
197
+ )
198
+ if next_user is None:
199
+ continue # claim accepted (session ended on the claim)
200
+ lower = next_user["text"].lower()
201
+ if any(phrase in lower for phrase in CORRECTION_PHRASES):
202
+ failed_claims += 1
203
+ if total_claims == 0:
204
+ return None, ["no done-claims found in session"]
205
+ return round((total_claims - failed_claims) / total_claims, 3), []
206
+
207
+
208
+ def _compute_metrics(body: str) -> SessionMetrics:
209
+ notes: List[str] = []
210
+ mhr, mhr_notes = _metric_memory_hit_ratio(body)
211
+ notes.extend(mhr_notes)
212
+ vpr, vpr_notes = _metric_verify_pass_rate(body)
213
+ notes.extend(vpr_notes)
214
+ return SessionMetrics(
215
+ tool_call_count=_metric_tool_call_count(body),
216
+ reply_chars_mean=_metric_reply_chars(body),
217
+ memory_hit_ratio=mhr,
218
+ verify_pass_rate=vpr,
219
+ notes=notes or None,
220
+ )
221
+
222
+
223
+ def _render_frontmatter(meta: Dict[str, Any]) -> str:
224
+ """Minimal YAML emitter — stdlib only, dict + scalar + list of strings.
225
+ Nested dict supported one level deep (for `metrics`).
226
+ """
227
+ def fmt_scalar(v: Any) -> str:
228
+ if v is None:
229
+ return "null"
230
+ if isinstance(v, bool):
231
+ return "true" if v else "false"
232
+ if isinstance(v, (int, float)):
233
+ return str(v)
234
+ return json.dumps(v, ensure_ascii=False)
235
+
236
+ lines = ["---"]
237
+ for k, v in meta.items():
238
+ if isinstance(v, dict):
239
+ lines.append(f"{k}:")
240
+ for kk, vv in v.items():
241
+ lines.append(f" {kk}: {fmt_scalar(vv)}")
242
+ elif isinstance(v, list):
243
+ lines.append(f"{k}:")
244
+ for item in v:
245
+ lines.append(f" - {fmt_scalar(item)}")
246
+ else:
247
+ lines.append(f"{k}: {fmt_scalar(v)}")
248
+ lines.append("---")
249
+ return "\n".join(lines) + "\n"
250
+
251
+
252
+ def cmd_capture(args: argparse.Namespace) -> int:
253
+ raw = _read_session(Path(args.input))
254
+ body = _split_body(raw)
255
+ metrics = _compute_metrics(body)
256
+ started = args.started or _now_iso()
257
+ ended = args.ended or _now_iso()
258
+ meta: Dict[str, Any] = {
259
+ "slug": args.slug,
260
+ "task_class": args.task_class,
261
+ "host_agent": args.host,
262
+ "model": args.model,
263
+ "commit_sha": _git_sha(),
264
+ "started": started,
265
+ "ended": ended,
266
+ "metrics": metrics.to_dict(),
267
+ }
268
+ frontmatter = _render_frontmatter(meta)
269
+ SESSIONS_DIR.mkdir(parents=True, exist_ok=True)
270
+ out_path = SESSIONS_DIR / f"{args.slug}.log"
271
+ if out_path.exists() and not args.force:
272
+ print(f"❌ refusing to overwrite {out_path} — pass --force",
273
+ file=sys.stderr)
274
+ return 1
275
+ out_path.write_text(frontmatter + body, encoding="utf-8")
276
+ try:
277
+ display = out_path.relative_to(ROOT)
278
+ except ValueError:
279
+ display = out_path
280
+ print(f"✅ wrote {display}")
281
+ if args.format == "json":
282
+ print(json.dumps(metrics.to_dict(), indent=2))
283
+ return 0
284
+
285
+
286
+ def cmd_metrics(args: argparse.Namespace) -> int:
287
+ raw = _read_session(Path(args.session))
288
+ body = _split_body(raw)
289
+ metrics = _compute_metrics(body)
290
+ selected = args.metric
291
+ available = {
292
+ "tool-call-count": metrics.tool_call_count,
293
+ "reply-chars": metrics.reply_chars_mean,
294
+ "memory-hit-ratio": metrics.memory_hit_ratio,
295
+ "verify-pass-rate": metrics.verify_pass_rate,
296
+ }
297
+ if selected != "all" and selected not in available:
298
+ print(f"❌ unknown metric: {selected}", file=sys.stderr)
299
+ return 1
300
+ if args.format == "json":
301
+ if selected == "all":
302
+ print(json.dumps(metrics.to_dict(), indent=2))
303
+ else:
304
+ print(json.dumps({selected: available[selected]}, indent=2))
305
+ return 0
306
+ items = available.items() if selected == "all" else [(selected, available[selected])]
307
+ for name, value in items:
308
+ rendered = "n/a" if value is None else str(value)
309
+ print(f" {name:<22} {rendered}")
310
+ if metrics.notes:
311
+ print()
312
+ for note in metrics.notes:
313
+ print(f" ℹ️ {note}")
314
+ return 0
315
+
316
+
317
+ def _build_parser() -> argparse.ArgumentParser:
318
+ p = argparse.ArgumentParser(
319
+ prog="capture_showcase_session.py",
320
+ description="Capture and measure /implement-ticket and /work showcase sessions.",
321
+ )
322
+ sub = p.add_subparsers(dest="command", required=True)
323
+
324
+ cap = sub.add_parser("capture", help="Write a session log with frontmatter.")
325
+ cap.add_argument("--input", required=True,
326
+ help="Path to raw chat log, or '-' for stdin.")
327
+ cap.add_argument("--slug", required=True,
328
+ help="Filename slug (becomes <slug>.log).")
329
+ cap.add_argument("--task-class", default="implement-ticket",
330
+ choices=["implement-ticket", "work", "review-changes", "qa"])
331
+ cap.add_argument("--host", default="unknown",
332
+ help="Host agent identifier (augment, claude-code, …).")
333
+ cap.add_argument("--model", default="unknown")
334
+ cap.add_argument("--started", default=None,
335
+ help="ISO-8601 start timestamp (defaults to now).")
336
+ cap.add_argument("--ended", default=None,
337
+ help="ISO-8601 end timestamp (defaults to now).")
338
+ cap.add_argument("--force", action="store_true",
339
+ help="Overwrite an existing session file.")
340
+ cap.add_argument("--format", choices=["text", "json"], default="text")
341
+ cap.set_defaults(func=cmd_capture)
342
+
343
+ met = sub.add_parser("metrics", help="Compute one or all metrics.")
344
+ met.add_argument("--session", required=True,
345
+ help="Path to a captured session log.")
346
+ met.add_argument("--metric", default="all",
347
+ choices=["all", "tool-call-count", "reply-chars",
348
+ "memory-hit-ratio", "verify-pass-rate"])
349
+ met.add_argument("--format", choices=["text", "json"], default="text")
350
+ met.set_defaults(func=cmd_metrics)
351
+ return p
352
+
353
+
354
+ def main(argv: Optional[List[str]] = None) -> int:
355
+ parser = _build_parser()
356
+ args = parser.parse_args(argv)
357
+ return args.func(args)
358
+
359
+
360
+ if __name__ == "__main__":
361
+ sys.exit(main())