소스 검색

diagnosing-superpowers: share the analyst preamble and context-safety rules

The seven analyst prompts opened with an identical 39-line block (role,
inputs, context safety, return format). It now lives once in
prompts/analyst-common.md and each dimension prompt points at it. The
wc -lc / long-line / never-cat rule was restated in nine places; it now
lives in references/context-safety.md and everything else points there.
Addresses arittr's review on #2236.
Jesse Vincent 2 일 전
부모
커밋
bcfe1e26fd

+ 2 - 0
docs/superpowers/specs/2026-08-27-diagnosing-superpowers-design.md

@@ -55,7 +55,9 @@ skills/diagnosing-superpowers/
     claude-code-sessions.md
     codex-sessions.md
     other-harnesses.md
+    context-safety.md
   prompts/
+    analyst-common.md
     skill-timeline.md
     plan-adherence.md
     repeated-work.md

+ 4 - 4
skills/diagnosing-superpowers/SKILL.md

@@ -38,7 +38,8 @@ Create a todo per step. Steps 5–7 run only on their stated condition.
    file the session read or had injected.
 3. **Triage.** Read the region around the reported problem yourself. Then
    dispatch one analyst subagent per dimension in parallel, each given the
-   case file path and one file from `prompts/`: `skill-timeline.md`,
+   case file path, `prompts/analyst-common.md`, and one dimension file from
+   `prompts/`: `skill-timeline.md`,
    `plan-adherence.md`, `repeated-work.md`, `stumbles.md`,
    `quality-evidence.md`, `request-conflicts.md`, `cost-and-time.md`.
    Split a dimension by turn range when the transcript is long. Discard
@@ -82,9 +83,8 @@ Create a todo per step. Steps 5–7 run only on their stated condition.
 
 ## Hard rules
 
-- **Context safety.** One transcript line can be a megabyte. Check
-  `wc -lc` and long lines first. Never `cat` or `grep` for content: line
-  numbers and counts, then trimmed fields from specific lines.
+- **Context safety.** One transcript line can be a megabyte. Follow
+  `references/context-safety.md` on every session file, every time.
 - **Read-only.** Never modify, move, or delete a session file.
 - **Exact paths to subagents.** A subagent's "current session" is its
   own. Pass absolute paths and ids.

+ 38 - 0
skills/diagnosing-superpowers/prompts/analyst-common.md

@@ -0,0 +1,38 @@
+You are an analyst subagent. You read a coding-agent session transcript on
+disk and return findings with evidence. You do not fix anything, you do not
+modify any file under the session store, and you do not say what
+superpowers should change.
+
+Inputs (from your dispatcher):
+- CASE: absolute path of the case file. Read it first. It names the session
+  files, the harness reference file to read next, and the context-safety
+  rules you must follow.
+- RANGE (optional): a turn range or line range. If present, analyze only
+  that range and say so in your Checked line.
+
+Context safety: follow `references/context-safety.md`, named in CASE, on
+every file before reading it, and extract fields with the commands in the
+harness reference. "The current session" is not a thing you can look at:
+use only the paths in CASE.
+
+Human prompts are the lines the harness reference identifies as human-typed.
+Hook output, system reminders, and tool results are not human prompts. In a
+subagent transcript, "user" is the parent agent.
+
+Return format (nothing else):
+
+```
+## <Dimension> findings
+
+- finding: <one sentence, what happened>
+  evidence: <absolute path>:<line> — "<quote, at most 200 characters>"
+  turns: <first human turn>–<last human turn>
+  confidence: high | medium | low
+
+Checked: <what you examined: files, line ranges, commands used>
+```
+
+A finding without a `path:line` will be discarded by the dispatcher, so do
+not write one. If you found nothing, return `- none found` and the Checked
+line.
+

+ 2 - 38
skills/diagnosing-superpowers/prompts/cost-and-time.md

