ahead-pi 0.2.1 → 0.3.1

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 (101) hide show
  1. package/README.md +26 -41
  2. package/dist/ahead_wasm.wasm +0 -0
  3. package/generated/corrective-debugging/ai-audit.md +39 -0
  4. package/generated/corrective-debugging/ai-review.md +46 -0
  5. package/generated/corrective-debugging/characterize.md +53 -0
  6. package/generated/corrective-debugging/conclude.md +59 -0
  7. package/generated/corrective-debugging/correction.md +53 -0
  8. package/generated/corrective-debugging/deploy.md +38 -0
  9. package/generated/corrective-debugging/human-review.md +45 -0
  10. package/generated/corrective-debugging/implement.md +42 -0
  11. package/generated/corrective-debugging/investigate.md +59 -0
  12. package/generated/corrective-debugging/manifest.json +30 -0
  13. package/generated/corrective-debugging/model.md +53 -0
  14. package/generated/corrective-debugging/outcome.md +38 -0
  15. package/generated/corrective-debugging/plan.md +53 -0
  16. package/generated/corrective-debugging/verify.md +47 -0
  17. package/generated/decision/compare.md +45 -0
  18. package/generated/decision/criteria.md +45 -0
  19. package/generated/decision/decide.md +45 -0
  20. package/generated/decision/frame.md +45 -0
  21. package/generated/decision/manifest.json +21 -0
  22. package/generated/decision/options.md +47 -0
  23. package/generated/decision/publish.md +38 -0
  24. package/generated/decision/research.md +45 -0
  25. package/generated/internal-improvement/ai-audit.md +39 -0
  26. package/generated/internal-improvement/ai-review.md +46 -0
  27. package/generated/internal-improvement/baseline.md +46 -0
  28. package/generated/internal-improvement/decision.md +45 -0
  29. package/generated/internal-improvement/deploy.md +38 -0
  30. package/generated/internal-improvement/human-review.md +45 -0
  31. package/generated/internal-improvement/implement.md +42 -0
  32. package/generated/internal-improvement/invariants.md +38 -0
  33. package/generated/internal-improvement/manifest.json +29 -0
  34. package/generated/internal-improvement/options.md +47 -0
  35. package/generated/internal-improvement/outcome.md +38 -0
  36. package/generated/internal-improvement/plan.md +53 -0
  37. package/generated/internal-improvement/target.md +45 -0
  38. package/generated/internal-improvement/verify.md +45 -0
  39. package/generated/investigation/bound.md +45 -0
  40. package/generated/investigation/conclude.md +45 -0
  41. package/generated/investigation/explore.md +60 -0
  42. package/generated/investigation/frame.md +45 -0
  43. package/generated/investigation/gather.md +45 -0
  44. package/generated/investigation/manifest.json +21 -0
  45. package/generated/investigation/synthesize.md +51 -0
  46. package/generated/operational-stabilization/assess.md +46 -0
  47. package/generated/operational-stabilization/execute-observe.md +45 -0
  48. package/generated/operational-stabilization/manifest.json +19 -0
  49. package/generated/operational-stabilization/monitor.md +45 -0
  50. package/generated/operational-stabilization/outcome.md +38 -0
  51. package/generated/operational-stabilization/respond.md +40 -0
  52. package/generated/operational-stabilization/verify-recovery.md +45 -0
  53. package/generated/product-change/ai-audit.md +7 -4
  54. package/generated/product-change/ai-review.md +15 -5
  55. package/generated/product-change/decision.md +11 -2
  56. package/generated/product-change/define.md +4 -2
  57. package/generated/product-change/deploy.md +4 -2
  58. package/generated/product-change/human-review.md +11 -2
  59. package/generated/product-change/implement.md +4 -2
  60. package/generated/product-change/manifest.json +8 -3
  61. package/generated/product-change/options.md +11 -2
  62. package/generated/product-change/outcome.md +4 -2
  63. package/generated/product-change/plan.md +17 -2
  64. package/generated/product-change/questions.md +17 -2
  65. package/generated/product-change/research.md +11 -2
  66. package/generated/product-change/verify.md +4 -2
  67. package/generated/recommended-skills.json +24 -0
  68. package/generated/reference/CONSTITUTION.md +2 -0
  69. package/generated/reference/docs/evidence/README.md +17 -0
  70. package/generated/reference/docs/evidence/evidence-standard.md +2 -0
  71. package/generated/reference/docs/evidence/research-map.md +2 -0
  72. package/generated/reference/docs/{references → evidence/sources}/pragmatic-programmer-page-index.md +3 -1
  73. package/generated/reference/docs/{references → evidence/sources}/submitted-engineering-notes.md +3 -1
  74. package/generated/reference/docs/guide/README.md +28 -0
  75. package/generated/reference/docs/{acceptable-ai-use.md → guide/acceptable-ai-use.md} +4 -2
  76. package/generated/reference/docs/{engineering-practice.md → guide/engineering-practice.md} +5 -3
  77. package/generated/reference/docs/{rationale.md → guide/rationale.md} +3 -1
  78. package/generated/reference/docs/guide/recommended-skills.md +21 -0
  79. package/generated/reference/docs/{workflows → guide/workflows}/README.md +6 -4
  80. package/generated/reference/docs/{workflows → guide/workflows}/corrective-debugging.md +39 -19
  81. package/generated/reference/docs/{workflows → guide/workflows}/decision.md +4 -2
  82. package/generated/reference/docs/{workflows → guide/workflows}/internal-improvement.md +37 -23
  83. package/generated/reference/docs/{workflows → guide/workflows}/investigation.md +5 -1
  84. package/generated/reference/docs/{workflows → guide/workflows}/operational-stabilization.md +16 -12
  85. package/generated/reference/docs/{workflows → guide/workflows}/product-change.md +16 -3
  86. package/generated/reference/index.json +200 -87
  87. package/package.json +34 -25
  88. package/src/engine.ts +27 -8
  89. package/src/flow-guides.ts +168 -0
  90. package/src/guidance.ts +220 -78
  91. package/src/index.ts +852 -189
  92. package/src/reference-viewer.ts +20 -18
  93. package/src/reference.ts +76 -14
  94. package/src/review.ts +360 -0
  95. package/src/skills.ts +133 -0
  96. package/src/storage.ts +139 -15
  97. package/src/types.ts +1 -0
  98. package/generated/reference/docs/design/debugging-and-operations.md +0 -119
  99. package/generated/reference/docs/design/executable-workflows.md +0 -110
  100. package/generated/reference/docs/design/process-taxonomy.md +0 -144
  101. package/generated/reference/docs/releasing-pi.md +0 -89
