@izkac/forgekit 0.3.11 → 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 -566
- package/src/score.test.mjs +366 -340
- 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 -225
- 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/change.test.mjs
CHANGED
|
@@ -1,83 +1,145 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import os from 'node:os';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import {
|
|
7
|
-
assertChangeName,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
assert.
|
|
22
|
-
assert.throws(() => assertChangeName('
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
assert.equal(
|
|
28
|
-
assert.
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
assert.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
assertChangeName,
|
|
8
|
+
assertCapabilityName,
|
|
9
|
+
archiveSpecsChange,
|
|
10
|
+
createSpecsChange,
|
|
11
|
+
parseArgs,
|
|
12
|
+
runChange,
|
|
13
|
+
} from './change.mjs';
|
|
14
|
+
import { writeProjectPlanConfig, scaffoldSpecs } from './plan-engine.mjs';
|
|
15
|
+
|
|
16
|
+
function tmp() {
|
|
17
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), 'forgekit-change-'));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
test('assertChangeName accepts kebab-case', () => {
|
|
21
|
+
assert.equal(assertChangeName('add-auth'), 'add-auth');
|
|
22
|
+
assert.throws(() => assertChangeName('Add Auth'), /kebab-case/);
|
|
23
|
+
assert.throws(() => assertChangeName('UPPER'), /kebab-case/);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('assertCapabilityName accepts kebab-case', () => {
|
|
27
|
+
assert.equal(assertCapabilityName('auth'), 'auth');
|
|
28
|
+
assert.throws(() => assertCapabilityName('Auth'), /kebab-case/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('parseArgs new and archive with capabilities', () => {
|
|
32
|
+
assert.deepEqual(parseArgs(['new', 'foo', '--force']).action, 'new');
|
|
33
|
+
assert.equal(parseArgs(['new', 'foo']).name, 'foo');
|
|
34
|
+
assert.equal(parseArgs(['archive', 'foo', '--date', '2026-01-02']).date, '2026-01-02');
|
|
35
|
+
assert.deepEqual(
|
|
36
|
+
parseArgs(['new', 'foo', '--capability', 'auth', '--cap', 'payments']).capabilities,
|
|
37
|
+
['auth', 'payments'],
|
|
38
|
+
);
|
|
39
|
+
assert.equal(parseArgs(['archive', 'foo', '--no-sync']).noSync, true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('createSpecsChange writes OpenSpec-parity artefacts including deltas', () => {
|
|
43
|
+
const cwd = tmp();
|
|
44
|
+
try {
|
|
45
|
+
writeProjectPlanConfig(cwd, { engine: 'specs' });
|
|
46
|
+
scaffoldSpecs(cwd);
|
|
47
|
+
const result = createSpecsChange(cwd, 'add-refunds', {
|
|
48
|
+
force: true,
|
|
49
|
+
capabilities: ['payments'],
|
|
50
|
+
});
|
|
51
|
+
assert.ok(fs.existsSync(path.join(result.changeDir, 'proposal.md')));
|
|
52
|
+
assert.ok(fs.existsSync(path.join(result.changeDir, 'design.md')));
|
|
53
|
+
assert.ok(fs.existsSync(path.join(result.changeDir, 'tasks.md')));
|
|
54
|
+
assert.ok(fs.existsSync(path.join(result.changeDir, 'specs', 'payments', 'spec.md')));
|
|
55
|
+
const proposal = fs.readFileSync(path.join(result.changeDir, 'proposal.md'), 'utf8');
|
|
56
|
+
assert.match(proposal, /## Capabilities/);
|
|
57
|
+
assert.match(proposal, /`payments`/);
|
|
58
|
+
const delta = fs.readFileSync(
|
|
59
|
+
path.join(result.changeDir, 'specs', 'payments', 'spec.md'),
|
|
60
|
+
'utf8',
|
|
61
|
+
);
|
|
62
|
+
assert.match(delta, /## ADDED Requirements/);
|
|
63
|
+
} finally {
|
|
64
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('createSpecsChange rejects openspec engine', () => {
|
|
69
|
+
const cwd = tmp();
|
|
70
|
+
try {
|
|
71
|
+
writeProjectPlanConfig(cwd, { engine: 'openspec' });
|
|
72
|
+
assert.throws(() => createSpecsChange(cwd, 'x'), /not "specs"/);
|
|
73
|
+
} finally {
|
|
74
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('createSpecsChange honors custom plan.dir', () => {
|
|
79
|
+
const cwd = tmp();
|
|
80
|
+
try {
|
|
81
|
+
writeProjectPlanConfig(cwd, { engine: 'specs', dir: 'openspec' });
|
|
82
|
+
scaffoldSpecs(cwd, { dir: 'openspec' });
|
|
83
|
+
const result = createSpecsChange(cwd, 'reuse-tree', {
|
|
84
|
+
force: true,
|
|
85
|
+
capabilities: ['auth'],
|
|
86
|
+
});
|
|
87
|
+
assert.equal(result.dir, 'openspec');
|
|
88
|
+
assert.ok(
|
|
89
|
+
fs.existsSync(path.join(cwd, 'openspec', 'changes', 'reuse-tree', 'specs', 'auth', 'spec.md')),
|
|
90
|
+
);
|
|
91
|
+
} finally {
|
|
92
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('archiveSpecsChange merges deltas then moves to dated archive', () => {
|
|
97
|
+
const cwd = tmp();
|
|
98
|
+
try {
|
|
99
|
+
writeProjectPlanConfig(cwd, { engine: 'specs' });
|
|
100
|
+
scaffoldSpecs(cwd);
|
|
101
|
+
createSpecsChange(cwd, 'ship-it', { force: true, capabilities: ['auth'] });
|
|
102
|
+
const archived = archiveSpecsChange(cwd, 'ship-it', { date: '2026-07-18' });
|
|
103
|
+
assert.equal(archived.to, 'specs/changes/archive/2026-07-18-ship-it');
|
|
104
|
+
assert.ok(!fs.existsSync(path.join(cwd, 'specs', 'changes', 'ship-it')));
|
|
105
|
+
assert.ok(
|
|
106
|
+
fs.existsSync(
|
|
107
|
+
path.join(cwd, 'specs', 'changes', 'archive', '2026-07-18-ship-it', 'proposal.md'),
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
assert.ok(fs.existsSync(path.join(cwd, 'specs', 'specs', 'auth', 'spec.md')));
|
|
111
|
+
assert.equal(archived.synced.length, 1);
|
|
112
|
+
assert.equal(archived.synced[0].capability, 'auth');
|
|
113
|
+
} finally {
|
|
114
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('archiveSpecsChange --no-sync skips main catalog merge', () => {
|
|
119
|
+
const cwd = tmp();
|
|
120
|
+
try {
|
|
121
|
+
writeProjectPlanConfig(cwd, { engine: 'specs' });
|
|
122
|
+
scaffoldSpecs(cwd);
|
|
123
|
+
createSpecsChange(cwd, 'no-merge', { force: true, capabilities: ['auth'] });
|
|
124
|
+
const archived = archiveSpecsChange(cwd, 'no-merge', {
|
|
125
|
+
date: '2026-07-18',
|
|
126
|
+
noSync: true,
|
|
127
|
+
});
|
|
128
|
+
assert.deepEqual(archived.synced, []);
|
|
129
|
+
assert.ok(!fs.existsSync(path.join(cwd, 'specs', 'specs', 'auth', 'spec.md')));
|
|
130
|
+
} finally {
|
|
131
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('runChange new prints next steps', () => {
|
|
136
|
+
const cwd = tmp();
|
|
137
|
+
try {
|
|
138
|
+
writeProjectPlanConfig(cwd, { engine: 'specs' });
|
|
139
|
+
scaffoldSpecs(cwd);
|
|
140
|
+
const code = runChange(['new', 'demo-feat', '--cwd', cwd, '--capability', 'demo']);
|
|
141
|
+
assert.equal(code, 0);
|
|
142
|
+
} finally {
|
|
143
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
144
|
+
}
|
|
145
|
+
});
|
package/src/cleanup-sessions.mjs
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Remove Forge sessions older than RETENTION_DAYS (default 14).
|
|
4
|
-
* Skips the active session unless --include-active is passed.
|
|
5
|
-
*
|
|
6
|
-
* Usage:
|
|
7
|
-
* forge cleanup
|
|
8
|
-
* forge cleanup-sessions [--dry-run] [--include-active]
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import fs from 'node:fs';
|
|
12
|
-
import path from 'node:path';
|
|
13
|
-
import {
|
|
14
|
-
clearActive,
|
|
15
|
-
loadSession,
|
|
16
|
-
readActive,
|
|
17
|
-
RETENTION_DAYS,
|
|
18
|
-
SESSIONS_DIR,
|
|
19
|
-
sessionAgeDays,
|
|
20
|
-
} from './lib.mjs';
|
|
21
|
-
import { unregisterSession } from './lib/fleet.mjs';
|
|
22
|
-
import { appendScorecardLedger } from './score.mjs';
|
|
23
|
-
|
|
24
|
-
const args = new Set(process.argv.slice(2));
|
|
25
|
-
const dryRun = args.has('--dry-run');
|
|
26
|
-
const includeActive = args.has('--include-active');
|
|
27
|
-
|
|
28
|
-
const active = readActive();
|
|
29
|
-
const activeId = active?.sessionId ?? null;
|
|
30
|
-
const removed = [];
|
|
31
|
-
const kept = [];
|
|
32
|
-
|
|
33
|
-
if (!fs.existsSync(SESSIONS_DIR)) {
|
|
34
|
-
process.stdout.write(JSON.stringify({ removed, kept, dryRun }, null, 2));
|
|
35
|
-
process.stdout.write('\n');
|
|
36
|
-
process.exit(0);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
for (const entry of fs.readdirSync(SESSIONS_DIR, { withFileTypes: true })) {
|
|
40
|
-
if (!entry.isDirectory()) continue;
|
|
41
|
-
const sessionId = entry.name;
|
|
42
|
-
const dir = path.join(SESSIONS_DIR, sessionId);
|
|
43
|
-
const sessionFile = path.join(dir, 'session.json');
|
|
44
|
-
if (!fs.existsSync(sessionFile)) continue;
|
|
45
|
-
|
|
46
|
-
let session;
|
|
47
|
-
try {
|
|
48
|
-
({ session } = loadSession(sessionId));
|
|
49
|
-
} catch {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const isActive = sessionId === activeId;
|
|
54
|
-
const tooOld = sessionAgeDays(session) > RETENTION_DAYS;
|
|
55
|
-
const isDone = session.phase === 'done' || session.phase === 'skipped';
|
|
56
|
-
|
|
57
|
-
const shouldRemove =
|
|
58
|
-
(tooOld || isDone) && (!isActive || includeActive);
|
|
59
|
-
|
|
60
|
-
if (shouldRemove) {
|
|
61
|
-
if (!dryRun) {
|
|
62
|
-
// Harvest the scorecard into the durable ledger before the session dir
|
|
63
|
-
// (and its scoring history) is erased. Covers sessions scored before
|
|
64
|
-
// the ledger existed; a no-op when the ledger already has the line.
|
|
65
|
-
try {
|
|
66
|
-
const cardFile = path.join(dir, 'scorecard.json');
|
|
67
|
-
if (fs.existsSync(cardFile)) {
|
|
68
|
-
appendScorecardLedger(dir, JSON.parse(fs.readFileSync(cardFile, 'utf8')), session);
|
|
69
|
-
}
|
|
70
|
-
} catch {
|
|
71
|
-
/* ledger is advisory — never block cleanup */
|
|
72
|
-
}
|
|
73
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
74
|
-
if (isActive) clearActive();
|
|
75
|
-
unregisterSession(process.cwd(), sessionId);
|
|
76
|
-
}
|
|
77
|
-
removed.push({ sessionId, reason: tooOld ? 'retention' : 'finished' });
|
|
78
|
-
} else {
|
|
79
|
-
kept.push({ sessionId, phase: session.phase, ageDays: sessionAgeDays(session).toFixed(1) });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
process.stdout.write(JSON.stringify({ removed, kept, dryRun, retentionDays: RETENTION_DAYS }, null, 2));
|
|
84
|
-
process.stdout.write('\n');
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Remove Forge sessions older than RETENTION_DAYS (default 14).
|
|
4
|
+
* Skips the active session unless --include-active is passed.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* forge cleanup
|
|
8
|
+
* forge cleanup-sessions [--dry-run] [--include-active]
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import {
|
|
14
|
+
clearActive,
|
|
15
|
+
loadSession,
|
|
16
|
+
readActive,
|
|
17
|
+
RETENTION_DAYS,
|
|
18
|
+
SESSIONS_DIR,
|
|
19
|
+
sessionAgeDays,
|
|
20
|
+
} from './lib.mjs';
|
|
21
|
+
import { unregisterSession } from './lib/fleet.mjs';
|
|
22
|
+
import { appendScorecardLedger } from './score.mjs';
|
|
23
|
+
|
|
24
|
+
const args = new Set(process.argv.slice(2));
|
|
25
|
+
const dryRun = args.has('--dry-run');
|
|
26
|
+
const includeActive = args.has('--include-active');
|
|
27
|
+
|
|
28
|
+
const active = readActive();
|
|
29
|
+
const activeId = active?.sessionId ?? null;
|
|
30
|
+
const removed = [];
|
|
31
|
+
const kept = [];
|
|
32
|
+
|
|
33
|
+
if (!fs.existsSync(SESSIONS_DIR)) {
|
|
34
|
+
process.stdout.write(JSON.stringify({ removed, kept, dryRun }, null, 2));
|
|
35
|
+
process.stdout.write('\n');
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
for (const entry of fs.readdirSync(SESSIONS_DIR, { withFileTypes: true })) {
|
|
40
|
+
if (!entry.isDirectory()) continue;
|
|
41
|
+
const sessionId = entry.name;
|
|
42
|
+
const dir = path.join(SESSIONS_DIR, sessionId);
|
|
43
|
+
const sessionFile = path.join(dir, 'session.json');
|
|
44
|
+
if (!fs.existsSync(sessionFile)) continue;
|
|
45
|
+
|
|
46
|
+
let session;
|
|
47
|
+
try {
|
|
48
|
+
({ session } = loadSession(sessionId));
|
|
49
|
+
} catch {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const isActive = sessionId === activeId;
|
|
54
|
+
const tooOld = sessionAgeDays(session) > RETENTION_DAYS;
|
|
55
|
+
const isDone = session.phase === 'done' || session.phase === 'skipped';
|
|
56
|
+
|
|
57
|
+
const shouldRemove =
|
|
58
|
+
(tooOld || isDone) && (!isActive || includeActive);
|
|
59
|
+
|
|
60
|
+
if (shouldRemove) {
|
|
61
|
+
if (!dryRun) {
|
|
62
|
+
// Harvest the scorecard into the durable ledger before the session dir
|
|
63
|
+
// (and its scoring history) is erased. Covers sessions scored before
|
|
64
|
+
// the ledger existed; a no-op when the ledger already has the line.
|
|
65
|
+
try {
|
|
66
|
+
const cardFile = path.join(dir, 'scorecard.json');
|
|
67
|
+
if (fs.existsSync(cardFile)) {
|
|
68
|
+
appendScorecardLedger(dir, JSON.parse(fs.readFileSync(cardFile, 'utf8')), session);
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
/* ledger is advisory — never block cleanup */
|
|
72
|
+
}
|
|
73
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
74
|
+
if (isActive) clearActive();
|
|
75
|
+
unregisterSession(process.cwd(), sessionId);
|
|
76
|
+
}
|
|
77
|
+
removed.push({ sessionId, reason: tooOld ? 'retention' : 'finished' });
|
|
78
|
+
} else {
|
|
79
|
+
kept.push({ sessionId, phase: session.phase, ageDays: sessionAgeDays(session).toFixed(1) });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
process.stdout.write(JSON.stringify({ removed, kept, dryRun, retentionDays: RETENTION_DAYS }, null, 2));
|
|
84
|
+
process.stdout.write('\n');
|
package/src/config.mjs
CHANGED
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Shared user (~/.forgekit/config.json) and project (.forge/config.json) config IO.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import fs from 'node:fs';
|
|
7
|
-
import os from 'node:os';
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {string} [home]
|
|
12
|
-
* @returns {string}
|
|
13
|
-
*/
|
|
14
|
-
export function userConfigPath(home = os.homedir()) {
|
|
15
|
-
return path.join(home, '.forgekit', 'config.json');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @param {string} [home]
|
|
20
|
-
* @returns {Record<string, unknown>}
|
|
21
|
-
*/
|
|
22
|
-
export function loadUserConfig(home = os.homedir()) {
|
|
23
|
-
const p = userConfigPath(home);
|
|
24
|
-
if (!fs.existsSync(p)) return {};
|
|
25
|
-
try {
|
|
26
|
-
return JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
27
|
-
} catch {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Deep-merge top-level keys; nested objects under named keys are shallow-merged.
|
|
34
|
-
* @param {Record<string, unknown>} patch
|
|
35
|
-
* @param {string} [home]
|
|
36
|
-
* @param {string[]} [mergeKeys] keys to shallow-merge instead of replace
|
|
37
|
-
*/
|
|
38
|
-
export function saveUserConfig(patch, home = os.homedir(), mergeKeys = ['adr', 'plan']) {
|
|
39
|
-
const dir = path.dirname(userConfigPath(home));
|
|
40
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
41
|
-
const current = loadUserConfig(home);
|
|
42
|
-
/** @type {Record<string, unknown>} */
|
|
43
|
-
const next = { ...current, ...patch };
|
|
44
|
-
for (const key of mergeKeys) {
|
|
45
|
-
if (patch[key] && typeof patch[key] === 'object') {
|
|
46
|
-
next[key] = {
|
|
47
|
-
...((current[key] && typeof current[key] === 'object' ? current[key] : {})),
|
|
48
|
-
.../** @type {Record<string, unknown>} */ (patch[key]),
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
fs.writeFileSync(userConfigPath(home), `${JSON.stringify(next, null, 2)}\n`, 'utf8');
|
|
53
|
-
return next;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @param {string} cwd
|
|
58
|
-
* @returns {string}
|
|
59
|
-
*/
|
|
60
|
-
export function projectConfigPath(cwd) {
|
|
61
|
-
return path.join(cwd, '.forge', 'config.json');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @param {string} cwd
|
|
66
|
-
* @returns {Record<string, unknown>}
|
|
67
|
-
*/
|
|
68
|
-
export function loadProjectConfig(cwd) {
|
|
69
|
-
const p = projectConfigPath(cwd);
|
|
70
|
-
if (!fs.existsSync(p)) return {};
|
|
71
|
-
try {
|
|
72
|
-
return JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
73
|
-
} catch {
|
|
74
|
-
return {};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Merge-write project config. Nested mergeKeys are shallow-merged unless listed in replaceKeys.
|
|
80
|
-
* @param {string} cwd
|
|
81
|
-
* @param {Record<string, unknown>} patch
|
|
82
|
-
* @param {{ mergeKeys?: string[], replaceKeys?: string[] }} [opts]
|
|
83
|
-
*/
|
|
84
|
-
export function saveProjectConfig(cwd, patch, opts = {}) {
|
|
85
|
-
const mergeKeys = opts.mergeKeys ?? ['adr', 'plan'];
|
|
86
|
-
const replaceKeys = new Set(opts.replaceKeys ?? []);
|
|
87
|
-
const p = projectConfigPath(cwd);
|
|
88
|
-
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
89
|
-
const current = loadProjectConfig(cwd);
|
|
90
|
-
/** @type {Record<string, unknown>} */
|
|
91
|
-
const next = { ...current, ...patch };
|
|
92
|
-
for (const key of mergeKeys) {
|
|
93
|
-
if (replaceKeys.has(key)) continue;
|
|
94
|
-
if (patch[key] && typeof patch[key] === 'object') {
|
|
95
|
-
next[key] = {
|
|
96
|
-
...((current[key] && typeof current[key] === 'object' ? current[key] : {})),
|
|
97
|
-
.../** @type {Record<string, unknown>} */ (patch[key]),
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
fs.writeFileSync(p, `${JSON.stringify(next, null, 2)}\n`, 'utf8');
|
|
102
|
-
return next;
|
|
103
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Shared user (~/.forgekit/config.json) and project (.forge/config.json) config IO.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} [home]
|
|
12
|
+
* @returns {string}
|
|
13
|
+
*/
|
|
14
|
+
export function userConfigPath(home = os.homedir()) {
|
|
15
|
+
return path.join(home, '.forgekit', 'config.json');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} [home]
|
|
20
|
+
* @returns {Record<string, unknown>}
|
|
21
|
+
*/
|
|
22
|
+
export function loadUserConfig(home = os.homedir()) {
|
|
23
|
+
const p = userConfigPath(home);
|
|
24
|
+
if (!fs.existsSync(p)) return {};
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
27
|
+
} catch {
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Deep-merge top-level keys; nested objects under named keys are shallow-merged.
|
|
34
|
+
* @param {Record<string, unknown>} patch
|
|
35
|
+
* @param {string} [home]
|
|
36
|
+
* @param {string[]} [mergeKeys] keys to shallow-merge instead of replace
|
|
37
|
+
*/
|
|
38
|
+
export function saveUserConfig(patch, home = os.homedir(), mergeKeys = ['adr', 'plan']) {
|
|
39
|
+
const dir = path.dirname(userConfigPath(home));
|
|
40
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
41
|
+
const current = loadUserConfig(home);
|
|
42
|
+
/** @type {Record<string, unknown>} */
|
|
43
|
+
const next = { ...current, ...patch };
|
|
44
|
+
for (const key of mergeKeys) {
|
|
45
|
+
if (patch[key] && typeof patch[key] === 'object') {
|
|
46
|
+
next[key] = {
|
|
47
|
+
...((current[key] && typeof current[key] === 'object' ? current[key] : {})),
|
|
48
|
+
.../** @type {Record<string, unknown>} */ (patch[key]),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
fs.writeFileSync(userConfigPath(home), `${JSON.stringify(next, null, 2)}\n`, 'utf8');
|
|
53
|
+
return next;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {string} cwd
|
|
58
|
+
* @returns {string}
|
|
59
|
+
*/
|
|
60
|
+
export function projectConfigPath(cwd) {
|
|
61
|
+
return path.join(cwd, '.forge', 'config.json');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @param {string} cwd
|
|
66
|
+
* @returns {Record<string, unknown>}
|
|
67
|
+
*/
|
|
68
|
+
export function loadProjectConfig(cwd) {
|
|
69
|
+
const p = projectConfigPath(cwd);
|
|
70
|
+
if (!fs.existsSync(p)) return {};
|
|
71
|
+
try {
|
|
72
|
+
return JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
73
|
+
} catch {
|
|
74
|
+
return {};
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Merge-write project config. Nested mergeKeys are shallow-merged unless listed in replaceKeys.
|
|
80
|
+
* @param {string} cwd
|
|
81
|
+
* @param {Record<string, unknown>} patch
|
|
82
|
+
* @param {{ mergeKeys?: string[], replaceKeys?: string[] }} [opts]
|
|
83
|
+
*/
|
|
84
|
+
export function saveProjectConfig(cwd, patch, opts = {}) {
|
|
85
|
+
const mergeKeys = opts.mergeKeys ?? ['adr', 'plan'];
|
|
86
|
+
const replaceKeys = new Set(opts.replaceKeys ?? []);
|
|
87
|
+
const p = projectConfigPath(cwd);
|
|
88
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
89
|
+
const current = loadProjectConfig(cwd);
|
|
90
|
+
/** @type {Record<string, unknown>} */
|
|
91
|
+
const next = { ...current, ...patch };
|
|
92
|
+
for (const key of mergeKeys) {
|
|
93
|
+
if (replaceKeys.has(key)) continue;
|
|
94
|
+
if (patch[key] && typeof patch[key] === 'object') {
|
|
95
|
+
next[key] = {
|
|
96
|
+
...((current[key] && typeof current[key] === 'object' ? current[key] : {})),
|
|
97
|
+
.../** @type {Record<string, unknown>} */ (patch[key]),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
fs.writeFileSync(p, `${JSON.stringify(next, null, 2)}\n`, 'utf8');
|
|
102
|
+
return next;
|
|
103
|
+
}
|