ahead-pi 0.2.0 → 0.3.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 (102) hide show
  1. package/README.md +29 -9
  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 +12 -6
  54. package/generated/product-change/ai-review.md +20 -7
  55. package/generated/product-change/decision.md +16 -4
  56. package/generated/product-change/define.md +9 -4
  57. package/generated/product-change/deploy.md +9 -4
  58. package/generated/product-change/human-review.md +16 -4
  59. package/generated/product-change/implement.md +14 -5
  60. package/generated/product-change/manifest.json +9 -4
  61. package/generated/product-change/options.md +16 -4
  62. package/generated/product-change/outcome.md +9 -4
  63. package/generated/product-change/plan.md +22 -4
  64. package/generated/product-change/questions.md +22 -4
  65. package/generated/product-change/research.md +16 -4
  66. package/generated/product-change/verify.md +9 -4
  67. package/generated/recommended-skills.json +24 -0
  68. package/generated/reference/CONSTITUTION.md +43 -0
  69. package/generated/reference/docs/acceptable-ai-use.md +217 -0
  70. package/generated/reference/docs/design/adapted-skill-guidance.md +27 -0
  71. package/generated/reference/docs/design/debugging-and-operations.md +119 -0
  72. package/generated/reference/docs/design/executable-workflows.md +122 -0
  73. package/generated/reference/docs/design/instruction-authoring.md +28 -0
  74. package/generated/reference/docs/design/process-taxonomy.md +144 -0
  75. package/generated/reference/docs/design/review-workbench.md +37 -0
  76. package/generated/reference/docs/engineering-practice.md +163 -0
  77. package/generated/reference/docs/evidence/evidence-standard.md +123 -0
  78. package/generated/reference/docs/evidence/research-map.md +98 -0
  79. package/generated/reference/docs/rationale.md +210 -0
  80. package/generated/reference/docs/recommended-skills.md +19 -0
  81. package/generated/reference/docs/references/pragmatic-programmer-page-index.md +113 -0
  82. package/generated/reference/docs/references/submitted-engineering-notes.md +306 -0
  83. package/generated/reference/docs/releasing-pi.md +89 -0
  84. package/generated/reference/docs/workflows/README.md +142 -0
  85. package/generated/reference/docs/workflows/corrective-debugging.md +221 -0
  86. package/generated/reference/docs/workflows/decision.md +149 -0
  87. package/generated/reference/docs/workflows/internal-improvement.md +219 -0
  88. package/generated/reference/docs/workflows/investigation.md +161 -0
  89. package/generated/reference/docs/workflows/operational-stabilization.md +187 -0
  90. package/generated/reference/docs/workflows/product-change.md +216 -0
  91. package/generated/reference/index.json +298 -0
  92. package/package.json +36 -25
  93. package/src/engine.ts +26 -7
  94. package/src/flow-guides.ts +168 -0
  95. package/src/guidance.ts +220 -72
  96. package/src/index.ts +696 -140
  97. package/src/reference-viewer.ts +73 -0
  98. package/src/reference.ts +107 -0
  99. package/src/review.ts +360 -0
  100. package/src/skills.ts +133 -0
  101. package/src/storage.ts +77 -13
  102. package/src/types.ts +1 -0
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,8 +117,9 @@ const guides: Record<string, PhaseGuide> = {
110
117
  },
111
118
  implement: {
112
119
  objective: "Produce a change the engineer understands and can defend.",
113
- human: "Own the implementation, understand every lasting change, run the planned checks, and record deviations.",
114
- ai: "Assist within the approved plan, explain changes, run authorized checks, and surface reasons to revisit earlier phases.",
120
+ human:
121
+ "Make the first attempt, ask questions freely, own the implementation, understand every lasting change, run the planned checks, and record deviations.",
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: [
117
125
  "What exact commit, branch, pull request, or diff identifies the current change?",
@@ -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,66 +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 === "human-review"
256
- ? "Independent reviewer records the current human review"
257
- : `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}`;
258
404
  return { actor, label, artifactKind: artifact.kind };
259
405
  }
260
406
 
261
- const label = state.phase.id === "ai-review"
262
- ? "Run AI review of the exact current changeset"
263
- : state.phase.id === "ai-audit"
264
- ? "Run AI audit across intent, evidence, and outcome"
265
- : `Ask AI to produce ${artifact.title}`;
266
- 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 };
267
421
  }
268
422
 
269
- 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
+ }
270
426
 
271
427
  const nextPhase = workflow.phases.find((phase) => phase.id === state.phase.next);
272
428
  return {
273
429
  actor: "human",
274
- 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",
275
433
  };
276
434
  }
277
435
 
278
- function optionalAssistBeforeFinalHumanRecord(state: RunState): GuidedNextAction | undefined {
279
- const orderedAssist = state.phase.id === "options"
280
- ? { prerequisite: "human-option", assist: "ai-challenge", final: "options" }
281
- : state.phase.id === "plan"
282
- ? { prerequisite: "first-pass-plan", assist: "ai-plan-review", final: "plan" }
283
- : undefined;
284
- if (!orderedAssist) return undefined;
285
-
286
- const prerequisite = state.artifacts.find((artifact) => artifact.kind === orderedAssist.prerequisite);
287
- const assist = state.artifacts.find((artifact) => artifact.kind === orderedAssist.assist);
288
- const final = state.artifacts.find((artifact) => artifact.kind === orderedAssist.final);
289
- if (!prerequisite?.present || assist?.present || final?.present) return undefined;
290
-
291
- return {
292
- actor: "ai",
293
- artifactKind: assist?.kind,
294
- label: state.phase.id === "options"
295
- ? "Ask AI to challenge the human option and expand alternatives"
296
- : "Ask AI to challenge the human first-pass plan",
297
- optional: true,
298
- };
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
+ );
299
443
  }
300
444
 
301
- export function buildWidgetLines(run: Run, state: RunState, workflow: WorkflowDefinition): string[] {
445
+ export function buildWidgetLines(
446
+ run: Run,
447
+ state: RunState,
448
+ workflow: WorkflowDefinition,
449
+ ): string[] {
302
450
  if (state.closed) {
303
451
  return [
304
452
  `AHEAD COMPLETE · ${run.title}`,
@@ -307,7 +455,7 @@ export function buildWidgetLines(run: Run, state: RunState, workflow: WorkflowDe
307
455
  ];
308
456
  }
309
457
 
310
- const guide = phaseGuide(state.phase.id);
458
+ const guide = phaseGuide(state.workflow_id, state.phase.id);
311
459
  const position = phasePosition(state, workflow);
312
460
  const required = state.artifacts.filter((artifact) => artifact.required);
313
461
  const checklist = required.length
@@ -323,7 +471,7 @@ export function buildWidgetLines(run: Run, state: RunState, workflow: WorkflowDe
323
471
  `AI: ${guide.ai}`,
324
472
  `Required: ${checklist}`,
325
473
  `Next (${action.actor === "human" ? "you" : "AI"}): ${action.label}`,
326
- "Run /ahead for the guided action.",
474
+ "Run /ahead for the guided action · /ahead-guide for framework docs.",
327
475
  ];
328
476
  }
329
477
 
@@ -333,7 +481,7 @@ export function buildArtifactTemplate(
333
481
  kind: string,
334
482
  title: string,
335
483
  ): string {
336
- const prompts = promptsForArtifact(state.phase.id, kind);
484
+ const prompts = promptsForArtifact(state.workflow_id, state.phase.id, kind);
337
485
  return [
338
486
  `# ${title}`,
339
487
  "",