self-evolving-workflow 0.0.0-stage → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/LICENSE +27 -0
  2. package/README.md +90 -2
  3. package/dist/agent-memory-prompts.d.ts +13 -0
  4. package/dist/agent-memory-prompts.js +55 -0
  5. package/dist/cli.d.ts +2 -0
  6. package/dist/cli.js +6 -0
  7. package/dist/closeout.d.ts +105 -0
  8. package/dist/closeout.js +479 -0
  9. package/dist/code.d.ts +39 -0
  10. package/dist/code.js +124 -0
  11. package/dist/common.d.ts +9 -0
  12. package/dist/common.js +42 -0
  13. package/dist/context-envelope.d.ts +59 -0
  14. package/dist/context-envelope.js +23 -0
  15. package/dist/host-adapters.d.ts +34 -0
  16. package/dist/host-adapters.js +151 -0
  17. package/dist/http.d.ts +3 -0
  18. package/dist/http.js +90 -0
  19. package/dist/index.d.ts +16 -0
  20. package/dist/index.js +13 -0
  21. package/dist/knowledge-cli.d.ts +183 -0
  22. package/dist/knowledge-cli.js +654 -0
  23. package/dist/knowledge-reads.d.ts +71 -0
  24. package/dist/knowledge-reads.js +193 -0
  25. package/dist/memory.d.ts +97 -0
  26. package/dist/memory.js +250 -0
  27. package/dist/retrospective.d.ts +57 -0
  28. package/dist/retrospective.js +248 -0
  29. package/dist/search.d.ts +36 -0
  30. package/dist/search.js +112 -0
  31. package/dist/skill-addition.d.ts +25 -0
  32. package/dist/skill-addition.js +89 -0
  33. package/dist/skill-design.d.ts +96 -0
  34. package/dist/skill-design.js +226 -0
  35. package/dist/skill-replay.d.ts +55 -0
  36. package/dist/skill-replay.js +451 -0
  37. package/dist/skill-route.d.ts +30 -0
  38. package/dist/skill-route.js +75 -0
  39. package/dist/transcript-evidence.d.ts +3 -0
  40. package/dist/transcript-evidence.js +58 -0
  41. package/dist/upstream/chunker.d.ts +24 -0
  42. package/dist/upstream/chunker.js +96 -0
  43. package/dist/upstream/file-protocol.d.ts +45 -0
  44. package/dist/upstream/file-protocol.js +117 -0
  45. package/dist/upstream/frontmatter.d.ts +47 -0
  46. package/dist/upstream/frontmatter.js +86 -0
  47. package/dist/upstream/graph-search.d.ts +33 -0
  48. package/dist/upstream/graph-search.js +67 -0
  49. package/dist/upstream/l1-extraction.d.ts +26 -0
  50. package/dist/upstream/l1-extraction.js +405 -0
  51. package/dist/upstream/llm.d.ts +8 -0
  52. package/dist/upstream/llm.js +1 -0
  53. package/dist/upstream/merge.d.ts +50 -0
  54. package/dist/upstream/merge.js +153 -0
  55. package/dist/upstream/prompts.d.ts +53 -0
  56. package/dist/upstream/prompts.js +185 -0
  57. package/dist/upstream/search-utils.d.ts +34 -0
  58. package/dist/upstream/search-utils.js +55 -0
  59. package/dist/upstream/slug.d.ts +26 -0
  60. package/dist/upstream/slug.js +103 -0
  61. package/dist/upstream/template.d.ts +29 -0
  62. package/dist/upstream/template.js +80 -0
  63. package/dist/upstream/tokenize.d.ts +4 -0
  64. package/dist/upstream/tokenize.js +29 -0
  65. package/dist/wiki-change.d.ts +76 -0
  66. package/dist/wiki-change.js +299 -0
  67. package/dist/wiki-entry.d.ts +26 -0
  68. package/dist/wiki-entry.js +93 -0
  69. package/dist/wiki-ingest.d.ts +12 -0
  70. package/dist/wiki-ingest.js +126 -0
  71. package/dist/wiki-migration.d.ts +16 -0
  72. package/dist/wiki-migration.js +268 -0
  73. package/dist/wiki-tokens.d.ts +1 -0
  74. package/dist/wiki-tokens.js +46 -0
  75. package/dist/wiki.d.ts +103 -0
  76. package/dist/wiki.js +330 -0
  77. package/dist/workflow-cli.d.ts +2 -0
  78. package/dist/workflow-cli.js +258 -0
  79. package/dist/workflow-install.d.ts +36 -0
  80. package/dist/workflow-install.js +148 -0
  81. package/dist/workflow-knowledge.d.ts +16 -0
  82. package/dist/workflow-knowledge.js +24 -0
  83. package/dist/workflow-mcp.d.ts +2 -0
  84. package/dist/workflow-mcp.js +144 -0
  85. package/dist/workflow-names.d.ts +4 -0
  86. package/dist/workflow-names.js +18 -0
  87. package/dist/workflow-runtime.d.ts +622 -0
  88. package/dist/workflow-runtime.js +627 -0
  89. package/dist/workflow-skills.d.ts +48 -0
  90. package/dist/workflow-skills.js +141 -0
  91. package/package.json +76 -4
  92. package/skills/ew-odyssey/SKILL.md +237 -0
  93. package/skills/ew-odyssey/references/audit-artifacts.md +7 -0
  94. package/skills/ew-odyssey/references/odyssey-base-codex.md +3 -0
  95. package/skills/ew-odyssey/references/odyssey-base.md +278 -0
  96. package/skills/ew-odyssey/references/odyssey-debug.codex.md +305 -0
  97. package/skills/ew-odyssey/references/odyssey-debug.md +283 -0
  98. package/skills/ew-odyssey/references/odyssey-defensive.codex.md +395 -0
  99. package/skills/ew-odyssey/references/odyssey-defensive.md +369 -0
  100. package/skills/ew-odyssey/references/odyssey-improve.codex.md +270 -0
  101. package/skills/ew-odyssey/references/odyssey-improve.md +248 -0
  102. package/skills/ew-odyssey/references/odyssey-planex.codex.md +352 -0
  103. package/skills/ew-odyssey/references/odyssey-planex.md +312 -0
  104. package/skills/ew-odyssey/references/odyssey-review.codex.md +283 -0
  105. package/skills/ew-odyssey/references/odyssey-review.md +251 -0
  106. package/skills/ew-odyssey/references/odyssey-security.md +249 -0
  107. package/skills/ew-odyssey/references/odyssey-ui.codex.md +294 -0
  108. package/skills/ew-odyssey/references/odyssey-ui.md +250 -0
  109. package/skills/ew-odyssey/references/prepare/odyssey-debug.md +105 -0
  110. package/skills/ew-odyssey/references/prepare/odyssey-defensive.md +121 -0
  111. package/skills/ew-odyssey/references/prepare/odyssey-improve.md +93 -0
  112. package/skills/ew-odyssey/references/prepare/odyssey-planex.md +104 -0
  113. package/skills/ew-odyssey/references/prepare/odyssey-review.md +98 -0
  114. package/skills/ew-odyssey/references/prepare/odyssey-security.md +94 -0
  115. package/skills/ew-odyssey/references/prepare/odyssey-ui.md +87 -0
  116. package/skills/ew-orchestrate/SKILL.md +236 -0
  117. package/skills/ew-orchestrate/references/auto-policy.md +165 -0
  118. package/skills/ew-orchestrate/references/companion-route.md +52 -0
  119. package/skills/ew-orchestrate/references/ew-orchestrate.md +27 -0
  120. package/skills/ew-orchestrate/references/goal.md +53 -0
  121. package/skills/ew-orchestrate/references/knowledge-route.md +163 -0
  122. package/skills/ew-orchestrate/references/orchestrator-run-loop.md +36 -0
  123. package/skills/ew-orchestrate/references/planning.md +137 -0
  124. package/skills/ew-orchestrate/steps/ew-analyze/SKILL.md +62 -0
  125. package/skills/ew-orchestrate/steps/ew-analyze/references/boundary-grill.md +50 -0
  126. package/skills/ew-orchestrate/steps/ew-analyze/references/issue-gaps-analyze.md +59 -0
  127. package/skills/ew-orchestrate/steps/ew-analyze/references/prepare.md +42 -0
  128. package/skills/ew-orchestrate/steps/ew-analyze/references/workflow.md +401 -0
  129. package/skills/ew-orchestrate/steps/ew-brainstorm/SKILL.md +32 -0
  130. package/skills/ew-orchestrate/steps/ew-companion/SKILL.md +9 -0
  131. package/skills/ew-orchestrate/steps/ew-execute/SKILL.md +71 -0
  132. package/skills/ew-orchestrate/steps/ew-execute/references/prepare.md +69 -0
  133. package/skills/ew-orchestrate/steps/ew-execute/references/workflow.md +373 -0
  134. package/skills/ew-orchestrate/steps/ew-plan/SKILL.md +102 -0
  135. package/skills/ew-orchestrate/steps/ew-plan/references/boundary-grill.md +50 -0
  136. package/skills/ew-orchestrate/steps/ew-plan/references/prepare.md +51 -0
  137. package/skills/ew-orchestrate/steps/ew-plan/references/tdd.md +53 -0
  138. package/skills/ew-orchestrate/steps/ew-plan/references/workflow.md +278 -0
  139. package/skills/ew-orchestrate/steps/ew-review/SKILL.md +44 -0
  140. package/skills/ew-orchestrate/steps/ew-review/references/odyssey-base-codex.md +3 -0
  141. package/skills/ew-orchestrate/steps/ew-review/references/prepare.md +76 -0
  142. package/skills/ew-orchestrate/steps/ew-review/references/workflow.md +283 -0
  143. package/skills/ew-skill-design/SKILL.md +28 -0
  144. package/skills/ew-skill-design/references/package-contract.md +28 -0
  145. package/skills/ew-skill-design/references/validation.md +7 -0
  146. package/skills/team-swarm/SKILL.md +231 -0
  147. package/skills/team-swarm/references/mcp-coordination.md +10 -0
  148. package/skills/team-swarm/roles/analyst/role.md +181 -0
  149. package/skills/team-swarm/roles/ant/role.md +149 -0
  150. package/skills/team-swarm/roles/coordinator/commands/converge.md +154 -0
  151. package/skills/team-swarm/roles/coordinator/commands/init-swarm.md +134 -0
  152. package/skills/team-swarm/roles/coordinator/commands/iterate.md +202 -0
  153. package/skills/team-swarm/roles/coordinator/role.md +228 -0
  154. package/skills/team-swarm/roles/scorer/role.md +150 -0
  155. package/skills/team-swarm/scripts/aco.py +646 -0
  156. package/skills/team-swarm/scripts/pheromone.py +144 -0
  157. package/skills/team-swarm/scripts/scoring.py +111 -0
  158. package/skills/team-swarm/scripts/test_aco.py +606 -0
  159. package/skills/team-swarm/specs/ant-output-schema.md +127 -0
  160. package/skills/team-swarm/specs/convergence-criteria.md +108 -0
  161. package/skills/team-swarm/specs/pheromone-schema.md +125 -0
  162. package/skills/team-swarm/specs/swarm-config-template.json +71 -0
  163. package/skills/team-swarm/specs/swarm-protocol.md +123 -0
  164. package/skills/workflow-closeout/SKILL.md +10 -0
  165. package/skills/workflow-evolve/SKILL.md +79 -0
  166. package/skills/workflow-evolve/references/agy-gate.md +27 -0
  167. package/skills/workflow-evolve/references/auto-loop.md +20 -0
  168. package/skills/workflow-evolve/references/history-review.md +14 -0
  169. package/skills/workflow-evolve/scripts/codex-memory-replay.mjs +76 -0
  170. package/skills/workflow-evolve/scripts/codex-replay.mjs +1 -0
  171. package/skills/workflow-evolve/scripts/evolve-loop.mjs +259 -0
  172. package/skills/workflow-evolve/scripts/memory-codex-mcp.mjs +124 -0
  173. package/workflows/index.json +23 -0
