@jiroamato/pstack 0.0.0-stage → 0.16.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.
- package/LICENSE +21 -0
- package/README.md +79 -2
- package/bin/pstack.js +95 -0
- package/lib/install.js +121 -0
- package/lib/prompt.js +77 -0
- package/lib/targets.js +43 -0
- package/package.json +38 -5
- package/pstack/.claude-plugin/plugin.json +26 -0
- package/pstack/.codex-plugin/plugin.json +36 -0
- package/pstack/LICENSE +21 -0
- package/pstack/LICENSE-cursor-team-kit +21 -0
- package/pstack/NOTICE +8 -0
- package/pstack/README.md +307 -0
- package/pstack/agents/comment-sicko.md +34 -0
- package/pstack/agents/poteto-agent.md +10 -0
- package/pstack/automations/benny/FOR_AGENTS.md +92 -0
- package/pstack/automations/benny/README.md +28 -0
- package/pstack/automations/benny/skills/reproduce-and-fix-issues/SKILL.md +313 -0
- package/pstack/automations/benny/skills/reproduce-and-fix-issues/references/control-adapter.md +169 -0
- package/pstack/automations/benny/skills/reproduce-and-fix-issues/references/feature-map.example.md +205 -0
- package/pstack/automations/benny/skills/reproduce-and-fix-issues/references/verify-existing-fix.md +93 -0
- package/pstack/automations/benny/skills/setup-benny/SKILL.md +271 -0
- package/pstack/automations/benny/skills/triage-issue-reports/SKILL.md +240 -0
- package/pstack/automations/benny/skills/triage-issue-reports/references/routing.example.md +61 -0
- package/pstack/automations/benny/templates/configuration.example.yaml +84 -0
- package/pstack/automations/benny/templates/reproduce-automation-prompt.md +33 -0
- package/pstack/automations/benny/templates/triage-automation-prompt.md +39 -0
- package/pstack/codex/agents/comment-sicko.toml +36 -0
- package/pstack/codex/agents/poteto-agent.toml +11 -0
- package/pstack/docs/guide/01-setup.md +80 -0
- package/pstack/docs/guide/02-poteto-mode.md +131 -0
- package/pstack/docs/guide/03-understand.md +79 -0
- package/pstack/docs/guide/04-design.md +133 -0
- package/pstack/docs/guide/05-build-and-clean.md +83 -0
- package/pstack/docs/guide/06-verify-and-ship.md +130 -0
- package/pstack/docs/guide/07-overnight.md +120 -0
- package/pstack/docs/guide/08-principles.md +72 -0
- package/pstack/docs/guide/09-make-it-yours.md +100 -0
- package/pstack/docs/guide/10-recipes-and-pitfalls.md +156 -0
- package/pstack/docs/guide/README.md +38 -0
- package/pstack/skills/architect/SKILL.md +85 -0
- package/pstack/skills/architect/agents/openai.yaml +2 -0
- package/pstack/skills/architect/references/design-red-flags.md +57 -0
- package/pstack/skills/architect/references/rationale-template.md +35 -0
- package/pstack/skills/architect/references/runner-prompt.md +20 -0
- package/pstack/skills/arena/SKILL.md +75 -0
- package/pstack/skills/arena/agents/openai.yaml +2 -0
- package/pstack/skills/automate-me/SKILL.md +104 -0
- package/pstack/skills/automate-me/agents/openai.yaml +2 -0
- package/pstack/skills/benchmark-checklist/SKILL.md +39 -0
- package/pstack/skills/benchmark-checklist/agents/openai.yaml +2 -0
- package/pstack/skills/blast-radius/SKILL.md +52 -0
- package/pstack/skills/blast-radius/agents/openai.yaml +2 -0
- package/pstack/skills/bro/SKILL.md +7 -0
- package/pstack/skills/bro/agents/openai.yaml +2 -0
- package/pstack/skills/control-cli/SKILL.md +55 -0
- package/pstack/skills/control-cli/agents/openai.yaml +2 -0
- package/pstack/skills/control-ui/SKILL.md +72 -0
- package/pstack/skills/control-ui/agents/openai.yaml +2 -0
- package/pstack/skills/correct/SKILL.md +34 -0
- package/pstack/skills/correct/agents/openai.yaml +2 -0
- package/pstack/skills/create-verification-skill/SKILL.md +47 -0
- package/pstack/skills/create-verification-skill/agents/openai.yaml +2 -0
- package/pstack/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
- package/pstack/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
- package/pstack/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
- package/pstack/skills/deslop/SKILL.md +30 -0
- package/pstack/skills/deslop/agents/openai.yaml +2 -0
- package/pstack/skills/figure-it-out/SKILL.md +55 -0
- package/pstack/skills/figure-it-out/agents/openai.yaml +2 -0
- package/pstack/skills/how/SKILL.md +58 -0
- package/pstack/skills/how/agents/openai.yaml +2 -0
- package/pstack/skills/how/references/explainer-prompt.md +55 -0
- package/pstack/skills/how/references/explorer-prompt.md +52 -0
- package/pstack/skills/interrogate/SKILL.md +111 -0
- package/pstack/skills/interrogate/agents/openai.yaml +2 -0
- package/pstack/skills/interrogate/references/code-quality-review.md +47 -0
- package/pstack/skills/interrogate/references/lead-judgment.md +58 -0
- package/pstack/skills/interrogate/references/reviewer-prompt.md +70 -0
- package/pstack/skills/interrogate/references/rubric.md +77 -0
- package/pstack/skills/kiss/SKILL.md +90 -0
- package/pstack/skills/kiss/agents/openai.yaml +2 -0
- package/pstack/skills/kiss/references/assess.md +110 -0
- package/pstack/skills/kiss/references/principles.md +138 -0
- package/pstack/skills/maintain-verification-skill/SKILL.md +41 -0
- package/pstack/skills/maintain-verification-skill/agents/openai.yaml +2 -0
- package/pstack/skills/make-bot-ui/SKILL.md +289 -0
- package/pstack/skills/make-bot-ui/agents/openai.yaml +2 -0
- package/pstack/skills/no-comments/SKILL.md +24 -0
- package/pstack/skills/no-comments/agents/openai.yaml +2 -0
- package/pstack/skills/poteto-help/SKILL.md +156 -0
- package/pstack/skills/poteto-help/agents/openai.yaml +2 -0
- package/pstack/skills/poteto-help/references/prompting.md +51 -0
- package/pstack/skills/poteto-help/references/recipes.md +47 -0
- package/pstack/skills/poteto-mode/SKILL.md +143 -0
- package/pstack/skills/poteto-mode/agents/openai.yaml +2 -0
- package/pstack/skills/poteto-mode/playbooks/authoring-a-skill.md +12 -0
- package/pstack/skills/poteto-mode/playbooks/autonomous-run.md +13 -0
- package/pstack/skills/poteto-mode/playbooks/autopilot-full.md +13 -0
- package/pstack/skills/poteto-mode/playbooks/autopilot-stack.md +16 -0
- package/pstack/skills/poteto-mode/playbooks/babysit.md +29 -0
- package/pstack/skills/poteto-mode/playbooks/bug-fix.md +15 -0
- package/pstack/skills/poteto-mode/playbooks/eval.md +25 -0
- package/pstack/skills/poteto-mode/playbooks/feature.md +21 -0
- package/pstack/skills/poteto-mode/playbooks/hillclimb.md +21 -0
- package/pstack/skills/poteto-mode/playbooks/investigation.md +14 -0
- package/pstack/skills/poteto-mode/playbooks/multi-phase-plan.md +155 -0
- package/pstack/skills/poteto-mode/playbooks/opening-a-pr.md +38 -0
- package/pstack/skills/poteto-mode/playbooks/orchestrate.md +114 -0
- package/pstack/skills/poteto-mode/playbooks/pause-safely.md +10 -0
- package/pstack/skills/poteto-mode/playbooks/perf-issue.md +25 -0
- package/pstack/skills/poteto-mode/playbooks/prototype.md +14 -0
- package/pstack/skills/poteto-mode/playbooks/refactoring.md +16 -0
- package/pstack/skills/poteto-mode/playbooks/runtime-forensics.md +11 -0
- package/pstack/skills/poteto-mode/playbooks/session-pickup.md +11 -0
- package/pstack/skills/poteto-mode/playbooks/shipping.md +17 -0
- package/pstack/skills/poteto-mode/playbooks/trace-forensics.md +14 -0
- package/pstack/skills/poteto-mode/playbooks/visual-parity.md +11 -0
- package/pstack/skills/poteto-mode/playbooks/worktree-cleanup.md +14 -0
- package/pstack/skills/poteto-mode/references/bugbot-triage.md +142 -0
- package/pstack/skills/poteto-mode/scripts/bootstrap.ts +62 -0
- package/pstack/skills/poteto-mode/scripts/bun.lock +67 -0
- package/pstack/skills/poteto-mode/scripts/check-plan.mjs +185 -0
- package/pstack/skills/poteto-mode/scripts/orch/orch.test.ts +634 -0
- package/pstack/skills/poteto-mode/scripts/orch/orch.ts +578 -0
- package/pstack/skills/poteto-mode/scripts/orch/store.ts +1607 -0
- package/pstack/skills/poteto-mode/scripts/package.json +16 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/cli.test.ts +224 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/cli.ts +223 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/fakes.test-helper.ts +118 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/github.test.ts +306 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/github.ts +699 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/policy.test.ts +420 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/policy.ts +832 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/render.ts +169 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/tsconfig.json +13 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/types.compile.ts +93 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/types.ts +401 -0
- package/pstack/skills/poteto-mode/scripts/watch-pr/watch-pr +6 -0
- package/pstack/skills/poteto-mode/scripts/worktree-audit.sh +92 -0
- package/pstack/skills/principle-attack-the-premise/SKILL.md +23 -0
- package/pstack/skills/principle-attack-the-premise/agents/openai.yaml +2 -0
- package/pstack/skills/principle-boundary-discipline/SKILL.md +34 -0
- package/pstack/skills/principle-boundary-discipline/agents/openai.yaml +2 -0
- package/pstack/skills/principle-build-the-lever/SKILL.md +23 -0
- package/pstack/skills/principle-build-the-lever/agents/openai.yaml +2 -0
- package/pstack/skills/principle-encode-lessons-in-structure/SKILL.md +31 -0
- package/pstack/skills/principle-encode-lessons-in-structure/agents/openai.yaml +2 -0
- package/pstack/skills/principle-exhaust-the-design-space/SKILL.md +21 -0
- package/pstack/skills/principle-exhaust-the-design-space/agents/openai.yaml +2 -0
- package/pstack/skills/principle-experience-first/SKILL.md +19 -0
- package/pstack/skills/principle-experience-first/agents/openai.yaml +2 -0
- package/pstack/skills/principle-explain-the-number/SKILL.md +23 -0
- package/pstack/skills/principle-explain-the-number/agents/openai.yaml +2 -0
- package/pstack/skills/principle-fix-root-causes/SKILL.md +23 -0
- package/pstack/skills/principle-fix-root-causes/agents/openai.yaml +2 -0
- package/pstack/skills/principle-foundational-thinking/SKILL.md +21 -0
- package/pstack/skills/principle-foundational-thinking/agents/openai.yaml +2 -0
- package/pstack/skills/principle-guard-the-context-window/SKILL.md +16 -0
- package/pstack/skills/principle-guard-the-context-window/agents/openai.yaml +2 -0
- package/pstack/skills/principle-laziness-protocol/SKILL.md +18 -0
- package/pstack/skills/principle-laziness-protocol/agents/openai.yaml +2 -0
- package/pstack/skills/principle-make-operations-idempotent/SKILL.md +24 -0
- package/pstack/skills/principle-make-operations-idempotent/agents/openai.yaml +2 -0
- package/pstack/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +22 -0
- package/pstack/skills/principle-migrate-callers-then-delete-legacy-apis/agents/openai.yaml +2 -0
- package/pstack/skills/principle-minimize-reader-load/SKILL.md +23 -0
- package/pstack/skills/principle-minimize-reader-load/agents/openai.yaml +2 -0
- package/pstack/skills/principle-model-the-domain/SKILL.md +26 -0
- package/pstack/skills/principle-model-the-domain/agents/openai.yaml +2 -0
- package/pstack/skills/principle-never-block-on-the-human/SKILL.md +20 -0
- package/pstack/skills/principle-never-block-on-the-human/agents/openai.yaml +2 -0
- package/pstack/skills/principle-outcome-oriented-execution/SKILL.md +21 -0
- package/pstack/skills/principle-outcome-oriented-execution/agents/openai.yaml +2 -0
- package/pstack/skills/principle-prove-it-works/SKILL.md +22 -0
- package/pstack/skills/principle-prove-it-works/agents/openai.yaml +2 -0
- package/pstack/skills/principle-redesign-from-first-principles/SKILL.md +16 -0
- package/pstack/skills/principle-redesign-from-first-principles/agents/openai.yaml +2 -0
- package/pstack/skills/principle-separate-before-serializing-shared-state/SKILL.md +16 -0
- package/pstack/skills/principle-separate-before-serializing-shared-state/agents/openai.yaml +2 -0
- package/pstack/skills/principle-sequence-verifiable-units/SKILL.md +17 -0
- package/pstack/skills/principle-sequence-verifiable-units/agents/openai.yaml +2 -0
- package/pstack/skills/principle-subtract-before-you-add/SKILL.md +21 -0
- package/pstack/skills/principle-subtract-before-you-add/agents/openai.yaml +2 -0
- package/pstack/skills/principle-test-behavior-not-implementation/SKILL.md +25 -0
- package/pstack/skills/principle-test-behavior-not-implementation/agents/openai.yaml +2 -0
- package/pstack/skills/principle-type-system-discipline/SKILL.md +31 -0
- package/pstack/skills/principle-type-system-discipline/agents/openai.yaml +2 -0
- package/pstack/skills/pstack-harness/SKILL.md +67 -0
- package/pstack/skills/recall/SKILL.md +35 -0
- package/pstack/skills/recall/agents/openai.yaml +2 -0
- package/pstack/skills/reflect/SKILL.md +76 -0
- package/pstack/skills/reflect/agents/openai.yaml +2 -0
- package/pstack/skills/reflect/references/divergent-reviewer.md +43 -0
- package/pstack/skills/reflect/references/judgment-reviewer.md +42 -0
- package/pstack/skills/reflect/references/synthesizer.md +56 -0
- package/pstack/skills/reflect/references/tooling-reviewer.md +55 -0
- package/pstack/skills/setup-pstack/SKILL.md +110 -0
- package/pstack/skills/show-me-your-work/SKILL.md +82 -0
- package/pstack/skills/show-me-your-work/agents/openai.yaml +2 -0
- package/pstack/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
- package/pstack/skills/show-me-your-work/scripts/log.sh +42 -0
- package/pstack/skills/swarm/SKILL.md +48 -0
- package/pstack/skills/swarm/agents/openai.yaml +2 -0
- package/pstack/skills/tdd/SKILL.md +44 -0
- package/pstack/skills/tdd/agents/openai.yaml +2 -0
- package/pstack/skills/teach/SKILL.md +21 -0
- package/pstack/skills/teach/agents/openai.yaml +2 -0
- package/pstack/skills/technical-writing/SKILL.md +106 -0
- package/pstack/skills/technical-writing/agents/openai.yaml +2 -0
- package/pstack/skills/typescript-best-practices/SKILL.md +31 -0
- package/pstack/skills/typescript-best-practices/agents/openai.yaml +2 -0
- package/pstack/skills/typescript-best-practices/references/patterns.md +324 -0
- package/pstack/skills/unslop/SKILL.md +67 -0
- package/pstack/skills/unslop/agents/openai.yaml +2 -0
- package/pstack/skills/why/SKILL.md +158 -0
- package/pstack/skills/why/agents/openai.yaml +2 -0
- package/pstack/skills/why/references/epistemics.md +144 -0
- package/pstack/skills/why/references/investigator-prompt.md +103 -0
- package/pstack/skills/why/references/source-playbook.md +17 -0
- package/pstack/skills/why/references/sources/code-archaeology.md +88 -0
- package/pstack/skills/why/references/sources/databricks.md +70 -0
- package/pstack/skills/why/references/sources/datadog.md +99 -0
- package/pstack/skills/why/references/sources/incident-postmortem.md +15 -0
- package/pstack/skills/why/references/sources/linear.md +48 -0
- package/pstack/skills/why/references/sources/notion.md +55 -0
- package/pstack/skills/why/references/sources/sentry.md +100 -0
- package/pstack/skills/why/references/sources/slack.md +54 -0
- package/pstack/skills/why/references/synthesizer-prompt.md +135 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
# TypeScript patterns
|
|
2
|
+
|
|
3
|
+
Code examples for each rule in `SKILL.md`. The underlying principles are language-agnostic. See the **type-system-discipline** and **boundary-discipline** principle skills.
|
|
4
|
+
|
|
5
|
+
## Branded types
|
|
6
|
+
|
|
7
|
+
Brand primitives so they can't be mixed up. Validate once at the boundary. Downstream code trusts the type.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
type AgentId = string & { readonly __brand: "AgentId" };
|
|
11
|
+
|
|
12
|
+
function parseAgentId(input: string): AgentId {
|
|
13
|
+
if (!isUUID(input)) throw new Error(`Invalid agent id: ${input}`);
|
|
14
|
+
return input as AgentId;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function focusAgent(id: AgentId): void {
|
|
18
|
+
/* input is trusted */
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Match the `readonly __brand: 'X'` shape. Don't invent a new convention.
|
|
23
|
+
|
|
24
|
+
## Discriminated unions
|
|
25
|
+
|
|
26
|
+
Model variants with a literal discriminant. Every variant shares the field name and each variant's value is unique, so impossible combos can't be represented.
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// Don't. Boolean + optionals lets contradictory states exist.
|
|
30
|
+
type DiffState = { loading: boolean; diff?: GitDiff; error?: string };
|
|
31
|
+
|
|
32
|
+
// Do. Only valid states exist.
|
|
33
|
+
type DiffState =
|
|
34
|
+
| { kind: "loading" }
|
|
35
|
+
| { kind: "ready"; diff: GitDiff }
|
|
36
|
+
| { kind: "error"; error: string };
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Pick one discriminant name (`kind`, `type`, `tag`) and stick to it.
|
|
40
|
+
|
|
41
|
+
## Constructive modeling
|
|
42
|
+
|
|
43
|
+
Build the type from parts that are all legal instead of restricting a loose type with runtime checks.
|
|
44
|
+
|
|
45
|
+
Non-empty, via a variadic tuple:
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
type NonEmpty<T> = [T, ...T[]];
|
|
49
|
+
|
|
50
|
+
// Don't: T[] plus a length check every caller must repeat
|
|
51
|
+
function pickWinner(entries: string[]): string {
|
|
52
|
+
if (entries.length === 0) throw new Error("no entries");
|
|
53
|
+
return entries[Math.floor(Math.random() * entries.length)];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Do: an empty value of the type can't exist
|
|
57
|
+
function pickWinner(entries: NonEmpty<string>): string {
|
|
58
|
+
return entries[Math.floor(Math.random() * entries.length)];
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Where a plain `T[]` arrives, narrow once with a guard. The fact then travels in the type:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const isNonEmpty = <T>(arr: T[]): arr is NonEmpty<T> => arr.length > 0;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Even length, as pairs:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
type Pairs<T> = [T, T][];
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
A time range, as start plus duration:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// Don't: a comment holds the invariant
|
|
78
|
+
type TimeRange = { start: Date; end: Date }; // start <= end
|
|
79
|
+
|
|
80
|
+
// Do: a negative range can't be written; derive end when needed
|
|
81
|
+
type TimeRange = { start: Date; durationMs: number };
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Keep `durationMs` a plain number. Brand it (per Branded types) only if a raw number could be passed where a duration is expected, not by reflex. Pick the representation that makes the bad state unconstructable, then expose the reading you need on top (`pairs.flat()`, a `rangeEnd()` helper).
|
|
85
|
+
|
|
86
|
+
## Simplest total type
|
|
87
|
+
|
|
88
|
+
Don't strengthen everything. Keep `T[]` when every operation on it is total:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
const sum = (xs: number[]) => xs.reduce((a, b) => a + b, 0); // [] is 0, fine
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Strengthen when the loose type forces a lie at a use site. The tells are `!`, `arr[0] as T`, and a "should never happen" throw:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
// Don't: partiality smuggled past the compiler
|
|
98
|
+
function newestSession(sessions: Session[]): Session {
|
|
99
|
+
return sessions.at(0)!;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Do: strengthen the input; the assertion disappears
|
|
103
|
+
function newestSession(sessions: NonEmpty<Session>): Session {
|
|
104
|
+
return sessions[0];
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Weakening the result to `Session | undefined` is the other total signature.
|
|
109
|
+
|
|
110
|
+
## `unknown` over `any`
|
|
111
|
+
|
|
112
|
+
External data is always `unknown`. Narrow before use.
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
// Don't
|
|
116
|
+
function handle(input: any) {
|
|
117
|
+
return input.foo.bar;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Do
|
|
121
|
+
function handle(input: unknown) {
|
|
122
|
+
if (typeof input === "object" && input !== null && "foo" in input) {
|
|
123
|
+
// narrowed; compiler verifies access
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
External sources include RPC payloads, `JSON.parse`, `postMessage`, IPC, file contents, environment variables, database results.
|
|
129
|
+
|
|
130
|
+
## Schemas before hand-rolled guards
|
|
131
|
+
|
|
132
|
+
Before writing a property-by-property type guard for external data, look for the repository's runtime schema library and existing schemas. Let one schema own validation and derive the TypeScript type from it. Do not maintain a schema, a duplicate interface, and a guard that can drift apart.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { z } from "zod";
|
|
136
|
+
|
|
137
|
+
const UserSchema = z.object({
|
|
138
|
+
id: z.string().uuid(),
|
|
139
|
+
role: z.enum(["admin", "member"]),
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
type User = z.infer<typeof UserSchema>;
|
|
143
|
+
|
|
144
|
+
function parseUser(input: unknown): User {
|
|
145
|
+
return UserSchema.parse(input);
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Use `safeParse` when failure is an expected branch. Use the equivalent inference helper when the repository uses another schema library. Do not add a new schema dependency for one guard. This rule prefers the schema system the codebase already trusts.
|
|
150
|
+
|
|
151
|
+
## No `as` casts
|
|
152
|
+
|
|
153
|
+
Every `as` is a potential runtime crash. Cast only after the type system has verified the claim.
|
|
154
|
+
|
|
155
|
+
```ts
|
|
156
|
+
import { z } from "zod";
|
|
157
|
+
|
|
158
|
+
// Don't
|
|
159
|
+
const user = data as User;
|
|
160
|
+
|
|
161
|
+
// Don't
|
|
162
|
+
function isUser(data: unknown): data is User {
|
|
163
|
+
return typeof data === "object" && data !== null && "id" in data;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Do
|
|
167
|
+
const userSchema = z.object({ id: z.string(), name: z.string() });
|
|
168
|
+
type User = z.infer<typeof userSchema>;
|
|
169
|
+
|
|
170
|
+
function parseUser(data: unknown): User {
|
|
171
|
+
return userSchema.parse(data);
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
When the type comes first, annotate the validator with the type it proves. The compiler then rejects a validator that proves less than the type. Remove `name` from the object below and the assignment fails to compile.
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
type User = { id: string; name: string };
|
|
179
|
+
|
|
180
|
+
const userSchema: z.ZodType<User> = z.object({ id: z.string(), name: z.string() });
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
When refactoring an `as` out of existing code, identify why TypeScript can't infer:
|
|
184
|
+
|
|
185
|
+
- Missing discriminant: add one, switch to a discriminated union.
|
|
186
|
+
- Overly wide source type (e.g. `Record<string, unknown>`): narrow it.
|
|
187
|
+
- Untyped boundary: parse with the schema that owns the shape. Add a schema only where none exists.
|
|
188
|
+
- Genuinely inexpressible: use a branded type or `satisfies`.
|
|
189
|
+
|
|
190
|
+
## Narrowing hierarchy
|
|
191
|
+
|
|
192
|
+
From best to last-resort:
|
|
193
|
+
|
|
194
|
+
1. **Discriminated union switch / if.** Compiler narrows automatically.
|
|
195
|
+
2. **`in` operator.** `"key" in obj` narrows to variants containing that key.
|
|
196
|
+
3. **`typeof` / `instanceof`.** For primitives and class instances.
|
|
197
|
+
4. **User-defined type guard.** When the above aren't enough.
|
|
198
|
+
5. **`as` cast.** Only after validation.
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
function area(s: Shape): number {
|
|
202
|
+
if ("radius" in s) return Math.PI * s.radius ** 2; // narrowed to circle
|
|
203
|
+
return s.width * s.height; // narrowed to rect
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Type guards
|
|
208
|
+
|
|
209
|
+
A guard must actually verify the claim. A lying guard is worse than `as`.
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
function isCircle(s: Shape): s is Shape & { kind: "circle" } {
|
|
213
|
+
return s.kind === "circle";
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Prefer discriminant narrowing when possible.
|
|
218
|
+
|
|
219
|
+
## Exhaustiveness
|
|
220
|
+
|
|
221
|
+
In default arms, assign the discriminant to a `never`-typed local.
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
// Value-returning switch
|
|
225
|
+
function area(s: Shape): number {
|
|
226
|
+
switch (s.kind) {
|
|
227
|
+
case "circle":
|
|
228
|
+
return Math.PI * s.radius ** 2;
|
|
229
|
+
case "rect":
|
|
230
|
+
return s.width * s.height;
|
|
231
|
+
default: {
|
|
232
|
+
const _exhaustive: never = s;
|
|
233
|
+
return _exhaustive;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Void switch
|
|
239
|
+
function handle(s: Shape): void {
|
|
240
|
+
switch (s.kind) {
|
|
241
|
+
case "circle":
|
|
242
|
+
drawCircle(s);
|
|
243
|
+
break;
|
|
244
|
+
case "rect":
|
|
245
|
+
drawRect(s);
|
|
246
|
+
break;
|
|
247
|
+
default: {
|
|
248
|
+
const _exhaustive: never = s;
|
|
249
|
+
void _exhaustive;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Return-style in value-returning switches, void-style in statement switches.
|
|
256
|
+
|
|
257
|
+
## `satisfies` over `as`
|
|
258
|
+
|
|
259
|
+
`satisfies` validates without widening literal types.
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
// Don't. Widens, loses literal types.
|
|
263
|
+
const config = { theme: "dark", cols: 3 } as Config;
|
|
264
|
+
|
|
265
|
+
// Do. Validates AND preserves literal types.
|
|
266
|
+
const config = { theme: "dark", cols: 3 } satisfies Config;
|
|
267
|
+
// config.theme is "dark" (literal), not string
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Boundary validation
|
|
271
|
+
|
|
272
|
+
Validate once where data crosses in. Trust types inside. See the **boundary-discipline** principle skill.
|
|
273
|
+
|
|
274
|
+
- **Wire formats** (proto, JSON-RPC): parse with `ignoreUnknownFields` so forward-compatible changes don't break old clients.
|
|
275
|
+
- **Persisted JSON:** versioned blob with a try/catch around the parse.
|
|
276
|
+
- **Don't re-validate** deep in call chains.
|
|
277
|
+
|
|
278
|
+
## Schema-derived types
|
|
279
|
+
|
|
280
|
+
When a `.proto`, OpenAPI spec, GraphQL schema, or database migration already defines a shape, derive from the generated types instead of duplicating them.
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
// Don't. Duplicate shape, drifts when the schema changes.
|
|
284
|
+
type CheckSummary = {
|
|
285
|
+
totalCount: number;
|
|
286
|
+
checks: { name: string; status: string }[];
|
|
287
|
+
};
|
|
288
|
+
function renderChecks(s: CheckSummary) {
|
|
289
|
+
/* ... */
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Do. Derive from the generated schema type.
|
|
293
|
+
import type { ChecksMessage } from "<generated module>";
|
|
294
|
+
function renderChecks(s: Pick<ChecksMessage, "totalCount" | "checks">) {
|
|
295
|
+
/* ... */
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
Reach for `Pick`, `Omit`, `Parameters`, `ReturnType`, `Awaited`, `typeof` before writing a new interface.
|
|
300
|
+
|
|
301
|
+
## Object args
|
|
302
|
+
|
|
303
|
+
```ts
|
|
304
|
+
// Don't. Swap two args, still compiles.
|
|
305
|
+
openFile(uri, {
|
|
306
|
+
startLineNumber: 10,
|
|
307
|
+
startColumn: 1,
|
|
308
|
+
endLineNumber: 10,
|
|
309
|
+
endColumn: 1,
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
// Do. Order-independent, self-documenting.
|
|
313
|
+
openFile({
|
|
314
|
+
uri,
|
|
315
|
+
selection: {
|
|
316
|
+
startLineNumber: 10,
|
|
317
|
+
startColumn: 1,
|
|
318
|
+
endLineNumber: 10,
|
|
319
|
+
endColumn: 1,
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Skip on hot paths: per-frame render, tokenizers, parsers, anything in a tight loop where the allocation cost matters.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: unslop
|
|
3
|
+
description: Cut AI tells from any writing. Must always apply.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Unslop
|
|
8
|
+
|
|
9
|
+
Edit text to remove AI patterns.
|
|
10
|
+
|
|
11
|
+
## Process
|
|
12
|
+
|
|
13
|
+
1. Scan for the patterns below.
|
|
14
|
+
2. Rewrite. Preserve meaning, match intended tone.
|
|
15
|
+
|
|
16
|
+
## Patterns to detect and fix
|
|
17
|
+
|
|
18
|
+
Rule numbers are stable ids that other skills cite. A removed rule leaves a gap.
|
|
19
|
+
|
|
20
|
+
### Content
|
|
21
|
+
|
|
22
|
+
3. **Superficial -ing phrases.** "highlighting...", "ensuring...", "reflecting...", "showcasing...", "fostering...". Delete or expand with real sources.
|
|
23
|
+
5. **Vague attributions.** "Experts believe", "Industry reports suggest", "Some critics argue". Name the source or delete.
|
|
24
|
+
|
|
25
|
+
### Language
|
|
26
|
+
|
|
27
|
+
7. **AI vocabulary.** Additionally, crucial, delve, enduring, enhance, fostering, garner, interplay, intricate, landscape (abstract), pivotal, showcase, tapestry (abstract), testament, underscore, vibrant. Replace with plain words.
|
|
28
|
+
8. **Fancy ways to say "is".** "serves as", "stands as", "boasts", "features". Just say "is" or "has".
|
|
29
|
+
9. **"Not just X, but Y."** State the point directly instead.
|
|
30
|
+
10. **Rule of three.** Forcing ideas into groups of three. Use the natural number.
|
|
31
|
+
11. **Synonym cycling.** Protagonist, main character, central figure, hero all in one paragraph. Pick one, repeat it.
|
|
32
|
+
12. **False ranges.** "from X to Y" where X and Y aren't on a meaningful scale. List topics directly.
|
|
33
|
+
|
|
34
|
+
### Style
|
|
35
|
+
|
|
36
|
+
13. **Em dash overuse.** Avoid em dashes entirely. Use periods or commas only (no parentheses, no en dashes, no hyphen-as-dash substitutes). If a thought needs separation, end the sentence or use a comma.
|
|
37
|
+
14. **Colon overuse.** Colons are fine before a list or example. Not as mid-sentence connectors. "If you're coming from traditional automation: instead of registering event handlers, you describe conditions" adds nothing with the colon. Rewrite to let the point stand on its own without comparison framing. "Describing when the scheduler should fire works best as plain English." Same meaning, no crutch punctuation.
|
|
38
|
+
15. **Boldface overuse.** Don't bold every proper noun or acronym.
|
|
39
|
+
16. **Inline-header lists.** The tell is a bold label and colon that restates the line: "**Performance:** Performance improved...". Convert those to prose. A bold lead-in that ends in a period, names the item, and is followed by genuinely new detail ("**Schema in TypeScript.** Tables live in one file.") is fine, not a tell.
|
|
40
|
+
17. **Title case headings.** Use sentence case.
|
|
41
|
+
18. **Decorative emojis.** Remove from headings and bullets.
|
|
42
|
+
19. **Curly quotes.** Replace with straight quotes.
|
|
43
|
+
|
|
44
|
+
### Communication artifacts
|
|
45
|
+
|
|
46
|
+
20. **Chatbot phrases.** "I hope this helps!", "Let me know if...", "Of course!", "Certainly!", "Found the smoking gun!" Remove.
|
|
47
|
+
22. **Sycophantic tone.** "Great question! You're absolutely right!" Respond directly.
|
|
48
|
+
|
|
49
|
+
### Filler
|
|
50
|
+
|
|
51
|
+
23. **Filler phrases.** "In order to" becomes "To". "Due to the fact that" becomes "Because". "It is important to note that" gets deleted.
|
|
52
|
+
24. **Excessive hedging.** "could potentially possibly be argued that it might" becomes "may".
|
|
53
|
+
25. **Generic conclusions.** "The future looks bright." State specific plans or facts.
|
|
54
|
+
|
|
55
|
+
### Jargon
|
|
56
|
+
|
|
57
|
+
26. **Abstract metaphor nouns.** Substrate, wedge, vector, locus, vantage, nexus, primitive (as noun), harness (as metaphor), surface (as in "API surface"), bedrock, scaffolding (as metaphor), modality, paradigm, gold-plating, ratchet (as metaphor), evacuate (for moving code), endgame, north star, flywheel. These read as technical but usually have a plainer concrete word. "Substrate" becomes "base". "Wedge in" becomes "add". "Vector" becomes "way" or "method". "Gold-plating" becomes "more than the job needs". "Ratchet" becomes the mechanism's real name or "a limit that only tightens". "Evacuate" becomes "move out". "Endgame" becomes "the last phase". Pick the concrete word.
|
|
58
|
+
|
|
59
|
+
### Plain speech
|
|
60
|
+
|
|
61
|
+
27. **Say what it does, not how it feels.** "the database stays close at hand", "SQL you can read", "types that follow your schema" name a feeling. The fix names the mechanism or a number: "`.toSQL()` returns the exact string sent to the database", "a column rename fails the build". Ask what the sentence tells the reader to do or know, then write that. If you can't restate it as a concrete instruction, fact, or number, cut it. One more check: if the sentence could appear unchanged in another project's docs, it says nothing about this one. Cut it.
|
|
62
|
+
28. **Shorten or split dense sentences.** If the reader has to backtrack to parse a sentence, break it in two or drop clauses. One idea per sentence.
|
|
63
|
+
29. **Active voice.** Prefer it. Catch "is/are/was/were + past participle" and name the actor: "queries are validated" becomes "the compiler validates queries", "the file is parsed by the loader" becomes "the loader parses the file". Passive is fine only when the actor is unknown or genuinely doesn't matter.
|
|
64
|
+
30. **Cut adverbs, or use a stronger verb.** "runs quickly" becomes "is fast" or the number. "significantly improves" becomes the measured delta. An adverb propping up a weak verb means the verb is wrong.
|
|
65
|
+
31. **Prefer the plain word.** "utilize" becomes "use", "leverage" becomes "use", "facilitate" becomes "help", "numerous" becomes "many", "in the event that" becomes "if". The fancier synonym is rarely clearer.
|
|
66
|
+
32. **Mannered prose.** Metaphor or flourish where a literal phrase exists: aphorisms ("wire it or delete it"), rhetorical fragments for effect, personified code ("the plan holds it"), figurative verbs ("rides along", "stands on"), stock framing phrases. "A dial worth turning" becomes "a parameter worth varying". Say what you mean. Rule 26 covers the metaphor nouns.
|
|
67
|
+
33. **Over-compression.** Dropped articles, verbless fragments, symbol-speak, and abbreviations that make the reader decode instead of read. "Parser rejects bad date → exit 2, no write" becomes "The parser rejects a bad date, exits with code 2, and writes nothing." Write whole sentences with their articles and verbs, and spell out arrows and abbreviations.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: why
|
|
3
|
+
description: "Use for 'why does X work this way', 'why we picked Y', design rationale, regressions, postmortems, or data-backed thresholds. Discovers available MCPs and queries each evidence category (source control, issue tracker, long-form docs, real-time chat, infrastructure observability, error tracking, product analytics warehouse) in parallel, then returns a cited read on decisions and tradeoffs. Use how for runtime behavior."
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Why
|
|
8
|
+
|
|
9
|
+
Investigate the motivation and intent behind code.
|
|
10
|
+
|
|
11
|
+
Companion to the `how` skill. `how` answers what the code does and how it works. `why` answers what forces led to its shape.
|
|
12
|
+
|
|
13
|
+
Read the **pstack-harness** skill first. Each spawn below names a role line in the pstack models file (`~/.pstack/models.md`, harness **models file** row) and a default (harness **tiers** row). Set `model` to that line's value, or to the default if the file or the line is missing. Leave `model` unset when the value is `auto` or `inherit-parent`. If the spawn rejects a model, use the default and say so. If it rejects the default, use the closest valid model of the same family from its error message.
|
|
14
|
+
|
|
15
|
+
## Operating Posture
|
|
16
|
+
|
|
17
|
+
Operate as a **careful, cautious, and precise investigator**. Be honest about what you know vs what you're inferring. Read `references/epistemics.md` for the full confidence framework and phrasing guide. The synthesizer must follow it.
|
|
18
|
+
|
|
19
|
+
## Step 1. Understand the Target and the Question
|
|
20
|
+
|
|
21
|
+
Parse what the user is asking. The **target** is usually a chunk of code, a pattern, a feature, or a named design decision. The **question** is usually a design rationale, a tradeoff, a motivating edge case, an external constraint, dead code, or a broad history sweep.
|
|
22
|
+
|
|
23
|
+
If the target is vague ("why do we do it this way?" with no clear referent), make your best guess from conversation context (open files, recent edits, cursor location, what was just discussed). State your interpretation briefly so the user can redirect if you're off, then proceed.
|
|
24
|
+
|
|
25
|
+
## Step 2. Establish the Code Anchor
|
|
26
|
+
|
|
27
|
+
Before spawning investigators, anchor the investigation in concrete code. You need:
|
|
28
|
+
|
|
29
|
+
- The relevant file path(s) and line range(s)
|
|
30
|
+
- The key symbols (function names, class names, constants)
|
|
31
|
+
- An initial commit list. The last few commits touching the target.
|
|
32
|
+
- PR numbers from merge commits (pattern `(#1234)` in the subject line)
|
|
33
|
+
|
|
34
|
+
Build this inline.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Blame target lines for last-touch commits
|
|
38
|
+
git blame -L <start>,<end> <file>
|
|
39
|
+
|
|
40
|
+
# Full file history, with patches, through renames
|
|
41
|
+
git log --follow -p -- <file>
|
|
42
|
+
|
|
43
|
+
# Last N commits touching the file, PR numbers visible
|
|
44
|
+
git log --oneline -20 -- <file>
|
|
45
|
+
|
|
46
|
+
# Extract PR numbers from a commit message
|
|
47
|
+
git log -1 --format=%B <commit>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Pull PR bodies and discussion via `gh` for any substantive commits:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
gh pr view <number> --json title,body,author,createdAt,mergedAt,labels,closingIssuesReferences,comments,reviews
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Capture this as seed context (file paths, symbols, commits, PR numbers, linked ticket IDs). Pass it to the investigators.
|
|
57
|
+
|
|
58
|
+
## Step 3. Spawn Parallel Investigators (default posture)
|
|
59
|
+
|
|
60
|
+
**Default to the full parallel investigation.**
|
|
61
|
+
|
|
62
|
+
### Discovery
|
|
63
|
+
|
|
64
|
+
Before spawning investigators, list the MCP servers available in this session from your tool list (tools named `mcp__<server>__*` on Claude Code, the MCP tool namespaces on Codex).
|
|
65
|
+
|
|
66
|
+
Map each available MCP to one evidence category:
|
|
67
|
+
|
|
68
|
+
1. Source control history
|
|
69
|
+
2. Issue / ticket tracker
|
|
70
|
+
3. Long-form documents
|
|
71
|
+
4. Real-time team chat
|
|
72
|
+
5. Infrastructure observability
|
|
73
|
+
6. Error / exception tracking
|
|
74
|
+
7. Product analytics warehouse
|
|
75
|
+
|
|
76
|
+
Source control is always available through git and `gh`. For the other six, classify using the MCP name, server instructions, tool names, and resource descriptors. If an MCP could fit more than one category, choose the one matching its primary evidence. Record ambiguous cases in the coverage map.
|
|
77
|
+
|
|
78
|
+
Aim for a complete **coverage map**, not a minimal one. Document the null, don't skip the search.
|
|
79
|
+
|
|
80
|
+
Launch all matching investigators in a single message so they run concurrently. Don't ask one agent to cover multiple MCPs.
|
|
81
|
+
|
|
82
|
+
Subagent config (each):
|
|
83
|
+
- `subagent_type`: `general-purpose` (harness **default agent** row)
|
|
84
|
+
- `model`: the `why investigators` line, default the code tier
|
|
85
|
+
- `readonly`: `false` (harness **read-write** row). **Do not use readonly/Ask mode.** It strips MCP access, which disables MCP-backed investigators entirely. Investigators still shouldn't write anything.
|
|
86
|
+
|
|
87
|
+
Each investigator gets:
|
|
88
|
+
1. The base prompt from `references/investigator-prompt.md`
|
|
89
|
+
2. The category playbook `references/sources/<source>.md` for the selected MCP, adapted from the examples in `references/source-playbook.md`
|
|
90
|
+
3. The cross-cutting `references/sources/incident-postmortem.md` **if the target code looks defensive** (null checks, retry logic, timeout handling, rate limiting, feature flags, egress guards, OOM handlers)
|
|
91
|
+
4. The code anchor from Step 2 (file paths, symbols, commit hashes, PR numbers, ticket IDs)
|
|
92
|
+
5. The user's original question
|
|
93
|
+
|
|
94
|
+
### Investigator roster. One per available evidence category
|
|
95
|
+
|
|
96
|
+
Spawn one investigator per category that has a matching MCP. Each owns exactly one tool or MCP.
|
|
97
|
+
|
|
98
|
+
Each entry names the category and the kind of "why" it uniquely surfaces. Use it to know what to expect back, how to name a gap when a category returns empty, and (only in the rare provably-irrelevant case) to justify a skip.
|
|
99
|
+
|
|
100
|
+
1. **Source control investigator**. Git history, `gh` for PRs, code comments, tests. Always spawn. The only guaranteed source. Best at surfacing *implementation-time rationale captured during review*.
|
|
101
|
+
|
|
102
|
+
2. **Issue / ticket tracker investigator** (e.g. Linear, Jira, GitHub Issues, Plane, Shortcut MCP). Best at surfacing *the product or business forcing function*. Strongest when the why is external to engineering.
|
|
103
|
+
|
|
104
|
+
3. **Long-form documents investigator** (e.g. Notion, Confluence, Google Docs, Coda MCP). Best at surfacing *long-form design rationale*. Where the why is written out before it becomes code.
|
|
105
|
+
|
|
106
|
+
4. **Real-time team chat investigator** (e.g. Slack, Discord, Microsoft Teams, Mattermost MCP). Best at surfacing *real-time deliberation that never reached a doc*. Especially important when the source control, ticket, and doc paper trail is thin.
|
|
107
|
+
|
|
108
|
+
5. **Infrastructure observability investigator** (e.g. Datadog, New Relic, Honeycomb, Grafana, Splunk MCP). Infra/runtime view. Best at surfacing *infrastructure and runtime reality that motivated the code*. Strongest when the target reacts to an infra signal (timeouts, retries, rate limits, circuit breakers).
|
|
109
|
+
|
|
110
|
+
6. **Error / exception tracking investigator** (e.g. Sentry, Rollbar, Bugsnag, Airbrake MCP). Best at surfacing *the specific exceptions and error trajectories that motivated defensive or corrective code*. Strongest for catch blocks, null guards, type checks, retries, and other defenses.
|
|
111
|
+
|
|
112
|
+
7. **Product analytics warehouse investigator** (e.g. Databricks, Snowflake, BigQuery, ClickHouse, dbt, Redshift MCP). Product/data view. Best at surfacing *product and data reality that shaped the code*. Strongest for flag-gated code, experiment-driven ships, data migrations, and "where did this number come from" questions.
|
|
113
|
+
|
|
114
|
+
### When to skip an investigator
|
|
115
|
+
|
|
116
|
+
Only skip with an **explicit, written justification** that goes in the final "Sources Consulted" section. Two valid reasons:
|
|
117
|
+
|
|
118
|
+
- **No MCP is available for that category** in this environment. Flag this as a gap, not a choice. Example: "Real-time team chat skipped. No matching MCP available, so the conversational record was not searchable."
|
|
119
|
+
- **The source is provably irrelevant**, not just "probably irrelevant." A high bar. Example: "Error / exception tracking skipped. Target is a build-time script with no runtime code path."
|
|
120
|
+
|
|
121
|
+
If your scope assessment suggests a single-commit trivial target where the PR description already contains the complete answer, you may answer inline **only after** confirming all seven available category searches would be redundant. Say so explicitly. This should be rare.
|
|
122
|
+
|
|
123
|
+
## Step 4. Synthesize
|
|
124
|
+
|
|
125
|
+
Spawn one synthesizer subagent:
|
|
126
|
+
|
|
127
|
+
- `subagent_type`: `general-purpose` (harness **default agent** row)
|
|
128
|
+
- `model`: the `why synthesizer` line, default the judgment tier
|
|
129
|
+
- `readonly`: `false` (harness **read-write** row). The synthesizer's quality check spot-verifies citations, which can require MCP access. Readonly/Ask mode strips MCPs and defeats that.
|
|
130
|
+
|
|
131
|
+
The synthesizer gets:
|
|
132
|
+
1. The investigator findings, including any null results and any categories skipped with justification
|
|
133
|
+
2. The code anchor from Step 2 (file paths, symbols, commit hashes, PR numbers, ticket IDs)
|
|
134
|
+
3. The user's original question
|
|
135
|
+
4. The epistemics framework from `references/epistemics.md`
|
|
136
|
+
5. The synthesizer prompt template from `references/synthesizer-prompt.md`
|
|
137
|
+
|
|
138
|
+
## Step 5. Present
|
|
139
|
+
|
|
140
|
+
Take the synthesizer's output and present it to the user. You may lightly edit for clarity or add context from the conversation, but **do not rewrite the confidence language**.
|
|
141
|
+
|
|
142
|
+
## Output Format
|
|
143
|
+
|
|
144
|
+
The output structure is the one in `references/synthesizer-prompt.md`: The Question, The Code in Question, What We Found, What We Can Reasonably Infer, Competing Hypotheses, What We Don't Know, Sources Consulted, Confidence Summary. Adapt as needed, but keep the confidence separation intact, and keep Sources Consulted as one line per investigator, including the ones that returned nothing or were skipped, with the reason.
|
|
145
|
+
|
|
146
|
+
After the Sources Consulted block, if the user's `why` question is a precursor to actually changing this code, convert the lineage findings into a Preserve / Change / Avoid / Risk constraint set suitable for planning the change.
|
|
147
|
+
|
|
148
|
+
## Common Failure Modes to Avoid
|
|
149
|
+
|
|
150
|
+
- **Recency bias**. Assuming the most recent commit is authoritative. The current shape is often the accretion of many earlier decisions. Trace back.
|
|
151
|
+
|
|
152
|
+
## Reference Files
|
|
153
|
+
|
|
154
|
+
- `references/epistemics.md`. Confidence tiers and phrasing guide. The synthesizer must follow it.
|
|
155
|
+
- `references/investigator-prompt.md`. Base prompt template for investigator subagents.
|
|
156
|
+
- `references/source-playbook.md`. Index pointing at the category playbooks below.
|
|
157
|
+
- `references/sources/*.md`. One self-contained example playbook per category, plus cross-cutting `incident-postmortem.md`. Give an investigator the single file that matches its category and adapt it to the available MCP.
|
|
158
|
+
- `references/synthesizer-prompt.md`. Prompt template for the synthesizer subagent, including the output format.
|