@izkac/forgekit 0.3.12 → 0.3.13
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/bin/forge.mjs +107 -107
- package/bin/forgekit.mjs +83 -83
- package/bin/review.mjs +81 -81
- package/package.json +1 -1
- package/scripts/prepack.mjs +78 -78
- package/scripts/run-tests.mjs +50 -50
- package/src/adr.mjs +236 -236
- package/src/adr.test.mjs +170 -170
- package/src/change.mjs +327 -234
- package/src/change.test.mjs +145 -83
- package/src/cleanup-sessions.mjs +84 -84
- package/src/config.mjs +103 -103
- package/src/defer.mjs +75 -75
- package/src/doctor.mjs +350 -341
- package/src/doctor.test.mjs +114 -114
- package/src/init.mjs +680 -621
- package/src/install.mjs +815 -815
- package/src/install.test.mjs +180 -180
- package/src/integrity-check.mjs +60 -60
- package/src/integrity.mjs +682 -682
- package/src/integrity.test.mjs +566 -566
- package/src/lib.mjs +143 -143
- package/src/models.defaults.json +41 -41
- package/src/new-session.mjs +99 -99
- package/src/openspec-overlays/README.md +19 -19
- package/src/openspec-overlays/openspec-apply-change-footer.md +14 -14
- package/src/openspec-overlays/opsx-apply-completion-step.md +1 -1
- package/src/openspec-overlays/opsx-apply-implement-step.md +11 -11
- package/src/paths.mjs +92 -92
- package/src/plan-engine.mjs +321 -278
- package/src/plan-engine.test.mjs +447 -283
- package/src/preferences.defaults.json +78 -78
- package/src/preferences.mjs +438 -438
- package/src/preferences.test.mjs +174 -174
- package/src/record-evidence.mjs +204 -204
- package/src/resolve-model.mjs +312 -312
- package/src/resolve-model.test.mjs +194 -194
- package/src/review/cli.test.mjs +117 -117
- package/src/review/export.mjs +172 -172
- package/src/review/export.test.mjs +197 -197
- package/src/review/fixtures/valid-review.json +42 -42
- package/src/review/lib.mjs +894 -894
- package/src/review/lib.test.mjs +266 -266
- package/src/review/schema.json +196 -196
- package/src/review/signals.test.mjs +62 -62
- package/src/score-cli.mjs +68 -68
- package/src/score.mjs +568 -568
- package/src/score.test.mjs +366 -366
- package/src/session-reminder.mjs +207 -207
- package/src/session-status.mjs +70 -70
- package/src/set-models.mjs +186 -186
- package/src/set-phase.mjs +205 -205
- package/src/set-prefs.mjs +294 -294
- package/src/specs-sync.mjs +234 -0
- package/src/specs-sync.test.mjs +114 -0
- package/src/spine.mjs +93 -93
- package/src/triage-prompt.mjs +175 -175
- package/src/triage-prompt.test.mjs +50 -50
- package/src/vendor-openspec-overlays.mjs +176 -176
- package/src/vendor-openspec-overlays.test.mjs +62 -62
- package/vendor/skills/archive-to-adr/SKILL.md +149 -149
- package/vendor/skills/forge/SKILL.md +136 -136
- package/vendor/skills/forge/docs/forge.md +650 -647
- package/vendor/skills/forge/phases/brainstorm.md +23 -23
- package/vendor/skills/forge/phases/finish.md +90 -87
- package/vendor/skills/forge/phases/implement.md +77 -77
- package/vendor/skills/forge/phases/plan-openspec.md +60 -60
- package/vendor/skills/forge/phases/plan-specs.md +163 -117
- package/vendor/skills/forge/phases/review.md +25 -25
- package/vendor/skills/forge/phases/verify.md +124 -124
- package/vendor/skills/forge/references/forge-layout.md +85 -85
- package/vendor/skills/forge/references/pace.md +115 -115
- package/vendor/skills/forge/references/plan-routing.md +52 -51
- package/vendor/skills/forge/references/runtime-integrity.md +232 -232
- package/vendor/skills/forge/references/substantial-work.md +37 -37
- package/vendor/skills/forge/references/test-evidence.md +30 -30
- package/vendor/skills/forge/references/test-strategy.md +68 -68
- package/vendor/skills/forge/skills/subagent-driven-development/SKILL.md +87 -87
- package/vendor/skills/forge/subagents/final-reviewer-prompt.md +56 -56
- package/vendor/skills/forge/subagents/implementer-prompt.md +38 -38
- package/vendor/skills/git-resolve-adr-conflict/SKILL.md +132 -132
- package/vendor/skills/thorough-code-review/SKILL.md +290 -290
- package/vendor/skills/thorough-code-review/examples.md +133 -133
- package/vendor/skills/thorough-code-review/reference/accepted-risks.md +26 -26
- package/vendor/skills/thorough-code-review/reference/lenses.md +96 -96
- package/vendor/skills/thorough-code-review/reference/phase1-scout.md +62 -62
- package/vendor/skills/thorough-code-review/reference/phase2-skeptic.md +105 -105
- package/vendor/skills/thorough-code-review/reference/report-schema.json +222 -222
- package/vendor/skills/thorough-code-review/reference/report-template.md +115 -115
- package/vendor/skills/thorough-code-review/reference/severity-rubric.md +49 -49
- package/vendor/skills/thorough-code-review/reference/signals-preflight.md +55 -55
- package/vendor/templates/adr/README.md +7 -7
- package/vendor/templates/adr/decisions.md +141 -141
- package/vendor/templates/adr/hooks/check-pending-adrs.mjs +74 -74
- package/vendor/templates/adr/hooks/check-pending-adrs.sh +3 -3
- package/vendor/templates/adr/hooks/openspec-archive-agent-message.mjs +52 -52
- package/vendor/templates/adr/hooks/openspec-archive-agent-message.sh +3 -3
- package/vendor/templates/project/claude/commands/forge-apply.md +75 -75
- package/vendor/templates/project/claude/commands/forge-brainstorm.md +7 -7
- package/vendor/templates/project/claude/commands/forge-build.md +17 -17
- package/vendor/templates/project/claude/commands/forge-plan.md +12 -12
- package/vendor/templates/project/claude/commands/forge-skip.md +14 -14
- package/vendor/templates/project/claude/commands/forge-status.md +16 -16
- package/vendor/templates/project/claude/commands/forge.md +16 -16
- package/vendor/templates/project/claude/hooks/forge-prompt-hook.mjs +73 -73
- package/vendor/templates/project/claude/hooks/forge-session-start.mjs +19 -19
- package/vendor/templates/project/claude/hooks/forge-triage-hook.mjs +77 -77
- package/vendor/templates/project/cursor/commands/forge-apply.md +75 -75
- package/vendor/templates/project/cursor/commands/forge-brainstorm.md +10 -10
- package/vendor/templates/project/cursor/commands/forge-build.md +17 -17
- package/vendor/templates/project/cursor/commands/forge-plan.md +15 -15
- package/vendor/templates/project/cursor/commands/forge-skip.md +14 -14
- package/vendor/templates/project/cursor/commands/forge-status.md +16 -16
- package/vendor/templates/project/cursor/commands/forge.md +16 -16
- package/vendor/templates/project/cursor/hooks/forge-session-start.mjs +30 -30
- package/vendor/templates/project/cursor/hooks/forge-session-start.sh +3 -3
package/src/record-evidence.mjs
CHANGED
|
@@ -1,204 +1,204 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Record tier-2 test evidence for a Forge implement task.
|
|
4
|
-
*
|
|
5
|
-
* Writes `.forge/sessions/<session-id>/tasks/<task>/test-evidence.md` using
|
|
6
|
-
* the canonical template from the forge skill
|
|
7
|
-
* (`references/test-evidence.md`). An existing file is overwritten — the
|
|
8
|
-
* latest run wins. A non-zero `--exit` is refused unless `--allow-fail`
|
|
9
|
-
* is passed.
|
|
10
|
-
*
|
|
11
|
-
* Usage:
|
|
12
|
-
* forge record-evidence --task <nn-slug> --command <cmd> --exit <code> --summary <text> [options]
|
|
13
|
-
*
|
|
14
|
-
* Options:
|
|
15
|
-
* --task <nn-slug> Task directory name, e.g. 03-record-evidence (required)
|
|
16
|
-
* --command <cmd> Test command that was run (required)
|
|
17
|
-
* --exit <code> Exit code of the test command (required, integer)
|
|
18
|
-
* --summary <text> Pass/fail summary, e.g. "3/3 pass" (required)
|
|
19
|
-
* --tier <label> Tier label (default: "2 (task-scoped — not full workspace unless noted)")
|
|
20
|
-
* --session <id> Session id (default: sessionId from .forge/active.json)
|
|
21
|
-
* --allow-fail Write evidence even when --exit is non-zero
|
|
22
|
-
* --forge-dir <path> Forge root directory (default: .forge under cwd)
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import fs from 'node:fs';
|
|
26
|
-
import path from 'node:path';
|
|
27
|
-
import { pathToFileURL } from 'node:url';
|
|
28
|
-
|
|
29
|
-
export const DEFAULT_TIER = '2 (task-scoped — not full workspace unless noted)';
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @param {string[]} argv
|
|
33
|
-
*/
|
|
34
|
-
export function parseArgs(argv) {
|
|
35
|
-
const opts = {
|
|
36
|
-
task: null,
|
|
37
|
-
command: null,
|
|
38
|
-
exit: null,
|
|
39
|
-
summary: null,
|
|
40
|
-
tier: null,
|
|
41
|
-
session: null,
|
|
42
|
-
allowFail: false,
|
|
43
|
-
forgeDir: null,
|
|
44
|
-
help: false,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
48
|
-
const arg = argv[i];
|
|
49
|
-
if (arg === '--task') opts.task = argv[++i];
|
|
50
|
-
else if (arg === '--command') opts.command = argv[++i];
|
|
51
|
-
else if (arg === '--exit') opts.exit = argv[++i];
|
|
52
|
-
else if (arg === '--summary') opts.summary = argv[++i];
|
|
53
|
-
else if (arg === '--tier') opts.tier = argv[++i];
|
|
54
|
-
else if (arg === '--session') opts.session = argv[++i];
|
|
55
|
-
else if (arg === '--allow-fail') opts.allowFail = true;
|
|
56
|
-
else if (arg === '--forge-dir') opts.forgeDir = argv[++i];
|
|
57
|
-
else if (arg === '--help' || arg === '-h') opts.help = true;
|
|
58
|
-
else throw new Error(`unknown argument: ${arg}`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return opts;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Render the canonical test-evidence template.
|
|
66
|
-
*
|
|
67
|
-
* @param {{ task: string, tier: string, command: string, exit: number, summary: string, runAt: string }} fields
|
|
68
|
-
* @returns {string}
|
|
69
|
-
*/
|
|
70
|
-
export function buildEvidence({ task, tier, command, exit, summary, runAt }) {
|
|
71
|
-
return [
|
|
72
|
-
`# Test evidence — Task ${task}`,
|
|
73
|
-
'',
|
|
74
|
-
`- **Tier:** ${tier}`,
|
|
75
|
-
`- **Command:** \`${command}\``,
|
|
76
|
-
`- **Exit code:** ${exit}`,
|
|
77
|
-
`- **Summary:** ${summary}`,
|
|
78
|
-
`- **Run at:** ${runAt}`,
|
|
79
|
-
'- **Recorded by:** implementer subagent (coordinator transcript)',
|
|
80
|
-
'',
|
|
81
|
-
].join('\n');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Resolve the session id: explicit `--session` wins, otherwise the sessionId
|
|
86
|
-
* from `<forgeDir>/active.json`.
|
|
87
|
-
*
|
|
88
|
-
* @param {string | null} session
|
|
89
|
-
* @param {string} forgeDir
|
|
90
|
-
* @returns {string | null}
|
|
91
|
-
*/
|
|
92
|
-
function resolveSessionId(session, forgeDir) {
|
|
93
|
-
if (session) return session;
|
|
94
|
-
const activeFile = path.join(forgeDir, 'active.json');
|
|
95
|
-
if (!fs.existsSync(activeFile)) return null;
|
|
96
|
-
try {
|
|
97
|
-
const active = JSON.parse(fs.readFileSync(activeFile, 'utf8'));
|
|
98
|
-
return typeof active?.sessionId === 'string' ? active.sessionId : null;
|
|
99
|
-
} catch {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @param {ReturnType<typeof parseArgs>} opts
|
|
106
|
-
* @param {string} [cwd]
|
|
107
|
-
* @param {() => Date} [now]
|
|
108
|
-
* @returns {{ exitCode: number; message: string }}
|
|
109
|
-
*/
|
|
110
|
-
export function runRecordEvidence(opts, cwd = process.cwd(), now = () => new Date()) {
|
|
111
|
-
for (const field of ['task', 'command', 'exit', 'summary']) {
|
|
112
|
-
if (!opts[field]) {
|
|
113
|
-
return { exitCode: 1, message: `--${field} is required` };
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const testExit = Number(opts.exit);
|
|
118
|
-
if (!Number.isInteger(testExit)) {
|
|
119
|
-
return { exitCode: 1, message: `--exit must be an integer, got: ${opts.exit}` };
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const forgeDir = path.resolve(cwd, opts.forgeDir ?? '.forge');
|
|
123
|
-
const sessionId = resolveSessionId(opts.session, forgeDir);
|
|
124
|
-
if (!sessionId) {
|
|
125
|
-
return { exitCode: 1, message: 'No active session. Run forge:new first or pass --session.' };
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const sessionDir = path.join(forgeDir, 'sessions', sessionId);
|
|
129
|
-
if (!fs.existsSync(sessionDir)) {
|
|
130
|
-
return { exitCode: 1, message: `Session dir not found: ${sessionDir} (session ${sessionId})` };
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (testExit !== 0 && !opts.allowFail) {
|
|
134
|
-
return {
|
|
135
|
-
exitCode: 1,
|
|
136
|
-
message: `Refusing to record failing evidence (exit code ${testExit}). Fix the tests and re-run, or pass --allow-fail to record anyway.`,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const taskDir = path.join(sessionDir, 'tasks', opts.task);
|
|
141
|
-
fs.mkdirSync(taskDir, { recursive: true });
|
|
142
|
-
|
|
143
|
-
const filePath = path.join(taskDir, 'test-evidence.md');
|
|
144
|
-
fs.writeFileSync(
|
|
145
|
-
filePath,
|
|
146
|
-
buildEvidence({
|
|
147
|
-
task: opts.task,
|
|
148
|
-
tier: opts.tier ?? DEFAULT_TIER,
|
|
149
|
-
command: opts.command,
|
|
150
|
-
exit: testExit,
|
|
151
|
-
summary: opts.summary,
|
|
152
|
-
runAt: now().toISOString(),
|
|
153
|
-
}),
|
|
154
|
-
'utf8',
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
return { exitCode: 0, message: `wrote: ${filePath}` };
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function printHelp() {
|
|
161
|
-
console.log(`Usage: forge record-evidence --task <nn-slug> --command <cmd> --exit <code> --summary <text> [options]
|
|
162
|
-
|
|
163
|
-
Record tier-2 test evidence for a Forge implement task at
|
|
164
|
-
.forge/sessions/<session-id>/tasks/<task>/test-evidence.md (latest run wins).
|
|
165
|
-
|
|
166
|
-
Options:
|
|
167
|
-
--task <nn-slug> Task directory name, e.g. 03-record-evidence (required)
|
|
168
|
-
--command <cmd> Test command that was run (required)
|
|
169
|
-
--exit <code> Exit code of the test command (required, integer)
|
|
170
|
-
--summary <text> Pass/fail summary, e.g. "3/3 pass" (required)
|
|
171
|
-
--tier <label> Tier label (default: "${DEFAULT_TIER}")
|
|
172
|
-
--session <id> Session id (default: sessionId from .forge/active.json)
|
|
173
|
-
--allow-fail Write evidence even when --exit is non-zero
|
|
174
|
-
--forge-dir <path> Forge root directory (default: .forge under cwd)
|
|
175
|
-
-h, --help Show this help
|
|
176
|
-
`);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function main() {
|
|
180
|
-
try {
|
|
181
|
-
const opts = parseArgs(process.argv.slice(2));
|
|
182
|
-
if (opts.help) {
|
|
183
|
-
printHelp();
|
|
184
|
-
process.exit(0);
|
|
185
|
-
}
|
|
186
|
-
const result = runRecordEvidence(opts);
|
|
187
|
-
if (result.exitCode === 0) {
|
|
188
|
-
console.log(result.message);
|
|
189
|
-
} else {
|
|
190
|
-
console.error(result.message);
|
|
191
|
-
}
|
|
192
|
-
process.exit(result.exitCode);
|
|
193
|
-
} catch (err) {
|
|
194
|
-
console.error(/** @type {Error} */ (err).message);
|
|
195
|
-
process.exit(1);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const isMain =
|
|
200
|
-
process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href;
|
|
201
|
-
|
|
202
|
-
if (isMain) {
|
|
203
|
-
main();
|
|
204
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Record tier-2 test evidence for a Forge implement task.
|
|
4
|
+
*
|
|
5
|
+
* Writes `.forge/sessions/<session-id>/tasks/<task>/test-evidence.md` using
|
|
6
|
+
* the canonical template from the forge skill
|
|
7
|
+
* (`references/test-evidence.md`). An existing file is overwritten — the
|
|
8
|
+
* latest run wins. A non-zero `--exit` is refused unless `--allow-fail`
|
|
9
|
+
* is passed.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* forge record-evidence --task <nn-slug> --command <cmd> --exit <code> --summary <text> [options]
|
|
13
|
+
*
|
|
14
|
+
* Options:
|
|
15
|
+
* --task <nn-slug> Task directory name, e.g. 03-record-evidence (required)
|
|
16
|
+
* --command <cmd> Test command that was run (required)
|
|
17
|
+
* --exit <code> Exit code of the test command (required, integer)
|
|
18
|
+
* --summary <text> Pass/fail summary, e.g. "3/3 pass" (required)
|
|
19
|
+
* --tier <label> Tier label (default: "2 (task-scoped — not full workspace unless noted)")
|
|
20
|
+
* --session <id> Session id (default: sessionId from .forge/active.json)
|
|
21
|
+
* --allow-fail Write evidence even when --exit is non-zero
|
|
22
|
+
* --forge-dir <path> Forge root directory (default: .forge under cwd)
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import fs from 'node:fs';
|
|
26
|
+
import path from 'node:path';
|
|
27
|
+
import { pathToFileURL } from 'node:url';
|
|
28
|
+
|
|
29
|
+
export const DEFAULT_TIER = '2 (task-scoped — not full workspace unless noted)';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {string[]} argv
|
|
33
|
+
*/
|
|
34
|
+
export function parseArgs(argv) {
|
|
35
|
+
const opts = {
|
|
36
|
+
task: null,
|
|
37
|
+
command: null,
|
|
38
|
+
exit: null,
|
|
39
|
+
summary: null,
|
|
40
|
+
tier: null,
|
|
41
|
+
session: null,
|
|
42
|
+
allowFail: false,
|
|
43
|
+
forgeDir: null,
|
|
44
|
+
help: false,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
48
|
+
const arg = argv[i];
|
|
49
|
+
if (arg === '--task') opts.task = argv[++i];
|
|
50
|
+
else if (arg === '--command') opts.command = argv[++i];
|
|
51
|
+
else if (arg === '--exit') opts.exit = argv[++i];
|
|
52
|
+
else if (arg === '--summary') opts.summary = argv[++i];
|
|
53
|
+
else if (arg === '--tier') opts.tier = argv[++i];
|
|
54
|
+
else if (arg === '--session') opts.session = argv[++i];
|
|
55
|
+
else if (arg === '--allow-fail') opts.allowFail = true;
|
|
56
|
+
else if (arg === '--forge-dir') opts.forgeDir = argv[++i];
|
|
57
|
+
else if (arg === '--help' || arg === '-h') opts.help = true;
|
|
58
|
+
else throw new Error(`unknown argument: ${arg}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return opts;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Render the canonical test-evidence template.
|
|
66
|
+
*
|
|
67
|
+
* @param {{ task: string, tier: string, command: string, exit: number, summary: string, runAt: string }} fields
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
export function buildEvidence({ task, tier, command, exit, summary, runAt }) {
|
|
71
|
+
return [
|
|
72
|
+
`# Test evidence — Task ${task}`,
|
|
73
|
+
'',
|
|
74
|
+
`- **Tier:** ${tier}`,
|
|
75
|
+
`- **Command:** \`${command}\``,
|
|
76
|
+
`- **Exit code:** ${exit}`,
|
|
77
|
+
`- **Summary:** ${summary}`,
|
|
78
|
+
`- **Run at:** ${runAt}`,
|
|
79
|
+
'- **Recorded by:** implementer subagent (coordinator transcript)',
|
|
80
|
+
'',
|
|
81
|
+
].join('\n');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Resolve the session id: explicit `--session` wins, otherwise the sessionId
|
|
86
|
+
* from `<forgeDir>/active.json`.
|
|
87
|
+
*
|
|
88
|
+
* @param {string | null} session
|
|
89
|
+
* @param {string} forgeDir
|
|
90
|
+
* @returns {string | null}
|
|
91
|
+
*/
|
|
92
|
+
function resolveSessionId(session, forgeDir) {
|
|
93
|
+
if (session) return session;
|
|
94
|
+
const activeFile = path.join(forgeDir, 'active.json');
|
|
95
|
+
if (!fs.existsSync(activeFile)) return null;
|
|
96
|
+
try {
|
|
97
|
+
const active = JSON.parse(fs.readFileSync(activeFile, 'utf8'));
|
|
98
|
+
return typeof active?.sessionId === 'string' ? active.sessionId : null;
|
|
99
|
+
} catch {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param {ReturnType<typeof parseArgs>} opts
|
|
106
|
+
* @param {string} [cwd]
|
|
107
|
+
* @param {() => Date} [now]
|
|
108
|
+
* @returns {{ exitCode: number; message: string }}
|
|
109
|
+
*/
|
|
110
|
+
export function runRecordEvidence(opts, cwd = process.cwd(), now = () => new Date()) {
|
|
111
|
+
for (const field of ['task', 'command', 'exit', 'summary']) {
|
|
112
|
+
if (!opts[field]) {
|
|
113
|
+
return { exitCode: 1, message: `--${field} is required` };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const testExit = Number(opts.exit);
|
|
118
|
+
if (!Number.isInteger(testExit)) {
|
|
119
|
+
return { exitCode: 1, message: `--exit must be an integer, got: ${opts.exit}` };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const forgeDir = path.resolve(cwd, opts.forgeDir ?? '.forge');
|
|
123
|
+
const sessionId = resolveSessionId(opts.session, forgeDir);
|
|
124
|
+
if (!sessionId) {
|
|
125
|
+
return { exitCode: 1, message: 'No active session. Run forge:new first or pass --session.' };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const sessionDir = path.join(forgeDir, 'sessions', sessionId);
|
|
129
|
+
if (!fs.existsSync(sessionDir)) {
|
|
130
|
+
return { exitCode: 1, message: `Session dir not found: ${sessionDir} (session ${sessionId})` };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (testExit !== 0 && !opts.allowFail) {
|
|
134
|
+
return {
|
|
135
|
+
exitCode: 1,
|
|
136
|
+
message: `Refusing to record failing evidence (exit code ${testExit}). Fix the tests and re-run, or pass --allow-fail to record anyway.`,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const taskDir = path.join(sessionDir, 'tasks', opts.task);
|
|
141
|
+
fs.mkdirSync(taskDir, { recursive: true });
|
|
142
|
+
|
|
143
|
+
const filePath = path.join(taskDir, 'test-evidence.md');
|
|
144
|
+
fs.writeFileSync(
|
|
145
|
+
filePath,
|
|
146
|
+
buildEvidence({
|
|
147
|
+
task: opts.task,
|
|
148
|
+
tier: opts.tier ?? DEFAULT_TIER,
|
|
149
|
+
command: opts.command,
|
|
150
|
+
exit: testExit,
|
|
151
|
+
summary: opts.summary,
|
|
152
|
+
runAt: now().toISOString(),
|
|
153
|
+
}),
|
|
154
|
+
'utf8',
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
return { exitCode: 0, message: `wrote: ${filePath}` };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function printHelp() {
|
|
161
|
+
console.log(`Usage: forge record-evidence --task <nn-slug> --command <cmd> --exit <code> --summary <text> [options]
|
|
162
|
+
|
|
163
|
+
Record tier-2 test evidence for a Forge implement task at
|
|
164
|
+
.forge/sessions/<session-id>/tasks/<task>/test-evidence.md (latest run wins).
|
|
165
|
+
|
|
166
|
+
Options:
|
|
167
|
+
--task <nn-slug> Task directory name, e.g. 03-record-evidence (required)
|
|
168
|
+
--command <cmd> Test command that was run (required)
|
|
169
|
+
--exit <code> Exit code of the test command (required, integer)
|
|
170
|
+
--summary <text> Pass/fail summary, e.g. "3/3 pass" (required)
|
|
171
|
+
--tier <label> Tier label (default: "${DEFAULT_TIER}")
|
|
172
|
+
--session <id> Session id (default: sessionId from .forge/active.json)
|
|
173
|
+
--allow-fail Write evidence even when --exit is non-zero
|
|
174
|
+
--forge-dir <path> Forge root directory (default: .forge under cwd)
|
|
175
|
+
-h, --help Show this help
|
|
176
|
+
`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function main() {
|
|
180
|
+
try {
|
|
181
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
182
|
+
if (opts.help) {
|
|
183
|
+
printHelp();
|
|
184
|
+
process.exit(0);
|
|
185
|
+
}
|
|
186
|
+
const result = runRecordEvidence(opts);
|
|
187
|
+
if (result.exitCode === 0) {
|
|
188
|
+
console.log(result.message);
|
|
189
|
+
} else {
|
|
190
|
+
console.error(result.message);
|
|
191
|
+
}
|
|
192
|
+
process.exit(result.exitCode);
|
|
193
|
+
} catch (err) {
|
|
194
|
+
console.error(/** @type {Error} */ (err).message);
|
|
195
|
+
process.exit(1);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const isMain =
|
|
200
|
+
process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href;
|
|
201
|
+
|
|
202
|
+
if (isMain) {
|
|
203
|
+
main();
|
|
204
|
+
}
|