ramstack 0.1.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 +44 -0
- package/agents/comment-sicko.md +32 -0
- package/agents/poteto-agent.md +9 -0
- package/cli/rstack.mjs +539 -0
- package/package.json +29 -0
- package/skills/architect/README.md +25 -0
- package/skills/architect/SKILL.md +83 -0
- package/skills/architect/agents/openai.yaml +5 -0
- package/skills/architect/references/design-red-flags.md +33 -0
- package/skills/architect/references/rationale-template.md +35 -0
- package/skills/architect/references/runner-prompt.md +20 -0
- package/skills/arena/README.md +21 -0
- package/skills/arena/SKILL.md +71 -0
- package/skills/arena/agents/openai.yaml +5 -0
- package/skills/automate-me/README.md +21 -0
- package/skills/automate-me/SKILL.md +109 -0
- package/skills/automate-me/agents/openai.yaml +5 -0
- package/skills/blast-radius/README.md +21 -0
- package/skills/blast-radius/SKILL.md +50 -0
- package/skills/blast-radius/agents/openai.yaml +5 -0
- package/skills/bro/README.md +16 -0
- package/skills/bro/SKILL.md +7 -0
- package/skills/bro/agents/openai.yaml +5 -0
- package/skills/create-verification-skill/README.md +22 -0
- package/skills/create-verification-skill/SKILL.md +44 -0
- package/skills/create-verification-skill/agents/openai.yaml +5 -0
- package/skills/create-verification-skill/references/feature-map-example/README.md +47 -0
- package/skills/create-verification-skill/references/feature-map-example/create-note.md +39 -0
- package/skills/create-verification-skill/references/feature-map-example/search.md +45 -0
- package/skills/figure-it-out/README.md +22 -0
- package/skills/figure-it-out/SKILL.md +55 -0
- package/skills/figure-it-out/agents/openai.yaml +5 -0
- package/skills/how/README.md +25 -0
- package/skills/how/SKILL.md +134 -0
- package/skills/how/agents/openai.yaml +3 -0
- package/skills/how/references/critic-prompt.md +59 -0
- package/skills/how/references/critique-rubric.md +58 -0
- package/skills/how/references/explainer-prompt.md +55 -0
- package/skills/how/references/explorer-prompt.md +52 -0
- package/skills/interrogate/README.md +21 -0
- package/skills/interrogate/SKILL.md +112 -0
- package/skills/interrogate/agents/openai.yaml +5 -0
- package/skills/interrogate/references/code-quality-review.md +47 -0
- package/skills/interrogate/references/lead-judgment.md +58 -0
- package/skills/interrogate/references/reviewer-prompt.md +72 -0
- package/skills/interrogate/references/rubric.md +77 -0
- package/skills/maintain-verification-skill/README.md +21 -0
- package/skills/maintain-verification-skill/SKILL.md +39 -0
- package/skills/maintain-verification-skill/agents/openai.yaml +5 -0
- package/skills/no-comments/README.md +22 -0
- package/skills/no-comments/SKILL.md +24 -0
- package/skills/no-comments/agents/openai.yaml +5 -0
- package/skills/poteto-mode/README.md +26 -0
- package/skills/poteto-mode/SKILL.md +140 -0
- package/skills/poteto-mode/agents/openai.yaml +5 -0
- package/skills/poteto-mode/playbooks/authoring-a-skill.md +13 -0
- package/skills/poteto-mode/playbooks/autonomous-run.md +13 -0
- package/skills/poteto-mode/playbooks/autopilot-full.md +13 -0
- package/skills/poteto-mode/playbooks/autopilot-stack.md +16 -0
- package/skills/poteto-mode/playbooks/babysit.md +27 -0
- package/skills/poteto-mode/playbooks/bug-fix.md +17 -0
- package/skills/poteto-mode/playbooks/eval.md +27 -0
- package/skills/poteto-mode/playbooks/feature.md +21 -0
- package/skills/poteto-mode/playbooks/hillclimb.md +21 -0
- package/skills/poteto-mode/playbooks/investigation.md +14 -0
- package/skills/poteto-mode/playbooks/multi-phase-plan.md +3 -0
- package/skills/poteto-mode/playbooks/opening-a-pr.md +11 -0
- package/skills/poteto-mode/playbooks/orchestrate.md +113 -0
- package/skills/poteto-mode/playbooks/pause-safely.md +10 -0
- package/skills/poteto-mode/playbooks/perf-issue.md +24 -0
- package/skills/poteto-mode/playbooks/prototype.md +14 -0
- package/skills/poteto-mode/playbooks/refactoring.md +16 -0
- package/skills/poteto-mode/playbooks/runtime-forensics.md +11 -0
- package/skills/poteto-mode/playbooks/session-pickup.md +13 -0
- package/skills/poteto-mode/playbooks/shipping.md +20 -0
- package/skills/poteto-mode/playbooks/trace-forensics.md +14 -0
- package/skills/poteto-mode/playbooks/visual-parity.md +11 -0
- package/skills/poteto-mode/playbooks/worktree-cleanup.md +14 -0
- package/skills/poteto-mode/references/bugbot-triage.md +142 -0
- package/skills/poteto-mode/references/plan.md +105 -0
- package/skills/poteto-mode/scripts/bootstrap.ts +62 -0
- package/skills/poteto-mode/scripts/bun.lock +67 -0
- package/skills/poteto-mode/scripts/orch/orch.test.ts +634 -0
- package/skills/poteto-mode/scripts/orch/orch.ts +578 -0
- package/skills/poteto-mode/scripts/orch/store.ts +1607 -0
- package/skills/poteto-mode/scripts/package.json +16 -0
- package/skills/poteto-mode/scripts/watch-pr/cli.test.ts +224 -0
- package/skills/poteto-mode/scripts/watch-pr/cli.ts +223 -0
- package/skills/poteto-mode/scripts/watch-pr/fakes.test-helper.ts +118 -0
- package/skills/poteto-mode/scripts/watch-pr/github.test.ts +306 -0
- package/skills/poteto-mode/scripts/watch-pr/github.ts +699 -0
- package/skills/poteto-mode/scripts/watch-pr/policy.test.ts +420 -0
- package/skills/poteto-mode/scripts/watch-pr/policy.ts +832 -0
- package/skills/poteto-mode/scripts/watch-pr/render.ts +169 -0
- package/skills/poteto-mode/scripts/watch-pr/tsconfig.json +13 -0
- package/skills/poteto-mode/scripts/watch-pr/types.compile.ts +93 -0
- package/skills/poteto-mode/scripts/watch-pr/types.ts +401 -0
- package/skills/poteto-mode/scripts/watch-pr/watch-pr +6 -0
- package/skills/poteto-mode/scripts/worktree-audit.sh +86 -0
- package/skills/principle-boundary-discipline/README.md +17 -0
- package/skills/principle-boundary-discipline/SKILL.md +34 -0
- package/skills/principle-boundary-discipline/agents/openai.yaml +5 -0
- package/skills/principle-build-the-lever/README.md +17 -0
- package/skills/principle-build-the-lever/SKILL.md +23 -0
- package/skills/principle-build-the-lever/agents/openai.yaml +5 -0
- package/skills/principle-encode-lessons-in-structure/README.md +17 -0
- package/skills/principle-encode-lessons-in-structure/SKILL.md +31 -0
- package/skills/principle-encode-lessons-in-structure/agents/openai.yaml +5 -0
- package/skills/principle-exhaust-the-design-space/README.md +17 -0
- package/skills/principle-exhaust-the-design-space/SKILL.md +21 -0
- package/skills/principle-exhaust-the-design-space/agents/openai.yaml +5 -0
- package/skills/principle-experience-first/README.md +17 -0
- package/skills/principle-experience-first/SKILL.md +19 -0
- package/skills/principle-experience-first/agents/openai.yaml +5 -0
- package/skills/principle-fix-root-causes/README.md +17 -0
- package/skills/principle-fix-root-causes/SKILL.md +23 -0
- package/skills/principle-fix-root-causes/agents/openai.yaml +5 -0
- package/skills/principle-foundational-thinking/README.md +17 -0
- package/skills/principle-foundational-thinking/SKILL.md +21 -0
- package/skills/principle-foundational-thinking/agents/openai.yaml +5 -0
- package/skills/principle-guard-the-context-window/README.md +17 -0
- package/skills/principle-guard-the-context-window/SKILL.md +17 -0
- package/skills/principle-guard-the-context-window/agents/openai.yaml +5 -0
- package/skills/principle-laziness-protocol/README.md +17 -0
- package/skills/principle-laziness-protocol/SKILL.md +18 -0
- package/skills/principle-laziness-protocol/agents/openai.yaml +5 -0
- package/skills/principle-make-operations-idempotent/README.md +17 -0
- package/skills/principle-make-operations-idempotent/SKILL.md +24 -0
- package/skills/principle-make-operations-idempotent/agents/openai.yaml +5 -0
- package/skills/principle-migrate-callers-then-delete-legacy-apis/README.md +17 -0
- package/skills/principle-migrate-callers-then-delete-legacy-apis/SKILL.md +22 -0
- package/skills/principle-migrate-callers-then-delete-legacy-apis/agents/openai.yaml +5 -0
- package/skills/principle-minimize-reader-load/README.md +17 -0
- package/skills/principle-minimize-reader-load/SKILL.md +23 -0
- package/skills/principle-minimize-reader-load/agents/openai.yaml +5 -0
- package/skills/principle-model-the-domain/README.md +17 -0
- package/skills/principle-model-the-domain/SKILL.md +26 -0
- package/skills/principle-model-the-domain/agents/openai.yaml +5 -0
- package/skills/principle-never-block-on-the-human/README.md +16 -0
- package/skills/principle-never-block-on-the-human/SKILL.md +23 -0
- package/skills/principle-never-block-on-the-human/agents/openai.yaml +5 -0
- package/skills/principle-outcome-oriented-execution/README.md +16 -0
- package/skills/principle-outcome-oriented-execution/SKILL.md +22 -0
- package/skills/principle-outcome-oriented-execution/agents/openai.yaml +5 -0
- package/skills/principle-prove-it-works/README.md +18 -0
- package/skills/principle-prove-it-works/SKILL.md +33 -0
- package/skills/principle-prove-it-works/agents/openai.yaml +5 -0
- package/skills/principle-redesign-from-first-principles/README.md +16 -0
- package/skills/principle-redesign-from-first-principles/SKILL.md +16 -0
- package/skills/principle-redesign-from-first-principles/agents/openai.yaml +5 -0
- package/skills/principle-separate-before-serializing-shared-state/README.md +16 -0
- package/skills/principle-separate-before-serializing-shared-state/SKILL.md +16 -0
- package/skills/principle-separate-before-serializing-shared-state/agents/openai.yaml +5 -0
- package/skills/principle-sequence-verifiable-units/README.md +18 -0
- package/skills/principle-sequence-verifiable-units/SKILL.md +22 -0
- package/skills/principle-sequence-verifiable-units/agents/openai.yaml +5 -0
- package/skills/principle-subtract-before-you-add/README.md +17 -0
- package/skills/principle-subtract-before-you-add/SKILL.md +22 -0
- package/skills/principle-subtract-before-you-add/agents/openai.yaml +5 -0
- package/skills/principle-type-system-discipline/README.md +19 -0
- package/skills/principle-type-system-discipline/SKILL.md +31 -0
- package/skills/principle-type-system-discipline/agents/openai.yaml +5 -0
- package/skills/recall/README.md +23 -0
- package/skills/recall/SKILL.md +35 -0
- package/skills/recall/agents/openai.yaml +5 -0
- package/skills/reflect/README.md +24 -0
- package/skills/reflect/SKILL.md +77 -0
- package/skills/reflect/agents/openai.yaml +5 -0
- package/skills/reflect/references/divergent-reviewer.md +43 -0
- package/skills/reflect/references/judgment-reviewer.md +42 -0
- package/skills/reflect/references/synthesizer.md +56 -0
- package/skills/reflect/references/tooling-reviewer.md +57 -0
- package/skills/setup-rstack/README.md +25 -0
- package/skills/setup-rstack/SKILL.md +81 -0
- package/skills/setup-rstack/agents/openai.yaml +3 -0
- package/skills/show-me-your-work/README.md +23 -0
- package/skills/show-me-your-work/SKILL.md +82 -0
- package/skills/show-me-your-work/agents/openai.yaml +5 -0
- package/skills/show-me-your-work/references/decision-log-template.tsv +1 -0
- package/skills/show-me-your-work/scripts/log.sh +40 -0
- package/skills/swarm/README.md +21 -0
- package/skills/swarm/SKILL.md +46 -0
- package/skills/swarm/agents/openai.yaml +5 -0
- package/skills/tdd/README.md +21 -0
- package/skills/tdd/SKILL.md +44 -0
- package/skills/tdd/agents/openai.yaml +5 -0
- package/skills/teach/README.md +22 -0
- package/skills/teach/SKILL.md +21 -0
- package/skills/teach/agents/openai.yaml +5 -0
- package/skills/technical-writing/README.md +23 -0
- package/skills/technical-writing/SKILL.md +130 -0
- package/skills/technical-writing/agents/openai.yaml +5 -0
- package/skills/typescript-best-practices/README.md +22 -0
- package/skills/typescript-best-practices/SKILL.md +28 -0
- package/skills/typescript-best-practices/agents/openai.yaml +3 -0
- package/skills/typescript-best-practices/references/patterns.md +292 -0
- package/skills/unslop/README.md +21 -0
- package/skills/unslop/SKILL.md +80 -0
- package/skills/unslop/agents/openai.yaml +3 -0
- package/skills/why/README.md +26 -0
- package/skills/why/SKILL.md +229 -0
- package/skills/why/agents/openai.yaml +3 -0
- package/skills/why/references/epistemics.md +144 -0
- package/skills/why/references/investigator-prompt.md +103 -0
- package/skills/why/references/source-playbook.md +17 -0
- package/skills/why/references/sources/code-archaeology.md +88 -0
- package/skills/why/references/sources/databricks.md +70 -0
- package/skills/why/references/sources/datadog.md +99 -0
- package/skills/why/references/sources/incident-postmortem.md +15 -0
- package/skills/why/references/sources/linear.md +48 -0
- package/skills/why/references/sources/notion.md +55 -0
- package/skills/why/references/sources/sentry.md +100 -0
- package/skills/why/references/sources/slack.md +54 -0
- package/skills/why/references/synthesizer-prompt.md +135 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# TDD
|
|
2
|
+
|
|
3
|
+
Write a failing regression test before fixing a bug. The test encodes the intended behavior and proves the fix.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
- The user asks for TDD, a failing test, or a regression test
|
|
8
|
+
- The bug has an obvious, cheap local test target
|
|
9
|
+
- Do not use when the test path is unclear, expensive, or integration-heavy
|
|
10
|
+
|
|
11
|
+
## What it produces
|
|
12
|
+
|
|
13
|
+
A focused regression test that fails before the fix and passes after it. The final report names the failing-before evidence, the passing-after run, and any nearby validation performed.
|
|
14
|
+
|
|
15
|
+
## How it works
|
|
16
|
+
|
|
17
|
+
Identifies the intended and current behavior, chooses the narrowest executable check (preferring existing test infrastructure), writes the failing test, confirms it fails for the right reason, fixes the bug, and reruns. If a failing test is impractical, the skill explains why and uses the closest alternative verification (script, manual reproduction, browser automation, snapshot comparison).
|
|
18
|
+
|
|
19
|
+
## Related
|
|
20
|
+
|
|
21
|
+
- [SKILL.md](SKILL.md)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: tdd
|
|
3
|
+
description: "Use only when the user explicitly asks for TDD, a failing test, or a regression test, OR when the bug has an obvious cheap local test target. Skip when the test path is unclear, expensive, integration-heavy, or not requested."
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# TDD Bug Fix
|
|
8
|
+
|
|
9
|
+
When fixing a bug with a clear, cheap test path, make the broken behavior executable before changing production code. The goal is a focused regression test that fails before the fix and passes after it.
|
|
10
|
+
|
|
11
|
+
Do not force a test when it would be impractical. If the available test would require broad harness setup, brittle mocks, slow end-to-end infrastructure, production-only state, vague reproduction steps, or large unrelated fixture churn, skip adding a new test and use the closest useful verification instead.
|
|
12
|
+
|
|
13
|
+
## Workflow
|
|
14
|
+
|
|
15
|
+
1. **Understand the bug.** Identify the intended behavior, current behavior, affected path, and smallest observable reproduction.
|
|
16
|
+
2. **Choose the narrowest executable check.** Prefer the closest unit, component, integration, or regression test already used for that codepath. If no practical test path is obvious, do not create one from scratch just to satisfy the workflow.
|
|
17
|
+
3. **Write the failing test first.** Add the smallest focused test that would have caught the bug. The test should encode intended behavior, not mirror the current implementation.
|
|
18
|
+
4. **Run the new test before fixing.** Confirm it fails for the intended reason. If it passes or fails for an unrelated reason, correct the test or reproduction before editing the implementation.
|
|
19
|
+
5. **Fix the bug.** Make the smallest production change that satisfies the intended behavior while preserving nearby contracts.
|
|
20
|
+
6. **Rerun the regression test.** Confirm the test now passes.
|
|
21
|
+
7. **Run nearby validation.** Run relevant adjacent tests, type checks, lint, or scenario checks when the change has broader risk.
|
|
22
|
+
|
|
23
|
+
## If a Failing Test Is Impractical
|
|
24
|
+
|
|
25
|
+
Do not silently skip the regression step. Before fixing, explicitly explain why a failing test is impossible or not worth the cost, then choose the closest executable regression check available. Examples include a targeted script, manual reproduction command, browser automation, snapshot comparison, log assertion, or focused integration check.
|
|
26
|
+
|
|
27
|
+
Prefer no new test over a bad test. A bad test is one that mostly tests mocks, encodes current implementation details, depends on timing or unrelated global state, needs expensive infrastructure for a small fix, or would be deleted immediately after proving the fix.
|
|
28
|
+
|
|
29
|
+
## Guardrails
|
|
30
|
+
|
|
31
|
+
- Do not change tests merely to match a wrong implementation.
|
|
32
|
+
- Do not weaken existing assertions unless the expected behavior has genuinely changed and the reason is clear.
|
|
33
|
+
- Keep the regression test focused on the bug; avoid broad fixture churn or unrelated coverage expansion.
|
|
34
|
+
- Do not add tests when the practical signal is weak; use manual or scripted verification and say why.
|
|
35
|
+
- If the bug is flaky, make the test deterministic where possible and document the signal being locked down.
|
|
36
|
+
- If the bug exposes a broader class of failures, first land the focused regression path, then consider additional sibling coverage.
|
|
37
|
+
|
|
38
|
+
## Final Response
|
|
39
|
+
|
|
40
|
+
Report the evidence, not just the outcome:
|
|
41
|
+
|
|
42
|
+
- Name the failing-before test or executable check and the failure it produced.
|
|
43
|
+
- Name the passing-after test run and any nearby validation performed.
|
|
44
|
+
- If failing-before evidence could not be demonstrated, state why and describe the closest regression check used instead.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Teach
|
|
2
|
+
|
|
3
|
+
Explain a body of work so a person actually understands it. Runs `how` and `why`, then weaves the findings into one plain explanation.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
- "Teach me this", "help me really understand X"
|
|
8
|
+
- "Explain this change or subsystem to me"
|
|
9
|
+
|
|
10
|
+
## What it produces
|
|
11
|
+
|
|
12
|
+
A plain-language explanation of what something is, how it works, and why it was built that way. Includes diagrams built up step by step when the subject has three or more moving parts.
|
|
13
|
+
|
|
14
|
+
## How it works
|
|
15
|
+
|
|
16
|
+
Decides what the person should walk away understanding based on why they are asking and what they already know. Runs `how` and `why` in parallel to gather the mechanics and the rationale. Blends the results into one explanation at the person's pace: a plain definition first, then how it works, then the deeper reasons. Uses the image generation tool for spatial concepts. Keeps `why`'s confidence language intact. Stops and lets the person go deeper where they want.
|
|
17
|
+
|
|
18
|
+
## Related
|
|
19
|
+
|
|
20
|
+
- [SKILL.md](SKILL.md)
|
|
21
|
+
- [how](../how/)
|
|
22
|
+
- [why](../why/)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: teach
|
|
3
|
+
description: "Explain a body of work plainly so a person actually understands it. Runs the `how` and `why` skills and weaves what they find into one clear explanation. Use for 'teach me this', 'help me really understand X', 'explain this change or subsystem to me'."
|
|
4
|
+
disable-model-invocation: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Teach
|
|
8
|
+
|
|
9
|
+
**You explain what a thing is, how it works, and why it's built that way, in one plain account at the person's pace. The goal is that they understand it, not that you change anything.** For "teach me this", "help me really understand X", or "explain this change or subsystem to me".
|
|
10
|
+
|
|
11
|
+
Teach sits on top of `how` and `why`. Get your bearings on what the work is and what it touches, then run `how` for how it works and `why` for why it's that way. Those are real skill invocations that do their own digging. Blend what they find into one plain explanation, lead with what matters to the person, and go deeper when they ask. Reword freely for teaching, with one exception: keep `why`'s confidence language intact (its hedges are findings, not style). Let those skills do the investigation. Don't redo it by hand.
|
|
12
|
+
|
|
13
|
+
1. Decide the few things they should walk away understanding. Choose them from why they're asking (about to change it, reviewing it, debugging it, new to it) and what they already know, both read from the conversation, not quizzed out of them. Skip what they plainly already know. Put the depth where their question is.
|
|
14
|
+
2. Let `how` and `why` do the work, don't redo it. Read the code yourself to get oriented, then run `how` for how it works and `why` for why. Run them in parallel and combine the results. Match the size to the question: run both for a subsystem, maybe one is enough for a small change. Keep `why` narrow by default since its full sweep is slow: put the narrowing in the ask itself (a scoped question, git plus a source or two) so `why` records the skipped categories per its own contract, and widen it only when the reasons are the point.
|
|
15
|
+
3. Start with a plain definition. Name the thing and say what it is in general terms, the way a senior engineer would say it out loud, with its common name if it has one. Then tie it to the case in front of you ("in X, we use this to ...") and build from there: how it works, the deeper reasons, the edge cases. Explain how it works, don't just name it. For each part, explain the idea so it clicks: the problem it solves and how it actually works. Walk through what happens as the person does the thing (opens a long chat, scrolls up) when that is what makes it land. Listing functions and constants is reference, not teaching. Don't print framing labels ("the one idea to hold onto", "the thing to walk away with", "the key insight", "at its core", "TL;DR"). Give the smallest complete answer first, a sentence or two, not a dense paragraph, then stop. Add layers when they ask. Never a wall of text.
|
|
16
|
+
4. Keep it a conversation, not a lecture or a performance. Offer to go deeper or move on, and follow their lead. No quizzes. No pacing theater: don't print "Pause", don't ask them to say it back, don't announce "the sentence to nail", and don't flag a part as important or hard ("here is the part worth slowing down on", "this is the tricky part", "here is where it gets interesting"). Just say it. When you would pause, stop and let them respond. Running one-shot with no live human, deliver it cleanly and put any offer to go deeper at the end.
|
|
17
|
+
5. Show, don't only tell, and build the picture up diagram by diagram. Open the diff, the code, or the debugger when that is the fastest way to land it. Draw when a picture lands faster than words. For anything with three or more moving parts, do not draw one diagram with all of them at once. Draw a short series instead, where each diagram redraws the last and adds a single part, so the reader watches the system assemble. That series is not a wall. It is the opposite of one, since each step is small and adds exactly one idea. A single all-at-once diagram, especially one saved for the end, is a reference, not teaching. Concretely, to teach a flow from A to B to C, draw it three times. First A to B. Then redraw and add C. Then redraw and add the return edge or the next piece. Three small growing diagrams beat one crowded diagram. Match the medium to the idea, and use both kinds when both help. A mermaid diagram fits a flow or structure where the labels carry the meaning. When the idea is spatial, like layout, overlap, scroll position, or a before and after, reach for the image-generation tool and draw it marker-on-whiteboard style with a few short labels, since image models garble long text. Generate that picture, don't settle for describing it in words. The build-up rule holds for generated images too. A single simple point needs no figure. A visual earns its place by teaching, not decorating.
|
|
18
|
+
|
|
19
|
+
Write every response through the **unslop** skill, in plain spoken English, the way you'd explain it to a colleague. Be tight, not terse: cut filler and hedging, keep the part that makes it click. Padding is the enemy, not ideas. Don't list functions and constants like a changelog. State the concrete mechanism, not a metaphor, a framing, or a preview of what is coming. This is the target density: "Virtualization runs in two parts, one for rendering and one for loading from disk. When an item scrolls out past the buffer, both its DOM node and its in-memory data are evicted." Normal sentence case, not all-lowercase. No em dashes. Prefer periods over commas. Keep each sentence to one or two commas. If clauses pile up, split them into separate sentences. Give each concept one name and keep it, since switching between synonyms for the same thing (bubble, message, row) makes the reader re-derive that they are the same. Avoid mirror sentences ("A without B, or B without A") and tidy closers ("the rest follows", "it all falls out"). The words in these steps are directions to you, not labels to print. Don't echo the scaffolding as headers or stock phrases.
|
|
20
|
+
|
|
21
|
+
**Reply:** the explanation itself, never a report about what you did or delivered. Lead with the main point, then the plain account of what it is, how it works, and why, and the threads worth chasing with `how` or `why`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Technical writing
|
|
2
|
+
|
|
3
|
+
Four-layer writing standard: Diataxis structure, Google developer style sentences, STE instruction rules, Global English syntax. The goal is writing a tired engineer understands on the first read.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
- `/technical-writing`
|
|
8
|
+
- Writing or reviewing docs, RFCs, READMEs, PR descriptions, or commit messages
|
|
9
|
+
|
|
10
|
+
## What it produces
|
|
11
|
+
|
|
12
|
+
Prose that follows the standard. The review checklist at the end of the SKILL.md is the acceptance test.
|
|
13
|
+
|
|
14
|
+
## How it works
|
|
15
|
+
|
|
16
|
+
Four layers, applied in order. Diataxis picks the document mode (tutorial, how-to, reference, explanation). Google developer style sets the voice (active, "you", commands for instructions, condition before instruction). STE limits each sentence to one thought. Global English removes ambiguity (every pronoun points at one thing, no dropped verbs, no slashes). Three overriding rules: cut every word that does no work, use the short word, and break any rule that makes a sentence worse.
|
|
17
|
+
|
|
18
|
+
Also applies the `unslop` skill to every doc it touches.
|
|
19
|
+
|
|
20
|
+
## Related
|
|
21
|
+
|
|
22
|
+
- [SKILL.md](SKILL.md)
|
|
23
|
+
- [unslop](../unslop/)
|
|
@@ -0,0 +1,130 @@
|
|
|
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
|
+
The goal is writing a tired engineer understands on the first read. Four layers get you there, one question each: what kind of document is this, how do sentences address the reader, how much does each sentence carry, and can any sentence be read two ways. Apply all four.
|
|
10
|
+
|
|
11
|
+
Three rules sit above the layers:
|
|
12
|
+
|
|
13
|
+
- **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.
|
|
14
|
+
- **Use the short, everyday word.** "Use", not "utilize". "Help", not "facilitate". "Do", not "perform". A long word has to buy its length with precision.
|
|
15
|
+
- **When a rule makes a sentence worse, fix the sentence another way or leave it alone.** The rules serve the reader. A sentence that follows every rule and sounds like a machine wrote it has failed.
|
|
16
|
+
|
|
17
|
+
The codebase is the word list. Write the real symbol, file, flag, or command name, not a synonym or a description of it.
|
|
18
|
+
|
|
19
|
+
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. Add new offenders to `unslop`'s abstract-metaphor rule with their replacement.
|
|
20
|
+
|
|
21
|
+
## Vary the rhythm
|
|
22
|
+
|
|
23
|
+
The layers decide what a document says and how much each sentence carries. A doc can obey all of them and still read machine-written: every sentence clipped short, no view anywhere, nothing specific.
|
|
24
|
+
|
|
25
|
+
- Mix sentence lengths on purpose. Short sentences land a point. Longer ones that take their time carry a fact with its condition or consequence.
|
|
26
|
+
- 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.
|
|
27
|
+
- 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.
|
|
28
|
+
- Be specific over sterile. Not "schema changes can cause issues" but "a column rename fails the build".
|
|
29
|
+
|
|
30
|
+
## Pick the mode first (Diátaxis)
|
|
31
|
+
|
|
32
|
+
One document, one mode. Two questions pick it: does the content inform action (doing) or understanding (thinking), and does it serve learning or work?
|
|
33
|
+
|
|
34
|
+
- Action + learning: **tutorial**.
|
|
35
|
+
- Action + work: **how-to**.
|
|
36
|
+
- Understanding + work: **reference**.
|
|
37
|
+
- Understanding + learning: **explanation**.
|
|
38
|
+
|
|
39
|
+
Use the compass on a whole document or on one sentence. Reach for it whenever you feel unsure what you are writing. Gut feel is often wrong here.
|
|
40
|
+
|
|
41
|
+
**Tutorial: learning by doing.** You are the teacher. 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. Teaching pauses break the lesson. Stay concrete. Write as "we", in commands: "First, do x. Now, do y."
|
|
42
|
+
|
|
43
|
+
**How-to: steps to a goal.** Solve a problem a person has, not an operation the machine can perform. Assume competence. 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".
|
|
44
|
+
|
|
45
|
+
**Reference: facts for lookup.** Describe. 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, so it stays true.
|
|
46
|
+
|
|
47
|
+
**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.
|
|
48
|
+
|
|
49
|
+
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.
|
|
50
|
+
|
|
51
|
+
Source: diataxis.fr, fetched 2026-07-18.
|
|
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." The reader skips what does not apply.
|
|
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
|
+
- Read the awkward sentence aloud. If it stays awkward, rewrite it.
|
|
63
|
+
- 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.
|
|
64
|
+
- 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.
|
|
65
|
+
- Numbered lists for sequences, bullets for everything else. Introduce a list with a complete sentence. Keep items parallel.
|
|
66
|
+
- Code goes in code font. UI elements go in bold. Use serial commas. Drop "etc." and say up front that a list is partial.
|
|
67
|
+
|
|
68
|
+
Source: developers.google.com/style, fetched 2026-07-18.
|
|
69
|
+
|
|
70
|
+
## Make statements load one at a time (STE rules)
|
|
71
|
+
|
|
72
|
+
- One instruction per sentence. One thought per sentence everywhere else.
|
|
73
|
+
- Split instructions longer than about 20 words and other sentences longer than about 25.
|
|
74
|
+
- Put the warning or condition before the step it guards: "If hot oil touches your skin, injuries can occur."
|
|
75
|
+
- Keep "the" and "a": "Remove backup file" reads two ways. "Remove the backup file" reads one.
|
|
76
|
+
- Give each word one meaning and one job, then keep it. If "check" means inspect, don't also use it for restrain.
|
|
77
|
+
- Pick one word per action and stick to it: "start", not "start" here and "initiate" there.
|
|
78
|
+
- Write procedures as direct commands, never as narration and never in the passive: "Install the component", not "the component must be installed".
|
|
79
|
+
- Avoid "-ing" words where you can. They take too many grammatical jobs and breed misreadings.
|
|
80
|
+
|
|
81
|
+
Source: asd-ste100.org (Issue 9, 2025), fetched 2026-07-18. The numbered rules and dictionary live in the spec PDF. The principles above are the transferable core.
|
|
82
|
+
|
|
83
|
+
## Leave no sentence open to two readings (Global English)
|
|
84
|
+
|
|
85
|
+
- Keep words like "only" and "not" next to the word they change: "only fails on growth" and "fails only on growth" say different things.
|
|
86
|
+
- Break up long noun strings: "the proto import budget check script" becomes "the script that checks the proto-import budget".
|
|
87
|
+
- 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.
|
|
88
|
+
- Don't drop verbs: "Phase 1 moves the converters and Phase 2 the runtime" leaves Phase 2 without one. Give it one.
|
|
89
|
+
- Keep the small words that show structure. "Ensure that the switch is off" keeps "that" because it makes the sentence parse one way. Never trade clarity for word count.
|
|
90
|
+
- 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.
|
|
91
|
+
- Say which parts "and" or "or" joins when a sentence can group two ways. "Both...and", "either...or", and "if...then" are free disambiguators.
|
|
92
|
+
- Use periods, not semicolons. Replace an em dash with a new sentence.
|
|
93
|
+
- Make text in parentheses a full grammatical unit or its own sentence. Never form plurals with "(s)".
|
|
94
|
+
- No slashes: write "a, b, or both" instead of "a/b" or "and/or".
|
|
95
|
+
- 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. Rewording an unchanged sentence between edits costs the same way: don't churn what didn't change.
|
|
96
|
+
- Skip idioms, colloquialisms, Latin abbreviations, and metaphors. A non-native reader, a translator, and an agent all parse plain constructions best.
|
|
97
|
+
|
|
98
|
+
Source: Kohl, The Global English Style Guide (SAS Press). Guideline text fetched from the Internet Archive and the SAS sample chapter, 2026-07-18.
|
|
99
|
+
|
|
100
|
+
## Voice and repo specifics
|
|
101
|
+
|
|
102
|
+
- Apply the **unslop** skill to every doc this skill touches. That skill owns the slop-pattern catalog: AI vocabulary, filler, hedging, formatting tells.
|
|
103
|
+
- PR descriptions and commit messages are writing too. Every layer except Diátaxis applies to them.
|
|
104
|
+
- Product UI strings are not documentation. Use your product's copy guidelines for those.
|
|
105
|
+
- Indent code snippets with tabs. Write real paths and real symbols. Make every count or tree claim true at the commit that lands it, and include the command that regenerates it.
|
|
106
|
+
|
|
107
|
+
## Worked example
|
|
108
|
+
|
|
109
|
+
Before:
|
|
110
|
+
|
|
111
|
+
> 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.
|
|
112
|
+
|
|
113
|
+
After:
|
|
114
|
+
|
|
115
|
+
> `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.
|
|
116
|
+
|
|
117
|
+
The fixes, by layer: "configuration is performed" becomes "`budget.mjs` reads", so someone does something (Google). "Ratchet" goes away. The script's real filename does the naming (jargon rule). The five-noun string breaks up into plain clauses (Global English). The hedge "note that it's important to remember" is deleted (cut every word that does no work). The failure condition moves ahead of the step it explains (STE). The buried "should only be done when lowering" becomes a command with "only" next to its verb (STE). "If exceeded" gets a subject: the count (Global English).
|
|
118
|
+
|
|
119
|
+
## Review checklist
|
|
120
|
+
|
|
121
|
+
Apply to any prose this skill covers. Item 1 applies only to document sets:
|
|
122
|
+
|
|
123
|
+
1. Is each file one Diátaxis mode, with links where modes meet?
|
|
124
|
+
2. Is every instruction written as a command, with its condition in front?
|
|
125
|
+
3. Does any sentence carry two instructions or two thoughts? Split it.
|
|
126
|
+
4. Can any word be cut without losing meaning? Cut it.
|
|
127
|
+
5. Is "only" next to the word it changes? Does every "it" point at one thing? Does every clause keep its verb?
|
|
128
|
+
6. Does each thing have exactly one name across the docs?
|
|
129
|
+
7. Would a developer say these words out loud? Replace invented metaphors and fancy synonyms with the plain word or the real symbol name.
|
|
130
|
+
8. Are all symbols, paths, and counts real at this commit, with the commands that regenerate the counts?
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# TypeScript best practices
|
|
2
|
+
|
|
3
|
+
TypeScript rules grounded in the `type-system-discipline` principle. Applied when reading or editing `.ts` or `.tsx` files.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
- Reading or editing any `.ts` or `.tsx` file
|
|
8
|
+
|
|
9
|
+
## What it produces
|
|
10
|
+
|
|
11
|
+
Code that follows the rule table: discriminated unions over optional-field bags, branded primitives, `unknown` over `any`, no `as` casts, exhaustive matching, boundary validation, schema-derived types, object arguments, real tests, and structured telemetry.
|
|
12
|
+
|
|
13
|
+
## How it works
|
|
14
|
+
|
|
15
|
+
A rule table with 14 entries covering type modeling, narrowing, validation, testing, and telemetry. Each rule has a one-line summary. Concrete syntax examples live in `references/patterns.md`.
|
|
16
|
+
|
|
17
|
+
## Related
|
|
18
|
+
|
|
19
|
+
- [SKILL.md](SKILL.md)
|
|
20
|
+
- [references/patterns.md](references/patterns.md)
|
|
21
|
+
- [principle-type-system-discipline](../principle-type-system-discipline/)
|
|
22
|
+
- [principle-boundary-discipline](../principle-boundary-discipline/)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: typescript-best-practices
|
|
3
|
+
description: TypeScript best practices. Use when reading or editing any .ts or .tsx file.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# TypeScript best practices
|
|
7
|
+
|
|
8
|
+
Apply the **type-system-discipline** principle skill first; this skill grounds it in TypeScript syntax.
|
|
9
|
+
|
|
10
|
+
| Rule | Summary |
|
|
11
|
+
|------|---------|
|
|
12
|
+
| Discriminated unions | Model variants with a `kind` literal discriminant so impossible states can't be represented. No optional-field bags. |
|
|
13
|
+
| Branded types | Brand primitives with `& { readonly __brand: "X" }` so they can't be mixed up. Validate once at creation. |
|
|
14
|
+
| 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. |
|
|
15
|
+
| 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. |
|
|
16
|
+
| `unknown` over `any` | External data is `unknown`. `any` disables type checking everywhere it touches. |
|
|
17
|
+
| No `as` casts | Every `as` is a runtime crash waiting. Cast only after validation. |
|
|
18
|
+
| Narrowing hierarchy | Discriminant switch > `in` operator > `typeof`/`instanceof` > user-defined type guard > `as`. |
|
|
19
|
+
| 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`. |
|
|
20
|
+
| Exhaustiveness | Inline `const _exhaustive: never = x;` in default arms so the compiler errors when a new variant is added. |
|
|
21
|
+
| `satisfies` over `as` | Validates the value without widening literal types. |
|
|
22
|
+
| Boundary validation | Validate where data crosses in; trust types inside. See the **boundary-discipline** principle skill. |
|
|
23
|
+
| Schema-derived types | Reach for `Pick`/`Omit`/`Parameters`/`ReturnType`/`Awaited`/`typeof` before declaring a new interface. |
|
|
24
|
+
| Object args | Pass objects, not positional, so argument order is self-documenting. Skip on hot paths (per-frame render, tokenizers, parsers). |
|
|
25
|
+
| 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. |
|
|
26
|
+
| Structured telemetry | Prefer structured logger diagnostics with enough context to debug from an id. No `console.log` in shipped code. |
|
|
27
|
+
|
|
28
|
+
Examples: `references/patterns.md`.
|
|
@@ -0,0 +1,292 @@
|
|
|
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 creation; 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
|
+
If a bug forces the question "wait, can this combination actually happen?", the type is too loose. 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. Adding is easier than subtracting.
|
|
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. TypeScript has no refinement types (no `arr.length % 2 === 0` at the type level); you don't need one:
|
|
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. A `Pairs<T>` is an even-length list under the interpretation you give it, the same way `{ start, durationMs }` is a range. 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. Either way the empty case lands at the call site, the one place that knows what empty means.
|
|
109
|
+
|
|
110
|
+
## `unknown` over `any`
|
|
111
|
+
|
|
112
|
+
`any` disables type checking for everything it touches. 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
|
+
## No `as` casts
|
|
131
|
+
|
|
132
|
+
Every `as` is a potential runtime crash. Cast only after the type system has verified the claim.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
// Don't
|
|
136
|
+
const user = data as User;
|
|
137
|
+
|
|
138
|
+
// Do. Earn the cast at the boundary.
|
|
139
|
+
function parseUser(data: unknown): User {
|
|
140
|
+
if (typeof data !== "object" || data === null) {
|
|
141
|
+
throw new Error("expected object");
|
|
142
|
+
}
|
|
143
|
+
if (!("id" in data) || typeof (data as Record<string, unknown>).id !== "string") {
|
|
144
|
+
throw new Error("expected id");
|
|
145
|
+
}
|
|
146
|
+
// ... validate all fields
|
|
147
|
+
return data as User; // OK, earned cast after full validation
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
When refactoring an `as` out of existing code, identify why TypeScript can't infer:
|
|
152
|
+
|
|
153
|
+
- Missing discriminant: add one, switch to a discriminated union.
|
|
154
|
+
- Overly wide source type (e.g. `Record<string, unknown>`): narrow it.
|
|
155
|
+
- Untyped boundary: add a parse function or schema.
|
|
156
|
+
- Genuinely inexpressible: use a branded type or `satisfies`.
|
|
157
|
+
|
|
158
|
+
## Narrowing hierarchy
|
|
159
|
+
|
|
160
|
+
From best to last-resort:
|
|
161
|
+
|
|
162
|
+
1. **Discriminated union switch / if.** Compiler narrows automatically.
|
|
163
|
+
2. **`in` operator.** `"key" in obj` narrows to variants containing that key.
|
|
164
|
+
3. **`typeof` / `instanceof`.** For primitives and class instances.
|
|
165
|
+
4. **User-defined type guard.** When the above aren't enough.
|
|
166
|
+
5. **`as` cast.** Only after validation.
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
function area(s: Shape): number {
|
|
170
|
+
if ("radius" in s) return Math.PI * s.radius ** 2; // narrowed to circle
|
|
171
|
+
return s.width * s.height; // narrowed to rect
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Type guards
|
|
176
|
+
|
|
177
|
+
A guard must actually verify the claim. A lying guard is worse than `as` because the bug hides behind a name that says it's safe.
|
|
178
|
+
|
|
179
|
+
```ts
|
|
180
|
+
function isCircle(s: Shape): s is Shape & { kind: "circle" } {
|
|
181
|
+
return s.kind === "circle";
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Prefer discriminant narrowing when possible. The guard adds a layer the reader has to follow.
|
|
186
|
+
|
|
187
|
+
## Exhaustiveness
|
|
188
|
+
|
|
189
|
+
In default arms, assign the discriminant to a `never`-typed local. The compiler errors if a new variant is added without handling.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
// Value-returning switch
|
|
193
|
+
function area(s: Shape): number {
|
|
194
|
+
switch (s.kind) {
|
|
195
|
+
case "circle":
|
|
196
|
+
return Math.PI * s.radius ** 2;
|
|
197
|
+
case "rect":
|
|
198
|
+
return s.width * s.height;
|
|
199
|
+
default: {
|
|
200
|
+
const _exhaustive: never = s;
|
|
201
|
+
return _exhaustive;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Void switch
|
|
207
|
+
function handle(s: Shape): void {
|
|
208
|
+
switch (s.kind) {
|
|
209
|
+
case "circle":
|
|
210
|
+
drawCircle(s);
|
|
211
|
+
break;
|
|
212
|
+
case "rect":
|
|
213
|
+
drawRect(s);
|
|
214
|
+
break;
|
|
215
|
+
default: {
|
|
216
|
+
const _exhaustive: never = s;
|
|
217
|
+
void _exhaustive;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Return-style in value-returning switches; void-style in statement switches.
|
|
224
|
+
|
|
225
|
+
## `satisfies` over `as`
|
|
226
|
+
|
|
227
|
+
`satisfies` validates without widening literal types.
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
// Don't. Widens, loses literal types.
|
|
231
|
+
const config = { theme: "dark", cols: 3 } as Config;
|
|
232
|
+
|
|
233
|
+
// Do. Validates AND preserves literal types.
|
|
234
|
+
const config = { theme: "dark", cols: 3 } satisfies Config;
|
|
235
|
+
// config.theme is "dark" (literal), not string
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Boundary validation
|
|
239
|
+
|
|
240
|
+
Validate once where data crosses in; trust types inside. See the **boundary-discipline** principle skill.
|
|
241
|
+
|
|
242
|
+
- **Wire formats** (proto, JSON-RPC): parse with `ignoreUnknownFields` so forward-compatible changes don't break old clients.
|
|
243
|
+
- **Persisted JSON:** versioned blob with a try/catch around the parse.
|
|
244
|
+
- **Don't re-validate** deep in call chains.
|
|
245
|
+
|
|
246
|
+
## Schema-derived types
|
|
247
|
+
|
|
248
|
+
When a `.proto`, OpenAPI spec, GraphQL schema, or database migration already defines a shape, derive from the generated types instead of duplicating them.
|
|
249
|
+
|
|
250
|
+
```ts
|
|
251
|
+
// Don't. Duplicate shape, drifts when the schema changes.
|
|
252
|
+
type CheckSummary = {
|
|
253
|
+
totalCount: number;
|
|
254
|
+
checks: { name: string; status: string }[];
|
|
255
|
+
};
|
|
256
|
+
function renderChecks(s: CheckSummary) {
|
|
257
|
+
/* ... */
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Do. Derive from the generated schema type.
|
|
261
|
+
import type { ChecksMessage } from "<generated module>";
|
|
262
|
+
function renderChecks(s: Pick<ChecksMessage, "totalCount" | "checks">) {
|
|
263
|
+
/* ... */
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Reach for `Pick`, `Omit`, `Parameters`, `ReturnType`, `Awaited`, `typeof` before writing a new interface.
|
|
268
|
+
|
|
269
|
+
## Object args
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
// Don't. Swap two args, still compiles.
|
|
273
|
+
openFile(uri, {
|
|
274
|
+
startLineNumber: 10,
|
|
275
|
+
startColumn: 1,
|
|
276
|
+
endLineNumber: 10,
|
|
277
|
+
endColumn: 1,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Do. Order-independent, self-documenting.
|
|
281
|
+
openFile({
|
|
282
|
+
uri,
|
|
283
|
+
selection: {
|
|
284
|
+
startLineNumber: 10,
|
|
285
|
+
startColumn: 1,
|
|
286
|
+
endLineNumber: 10,
|
|
287
|
+
endColumn: 1,
|
|
288
|
+
},
|
|
289
|
+
});
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Skip on hot paths: per-frame render, tokenizers, parsers, anything in a tight loop where the allocation cost matters.
|