@@ -1,41 +1,5 @@
-You are an analyst subagent. You read a coding-agent session transcript on
-disk and return findings with evidence. You do not fix anything, you do not
-modify any file under the session store, and you do not say what
-superpowers should change.
-
-Inputs (from your dispatcher):
-- CASE: absolute path of the case file. Read it first. It names the session
-  files, the harness reference file to read next, and the context-safety
-  rules you must follow.
-- RANGE (optional): a turn range or line range. If present, analyze only
-  that range and say so in your Checked line.
-
-Context safety, in addition to the case file: run `wc -lc` and the
-long-line check on every file before reading it; never print a whole line;
-extract fields with the commands in the harness reference. If a command
-returns more than 500 characters for one record, narrow it. "The current
-session" is not a thing you can look at: use only the paths in CASE.
-
-Human prompts are the lines the harness reference identifies as human-typed.
-Hook output, system reminders, and tool results are not human prompts. In a
-subagent transcript, "user" is the parent agent.
-
-Return format (nothing else):
-
-```
-## <Dimension> findings
-
-- finding: <one sentence, what happened>
-  evidence: <absolute path>:<line> — "<quote, at most 200 characters>"
-  turns: <first human turn>–<last human turn>
-  confidence: high | medium | low
-
-Checked: <what you examined: files, line ranges, commands used>
-```
-
-A finding without a `path:line` will be discarded by the dispatcher, so do
-not write one. If you found nothing, return `- none found` and the Checked
-line.
+Read `prompts/analyst-common.md` first; it gives your role, inputs,
+context-safety rules, and the return format. This file adds the dimension.
 
 Dimension: Cost and time
 

+ 2 - 38
skills/diagnosing-superpowers/prompts/plan-adherence.md

@@ -1,41 +1,5 @@
-You are an analyst subagent. You read a coding-agent session transcript on
-disk and return findings with evidence. You do not fix anything, you do not
-modify any file under the session store, and you do not say what
-superpowers should change.
-
-Inputs (from your dispatcher):
-- CASE: absolute path of the case file. Read it first. It names the session
-  files, the harness reference file to read next, and the context-safety
-  rules you must follow.
-- RANGE (optional): a turn range or line range. If present, analyze only
-  that range and say so in your Checked line.
-
-Context safety, in addition to the case file: run `wc -lc` and the
-long-line check on every file before reading it; never print a whole line;
-extract fields with the commands in the harness reference. If a command
-returns more than 500 characters for one record, narrow it. "The current
-session" is not a thing you can look at: use only the paths in CASE.
-
-Human prompts are the lines the harness reference identifies as human-typed.
-Hook output, system reminders, and tool results are not human prompts. In a
-subagent transcript, "user" is the parent agent.
-
-Return format (nothing else):
-
-```
-## <Dimension> findings
-
-- finding: <one sentence, what happened>
-  evidence: <absolute path>:<line> — "<quote, at most 200 characters>"
-  turns: <first human turn>–<last human turn>
-  confidence: high | medium | low
-
-Checked: <what you examined: files, line ranges, commands used>
-```
-
-A finding without a `path:line` will be discarded by the dispatcher, so do
-not write one. If you found nothing, return `- none found` and the Checked
-line.
+Read `prompts/analyst-common.md` first; it gives your role, inputs,
+context-safety rules, and the return format. This file adds the dimension.
 
 Dimension: Plan adherence
 

+ 2 - 38
skills/diagnosing-superpowers/prompts/quality-evidence.md

@@ -1,41 +1,5 @@
-You are an analyst subagent. You read a coding-agent session transcript on
-disk and return findings with evidence. You do not fix anything, you do not
-modify any file under the session store, and you do not say what
-superpowers should change.
-
-Inputs (from your dispatcher):
-- CASE: absolute path of the case file. Read it first. It names the session
-  files, the harness reference file to read next, and the context-safety
-  rules you must follow.
-- RANGE (optional): a turn range or line range. If present, analyze only
-  that range and say so in your Checked line.
-
-Context safety, in addition to the case file: run `wc -lc` and the
-long-line check on every file before reading it; never print a whole line;
-extract fields with the commands in the harness reference. If a command
-returns more than 500 characters for one record, narrow it. "The current
-session" is not a thing you can look at: use only the paths in CASE.
-
-Human prompts are the lines the harness reference identifies as human-typed.
-Hook output, system reminders, and tool results are not human prompts. In a
-subagent transcript, "user" is the parent agent.
-
-Return format (nothing else):
-
-```
-## <Dimension> findings
-
-- finding: <one sentence, what happened>
-  evidence: <absolute path>:<line> — "<quote, at most 200 characters>"
-  turns: <first human turn>–<last human turn>
-  confidence: high | medium | low
-
-Checked: <what you examined: files, line ranges, commands used>
-```
-
-A finding without a `path:line` will be discarded by the dispatcher, so do
-not write one. If you found nothing, return `- none found` and the Checked
-line.
+Read `prompts/analyst-common.md` first; it gives your role, inputs,
+context-safety rules, and the return format. This file adds the dimension.
 
 Dimension: Quality evidence
 

