ai-engineering-loop 1.0.16 → 1.0.18

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.
@@ -63,3 +63,26 @@ The Verification Gate immediately halts and returns to the Maker if:
63
63
  - Test logs contain zero passing assertions for new acceptance criteria.
64
64
  - assertionEvidence maps only to a happy path while the Goal Contract lists empty, boundary, sibling, or error AC rows.
65
65
  - The only new "test" is a source grep or a coverage percentage.
66
+
67
+ ---
68
+
69
+ ## 5. Claimed vs Reality (before Devil's Advocate)
70
+
71
+ Write `.ai-engineering-loop/tasks/claimed-vs-reality.md` after verification logs exist:
72
+
73
+ ```markdown
74
+ # Claimed vs Reality
75
+
76
+ | AC | Claimed | Reality |
77
+ |---|---|---|
78
+ | AC-1 | <what Maker said is done> | <command, exit code, assertion or log line> |
79
+ ```
80
+
81
+ Do **not** spawn Devil's Advocate if:
82
+
83
+ - the file is missing
84
+ - the table has zero rows
85
+ - any Claimed row has empty Reality
86
+ - Reality is only `seems green`
87
+
88
+ Parser: `lib/claimed-vs-reality.js` (`readyForDa`). Pass that path to DA/Judge with the verification log.
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ function parseClaimedVsReality(markdown) {
4
+ const rows = [];
5
+ if (!markdown || !String(markdown).trim()) return { rows };
6
+ const lines = String(markdown).split('\n');
7
+ for (const line of lines) {
8
+ const trimmed = line.trim();
9
+ if (!trimmed.startsWith('|')) continue;
10
+ if (/^\|\s*-+\s*\|/.test(trimmed) || /^\|\s*AC\s*\|/i.test(trimmed)) continue;
11
+ const cells = trimmed.split('|').map((c) => c.trim()).filter((_, i, arr) => i > 0 && i < arr.length - 1);
12
+ if (cells.length < 3) continue;
13
+ rows.push({
14
+ ac: cells[0],
15
+ claimed: cells[1],
16
+ reality: cells[2]
17
+ });
18
+ }
19
+ return { rows };
20
+ }
21
+
22
+ function readyForDa(markdown) {
23
+ const { rows } = parseClaimedVsReality(markdown);
24
+ if (rows.length === 0) return false;
25
+ return rows.every((row) => {
26
+ const reality = (row.reality || '').trim();
27
+ if (!reality) return false;
28
+ if (/^seems green$/i.test(reality)) return false;
29
+ if (!(row.claimed || '').trim()) return false;
30
+ return true;
31
+ });
32
+ }
33
+
34
+ module.exports = {
35
+ parseClaimedVsReality,
36
+ readyForDa
37
+ };
@@ -0,0 +1,233 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const REQUIRED_STAGES = ['goal_contract', 'verification', 'devil_advocate', 'judge'];
7
+ const ALLOWED_OPTIONAL_SKIPS = ['blast_radius', 'generate_adapter'];
8
+ const DEFAULT_HOOKS = {
9
+ before_grill: 'none',
10
+ after_freeze: 'none',
11
+ after_pass: 'none'
12
+ };
13
+ const DEFAULT_MAKER_INTERN = 'none';
14
+
15
+ const REQUIRED_ALIASES = {
16
+ goal_contract: 'goal_contract',
17
+ 'goal contract': 'goal_contract',
18
+ verification: 'verification',
19
+ devil_advocate: 'devil_advocate',
20
+ "devil's advocate": 'devil_advocate',
21
+ 'devils advocate': 'devil_advocate',
22
+ judge: 'judge'
23
+ };
24
+
25
+ function normalizeSkip(name) {
26
+ return String(name || '')
27
+ .trim()
28
+ .toLowerCase()
29
+ .replace(/['"]/g, '')
30
+ .replace(/\s+/g, '_');
31
+ }
32
+
33
+ function assertNoRequiredSkip(skips) {
34
+ for (const raw of skips || []) {
35
+ const id = REQUIRED_ALIASES[normalizeSkip(raw)] || normalizeSkip(raw);
36
+ if (REQUIRED_STAGES.includes(id)) {
37
+ const err = new Error(`cannot skip required stage: ${id}`);
38
+ err.code = 'REQUIRED_SKIP';
39
+ throw err;
40
+ }
41
+ }
42
+ }
43
+
44
+ function routeDurableNote(kind) {
45
+ const map = {
46
+ term: 'glossary.md',
47
+ process: 'lessons.md',
48
+ lesson: 'lessons.md',
49
+ convention: 'conventions.md',
50
+ adr: 'adrs/'
51
+ };
52
+ return map[kind] || 'lessons.md';
53
+ }
54
+
55
+ function normalizeMakerIntern(raw) {
56
+ const s = String(raw || '').trim();
57
+ if (!s || /^none$/i.test(s)) return DEFAULT_MAKER_INTERN;
58
+ if (/api[_-]?key/i.test(s) || /^sk-/i.test(s) || /https?:\/\//i.test(s)) {
59
+ const err = new Error('maker_intern is a host-native label, not a key or URL');
60
+ err.code = 'INTERN_SECRET';
61
+ throw err;
62
+ }
63
+ return s;
64
+ }
65
+
66
+ function parseMakerInternLine(text) {
67
+ const match = String(text || '').match(/\*\*maker_intern\*\*:\s*(.*)/i);
68
+ if (!match) return DEFAULT_MAKER_INTERN;
69
+ return normalizeMakerIntern(match[1]);
70
+ }
71
+
72
+ function workflowMarkdown({ hooks = DEFAULT_HOOKS, optionalSkips = [], makerIntern = DEFAULT_MAKER_INTERN } = {}) {
73
+ const skipLine = optionalSkips.length ? optionalSkips.join(', ') : 'none';
74
+ const intern = normalizeMakerIntern(makerIntern);
75
+ return `# Loop Overlay
76
+
77
+ This file adds hooks around the AI Engineering Loop. It does not replace the 8-stage OS.
78
+
79
+ ## Required (cannot skip)
80
+ - Goal Contract
81
+ - verification
82
+ - Devil's Advocate
83
+ - Judge
84
+
85
+ ## Hooks
86
+ - **before_grill**: ${hooks.before_grill || 'none'}
87
+ - **after_freeze**: ${hooks.after_freeze || 'none'}
88
+ - **after_pass**: ${hooks.after_pass || 'none'}
89
+
90
+ ## Maker intern
91
+ - **maker_intern**: ${intern}
92
+
93
+ Default \`none\` = parent is Maker. Any host-native label is allowed (gemini-flash, grok-mini, haiku, qwen, deepseek, ...). Not locked to one vendor. AEL does not store intern API keys. Devil's Advocate and Judge stay on the parent. Intern cannot skip them.
94
+
95
+ ## Optional skips
96
+ ${skipLine}
97
+
98
+ Allowed optional skips: \`blast_radius\` (when the change is not business logic), \`generate_adapter\` (when adapter.md already exists).
99
+ Do not list Goal Contract, verification, Devil's Advocate, or Judge here.
100
+ `;
101
+ }
102
+
103
+ function lessonsMarkdown() {
104
+ return `# Lessons
105
+
106
+ Confirmed by a human. One row per lesson. Not a chat transcript. Not a glossary.
107
+
108
+ Route elsewhere when it fits: term → glossary.md, code ban → conventions.md, load-bearing design → adrs/.
109
+
110
+ | Date | Lesson | Do not |
111
+ |---|---|---|
112
+ `;
113
+ }
114
+
115
+ function parseHookLine(text, key) {
116
+ const re = new RegExp(`\\*\\*${key}\\*\\*:\\s*(.+)`, 'i');
117
+ const match = text.match(re);
118
+ if (!match) return 'none';
119
+ return match[1].trim() || 'none';
120
+ }
121
+
122
+ function parseOptionalSkips(text) {
123
+ const block = text.split(/## Optional skips/i)[1];
124
+ if (!block) return [];
125
+ const line = block.split('\n').find((row) => row.trim() && !row.startsWith('#'));
126
+ if (!line) return [];
127
+ const raw = line.replace(/^-\s*/, '').trim();
128
+ if (!raw || /^none$/i.test(raw)) return [];
129
+ return raw.split(/,|\|/).map((item) => normalizeSkip(item)).filter(Boolean);
130
+ }
131
+
132
+ function parseWorkflowMarkdown(text) {
133
+ return {
134
+ missing: false,
135
+ required: REQUIRED_STAGES.slice(),
136
+ hooks: {
137
+ before_grill: parseHookLine(text, 'before_grill'),
138
+ after_freeze: parseHookLine(text, 'after_freeze'),
139
+ after_pass: parseHookLine(text, 'after_pass')
140
+ },
141
+ makerIntern: parseMakerInternLine(text),
142
+ optionalSkips: parseOptionalSkips(text)
143
+ };
144
+ }
145
+
146
+ function parseWorkflowFile(rootDir) {
147
+ const dest = path.join(rootDir, '.ai-engineering-loop', 'workflow.md');
148
+ try {
149
+ const text = fs.readFileSync(dest, 'utf8');
150
+ return parseWorkflowMarkdown(text);
151
+ } catch {
152
+ return {
153
+ missing: true,
154
+ required: REQUIRED_STAGES.slice(),
155
+ hooks: { ...DEFAULT_HOOKS },
156
+ makerIntern: DEFAULT_MAKER_INTERN,
157
+ optionalSkips: []
158
+ };
159
+ }
160
+ }
161
+
162
+ function lessonsAreFilled(text) {
163
+ if (!text || !text.trim()) return false;
164
+ return /\| 20\d{2}-/.test(text);
165
+ }
166
+
167
+ function writeWorkflowOverlay(rootDir, { hooks, optionalSkips, makerIntern } = {}) {
168
+ const skips = optionalSkips || [];
169
+ assertNoRequiredSkip(skips);
170
+ for (const skip of skips) {
171
+ const id = normalizeSkip(skip);
172
+ if (!ALLOWED_OPTIONAL_SKIPS.includes(id)) {
173
+ const err = new Error(`Unknown optional skip: ${skip}. Use ${ALLOWED_OPTIONAL_SKIPS.join('|')}`);
174
+ err.code = 'UNKNOWN_SKIP';
175
+ throw err;
176
+ }
177
+ }
178
+ const intern = normalizeMakerIntern(makerIntern);
179
+ const dir = path.join(rootDir, '.ai-engineering-loop');
180
+ fs.mkdirSync(dir, { recursive: true });
181
+ const workflowPath = path.join(dir, 'workflow.md');
182
+ const lessonsPath = path.join(dir, 'lessons.md');
183
+ fs.writeFileSync(
184
+ workflowPath,
185
+ workflowMarkdown({
186
+ hooks: { ...DEFAULT_HOOKS, ...(hooks || {}) },
187
+ optionalSkips: skips,
188
+ makerIntern: intern
189
+ })
190
+ );
191
+ if (!fs.existsSync(lessonsPath) || !lessonsAreFilled(fs.readFileSync(lessonsPath, 'utf8'))) {
192
+ if (!fs.existsSync(lessonsPath)) {
193
+ fs.writeFileSync(lessonsPath, lessonsMarkdown());
194
+ }
195
+ }
196
+ return { workflow: workflowPath, lessons: lessonsPath };
197
+ }
198
+
199
+ function formatGenerateWorkflowReport({ version, wrote } = {}) {
200
+ const lines = [
201
+ `Workflow overlay generate (v${version || 'unknown'})`,
202
+ 'This is not a second OS. Required: Goal Contract, verification, Devil\'s Advocate, Judge.',
203
+ 'Files: .ai-engineering-loop/workflow.md and lessons.md',
204
+ 'Next: load skill generate-workflow. Ask Q1-Q6. Wait.',
205
+ 'Headless: npx ai-engineering-loop generate-workflow --write'
206
+ ];
207
+ if (wrote) {
208
+ lines.push(`Wrote: ${wrote.workflow}`);
209
+ lines.push(`Lessons: ${wrote.lessons}`);
210
+ }
211
+ return lines.join('\n');
212
+ }
213
+
214
+ function parseWriteArg(argv) {
215
+ return argv.includes('--write');
216
+ }
217
+
218
+ module.exports = {
219
+ REQUIRED_STAGES,
220
+ ALLOWED_OPTIONAL_SKIPS,
221
+ DEFAULT_HOOKS,
222
+ DEFAULT_MAKER_INTERN,
223
+ assertNoRequiredSkip,
224
+ normalizeMakerIntern,
225
+ routeDurableNote,
226
+ workflowMarkdown,
227
+ lessonsMarkdown,
228
+ parseWorkflowMarkdown,
229
+ parseWorkflowFile,
230
+ writeWorkflowOverlay,
231
+ formatGenerateWorkflowReport,
232
+ parseWriteArg
233
+ };
package/lib/sync-hosts.js CHANGED
@@ -35,6 +35,7 @@ function hostFileMap(home) {
35
35
  { src: '.claude/skills/ai-engineering-loop/SKILL.md', dest: path.join(claude, 'skills/ai-engineering-loop/SKILL.md'), mode: 'upsert' },
36
36
  { src: 'adapters/dot/skills/task-impact-inquiry/SKILL.md', dest: path.join(claude, 'skills/task-impact-inquiry/SKILL.md'), mode: 'upsert' },
37
37
  { src: 'adapters/generate-adapter/SKILL.md', dest: path.join(claude, 'skills/generate-adapter/SKILL.md'), mode: 'upsert' },
38
+ { src: 'adapters/generate-workflow/SKILL.md', dest: path.join(claude, 'skills/generate-workflow/SKILL.md'), mode: 'upsert' },
38
39
  { src: '.claude/agents/devil-advocate.md', dest: path.join(claude, 'agents/devil-advocate.md'), mode: 'upsert' },
39
40
  { src: '.claude/agents/judge.md', dest: path.join(claude, 'agents/judge.md'), mode: 'upsert' },
40
41
  { src: '.claude/commands/ai-engineering-loop.md', dest: path.join(claude, 'commands/ai-engineering-loop.md'), mode: 'upsert' }
@@ -47,6 +48,7 @@ function hostFileMap(home) {
47
48
  { src: '.grok/skills/ai-engineering-loop/SKILL.md', dest: path.join(grok, 'skills/ai-engineering-loop/SKILL.md'), mode: 'upsert', grokSkillOverlay: true },
48
49
  { src: 'adapters/dot/skills/task-impact-inquiry/SKILL.md', dest: path.join(grok, 'skills/task-impact-inquiry/SKILL.md'), mode: 'upsert', grokSkillOverlay: true },
49
50
  { src: 'adapters/generate-adapter/SKILL.md', dest: path.join(grok, 'skills/generate-adapter/SKILL.md'), mode: 'upsert', grokSkillOverlay: true },
51
+ { src: 'adapters/generate-workflow/SKILL.md', dest: path.join(grok, 'skills/generate-workflow/SKILL.md'), mode: 'upsert', grokSkillOverlay: true },
50
52
  { src: '.grok/agents/devil-advocate.md', dest: path.join(grok, 'agents/devil-advocate.md'), mode: 'upsert' },
51
53
  { src: '.grok/agents/judge.md', dest: path.join(grok, 'agents/judge.md'), mode: 'upsert' },
52
54
  { src: '.grok/commands/ai-engineering-loop.md', dest: path.join(grok, 'commands/ai-engineering-loop.md'), mode: 'upsert' }
@@ -58,7 +60,8 @@ function hostFileMap(home) {
58
60
  files: [
59
61
  { src: '.gemini/skills/ai-engineering-loop/SKILL.md', dest: path.join(gemini, 'config/skills/ai-engineering-loop/SKILL.md'), mode: 'upsert' },
60
62
  { src: 'adapters/dot/skills/task-impact-inquiry/SKILL.md', dest: path.join(gemini, 'config/skills/task-impact-inquiry/SKILL.md'), mode: 'upsert' },
61
- { src: 'adapters/generate-adapter/SKILL.md', dest: path.join(gemini, 'config/skills/generate-adapter/SKILL.md'), mode: 'upsert' }
63
+ { src: 'adapters/generate-adapter/SKILL.md', dest: path.join(gemini, 'config/skills/generate-adapter/SKILL.md'), mode: 'upsert' },
64
+ { src: 'adapters/generate-workflow/SKILL.md', dest: path.join(gemini, 'config/skills/generate-workflow/SKILL.md'), mode: 'upsert' }
62
65
  ]
63
66
  },
64
67
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-engineering-loop",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "A reusable, framework-agnostic AI Engineering Operating System for autonomous coding agents.",
5
5
  "main": "bin/ai-engineering-loop.js",
6
6
  "bin": {
@@ -0,0 +1,8 @@
1
+ # Lessons
2
+
3
+ Confirmed by a human. One row per lesson. Not a chat transcript. Not a glossary.
4
+
5
+ Route elsewhere when it fits: term → glossary.md, code ban → conventions.md, load-bearing design → adrs/.
6
+
7
+ | Date | Lesson | Do not |
8
+ |---|---|---|
@@ -0,0 +1,25 @@
1
+ # Loop Overlay
2
+
3
+ This file adds hooks around the AI Engineering Loop. It does not replace the 8-stage OS.
4
+
5
+ ## Required (cannot skip)
6
+ - Goal Contract
7
+ - verification
8
+ - Devil's Advocate
9
+ - Judge
10
+
11
+ ## Hooks
12
+ - **before_grill**: none
13
+ - **after_freeze**: none
14
+ - **after_pass**: none
15
+
16
+ ## Maker intern
17
+ - **maker_intern**: none
18
+
19
+ Default `none` = parent is Maker. Any host-native label is allowed (gemini-flash, grok-mini, haiku, qwen, deepseek, ...). Not locked to one vendor. AEL does not store intern API keys. Devil's Advocate and Judge stay on the parent. Intern cannot skip them.
20
+
21
+ ## Optional skips
22
+ none
23
+
24
+ Allowed optional skips: `blast_radius` (when the change is not business logic), `generate_adapter` (when adapter.md already exists).
25
+ Do not list Goal Contract, verification, Devil's Advocate, or Judge here.
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ const test = require('node:test');
4
+ const assert = require('node:assert');
5
+ const { parseClaimedVsReality, readyForDa } = require('../lib/claimed-vs-reality.js');
6
+
7
+ test('AC-4 filled table is ready for DA', () => {
8
+ const md = `# Claimed vs Reality
9
+
10
+ | AC | Claimed | Reality |
11
+ |---|---|---|
12
+ | AC-1 | overlay writes workflow.md | npm test exit 0; AC-1 test passed |
13
+ | AC-2 | missing overlay is default | npm test exit 0; AC-2 test passed |
14
+ `;
15
+ const { rows } = parseClaimedVsReality(md);
16
+ assert.strictEqual(rows.length, 2);
17
+ assert.strictEqual(readyForDa(md), true);
18
+ });
19
+
20
+ test('AC-5 empty Reality or seems-green is not ready for DA', () => {
21
+ assert.strictEqual(readyForDa(''), false);
22
+ assert.strictEqual(readyForDa('# Claimed vs Reality\n'), false);
23
+ const emptyReality = `| AC | Claimed | Reality |\n|---|---|---|\n| AC-1 | tests pass | |\n`;
24
+ assert.strictEqual(readyForDa(emptyReality), false);
25
+ const seems = `| AC | Claimed | Reality |\n|---|---|---|\n| AC-1 | tests pass | seems green |\n`;
26
+ assert.strictEqual(readyForDa(seems), false);
27
+ });
@@ -0,0 +1,179 @@
1
+ 'use strict';
2
+
3
+ const test = require('node:test');
4
+ const assert = require('node:assert');
5
+ const fs = require('fs');
6
+ const os = require('os');
7
+ const path = require('path');
8
+ const { execFileSync } = require('child_process');
9
+
10
+ const {
11
+ parseWorkflowFile,
12
+ parseWorkflowMarkdown,
13
+ writeWorkflowOverlay,
14
+ assertNoRequiredSkip,
15
+ routeDurableNote,
16
+ parseWriteArg,
17
+ normalizeMakerIntern,
18
+ workflowMarkdown
19
+ } = require('../lib/generate-workflow.js');
20
+
21
+ const CLI = path.join(__dirname, '..', 'bin', 'ai-engineering-loop.js');
22
+
23
+ function tmpRepo() {
24
+ return fs.mkdtempSync(path.join(os.tmpdir(), 'ael-workflow-'));
25
+ }
26
+
27
+ test('AC-1 writeWorkflowOverlay writes workflow.md and empty lessons.md', () => {
28
+ const dir = tmpRepo();
29
+ const wrote = writeWorkflowOverlay(dir, {});
30
+ const workflow = fs.readFileSync(wrote.workflow, 'utf8');
31
+ const lessons = fs.readFileSync(wrote.lessons, 'utf8');
32
+ assert.match(workflow, /Goal Contract/);
33
+ assert.match(workflow, /Devil's Advocate/);
34
+ assert.match(workflow, /Judge/);
35
+ assert.match(workflow, /verification/);
36
+ assert.match(workflow, /before_grill/);
37
+ assert.doesNotMatch(workflow, /skip Devil's Advocate/i);
38
+ assert.match(lessons, /# Lessons/);
39
+ assert.doesNotMatch(lessons, /\| 20\d{2}-/);
40
+ });
41
+
42
+ test('AC-2 missing workflow.md returns default overlay', () => {
43
+ const dir = tmpRepo();
44
+ const parsed = parseWorkflowFile(dir);
45
+ assert.strictEqual(parsed.missing, true);
46
+ assert.strictEqual(parsed.hooks.before_grill, 'none');
47
+ assert.strictEqual(parsed.hooks.after_freeze, 'none');
48
+ assert.strictEqual(parsed.hooks.after_pass, 'none');
49
+ assert.deepStrictEqual(parsed.optionalSkips, []);
50
+ assert.deepStrictEqual(parsed.required, [
51
+ 'goal_contract',
52
+ 'verification',
53
+ 'devil_advocate',
54
+ 'judge'
55
+ ]);
56
+ });
57
+
58
+ test('AC-3 skip devil_advocate is rejected and does not write', () => {
59
+ const dir = tmpRepo();
60
+ assert.throws(
61
+ () => writeWorkflowOverlay(dir, { optionalSkips: ['devil_advocate'] }),
62
+ /cannot skip/
63
+ );
64
+ assert.ok(!fs.existsSync(path.join(dir, '.ai-engineering-loop', 'workflow.md')));
65
+ assert.throws(() => assertNoRequiredSkip(['judge']), /cannot skip/);
66
+ assert.throws(() => assertNoRequiredSkip(['goal_contract']), /cannot skip/);
67
+ assert.throws(() => assertNoRequiredSkip(['verification']), /cannot skip/);
68
+ assert.doesNotThrow(() => assertNoRequiredSkip(['blast_radius']));
69
+ });
70
+
71
+ test('AC-4 routeDurableNote sends term to glossary and process to lessons', () => {
72
+ assert.strictEqual(routeDurableNote('term'), 'glossary.md');
73
+ assert.strictEqual(routeDurableNote('process'), 'lessons.md');
74
+ assert.strictEqual(routeDurableNote('convention'), 'conventions.md');
75
+ assert.strictEqual(routeDurableNote('adr'), 'adrs/');
76
+ });
77
+
78
+ test('AC-5 --write does not overwrite filled lessons.md', () => {
79
+ const dir = tmpRepo();
80
+ const ctx = path.join(dir, '.ai-engineering-loop');
81
+ fs.mkdirSync(ctx, { recursive: true });
82
+ const lessonsPath = path.join(ctx, 'lessons.md');
83
+ fs.writeFileSync(lessonsPath, '# Lessons\n\n| Date | Lesson | Do not |\n|---|---|---|\n| 2026-08-30 | Keep the Figma step | skip Figma |\n');
84
+ writeWorkflowOverlay(dir, {});
85
+ const after = fs.readFileSync(lessonsPath, 'utf8');
86
+ assert.match(after, /Keep the Figma step/);
87
+ assert.ok(fs.existsSync(path.join(ctx, 'workflow.md')));
88
+ });
89
+
90
+ test('parseWriteArg reads --write', () => {
91
+ assert.strictEqual(parseWriteArg(['generate-workflow', '--write']), true);
92
+ assert.strictEqual(parseWriteArg(['generate-workflow']), false);
93
+ });
94
+
95
+ test('CLI generate-workflow without --write prints grill protocol', () => {
96
+ const dir = tmpRepo();
97
+ const out = execFileSync('node', [CLI, 'generate-workflow'], { cwd: dir, encoding: 'utf8' });
98
+ assert.match(out, /generate-workflow/);
99
+ assert.match(out, /Q1-Q6/);
100
+ assert.ok(!fs.existsSync(path.join(dir, '.ai-engineering-loop', 'workflow.md')));
101
+ });
102
+
103
+ test('CLI generate-workflow --write writes overlay files', () => {
104
+ const dir = tmpRepo();
105
+ const out = execFileSync('node', [CLI, 'generate-workflow', '--write'], {
106
+ cwd: dir,
107
+ encoding: 'utf8'
108
+ });
109
+ assert.match(out, /Wrote:/);
110
+ assert.ok(fs.existsSync(path.join(dir, '.ai-engineering-loop', 'workflow.md')));
111
+ assert.ok(fs.existsSync(path.join(dir, '.ai-engineering-loop', 'lessons.md')));
112
+ });
113
+
114
+ test('compact pipeline does not add overlay pipeline or Q7', () => {
115
+ const text = workflowMarkdown();
116
+ assert.doesNotMatch(text, /\*\*pipeline\*\*/);
117
+ assert.doesNotMatch(text, /## Pipeline/);
118
+ const skill = fs.readFileSync(
119
+ path.join(__dirname, '..', 'adapters', 'generate-workflow', 'SKILL.md'),
120
+ 'utf8'
121
+ );
122
+ assert.doesNotMatch(skill, /Q7/);
123
+ assert.match(skill, /Q1–Q6|Q1-Q6|Q1\.\.Q6|Q6/);
124
+ });
125
+
126
+ test('AC-1 default overlay maker_intern is none', () => {
127
+ const dir = tmpRepo();
128
+ const wrote = writeWorkflowOverlay(dir, {});
129
+ const workflow = fs.readFileSync(wrote.workflow, 'utf8');
130
+ const parsed = parseWorkflowFile(dir);
131
+ assert.match(workflow, /\*\*maker_intern\*\*: none/);
132
+ assert.strictEqual(parsed.makerIntern, 'none');
133
+ assert.match(workflowMarkdown(), /Not locked to one vendor/);
134
+ assert.match(workflowMarkdown(), /gemini-flash/);
135
+ });
136
+
137
+ test('AC-2 missing workflow.md makerIntern is none', () => {
138
+ const dir = tmpRepo();
139
+ const parsed = parseWorkflowFile(dir);
140
+ assert.strictEqual(parsed.missing, true);
141
+ assert.strictEqual(parsed.makerIntern, 'none');
142
+ });
143
+
144
+ test('AC-3 empty or None intern normalizes to none', () => {
145
+ assert.strictEqual(normalizeMakerIntern(''), 'none');
146
+ assert.strictEqual(normalizeMakerIntern('none'), 'none');
147
+ assert.strictEqual(normalizeMakerIntern('None'), 'none');
148
+ const parsed = parseWorkflowMarkdown('# Loop Overlay\n\n- **maker_intern**:\n');
149
+ assert.strictEqual(parsed.makerIntern, 'none');
150
+ });
151
+
152
+ test('AC-4 gemini-flash and haiku are valid intern labels', () => {
153
+ const dir = tmpRepo();
154
+ writeWorkflowOverlay(dir, { makerIntern: 'gemini-flash' });
155
+ assert.strictEqual(parseWorkflowFile(dir).makerIntern, 'gemini-flash');
156
+ writeWorkflowOverlay(dir, { makerIntern: 'haiku' });
157
+ assert.strictEqual(parseWorkflowFile(dir).makerIntern, 'haiku');
158
+ const text = workflowMarkdown();
159
+ assert.doesNotMatch(text, /must use qwen/i);
160
+ assert.doesNotMatch(text, /must use deepseek/i);
161
+ assert.doesNotMatch(text, /required: qwen/i);
162
+ });
163
+
164
+ test('AC-5 intern label does not allow skipping Devil\'s Advocate', () => {
165
+ const dir = tmpRepo();
166
+ assert.throws(
167
+ () => writeWorkflowOverlay(dir, { makerIntern: 'qwen', optionalSkips: ['devil_advocate'] }),
168
+ /cannot skip/
169
+ );
170
+ assert.ok(!fs.existsSync(path.join(dir, '.ai-engineering-loop', 'workflow.md')));
171
+ });
172
+
173
+ test('AC-6 intern rejects API keys and URLs', () => {
174
+ const dir = tmpRepo();
175
+ assert.throws(() => writeWorkflowOverlay(dir, { makerIntern: 'sk-abc' }), /not a key or URL/);
176
+ assert.throws(() => writeWorkflowOverlay(dir, { makerIntern: 'https://api.example.com' }), /not a key or URL/);
177
+ assert.throws(() => normalizeMakerIntern('openai_api_key'), /not a key or URL/);
178
+ assert.ok(!fs.existsSync(path.join(dir, '.ai-engineering-loop', 'workflow.md')));
179
+ });
@@ -21,10 +21,16 @@ test('init writes glossary.md and adrs/README.md', () => {
21
21
  execFileSync('node', [CLI, 'init'], { cwd: dir, encoding: 'utf8' });
22
22
  const glossary = path.join(dir, '.ai-engineering-loop', 'glossary.md');
23
23
  const adr = path.join(dir, '.ai-engineering-loop', 'adrs', 'README.md');
24
+ const workflow = path.join(dir, '.ai-engineering-loop', 'workflow.md');
25
+ const lessons = path.join(dir, '.ai-engineering-loop', 'lessons.md');
24
26
  assert.ok(fs.existsSync(glossary));
25
27
  assert.ok(fs.existsSync(adr));
28
+ assert.ok(fs.existsSync(workflow));
29
+ assert.ok(fs.existsSync(lessons));
26
30
  assert.match(fs.readFileSync(glossary, 'utf8'), /Ubiquitous Language/);
27
31
  assert.match(fs.readFileSync(adr, 'utf8'), /Architecture Decision Records/);
32
+ assert.match(fs.readFileSync(workflow, 'utf8'), /before_grill/);
33
+ assert.match(fs.readFileSync(lessons, 'utf8'), /# Lessons/);
28
34
  });
29
35
 
30
36
  test('repair fills missing glossary without overwriting a filled glossary or architecture', () => {
@@ -44,3 +50,12 @@ test('repair fills missing glossary without overwriting a filled glossary or arc
44
50
  assert.match(fs.readFileSync(glossary, 'utf8'), /Foo: bar/);
45
51
  assert.ok(fs.existsSync(architecture));
46
52
  });
53
+
54
+ test('init does not overwrite filled lessons.md', () => {
55
+ const dir = tmpRepo();
56
+ execFileSync('node', [CLI, 'init'], { cwd: dir, encoding: 'utf8' });
57
+ const lessons = path.join(dir, '.ai-engineering-loop', 'lessons.md');
58
+ fs.writeFileSync(lessons, '# Lessons\n\n| Date | Lesson | Do not |\n|---|---|---|\n| 2026-08-30 | Keep Figma | skip Figma |\n');
59
+ execFileSync('node', [CLI, 'init'], { cwd: dir, encoding: 'utf8' });
60
+ assert.match(fs.readFileSync(lessons, 'utf8'), /Keep Figma/);
61
+ });