@nklisch/pi-agile-workflow 0.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/.claude-plugin/plugin.json +10 -0
  2. package/.codex-plugin/plugin.json +28 -0
  3. package/CHANGELOG.md +591 -0
  4. package/README.md +107 -0
  5. package/docs/ARCHITECTURE.md +716 -0
  6. package/docs/MIGRATION.md +419 -0
  7. package/docs/PRINCIPLES.md +464 -0
  8. package/docs/ROADMAP.md +95 -0
  9. package/docs/SPEC.md +855 -0
  10. package/docs/VISION.md +106 -0
  11. package/extensions/agile-workflow.test.ts +419 -0
  12. package/extensions/agile-workflow.ts +467 -0
  13. package/hooks/hooks.json +52 -0
  14. package/hooks/scripts/prompt-context.py +628 -0
  15. package/hooks/scripts/substrate-maintainer.py +359 -0
  16. package/hooks/scripts/test_prompt_context.py +757 -0
  17. package/package.json +30 -0
  18. package/scripts/install-work-view.sh +165 -0
  19. package/scripts/tests/agent-metadata.test.sh +75 -0
  20. package/scripts/tests/bump-version.test.sh +552 -0
  21. package/scripts/tests/channel-parity.test.sh +117 -0
  22. package/scripts/tests/convert-content-integrity.test.sh +246 -0
  23. package/scripts/tests/convert-install-routing.test.sh +159 -0
  24. package/scripts/tests/install-work-view.test.sh +411 -0
  25. package/scripts/tests/pi-package-metadata.test.sh +119 -0
  26. package/scripts/tests/work-board-shim.test.sh +239 -0
  27. package/scripts/tests/work-view-dist-version.test.sh +105 -0
  28. package/scripts/work-board.sh +64 -0
  29. package/scripts/work-view.sh +423 -0
  30. package/skills/autopilot/SKILL.md +330 -0
  31. package/skills/autopilot/agents/openai.yaml +6 -0
  32. package/skills/board/SKILL.md +62 -0
  33. package/skills/board/agents/openai.yaml +6 -0
  34. package/skills/bold-refactor/SKILL.md +244 -0
  35. package/skills/bold-refactor/agents/openai.yaml +6 -0
  36. package/skills/bug-scan/SKILL.md +378 -0
  37. package/skills/bug-scan/agents/openai.yaml +6 -0
  38. package/skills/bug-scan/references/async-promises.md +119 -0
  39. package/skills/bug-scan/references/concurrency-races.md +148 -0
  40. package/skills/bug-scan/references/data-layer.md +167 -0
  41. package/skills/bug-scan/references/error-handling.md +197 -0
  42. package/skills/bug-scan/references/gate-item-template.md +94 -0
  43. package/skills/bug-scan/references/language-footguns.md +219 -0
  44. package/skills/bug-scan/references/parked-item-template.md +103 -0
  45. package/skills/bug-scan/references/report-template.md +115 -0
  46. package/skills/bug-scan/references/resource-leaks.md +199 -0
  47. package/skills/bug-scan/references/state-closures.md +148 -0
  48. package/skills/bug-scan/references/time-numbers.md +158 -0
  49. package/skills/convert/SKILL.md +1463 -0
  50. package/skills/convert/agents/openai.yaml +6 -0
  51. package/skills/convert/references/legacy-overlap-migration.md +179 -0
  52. package/skills/deep-code-scan/SKILL.md +378 -0
  53. package/skills/deep-code-scan/agents/openai.yaml +6 -0
  54. package/skills/deep-code-scan/references/artifact-ledger.md +148 -0
  55. package/skills/deep-code-scan/references/consolidation.md +91 -0
  56. package/skills/deep-code-scan/references/decomposition.md +127 -0
  57. package/skills/deep-code-scan/references/item-templates.md +263 -0
  58. package/skills/deep-code-scan/references/lane-catalog.md +129 -0
  59. package/skills/deep-code-scan/references/review-gauntlet.md +108 -0
  60. package/skills/deep-code-scan/references/scanner-brief.md +152 -0
  61. package/skills/e2e-test-design/SKILL.md +517 -0
  62. package/skills/e2e-test-design/references/anti-tautology.md +261 -0
  63. package/skills/e2e-test-design/references/service-mocks.md +234 -0
  64. package/skills/e2e-test-design/references/test-taxonomy.md +211 -0
  65. package/skills/epic-design/SKILL.md +476 -0
  66. package/skills/epicize/SKILL.md +210 -0
  67. package/skills/epicize/agents/openai.yaml +6 -0
  68. package/skills/feature-design/SKILL.md +472 -0
  69. package/skills/fix/SKILL.md +173 -0
  70. package/skills/gate-cruft/SKILL.md +258 -0
  71. package/skills/gate-docs/SKILL.md +278 -0
  72. package/skills/gate-patterns/SKILL.md +389 -0
  73. package/skills/gate-refactor/SKILL.md +408 -0
  74. package/skills/gate-security/SKILL.md +275 -0
  75. package/skills/gate-tests/SKILL.md +367 -0
  76. package/skills/groom/SKILL.md +162 -0
  77. package/skills/groom/agents/openai.yaml +6 -0
  78. package/skills/ideate/SKILL.md +185 -0
  79. package/skills/ideate/agents/openai.yaml +6 -0
  80. package/skills/implement/SKILL.md +288 -0
  81. package/skills/implement-orchestrator/SKILL.md +604 -0
  82. package/skills/park/SKILL.md +111 -0
  83. package/skills/perf-design/SKILL.md +427 -0
  84. package/skills/perf-scout/SKILL.md +404 -0
  85. package/skills/perf-scout/agents/openai.yaml +6 -0
  86. package/skills/perf-scout/references/algorithmic-and-data-structures.md +126 -0
  87. package/skills/perf-scout/references/approximation-and-precomputation.md +136 -0
  88. package/skills/perf-scout/references/caching-and-memoization.md +123 -0
  89. package/skills/perf-scout/references/compiler-runtime-and-language.md +136 -0
  90. package/skills/perf-scout/references/database-and-storage-internals.md +144 -0
  91. package/skills/perf-scout/references/distributed-systems.md +150 -0
  92. package/skills/perf-scout/references/game-engine-and-realtime.md +136 -0
  93. package/skills/perf-scout/references/gpu-and-accelerators.md +130 -0
  94. package/skills/perf-scout/references/idea-ranking.md +75 -0
  95. package/skills/perf-scout/references/io-and-batching.md +135 -0
  96. package/skills/perf-scout/references/memory-and-data-locality.md +137 -0
  97. package/skills/perf-scout/references/parallelism-and-vectorization.md +126 -0
  98. package/skills/perf-scout/references/parked-item-template.md +117 -0
  99. package/skills/perf-scout/references/peer-review-pass.md +150 -0
  100. package/skills/perf-scout/references/report-template.md +148 -0
  101. package/skills/principles/SKILL.md +678 -0
  102. package/skills/principles/references/models.md +191 -0
  103. package/skills/principles/references/subagents.md +158 -0
  104. package/skills/prose-author/SKILL.md +185 -0
  105. package/skills/refactor-conventions-creator/SKILL.md +359 -0
  106. package/skills/refactor-conventions-creator/agents/openai.yaml +6 -0
  107. package/skills/refactor-conventions-creator/references/common-structures.md +91 -0
  108. package/skills/refactor-conventions-creator/references/common-styles.md +90 -0
  109. package/skills/refactor-design/SKILL.md +384 -0
  110. package/skills/release-deploy/SKILL.md +667 -0
  111. package/skills/release-deploy/agents/openai.yaml +6 -0
  112. package/skills/research/SKILL.md +166 -0
  113. package/skills/research/agents/openai.yaml +6 -0
  114. package/skills/review/SKILL.md +267 -0
  115. package/skills/review/references/deep-review.md +98 -0
  116. package/skills/review/references/review-lenses.md +68 -0
  117. package/skills/review/references/substrate-side-effects.md +161 -0
  118. package/skills/review/references/target-resolution.md +52 -0
  119. package/skills/scope/SKILL.md +486 -0
  120. package/work-view/Cargo.lock +486 -0
  121. package/work-view/Cargo.toml +9 -0
  122. package/work-view/crates/cli/.work-view-version +1 -0
  123. package/work-view/crates/cli/Cargo.toml +18 -0
  124. package/work-view/crates/cli/src/actionable.rs +500 -0
  125. package/work-view/crates/cli/src/args.rs +792 -0
  126. package/work-view/crates/cli/src/board/assets/board.css +855 -0
  127. package/work-view/crates/cli/src/board/assets/board.js +259 -0
  128. package/work-view/crates/cli/src/board/assets/card.js +139 -0
  129. package/work-view/crates/cli/src/board/assets/components.css +290 -0
  130. package/work-view/crates/cli/src/board/assets/dependency.js +1193 -0
  131. package/work-view/crates/cli/src/board/assets/detail.js +256 -0
  132. package/work-view/crates/cli/src/board/assets/filters.js +389 -0
  133. package/work-view/crates/cli/src/board/assets/index.html +77 -0
  134. package/work-view/crates/cli/src/board/assets/kanban.js +231 -0
  135. package/work-view/crates/cli/src/board/assets/markdown.js +260 -0
  136. package/work-view/crates/cli/src/board/assets/motion.css +131 -0
  137. package/work-view/crates/cli/src/board/assets/state.js +245 -0
  138. package/work-view/crates/cli/src/board/assets/table.js +304 -0
  139. package/work-view/crates/cli/src/board/assets/tokens.css +602 -0
  140. package/work-view/crates/cli/src/board/assets/views.js +41 -0
  141. package/work-view/crates/cli/src/board/assets.rs +162 -0
  142. package/work-view/crates/cli/src/board/feed.rs +204 -0
  143. package/work-view/crates/cli/src/board/mod.rs +246 -0
  144. package/work-view/crates/cli/src/board/open.rs +144 -0
  145. package/work-view/crates/cli/src/board/server.rs +407 -0
  146. package/work-view/crates/cli/src/main.rs +195 -0
  147. package/work-view/crates/cli/src/render.rs +354 -0
  148. package/work-view/crates/cli/src/scope.rs +157 -0
  149. package/work-view/crates/cli/src/stale.rs +581 -0
  150. package/work-view/crates/cli/tests/board-js/dependency-table.test.mjs +64 -0
  151. package/work-view/crates/cli/tests/board-js/expanded-browsing.test.mjs +79 -0
  152. package/work-view/crates/cli/tests/board-js/harness-smoke.test.mjs +11 -0
  153. package/work-view/crates/cli/tests/board-js/harness.mjs +437 -0
  154. package/work-view/crates/cli/tests/board-js/kanban-detail.test.mjs +75 -0
  155. package/work-view/crates/cli/tests/board-js/markdown-filter.test.mjs +60 -0
  156. package/work-view/crates/cli/tests/fixtures/golden/.work/CONVENTIONS.md +3 -0
  157. package/work-view/crates/cli/tests/fixtures/golden/.work/active/epics/epic-alpha.md +16 -0
  158. package/work-view/crates/cli/tests/fixtures/golden/.work/active/features/feat-a.md +16 -0
  159. package/work-view/crates/cli/tests/fixtures/golden/.work/active/features/feat-b.md +16 -0
  160. package/work-view/crates/cli/tests/fixtures/golden/.work/active/stories/story-alpha-1.md +16 -0
  161. package/work-view/crates/cli/tests/fixtures/golden/.work/active/stories/story-research-1.md +19 -0
  162. package/work-view/crates/cli/tests/fixtures/golden/.work/archive/feat-done.md +16 -0
  163. package/work-view/crates/cli/tests/fixtures/golden/.work/archive/feat-shipped.md +18 -0
  164. package/work-view/crates/cli/tests/fixtures/golden/.work/backlog/idea-backlog.md +7 -0
  165. package/work-view/crates/cli/tests/fixtures/golden/.work/releases/v1.0/v1.0.md +16 -0
  166. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/CONVENTIONS.md +6 -0
  167. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/active/features/feat-dep-done.md +17 -0
  168. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/active/features/feat-design-ready.md +17 -0
  169. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/active/features/feat-impl-ready.md +17 -0
  170. package/work-view/crates/cli/tests/fixtures/ready-drafting/.work/active/stories/story-review-ready.md +17 -0
  171. package/work-view/crates/cli/tests/fixtures/with-malformed/.work/CONVENTIONS.md +4 -0
  172. package/work-view/crates/cli/tests/fixtures/with-malformed/.work/active/epics/malformed-no-closing-fence.md +8 -0
  173. package/work-view/crates/cli/tests/fixtures/with-malformed/.work/active/features/good-item.md +16 -0
  174. package/work-view/crates/cli/tests/integration.rs +2833 -0
  175. package/work-view/crates/core/Cargo.toml +13 -0
  176. package/work-view/crates/core/src/error.rs +61 -0
  177. package/work-view/crates/core/src/filter.rs +804 -0
  178. package/work-view/crates/core/src/graph.rs +324 -0
  179. package/work-view/crates/core/src/index.rs +590 -0
  180. package/work-view/crates/core/src/lib.rs +54 -0
  181. package/work-view/crates/core/src/model.rs +202 -0
  182. package/work-view/crates/core/src/parse.rs +494 -0
  183. package/work-view/crates/core/tests/fixtures/golden/.work/CONVENTIONS.md +15 -0
  184. package/work-view/crates/core/tests/fixtures/golden/.work/active/epics/epic-core.md +16 -0
  185. package/work-view/crates/core/tests/fixtures/golden/.work/active/features/feat-parser.md +16 -0
  186. package/work-view/crates/core/tests/fixtures/golden/.work/active/features/feat-query.md +16 -0
  187. package/work-view/crates/core/tests/fixtures/golden/.work/active/stories/malformed-no-id.md +15 -0
  188. package/work-view/crates/core/tests/fixtures/golden/.work/active/stories/story-parse-unit.md +16 -0
  189. package/work-view/crates/core/tests/fixtures/golden/.work/active/stories/story-security-gate.md +16 -0
  190. package/work-view/crates/core/tests/fixtures/golden/.work/archive/feat-old.md +16 -0
  191. package/work-view/crates/core/tests/fixtures/golden/.work/archive/feat-parser.md +17 -0
  192. package/work-view/crates/core/tests/fixtures/golden/.work/backlog/idea-future-board.md +7 -0
  193. package/work-view/crates/core/tests/fixtures/golden/.work/releases/v1.0/v1.0.md +16 -0
  194. package/work-view/crates/core/tests/fixtures/precedence/.work/CONVENTIONS.md +10 -0
  195. package/work-view/crates/core/tests/fixtures/precedence/.work/archive/dup-item.md +18 -0
  196. package/work-view/crates/core/tests/fixtures/precedence/.work/releases/v2.0/dup-item.md +18 -0
  197. package/work-view/crates/core/tests/integration.rs +541 -0
  198. package/work-view/dist/.gitattributes +1 -0
  199. package/work-view/dist/README.md +42 -0
  200. package/work-view/dist/aarch64-apple-darwin/work-view +0 -0
  201. package/work-view/dist/aarch64-unknown-linux-musl/work-view +0 -0
  202. package/work-view/dist/x86_64-apple-darwin/work-view +0 -0
  203. package/work-view/dist/x86_64-unknown-linux-musl/work-view +0 -0
