ai-engineering-loop 2.2.0 → 2.4.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.
- package/.agents/skills/ai-engineering-loop/SKILL.md +4 -4
- package/.agents/skills/ai-engineering-loop/references/loop-deliver.md +2 -2
- package/.agents/skills/ai-engineering-loop/references/loop-goal.md +3 -3
- package/.agents/skills/ai-engineering-loop/references/loop-maker.md +1 -0
- package/.agents/skills/ai-engineering-loop/references/loop-review.md +3 -4
- package/.agents/skills/ai-engineering-loop/references/loop-risky.md +1 -0
- package/.agents/skills/ai-engineering-loop/references/loop-verify.md +3 -3
- package/.claude/agents/judge.md +5 -2
- package/.grok/agents/judge.md +5 -2
- package/CHANGELOG.md +60 -0
- package/README.md +1 -0
- package/THIRD_PARTY_NOTICES.md +11 -0
- package/adapters/spec/LICENSE +202 -0
- package/adapters/spec/NOTICE-AEL.md +26 -0
- package/adapters/spec/agents/ael-spec-codebase-details.md +71 -0
- package/adapters/spec/agents/ael-spec-comprehension.md +71 -0
- package/adapters/spec/agents/ael-spec-design.md +65 -0
- package/adapters/spec/agents/ael-spec-implementation-readiness.md +64 -0
- package/adapters/spec/agents/ael-spec-structural.md +67 -0
- package/adapters/spec/agents/ael-spec-style.md +68 -0
- package/adapters/spec/agents/ael-spec-synthesizer.md +73 -0
- package/adapters/spec/agents/ael-spec-zoom-out.md +76 -0
- package/adapters/spec/skills/ael-spec-brainstorm/SKILL.md +265 -0
- package/adapters/spec/skills/ael-spec-draft/SKILL.md +315 -0
- package/adapters/spec/skills/ael-spec-draft/references/design_doc.md +179 -0
- package/adapters/spec/skills/ael-spec-drift/SKILL.md +68 -0
- package/adapters/spec/skills/ael-spec-resolve/SKILL.md +188 -0
- package/adapters/spec/skills/ael-spec-review/SKILL.md +403 -0
- package/adapters/spec/skills/ael-spec-review-loop/SKILL.md +191 -0
- package/adapters/spec/standards/ael-spec-execution-instructions.md +36 -0
- package/adapters/spec/standards/ael-spec-feature-spec-standard.md +38 -0
- package/adapters/spec/standards/ael-spec-heilmeier-standard.md +32 -0
- package/adapters/spec/standards/ael-spec-implementation-readiness-standard.md +36 -0
- package/adapters/spec/standards/ael-spec-re-implementation-standard.md +39 -0
- package/adapters/spec/standards/ael-spec-zoom-out-standard.md +62 -0
- package/agents/maker.md +1 -1
- package/agents/shared/judge.body.md +5 -2
- package/bin/ai-engineering-loop.js +344 -78
- package/core/definition-of-done.md +2 -2
- package/core/escalation-policy.md +1 -1
- package/core/goal-contract.md +1 -1
- package/core/iteration-policy.md +2 -1
- package/core/judge-policy.md +10 -4
- package/core/orchestration-model.md +8 -7
- package/core/repo-config-schema.md +2 -2
- package/core/runtime-safety.md +3 -3
- package/core/spec-pack.md +47 -0
- package/lib/auto-update.js +8 -14
- package/lib/claimed-vs-reality.js +2 -2
- package/lib/cli-args.js +3 -1
- package/lib/design-ref.js +178 -0
- package/lib/docs.js +1 -1
- package/lib/doctor.js +0 -6
- package/lib/escalation.js +1 -1
- package/lib/fsutil.js +88 -0
- package/lib/gates.js +70 -27
- package/lib/generate-workflow.js +0 -29
- package/lib/goal-runtime.js +8 -2
- package/lib/guard-hooks.js +26 -7
- package/lib/guard.js +100 -10
- package/lib/hosts/doctor.js +17 -7
- package/lib/impact-map.js +31 -8
- package/lib/jsonl-ledger.js +104 -0
- package/lib/learn.js +4 -9
- package/lib/loop-groups.js +0 -25
- package/lib/migrations.js +1 -5
- package/lib/no-progress.js +119 -0
- package/lib/node-evidence.js +1 -5
- package/lib/orchestration.js +5 -361
- package/lib/personal-workflow.js +1 -1
- package/lib/quick.js +152 -0
- package/lib/receipt.js +13 -6
- package/lib/recipe-builder.js +3 -35
- package/lib/recipe-graph.js +2 -63
- package/lib/recipe.js +2 -4
- package/lib/review-ingest.js +116 -0
- package/lib/run-abandon.js +2 -1
- package/lib/run-compaction.js +4 -12
- package/lib/run-interactions.js +16 -71
- package/lib/run-lifecycle.js +25 -77
- package/lib/run-state.js +68 -17
- package/lib/run-watcher.js +11 -14
- package/lib/runtime-files.js +45 -1
- package/lib/safe-context.js +17 -6
- package/lib/sandbox.js +2 -1
- package/lib/smart-context.js +13 -14
- package/lib/spawn-command.js +94 -0
- package/lib/studio-layout.js +2 -8
- package/lib/studio-runtime.js +2 -1
- package/lib/studio-server.js +25 -5
- package/lib/sync-hosts.js +25 -2
- package/lib/tier.js +36 -10
- package/lib/user-state.js +2 -17
- package/lib/verification-lanes.js +115 -0
- package/lib/verification-recorder.js +110 -22
- package/lib/workflow-runtime.js +7 -4
- package/package.json +1 -2
- package/policies/review-budget.md +1 -1
- package/schemas/goal-contract.schema.json +87 -11
- package/.claude/skills/ai-engineering-loop/SKILL.md +0 -62
- package/.claude/skills/ai-engineering-loop/references/loop-commands.md +0 -24
- package/.claude/skills/ai-engineering-loop/references/loop-deliver.md +0 -10
- package/.claude/skills/ai-engineering-loop/references/loop-goal.md +0 -11
- package/.claude/skills/ai-engineering-loop/references/loop-hosts.md +0 -48
- package/.claude/skills/ai-engineering-loop/references/loop-maker.md +0 -14
- package/.claude/skills/ai-engineering-loop/references/loop-review.md +0 -20
- package/.claude/skills/ai-engineering-loop/references/loop-risky.md +0 -9
- package/.claude/skills/ai-engineering-loop/references/loop-verify.md +0 -20
- package/.claude/skills/animate/RECIPES.md +0 -324
- package/.claude/skills/animate/SKILL.md +0 -207
- package/.claude/skills/animate-expo/RECIPES.md +0 -385
- package/.claude/skills/animate-expo/SKILL.md +0 -263
- package/.claude/skills/animation-vocabulary/SKILL.md +0 -181
- package/.claude/skills/apple-design/SKILL.md +0 -290
- package/.claude/skills/ask-sonner/API.md +0 -64
- package/.claude/skills/ask-sonner/SKILL.md +0 -88
- package/.claude/skills/backend-development/SKILL.md +0 -272
- package/.claude/skills/backend-development/references/api-design-guidelines.md +0 -95
- package/.claude/skills/backend-development/references/query-and-database-best-practices.md +0 -53
- package/.claude/skills/backend-development/references/security-checklist.md +0 -60
- package/.claude/skills/emil-design-eng/SKILL.md +0 -674
- package/.claude/skills/find-animation-opportunities/SKILL.md +0 -140
- package/.claude/skills/improve-animations/AUDIT.md +0 -115
- package/.claude/skills/improve-animations/PLAN-TEMPLATE.md +0 -73
- package/.claude/skills/improve-animations/SKILL.md +0 -109
- package/.claude/skills/mobile-native/SKILL.md +0 -311
- package/.claude/skills/pick-ui-library/SKILL.md +0 -85
- package/.claude/skills/prototype/PICKER.md +0 -197
- package/.claude/skills/prototype/SKILL.md +0 -98
- package/.claude/skills/review-animations/SKILL.md +0 -120
- package/.claude/skills/review-animations/STANDARDS.md +0 -187
- package/.claude/skills/write-swift/SKILL.md +0 -396
- package/lib/intern-catalog.js +0 -53
|
@@ -13,8 +13,22 @@
|
|
|
13
13
|
const fs = require('fs');
|
|
14
14
|
const os = require('os');
|
|
15
15
|
const path = require('path');
|
|
16
|
-
const
|
|
16
|
+
const { readJsonOptional, sha256: sha256Text } = require('../lib/fsutil.js');
|
|
17
17
|
const { execSync, spawn } = require('child_process');
|
|
18
|
+
|
|
19
|
+
// Command modules load on first use, so a hot path such as
|
|
20
|
+
// `guard check --hook` (run before every tool call) loads only what it
|
|
21
|
+
// touches. lazyModule: a namespace that requires the file on first property
|
|
22
|
+
// read. lazyFunctions: destructure functions now, require the file on first
|
|
23
|
+
// call. Modules whose constants are read at load time stay eager.
|
|
24
|
+
function lazyModule(file) {
|
|
25
|
+
let mod;
|
|
26
|
+
return new Proxy({}, { get: (_, key) => (mod ||= require(file))[key] });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function lazyFunctions(file) {
|
|
30
|
+
return new Proxy({}, { get: (_, key) => (...params) => require(file)[key](...params) });
|
|
31
|
+
}
|
|
18
32
|
const {
|
|
19
33
|
homeDir,
|
|
20
34
|
applyHostSync,
|
|
@@ -22,9 +36,9 @@ const {
|
|
|
22
36
|
resolveHostSelection,
|
|
23
37
|
planHostSync,
|
|
24
38
|
formatHostSyncReport
|
|
25
|
-
} =
|
|
26
|
-
const hostCommands =
|
|
27
|
-
const { listDocs, readDoc } =
|
|
39
|
+
} = lazyFunctions('../lib/sync-hosts.js');
|
|
40
|
+
const hostCommands = lazyModule('../lib/hosts/commands.js');
|
|
41
|
+
const { listDocs, readDoc } = lazyFunctions('../lib/docs.js');
|
|
28
42
|
const {
|
|
29
43
|
wantsCommandHelp,
|
|
30
44
|
unknownWriterArgs,
|
|
@@ -36,16 +50,16 @@ const {
|
|
|
36
50
|
writeShippedAdapter,
|
|
37
51
|
formatGenerateAdapterReport,
|
|
38
52
|
parseTypeArg
|
|
39
|
-
} =
|
|
40
|
-
const { detectAdapter } =
|
|
41
|
-
const { checkAdapter } =
|
|
53
|
+
} = lazyFunctions('../lib/generate-adapter.js');
|
|
54
|
+
const { detectAdapter } = lazyFunctions('../lib/adapter-detect.js');
|
|
55
|
+
const { checkAdapter } = lazyFunctions('../lib/adapter-check.js');
|
|
42
56
|
const {
|
|
43
57
|
writeWorkflowOverlay,
|
|
44
58
|
formatGenerateWorkflowReport,
|
|
45
59
|
parseWriteArg,
|
|
46
60
|
workflowMarkdown,
|
|
47
61
|
lessonsMarkdown
|
|
48
|
-
} =
|
|
62
|
+
} = lazyFunctions('../lib/generate-workflow.js');
|
|
49
63
|
const {
|
|
50
64
|
RUN_MODES,
|
|
51
65
|
TERMINAL_STATES,
|
|
@@ -66,23 +80,23 @@ const {
|
|
|
66
80
|
const {
|
|
67
81
|
applyGate,
|
|
68
82
|
judgeRequirement
|
|
69
|
-
} =
|
|
70
|
-
const { initialTierState } =
|
|
71
|
-
const impactMap =
|
|
72
|
-
const guard =
|
|
73
|
-
const guardHooks =
|
|
74
|
-
const receipts =
|
|
75
|
-
const { learn } =
|
|
83
|
+
} = lazyFunctions('../lib/gates.js');
|
|
84
|
+
const { initialTierState } = lazyFunctions('../lib/tier.js');
|
|
85
|
+
const impactMap = lazyModule('../lib/impact-map.js');
|
|
86
|
+
const guard = lazyModule('../lib/guard.js');
|
|
87
|
+
const guardHooks = lazyModule('../lib/guard-hooks.js');
|
|
88
|
+
const receipts = lazyModule('../lib/receipt.js');
|
|
89
|
+
const { learn } = lazyFunctions('../lib/learn.js');
|
|
76
90
|
const {
|
|
77
91
|
runBench,
|
|
78
92
|
compareBenches,
|
|
79
93
|
formatCompare,
|
|
80
94
|
parseBenchTimeoutSeconds
|
|
81
|
-
} =
|
|
95
|
+
} = lazyFunctions('../lib/bench.js');
|
|
82
96
|
const {
|
|
83
97
|
createContextPack,
|
|
84
98
|
contextPackSummary
|
|
85
|
-
} =
|
|
99
|
+
} = lazyFunctions('../lib/safe-context.js');
|
|
86
100
|
const {
|
|
87
101
|
assessSmallTaskFastPath,
|
|
88
102
|
buildContextIndex,
|
|
@@ -90,51 +104,51 @@ const {
|
|
|
90
104
|
queryContextIndex,
|
|
91
105
|
relatedContextIndex,
|
|
92
106
|
smartContextSummary
|
|
93
|
-
} =
|
|
107
|
+
} = lazyFunctions('../lib/smart-context.js');
|
|
94
108
|
const {
|
|
95
109
|
compactRun
|
|
96
|
-
} =
|
|
110
|
+
} = lazyFunctions('../lib/run-compaction.js');
|
|
97
111
|
const {
|
|
98
112
|
defaultCasesDir,
|
|
99
113
|
loadEvaluationCases,
|
|
100
114
|
loadResults,
|
|
101
115
|
scoreEvaluationResults,
|
|
102
116
|
catalogSummary
|
|
103
|
-
} =
|
|
117
|
+
} = lazyFunctions('../lib/evaluation.js');
|
|
104
118
|
const {
|
|
105
119
|
assessRunEscalation
|
|
106
|
-
} =
|
|
120
|
+
} = lazyFunctions('../lib/escalation.js');
|
|
107
121
|
const {
|
|
108
122
|
writeVerificationSummary
|
|
109
|
-
} =
|
|
123
|
+
} = lazyFunctions('../lib/verification-summary.js');
|
|
110
124
|
const {
|
|
111
125
|
recordVerificationCommands,
|
|
112
126
|
recordVerificationCommand
|
|
113
|
-
} =
|
|
127
|
+
} = lazyFunctions('../lib/verification-recorder.js');
|
|
114
128
|
const {
|
|
115
129
|
scaffoldArtifact,
|
|
116
130
|
validateArtifactFile
|
|
117
|
-
} =
|
|
131
|
+
} = lazyFunctions('../lib/agent-artifacts.js');
|
|
118
132
|
const {
|
|
119
133
|
createClaimedVsRealityTemplate
|
|
120
|
-
} =
|
|
134
|
+
} = lazyFunctions('../lib/claimed-vs-reality.js');
|
|
121
135
|
const {
|
|
122
136
|
runDoctor
|
|
123
|
-
} =
|
|
137
|
+
} = lazyFunctions('../lib/doctor.js');
|
|
124
138
|
const {
|
|
125
139
|
checkForUpdate,
|
|
126
140
|
detectInstallScope,
|
|
127
141
|
executeUpdatePlan
|
|
128
|
-
} =
|
|
129
|
-
const autoUpdate =
|
|
130
|
-
const projectRegistry =
|
|
142
|
+
} = lazyFunctions('../lib/update-manager.js');
|
|
143
|
+
const autoUpdate = lazyModule('../lib/auto-update.js');
|
|
144
|
+
const projectRegistry = lazyModule('../lib/project-registry.js');
|
|
131
145
|
const {
|
|
132
146
|
assertBudgetAvailable,
|
|
133
147
|
budgetStatus,
|
|
134
148
|
recordTokenUsage,
|
|
135
149
|
recordUsageUnavailable,
|
|
136
150
|
setKillSwitch
|
|
137
|
-
} =
|
|
151
|
+
} = lazyFunctions('../lib/budget.js');
|
|
138
152
|
const {
|
|
139
153
|
PRIVATE_RUNTIME_GITIGNORE
|
|
140
154
|
} = require('../lib/runtime-files.js');
|
|
@@ -142,23 +156,23 @@ const {
|
|
|
142
156
|
appendRunAnswer,
|
|
143
157
|
appendRunQuestion,
|
|
144
158
|
listRunInteractions
|
|
145
|
-
} =
|
|
159
|
+
} = lazyFunctions('../lib/run-interactions.js');
|
|
146
160
|
const {
|
|
147
161
|
appendRunLifecycle,
|
|
148
162
|
listRunLifecycle,
|
|
149
163
|
runAgentPresence
|
|
150
|
-
} =
|
|
164
|
+
} = lazyFunctions('../lib/run-lifecycle.js');
|
|
151
165
|
const {
|
|
152
166
|
freezeGoal,
|
|
153
167
|
loadGoalDraft,
|
|
154
168
|
saveGoalDraft
|
|
155
|
-
} =
|
|
169
|
+
} = lazyFunctions('../lib/goal-runtime.js');
|
|
156
170
|
const {
|
|
157
171
|
abortSandbox,
|
|
158
172
|
captureSandbox,
|
|
159
173
|
createSandbox,
|
|
160
174
|
sandboxStatus
|
|
161
|
-
} =
|
|
175
|
+
} = lazyFunctions('../lib/sandbox.js');
|
|
162
176
|
const {
|
|
163
177
|
compileRecipe,
|
|
164
178
|
explainPlan,
|
|
@@ -167,7 +181,7 @@ const {
|
|
|
167
181
|
mermaidPlan,
|
|
168
182
|
simulatePlan,
|
|
169
183
|
validateRecipe
|
|
170
|
-
} =
|
|
184
|
+
} = lazyFunctions('../lib/recipe.js');
|
|
171
185
|
const {
|
|
172
186
|
applyWorkflowGate,
|
|
173
187
|
approveWorkflowNode,
|
|
@@ -178,21 +192,21 @@ const {
|
|
|
178
192
|
retryWorkflowNode,
|
|
179
193
|
startWorkflowNode,
|
|
180
194
|
workflowStatus
|
|
181
|
-
} =
|
|
195
|
+
} = lazyFunctions('../lib/workflow-runtime.js');
|
|
182
196
|
const {
|
|
183
197
|
cloneRecipe,
|
|
184
198
|
diffRecipes,
|
|
185
199
|
inspectRecipe,
|
|
186
200
|
installRecipe,
|
|
187
201
|
recipeCatalog
|
|
188
|
-
} =
|
|
202
|
+
} = lazyFunctions('../lib/recipe-builder.js');
|
|
189
203
|
const {
|
|
190
204
|
createHandoff,
|
|
191
205
|
handoffBrief,
|
|
192
206
|
readHandoff,
|
|
193
207
|
verifyHandoff
|
|
194
|
-
} =
|
|
195
|
-
const { createStudioServer, readStudioUrl } =
|
|
208
|
+
} = lazyFunctions('../lib/handoff.js');
|
|
209
|
+
const { createStudioServer, readStudioUrl } = lazyFunctions('../lib/studio-server.js');
|
|
196
210
|
|
|
197
211
|
const VERSION = require('../package.json').version;
|
|
198
212
|
const CWD = process.cwd();
|
|
@@ -215,19 +229,15 @@ const REQUIRED_FILES = [
|
|
|
215
229
|
// .ael-generated.json) or is package-owned; otherwise the new template goes to
|
|
216
230
|
// `<file>.ael-new` and the user's file is left alone.
|
|
217
231
|
// Legacy projects (no .ael-generated.json yet, decision 5 on #37): the first
|
|
218
|
-
// such refresh overwrites AEL-managed files directly
|
|
219
|
-
//
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
// OBSOLETE_CONTEXT_FILES) are touched; files written with overwrite:false
|
|
232
|
+
// such refresh overwrites AEL-managed files directly, after copying the old
|
|
233
|
+
// content into a snapshot under .ai-engineering-loop/.ael-backup/<timestamp>/.
|
|
234
|
+
// Hashes are recorded so later refreshes use the normal flow. Only paths this
|
|
235
|
+
// writer generates are touched; files written with overwrite:false
|
|
223
236
|
// (lessons, glossary, ...) and every other user file are left alone.
|
|
224
237
|
let CONTEXT_WRITE_SAFE = false;
|
|
225
238
|
let CONTEXT_WRITE_LEGACY = null; // { root, snapshotDir } during a legacy refresh
|
|
226
239
|
const CONTEXT_WRITE_REPORT = { updated: [], aelNew: [], kept: [], seen: new Set(), snapshot: [], removed: [], obsoleteKept: [] };
|
|
227
240
|
const PACKAGE_OWNED_CONTEXT = new Set(['metadata.json']);
|
|
228
|
-
// Context files older AEL versions generated and this one no longer does
|
|
229
|
-
// (relative to .ai-engineering-loop/). Deleted on the first legacy refresh.
|
|
230
|
-
const OBSOLETE_CONTEXT_FILES = Object.freeze([]);
|
|
231
241
|
const GENERATED_HASHES_FILE = '.ael-generated.json';
|
|
232
242
|
|
|
233
243
|
function generatedHashesPath(filePath) {
|
|
@@ -235,11 +245,7 @@ function generatedHashesPath(filePath) {
|
|
|
235
245
|
}
|
|
236
246
|
|
|
237
247
|
function readGeneratedHashes(filePath) {
|
|
238
|
-
|
|
239
|
-
return JSON.parse(fs.readFileSync(generatedHashesPath(filePath), 'utf8'));
|
|
240
|
-
} catch {
|
|
241
|
-
return {};
|
|
242
|
-
}
|
|
248
|
+
return readJsonOptional(generatedHashesPath(filePath), {});
|
|
243
249
|
}
|
|
244
250
|
|
|
245
251
|
function writeGeneratedHashes(filePath, hashes) {
|
|
@@ -252,14 +258,10 @@ function writeGeneratedHashes(filePath, hashes) {
|
|
|
252
258
|
|
|
253
259
|
function recordGeneratedHash(filePath, content) {
|
|
254
260
|
const hashes = readGeneratedHashes(filePath);
|
|
255
|
-
hashes[path.basename(filePath)] =
|
|
261
|
+
hashes[path.basename(filePath)] = sha256Text(content);
|
|
256
262
|
writeGeneratedHashes(filePath, hashes);
|
|
257
263
|
}
|
|
258
264
|
|
|
259
|
-
function sha256Text(content) {
|
|
260
|
-
return require('crypto').createHash('sha256').update(content).digest('hex');
|
|
261
|
-
}
|
|
262
|
-
|
|
263
265
|
function snapshotContextFile(filePath) {
|
|
264
266
|
if (!CONTEXT_WRITE_LEGACY || !fs.existsSync(filePath)) return;
|
|
265
267
|
const rel = path.relative(CONTEXT_WRITE_LEGACY.root, filePath);
|
|
@@ -300,8 +302,8 @@ function writeContextFile(filePath, content, { overwrite = true } = {}) {
|
|
|
300
302
|
|
|
301
303
|
// After a non-destructive refresh: remove AEL-managed files this version no
|
|
302
304
|
// longer generates. Normal flow: only files whose recorded hash still matches
|
|
303
|
-
// (edited ones are reported and kept)
|
|
304
|
-
//
|
|
305
|
+
// (edited ones are reported and kept); removed files are snapshotted first
|
|
306
|
+
// during a legacy refresh.
|
|
305
307
|
function removeObsoleteContextFiles(contextDir) {
|
|
306
308
|
const root = path.resolve(contextDir);
|
|
307
309
|
const candidates = new Map();
|
|
@@ -322,12 +324,6 @@ function removeObsoleteContextFiles(contextDir) {
|
|
|
322
324
|
candidates.set(path.join(dir, name), { hash, dir, name });
|
|
323
325
|
}
|
|
324
326
|
}
|
|
325
|
-
if (CONTEXT_WRITE_LEGACY) {
|
|
326
|
-
for (const rel of OBSOLETE_CONTEXT_FILES) {
|
|
327
|
-
const abs = path.resolve(root, rel);
|
|
328
|
-
if (abs.startsWith(root + path.sep)) candidates.set(abs, { hash: null, dir: path.dirname(abs), name: path.basename(abs), legacy: true });
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
327
|
for (const [abs, info] of candidates) {
|
|
332
328
|
if (CONTEXT_WRITE_REPORT.seen.has(abs)) continue;
|
|
333
329
|
const rel = path.relative(root, abs).split(path.sep).join('/');
|
|
@@ -338,7 +334,7 @@ function removeObsoleteContextFiles(contextDir) {
|
|
|
338
334
|
stat = null;
|
|
339
335
|
}
|
|
340
336
|
if (stat && stat.isFile()) {
|
|
341
|
-
if (
|
|
337
|
+
if (sha256Text(fs.readFileSync(abs)) !== info.hash) {
|
|
342
338
|
CONTEXT_WRITE_REPORT.obsoleteKept.push(rel);
|
|
343
339
|
continue;
|
|
344
340
|
}
|
|
@@ -399,7 +395,7 @@ function readFileSafe(filePath) {
|
|
|
399
395
|
function getFileChecksum(filePath) {
|
|
400
396
|
const content = readFileSafe(filePath);
|
|
401
397
|
if (!content) return null;
|
|
402
|
-
return
|
|
398
|
+
return sha256Text(content).slice(0, 16);
|
|
403
399
|
}
|
|
404
400
|
|
|
405
401
|
/**
|
|
@@ -501,6 +497,14 @@ function analyzeRepository(rootDir) {
|
|
|
501
497
|
const pm = discovery.packageManager;
|
|
502
498
|
if (scripts['test:unit']) discovery.scripts.testUnit = `${pm} run test:unit`;
|
|
503
499
|
else if (scripts['test']) discovery.scripts.testUnit = `${pm} test`;
|
|
500
|
+
// Fast verification lane (`verify --related`): the runner's own
|
|
501
|
+
// related-test selection, through the project's test script when it has one.
|
|
502
|
+
const testScript = scripts['test:unit'] ? 'test:unit' : (scripts['test'] ? 'test' : null);
|
|
503
|
+
const viaScript = (extra) => (testScript ? `${pm} run ${testScript}${pm === 'npm' ? ' --' : ''} ${extra}` : null);
|
|
504
|
+
if (allDeps['vitest']) discovery.scripts.testRelated = `npx vitest related --run --passWithNoTests {files}`;
|
|
505
|
+
else if (allDeps['jest'] || allDeps['ts-jest']) {
|
|
506
|
+
discovery.scripts.testRelated = viaScript('--findRelatedTests --passWithNoTests {files}') || 'npx jest --findRelatedTests --passWithNoTests {files}';
|
|
507
|
+
}
|
|
504
508
|
|
|
505
509
|
if (scripts['typecheck']) discovery.scripts.typecheck = `${pm} run typecheck`;
|
|
506
510
|
else if (scripts['type-check']) discovery.scripts.typecheck = `${pm} run type-check`;
|
|
@@ -664,6 +668,7 @@ ${discovery.topLevelDirs.map((d) => `- \`${d}/\``).join('\n') || '- Flat directo
|
|
|
664
668
|
- **lint**: \`${discovery.scripts.lint}\`
|
|
665
669
|
- **build**: \`${discovery.scripts.build}\`
|
|
666
670
|
${discovery.scripts.e2e ? `- **e2e**: \`${discovery.scripts.e2e}\`` : ''}
|
|
671
|
+
${discovery.scripts.testRelated ? `- **test_related**: \`${discovery.scripts.testRelated}\`` : ''}
|
|
667
672
|
|
|
668
673
|
## Verification Protocol
|
|
669
674
|
- Default order, cheapest first, stop at the first failure: build -> typecheck -> lint -> test_unit -> security scan (for example \`npm audit --omit=dev\`) -> e2e (optional).
|
|
@@ -1252,6 +1257,27 @@ function detectGrokHost() {
|
|
|
1252
1257
|
}
|
|
1253
1258
|
}
|
|
1254
1259
|
|
|
1260
|
+
// Top lessons from earlier Runs (learn.js), ranked for the files in play.
|
|
1261
|
+
function runLearnings() {
|
|
1262
|
+
try {
|
|
1263
|
+
const { selectLearnings } = require('../lib/learn.js');
|
|
1264
|
+
return selectLearnings(CWD, { files: workingTreePaths(CWD), budgetTokens: 600, limit: 5 }).learnings;
|
|
1265
|
+
} catch {
|
|
1266
|
+
return [];
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// Lessons are mined when a Run ends (delivered or escalated), so the next Run
|
|
1271
|
+
// sees them without a manual `learn`. Best effort: never fails the gate.
|
|
1272
|
+
function autoLearn(run) {
|
|
1273
|
+
if (!run || !['DELIVERED', 'ESCALATED'].includes(run.state) || process.env.AEL_NO_AUTO_LEARN === '1') return;
|
|
1274
|
+
try {
|
|
1275
|
+
learn(CWD, {});
|
|
1276
|
+
} catch (err) {
|
|
1277
|
+
console.error(`! learnings not updated: ${err.message}`);
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1255
1281
|
function workingTreePaths(rootDir) {
|
|
1256
1282
|
try {
|
|
1257
1283
|
return execSync('git status --porcelain --untracked-files=all', { cwd: rootDir, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })
|
|
@@ -1450,6 +1476,8 @@ function handleRun() {
|
|
|
1450
1476
|
const h = hostSkillStatus({ home: homeDir(), version: VERSION });
|
|
1451
1477
|
return { stale: h.stale, staleFiles: h.staleFiles, installedVersion: h.installedVersion, packageVersion: VERSION };
|
|
1452
1478
|
})(),
|
|
1479
|
+
learnings: runLearnings(),
|
|
1480
|
+
...specHintField(runResult),
|
|
1453
1481
|
studioUrl: readStudioUrl(CWD)
|
|
1454
1482
|
}, null, 2));
|
|
1455
1483
|
return;
|
|
@@ -1459,6 +1487,8 @@ function handleRun() {
|
|
|
1459
1487
|
const t = runResult.run.tier;
|
|
1460
1488
|
console.log(`- Tier: ${t.current} (${t.source}; ${t.reasons.map((r) => r.code).join(', ')})`);
|
|
1461
1489
|
}
|
|
1490
|
+
const hint = specHintField(runResult).specHint;
|
|
1491
|
+
if (hint) console.log(`- Spec: ${hint}`);
|
|
1462
1492
|
console.log(`- State: ${runResult.run.state}, iteration ${runResult.run.iteration}`);
|
|
1463
1493
|
console.log(`- Mode: ${runResult.run.mode || RUN_MODES.ASSISTED}`);
|
|
1464
1494
|
if (runResult.run.workflow) {
|
|
@@ -1849,6 +1879,7 @@ function executeGate(gate, runId) {
|
|
|
1849
1879
|
: applyGate(CWD, gate, { runId: target.runId });
|
|
1850
1880
|
if (gate === 'goal') ensureImpactMap(target.runId);
|
|
1851
1881
|
if (gate === 'verification') recordImpactDrift(target.runId);
|
|
1882
|
+
autoLearn(run);
|
|
1852
1883
|
const runCompleted = run.state === 'DELIVERED' || run.state === 'REPORTED';
|
|
1853
1884
|
appendRunLifecycle(CWD, target.runId, {
|
|
1854
1885
|
type: runCompleted
|
|
@@ -1863,6 +1894,34 @@ function executeGate(gate, runId) {
|
|
|
1863
1894
|
return run;
|
|
1864
1895
|
}
|
|
1865
1896
|
|
|
1897
|
+
const FREEZE_QUESTION = /^Freeze Goal draft revision \d+/;
|
|
1898
|
+
|
|
1899
|
+
// The freeze answers the pending freeze question(s) that `goal draft` asked,
|
|
1900
|
+
// so Studio does not keep showing them. Best effort.
|
|
1901
|
+
function closeFreezeQuestions(runId, actor) {
|
|
1902
|
+
try {
|
|
1903
|
+
const { listRunInteractions, appendRunAnswer } = require('../lib/run-interactions.js');
|
|
1904
|
+
for (const question of listRunInteractions(CWD, runId).pending) {
|
|
1905
|
+
if (FREEZE_QUESTION.test(question.message)) {
|
|
1906
|
+
appendRunAnswer(CWD, runId, question.questionId, { message: 'Goal frozen', actor });
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
} catch (err) {
|
|
1910
|
+
console.error(`! freeze question not closed: ${err.message}`);
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
// Blast radius of a Goal draft, so the human sees it with the Goal and can
|
|
1915
|
+
// confirm both in one stop (`goal freeze --confirm-impact`). Best effort.
|
|
1916
|
+
function impactPreview(runId, goal) {
|
|
1917
|
+
try {
|
|
1918
|
+
const map = impactMap.buildImpactMap(CWD, { run: loadRun(CWD, runId), goal });
|
|
1919
|
+
return { files: (map.files || []).map((file) => file.path), tests: (map.tests || []).map((t) => t.path || t).slice(0, 10) };
|
|
1920
|
+
} catch (err) {
|
|
1921
|
+
return { error: err.message };
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1866
1925
|
// Blast-radius map (#71): written into the Run once the Goal is frozen, so it
|
|
1867
1926
|
// exists before Stage 3. Best effort: a scan failure never blocks a gate.
|
|
1868
1927
|
function ensureImpactMap(runId) {
|
|
@@ -1913,6 +1972,15 @@ function captureMakerDiff(run) {
|
|
|
1913
1972
|
return { path: path.relative(CWD, target).split(path.sep).join('/'), files: untracked.length };
|
|
1914
1973
|
}
|
|
1915
1974
|
|
|
1975
|
+
function reviewLedgerBinding(run) {
|
|
1976
|
+
try {
|
|
1977
|
+
const ledger = JSON.parse(fs.readFileSync(path.join(CWD, '.ai-engineering-loop', 'runs', run.runId, 'findings.json'), 'utf8'));
|
|
1978
|
+
return require('../lib/review-ingest.js').checkLedgerBinding(CWD, run, ledger).binding;
|
|
1979
|
+
} catch {
|
|
1980
|
+
return null;
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1916
1984
|
function handleGate() {
|
|
1917
1985
|
const gate = process.argv[3];
|
|
1918
1986
|
const runId = argValue('--run');
|
|
@@ -1928,6 +1996,7 @@ function handleGate() {
|
|
|
1928
1996
|
}
|
|
1929
1997
|
const run = executeGate(gate, target.runId);
|
|
1930
1998
|
const judge = gate === 'review' && run.tier ? judgeRequirement(CWD, run) : null;
|
|
1999
|
+
const ledgerBinding = gate === 'review' ? reviewLedgerBinding(run) : null;
|
|
1931
2000
|
const guardEvents = guard.guardSummary(CWD, run.runId);
|
|
1932
2001
|
if (json) {
|
|
1933
2002
|
console.log(JSON.stringify({
|
|
@@ -1938,6 +2007,7 @@ function handleGate() {
|
|
|
1938
2007
|
gate,
|
|
1939
2008
|
...(run.tier ? { tier: run.tier.current } : {}),
|
|
1940
2009
|
...(judge ? { judgeRequired: judge.required, judgeReasons: judge.reasons } : {}),
|
|
2010
|
+
...(ledgerBinding ? { ledgerBinding } : {}),
|
|
1941
2011
|
guard: guardEvents
|
|
1942
2012
|
}));
|
|
1943
2013
|
} else {
|
|
@@ -1948,6 +2018,9 @@ function handleGate() {
|
|
|
1948
2018
|
if (guardEvents.warn || guardEvents.block) {
|
|
1949
2019
|
console.log(`- Guard: ${guardEvents.block} blocked, ${guardEvents.warn} warned (${guardEvents.rules.join(', ')}); see guard-events.json`);
|
|
1950
2020
|
}
|
|
2021
|
+
if (ledgerBinding === 'UNBOUND') {
|
|
2022
|
+
console.log('- Ledger: UNBOUND (hand-written findings.json). Prefer `review ingest` so the ledger is bound to the reviewer output.');
|
|
2023
|
+
}
|
|
1951
2024
|
if (judge) {
|
|
1952
2025
|
console.log(judge.required
|
|
1953
2026
|
? `- Judge: REQUIRED (${judge.reasons.join('; ')}). Spawn the Judge subagent, write verdict.json, then gate judge.`
|
|
@@ -2985,7 +3058,7 @@ function requiredIntegerArg(name) {
|
|
|
2985
3058
|
|
|
2986
3059
|
function readBoundedJsonInput(fileName) {
|
|
2987
3060
|
if (!fileName) {
|
|
2988
|
-
const error = new Error('goal draft requires --file <json>');
|
|
3061
|
+
const error = new Error('goal draft requires --file <json> or --from-design <doc.md>');
|
|
2989
3062
|
error.code = 'INVALID_USAGE';
|
|
2990
3063
|
throw error;
|
|
2991
3064
|
}
|
|
@@ -3005,13 +3078,32 @@ function readBoundedJsonInput(fileName) {
|
|
|
3005
3078
|
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
3006
3079
|
}
|
|
3007
3080
|
|
|
3081
|
+
// Spec pack hint (#99): once, when a new Run starts at T2. T0/T1 and resumed
|
|
3082
|
+
// Runs get nothing, so their output is unchanged.
|
|
3083
|
+
function specHintField(runResult) {
|
|
3084
|
+
const run = runResult.run;
|
|
3085
|
+
if (runResult.resumed || run.tier?.current !== 'T2') return {};
|
|
3086
|
+
let installed = false;
|
|
3087
|
+
try {
|
|
3088
|
+
installed = hostSkillStatus({ home: homeDir(), version: VERSION }).packs.includes('spec');
|
|
3089
|
+
} catch {
|
|
3090
|
+
installed = false;
|
|
3091
|
+
}
|
|
3092
|
+
return {
|
|
3093
|
+
specHint: 'For a new feature or architecture change, design first: ael-spec-brainstorm -> ael-spec-draft -> ael-spec-review, then `goal draft --from-design docs/designs/<name>.md`.' +
|
|
3094
|
+
(installed ? '' : ' Install with `sync-hosts --pack spec`.')
|
|
3095
|
+
};
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3008
3098
|
function handleGoal() {
|
|
3009
3099
|
const action = args[1] || 'show';
|
|
3010
3100
|
try {
|
|
3011
3101
|
const runId = requiredRunId('goal');
|
|
3012
3102
|
let result;
|
|
3103
|
+
const extra = {};
|
|
3013
3104
|
if (action === 'show') {
|
|
3014
3105
|
result = loadGoalDraft(CWD, runId);
|
|
3106
|
+
if (result?.contract?.designRef) extra.design = require('../lib/design-ref.js').designStatus(CWD, result.contract.designRef);
|
|
3015
3107
|
} else if (action === 'draft') {
|
|
3016
3108
|
appendRunLifecycle(CWD, runId, {
|
|
3017
3109
|
type: 'GOAL_DRAFTING',
|
|
@@ -3019,10 +3111,29 @@ function handleGoal() {
|
|
|
3019
3111
|
actor: argValue('--by') || 'agent',
|
|
3020
3112
|
message: argValue('--message') || 'Updating the Goal draft'
|
|
3021
3113
|
});
|
|
3022
|
-
|
|
3114
|
+
const designFile = argValue('--from-design');
|
|
3115
|
+
let draftGoal;
|
|
3116
|
+
if (designFile) {
|
|
3117
|
+
const designRef = require('../lib/design-ref.js');
|
|
3118
|
+
const doc = designRef.readDesignDoc(CWD, designFile);
|
|
3119
|
+
const parsed = designRef.parseDesignDoc(doc.text);
|
|
3120
|
+
draftGoal = argValue('--file')
|
|
3121
|
+
? { ...readBoundedJsonInput(argValue('--file')), designRef: designRef.designRefFrom(doc, parsed) }
|
|
3122
|
+
: designRef.draftFromDesign(doc, parsed);
|
|
3123
|
+
extra.design = {
|
|
3124
|
+
path: doc.path,
|
|
3125
|
+
targetFiles: parsed.targetFiles.length,
|
|
3126
|
+
placeholders: designRef.placeholderRows(draftGoal),
|
|
3127
|
+
warnings: parsed.warnings
|
|
3128
|
+
};
|
|
3129
|
+
} else {
|
|
3130
|
+
draftGoal = readBoundedJsonInput(argValue('--file'));
|
|
3131
|
+
}
|
|
3132
|
+
result = saveGoalDraft(CWD, runId, draftGoal, {
|
|
3023
3133
|
actor: argValue('--by') || 'agent',
|
|
3024
3134
|
expectedRevision: requiredIntegerArg('--revision')
|
|
3025
3135
|
});
|
|
3136
|
+
extra.impactPreview = impactPreview(runId, draftGoal);
|
|
3026
3137
|
appendRunLifecycle(CWD, runId, {
|
|
3027
3138
|
type: 'GOAL_DRAFT_UPDATED',
|
|
3028
3139
|
phase: 'goal',
|
|
@@ -3035,6 +3146,17 @@ function handleGoal() {
|
|
|
3035
3146
|
actor: argValue('--by') || 'agent',
|
|
3036
3147
|
message: `Goal draft revision ${result.metadata.revision} is ready for review`
|
|
3037
3148
|
});
|
|
3149
|
+
// The freeze question is persisted with the draft, so Studio shows it
|
|
3150
|
+
// without a separate `interaction question` call.
|
|
3151
|
+
try {
|
|
3152
|
+
extra.question = appendRunQuestion(CWD, runId, {
|
|
3153
|
+
message: `Freeze Goal draft revision ${result.metadata.revision} (and accept its blast radius)?`,
|
|
3154
|
+
actor: argValue('--by') || 'agent'
|
|
3155
|
+
});
|
|
3156
|
+
appendRunLifecycle(CWD, runId, { type: 'AGENT_WAITING', phase: 'goal', actor: argValue('--by') || 'agent', message: `Waiting for answer to Q${extra.question.number}` });
|
|
3157
|
+
} catch (err) {
|
|
3158
|
+
extra.question = { error: err.message };
|
|
3159
|
+
}
|
|
3038
3160
|
} else if (action === 'freeze') {
|
|
3039
3161
|
const latest = process.argv.includes('--latest');
|
|
3040
3162
|
const latestDraft = latest ? loadGoalDraft(CWD, runId) : null;
|
|
@@ -3076,12 +3198,19 @@ function handleGoal() {
|
|
|
3076
3198
|
message: 'Goal Contract frozen'
|
|
3077
3199
|
});
|
|
3078
3200
|
ensureImpactMap(runId);
|
|
3201
|
+
closeFreezeQuestions(runId, argValue('--by') || 'human');
|
|
3202
|
+
// One human stop: the same person accepts the Goal and its blast radius
|
|
3203
|
+
// (shown as impactPreview with the draft).
|
|
3204
|
+
if (process.argv.includes('--confirm-impact')) {
|
|
3205
|
+
const confirmed = impactMap.confirmImpactMap(CWD, { runId, by: argValue('--by') || 'human' });
|
|
3206
|
+
extra.impact = { status: confirmed.map ? confirmed.map.status : 'CONFIRMED' };
|
|
3207
|
+
}
|
|
3079
3208
|
} else {
|
|
3080
3209
|
const error = new Error('goal must be show, draft, or freeze');
|
|
3081
3210
|
error.code = 'INVALID_USAGE';
|
|
3082
3211
|
throw error;
|
|
3083
3212
|
}
|
|
3084
|
-
console.log(JSON.stringify({ ok: true, runId, [action === 'show' ? 'draft' : 'result']: result }, null, 2));
|
|
3213
|
+
console.log(JSON.stringify({ ok: true, runId, [action === 'show' ? 'draft' : 'result']: result, ...extra }, null, 2));
|
|
3085
3214
|
} catch (error) {
|
|
3086
3215
|
log.error(`${error.code || 'GOAL_FAILED'}: ${error.message}`);
|
|
3087
3216
|
process.exitCode = 1;
|
|
@@ -3257,20 +3386,61 @@ async function handleVerify() {
|
|
|
3257
3386
|
try {
|
|
3258
3387
|
const runId = requiredRunId('verify');
|
|
3259
3388
|
const shell = process.argv.includes('--shell');
|
|
3389
|
+
const related = process.argv.includes('--related');
|
|
3390
|
+
const final = process.argv.includes('--final');
|
|
3391
|
+
if (related && final) throw Object.assign(new Error('--related and --final cannot be combined'), { code: 'INVALID_USAGE' });
|
|
3260
3392
|
let texts = repeatedArg('--cmd');
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3393
|
+
const lanes = require('../lib/verification-lanes.js');
|
|
3394
|
+
let commandsToRun;
|
|
3395
|
+
if (related && texts.length === 0) {
|
|
3396
|
+
const target = loadRun(CWD, runId);
|
|
3397
|
+
commandsToRun = [lanes.relatedCommand(CWD, target, { split: splitCommand, shell })];
|
|
3398
|
+
} else {
|
|
3399
|
+
if (texts.length === 0) {
|
|
3400
|
+
const fallback = defaultVerificationCommand();
|
|
3401
|
+
if (!fallback) throw Object.assign(new Error('No --cmd given and no test_unit command in .ai-engineering-loop/verification.md'), { code: 'INVALID_COMMAND' });
|
|
3402
|
+
texts = [fallback];
|
|
3403
|
+
}
|
|
3404
|
+
commandsToRun = texts.map((text) => splitCommand(text, shell));
|
|
3265
3405
|
}
|
|
3266
3406
|
const timeoutValue = argValue('--timeout-ms');
|
|
3407
|
+
if (final) {
|
|
3408
|
+
const target = loadRun(CWD, runId);
|
|
3409
|
+
if (target.state !== 'JUDGED_PASS') throw Object.assign(new Error(`verify --final needs a Judge PASS (state is ${target.state})`), { code: 'INVALID_STATE' });
|
|
3410
|
+
const status = lanes.finalVerificationStatus(CWD, target);
|
|
3411
|
+
let recordedFinal = null;
|
|
3412
|
+
if (status.required && !status.satisfied) {
|
|
3413
|
+
recordedFinal = await recordVerificationCommands(CWD, {
|
|
3414
|
+
runId,
|
|
3415
|
+
commands: commandsToRun,
|
|
3416
|
+
target: 'final',
|
|
3417
|
+
fresh: process.argv.includes('--fresh'),
|
|
3418
|
+
serial: process.argv.includes('--serial'),
|
|
3419
|
+
...(timeoutValue == null ? {} : { timeoutMs: parsePositiveIntegerArg('--timeout-ms', timeoutValue) })
|
|
3420
|
+
});
|
|
3421
|
+
}
|
|
3422
|
+
const result = {
|
|
3423
|
+
ok: recordedFinal ? recordedFinal.passed : true,
|
|
3424
|
+
runId,
|
|
3425
|
+
final: recordedFinal
|
|
3426
|
+
? { path: recordedFinal.path, commands: recordedFinal.commands.map((c) => ({ command: c.command, exitCode: c.exitCode, reused: Boolean(c.reused) })) }
|
|
3427
|
+
: { reused: true, reason: status.reason }
|
|
3428
|
+
};
|
|
3429
|
+
if (json) console.log(JSON.stringify(result));
|
|
3430
|
+
else if (result.ok) log.success(`✓ final verification ${recordedFinal ? 'passed' : `not needed (${status.reason})`}; deliver next`);
|
|
3431
|
+
else log.error('Final verification failed; fix it before delivery.');
|
|
3432
|
+
if (!result.ok) process.exitCode = 1;
|
|
3433
|
+
return;
|
|
3434
|
+
}
|
|
3267
3435
|
const recorded = await recordVerificationCommands(CWD, {
|
|
3268
3436
|
runId,
|
|
3269
|
-
commands:
|
|
3437
|
+
commands: commandsToRun,
|
|
3270
3438
|
serial: process.argv.includes('--serial'),
|
|
3439
|
+
fresh: process.argv.includes('--fresh'),
|
|
3440
|
+
...(related ? { scope: 'related' } : {}),
|
|
3271
3441
|
...(timeoutValue == null ? {} : { timeoutMs: parsePositiveIntegerArg('--timeout-ms', timeoutValue) })
|
|
3272
3442
|
});
|
|
3273
|
-
const commands = recorded.commands.map((c) => ({ command: c.command, exitCode: c.exitCode, timeoutStatus: c.timeoutStatus }));
|
|
3443
|
+
const commands = recorded.commands.map((c) => ({ command: c.command, exitCode: c.exitCode, timeoutStatus: c.timeoutStatus, ...(c.scope ? { scope: c.scope } : {}), ...(c.reused ? { reused: true } : {}) }));
|
|
3274
3444
|
if (!recorded.passed) {
|
|
3275
3445
|
autoHeartbeat(runId, 'verification', 'Verification failed; Maker must fix before review');
|
|
3276
3446
|
const result = { ok: false, code: 'VERIFICATION_FAILED', runId, commands, gate: null };
|
|
@@ -3301,6 +3471,7 @@ async function handleVerify() {
|
|
|
3301
3471
|
impactDrift: { mapStatus: drift.mapStatus, outOfMap: drift.outOfMap },
|
|
3302
3472
|
compact: compact.paths,
|
|
3303
3473
|
claimedVsReality: claimed,
|
|
3474
|
+
...(related ? { scope: 'related', finalRequired: 'Run `verify --final` after Judge PASS, before delivery.' } : {}),
|
|
3304
3475
|
next: run.tier && run.tier.current === 'T0'
|
|
3305
3476
|
? 'Fill claimed-vs-reality, then gate review and gate judge'
|
|
3306
3477
|
: 'Fill claimed-vs-reality, then review-pack and spawn the Devil\'s Advocate'
|
|
@@ -3364,7 +3535,8 @@ function handleGuard() {
|
|
|
3364
3535
|
} catch (err) {
|
|
3365
3536
|
if (hook) {
|
|
3366
3537
|
console.error(`ai-engineering-loop guard: ${err.message}`);
|
|
3367
|
-
|
|
3538
|
+
// Exit 2 makes Claude Code block the call; exit 1 would let it run.
|
|
3539
|
+
process.exitCode = guard.hookFailureExitCode(CWD, argValue('--run'));
|
|
3368
3540
|
return;
|
|
3369
3541
|
}
|
|
3370
3542
|
stageJsonError(err, json, 'GUARD_FAILED');
|
|
@@ -3492,6 +3664,7 @@ function handleReviewPack() {
|
|
|
3492
3664
|
if (result.impactDrift?.outOfMap.length) {
|
|
3493
3665
|
console.log(`- Outside the impact map: ${result.impactDrift.outOfMap.join(', ')} (check their side effects)`);
|
|
3494
3666
|
}
|
|
3667
|
+
for (const line of result.impactDrift?.design || []) console.log(`- ${line}`);
|
|
3495
3668
|
}
|
|
3496
3669
|
} catch (err) {
|
|
3497
3670
|
stageJsonError(err, json, 'REVIEW_PACK_FAILED');
|
|
@@ -3678,6 +3851,83 @@ function handleBench() {
|
|
|
3678
3851
|
}
|
|
3679
3852
|
}
|
|
3680
3853
|
|
|
3854
|
+
// Command: review ingest (ledger bound to the reviewer output; lib/review-ingest.js)
|
|
3855
|
+
// Writes findings.json from the raw child output, gates review, and gates the
|
|
3856
|
+
// Judge too when the deterministic verdict is allowed.
|
|
3857
|
+
function handleReview() {
|
|
3858
|
+
const json = process.argv.includes('--json');
|
|
3859
|
+
try {
|
|
3860
|
+
if (process.argv[3] !== 'ingest') throw Object.assign(new Error('Usage: review ingest --run <id> --child-id <id> --file <child-output>'), { code: 'INVALID_USAGE' });
|
|
3861
|
+
const { ingestReview } = require('../lib/review-ingest.js');
|
|
3862
|
+
const ingested = ingestReview(CWD, { runId: argValue('--run'), childId: argValue('--child-id'), file: argValue('--file') });
|
|
3863
|
+
let run = executeGate('review', ingested.runId);
|
|
3864
|
+
const judge = run.tier ? judgeRequirement(CWD, run) : { required: true, reasons: ['NO_TIER'] };
|
|
3865
|
+
if (!judge.required) run = executeGate('judge', ingested.runId);
|
|
3866
|
+
const result = {
|
|
3867
|
+
ok: true,
|
|
3868
|
+
runId: run.runId,
|
|
3869
|
+
state: run.state,
|
|
3870
|
+
iteration: run.iteration,
|
|
3871
|
+
findings: ingested.findings,
|
|
3872
|
+
ledgerBinding: 'BOUND',
|
|
3873
|
+
judgeRequired: judge.required,
|
|
3874
|
+
judgeReasons: judge.reasons,
|
|
3875
|
+
next: judge.required
|
|
3876
|
+
? 'Spawn the Judge with the ledger and contract, write verdict.json, then gate judge.'
|
|
3877
|
+
: (run.state === 'JUDGED_PASS' ? 'Deliver after human approval.' : `Judge returned ${run.state}; fix and re-verify.`)
|
|
3878
|
+
};
|
|
3879
|
+
if (json) console.log(JSON.stringify(result));
|
|
3880
|
+
else {
|
|
3881
|
+
log.success(`✓ review ingested (${ingested.findings} finding(s), bound to the reviewer output)`);
|
|
3882
|
+
console.log(`- State: ${run.state}, iteration ${run.iteration}`);
|
|
3883
|
+
console.log(`- Next: ${result.next}`);
|
|
3884
|
+
}
|
|
3885
|
+
} catch (err) {
|
|
3886
|
+
stageJsonError(err, json, 'REVIEW_INGEST_FAILED');
|
|
3887
|
+
}
|
|
3888
|
+
}
|
|
3889
|
+
|
|
3890
|
+
// Command: quick start|finish (T0 in two calls; lib/quick.js)
|
|
3891
|
+
function handleQuick() {
|
|
3892
|
+
const action = process.argv[3];
|
|
3893
|
+
const json = process.argv.includes('--json');
|
|
3894
|
+
const { startQuick, finishQuick } = require('../lib/quick.js');
|
|
3895
|
+
try {
|
|
3896
|
+
let result;
|
|
3897
|
+
if (action === 'start') {
|
|
3898
|
+
const valued = new Set(['--mode', '--run', '--cmd', '--timeout-ms']);
|
|
3899
|
+
const words = [];
|
|
3900
|
+
for (let index = 4; index < process.argv.length; index += 1) {
|
|
3901
|
+
const arg = process.argv[index];
|
|
3902
|
+
if (valued.has(arg)) { index += 1; continue; }
|
|
3903
|
+
if (arg.startsWith('--')) continue;
|
|
3904
|
+
words.push(arg);
|
|
3905
|
+
}
|
|
3906
|
+
result = startQuick(CWD, { task: words.join(' '), mode: argValue('--mode') });
|
|
3907
|
+
} else if (action === 'finish') {
|
|
3908
|
+
const timeoutValue = argValue('--timeout-ms');
|
|
3909
|
+
result = finishQuick(CWD, {
|
|
3910
|
+
runId: argValue('--run'),
|
|
3911
|
+
commands: repeatedArg('--cmd'),
|
|
3912
|
+
shell: process.argv.includes('--shell'),
|
|
3913
|
+
serial: process.argv.includes('--serial'),
|
|
3914
|
+
timeoutMs: timeoutValue == null ? null : parsePositiveIntegerArg('--timeout-ms', timeoutValue)
|
|
3915
|
+
});
|
|
3916
|
+
} else {
|
|
3917
|
+
throw Object.assign(new Error('Usage: quick start "<task>" [--mode assisted] | quick finish [--run <id>] [--cmd "<command>"]...'), { code: 'INVALID_USAGE' });
|
|
3918
|
+
}
|
|
3919
|
+
if (json) console.log(JSON.stringify(result));
|
|
3920
|
+
else {
|
|
3921
|
+
(result.ok ? log.success : log.warn)(`${result.ok ? '✓' : '!'} quick ${action}: Run ${result.runId} (${result.tier}${result.state ? `, ${result.state}` : ''})`);
|
|
3922
|
+
for (const item of result.learnings || []) console.log(`- Learning [${item.severity}]: ${item.lesson}`);
|
|
3923
|
+
console.log(`- Next: ${result.next}`);
|
|
3924
|
+
}
|
|
3925
|
+
if (!result.ok) process.exitCode = 1;
|
|
3926
|
+
} catch (err) {
|
|
3927
|
+
stageJsonError(err, json, 'QUICK_FAILED');
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
|
|
3681
3931
|
function handleLearn() {
|
|
3682
3932
|
const json = process.argv.includes('--json');
|
|
3683
3933
|
try {
|
|
@@ -3758,6 +4008,7 @@ Commands:
|
|
|
3758
4008
|
goal Share one revision-bound Goal draft between the Agent and Studio
|
|
3759
4009
|
show [--run <id>]
|
|
3760
4010
|
draft --file <json> --revision <n> [--run <id>] [--by <agent>]
|
|
4011
|
+
draft --from-design <doc.md> [--file <json>] --revision <n> prefill from a design doc, record designRef
|
|
3761
4012
|
freeze --revision <n> --hash <sha256> [--run <id>] [--by <name>]
|
|
3762
4013
|
freeze --latest [--run <id>] --by <name> freeze the newest draft (CLI resolves revision/hash)
|
|
3763
4014
|
verification Summarize verification.json for compact Judge context
|
|
@@ -3835,9 +4086,18 @@ Commands:
|
|
|
3835
4086
|
escalation Compute the minimum Judge model tier from deterministic risk signals
|
|
3836
4087
|
--run <id> target a non-current run
|
|
3837
4088
|
--json print machine-readable reasons
|
|
4089
|
+
review ingest --run <id> --child-id <id> --file <child-output> [--json]
|
|
4090
|
+
bind findings.json to the Devil's Advocate output, gate review, and gate the
|
|
4091
|
+
Judge too when the deterministic verdict is allowed
|
|
4092
|
+
quick T0 in two calls: start creates the Run and a derived Goal; finish gates the
|
|
4093
|
+
working-tree diff, verifies, writes claimed-vs-reality, and runs review + judge
|
|
4094
|
+
start "<task>" [--mode assisted|unattended] | finish [--run <id>] [--cmd "<command>"]...
|
|
3838
4095
|
verify Record verification commands, gate them, compact, and scaffold claimed-vs-reality
|
|
3839
|
-
[--run <id>] [--cmd "<command>"]... [--shell] [--serial] [--timeout-ms <n>] [--json]
|
|
4096
|
+
[--run <id>] [--cmd "<command>"]... [--shell] [--serial] [--timeout-ms <n>] [--fresh] [--json]
|
|
3840
4097
|
default command: test_unit from .ai-engineering-loop/verification.md; commands run in parallel
|
|
4098
|
+
--related fast lane: test_related with {files} = changed files of the gated diff
|
|
4099
|
+
--final after Judge PASS: full run delivery needs when verification was related-only
|
|
4100
|
+
--fresh re-run commands that already passed for the same diff and revision
|
|
3841
4101
|
impact Blast-radius map of the frozen Goal before Stage 3 (written to the Run on Goal freeze)
|
|
3842
4102
|
map [--run <id>] [--limit <n>] [--force] [--json] files, modules, endpoints, DB tables, tests
|
|
3843
4103
|
show [--run <id>] [--json]
|
|
@@ -4056,6 +4316,12 @@ switch (command) {
|
|
|
4056
4316
|
case 'learn':
|
|
4057
4317
|
handleLearn();
|
|
4058
4318
|
break;
|
|
4319
|
+
case 'quick':
|
|
4320
|
+
handleQuick();
|
|
4321
|
+
break;
|
|
4322
|
+
case 'review':
|
|
4323
|
+
handleReview();
|
|
4324
|
+
break;
|
|
4059
4325
|
case 'verify-receipt':
|
|
4060
4326
|
handleVerifyReceipt();
|
|
4061
4327
|
break;
|