From b48549b560f80d262154d0026ee283fefab1b945 Mon Sep 17 00:00:00 2001 From: chen <23054115+cwkang1998@users.noreply.github.com> Date: Mon, 16 Nov 2026 05:14:58 +0700 Subject: [PATCH 1/3] feat: sync upstream pstack 0.15.42 (bf0c7cd) Takes the rest of 0.15.42 and pins upstream.lock.json to bf0c7cd. - how starts one read-only explorer that explores and explains in one pass. The explorers, the explainer and their prompt templates are deleted. - why answers from the commit and PR record in one paragraph. Its investigators, synthesizer and reference files are deleted. - recall starts its own researcher per source instead of borrowing why's investigators. - poteto-mode no longer routes to how, and the playbooks, architect, no-comments, teach and blast-radius trace the code directly. - The how explorer, how explainer, why investigators and why synthesizer config lines and their routing rows are retired. --- skills/architect/SKILL.md | 4 +- skills/arena/SKILL.md | 2 +- skills/blast-radius/SKILL.md | 4 +- skills/how/SKILL.md | 29 +--- skills/how/references/explainer-prompt.md | 55 -------- skills/how/references/explorer-prompt.md | 35 ----- skills/no-comments/SKILL.md | 2 +- skills/poteto-help/SKILL.md | 2 +- skills/poteto-mode/SKILL.md | 1 - skills/poteto-mode/playbooks/bug-fix.md | 2 +- skills/poteto-mode/playbooks/feature.md | 2 +- skills/poteto-mode/playbooks/hillclimb.md | 2 +- skills/poteto-mode/playbooks/investigation.md | 4 +- .../poteto-mode/playbooks/multi-phase-plan.md | 2 +- skills/poteto-mode/playbooks/perf-issue.md | 2 +- skills/poteto-mode/playbooks/refactoring.md | 2 +- skills/pstack-omp/SKILL.md | 4 - skills/recall/SKILL.md | 4 +- skills/reflect/references/synthesizer.md | 2 +- skills/reproduce-and-fix-issues/SKILL.md | 2 +- skills/setup-benny/SKILL.md | 1 - skills/setup-pstack/SKILL.md | 26 ++-- skills/sharpen/SKILL.md | 2 +- skills/statechart/scripts/backends/mermaid.ts | 58 +++++++- skills/statechart/scripts/run.ts | 35 ++++- skills/statechart/scripts/test/chart.test.ts | 43 ++++++ skills/statechart/scripts/test/cli.test.ts | 41 +++--- skills/statechart/scripts/test/corpus.test.ts | 38 ++++++ .../scripts/test/corpus/Login/chart.mmd | 3 +- skills/statechart/scripts/test/drawn.ts | 20 +++ skills/statechart/scripts/test/labels.ts | 27 ++-- skills/statechart/scripts/test/render.test.ts | 64 +++++++++ skills/teach/SKILL.md | 2 +- skills/triage-issue-reports/SKILL.md | 2 +- skills/why/SKILL.md | 95 +------------ skills/why/references/epistemics.md | 71 ---------- skills/why/references/investigator-prompt.md | 84 ------------ skills/why/references/source-playbook.md | 17 --- .../references/sources/code-archaeology.md | 51 ------- skills/why/references/sources/databricks.md | 70 ---------- skills/why/references/sources/datadog.md | 97 ------------- .../references/sources/incident-postmortem.md | 5 - skills/why/references/sources/linear.md | 48 ------- skills/why/references/sources/notion.md | 55 -------- skills/why/references/sources/sentry.md | 66 --------- skills/why/references/sources/slack.md | 17 --- skills/why/references/synthesizer-prompt.md | 129 ------------------ upstream.lock.json | 2 +- 48 files changed, 330 insertions(+), 1001 deletions(-) delete mode 100644 skills/how/references/explainer-prompt.md delete mode 100644 skills/how/references/explorer-prompt.md create mode 100644 skills/statechart/scripts/test/drawn.ts delete mode 100644 skills/why/references/epistemics.md delete mode 100644 skills/why/references/investigator-prompt.md delete mode 100644 skills/why/references/source-playbook.md delete mode 100644 skills/why/references/sources/code-archaeology.md delete mode 100644 skills/why/references/sources/databricks.md delete mode 100644 skills/why/references/sources/datadog.md delete mode 100644 skills/why/references/sources/incident-postmortem.md delete mode 100644 skills/why/references/sources/linear.md delete mode 100644 skills/why/references/sources/notion.md delete mode 100644 skills/why/references/sources/sentry.md delete mode 100644 skills/why/references/sources/slack.md delete mode 100644 skills/why/references/synthesizer-prompt.md diff --git a/skills/architect/SKILL.md b/skills/architect/SKILL.md index 139e371..6419a4e 100644 --- a/skills/architect/SKILL.md +++ b/skills/architect/SKILL.md @@ -22,7 +22,7 @@ Open a todolist with one entry per phase before starting. ## Phase A: Ground the problem -Build a real mental model of every system the new code touches. Run the **how** skill over the relevant subsystems. Naming a file isn't grounding. Produce the architectural explanation `how` prescribes. If the design redefines ownership or layering, also run the **why** skill on the existing shape so the rationale becomes a constraint, not a guess. +Build a real mental model of every system the new code touches. Trace the relevant subsystems. Naming a file isn't grounding. Write an architectural explanation of each. If the design redefines ownership or layering, also run the **why** skill on the existing shape so the rationale becomes a constraint, not a guess. Skip Phase A only when the work is genuinely greenfield with no surrounding system to integrate. @@ -71,7 +71,7 @@ Use judgment. A few edge cases don't condemn an architecture. Some problems are When you scrap: -1. Re-run the **how** skill over what's been built. +1. Trace what's been built. 2. Redesign as if the new constraints had been day-one assumptions, per redesign-from-first-principles. 3. Subtract before adding, per the **subtract-before-you-add** principle skill. The new sketch should be smaller than the old one before it grows. 4. Return to Phase B and re-run arena. diff --git a/skills/arena/SKILL.md b/skills/arena/SKILL.md index db607d3..5f6f970 100644 --- a/skills/arena/SKILL.md +++ b/skills/arena/SKILL.md @@ -27,7 +27,7 @@ If a candidate produces no output, proceed with N-1 and note the dropout. ## Phase C: Cross-judge -After all Phase B candidates complete, choose one entry from the `arena cross-judge pool` line in `$PSTACK_CONFIG (or .pstack/config.md)`, and start entry N on its judge agent per the Model routing section of the **pstack-omp** skill. If the configuration or that line is missing, choose from the canonical `reviewer` and `planner` roles. Spawn one readonly judge subagent. The judge is never from the parent's family. Here a family is the model an entry names, not the canonical role from Phase A step 3, because the parent fills no role. Try only the entries from another family, in pool order. If that section's check stops an entry, or its spawn fails, report it and move to the next entry. If no entry from another family runs, skip the judge, pick the base alone in Phase D, and say so. The judge sees the rubric and the candidates by path label, scores each criterion, and recommends a base with rationale. It runs in parallel with your reading in Phase D. Don't spawn it while candidates are still writing. +After all Phase B candidates complete, choose one entry from the `arena cross-judge pool` line in `$PSTACK_CONFIG (or .pstack/config.md)`, and start entry N on its judge agent per the Model routing section of the **pstack-omp** skill. If the configuration or that line is missing, choose from the canonical `reviewer` and `planner` roles. Spawn one readonly judge subagent. The judge is never from the parent's vendor. A vendor is the provider behind the model an entry names, not the canonical role from Phase A step 3, because the parent fills no role. Every Claude model, Fable included, is one vendor. Try only the entries from another vendor, in pool order. If that section's check stops an entry, or its spawn fails, report it and move to the next entry. If no entry from another vendor runs, skip the judge, pick the base alone in Phase D, and say so. The judge sees the rubric and the candidates by path label, scores each criterion, and recommends a base with rationale. It runs in parallel with your reading in Phase D. Don't spawn it while candidates are still writing. ## Phase D: Pick a base diff --git a/skills/blast-radius/SKILL.md b/skills/blast-radius/SKILL.md index b296cce..1f5c951 100644 --- a/skills/blast-radius/SKILL.md +++ b/skills/blast-radius/SKILL.md @@ -30,10 +30,10 @@ Step 4 is usually one small script that imports the same library the app ships a ## Steps -1. Read the change. The diff, the symbols it adds, changes, and deletes, and what it now does differently, including the part the diff doesn't spell out. Use `why` step 2 to pull the PR and commits. +1. Read the change. The diff, the symbols it adds, changes, and deletes, and what it now does differently, including the part the diff doesn't spell out. Pull the PR and its commits. 2. Find the one fact it's safe because of. Most changes that look risky are safe because of a single fact, like "this call only drops already-dead cache entries and does nothing else". Find that fact. If it holds, most risky cases are cleared at once. Spend your time here, not on a long list of maybes. 3. Look where grep stops. Read the source of the library you call, and check its pinned version and any local patch. Work out when things run: microtasks, unmount and teardown, Solid versus React. Follow what a symbol search misses: the JSON an API returns, a DB column, a wire format, another language reading the same bytes, a feature flag, code three hops downstream. -4. Be honest about each risk. Give it a real chance of happening and a real cost if it does. Keep the risks you confirmed. List the ones you checked and cleared separately. Same rules as `why`. Cite a real `file:line`, a search that finds nothing is still an answer, and never make up a caller or an API. +4. Be honest about each risk. Give it a real chance of happening and a real cost if it does. Keep the risks you confirmed. List the ones you checked and cleared separately. Cite a real `file:line`, a search that finds nothing is still an answer, and never make up a caller or an API. 5. Prove the one fact. Write a script or test that runs the real code, run it, and paste what happened. 6. For a big or wide change, run it as an `arena`. Ask more than one model the same question and merge the answers. Different models catch different real bugs. diff --git a/skills/how/SKILL.md b/skills/how/SKILL.md index aae2da8..fd3e5e3 100644 --- a/skills/how/SKILL.md +++ b/skills/how/SKILL.md @@ -6,33 +6,18 @@ disable-model-invocation: true # How -Follow the [portable runtime contract](../pstack-omp/references/runtime.md) for explorer and synthesizer roles, model choices, and host fallbacks. +Follow the [portable runtime contract](../pstack-omp/references/runtime.md) for roles and host fallbacks. -Explore the codebase to answer "how does X work?" questions. Produce architectural explanations at the level of a senior engineer onboarding onto a subsystem, enough to build a working mental model, not so much that it reads like annotated source code. - -Every spawn is a read-only host task runner subagent. Explorers use the `how explorer` line in `$PSTACK_CONFIG (or .pstack/config.md)` (default role `explorer`), and every explainer uses the `how explainer` line (default role `synthesizer`). Start the agent the Model routing section of the **pstack-omp** skill names for each line, and use the role's default agent if the configuration or the line is missing. If that section's check stops a spawn, or the spawn fails, stop and report it. Set each child's reasoning effort for the job through the task runner's effort setting when the host exposes it, per the Delegation section of the **poteto-mode** skill. - -## 1. Assess complexity +Explore the codebase to answer "how does X work?" questions. If the scope is ambiguous, state your interpretation and explore. The user can redirect. -- **Simple** (a single module, a small utility, a narrow question such as "how does function X work"): no explorers. Spawn one explainer that explores and explains in one pass, built from `references/explainer-prompt.md` without the explorer-findings section. Go to step 4. -- **Complex** (a subsystem spanning multiple files or services, a cross-cutting feature, a full architectural overview): go to step 2. - -When in doubt, take the simple path. - -## 2. Explore (complex only) - -Decompose the question into 2 to 4 angles, each a distinct slice of the subsystem. Spawn all explorers in a single message, each with `references/explorer-prompt.md` and its angle filled in. - -## 3. Synthesize (complex only) - -Once all explorers have returned, spawn one explainer with `references/explainer-prompt.md` and every explorer's findings filled in. +## 1. Explain -## 4. Present +Start one read-only canonical `explorer` subagent that explores and explains in one pass. Give it the user's question and this brief: -Present the explainer's output. Light edits for clarity or context from the conversation are fine. Do not substantially rewrite it. +> You are writing an architectural explanation for a senior engineer. Explore the codebase and write an explanation that a senior engineer unfamiliar with this area could read and walk away with a solid mental model. They should understand the architecture well enough to start working in it confidently. You have read-only access to the codebase. -## Output format +## 2. Present -The explanation uses the sections defined in `references/explainer-prompt.md`, dropping any that do not apply: Overview, Key Concepts, How It Works, Where Things Live, Gotchas. +Present the subagent's output. Light edits for clarity or context from the conversation are fine. Do not substantially rewrite it. diff --git a/skills/how/references/explainer-prompt.md b/skills/how/references/explainer-prompt.md deleted file mode 100644 index 3a36fb6..0000000 --- a/skills/how/references/explainer-prompt.md +++ /dev/null @@ -1,55 +0,0 @@ -# Explainer Prompt Template - -Build the explainer subagent's prompt from this template. Fill in the placeholders. - ---- - -You are writing an architectural explanation for a senior engineer. Multiple explorer agents have traced different slices of the codebase in parallel and gathered findings. Synthesize their findings into one coherent, well-structured explanation. - -## Original Question - -> {QUESTION} - -## Explorer Findings - -{EXPLORER_FINDINGS_ALL} - -## Instructions - -The explorers each investigated a different angle of the same subsystem. Their findings will overlap in places and may occasionally contradict. Reconcile them. Merge overlapping descriptions, resolve contradictions by checking the code yourself, and combine the separate slices into a unified picture. - -Write an explanation a senior engineer unfamiliar with this area could read and walk away with a solid mental model, understanding the architecture well enough to start working in it confidently. - -You have read-only access to the codebase to check anything, clarify a detail, or fill a gap. Use Read, Grep, and Glob as needed. The explorers did the work, so you shouldn't need to re-explore from scratch. - -## Output Format - -Use this structure, adapted to what makes sense for the question. Not every section is needed for every question. - -### Overview -1-2 paragraphs. What is this thing, what does it do, why does it exist. Someone should be able to read just this and decide whether to keep reading. - -### Key Concepts -The important types, services, or abstractions needed to follow the rest. Brief definitions, not exhaustive. - -### How It Works -The core of the explanation, and the longest section. Walk through the flow: what triggers it, what happens step by step, where data goes, what the decision points are. - -Use prose, not pseudocode. Reference specific files and functions so the reader knows where to look, but don't dump large code blocks unless a snippet is essential to a point. - -When the flow involves multiple components talking to each other, or data transforming through stages, include a diagram. Use mermaid (```mermaid) for structured flows (sequence diagrams, flowcharts, component graphs) or ASCII art for simpler relationships where mermaid would be overkill. Use your judgment. A diagram should clarify, not decorate. If prose covers the flow, skip the diagram. - -### Where Things Live -A brief file/directory map. Just the ones someone would need to start working here. - -### Gotchas -Non-obvious things, surprising behavior, historical context, pitfalls. Skip this section if there's nothing worth calling out. - -## Communication Style - -- Use concrete language, not abstractions-about-abstractions -- Say "the `UserService` calls `AuthClient.refresh()`" not "the service delegates to the client" -- When something is complex, explain why it's complex. Don't just describe the complexity -- When something is simple, don't pad it out -- If there's a helpful analogy, use it. If there isn't, don't force one -- If the explorers flagged open questions or gaps, acknowledge them rather than hiding them diff --git a/skills/how/references/explorer-prompt.md b/skills/how/references/explorer-prompt.md deleted file mode 100644 index 724bacf..0000000 --- a/skills/how/references/explorer-prompt.md +++ /dev/null @@ -1,35 +0,0 @@ -# Explorer Prompt Template - -Build each explorer subagent's prompt from this template. Fill in the placeholders. - ---- - -Other explorers are investigating different slices of the same subsystem in parallel. Don't try to cover everything. Focus on your assigned angle and go deep. - -## Question - -> {QUESTION} - -## Your Exploration Angle - -{EXPLORATION_ANGLE} - -## Output - -### Components Found -The key types, services, classes, and abstractions. For each: name, file path, and a one-sentence description of what it does. - -### Flow -The execution flow step by step. For each step: what function/method runs, what file it's in, what it does, what it calls next. Include the data that flows between steps. - -### Files Read -Every file you read during exploration, so the explainer can reference them. - -### Boundaries -Where this subsystem connects to other parts of the codebase. The inputs and outputs. - -### Non-Obvious Things -Anything surprising, historically motivated, or easy to get wrong. Things that look like they should work one way but work another. - -### Open Questions -Anything you couldn't fully trace or understand. Be honest about gaps. diff --git a/skills/no-comments/SKILL.md b/skills/no-comments/SKILL.md index 1aa8a5a..446efec 100644 --- a/skills/no-comments/SKILL.md +++ b/skills/no-comments/SKILL.md @@ -19,7 +19,7 @@ Use the caller's files or diff. Otherwise use the current diff against the base ## Steps 1. Spawn the custom `comment-sicko` agent through the host task runner, a direct compatibility call per the **pstack-omp** skill. Pass the scope. Set each child's reasoning effort for the job through the task runner's effort setting when the host exposes it, per the Delegation section of the **poteto-mode** skill. Do not restate its rules. If the live task inventory lacks `comment-sicko`, launch a fresh canonical `reviewer` child for the no-comments objective instead and report that the specialized reviewer did not run. -2. Inspect its report and diff. Reject application-code edits, scope escapes, exception-protected deletions, misstated `MUST KILL` reasons, and flags that treat kept intentional code as guilty. Reshape flags on our-code surprises stay actionable. Do not restore those comments. A keep survives only with proof it is about something we cannot change. Audit missed scoped lint and TypeScript suppressions. Correctness or safety suppressions stay actionable `MUST KILL`s. Restore deletions only with exact exceptions and scoped proof. Before accepting thin `IMPORTANT` or `do not remove` kills or keeps, run `/how` or `/why` on their symbol. If a kill is ambiguous, do not restore. If a keep is refuted or still ambiguous, delete it. Revert and rerun one rejected report with the failure named. Reject a second, report it open, and fail `/no-comments`. +2. Inspect its report and diff. Reject application-code edits, scope escapes, exception-protected deletions, misstated `MUST KILL` reasons, and flags that treat kept intentional code as guilty. Reshape flags on our-code surprises stay actionable. Do not restore those comments. A keep survives only with proof it is about something we cannot change. Audit missed scoped lint and TypeScript suppressions. Correctness or safety suppressions stay actionable `MUST KILL`s. Restore deletions only with exact exceptions and scoped proof. Before accepting thin `IMPORTANT` or `do not remove` kills or keeps, trace their symbol or run `/why` on it. If a kill is ambiguous, do not restore. If a keep is refuted or still ambiguous, delete it. Revert and rerun one rejected report with the failure named. Reject a second, report it open, and fail `/no-comments`. 3. Fix trivial accepted flags directly by deleting a dead path, dropping a parameter, or using the real API. If any fix needs a shape, run `/architect` once for the accepted set and surrounding code. Stop at the sketch. Architect shapes. Step 4 implements. 4. Implement the smallest root-cause fix in scope. Remove every named workaround. If the root cause is out of scope, land the smallest in-scope fix and report the rest open. The **principle-fix-root-causes** and **principle-redesign-from-first-principles** skills guide intent only. Neither authorizes widening the fence nor fixing instances outside it. Never bolt on symptom guards. 5. Constraint comments say `do not remove`, `do not change wording`, or `talk to X before changing`. Leave keeps about things we cannot change. Offer the cheapest in-scope type, runtime, test, or CI lint. Wait for interactive approval. Unattended and eval require caller pre-approval. If approved, encode then delete. Otherwise delete, report the constraint open, and sketch out-of-scope work. diff --git a/skills/poteto-help/SKILL.md b/skills/poteto-help/SKILL.md index beba4ca..0af072e 100644 --- a/skills/poteto-help/SKILL.md +++ b/skills/poteto-help/SKILL.md @@ -45,7 +45,7 @@ If cost is the worry, say where the tokens go and how to spend fewer. pstack spe This package is the OMP port of pstack. The [`pstack-omp`](../pstack-omp/SKILL.md) skill maps pstack's roles, delegation, and lifecycle to OMP task agents. The upstream guide also describes Cursor-only features, such as Custom Modes, `/loop`, and cloud agents, that OMP does not have. -Other tools can read the skills, because they use the Agent Skills format. But most workflow skills, including `/poteto-mode`, `/how`, `/why`, and `/teach`, spawn OMP subagents with per-role models, so those parts may not work there. +Other tools can read the skills, because they use the Agent Skills format. But most workflow skills, including `/poteto-mode`, `/how`, and `/teach`, spawn OMP subagents, some with per-role models, so those parts may not work there. ## Start a task with `/poteto-mode` diff --git a/skills/poteto-mode/SKILL.md b/skills/poteto-mode/SKILL.md index e7e3fa9..ee21acd 100644 --- a/skills/poteto-mode/SKILL.md +++ b/skills/poteto-mode/SKILL.md @@ -15,7 +15,6 @@ The Principles section below grounds every trigger. In your reply, name each pri Remaining triggers: - Your first message on a task → tell the user, in your own words, their goal, the problem they are solving, and, if the task ships a change, the smallest change you expect to meet it. Don't wait for confirmation. If the evidence rules out the change the user asked for, show it and stop. Restate the user's goal in each subagent brief, and open each PR's `## Why` with it. Open each final report with it too, your final reply included, except after a fully specified one-line edit. -- Nontrivial change, architecture decision, or "are we sure?" → the **how** skill. - About to use the host's structured interaction tool on a "which approach", "how should I", or "what should this do" fork → classify it before you ask. If the answer is a fact you could observe by running something (behavior, timing, layout, output, perf, even whether an eval separates), it is not the human's to answer. Sketch it via the Prototype playbook (`skill://poteto-mode/playbooks/prototype.md`) and let the result decide. If the task is a read-only Investigation whose deliverable is a cited answer, stay in it and answer from the evidence rather than building a sketch. Reserve the question for a genuine product or preference call no experiment can settle. Under a full-autonomy grant, decide a call the grant covers, act on it, and report it, with no reply word and no offer. Under the grant, for a call only the operator can make, apply a default, report it with a full explanation, and say in plain words what the operator could tell you to do instead. The operator answers in their own words. Never give a shorthand token to type back. Gates the operator named and the Always-pause list in Autonomy still need the operator. - Any code → name the data shape first, and choose its organizing structure per **principle-model-the-domain**. - Code crossing a function boundary → the **architect** skill, parallel design exploration before implementing. diff --git a/skills/poteto-mode/playbooks/bug-fix.md b/skills/poteto-mode/playbooks/bug-fix.md index ed5b470..fd7883f 100644 --- a/skills/poteto-mode/playbooks/bug-fix.md +++ b/skills/poteto-mode/playbooks/bug-fix.md @@ -5,7 +5,7 @@ Be scientific. Every shipped line traces to runtime evidence. Belt-and-suspenders that "might help" is a hypothesis, not a fix. It does not ship. When evidence refutes a hypothesis, revert what it motivated. The smallest change the evidence justifies ships, nothing more. 1. Reproduce it yourself on the matching surface via the control skill (Non-negotiables), even when a debug or instrumentation protocol says to ask the user to reproduce. Ask the user only with a stated, specific reason the control surface cannot reach the target, and only after driving it as far as it goes. If it won't reproduce directly, synthesize the trigger, tighten conditions, or instrument until it fires. -2. Binary-search the cause. Form the candidate hypotheses, then rule them out until one survives. Seed them with `how` over the affected subsystem and the **why** skill for regression history. Each pass, take the split that cuts the most remaining problem space, get runtime evidence, eliminate. When program state is unclear, add instrumentation or logging and read it as the code runs. Don't guess. Drive a long or stubborn hunt with the wake mechanism from the Autonomous run playbook (`skill://poteto-mode/playbooks/autonomous-run.md`). Confirm the surviving *mechanism* with runtime evidence before the step-3 architect/interrogate fan-out. +2. Binary-search the cause. Form the candidate hypotheses, then rule them out until one survives. Seed them with a trace of the affected subsystem and the **why** skill for regression history. Each pass, take the split that cuts the most remaining problem space, get runtime evidence, eliminate. When program state is unclear, add instrumentation or logging and read it as the code runs. Don't guess. Drive a long or stubborn hunt with the wake mechanism from the Autonomous run playbook (`skill://poteto-mode/playbooks/autonomous-run.md`). Confirm the surviving *mechanism* with runtime evidence before the step-3 architect/interrogate fan-out. 3. Plan the fix. If it crosses a function boundary, `architect` first. Delegate implementation to a canonical `implementer` subagent through the active adapter's **Bounded session** protocol, using your configured bug-fix model (default the `implementer` role), with a specific scope. 4. Verify on the same surface. The original repro now passes. "Inconclusive" or wrong-surface is not a pass. Flag it. Unit tests show branch behavior, not bug absence. 5. Stage the commits so the failing repro lands before the fix in git history. See the **tdd** skill for the failing-test-first cadence when the bug has a cheap local test path. Skip it when the test would be expensive, integration-heavy, or unclear. diff --git a/skills/poteto-mode/playbooks/feature.md b/skills/poteto-mode/playbooks/feature.md index ec7b138..7ea1279 100644 --- a/skills/poteto-mode/playbooks/feature.md +++ b/skills/poteto-mode/playbooks/feature.md @@ -2,7 +2,7 @@ **You own the design. Plan, review, verify.** Delegate implementation. Stay in the lead. -1. `how` over the affected subsystem. +1. Trace the affected subsystem. 2. `architect` for parallel design exploration. 3. Write the throughput checkpoint as four todo items. A dimension that genuinely does not apply (single file, no fan-out) keeps its item with `n/a: ` rather than being dropped: - **Blocking first steps.** Gates run before fan-out. diff --git a/skills/poteto-mode/playbooks/hillclimb.md b/skills/poteto-mode/playbooks/hillclimb.md index 76a9e2b..f41dcfa 100644 --- a/skills/poteto-mode/playbooks/hillclimb.md +++ b/skills/poteto-mode/playbooks/hillclimb.md @@ -4,7 +4,7 @@ Core discipline: one change, one measurement, keep or revert. Never stack untested changes, and never claim a win from code inspection (the **prove-it-works** principle skill). -1. Ground the workload and architecture before choosing the metric. Run the **how** skill over the target, name the realistic workload dimensions that can move the result (data size, history, state, concurrency), and select a case that reproduces the user's complaint. If no case reproduces it, fix the repro instead of hillclimbing. Then fix one metric, the direction that counts as better, and a checkable stop predicate that pairs a target with a floor on attempts so a lucky early win can't end the run (the example "at least 50% better than baseline and at least 10 iterations" is this shape). Use the user's numbers when given, otherwise agree them. +1. Ground the workload and architecture before choosing the metric. Trace the target, name the realistic workload dimensions that can move the result (data size, history, state, concurrency), and select a case that reproduces the user's complaint. If no case reproduces it, fix the repro instead of hillclimbing. Then fix one metric, the direction that counts as better, and a checkable stop predicate that pairs a target with a floor on attempts so a lucky early win can't end the run (the example "at least 50% better than baseline and at least 10 iterations" is this shape). Use the user's numbers when given, otherwise agree them. 2. Build the measurement harness, prove its sensitivity, then freeze it (the **build-the-lever** principle skill). Run contrasting realistic workloads and confirm the target case reproduces the symptom while easier cases separate as expected. If the harness cannot distinguish them, revise the workload or metric. Vet the harness with the **benchmark-checklist** skill before you freeze it, and make it print its error count and a count of the work done. Once frozen, one repeatable command emits the metric, sampled enough to clear the noise (median of N, not a single run). Record the baseline metric and a green run of the regression gate (the tests that must keep passing) before any change. 3. Open the decision log via the **show-me-your-work** skill. A `decision.tsv`, one row per attempt: id, hypothesis, change, before, after, delta, tests, verdict (kept or reverted), note. Read it before each attempt. Keep it out of the tree (gitignored). 4. Ground each hypothesis in the architecture model from step 1, so it names a specific mechanism ("defer X off the boot path because it blocks first paint"), not "try memoizing something". For a perf metric, order hypotheses by the performance mantras in step 2 of the Perf issue playbook (`skill://poteto-mode/playbooks/perf-issue.md`). Borrow only their order, not that step's stop rule. diff --git a/skills/poteto-mode/playbooks/investigation.md b/skills/poteto-mode/playbooks/investigation.md index cd119f0..854d56f 100644 --- a/skills/poteto-mode/playbooks/investigation.md +++ b/skills/poteto-mode/playbooks/investigation.md @@ -4,9 +4,9 @@ Investigation requests are read-only. They produce a cited explanation or a recommendation, not a code change. -1. Route through the **how** skill. For motivation questions, also route through the **why** skill. +1. Trace the code the question is about. For motivation questions, also route through the **why** skill. 2. Throughput checkpoint stays one line: `throughput checkpoint: n/a, read-only investigation`. -3. Produce the `how`-shaped output (Overview / Key Concepts / How It Works / Where Things Live / Gotchas), or a recommendation with a tradeoffs table if the request is a decision between alternatives. +3. Produce the output (Overview / Key Concepts / How It Works / Where Things Live / Gotchas), or a recommendation with a tradeoffs table if the request is a decision between alternatives. 4. Apply the **unslop** skill to the reply. No PR, no babysit, no `architect` unless the investigation precedes a code change. If it does, hand back to the user and re-route to Bug fix or Feature. diff --git a/skills/poteto-mode/playbooks/multi-phase-plan.md b/skills/poteto-mode/playbooks/multi-phase-plan.md index f63fb99..e72f4ef 100644 --- a/skills/poteto-mode/playbooks/multi-phase-plan.md +++ b/skills/poteto-mode/playbooks/multi-phase-plan.md @@ -149,7 +149,7 @@ Each live lane runs in its own isolated worktree at the PR head. Drive through t ## Appendix D. Links and reading list - + ```` **Reply:** the plan path, the PR ids with their dependencies and the review-gated set, what the prototypes proved and what stays unproven, and the check script's output. diff --git a/skills/poteto-mode/playbooks/perf-issue.md b/skills/poteto-mode/playbooks/perf-issue.md index 8b74cf9..d1e9078 100644 --- a/skills/poteto-mode/playbooks/perf-issue.md +++ b/skills/poteto-mode/playbooks/perf-issue.md @@ -3,7 +3,7 @@ **You own the measurement story. Plan, review, verify the numbers.** Tie every fix to a measurement, don't read source instead of measuring. 1. Capture a baseline trace via the matching control skill. Vet the baseline, and each later number, with the **benchmark-checklist** skill. -2. `how` to ground hypotheses. Don't claim a perf ceiling without running it first. +2. Trace the code to ground hypotheses. Don't claim a perf ceiling without running it first. Try the performance mantras in order, cheapest first: 1. Don't do it. Stop work whose result nothing uses rather than cheapening it. 2. Do it, but don't do it again. diff --git a/skills/poteto-mode/playbooks/refactoring.md b/skills/poteto-mode/playbooks/refactoring.md index 76c5f5a..1792d4d 100644 --- a/skills/poteto-mode/playbooks/refactoring.md +++ b/skills/poteto-mode/playbooks/refactoring.md @@ -4,7 +4,7 @@ If the cleanup reveals a missing feature or a real bug, split it out and ship the structural change first against the pinned contract. A redesign is allowed, but name it and route to Feature. Large or cross-cutting structural work belongs to the **figure-it-out** skill. This playbook is the focused-to-medium change. -1. Pin the behavior contract first. Run the **how** skill over the affected subsystem to learn the contract, then write a characterization test, snapshot, or equivalence harness that captures current behavior before any structure moves. If the area has no coverage, write the pin before touching structure. Type check and lint are not a pin. +1. Pin the behavior contract first. Trace the affected subsystem to learn the contract, then write a characterization test, snapshot, or equivalence harness that captures current behavior before any structure moves. If the area has no coverage, write the pin before touching structure. Type check and lint are not a pin. 2. Name the structure the code is missing per **principle-model-the-domain**. Boring code stays when the shape is already clear and local. The reshape must delete branches or invalid states, not add indirection. 3. Name the target shape. State what the module layout, types, and call graph should be if built today (**principle-foundational-thinking**, **principle-redesign-from-first-principles**). If the target crosses a function boundary, run the **architect** skill for parallel design exploration of the shape before the move. 4. Subtract before you add. Delete dead code, collapse one-caller wrappers, drop redundant validators, and remove orphan references before introducing the new shape (**principle-subtract-before-you-add**). The smallest change that reaches the target shape ships (**principle-laziness-protocol**). A speculative cleanup that "might help" gets reverted. diff --git a/skills/pstack-omp/SKILL.md b/skills/pstack-omp/SKILL.md index 1671c16..94593e5 100644 --- a/skills/pstack-omp/SKILL.md +++ b/skills/pstack-omp/SKILL.md @@ -248,10 +248,6 @@ A spawn for a config line starts the agent below. Entry N of a panel line starts | `hillclimb` | `task` | | `judgment and prose` | `pstack-judgment` | | `hardest tasks` | `pstack-hardest` | -| `how explorer` | `scout` | -| `how explainer` | `reviewer` | -| `why investigators` | `librarian` | -| `why synthesizer` | `reviewer` | | `reflect tooling` | `pstack-reflect-tooling` | | `reflect judgment, divergent, synthesizer` | `reviewer` | | `swarm workers` | `pstack-swarm-worker` | diff --git a/skills/recall/SKILL.md b/skills/recall/SKILL.md index a3e409b..7ae834e 100644 --- a/skills/recall/SKILL.md +++ b/skills/recall/SKILL.md @@ -12,14 +12,14 @@ Follow the [portable runtime contract](../pstack-omp/references/runtime.md) for Keep it tight and on-topic. Read only what the in-scope threads need, then stop. -Your context lives in two records. Your own chat history holds what you did and decided. The shared record holds everything that happened around the same code under other names: the symptoms users keep reporting, the fixes that shipped and got reverted, the errors still firing in prod. That second record is what the **why** skill searches, across source control, the issue tracker, chat and issue channels, long-form docs, and error tracking. A feature with a long bug tail keeps most of its story there, so don't reconstruct it from your transcripts alone. +Your context lives in two records. Your own chat history holds what you did and decided. The shared record holds everything that happened around the same code under other names: the symptoms users keep reporting, the fixes that shipped and got reverted, the errors still firing in prod. That second record lives in source control, the issue tracker, chat and issue channels, long-form docs, and error tracking. A feature with a long bug tail keeps most of its story there, so don't reconstruct it from your transcripts alone. Transcripts live in `$PSTACK_TRANSCRIPTS_DIR` when set. Otherwise they live in this workspace's OMP sessions directory, `$(dirname "$PI_SESSION_FILE")`, as `_.jsonl`, with subagent chats under `_/`. Read a known session ID through `history://`. Every line is one session entry, such as a chat message. 1. Classify, then route. One specific prior chat to resume is the `session-pickup` playbook, not this. Turning habits into a durable skill is `automate-me`. A human-readable summary of your work is a different task. Recall loads working context across recent chats before you act. If the user already gave you a full state capsule (paths, branch, the change), use it and skip the mining. 2. Lock the scope before searching. Pin the window ("recent" is a real range, default the last 7 days), the topic if named, and the workspace (default the active one. Never read another project's transcripts without being asked). State the scope back. Never quietly turn "all" into "recent N". 3. Fan out across your chat history. Spawn parallel `explorer` subagents on a fast, cheap model, each taking a slice of the corpus. Tell every subagent to order candidates by real modification time (`ls -t`) and never by UUID name, grep the topic first and then read only the matching chats and only their relevant regions, and skip the current chat plus obvious noise (subagent, eval, and test chats). Each returns the same schema, one block per chat: topic, the user's goal, decisions, open threads, struggles and corrections, and artifacts (PRs, tickets, branches), each citing the chat UUID. For one or two chats, skip the fan-out and search directly. The raw transcripts stay in the subagents. The main thread gets only their findings. Set each child's reasoning effort for the job through the task runner's effort setting when the host exposes it, per the Delegation section of the **poteto-mode** skill. -4. Sweep the shared record whenever the topic names a feature, file, subsystem, area, or bug. This is the default, not a judgment call, and "my work on X" does not exempt it. Hand it to the **why** skill's source investigators, but steer their question from "why was this built this way" to "what's the current state, what's been tried and didn't hold, and what are users still reporting". Reuse its per-source playbooks, run the investigators in parallel with the chat-history mining, and inherit its posture: one investigator per source, null results are findings, skip an unavailable MCP and say so. Fold what comes back into the brief. Skip this step only for pure activity recall with no named target ("what did I do this week"), where your own history and live state are the entire answer. +4. Sweep the shared record whenever the topic names a feature, file, subsystem, area, or bug. This is the default, not a judgment call, and "my work on X" does not exempt it. Spawn one canonical `researcher` subagent per source, with MCP access because a read-only mode strips it, and ask each "what's the current state, what's been tried and didn't hold, and what are users still reporting". Run them in parallel with the chat-history mining. Null results are findings. Skip an unavailable MCP and say so. Fold what comes back into the brief. Skip this step only for pure activity recall with no named target ("what did I do this week"), where your own history and live state are the entire answer. 5. Verify against live state. Take the PRs, branches, and tickets that the mining and the sweep surfaced and check them with `git` and `gh`. When the answer hinges on what an agent actually did (the tools it ran, files it read, errors it hit), read the full transcript, not just a trimmed local copy. 6. Write the brief to the contract below. Group by thread. Stay on the named topic. diff --git a/skills/reflect/references/synthesizer.md b/skills/reflect/references/synthesizer.md index ae59d7c..682caf7 100644 --- a/skills/reflect/references/synthesizer.md +++ b/skills/reflect/references/synthesizer.md @@ -25,7 +25,7 @@ Drop (implementation details that drift): - "linter at SHA `bd91aa7` uses chars/4 heuristic" - "`` has 175 tokens at limit 80" - "Bugbot flagged regex backtracking on May 2" -- "we renamed `gpt-4` to `gpt-4o` in `encodingForModel`" +- "we renamed `parseConfig` to `loadConfig` in `settings.ts`" Keep (durable patterns): - "closed regex enums for trigger detection are brittle. Prefer schema-validated structures" diff --git a/skills/reproduce-and-fix-issues/SKILL.md b/skills/reproduce-and-fix-issues/SKILL.md index 8a1b3ab..bce9374 100644 --- a/skills/reproduce-and-fix-issues/SKILL.md +++ b/skills/reproduce-and-fix-issues/SKILL.md @@ -160,7 +160,7 @@ Collect: Inspect screenshots and video. Use read-only parallel workers for code history, test ideas, blast-radius mapping, and media review when useful. Each worker gets a narrow question and the Slack-write prohibition. -Use pstack's `how` skill to trace the action through the repository. Use `why` for regression history and defensive code. Form competing cause hypotheses and identify evidence that would separate them. +Trace the action through the repository. Use pstack's `why` skill for regression history and defensive code. Form competing cause hypotheses and identify evidence that would separate them. ## 7. Reproduce diff --git a/skills/setup-benny/SKILL.md b/skills/setup-benny/SKILL.md index e669aaa..4d8389f 100644 --- a/skills/setup-benny/SKILL.md +++ b/skills/setup-benny/SKILL.md @@ -37,7 +37,6 @@ Install pstack-omp for the target repository from a configured marketplace with Reload the target project or start a fresh agent rooted there. Verify that these shared pstack skills resolve from project scope: -- `how` - `why` - `tdd` - `unslop` diff --git a/skills/setup-pstack/SKILL.md b/skills/setup-pstack/SKILL.md index fb5a1ac..0fbd5a7 100644 --- a/skills/setup-pstack/SKILL.md +++ b/skills/setup-pstack/SKILL.md @@ -17,7 +17,7 @@ Enumerate the `provider/model-id` models OMP routes task agents to in this sessi ### 2. Load current state -The default role-to-model mapping is the config shape shown in step 5 below. If `$PSTACK_CONFIG (or .pstack/config.md)` already exists, read it and treat its `# budget` line and its role values as the current choices. Otherwise start from those defaults. A line whose role is not in step 5, such as `how critics`, is from a retired role. Drop it. If the file contains only role aliases the current OMP settings cannot honor, treat those aliases as stale inactive state and start from the detected models. +The default role-to-model mapping is the config shape shown in step 5 below. If `$PSTACK_CONFIG (or .pstack/config.md)` already exists, read it and treat its `# budget` line and its role values as the current choices. Otherwise start from those defaults. A line whose role is not in step 5, such as `how explorer` or `why investigators`, is from a retired role. Drop it. If the file contains only role aliases the current OMP settings cannot honor, treat those aliases as stale inactive state and start from the detected models. ### 3. Budget, map, and confirm @@ -28,9 +28,9 @@ The default role-to-model mapping is the config shape shown in step 5 below. If - `medium — high reasoning` - `small — medium reasoning` -**(b) Apply it.** Build the working table from the skill defaults, and on a re-run keep any role you changed by family or list. `unlimited`, `large`, `medium`, and `small` set the effort level of every real model, panel entries included, to `max`, `xhigh`, `high`, or `medium`. The effort level is the model's `:level` suffix, on the ladder `max` > `xhigh` > `high` > `medium` > `low`. If the model does not support that level, use its highest supported level at or below the target, else mark the role as needing a choice. So `unlimited` turns `:xhigh` into `:max`. A model that tops out at `xhigh` stays at `xhigh` under `unlimited`. `large` keeps the defaults. `small` turns every default into `:medium`. +**(b) Apply it.** Build the working table from the skill defaults, and on a re-run keep any role you changed by family or list. Each role has a target effort, which is its default's effort moved by the budget. `large` keeps it, `unlimited` raises it one step, `medium` lowers it one step, and `small` lowers it two steps, on the ladder `max` > `xhigh` > `high` > `medium` > `low`. A target at either end of the ladder stays there. Most defaults are at `xhigh`, and each budget label names where those land. Set the effort level of every real model in the role, panel entries included, to the role's target. The effort level is the model's `:level` suffix. If the model does not support that level, use its highest supported level at or below the target, else mark the role as needing a choice. So `unlimited` turns `:xhigh` into `:max` and `:high` into `:xhigh`, and it keeps `:max`. A model that tops out at `high` stays at `high` under `unlimited`. `small` turns `:xhigh` into `:medium` and `:high` into `:low`. -**(c) Show the roles and confirm.** Show every role with its model, marking any real model not in the detected set as needing a choice. Also list each line step 2 dropped. Ask whether to accept as-is or change specific roles, offering the detected models as the options. Prefer structured interaction tool over free text. For panel roles (arena runners, architect runners, interrogate reviewers) the value is a list of up to three models, and one subagent runs per entry, so the list length sets the count. `arena cross-judge pool` is also a list of up to three, but Arena runs one judge. It tries only values from a family other than the parent's, in list order, so order it by preference. `swarm workers` is the default model for every worker unless a race or comparison assigns another model per arm. +**(c) Show the roles and confirm.** Show every role with its model, marking any real model not in the detected set as needing a choice. Also list each line step 2 dropped. Ask whether to accept as-is or change specific roles, offering the detected models as the options. Prefer structured interaction tool over free text. For panel roles (arena runners, architect runners, interrogate reviewers) the value is a list of up to three models, and one subagent runs per entry, so the list length sets the count. `arena cross-judge pool` is also a list of up to three, but Arena runs one judge. It tries only values from a vendor other than the parent's, in list order, so order it by preference. Every Claude model, Fable included, is one vendor. `swarm workers` is the default model for every worker unless a race or comparison assigns another model per arm. If the live session exposes models but no usable task facility, stop model mapping with an explicit capability report naming the missing capability. Say that no pstack role can receive a different model in this session and do not present the portable defaults as an assignment or overwrite an existing role configuration with inactive aliases. @@ -46,7 +46,7 @@ Every real model written must be in the detected set. If a chosen real model is ### 5. Write the config -Write `$PSTACK_CONFIG (or .pstack/config.md)` with a `# budget` line with the chosen label and its target effort, and one line per role, using the same labels poteto-mode uses. Overwrite the whole file so re-runs stay idempotent. Each `` default is the model OMP resolves for the agent that role maps to in the `pstack-omp` role map. Shape: +Write `$PSTACK_CONFIG (or .pstack/config.md)` with a `# budget` line with the chosen label and the effort that label names, and one line per role, using the same labels poteto-mode uses. Overwrite the whole file so re-runs stay idempotent. Each `` default is the model OMP resolves for the agent that role maps to in the `pstack-omp` role map. `` is a detected model from a vendor other than those of `` and ``. Leave that seat out when no such model is detected. Shape: ``` # pstack model configuration. One line per role. A role with no line runs on its default agent's override. @@ -57,18 +57,14 @@ bug-fix: :xhigh perf-issue: :xhigh hillclimb: :xhigh judgment and prose: :xhigh -hardest tasks: :max -how explorer: :xhigh -how explainer: :xhigh -why investigators: :xhigh -why synthesizer: :xhigh -reflect tooling: :xhigh +hardest tasks: :max +reflect tooling: :high reflect judgment, divergent, synthesizer: :xhigh -arena runners: :xhigh, :xhigh -arena cross-judge pool: :xhigh, :xhigh -swarm workers: :xhigh -architect runners: :xhigh, :xhigh -interrogate reviewers: :xhigh, :xhigh +arena runners: :high, :high, :high +arena cross-judge pool: :high, :high, :high +swarm workers: :high +architect runners: :high, :high, :high +interrogate reviewers: :high, :high, :high ``` Then write `task.agentModelOverrides` in the global OMP config, preserving unrelated keys. Give each agent in the Model routing table the value of its config line, and give `pstack-runner-` and `pstack-judge-` entry N of their lines. Remove the entry for a seat agent whose lines have fewer entries. Keep the existing entries for agents no config line names, such as `planner`, `designer`, `security-reviewer`, and `sonic`, or ask for a model when one is missing. Re-read `cfg://task/agentModelOverrides` and confirm that every line matches its agent's entry. diff --git a/skills/sharpen/SKILL.md b/skills/sharpen/SKILL.md index 5b4a7b1..2a03402 100644 --- a/skills/sharpen/SKILL.md +++ b/skills/sharpen/SKILL.md @@ -13,4 +13,4 @@ I want a deeper version of this task, not a bigger one. Before rewriting it, do Then rewrite my prompt to ask for exactly that. -Leave choices that are mine to make open instead of deciding them. +Have the rewritten prompt ask the agent to prototype any choice an experiment can settle and recommend an option based on what it observed. Leave product or preference choices that no experiment can settle for me to make. diff --git a/skills/statechart/scripts/backends/mermaid.ts b/skills/statechart/scripts/backends/mermaid.ts index 327220c..21ad39c 100644 --- a/skills/statechart/scripts/backends/mermaid.ts +++ b/skills/statechart/scripts/backends/mermaid.ts @@ -93,6 +93,52 @@ const esc = (s: string, quoted = false) => { const or = (names: Iterable) => [...names].sort(byText).join(" or "); +type Edge = { from: string[]; start: boolean; to: string[]; label: string | undefined }; + +const within = (parent: string[], path: string[]) => + path.length >= parent.length && parent.every((p, i) => path[i] === p); +const wayIn = (e: Edge) => tupleKey([e.start, e.from]); + +export function drawnEdges(r: Region): Edge[] { + let out: Edge[] = []; + for (const s of r.states) + if (s.start) out.push({ from: [], start: true, to: s.path, label: undefined }); + for (const s of r.steps) + out.push({ + from: s.from, + start: false, + to: s.to, + label: s.label + (s.when ? ` [${s.when}]` : ""), + }); + const parents = new Map(); + for (const s of r.states) + for (let i = 1; i < s.path.length; i++) { + const prefix = s.path.slice(0, i); + parents.set(tupleKey(prefix), prefix); + } + for (const parent of [...parents.values()].sort((a, b) => a.length - b.length)) { + const into = out.filter( + (e) => e.to.length > parent.length && within(parent, e.to) && !within(parent, e.from), + ); + if (!into.length || into.some((e) => wayIn(e) !== wayIn(into[0]))) continue; + const one = into.length === 1; + const at = out.indexOf(into[0]); + out = out.filter((e) => !into.includes(e)); + out.splice( + at, + 0, + { ...into[0], to: parent, label: one ? into[0].label : undefined }, + ...into.map((e) => ({ + from: parent, + start: true, + to: e.to, + label: one ? undefined : e.label, + })), + ); + } + return out; +} + const MARK_STYLES = { breaks: "fill:#ffecee,stroke:#e72e3b,stroke-width:2.5px,color:#cd2834", mayBreak: "fill:#fff3e6,stroke:#e8730c,stroke-width:2.5px,color:#b85a06", @@ -121,6 +167,9 @@ export function mermaidLines(chart: Chart) { if (s === undefined) known.set(path, (s = id(path))); return s; }; + const drawn = drawnEdges(r); + const line = (e: Edge, indent: string) => + `${indent}${e.start ? "[*]" : idOf(e.from)} --> ${idOf(e.to)}${e.label === undefined ? "" : `: ${esc(e.label)}`}`; const tree = (prefix: string[], indent: string, below: ChartState[]) => { const heads = new Map(); for (const s of below) append(heads, s.path[prefix.length], s); @@ -134,6 +183,9 @@ export function mermaidLines(chart: Chart) { if (inner.length) { out.push(`${indent}state "${esc(head, true)}" as ${id(path)} {`); tree(path, indent + " ", inner); + const key = tupleKey(path); + for (const e of drawn) + if (e.start && tupleKey(e.from) === key) out.push(line(e, `${indent} `)); out.push(`${indent}}`); } else if (leaf) { const sid = idOf(leaf.path); @@ -153,11 +205,7 @@ export function mermaidLines(chart: Chart) { } }; tree([], " ", r.states); - for (const s of r.states) if (s.start) out.push(` [*] --> ${idOf(s.path)}`); - for (const s of r.steps) - out.push( - ` ${idOf(s.from)} --> ${idOf(s.to)}: ${esc(s.label + (s.when ? ` [${s.when}]` : ""))}`, - ); + for (const e of drawn) if (!e.start || !e.from.length) out.push(line(e, " ")); return out; }; let body: string[]; diff --git a/skills/statechart/scripts/run.ts b/skills/statechart/scripts/run.ts index 4efd368..017684f 100644 --- a/skills/statechart/scripts/run.ts +++ b/skills/statechart/scripts/run.ts @@ -68,6 +68,7 @@ const TLC_TOOL = "http:tla2tools[url=https://github.com/tlaplus/tlaplus/releases/download/v1.7.4/tla2tools.jar,checksum=sha256:936a262061c914694dfd669a543be24573c45d5aa0ff20a8b96b23d01e050e88]@1.7.4"; const JAVA_TOOL = "java@temurin-25"; export const PINNED_FLAGS = ["-workers", "1", "-fp", "0", "-lncheck", "final"]; +const SANY_ERRORS = /^\*\*\* ?(?:Errors|Abort messages|Parse Error)/m; type ChildResult = { status: number | null; @@ -227,6 +228,12 @@ const tail = (r: FileResult) => { return kept.join("").trim().split("\n").slice(-30).join("\n"); }; +const firstLines = (text: string) => { + const lines = text.trim().split("\n"); + if (lines.length > 40) lines.splice(40, Infinity, `... ${lines.length - 40} more lines`); + return lines.join("\n"); +}; + const stopOf = (r: FileResult): Stop => { const errors: Part[] = []; for (const m of r.error ? [] : messagesOf(r.output)) @@ -238,9 +245,14 @@ const stopOf = (r: FileResult): Stop => { ) errors.push(m); if (!errors.length) return { status: r.status, message: tail(r) }; - const lines = [...plainText(errors)].join("").trim().split("\n"); - if (lines.length > 40) lines.splice(40, Infinity, `... ${lines.length - 40} more lines`); - return { status: r.status, message: lines.join("\n") }; + return { status: r.status, message: firstLines([...plainText(errors)].join("")) }; +}; + +const sanyErrors = (r: FileResult) => { + if (r.error) return undefined; + const text = [...plainText(messagesOf(r.output))].join(""); + const at = text.search(SANY_ERRORS); + return at === -1 ? undefined : firstLines(text.slice(at)); }; const names = (rules: Rule[], kind: Rule["kind"]) => { @@ -305,8 +317,21 @@ export async function check(specFile: string, configFile: string): Promise path.join(here, "corpus", name, file); @@ -693,6 +694,48 @@ test("a step that leaves every child of a parent the same way is one arrow from assert.deepEqual(quits, [[open, closed]]); }); +test("a parent's only way in ends at the parent, and its start marker goes on to each state with that step's label", () => { + const graph = graphOf( + [ + ["ask", { at: "Asking" }, true], + ["flat", { at: "Layout.Flat" }], + ["parents", { at: "Layout.Parents" }], + ["drawn", { at: "Done.Drawn" }], + ], + [ + ["ask", "flat", "String"], + ["ask", "parents", "Array"], + ["flat", "drawn", "Draw"], + ], + ); + const { chart } = draw(graph, { state: (v) => String(v.at).split(".") }); + assert.deepEqual(drawn(chart).arrows.sort(), [ + "Asking --> Layout", + "Done start --> Drawn", + "Flat --> Done: Draw", + "Layout start --> Flat: String", + "Layout start --> Parents: Array", + ]); +}); + +test("a parent that two states lead into keeps an arrow from each, since one start marker cannot say where each came from", () => { + const graph = graphOf( + [ + ["a", { at: "A" }, true], + ["b", { at: "B" }], + ["p", { at: "P.p" }], + ["q", { at: "P.q" }], + ], + [ + ["a", "b", "Go"], + ["a", "p", "Left"], + ["b", "q", "Right"], + ], + ); + const { chart } = draw(graph, { state: (v) => String(v.at).split(".") }); + assert.deepEqual(drawn(chart).arrows.sort(), ["A --> B: Go", "A --> p: Left", "B --> q: Right"]); +}); + test("a label codes only the characters that Mermaid reads as syntax, so TLA+ values stay as TLC prints them", () => { const graph = graphOf( [ diff --git a/skills/statechart/scripts/test/cli.test.ts b/skills/statechart/scripts/test/cli.test.ts index 97b71c3..11f06a6 100644 --- a/skills/statechart/scripts/test/cli.test.ts +++ b/skills/statechart/scripts/test/cli.test.ts @@ -9,6 +9,7 @@ import { setTimeout as sleep } from "node:timers/promises"; import { fileURLToPath, pathToFileURL } from "node:url"; import { plainText } from "../backends/plain-text.ts"; import { readMessages } from "../frontends/messages.ts"; +import { drawn } from "./drawn.ts"; const here = path.dirname(fileURLToPath(import.meta.url)); const corpus = path.join(here, "corpus"); @@ -881,18 +882,6 @@ test("a view with a group in a theme color draws that color and names the group assert.match(chart, new RegExp(`^ {2}class ${legend} teal$`, "m")); }); -const shown = (text: string) => text.replace(/#(\d+);/g, (_, n) => String.fromCodePoint(Number(n))); - -const drawn = (chart: string) => { - const names = new Map(); - for (const m of chart.matchAll(/^ *(?:state "(.*)" as (s\d+) \{|(s\d+): (.*))$/gm)) - names.set(m[2] ?? m[3], shown(m[1] ?? m[4])); - const arrows: string[] = []; - for (const [, from, to, text] of chart.matchAll(/^ *(s\d+) --> (s\d+): (.*)$/gm)) - arrows.push(`${names.get(from)} --> ${names.get(to)}: ${shown(text)}`); - return { states: [...names.values()], arrows }; -}; - const byX = (labels: unknown[]) => `export const state = (v) => ${JSON.stringify(labels)}[v.x];\n`; const fanOut = (n: number) => { @@ -926,7 +915,7 @@ for (const [what, c] of [ view: byX([["a\0b"], ["a", "b"], ["c"], ["d"]]), status: 0, states: ["ab", "a", "b", "c", "d"], - arrows: ["ab --> b: Inc", "b --> c: Inc", "c --> d: Inc"], + arrows: ["a start --> b", "ab --> a: Inc", "b --> c: Inc", "c --> d: Inc"], says: /^TLC reached 4 states and 3 steps\. The chart draws 4 states and 3 arrows\.$/m, }, ], @@ -942,7 +931,14 @@ for (const [what, c] of [ ]), status: 0, states: ["R f", "S p", "R ab", "S q", "R a", "R b", "S r"], - arrows: ["S p --> S q: Inc", "S p --> S r: Inc"], + arrows: [ + "R f start --> S p", + "R ab start --> S q", + "R b start --> S r", + "R a start --> R b", + "S p --> R ab: Inc", + "S p --> R a: Inc", + ], says: /^The regions chart lets R f, S p go to R a\0b, S r by Inc, which the model never does\. So the chart draws parent states in place of regions\.$/m, }, ], @@ -964,7 +960,7 @@ for (const [what, c] of [ view: byX([["a\u0001b"], ["a", "b"], ["c"], ["d"]]), status: 0, states: ["a\u0001b", "a", "b", "c", "d"], - arrows: ["a\u0001b --> b: Inc", "b --> c: Inc", "c --> d: Inc"], + arrows: ["a start --> b", "a\u0001b --> a: Inc", "b --> c: Inc", "c --> d: Inc"], says: /^TLC reached 4 states and 3 steps\. The chart draws 4 states and 3 arrows\.$/m, }, ], @@ -1002,7 +998,7 @@ for (const [what, c] of [ view: byX([["a"], ["P", "b\u0002c"], ["d"], ["e"]]), status: 1, states: ["a", "P", "b\u0002c", "d", "e"], - arrows: ["a --> b\u0002c: Next", "b\u0002c --> d: Next", "d --> e: Next"], + arrows: ["P start --> b\u0002c", "a --> P: Next", "b\u0002c --> d: Next", "d --> e: Next"], says: /^## NotOne breaks\nThe shortest path has 1 step:\n0\. a\n1\. Next: P \/ b\cBc$/m, }, ], @@ -1039,10 +1035,15 @@ for (const [what, c] of [ status: 0, states: ["R f", "S p", "R a", "S r", "R b", "S q", "R X\u0003a", "S q", "R X\u0003b", "S r"], arrows: [ - "S p --> S r: Go\u0003X", - "S p --> S q: Go\u0003X", - "S p --> S q: Go", - "S p --> S r: Go", + "R f start --> S p", + "R a start --> S r", + "R b start --> S q", + "R X\u0003a start --> S q", + "R X\u0003b start --> S r", + "S p --> R a: Go\u0003X", + "S p --> R b: Go\u0003X", + "S p --> R X\u0003a: Go", + "S p --> R X\u0003b: Go", ], says: /^The regions chart lets R f, S p go to R a, S q by Go\cCX, which the model never does\. So the chart draws parent states in place of regions\.$/m, }, diff --git a/skills/statechart/scripts/test/corpus.test.ts b/skills/statechart/scripts/test/corpus.test.ts index 8934373..90a4104 100644 --- a/skills/statechart/scripts/test/corpus.test.ts +++ b/skills/statechart/scripts/test/corpus.test.ts @@ -383,6 +383,44 @@ for (const [width, height, config, status, drawn, chart, header] of [ }, ); +for (const [what, tla, where] of [ + [ + "an unknown name", + ["---- MODULE Broken ----", "VARIABLE x", "Init == x = 0", "Next == x' = y", "===="], + /^line 4, col 14 to line 4, col 14 of module Broken\n+Unknown operator: `y'\.$/m, + ], + [ + "a parse error", + ["---- MODULE Broken ----", "VARIABLE x", "Init == x = = 0", "Next == x' = x", "===="], + /^Encountered "0" at line 3, column 15/m, + ], + [ + "twelve unknown names", + [ + "---- MODULE Broken ----", + "VARIABLE x", + "Init == x = 0", + ...Array.from({ length: 12 }, (_, i) => `D${i} == u${i}`), + "Next == x' = x", + "====", + ], + /^\*\*\* Errors: 12\n+line 4, col 7 to line 4, col 8 of module Broken\n+Unknown operator: `u0'\.$/m, + ], +] as const) + test( + `a spec with ${what} gets SANY's line and column, not a Java stack trace`, + { skip }, + async () => { + const base = writeSpec("Broken", [...tla], "INIT Init\nNEXT Next\n"); + await assert.rejects(check(`${base}.tla`, `${base}.cfg`), (error: Error) => { + assert.match(error.message, /^SANY could not read .*Broken\.tla \(exit 1\):\n/); + assert.match(error.message, where); + assert.doesNotMatch(error.message, /^\s+at tla2sany\./m); + return true; + }); + }, + ); + test( "check() leaves no statechart- folder in the temp dir when it returns and when it throws", { skip }, diff --git a/skills/statechart/scripts/test/corpus/Login/chart.mmd b/skills/statechart/scripts/test/corpus/Login/chart.mmd index 9733b21..547bd3e 100644 --- a/skills/statechart/scripts/test/corpus/Login/chart.mmd +++ b/skills/statechart/scripts/test/corpus/Login/chart.mmd @@ -6,12 +6,13 @@ stateDiagram-v2 s4: Checking second try s5: Wrong password, 1 try left s6: Checking last try + [*] --> s2 } s7: Reset email sent s8: Signed in s9: Locked out [*] --> s0 - s0 --> s2: YouSubmitAPassword + s0 --> s1: YouSubmitAPassword s2 --> s8: ThePasswordIsRight s2 --> s3: ThePasswordIsWrong s7 --> s0: YouSetANewPassword diff --git a/skills/statechart/scripts/test/drawn.ts b/skills/statechart/scripts/test/drawn.ts new file mode 100644 index 0000000..1290403 --- /dev/null +++ b/skills/statechart/scripts/test/drawn.ts @@ -0,0 +1,20 @@ +const shown = (text: string) => text.replace(/#(\d+);/g, (_, n) => String.fromCodePoint(Number(n))); + +export const drawn = (chart: string) => { + const names = new Map(); + for (const m of chart.matchAll(/^ *(?:state "(.*)" as (s\d+) \{|(s\d+): (.*))$/gm)) + names.set(m[2] ?? m[3], shown(m[1] ?? m[4])); + const arrows: string[] = []; + const blocks: string[] = []; + for (const line of chart.split("\n")) { + const block = line.match(/^ *state ".*" as (\w+) \{$/); + if (block) blocks.push(block[1]); + if (/^ *\}$/.test(line)) blocks.pop(); + const m = line.match(/^ *(s\d+|\[\*\]) --> (s\d+)(?:: (.*))?$/); + const parent = names.get(blocks.at(-1) ?? ""); + if (!m || (m[1] === "[*]" && parent === undefined)) continue; + const from = m[1] === "[*]" ? `${parent} start` : names.get(m[1]); + arrows.push(`${from} --> ${names.get(m[2])}${m[3] === undefined ? "" : `: ${shown(m[3])}`}`); + } + return { states: [...names.values()], arrows }; +}; diff --git a/skills/statechart/scripts/test/labels.ts b/skills/statechart/scripts/test/labels.ts index a3d1499..8249724 100644 --- a/skills/statechart/scripts/test/labels.ts +++ b/skills/statechart/scripts/test/labels.ts @@ -1,5 +1,5 @@ import { inspect } from "node:util"; -import { mermaid as chartText } from "../backends/mermaid.ts"; +import { drawnEdges, mermaid as chartText } from "../backends/mermaid.ts"; import { checkView } from "../frontends/view.ts"; import type { Chart, ChartState, State, Step, View } from "../ir.ts"; import { walk } from "../passes/reach.ts"; @@ -398,6 +398,7 @@ function expected(chart: Chart): Want { const region = chart.regions[i]; const wrap = multi ? `r${i}` : null; if (wrap) nodes.set(wrap, { text: region.name, parent: "all", group: true }); + const drawn = drawnEdges(region); const tree = (prefix: string[], parent: string | null, below: ChartState[]) => { const heads = new Map(); for (const s of below) { @@ -413,19 +414,23 @@ function expected(chart: Chart): Want { else leaf = s; const node = id(region.name, path); nodes.set(node, { text: head, parent, group: inner.length > 0 }); - if (inner.length) tree(path, node, inner); - else if (leaf?.group !== undefined) used.add(chart.colors[String(leaf.group)]); + if (inner.length) { + tree(path, node, inner); + const key = JSON.stringify(path); + for (const e of drawn) + if (e.start && JSON.stringify(e.from) === key) + edges.push([`${node}_start`, id(region.name, e.to), e.label ?? ""]); + } else if (leaf?.group !== undefined) used.add(chart.colors[String(leaf.group)]); } }; tree([], wrap, region.states); - for (const s of region.states) - if (s.start) edges.push([`${wrap ?? "root"}_start`, id(region.name, s.path), ""]); - for (const s of region.steps) - edges.push([ - id(region.name, s.from), - id(region.name, s.to), - s.label + (s.when ? ` [${s.when}]` : ""), - ]); + for (const e of drawn) + if (!e.start || !e.from.length) + edges.push([ + e.start ? `${wrap ?? "root"}_start` : id(region.name, e.from), + id(region.name, e.to), + e.label ?? "", + ]); } let legend = 0; for (const [text, cls] of Object.entries(chart.colors)) diff --git a/skills/statechart/scripts/test/render.test.ts b/skills/statechart/scripts/test/render.test.ts index 5309a92..57ff41e 100644 --- a/skills/statechart/scripts/test/render.test.ts +++ b/skills/statechart/scripts/test/render.test.ts @@ -6,6 +6,10 @@ import os from "node:os"; import path from "node:path"; import { before, test } from "node:test"; import { fileURLToPath, pathToFileURL } from "node:url"; +import { mermaid as chartText } from "../backends/mermaid.ts"; +import type { Graph } from "../ir.ts"; +import { walk } from "../passes/reach.ts"; +import { project } from "../pipeline.ts"; import { fuzz, type Html, type Mermaid, type Render } from "./labels.ts"; const here = path.dirname(fileURLToPath(import.meta.url)); @@ -75,6 +79,66 @@ test("random labels and colors keep their text and the chart's shape in Mermaid assert.ok(drawn > 400 && refused > 20, `${drawn} charts drawn, ${refused} refused`); }); +const pathPoints = (d: string) => { + const points: number[][] = []; + let [ax, ay] = [0, 0]; + for (const [, cmd, args] of d.matchAll(/([MLC])([^MLC]*)/g)) { + const n = args.split(/[ ,]/).filter(Boolean).map(Number); + const [x, y] = n.slice(-2); + if (cmd !== "M") + for (let t = 0; t <= 1; t += 1 / 64) { + const u = 1 - t; + points.push( + cmd === "L" + ? [ax + (x - ax) * t, ay + (y - ay) * t] + : [ + u ** 3 * ax + 3 * u * u * t * n[0] + 3 * u * t * t * n[2] + t ** 3 * x, + u ** 3 * ay + 3 * u * u * t * n[1] + 3 * u * t * t * n[3] + t ** 3 * y, + ], + ); + } + [ax, ay] = [x, y]; + } + return points; +}; + +test("an arrow into a parent from its only way in stays out of the parent's title bar in Pele 1.9.0", () => { + const graph: Graph = { states: new Map(), steps: [] }; + for (const [id, at] of [ + ["ask", "Asking your view for labels"], + ["flat", "Laying out the chart/Flat"], + ["parents", "Laying out the chart/Parent states"], + ["regions", "Laying out the chart/Regions"], + ]) + graph.states.set(id, { vars: { at }, start: id === "ask", breaks: [] }); + for (const [to, action] of [ + ["flat", "String"], + ["parents", "Array"], + ["regions", "Object"], + ]) + graph.steps.push({ from: "ask", to, action }); + const { chart } = project(graph, walk(graph), { state: (v) => String(v.at).split("/") }, []); + const { svg } = render(chartText(chart)); + const bars = [ + ...svg.matchAll( + /]*\/> x > bar.left && x < bar.right && y > bar.top && y < bar.bottom, + ) + ) + crossings.push(`${id} crosses the title bar of ${bar.id}`); + assert.deepEqual(crossings, []); +}); + test("the theme in references/render.md colors each class that the charts use", () => { assert.ok(classes.size > 0); for (const name of classes) assert.match(theme, new RegExp(`\\.pele \\.${name} rect \\{`), name); diff --git a/skills/teach/SKILL.md b/skills/teach/SKILL.md index 1d61dc0..da1482b 100644 --- a/skills/teach/SKILL.md +++ b/skills/teach/SKILL.md @@ -13,7 +13,7 @@ Follow the [portable runtime contract](../pstack-omp/references/runtime.md) when 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). 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. -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. +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. 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. 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. 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. 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. 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. 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. diff --git a/skills/triage-issue-reports/SKILL.md b/skills/triage-issue-reports/SKILL.md index 810c505..3d1e3ab 100644 --- a/skills/triage-issue-reports/SKILL.md +++ b/skills/triage-issue-reports/SKILL.md @@ -70,7 +70,7 @@ Use evidence already in the thread before asking the reporter for more. ## 3. Trace cause before routing -Do a bounded source and history pass before choosing an owner or destination. Use pstack's `how` skill to trace the path from the reported action to the observed result. Use `why` when the report looks like a regression or touches defensive code. +Do a bounded source and history pass before choosing an owner or destination. Trace the path from the reported action to the observed result. Use pstack's `why` skill when the report looks like a regression or touches defensive code. 1. Identify the likely code path from the reported action to the observed result. 2. Check whether the visible symptom belongs to that code path or a dependency below it. diff --git a/skills/why/SKILL.md b/skills/why/SKILL.md index 86fc790..9939783 100644 --- a/skills/why/SKILL.md +++ b/skills/why/SKILL.md @@ -1,100 +1,9 @@ --- name: why -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." +description: "Use for 'why does X work this way', 'why we picked Y', design rationale, regressions, postmortems, or data-backed thresholds. Returns a cited read on decisions and tradeoffs. Use how for runtime behavior." disable-model-invocation: true --- # Why -Follow the [portable runtime contract](../pstack-omp/references/runtime.md) for tool discovery, researcher and synthesizer roles, model choices, concurrency, and unavailable-capability reporting. - -Investigate the motivation and intent behind code. The companion `how` skill answers what the code does and how it works. `why` answers what forces led to its shape. - -Each spawn below names a role line in `$PSTACK_CONFIG (or .pstack/config.md)` and a default role. Start the agent the Model routing section of the **pstack-omp** skill names for that line, and use the role's default agent if the configuration or the line is missing. If that section's check stops a spawn, or the spawn fails, stop and report it. Set each child's reasoning effort for the job through the task runner's effort setting when the host exposes it, per the Delegation section of the **poteto-mode** skill. - -Every spawn keeps MCP access. **Do not use a read-only mode that strips it.** That disables the MCP-backed investigators and the synthesizer's citation spot-checks. Investigators still shouldn't write anything. - -## Operating Posture - -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. - -## Step 1. Understand the Target and the Question - -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. - -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. - -## Step 2. Establish the Code Anchor - -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 , ` for last-touch commits, `git log --follow -p -- ` for full history with patches through renames, `git log --oneline -20 -- ` for recent commits with PR numbers visible, and `git log -1 --format=%B ` to extract PR numbers. Then pull the PR bodies and discussion for any substantive commit: `gh pr view --json title,body,author,createdAt,mergedAt,labels,closingIssuesReferences,comments,reviews`. This anchor goes to every investigator and to the synthesizer. - -## Step 3. Spawn Parallel Investigators - -**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. - -### Discovery - -Before spawning investigators, list the available MCPs from the OMP environment, using the session's tool list and any MCP server instructions. - -Map each available MCP to one evidence category: - -1. Source control history -2. Issue / ticket tracker -3. Long-form documents -4. Real-time team chat -5. Infrastructure observability -6. Error / exception tracking -7. Product analytics warehouse - -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. - -Spawn one investigator per category that has a matching MCP, all in a single message so they run concurrently, each owning exactly one tool or MCP. Don't ask one agent to cover multiple MCPs. Role line: the `why investigators` line, default role `researcher`. - -Each investigator's prompt is `references/investigator-prompt.md` filled in, plus: -- the category playbook `references/sources/.md` for the selected MCP, adapted from the examples in `references/source-playbook.md` -- `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) -- the code anchor and the user's original question - -### Investigator roster, one per available evidence category - -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. - -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*. -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. -3. **Long-form documents** (e.g. Notion, Confluence, Google Docs, Coda MCP). Best at *long-form design rationale*, written out before it becomes code. -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. -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). -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. -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. - -### When to skip an investigator - -Only with an **explicit, written justification** that goes in the final Sources Consulted. Two valid reasons: - -- **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." -- **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." - -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. - -## Step 4. Synthesize - -Spawn one synthesizer. Role line: the `why synthesizer` line, default role `synthesizer`. It gets: -1. The investigator findings, including any null results and any categories skipped with justification -2. The code anchor -3. The user's original question -4. The epistemics framework from `references/epistemics.md` -5. The synthesizer prompt template from `references/synthesizer-prompt.md` - -## Step 5. Present - -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**. - -## Output Format - -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. - -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. - -## Common Failure Modes to Avoid - -- **Recency bias**. Assuming the most recent commit is authoritative. The current shape is often the accretion of many earlier decisions. Trace back. +Answer from the record, not the code: read the commits and PR discussions that introduced the target and each later change, and other sources if the trail is thin. Cite what the authors wrote, mark your own inferences as inferences, and say what the record does not answer. diff --git a/skills/why/references/epistemics.md b/skills/why/references/epistemics.md deleted file mode 100644 index b18abf4..0000000 --- a/skills/why/references/epistemics.md +++ /dev/null @@ -1,71 +0,0 @@ -# Epistemics - -How to reason about confidence when evidence is historical, fragmentary, and sometimes contradictory, and how to tell the user without flattening it into false certainty. Code shows what it does, not *why it exists*. The why lives in commits, PRs, tickets, docs, and conversations, all incomplete, biased, and sometimes missing. Pretending otherwise produces confident-sounding guesses that mislead the user. - -## Confidence Tiers - -Every claim in the output must sit in one tier. The tier sets its section and its phrasing. - -### 1. Direct - -An explicit, textual citation answers the question: something an author actually *wrote* that says why, not "the code does X so the author must have wanted X." For example, a PR description "this fixes the bug where users with >1000 items couldn't paginate", a ticket "we're adding this because customer Acme requested it in their security review", a code comment "// clamp to 100 because the upstream API rejects larger values", a design doc "we chose option A over option B because we need persistence across restarts", or a chat message from the author "switching to this approach since the old one was flaky in tests". - -Phrasing: confident, present tense, cited. "This exists because X." - -### 2. Supported - -Multiple pieces of indirect evidence converge on one conclusion. No single source states it explicitly, but the pattern across sources makes it likely. For example, the PR title says "improve performance", the ticket is labeled "perf", and the surrounding commits all touch the same hot path. Or several tests added with the change all exercise very large inputs. Or the author's other PRs from the same week all name the same incident. - -Phrasing: confident but clearly derived, citing each item. "The evidence points strongly to X: [the specific pieces]." - -### 3. Inferred - -A reasonable reading of the context that nothing explicitly supports. It is *your interpretation*, not a fact from the record. For example, the PR doesn't say why, but the error was happening in production (per the incident channel timing) and the fix was rushed (merged the same day), so it was likely a hotfix. Or the function name suggests retry logic, and its retry count of 3 matches the team's 3-retry convention elsewhere in the codebase. - -Phrasing: hedged, with the chain explicit. "Given A and B, C seems likely because D." - -### 4. Speculative - -A plausible hypothesis on thin evidence, where other explanations fit equally well. Worth presenting, since the user may know which is right, but mark it as a guess. For example, "This might be a workaround for a browser bug that's since been fixed, but we found no contemporary evidence of that", or "It's possible this threshold was chosen to match an SLA commitment, but no SLA doc references it." - -Phrasing: "One possibility is X, but we have no direct evidence." Usually lives in Competing Hypotheses, alongside other possibilities. - -### 5. Unknown - -You looked and couldn't find out. A valid, important outcome. Document it. - -Phrasing: "We searched X, Y, and Z and found no evidence of why." Be specific about *what* you searched. "We couldn't find out" is less useful than "We searched the ticket tracker with keywords A and B, scanned the 6 PRs that touched this file since 2023, and grep'd the repo for string literals matching the threshold. None surfaced a rationale." - -## Phrasing Guide - -**Confidence words** imply Direct or Supported evidence and need a citation immediately adjacent. Never use them for inferences: "because", "the reason is", "was designed to" (claims author intent), "fixes" / "addresses" / "solves" (claims the change achieved its goal), "the team decided" (claims a group decision happened). - -**Hedges** signal interpretation, not report. Use them liberally in What We Can Reasonably Infer: "appears to", "seems to", "likely", "suggests", "is consistent with", "one reading is", "plausibly", "may have been", "the evidence points toward". - -**Words to avoid:** - -- "obviously". If it were obvious, the user wouldn't be asking -- "clearly". Almost always precedes a claim that isn't clear -- "of course". Same -- "just" (as in "it's just X for performance"). Dismissive and usually hides uncertainty -- "I think" / "I believe". You're synthesizing evidence, not giving a personal opinion. Use "the evidence suggests" instead. - -## Avoid Rationalization - -Code that "makes sense" today may have been written for reasons that no longer apply, or that were wrong at the time. Don't retrofit a clean rationale onto messy history. Don't assume the author did the "right" thing and work backward to justify it. Don't assume a consistent pattern was intentional when it might be copy-paste. Don't turn an absence of evidence into evidence of absence ("no one mentioned security concerns, so it must not have been a concern"). - -## The Sycophancy Trap - -Users often embed a hypothesis: "Why do we do it this way, I assume it's for performance?" Don't simply confirm it. The guess is a prompt for investigation, not a conclusion to validate. Treat it as one candidate among others and check the evidence independently. If the evidence supports it, say so with citations. If not, say so, and present what the evidence *does* support. - -## When Evidence Contradicts - -Surface both sources in the output, with citations. Don't pick the one that fits a tidier narrative. For example, the ticket says "we need this for customer X's compliance requirement" and the PR says "cleaning up tech debt in this area". Both may be true (the ticket motivated the work, the PR gave the author's framing), or one may be wrong. Let the user make the call. - -## When Evidence Is Missing - -An honest "we don't know" is one of the most valuable outputs. The user learns the answer isn't in the obvious places, that they'll need to ask a human (the original author, the product owner, the team lead), or that they can decide the question isn't worth pursuing further. Failing to mark a gap, and instead filling it with a confident guess, actively harms the user, because they'll act on the guess. Name each gap concretely: the question, the sources searched, what you searched for in each, and what you found (nothing, or only tangential material). - -## Before Finalizing - -Before the synthesizer delivers the output, it checks every claim in "What We Found" and "What We Can Reasonably Infer". Each claim has a citation or moves to Inferred or Hypotheses. Its phrasing matches its tier. It doesn't treat code as evidence for its own intent (if it does, remove or reclassify it). The output has a "What We Don't Know" section. If no gaps are mentioned, that's suspicious. Either the evidence was unusually complete or something is being swept under the rug. diff --git a/skills/why/references/investigator-prompt.md b/skills/why/references/investigator-prompt.md deleted file mode 100644 index e1c2bbf..0000000 --- a/skills/why/references/investigator-prompt.md +++ /dev/null @@ -1,84 +0,0 @@ -# Investigator Prompt Template - -Fill in the placeholders. Append the one category playbook `sources/.md` for this investigator's evidence category (index: `source-playbook.md`). If the target code looks defensive (null checks, retry logic, timeout handling, rate limiting, feature flags, egress guards, OOM handlers), also append `sources/incident-postmortem.md` so the investigator runs incident-flavored queries inside its own source. - ---- - -You are investigating the historical context and motivation behind a piece of code. Other investigators search other sources in parallel, and a separate synthesizer combines all findings into the final answer. Go deep on your assigned source only. Gather evidence accurately rather than writing prose. - -Work like a **careful, cautious, and precise investigator**. Surface evidence and describe it accurately, including the parts that don't fit a tidy story. Boring and exact beats plausible. One verbatim quote with a precise citation is worth more than a paragraph of summary. - -## The Question - -> {QUESTION} - -## The Code Anchor - -**Target files:** {FILES_WITH_LINE_RANGES} - -**Key symbols:** {SYMBOLS} - -**Initial commits touching this code (most recent first):** -{COMMIT_LIST} - -**PR numbers extracted from commit messages:** {PR_NUMBERS} - -**Ticket IDs mentioned in commits or PR bodies (if any):** {TICKET_IDS} - -## Your Assigned Source - -{SOURCE_NAME} - -{SOURCE_PLAYBOOK_SECTION} - -## Investigation Loop - -1. **Cast a wide net first** so you don't miss related context. Only then narrow in on specific items. -2. **Read the whole thing.** Read each PR, ticket, doc, or thread fully, not just the title or summary. The key evidence is often in a comment, a subtask, or a follow-up. -3. **Follow links within your source only.** Pull the PR or commit a PR references, the parent or sibling of a ticket, the doc a doc links. Do NOT chase a cross-source reference. Record it under Additional Leads for that source's investigator. The one-investigator-per-category design depends on this. Chasing it duplicates work and confuses scope. -4. **Quote verbatim**, with the exact location (PR number, ticket ID, URL, commit hash, file:line), so the reader can confirm the claim in seconds. -5. **Record what you searched, not just what you found.** Write queries verbatim. An empty search is a finding. -6. **Resist the story.** If two items in your source disagree, record both. Don't suppress the inconvenient one. If three items line up and a fourth contradicts them, the contradiction is the most interesting finding. - -Before reporting a finding as strong, ask whether you would expect to find it if your current reading were wrong, and how the evidence would differ. **Never invent.** If you're tempted to round a partial finding up into a confident statement, stop and label it partial. The synthesizer counts on your output being accurate. - -## Epistemic Discipline - -- **Mechanics are not motivation.** A commit changing `limit = 50` to `limit = 100` shows the change, not necessarily why. Look for the reason in the commit message, PR description, linked ticket, or review comments. -- **No intent from code behavior or style.** You may read code to learn what the target *is*. "The author chose a functional approach" is an observation about code, not evidence of intent. Claim intent only where the author stated it. -- **Preserve uncertainty.** Say when evidence is ambiguous, or when one reading is more plausible but not certain. Don't collapse ambiguity to look decisive. -- **No silent substitutions.** If the question is about feature X and you only find evidence about feature Y, don't present Y's evidence as if it answers X. -- **Gather, don't conclude.** Collect the raw material honestly and completely. Don't answer the question, form a final opinion on "the why", or pick sides in contradictions. Don't speculate beyond what the evidence supports. A hunch with no evidence isn't evidence. The synthesizer does the reasoning. - -## Output Format - -Return your findings in this structure. The synthesizer reads it directly. - -### Source -Which source you investigated (source control, issue / ticket tracker, long-form documents, real-time team chat, infrastructure observability, error / exception tracking, product analytics warehouse, code comments, etc.). - -### What I Searched -The queries you ran, items you opened, and places you looked. Be specific. This shows how thorough the search was and what is still unsearched. - -### Direct Evidence Found -For each item that explicitly addresses the question: -- **What it says**: verbatim quote or accurate paraphrase -- **Where it's from**: PR #123, ticket ID, doc URL, chat permalink, commit hash, or file:line -- **Author and date** (if available) -- **Relevance**: one sentence on how it bears on the question - -### Indirect / Circumstantial Evidence -For each item that bears on the question without answering it: -- **What it is**: brief description -- **Where it's from**: location -- **What it suggests**: what a careful reader might infer, and the inference chain -- **Alternative readings**: if the same evidence could support a different interpretation, note it - -### Contradictions -Items that disagree with each other, with both citations. - -### Gaps -What you searched for and didn't find, specifically: "Searched the issue tracker for [query] across [time range]. No matching issues." - -### Additional Leads -Anything that suggests further investigation in a different source, for its investigator or a follow-up pass. For example, a chat thread that a PR mentions. diff --git a/skills/why/references/source-playbook.md b/skills/why/references/source-playbook.md deleted file mode 100644 index aa3d877..0000000 --- a/skills/why/references/source-playbook.md +++ /dev/null @@ -1,17 +0,0 @@ -# Source playbooks - -The why skill spawns one investigator per available evidence category, each reading a single source-specific playbook below. The playbooks are concrete examples for common MCPs. Adapt them for a different MCP in the same category. - -| Category | Playbook | Example MCP it documents | -|---|---|---| -| Source control history | [`code-archaeology.md`](./sources/code-archaeology.md) | git, `gh` | -| Issue / ticket tracker | [`linear.md`](./sources/linear.md) | Linear (adapt for Jira, GitHub Issues, Plane, Shortcut) | -| Long-form documents | [`notion.md`](./sources/notion.md) | Notion (adapt for Confluence, Google Docs, Coda) | -| Real-time team chat | [`slack.md`](./sources/slack.md) | Slack (adapt for Discord, Microsoft Teams, Mattermost) | -| Infrastructure observability | [`datadog.md`](./sources/datadog.md) | Datadog (adapt for New Relic, Honeycomb, Grafana, Splunk) | -| Error / exception tracking | [`sentry.md`](./sources/sentry.md) | Sentry (adapt for Rollbar, Bugsnag, Airbrake) | -| Product analytics warehouse | [`databricks.md`](./sources/databricks.md) | Databricks SQL (adapt for Snowflake, BigQuery, ClickHouse, dbt) | - -Cross-cutting: - -- [`incident-postmortem.md`](./sources/incident-postmortem.md). Add this if the target code looks defensive (null checks, retry, timeout, rate limit, feature flag, egress guard, OOM handler). diff --git a/skills/why/references/sources/code-archaeology.md b/skills/why/references/sources/code-archaeology.md deleted file mode 100644 index e3555f8..0000000 --- a/skills/why/references/sources/code-archaeology.md +++ /dev/null @@ -1,51 +0,0 @@ -# Code Archaeology (git + in-repo) - -## What this source contains - -- Commit history (messages, dates, authors, diffs) -- PR descriptions, review comments, and discussion threads (via `gh`) -- Inline code comments, TODOs, FIXMEs, deprecation notes -- ADRs (architectural decision records) if the repo keeps them -- Tests, whose names and assertions often encode the edge cases that motivated a change -- Related files modified in the same commits (co-change signal) -- CHANGELOG entries and release notes in the repo -- Issue/ticket IDs in commit messages and PR bodies - -The most trustworthy source, tied directly to the code, and the most complete. Everything that went through the repo should be here. - -## How to search it - -Expand the seed commit list: - -```bash -# History through renames -git log --follow --oneline -- - -# Pickaxe: commits that added or removed this exact text -git log -S '' -- - -# Or for patterns: -git log -G '' -- - -# Who wrote each line and when -git blame -L , - -# One commit's full diff -git show - -# Commits between two points affecting this file -git log .. -p -- -``` - -Look for out-of-band docs: - -```bash -# ADRs often live in docs/adr/ or similar -rg -l -i 'architecture.decision' --glob '*.md' - -# TODOs and FIXMEs near the target -rg -n -C2 '(TODO|FIXME|HACK|XXX|NOTE)' - -# Related tests -rg -l '' --glob '*test*' -``` diff --git a/skills/why/references/sources/databricks.md b/skills/why/references/sources/databricks.md deleted file mode 100644 index 2770763..0000000 --- a/skills/why/references/sources/databricks.md +++ /dev/null @@ -1,70 +0,0 @@ -# Databricks Analytics & System Tables - -## What this source contains - -Databricks is the product-analytics, data-pipeline, and warehouse-telemetry layer. It complements Datadog. Datadog is the *infra/runtime* view, Databricks is the *product/data* view (what users did, which experiments ran, how feature usage evolved, where a threshold constant came from). - -- **Product analytics events.** `your_warehouse.events.analytics_track_event` (raw) and typed, deduplicated per-event dbt models in `..`. User behavior: feature invocations, clicks, accepts/rejects, submissions, client-reported errors. -- **Usage & billing events.** `your_warehouse.events.usage_event` / `..stg_usage_events`, `your_warehouse.events.raw_model_event` / `..stg_raw_model_events`. For cost- or volume-driven decisions. -- **Experiment / feature-flag data.** Exposure and outcome tables. **Schema is company-specific.** Probe with `SHOW TABLES` before assuming names. -- **System tables.** `system.query.history`, `system.compute.warehouses`, `system.billing.*`, `system.access.audit`. Answer "was this query expensive?", "how often did anyone run this?", "when did warehouse load spike?" -- **dbt lineage.** Models in `.` reveal what pipelines depend on a table/field. Upstream changes frequently motivate consumer-code changes. -- **Databricks notebooks.** Exploratory analyses engineers wrote before code changes. **Not queryable via the SQL MCP.** If you suspect the rationale lives in a notebook, name it as a gap. - -## How to search it - -Use the Databricks SQL MCP. Primary tool: `execute_sql_read_only`. If it returns a `statement_id`, poll with `poll_sql_result` rather than re-running. - -**Orient before querying.** Schemas are company-specific. Probe before trusting a table name: - -```sql -SHOW TABLES IN . LIKE '**'; -DESCRIBE TABLE ..stg_; -``` - -**Time-bound every query.** These tables are huge and unconstrained scans time out. Filter on `_timestamp` (events) or `start_time` (`system.query.history`) with a window bracketing the ship date, typically ~30 days before and after, wider only for strong reason. - -**Prefer typed dbt models over the raw table.** `..
` is deduplicated, typed, and liquid-clustered. `your_warehouse.events.analytics_track_event` has duplicates and untyped `properties_json`. Model-name pattern: `stg__`, where `` is `app`, `backend`, `website`, or `cli`. Confirm the exact model name with `SHOW TABLES` when the pattern alone doesn't resolve it. Drop to the raw table only when there's no dbt model yet, or you need events from inside the dbt refresh lag. - -**Column conventions on the typed dbt models** (knowing these avoids a `DESCRIBE` round-trip): - -- `_timestamp`, `_id`, `_auth_id`, `_request_id`, `event_name`. Standard on every model -- `properties_`. Typed, underscore-cased event properties (`properties_entrypoint`, `properties_size_bytes`, …) -- `context_team_id`, `context_client_version`, `context_country`, `context_client_os`. Pre-extracted client context - -### Investigation patterns that tend to pay off - -Pick the table + column combination that matches the target: - -1. **Event usage trajectory.** Daily counts on the relevant `stg_*` model across a ±30d window around the PR merge. A step function from zero to steady volume within a day or two of the merge is strong circumstantial evidence the PR launched the feature. A decay to zero suggests a deprecation or deletion. -2. **Guard-rail / defensive-check origin.** Distribution (median / p99 / max) of the relevant `properties_` column in the 14 days *before* the PR. A p99 that matches the target's threshold constant suggests the number was chosen from data. -3. **Experiment / feature-flag lookup.** `SHOW TABLES ... LIKE '*experiment*'` to find the exposure table, then pull exposure counts by variant for the relevant flag key near the PR date. -4. **Query-history evidence for migrations, backfills, or perf rewrites.** `system.query.history` filtered by `statement_text ILIKE '%%'` with a tight `start_time` window surfaces the expensive queries that likely motivated the change (sort by `total_duration_ms` or aggregate `SUM(read_bytes)`, `COUNT(*)`). -5. **dbt lineage.** If the target reads from or writes into a `.` model, the model's own git history (in this repo) often carries the rationale. Hand that lead back to the git investigator rather than chasing it yourself. - -## What good evidence looks like here - -Beyond the pattern shapes above: - -- An error-classifying event's count drops to near zero in the days after a defensive-code PR. Suggests the PR resolved that error class -- An exposure table row names the target's feature-flag key with a "shipped" / "concluded" decision around the PR ship date - -## Common pitfalls - -- **Instrumented ≠ caused.** An event's existence means someone cared enough to log it, not that the target code exists *because* of it. Pair with a PR/commit citation from the git investigator before claiming causation. -- **Silent instrumentation changes.** A step function in event volume may mean a new event started being logged, not that user behavior changed. Check for instrumentation PRs in the same window before reading the ramp as a feature-launch signal. -- **Schema drift.** Event properties evolve. A column on the typed dbt model today may not have existed when the target was written. Older data may carry the property only inside raw `properties_json`. -- **dbt refresh lag.** `..*` is rebuilt on a schedule (often hourly/daily). For events from the last few hours, fall back to `your_warehouse.events.*` and deduplicate by `_id`. -- **Company-specific tables.** Experiment, feature-flag, billing, and usage tables vary. Reporting a result from a table whose existence you never confirmed is a classic failure mode. Probe with `SHOW TABLES` / `DESCRIBE TABLE` first. -- **Retention cliff.** If the relevant window predates the table's retention or the dbt model's creation date, that's a *gap*, not a null result. Name it explicitly so the synthesizer doesn't read "no results" as "no activity." -- **Notebooks aren't queryable.** The SQL MCP can't see Databricks notebooks. If you suspect the rationale lives in one, return a gap. - -## What to return - -For each relevant finding: -- Type (product event / experiment exposure / usage or billing event / system-table row / dbt model) -- Fully-qualified table name and the exact query you ran -- Time window queried -- Compact numeric summary (counts, percentiles, first/last-seen timestamps). **Don't dump raw rows.** -- Temporal correlation with the target's ship date (e.g., "first row 2024-08-15, PR #49074 merged 2024-08-14") -- Relevance + strength: direct / circumstantial / weak diff --git a/skills/why/references/sources/datadog.md b/skills/why/references/sources/datadog.md deleted file mode 100644 index 536466d..0000000 --- a/skills/why/references/sources/datadog.md +++ /dev/null @@ -1,97 +0,0 @@ -# Datadog Telemetry - -## What this source contains - -Datadog holds the runtime record, what actually happened in production, as opposed to what was planned or discussed. - -- **Metrics.** Counters, gauges, histograms instrumented by the team. A metric's *presence* is itself evidence that someone thought the number worth watching. -- **Monitors & alerts.** Conditions the team decided warranted waking someone up. A monitor firing on `rate_limit_hit > 10/min` is direct evidence the team worried about that threshold. -- **Dashboards.** Curated views of what the team considers important for a subsystem. -- **APM traces & spans.** Request-level runtime data, for "why is this slow" / "why is there a timeout here" questions. -- **Logs.** High-volume event records, often holding the error conditions that motivated defensive code. -- **Incidents.** Formal incident records with timelines and linked postmortems. -- **Notebooks.** The team's exploratory investigations, often with hypotheses and analyses. - -## How to search it - -Use the Datadog MCP. Start broad, then narrow. - -1. **Identify the owning service(s).** - - ``` - search_datadog_services (filter by name or team) - search_datadog_service_dependencies (see upstream/downstream) - ``` - -2. **Dashboards and monitors first.** - - ``` - search_datadog_dashboards (query: feature name, service name, symbol) - search_datadog_monitors (same queries) - ``` - - When a dashboard or monitor covers the target, note its queries and watched thresholds. The threshold is frequently the answer to "why is this clamped at N?" - -3. **Metrics around the target.** - - ``` - search_datadog_metrics (by name pattern, e.g., the feature or symbol) - get_datadog_metric_context (metadata: description, units, tags) - get_datadog_metric (timeseries; "was there a spike around the PR date?") - ``` - - Correlating a metric's trajectory with the target's add/change date is strong supporting evidence: "the `payment_timeout` metric spiked 2023-11-03, and the retry logic merged 2023-11-06." - -4. **Logs. Narrow, don't dump.** - - ``` - search_datadog_logs (raw log patterns near the target, set use_log_patterns=true) - analyze_datadog_logs (SQL-style aggregations, only when you need counts) - ``` - - Search with symbols, error strings, or feature names. **Strongly prefer time-bounded queries** (e.g., 30 days before/after the change). - -5. **APM spans and traces.** - - ``` - aggregate_spans (stats: "how often does this endpoint fail?") - search_datadog_spans (inspect individual spans) - get_datadog_trace (a specific trace ID) - ``` - - Useful for timeouts, retries, slow paths, and cross-service behavior. - -6. **Incidents.** - - ``` - search_datadog_incidents (by title, team, date range) - get_datadog_incident (full detail for a specific incident) - ``` - - If the target looks defensive, search for incidents around the time it was added. An incident whose timeline includes "added defensive check for X" is near-direct evidence. - -## What good evidence looks like here - -- A monitor whose query and threshold match the constraint the code enforces (code clamps to 100, monitor alerts when requests exceed 100/min) -- A dashboard created by the target's author, with widgets that correspond to what the code measures or guards against -- A metric showing a production spike immediately before the code was merged, and stable values after -- An incident record referencing the target code, the same symbols, or the same error strings -- Logs showing a specific error pattern the defensive code would prevent, timestamped in the window before the change - -## Common pitfalls - -- **Correlation is not causation.** A spike before a PR and stabilization after is suggestive, not definitive, since other changes may have landed in the same window. Check neighboring PRs. -- **Overfitting to the chart you found.** A chart reflects its maker's framing. A chart named "retry success rate" is evidence the team cared about retry success, not that it's why a specific line of code exists. -- **Vanished telemetry.** Metrics can be renamed, deleted, or have short retention. If you can't find data from the relevant window, that's a gap, not a null result. -- **Noise at scale.** Narrow log searches by service, tag, and time window aggressively. Use `analyze_datadog_logs` to aggregate rather than dumping raw logs. -- **Instrumented != caused.** A metric shows someone cared enough to measure something, not that the code was added *because* of it. Cross-reference with commit/PR dates. - -## What to return - -For each relevant item: -- Type (dashboard / monitor / metric / log pattern / trace / incident / notebook) -- Title or name -- Link or identifier (dashboard ID, monitor ID, metric name, incident ID) -- Owner/author and created/modified date -- The specific condition, query, or quote that bears on the question (verbatim where possible) -- Relevance: what this suggests about the target code, and how strong the connection is diff --git a/skills/why/references/sources/incident-postmortem.md b/skills/why/references/sources/incident-postmortem.md deleted file mode 100644 index e7397e7..0000000 --- a/skills/why/references/sources/incident-postmortem.md +++ /dev/null @@ -1,5 +0,0 @@ -# Incident & Postmortem Context - -- **Linear**: look for tickets labeled `incident`, `sev-*`, `postmortem-action-item`, `reliability` -- **Slack**: search `#sev-*` and `#incident-*` channels around the dates the target code was added -- **Git**: commits with messages like "fix for incident", "add defensive check", "revert" followed by "re-apply with..." are strong signals diff --git a/skills/why/references/sources/linear.md b/skills/why/references/sources/linear.md deleted file mode 100644 index 899c643..0000000 --- a/skills/why/references/sources/linear.md +++ /dev/null @@ -1,48 +0,0 @@ -# Linear Tickets - -## What this source contains - -- Issues describing features, bugs, and their motivation -- Project docs attached to issues (often PRDs or specs) -- Parent/sub-issue relationships (broader initiative → specific tickets) -- Comments on issues (clarifications, scope changes, "why we're doing this" rationale) -- Labels (e.g., `compliance`, `customer-request`, `perf`) that signal the type of motivation -- Status updates that explain scope changes -- Attachments and linked GitHub PRs - -Linear is where the product/business context often lives: the "we're doing this because customer X asked" or "this is for the Q3 compliance initiative" layer. - -## How to search it - -Use the Linear MCP. - -1. **Start with linked tickets.** If the seed commits or PRs reference ticket IDs (e.g., `ENG-1234`, `[BUG-567]`), fetch those first with `get_issue`. Read the full issue including comments. -2. **List related issues by keyword.** Use `list_issues` with text search for the feature name, key symbol, or business term. Try multiple phrasings. -3. **Walk the issue tree.** If you land on a sub-issue, fetch its parent. Sub-issues are tactical. Parents often carry the "why." -4. **Read project docs.** If the issue belongs to a project, use `get_project` and check attached docs. Project-level documents are where specs and rationale are most often captured. -5. **Check labels and milestones.** Labels hint at the category of motivation (customer-request, incident-followup, compliance). Milestones tie work to deadlines, which often reveal motivation. - -## What good evidence looks like here - -- An issue description stating the business problem: "Customer Acme needs X because of their SOC2 audit" -- A comment recording a decision: "We decided to go with approach B because approach A would require touching the billing service" -- A parent issue titled like an initiative: "Q3 Enterprise Readiness" or "Reduce Payment Failures" -- An attached PRD or spec -- Labels like `customer:acme`, `incident-followup`, `compliance`, `perf-regression` - -## Common pitfalls - -- **Scope drift.** The ticket the PR references may have been closed and reopened with a different scope. Read the whole history. -- **Mechanical templates.** Some teams require "Why" sections but fill them with boilerplate. Generic text ("improve user experience") is probably not a real answer. -- **Stale tickets.** Old tickets often reflect a version of the plan that changed. Check dates and cross-reference with the code's ship date. -- **Closed-as-duplicate chains.** Follow the duplicate-of relationships back to the canonical ticket. -- **Private workspace content.** If you can't access an issue, note that as a gap rather than guessing. - -## What to return - -For each relevant ticket: -- Ticket ID and title -- The problem/motivation quoted from the description or comments (not paraphrased. The synthesizer needs the exact text to cite) -- Labels, parent issue, project -- Author, created date, closed date -- Link to the ticket if available diff --git a/skills/why/references/sources/notion.md b/skills/why/references/sources/notion.md deleted file mode 100644 index d16230a..0000000 --- a/skills/why/references/sources/notion.md +++ /dev/null @@ -1,55 +0,0 @@ -# Notion Docs - -## What this source contains - -- PRDs (product requirement documents) -- Technical specs and RFCs -- Architectural decision records (ADRs) -- Meeting notes from design reviews -- Team pages with domain context -- Postmortems from incidents -- Runbooks that may explain defensive code -- Strategy documents that set priorities - -Notion is where "why" often lives in long-form before it becomes code. A significant feature usually has a doc. - -## How to search it - -Use the Notion MCP. - -1. **Keyword searches with `notion-search`.** Try: - - The feature name - - Key symbols / class names from the target code - - Author handles (design docs are often authored before the code lands) - - Error strings or user-visible terms - - Time-bounded queries if you know when the code shipped -2. **Fetch candidate pages with `notion-fetch`.** Read the full content, not the preview. Rationale is often buried mid-document. -3. **Follow backlinks and child pages.** Design docs often have sub-pages for alternatives considered, appendices, or implementation notes. -4. **Check related databases.** `notion-query-data-sources` and `notion-query-meeting-notes` can surface meeting notes that discussed the decision. -5. **Search author-specific spaces.** If the PR author has a personal notebook (common at some companies), it may hold exploratory thinking that preceded the code. - -## What good evidence looks like here - -- A PRD with a "Problem statement" or "Motivation" section that matches the target code's purpose -- An "Alternatives considered" or "Rejected approaches" section -- A postmortem that names the target code as the fix for a specific incident -- Meeting notes that record "we decided X because Y" and tie to the same author/date range as the PR -- An ADR template filled out non-trivially (status, context, decision, consequences) - -## Common pitfalls - -- **Outdated docs.** Specs are often written before implementation and not updated. The doc may describe a plan that changed. Cross-check against the actual PR. -- **Doc vs. reality drift.** A spec may say "we'll do X" but the code actually does Y. Flag the divergence. The synthesizer will surface the contradiction. -- **Boilerplate templates.** Some orgs require a "Why" section that gets filled with fluff. Look for specificity. -- **Unlinked docs.** The most relevant doc may not be linked from anywhere. Broad keyword searches help. -- **Multiple drafts.** If a topic has multiple docs, find the one that was finalized or most recently updated. Check dates. -- **Access-restricted pages.** If you can't access a page, note it as a gap. - -## What to return - -For each relevant doc: -- Title and URL -- Authors and last-updated date -- The motivation text (verbatim quote), with page/section location -- Relevant linked pages (so the synthesizer can cite them) -- Whether the doc was finalized or draft diff --git a/skills/why/references/sources/sentry.md b/skills/why/references/sources/sentry.md deleted file mode 100644 index 8200fd9..0000000 --- a/skills/why/references/sources/sentry.md +++ /dev/null @@ -1,66 +0,0 @@ -# Sentry Error History - -## How to search it - -Use the Sentry MCP. - -1. **Orient.** If you don't know the project slug and organization: - - ``` - find_organizations - find_projects - ``` - -2. **Search for issues related to the target.** - - ``` - search_issues (natural language, e.g., "errors in PaymentService timeout", "unhandled exceptions in uploadFile") - ``` - - Build queries from the exception class names the target handles, its function or class name, the error message strings it checks for, and its file path. - -3. **Narrow by release and time window.** - - ``` - search_issue_events (filter by release, time, environment, trace ID, tags) - get_issue_tag_values (for an issue, see distribution across versions, users, environments) - ``` - - For a suspected issue, check **first seen** and **last seen** (does the stop line up with the target's ship date?), the **affected releases** (which saw it, and which was the fix?), and the **frequency trajectory** (did it spike, then get resolved?). - -4. **Pull the full event for context.** - - ``` - get_sentry_resource (pass a Sentry URL or type+ID) - ``` - - Does the stack trace pass through the target code? Do the tags and breadcrumbs match the conditions the target defends against? - -5. **Check releases that landed near the target.** - - ``` - find_releases (around the commit date of the target) - ``` - - Cross-reference release version with the PR's merge date. - -6. **Use Seer sparingly.** - - ``` - analyze_issue_with_seer - ``` - - Seer's AI root-cause analyses are a hypothesis generator. Treat them as inference, not authoritative. The actual events and stack traces are the primary evidence. - -## What to return - -For each relevant issue: -- Issue ID and title -- Project and organization -- First seen / last seen timestamps -- Event count (and sampling rate if known) -- Affected releases -- A representative stack trace snippet showing relevance to the target (verbatim excerpt, not summary) -- First/last-seen correlation with the target's ship date -- Link to the issue -- Any author comments or resolution notes diff --git a/skills/why/references/sources/slack.md b/skills/why/references/sources/slack.md deleted file mode 100644 index cadd561..0000000 --- a/skills/why/references/sources/slack.md +++ /dev/null @@ -1,17 +0,0 @@ -# Slack Conversations - -## How to search it - -Slack MCP tools vary. Check which Slack MCP is available and inspect its tool schema first. It may require `mcp_auth`. If authentication fails, stop and report the gap. - -1. **Author-bounded search.** Messages from the PR author around the PR merge date. Limits scope dramatically and often hits gold. -3. **PR URL search.** Slack often links PRs when they're reviewed or discussed. Search for the PR URL (or just `/pull/`). -4. **Error string search.** If the code handles a specific error, search for the error string. Incident threads often surface. - -## Common pitfalls - -- **Channel archaeology limits.** Very old messages may be gone due to retention policies. If you can't find anything before a certain date, note the retention cliff. -- **Unsearched DMs.** Many decisions happen in DMs that aren't searchable. You'll miss them. That's a known limitation. -- **Speculative jokes as "decisions."** Slack is casual. "Lol just do the thing" isn't a decision, even if it preceded the commit. Look for considered discussion. -- **Context collapse in single messages.** Without the thread, a single message often reads differently than in context. Always fetch threads. -- **Auth failures.** If the MCP isn't authenticated, stop. Don't make up findings. Report that Slack wasn't searchable. diff --git a/skills/why/references/synthesizer-prompt.md b/skills/why/references/synthesizer-prompt.md deleted file mode 100644 index 287a350..0000000 --- a/skills/why/references/synthesizer-prompt.md +++ /dev/null @@ -1,129 +0,0 @@ -# Synthesizer Prompt Template - -Fill in the placeholders. - ---- - -You are answering a "why" question about a piece of code by synthesizing findings from investigators who searched different historical sources (source control, issue / ticket tracker, long-form documents, real-time team chat, infrastructure observability, error / exception tracking, product analytics warehouse, and code comments). Produce a confidence-weighted, evidence-cited narrative that says honestly what the evidence supports, and just as honestly what it doesn't. - -## The Question - -> {QUESTION} - -## The Code Anchor - -**Target files:** {FILES_WITH_LINE_RANGES} - -**Key symbols:** {SYMBOLS} - -## Investigator Findings - -{ALL_INVESTIGATOR_FINDINGS} - -## Sources That Weren't Searched - -{SKIPPED_SOURCES_WITH_REASONS} - -## Epistemics Framework - -You MUST follow `references/epistemics.md`. Read it in full before writing. The key rules: - -1. Every claim must sit in one tier: **Direct**, **Supported**, **Inferred**, **Speculative**, **Unknown**. The tier sets its section and its phrasing. -2. Every Direct/Supported claim must have a citation (PR #, ticket ID, doc URL, chat permalink, commit hash, or file:line). -3. Inferred and Speculative claims must use hedged language ("appears to", "likely", "suggests", "one possibility is"). -4. Never cite code as evidence for its own intent. -5. Document gaps. Don't fill them with plausible-sounding guesses. -6. Treat a hypothesis embedded in the user's question as a candidate, not a conclusion. Check it independently. - -## Instructions - -1. **Read all investigator findings** and weigh the evidence yourself. Investigators gathered raw evidence, not conclusions. -2. **Merge overlaps.** When several investigators cite the same PR, ticket, or doc, give it one authoritative reference. -3. **Surface contradictions.** When two items disagree, show both. Don't pick one. -4. **Calibrate each claim.** Find its evidence and tier. Direct: cite it and state it plainly. Inferred: hedge it and show the inference. Speculative: mark it. No evidence: put it in the gaps. -5. **Verify citations by spot-checking.** If you're uncertain a cited item exists or says what the investigator claims, check it by reading the codebase or calling MCP tools. Don't propagate errors. Do not write files, commit, or modify external state. -6. **Don't overreach.** The user will act on this. Leave an open question open rather than fill it with a confident guess. - -## Output Format - -Write for the user, in this exact structure: - ---- - -### The Question - -Restate the user's question in one or two sentences. - -### The Code in Question - -File paths, line ranges, key symbols. Two or three lines to orient a cold reader. - -### What We Found - -Claims with textual evidence, each quoted or paraphrased and cited precisely: - -- **[Direct]** {Claim}. Source: [PR #123](url) / ticket ID / file:line. {Brief quote or paraphrase.} -- **[Supported]** {Claim}. Evidence: {list of items and what each contributes}. - -`[Direct]` is single-source, explicit evidence. `[Supported]` is multiple indirect items converging on a conclusion. - -### What We Can Reasonably Infer - -Claims stated nowhere but well-supported by indirect evidence. Each bullet must make the inference chain visible ("Given A and B, it's likely that C") and must use hedged language ("appears to", "likely", "suggests", "is consistent with"): - -- **[Inferred]** {Hedged claim}. Reasoning: {the specific evidence and the inference step}. - -Skip this section if there's nothing to infer. - -### Competing Hypotheses - -If the evidence fits multiple stories, present each. Don't force a winner the record doesn't support. For each hypothesis: - -- **Hypothesis:** {one-sentence statement} -- **Evidence for:** {specific items} -- **Evidence against or missing:** {what would need to be true but isn't, or what counter-signals exist} - -Skip this section if there's a single clear answer. - -### What We Don't Know - -Specific gaps: "We searched the issue tracker for [query1], [query2], [query3] and found no issue discussing the rate-limit threshold", not "We don't know why." Include: - -- Questions that went unanswered -- Searches that returned nothing -- Sources that were unavailable, and why (such as a missing real-time team chat MCP) -- People who would likely know but whom you can't ask - -### Sources Consulted - -What was actually searched, so the user can judge coverage and redirect: - -- **Source control history**: {file paths}, {number of commits reviewed}, PRs #{numbers}, and code comments searched. Or "Not searched. This should not happen because git and `gh` are always expected." -- **Issue / ticket tracker**: {ticket IDs and keyword searches}. Or "Not searched. No matching MCP available in this environment." -- **Long-form documents**: {page titles and search queries}. Or "Not searched. No matching MCP available in this environment." -- **Real-time team chat**: {channels searched, date ranges, queries}. Or "Not searched. No matching MCP available in this environment." -- **Infrastructure observability**: {dashboards, monitors, metrics, logs, traces, or incidents searched}. Or "Not searched. No matching MCP available in this environment." -- **Error / exception tracking**: {issues, events, or releases searched}. Or "Not searched. No matching MCP available in this environment." -- **Product analytics warehouse**: {fully-qualified tables queried, the time windows, and the numeric summaries (counts, percentiles, first/last-seen timestamps) that bore on the question}. Or "Not searched. No matching MCP available in this environment." - -### Confidence Summary - -One or two sentences on overall confidence, e.g.: - -> "The core rationale (A) is well-supported by direct PR and ticket evidence. The specific threshold value (100) is inferred from the surrounding context but not explicitly documented. The question of whether this was driven by a customer request could not be answered. No relevant issue tracker or long-form doc content surfaced, and real-time team chat search was unavailable." - ---- - -## Quality Check Before Returning - -Revise if any item fails: - -1. Does every claim in "What We Found" have a citation? If not, add one or move it to "Inferred" or "Hypotheses." -2. Is the phrasing tier-appropriate? (Direct claims can use "because". Inferred claims cannot.) -3. Did you surface every contradiction you noticed, or quietly pick one? -4. Does "What We Don't Know" name specific gaps? If it's empty or missing, be suspicious. Historical investigations almost always have gaps. -5. Did you check any hypothesis embedded in the question against the evidence rather than rubber-stamp it? -6. Did you cite code as evidence for its own intent? Remove it. Code is mechanics, not motivation. -7. Is the tone calibrated? A confident-sounding answer on weak evidence is the exact failure this skill exists to prevent. - -The value of this output is its honesty, not its authority. A reader who takes it to the original author, an engineering lead, or a product manager should know what's known, what's inferred, and what's missing, so they can ask the right follow-up questions. Optimize for being useful, not for looking decisive. diff --git a/upstream.lock.json b/upstream.lock.json index f95f065..70ae5a1 100644 --- a/upstream.lock.json +++ b/upstream.lock.json @@ -2,7 +2,7 @@ "repository": "https://github.com/cursor/plugins.git", "ref": "main", "path": "pstack", - "commit": "ae5650febf4320793844c12c4adaa937f417f8da", + "commit": "bf0c7cd80abdbf7fe47b634978a7d1b4071f71a7", "sourceRoots": [ { "source": "pstack/skills", From cae18ec09b4e7a56bfc1d9eb1e895dac6681ab6b Mon Sep 17 00:00:00 2001 From: chen <23054115+cwkang1998@users.noreply.github.com> Date: Mon, 16 Nov 2026 05:17:20 +0700 Subject: [PATCH 2/3] chore(verify): fail a sync that drops the fork's routing decisions forkInvariants lists the fork's routing and workflow decisions by file and phrase, and verify fails when a sync loses one. routingRegressions lists upstream wording that bypasses the routing, such as model-slug fallbacks and the Subagents section, and verify fails when a sync brings it back. The upstream-sync workflow runs verify before it opens the update pull request. --- README.md | 5 +++++ scripts/verify.mjs | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/README.md b/README.md index 4d9b8c6..53a3adb 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,11 @@ npm run sync:apply Protected adaptation changes require a human merge decision. The updater never silently overwrites them. +`npm run verify` also checks the fork's own decisions, listed as +`forkInvariants` and `routingRegressions` in `scripts/verify.mjs`. A sync that +drops one of them, or brings back upstream wording that bypasses the model +routing, fails before the update pull request opens. + ## Development and verification ```bash diff --git a/scripts/verify.mjs b/scripts/verify.mjs index da754a2..06d5956 100644 --- a/scripts/verify.mjs +++ b/scripts/verify.mjs @@ -188,6 +188,54 @@ for (const path of markdownFiles) { } } +// Upstream wording that would undo the fork's model routing if a sync brought it back. +const routingRegressions = [ + "use the default and say so", + "closest valid agent", + "closest valid slug", + "Subagents section", + "fast or standard speed", + "a different model after", + "omit `model`", + "run_in_background", + "readonly: true", + "pstack-models.mdc", + "high-fast", + "gemini-4-carbon", +]; +for (const path of markdownFiles) { + const source = await readFile(path, "utf8"); + for (const phrase of routingRegressions) { + if (source.includes(phrase)) { + failures.push(`${relative(root, path)} contains "${phrase}", which bypasses the fork's model routing`); + } + } +} + +// Decisions the fork made on purpose. A sync that resolves a conflict toward upstream drops one of these. +const forkInvariants = [ + ["skills/pstack-omp/SKILL.md", "compare the agent's entry with the line's value", "the drift check before each config-line spawn"], + ["skills/pstack-omp/SKILL.md", "Send no `effort` on a spawn for a config line", "the rule that overrides set the level"], + ["skills/pstack-omp/SKILL.md", "Never start the role on another agent or model", "the fail-closed rule"], + ["skills/pstack-omp/SKILL.md", "write proc:///kill", "OMP's live task tools"], + ["skills/poteto-mode/SKILL.md", "so send no effort setting for it", "the no-effort rule"], + ["skills/poteto-mode/playbooks/orchestrate.md", "Never retry on another model", "the no-model-switch retry rule"], + ["skills/setup-pstack/SKILL.md", "Then write `task.agentModelOverrides`", "setup writing the overrides"], + ["skills/setup-pstack/SKILL.md", "before_subagent_spawn", "setup's refusal rules"], + ["skills/arena/SKILL.md", "start entry N on its seat agent", "arena's seat routing"], + ["skills/arena/SKILL.md", "start entry N on its judge agent", "arena's judge routing"], + ["skills/architect/SKILL.md", "as the **arena** skill's Phase A step 3 says", "architect's seat routing"], + ["skills/swarm/SKILL.md", "names for the `swarm workers` line", "swarm's worker routing"], + ["skills/reflect/SKILL.md", "names for its lens's role line", "reflect's lens routing"], + ["README.md", "Protected adaptation changes require a human merge decision", "the README's sync wording"], +]; +for (const [path, phrase, decision] of forkInvariants) { + const source = await readFile(join(root, path), "utf8").catch(() => ""); + if (!source.includes(phrase)) { + failures.push(`${path} no longer has ${decision} ("${phrase}")`); + } +} + for (const path of skillFiles) { if (/^(<{7}|>{7}) /mu.test(await readFile(path, "utf8"))) { failures.push(`${relative(root, path)} contains unresolved merge conflict markers`); From f734730306b5845c53db5576dde815ef1fd788d7 Mon Sep 17 00:00:00 2001 From: chen <23054115+cwkang1998@users.noreply.github.com> Date: Mon, 16 Nov 2026 05:20:45 +0700 Subject: [PATCH 3/3] refactor(verify): check structure instead of hard-coded names and phrases Drop the required-skill list, the package.json name and keyword checks, the upstream lock field checks, the forbidden-token list, routingRegressions and forkInvariants. Every skill directory now needs a SKILL.md whose name is the directory. Links, skill:// references and named skills must resolve, and root JSON files must parse. Routing checks derive from the files: the Model routing table must cover exactly the config lines setup-pstack writes, seat agents come from each panel line's entry count, every routed agent must be in the roster, and an agent made for one config line must name only its own role as its model. --- README.md | 13 +- scripts/verify.mjs | 364 +++++++++++---------------------------------- 2 files changed, 91 insertions(+), 286 deletions(-) diff --git a/README.md b/README.md index 53a3adb..2f925e2 100644 --- a/README.md +++ b/README.md @@ -118,11 +118,6 @@ npm run sync:apply Protected adaptation changes require a human merge decision. The updater never silently overwrites them. -`npm run verify` also checks the fork's own decisions, listed as -`forkInvariants` and `routingRegressions` in `scripts/verify.mjs`. A sync that -drops one of them, or brings back upstream wording that bypasses the model -routing, fails before the update pull request opens. - ## Development and verification ```bash @@ -135,8 +130,12 @@ bun install --cwd skills/statechart-dashboard/scripts --frozen-lockfile bun test skills/statechart-dashboard/scripts ``` -`npm run verify` checks skill inventory, frontmatter, local references, manifests, -the upstream lock, and forbidden vendor-specific runtime bindings. +`npm run verify` checks that every skill and agent has matching frontmatter, that +links, `skill://` references, and named skills resolve, and that no merge +conflict markers remain. It also checks that the adapter's Model routing table +covers exactly the config lines `setup-pstack` writes, routes only to agents in +its roster, and that an agent made for one config line names no model but its +own override. ## Host contract diff --git a/scripts/verify.mjs b/scripts/verify.mjs index 06d5956..0d5a01f 100644 --- a/scripts/verify.mjs +++ b/scripts/verify.mjs @@ -3,316 +3,122 @@ import { join, relative, resolve } from "node:path"; const root = resolve(import.meta.dirname, ".."); const skillsRoot = join(root, "skills"); -const requiredSkills = new Set([ - "architect", - "arena", - "automate-me", - "blast-radius", - "bro", - "create-verification-skill", - "figure-it-out", - "how", - "interrogate", - "maintain-verification-skill", - "no-comments", - "poteto-mode", - "pstack-omp", - "recall", - "reflect", - "setup-pstack", - "show-me-your-work", - "swarm", - "tdd", - "teach", - "technical-writing", - "typescript-best-practices", - "unslop", - "why", - "reproduce-and-fix-issues", - "setup-benny", - "triage-issue-reports", - "principle-boundary-discipline", - "principle-build-the-lever", - "principle-encode-lessons-in-structure", - "principle-exhaust-the-design-space", - "principle-experience-first", - "principle-fix-root-causes", - "principle-foundational-thinking", - "principle-guard-the-context-window", - "principle-laziness-protocol", - "principle-make-operations-idempotent", - "principle-migrate-callers-then-delete-legacy-apis", - "principle-minimize-reader-load", - "principle-model-the-domain", - "principle-never-block-on-the-human", - "principle-outcome-oriented-execution", - "principle-prove-it-works", - "principle-redesign-from-first-principles", - "principle-separate-before-serializing-shared-state", - "principle-sequence-verifiable-units", - "principle-subtract-before-you-add", - "principle-type-system-discipline", - "rust-best-practices", - "ketchup", - "ketchup-video", - "sharpen", - "in-your-own-words", - "statechart", - "create-formal-verification-skill", - "maintain-formal-verification-skill", - "grill-me", - "grilling", - "grill-with-docs", - "domain-modeling", - "wizard", - "statechart-dashboard", -]); - +const agentsRoot = join(root, "agents"); const failures = []; -const skillDirs = (await readdir(skillsRoot, { withFileTypes: true })) - .filter((entry) => entry.isDirectory()) - .map((entry) => entry.name); +const rel = (path) => relative(root, path); +const exists = (path) => stat(path).then(() => true, () => false); -for (const name of requiredSkills) { - const path = join(skillsRoot, name, "SKILL.md"); - try { - const source = await readFile(path, "utf8"); - const frontmatter = source.match(/^---\n([\s\S]*?)\n---/u)?.[1] ?? ""; - if (!/^name:\s*\S+/mu.test(frontmatter)) { - failures.push(`${relative(root, path)} is missing frontmatter name`); - } - if (!/^description:\s*\S+/mu.test(frontmatter)) { - failures.push(`${relative(root, path)} is missing frontmatter description`); - } - } catch { - failures.push(`missing ${relative(root, path)}`); - } -} - -const skillFiles = []; -const collectAll = async (directory) => { +async function filesUnder(directory) { + const files = []; for (const entry of await readdir(directory, { withFileTypes: true })) { if (entry.name === "node_modules") continue; const path = join(directory, entry.name); - if (entry.isDirectory()) await collectAll(path); - else skillFiles.push(path); - } -}; -await collectAll(skillsRoot); -const markdownFiles = skillFiles.filter((path) => path.endsWith(".md")); - -for (const path of markdownFiles) { - const source = (await readFile(path, "utf8")).replace(/^(`{3,}|~{3,})[^\n]*\n[\s\S]*?^\1[ \t]*$/gmu, ""); - for (const match of source.matchAll(/\]\(([^)#][^)]*)\)/gu)) { - const target = match[1].split("#", 1)[0]; - if (target === "" || /^[a-z]+[0-9]*$/u.test(target)) continue; - if ( - target.startsWith("http://") || - target.startsWith("https://") || - target.startsWith("skill://") - ) continue; - const targetPath = resolve(path, "..", target); - try { - await stat(targetPath); - } catch { - failures.push(`${relative(root, path)} references missing ${target}`); - } + if (entry.isDirectory()) files.push(...(await filesUnder(path))); + else files.push(path); } + return files; } -for (const path of [ - join(root, "package.json"), - join(root, "upstream.lock.json"), -]) { - try { - JSON.parse(await readFile(path, "utf8")); - } catch { - failures.push(`${relative(root, path)} is not valid JSON`); - } +function frontmatter(source) { + const block = source.match(/^---\n([\s\S]*?)\n---/u)?.[1] ?? ""; + const scalar = (key) => block.match(new RegExp(`^${key}:[ \\t]*(\\S.*)$`, "mu"))?.[1]; + const list = (key) => + [...(block.match(new RegExp(`^${key}:\\n((?: - .*\\n?)*)`, "mu"))?.[1] ?? "").matchAll(/^ - "?([^"\n]+)"?$/gmu)].map((m) => m[1]); + return { scalar, list }; } -try { - const packageManifest = JSON.parse( - await readFile(join(root, "package.json"), "utf8") - ); - const requiredKeywords = [ - "pstack", - "agent-skills", - "coding-agent", - "omp", - ]; - if (packageManifest.name !== "pstack-omp") { - failures.push("package.json does not use the pstack-omp package name"); - } - if (!packageManifest.omp?.skills?.includes("./skills")) { - failures.push("package.json does not expose ./skills through the omp manifest"); - } - if (requiredKeywords.some((keyword) => !packageManifest.keywords?.includes(keyword))) { - failures.push("package.json is missing discoverability keywords"); - } - const upstreamLock = JSON.parse( - await readFile(join(root, "upstream.lock.json"), "utf8") - ); - if ( - upstreamLock.repository !== "https://github.com/cursor/plugins.git" || - upstreamLock.ref !== "main" || - !/^[0-9a-f]{40}$/u.test(upstreamLock.commit) || - !Array.isArray(upstreamLock.sourceRoots) - ) { - failures.push("upstream.lock.json is missing an authoritative pinned source"); - } -} catch { - // The JSON parse and existence failures above provide the actionable report. -} +const skillDirs = (await readdir(skillsRoot, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name); +const skillFiles = await filesUnder(skillsRoot); +const markdownFiles = [...skillFiles, ...(await filesUnder(agentsRoot)), join(root, "README.md")].filter((path) => path.endsWith(".md")); -const forbidden = [ - "~/.cursor/", - "~/.agents/skills/", - ".cursor/skills/", - ".cursor/plugins/", - "subagent_type:", - "AskQuestion", - "environment: \"cloud\"", - "claude-fable-5-thinking-max", - "gpt-5.6-sol-max", - "grok-4.6-fast-xhigh", - "claude-opus-5-thinking-xhigh", - "/scripts/statechart ", -]; -for (const path of markdownFiles) { - const source = await readFile(path, "utf8"); - for (const token of forbidden) { - if (source.includes(token)) { - failures.push(`${relative(root, path)} contains forbidden runtime binding ${token}`); - } +for (const name of skillDirs) { + const path = join(skillsRoot, name, "SKILL.md"); + if (!(await exists(path))) { + failures.push(`${rel(path)} is missing`); + continue; } + const meta = frontmatter(await readFile(path, "utf8")); + if (meta.scalar("name") !== name) failures.push(`${rel(path)} frontmatter name is not ${name}`); + if (!meta.scalar("description")) failures.push(`${rel(path)} has no description`); } -// Upstream wording that would undo the fork's model routing if a sync brought it back. -const routingRegressions = [ - "use the default and say so", - "closest valid agent", - "closest valid slug", - "Subagents section", - "fast or standard speed", - "a different model after", - "omit `model`", - "run_in_background", - "readonly: true", - "pstack-models.mdc", - "high-fast", - "gemini-4-carbon", -]; for (const path of markdownFiles) { const source = await readFile(path, "utf8"); - for (const phrase of routingRegressions) { - if (source.includes(phrase)) { - failures.push(`${relative(root, path)} contains "${phrase}", which bypasses the fork's model routing`); - } + const prose = source.replace(/^(`{3,}|~{3,})[^\n]*\n[\s\S]*?^\1[ \t]*$/gmu, ""); + for (const [, link] of prose.matchAll(/\]\(([^)#][^)]*)\)/gu)) { + const target = link.split("#", 1)[0]; + if (target === "" || /^[a-z]+[0-9]*$/u.test(target) || /^(https?|skill):\/\//u.test(target)) continue; + if (!(await exists(resolve(path, "..", target)))) failures.push(`${rel(path)} links to missing ${target}`); } -} - -// Decisions the fork made on purpose. A sync that resolves a conflict toward upstream drops one of these. -const forkInvariants = [ - ["skills/pstack-omp/SKILL.md", "compare the agent's entry with the line's value", "the drift check before each config-line spawn"], - ["skills/pstack-omp/SKILL.md", "Send no `effort` on a spawn for a config line", "the rule that overrides set the level"], - ["skills/pstack-omp/SKILL.md", "Never start the role on another agent or model", "the fail-closed rule"], - ["skills/pstack-omp/SKILL.md", "write proc:///kill", "OMP's live task tools"], - ["skills/poteto-mode/SKILL.md", "so send no effort setting for it", "the no-effort rule"], - ["skills/poteto-mode/playbooks/orchestrate.md", "Never retry on another model", "the no-model-switch retry rule"], - ["skills/setup-pstack/SKILL.md", "Then write `task.agentModelOverrides`", "setup writing the overrides"], - ["skills/setup-pstack/SKILL.md", "before_subagent_spawn", "setup's refusal rules"], - ["skills/arena/SKILL.md", "start entry N on its seat agent", "arena's seat routing"], - ["skills/arena/SKILL.md", "start entry N on its judge agent", "arena's judge routing"], - ["skills/architect/SKILL.md", "as the **arena** skill's Phase A step 3 says", "architect's seat routing"], - ["skills/swarm/SKILL.md", "names for the `swarm workers` line", "swarm's worker routing"], - ["skills/reflect/SKILL.md", "names for its lens's role line", "reflect's lens routing"], - ["README.md", "Protected adaptation changes require a human merge decision", "the README's sync wording"], -]; -for (const [path, phrase, decision] of forkInvariants) { - const source = await readFile(join(root, path), "utf8").catch(() => ""); - if (!source.includes(phrase)) { - failures.push(`${path} no longer has ${decision} ("${phrase}")`); + for (const [, name, subpath] of source.matchAll(/skill:\/\/([a-z0-9-]+)((?:\/[A-Za-z0-9._-]+)*)(?![A-Za-z0-9._<-])/gu)) { + if (!skillDirs.includes(name)) failures.push(`${rel(path)} refers to missing skill://${name}`); + else if (subpath && !(await exists(join(skillsRoot, name, subpath)))) failures.push(`${rel(path)} refers to missing skill://${name}${subpath}`); + } + for (const [, name, principle] of source.matchAll(/\*\*([a-z0-9-]+)\*\* (principle )?skill/gu)) { + const skill = principle && !name.startsWith("principle-") ? `principle-${name}` : name; + if (!skillDirs.includes(skill)) failures.push(`${rel(path)} names missing skill ${skill}`); } } for (const path of skillFiles) { - if (/^(<{7}|>{7}) /mu.test(await readFile(path, "utf8"))) { - failures.push(`${relative(root, path)} contains unresolved merge conflict markers`); - } + if (/^(<{7}|>{7}) /mu.test(await readFile(path, "utf8"))) failures.push(`${rel(path)} contains merge conflict markers`); } -const ompBundledAgents = new Set(["scout", "reviewer", "security-reviewer", "task", "sonic"]); -const packageAgents = new Map(); -for (const entry of await readdir(join(root, "agents"))) { - if (!entry.endsWith(".md")) continue; - const path = join(root, "agents", entry); - const frontmatter = (await readFile(path, "utf8")).match(/^---\n([\s\S]*?)\n---/u)?.[1] ?? ""; - const name = frontmatter.match(/^name:\s*(\S+)/mu)?.[1]; - if (name !== entry.slice(0, -3)) { - failures.push(`${relative(root, path)} frontmatter name does not match its filename`); - } - for (const key of ["description", "model"]) { - if (!new RegExp(`^${key}:`, "mu").test(frontmatter)) { - failures.push(`${relative(root, path)} is missing frontmatter ${key}`); - } +for (const entry of await readdir(root)) { + if (!entry.endsWith(".json")) continue; + try { + JSON.parse(await readFile(join(root, entry), "utf8")); + } catch { + failures.push(`${entry} is not valid JSON`); } - const list = (key) => [...(frontmatter.match(new RegExp(`^${key}:\\n((?: - .*\\n?)*)`, "mu"))?.[1] ?? "").matchAll(/^ - "?([^"\n]+)"?$/gmu)].map((match) => match[1]); - packageAgents.set(name, { path, tools: list("tools"), models: list("model") }); } -for (const [name, agent] of packageAgents) { - if (!name.startsWith("pstack-")) continue; - // A second model, or a role something else sets, would let the agent run without its override. - if (agent.models.length !== 1 || agent.models[0] !== `@${name}`) { - failures.push(`${relative(root, agent.path)} must name only its own role, @${name}, as its model`); - } - if (name.startsWith("pstack-judge-") && agent.tools.some((tool) => tool === "edit" || tool === "write")) { - failures.push(`${relative(root, agent.path)} is a judge and must not have edit or write`); - } + +const shippedAgents = new Map(); +for (const entry of await readdir(agentsRoot)) { + if (!entry.endsWith(".md")) continue; + const path = join(agentsRoot, entry); + const meta = frontmatter(await readFile(path, "utf8")); + const name = entry.slice(0, -3); + if (meta.scalar("name") !== name) failures.push(`${rel(path)} frontmatter name is not ${name}`); + if (!meta.scalar("description")) failures.push(`${rel(path)} has no description`); + if (meta.list("model").length === 0) failures.push(`${rel(path)} has no model`); + shippedAgents.set(name, { path, models: meta.list("model") }); } + +// The adapter's role map, roster, and Model routing table, and the config shape setup-pstack writes, +// describe one routing contract. These checks keep them consistent with each other and with agents/. const adapterPath = join(skillsRoot, "pstack-omp", "SKILL.md"); const adapter = await readFile(adapterPath, "utf8"); -const roster = adapter.match(/The reference roster is closed:\n\n```text\n([\s\S]*?)\n```/u)?.[1]; -const PANEL_SEATS = 3; -const lineAgents = new Map( - [...adapter.matchAll(/^\| `([a-z ,-]+)` \| `([a-z<>N-]+)` \|$/gmu)].map((match) => [match[1], match[2]]), -); -const mappedAgents = [ - ...[...adapter.matchAll(/^\| `[a-z]+` \| `([a-z-]+)` \|/gmu)].map((match) => match[1]), - ...[...lineAgents.values()].flatMap((agent) => - agent.includes("") ? Array.from({ length: PANEL_SEATS }, (_, i) => agent.replace("", String(i + 1))) : [agent], - ), -]; const setupPath = join(skillsRoot, "setup-pstack", "SKILL.md"); +const roster = new Set(adapter.match(/roster is closed:\n\n```text\n([\s\S]*?)\n```/u)?.[1].split("\n") ?? []); +const roleAgents = new Set([...adapter.matchAll(/^\| `[a-z]+` \| `([a-z-]+)` \|/gmu)].map((m) => m[1])); +const routing = new Map([...adapter.matchAll(/^\| `([a-z ,-]+)` \| `([a-z<>N-]+)` \|$/gmu)].map((m) => [m[1], m[2]])); const configShape = (await readFile(setupPath, "utf8")).match(/^```\n# pstack model configuration[\s\S]*?\n```/mu)?.[0] ?? ""; -const configLines = [...configShape.matchAll(/^([a-z][a-z ,-]*): /gmu)].map((match) => match[1]); -if (configLines.length === 0) failures.push(`${relative(root, setupPath)} has no config shape to check routing against`); -for (const line of configLines) { - if (!lineAgents.has(line)) { - failures.push(`${relative(root, adapterPath)} has no Model routing row for the ${line} line in ${relative(root, setupPath)}`); - } -} -for (const line of lineAgents.keys()) { - if (!configLines.includes(line)) { - failures.push(`${relative(root, adapterPath)} routes ${line}, which is not a line in ${relative(root, setupPath)}`); - } -} -if (!roster) failures.push(`${relative(root, adapterPath)} is missing the closed agent roster`); -for (const agent of new Set([...(roster?.split("\n") ?? []), ...mappedAgents])) { - if (!ompBundledAgents.has(agent) && !packageAgents.has(agent)) { - failures.push(`${relative(root, adapterPath)} routes to ${agent}, which is neither OMP-bundled nor shipped in agents/`); - } -} +const configLines = new Map([...configShape.matchAll(/^([a-z][a-z ,-]*): (.+)$/gmu)].map((m) => [m[1], m[2].split(",").length])); -const localRoutesUrl = "skill://pstack-omp/references/local-routes.md"; -const routerPath = join(skillsRoot, "poteto-mode", "SKILL.md"); -if (!(await readFile(routerPath, "utf8")).includes(localRoutesUrl)) { - failures.push(`${relative(root, routerPath)} no longer points to ${localRoutesUrl}`); -} -const localRoutesPath = join(skillsRoot, "pstack-omp", "references", "local-routes.md"); -for (const match of (await readFile(localRoutesPath, "utf8")).matchAll(/\*\*([a-z0-9-]+)\*\* skill/gu)) { - if (!skillDirs.includes(match[1])) { - failures.push(`${relative(root, localRoutesPath)} routes to missing skill ${match[1]}`); +if (roster.size === 0) failures.push(`${rel(adapterPath)} has no agent roster`); +if (configLines.size === 0) failures.push(`${rel(setupPath)} has no config shape`); +for (const line of configLines.keys()) { + if (!routing.has(line)) failures.push(`${rel(adapterPath)} has no Model routing row for the ${line} line`); +} +const routedAgents = new Set(roleAgents); +for (const [line, agent] of routing) { + if (!configLines.has(line)) { + failures.push(`${rel(adapterPath)} routes ${line}, which ${rel(setupPath)} does not write`); + continue; + } + const seats = agent.includes("") ? configLines.get(line) : 1; + for (let seat = 1; seat <= seats; seat++) routedAgents.add(agent.replace("", String(seat))); +} +for (const agent of routedAgents) { + if (!roster.has(agent)) failures.push(`${rel(adapterPath)} routes to ${agent}, which is not in its roster`); +} +for (const [name, agent] of shippedAgents) { + // An agent that exists only to carry a config line must have no model but its override, or it could + // run on another model when the override is missing. + if (!routedAgents.has(name) || roleAgents.has(name)) continue; + if (agent.models.length !== 1 || agent.models[0] !== `@${name}`) { + failures.push(`${rel(agent.path)} must name only @${name} as its model`); } }