@@ -0,0 +1,168 @@
1
+ import type { PhaseGuide } from "./guidance.js";
2
+
3
+ function guide(objective: string, human: string, ai: string): PhaseGuide {
4
+ return { objective, human, ai, artifactPrompts: {} };
5
+ }
6
+
7
+ export const flowGuides: Record<string, PhaseGuide> = {
8
+ "corrective-debugging:characterize": guide(
9
+ "Describe the failure precisely before explaining it.",
10
+ "Record observed and expected behavior, reproduction, timing, location, scope, and important non-occurrences.",
11
+ "After the human account exists, clarify observations and missing discriminators without inventing a cause.",
12
+ ),
13
+ "corrective-debugging:model": guide(
14
+ "Make the human's current causal model explicit and falsifiable.",
15
+ "Explain what you currently think is happening, why, and what that explanation predicts.",
16
+ "After the human model exists, challenge assumptions and surface alternatives without selecting the diagnosis.",
17
+ ),
18
+ "corrective-debugging:investigate": guide(
19
+ "Use discriminating evidence and tests to update competing hypotheses.",
20
+ "Choose what to inspect or test, interpret the results, and maintain epistemic discipline.",
21
+ "Inspect authorized code, logs, history, dependencies, and runtime data; propose hypotheses and bounded tests while separating fact from inference.",
22
+ ),
23
+ "corrective-debugging:conclude": guide(
24
+ "Reach a supported diagnosis or explicitly accept that the cause remains unknown.",
25
+ "Judge the evidence, confidence, uncertainty, and risk, then own the diagnostic conclusion.",
26
+ "Test the conclusion against the ledger and expose counterevidence; do not manufacture certainty or decide for the human.",
27
+ ),
28
+ "corrective-debugging:correction": guide(
29
+ "Select a correction that follows from the accepted diagnosis and can be verified.",
30
+ "Choose the approach and own its risk, blast radius, reversibility, and verification strategy.",
31
+ "Compare likely effectiveness, regressions, observability, and alternatives without choosing the correction.",
32
+ ),
33
+ "corrective-debugging:verify": guide(
34
+ "Demonstrate that the original characterized failure is resolved without unacceptable regression.",
35
+ "Repeat the original reproduction and choose adequate regression and runtime checks.",
36
+ "Help analyze tests and observations while keeping code, deployment, and observed behavior separate.",
37
+ ),
38
+ "operational-stabilization:assess": guide(
39
+ "Establish impact, recovery signals, and accountable response mode.",
40
+ "Assess the situation and explicitly set ownership, communication, authority boundaries, and stop conditions.",
41
+ "Organize evidence and clarify scope after the human assessment begins; do not declare response mode or assume command.",
42
+ ),
43
+ "operational-stabilization:respond": guide(
44
+ "Investigate and select the next bounded stabilizing action without waiting for proven root cause.",
45
+ "Maintain the system model and choose an intervention with actor, scope, rollback, expected signals, uncertainty, and stop conditions.",
46
+ "Investigate in parallel, challenge the intervention, and surface risk; never authorize or execute it.",
47
+ ),
48
+ "operational-stabilization:execute-observe": guide(
49
+ "Execute only the authorized intervention and capture its immediate effects.",
50
+ "Ensure an authorized actor performs the action, observes it, and makes stop or rollback decisions.",
51
+ "Interpret observations only. AI has no workflow authority to execute the intervention or write the action record.",
52
+ ),
53
+ "operational-stabilization:verify-recovery": guide(
54
+ "Demonstrate end-to-end recovery or return for another bounded action.",
55
+ "Compare real system and user-visible behavior with the recorded recovery signals and judge residual risk.",
56
+ "Suggest and analyze authorized checks without treating component health as sufficient proof or requiring root cause.",
57
+ ),
58
+ "operational-stabilization:monitor": guide(
59
+ "Observe long enough to detect recurrence or delayed degradation.",
60
+ "Select the observation window and decide whether the system is stable enough to leave response mode.",
61
+ "Inspect authorized signals and surface recurrence or delayed effects; do not shorten the window or declare stability.",
62
+ ),
63
+ "operational-stabilization:outcome": guide(
64
+ "Close response mode with residual risk, causal uncertainty, and follow-up ownership explicit.",
65
+ "Own closure and route debugging, investigation, product, or improvement follow-up as needed.",
66
+ "Summarize and challenge the evidence without treating stabilization as proof of root cause or accepting closure.",
67
+ ),
68
+ "decision:frame": guide(
69
+ "State the exact decision and who is accountable for it.",
70
+ "Define the choice, purpose, owner, stakeholders, scope, deadline, and reversibility.",
71
+ "Expose ambiguity and assumptions after the human framing; do not redefine the decision.",
72
+ ),
73
+ "decision:criteria": guide(
74
+ "Agree on priorities, constraints, and acceptable uncertainty before comparing options.",
75
+ "Set the values, constraints, evidence standard, and uncertainty that will govern the choice.",
76
+ "Test criteria for conflict, invisibility, or omission without steering them toward a preferred answer.",
77
+ ),
78
+ "decision:research": guide(
79
+ "Gather the material evidence needed for this decision.",
80
+ "Set the boundary, judge relevance, and decide whether evidence gaps can be accepted.",
81
+ "Research authorized sources with provenance, contradictions, assumptions, and explicit gaps.",
82
+ ),
83
+ "decision:options": guide(
84
+ "Develop genuinely viable alternatives before comparison.",
85
+ "Offer the first options, then evaluate AI challenges and own the viable set.",
86
+ "Only after the human first pass, challenge assumptions and surface missing alternatives without steering the choice.",
87
+ ),
88
+ "decision:compare": guide(
89
+ "Compare options against the recorded criteria without hiding tradeoffs.",
90
+ "Make and own the comparison, including risk, confidence, sensitivity, and disagreement.",
91
+ "Check consistency and expose hidden tradeoffs after the human comparison; do not replace it with a synthetic answer.",
92
+ ),
93
+ "decision:decide": guide(
94
+ "Make an accountable, explainable, and revisitable choice.",
95
+ "Choose and record rationale, tradeoffs, dissent, unknowns, confidence, and reversibility.",
96
+ "Challenge whether the choice follows from the evidence, but never make or approve it.",
97
+ ),
98
+ "decision:publish": guide(
99
+ "Make the decision durable, understandable, and connected to downstream work.",
100
+ "Record and communicate the decision, affected work, review trigger, and revisit date.",
101
+ "Improve clarity and traceability without communicating externally or closing work without authorization.",
102
+ ),
103
+ "investigation:frame": guide(
104
+ "Define a question that can be answered or responsibly left unresolved.",
105
+ "State the question, motivation, owner, intended use, and what would count as an answer.",
106
+ "Clarify testability after the human framing without turning the question into a decision or implementation task.",
107
+ ),
108
+ "investigation:bound": guide(
109
+ "Constrain the search with an evidence standard and stop conditions.",
110
+ "Set scope, non-goals, time or cost box, risks, and stopping rules.",
111
+ "Expose unbounded searches or unreachable standards without expanding the authorized purpose.",
112
+ ),
113
+ "investigation:gather": guide(
114
+ "Collect relevant evidence with provenance and visible gaps.",
115
+ "Judge source relevance and decide when enough evidence exists to explore explanations.",
116
+ "Gather authorized sources, observations, and measurements; separate facts, inference, contradiction, and uncertainty.",
117
+ ),
118
+ "investigation:explore": guide(
119
+ "Test competing explanations and learn cheaply within the investigation bounds.",
120
+ "Supply the first model or path, select tests, interpret results, and dispose of any prototype.",
121
+ "After the human first pass, challenge it and propose tests or disposable prototypes while keeping production code out of scope.",
122
+ ),
123
+ "investigation:synthesize": guide(
124
+ "Turn the evidence into a traceable account of what is known and unknown.",
125
+ "Synthesize findings, evidence strength, contradictions, limitations, and confidence.",
126
+ "Check completeness and traceability without overstating convergence or writing the human conclusion.",
127
+ ),
128
+ "investigation:conclude": guide(
129
+ "Record an answer or defensible non-answer and route consequential choice explicitly.",
130
+ "Own the conclusion, confidence, unresolved questions, reusable evidence, and any route to Decision.",
131
+ "Summarize and challenge the conclusion without deciding, implementing, or accepting closure.",
132
+ ),
133
+ "internal-improvement:invariants": guide(
134
+ "Protect behavior that must not regress before optimizing anything.",
135
+ "Define testable behavior, compatibility, safety, operability, and other invariants.",
136
+ "Help make invariants observable without trading them away for a metric.",
137
+ ),
138
+ "internal-improvement:baseline": guide(
139
+ "Establish a reproducible current measurement before choosing a change.",
140
+ "Own the method, sample, uncertainty, reproducibility, and accepted baseline.",
141
+ "After the baseline exists, challenge noise, confounders, sampling, and observer effects.",
142
+ ),
143
+ "internal-improvement:target": guide(
144
+ "Set a measurable improvement target with guardrails and stop conditions.",
145
+ "Choose the desired change, threshold, scope, guardrails, and acceptable tradeoffs.",
146
+ "Test for gaming, shifted cost, and proxy failure without choosing the target.",
147
+ ),
148
+ "internal-improvement:options": guide(
149
+ "Develop alternatives that can improve the target while preserving invariants.",
150
+ "Provide the first approach, then evaluate alternatives and own the final option set.",
151
+ "After the human first pass, challenge assumptions, alternatives, maintenance cost, and measurement risk.",
152
+ ),
153
+ "internal-improvement:decision": guide(
154
+ "Choose an improvement approach that follows from the baseline, target, and invariants.",
155
+ "Own the selected option, rationale, tradeoffs, risks, confidence, and reversibility.",
156
+ "Check the relationship to the evidence and guardrails without choosing or approving the approach.",
157
+ ),
158
+ "internal-improvement:verify": guide(
159
+ "Show that invariants hold and the measured improvement is real enough to adopt.",
160
+ "Repeat comparable measurements, assess noise and regressions, and judge the result.",
161
+ "Analyze before-and-after evidence without cherry-picking a favorable number or declaring success.",
162
+ ),
163
+ "internal-improvement:outcome": guide(
164
+ "Decide whether to adopt, roll back, accept a tradeoff, or continue learning.",
165
+ "Own the outcome, measurement uncertainty, follow-up, and learning.",
166
+ "Challenge unsupported success claims and organize evidence without accepting closure.",
167
+ ),
168
+ };
package/src/guidance.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { ArtifactState, Run, RunState, WorkflowDefinition } from "./types.js";
2
+ import { flowGuides } from "./flow-guides.ts";
2
3
 
