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
package/lib/tier.js
CHANGED
|
@@ -41,26 +41,52 @@ function changedLineCount(diff) {
|
|
|
41
41
|
return count;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const MANIFEST_PATH = /(^|\/)(package\.json|package-lock\.json|npm-shrinkwrap\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb?|go\.(mod|sum)|requirements[^/]*\.txt|Pipfile(\.lock)?|pyproject\.toml|poetry\.lock|uv\.lock|Cargo\.(toml|lock)|composer\.(json|lock)|Gemfile(\.lock)?|pom\.xml|build\.gradle(\.kts)?|gradle\.lockfile|Podfile(\.lock)?|pubspec\.(yaml|lock))$/i;
|
|
45
|
+
|
|
46
|
+
// Classify from the paths already known (working tree at `run`, Maker diff
|
|
47
|
+
// later) first, then the task text. Returns { tier, reasons: [{ code, detail }] }.
|
|
48
|
+
// - Risky paths and many files are T2 whatever the text says.
|
|
49
|
+
// - Known, docs-only paths are T0 even when the text names a risky topic
|
|
50
|
+
// ("fix typo in the auth README").
|
|
51
|
+
// - A dependency manifest or lockfile is never T0 ("bump" is not trivial there).
|
|
52
|
+
// - Without paths, text that is both trivial and risky is T1; the Maker diff
|
|
53
|
+
// raises it to T2 if risky paths appear.
|
|
46
54
|
function classifyTier({ task = '', changedPaths = [], changedLines = null } = {}) {
|
|
47
55
|
const reasons = [];
|
|
48
|
-
|
|
49
|
-
const
|
|
56
|
+
// Prose under a risky directory (docs/auth.md) is still prose.
|
|
57
|
+
const riskyPaths = changedPaths.filter((p) => isHighRiskPath(p) && !DOC_PATH.test(p));
|
|
50
58
|
if (riskyPaths.length) reasons.push({ code: 'HIGH_RISK_PATH', detail: riskyPaths.join(', '), tier: 'T2' });
|
|
51
|
-
if (riskyWord) reasons.push({ code: 'RISKY_TASK_TEXT', detail: riskyWord[0], tier: 'T2' });
|
|
52
59
|
if (changedPaths.length > T2_FILE_THRESHOLD) {
|
|
53
60
|
reasons.push({ code: 'MANY_FILES', detail: `${changedPaths.length} files > ${T2_FILE_THRESHOLD}`, tier: 'T2' });
|
|
54
61
|
}
|
|
55
62
|
if (reasons.length) return { tier: TIERS.T2, reasons };
|
|
56
63
|
|
|
57
|
-
const
|
|
58
|
-
const docsOnly = changedPaths.length > 0 && changedPaths.every((p) => DOC_PATH.test(p));
|
|
64
|
+
const manifests = changedPaths.filter((p) => MANIFEST_PATH.test(p));
|
|
65
|
+
const docsOnly = changedPaths.length > 0 && !manifests.length && changedPaths.every((p) => DOC_PATH.test(p));
|
|
59
66
|
const small = changedPaths.length <= T0_LIMITS.maxFiles
|
|
60
67
|
&& (changedLines == null || changedLines <= T0_LIMITS.maxChangedLines);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
68
|
+
const riskyWord = String(task).match(RISKY_TASK);
|
|
69
|
+
const trivialWord = String(task).match(TRIVIAL_TASK);
|
|
70
|
+
|
|
71
|
+
if (docsOnly && small) {
|
|
72
|
+
reasons.push({ code: 'DOCS_ONLY_PATHS', detail: changedPaths.join(', '), tier: 'T0' });
|
|
73
|
+
if (riskyWord) reasons.push({ code: 'RISKY_TEXT_IGNORED', detail: `${riskyWord[0]} (docs-only paths)`, tier: 'T0' });
|
|
74
|
+
return { tier: TIERS.T0, reasons };
|
|
75
|
+
}
|
|
76
|
+
if (riskyWord && !(trivialWord && changedPaths.length === 0)) {
|
|
77
|
+
reasons.push({ code: 'RISKY_TASK_TEXT', detail: riskyWord[0], tier: 'T2' });
|
|
78
|
+
return { tier: TIERS.T2, reasons };
|
|
79
|
+
}
|
|
80
|
+
if (riskyWord) {
|
|
81
|
+
reasons.push({ code: 'MIXED_TASK_TEXT', detail: `${trivialWord[0]} + ${riskyWord[0]}; the Maker diff decides`, tier: 'T1' });
|
|
82
|
+
return { tier: TIERS.T1, reasons };
|
|
83
|
+
}
|
|
84
|
+
if (manifests.length) {
|
|
85
|
+
reasons.push({ code: 'DEPENDENCY_MANIFEST', detail: manifests.join(', '), tier: 'T1' });
|
|
86
|
+
return { tier: TIERS.T1, reasons };
|
|
87
|
+
}
|
|
88
|
+
if (small && trivialWord) {
|
|
89
|
+
reasons.push({ code: 'TRIVIAL_TASK_TEXT', detail: trivialWord[0], tier: 'T0' });
|
|
64
90
|
return { tier: TIERS.T0, reasons };
|
|
65
91
|
}
|
|
66
92
|
reasons.push({ code: 'DEFAULT', detail: 'normal change', tier: 'T1' });
|
package/lib/user-state.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
// It is never part of a repository. `home` resolves AEL_HOME first so tests and
|
|
5
5
|
// sandboxes never touch the real home directory.
|
|
6
6
|
|
|
7
|
-
const crypto = require('crypto');
|
|
8
7
|
const fs = require('fs');
|
|
9
8
|
const os = require('os');
|
|
10
9
|
const path = require('path');
|
|
10
|
+
const { sha256, writePrivateFile } = require('./fsutil.js');
|
|
11
11
|
|
|
12
12
|
function homeDir(env = process.env) {
|
|
13
13
|
if (env.AEL_HOME) return env.AEL_HOME;
|
|
@@ -23,23 +23,8 @@ function userStatePath(name, home = homeDir()) {
|
|
|
23
23
|
return path.join(userStateDir(home), name);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function sha256(content) {
|
|
27
|
-
return crypto.createHash('sha256').update(content).digest('hex');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
26
|
function atomicWritePrivate(filePath, content) {
|
|
31
|
-
|
|
32
|
-
const temporary = `${filePath}.${process.pid}.${crypto.randomBytes(4).toString('hex')}.tmp`;
|
|
33
|
-
try {
|
|
34
|
-
fs.writeFileSync(temporary, content, { mode: 0o600 });
|
|
35
|
-
fs.renameSync(temporary, filePath);
|
|
36
|
-
} finally {
|
|
37
|
-
try {
|
|
38
|
-
fs.unlinkSync(temporary);
|
|
39
|
-
} catch {
|
|
40
|
-
// Rename succeeded or nothing was written.
|
|
41
|
-
}
|
|
42
|
-
}
|
|
27
|
+
writePrivateFile(filePath, content, { dirMode: 0o700 });
|
|
43
28
|
}
|
|
44
29
|
|
|
45
30
|
function readJsonFile(filePath, fallback) {
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Verification lanes: a fast `related` lane for iterations and one `final`
|
|
4
|
+
// full run before delivery when the gated verification was related-only.
|
|
5
|
+
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { runsDir } = require('./run-state.js');
|
|
9
|
+
const { extractChangedPaths } = require('./escalation.js');
|
|
10
|
+
|
|
11
|
+
const FINAL_FILE = 'final-verification.json';
|
|
12
|
+
const FILES_TOKEN = '{files}';
|
|
13
|
+
|
|
14
|
+
function laneError(message, code) {
|
|
15
|
+
return Object.assign(new Error(message), { code });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// `- **key**: `command`` lines from .ai-engineering-loop/verification.md.
|
|
19
|
+
function verificationCommands(rootDir) {
|
|
20
|
+
let text = '';
|
|
21
|
+
try {
|
|
22
|
+
text = fs.readFileSync(path.join(rootDir, '.ai-engineering-loop', 'verification.md'), 'utf8');
|
|
23
|
+
} catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
const commands = {};
|
|
27
|
+
for (const match of text.matchAll(/\*\*([a-z0-9_]+)\*\*:\s*`([^`]+)`/gi)) {
|
|
28
|
+
if (!Object.hasOwn(commands, match[1])) commands[match[1]] = match[2].trim();
|
|
29
|
+
}
|
|
30
|
+
return commands;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Changed files of the gated Maker diff that still exist (deleted files have
|
|
34
|
+
// no tests to relate to).
|
|
35
|
+
function relatedFiles(rootDir, run) {
|
|
36
|
+
const artifact = run.artifacts?.diff;
|
|
37
|
+
if (!artifact?.path) throw laneError('Maker evidence is not gated yet. Run `gate maker` first.', 'MAKER_NOT_GATED');
|
|
38
|
+
const diff = fs.readFileSync(path.join(rootDir, artifact.path), 'utf8');
|
|
39
|
+
return [...new Set(extractChangedPaths(diff))]
|
|
40
|
+
.filter((file) => !file.startsWith('.ai-engineering-loop/'))
|
|
41
|
+
.filter((file) => {
|
|
42
|
+
try {
|
|
43
|
+
return fs.statSync(path.join(rootDir, file)).isFile();
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Expand `{files}` in the project's test_related command. `split` is the
|
|
51
|
+
// CLI's command splitter so quoting rules stay identical to `--cmd`.
|
|
52
|
+
function relatedCommand(rootDir, run, { split, shell = false } = {}) {
|
|
53
|
+
const template = verificationCommands(rootDir).test_related;
|
|
54
|
+
if (!template) {
|
|
55
|
+
throw laneError(
|
|
56
|
+
'No test_related command in .ai-engineering-loop/verification.md. Add e.g. - **test_related**: `npx jest --findRelatedTests {files}`, or pass --cmd.',
|
|
57
|
+
'NO_RELATED_COMMAND'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (!template.includes(FILES_TOKEN)) {
|
|
61
|
+
throw laneError(`test_related must contain ${FILES_TOKEN}`, 'INVALID_RELATED_COMMAND');
|
|
62
|
+
}
|
|
63
|
+
const files = relatedFiles(rootDir, run);
|
|
64
|
+
if (!files.length) {
|
|
65
|
+
throw laneError('The gated diff has no existing files to relate tests to; run the full `verify`.', 'NO_RELATED_FILES');
|
|
66
|
+
}
|
|
67
|
+
if (shell) {
|
|
68
|
+
const quoted = files.map((file) => `'${file.replace(/'/g, `'\\''`)}'`).join(' ');
|
|
69
|
+
return { ...split(template.split(FILES_TOKEN).join(quoted), true), files };
|
|
70
|
+
}
|
|
71
|
+
const parsed = split(template.replace(FILES_TOKEN, 'AEL_FILES_PLACEHOLDER'), false);
|
|
72
|
+
const args = parsed.args.flatMap((arg) => (arg === 'AEL_FILES_PLACEHOLDER' ? files : [arg]));
|
|
73
|
+
return { ...parsed, args, files };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function readJson(filePath) {
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const passed = (record) => record && record.exitCode === 0 && record.timeoutStatus === 'COMPLETED';
|
|
85
|
+
const isFull = (record) => (record.scope || 'full') !== 'related';
|
|
86
|
+
|
|
87
|
+
// Whether delivery needs (or already has) a full run for the gated diff.
|
|
88
|
+
function finalVerificationStatus(rootDir, run) {
|
|
89
|
+
const dir = path.join(runsDir(rootDir), run.runId);
|
|
90
|
+
const bundle = readJson(path.join(dir, 'verification.json'));
|
|
91
|
+
const commands = bundle?.commands || [];
|
|
92
|
+
if (!commands.length || commands.some(isFull)) {
|
|
93
|
+
return { required: false, satisfied: true, reason: 'gated verification already ran full scope' };
|
|
94
|
+
}
|
|
95
|
+
const final = readJson(path.join(dir, FINAL_FILE));
|
|
96
|
+
const diffHash = run.artifacts?.diff?.sha256;
|
|
97
|
+
if (!final) return { required: true, satisfied: false, reason: `missing ${FINAL_FILE}; run \`verify --final --run ${run.runId}\`` };
|
|
98
|
+
if (final.runId !== run.runId || final.diffHash !== diffHash) {
|
|
99
|
+
return { required: true, satisfied: false, reason: `${FINAL_FILE} is not bound to the gated Maker diff` };
|
|
100
|
+
}
|
|
101
|
+
const records = final.commands || [];
|
|
102
|
+
if (!records.length || !records.every(passed)) {
|
|
103
|
+
return { required: true, satisfied: false, reason: `${FINAL_FILE} has a failing or missing command` };
|
|
104
|
+
}
|
|
105
|
+
return { required: true, satisfied: true, reason: 'final full verification passed' };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
module.exports = {
|
|
109
|
+
FINAL_FILE,
|
|
110
|
+
FILES_TOKEN,
|
|
111
|
+
verificationCommands,
|
|
112
|
+
relatedFiles,
|
|
113
|
+
relatedCommand,
|
|
114
|
+
finalVerificationStatus
|
|
115
|
+
};
|
|
@@ -8,16 +8,19 @@ const {
|
|
|
8
8
|
getCurrentRun,
|
|
9
9
|
getGitRevision,
|
|
10
10
|
loadRun,
|
|
11
|
-
runsDir
|
|
11
|
+
runsDir,
|
|
12
|
+
withFileLock
|
|
12
13
|
} = require('./run-state.js');
|
|
13
14
|
const { hashFile } = require('./gates.js');
|
|
14
15
|
const { redactHomePaths, redactSecrets } = require('./safe-context.js');
|
|
15
16
|
const { writeVerificationSummary } = require('./verification-summary.js');
|
|
17
|
+
const { killProcessTree, resolveSpawn } = require('./spawn-command.js');
|
|
16
18
|
|
|
17
19
|
const MAX_CAPTURE_BYTES = 256 * 1024;
|
|
18
20
|
const DEFAULT_TIMEOUT_MS = 30 * 60 * 1000;
|
|
19
21
|
const MAX_TIMEOUT_MS = 60 * 60 * 1000;
|
|
20
22
|
const KILL_GRACE_MS = 2_000;
|
|
23
|
+
const PIPE_DRAIN_MS = 10_000;
|
|
21
24
|
|
|
22
25
|
function recorderError(message, code = 'VERIFICATION_RECORD_FAILED') {
|
|
23
26
|
const error = new Error(message);
|
|
@@ -137,29 +140,54 @@ function runCommand(command, args, { cwd, timeoutMs, shell }) {
|
|
|
137
140
|
let timedOut = false;
|
|
138
141
|
let launchError = null;
|
|
139
142
|
let forceKillTimer = null;
|
|
140
|
-
|
|
143
|
+
let pipeTimer = null;
|
|
144
|
+
let settled = false;
|
|
145
|
+
const target = shell ? { command, args: [], options: {} } : resolveSpawn(command, args);
|
|
146
|
+
// POSIX: lead a process group so a timeout can stop grandchildren too.
|
|
147
|
+
const detached = process.platform !== 'win32';
|
|
148
|
+
const child = spawn(target.command, target.args, {
|
|
141
149
|
cwd,
|
|
142
150
|
env: process.env,
|
|
143
151
|
shell: Boolean(shell),
|
|
144
|
-
|
|
152
|
+
detached,
|
|
153
|
+
windowsHide: true,
|
|
154
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
155
|
+
...target.options
|
|
145
156
|
});
|
|
146
157
|
const stdout = captureStream(child.stdout);
|
|
147
158
|
const stderr = captureStream(child.stderr);
|
|
159
|
+
// A detached group no longer receives the terminal's Ctrl-C; forward it.
|
|
160
|
+
const forward = (signal) => {
|
|
161
|
+
killProcessTree(child, 'SIGKILL');
|
|
162
|
+
process.removeListener('SIGINT', onSigint);
|
|
163
|
+
process.removeListener('SIGTERM', onSigterm);
|
|
164
|
+
process.kill(process.pid, signal);
|
|
165
|
+
};
|
|
166
|
+
const onSigint = () => forward('SIGINT');
|
|
167
|
+
const onSigterm = () => forward('SIGTERM');
|
|
168
|
+
if (detached) {
|
|
169
|
+
process.once('SIGINT', onSigint);
|
|
170
|
+
process.once('SIGTERM', onSigterm);
|
|
171
|
+
}
|
|
148
172
|
|
|
149
173
|
const timeout = setTimeout(() => {
|
|
150
174
|
timedOut = true;
|
|
151
|
-
child
|
|
152
|
-
forceKillTimer = setTimeout(() => child
|
|
175
|
+
killProcessTree(child, 'SIGTERM');
|
|
176
|
+
forceKillTimer = setTimeout(() => killProcessTree(child, 'SIGKILL'), KILL_GRACE_MS);
|
|
153
177
|
forceKillTimer.unref?.();
|
|
154
178
|
}, timeoutMs);
|
|
155
179
|
timeout.unref?.();
|
|
156
180
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
child.once('close', (code, signal) => {
|
|
181
|
+
const finish = (code, signal) => {
|
|
182
|
+
if (settled) return;
|
|
183
|
+
settled = true;
|
|
161
184
|
clearTimeout(timeout);
|
|
162
185
|
if (forceKillTimer) clearTimeout(forceKillTimer);
|
|
186
|
+
if (pipeTimer) clearTimeout(pipeTimer);
|
|
187
|
+
process.removeListener('SIGINT', onSigint);
|
|
188
|
+
process.removeListener('SIGTERM', onSigterm);
|
|
189
|
+
child.stdout?.destroy();
|
|
190
|
+
child.stderr?.destroy();
|
|
163
191
|
const finished = new Date();
|
|
164
192
|
const rawStdout = stdout.value();
|
|
165
193
|
const rawStderr = launchError ? launchError.message : stderr.value();
|
|
@@ -182,7 +210,55 @@ function runCommand(command, args, { cwd, timeoutMs, shell }) {
|
|
|
182
210
|
...(launchError ? { launchError: true } : {}),
|
|
183
211
|
...(timedOut ? { summary: `Command timed out after ${timeoutMs} ms.` } : {})
|
|
184
212
|
});
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
child.once('error', (error) => {
|
|
216
|
+
launchError = error;
|
|
217
|
+
if (!child.pid) finish(null, null);
|
|
218
|
+
});
|
|
219
|
+
// 'close' waits for the pipes; a grandchild that escaped the group can
|
|
220
|
+
// hold them open forever. After the child exits, give the pipes a grace
|
|
221
|
+
// period to drain and then stop waiting.
|
|
222
|
+
child.once('exit', (code, signal) => {
|
|
223
|
+
pipeTimer = setTimeout(() => {
|
|
224
|
+
killProcessTree(child, 'SIGKILL');
|
|
225
|
+
finish(code, signal);
|
|
226
|
+
}, timedOut ? KILL_GRACE_MS : PIPE_DRAIN_MS);
|
|
227
|
+
pipeTimer.unref?.();
|
|
185
228
|
});
|
|
229
|
+
child.once('close', (code, signal) => finish(code, signal));
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Commands can run for minutes, and other recorders may finish meanwhile.
|
|
234
|
+
// Re-read the Run and the bundle under a lock right before writing so no
|
|
235
|
+
// result is lost and nothing lands after the verification gate.
|
|
236
|
+
const passedRecord = (record) => record.exitCode === 0 && record.timeoutStatus === 'COMPLETED';
|
|
237
|
+
|
|
238
|
+
// Re-read under a lock right before writing so concurrent recorders never
|
|
239
|
+
// drop each other's results. `final` writes final-verification.json, which is
|
|
240
|
+
// recorded after the verification gate and has no summary.
|
|
241
|
+
function appendRecordedCommands(rootDir, runId, results, { filePath, gitRevision, diffHash, final = false }) {
|
|
242
|
+
return withFileLock(`${filePath}.lock`, () => {
|
|
243
|
+
const run = loadRun(rootDir, runId);
|
|
244
|
+
if (!final && run.artifacts?.verification) {
|
|
245
|
+
throw recorderError('Verification passed its gate while the command ran. Do not mutate gated evidence; start a new verification iteration instead.', 'VERIFICATION_ALREADY_GATED');
|
|
246
|
+
}
|
|
247
|
+
if (resolveDiff(rootDir, run) !== diffHash) {
|
|
248
|
+
throw recorderError('The gated Maker diff changed while the command ran. Re-run the Maker gate.', 'STALE_DIFF');
|
|
249
|
+
}
|
|
250
|
+
const bundle = readExistingBundle(filePath, { runId, gitRevision, diffHash });
|
|
251
|
+
// A re-run on the same diff supersedes that command's earlier failure; the
|
|
252
|
+
// failure stays on record under `superseded` and the gate sees the latest.
|
|
253
|
+
const rerun = new Set(results.map((result) => result.command));
|
|
254
|
+
const stale = bundle.commands.filter((record) => rerun.has(record.command) && !passedRecord(record));
|
|
255
|
+
if (stale.length) {
|
|
256
|
+
bundle.superseded = [...(bundle.superseded || []), ...stale];
|
|
257
|
+
bundle.commands = bundle.commands.filter((record) => !stale.includes(record));
|
|
258
|
+
}
|
|
259
|
+
bundle.commands.push(...results);
|
|
260
|
+
atomicWriteJson(filePath, bundle);
|
|
261
|
+
return final ? null : writeVerificationSummary(rootDir, { runId }).summary;
|
|
186
262
|
});
|
|
187
263
|
}
|
|
188
264
|
|
|
@@ -202,12 +278,9 @@ async function recordVerificationCommand(rootDir, {
|
|
|
202
278
|
const diffHash = resolveDiff(rootDir, run);
|
|
203
279
|
const gitRevision = getGitRevision(rootDir);
|
|
204
280
|
const filePath = path.join(runsDir(rootDir), run.runId, 'verification.json');
|
|
205
|
-
|
|
281
|
+
readExistingBundle(filePath, { runId: run.runId, gitRevision, diffHash });
|
|
206
282
|
const result = await runCommand(command, args, { cwd: rootDir, timeoutMs, shell });
|
|
207
|
-
|
|
208
|
-
atomicWriteJson(filePath, bundle);
|
|
209
|
-
|
|
210
|
-
const summary = writeVerificationSummary(rootDir, { runId: run.runId }).summary;
|
|
283
|
+
const summary = appendRecordedCommands(rootDir, run.runId, [result], { filePath, gitRevision, diffHash });
|
|
211
284
|
return {
|
|
212
285
|
runId: run.runId,
|
|
213
286
|
path: path.relative(rootDir, filePath).split(path.sep).join('/'),
|
|
@@ -219,11 +292,18 @@ async function recordVerificationCommand(rootDir, {
|
|
|
219
292
|
// Issue #34: run several verification commands in one CLI call. Independent
|
|
220
293
|
// commands run in parallel by default (`serial: true` opts out); results are
|
|
221
294
|
// appended to verification.json in the given order, in one atomic write.
|
|
295
|
+
// `scope` tags records ('related' for the fast lane, 'full' otherwise).
|
|
296
|
+
// `target: 'final'` writes final-verification.json for a run whose gated
|
|
297
|
+
// verification was related-only. A passing record for the same command, diff,
|
|
298
|
+
// and revision is reused unless `fresh` is set.
|
|
222
299
|
async function recordVerificationCommands(rootDir, {
|
|
223
300
|
runId,
|
|
224
301
|
commands = [],
|
|
225
302
|
serial = false,
|
|
226
|
-
timeoutMs = DEFAULT_TIMEOUT_MS
|
|
303
|
+
timeoutMs = DEFAULT_TIMEOUT_MS,
|
|
304
|
+
scope = null,
|
|
305
|
+
target = 'verification',
|
|
306
|
+
fresh = false
|
|
227
307
|
} = {}) {
|
|
228
308
|
if (!Array.isArray(commands) || commands.length === 0) {
|
|
229
309
|
throw recorderError('Provide at least one verification command.', 'INVALID_COMMAND');
|
|
@@ -232,14 +312,22 @@ async function recordVerificationCommands(rootDir, {
|
|
|
232
312
|
validateRecordingRequest({ command: item.command, args: item.args || [], timeoutMs, shell: Boolean(item.shell) });
|
|
233
313
|
}
|
|
234
314
|
const run = resolveRun(rootDir, runId);
|
|
235
|
-
|
|
315
|
+
const final = target === 'final';
|
|
316
|
+
if (!final && run.artifacts?.verification) {
|
|
236
317
|
throw recorderError('Verification has already passed its gate. Do not mutate gated evidence; start a new verification iteration instead.', 'VERIFICATION_ALREADY_GATED');
|
|
237
318
|
}
|
|
238
319
|
const diffHash = resolveDiff(rootDir, run);
|
|
239
320
|
const gitRevision = getGitRevision(rootDir);
|
|
240
|
-
const filePath = path.join(runsDir(rootDir), run.runId, 'verification.json');
|
|
321
|
+
const filePath = path.join(runsDir(rootDir), run.runId, final ? 'final-verification.json' : 'verification.json');
|
|
241
322
|
const bundle = readExistingBundle(filePath, { runId: run.runId, gitRevision, diffHash });
|
|
242
|
-
const exec = (item) =>
|
|
323
|
+
const exec = async (item) => {
|
|
324
|
+
const display = displayCommand(item.command, item.args || []);
|
|
325
|
+
const previous = fresh ? null : bundle.commands.find((record) => record.command === display && passedRecord(record)
|
|
326
|
+
&& (record.scope || 'full') === (scope || 'full'));
|
|
327
|
+
if (previous) return { ...previous, reused: true };
|
|
328
|
+
const result = await runCommand(item.command, item.args || [], { cwd: rootDir, timeoutMs, shell: Boolean(item.shell) });
|
|
329
|
+
return scope ? { ...result, scope } : result;
|
|
330
|
+
};
|
|
243
331
|
let results;
|
|
244
332
|
if (serial) {
|
|
245
333
|
results = [];
|
|
@@ -247,15 +335,15 @@ async function recordVerificationCommands(rootDir, {
|
|
|
247
335
|
} else {
|
|
248
336
|
results = await Promise.all(commands.map(exec));
|
|
249
337
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
338
|
+
const summary = appendRecordedCommands(rootDir, run.runId, results.filter((result) => !result.reused), {
|
|
339
|
+
filePath, gitRevision, diffHash, final
|
|
340
|
+
});
|
|
253
341
|
return {
|
|
254
342
|
runId: run.runId,
|
|
255
343
|
path: path.relative(rootDir, filePath).split(path.sep).join('/'),
|
|
256
344
|
commands: results,
|
|
257
345
|
summary,
|
|
258
|
-
passed: results.every(
|
|
346
|
+
passed: results.every(passedRecord)
|
|
259
347
|
};
|
|
260
348
|
}
|
|
261
349
|
|
package/lib/workflow-runtime.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
+
const { ACTOR_ID } = require('./fsutil.js');
|
|
5
6
|
const { sha256 } = require('./recipe.js');
|
|
6
7
|
const { redactSecrets } = require('./safe-context.js');
|
|
8
|
+
const { repairJsonlTail, splitJsonlLines } = require('./runtime-files.js');
|
|
7
9
|
const {
|
|
8
10
|
RUN_STATES,
|
|
9
11
|
atomicWriteJson,
|
|
@@ -205,7 +207,7 @@ function readEvents(filePath, runId, graphHash) {
|
|
|
205
207
|
throw runtimeError('Workflow event log must be a regular file', 'INVALID_WORKFLOW_EVENTS');
|
|
206
208
|
}
|
|
207
209
|
const text = fs.readFileSync(filePath, 'utf8');
|
|
208
|
-
const events = text
|
|
210
|
+
const events = splitJsonlLines(text).lines.map((line, index) => {
|
|
209
211
|
try {
|
|
210
212
|
return JSON.parse(line);
|
|
211
213
|
} catch (cause) {
|
|
@@ -286,6 +288,7 @@ function appendEvent(filePath, event) {
|
|
|
286
288
|
const noFollow = fs.constants.O_NOFOLLOW || 0;
|
|
287
289
|
let descriptor;
|
|
288
290
|
try {
|
|
291
|
+
repairJsonlTail(filePath);
|
|
289
292
|
descriptor = fs.openSync(
|
|
290
293
|
filePath,
|
|
291
294
|
fs.constants.O_APPEND | fs.constants.O_WRONLY | noFollow
|
|
@@ -431,7 +434,7 @@ function resetLoopNodes(workflow, group, iteration, now) {
|
|
|
431
434
|
}
|
|
432
435
|
|
|
433
436
|
function assertDecisionActor(actor) {
|
|
434
|
-
if (
|
|
437
|
+
if (!ACTOR_ID.test(String(actor || ''))) {
|
|
435
438
|
throw runtimeError('actor must be a short account identifier', 'INVALID_LOOP_ACTOR');
|
|
436
439
|
}
|
|
437
440
|
}
|
|
@@ -950,7 +953,7 @@ function retryWorkflowNode(rootDir, nodeId, { runId, now = new Date() } = {}) {
|
|
|
950
953
|
function approveWorkflowNode(rootDir, nodeId, { runId, approvedBy = 'human', now = new Date() } = {}) {
|
|
951
954
|
const resolved = resolveRunId(rootDir, runId);
|
|
952
955
|
return withWorkflowLock(rootDir, resolved, () => {
|
|
953
|
-
if (
|
|
956
|
+
if (!ACTOR_ID.test(approvedBy)) {
|
|
954
957
|
throw runtimeError('approvedBy must be a short account identifier', 'INVALID_APPROVER');
|
|
955
958
|
}
|
|
956
959
|
const workflow = loadWorkflow(rootDir, resolved);
|
|
@@ -1080,7 +1083,7 @@ function cancelWorkflowRun(
|
|
|
1080
1083
|
const resolved = resolveRunId(rootDir, runId);
|
|
1081
1084
|
return withWorkflowLock(rootDir, resolved, () => {
|
|
1082
1085
|
let workflow = loadWorkflow(rootDir, resolved);
|
|
1083
|
-
if (
|
|
1086
|
+
if (!ACTOR_ID.test(String(actor))) {
|
|
1084
1087
|
throw runtimeError('Cancellation actor must be a short account identifier', 'INVALID_RUN_ACTOR');
|
|
1085
1088
|
}
|
|
1086
1089
|
const cleanReason = redactSecrets(String(reason || '').trim()).text;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-engineering-loop",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "A visual workspace that helps AI coding agents plan, build, review, and ship reliable software.",
|
|
5
5
|
"main": "bin/ai-engineering-loop.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,6 @@
|
|
|
22
22
|
".agents/",
|
|
23
23
|
".grok/",
|
|
24
24
|
".claude/agents/",
|
|
25
|
-
".claude/skills/",
|
|
26
25
|
"LICENSE",
|
|
27
26
|
"THIRD_PARTY_NOTICES.md",
|
|
28
27
|
"CHANGELOG.md",
|
|
@@ -11,7 +11,7 @@ Host files (`.claude/agents/`, `.grok/agents/`, `.agents/`) may differ only in Y
|
|
|
11
11
|
|
|
12
12
|
## Shared spawn rules
|
|
13
13
|
|
|
14
|
-
-
|
|
14
|
+
- Reviewers read the `review-pack` output or `RUN_DIR/diff.patch`; do not write a separate `tasks/current.diff`.
|
|
15
15
|
- Pass artifact **paths**, not Maker chat.
|
|
16
16
|
- Use the runtime policy `reviewProfile` to size context packs. Default `lean` protects Codex/GPT Plus-style sessions from repeated full-file prompts while keeping all gates intact.
|
|
17
17
|
- Prefer `npx ai-engineering-loop context diff-hunks --run <run-id>` for review. It writes a private hunk-only pack with file summaries and unresolved findings, so reviewers do not need full source bodies unless a cited hunk is insufficient.
|
|
@@ -3,25 +3,55 @@
|
|
|
3
3
|
"$id": "https://github.com/egagofur/ai-engineering-loop/schemas/goal-contract.schema.json",
|
|
4
4
|
"title": "AI Engineering Loop Goal Contract",
|
|
5
5
|
"type": "object",
|
|
6
|
-
"required": [
|
|
6
|
+
"required": [
|
|
7
|
+
"schemaVersion",
|
|
8
|
+
"runId",
|
|
9
|
+
"objective",
|
|
10
|
+
"acceptanceCriteria"
|
|
11
|
+
],
|
|
7
12
|
"properties": {
|
|
8
|
-
"schemaVersion": {
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
"schemaVersion": {
|
|
14
|
+
"const": 1
|
|
15
|
+
},
|
|
16
|
+
"runId": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"minLength": 1
|
|
19
|
+
},
|
|
20
|
+
"objective": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"minLength": 1
|
|
23
|
+
},
|
|
11
24
|
"acceptanceCriteria": {
|
|
12
25
|
"type": "array",
|
|
13
26
|
"minItems": 1,
|
|
14
27
|
"items": {
|
|
15
28
|
"type": "object",
|
|
16
|
-
"required": [
|
|
29
|
+
"required": [
|
|
30
|
+
"id",
|
|
31
|
+
"statement",
|
|
32
|
+
"evidenceRequired",
|
|
33
|
+
"failureCases"
|
|
34
|
+
],
|
|
17
35
|
"properties": {
|
|
18
|
-
"id": {
|
|
19
|
-
|
|
20
|
-
|
|
36
|
+
"id": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"pattern": "^AC-[0-9]+$"
|
|
39
|
+
},
|
|
40
|
+
"statement": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"minLength": 1
|
|
43
|
+
},
|
|
44
|
+
"evidenceRequired": {
|
|
45
|
+
"type": "string",
|
|
46
|
+
"minLength": 1
|
|
47
|
+
},
|
|
21
48
|
"failureCases": {
|
|
22
49
|
"type": "array",
|
|
23
50
|
"minItems": 1,
|
|
24
|
-
"items": {
|
|
51
|
+
"items": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"minLength": 1
|
|
54
|
+
}
|
|
25
55
|
}
|
|
26
56
|
},
|
|
27
57
|
"additionalProperties": true
|
|
@@ -31,10 +61,56 @@
|
|
|
31
61
|
"description": "Optional file scope frozen with the Goal (#59). Absent = no path enforcement. Globs: ** crosses directories, * stays in one segment, a trailing / is a directory prefix.",
|
|
32
62
|
"type": "object",
|
|
33
63
|
"properties": {
|
|
34
|
-
"allowedPaths": {
|
|
35
|
-
|
|
64
|
+
"allowedPaths": {
|
|
65
|
+
"type": "array",
|
|
66
|
+
"items": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"minLength": 1
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"deniedPaths": {
|
|
72
|
+
"type": "array",
|
|
73
|
+
"items": {
|
|
74
|
+
"type": "string",
|
|
75
|
+
"minLength": 1
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"additionalProperties": false
|
|
80
|
+
},
|
|
81
|
+
"designRef": {
|
|
82
|
+
"description": "Optional design document this Goal implements (#97): written by `goal draft --from-design`. targetFiles feed the design drift check.",
|
|
83
|
+
"type": "object",
|
|
84
|
+
"required": [
|
|
85
|
+
"path",
|
|
86
|
+
"sha256"
|
|
87
|
+
],
|
|
88
|
+
"properties": {
|
|
89
|
+
"path": {
|
|
90
|
+
"type": "string",
|
|
91
|
+
"minLength": 1
|
|
92
|
+
},
|
|
93
|
+
"sha256": {
|
|
94
|
+
"type": "string",
|
|
95
|
+
"pattern": "^[a-f0-9]{64}$"
|
|
96
|
+
},
|
|
97
|
+
"targetFiles": {
|
|
98
|
+
"type": "array",
|
|
99
|
+
"items": {
|
|
100
|
+
"type": "string",
|
|
101
|
+
"minLength": 1
|
|
102
|
+
}
|
|
103
|
+
}
|
|
36
104
|
},
|
|
37
105
|
"additionalProperties": false
|
|
106
|
+
},
|
|
107
|
+
"outOfScope": {
|
|
108
|
+
"description": "Optional list of things this Goal must not change.",
|
|
109
|
+
"type": "array",
|
|
110
|
+
"items": {
|
|
111
|
+
"type": "string",
|
|
112
|
+
"minLength": 1
|
|
113
|
+
}
|
|
38
114
|
}
|
|
39
115
|
},
|
|
40
116
|
"additionalProperties": true
|