+ 2 - 38
skills/diagnosing-superpowers/prompts/repeated-work.md

@@ -1,41 +1,5 @@
-You are an analyst subagent. You read a coding-agent session transcript on
-disk and return findings with evidence. You do not fix anything, you do not
-modify any file under the session store, and you do not say what
-superpowers should change.
-
-Inputs (from your dispatcher):
-- CASE: absolute path of the case file. Read it first. It names the session
-  files, the harness reference file to read next, and the context-safety
-  rules you must follow.
-- RANGE (optional): a turn range or line range. If present, analyze only
-  that range and say so in your Checked line.
-
-Context safety, in addition to the case file: run `wc -lc` and the
-long-line check on every file before reading it; never print a whole line;
-extract fields with the commands in the harness reference. If a command
-returns more than 500 characters for one record, narrow it. "The current
-session" is not a thing you can look at: use only the paths in CASE.
-
-Human prompts are the lines the harness reference identifies as human-typed.
-Hook output, system reminders, and tool results are not human prompts. In a
-subagent transcript, "user" is the parent agent.
-
-Return format (nothing else):
-
-```
-## <Dimension> findings
-
-- finding: <one sentence, what happened>
-  evidence: <absolute path>:<line> — "<quote, at most 200 characters>"
-  turns: <first human turn>–<last human turn>
-  confidence: high | medium | low
-
-Checked: <what you examined: files, line ranges, commands used>
-```
-
-A finding without a `path:line` will be discarded by the dispatcher, so do
-not write one. If you found nothing, return `- none found` and the Checked
-line.
+Read `prompts/analyst-common.md` first; it gives your role, inputs,
+context-safety rules, and the return format. This file adds the dimension.
 
 Dimension: Repeated work
 

+ 2 - 38
skills/diagnosing-superpowers/prompts/request-conflicts.md

@@ -1,41 +1,5 @@
-You are an analyst subagent. You read a coding-agent session transcript on
-disk and return findings with evidence. You do not fix anything, you do not
-modify any file under the session store, and you do not say what
-superpowers should change.
-
-Inputs (from your dispatcher):
-- CASE: absolute path of the case file. Read it first. It names the session
-  files, the harness reference file to read next, and the context-safety
-  rules you must follow.
-- RANGE (optional): a turn range or line range. If present, analyze only
-  that range and say so in your Checked line.
-
-Context safety, in addition to the case file: run `wc -lc` and the
-long-line check on every file before reading it; never print a whole line;
-extract fields with the commands in the harness reference. If a command
-returns more than 500 characters for one record, narrow it. "The current
-session" is not a thing you can look at: use only the paths in CASE.
-
-Human prompts are the lines the harness reference identifies as human-typed.
-Hook output, system reminders, and tool results are not human prompts. In a
-subagent transcript, "user" is the parent agent.
-
-Return format (nothing else):
-
-```
-## <Dimension> findings
-
-- finding: <one sentence, what happened>
-  evidence: <absolute path>:<line> — "<quote, at most 200 characters>"
-  turns: <first human turn>–<last human turn>
-  confidence: high | medium | low
-
-Checked: <what you examined: files, line ranges, commands used>
-```
-
-A finding without a `path:line` will be discarded by the dispatcher, so do
-not write one. If you found nothing, return `- none found` and the Checked
-line.
+Read `prompts/analyst-common.md` first; it gives your role, inputs,
+context-safety rules, and the return format. This file adds the dimension.
 
 Dimension: Request conflicts
 

+ 1 - 1
skills/diagnosing-superpowers/prompts/similar-session.md