@@ -0,0 +1,251 @@
1
+ ---
2
+ name: ew-odyssey-review
3
+ prepare: odyssey-review
4
+ session-mode: inherited
5
+ ---
6
+
7
+ # Workflow: Odyssey Review
8
+
9
+ ## State Chain
10
+
11
+ ```
12
+ S_INTAKE → S_ARCHAEOLOGY → S_EXPLORE → S_REVIEW → S_FIX → S_CONFIRM → [back-half]
13
+ ```
14
+
15
+ Back-half: `S_GENERALIZE → S_DISCOVER → S_RECORD → END` (see [shared phases](odyssey-base.md)).
16
+
17
+ ---
18
+
19
+ ## Boundary
20
+
21
+ **In scope:** Multi-dimensional deep review of target code → exhaustive fix ALL findings by severity → generalize patterns project-wide.
22
+ **Out of scope:** Root cause debug → `--mode debug` | Feature implementation → `--mode planex` | UI visual optimization → `--mode ui`. Zero-residual applies (fix ALL findings within fix_threshold, default all).
23
+
24
+ ---
25
+
26
+ ## Target Resolution
27
+
28
+ | Input | Resolution |
29
+ |-------|-----------|
30
+ | File/dir path | Review those files |
31
+ | `HEAD` / `staged` | `git diff HEAD` / `git diff --staged` |
32
+ | Phase number | state.json → changed files |
33
+ | PR number | `git diff main...HEAD` |
34
+
35
+ ---
36
+
37
+ ## Session Fields
38
+
39
+ ```json
40
+ { "target": "", "dimensions": [], "review_result": {"remaining_actionable": 0},
41
+ "patterns": [], "confirmation": null, "generalization_stats": null }
42
+ ```
43
+
44
+ ---
45
+
46
+ ## evidence.ndjson Phases
47
+
48
+ `archaeology|explore|review|fix|discovery|decision|self-iteration`
49
+
50
+ ---
51
+
52
+ ## phase_goals[]
53
+
54
+ | ID | Goal | done_when | phase | skip_when |
55
+ |----|------|-----------|-------|-----------|
56
+ | G1 | Review completed | all dimensions reviewed | S_REVIEW | — |
57
+ | G2 | Explore context | explore.json populated | S_EXPLORE | — |
58
+ | G3 | Zero remaining | `remaining_actionable == 0` | S_CONFIRM | skip_fix |
59
+ | G4 | Pattern generalized | patterns[] ≥1 | S_GENERALIZE | skip_generalize |
60
+ | G5 | Discoveries triaged | all hits classified | S_DISCOVER | skip_generalize |
61
+ | G6 | Learnings persisted | spec entries or no actionable | S_RECORD | — |
62
+
63
+ ---
64
+
65
+ ## understanding.md — 8 Sections
66
+
67
+ 1. Target & Scope
68
+ 2. Archaeology
69
+ 3. Exploration
70
+ 4. Review Results
71
+ 5. Fix & Confirmation
72
+ 6. Generalization
73
+ 7. Discoveries
74
+ 8. Learnings
75
+
76
+ Specs: `agent-memory wiki constraints --category review`.
77
+
78
+ ---
79
+
80
+ ## State Machine — Transitions
81
+
82
+ ```
83
+ S_ARCHAEOLOGY → S_EXPLORE : complete
84
+ S_EXPLORE → S_REVIEW : complete
85
+ S_REVIEW → S_FIX : !skip_fix AND findings
86
+ S_REVIEW → S_GENERALIZE : skip_fix OR no findings, !skip_generalize
87
+ S_REVIEW → S_RECORD : both skip
88
+ S_FIX → S_CONFIRM : tier complete
89
+ S_CONFIRM → S_GENERALIZE : confirmed, !skip_generalize
90
+ S_CONFIRM → S_RECORD : confirmed, skip_generalize
91
+ S_CONFIRM → S_FIX : needs_rework
92
+ ```
93
+
94
+ Discover routes: fixable sibling → S_FIX; new target needing review → S_REVIEW (loops < max_loops).
95
+
96
+ ---
97
+
98
+ ## Actions
99
+
100
+ ### A_ARCHAEOLOGY
101
+
102
+ 2 parallel Agents:
103
+ - **Timeline**: `git log --oneline -20 -- {files}`
104
+ - **Blame**: top 3 files `git blame -L {region}`
105
+
106
+ Evidence phase=archaeology.
107
+
108
+ `evolve delegate --role analyze --mode analysis` (`run_in_background: true`):
109
+ - PURPOSE: review recent modifications related to {target}
110
+ - EXPECTED: JSON `[{commit_sha, risk_level, analysis, could_cause_issue, explanation}]`
111
+
112
+ Update §2 (Archaeology).
113
+
114
+ If an archaeology agent fails, log W003 and proceed with available results.
115
+
116
+ ### A_EXPLORE
117
+
118
+ Skip if no CLI tools (W006).
119
+
120
+ `evolve delegate --role explore --mode analysis` (`run_in_background: true`):
121
+ - PURPOSE: call chains, recent changes, error gaps, similar patterns
122
+ - EXPECTED: JSON `{call_chains, recent_changes, error_gaps, similar_patterns}`
123
+
124
+ Write `explore.json` + evidence phase=explore. Update §3 (Exploration). Mark G2.
125
+
126
+ **GATE: discovery-complete** — archaeology/explore evidence logged, understanding.md §2-§3 updated, G2 marked (W003 partial / W006 skip acceptable).
127
+
128
+ ### A_REVIEW
129
+
130
+ Spawn N parallel Agents, one per dimension:
131
+ - **Correctness**: logic errors, boundary conditions, null/undefined, race conditions
132
+ - **Security**: injection, XSS, CSRF, data exposure, auth bypass
133
+ - **Performance**: hot paths, N+1, memory leaks, unnecessary recomputation
134
+ - **Architecture**: layer violations, circular deps, interface contracts, SoC
135
+
136
+ Each returns `[{title, severity, file, line, description, suggestion, cwe}]`. Merge → evidence phase=review. Write `review_result` + §4 severity matrix. Mark G1.
137
+
138
+ **GATE: all-dimensions-reviewed** — all 4 dimension agents (correctness, security, performance, architecture) completed, findings merged into review_result with severity classification, evidence phase=review logged, §4 severity matrix written, G1 marked. Zero dimensions reviewed is BLOCKED (W002 partial with ≥1 dimension allowed).
139
+
140
+ ### A_FIX
141
+
142
+ Exhaustive iterative fix — descend by severity until `remaining_actionable == 0`:
143
+ ```
144
+ for tier in [critical, high, medium, low].filter(>= threshold):
145
+ for each unfixed candidate: read ±20 lines → fix → evidence phase=fix
146
+ re-review modified area (new findings → append, continue; max 2 per tier)
147
+ tier done → auto-commit
148
+ ```
149
+ Normal: request_user_input per tier | `-y`: auto-fix all. Remaining > 0 → retry (**MANDATORY hard limit: max_fix_rounds = 5**). Unchanged 2 rounds → classify each individually. After 5 rounds remaining > 0 → escalate: Normal: request_user_input (continue/accept/reclassify) | `-y`: classify remaining as `deferred`, proceed. **No partial-tier advancement** — a tier is complete only when every finding is fixed or individually classified. Blanket "pre-existing" forbidden. Commit per tier: `"odyssey-review({slug}): FIX-{tier} — {N} items fixed"`.
150
+
151
+ ### A_CONFIRM
152
+
153
+ Run tests + `evolve delegate --role review --mode analysis` (`run_in_background: true`) zero-residual review. `remaining == 0 AND new == 0` → confirmed, mark G3; otherwise → needs_rework → S_FIX. Update `confirmation` + `remaining_actionable` + §5.
154
+
155
+ **GATE: zero-remaining** — exhaustive fix applied tier-by-tier, `remaining_actionable == 0` (or all remaining individually classified as deferred after 5-round escalation), tests pass, CLI re-review confirms no new findings, confirmation + §5 written, G3 marked. `needs_rework` routes back to FIX; skippable only when `skip_fix == true`.
156
+
157
+ ---
158
+
159
+ ## Generalize Source
160
+
161
+ Review findings with severity >= medium.
162
+
163
+ **Discover routing:** fixable sibling → S_FIX; new target → S_REVIEW.
164
+
165
+ ---
166
+
167
+ ## Knowledge Persistence (§8)
168
+
169
+ Include verified reusable findings in the Run summary and harvest the completed Session through Agent Memory closeout.
170
+
171
+
172
+ | Category | Content | Follow-up |
173
+ |----------|---------|-----------|
174
+ | Cross-dimension recurring pattern | Pattern + affected dimensions + coding standard | `stage spec → review` |
175
+ | Security finding | Vulnerability type + triggers + fix approach | `stage spec → debug` |
176
+ | Architecture violation pattern | Violation + correct boundary + verification | `stage spec → arch` |
177
+ | Reusable generalization pattern | Signature + risk + fix template + scope | `stage spec → coding` |
178
+
179
+ ---
180
+
181
+ ## Completion Summary
182
+
183
+ ```
184
+ --- REVIEW-TEST-FIX ODYSSEY COMPLETE ---
185
+ Target: {target} Dimensions: {dims}
186
+ Findings: {C}C {H}H {M}M {L}L Fix: {fixed}, confirmed={yes|skip}
187
+ Patterns: {N} ({by_layer}) Scan hits: {total} ({cross} cross-layer)
188
+ Issues: {N} created
189
+ Decisions: {N} resolved, {M} pending, {K} deferred
190
+ Learnings: {N} persisted
191
+ Self-iter: {N} rounds across {M} stages
192
+ Goals: {done}/{total} ({skipped} skipped)
193
+ ---
194
+ ```
195
+
196
+ ---
197
+
198
+ ## `-y` Decision Points
199
+
200
+ | Decision Point | Normal | `-y` |
201
+ |---------------|--------|------|
202
+ | S_FIX tier candidates | request_user_input | auto-fix `deferred` |
203
+ | S_FIX re-review new findings | request_user_input | auto-append |
204
+ | S_CONFIRM needs_rework | request_user_input | auto proceed |
205
+ | A_DISCOVER routing | request_user_input | auto-fix w/ template, issue for rest |
206
+
207
+ ---
208
+
209
+ ## Mode-Specific Phase Gates
210
+
211
+ - **Discovery gate** (ARCHAEOLOGY/EXPLORE): evidence logged, understanding.md updated. Archaeology partial via W003 acceptable; explore W006 skip acceptable.
212
+ - **Audit gate** (REVIEW): all dimension agents completed, findings merged. Zero dimensions reviewed is BLOCKED (W002 partial allowed).
213
+ - **FIX gate:** current severity tier fully addressed. Per-fix evidence logged. Auto-commit per tier. No partial-tier advancement.
214
+ - **CONFIRM gate:** tests pass; `remaining_actionable == 0` and new findings == 0; confirmation written. needs_rework → route back to FIX.
215
+
216
+ ---
217
+
218
+ ## Error Codes (review-specific)
219
+
220
+ | Code | Severity | Condition | Recovery |
221
+ |------|----------|-----------|----------|
222
+ | W003 | warning | Archaeology agent failure | Proceed with available results |
223
+ | W006 | warning | No CLI tools | Skip explore |
224
+
225
+ ---
226
+
227
+ ## Success Criteria (review-specific)
228
+
229
+ - [ ] Session + 4 output files + prior knowledge searched
230
+ - [ ] Archaeology + CLI review → evidence
231
+ - [ ] CLI exploration → explore.json
232
+ - [ ] All 4 dimensions reviewed with findings merged
233
+ - [ ] understanding.md 8 sections progressive
234
+ - [ ] Exhaustive fix by severity tier + confirmed (unless --skip-fix)
235
+ - [ ] Generalization + scan (unless --skip-generalize)
236
+ - [ ] Discoveries classified; unfixed findings individually justified
237
+ - [ ] phase_goals + goal audit + resumable via -c
238
+ - [ ] Completion summary
239
+
240
+ ---
241
+
242
+ ## Next Step Routing (review-specific)
243
+
244
+ | Condition | Next |
245
+ |-----------|------|
246
+ | Discovery issues | `Open the follow-up findings in the project issue tracker` |
247
+ | Document pattern | `Review the module and stage the reusable method via Agent Memory closeout` |
248
+ | Debug root cause | `/ew-odyssey <issue> --mode debug` |
249
+ | Second opinion | `evolve delegate "<review prompt>" --mode analysis` |
250
+ | Related question | `Use an Evolve analyze step for the question` |
251
+ | Pending decisions | Filter evidence phase=decision status=pending |
@@ -0,0 +1,249 @@
1
+ ---
2
+ name: ew-odyssey-security
3
+ prepare: odyssey-security
4
+ session-mode: inherited
5
+ ---
6
+
7
+ # Workflow: Odyssey Security
8
+
9
+ Read-only tiered security audit — OWASP Top 10 / dependency supply chain / secrets / CI/CD / STRIDE / git history → severity matrix report → generalize security patterns.
10
+
11
+ ---
12
+
13
+ ## State Chain
14
+
15
+ ```
16
+ S_INTAKE → S_RECON → S_SCAN → S_REPORT → [back-half]
17
+ ```
18
+
19
+ Back-half: `S_GENERALIZE → S_DISCOVER → S_RECORD → END` (see [shared phases](odyssey-base.md) §Shared Back-Half).
20
+
21
+ **No S_FIX / S_CONFIRM** — this mode is read-only. Findings route to `--mode improve` or `--mode debug` for remediation.
22
+
23
+ ---
24
+
25
+ ## Boundary
26
+
27
+ **In scope:** Read-only security audit — OWASP Top 10, dependency supply chain, secrets detection, CI/CD pipeline, STRIDE threat modeling, git history archaeology → severity matrix report → generalize security patterns.
28
+ **Out of scope:** Fixing vulnerabilities → `--mode improve` | Root cause debug → `--mode debug` | Feature implementation → `--mode planex` | UI → `--mode ui`. Read-only invariant applies: NEVER modify source code.
29
+
30
+ ---
31
+
32
+ ## Context
33
+
34
+ Target resolution (input → audit scope) and tier coverage (which audits each tier runs) are defined in [the selected mode preparation](prepare/odyssey-security.md) §Input Interpretation — that is the canonical wording.
35
+
36
+ ### Session Fields
37
+
38
+ ```json
39
+ { "target": "", "tier": "standard", "scan_phases": [],
40
+ "audit_result": {}, "findings_count": {},
41
+ "generalization_stats": null }
42
+ ```
43
+
44
+ ### evidence.ndjson Phases
45
+
46
+ `recon|scan|report|discovery|decision|self-iteration`
47
+
48
+ - `recon`: `category` (tech_stack|entry_point|auth_module|data_flow), `detail`
49
+ - `scan`: `phase` (owasp|dependency|secrets|cicd|stride|git_history), `severity`, `cwe`
50
+ - `report`: `finding_ref`, `remediation`
51
+
52
+ ### phase_goals[]
53
+
54
+ | ID | Goal | Phase | skip_when |
55
+ |----|------|-------|-----------|
56
+ | G1 | Recon completed | S_RECON | — |
57
+ | G2 | Scan completed (all tier phases) | S_SCAN | — |
58
+ | G3 | Report produced | S_REPORT | — |
59
+ | G4 | Pattern generalized | S_GENERALIZE | skip_generalize |
60
+ | G5 | Discoveries triaged | S_DISCOVER | skip_generalize |
61
+ | G6 | Learnings persisted | S_RECORD | — |
62
+
63
+ ### understanding.md — 7 Sections
64
+
65
+ 1. Target & Tier
66
+ 2. Reconnaissance
67
+ 3. Scan Findings (by phase)
68
+ 4. Severity Matrix
69
+ 5. Full Report (findings + remediation)
70
+ 6. Generalization
71
+ 7. Discoveries & Learnings
72
+
73
+ ---
74
+
75
+ ## State Machine
76
+
77
+ ### Transitions
78
+
79
+ ```
80
+ S_RECON → S_SCAN : complete
81
+ S_SCAN → S_REPORT : all tier phases complete
82
+ S_REPORT → S_GENERALIZE : report produced, !skip_generalize
83
+ S_REPORT → S_RECORD : report produced, skip_generalize
84
+ ```
85
+
86
+ Discover routes: new security concern in sibling module → S_SCAN (re-scan with expanded scope, loops < max_loops).
87
+
88
+ ---
89
+
90
+ ## Actions
91
+
92
+ **A_INTAKE extra** — Tier resolution: parse `--tier` flag (default: standard). Record tier + applicable scan phases to `session.json.scan_phases`.
93
+
94
+ **A_RECON** — (1) Detect tech stack from package.json / go.mod / requirements.txt / Cargo.toml. (2) Identify entry points: HTTP handlers, API routes, CLI parsers, WebSocket handlers. (3) List authentication/authorization modules. (4) Map data flow: user input → processing → storage → output. (5) Evidence phase=recon. Update §2. Mark G1.
95
+
96
+ **GATE: recon-complete** — tech stack detected, entry points identified, auth/authz modules listed, data flow mapped. Evidence phase=recon logged. §2 updated. BLOCKED if no entry points found (E002).
97
+
98
+ Commit: `"odyssey-security({slug}): RECON — reconnaissance complete"`
99
+
100
+ **A_SCAN** — Tier-gated parallel scan phases:
101
+
102
+ - **OWASP Top 10** (all tiers): Spawn parallel agents per category (A01-A10). Each scans relevant source files using Grep pattern matching (`eval(`, `exec(`, `innerHTML`, `dangerouslySetInnerHTML`, `sql.*\+.*req\.`, `process\.env` without validation). Returns `[{title, severity, category, file, line, description, cwe, remediation}]`.
103
+
104
+ | # | Category | What to check |
105
+ |---|----------|--------------|
106
+ | A01 | Broken Access Control | Missing auth middleware, direct object references, path traversal |
107
+ | A02 | Cryptographic Failures | Weak algorithms, hardcoded keys, missing TLS, plaintext storage |
108
+ | A03 | Injection | SQL concatenation, shell exec with user input, template injection |
109
+ | A04 | Insecure Design | Missing rate limits, no CSRF tokens, predictable tokens |
110
+ | A05 | Security Misconfiguration | Debug mode, default credentials, verbose errors, open CORS |
111
+ | A06 | Vulnerable Components | Known CVEs in dependencies |
112
+ | A07 | Auth Failures | Weak password rules, missing brute-force protection, session fixation |
113
+ | A08 | Data Integrity | Deserialization of untrusted data, unsigned updates |
114
+ | A09 | Logging Failures | Missing audit logs, logging sensitive data |
115
+ | A10 | SSRF | Unvalidated URLs in server-side requests |
116
+
117
+ - **Dependency Audit** (all tiers): `npm audit --json` / lockfile integrity / typosquatting risk on critical dependencies.
118
+ - **Secrets Detection** (standard + deep): Grep for `(password|secret|api.?key|token|credential).*=.*['"][^'"]{8,}` in `*.{ts,js,json,env*}`. Check `.env.example` for leaked values. Check `.gitignore` for missing `.env` patterns. **NEVER log actual secret values.**
119
+ - **CI/CD Audit** (standard + deep): Scan `.github/workflows/*.yml` for overly permissive permissions, unpinned action versions, secrets in logs, `pull_request_target` injection risk.
120
+ - **STRIDE Threat Modeling** (deep only): For each critical module from recon:
121
+
122
+ | Threat | Question |
123
+ |--------|----------|
124
+ | **S**poofing | Can identity be faked? Is auth per-request? |
125
+ | **T**ampering | Can data be modified in transit/storage? Integrity checks? |
126
+ | **R**epudiation | Are actions logged with user identity? |
127
+ | **I**nformation Disclosure | Can unauthorized data be accessed? |
128
+ | **D**enial of Service | Resource limits? Rate limiting? |
129
+ | **E**levation of Privilege | Can roles be escalated? Input validation on role fields? |
130
+
131
+ - **Git History Archaeology** (deep only): Search for previously committed secrets (`git log --all --diff-filter=D -- "*.env" "*.key" "*.pem"`), password strings in history.
132
+
133
+ Merge all findings → evidence phase=scan. Write `session.json.audit_result`. Update §3 (findings by phase) + §4 (severity matrix). Mark G2.
134
+
135
+ **GATE: scan-complete** — all tier-required scan phases completed with structured findings, merged into severity matrix, evidence phase=scan logged per phase. Tier-required phase not attempted is BLOCKED (W001 tool unavailable / W002 git history failure are warnings, not blocks).
136
+
137
+ Commit: `"odyssey-security({slug}): SCAN — {tier} tier scan complete"`
138
+
139
+ **A_REPORT** — (1) Produce severity matrix: CRITICAL / HIGH / MEDIUM / LOW with file:line references and remediation for each finding. (2) Compute summary statistics. (3) Write understanding.md §5 (full report). (4) Write `session.json.findings_count`. (5) Evidence phase=report. Mark G3.
140
+
141
+ **GATE: report-produced** — severity matrix with file:line references and remediation for every finding; summary statistics computed; §5 written; `audit_result` populated.
142
+
143
+ Commit: `"odyssey-security({slug}): REPORT — severity matrix produced"`
144
+
145
+ ---
146
+
147
+ ## Generalize Source
148
+
149
+ Security findings with severity >= medium + vulnerability patterns across scan phases.
150
+
151
+ **Discover routing:** sibling module with same vulnerability class → S_SCAN (re-scan expanded scope); new critical finding → evidence phase=decision, recommend `--mode improve`.
152
+
153
+ ---
154
+
155
+ ## Knowledge Persistence (§7)
156
+
157
+ Include verified reusable findings in the Run summary and harvest the completed Session through Agent Memory closeout.
158
+
159
+
160
+ | Category | Content | Follow-up |
161
+ |----------|---------|-----------|
162
+ | Vulnerability pattern | CWE + trigger + detection pattern + remediation | `stage spec → debug` |
163
+ | Security constraint | Trust boundary + validation rule + enforcement | `stage spec → arch` |
164
+ | Dependency risk | Package + CVE + safe version + migration path | `stage spec → coding` |
165
+ | CI/CD hardening | Misconfiguration + fix + prevention check | `stage spec → coding` |
166
+
167
+ ---
168
+
169
+ ## Completion Summary
170
+
171
+ ```
172
+ --- SECURITY ODYSSEY COMPLETE ---
173
+ Target: {target}
174
+ Tier: {tier}
175
+ Phases: {completed}/{total} ({skipped} skipped)
176
+ Findings: {critical}C / {high}H / {medium}M / {low}L
177
+ Categories: {owasp_hits} OWASP / {dep_vulns} dependency / {secrets} secrets
178
+ Patterns: {count} ({by_layer})
179
+ Scan hits: {total} ({cross_layer_confirmed} confirmed)
180
+ Issues: {N} created
181
+ Decisions: {N} resolved, {M} pending, {K} deferred
182
+ Learnings: {N} persisted
183
+ Self-iter: {N} rounds across {M} stages
184
+ Cross-loops: {N}
185
+ Goals: {done}/{total} ({skipped} skipped)
186
+ ---
187
+ ```
188
+
189
+ ---
190
+
191
+ ## Mode `-y` Points
192
+
193
+ | Decision Point | Normal | `-y` |
194
+ |---------------|--------|------|
195
+ | A_SCAN false positive dismissal | request_user_input | Dismiss only with recorded counter-evidence. Keep unresolved candidates as deferred. |
196
+ | A_REPORT severity downgrade | request_user_input | Downgrade only with documented counter-evidence. Keep the current severity when the decision is deferred. |
197
+ | A_DISCOVER routing | request_user_input | Record a deferred discovery with evidence. Route issue creation through an explicit follow-up. |
198
+ | Ambiguous items | request_user_input | all `deferred` |
199
+
200
+ ---
201
+
202
+ ## Phase Gates
203
+
204
+ - **Recon gate** (S_RECON): tech stack + entry points + auth modules + data flow mapped. Evidence logged, understanding.md §2 updated.
205
+ - **Scan gate** (S_SCAN): all tier-required phases completed. Per-phase evidence logged. Findings merged with severity classification. Tier-required phase missing is BLOCKED (W001/W002 partial allowed).
206
+ - **Report gate** (S_REPORT): severity matrix produced with file:line + remediation. Summary statistics. §5 written. Read-only invariant verified (no source modifications in session).
207
+
208
+ ---
209
+
210
+ ## Error Codes
211
+
212
+ | Code | Severity | Condition | Recovery |
213
+ |------|----------|-----------|----------|
214
+ | E001 | error | No target / scope provided | Provide target or -c |
215
+ | E002 | error | No source files found in scope / no entry points | Verify --scope path exists |
216
+ | W001 | warning | Dependency audit tool unavailable (npm audit etc.) | Skip dependency phase, note limitation |
217
+ | W002 | warning | Git history scan failed | Skip git history phase, note limitation |
218
+ | W003 | warning | Partial scan (some files inaccessible) | Report coverage gap in findings |
219
+ | W004 | warning | Generalization 0 hits after full 3-layer scan | Advance to S_RECORD |
220
+ | W005 | warning | Pending decisions | Filter evidence phase=decision |
221
+
222
+ ---
223
+
224
+ ## Success Criteria
225
+
226
+ - [ ] Target resolved; tier determined; session + output files created
227
+ - [ ] Recon completed: tech stack, entry points, auth modules, data flow mapped
228
+ - [ ] All tier-required scan phases completed (OWASP, dependencies, secrets, CI/CD, STRIDE, git history per tier)
229
+ - [ ] understanding.md sections written progressively (§1–§7)
230
+ - [ ] Severity matrix produced with file:line references and remediation for every finding
231
+ - [ ] Read-only invariant maintained — zero source code modifications
232
+ - [ ] Multi-layer generalization + discovery triage (unless --skip-generalize)
233
+ - [ ] phase_goals derived, tracked, and hardened-audited; goal_mode injected via prepare goal:true
234
+ - [ ] Session resumable via -c; completion summary emitted
235
+
236
+ ---
237
+
238
+ ## Next Step Routing
239
+
240
+ | Condition | Next |
241
+ |-----------|------|
242
+ | Critical findings need fix | `/ew-odyssey <finding> --mode improve` |
243
+ | Deeper debug needed | `/ew-odyssey <finding> --mode debug` |
244
+ | Discovery issues created | `Open the follow-up findings in the project issue tracker` |
245
+ | Need deeper audit tier | `/ew-odyssey <target> --mode security --tier deep` |
246
+ | Document pattern | `Review the module and stage the reusable method via Agent Memory closeout` |
247
+ | Second opinion | `evolve delegate "<review prompt>" --mode analysis` |
248
+ | Security pattern to persist | `stage spec → debug` |
249
+ | Pending decisions | Filter evidence phase=decision status=pending |