@codename_inc/spectre 3.7.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +6 -7
  2. package/package.json +3 -2
  3. package/plugins/spectre/.claude-plugin/plugin.json +1 -1
  4. package/plugins/spectre/bin/spectre-register +5 -0
  5. package/plugins/spectre/hooks/hooks.json +3 -14
  6. package/plugins/spectre/hooks/scripts/bootstrap.mjs +98 -0
  7. package/plugins/spectre/hooks/scripts/handoff-resume.mjs +404 -0
  8. package/plugins/spectre/hooks/scripts/lib.mjs +82 -0
  9. package/plugins/spectre/hooks/scripts/load-knowledge.mjs +189 -0
  10. package/plugins/spectre/hooks/scripts/register_learning.mjs +264 -0
  11. package/plugins/spectre/hooks/scripts/{test_bootstrap.cjs → test_bootstrap.mjs} +12 -7
  12. package/plugins/spectre/hooks/scripts/{test_handoff-resume.cjs → test_handoff-resume.mjs} +13 -11
  13. package/plugins/spectre/hooks/scripts/{test_load-knowledge.cjs → test_load-knowledge.mjs} +103 -22
  14. package/plugins/spectre/hooks/scripts/test_register-learning.mjs +335 -0
  15. package/plugins/spectre/skills/apply/SKILL.md +87 -0
  16. package/plugins/spectre/{commands/architecture_review.md → skills/architecture_review/SKILL.md} +9 -0
  17. package/plugins/spectre/{commands/clean.md → skills/clean/SKILL.md} +9 -0
  18. package/plugins/spectre/{commands/code_review.md → skills/code_review/SKILL.md} +9 -0
  19. package/plugins/spectre/{commands/create_plan.md → skills/create_plan/SKILL.md} +9 -0
  20. package/plugins/spectre/{commands/create_tasks.md → skills/create_tasks/SKILL.md} +9 -0
  21. package/plugins/spectre/{commands/create_test_guide.md → skills/create_test_guide/SKILL.md} +9 -0
  22. package/plugins/spectre/{commands/evaluate.md → skills/evaluate/SKILL.md} +11 -2
  23. package/plugins/spectre/{commands/execute.md → skills/execute/SKILL.md} +12 -3
  24. package/plugins/spectre/{commands/fix.md → skills/fix/SKILL.md} +9 -0
  25. package/plugins/spectre/{commands/forget.md → skills/forget/SKILL.md} +9 -0
  26. package/plugins/spectre/skills/{spectre-guide → guide}/SKILL.md +6 -5
  27. package/plugins/spectre/{commands/handoff.md → skills/handoff/SKILL.md} +9 -0
  28. package/plugins/spectre/{commands/kickoff.md → skills/kickoff/SKILL.md} +9 -0
  29. package/plugins/spectre/skills/{spectre-learn → learn}/SKILL.md +19 -59
  30. package/plugins/spectre/skills/learn/references/recall-template.md +34 -0
  31. package/plugins/spectre/{commands/plan.md → skills/plan/SKILL.md} +66 -25
  32. package/plugins/spectre/{commands/plan_review.md → skills/plan_review/SKILL.md} +9 -0
  33. package/plugins/spectre/skills/prototype/SKILL.md +314 -0
  34. package/plugins/spectre/{commands/quick_dev.md → skills/quick_dev/SKILL.md} +9 -0
  35. package/plugins/spectre/{commands/rebase.md → skills/rebase/SKILL.md} +9 -0
  36. package/plugins/spectre/skills/recall/SKILL.md +17 -0
  37. package/plugins/spectre/{commands/research.md → skills/research/SKILL.md} +9 -0
  38. package/plugins/spectre/skills/scope/SKILL.md +174 -0
  39. package/plugins/spectre/{commands/ship.md → skills/ship/SKILL.md} +9 -0
  40. package/plugins/spectre/{commands/sweep.md → skills/sweep/SKILL.md} +9 -0
  41. package/plugins/spectre/skills/tdd/SKILL.md +111 -0
  42. package/plugins/spectre/{commands/test.md → skills/test/SKILL.md} +9 -0
  43. package/plugins/spectre/skills/ux/SKILL.md +121 -0
  44. package/plugins/spectre/{commands/validate.md → skills/validate/SKILL.md} +9 -0
  45. package/plugins/spectre-codex/agents/analyst.toml +117 -0
  46. package/plugins/spectre-codex/agents/dev.toml +65 -0
  47. package/plugins/spectre-codex/agents/finder.toml +101 -0
  48. package/plugins/spectre-codex/agents/patterns.toml +203 -0
  49. package/plugins/spectre-codex/agents/reviewer.toml +123 -0
  50. package/plugins/spectre-codex/agents/sync.toml +146 -0
  51. package/plugins/spectre-codex/agents/tester.toml +205 -0
  52. package/plugins/spectre-codex/agents/web-research.toml +104 -0
  53. package/plugins/spectre-codex/hooks/hooks.json +23 -0
  54. package/plugins/{spectre/hooks/scripts/bootstrap.cjs → spectre-codex/hooks/scripts/bootstrap.mjs} +15 -16
  55. package/plugins/{spectre/hooks/scripts/handoff-resume.cjs → spectre-codex/hooks/scripts/handoff-resume.mjs} +21 -27
  56. package/plugins/{spectre/hooks/scripts/lib.cjs → spectre-codex/hooks/scripts/lib.mjs} +3 -4
  57. package/plugins/spectre-codex/hooks/scripts/load-knowledge.mjs +189 -0
  58. package/plugins/spectre-codex/hooks/scripts/register_learning.mjs +264 -0
  59. package/plugins/spectre-codex/skills/apply/SKILL.md +87 -0
  60. package/plugins/spectre-codex/skills/architecture_review/SKILL.md +129 -0
  61. package/plugins/spectre-codex/skills/clean/SKILL.md +322 -0
  62. package/plugins/spectre-codex/skills/code_review/SKILL.md +417 -0
  63. package/plugins/spectre-codex/skills/create_plan/SKILL.md +126 -0
  64. package/plugins/spectre-codex/skills/create_tasks/SKILL.md +383 -0
  65. package/plugins/spectre-codex/skills/create_test_guide/SKILL.md +129 -0
  66. package/plugins/spectre-codex/skills/evaluate/SKILL.md +59 -0
  67. package/plugins/spectre-codex/skills/execute/SKILL.md +96 -0
  68. package/plugins/spectre-codex/skills/fix/SKILL.md +70 -0
  69. package/plugins/spectre-codex/skills/forget/SKILL.md +67 -0
  70. package/plugins/spectre-codex/skills/guide/SKILL.md +359 -0
  71. package/plugins/spectre-codex/skills/handoff/SKILL.md +170 -0
  72. package/plugins/spectre-codex/skills/kickoff/SKILL.md +124 -0
  73. package/plugins/spectre-codex/skills/learn/SKILL.md +595 -0
  74. package/plugins/{spectre/skills/spectre-learn → spectre-codex/skills/learn}/references/recall-template.md +4 -1
  75. package/plugins/spectre-codex/skills/plan/SKILL.md +211 -0
  76. package/plugins/spectre-codex/skills/plan_review/SKILL.md +42 -0
  77. package/plugins/spectre-codex/skills/prototype/SKILL.md +314 -0
  78. package/plugins/spectre-codex/skills/quick_dev/SKILL.md +110 -0
  79. package/plugins/spectre-codex/skills/rebase/SKILL.md +82 -0
  80. package/plugins/spectre-codex/skills/recall/SKILL.md +17 -0
  81. package/plugins/spectre-codex/skills/research/SKILL.md +168 -0
  82. package/plugins/spectre-codex/skills/scope/SKILL.md +174 -0
  83. package/plugins/spectre-codex/skills/ship/SKILL.md +181 -0
  84. package/plugins/spectre-codex/skills/sweep/SKILL.md +91 -0
  85. package/plugins/{spectre/skills/spectre-tdd → spectre-codex/skills/tdd}/SKILL.md +1 -1
  86. package/plugins/spectre-codex/skills/test/SKILL.md +389 -0
  87. package/plugins/spectre-codex/skills/ux/SKILL.md +121 -0
  88. package/plugins/spectre-codex/skills/validate/SKILL.md +352 -0
  89. package/src/config.test.js +6 -5
  90. package/src/install.test.js +100 -11
  91. package/src/lib/config.js +107 -54
  92. package/src/lib/constants.js +17 -23
  93. package/src/lib/doctor.js +19 -22
  94. package/src/lib/install.js +98 -313
  95. package/src/lib/knowledge.js +7 -37
  96. package/src/lib/paths.js +0 -12
  97. package/src/pack.test.js +87 -0
  98. package/plugins/spectre/commands/learn.md +0 -15
  99. package/plugins/spectre/commands/recall.md +0 -5
  100. package/plugins/spectre/commands/scope.md +0 -119
  101. package/plugins/spectre/commands/ux_spec.md +0 -91
  102. package/plugins/spectre/hooks/scripts/load-knowledge.cjs +0 -120
  103. package/plugins/spectre/hooks/scripts/precompact-warning.cjs +0 -19
  104. package/plugins/spectre/hooks/scripts/register_learning.cjs +0 -144
  105. package/plugins/spectre/hooks/scripts/test_register-learning.cjs +0 -146
  106. package/plugins/spectre/skills/spectre-apply/SKILL.md +0 -189