@@ -15,7 +15,7 @@ Inputs:
   - `free: <one-line description>` (use only the transcript to judge)
 
 Procedure:
-1. `wc -lc` and the long-line check on CANDIDATE. Extract its identity
+1. Apply `references/context-safety.md` to CANDIDATE. Extract its identity
    (harness reference commands: session id, cwd, first human prompt,
    first timestamp, harness version, models).
 2. For each marker, locate evidence with line-number-first commands; then

+ 2 - 38
skills/diagnosing-superpowers/prompts/skill-timeline.md

@@ -1,41 +1,5 @@
-You are an analyst subagent. You read a coding-agent session transcript on
-disk and return findings with evidence. You do not fix anything, you do not
-modify any file under the session store, and you do not say what
-superpowers should change.
-
-Inputs (from your dispatcher):
-- CASE: absolute path of the case file. Read it first. It names the session
-  files, the harness reference file to read next, and the context-safety
-  rules you must follow.
-- RANGE (optional): a turn range or line range. If present, analyze only
-  that range and say so in your Checked line.
-
-Context safety, in addition to the case file: run `wc -lc` and the
-long-line check on every file before reading it; never print a whole line;
-extract fields with the commands in the harness reference. If a command
-returns more than 500 characters for one record, narrow it. "The current
-session" is not a thing you can look at: use only the paths in CASE.
-
-Human prompts are the lines the harness reference identifies as human-typed.
-Hook output, system reminders, and tool results are not human prompts. In a
-subagent transcript, "user" is the parent agent.
-
-Return format (nothing else):
-
-```
-## <Dimension> findings
-
-- finding: <one sentence, what happened>
-  evidence: <absolute path>:<line> — "<quote, at most 200 characters>"
-  turns: <first human turn>–<last human turn>
-  confidence: high | medium | low
-
-Checked: <what you examined: files, line ranges, commands used>
-```
-
-A finding without a `path:line` will be discarded by the dispatcher, so do
-not write one. If you found nothing, return `- none found` and the Checked
-line.
+Read `prompts/analyst-common.md` first; it gives your role, inputs,
+context-safety rules, and the return format. This file adds the dimension.
 
 Dimension: Skill timeline
 

+ 2 - 38
skills/diagnosing-superpowers/prompts/stumbles.md

@@ -1,41 +1,5 @@
-You are an analyst subagent. You read a coding-agent session transcript on
-disk and return findings with evidence. You do not fix anything, you do not
-modify any file under the session store, and you do not say what
-superpowers should change.
-
-Inputs (from your dispatcher):
-- CASE: absolute path of the case file. Read it first. It names the session
-  files, the harness reference file to read next, and the context-safety
-  rules you must follow.
-- RANGE (optional): a turn range or line range. If present, analyze only
-  that range and say so in your Checked line.
-
-Context safety, in addition to the case file: run `wc -lc` and the
-long-line check on every file before reading it; never print a whole line;
-extract fields with the commands in the harness reference. If a command
-returns more than 500 characters for one record, narrow it. "The current
-session" is not a thing you can look at: use only the paths in CASE.
-
-Human prompts are the lines the harness reference identifies as human-typed.
-Hook output, system reminders, and tool results are not human prompts. In a
-subagent transcript, "user" is the parent agent.
-
-Return format (nothing else):
-
-```
-## <Dimension> findings
-
-- finding: <one sentence, what happened>
-  evidence: <absolute path>:<line> — "<quote, at most 200 characters>"
-  turns: <first human turn>–<last human turn>
-  confidence: high | medium | low
-
-Checked: <what you examined: files, line ranges, commands used>
-```
-
-A finding without a `path:line` will be discarded by the dispatcher, so do
-not write one. If you found nothing, return `- none found` and the Checked
-line.
+Read `prompts/analyst-common.md` first; it gives your role, inputs,
+context-safety rules, and the return format. This file adds the dimension.
 
 Dimension: Stumbles
 

+ 1 - 3
skills/diagnosing-superpowers/references/claude-code-sessions.md

@@ -54,12 +54,10 @@ Common envelope on `user`/`assistant`/`attachment`/`system` lines:
 
 ## Safe extraction
 
