@massa-ai/cursor-plugin 1.6.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 (172) hide show
  1. package/.cursor-plugin/plugin.json +5 -0
  2. package/README.md +87 -0
  3. package/agents/massa-ai-architecture-specialist.md +65 -0
  4. package/agents/massa-ai-audit-specialist.md +81 -0
  5. package/agents/massa-ai-builder.md +67 -0
  6. package/agents/massa-ai-context-curator.md +67 -0
  7. package/agents/massa-ai-documentation-agent.md +65 -0
  8. package/agents/massa-ai-furps-analyst.md +71 -0
  9. package/agents/massa-ai-investigator.md +68 -0
  10. package/agents/massa-ai-mobile-specialist.md +82 -0
  11. package/agents/massa-ai-navigator.md +75 -0
  12. package/agents/massa-ai-plan-critic.md +90 -0
  13. package/agents/massa-ai-planner.md +65 -0
  14. package/agents/massa-ai-requirements-analyst.md +64 -0
  15. package/agents/massa-ai-reviewer.md +66 -0
  16. package/agents/massa-ai-test-engineer.md +66 -0
  17. package/agents/massa-ai-verification-agent.md +65 -0
  18. package/hooks/hooks.json +26 -0
  19. package/hooks/massa-ai-hook +298 -0
  20. package/install.sh +413 -0
  21. package/package.json +30 -0
  22. package/skills/agents/architecture-specialist/SKILL.md +69 -0
  23. package/skills/agents/audit-specialist/SKILL.md +85 -0
  24. package/skills/agents/builder/SKILL.md +71 -0
  25. package/skills/agents/context-curator/SKILL.md +71 -0
  26. package/skills/agents/documentation-agent/SKILL.md +69 -0
  27. package/skills/agents/furps-analyst/SKILL.md +74 -0
  28. package/skills/agents/investigator/SKILL.md +72 -0
  29. package/skills/agents/mobile-specialist/SKILL.md +86 -0
  30. package/skills/agents/navigator/SKILL.md +79 -0
  31. package/skills/agents/plan-critic/SKILL.md +93 -0
  32. package/skills/agents/planner/SKILL.md +69 -0
  33. package/skills/agents/requirements-analyst/SKILL.md +68 -0
  34. package/skills/agents/reviewer/SKILL.md +70 -0
  35. package/skills/agents/test-engineer/SKILL.md +70 -0
  36. package/skills/agents/verification-agent/SKILL.md +69 -0
  37. package/skills/def/SKILL.md +17 -0
  38. package/skills/find/SKILL.md +19 -0
  39. package/skills/graph/SKILL.md +16 -0
  40. package/skills/index/SKILL.md +19 -0
  41. package/skills/map/SKILL.md +24 -0
  42. package/skills/massa-ai/SKILL.md +315 -0
  43. package/skills/massa-ai/personas/README.md +35 -0
  44. package/skills/massa-ai/personas/ai-native-nodejs-cli-architect.md +76 -0
  45. package/skills/massa-ai/personas/catalog.json +157 -0
  46. package/skills/massa-ai/personas/context-skill-harness-engineer-architect.md +74 -0
  47. package/skills/massa-ai/personas/product-manager.md +67 -0
  48. package/skills/massa-ai/personas/senior-mobile-engineer.md +74 -0
  49. package/skills/massa-ai/personas/senior-mobile-qa-automation-engineer.md +75 -0
  50. package/skills/massa-ai/references/adr-authoring.md +189 -0
  51. package/skills/massa-ai/references/agent-orchestration.md +221 -0
  52. package/skills/massa-ai/references/architecture-coupling-lens.md +239 -0
  53. package/skills/massa-ai/references/architecture-deepening-lens.md +136 -0
  54. package/skills/massa-ai/references/architecture-domain-lens.md +186 -0
  55. package/skills/massa-ai/references/architecture-lenses.md +108 -0
  56. package/skills/massa-ai/references/audit-report-io.md +459 -0
  57. package/skills/massa-ai/references/audit-scope.md +103 -0
  58. package/skills/massa-ai/references/code-annotation.md +111 -0
  59. package/skills/massa-ai/references/codebase-investigation.md +96 -0
  60. package/skills/massa-ai/references/context-firewall.md +62 -0
  61. package/skills/massa-ai/references/conversation-feedback.md +104 -0
  62. package/skills/massa-ai/references/debug-diagnosis-loop.md +140 -0
  63. package/skills/massa-ai/references/decision-engine.md +73 -0
  64. package/skills/massa-ai/references/evidence-gate.md +53 -0
  65. package/skills/massa-ai/references/furps/analyst-role.md +49 -0
  66. package/skills/massa-ai/references/furps/checklist.md +92 -0
  67. package/skills/massa-ai/references/furps/intake.md +104 -0
  68. package/skills/massa-ai/references/furps/report-contract.md +140 -0
  69. package/skills/massa-ai/references/hook-enforcement.md +137 -0
  70. package/skills/massa-ai/references/implementation-delivery.md +101 -0
  71. package/skills/massa-ai/references/installation.md +110 -0
  72. package/skills/massa-ai/references/lessons.md +119 -0
  73. package/skills/massa-ai/references/maestro/artifacts-reports.md +69 -0
  74. package/skills/massa-ai/references/maestro/cli-device.md +65 -0
  75. package/skills/massa-ai/references/maestro/cloud.md +67 -0
  76. package/skills/massa-ai/references/maestro/config-env-output.md +76 -0
  77. package/skills/massa-ai/references/maestro/fact-ledger.md +71 -0
  78. package/skills/massa-ai/references/maestro/js-scripting.md +70 -0
  79. package/skills/massa-ai/references/maestro/mcp.md +59 -0
  80. package/skills/massa-ai/references/maestro/patterns.md +96 -0
  81. package/skills/massa-ai/references/maestro/selectors.md +91 -0
  82. package/skills/massa-ai/references/maestro/workspace-execution.md +81 -0
  83. package/skills/massa-ai/references/maestro/yaml-commands.md +203 -0
  84. package/skills/massa-ai/references/maestro.md +47 -0
  85. package/skills/massa-ai/references/mcp-tools.md +296 -0
  86. package/skills/massa-ai/references/memory-policy.md +103 -0
  87. package/skills/massa-ai/references/mobile-context.md +113 -0
  88. package/skills/massa-ai/references/mobile-diagnosis.md +106 -0
  89. package/skills/massa-ai/references/mobile-figma-matcher/ATTRIBUTION.md +5 -0
  90. package/skills/massa-ai/references/mobile-figma-matcher/android-compose.md +13 -0
  91. package/skills/massa-ai/references/mobile-figma-matcher/android-views.md +13 -0
  92. package/skills/massa-ai/references/mobile-figma-matcher/core.md +117 -0
  93. package/skills/massa-ai/references/mobile-figma-matcher/ios-swiftui.md +12 -0
  94. package/skills/massa-ai/references/mobile-figma-matcher/ios-uikit.md +12 -0
  95. package/skills/massa-ai/references/mobile-figma-matcher/kmp-compose-multiplatform.md +14 -0
  96. package/skills/massa-ai/references/mobile-figma-matcher/repository-detection.md +77 -0
  97. package/skills/massa-ai/references/naming-standards.md +47 -0
  98. package/skills/massa-ai/references/pr-task-fix.md +80 -0
  99. package/skills/massa-ai/references/project-context.md +76 -0
  100. package/skills/massa-ai/references/rfc/ATTRIBUTION.md +5 -0
  101. package/skills/massa-ai/references/rfc/discovery-and-sizing.md +120 -0
  102. package/skills/massa-ai/references/rfc/document-contract.md +85 -0
  103. package/skills/massa-ai/references/rfc/quality-and-lifecycle.md +101 -0
  104. package/skills/massa-ai/references/root-cause-scripts.md +97 -0
  105. package/skills/massa-ai/references/spec-driven/artifact-store.md +98 -0
  106. package/skills/massa-ai/references/spec-driven/code-analysis.md +119 -0
  107. package/skills/massa-ai/references/spec-driven/coding-principles.md +80 -0
  108. package/skills/massa-ai/references/spec-driven/context-limits.md +64 -0
  109. package/skills/massa-ai/references/spec-driven/design.md +257 -0
  110. package/skills/massa-ai/references/spec-driven/discuss.md +182 -0
  111. package/skills/massa-ai/references/spec-driven/execute.md +471 -0
  112. package/skills/massa-ai/references/spec-driven/lessons.md +5 -0
  113. package/skills/massa-ai/references/spec-driven/memory.md +214 -0
  114. package/skills/massa-ai/references/spec-driven/specify.md +283 -0
  115. package/skills/massa-ai/references/spec-driven/sub-agents.md +151 -0
  116. package/skills/massa-ai/references/spec-driven/tasks.md +494 -0
  117. package/skills/massa-ai/references/spec-driven/validate.md +397 -0
  118. package/skills/massa-ai/references/subagent-design.md +132 -0
  119. package/skills/massa-ai/references/synapse-policy.md +160 -0
  120. package/skills/massa-ai/references/tdd/calibrated-examples.md +54 -0
  121. package/skills/massa-ai/references/tdd/discovery-and-sizing.md +83 -0
  122. package/skills/massa-ai/references/tdd/document-contract.md +136 -0
  123. package/skills/massa-ai/references/tdd/quality-and-lifecycle.md +83 -0
  124. package/skills/massa-ai/references/the-fool/cognitive-bias-inventory.md +103 -0
  125. package/skills/massa-ai/references/the-fool/dialectic-synthesis.md +170 -0
  126. package/skills/massa-ai/references/the-fool/evidence-audit.md +202 -0
  127. package/skills/massa-ai/references/the-fool/mode-selection-guide.md +113 -0
  128. package/skills/massa-ai/references/the-fool/pre-mortem-analysis.md +200 -0
  129. package/skills/massa-ai/references/the-fool/red-team-adversarial.md +206 -0
  130. package/skills/massa-ai/references/the-fool/socratic-questioning.md +153 -0
  131. package/skills/massa-ai/references/ticket/atlassian-fix.md +130 -0
  132. package/skills/massa-ai/references/ticket/intake-and-sources.md +65 -0
  133. package/skills/massa-ai/references/ticket/templates-and-quality.md +129 -0
  134. package/skills/massa-ai/references/verification-ladder.md +62 -0
  135. package/skills/massa-ai/scripts/lessons.py +590 -0
  136. package/skills/massa-ai/workflows/adr.md +33 -0
  137. package/skills/massa-ai/workflows/architecture/architecture-audit.md +125 -0
  138. package/skills/massa-ai/workflows/architecture/architecture-fix.md +110 -0
  139. package/skills/massa-ai/workflows/bugs/bugs-audit.md +113 -0
  140. package/skills/massa-ai/workflows/bugs/bugs-fix.md +97 -0
  141. package/skills/massa-ai/workflows/code-quality/code-quality-audit.md +154 -0
  142. package/skills/massa-ai/workflows/code-quality/code-quality-fix.md +99 -0
  143. package/skills/massa-ai/workflows/commit.md +61 -0
  144. package/skills/massa-ai/workflows/debug.md +86 -0
  145. package/skills/massa-ai/workflows/design.md +54 -0
  146. package/skills/massa-ai/workflows/exploration.md +119 -0
  147. package/skills/massa-ai/workflows/feature.md +52 -0
  148. package/skills/massa-ai/workflows/general.md +46 -0
  149. package/skills/massa-ai/workflows/implementation/implementation-audit.md +87 -0
  150. package/skills/massa-ai/workflows/implementation/implementation-fix.md +90 -0
  151. package/skills/massa-ai/workflows/long-session.md +44 -0
  152. package/skills/massa-ai/workflows/maestro/maestro-audit.md +56 -0
  153. package/skills/massa-ai/workflows/maestro/maestro-fix.md +74 -0
  154. package/skills/massa-ai/workflows/maestro/maestro.md +68 -0
  155. package/skills/massa-ai/workflows/mobile-figma/mobile-figma-audit.md +68 -0
  156. package/skills/massa-ai/workflows/mobile-figma/mobile-figma-fix.md +74 -0
  157. package/skills/massa-ai/workflows/onboarding.md +23 -0
  158. package/skills/massa-ai/workflows/refactor.md +47 -0
  159. package/skills/massa-ai/workflows/refinement/furps-refinement.md +81 -0
  160. package/skills/massa-ai/workflows/requirements/requirements-audit.md +114 -0
  161. package/skills/massa-ai/workflows/requirements/requirements-fix.md +93 -0
  162. package/skills/massa-ai/workflows/rfc.md +55 -0
  163. package/skills/massa-ai/workflows/security/security-audit.md +113 -0
  164. package/skills/massa-ai/workflows/security/security-fix.md +97 -0
  165. package/skills/massa-ai/workflows/spec-driven.md +217 -0
  166. package/skills/massa-ai/workflows/tdd.md +71 -0
  167. package/skills/massa-ai/workflows/tests/tests-audit.md +114 -0
  168. package/skills/massa-ai/workflows/tests/tests-fix.md +96 -0
  169. package/skills/massa-ai/workflows/the-fool.md +82 -0
  170. package/skills/massa-ai/workflows/ticket.md +42 -0
  171. package/skills/persona-router/SKILL.md +158 -0
  172. package/skills/status/SKILL.md +15 -0
