Commit 4ac6296
authored
feat(session-log): /log-session command + 6-field format spec (#114)
## Context
Roadmap **P0.2** from the [2026-04-19 overnight research implementation
roadmap](https://github.com/mojwang/mojwang.tech/blob/main/../../../../../ai/workspace/claude/resources/agentic-research/2026-04-19-implementation-roadmap.md).
Unblocks **P0.3** (\`/grade-session\` retroactive grading) and **P5.1**
(meta-agent) — both need a real log with real rows.
PR #112 shipped documentation for a 5-field cost-log format but never
shipped a writer. This PR ships the writer and extends the format to 6
fields: adds \`agent_sha\` so later analysis can correlate outcomes with
specific agent-prompt versions (P5.1 requirement).
## Format (pipe-separated)
\`\`\`
YYYY-MM-DDTHH:MM:SS | topic | dispatches | models | outcome | agent_sha
\`\`\`
Outcome enum: \`shipped | partial | reverted | blocked | plan-only |
(empty)\`. Empty = "grade later," filled retroactively by
\`/grade-session\` (forthcoming in P0.3).
## Design decisions
- **Slash command + shell script, NOT a Stop hook.** Claude Code's
\`Stop\` hook fires every turn, not session end, so a hook-driven
autolog would misfire on partial turns. One explicit \`/log-session\`
per session is cleaner and gives the user control over
topic/dispatches/models (fields no hook could auto-capture).
- **Timestamp instead of just date** — multiple sessions per day are
common.
- **Auto-captured fields:** timestamp (\`date\`), agent_sha (\`git log\`
on \`.claude/agents/\`).
- **\`--outcome\` sentinel:** \`--outcome \"\"\` explicitly marks
ungraded, skipping the prompt; missing \`--outcome\` prompts
interactively.
- **Pipe-char sanitization:** user fields replace \`|\` with \`;\` so
malformed input doesn't break column parsing.
- **Log file gitignored** — personal state, not a shared artifact.
## Files
- \`scripts/log-session.sh\` — new, executable, \`shellcheck\` clean,
follows \`#!/usr/bin/env bash\` + \`set -euo pipefail\` convention
- \`.claude/commands/log-session.md\` — new slash-command wrapper
- \`docs/CLAUDE_AGENTS.md\` — updated format doc (6 fields, broader
outcome enum, usage example)
- \`.gitignore\` — adds \`scripts/.session-cost.log\`
## Usage
\`\`\`
/log-session --topic \"P0.2 session-logger infra\" --dispatches \"—\"
--models \"sonnet\" --outcome \"shipped\"
\`\`\`
Missing flags prompt interactively.
## Verification
- [x] \`shellcheck scripts/log-session.sh\` — clean
- [x] Happy path: \`--topic … --outcome shipped\` writes a row
- [x] Empty outcome: \`--outcome \"\"\` writes a row with blank 5th
field
- [x] Invalid outcome: \`--outcome bogus\` exits 2 with clear error
- [x] Pipe sanitization: topic containing \`|\` is rewritten as \`;\`
- [x] Gitignored: log file doesn't appear in \`git status\`
## Out of scope (deferred to P0.3)
- \`/grade-session\` retroactive grading (walks ungraded rows)
- \`weekly-review\` command update to surface ungraded sessions
- SessionStart hook nudge (\"N ungraded sessions\")
- Auto-capture of dispatches + models via transcript parsing (Claude
Code doesn't expose transcripts to hooks)1 parent 0c5ac08 commit 4ac6296
4 files changed
Lines changed: 187 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
| 179 | + | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
191 | 192 | | |
192 | | - | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
193 | 201 | | |
194 | 202 | | |
195 | 203 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
0 commit comments