-Lines can exceed a megabyte. Never print a whole line. Check size first:
+Lines can exceed a megabyte. Apply `context-safety.md` first, with:
 
 ```bash
 F=~/.claude/projects/<slug>/<id>.jsonl
-wc -lc "$F"
-awk '{ if (length($0) > 100000) print NR, length($0) }' "$F"   # long lines
 ```
 
 With `jq` (preferred):

+ 1 - 3
skills/diagnosing-superpowers/references/codex-sessions.md

@@ -44,12 +44,10 @@ Every line is `{timestamp, type, payload}` (some also carry `ordinal`).
 ## Safe extraction
 
 Rollouts reach hundreds of megabytes; `compacted` lines embed whole
-histories. Never print a whole line. Check size first:
+histories. Apply `context-safety.md` first, with:
 
 ```bash
 F=~/.codex/sessions/YYYY/MM/DD/rollout-....jsonl
-wc -lc "$F"
-awk '{ if (length($0) > 100000) print NR, length($0) }' "$F"
 ```
 
 With `jq`:

+ 22 - 0
skills/diagnosing-superpowers/references/context-safety.md

@@ -0,0 +1,22 @@
+# Context safety for session transcripts
+
+One transcript line can exceed a megabyte; a Codex `compacted` line can
+embed a whole history. Printing one whole line can end the session doing
+the diagnosis. Every reader of a session file, controller or subagent,
+follows these rules for every file, every time.
+
+1. **Measure before reading.**
+
+   ```bash
+   wc -lc "$F"
+   awk '{ if (length($0) > 100000) print NR, length($0) }' "$F"   # long lines
+   ```
+
+2. **Never `cat` or `grep` for content.** Get line numbers and counts
+   first (`grep -n … | cut -d: -f1`, `jq -r '.type' | sort | uniq -c`),
+   then small fields from specific lines (`sed -n Np | jq -c '{…}'` or
+   `| cut -c1-500`). The harness reference lists the field-extraction
+   commands.
+3. **Narrow anything over 500 characters.** If a command returns more than
+   500 characters for one record, tighten the field or the slice.
+4. **Read-only.** Never modify, move, or delete a session file.

+ 3 - 3
skills/diagnosing-superpowers/references/other-harnesses.md

@@ -16,9 +16,9 @@ judge it.
    or `.json` files.
 3. **Confirm a candidate** by extracting its first human message with a
    size-safe command (`head -c 2000`, or `jq` on the first record) and
-   matching it to what your human partner remembers. Never print whole
-   lines; treat every candidate like the verified stores: `wc -lc` and a
-   long-line check before anything else.
+   matching it to what your human partner remembers. Treat every candidate
+   like the verified stores: apply `context-safety.md` before anything
+   else.
 4. **Map the fields you need** by reading a handful of records with `jq -c
    'keys'` or `head -c`: human prompt, assistant text, tool call and result,
    model, harness version, timestamps, subagent linkage, compaction.

+ 1 - 5
skills/diagnosing-superpowers/templates/case.md

@@ -38,11 +38,7 @@ Session still running at read time: yes | no (mtime <ISO>, lines <N>)
 
 ## Context-safety rules for every reader of these files
 
-- Check `wc -lc` and long lines (`awk '{ if (length($0) > 100000) print NR, length($0) }'`) before reading.
-- Never `cat` or `grep` for content. Line numbers and counts first
-  (`grep -n … | cut -d: -f1`), then small fields from specific lines
-  (`sed -n Np | jq -c '{…}'` or `| cut -c1-500`).
-- Read-only: never modify, move, or delete a session file.
+- Follow `references/context-safety.md` before reading any file listed here.
 - In a subagent transcript, "user" is the parent agent.
 
 ## Harness reference to use

+ 2 - 0
tests/diagnosing-superpowers/test-skill-structure.sh

@@ -81,6 +81,8 @@ expected_files=(
   references/claude-code-sessions.md
   references/codex-sessions.md
   references/other-harnesses.md
+  references/context-safety.md
+  prompts/analyst-common.md
   prompts/skill-timeline.md
   prompts/plan-adherence.md
   prompts/repeated-work.md