@@ -0,0 +1,181 @@
1
+ ---
2
+ name: "ship"
3
+ description: "👻 | Autonomous end-to-end: brain dump -> scope -> TDD -> commit -> rebase -> PR"
4
+ user-invocable: true
5
+ ---
6
+
7
+ # ship
8
+
9
+ ## Input Handling
10
+
11
+ Treat the current command arguments as this workflow's input. When invoked from a slash command, use the forwarded `$ARGUMENTS` value.
12
+
13
+ # ship: Autonomous End-to-End Delivery
14
+
15
+ Take a brain dump and autonomously produce a reviewable PR. Zero confirmation gates — scope, implement with TDD, sweep, rebase, and open a PR.
16
+
17
+ **Execution Style**: Fully autonomous. No user approval gates. Parse intent, build it, ship the PR.
18
+
19
+ ## ARGUMENTS
20
+
21
+ <ARGUMENTS> $ARGUMENTS </ARGUMENTS>
22
+
23
+ ## Step (1/8) - Parse Context
24
+
25
+ - **Action** — ParseBrainDump: Extract from ARGUMENTS:
26
+ - `INTENT_TYPE`: `feat` or `fix` (infer from context — new behavior = feat, broken behavior = fix)
27
+ - `TARGET_BRANCH`: Extract if specified (e.g., "rebase onto develop"), default `origin/main`
28
+ - `SCOPE_SUMMARY`: 1-2 sentence distillation of what to build/fix
29
+ - `RELEVANT_FILES`: Any files, components, or areas mentioned
30
+ - `CONTEXT`: Remaining context, constraints, preferences
31
+ - **Action** — ValidateInput:
32
+ - **If** ARGUMENTS empty → ask user for brain dump, then proceed autonomously
33
+ - **Else** → proceed
34
+
35
+ ## Step (2/8) - Ensure Worktree
36
+
37
+ - **Action** — DetectBranch: `git rev-parse --abbrev-ref HEAD`
38
+ - **If** already in a worktree or on a non-main branch (not `main`, not `master`) → use current context, proceed
39
+ - **If** on `main` or `master` → use `EnterWorktree` to create an isolated worktree
40
+ - **Action** — SetBranchName: Capture current branch name as `BRANCH_NAME` for artifact paths
41
+
42
+ ## Step (3/8) - Quick Scope
43
+
44
+ - **Action** — DispatchResearch: Spawn parallel lightweight agents:
45
+
46
+ - `@finder` — Locate files related to `RELEVANT_FILES` and `SCOPE_SUMMARY`
47
+ - `@analyst` — Understand the relevant code area, key interfaces, existing patterns
48
+
49
+ - **Action** — WriteScopeDoc: Create `docs/tasks/{BRANCH_NAME}/concepts/scope.md`:
50
+
51
+ ```markdown
52
+ # Scope: {SCOPE_SUMMARY}
53
+
54
+ ## Objective
55
+ {1-2 sentences from brain dump}
56
+
57
+ ## Type
58
+ {feat or fix}
59
+
60
+ ## In Scope
61
+ - {bullet list of what will be done}
62
+
63
+ ## Out of Scope
64
+ - {what this explicitly won't touch}
65
+
66
+ ## Target Branch
67
+ {TARGET_BRANCH}
68
+
69
+ ## Key Files
70
+ {from research — relevant files and their roles}
71
+ ```
72
+
73
+ Keep it \~20 lines. This is a lightweight scope, not full `scope`.
74
+
75
+ ## Step (4/8) - Create Tasks
76
+
77
+ - **Action** — CreateTasks: Use `TaskCreate` to create 3-8 tasks proportional to scope complexity.
78
+ - Each task gets: clear `subject` (imperative), `description` (what to do + acceptance criteria), `activeForm` (present continuous)
79
+ - Order tasks by dependency — foundational work first
80
+ - Tasks are ephemeral and operational — no file artifact needed
81
+
82
+ ## Step (5/8) - Execute with TDD
83
+
84
+ - **Action** — ExecuteLoop: For each task sequentially:
85
+
86
+ 1. `TaskUpdate` → `in_progress`
87
+ 2. Load `Skill(spectre-tdd)` for TDD methodology
88
+ 3. Execute: RED (write failing test) → GREEN (minimal implementation) → REFACTOR (clean up)
89
+ 4. Commit with conventional format: `{INTENT_TYPE}({scope}): {description}`
90
+ 5. `TaskUpdate` → `completed`
91
+
92
+ **Rules**:
93
+
94
+ - One commit per task minimum
95
+ - Conventional commit format always
96
+ - TDD methodology for implementation tasks (skip for config/doc-only tasks)
97
+ - If a task reveals new work, create additional tasks rather than scope-creeping the current one
98
+
99
+ ## Step (6/8) - Sweep
100
+
101
+ Inline sweep — same checklist as `sweep`, no subagents:
102
+
103
+ ### 6.1 Diff Sanity Check
104
+
105
+ - Review full diff for unintentional changes (whitespace-only edits, merge artifacts)
106
+ - Verify no accidentally staged files outside the intended scope
107
+ - Confirm no secrets, API keys, credentials, or sensitive data in diff
108
+
109
+ ### 6.2 Logging Audit
110
+
111
+ - Remove temporary/debug logging (console.log, print, debug flags)
112
+ - Preserve intentional logs: errors, critical warnings, key state transitions
113
+ - Verify log levels are appropriate for production context
114
+
115
+ ### 6.3 Code Hygiene
116
+
117
+ - Remove commented-out code (it's in git history if needed)
118
+ - Resolve or document any TODO/FIXME/HACK introduced in this session
119
+ - Remove hardcoded test values that should be config/env
120
+
121
+ ### 6.4 Opportunistic Dead Code Cleanup
122
+
123
+ - Orphaned imports with no usage in the file
124
+ - Unused variables or functions declared but never referenced
125
+ - Debug artifacts (debugger statements, leftover TODO/FIXME from this work)
126
+
127
+ ### 6.5 Lint (Strict)
128
+
129
+ - Run the project linter and **fix all violations** — no skipping, no eslint-disable
130
+ - Address structural lint issues by refactoring, not suppressing
131
+
132
+ ### 6.6 Test
133
+
134
+ - Run affected tests + full test suite
135
+ - Fix any failures caused by the changes
136
+ - Do NOT write new tests here — that was done in Step 5
137
+
138
+ ### 6.7 Commit Sweep Fixes
139
+
140
+ - If sweep produced changes, commit: `chore({scope}): sweep cleanup`
141
+
142
+ ## Step (7/8) - Rebase
143
+
144
+ - **Action** — FetchLatest: `git fetch origin`
145
+ - **Action** — CreateSafetyRef: `git branch backup/ship-$(date +%Y%m%d-%H%M%S)`
146
+ - **Action** — Rebase: `git rebase {TARGET_BRANCH}`
147
+ - **If** conflicts → resolve automatically, favoring target branch conventions
148
+ - Track resolution decisions for PR summary
149
+ - **Action** — VerifyPostRebase:
150
+ - Run linter — fix violations
151
+ - Run full test suite — fix failures
152
+ - Confirm commit count and no unexpected changes
153
+
154
+ ## Step (8/8) - Create PR
155
+
156
+ - **Action** — PushBranch: `git push -u origin {BRANCH_NAME}`
157
+
158
+ - **Action** — CreatePR: `gh pr create` with:
159
+
160
+ **Title**: `{INTENT_TYPE}({scope}): {SCOPE_SUMMARY}` (under 70 chars)
161
+
162
+ **Body**:
163
+
164
+ ```markdown
165
+ ## Summary
166
+ {From scope doc — objective and what was done}
167
+
168
+ ## Changes
169
+ {Bulleted list derived from completed tasks}
170
+
171
+ ## Test Plan
172
+ {Bulleted checklist — what was tested, what to verify manually}
173
+
174
+ Shipped autonomously via `ship`
175
+ ```
176
+
177
+ - **Action** — OutputPRUrl: Display the PR URL as the final deliverable
178
+
179
+ ## Next Steps
180
+
181
+ Use `Skill(spectre-guide)` skill to render the Next Steps footer.
@@ -0,0 +1,91 @@
1
+ ---
2
+ name: "sweep"
3
+ description: "👻 | Light pass cleanup - clean, lint, test, commit"
4
+ user-invocable: true
5
+ ---
6
+
7
+ # sweep
8
+
9
+ ## Input Handling
10
+
11
+ Treat the current command arguments as this workflow's input. When invoked from a slash command, use the forwarded `$ARGUMENTS` value.
12
+
13
+
14
+ ## Pre-Commit Sweep
15
+
16
+ You are preparing uncommitted or recently committed changes for check-in. Perform a systematic cleanup, then commit with descriptive conventional commits.
17
+
18
+ **Execution Style**: Fast, formulaic checklist. No subagents, no user approval gates. Execute each step and move on.
19
+
20
+ ### 1. Diff Sanity Check
21
+
22
+ - Review full diff for unintentional changes (whitespace-only edits, merge artifacts)
23
+ - Verify no accidentally staged files outside the intended scope
24
+ - Confirm no secrets, API keys, credentials, or sensitive data in diff
25
+
26
+ ### 2. Logging Audit
27
+
28
+ - Remove temporary/debug logging (console.log, print, debug flags, etc.)
29
+ - Preserve intentional logs: errors, critical warnings, key state transitions
30
+ - Verify log levels are appropriate for production context
31
+
32
+ ### 3. Code Hygiene
33
+
34
+ - Remove commented-out code (it's in git history if needed)
35
+ - Resolve or document any TODO/FIXME/HACK introduced in this session
36
+ - Remove hardcoded test values that should be config/env
37
+
38
+ ### 4. Opportunistic Dead Code Cleanup
39
+
40
+ Quick scan of changed files only — remove anything obviously dead, no deep investigation:
41
+
42
+ - Orphaned imports with no usage in the file
43
+ - Unused variables or functions declared but never referenced
44
+ - Commented-out code blocks
45
+ - Debug artifacts (debugger statements, leftover TODO/FIXME from this work)
46
+
47
+ Do not hunt for dead code beyond the changed files. This is opportunistic, not forensic.
48
+
49
+ ### 5. Lint (Strict)
50
+
51
+ - Run the project linter and **fix all violations** — no skipping, no eslint-disable
52
+ - Address structural lint issues (file size, complexity thresholds) by refactoring, not suppressing
53
+ - Verify .gitignore coverage (no temp files, build artifacts, IDE configs)
54
+
55
+ ### 6. Test
56
+
57
+ - Identify test files related to the changed files (co-located tests, imports, shared modules)
58
+ - Run those tests and the broader test suite
59
+ - Fix any failures caused by the changes
60
+ - Do NOT write new tests in this step — this is a sweep, not a test authoring pass
61
+
62
+ ### 7. Commit
63
+
64
+ Group changes into logical conventional commits. Commits are project history and critical context for LLMs and future developers — invest in making them descriptive.
65
+
66
+ **Format**: `type(scope): description`
67
+
68
+ **Types**: feat, fix, refactor, test, chore, docs, style, perf
69
+
70
+ **Grouping** — separate commits by concern:
71
+ - Feature/behavior additions → `feat`
72
+ - Refactors/cleanup with no behavior change → `refactor`
73
+ - Bug fixes → `fix`
74
+ - Test additions/updates → `test`
75
+ - Config/dependency changes → `chore`
76
+ - Documentation → `docs`
77
+
78
+ **Commit message quality**:
79
+ - Subject line answers: what changed and why (not "fix stuff" or "update files")
80
+ - Include scope to locate the change: `feat(auth): add token refresh on 401 response`
81
+ - If the commit touches multiple concerns, it's too big — split it
82
+ - Body (optional) adds context: motivation, trade-offs, what was considered and rejected
83
+
84
+ **Anti-patterns**:
85
+ - `fix: updates` — says nothing
86
+ - `refactor: clean up` — clean up what? why?
87
+ - One giant commit for unrelated changes
88
+
89
+ ### 8. Render Footer
90
+
91
+ Use `Skill(spectre-guide)` skill for Next Steps footer.
@@ -1,5 +1,5 @@
1
1
  ---
2
- name: spectre-tdd
2
+ name: "tdd"
3
3
  description: "Load this skill when executing TDD (Test-Driven Development) methodology. Use when implementing features via strict RED-GREEN-REFACTOR cycles, or when a prompt instructs execution via TDD."
4
4
  ---
5
5
 
@@ -0,0 +1,389 @@
1
+ ---
2
+ name: "test"
3
+ description: "👻 | Risk-aware test coverage & commit - primary agent"
4
+ user-invocable: true
5
+ ---
6
+
7
+ # test
8
+
9
+ ## Input Handling
10
+
11
+ Treat the current command arguments as this workflow's input. When invoked from a slash command, use the forwarded `$ARGUMENTS` value.
12
+
13
+ # test: test coverage with risk-aware focus
14
+
15
+ ## Description
16
+
17
+ - **What** — Triage changes into risk tiers, dispatch @tester subagents to fix lint and write **risk-appropriate tests** (not brute-force 100% line coverage), and commit after each passing batch.
18
+ - **Outcome** — All lint issues fixed, surgical test coverage that maximizes confidence while minimizing token cost, incremental commits per batch, artifacts recorded in OUT_DIR.
19
+ - **Philosophy** — Test behaviors at boundaries, not implementation details. Prioritize code that can hurt users when it breaks. Skip tests that only measure "was this line executed?" without verifying correctness.
20
+
21
+ ## ARGUMENTS Input
22
+
23
+ Optional scope hint or specific files to focus on.
24
+
25
+ <ARGUMENTS> $ARGUMENTS </ARGUMENTS>
26
+
27
+ ## Instructions
28
+
29
+ - Primary agent plans and verifies; @tester subagents write test code
30
+ - Maximize parallelism: dispatch multiple @tester agents simultaneously, not sequentially
31
+ - Primary agent coordinates; subagents execute test writing in parallel batches
32
+ - No OUT_DIR artifacts — this is a lightweight flow
33
+ - Risk assessment is inline reasoning, not a classification phase
34
+ - Test behaviors at boundaries, not implementation details
35
+ - Skip tests for P3 files (types, configs, simple wrappers)
36
+ - when committing, —no-verify and eslint-disable, or committing code with eslint-disable, is expressly forbidden without the user’s explicit permission.
37
+
38
+ ### Why Risk-Weighted > 100% Line Coverage
39
+
40
+ **100% line coverage is a vanity metric that:**
41
+
42
+ - Treats all code equally (a payment handler vs a string formatter)
43
+ - Tests implementation details (brittle, breaks on refactor)
44
+ - Creates maintenance burden (tests that slow you down)
45
+ - Gives false confidence (100% coverage ≠ 100% correctness)
46
+ - Burns tokens on code that can't break in production
47
+
48
+ **Risk-weighted coverage instead:**
49
+
50
+ - Focuses testing effort where bugs cause user pain
51
+ - Tests behaviors and contracts, not internal wiring
52
+ - Creates tests that survive refactoring
53
+ - Catches actual bugs via mutation-resistant assertions
54
+ - Dramatically reduces token cost while increasing safety
55
+
56
+ ### Risk Tier Definitions
57
+
58
+ #### P0 — Critical (Must Test Thoroughly)
59
+
60
+ **Identification patterns:**
61
+
62
+ - Path contains: `auth`, `payment`, `security`, `crypto`, `session`, `token`
63
+ - File has `@critical` JSDoc/comment annotation
64
+ - Handles: user data mutations, financial transactions, PII, permissions
65
+ - API handlers for external consumers
66
+ - Database migration files
67
+
68
+ **Coverage requirements:**
69
+
70
+ - 100% **behavioral** coverage (every user-facing outcome has a test)
71
+ - All error paths tested with specific error assertions
72
+ - Edge cases for security-sensitive inputs (null, empty, malformed, overflow)
73
+ - Contract tests for all public APIs (schema validation)
74
+ - Mutation-resistant assertions (would a bug actually fail this test?)
75
+
76
+ **Test quality bar:**
77
+
78
+ ```typescript
79
+ // ✅ GOOD P0 test - tests behavior and catches real bugs
80
+ it('rejects payment when card is expired', async () => {
81
+ const result = await processPayment({ card: expiredCard, amount: 100 });
82
+ expect(result.status).toBe('DECLINED');
83
+ expect(result.reason).toBe('CARD_EXPIRED');
84
+ expect(chargeService.charge).not.toHaveBeenCalled(); // Side effect prevented
85
+ });
86
+
87
+ // ❌ BAD test - tests implementation, not behavior
88
+ it('calls validateCard', async () => {
89
+ await processPayment({ card, amount: 100 });
90
+ expect(validateCard).toHaveBeenCalledWith(card);
91
+ });
92
+ ```
93
+
94
+ #### P1 — Core (Test Key Behaviors)
95
+
96
+ **Identification patterns:**
97
+
98
+ - Main feature components (not utility wrappers)
99
+ - API route handlers (internal)
100
+ - State management (stores, reducers, contexts)
101
+ - Core business logic
102
+ - Data fetching/caching layers
103
+
104
+ **Coverage requirements:**
105
+
106
+ - Happy path coverage for all public functions
107
+ - Critical error paths (ones users would see)
108
+ - Contract tests at team boundaries (exported APIs other modules consume)
109
+ - No need to test internal helper functions
110
+ - No need to test every code branch, just primary behaviors
111
+
112
+ **Test quality bar:**
113
+
114
+ ```typescript
115
+ // ✅ GOOD P1 test - covers the behavior users care about
116
+ it('fetches and caches user profile', async () => {
117
+ const profile = await getUserProfile(userId);
118
+ expect(profile.name).toBe('Joe');
119
+
120
+ // Second call uses cache
121
+ await getUserProfile(userId);
122
+ expect(api.get).toHaveBeenCalledTimes(1);
123
+ });
124
+
125
+ // ❌ SKIP - internal implementation detail
126
+ it('calls normalizeUserData internally', () => { ... });
127
+ ```
128
+
129
+ #### P2 — Supporting (Test Public Surface Only)
130
+
131
+ **Identification patterns:**
132
+
133
+ - Utility functions and helpers
134
+ - Internal services not exposed to other teams
135
+ - Formatters, validators, transformers
136
+ - Hooks that compose other hooks
137
+ - Adapters and wrappers
138
+
139
+ **Coverage requirements:**
140
+
141
+ - Public exported functions: happy path only
142
+ - Skip internal/private functions entirely
143
+ - Skip trivial functions (single-line returns, simple compositions)
144
+ - Only test if the function has logic worth verifying
145
+
146
+ **Test quality bar:**
147
+
148
+ ```typescript
149
+ // ✅ GOOD P2 test - public util with actual logic
150
+ it('formats currency correctly', () => {
151
+ expect(formatCurrency(1234.5, 'USD')).toBe('$1,234.50');
152
+ expect(formatCurrency(1234.5, 'EUR')).toBe('€1,234.50');
153
+ });
154
+
155
+ // ❌ SKIP - trivial wrapper with no logic
156
+ // export const getFullName = (u) => `${u.first} ${u.last}`;
157
+ ```
158
+
159
+ #### P3 — Low Risk (Skip Testing)
160
+
161
+ **Identification patterns:**
162
+
163
+ - TypeScript type definitions (`.d.ts`)
164
+ - JSON/YAML configuration files
165
+ - CSS/SCSS/Tailwind styles
166
+ - Markdown documentation
167
+ - Constants and enums (no logic)
168
+ - Re-export barrels (`index.ts` that just re-exports)
169
+ - Simple component wrappers (just pass props through)
170
+ - Build scripts and tooling config
171
+
172
+ **Coverage requirements:**
173
+
174
+ - **NO TESTS REQUIRED** — Types are the test
175
+ - Type checking + linting is sufficient
176
+ - These files cannot break at runtime in ways tests would catch
177
+
178
+ ### Test Quality Requirements (All Tiers)
179
+
180
+ #### Each test MUST:
181
+
182
+ - **Test ONE behavior** — Single assertion focus, clear failure message
183
+ - **Use descriptive names** — `when_[condition]_then_[outcome]` or `[action]_should_[result]`
184
+ - **Assert outcomes, not calls** — Verify what happened, not what was invoked
185
+ - **Be refactor-resilient** — Test should pass if behavior unchanged, even if internals change
186
+ - **Catch real bugs** — Ask: "If I introduced a bug, would this test fail?"
187
+
188
+ #### Each test MUST NOT:
189
+
190
+ - **Mock implementation details** — Don't mock internal functions
191
+ - **Assert on call counts** — Unless testing side-effect prevention
192
+ - **Duplicate type coverage** — Don't test that TS types are correct
193
+ - **Test framework behavior** — Don't test that React renders or Express routes
194
+
195
+ #### Mutation Testing Mindset
196
+
197
+ For every test, ask: "If I changed the implementation to return a wrong value, would this test catch it?"
198
+
199
+ ```typescript
200
+ // ✅ Mutation-resistant — changing the discount calculation would fail this
201
+ it('applies 20% discount for premium users', () => {
202
+ expect(calculateTotal({ items: [100], userTier: 'premium' })).toBe(80);
203
+ });
204
+
205
+ // ❌ NOT mutation-resistant — always passes regardless of implementation
206
+ it('calls calculateDiscount', () => {
207
+ calculateTotal({ items: [100], userTier: 'premium' });
208
+ expect(calculateDiscount).toHaveBeenCalled();
209
+ });
210
+ ```
211
+
212
+ ### Contract Tests at Team Boundaries
213
+
214
+ When your code is consumed by other teams/modules, add contract tests:
215
+
216
+ ```typescript
217
+ // API Contract Test
218
+ describe('UserAPI contract', () => {
219
+ it('GET /users/:id returns UserResponse schema', async () => {
220
+ const response = await request(app).get('/users/123');
221
+ expect(response.body).toMatchSchema(UserResponseSchema);
222
+ });
223
+
224
+ it('returns standard APIError shape on 404', async () => {
225
+ const response = await request(app).get('/users/nonexistent');
226
+ expect(response.status).toBe(404);
227
+ expect(response.body).toMatchSchema(APIErrorSchema);
228
+ });
229
+ });
230
+
231
+ // Event Contract Test
232
+ describe('UserCreated event contract', () => {
233
+ it('emits event matching UserCreatedEvent schema', async () => {
234
+ await createUser({ name: 'Test' });
235
+ expect(eventBus.lastEvent).toMatchSchema(UserCreatedEventSchema);
236
+ });
237
+ });
238
+ ```
239
+
240
+ ## Steps
241
+
242
+ ### Step 1/4 — Discover Full Working Set and Plan
243
+
244
+ - **Action** — DiscoverFullWorkingSet:
245
+ - Validate commit_id if provided
246
+ - Gather: committed changes + staged + unstaged + untracked
247
+ - **Full Working Set** = UNION of all sources
248
+ - **Action** — RecordWorkingSet: Write `OUT_DIR/working_set.json`
249
+ - **Action** — BaselineLintFull: Run lint on ALL files in Full Working Set
250
+ - **Action** — MapDependencies: Build import/dep snapshot
251
+
252
+ ### Step (2/4) - Risk Assessment & Test Plan
253
+
254
+ - **Action** — InlineRiskCheck: Quick mental triage of changed files
255
+
256
+ **P0 Critical** (thorough coverage required):
257
+
258
+ - Paths containing: `auth`, `payment`, `security`, `crypto`, `session`, `token`
259
+ - Handles: user data mutations, financial transactions, PII, permissions
260
+ - Has `@critical` annotation
261
+
262
+ **P1 Core** (key behaviors):
263
+
264
+ - API handlers, feature components, state management, services
265
+
266
+ **P2 Supporting** (public surface only):
267
+
268
+ - Utils, helpers, hooks, formatters
269
+
270
+ **P3 Skip** (no tests):
271
+
272
+ - Type definitions (`.d.ts`), configs, styles, index barrels, simple wrappers
273
+
274
+ - **Action** — CreateTestPlan: Write 3-7 bullet test plan
275
+
276
+ - Format: `- [P{tier}] {file}: {behavior to test}`
277
+ - P0 files get multiple bullets (all behaviors + error paths)
278
+ - P1 files get 1-2 bullets (happy path + critical errors)
279
+ - P2 files get 1 bullet (public function smoke test)
280
+ - P3 files listed as "SKIP — {reason}"
281
+
282
+ - **Action** - Update`OUT_DIR/working_set.json` with risk tier categorization.
283
+
284
+ ### Step (3/4) - Write Tests & Verify
285
+
286
+ - **Action** — DispatchTestWriter: Spawn MULTIPLE @tester subagents IN PARALLEL
287
+
288
+ - **Parallelization Strategy**:
289
+ - Partition test plan items into independent batches (by file or logical grouping)
290
+ - Dispatch one @tester per batch — aim for 3-5 parallel agents for medium scope, up to 8 for large scope
291
+ - Each agent receives: its batch of test plan items, file paths, risk tier context
292
+ - **Critical**: Use a single message with multiple Task tool calls to launch all agents simultaneously
293
+ - **Batching Heuristics**:
294
+ - P0 files: 1 agent per file (thorough coverage requires focus)
295
+ - P1 files: Group 2-3 related files per agent
296
+ - P2 files: Group 3-5 files per agent (lighter coverage)
297
+ - Instruct each: "Write behavioral tests, assert outcomes not calls, mutation-resistant"
298
+ - Wait for all agents to complete before proceeding to lint/test verification
299
+
300
+ - **Action** — RunLint: Execute linter; fix violations
301
+
302
+ - **If** lint fails → autofix first, then manual fix
303
+ - **Else** → continue
304
+
305
+ - **Action** — RunTests: Execute full test suite
306
+
307
+ - **If** tests fail → analyze failure, fix via @tester or direct edit
308
+ - **Else** → continue
309
+
310
+ - **Action** — VerifyQuality: Spot-check 1-2 tests
311
+
312
+ - Confirm: tests assert behaviors, would catch real bugs, survive refactoring
313
+ - **If** test quality poor → rework via @tester
314
+ - **Else** → continue
315
+
316
+ ### Step (4/4) - Commit
317
+
318
+ - **Action** — CommitPlanningArtifacts: Gather and commit planning/working docs FIRST
319
+ - Check for uncommitted files in `OUT_DIR/`:
320
+ - `working_set.json` (scope and risk tier categorization)
321
+ - Any other `.md` or `.json` artifacts created during this flow
322
+ - Check for uncommitted docs in `docs/tasks/{branch_name}/` or related planning directories
323
+ - **If** uncommitted planning artifacts exist:
324
+ - Stage all: `git add docs/tasks/{branch_name}/ OUT_DIR/`
325
+ - Commit: `docs(test): add test planning artifacts for {branch_name}`
326
+
327
+ - **Action** — GroupChanges: Organize code changes into logical commits
328
+
329
+ - Group by: feat/fix/refactor/test/chore
330
+ - Tests can be bundled with their feature or separate (your judgment)
331
+
332
+ - **Action** — CommitAll: Create conventional commits for code changes
333
+
334
+ - Format: `type(scope): description`
335
+ - Each commit answers: What changed and why?
336
+
337
+ - **Action** — RenderFooter: Render Next Steps footer using `Skill(spectre-guide)` skill (contains format template and spectre command options)
338
+
339
+ ## Next Steps
340
+
341
+ See `Skill(spectre-guide)` skill for footer format and command options.
342
+
343
+ ## Success Criteria
344
+
345
+ **Step 1 - Analyze Diff**:
346
+
347
+ - [ ] Scope identified (files changed) and documented
348
+
349
+ - [ ] Behaviors changed listed (not just file names)
350
+
351
+ **Step 2 - Risk Assessment & Test Plan**:
352
+
353
+ - [ ] Each changed file assigned P0-P3 tier
354
+
355
+ - [ ] Test plan created with 3-7 bullets
356
+
357
+ - [ ] P3 files explicitly marked SKIP
358
+
359
+ **Step 3 - Write Tests & Verify**:
360
+
361
+ - [ ] Multiple @tester agents dispatched in parallel (not sequential)
362
+
363
+ - [ ] Test plan partitioned into independent batches
364
+
365
+ - [ ] All agents launched in single message (parallel tool calls)
366
+
367
+ - [ ] P0 files have thorough behavioral coverage
368
+
369
+ - [ ] P1 files have key path coverage
370
+
371
+ - [ ] P2 files have public surface coverage
372
+
373
+ - [ ] P3 files have NO tests (confirmed skipped)
374
+
375
+ - [ ] Lint passes
376
+
377
+ - [ ] All tests pass
378
+
379
+ - [ ] Test quality spot-checked
380
+
381
+ **Step 4 - Commit**:
382
+
383
+ - [ ] Changes grouped logically
384
+
385
+ - [ ] Conventional commit format used
386
+
387
+ - [ ] Single Next Steps footer rendered
388
+
389
+ - [ ] Next steps guide read and options sourced