dsh-pstack 0.0.0-stage → 0.2.0-beta.1
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 +22 -0
- package/README.md +133 -2
- package/assets/agents/comment-sicko.md +32 -0
- package/assets/agents/poteto-agent.md +8 -0
- package/assets/docs/guide/01-setup.md +64 -0
- package/assets/docs/guide/02-poteto-mode.md +139 -0
- package/assets/docs/guide/03-understand.md +79 -0
- package/assets/docs/guide/04-design.md +133 -0
- package/assets/docs/guide/05-build-and-clean.md +83 -0
- package/assets/docs/guide/06-verify-and-ship.md +152 -0
- package/assets/docs/guide/07-overnight.md +120 -0
- package/assets/docs/guide/08-principles.md +72 -0
- package/assets/docs/guide/09-make-it-yours.md +96 -0
- package/assets/docs/guide/10-recipes-and-pitfalls.md +180 -0
- package/assets/docs/guide/README.md +38 -0
- package/assets/docs/guide/images/design.jpg +0 -0
- package/assets/docs/guide/images/overnight.jpg +0 -0
- package/assets/docs/guide/images/recipes.jpg +0 -0
- package/assets/docs/guide/images/router.jpg +0 -0
- package/assets/docs/guide/images/understanding.jpg +0 -0
- package/assets/docs/guide/images/verification.jpg +0 -0
- package/assets/docs/harness/dsh.md +60 -0
- package/assets/docs/pstack-models.example.md +54 -0
- package/assets/skills/architect/SKILL.md +81 -0
- package/assets/skills/architect/references/design-red-flags.md +57 -0
- package/assets/skills/architect/references/rationale-template.md +35 -0
- package/assets/skills/architect/references/runner-prompt.md +20 -0
- package/assets/skills/arena/SKILL.md +50 -0
- package/assets/skills/automate-me/SKILL.md +106 -0
- package/assets/skills/benchmark-checklist/SKILL.md +39 -0
- package/assets/skills/blast-radius/SKILL.md +52 -0
- package/assets/skills/bro/SKILL.md +7 -0
- package/assets/skills/correct/SKILL.md +32 -0
- package/assets/skills/create-formal-verification-skill/SKILL.md +43 -0
- package/assets/skills/create-verification-skill/SKILL.md +46 -0
- package/assets/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
- package/assets/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
- package/assets/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
- package/assets/skills/figure-it-out/SKILL.md +54 -0
- package/assets/skills/how/SKILL.md +38 -0
- package/assets/skills/how/references/explainer-prompt.md +55 -0
- package/assets/skills/how/references/explorer-prompt.md +35 -0
- package/assets/skills/in-your-own-words/SKILL.md +7 -0
- package/assets/skills/interrogate/SKILL.md +71 -0
- package/assets/skills/interrogate/references/code-quality-review.md +47 -0
- package/assets/skills/interrogate/references/lead-judgment.md +39 -0
- package/assets/skills/interrogate/references/reviewer-prompt.md +62 -0
- package/assets/skills/interrogate/references/rubric.md +77 -0
- package/assets/skills/ketchup/SKILL.md +45 -0
- package/assets/skills/maintain-formal-verification-skill/SKILL.md +60 -0
- package/assets/skills/maintain-verification-skill/SKILL.md +41 -0
- package/assets/skills/no-comments/SKILL.md +26 -0
- package/assets/skills/poteto-help/SKILL.md +162 -0
- package/assets/skills/poteto-help/references/prompting.md +51 -0
- package/assets/skills/poteto-help/references/recipes.md +51 -0
- package/assets/skills/poteto-mode/SKILL.md +151 -0
- package/assets/skills/poteto-mode/playbooks/authoring-a-skill.md +12 -0
- package/assets/skills/poteto-mode/playbooks/autonomous-run.md +15 -0
- package/assets/skills/poteto-mode/playbooks/autopilot-full.md +25 -0
- package/assets/skills/poteto-mode/playbooks/autopilot-stack.md +12 -0
- package/assets/skills/poteto-mode/playbooks/babysit.md +23 -0
- package/assets/skills/poteto-mode/playbooks/bug-fix.md +15 -0
- package/assets/skills/poteto-mode/playbooks/eval.md +25 -0
- package/assets/skills/poteto-mode/playbooks/feature.md +21 -0
- package/assets/skills/poteto-mode/playbooks/hillclimb.md +21 -0
- package/assets/skills/poteto-mode/playbooks/investigation.md +14 -0
- package/assets/skills/poteto-mode/playbooks/multi-phase-plan.md +155 -0
- package/assets/skills/poteto-mode/playbooks/opening-a-pr.md +34 -0
- package/assets/skills/poteto-mode/playbooks/orchestrate.md +112 -0
- package/assets/skills/poteto-mode/playbooks/pause-safely.md +10 -0
- package/assets/skills/poteto-mode/playbooks/perf-issue.md +25 -0
- package/assets/skills/poteto-mode/playbooks/prototype.md +14 -0
- package/assets/skills/poteto-mode/playbooks/refactoring.md +16 -0
- package/assets/skills/poteto-mode/playbooks/runtime-forensics.md +11 -0
- package/assets/skills/poteto-mode/playbooks/session-pickup.md +11 -0
- package/assets/skills/poteto-mode/playbooks/shipping.md +12 -0
- package/assets/skills/poteto-mode/playbooks/trace-forensics.md +14 -0
- package/assets/skills/poteto-mode/playbooks/visual-parity.md +11 -0
- package/assets/skills/poteto-mode/playbooks/worktree-cleanup.md +20 -0
- package/assets/skills/poteto-mode/references/bugbot-triage.md +142 -0
- package/assets/skills/poteto-mode/scripts/check-plan.mjs +220 -0
- package/assets/skills/poteto-mode/scripts/check-plan.test.mjs +343 -0
- package/assets/skills/poteto-mode/scripts/orch/orch.mjs +4282 -0
- package/assets/skills/poteto-mode/scripts/orch/orch.test.mjs +2042 -0
- package/assets/skills/poteto-mode/scripts/watch-pr/cli.test.mjs +5101 -0
- package/assets/skills/poteto-mode/scripts/watch-pr/github.test.mjs +1177 -0
- package/assets/skills/poteto-mode/scripts/watch-pr/policy.test.mjs +1441 -0
- package/assets/skills/poteto-mode/scripts/watch-pr/watch-pr.mjs +4601 -0
- package/assets/skills/poteto-mode/scripts/worktree-audit.mjs +675 -0
- package/assets/skills/principle-attack-the-premise/SKILL.md +21 -0
- package/assets/skills/principle-boundary-discipline/SKILL.md +34 -0
- package/assets/skills/principle-build-the-lever/SKILL.md +23 -0
- package/assets/skills/principle-encode-lessons-in-structure/SKILL.md +11 -0
- package/assets/skills/principle-exhaust-the-design-space/SKILL.md +9 -0
- package/assets/skills/principle-experience-first/SKILL.md +19 -0
- package/assets/skills/principle-explain-the-number/SKILL.md +17 -0
- package/assets/skills/principle-fix-root-causes/SKILL.md +21 -0
- package/assets/skills/principle-foundational-thinking/SKILL.md +21 -0
- package/assets/skills/principle-guard-the-context-window/SKILL.md +12 -0
- package/assets/skills/principle-laziness-protocol/SKILL.md +10 -0
- package/assets/skills/principle-make-operations-idempotent/SKILL.md +22 -0
- package/assets/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +14 -0
- package/assets/skills/principle-minimize-reader-load/SKILL.md +18 -0
- package/assets/skills/principle-model-the-domain/SKILL.md +24 -0
- package/assets/skills/principle-never-block-on-the-human/SKILL.md +15 -0
- package/assets/skills/principle-outcome-oriented-execution/SKILL.md +21 -0
- package/assets/skills/principle-prove-it-works/SKILL.md +24 -0
- package/assets/skills/principle-redesign-from-first-principles/SKILL.md +16 -0
- package/assets/skills/principle-separate-before-serializing-shared-state/SKILL.md +16 -0
- package/assets/skills/principle-sequence-verifiable-units/SKILL.md +17 -0
- package/assets/skills/principle-subtract-before-you-add/SKILL.md +18 -0
- package/assets/skills/principle-test-behavior-not-implementation/SKILL.md +20 -0
- package/assets/skills/principle-type-system-discipline/SKILL.md +13 -0
- package/assets/skills/recall/SKILL.md +37 -0
- package/assets/skills/reflect/SKILL.md +69 -0
- package/assets/skills/reflect/references/divergent-reviewer.md +38 -0
- package/assets/skills/reflect/references/judgment-reviewer.md +37 -0
- package/assets/skills/reflect/references/synthesizer.md +56 -0
- package/assets/skills/reflect/references/tooling-reviewer.md +48 -0
- package/assets/skills/setup-pstack/SKILL.md +67 -0
- package/assets/skills/sharpen/SKILL.md +16 -0
- package/assets/skills/show-me-your-work/SKILL.md +84 -0
- package/assets/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
- package/assets/skills/show-me-your-work/scripts/log.mjs +108 -0
- package/assets/skills/swarm/SKILL.md +43 -0
- package/assets/skills/tdd/SKILL.md +42 -0
- package/assets/skills/teach/SKILL.md +23 -0
- package/assets/skills/technical-writing/SKILL.md +108 -0
- package/assets/skills/typescript-best-practices/SKILL.md +34 -0
- package/assets/skills/typescript-best-practices/references/patterns.md +328 -0
- package/assets/skills/unslop/SKILL.md +62 -0
- package/assets/skills/why/SKILL.md +100 -0
- package/assets/skills/why/references/epistemics.md +71 -0
- package/assets/skills/why/references/investigator-prompt.md +84 -0
- package/assets/skills/why/references/source-playbook.md +17 -0
- package/assets/skills/why/references/sources/code-archaeology.md +51 -0
- package/assets/skills/why/references/sources/databricks.md +70 -0
- package/assets/skills/why/references/sources/datadog.md +97 -0
- package/assets/skills/why/references/sources/incident-postmortem.md +5 -0
- package/assets/skills/why/references/sources/linear.md +48 -0
- package/assets/skills/why/references/sources/notion.md +55 -0
- package/assets/skills/why/references/sources/sentry.md +66 -0
- package/assets/skills/why/references/sources/slack.md +17 -0
- package/assets/skills/why/references/synthesizer-prompt.md +129 -0
- package/cordis.patch.yml +39 -0
- package/dist/frontmatter-BQX3ekwP.mjs +229 -0
- package/dist/frontmatter-BQX3ekwP.mjs.map +1 -0
- package/dist/history.d.mts +429 -0
- package/dist/history.mjs +1129 -0
- package/dist/history.mjs.map +1 -0
- package/dist/host-contract-o47JH_r8.d.mts +527 -0
- package/dist/index.d.mts +278 -0
- package/dist/index.mjs +272 -0
- package/dist/index.mjs.map +1 -0
- package/dist/paths-D_JlVmBk.mjs +42 -0
- package/dist/paths-D_JlVmBk.mjs.map +1 -0
- package/dist/script.d.mts +193 -0
- package/dist/script.mjs +782 -0
- package/dist/script.mjs.map +1 -0
- package/dist/subagent.d.mts +336 -0
- package/dist/subagent.mjs +1402 -0
- package/dist/subagent.mjs.map +1 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +106 -3
- package/static/icon.png +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: technical-writing
|
|
3
|
+
description: "Layered technical-writing standard: Diátaxis structure, Google developer style sentences, STE instruction rules, Global English syntax. Use for /technical-writing or when writing or reviewing docs, RFCs, readmes, PR descriptions, or commit messages."
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Technical writing
|
|
8
|
+
|
|
9
|
+
> DSH port of pstack. `pstack_subagent` replaces Cursor's Task tool, and `role` replaces Cursor model slugs. Full mapping: `../../docs/harness/dsh.md`.
|
|
10
|
+
|
|
11
|
+
Write so a tired engineer understands on the first read. Apply all four layers.
|
|
12
|
+
|
|
13
|
+
Three rules sit above the layers:
|
|
14
|
+
|
|
15
|
+
- **Cut every word that does no work.** If the sentence survives without a word, the word goes. "In order to" is "to". "It is important to note that" is nothing.
|
|
16
|
+
- **Use the short, everyday word.** "Use", not "utilize". "Help", not "facilitate". "Do", not "perform". A long word has to buy its length with precision.
|
|
17
|
+
- **When a rule makes a sentence worse, fix the sentence another way or leave it alone.** A sentence that follows every rule and sounds like a machine wrote it has failed.
|
|
18
|
+
|
|
19
|
+
The codebase is the word list. Write the real symbol, file, flag, or command name, not a synonym or a description of it.
|
|
20
|
+
|
|
21
|
+
Don't invent jargon. Use the words a developer would say out loud: "move", "delete", "a budget that only decreases", not "evacuate", "ratchet", or "endgame". A named pattern is fine when the doc says what it means the first time. Propose a new offender and its replacement as an addition to `unslop`'s abstract-metaphor rule in your reply, with the diff. Don't edit that skill.
|
|
22
|
+
|
|
23
|
+
## Vary the rhythm
|
|
24
|
+
|
|
25
|
+
A doc can obey every layer and still read machine-written: every sentence clipped short, no view anywhere, nothing specific.
|
|
26
|
+
|
|
27
|
+
- Mix sentence lengths on purpose. Short sentences land a point. Longer ones carry a fact with its condition or consequence.
|
|
28
|
+
- One thought per sentence does not mean one length per sentence. Split the sentence that carries two thoughts. Keep the long sentence that carries one.
|
|
29
|
+
- Have a view where the mode allows it. Explanation weighs trade-offs, so say what you make of them instead of listing pros and cons. Reference stays dry.
|
|
30
|
+
- Be specific over sterile. Not "schema changes can cause issues" but "a column rename fails the build".
|
|
31
|
+
|
|
32
|
+
## Pick the mode first (Diátaxis)
|
|
33
|
+
|
|
34
|
+
One document, one mode. Two questions pick it: does the content inform action (doing) or understanding (thinking), and does it serve learning or work?
|
|
35
|
+
|
|
36
|
+
- Action + learning: **tutorial**.
|
|
37
|
+
- Action + work: **how-to**.
|
|
38
|
+
- Understanding + work: **reference**.
|
|
39
|
+
- Understanding + learning: **explanation**.
|
|
40
|
+
|
|
41
|
+
Use the compass on a whole document or on one sentence.
|
|
42
|
+
|
|
43
|
+
**Tutorial: learning by doing.** The learner's success is your job, not theirs. Open by saying what the learner will build, not what they will "learn". Every step produces a visible result, early and often. Tell them what they should see: the expected output, the prompt change, the log line. Cut explanation to one clause and a link. Stay concrete. Write as "we", in commands: "First, do x. Now, do y."
|
|
44
|
+
|
|
45
|
+
**How-to: steps to a goal.** Solve a problem a person has, not an operation the machine can perform. Assume competence and skip teaching. Action only: no digressions, no background, no completeness for its own sake. Link those instead. Allow forks and judgment: "If you want x, do y." Name the guide by the task: "How to calibrate the radar array", not "Radar array calibration".
|
|
46
|
+
|
|
47
|
+
**Reference: facts for lookup.** Only describe. No instruction, no persuasion, no opinion. Be dry, complete, and sure. State facts, options, limits, and errors with no hedging. Mirror the structure of the thing described, so code and docs can be navigated together. Put material where readers expect it. Generate from code where possible.
|
|
48
|
+
|
|
49
|
+
**Explanation: understanding and why.** One bounded topic, readable away from the product. Each title should tolerate an implicit "About..." in front. Anchor on a real why question. Give context: design decisions, history, constraints, alternatives. Opinion is allowed here and nowhere else.
|
|
50
|
+
|
|
51
|
+
Don't mix modes: no reference tables inside a tutorial, no tutorial hand-holding inside reference, no arguing inside a how-to. Split and link instead.
|
|
52
|
+
|
|
53
|
+
## Write sentences to the reader (Google developer style)
|
|
54
|
+
|
|
55
|
+
- Talk to the reader as "you", in the present tense. "Will" only for things that genuinely happen later.
|
|
56
|
+
- Say who does what: "the compiler checks", not "is checked". Passive is fine only when the actor is unknown or beside the point.
|
|
57
|
+
- Write instructions as commands: "Click Submit." State facts plainly. Never "should be done".
|
|
58
|
+
- Put the condition before the instruction: "To delete the document, click Delete."
|
|
59
|
+
- Put the common case first. Exceptions after.
|
|
60
|
+
- Sound like a knowledgeable friend. No buzzwords, no figurative language, no "please" in instructions, and never "simply", "easy", or "quickly" in a procedure. If it were simple, the reader would not be here.
|
|
61
|
+
- Don't pre-announce ("we will soon support...") and don't start consecutive sentences with the same phrase.
|
|
62
|
+
- Link with words that say where the link goes: the page title or a short description. Never "click here". Prefer a sentence of context on the page over a link off it.
|
|
63
|
+
- Headings carry the point, not just the topic ("Pick the mode first", not "Modes"). Sentence case. A task heading is a bare verb phrase ("Create an instance"). A concept heading is a noun phrase. One h1 per page, no skipped levels.
|
|
64
|
+
- Numbered lists for sequences, bullets for everything else. Introduce a list with a complete sentence. Keep items parallel.
|
|
65
|
+
- Code goes in code font. UI elements go in bold. Use serial commas. Drop "etc." and say up front that a list is partial.
|
|
66
|
+
|
|
67
|
+
## Make statements load one at a time (STE rules)
|
|
68
|
+
|
|
69
|
+
- One instruction per sentence. One thought per sentence everywhere else.
|
|
70
|
+
- Split instructions longer than about 20 words and other sentences longer than about 25.
|
|
71
|
+
- Put the warning or condition before the step it guards: "If hot oil touches your skin, injuries can occur."
|
|
72
|
+
- Keep "the" and "a": "Remove backup file" reads two ways. "Remove the backup file" reads one.
|
|
73
|
+
- Give each word one meaning and one job, then keep it. If "check" means inspect, don't also use it for restrain.
|
|
74
|
+
- Pick one word per action and stick to it: "start", not "start" here and "initiate" there.
|
|
75
|
+
- Write procedures as direct commands, never as narration and never in the passive: "Install the component", not "the component must be installed".
|
|
76
|
+
- Avoid "-ing" words where you can.
|
|
77
|
+
|
|
78
|
+
## Leave no sentence open to two readings (Global English)
|
|
79
|
+
|
|
80
|
+
- Keep words like "only" and "not" next to the word they change: "only fails on growth" and "fails only on growth" say different things.
|
|
81
|
+
- Break up long noun strings: "the proto import budget check script" becomes "the script that checks the proto-import budget".
|
|
82
|
+
- Make every "it", "they", and "this" point at one obvious thing. Repeat the noun when in doubt. Never use "this" or "which" to point at a whole clause.
|
|
83
|
+
- Don't drop verbs: "Phase 1 moves the converters and Phase 2 the runtime" leaves Phase 2 without one. Give it one.
|
|
84
|
+
- Keep the small words that show structure, such as "that" in "Ensure that the switch is off". Never trade clarity for word count.
|
|
85
|
+
- Repeat the article in a series when it prevents a misread: "the client and the host", not "the client and host", when they are two things.
|
|
86
|
+
- Say which parts "and" or "or" joins when a sentence can group two ways. "Both...and", "either...or", and "if...then" are free disambiguators.
|
|
87
|
+
- Use periods, not semicolons. Replace an em dash with a new sentence.
|
|
88
|
+
- Make text in parentheses a full grammatical unit or its own sentence. Never form plurals with "(s)".
|
|
89
|
+
- No slashes: write "a, b, or both" instead of "a/b" or "and/or".
|
|
90
|
+
- Call each thing by one name, everywhere. A doc that says "the gate", "the ratchet", and "the budget check" for one thing teaches three things. Don't churn what didn't change.
|
|
91
|
+
- Skip idioms, colloquialisms, Latin abbreviations, and metaphors.
|
|
92
|
+
|
|
93
|
+
## Voice and repo specifics
|
|
94
|
+
|
|
95
|
+
- Apply the **unslop** skill to every doc this skill touches. That skill owns the slop-pattern catalog: AI vocabulary, filler, hedging, formatting tells.
|
|
96
|
+
- PR descriptions and commit messages are writing too. Every layer except Diátaxis applies to them. A PR body is a briefing that a reviewer can read in under a minute. Do not paste swarm logs, SHA lists, or metric tables. Link them.
|
|
97
|
+
- Product UI strings are not documentation. Use your product's copy guidelines for those.
|
|
98
|
+
- Indent code snippets with tabs. Write real paths. Make every count or tree claim true at the commit that lands it, and include the command that regenerates it.
|
|
99
|
+
|
|
100
|
+
## Worked example
|
|
101
|
+
|
|
102
|
+
Before:
|
|
103
|
+
|
|
104
|
+
> Configuration of the proto import ratchet budget script parameters is performed via budget.json. Note that it's important to remember that running with --write, which updates the committed budget to reflect the current count, should only be done when lowering it. If exceeded, CI fails.
|
|
105
|
+
|
|
106
|
+
After:
|
|
107
|
+
|
|
108
|
+
> `budget.mjs` reads the committed budget from `budget.json` and counts the files that import protos. If the count exceeds the budget, CI fails. Run `budget.mjs --write` only to lower the budget.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: typescript-best-practices
|
|
3
|
+
description: TypeScript best practices. Use when reading or editing any .ts or .tsx file.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# TypeScript best practices
|
|
8
|
+
|
|
9
|
+
> DSH port of pstack. `pstack_subagent` replaces Cursor's Task tool, and `role` replaces Cursor model slugs. Full mapping: `../../docs/harness/dsh.md`.
|
|
10
|
+
|
|
11
|
+
Apply `principle-type-system-discipline` first; read its `SKILL.md` at its absolute resource path.
|
|
12
|
+
|
|
13
|
+
| Rule | Summary |
|
|
14
|
+
|------|---------|
|
|
15
|
+
| Discriminated unions | Model variants with a `kind` literal discriminant so impossible states can't be represented. No optional-field bags. |
|
|
16
|
+
| Branded types | Brand primitives with `& { readonly __brand: "X" }` so they can't be mixed up. Validate once at the boundary. A brand comes from a verifying type guard (`input is AgentId`), never from `as`. |
|
|
17
|
+
| Constructive modeling | Build the shape so the illegal value can't be constructed. `[T, ...T[]]` for non-empty, `[T, T][]` for even length, `start` plus `duration` for a range. Not a runtime guard, not a wish for refinement types. |
|
|
18
|
+
| Simplest total type | Keep `T[]` while every operation on it stays total. Strengthen to `NonEmpty<T>` only where the loose type forces `!`, a cast, or a "should never happen" throw. |
|
|
19
|
+
| `unknown` over `any` | External data is `unknown`. |
|
|
20
|
+
| Schemas before guards | Before hand-writing a property-by-property type guard, use the repository's runtime schema library and infer the type from the schema, such as `z.infer`. |
|
|
21
|
+
| No `as` casts | Every `as` is a runtime crash waiting. Cast only after validation. |
|
|
22
|
+
| Narrowing hierarchy | Discriminant switch > `in` operator > `typeof`/`instanceof` > user-defined type guard > `as`. |
|
|
23
|
+
| Type guards | Must verify the claim. A lying guard is worse than `as` because the bug hides behind a name that says it's safe. Name them `isX` or `hasX`. |
|
|
24
|
+
| Exhaustiveness | Inline `const _exhaustive: never = x;` in default arms so the compiler errors when a new variant is added. |
|
|
25
|
+
| `satisfies` over `as` | Validates the value without widening literal types. |
|
|
26
|
+
| Boundary validation | Parse where data crosses in, into a named domain type. `Record<string, unknown>` (however spelled) stops at that parse. Trust types inside. See `principle-boundary-discipline`; read its `SKILL.md` at its absolute resource path. |
|
|
27
|
+
| Schema-derived types | Reach for `Pick`/`Omit`/`Parameters`/`ReturnType`/`Awaited`/`typeof` before declaring a new interface. |
|
|
28
|
+
| Object args | Pass objects, not positional, so argument order is self-documenting. Skip on hot paths (per-frame render, tokenizers, parsers). |
|
|
29
|
+
| Real tests | Don't mock what you can run. Prefer the framework's real test primitives with leak/disposable checks, and verify UI in a running build. Mock only what you can't run locally. |
|
|
30
|
+
| Structured telemetry | Prefer structured logger diagnostics with enough context to debug from an id. No `console.log` in shipped code. |
|
|
31
|
+
|
|
32
|
+
Examples: `references/patterns.md`.
|
|
33
|
+
|
|
34
|
+
This skill is explicit-invocation only. DSH does not consume a `paths` glob, so opening a `.ts` or `.tsx` file does not attach it: load it by name when you want it applied.
|
|
@@ -0,0 +1,328 @@
|
|
|
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 isAgentId(input: string): input is AgentId {
|
|
13
|
+
return isUUID(input);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function parseAgentId(input: string): AgentId {
|
|
17
|
+
if (!isAgentId(input)) throw new Error(`Invalid agent id: ${input}`);
|
|
18
|
+
return input;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function focusAgent(id: AgentId): void {
|
|
22
|
+
/* input is trusted */
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Match the `readonly __brand: 'X'` shape. Don't invent a new convention.
|
|
27
|
+
|
|
28
|
+
## Discriminated unions
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// Don't. Boolean + optionals lets contradictory states exist.
|
|
34
|
+
type DiffState = { loading: boolean; diff?: GitDiff; error?: string };
|
|
35
|
+
|
|
36
|
+
// Do. Only valid states exist.
|
|
37
|
+
type DiffState =
|
|
38
|
+
| { kind: "loading" }
|
|
39
|
+
| { kind: "ready"; diff: GitDiff }
|
|
40
|
+
| { kind: "error"; error: string };
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Pick one discriminant name (`kind`, `type`, `tag`) and stick to it.
|
|
44
|
+
|
|
45
|
+
## Constructive modeling
|
|
46
|
+
|
|
47
|
+
Build the type from parts that are all legal instead of restricting a loose type with runtime checks.
|
|
48
|
+
|
|
49
|
+
Non-empty, via a variadic tuple:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
type NonEmpty<T> = [T, ...T[]];
|
|
53
|
+
|
|
54
|
+
// Don't: T[] plus a length check every caller must repeat
|
|
55
|
+
function pickWinner(entries: string[]): string {
|
|
56
|
+
if (entries.length === 0) throw new Error("no entries");
|
|
57
|
+
return entries[Math.floor(Math.random() * entries.length)];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Do: an empty value of the type can't exist
|
|
61
|
+
function pickWinner(entries: NonEmpty<string>): string {
|
|
62
|
+
return entries[Math.floor(Math.random() * entries.length)];
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Where a plain `T[]` arrives, narrow once with a guard. The fact then travels in the type:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
const isNonEmpty = <T>(arr: T[]): arr is NonEmpty<T> => arr.length > 0;
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Even length, as pairs:
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
type Pairs<T> = [T, T][];
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
A time range, as start plus duration:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
// Don't: a comment holds the invariant
|
|
82
|
+
type TimeRange = { start: Date; end: Date }; // start <= end
|
|
83
|
+
|
|
84
|
+
// Do: a negative range can't be written; derive end when needed
|
|
85
|
+
type TimeRange = { start: Date; durationMs: number };
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
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).
|
|
89
|
+
|
|
90
|
+
## Simplest total type
|
|
91
|
+
|
|
92
|
+
Don't strengthen everything. Keep `T[]` when every operation on it is total:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const sum = (xs: number[]) => xs.reduce((a, b) => a + b, 0); // [] is 0, fine
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
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:
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// Don't: partiality smuggled past the compiler
|
|
102
|
+
function newestSession(sessions: Session[]): Session {
|
|
103
|
+
return sessions.at(0)!;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Do: strengthen the input; the assertion disappears
|
|
107
|
+
function newestSession(sessions: NonEmpty<Session>): Session {
|
|
108
|
+
return sessions[0];
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Weakening the result to `Session | undefined` is the other total signature.
|
|
113
|
+
|
|
114
|
+
## `unknown` over `any`
|
|
115
|
+
|
|
116
|
+
External data is always `unknown`. Narrow before use.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
// Don't
|
|
120
|
+
function handle(input: any) {
|
|
121
|
+
return input.foo.bar;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Do
|
|
125
|
+
function handle(input: unknown) {
|
|
126
|
+
if (typeof input === "object" && input !== null && "foo" in input) {
|
|
127
|
+
// narrowed; compiler verifies access
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
External sources include RPC payloads, `JSON.parse`, `postMessage`, IPC, file contents, environment variables, database results.
|
|
133
|
+
|
|
134
|
+
## Schemas before hand-rolled guards
|
|
135
|
+
|
|
136
|
+
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.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { z } from "zod";
|
|
140
|
+
|
|
141
|
+
const UserSchema = z.object({
|
|
142
|
+
id: z.string().uuid(),
|
|
143
|
+
role: z.enum(["admin", "member"]),
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
type User = z.infer<typeof UserSchema>;
|
|
147
|
+
|
|
148
|
+
function parseUser(input: unknown): User {
|
|
149
|
+
return UserSchema.parse(input);
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
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.
|
|
154
|
+
|
|
155
|
+
## No `as` casts
|
|
156
|
+
|
|
157
|
+
Every `as` is a potential runtime crash. Cast only after the type system has verified the claim.
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
import { z } from "zod";
|
|
161
|
+
|
|
162
|
+
// Don't
|
|
163
|
+
const user = data as User;
|
|
164
|
+
|
|
165
|
+
// Don't
|
|
166
|
+
function isUser(data: unknown): data is User {
|
|
167
|
+
return typeof data === "object" && data !== null && "id" in data;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Do
|
|
171
|
+
const userSchema = z.object({ id: z.string(), name: z.string() });
|
|
172
|
+
type User = z.infer<typeof userSchema>;
|
|
173
|
+
|
|
174
|
+
function parseUser(data: unknown): User {
|
|
175
|
+
return userSchema.parse(data);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
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.
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
type User = { id: string; name: string };
|
|
183
|
+
|
|
184
|
+
const userSchema: z.ZodType<User> = z.object({ id: z.string(), name: z.string() });
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
When refactoring an `as` out of existing code, identify why TypeScript can't infer:
|
|
188
|
+
|
|
189
|
+
- Missing discriminant: add one, switch to a discriminated union.
|
|
190
|
+
- Overly wide source type (e.g. `Record<string, unknown>`): narrow it.
|
|
191
|
+
- Untyped boundary: parse with the schema that owns the shape. Add a schema only where none exists.
|
|
192
|
+
- Genuinely inexpressible: use a branded type or `satisfies`.
|
|
193
|
+
|
|
194
|
+
## Narrowing hierarchy
|
|
195
|
+
|
|
196
|
+
From best to last-resort:
|
|
197
|
+
|
|
198
|
+
1. **Discriminated union switch / if.** Compiler narrows automatically.
|
|
199
|
+
2. **`in` operator.** `"key" in obj` narrows to variants containing that key.
|
|
200
|
+
3. **`typeof` / `instanceof`.** For primitives and class instances.
|
|
201
|
+
4. **User-defined type guard.** When the above aren't enough.
|
|
202
|
+
5. **`as` cast.** Only after validation.
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
function area(s: Shape): number {
|
|
206
|
+
if ("radius" in s) return Math.PI * s.radius ** 2; // narrowed to circle
|
|
207
|
+
return s.width * s.height; // narrowed to rect
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Type guards
|
|
212
|
+
|
|
213
|
+
A guard must actually verify the claim. A lying guard is worse than `as`.
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
function isCircle(s: Shape): s is Shape & { kind: "circle" } {
|
|
217
|
+
return s.kind === "circle";
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Prefer discriminant narrowing when possible.
|
|
222
|
+
|
|
223
|
+
## Exhaustiveness
|
|
224
|
+
|
|
225
|
+
In default arms, assign the discriminant to a `never`-typed local.
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
// Value-returning switch
|
|
229
|
+
function area(s: Shape): number {
|
|
230
|
+
switch (s.kind) {
|
|
231
|
+
case "circle":
|
|
232
|
+
return Math.PI * s.radius ** 2;
|
|
233
|
+
case "rect":
|
|
234
|
+
return s.width * s.height;
|
|
235
|
+
default: {
|
|
236
|
+
const _exhaustive: never = s;
|
|
237
|
+
return _exhaustive;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Void switch
|
|
243
|
+
function handle(s: Shape): void {
|
|
244
|
+
switch (s.kind) {
|
|
245
|
+
case "circle":
|
|
246
|
+
drawCircle(s);
|
|
247
|
+
break;
|
|
248
|
+
case "rect":
|
|
249
|
+
drawRect(s);
|
|
250
|
+
break;
|
|
251
|
+
default: {
|
|
252
|
+
const _exhaustive: never = s;
|
|
253
|
+
void _exhaustive;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Return-style in value-returning switches, void-style in statement switches.
|
|
260
|
+
|
|
261
|
+
## `satisfies` over `as`
|
|
262
|
+
|
|
263
|
+
`satisfies` validates without widening literal types.
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
// Don't. Widens, loses literal types.
|
|
267
|
+
const config = { theme: "dark", cols: 3 } as Config;
|
|
268
|
+
|
|
269
|
+
// Do. Validates AND preserves literal types.
|
|
270
|
+
const config = { theme: "dark", cols: 3 } satisfies Config;
|
|
271
|
+
// config.theme is "dark" (literal), not string
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
## Boundary validation
|
|
275
|
+
|
|
276
|
+
Validate once where data crosses in. Trust types inside. See the **boundary-discipline** principle skill.
|
|
277
|
+
|
|
278
|
+
- **Wire formats** (proto, JSON-RPC): parse with `ignoreUnknownFields` so forward-compatible changes don't break old clients.
|
|
279
|
+
- **Persisted JSON:** versioned blob with a try/catch around the parse.
|
|
280
|
+
- **Don't re-validate** deep in call chains.
|
|
281
|
+
|
|
282
|
+
## Schema-derived types
|
|
283
|
+
|
|
284
|
+
When a `.proto`, OpenAPI spec, GraphQL schema, or database migration already defines a shape, derive from the generated types instead of duplicating them.
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
// Don't. Duplicate shape, drifts when the schema changes.
|
|
288
|
+
type CheckSummary = {
|
|
289
|
+
totalCount: number;
|
|
290
|
+
checks: { name: string; status: string }[];
|
|
291
|
+
};
|
|
292
|
+
function renderChecks(s: CheckSummary) {
|
|
293
|
+
/* ... */
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// Do. Derive from the generated schema type.
|
|
297
|
+
import type { ChecksMessage } from "<generated module>";
|
|
298
|
+
function renderChecks(s: Pick<ChecksMessage, "totalCount" | "checks">) {
|
|
299
|
+
/* ... */
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Reach for `Pick`, `Omit`, `Parameters`, `ReturnType`, `Awaited`, `typeof` before writing a new interface.
|
|
304
|
+
|
|
305
|
+
## Object args
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
// Don't. Swap two args, still compiles.
|
|
309
|
+
openFile(uri, {
|
|
310
|
+
startLineNumber: 10,
|
|
311
|
+
startColumn: 1,
|
|
312
|
+
endLineNumber: 10,
|
|
313
|
+
endColumn: 1,
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// Do. Order-independent, self-documenting.
|
|
317
|
+
openFile({
|
|
318
|
+
uri,
|
|
319
|
+
selection: {
|
|
320
|
+
startLineNumber: 10,
|
|
321
|
+
startColumn: 1,
|
|
322
|
+
endLineNumber: 10,
|
|
323
|
+
endColumn: 1,
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
Skip on hot paths: per-frame render, tokenizers, parsers, anything in a tight loop where the allocation cost matters.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: unslop
|
|
3
|
+
description: Cut AI tells from any writing.
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Unslop
|
|
8
|
+
|
|
9
|
+
Edit text to remove AI patterns. Scan for the patterns below, then rewrite. Preserve meaning and match the intended tone.
|
|
10
|
+
|
|
11
|
+
## Patterns to detect and fix
|
|
12
|
+
|
|
13
|
+
Rule numbers are stable ids that other skills cite. A removed rule leaves a gap.
|
|
14
|
+
|
|
15
|
+
### Content
|
|
16
|
+
|
|
17
|
+
3. **Superficial -ing phrases.** "highlighting...", "ensuring...", "reflecting...", "showcasing...", "fostering...". Delete or expand with real sources.
|
|
18
|
+
5. **Vague attributions.** "Experts believe", "Industry reports suggest", "Some critics argue". Name the source or delete.
|
|
19
|
+
|
|
20
|
+
### Language
|
|
21
|
+
|
|
22
|
+
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.
|
|
23
|
+
8. **Fancy ways to say "is".** "serves as", "stands as", "boasts", "features". Say "is" or "has".
|
|
24
|
+
9. **"Not just X, but Y."** State the point directly instead.
|
|
25
|
+
10. **Rule of three.** Don't force ideas into groups of three. Use the natural number.
|
|
26
|
+
11. **Synonym cycling.** Protagonist, main character, central figure, hero all in one paragraph. Pick one, repeat it.
|
|
27
|
+
12. **False ranges.** "from X to Y" where X and Y aren't on a meaningful scale. List topics directly.
|
|
28
|
+
|
|
29
|
+
### Style
|
|
30
|
+
|
|
31
|
+
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.
|
|
32
|
+
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.
|
|
33
|
+
15. **Boldface overuse.** Don't bold every proper noun or acronym.
|
|
34
|
+
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.
|
|
35
|
+
17. **Title case headings.** Use sentence case.
|
|
36
|
+
18. **Decorative emojis.** Remove from headings and bullets.
|
|
37
|
+
19. **Curly quotes.** Use straight quotes.
|
|
38
|
+
|
|
39
|
+
### Communication artifacts
|
|
40
|
+
|
|
41
|
+
20. **Chatbot phrases.** "I hope this helps!", "Let me know if...", "Of course!", "Certainly!", "Found the smoking gun!" Remove.
|
|
42
|
+
22. **Sycophantic tone.** "Great question! You're absolutely right!" Respond directly.
|
|
43
|
+
|
|
44
|
+
### Filler
|
|
45
|
+
|
|
46
|
+
23. **Filler phrases.** "In order to" becomes "To". "Due to the fact that" becomes "Because". Delete "It is important to note that".
|
|
47
|
+
24. **Excessive hedging.** "could potentially possibly be argued that it might" becomes "may".
|
|
48
|
+
25. **Generic conclusions.** "The future looks bright." State specific plans or facts.
|
|
49
|
+
|
|
50
|
+
### Jargon
|
|
51
|
+
|
|
52
|
+
26. **Abstract metaphor nouns.** Substrate (base), wedge, wedge in (add), vector (way, method), locus, vantage, nexus, primitive as a noun, harness as a metaphor, surface as in "API surface", bedrock, scaffolding as a metaphor, modality, paradigm, gold-plating (more than the job needs), ratchet as a metaphor (the mechanism's real name, or a limit that only tightens), evacuate for moving code (move out), endgame (the last phase), north star, flywheel. These read as technical but usually have a plainer concrete word. Pick the concrete word.
|
|
53
|
+
|
|
54
|
+
### Plain speech
|
|
55
|
+
|
|
56
|
+
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.
|
|
57
|
+
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.
|
|
58
|
+
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.
|
|
59
|
+
30. **Cut adverbs, or use a stronger verb.** "runs quickly" becomes "is fast" or the number, and "significantly improves" becomes the measured delta. An adverb propping up a weak verb means the verb is wrong.
|
|
60
|
+
31. **Prefer the plain word.** "utilize" and "leverage" become "use", "facilitate" becomes "help", "numerous" becomes "many", "in the event that" becomes "if". The fancier synonym is rarely clearer.
|
|
61
|
+
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.
|
|
62
|
+
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,100 @@
|
|
|
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
|
+
> DSH port of pstack. `pstack_subagent` replaces Cursor's Task tool, and `role` replaces Cursor model slugs. Full mapping: `../../docs/harness/dsh.md`.
|
|
10
|
+
|
|
11
|
+
Investigate the motivation and intent behind code. The companion `how` skill answers what the code does and how it works; read its `SKILL.md` at its absolute resource path when you need it. `why` answers what forces led to its shape.
|
|
12
|
+
|
|
13
|
+
Each spawn below names a role key. `pstack_subagent` reads the route from `$DSH_HOME/pstack-models.md` on every delegation, and a role the file does not name inherits the parent route. Never invent a model id: this package cannot know which routes a deployment serves. An effort is different, because the target model advertises its own list and `pstack_subagent` checks your value against it and names the real values when it refuses, so predict no ladder beyond that. Read the Subagents section of the `poteto-mode` skill at its absolute resource path before you spawn anything. Start from the level the role line names, raise it for hard work and lower it for routine work by passing `reasoningEffort`; a child that cannot call `set_reasoning_effort` keeps the level you gave it.
|
|
14
|
+
|
|
15
|
+
Every spawn is `agent: "general"` with a brief that forbids writes. **Do not swap in a narrower preset or tool set.** A narrower set can drop MCP tools, which disables the MCP-backed investigators and the synthesizer's citation spot-checks. Investigators still must not write anything, and each brief says so; that rule is an instruction, not a sandbox, so check `git status` before believing a report.
|
|
16
|
+
|
|
17
|
+
## Operating Posture
|
|
18
|
+
|
|
19
|
+
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.
|
|
20
|
+
|
|
21
|
+
## Step 1. Understand the Target and the Question
|
|
22
|
+
|
|
23
|
+
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.
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
## Step 2. Establish the Code Anchor
|
|
28
|
+
|
|
29
|
+
Before spawning investigators, build the seed context inline: file paths and line ranges, key symbols (functions, classes, constants), the last few commits touching the target, PR numbers from merge commits (pattern `(#1234)` in the subject line), and any linked ticket IDs. Run `git blame -L <start>,<end> <file>` for last-touch commits, `git log --follow -p -- <file>` for full history with patches through renames, `git log --oneline -20 -- <file>` for recent commits with PR numbers visible, and `git log -1 --format=%B <commit>` to extract PR numbers. Then pull the PR bodies and discussion for any substantive commit: `gh pr view <number> --json title,body,author,createdAt,mergedAt,labels,closingIssuesReferences,comments,reviews`. This anchor goes to every investigator and to the synthesizer.
|
|
30
|
+
|
|
31
|
+
## Step 3. Spawn Parallel Investigators
|
|
32
|
+
|
|
33
|
+
**Default to the full parallel investigation.** The goal is a complete coverage map, not a minimal one. Document the null, don't skip the search.
|
|
34
|
+
|
|
35
|
+
### Discovery
|
|
36
|
+
|
|
37
|
+
Before spawning investigators, list the tools this Session actually has, and treat an MCP as available only when its own tools appear in that list. The DSH harness exposes no MCP directory to inspect, and this port does not read one: an MCP that is absent from the tool list is a recorded gap, never a guess.
|
|
38
|
+
|
|
39
|
+
Map each available MCP to one evidence category:
|
|
40
|
+
|
|
41
|
+
1. Source control history
|
|
42
|
+
2. Issue / ticket tracker
|
|
43
|
+
3. Long-form documents
|
|
44
|
+
4. Real-time team chat
|
|
45
|
+
5. Infrastructure observability
|
|
46
|
+
6. Error / exception tracking
|
|
47
|
+
7. Product analytics warehouse
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
Spawn one investigator per category that has a matching MCP, all in one batch of `pstack_subagent` calls so they start together, each owning exactly one tool or MCP. Don't ask one agent to cover multiple MCPs. Use `role: "why investigators"`. Each call returns a child id and the reports arrive as completion notices, so nothing polls and the synthesizer waits for every investigator that was started.
|
|
52
|
+
|
|
53
|
+
Each investigator's prompt is `references/investigator-prompt.md` filled in, plus:
|
|
54
|
+
- the category playbook `references/sources/<source>.md` for the selected MCP, adapted from the examples in `references/source-playbook.md`
|
|
55
|
+
- `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)
|
|
56
|
+
- the code anchor and the user's original question
|
|
57
|
+
|
|
58
|
+
### Investigator roster, one per available evidence category
|
|
59
|
+
|
|
60
|
+
Each category below is uniquely positioned to surface one shape of "why", shown after "Best at". Use it to know what to expect back, to name a gap when a category returns empty, and, only in the rare provably-irrelevant case, to justify a skip.
|
|
61
|
+
|
|
62
|
+
1. **Source control** (git history, `gh` for PRs, code comments, tests). Always spawn, the only guaranteed source. Best at *implementation-time rationale captured during review*.
|
|
63
|
+
2. **Issue / ticket tracker** (e.g. Linear, Jira, GitHub Issues, Plane, Shortcut MCP). Best at *the product or business forcing function*. Strongest when the why is external to engineering.
|
|
64
|
+
3. **Long-form documents** (e.g. Notion, Confluence, Google Docs, Coda MCP). Best at *long-form design rationale*, written out before it becomes code.
|
|
65
|
+
4. **Real-time team chat** (e.g. Slack, Discord, Microsoft Teams, Mattermost MCP). Best at *real-time deliberation that never reached a doc*. Especially important when the source control, ticket, and doc paper trail is thin.
|
|
66
|
+
5. **Infrastructure observability** (e.g. Datadog, New Relic, Honeycomb, Grafana, Splunk MCP). Best at *infrastructure and runtime reality that motivated the code*. Strongest when the target reacts to an infra signal (timeouts, retries, rate limits, circuit breakers).
|
|
67
|
+
6. **Error / exception tracking** (e.g. Sentry, Rollbar, Bugsnag, Airbrake MCP). Best at *the specific exceptions and error trajectories that motivated defensive or corrective code*. Strongest for catch blocks, null guards, type checks, retries, and other defenses.
|
|
68
|
+
7. **Product analytics warehouse** (e.g. Databricks, Snowflake, BigQuery, ClickHouse, dbt, Redshift MCP). Best at *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.
|
|
69
|
+
|
|
70
|
+
### When to skip an investigator
|
|
71
|
+
|
|
72
|
+
Only with an **explicit, written justification** that goes in the final Sources Consulted. Two valid reasons:
|
|
73
|
+
|
|
74
|
+
- **No MCP is available for that category** in this environment. Flag it as a gap, not a choice: "Real-time team chat skipped. No matching MCP available, so the conversational record was not searchable."
|
|
75
|
+
- **The source is provably irrelevant**, not just "probably irrelevant." A high bar: "Error / exception tracking skipped. Target is a build-time script with no runtime code path."
|
|
76
|
+
|
|
77
|
+
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.
|
|
78
|
+
|
|
79
|
+
## Step 4. Synthesize
|
|
80
|
+
|
|
81
|
+
Spawn one synthesizer with `role: "why synthesizer"`. It gets:
|
|
82
|
+
1. The investigator findings, including any null results and any categories skipped with justification
|
|
83
|
+
2. The code anchor
|
|
84
|
+
3. The user's original question
|
|
85
|
+
4. The epistemics framework from `references/epistemics.md`
|
|
86
|
+
5. The synthesizer prompt template from `references/synthesizer-prompt.md`
|
|
87
|
+
|
|
88
|
+
## Step 5. Present
|
|
89
|
+
|
|
90
|
+
Present the synthesizer's output to the user. You may lightly edit for clarity or add context from the conversation, but **do not rewrite the confidence language**.
|
|
91
|
+
|
|
92
|
+
## Output Format
|
|
93
|
+
|
|
94
|
+
The 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.
|
|
95
|
+
|
|
96
|
+
After Sources Consulted, if the user's `why` question is a precursor to changing this code, convert the lineage findings into a Preserve / Change / Avoid / Risk constraint set for planning the change.
|
|
97
|
+
|
|
98
|
+
## Common Failure Modes to Avoid
|
|
99
|
+
|
|
100
|
+
- **Recency bias**. Assuming the most recent commit is authoritative. The current shape is often the accretion of many earlier decisions. Trace back.
|