@@ -0,0 +1,111 @@
1
+ ---
2
+ name: park
3
+ description: >
4
+ ALWAYS invoke this skill when the user wants to capture an idea for later without derailing current
5
+ work — do not start working on the parked idea inline. Captures short ideas, richer context notes,
6
+ or roadmap-style multi-arc thoughts into the agile-workflow backlog under .work/backlog/ with
7
+ minimal frontmatter. Use when a new direction surfaces mid-flow and you shouldn't derail what's
8
+ currently in progress. Triggers on "park this", "park it", "remind me about X", "add to backlog",
9
+ "we should consider Y", "save this for later", "let's not lose this".
10
+ ---
11
+
12
+ # Park
13
+
14
+ You capture an idea into the project's `.work/backlog/` tier without interrupting
15
+ the current work. The captured file is intentionally unscoped — full kind, stage,
16
+ parent, dependency, and decomposition decisions happen later via
17
+ `/agile-workflow:scope`.
18
+
19
+ ## When to invoke
20
+
21
+ Auto-trigger on capture phrases:
22
+ - "park this", "park the idea of"
23
+ - "remind me about X later"
24
+ - "add to backlog"
25
+ - "we should consider X" (when the user clearly doesn't want to derail current work)
26
+ - "good idea — for later"
27
+
28
+ If the user is actively scoping or designing the captured idea, use `/agile-workflow:scope`
29
+ instead. Park is for the deferred-consideration case only.
30
+
31
+ ## Workflow
32
+
33
+ ### Phase 1: Verify substrate
34
+
35
+ Confirm `.work/CONVENTIONS.md` exists in the project. If not, halt:
36
+ > "No agile-workflow substrate found. Run `/agile-workflow:convert` to bootstrap, then
37
+ > retry."
38
+
39
+ ### Phase 2: Capture the idea
40
+
41
+ Preserve the user's useful context without turning park into design work:
42
+ - **Slug**: kebab-case `id`, prefixed `idea-` by default (e.g.,
43
+ `idea-csv-export`, `idea-multi-tenancy`). Use `roadmap-` only when the user
44
+ explicitly asks to park a roadmap-style or multi-arc capture. Keep it short —
45
+ 2-5 words.
46
+ - **Tags**: only if the user mentioned a clear category (e.g., "park this security
47
+ thought" → `[security]`). Otherwise leave empty.
48
+ - **Body**: size the capture to the input and situation. A simple idea can be
49
+ one paragraph. A rich idea can keep bullets, pasted notes, links, referenced
50
+ files, relevant constraints, or "current situation" context from the active
51
+ thread. A roadmap-style capture can preserve multiple possible epic/feature/story
52
+ arcs as raw notes. It is not a binding release roadmap or an active decomposition.
53
+
54
+ Only include information already supplied by the user or directly necessary to
55
+ make the parked thought intelligible later. You may lightly organize, dedupe, and
56
+ label that context. Do not add new requirements, propose fresh architecture, choose
57
+ kind/stage/parent/dependencies, or decompose the work beyond what the user already
58
+ said — those happen at scope/design time only when asked.
59
+
60
+ ### Phase 3: Write the file
61
+
62
+ Write to `.work/backlog/<id>.md`:
63
+
64
+ ```yaml
65
+ ---
66
+ id: <id>
67
+ created: YYYY-MM-DD # today's local date (matches the PostToolUse hook)
68
+ updated: YYYY-MM-DD # same as created at birth; the PostToolUse hook bumps it on every edit
69
+ tags: [<tag>, ...] # empty array if no clear category
70
+ ---
71
+
72
+ <idea body sized to the capture: one paragraph, bullets, or roadmap-style notes>
73
+ ```
74
+
75
+ `updated` is written equal to `created` so a backlog item carries a reliable
76
+ last-touched signal from birth (the hook is replace-only and cannot insert a
77
+ missing `updated:` line). It stays optional in the backlog contract — a legacy
78
+ item without it is treated as last-touched at `created`.
79
+
80
+ If a backlog file with the same `id` already exists, append a numeric suffix
81
+ (`idea-csv-export-2`, `roadmap-admin-ux-2`, etc.).
82
+
83
+ ### Phase 4: Commit
84
+
85
+ ```bash
86
+ git add .work/backlog/<id>.md
87
+ git commit -m "park: <id>"
88
+ ```
89
+
90
+ Then return to the prior conversation. Park is a side trip; don't expand on what was
91
+ captured beyond confirming the slug.
92
+
93
+ ## Output
94
+
95
+ One-line confirmation in conversation:
96
+ > "Parked: `<id>`"
97
+
98
+ ## Guardrails
99
+
100
+ - Park is a single-stride operation. Do NOT promote to active, do NOT design, do NOT
101
+ ask about scope, dependencies, or release binding. Those are scope's job.
102
+ - Do NOT proactively add design after invocation. Preserve and lightly organize
103
+ supplied context, but do not create new plans, requirements, acceptance criteria,
104
+ or decomposition unless the user explicitly included them in the parked thought.
105
+ - Do NOT compress rich context into a one-paragraph summary when that would lose
106
+ useful information. Low-friction capture means no extra process, not minimal
107
+ content at all costs.
108
+ - Do NOT skip the commit. Each park is a cheap, atomic git event so the user can revert
109
+ individual parks cleanly if needed.
110
+ - Do NOT add the parked item to the conversation's working context — the user wants it
111
+ out of mind so they can keep working on the current thread.
@@ -0,0 +1,427 @@
1
+ ---
2
+ name: perf-design
3
+ description: >
4
+ ALWAYS invoke when the user asks to profile performance, find bottlenecks, optimize code, make
5
+ something faster, or design a [perf]-tagged feature; do not optimize inline. Discovery mode profiles
6
+ likely hot paths and emits substrate items per bottleneck. Per-feature mode designs an existing
7
+ stage:drafting [perf] feature, writes the plan and benchmark scaffolds into the feature body, spawns
8
+ child stories, and advances drafting to implementing. Uses the hierarchy: algorithmic/data model,
9
+ I/O, data locality and CPU/cache behavior, language/runtime idioms, then parallelism. Route
10
+ greenfield work to feature-design and refactors to refactor-design.
11
+ ---
12
+
13
+ # Perf-Design
14
+
15
+ You diagnose performance bottlenecks via profiling, then design optimized solutions
16
+ following a strict optimization hierarchy. The plan lives in the feature item's body,
17
+ including benchmark scaffolds for the implementation pass.
18
+
19
+ Use the hierarchy to choose solution shape, and use the profiling taxonomy below
20
+ to choose what to measure. For low-level engines, runtimes, databases, compilers,
21
+ graphics/simulation code, storage/networking code, or any CPU-bound path with
22
+ tight throughput or tail-latency targets, CPU/cache behavior is first-class. If
23
+ you do not collect microarchitecture evidence for that class of work, state why.
24
+
25
+ ## Trigger
26
+
27
+ The agent picks this skill in two cases:
28
+ - A feature at `stage: drafting` with `tags: [perf, ...]` is ready for design (per-feature mode)
29
+ - The user asks to find perf candidates ("what's slow", "profile the codebase", "find perf issues") (discovery mode)
30
+
31
+ Common phrases:
32
+ - per-feature: "design the perf optimization for X", "plan the perf work on Y"
33
+ - discovery: "find perf issues", "what's slow here", "profile the codebase"
34
+
35
+ ## Invocation modes
36
+
37
+ | Invocation | Behavior |
38
+ |---|---|
39
+ | `perf-design` (no arg) / `--all` | **Discovery mode**: detect entry points, pick top 3-5 hot paths, profile, emit items |
40
+ | `perf-design <path>` | Discovery mode scoped to a path |
41
+ | `perf-design <NL scope>` (e.g. "the api layer") | Discovery mode scoped by NL filter |
42
+ | `perf-design <feature-id>` | **Per-feature mode**: design the perf work for an existing `[perf]`-tagged feature at `stage: drafting` |
43
+ | `perf-design --only-questions <id>` / `--only-questions --all` | Question-only alignment pass over `[perf]`-tagged drafting features. Captures answers under `## Design decisions`, does NOT design or advance stage. Requires interactive mode. |
44
+
45
+ Disambiguation: an arg is treated as a feature id only if
46
+ `.work/active/features/<arg>.md` exists and has `tags: [perf]`. Otherwise
47
+ discovery mode against the arg as path or NL scope.
48
+
49
+ ## Workflow — discovery mode
50
+
51
+ Use this path for `perf-design`, `--all`, `<path>`, or `<NL scope>`. Goal:
52
+ profile likely hot paths, emit items per bottleneck.
53
+
54
+ ### Phase D1: Resolve scope
55
+
56
+ - no arg / `--all` → whole codebase
57
+ - `<path>` → that directory or file
58
+ - `<NL scope>` → interpret against the codebase structure; log the interpretation
59
+
60
+ ### Phase D2: Detect entry points and pick top N
61
+
62
+ Discover candidate entry points: HTTP handlers, CLI commands, public library
63
+ APIs, batch job entrypoints, hot loops with measurable workload. Use Glob and
64
+ Grep against the target scope.
65
+
66
+ Pick the **top 3-5** entry points most likely to dominate runtime. Heuristics:
67
+ on critical user paths, called per-request or per-event, high call count from
68
+ logs/tests, known historically slow, contain nested loops or I/O.
69
+
70
+ If confidence is low about which to pick, ask via `structured question tool` (single
71
+ multi-select question). Log the picks.
72
+
73
+ **Cap the scan.** Never profile every function in the codebase.
74
+
75
+ ### Phase D3: Profile the picks
76
+
77
+ For each picked entry point, run the existing Phase 3-5 logic (detect &
78
+ research profiling tools, profile, diagnose). Capture top bottleneck per entry
79
+ point.
80
+
81
+ ### Phase D4: Emit items per bottleneck
82
+
83
+ | Bottleneck shape | Item kind | Stage |
84
+ |---|---|---|
85
+ | Single-site, surgical fix (e.g. eliminate one N+1) | story | `implementing` |
86
+ | Multi-site or needs a design pass / benchmarks | feature | `drafting` (with `[perf]` tag — per-feature mode picks up later) |
87
+
88
+ Set `gate_origin: perf-design`. Brief = bottleneck location + profiling
89
+ evidence + proposed hierarchy level + probe family.
90
+
91
+ Commit per batch:
92
+ ```bash
93
+ git add .work/active/stories/ .work/active/features/
94
+ git commit -m "perf-design discovery: <N> bottlenecks across <M> entry points"
95
+ ```
96
+
97
+ ### Phase D5: Output
98
+
99
+ In conversation:
100
+ - **Scope**: how the target was interpreted
101
+ - **Entry points profiled**: the picks
102
+ - **Bottlenecks**: count, with top hierarchy levels and probe families
103
+ - **Items emitted**: counts by kind with new ids
104
+ - **Next**: start an autopilot goal to drain, or run
105
+ `/agile-workflow:perf-design <feature-id>` per emitted feature for the
106
+ detailed design pass
107
+
108
+ ## Workflow — `--only-questions` mode
109
+
110
+ Mirrors `feature-design`'s `--only-questions` mode, scoped to `[perf]`-tagged
111
+ drafting features. Iterate over the target set:
112
+
113
+ 1. Read the feature; skip if not `[perf]`-tagged or not at `stage: drafting`
114
+ 2. Light ground (foundation docs + AGENTS.md / CLAUDE.md + existing benchmarks)
115
+ 3. Surface strategic ambiguities specific to perf (e.g., "what target
116
+ scenario?", "current vs desired measured throughput?", "target hardware?",
117
+ "acceptable memory or layout tradeoff for speed?"). Use structured question tool.
118
+ 4. Capture answers under `## Design decisions` in the feature body
119
+ 5. Do NOT design or advance stage
120
+ 6. Commit per feature: `perf-design --only-questions: <id>`
121
+
122
+ Requires interactive mode; refuse to run under an active autopilot run or goal.
123
+
124
+ ## The optimization hierarchy
125
+
126
+ Higher levels produce bigger wins with less complexity. Walk top-down for each
127
+ bottleneck.
128
+
129
+ | Priority | Level | Examples |
130
+ |---|---|---|
131
+ | 1 (highest) | **Algorithmic / data model** | Better data structures, reduced complexity class, eliminated redundant work, changed representation or traversal that reduces work |
132
+ | 2 | **I/O / service boundary** | Batched queries, connection pooling, eliminated N+1, reduced serialization, fewer syscalls |
133
+ | 3 | **Data locality / microarchitecture** | Contiguous access, hot/cold splits, AoS vs SoA, fewer pointer hops, cache/TLB locality, branch predictability, SIMD/vectorization, false-sharing fixes |
134
+ | 4 | **Language / runtime idioms** | Pre-allocation, avoiding copies/boxing, string builders, fewer temporary objects, lower GC pressure, monomorphization/devirtualization when measured |
135
+ | 5 (lowest) | **Parallelism** | Worker pools, async pipelines, concurrent data structures, sharding to reduce contention |
136
+
137
+ **Exception**: Parallelism moves up when the bottleneck is *inherently parallel* —
138
+ processing N independent requests sequentially, or a map operation over independent
139
+ items. In those cases, parallelism IS the algorithmic fix.
140
+
141
+ **Data-layout rule**: if changing layout changes the work model or traversal shape,
142
+ treat it as level 1. If the algorithm stays the same but the hot path is bound by
143
+ cache misses, TLB misses, branch misses, vectorization limits, or cache-line
144
+ contention, treat it as level 3.
145
+
146
+ ## Profiling taxonomy
147
+
148
+ Do not run every profiler. Pick probes that match the symptom, workload, and
149
+ runtime. Record skipped high-value probes when the target is low-level or
150
+ CPU-bound.
151
+
152
+ | Probe family | Finds | Typical evidence |
153
+ |---|---|---|
154
+ | **Workload baseline** | Real throughput/latency target, p50/p95/p99, warmup effects, regression budget | benchmark timings, load-test output, production trace/metric excerpts |
155
+ | **On-CPU time** | Hot functions, call paths, inefficient loops | CPU samples, wall/CPU flamegraphs, cumulative time |
156
+ | **Memory allocation / GC** | Allocation rate, retained heap, GC pauses, allocator overhead | allocs/op, bytes/op, heap profile, GC traces, RSS growth |
157
+ | **I/O and serialization** | Slow DB/network/disk calls, redundant round-trips, syscall overhead | traces/spans, query logs, syscall profiles, bytes transferred |
158
+ | **Off-CPU / synchronization** | Blocking, lock contention, scheduler delay, queueing | block/mutex profiles, off-CPU flamegraphs, run queue, context switches |
159
+ | **Microarchitecture** | IPC/CPI loss, cache/TLB misses, branch misses, frontend/backend stalls, vectorization limits | hardware counters, cache/branch profiles, compiler vectorization reports, instruction throughput analysis |
160
+ | **Cache-line / NUMA contention** | False sharing, remote memory access, cross-core cache bouncing | c2c/cache-line reports, remote vs local access counters, per-core contention evidence |
161
+
162
+ For low-level high-performance systems, include a microarchitecture pass when
163
+ the profile is CPU-bound: at minimum cycles/instructions/IPC, cache/LLC or TLB
164
+ misses, and branch misses when tooling permits. Add false-sharing/NUMA probes
165
+ when threads mutate adjacent or shared state.
166
+
167
+ ## Workflow — per-feature mode
168
+
169
+ ### Phase 1: Read the feature item
170
+
171
+ Read `.work/active/features/<id>.md`. Confirm:
172
+ - `kind: feature`
173
+ - `stage: drafting`
174
+ - `tags` includes `perf`
175
+
176
+ The brief should describe the perf problem and target. If it's vague:
177
+ - Autopilot mode: profile the hottest identifiable path, set a "2x current"
178
+ default target, log under `## Inferred targets` in the body. Halt only if
179
+ there's no measurable scenario at all (no entry point matching the brief).
180
+ - Otherwise: ask the user for target scenario, current measured performance,
181
+ desired performance.
182
+
183
+ ### Phase 2: Ground yourself
184
+
185
+ The principles skill auto-loads. Read:
186
+ - `docs/VISION.md`, `docs/SPEC.md` (perf targets may be specified)
187
+ - `AGENTS.md` / `CLAUDE.md`
188
+ - `.agents/rules/*.md` (if present) — the project's force-loaded agent rules
189
+ (tag semantics, test integrity, review policy)
190
+ - Existing benchmarks (search for benchmark files, perf tests, load tests)
191
+ - Existing test suite (so benchmarks follow the same patterns)
192
+ - Source code under investigation — read the target code thoroughly before profiling
193
+
194
+ ### Phase 3: Detect & research profiling tools
195
+
196
+ 1. Detect language and runtime from the project's source files and build config
197
+ 2. Spawn a research sub-agent:
198
+ - Use the host's generic/general-purpose subagent prompted with the explorer
199
+ capsule from `../principles/references/subagents.md`, at medium reasoning
200
+ for known stacks.
201
+ - Use high reasoning for unfamiliar runtimes or deeper investigations, and
202
+ strongest reviewer reasoning only for broad, high-risk perf redesigns.
203
+ - If no generic subagent adapter is available, keep the same host-local
204
+ research fallback.
205
+ Brief it:
206
+ "Find the recommended profiling tools for <language/runtime>. Return: CPU
207
+ profiler, memory/allocation profiler, I/O/tracing tool, lock/off-CPU profiler,
208
+ flamegraph workflow, and hardware-counter/cache/branch tools for CPU-bound or
209
+ low-level code. Include ecosystem-specific gotchas. Verify from current docs -
210
+ do not trust training data."
211
+ 3. Read the results before proceeding
212
+
213
+ ### Phase 4: Profile
214
+
215
+ Run profiling using the researched tools via Bash.
216
+
217
+ 1. **Workload baseline**: capture current throughput/latency with representative
218
+ input. Include warmup, input size, machine/runtime details, and the exact run
219
+ command when they affect repeatability.
220
+ 2. **CPU/latency**: profile the target code path. For a function: write a driver
221
+ script. For a server: use existing load tests or write a minimal one.
222
+ 3. **Memory**: track allocation counts and sizes; identify GC/allocator pressure
223
+ if applicable.
224
+ 4. **I/O / serialization**: inspect traces, query logs, syscall/network/disk
225
+ profiles, or spans when the hot path crosses process or storage boundaries.
226
+ 5. **Off-CPU / synchronization**: profile blocking time, mutexes, channels,
227
+ scheduler delay, and queueing when wall time exceeds on-CPU time or concurrent
228
+ work is involved.
229
+ 6. **Microarchitecture**: for CPU-bound or low-level high-perf paths, collect
230
+ counters for cycles, instructions, IPC/CPI, cache/LLC/TLB misses, and branch
231
+ misses when tooling permits. Use cache/branch profilers, compiler
232
+ vectorization reports, or instruction-throughput analyzers when they fit.
233
+ 7. **Cache-line / NUMA contention**: for multi-threaded hot paths, check false
234
+ sharing, cache-line bouncing, remote memory, and per-core contention when
235
+ shared or adjacent mutable state appears in the profile.
236
+ 8. **Flamegraphs** if the ecosystem supports them.
237
+ 9. **Save raw output** to a temp file for reference.
238
+
239
+ ### Phase 5: Diagnose
240
+
241
+ Analyze the profile to identify top bottlenecks.
242
+
243
+ 1. **Rank by impact** — sort hot spots by cumulative time or allocation volume
244
+ 2. **Categorize** each bottleneck by hierarchy level and probe family:
245
+ - Wrong complexity class, redundant work, or representation forces excess work? -> Algorithmic / data model
246
+ - Waiting on I/O, redundant calls, syscalls, or unnecessary serialization? -> I/O / service boundary
247
+ - CPU-bound with poor cache/TLB locality, pointer chasing, branch misses, vectorization limits, or false sharing? -> Data locality / microarchitecture
248
+ - Excess allocations, copies, boxing, temporary objects, GC pressure, or inefficient runtime construct? -> Language / runtime idiom
249
+ - Inherently parallel work being done sequentially, or contention solved by ownership/sharding? -> Parallelism
250
+ 3. **Identify the top 3-5 bottlenecks**. Don't try to fix everything.
251
+
252
+ For each bottleneck, note:
253
+ - File and function/method
254
+ - Profiling evidence (time %, allocation count, call count, IPC/cache/branch
255
+ counters, lock/off-CPU time, trace span, etc. as applicable)
256
+ - Current complexity class (if relevant)
257
+ - Why it's slow (root cause, not symptom)
258
+
259
+ ### Phase 6: Design solutions
260
+
261
+ For each bottleneck, walk the hierarchy top-down:
262
+
263
+ 1. **Algorithmic / data-model fix?** Better data structure, reduced work,
264
+ eliminated redundancy, changed layout/traversal that reduces the amount of
265
+ work?
266
+ If yes → design it. Stop here.
267
+ 2. **I/O fix?** Batching, pooling, eliminating round-trips, reducing serialization?
268
+ If yes → design it. Stop here.
269
+ 3. **Data-locality / microarchitecture fix?** Contiguous access, hot/cold split,
270
+ AoS/SoA change, fewer pointer hops, cache/TLB locality, predictable branches,
271
+ SIMD/vectorization, cache-line padding/alignment, NUMA locality, or reduced
272
+ false sharing?
273
+ If yes → design it. Stop here.
274
+ 4. **Language / runtime idiom fix?** Pre-allocation, avoiding copies/boxing,
275
+ fewer temporary objects, lower GC/allocator pressure, devirtualization, or
276
+ simpler constructs?
277
+ If yes → design it. Stop here.
278
+ 5. **Parallelism?** Or is the work inherently parallel (algorithmic)?
279
+ If yes → design it with explicit justification for why higher levels don't apply.
280
+
281
+ For each solution:
282
+ - Hierarchy level + probe family + why higher levels don't apply (skip this for level 1)
283
+ - Expected improvement (quantified: "O(n²) → O(n log n)" or "eliminates N round-trips")
284
+ - Expected metric movement (wall time, p99, allocations/op, cycles/op, IPC,
285
+ cache-miss rate, branch-miss rate, lock wait, bytes transferred)
286
+ - Exact file paths and function signatures
287
+ - Implementation notes for non-obvious logic
288
+ - Risk assessment (does this change behavior? thread safety concerns?)
289
+
290
+ ### Phase 7: Scaffold benchmarks
291
+
292
+ Write benchmark code that measures before/after.
293
+
294
+ 1. Determine benchmark location per project conventions. Adjacent to code under test
295
+ if no standard location exists.
296
+ 2. Write **before benchmarks** (baseline) using the language's standard benchmarking
297
+ framework (`testing.B` in Go, `pytest-benchmark` in Python, `vitest bench` in JS,
298
+ etc.).
299
+ 3. Write **after benchmark stubs** with comments indicating expected targets.
300
+ 4. Include representative input data — must exercise the actual hot path.
301
+ 5. For low-level CPU-bound optimizations, include hardware-counter or
302
+ cache/branch measurements in the benchmark command when the project tooling
303
+ supports them.
304
+
305
+ ### Phase 8: Spawn child stories
306
+
307
+ Each optimization that warrants its own implementation pass becomes a child story:
308
+ - `.work/active/stories/<feature-id>-opt-<N>.md`
309
+ - `kind: story`, `stage: implementing`, `parent: <feature-id>`,
310
+ `tags: [perf]`, `depends_on: [...]` (in order — usually higher-impact first)
311
+ - Body: the optimization's design + benchmark expectations
312
+
313
+ For trivial single-site optimizations, skip child stories.
314
+
315
+ ### Phase 9: Write plan INTO feature body
316
+
317
+ Append to the feature file:
318
+
319
+ ```markdown
320
+ ## Perf Overview
321
+ <what was profiled, key findings, summary of proposed optimizations>
322
+
323
+ ## Profiling Summary
324
+ <top hot spots with data, allocation patterns, flamegraph highlights>
325
+
326
+ ## Optimization Plan
327
+
328
+ ### Optimization 1: <name>
329
+ **Hierarchy Level**: Algorithmic / Data Model / I/O / Data Locality / Microarchitecture / Runtime Idiom / Parallelism
330
+ **Probe Family**: <CPU / memory / I/O / off-CPU / microarchitecture / cache-line / NUMA>
331
+ **Bottleneck**: <what's slow and why — cite profiling data>
332
+ **Expected Metric Movement**: <wall time, p99, allocations/op, cycles/op, cache misses, branch misses, lock wait, etc.>
333
+ **Why higher levels don't apply**: <skip for algorithmic-level fixes>
334
+ **Story**: `<story-id>` (if spawned)
335
+
336
+ #### Implementation Units
337
+
338
+ ##### Unit 1.1: <name>
339
+ **File**: `src/path/to/file.ext`
340
+
341
+ \`\`\`<lang>
342
+ // Exact interfaces, types, signatures
343
+ \`\`\`
344
+
345
+ **Implementation Notes**:
346
+ - <key detail>
347
+
348
+ **Acceptance Criteria**:
349
+ - [ ] Benchmark shows improvement of <X>
350
+ - [ ] Existing tests pass
351
+ - [ ] <specific behavioral criterion>
352
+
353
+ ---
354
+
355
+ ## Benchmarks
356
+ **Location**: <benchmark file path>
357
+ **Run command**: <command>
358
+ **Baseline targets**: <current measured>
359
+ **Expected targets**: <post-optimization>
360
+ **Counter targets**: <optional cycles/op, IPC, cache/branch miss rate, allocations/op>
361
+
362
+ ## Implementation Order
363
+ 1. <highest impact, lowest risk first>
364
+ 2. <next>
365
+ ```
366
+
367
+ ### Phase 10: Advance stage and commit
368
+
369
+ 1. Update feature frontmatter: `stage: drafting → implementing`.
370
+ 2. Commit (include the benchmark scaffolds):
371
+ ```bash
372
+ git add .work/active/features/<id>.md .work/active/stories/<feature-id>-opt-*.md <benchmark-files>
373
+ git commit -m "perf-design: <feature-id> (<N> optimizations)"
374
+ ```
375
+
376
+ ## Output
377
+
378
+ In conversation:
379
+ - **Designed**: `<feature-id>` advanced to `stage: implementing`
380
+ - **Top bottlenecks**: list with hierarchy level and probe family
381
+ - **Optimizations**: list ordered by impact
382
+ - **Benchmarks**: location and run command
383
+ - **Next**: `/agile-workflow:implement <story-id>` per optimization, or
384
+ `/agile-workflow:implement-orchestrator <feature-id>` for parallel agents
385
+
386
+ ## Common traps
387
+
388
+ - Reach for parallelism only after exhausting algorithmic, I/O, data-locality,
389
+ and language/runtime solutions — parallelism adds complexity, and higher-level
390
+ fixes often eliminate the bottleneck entirely
391
+ - Design solutions from profiling data, not intuition — gut feelings about
392
+ bottlenecks are frequently wrong
393
+ - **Focus effort on the hot path** — optimizing cold code wastes time for
394
+ unmeasurable gains. If a function takes 0.1% of total time, a 10x speedup is
395
+ invisible.
396
+ - Treat caching as a band-aid, not a fix — caching hides the real problem and
397
+ adds invalidation complexity. Only propose caching when the underlying work
398
+ is genuinely irreducible.
399
+ - Profile memory alongside CPU — GC pressure and allocation overhead are real
400
+ bottlenecks that CPU profiles miss
401
+ - Do not skip CPU/cache evidence for low-level CPU-bound systems. If hardware
402
+ counters or cache/branch tools are unavailable, say what blocked them and use
403
+ the nearest substitute.
404
+ - Treat microbenchmarks as evidence, not proof. Validate hot-path wins against
405
+ representative end-to-end workload, and control obvious noise: warmup, input
406
+ size, CPU frequency, debug builds, logging, and background load.
407
+ - Beware pointer chasing, branch unpredictability, cache-line bouncing, and NUMA
408
+ effects in concurrent low-level code. These often look like "CPU time" until
409
+ hardware counters or cache-line tools separate the cause.
410
+ - Research the ecosystem's profiling tools first — they vary dramatically and
411
+ using the wrong one wastes cycles
412
+
413
+ ## Guardrails
414
+
415
+ - Reach for parallelism only after exhausting higher levels — parallelism adds
416
+ complexity, and algorithmic/I/O fixes often eliminate the bottleneck entirely
417
+ - Design from profiling data, not intuition. Gut feelings are frequently wrong.
418
+ - Treat caching as a band-aid, not a fix. Caching hides the real problem and adds
419
+ invalidation complexity. Only propose caching when the underlying work is genuinely
420
+ irreducible.
421
+ - Profile memory alongside CPU. GC pressure and allocation overhead are real
422
+ bottlenecks that CPU profiles miss.
423
+ - For low-level CPU-bound work, include CPU/cache and branch evidence or record
424
+ why it was not available.
425
+ - Research the ecosystem's profiling tools first. Don't trust training data for
426
+ fast-moving tooling.
427
+ - The plan lives in the feature's body. NEVER create `docs/designs/perf-<name>.md`.