ahead-pi 0.2.1 → 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 (91) hide show
  1. package/README.md +17 -7
  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/docs/design/adapted-skill-guidance.md +27 -0
  69. package/generated/reference/docs/design/executable-workflows.md +20 -8
  70. package/generated/reference/docs/design/instruction-authoring.md +28 -0
  71. package/generated/reference/docs/design/review-workbench.md +37 -0
  72. package/generated/reference/docs/recommended-skills.md +19 -0
  73. package/generated/reference/docs/workflows/README.md +3 -3
  74. package/generated/reference/docs/workflows/corrective-debugging.md +37 -19
  75. package/generated/reference/docs/workflows/decision.md +2 -2
  76. package/generated/reference/docs/workflows/internal-improvement.md +35 -23
  77. package/generated/reference/docs/workflows/investigation.md +3 -1
  78. package/generated/reference/docs/workflows/operational-stabilization.md +14 -12
  79. package/generated/reference/docs/workflows/product-change.md +14 -3
  80. package/generated/reference/index.json +131 -13
  81. package/package.json +34 -25
  82. package/src/engine.ts +26 -7
  83. package/src/flow-guides.ts +168 -0
  84. package/src/guidance.ts +218 -72
  85. package/src/index.ts +603 -175
  86. package/src/reference-viewer.ts +20 -18
  87. package/src/reference.ts +65 -14
  88. package/src/review.ts +360 -0
  89. package/src/skills.ts +133 -0
  90. package/src/storage.ts +77 -13
  91. package/src/types.ts +1 -0
package/package.json CHANGED
@@ -1,62 +1,71 @@
1
1
  {
2
2
  "name": "ahead-pi",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "AHEAD workflow enforcement and context for Pi",
5
+ "keywords": [
6
+ "ahead",
7
+ "human-in-the-loop",
8
+ "pi-package"
9
+ ],
10
+ "homepage": "https://github.com/Kade-Powell/ahead/tree/main/integrations/pi#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/Kade-Powell/ahead/issues"
13
+ },
5
14
  "license": "MIT",
6
- "type": "module",
7
15
  "repository": {
8
16
  "type": "git",
9
17
  "url": "git+https://github.com/Kade-Powell/ahead.git",
10
18
  "directory": "integrations/pi"
11
19
  },
12
- "homepage": "https://github.com/Kade-Powell/ahead/tree/main/integrations/pi#readme",
13
- "bugs": {
14
- "url": "https://github.com/Kade-Powell/ahead/issues"
15
- },
16
- "engines": {
17
- "node": ">=22.19.0"
18
- },
19
20
  "files": [
20
21
  "dist/ahead_wasm.wasm",
21
22
  "generated/",
22
23
  "src/"
23
24
  ],
25
+ "type": "module",
24
26
  "publishConfig": {
25
27
  "access": "public",
26
28
  "provenance": true,
27
29
  "registry": "https://registry.npmjs.org/"
28
30
  },
29
- "keywords": [
30
- "pi-package",
31
- "ahead",
32
- "human-in-the-loop"
33
- ],
34
- "pi": {
35
- "extensions": [
36
- "./src/index.ts"
37
- ]
38
- },
39
31
  "scripts": {
40
32
  "build": "npm run build:instructions && npm run build:wasm && npm run typecheck",
41
33
  "build:instructions": "node ../../scripts/build-instructions.mjs",
42
34
  "build:wasm": "node ./scripts/build-wasm.mjs",
35
+ "format": "cd ../.. && integrations/pi/node_modules/.bin/oxfmt -c ./.oxfmtrc.json .oxfmtrc.json .oxlintrc.json scripts integrations/pi/scripts integrations/pi/src integrations/pi/test integrations/pi/package.json integrations/pi/tsconfig.json",
36
+ "format:check": "npm run format -- --check",
37
+ "lint": "npm run lint:source && npm run lint:types",
38
+ "lint:source": "cd ../.. && integrations/pi/node_modules/.bin/oxlint -c ./.oxlintrc.json --report-unused-disable-directives-severity=off scripts integrations/pi/scripts integrations/pi/src integrations/pi/test",
39
+ "lint:types": "cd ../.. && integrations/pi/node_modules/.bin/oxlint -c ./.oxlintrc.json --type-aware --tsconfig integrations/pi/tsconfig.json integrations/pi/src",
43
40
  "prepack": "npm run build",
44
41
  "prepublishOnly": "npm run verify",
45
42
  "pack:verify": "node ./scripts/verify-package.mjs",
43
+ "quality": "npm run format:check && npm run lint && npm run typecheck",
46
44
  "typecheck": "tsc --noEmit",
47
- "verify": "npm run build && node --test ./test/*.test.mjs",
45
+ "verify": "npm run build && npm run format:check && npm run lint && node --test ./test/*.test.mjs",
48
46
  "test": "npm run verify && npm run pack:verify"
49
47
  },