@@ -0,0 +1,113 @@
1
+ ### Security Audit
2
+
3
+ Use this workflow for findings-only security review in a concrete target: modified files, explicit files/globs, commit ranges, branch comparisons, modules/packages, symbols/classes/functions, feature/runtime flows, explicitly requested whole-repo scope, or an implementation scope packet supplied by `workflows/implementation/implementation-audit.md`.
4
+
5
+ Before the first substantive read, load `references/project-context.md` and run the project-context intake sweep for this repository.
6
+
7
+ Do not use this workflow for generic correctness bugs; route those to `workflows/bugs/bugs-audit.md`. Do not use it for broad architecture, code quality, requirements, or test coverage audits; route those to their dedicated workflows.
8
+
9
+ This workflow is findings-only. Do not edit code unless the user separately asks for fixes.
10
+
11
+ 1. Resolve/reuse `workflowSessionId`: `security-[entity]`
12
+ 2. Load shared references:
13
+ - `references/codebase-investigation.md`
14
+ - `references/audit-scope.md`
15
+ - `references/audit-report-io.md` before writing the final direct audit report
16
+ - `references/mobile-context.md` when the scope touches KMP, iOS, Android, native bridges, mobile permissions, secure storage, biometrics, deep links, push/background behavior, local persistence, offline queues, logs/crash privacy, or backend-mobile contracts
17
+ - `references/context-firewall.md` before inspecting large diffs, logs, snapshots, generated reports, or broad search output
18
+ - `references/synapse-policy.md` when repeated massa-ai searches are expected
19
+ - `references/agent-orchestration.md` only for large scopes, explicit parallel/subagent requests, PR subagent invocation, or independent verification of high-impact findings
20
+ 3. `recall` -> load prior security decisions, auth boundaries, validation rules, known regressions, project constraints, ADRs, fragile flows, and accepted exceptions for the target area.
21
+ - Apply the Memory Freshness Gate from `references/audit-scope.md`; recalled exceptions are leads, not proof.
22
+ 4. Establish the investigation scope before proceeding:
23
+ - Modified files scope: use when the user says modified files, changed files, current changes, uncommitted changes, staged changes, or unstaged changes.
24
+ - Explicit files/globs scope: use when the user names files, directories, or globs.
25
+ - Commit range scope: use when the user provides commits/ranges or asks for commits made by me, my branch commits, or security issues introduced by branch commits.
26
+ - Branch comparison scope: use when the user names base/head branches, refs, or a branch diff.
27
+ - Codebase area scope: use when the user names a path, module, package, feature area, trust boundary, or glob.
28
+ - Symbol/class/function scope: use when the user names handlers, middleware, validators, policies, classes, functions, or exported surfaces.
29
+ - Feature/flow scope: use when the user names a runtime flow, user journey, auth path, or data boundary.
30
+ - Whole-repo scope: use only when the user explicitly asks for a whole-repo security audit.
31
+ - Implementation parent scope: use only when `workflows/implementation/implementation-audit.md` invokes this workflow with a concrete implementation scope packet.
32
+ - If the target focus is missing, vague, or too broad, ask for a concrete target from the supported scope types in `references/audit-scope.md`.
33
+ - Build the shared scope packet from `references/audit-scope.md` and carry it into the report.
34
+ 5. For modified files scope:
35
+ - Include staged and unstaged tracked files from the working tree.
36
+ - Include untracked non-generated source, test, fixture, schema, config, and docs files only when they can affect runtime or validation behavior.
37
+ - Exclude deleted files unless their deletion can break imports, exports, routing, migrations, config, tests, packaging, secrets handling, or policy enforcement.
38
+ - Exclude generated, dependency, build, log, cache, temporary, and secret paths per repo rules.
39
+ - Inspect diffs first, then only the surrounding code needed to understand security behavior.
40
+ 6. For commit range scope:
41
+ - If the user supplied explicit commits or a revision range, use that exact range.
42
+ - If the user asked for commits made by me, resolve author identity from `git config user.email`; if empty, use `git config user.name`.
43
+ - For branch-relative commit scopes, resolve the branch base from the upstream merge-base first, then fall back in order to `origin/main`, `origin/master`, `main`, and `master`.
44
+ - If the user asked for commits made by me, review branch-unique commits authored by the resolved identity.
45
+ - If no explicit range, required author identity, or branch base can be resolved, ask the user for the missing value before proceeding.
46
+ - Inspect changed files and diffs from those commits, then auth boundaries, callers, tests, config, schemas, and policy definitions only as needed.
47
+ 7. For codebase area scope:
48
+ - Require a concrete path, module, package, feature area, or glob.
49
+ - If the target area is missing, ask for it before proceeding.
50
+ - Follow the shared retrieval order from `references/codebase-investigation.md` to find entry points, trust boundaries, policy checks, validators, tests, and adjacent config.
51
+ 8. For explicit files/globs, branch comparison, symbol/class/function, feature/flow, or explicitly requested whole-repo scope:
52
+ - Resolve the target with `references/audit-scope.md` and record the resolution method, base/head when relevant, resolved files, exclusions, and freshness timestamp.
53
+ - For symbol/class/function targets, inspect definitions, call paths, trust boundaries, validators, policies, tests, config, and schemas only as needed.
54
+ - For feature/flow targets, trace untrusted input, identity, authorization, validation, persistence, side effects, and logs through the named flow.
55
+ - If whole-repo scope is requested, map major trust boundaries first and report skipped depth checks rather than implying exhaustive review.
56
+ 9. For implementation parent scope:
57
+ - Accept the exact scope packet from `implementation-audit`; do not broaden beyond resolved files, surrounding code, called auth/validation helpers, config, schemas, and tests needed to verify a security claim.
58
+ - Return compact findings to the parent implementation audit; do not write broad project memories unless explicitly assigned.
59
+ 10. Investigation pass. Dispatch `audit-specialist` per `references/agent-orchestration.md` when the scope justifies an isolated read-only subagent:
60
+
61
+ > **Dispatch: `massa-ai-audit-specialist`** (role: `audit-specialist`) — charter `skills/agents/audit-specialist/SKILL.md`
62
+ > - trigger: large scope, explicit parallel/subagent request, PR subagent invocation, or independent verification of high-impact finding
63
+ > - scope: the security audit target — files, trust boundaries, auth paths, validators
64
+ > - permissions: read-only
65
+ > - inputs: shared scope packet; `lens: security`; recalled security decisions, auth boundaries, validation rules, accepted exceptions
66
+ > - sensors: trace untrusted input -> validation -> authorization -> transformation -> persistence; authn/authz, object ownership, tenant isolation, input validation, secret handling, injection risks
67
+ > - output: findings with security boundary, asset, trigger/exploit path, severity, confidence, evidence, simplest fix direction, verification suggestion
68
+ > - firewall: raw diffs/logs/search output summarized, not returned raw
69
+ > - memory: suggest-only; main agent persists reusable security patterns
70
+
71
+ - Trace untrusted input -> validation -> authorization -> transformation -> persistence or side effect.
72
+ - Check authn/authz, object ownership, tenant isolation, input validation, output encoding, secret handling, cryptography use, SSRF/path traversal/injection risks, logging privacy, dependency/config exposure, and security-sensitive tests.
73
+ - For mobile scopes, check secure storage/keychain/keystore use, permission states, deep links and auth guards, push token handling, biometrics, local DB/cache and offline queues, logs/crash reports/screenshots, native bridge payload trust, and backend-mobile contract skew from `references/mobile-context.md`.
74
+ - For each candidate finding, record the concrete claim, source evidence, impacted asset or boundary, likely trigger, provisional severity, and what would disprove it.
75
+ 11. False-positive pass:
76
+ - Try to disprove every candidate before reporting it.
77
+ - Check guards, framework defaults, policy layers, middleware order, type checks, tests, feature flags, call paths, existing invariants, ADRs, and accepted exceptions.
78
+ - Use official docs or web research only when current external API, framework, or security behavior matters.
79
+ - Drop candidates disproven by evidence, downgrade candidates with partial mitigation, and mark low-confidence findings explicitly.
80
+ 12. Severity rules (apply the countable threshold first, then the qualitative clause):
81
+ - `critical`: likely auth bypass, privilege escalation, data exfiltration, secret exposure, remote code execution, tenant break, irreversible data corruption, OR affects >10 files; otherwise use the qualitative clause below.
82
+ - `high`: likely missing authorization, injection risk, sensitive data leak, broken security boundary, unsafe deserialization, or severe config exposure.
83
+ - `medium`: real edge-flow security bug, incomplete validation, privacy leak with limited scope (<=10 affected files), weak cryptographic/config practice with plausible exploitation, or meaningful test gap around security logic.
84
+ - `low`: defensive hardening opportunity, low-impact information exposure, incomplete evidence, or weakly supported concern.
85
+ 13. Final report:
86
+ - Findings first, ordered by severity: `critical`, `high`, `medium`, `low`.
87
+ - Each finding must use `SEC-<N>` and include the canonical fields from `references/audit-report-io.md`: severity, confidence, file/line, evidence, security boundary, asset, trigger or exploit path, negative test direction, simplest fix direction, and verification suggestion.
88
+ - If no security findings are found, say that clearly and list scope checked plus skipped checks.
89
+ - Include ruled-out candidates when they were plausible enough to matter.
90
+ - Include scope checked, deterministic evidence or skipped-check notes, memory outcome, and residual risk.
91
+ - Include the Verification/Test Fidelity Checklist from `references/audit-report-io.md`; tie every `SEC-*` finding or no-finding claim to deterministic sensors, commands/artifacts, results, validation assets, or skipped-check reasons. Model judgment alone cannot satisfy verification/testing all-clear.
92
+ - For direct top-level invocation, use the Plan Mode save rule and canonical report contract from `references/audit-report-io.md` for `audits/security/<YYYY-MM-DD security-audit>.md`.
93
+ - For implementation audit child invocation, return compact findings to the parent unless the parent explicitly requests saved audit artifacts.
94
+ 14. Persist only durable knowledge:
95
+ - Do not persist one-off findings.
96
+ - Persist repeated security patterns, project-specific security boundaries, accepted exceptions, or reusable verification recipes after scoring with the Importance Calibration System.
97
+ - Use required tags: `project:<projectId>`, `session:<workflowSessionId>`, `workflow:security-audit`, `entity:<entity>`, and one `memory:<tier>` tag.
98
+ 15. Complete the Evidence Gate from `references/evidence-gate.md`.
99
+
100
+ ## Examples
101
+
102
+ User asks: "Audit modified files for security issues."
103
+
104
+ 1. Use `workflowSessionId=security-modified-files`.
105
+ 2. Scope to staged, unstaged, and relevant untracked files; exclude generated/dependency/build/log/cache/secret paths.
106
+ 3. Inspect diffs first, then auth, validation, secret handling, config, and tests around the changed code.
107
+ 4. Run a false-positive pass before reporting findings.
108
+
109
+ User asks: "Audit src/auth for security risks."
110
+
111
+ 1. Use `workflowSessionId=security-auth`.
112
+ 2. Scope to `src/auth` and adjacent policy, middleware, config, schema, and tests needed to verify claims.
113
+ 3. Report findings by severity with confidence, evidence, impact, and verification suggestions.
@@ -0,0 +1,97 @@
1
+ ### Security Fix
2
+
3
+ Use this workflow only to execute fixes from a security audit markdown report.
4
+
5
+ Before the first substantive read, load `references/project-context.md` and run the project-context intake sweep for this repository.
6
+
7
+ Before the first repository mutation, load `references/implementation-delivery.md` for worktree isolation, atomic commits, PR creation, CI watch, and the merge gate, and `references/code-annotation.md` for doc blocks, rationale comments, and test coverage on every created or updated unit. If two consecutive fix attempts fail on the same symptom, stop editing and load `references/root-cause-scripts.md`.
8
+
9
+ Do not use this workflow for findings-only security review; route that to `workflows/security/security-audit.md`. Do not use it for generic correctness fixes unless the security report identifies the correctness issue as part of an exploitable path.
10
+
11
+ 1. Resolve/reuse `workflowSessionId`: `security-fix-[entity]`
12
+ 2. Load shared references:
13
+ - `references/audit-report-io.md` before any code change
14
+ - `references/lessons.md` to load confirmed project lessons
15
+ - `references/codebase-investigation.md` before changing unfamiliar security boundaries
16
+ - `references/mobile-context.md` when the report target touches KMP, iOS, Android, native bridges, mobile permissions, secure storage, biometrics, deep links, push/background behavior, local persistence, offline queues, logs/crash privacy, or backend-mobile contracts
17
+ - `references/verification-ladder.md` before non-trivial edits
18
+ - `references/context-firewall.md` before inspecting large diffs, logs, generated reports, or broad search output
19
+ - `references/agent-orchestration.md` only for large/high-risk findings, disjoint implementation slices, or independent verification
20
+ 3. `recall` -> load auth boundaries, tenant rules, validation conventions, secret-handling policies, accepted exceptions, prior incidents, and verification recipes for the report target.
21
+ 4. Select the security audit report with execution focus:
22
+ - Establish the report selector, target focus, and optional finding selector before selecting a report. Target focus can be a trust boundary, route, module, flow, files/globs, branch comparison, commit range, symbol/class/function, or explicit whole-repo target.
23
+ - If the user gives a path, read that exact markdown file.
24
+ - If the user asks for "latest" or gives no path, require a concrete target focus first; do not run the latest security report against an unspecified target.
25
+ - Select the latest `audits/security/<YYYY-MM-DD security-audit>.md` only after target focus is known, using `references/audit-report-io.md`.
26
+ - Stop if no report exists; do not infer findings from conversation history.
27
+ - Validate the report with `references/audit-report-io.md`: workflow, `ProjectId`, `Target`, `Target Focus`, scope, git base/head, required fields, `SEC-` IDs, resolved files or material scope evidence, and current file/line evidence. Stop on invalid, stale, target-drifted, or ambiguous reports before editing.
28
+ 5. Extract actionable findings:
29
+ - Keep findings with concrete `Security Boundary`, `Asset`, `Location`, `Evidence`, exploit path or trigger, `Negative Test Direction`, `Simplest Fix Direction`, and `Verification Suggestion`.
30
+ - Ignore ruled-out candidates, no-finding sections, and low-confidence hardening ideas unless the user explicitly asks to include them.
31
+ - If the user supplied finding IDs, extract only those IDs after validating they exist and match the current target focus.
32
+ - Rank by exploitability, severity, affected asset, dependency order, and regression risk.
33
+ 6. Build a threat-model fix map before editing:
34
+ - Finding ID -> attacker or misuse path, trust boundary, missing/weak guard, data asset, required invariant, negative test, and rollback path.
35
+ - Identify whether the fix belongs in authentication, authorization, ownership/tenant isolation, validation, output encoding, persistence, logging, crypto, config, or tests.
36
+ - For mobile findings, identify whether the fix belongs in secure storage, permission handling, deep-link routing, push/background token handling, biometric fallback, local persistence/offline queue, logs/crash privacy, native bridge payload validation, or backend-mobile contract hardening.
37
+ 7. Size each finding with `references/verification-ladder.md`:
38
+ - Quick: local guard, schema validation, log redaction, config hardening, or focused negative test.
39
+ - Standard: policy-layer change, middleware ordering, ownership rule, public API validation, data-access guard, or multi-file regression coverage; define verification recipe first.
40
+ - Spec-driven: security model redesign, role model change, tenant model migration, crypto migration, or behavior change needing stakeholder approval; pause and route to `workflows/spec-driven.md` or ask for approval.
41
+ 8. Apply security fixing methods:
42
+ - Authentication: fail closed on missing/invalid identity, preserve session/token invariants, and avoid bypass paths.
43
+ - Authorization: enforce permission checks at stable boundaries, verify object ownership and tenant isolation, and deny by default.
44
+ - Validation: validate untrusted input before transformation or persistence; prefer schema or framework validators over ad hoc checks.
45
+ - Output and privacy: encode or sanitize outputs, redact secrets and sensitive personal data from logs/errors, and avoid leaking existence of protected resources.
46
+ - Injection and traversal: parameterize queries, constrain paths/URLs, validate protocols/hosts, and avoid unsafe deserialization or dynamic execution.
47
+ - Secrets and crypto: remove hardcoded secrets, use safe config sources, avoid weak algorithms, and preserve key/credential rotation paths.
48
+ - Mobile trust boundaries: preserve platform parity, fail closed on denied/restricted permissions when security-sensitive, validate native bridge payloads before trust, redact local logs/crash artifacts, and protect tokens or personal data in secure storage and offline queues.
49
+ 9. Preserve security intent with tests:
50
+ - Add or update negative tests for the exploit path when feasible.
51
+ - Include positive tests for allowed behavior so the fix does not over-block legitimate use.
52
+ - Do not weaken existing security assertions to make tests pass.
53
+ 10. Use agent orchestration only when it improves signal. Dispatch per `references/agent-orchestration.md`:
54
+
55
+ > **Dispatch: `massa-ai-builder`** (role: `builder`) — charter `skills/agents/builder/SKILL.md`
56
+ > - trigger: large/high-risk finding, disjoint implementation slice, or explicit subagent request
57
+ > - scope: one isolated security finding with a disjoint write set
58
+ > - permissions: write (disjoint write set)
59
+ > - inputs: the finding ID, impacted asset/boundary, exploit path, current guards, and simplest fix direction
60
+ > - sensors: report's verification suggestion or equivalent deterministic command; negative tests that attempt to disprove the fix
61
+ > - output: implementation summary, commands run, test counts, deviations
62
+ > - firewall: raw diffs/logs summarized
63
+ > - memory: suggest-only; main agent persists reusable security patterns
64
+
65
+ > **Dispatch: `massa-ai-verification-agent`** (role: `verification-agent`) — charter `skills/agents/verification-agent/SKILL.md`
66
+ > - trigger: independent verification of a high-risk security fix
67
+ > - scope: the fixed finding's guard restoration, middleware order, redaction, and report claim closure
68
+ > - permissions: read-only
69
+ > - inputs: the finding, the applied fix, the verification suggestion, and validation assets
70
+ > - sensors: deterministic command (negative tests, middleware-order inspection, redaction check) and report claim closure
71
+ > - output: confirmed/disproven closure verdict with evidence
72
+ > - firewall: raw test output/logs summarized
73
+ > - memory: suggest-only; main agent persists reusable verification recipes
74
+ - Main agent owns report parsing, prioritization, memory writes, final synthesis, and Evidence Gate.
75
+ 11. Verify each completed finding:
76
+ - If verification found a reusable signal (`ac_gap`, `surviving_mutant`, `spec_precision_gap`, `spec_deviation`, `gate_fail`), record it via `references/lessons.md`:
77
+ `python3 skills/massa-ai/scripts/lessons.py --root . add --feature "<slug>" --signal "<signal>" --source "<ref>" --text "<one terse lesson>"`
78
+ - Apply the Mandatory Verification Fix Gate from `references/verification-ladder.md`: run the report's Verification Suggestion or an equivalent deterministic command/artifact check for each selected finding or coherent group.
79
+ - A finding cannot be marked `fixed` when a target-relevant command or artifact check exists but was not attempted; if verification cannot run, mark it `blocked`, `deferred`, or `skipped` with an allowed skipped-check reason.
80
+ - Run the report's verification suggestion when available.
81
+ - Run targeted tests for negative and positive paths, plus lint/type/build checks relevant to touched files.
82
+ - Inspect logs/config/errors when the finding involves data exposure.
83
+ - Record command/artifact, result, skipped reason or `none`, highest Verification Ladder level reached, validation assets protected, and residual risk.
84
+ 12. At completion, persist only durable knowledge:
85
+ - Security boundary decisions, accepted exceptions, reusable exploit-path tests, or incident-prevention patterns after scoring with the Importance Calibration System.
86
+ - Use required tags: `project:<projectId>`, `session:<workflowSessionId>`, `workflow:security-fix`, `entity:<entity>`, and one `memory:<tier>` tag.
87
+ 13. Complete the Evidence Gate from `references/evidence-gate.md`.
88
+
89
+ ## Examples
90
+
91
+ User asks: "Use security-fix to fix latest audit findings for user routes."
92
+
93
+ 1. Confirm target focus is `user routes`, then read the latest matching `audits/security/* security-audit.md`.
94
+ 2. Validate metadata, target focus, freshness, required fields, and current evidence before editing.
95
+ 3. Fix critical/high exploit paths first.
96
+ 4. Add negative tests for denied access, invalid input, or redacted output.
97
+ 5. Run deterministic tests and report residual security risk.
@@ -0,0 +1,217 @@
1
+ ### Spec-Driven
2
+
3
+ Use this workflow for explicit spec-driven requests and broad, ambiguous, migration-heavy, cross-boundary, public-contract, or long-running delivery that needs requirements-through-verification control. Ordinary localized fixes and clear small features stay in `debug`, `feature`, `refactor`, or `general` unless the user explicitly requests this workflow.
4
+
5
+ Before the first substantive read, load `references/project-context.md` and run the project-context intake sweep for this repository.
6
+
7
+ Before the first repository mutation, load `references/implementation-delivery.md` for worktree isolation, atomic commits, PR creation, CI watch, and the merge gate, and `references/code-annotation.md` for doc blocks, rationale comments, and test coverage on every created or updated unit. If two consecutive fix attempts fail on the same symptom, stop editing and load `references/root-cause-scripts.md`.
8
+
9
+ ## TLC v3 Flow
10
+
11
+ Run the integrated TLC Spec-Driven v3 flow:
12
+
13
+ `Specify -> (Design) -> (Tasks) -> Execute`
14
+
15
+ - `Specify` and `Execute` are always required.
16
+ - Validation is the mandatory final Execute gate, not a separate optional phase.
17
+ - `Design` is included for Large/Complex work and whenever architecture, interfaces, data model, migration, security/privacy, public contract, or reusable pattern decisions exist.
18
+ - `Tasks` is included for Large/Complex work and whenever execution has more than 3 obvious linear steps or has dependency, branch, join, parallelism, or sequencing complexity.
19
+ - Large/Complex work must include full requirement IDs, the implicit-requirement sweep, design approach tradeoffs, a task breakdown, and final validation.
20
+ - If a skipped phase becomes necessary later, stop, create or revise the phase artifact, record the safety-valve reason, and resume from the updated contract.
21
+
22
+ ## Execution Contract — Non-Negotiable
23
+
24
+ Holds for every task, even if reference files are not opened:
25
+
26
+ 1. Tests derive from the spec's acceptance criteria and assert spec-defined outcomes — they never mirror the implementation.
27
+ 2. The gate must pass (tests pass) before a task is done — the test runner decides, not self-assessment.
28
+ 3. One atomic commit per task. Never batch tasks; never weaken, skip, or delete tests to make them pass.
29
+ 4. After the last task, a fresh verification-agent always runs automatically (author ≠ verifier) — spec-anchored outcome check plus discrimination sensor. Never optional, never prompted.
30
+
31
+ ## Auto-Sizing
32
+
33
+ Complexity determines depth, not a fixed pipeline. Assess scope first, apply only what is needed:
34
+
35
+ | Scope | What | Specify | Design | Tasks | Execute |
36
+ | --- | --- | --- | --- | --- | --- |
37
+ | Small | ≤3 files, one sentence | One-liner inline | Skip | Skip | Implement + verify inline |
38
+ | Medium | Clear feature, <10 tasks | Brief spec | Skip — inline | Skip — implicit | Implement + verify |
39
+ | Large | >10 tasks OR multi-component feature | Full spec + requirement IDs | Architecture + components | Full breakdown + deps | Implement + verify per task |
40
+ | Complex | Ambiguity or new domain (unfamiliar vocabulary, no prior pattern) | Full spec + discuss gray areas | Research + architecture | Breakdown + phase plan | Implement + interactive UAT |
41
+
42
+ A "phase" is a group of tasks sharing a dependency boundary or a checkpoint commit — it is distinct from a single task or atomic step. The sub-agent offer fires when a formal `tasks.md` packs into more than one task-budgeted batch (> ~8 tasks).
43
+
44
+ - Specify and Execute are always required.
45
+ - Design is skipped when straightforward (no architectural decisions, no new patterns).
46
+ - Tasks is skipped when ≤3 obvious steps (implicit in Execute).
47
+ - Discuss runs inside Specify when gray areas or any implicit-requirement dimension is present (persistence/state, external calls, auth, payments, concurrency, state transitions).
48
+ - Interactive UAT runs inside Execute only for user-facing features with complex behavior.
49
+
50
+ ## Quick Mode Guardrails
51
+
52
+ Quick mode is the Small/auto-sized path: a single change touching **max 3 files** with no new dependency and no design decision. It is the fast lane, not a parallel pipeline — it still closes requirements and runs the Execute gate.
53
+
54
+ Enter Quick mode only when **all** hold:
55
+
56
+ - The change touches max 3 files.
57
+ - No new dependency is introduced.
58
+ - No design decision is required (no architecture, interface, data model, migration, security/privacy, or public-contract choice).
59
+
60
+ Exit Quick mode immediately — run the full Specify → (Design) → (Tasks) → Execute pipeline — when **any** of these appears mid-task:
61
+
62
+ - A new dependency.
63
+ - Any design decision surfaces.
64
+ - The change grows past max 3 files.
65
+
66
+ Promote to a feature when **5+ quick tasks** accumulate in one area: that signal means the work has hidden coupling and belongs in a tracked feature with full requirements, not a string of quick fixes. Record the promotion in `.specs/project/STATE.md` and open the feature under `.specs/features/<slug>/`.
67
+
68
+ Quick artifacts live under `.specs/quick/NNN-slug/` with a `TASK.md` (one-line intent + acceptance) and a `SUMMARY.md` (files changed + gate evidence). See `references/spec-driven/artifact-store.md` for templates. Quick tasks are listed in the STATE.md Quick Tasks table (see `references/spec-driven/memory.md`).
69
+
70
+ ## Workflow
71
+
72
+ 1. Resolve/reuse `projectId` and `workflowSessionId`: `spec-[entity]`.
73
+ 2. Restore context before planning:
74
+ - `recall` for exact-session continuity, durable decisions, rejected approaches, patterns, blockers, and handoffs.
75
+ - Load `references/spec-driven/artifact-store.md` before reading or writing feature registry, state, handoff, phase artifacts, validation reports, or lessons.
76
+ - Load `references/synapse-policy.md` when two or more related searches are expected. When the investigation involves multi-search, call `synapse_task_begin` with `id` (the `synapseSessionId`) and `taskContext` before the first search to open a task envelope; call `synapse_prefetch` with `id` and `filePath` after opening a file for deep investigation to warm the buffer; call `synapse_task_end` with `id` when the investigation phase completes. `synapse_task_begin`/`synapse_task_end` require an existing `synapse_session` id.
77
+ - Load `references/context-firewall.md` before broad source inspection, generated reports, external research, or verbose tool output.
78
+ - Keep the loaded context budget under the `references/spec-driven/context-limits.md` target; summarize or narrow before loading bulky artifacts.
79
+ - Use `references/spec-driven/code-analysis.md` when source inspection needs structural search or tool fallback.
80
+ - Load current canonical artifacts from `.specs/` files: `.specs/project/FEATURES.json`, `.specs/project/STATE.md`, `.specs/HANDOFF.md`, existing `.specs/features/<slug>/` phase artifacts, lessons, and project source. Current repository source and approved `.specs/` artifacts override stale memory, old handoff notes, external summaries, debug exports, or unapproved generated plans.
81
+ - `search` only counts as codebase evidence when it is fresh for the current repository path and commit/worktree state, or when the result is confirmed against source files read in this session.
82
+ - Load confirmed project lessons through `references/lessons.md` when `.specs/lessons.json` exists:
83
+ `python3 skills/massa-ai/scripts/lessons.py --root . list --status confirmed`
84
+ 3. Run `Specify` with `references/spec-driven/specify.md`.
85
+ - Capture stable requirement IDs, testable acceptance criteria, edge cases, and explicit out-of-scope items.
86
+ - Run `references/spec-driven/discuss.md` inside Specify when gray areas, implicit requirements, persistence/state, external calls, auth, payments, concurrency, or state transitions affect behavior.
87
+ - For Android, iOS, or KMP Compose Multiplatform UI work, load `references/mobile-context.md` and run the optional design-source gate: ask for one or more Figma links, node IDs, a readable desktop selection, supplied screenshots, or explicit `none`; record `Figma Source: none by user choice` when declined. Screenshots are context-only unless paired with structured Figma evidence. For unsupported targets, record the source as outside mobile Figma scope and do not run mobile Figma.
88
+ - Apply the Requirement Closure Gate: every open requirement question is resolved with the user or recorded as an accepted assumption before execution begins.
89
+ 4. Decide whether `Design` is required. If yes, run `references/spec-driven/design.md`; if no, record why the skip is valid. When Design is skipped and a design concern appears later, stop and create `design.md` before continuing.
90
+ 5. Decide whether `Tasks` is required. If yes, run `references/spec-driven/tasks.md`; if no, list the inline atomic execution steps before editing. If the inline list reveals more than 5 steps or complex dependencies, stop and create `tasks.md` — the Tasks phase was wrongly skipped (safety valve).
91
+ 6. Run `Execute` with `references/spec-driven/execute.md`.
92
+ - Load `references/spec-driven/coding-principles.md` before implementation.
93
+ - Use the Test Coverage Matrix and Gate Check Commands from `tasks.md`, or state their inline equivalents when Tasks was skipped.
94
+ - Ask the MCP and skill question in Tasks or inline Execute when tool choice can change correctness or verification.
95
+ - If a formal `tasks.md` packs into more than one task-budgeted batch (> ~8 tasks), present the sub-agent offer from `references/spec-driven/sub-agents.md` before starting Execute. Offer-then-confirm — never auto-spawn; the user must accept before any sub-agent is dispatched. One worker per batch (~7 tasks, whole phases): each batch worker executes all its tasks in order (implement → gate → atomic commit), then reports a compact summary (tasks done, commit hashes, test counts, deviations). Workers never spawn further sub-agents.
96
+ - Implement one atomic step or approved task at a time.
97
+ - For long-running task sequences, create a checkpoint via `create_checkpoint` at task boundaries with `taskId`, `description`, `progressPercent`, `currentStep`, `nextAction`, `fileChanges`, and `checkpointType: "manual"` so progress is resumable after interruption.
98
+ - If resuming after interruption, call `list_checkpoints` with the `taskId` and `restore_checkpoint` to recover task state before continuing. If `create_checkpoint` is unavailable (e.g. `task_checkpoints` table missing), continue with `.specs/` artifact state as the fallback.
99
+ - Use per-task commits when the environment and user permissions allow commits; otherwise record the skipped reason.
100
+ - Keep validation assets protected.
101
+ - Update logical feature artifacts in `.specs/features/<slug>/` and `.specs/project/STATE.md` after meaningful progress.
102
+ - Finish Execute by running `references/spec-driven/validate.md`. Dispatch `verification-agent` (author ≠ verifier) per `references/agent-orchestration.md`; the verification-agent always runs automatically and writes `.specs/features/<slug>/validation.md`. Without subagents, run the standalone fresh-eyes fallback in `validate.md`.
103
+
104
+ > **Dispatch: `massa-ai-verification-agent`** (role: `verification-agent`) — charter `skills/agents/verification-agent/SKILL.md`
105
+ > - trigger: spec-driven Execute final gate; author ≠ verifier independence required
106
+ > - scope: the feature's git diff surface, test files, and spec ACs
107
+ > - permissions: read-only
108
+ > - inputs: `spec.md` (ACs = source of truth), `references/spec-driven/validate.md` as operating checklist, commit range, test files in scope
109
+ > - sensors: (1) spec-anchored outcome check — each test's asserted value matches the spec-defined expected outcome; (2) discrimination sensor — injects behavior-level faults in scratch state, confirms tests kill them, discards mutations; surviving mutants become fix tasks
110
+ > - output: `.specs/features/<slug>/validation.md` (PASS/FAIL, per-AC evidence, sensor result, diff range); compact verdict + ranked gap list; gaps become fix tasks
111
+ > - firewall: raw diffs/logs/test output summarized; mutations run in scratch state only
112
+ > - memory: suggest-only; main agent persists validation outcomes
113
+
114
+ - The verification-agent re-derives coverage independently using evidence-or-zero and does not inherit the author's mental model.
115
+ - The fix → re-verify loop is capped at 3 iterations before escalating to `Blocked`.
116
+ - Distill lesson signals through `references/lessons.md` when validation produces grounded reusable failures.
117
+ 7. Update `.specs/project/STATE.md`, `.specs/HANDOFF.md`, and `references/spec-driven/memory.md` records for decisions, blockers, handoff, and completion evidence.
118
+ 8. When the user splits planning and implementation across clean chats, resume from the canonical `.specs/` artifacts — `.specs/project/STATE.md`, `.specs/project/FEATURES.json`, `.specs/HANDOFF.md`, and the feature's phase files. This workflow owns the spec phase contracts on both sides of the split; there is no separate save/load procedure.
119
+ 9. Complete the configured Plan Challenge Gate for non-trivial plans and complete `references/evidence-gate.md` before claiming completion.
120
+
121
+ ## Artifact Ownership
122
+
123
+ - Feature artifacts live under `.specs/features/<slug>/`.
124
+ - Active harness state is `.specs/project/STATE.md`.
125
+ - Feature registry is `.specs/project/FEATURES.json`.
126
+ - Handoff is `.specs/HANDOFF.md`.
127
+ - `.specs/` files are canonical and git-tracked; there is no secondary store.
128
+ - `.specs/lessons.json` is the machine-owned canonical lessons state; `.specs/LESSONS.md` is its rendered view, regenerated by `scripts/lessons.py` on every write — do not hand-edit.
129
+ - Optional `.specs-exports/` projections are untracked debug aids only.
130
+ - `remember` remains canonical for durable cross-session decisions, rejected approaches, reusable patterns, and verification recipes.
131
+
132
+ ## Failure Handling
133
+
134
+ - `.specs/` directory missing or not writable: block spec-driven state mutation; do not fall back to memory or chat.
135
+ - massa-ai search or durable memory unavailable: continue from current source and `.specs/` artifacts; report that discovery or durable-memory synchronization was skipped.
136
+ - Synapse unavailable: continue with stateless targeted search.
137
+ - Artifact missing: create it only through an approved first write; otherwise block and ask for direction.
138
+ - Requirement cannot close: keep Specify open and ask the user, or record an explicit accepted assumption before execution.
139
+ - Design or Tasks was skipped incorrectly: stop, create the missing artifact, and resume from the updated contract.
140
+ - Validation command unavailable: record the missing command/tool in `validation.md` and mark `Blocked`.
141
+ - Discrimination sensor cannot be made safely reversible: mark `Blocked` unless the verification-agent can prove equivalent discrimination with an existing deterministic mutation fixture.
142
+ - Validation conflict: stop for user resolution when a validation asset conflicts with an approved specification.
143
+ - Fix loop exceeds 3 iterations: stop with `Blocked`, preserve evidence, and ask for direction.
144
+
145
+ ## Knowledge Verification Chain
146
+
147
+ When researching, designing, or making any technical decision, follow this chain in strict order. Never skip steps.
148
+
149
+ ```
150
+ Step 1: Codebase → existing code, conventions, patterns already in use
151
+ Step 2: Project docs → README, docs/, inline comments, .specs/project/STATE.md (Decisions)
152
+ Step 3: Context7 MCP → resolve library ID, then query for current API/patterns
153
+ Step 4: Web search → official docs, reputable sources, community patterns
154
+ Step 5: Flag as uncertain → "I'm not certain about X — here's my reasoning, but verify"
155
+ ```
156
+
157
+ - If a chain step's tool is unavailable (Context7 MCP not registered, no web
158
+ access), record it as a skipped sensor with its reason and continue to the next
159
+ step. An unavailable step is skipped, never silently treated as answered.
160
+ - Never skip to Step 5 if Steps 1-4 are available.
161
+ - Step 5 is always flagged uncertain — never presented as fact.
162
+ - Never assume or fabricate. If no answer is found, say "I don't know" or "I couldn't find documentation for this". Uncertainty is always preferable to fabrication; invented APIs/patterns cause cascading failures across design → tasks → implementation.
163
+
164
+ ## Brownfield Onboarding — 7-Doc Codebase Mapping
165
+
166
+ When the spec-driven work targets a codebase the agent has not yet mapped (brownfield, new repo, or cold project), derive a 7-doc codebase map before Specify closes. The map is the shared factual ground for requirements, design, and task derivation; it is not busywork — each doc feeds a downstream phase.
167
+
168
+ | Doc | Derives | Feeds |
169
+ | --- | --- | --- |
170
+ | `STACK.md` | languages, runtimes, frameworks, key libraries | Design constraints, verification commands |
171
+ | `ARCHITECTURE.md` | layers, modules, boundaries, data flow | Design, risk surface |
172
+ | `CONVENTIONS.md` | naming, file layout, commit/test conventions | Tasks, Execute |
173
+ | `STRUCTURE.md` | directory map, where new code goes | Tasks, file placement |
174
+ | `TESTING.md` | test runner, how to run gates, coverage tooling | Gate Check Commands, verification recipe |
175
+ | `INTEGRATIONS.md` | external services, APIs, contracts, auth | Discuss, risk escalation |
176
+ | `CONCERNS.md` | known risks, tech debt, migration landmines, security/privacy hotspots | Risk-domain escalation, validation focus |
177
+
178
+ Minimum bar: derive at least **`CONCERNS.md`** (risk surface — drives risk-domain escalation and validation focus) and **`TESTING.md`** (gate derivation — exact commands the Execute gate will run). If time or access is constrained, these two are non-negotiable; the other five are derived as the work needs them. Record the map under `.specs/features/<slug>/` (or the project onboarding dir) and confirm it against current source, not memory or external summaries.
179
+
180
+ ## Commands
181
+
182
+ Feature-level (auto-sized):
183
+
184
+ | Trigger Pattern | Reference |
185
+ | --- | --- |
186
+ | Specify feature, define requirements | `references/spec-driven/specify.md` |
187
+ | Discuss feature, capture context, how should this work | `references/spec-driven/discuss.md` |
188
+ | Design feature, architecture | `references/spec-driven/design.md` |
189
+ | Break into tasks, create tasks | `references/spec-driven/tasks.md` |
190
+ | Implement task, build, execute | `references/spec-driven/execute.md` |
191
+ | Validate, verify, test, UAT, walk me through it | `references/spec-driven/validate.md` |
192
+
193
+ Memory:
194
+
195
+ | Trigger Pattern | Reference |
196
+ | --- | --- |
197
+ | Record decision, project-level decision | `references/spec-driven/memory.md` |
198
+ | Pause work, end session, I need to stop | `references/spec-driven/memory.md` |
199
+ | Resume work, continue, pick up where we left off | `references/spec-driven/memory.md` |
200
+ | Load lessons, what have we learned, apply past lessons | `references/spec-driven/lessons.md` |
201
+ | Record lesson, distill lessons (auto-runs after validation) | `references/spec-driven/lessons.md` |
202
+
203
+ ## Output Behavior
204
+
205
+ After lightweight tasks (validation, feature-level checks), mention once per session that such tasks suit faster/cheaper models. For heavy tasks (complex design, large features), briefly note the reasoning requirements before starting. Be conversational, not robotic — add as a natural closing note, skip if the user is experienced or has already acknowledged the tip.
206
+
207
+ ## Example
208
+
209
+ User asks: "Specify offline draft sync, design it, create tasks, implement it, and verify it."
210
+
211
+ 1. Reuse `projectId` and `workflowSessionId=spec-offline-draft-sync`; recall prior sync decisions and load current `.specs/` artifacts.
212
+ 2. Run Specify and close requirements.
213
+ 3. Include Design because sync affects data, migration, and public behavior.
214
+ 4. Include Tasks because execution has dependency complexity.
215
+ 5. Execute one approved task at a time.
216
+ 6. Finish Execute with independent validation, including the discrimination sensor, then write `validation.md`.
217
+ <!-- validator anchors: .specs/ files | current repository source and approved .specs/ artifacts override stale memory | .specs/ directory missing | 3 verification iterations -->
@@ -0,0 +1,71 @@
1
+ ### TDD (Technical Design Document)
2
+
3
+ Use this workflow when the readiness checklist is true: one product direction is selected, a named requirements source exists, and no unresolved API, data, security/privacy, migration, rollout, or public compatibility decision blocks implementation design. Route unresolved proposals or competing directions to `workflows/rfc.md`, isolated finalized architecture decisions to `workflows/adr.md`, and broad requirements-to-delivery work to `workflows/spec-driven.md`.
4
+
5
+ Before the first substantive read, load `references/project-context.md` and run the project-context intake sweep for this repository.
6
+
7
+ ## Workflow
8
+
9
+ 1. Resolve or reuse `projectId` and `workflowSessionId=tdd-[entity]`.
10
+ 2. Establish evidence before asking questions:
11
+ - `recall` approved RFCs, ADRs, prior TDD decisions, constraints, rejected approaches, and verification patterns.
12
+ - Load `references/tdd/discovery-and-sizing.md`.
13
+ - Inspect current source, tests, source sets, project instructions, architecture documents, and existing design artifacts. Current source and approved project artifacts override stale memory.
14
+ - For testing plans, find whether each planned test file already exists and which source set owns it before choosing a location such as `commonTest`, `androidUnitTest`, `unitTest`, or the repository's actual equivalent.
15
+ - For UI/UX-affecting method, class, enum, sealed type, mapper, or state changes, enumerate parallel rendering surfaces and mappers that consume the affected symbol.
16
+ - When supplied Figma links, nodes, desktop selections, or screenshots materially affect supported Android, iOS, or KMP Compose Multiplatform UI design, use `workflows/design.md` as optional child context and keep this TDD as the owner of architecture, contracts, rollout, and verification strategy. Screenshots are context-only unless paired with structured Figma evidence.
17
+ - Run a pre-TDD `Strings Audit` when mappers branch on a type and call `stringResource`; record affected string keys/resources, branches, fallback behavior, and surfaces before proposing string changes.
18
+ - Load `references/synapse-policy.md` when two or more related searches are expected and `references/context-firewall.md` before broad or verbose source inspection.
19
+ 3. Confirm workflow fit with the readiness checklist in `references/tdd/discovery-and-sizing.md` and classify the document as Compact, Standard, or High-Risk from the exact sizing rules there. Do not size by guessed calendar duration.
20
+ - Record a `project_type` intake tag from this taxonomy: `integration`, `feature`, `refactor`, `infrastructure`, `payment`, `auth`, `data`. The `project_type` selects which conditional concerns in `references/tdd/document-contract.md` apply and which calibrated reference values from `references/tdd/calibrated-examples.md` are relevant; it does not mandate section counts or a fixed document shape.
21
+ - Apply the critical-section MANDATORY trigger mapping below. These are workflow-level selectors that point at the Conditional Concerns table in `references/tdd/document-contract.md`; they do not duplicate that table. When a trigger fires, the matching concerns are mandatory, not optional:
22
+ - `payment`, `auth`, PII, or regulated data → Security is mandatory.
23
+ - production or customer-facing rollout → Monitoring and Rollback are mandatory.
24
+ - external or cross-service integration → Dependencies and Security are mandatory.
25
+ 4. Resolve only material unknowns:
26
+ - Reuse facts already available in source or approved documents.
27
+ - Ask at most three related questions at a time, in the user's language.
28
+ - Distinguish verified facts, evidence-backed inferences, proposed decisions, and unresolved questions.
29
+ - Never invent owners, links, APIs, schemas, vendors, dates, thresholds, estimates, approvals, or project facts to complete a template.
30
+ 5. Load `references/tdd/document-contract.md`, plus `references/naming-standards.md` when the design names proposed components, modules, states, events, schemas, or fields, and draft the smallest decision-complete TDD for the selected depth.
31
+ - Write in the user's language while preserving established project terminology and technical identifiers.
32
+ - Focus on architecture, ownership boundaries, stable interfaces, data flow, failure behavior, and implementation strategy.
33
+ - Include implementation detail when it defines a contract or removes material ambiguity; exclude production implementation code and incidental framework syntax.
34
+ - For implementation planning, group task rows into independently buildable and testable PR groups using the TDD implementation task table contract. Prefer Small PRs; use Medium PRs only when splitting would break build, tests, UI, or review coherence; treat Large PRs as exceptions requiring split, stacked PR, or feature-flag rationale.
35
+ - Order non-breaking PR groups by layer when applicable: Data first, then Domain, then Presentation/Navigation. If the target project does not use clean layer names, map those labels to the closest repository boundaries and state the mapping.
36
+ - Include a test strategy checklist table. For each planned test file, write `amplify in existing location: <path> (<sourceSet>)` when source inspection finds an existing test, or `create in <sourceSet>: <path>` only when evidence supports the new location.
37
+ - Include a parallel rendering surfaces checklist for UI/UX-affecting changes, covering every discovered rendering surface and mapper that consumes the affected method, class, enum type, state, or model.
38
+ - Include `Decisions Revised During Implementation` and `Pre-Merge TDD Fidelity Check` sections so implementation-time divergences remain visible instead of silently rewriting the original design.
39
+ - Use a diagram only when it communicates interactions or state more clearly than prose. Use `mermaid-studio` when installed and rendering or complex diagram validation is valuable; otherwise use valid inline Mermaid or prose.
40
+ 6. Choose the artifact path from an explicit user path or an existing project convention. Otherwise default to `docs/design/<entity>.md`.
41
+ - If the target exists, treat the request as an update only when the user explicitly requested one; otherwise ask before overwriting it.
42
+ - When file mutation is unavailable or the user requested plan-only output, present the complete draft and intended path without writing.
43
+ 7. Run the configured Plan Challenge Gate. TDD plans require the full gate under the default policy; revise valid critical or high findings before finalization.
44
+ 8. Load `references/tdd/quality-and-lifecycle.md`, validate the document, and resolve blocking gaps. Keep non-blocking unknowns explicit with owners or decision points when known.
45
+ 9. If the implementation task table is stable and validated, discover whether Atlassian MCP has readable Jira project metadata and issue-creation capability.
46
+ - If Atlassian MCP is unavailable or read-only, leave the table's `Jira Key` values as `Unavailable` and report that ticket creation was skipped.
47
+ - If Atlassian MCP is available, ask whether the user wants to create Jira tickets now. If declined, set `Jira Key` to `Not requested`.
48
+ - If the user accepts, invoke `workflows/ticket.md`; Jira creation remains owned solely by the ticket workflow. Create one standard Jira issue per PR group. Create row-level sub-tasks only when the selected ticket hierarchy requires them.
49
+ - Update `Jira Key` only with confirmed Jira keys returned by the ticket workflow. Use `Pending` for approved-but-uncreated PR groups and never fabricate keys.
50
+ 10. Save the document as `Draft` or `In Review`. Never mark it `Approved`, invent sign-off, or begin downstream implementation without the required human decision.
51
+ 11. Persist only durable architecture constraints, accepted trade-offs, rejected approaches, compatibility requirements, and verification recipes through `remember` after recall, deduplication, and scoring. Use `decision` with `memory:semantic` for the architectural blueprint.
52
+ 12. Complete `references/evidence-gate.md` and report the artifact path, included conditional sections, unresolved questions, Jira creation outcome, memory outcome, and residual risk.
53
+
54
+ ## Failure Handling
55
+
56
+ - massa-ai unavailable: continue from current source and project documents; report skipped durable-memory synchronization.
57
+ - Synapse unavailable: continue with stateless targeted search.
58
+ - Evidence is insufficient: ask the smallest blocking question set or mark the point unresolved; do not fabricate completion.
59
+ - Direction is still disputed: stop and route to RFC rather than embedding an unapproved choice in the TDD.
60
+ - Existing document conflicts with current source or approved decisions: surface the conflict and request resolution before replacing the authoritative statement.
61
+ - Diagram tooling unavailable: use simple validated Mermaid or prose; diagram rendering must not block a complete design.
62
+
63
+ ## Example
64
+
65
+ User asks: "Create a TDD for moving password reset tokens from the users table into a dedicated store."
66
+
67
+ 1. Recall approved auth decisions and inspect the current token flow, persistence model, tests, and operational constraints.
68
+ 2. Classify High-Risk because the design affects authentication and sensitive data.
69
+ 3. Ask only unresolved security, compatibility, or rollout questions that source cannot answer.
70
+ 4. Draft the core design plus conditional security, data migration, observability, rollout, and rollback sections.
71
+ 5. Challenge the plan, revise serious findings, validate decision completeness, and save a Draft without fabricated approval.