3
4
  export interface PhaseGuide {
4
5
  objective: string;
@@ -11,7 +12,8 @@ export interface PhaseGuide {
11
12
  const guides: Record<string, PhaseGuide> = {
12
13
  define: {
13
14
  objective: "Agree on the problem and the observable outcome before solution work begins.",
14
- human: "Describe the users, current problem, desired outcome, scope, constraints, and success signals.",
15
+ human:
16
+ "Describe the users, current problem, desired outcome, scope, constraints, and success signals.",
15
17
  ai: "Explain the prompts. After your first statement, clarify ambiguity and expose assumptions without redefining the problem.",
16
18
  artifactPrompts: {
17
19
  problem: [
@@ -25,7 +27,8 @@ const guides: Record<string, PhaseGuide> = {
25
27
  },
26
28
  research: {
27
29
  objective: "Build enough evidence to understand the problem before choosing a solution.",
28
- human: "Set the research boundary, judge source relevance, and identify what evidence is material.",
30
+ human:
31
+ "Set the research boundary, judge source relevance, and identify what evidence is material.",
29
32
  ai: "Inspect authorized sources, organize evidence, surface contradictions, and state confidence and gaps.",
30
33
  artifactPrompts: {
31
34
  research: [
@@ -38,7 +41,8 @@ const guides: Record<string, PhaseGuide> = {
38
41
  },
39
42
  questions: {
40
43
  objective: "Dispose the unknowns that could materially change the decision or plan.",
41
- human: "Decide which unknowns must be answered and which uncertainty can be accepted explicitly.",
44
+ human:
45
+ "Decide which unknowns must be answered and which uncertainty can be accepted explicitly.",
42
46
  ai: "Challenge gaps, perform authorized follow-up research, and distinguish evidence from inference.",
43
47
  artifactPrompts: {
44
48
  unknowns: [
@@ -54,7 +58,8 @@ const guides: Record<string, PhaseGuide> = {
54
58
  },
55
59
  options: {
56
60
  objective: "Understand viable approaches and tradeoffs before committing to one.",
57
- human: "Produce the first option, then evaluate alternatives and tradeoffs in the system's real context.",
61
+ human:
62
+ "Produce the first option, then evaluate alternatives and tradeoffs in the system's real context.",
58
63
  ai: "After the human first pass, challenge assumptions and add materially different alternatives.",
59
64
  artifactPrompts: {
60
65
  "human-option": [
@@ -75,7 +80,8 @@ const guides: Record<string, PhaseGuide> = {
75
80
  },
76
81
  decision: {
77
82
  objective: "Make an accountable and explainable choice.",
78
- human: "Choose the approach and own its rationale, tradeoffs, remaining uncertainty, and reversibility.",
83
+ human:
84
+ "Choose the approach and own its rationale, tradeoffs, remaining uncertainty, and reversibility.",
79
85
  ai: "Test the recorded decision for contradictions, weak evidence, and hidden consequences.",
80
86
  artifactPrompts: {
81
87
  decision: [
@@ -88,7 +94,8 @@ const guides: Record<string, PhaseGuide> = {
88
94
  },
89
95
  plan: {
90
96
  objective: "Create an implementable plan with verification, rollout, and recovery.",
91
- human: "Write the first-pass sequence and approve the final plan after challenges are resolved.",
97
+ human:
98
+ "Write the first-pass sequence and approve the final plan after challenges are resolved.",
92
99
  ai: "After the human first pass, identify missing dependencies, tests, edge cases, rollout evidence, recovery, and decision points.",
93
100
  artifactPrompts: {
94
101
  "first-pass-plan": [
@@ -110,7 +117,8 @@ const guides: Record<string, PhaseGuide> = {
110
117
  },
111
118
  implement: {
112
119
  objective: "Produce a change the engineer understands and can defend.",
113
- human: "Make the first attempt, ask questions freely, own the implementation, understand every lasting change, run the planned checks, and record deviations.",
120
+ human:
121
+ "Make the first attempt, ask questions freely, own the implementation, understand every lasting change, run the planned checks, and record deviations.",
114
122
  ai: "Coach, explain, help diagnose, and suggest bounded next steps within the approved plan. Do not turn a question into taking over the implementation.",
115
123
  artifactPrompts: {
116
124
  changeset: [
@@ -130,20 +138,26 @@ const guides: Record<string, PhaseGuide> = {
130
138
  },
131
139
  "ai-review": {
132
140
  objective: "Add an AI review of the exact current changeset before independent human review.",
133
- human: "Validate and dispose every material finding. Return to implementation when a change is required.",
141
+ human:
142
+ "Validate and dispose every material finding. Return to implementation when a change is required.",
134
143
  ai: "Review without modifying: correctness, security, tests, architecture, plan compliance, operations, and maintainability.",
135
144
  artifactPrompts: {
136
145
  "ai-review": [
137
- "What exact commit or diff was reviewed?",
138
- "What findings were identified, with evidence and severity?",
139
- "What disposition is proposed for each finding?",
146
+ "What exact AHEAD review snapshot was reviewed?",
147
+ "What stable AR findings were identified, with severity, category, location, evidence, impact, and a falsifiable explanation?",
140
148
  "What could not be assessed?",
141
149
  ],
150
+ "review-disposition": [
151
+ "Does the snapshot still match the AI review?",
152
+ "For every material AR finding, is it fixed, invalid, accepted risk, or follow-up?",
153
+ "What human rationale and evidence support each disposition?",
154
+ ],
142
155
  },
143
156
  },
144
157
  "human-review": {
145
158
  objective: "Obtain independent final engineering judgment on the current change.",
146
- human: "A reviewer other than the implementer examines the exact change and material evidence, then accepts or returns it.",
159
+ human:
160
+ "A reviewer other than the implementer examines the exact change and material evidence, then accepts or returns it.",
147
161
  ai: "Retrieve evidence and answer targeted questions. It cannot approve the change or replace reviewer judgment.",
148
162
  handoff: "READY FOR INDEPENDENT HUMAN REVIEW",
149
163
  artifactPrompts: {
@@ -157,7 +171,8 @@ const guides: Record<string, PhaseGuide> = {
157
171
  },
158
172
  deploy: {
159
173
  objective: "Authorize and record deployment or explicitly establish that it is not applicable.",
160
- human: "Own the release decision and production risk. Record the exact version, target, actor, time, authorization, and result.",
174
+ human:
175
+ "Own the release decision and production risk. Record the exact version, target, actor, time, authorization, and result.",
161
176
  ai: "Analyze readiness evidence. It cannot authorize deployment or claim a version is live.",
162
177
  artifactPrompts: {
163
178
  deployment: [
@@ -169,8 +184,10 @@ const guides: Record<string, PhaseGuide> = {
169
184
  },
170
185
  },
171
186
  verify: {
172
- objective: "Demonstrate the intended outcome using observed evidence, not just test or deployment status.",
173
- human: "Select adequate checks and decide whether the original success signals are demonstrated.",
187
+ objective:
188
+ "Demonstrate the intended outcome using observed evidence, not just test or deployment status.",
189
+ human:
190
+ "Select adequate checks and decide whether the original success signals are demonstrated.",
174
191
  ai: "Suggest checks and analyze authorized observations while separating code, deployment, and observed behavior.",
175
192
  artifactPrompts: {
176
193
  verification: [
@@ -182,7 +199,8 @@ const guides: Record<string, PhaseGuide> = {
182
199
  },
183
200
  },
184
201
  "ai-audit": {
185
- objective: "Compare the result with the original intent and expose weak evidence or divergence.",
202
+ objective:
203
+ "Compare the result with the original intent and expose weak evidence or divergence.",
186
204
  human: "Review and dispose material audit findings; reopen work when the evidence demands it.",
187
205
  ai: "Audit the full chain from problem through observed outcome without changing or approving the work.",
188
206
  artifactPrompts: {
@@ -191,11 +209,17 @@ const guides: Record<string, PhaseGuide> = {
191
209
  "Which claims have weak or missing evidence?",
192
210
  "Which findings require follow-up or reopening?",
193
211
  ],
212
+ "audit-disposition": [
213
+ "Which audit findings are accepted, rejected, resolved, or routed to follow-up?",
214
+ "What human rationale and evidence support each disposition?",
215
+ "Does any finding require reopening an earlier phase rather than closing the work?",
216
+ ],
194
217
  },
195
218
  },
196
219
  outcome: {
197
220
  objective: "Make the accountable outcome decision and preserve learning.",
198
- human: "Accept, roll back, follow up, abandon, or reopen the work, including remaining uncertainty.",
221
+ human:
222
+ "Accept, roll back, follow up, abandon, or reopen the work, including remaining uncertainty.",
199
223
  ai: "Organize evidence and summarize learning. It cannot choose or accept the outcome.",
200
224
  artifactPrompts: {
201
225
  outcome: [
@@ -215,18 +239,137 @@ const fallbackGuide: PhaseGuide = {
215
239
  artifactPrompts: {},
216
240
  };
217
241
 
218
- export function phaseGuide(phaseId: string): PhaseGuide {
219
- return guides[phaseId] ?? fallbackGuide;
242
+ const artifactPromptCatalog: Record<string, string[]> = {
243
+ "failure-characterization": [
244
+ "What was observed, and what was expected instead?",
245
+ "How can it be reproduced, and when, where, or for whom does it occur?",
246
+ "What does not fail, and what does that boundary rule out?",
247
+ ],
248
+ "human-model": [
249
+ "What do you currently believe is happening, and why?",
250
+ "What predictions would distinguish this model from alternatives?",
251
+ "Which parts are observed facts, inferences, or assumptions?",
252
+ ],
253
+ "investigation-ledger": [
254
+ "Which facts, inferences, hypotheses, and confidence levels are current?",
255
+ "What did each hypothesis predict, what was tested, and what happened?",
256
+ "What evidence supports or contradicts each live explanation?",
257
+ ],
258
+ diagnosis: [
259
+ "What diagnosis is supported, or why does the cause remain unknown?",
260
+ "Which evidence and counterevidence determine the confidence?",
261
+ "What risk and uncertainty remain if work proceeds?",
262
+ ],
263
+ correction: [
264
+ "What correction is selected, and how does it follow from the diagnosis?",
265
+ "What blast radius, regressions, and reversibility matter?",
266
+ "How will the original failure and side effects be verified?",
267
+ ],
268
+ assessment: [
269
+ "What symptoms, impact, scope, urgency, and known facts define the situation?",
270
+ "Which signals would demonstrate recovery or worsening?",
271
+ ],
272
+ "response-mode": [
273
+ "Who owns the response and communication?",
274
+ "What authority boundaries, escalation path, and stop conditions apply?",
275
+ ],
276
+ "system-model": [
277
+ "What is the human's current model of the system and failure mode?",
278
+ "What is known, inferred, and still uncertain?",
279
+ ],
280
+ intervention: [
281
+ "What bounded action is proposed, who may execute it, and what is its scope?",
282
+ "What are the blast radius, rollback, expected signals, uncertainty, and stop conditions?",
283
+ ],
284
+ "action-record": [
285
+ "What authorized action actually occurred, who performed it, and when?",
286
+ "What immediate effects, stop decisions, and rollback status were observed?",
287
+ ],
288
+ "recovery-evidence": [
289
+ "Which system and user-visible recovery signals were checked?",
290
+ "What regressions, residual risk, and uncertainty remain?",
291
+ ],
292
+ monitoring: [
293
+ "What observation window and signals were selected?",
294
+ "Was there recurrence or delayed degradation, and what residual risk remains?",
295
+ ],
296
+ "decision-frame": [
297
+ "What exact choice must be made, by whom, and for whom?",
298
+ "What are its scope, deadline, consequences, and reversibility?",
299
+ ],
300
+ criteria: [
301
+ "Which priorities and constraints govern the choice?",
302
+ "What evidence standard and remaining uncertainty are acceptable?",
303
+ ],
304
+ comparison: [
305
+ "How does each option perform against the recorded criteria?",
306
+ "What tradeoffs, risks, sensitivity, confidence, and disagreement remain?",
307
+ ],
308
+ "published-decision": [
309
+ "Where is the durable decision and rationale recorded?",
310
+ "Who is affected, what downstream work is linked, and how will it be communicated?",
311
+ "What event or date should trigger review?",
312
+ ],
313
+ question: [
314
+ "What exact question is being investigated, and why does it matter?",
315
+ "Who owns it, how will findings be used, and what would count as an answer?",
316
+ ],
317
+ bounds: [
318
+ "What is in scope and explicitly out of scope?",
319
+ "What evidence standard, time or cost box, risks, and stop conditions apply?",
320
+ ],
321
+ evidence: [
322
+ "Which sources, observations, or measurements were gathered, with what provenance?",
323
+ "What is supported, contradicted, uncertain, or still missing?",
324
+ ],
325
+ "exploration-ledger": [
326
+ "Which models or paths were considered and what did each predict?",
327
+ "Which tests or prototypes ran, what happened, and how did confidence change?",
328
+ ],
329
+ "prototype-disposition": [
330
+ "What disposable prototype was created and what was learned, or was no prototype used?",
331
+ "How was the prototype isolated, retained, or discarded so it cannot silently become production code?",
332
+ ],
333
+ synthesis: [
334
+ "What findings follow from the evidence?",
335
+ "What contradictions, limitations, uncertainty, and confidence remain?",
336
+ ],
337
+ conclusion: [
338
+ "What answer or defensible non-answer follows from the investigation?",
339
+ "What remains unresolved, what evidence is reusable, and does consequential choice route to Decision?",
340
+ ],
341
+ invariants: [
342
+ "Which behavior, compatibility, safety, and operability properties must not regress?",
343
+ "How will each invariant be observed or tested?",
344
+ ],
345
+ baseline: [
346
+ "What is the current measurement and exact method?",
347
+ "What sample, noise, confounders, uncertainty, and reproducibility limitations apply?",
348
+ ],
349
+ target: [
350
+ "What measurable improvement and threshold are desired?",
351
+ "What guardrails, scope, acceptable tradeoffs, and stop conditions apply?",
352
+ ],
353
+ };
354
+
355
+ export function phaseGuide(workflowId: string, phaseId: string): PhaseGuide {
356
+ return flowGuides[`${workflowId}:${phaseId}`] ?? guides[phaseId] ?? fallbackGuide;
220
357
  }
221
358
 
222
- export function promptsForArtifact(phaseId: string, kind: string): string[] {
223
- return phaseGuide(phaseId).artifactPrompts[kind] ?? [
224
- "What must another engineer understand from this record?",
225
- "What evidence, uncertainty, and rationale should remain durable?",
226
- ];
359
+ export function promptsForArtifact(workflowId: string, phaseId: string, kind: string): string[] {
360
+ return (
361
+ phaseGuide(workflowId, phaseId).artifactPrompts[kind] ??
362
+ artifactPromptCatalog[kind] ?? [
363
+ "What must another engineer understand from this record?",
364
+ "What evidence, uncertainty, and rationale should remain durable?",
365
+ ]
366
+ );
227
367
  }
228
368
 
229
- export function phasePosition(state: RunState, workflow: WorkflowDefinition): { current: number; total: number } {
369
+ export function phasePosition(
370
+ state: RunState,
371
+ workflow: WorkflowDefinition,
372
+ ): { current: number; total: number } {
230
373
  const index = workflow.phases.findIndex((phase) => phase.id === state.phase.id);
231
374
  return { current: index < 0 ? 0 : index + 1, total: workflow.phases.length };
232
375
  }
@@ -239,68 +382,71 @@ export interface GuidedNextAction {
239
382
  }
240
383
 
241
384
  export function nextAction(state: RunState, workflow: WorkflowDefinition): GuidedNextAction {
242
- if (state.closed) return { actor: "human", label: "Work complete; start another run only for new work" };
243
-
244
- const orderedAssist = optionalAssistBeforeFinalHumanRecord(state);
245
- if (orderedAssist) return orderedAssist;
385
+ if (state.closed) {
386
+ return { actor: "human", label: "Work complete; start another run only for new work" };
387
+ }
246
388
 
247
- const artifact = state.artifacts.find((candidate) => candidate.required && !candidate.present);
389
+ const artifact = nextPendingArtifact(state);
248
390
  if (artifact) {
249
- const actor = artifact.actor === "human"
250
- ? "human"
251
- : artifact.actor === "ai" || state.phase.id === "research"
252
- ? "ai"
253
- : "human";
391
+ const actor =
392
+ artifact.actor === "human"
393
+ ? "human"
394
+ : artifact.actor === "ai" || state.allowed_ai_capabilities.includes("record")
395
+ ? "ai"
396
+ : "human";
254
397
  if (actor === "human") {
255
- const label = state.phase.id === "implement" && artifact.kind === "changeset"
256
- ? "Implement first, then record the exact changeset"
257
- : state.phase.id === "human-review"
258
- ? "Independent reviewer records the current human review"
259
- : `Write ${artifact.title}`;
398
+ const label =
399
+ state.phase.id === "implement" && artifact.kind === "changeset"
400
+ ? "Implement first, then record the exact changeset"
401
+ : state.phase.id === "human-review"
402
+ ? "Independent reviewer records the current human review"
403
+ : `Write ${artifact.title}`;
260
404
  return { actor, label, artifactKind: artifact.kind };
261
405
  }
262
406
 
263
- const label = state.phase.id === "ai-review"
264
- ? "Run AI review of the exact current changeset"
265
- : state.phase.id === "ai-audit"
266
- ? "Run AI audit across intent, evidence, and outcome"
267
- : `Ask AI to produce ${artifact.title}`;
268
- return { actor, label, artifactKind: artifact.kind };
407
+ const label = artifact.required
408
+ ? state.phase.id === "ai-review"
409
+ ? "Run AI review of the exact current changeset"
410
+ : state.phase.id === "ai-audit"
411
+ ? "Run AI audit across intent, evidence, and outcome"
412
+ : `Ask AI to produce ${artifact.title}`
413
+ : state.phase.id === "options"
414
+ ? "Ask AI to challenge the human option and expand alternatives"
415
+ : state.phase.id === "plan"
416
+ ? "Ask AI to challenge the human first-pass plan"
417
+ : `Ask AI to contribute ${artifact.title}`;
418
+ return artifact.required
419
+ ? { actor, label, artifactKind: artifact.kind }
420
+ : { actor, label, artifactKind: artifact.kind, optional: true };
269
421
  }
270
422
 
271
- if (!state.gate.accepted) return { actor: "human", label: `Review evidence and accept: ${state.gate.title}` };
423
+ if (!state.gate.accepted) {
424
+ return { actor: "human", label: `Review evidence and accept: ${state.gate.title}` };
425
+ }
272
426
 
273
427
  const nextPhase = workflow.phases.find((phase) => phase.id === state.phase.next);
274
428
  return {
275
429
  actor: "human",
276
- label: nextPhase ? `Continue to ${nextPhase.title}` : "Accept the outcome and close this AHEAD run",
430
+ label: nextPhase
431
+ ? `Continue to ${nextPhase.title}`
432
+ : "Accept the outcome and close this AHEAD run",
277
433
  };
278
434
  }
279
435
 
280
- function optionalAssistBeforeFinalHumanRecord(state: RunState): GuidedNextAction | undefined {
281
- const orderedAssist = state.phase.id === "options"
282
- ? { prerequisite: "human-option", assist: "ai-challenge", final: "options" }
283
- : state.phase.id === "plan"
284
- ? { prerequisite: "first-pass-plan", assist: "ai-plan-review", final: "plan" }
285
- : undefined;
286
- if (!orderedAssist) return undefined;
287
-
288
- const prerequisite = state.artifacts.find((artifact) => artifact.kind === orderedAssist.prerequisite);
289
- const assist = state.artifacts.find((artifact) => artifact.kind === orderedAssist.assist);
290
- const final = state.artifacts.find((artifact) => artifact.kind === orderedAssist.final);
291
- if (!prerequisite?.present || assist?.present || final?.present) return undefined;
292
-
293
- return {
294
- actor: "ai",
295
- artifactKind: assist?.kind,
296
- label: state.phase.id === "options"
297
- ? "Ask AI to challenge the human option and expand alternatives"
298
- : "Ask AI to challenge the human first-pass plan",
299
- optional: true,
300
- };
436
+ function nextPendingArtifact(state: RunState): ArtifactState | undefined {
437
+ return state.artifacts.find(
438
+ (artifact) =>
439
+ !artifact.present &&
440
+ (artifact.required ||
441
+ (artifact.actor !== "human" && state.allowed_ai_capabilities.includes("record"))),
442
+ );
301
443
  }
302
444
 
303
- export function buildWidgetLines(run: Run, state: RunState, workflow: WorkflowDefinition): string[] {
445
+ export function buildHeaderLines(
446
+ run: Run,
447
+ state: RunState,
448
+ workflow: WorkflowDefinition,
449
+ ): string[] {
304
450
  if (state.closed) {
305
451
  return [
306
452
  `AHEAD COMPLETE · ${run.title}`,
@@ -309,7 +455,7 @@ export function buildWidgetLines(run: Run, state: RunState, workflow: WorkflowDe
309
455
  ];
310
456
  }
311
457
 
312
- const guide = phaseGuide(state.phase.id);
458
+ const guide = phaseGuide(state.workflow_id, state.phase.id);
313
459
  const position = phasePosition(state, workflow);
314
460
  const required = state.artifacts.filter((artifact) => artifact.required);
315
461
  const checklist = required.length
@@ -318,14 +464,10 @@ export function buildWidgetLines(run: Run, state: RunState, workflow: WorkflowDe
318
464
  const action = nextAction(state, workflow);
319
465
 
320
466
  return [
321
- `AHEAD MODE · ${workflow.title.toUpperCase()} · ${position.current}/${position.total}`,
322
- `${guide.handoff ?? state.phase.title.toUpperCase()} · HUMAN LEADS · AI ASSISTS`,
467
+ `AHEAD · ${workflow.title} · ${position.current}/${position.total} · ${state.phase.title}`,
323
468
  `Goal: ${guide.objective}`,
324
- `You: ${guide.human}`,
325
- `AI: ${guide.ai}`,
326
469
  `Required: ${checklist}`,
327
- `Next (${action.actor === "human" ? "you" : "AI"}): ${action.label}`,
328
- "Run /ahead for the guided action · /ahead-guide for framework docs.",
470
+ `Next: ${action.actor === "human" ? "You" : "AI"} → ${action.label}`,
329
471
  ];
330
472
  }
331
473
 
@@ -335,7 +477,7 @@ export function buildArtifactTemplate(
335
477
  kind: string,
336
478
  title: string,
337
479
  ): string {
338
- const prompts = promptsForArtifact(state.phase.id, kind);
480
+ const prompts = promptsForArtifact(state.workflow_id, state.phase.id, kind);
339
481
  return [
340
482
  `# ${title}`,
341
483
  "",