50
- "peerDependencies": {
51
- "@earendil-works/pi-coding-agent": "*",
52
- "@earendil-works/pi-tui": "*",
53
- "typebox": "*"
54
- },
55
48
  "devDependencies": {
56
49
  "@earendil-works/pi-coding-agent": "^0.84.1",
57
50
  "@earendil-works/pi-tui": "^0.84.1",
58
51
  "@types/node": "24.12.4",
52
+ "oxfmt": "^0.63.0",
53
+ "oxlint": "^1.78.0",
54
+ "oxlint-tsgolint": "^7.0.2001",
59
55
  "typebox": "1.1.38",
60
56
  "typescript": "5.9.3"
57
+ },
58
+ "peerDependencies": {
59
+ "@earendil-works/pi-coding-agent": "*",
60
+ "@earendil-works/pi-tui": "*",
61
+ "typebox": "*"
62
+ },
63
+ "engines": {
64
+ "node": ">=22.19.0"
65
+ },
66
+ "pi": {
67
+ "extensions": [
68
+ "./src/index.ts"
69
+ ]
61
70
  }
62
71
  }
package/src/engine.ts CHANGED
@@ -40,11 +40,9 @@ export class AheadEngine {
40
40
  static async load(path: string): Promise<AheadEngine> {
41
41
  const bytes = await readFile(path);
42
42
  const instantiated = await WebAssembly.instantiate(bytes, {});
43
- const wasm = instantiated.instance.exports as WasmExports;
44
- for (const name of ["memory", "ahead_alloc", "ahead_dealloc", "ahead_dispatch"]) {
45
- if (!(name in wasm)) {
46
- throw new Error(`AHEAD WebAssembly module is missing export: ${name}`);
47
- }
43
+ const wasm = instantiated.instance.exports;
44
+ if (!isWasmExports(wasm)) {
45
+ throw new Error("AHEAD WebAssembly module does not expose the required engine ABI");
48
46
  }
49
47
  return new AheadEngine(wasm);
50
48
  }
@@ -53,6 +51,10 @@ export class AheadEngine {
53
51
  return this.call("get_workflow", { workflow_id: workflowId });
54
52
  }
55
53
 
54
+ listWorkflows(): WorkflowDefinition[] {
55
+ return this.call("list_workflows", {});
56
+ }
57
+
56
58
  createRun(input: {
57
59
  id: string;
58
60
  title: string;
@@ -78,10 +80,14 @@ export class AheadEngine {
78
80
  });
79
81
  }
80
82
 
81
- toolAllowed(run: Run, capability: Capability): { allowed: boolean; reason: string; capability: Capability } {
83
+ toolAllowed(
84
+ run: Run,
85
+ capability: Capability,
86
+ ): { allowed: boolean; reason: string; capability: Capability } {
82
87
  return this.call("tool_allowed", { run, capability });
83
88
  }
84
89
 
90
+ // oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- the operation selects the Rust response type
85
91
  private call<T>(operation: string, input: unknown): T {
86
92
  const request = new TextEncoder().encode(
87
93
  JSON.stringify({ api_version: ENGINE_API_VERSION, operation, input }),
@@ -96,9 +102,13 @@ export class AheadEngine {
96
102
  outputPointer = Number(packed >> 32n);
97
103
  outputLength = Number(packed & 0xffff_ffffn);
98
104
  const output = new Uint8Array(this.wasm.memory.buffer, outputPointer, outputLength).slice();
105
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the versioned Rust ABI owns this response envelope
99
106
  const response = JSON.parse(new TextDecoder().decode(output)) as EngineResponse<T>;
100
107
  if (!response.ok || response.result === undefined) {
101
- const error = response.error ?? { code: "unknown_engine_error", message: "AHEAD engine call failed" };
108
+ const error = response.error ?? {
109
+ code: "unknown_engine_error",
110
+ message: "AHEAD engine call failed",
111
+ };
102
112
  throw new AheadEngineError(error.code, error.message);
103
113
  }
104
114
  return response.result;
@@ -110,3 +120,12 @@ export class AheadEngine {
110
120
  }
111
121
  }
112
122
  }
123
+
124
+ function isWasmExports(exports: WebAssembly.Exports): exports is WasmExports {
125
+ return (
126
+ exports.memory instanceof WebAssembly.Memory &&
127
+ typeof exports.ahead_alloc === "function" &&
128
+ typeof exports.ahead_dealloc === "function" &&
129
+ typeof exports.ahead_dispatch === "function"
130
+ );
131
+ }
@@ -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
+ };