@agentic-sdlc-kit/cli 0.0.0-stage → 0.8.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/LICENSE +21 -0
- package/README.md +32 -2
- package/dist/application/agent/execution-store.d.ts +55 -0
- package/dist/application/agent/execution-store.d.ts.map +1 -0
- package/dist/application/agent/execution-store.js +90 -0
- package/dist/application/agent/execution-store.js.map +1 -0
- package/dist/application/agent/gateway.d.ts +74 -0
- package/dist/application/agent/gateway.d.ts.map +1 -0
- package/dist/application/agent/gateway.js +580 -0
- package/dist/application/agent/gateway.js.map +1 -0
- package/dist/application/agent/index.d.ts +6 -0
- package/dist/application/agent/index.d.ts.map +1 -0
- package/dist/application/agent/index.js +18 -0
- package/dist/application/agent/index.js.map +1 -0
- package/dist/application/agent/orchestrator.d.ts +76 -0
- package/dist/application/agent/orchestrator.d.ts.map +1 -0
- package/dist/application/agent/orchestrator.js +422 -0
- package/dist/application/agent/orchestrator.js.map +1 -0
- package/dist/application/agent/providers/claude-code/claude-argv.d.ts +15 -0
- package/dist/application/agent/providers/claude-code/claude-argv.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/claude-argv.js +98 -0
- package/dist/application/agent/providers/claude-code/claude-argv.js.map +1 -0
- package/dist/application/agent/providers/claude-code/index.d.ts +7 -0
- package/dist/application/agent/providers/claude-code/index.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/index.js +13 -0
- package/dist/application/agent/providers/claude-code/index.js.map +1 -0
- package/dist/application/agent/providers/claude-code/mod-parity.d.ts +15 -0
- package/dist/application/agent/providers/claude-code/mod-parity.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/mod-parity.js +41 -0
- package/dist/application/agent/providers/claude-code/mod-parity.js.map +1 -0
- package/dist/application/agent/providers/claude-code/permission-config.d.ts +59 -0
- package/dist/application/agent/providers/claude-code/permission-config.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/permission-config.js +189 -0
- package/dist/application/agent/providers/claude-code/permission-config.js.map +1 -0
- package/dist/application/agent/providers/claude-code/provider.d.ts +38 -0
- package/dist/application/agent/providers/claude-code/provider.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/provider.js +577 -0
- package/dist/application/agent/providers/claude-code/provider.js.map +1 -0
- package/dist/application/agent/providers/claude-code/resume-store.d.ts +25 -0
- package/dist/application/agent/providers/claude-code/resume-store.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/resume-store.js +120 -0
- package/dist/application/agent/providers/claude-code/resume-store.js.map +1 -0
- package/dist/application/agent/providers/claude-code/stream-parser.d.ts +50 -0
- package/dist/application/agent/providers/claude-code/stream-parser.d.ts.map +1 -0
- package/dist/application/agent/providers/claude-code/stream-parser.js +129 -0
- package/dist/application/agent/providers/claude-code/stream-parser.js.map +1 -0
- package/dist/application/agent/test-fixture.d.ts +15 -0
- package/dist/application/agent/test-fixture.d.ts.map +1 -0
- package/dist/application/agent/test-fixture.js +93 -0
- package/dist/application/agent/test-fixture.js.map +1 -0
- package/dist/application/agent/workspace.d.ts +24 -0
- package/dist/application/agent/workspace.d.ts.map +1 -0
- package/dist/application/agent/workspace.js +139 -0
- package/dist/application/agent/workspace.js.map +1 -0
- package/dist/application/dispatcher.d.ts +13 -0
- package/dist/application/dispatcher.d.ts.map +1 -0
- package/dist/application/dispatcher.js +104 -0
- package/dist/application/dispatcher.js.map +1 -0
- package/dist/application/index.d.ts +5 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +6 -0
- package/dist/application/index.js.map +1 -0
- package/dist/application/registry.d.ts +8 -0
- package/dist/application/registry.d.ts.map +1 -0
- package/dist/application/registry.js +17 -0
- package/dist/application/registry.js.map +1 -0
- package/dist/application/version.d.ts +2 -0
- package/dist/application/version.d.ts.map +1 -0
- package/dist/application/version.js +7 -0
- package/dist/application/version.js.map +1 -0
- package/dist/commands/doctor.d.ts +3 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +68 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/elicit.d.ts +3 -0
- package/dist/commands/elicit.d.ts.map +1 -0
- package/dist/commands/elicit.js +163 -0
- package/dist/commands/elicit.js.map +1 -0
- package/dist/commands/evolve.d.ts +3 -0
- package/dist/commands/evolve.d.ts.map +1 -0
- package/dist/commands/evolve.js +165 -0
- package/dist/commands/evolve.js.map +1 -0
- package/dist/commands/feature.d.ts +13 -0
- package/dist/commands/feature.d.ts.map +1 -0
- package/dist/commands/feature.js +326 -0
- package/dist/commands/feature.js.map +1 -0
- package/dist/commands/fix.d.ts +3 -0
- package/dist/commands/fix.d.ts.map +1 -0
- package/dist/commands/fix.js +61 -0
- package/dist/commands/fix.js.map +1 -0
- package/dist/commands/help.d.ts +4 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +32 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/index.d.ts +21 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +22 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +90 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/inspect.d.ts +3 -0
- package/dist/commands/inspect.d.ts.map +1 -0
- package/dist/commands/inspect.js +64 -0
- package/dist/commands/inspect.js.map +1 -0
- package/dist/commands/install.d.ts +3 -0
- package/dist/commands/install.d.ts.map +1 -0
- package/dist/commands/install.js +329 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/journal.d.ts +3 -0
- package/dist/commands/journal.d.ts.map +1 -0
- package/dist/commands/journal.js +107 -0
- package/dist/commands/journal.js.map +1 -0
- package/dist/commands/memory.d.ts +3 -0
- package/dist/commands/memory.d.ts.map +1 -0
- package/dist/commands/memory.js +85 -0
- package/dist/commands/memory.js.map +1 -0
- package/dist/commands/new.d.ts +3 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +68 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/next.d.ts +3 -0
- package/dist/commands/next.d.ts.map +1 -0
- package/dist/commands/next.js +107 -0
- package/dist/commands/next.js.map +1 -0
- package/dist/commands/optimize.d.ts +3 -0
- package/dist/commands/optimize.d.ts.map +1 -0
- package/dist/commands/optimize.js +28 -0
- package/dist/commands/optimize.js.map +1 -0
- package/dist/commands/plugin-linker.d.ts +34 -0
- package/dist/commands/plugin-linker.d.ts.map +1 -0
- package/dist/commands/plugin-linker.js +177 -0
- package/dist/commands/plugin-linker.js.map +1 -0
- package/dist/commands/refactor.d.ts +3 -0
- package/dist/commands/refactor.d.ts.map +1 -0
- package/dist/commands/refactor.js +32 -0
- package/dist/commands/refactor.js.map +1 -0
- package/dist/commands/types.d.ts +19 -0
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/types.js +7 -0
- package/dist/commands/types.js.map +1 -0
- package/dist/commands/validate-plan.d.ts +3 -0
- package/dist/commands/validate-plan.d.ts.map +1 -0
- package/dist/commands/validate-plan.js +62 -0
- package/dist/commands/validate-plan.js.map +1 -0
- package/dist/commands/validate-spec.d.ts +3 -0
- package/dist/commands/validate-spec.d.ts.map +1 -0
- package/dist/commands/validate-spec.js +62 -0
- package/dist/commands/validate-spec.js.map +1 -0
- package/dist/commands/verify.d.ts +3 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +103 -0
- package/dist/commands/verify.js.map +1 -0
- package/dist/commands/version.d.ts +3 -0
- package/dist/commands/version.d.ts.map +1 -0
- package/dist/commands/version.js +12 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/output/formatter.d.ts +2 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +10 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/index.d.ts +2 -0
- package/dist/output/index.d.ts.map +1 -0
- package/dist/output/index.js +3 -0
- package/dist/output/index.js.map +1 -0
- package/package.json +37 -3
- package/src/application/agent/execution-store.ts +162 -0
- package/src/application/agent/gateway.test.ts +529 -0
- package/src/application/agent/gateway.ts +744 -0
- package/src/application/agent/index.ts +18 -0
- package/src/application/agent/orchestrator.test.ts +341 -0
- package/src/application/agent/orchestrator.ts +628 -0
- package/src/application/agent/providers/claude-code/claude-argv.ts +119 -0
- package/src/application/agent/providers/claude-code/claude-code-smoke.test.ts +139 -0
- package/src/application/agent/providers/claude-code/fixtures/fake-claude.mjs +125 -0
- package/src/application/agent/providers/claude-code/index.ts +28 -0
- package/src/application/agent/providers/claude-code/mod-parity.ts +50 -0
- package/src/application/agent/providers/claude-code/permission-config.test.ts +221 -0
- package/src/application/agent/providers/claude-code/permission-config.ts +242 -0
- package/src/application/agent/providers/claude-code/provider.test.ts +378 -0
- package/src/application/agent/providers/claude-code/provider.ts +717 -0
- package/src/application/agent/providers/claude-code/resume-store.test.ts +161 -0
- package/src/application/agent/providers/claude-code/resume-store.ts +157 -0
- package/src/application/agent/providers/claude-code/stream-parser.ts +166 -0
- package/src/application/agent/test-fixture.ts +131 -0
- package/src/application/agent/workspace.test.ts +104 -0
- package/src/application/agent/workspace.ts +156 -0
- package/src/application/dispatcher.test.ts +89 -0
- package/src/application/dispatcher.ts +98 -0
- package/src/application/index.ts +5 -0
- package/src/application/registry.ts +24 -0
- package/src/application/version.ts +7 -0
- package/src/commands/clse.test.ts +181 -0
- package/src/commands/doctor.test.ts +29 -0
- package/src/commands/doctor.ts +78 -0
- package/src/commands/elicit.test.ts +111 -0
- package/src/commands/elicit.ts +188 -0
- package/src/commands/evolve.ts +209 -0
- package/src/commands/feature.test.ts +323 -0
- package/src/commands/feature.ts +405 -0
- package/src/commands/fix.test.ts +36 -0
- package/src/commands/fix.ts +69 -0
- package/src/commands/help.test.ts +33 -0
- package/src/commands/help.ts +35 -0
- package/src/commands/index.ts +21 -0
- package/src/commands/init.test.ts +65 -0
- package/src/commands/init.ts +103 -0
- package/src/commands/inspect.test.ts +57 -0
- package/src/commands/inspect.ts +73 -0
- package/src/commands/install.test.ts +61 -0
- package/src/commands/install.ts +375 -0
- package/src/commands/journal.ts +118 -0
- package/src/commands/memory.ts +96 -0
- package/src/commands/new.test.ts +44 -0
- package/src/commands/new.ts +77 -0
- package/src/commands/next.test.ts +241 -0
- package/src/commands/next.ts +124 -0
- package/src/commands/optimize.ts +30 -0
- package/src/commands/plugin-linker.test.ts +139 -0
- package/src/commands/plugin-linker.ts +196 -0
- package/src/commands/refactor.ts +34 -0
- package/src/commands/stack-commands.test.ts +67 -0
- package/src/commands/tier-c-conformance.test.ts +194 -0
- package/src/commands/types.ts +26 -0
- package/src/commands/validate-plan.test.ts +107 -0
- package/src/commands/validate-plan.ts +67 -0
- package/src/commands/validate-spec.test.ts +59 -0
- package/src/commands/validate-spec.ts +68 -0
- package/src/commands/verify.test.ts +117 -0
- package/src/commands/verify.ts +112 -0
- package/src/commands/version.test.ts +11 -0
- package/src/commands/version.ts +14 -0
- package/src/index.ts +30 -0
- package/src/output/formatter.ts +10 -0
- package/src/output/index.ts +2 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/workspace.test.ts
|
|
2
|
+
//
|
|
3
|
+
// Worktree workspace manager tests (ADR-0019 v2 revision B, ADR-0020 §7):
|
|
4
|
+
// a dedicated git worktree per run, with the branch + baseCommitSha
|
|
5
|
+
// identity the contract requires, and honest failure modes.
|
|
6
|
+
|
|
7
|
+
import { execFile } from 'node:child_process';
|
|
8
|
+
import { promises as fs } from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { promisify } from 'node:util';
|
|
12
|
+
import { describe, expect, it } from 'vitest';
|
|
13
|
+
import {
|
|
14
|
+
createWorktreeWorkspace,
|
|
15
|
+
removeWorktreeWorkspace,
|
|
16
|
+
worktreeBranch,
|
|
17
|
+
worktreeDir,
|
|
18
|
+
workspaceExists,
|
|
19
|
+
} from './workspace.js';
|
|
20
|
+
|
|
21
|
+
const exec = promisify(execFile);
|
|
22
|
+
|
|
23
|
+
async function gitRepo(): Promise<string> {
|
|
24
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-workspace-'));
|
|
25
|
+
await exec('git', ['init', '-b', 'main'], { cwd: root });
|
|
26
|
+
await fs.writeFile(path.join(root, 'file.txt'), 'baseline\n');
|
|
27
|
+
await exec(
|
|
28
|
+
'git',
|
|
29
|
+
['-c', 'user.email=k@e.com', '-c', 'user.name=k', 'add', '.'],
|
|
30
|
+
{ cwd: root },
|
|
31
|
+
);
|
|
32
|
+
await exec(
|
|
33
|
+
'git',
|
|
34
|
+
['-c', 'user.email=k@e.com', '-c', 'user.name=k', 'commit', '-m', 'init'],
|
|
35
|
+
{ cwd: root },
|
|
36
|
+
);
|
|
37
|
+
return root;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe('createWorktreeWorkspace', () => {
|
|
41
|
+
it('creates an isolated git worktree with full identity (kind/branch/baseCommitSha)', async () => {
|
|
42
|
+
const root = await gitRepo();
|
|
43
|
+
const res = await createWorktreeWorkspace(root, 'RUN-001');
|
|
44
|
+
expect(res.ok).toBe(true);
|
|
45
|
+
if (!res.ok) return;
|
|
46
|
+
expect(res.value.kind).toBe('git-worktree');
|
|
47
|
+
expect(res.value.branch).toBe('kit/RUN-001');
|
|
48
|
+
expect(res.value.rootPath).toBe(worktreeDir(root, 'RUN-001'));
|
|
49
|
+
expect(res.value.baseCommitSha).toMatch(/^[0-9a-f]{7,40}$/);
|
|
50
|
+
// A real worktree: .git is a FILE pointing at the main repo metadata.
|
|
51
|
+
const stat = await fs.stat(path.join(res.value.rootPath, '.git'));
|
|
52
|
+
expect(stat.isFile()).toBe(true);
|
|
53
|
+
// The committed baseline is present in the worktree.
|
|
54
|
+
expect(await fs.readFile(path.join(res.value.rootPath, 'file.txt'), 'utf8')).toBe('baseline\n');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('refuses to overwrite an existing workspace directory', async () => {
|
|
58
|
+
const root = await gitRepo();
|
|
59
|
+
const first = await createWorktreeWorkspace(root, 'RUN-001');
|
|
60
|
+
expect(first.ok).toBe(true);
|
|
61
|
+
const second = await createWorktreeWorkspace(root, 'RUN-001');
|
|
62
|
+
expect(second.ok).toBe(false);
|
|
63
|
+
if (!second.ok) expect(second.error.message).toContain('already exists');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('fails honestly in a directory that is not a git repository', async () => {
|
|
67
|
+
const notGit = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-notgit-'));
|
|
68
|
+
const res = await createWorktreeWorkspace(notGit, 'RUN-001');
|
|
69
|
+
expect(res.ok).toBe(false);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe('workspaceExists / removeWorktreeWorkspace', () => {
|
|
74
|
+
it('probes existence and removes worktree plus branch', async () => {
|
|
75
|
+
const root = await gitRepo();
|
|
76
|
+
const res = await createWorktreeWorkspace(root, 'RUN-001');
|
|
77
|
+
expect(res.ok).toBe(true);
|
|
78
|
+
if (!res.ok) return;
|
|
79
|
+
expect(await workspaceExists(res.value)).toBe(true);
|
|
80
|
+
|
|
81
|
+
const rm = await removeWorktreeWorkspace(root, res.value);
|
|
82
|
+
expect(rm.ok).toBe(true);
|
|
83
|
+
expect(await workspaceExists(res.value)).toBe(false);
|
|
84
|
+
// The branch is gone too.
|
|
85
|
+
const branches = await exec('git', ['branch', '--list', worktreeBranch('RUN-001')], {
|
|
86
|
+
cwd: root,
|
|
87
|
+
});
|
|
88
|
+
expect(branches.stdout.trim()).toBe('');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('treats a missing workspace as absent (not an error)', async () => {
|
|
92
|
+
const root = await gitRepo();
|
|
93
|
+
expect(
|
|
94
|
+
await workspaceExists({
|
|
95
|
+
id: 'ws-gone',
|
|
96
|
+
kind: 'git-worktree',
|
|
97
|
+
rootPath: path.join(root, '.ai-kit', 'worktrees', 'RUN-404'),
|
|
98
|
+
branch: 'kit/RUN-404',
|
|
99
|
+
baseCommitSha: '0000000',
|
|
100
|
+
createdAt: new Date().toISOString(),
|
|
101
|
+
}),
|
|
102
|
+
).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// packages/cli/src/application/agent/workspace.ts
|
|
2
|
+
//
|
|
3
|
+
// Execution workspace manager (ADR-0019 v2 revision B, ADR-0020 §7).
|
|
4
|
+
//
|
|
5
|
+
// Every Mode 1 run executes in a DEDICATED GIT WORKTREE per workflow run,
|
|
6
|
+
// never in the developer's active working tree. This isolates repository
|
|
7
|
+
// changes and gives the orchestrator a clean diff for evidence (branch +
|
|
8
|
+
// baseCommitSha are recorded in the ExecutionWorkspace, which is exactly
|
|
9
|
+
// what the git-worktree schema variant requires).
|
|
10
|
+
//
|
|
11
|
+
// SECURITY QUALIFICATION (ADR-0020 §7, honest scope): a git worktree
|
|
12
|
+
// isolates REPOSITORY changes; it is NOT an OS sandbox. Provider
|
|
13
|
+
// processes must additionally run with restricted host permissions or in
|
|
14
|
+
// a container (PR4's concern). Nothing here claims otherwise.
|
|
15
|
+
//
|
|
16
|
+
// All git invocations are argument arrays via execFile — never a shell
|
|
17
|
+
// string, never shell:true (the kit's non-negotiable process rule).
|
|
18
|
+
|
|
19
|
+
import { execFile } from 'node:child_process';
|
|
20
|
+
import { promises as fs } from 'node:fs';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import { Errors, type ExecutionWorkspace, type Result } from '@agentic-sdlc-kit/contracts';
|
|
23
|
+
|
|
24
|
+
const GIT_TIMEOUT_MS = 30_000;
|
|
25
|
+
|
|
26
|
+
function execGit(args: readonly string[], cwd: string): Promise<{ stdout: string; stderr: string }> {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
execFile(
|
|
29
|
+
'git',
|
|
30
|
+
[...args],
|
|
31
|
+
{ cwd, timeout: GIT_TIMEOUT_MS, windowsHide: true },
|
|
32
|
+
(err, stdout, stderr) => {
|
|
33
|
+
if (err) {
|
|
34
|
+
reject(new Error(`git ${args.join(' ')} failed: ${String(stderr || err.message)}`));
|
|
35
|
+
} else {
|
|
36
|
+
resolve({ stdout: String(stdout), stderr: String(stderr) });
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function worktreeDir(projectRoot: string, runId: string): string {
|
|
44
|
+
return path.resolve(projectRoot, '.ai-kit', 'worktrees', runId);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function worktreeBranch(runId: string): string {
|
|
48
|
+
return `kit/${runId}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function pathExists(p: string): Promise<boolean> {
|
|
52
|
+
try {
|
|
53
|
+
await fs.stat(p);
|
|
54
|
+
return true;
|
|
55
|
+
} catch {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Create the isolated execution workspace for a run: a git worktree at
|
|
62
|
+
* .ai-kit/worktrees/<runId> on branch kit/<runId>, based at the current
|
|
63
|
+
* HEAD of the project. The workspace identity (branch + baseCommitSha) is
|
|
64
|
+
* frozen in the returned ExecutionWorkspace and persisted by the
|
|
65
|
+
* orchestrator, so later phases and audits can derive clean diffs.
|
|
66
|
+
*/
|
|
67
|
+
export async function createWorktreeWorkspace(
|
|
68
|
+
projectRoot: string,
|
|
69
|
+
runId: string,
|
|
70
|
+
now: () => Date = () => new Date(),
|
|
71
|
+
): Promise<Result<ExecutionWorkspace>> {
|
|
72
|
+
const dir = worktreeDir(projectRoot, runId);
|
|
73
|
+
try {
|
|
74
|
+
if (await pathExists(dir)) {
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
error: Errors.contractInvalid(
|
|
78
|
+
`Workspace directory ${dir} already exists — the orchestration state and the ` +
|
|
79
|
+
`filesystem have diverged; refusing to overwrite`,
|
|
80
|
+
),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const shaRes = await execGit(['rev-parse', 'HEAD'], projectRoot);
|
|
84
|
+
const baseCommitSha = shaRes.stdout.trim();
|
|
85
|
+
if (!/^[0-9a-f]{7,40}$/.test(baseCommitSha)) {
|
|
86
|
+
return {
|
|
87
|
+
ok: false,
|
|
88
|
+
error: Errors.contractInvalid(
|
|
89
|
+
`Could not resolve a commit HEAD for ${projectRoot} — the project must have ` +
|
|
90
|
+
`at least one commit before Mode 1 execution (spec, plan, and profile must be committed)`,
|
|
91
|
+
),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
await execGit(['worktree', 'add', '-b', worktreeBranch(runId), dir, baseCommitSha], projectRoot);
|
|
95
|
+
return {
|
|
96
|
+
ok: true,
|
|
97
|
+
value: {
|
|
98
|
+
id: `ws-${runId}`,
|
|
99
|
+
kind: 'git-worktree',
|
|
100
|
+
rootPath: dir,
|
|
101
|
+
branch: worktreeBranch(runId),
|
|
102
|
+
baseCommitSha,
|
|
103
|
+
createdAt: now().toISOString(),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
} catch (e) {
|
|
107
|
+
return {
|
|
108
|
+
ok: false,
|
|
109
|
+
error: Errors.internal(`Failed to create execution workspace: ${String(e)}`),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Probe that a persisted workspace still exists on disk. A git worktree
|
|
116
|
+
* is marked by a `.git` FILE (not a directory) pointing at the main
|
|
117
|
+
* repo's worktree metadata — that is the check.
|
|
118
|
+
*/
|
|
119
|
+
export async function workspaceExists(workspace: ExecutionWorkspace): Promise<boolean> {
|
|
120
|
+
try {
|
|
121
|
+
const gitLink = path.join(workspace.rootPath, '.git');
|
|
122
|
+
const stat = await fs.stat(gitLink);
|
|
123
|
+
return stat.isFile();
|
|
124
|
+
} catch {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Remove a worktree and its branch. Used by tests and by explicit
|
|
131
|
+
* cleanup; the orchestrator does NOT auto-remove on completion — the
|
|
132
|
+
* worktree is the evidence (the diff) and stays for review/merge.
|
|
133
|
+
*/
|
|
134
|
+
export async function removeWorktreeWorkspace(
|
|
135
|
+
projectRoot: string,
|
|
136
|
+
workspace: ExecutionWorkspace,
|
|
137
|
+
): Promise<Result<true>> {
|
|
138
|
+
try {
|
|
139
|
+
await execGit(['worktree', 'remove', '--force', workspace.rootPath], projectRoot);
|
|
140
|
+
} catch {
|
|
141
|
+
// The worktree may already be gone; prune and continue.
|
|
142
|
+
try {
|
|
143
|
+
await execGit(['worktree', 'prune'], projectRoot);
|
|
144
|
+
} catch {
|
|
145
|
+
// fall through: branch cleanup below is best-effort too
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
if (workspace.branch) {
|
|
150
|
+
await execGit(['branch', '-D', workspace.branch], projectRoot);
|
|
151
|
+
}
|
|
152
|
+
} catch {
|
|
153
|
+
// Branch may not exist (already merged/deleted) — not an error.
|
|
154
|
+
}
|
|
155
|
+
return { ok: true, value: true };
|
|
156
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// packages/cli/src/application/dispatcher.test.ts
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import { createDispatcher } from './dispatcher.js';
|
|
4
|
+
import type { CommandContext } from '../commands/types.js';
|
|
5
|
+
|
|
6
|
+
const makeCtx = (
|
|
7
|
+
argv: ReadonlyArray<string>,
|
|
8
|
+
): CommandContext & { out: string[]; err: string[] } => {
|
|
9
|
+
const out: string[] = [];
|
|
10
|
+
const err: string[] = [];
|
|
11
|
+
return {
|
|
12
|
+
argv,
|
|
13
|
+
cwd: '/tmp',
|
|
14
|
+
stdout: (s) => void out.push(s),
|
|
15
|
+
stderr: (s) => void err.push(s),
|
|
16
|
+
out,
|
|
17
|
+
err,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe('dispatcher', () => {
|
|
22
|
+
it('handles --version', async () => {
|
|
23
|
+
const { dispatch } = createDispatcher();
|
|
24
|
+
const ctx = makeCtx(['--version']);
|
|
25
|
+
const r = await dispatch(ctx);
|
|
26
|
+
expect(r.exitCode).toBe(0);
|
|
27
|
+
expect(r.message).toBe('0.8.0');
|
|
28
|
+
expect(r.command).toBe('version');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('handles -v', async () => {
|
|
32
|
+
const { dispatch } = createDispatcher();
|
|
33
|
+
const ctx = makeCtx(['-v']);
|
|
34
|
+
const r = await dispatch(ctx);
|
|
35
|
+
expect(r.exitCode).toBe(0);
|
|
36
|
+
expect(r.message).toBe('0.8.0');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('handles --help', async () => {
|
|
40
|
+
const { dispatch } = createDispatcher();
|
|
41
|
+
const ctx = makeCtx(['--help']);
|
|
42
|
+
const r = await dispatch(ctx);
|
|
43
|
+
expect(r.exitCode).toBe(0);
|
|
44
|
+
expect(r.command).toBe('help');
|
|
45
|
+
// help text mentions the registered commands
|
|
46
|
+
expect(ctx.out[0]).toContain('kit — Agentic SDLC Kit');
|
|
47
|
+
expect(ctx.out[0]).toContain('version');
|
|
48
|
+
expect(ctx.out[0]).toContain('doctor');
|
|
49
|
+
expect(ctx.out[0]).toContain('inspect');
|
|
50
|
+
expect(ctx.out[0]).toContain('init');
|
|
51
|
+
expect(ctx.out[0]).toContain('validate-spec');
|
|
52
|
+
expect(ctx.out[0]).toContain('validate-plan');
|
|
53
|
+
expect(ctx.out[0]).toContain('verify');
|
|
54
|
+
expect(ctx.out[0]).toContain('feature');
|
|
55
|
+
expect(ctx.out[0]).toContain('new');
|
|
56
|
+
expect(ctx.out[0]).toContain('fix');
|
|
57
|
+
expect(ctx.out[0]).toContain('install');
|
|
58
|
+
expect(ctx.out[0]).toContain('memory');
|
|
59
|
+
expect(ctx.out[0]).toContain('evolve');
|
|
60
|
+
expect(ctx.out[0]).toContain('help');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('handles no args as help', async () => {
|
|
64
|
+
const { dispatch } = createDispatcher();
|
|
65
|
+
const ctx = makeCtx([]);
|
|
66
|
+
const r = await dispatch(ctx);
|
|
67
|
+
expect(r.exitCode).toBe(0);
|
|
68
|
+
expect(r.command).toBe('help');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('dispatches the doctor command', async () => {
|
|
72
|
+
const { dispatch } = createDispatcher();
|
|
73
|
+
const ctx = makeCtx(['doctor']);
|
|
74
|
+
const r = await dispatch(ctx);
|
|
75
|
+
expect(r.exitCode).toBe(0);
|
|
76
|
+
expect(r.command).toBe('doctor');
|
|
77
|
+
expect(ctx.out[0]).toContain('kit 0.8.0');
|
|
78
|
+
expect(ctx.out[0]).toContain('node');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('rejects unknown commands with exit code 1', async () => {
|
|
82
|
+
const { dispatch } = createDispatcher();
|
|
83
|
+
const ctx = makeCtx(['bogus']);
|
|
84
|
+
const r = await dispatch(ctx);
|
|
85
|
+
expect(r.exitCode).toBe(1);
|
|
86
|
+
expect(r.command).toBe('bogus');
|
|
87
|
+
expect(ctx.err[0]).toContain("unknown command 'bogus'");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// packages/cli/src/application/dispatcher.ts
|
|
2
|
+
//
|
|
3
|
+
// Resolves the first non-flag argument to a registered command and runs it.
|
|
4
|
+
// Handles --help, --version, and unknown commands.
|
|
5
|
+
|
|
6
|
+
import { makeHelpCommand } from '../commands/help.js';
|
|
7
|
+
import { versionCommand } from '../commands/version.js';
|
|
8
|
+
import { doctorCommand } from '../commands/doctor.js';
|
|
9
|
+
import { inspectCommand } from '../commands/inspect.js';
|
|
10
|
+
import { initCommand } from '../commands/init.js';
|
|
11
|
+
import { validateSpecCommand } from '../commands/validate-spec.js';
|
|
12
|
+
import { elicitCommand } from '../commands/elicit.js';
|
|
13
|
+
import { validatePlanCommand } from '../commands/validate-plan.js';
|
|
14
|
+
import { verifyCommand } from '../commands/verify.js';
|
|
15
|
+
import { featureCommand } from '../commands/feature.js';
|
|
16
|
+
import { newCommand } from '../commands/new.js';
|
|
17
|
+
import { fixCommand } from '../commands/fix.js';
|
|
18
|
+
import { installCommand } from '../commands/install.js';
|
|
19
|
+
import { memoryCommand } from '../commands/memory.js';
|
|
20
|
+
import { evolveCommand } from '../commands/evolve.js';
|
|
21
|
+
import { refactorCommand } from '../commands/refactor.js';
|
|
22
|
+
import { optimizeCommand } from '../commands/optimize.js';
|
|
23
|
+
import { nextCommand } from '../commands/next.js';
|
|
24
|
+
import { journalCommand } from '../commands/journal.js';
|
|
25
|
+
import type { Command, CommandContext, CommandResult } from '../commands/types.js';
|
|
26
|
+
import { createCommandRegistry, type CommandRegistry } from './registry.js';
|
|
27
|
+
import { VERSION } from './version.js';
|
|
28
|
+
|
|
29
|
+
export interface DispatchResult extends CommandResult {
|
|
30
|
+
command?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface DispatcherOptions {
|
|
34
|
+
registry?: CommandRegistry;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createDispatcher(opts: DispatcherOptions = {}): {
|
|
38
|
+
dispatch: (ctx: CommandContext) => Promise<DispatchResult>;
|
|
39
|
+
registry: CommandRegistry;
|
|
40
|
+
} {
|
|
41
|
+
const registry = opts.registry ?? createCommandRegistry();
|
|
42
|
+
// Register default commands. Help needs the registry so it is built lazily.
|
|
43
|
+
if (!registry.get('version')) registry.register(versionCommand);
|
|
44
|
+
if (!registry.get('doctor')) registry.register(doctorCommand);
|
|
45
|
+
if (!registry.get('inspect')) registry.register(inspectCommand);
|
|
46
|
+
if (!registry.get('init')) registry.register(initCommand);
|
|
47
|
+
if (!registry.get('validate-spec')) registry.register(validateSpecCommand);
|
|
48
|
+
if (!registry.get('elicit')) registry.register(elicitCommand);
|
|
49
|
+
if (!registry.get('validate-plan')) registry.register(validatePlanCommand);
|
|
50
|
+
if (!registry.get('verify')) registry.register(verifyCommand);
|
|
51
|
+
if (!registry.get('feature')) registry.register(featureCommand);
|
|
52
|
+
if (!registry.get('new')) registry.register(newCommand);
|
|
53
|
+
if (!registry.get('fix')) registry.register(fixCommand);
|
|
54
|
+
if (!registry.get('install')) registry.register(installCommand);
|
|
55
|
+
if (!registry.get('memory')) registry.register(memoryCommand);
|
|
56
|
+
if (!registry.get('evolve')) registry.register(evolveCommand);
|
|
57
|
+
if (!registry.get('refactor')) registry.register(refactorCommand);
|
|
58
|
+
if (!registry.get('optimize')) registry.register(optimizeCommand);
|
|
59
|
+
if (!registry.get('next')) registry.register(nextCommand);
|
|
60
|
+
if (!registry.get('journal')) registry.register(journalCommand);
|
|
61
|
+
if (!registry.get('help')) registry.register(makeHelpCommand(registry));
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
registry,
|
|
65
|
+
async dispatch(ctx: CommandContext): Promise<DispatchResult> {
|
|
66
|
+
const argv = ctx.argv;
|
|
67
|
+
// --version / -v
|
|
68
|
+
if (argv.includes('--version') || argv.includes('-v')) {
|
|
69
|
+
return { exitCode: 0, message: VERSION, command: 'version' };
|
|
70
|
+
}
|
|
71
|
+
// --help / -h with no further command, OR no args at all
|
|
72
|
+
if (argv.length === 0 || argv.includes('--help') || argv.includes('-h')) {
|
|
73
|
+
const help = registry.get('help');
|
|
74
|
+
if (!help) return { exitCode: 1, command: 'help', message: 'help command missing' };
|
|
75
|
+
const r = await help.run(ctx);
|
|
76
|
+
return { ...r, command: 'help' };
|
|
77
|
+
}
|
|
78
|
+
// First non-flag argument is the command name.
|
|
79
|
+
const first = argv.find((a) => !a.startsWith('-'));
|
|
80
|
+
if (!first) {
|
|
81
|
+
const help = registry.get('help');
|
|
82
|
+
if (help) {
|
|
83
|
+
const r = await help.run(ctx);
|
|
84
|
+
return { ...r, command: 'help' };
|
|
85
|
+
}
|
|
86
|
+
return { exitCode: 1, message: 'no command' };
|
|
87
|
+
}
|
|
88
|
+
const cmd: Command | undefined = registry.get(first);
|
|
89
|
+
if (!cmd) {
|
|
90
|
+
ctx.stderr(`kit: unknown command '${first}'\nRun 'kit --help' for usage.\n`);
|
|
91
|
+
return { exitCode: 1, command: first, message: 'unknown command' };
|
|
92
|
+
}
|
|
93
|
+
const rest = argv.filter((a) => a !== first);
|
|
94
|
+
const r = await cmd.run({ ...ctx, argv: rest });
|
|
95
|
+
return { ...r, command: first };
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// packages/cli/src/application/registry.ts
|
|
2
|
+
//
|
|
3
|
+
// Command registry. The dispatcher uses this to find a command by name.
|
|
4
|
+
// Adding a command = adding one entry here.
|
|
5
|
+
|
|
6
|
+
import type { Command } from '../commands/types.js';
|
|
7
|
+
|
|
8
|
+
export interface CommandRegistry {
|
|
9
|
+
list(): ReadonlyArray<Command>;
|
|
10
|
+
get(name: string): Command | undefined;
|
|
11
|
+
register(command: Command): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createCommandRegistry(initial: ReadonlyArray<Command> = []): CommandRegistry {
|
|
15
|
+
const commands = new Map<string, Command>();
|
|
16
|
+
for (const c of initial) commands.set(c.name, c);
|
|
17
|
+
return {
|
|
18
|
+
list: () => Array.from(commands.values()),
|
|
19
|
+
get: (name: string) => commands.get(name),
|
|
20
|
+
register: (command: Command) => {
|
|
21
|
+
commands.set(command.name, command);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// packages/cli/src/application/version.ts
|
|
2
|
+
//
|
|
3
|
+
// Single source of truth for the kit version. Sourced from package.json at
|
|
4
|
+
// build time via a build-time constant. In M1 we hard-code to keep the
|
|
5
|
+
// build simple; M16 wires this to a generated file.
|
|
6
|
+
|
|
7
|
+
export const VERSION = '0.8.0';
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// packages/cli/src/commands/clse.test.ts
|
|
2
|
+
import { promises as fs } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
import { installCommand } from './install.js';
|
|
7
|
+
import { memoryCommand } from './memory.js';
|
|
8
|
+
import { evolveCommand } from './evolve.js';
|
|
9
|
+
import type { CommandContext } from './types.js';
|
|
10
|
+
|
|
11
|
+
const makeCtx = (
|
|
12
|
+
argv: string[],
|
|
13
|
+
cwd: string,
|
|
14
|
+
): CommandContext & { out: string[]; err: string[] } => {
|
|
15
|
+
const out: string[] = [];
|
|
16
|
+
const err: string[] = [];
|
|
17
|
+
return {
|
|
18
|
+
argv,
|
|
19
|
+
cwd,
|
|
20
|
+
stdout: (s) => void out.push(s),
|
|
21
|
+
stderr: (s) => void err.push(s),
|
|
22
|
+
out,
|
|
23
|
+
err,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
describe('installCommand (M15)', () => {
|
|
28
|
+
it('installs kit configuration files and writes ownership manifest', async () => {
|
|
29
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-install-'));
|
|
30
|
+
try {
|
|
31
|
+
const ctx = makeCtx(['--profile', 'full-sdlc', '--stack', 'node-typescript'], tmp);
|
|
32
|
+
const r = await installCommand.run(ctx);
|
|
33
|
+
expect(r.exitCode).toBe(0);
|
|
34
|
+
expect(ctx.out[0]).toContain('kit install: SUCCESS');
|
|
35
|
+
// Verify files were actually written.
|
|
36
|
+
const projectYml = path.join(tmp, '.ai-kit', 'project.yml');
|
|
37
|
+
const stat = await fs.stat(projectYml);
|
|
38
|
+
expect(stat.isFile()).toBe(true);
|
|
39
|
+
// Verify ownership manifest was written.
|
|
40
|
+
const manifest = path.join(tmp, '.ai-kit', 'ownership-manifest.json');
|
|
41
|
+
const manifestStat = await fs.stat(manifest);
|
|
42
|
+
expect(manifestStat.isFile()).toBe(true);
|
|
43
|
+
// Verify docs directories were created.
|
|
44
|
+
await fs.stat(path.join(tmp, 'docs', 'specifications', '.gitkeep'));
|
|
45
|
+
await fs.stat(path.join(tmp, 'docs', 'plans', '.gitkeep'));
|
|
46
|
+
} finally {
|
|
47
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('supports --dry-run without writing files', async () => {
|
|
52
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-dryrun-'));
|
|
53
|
+
try {
|
|
54
|
+
const ctx = makeCtx(['--profile', 'minimal', '--dry-run'], tmp);
|
|
55
|
+
const r = await installCommand.run(ctx);
|
|
56
|
+
expect(r.exitCode).toBe(0);
|
|
57
|
+
expect(ctx.out[0]).toContain('dry-run');
|
|
58
|
+
// Verify NO files were written.
|
|
59
|
+
await expect(fs.stat(path.join(tmp, '.ai-kit', 'project.yml'))).rejects.toThrow();
|
|
60
|
+
} finally {
|
|
61
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
describe('memoryCommand (M29)', () => {
|
|
67
|
+
it('reports honestly when no memory has been persisted', async () => {
|
|
68
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-memory-empty-'));
|
|
69
|
+
try {
|
|
70
|
+
const ctx = makeCtx(['architecture'], tmp);
|
|
71
|
+
const r = await memoryCommand.run(ctx);
|
|
72
|
+
expect(r.exitCode).toBe(0);
|
|
73
|
+
expect(ctx.out[0]).toContain('no memory entries found');
|
|
74
|
+
} finally {
|
|
75
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('reads and searches persisted memory entries', async () => {
|
|
80
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-memory-search-'));
|
|
81
|
+
try {
|
|
82
|
+
// Write a memory file.
|
|
83
|
+
await fs.mkdir(path.join(tmp, '.ai-kit', 'state'), { recursive: true });
|
|
84
|
+
const memory = {
|
|
85
|
+
schemaVersion: 1,
|
|
86
|
+
entries: [
|
|
87
|
+
{
|
|
88
|
+
id: 'MEM-TEST-001',
|
|
89
|
+
type: 'semantic',
|
|
90
|
+
domain: 'architecture',
|
|
91
|
+
summary: 'Modular Monorepo Invariant',
|
|
92
|
+
content: 'Contracts depends on nothing; Core depends only on Contracts.',
|
|
93
|
+
confidence: 1.0,
|
|
94
|
+
provenance: ['ARCHITECTURE.md'],
|
|
95
|
+
appliedCount: 12,
|
|
96
|
+
successCount: 12,
|
|
97
|
+
createdAt: '2026-01-01T00:00:00.000Z',
|
|
98
|
+
updatedAt: '2026-01-01T00:00:00.000Z',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
await fs.writeFile(
|
|
103
|
+
path.join(tmp, '.ai-kit', 'state', 'memory.json'),
|
|
104
|
+
JSON.stringify(memory, null, 2),
|
|
105
|
+
'utf8',
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const ctx = makeCtx(['Monorepo'], tmp);
|
|
109
|
+
const r = await memoryCommand.run(ctx);
|
|
110
|
+
expect(r.exitCode).toBe(0);
|
|
111
|
+
expect(ctx.out[0]).toContain('MEM-TEST-001');
|
|
112
|
+
expect(ctx.out[0]).toContain('Modular Monorepo Invariant');
|
|
113
|
+
} finally {
|
|
114
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe('evolveCommand (M31-M33)', () => {
|
|
120
|
+
it('reports honestly when no experiences have been persisted', async () => {
|
|
121
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-evolve-empty-'));
|
|
122
|
+
try {
|
|
123
|
+
const ctx = makeCtx(['--dry-run'], tmp);
|
|
124
|
+
const r = await evolveCommand.run(ctx);
|
|
125
|
+
expect(r.exitCode).toBe(1);
|
|
126
|
+
expect(ctx.out[0]).toContain('no experience records found');
|
|
127
|
+
} finally {
|
|
128
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('distills lessons from persisted experiences', async () => {
|
|
133
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-evolve-real-'));
|
|
134
|
+
try {
|
|
135
|
+
// Write an experiences file with recurring failures.
|
|
136
|
+
await fs.mkdir(path.join(tmp, '.ai-kit', 'state'), { recursive: true });
|
|
137
|
+
const experiences = {
|
|
138
|
+
schemaVersion: 1,
|
|
139
|
+
records: [
|
|
140
|
+
{
|
|
141
|
+
id: 'EXP-1',
|
|
142
|
+
workflowId: 'WF-1',
|
|
143
|
+
featureId: 'FEATURE-A',
|
|
144
|
+
stack: 'node-typescript',
|
|
145
|
+
outcome: 'failure',
|
|
146
|
+
phases: [{ name: 'tdd', status: 'failed', durationMs: 200 }],
|
|
147
|
+
timestamp: '2026-01-01T00:00:00.000Z',
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
id: 'EXP-2',
|
|
151
|
+
workflowId: 'WF-2',
|
|
152
|
+
featureId: 'FEATURE-B',
|
|
153
|
+
stack: 'node-typescript',
|
|
154
|
+
outcome: 'failure',
|
|
155
|
+
phases: [{ name: 'tdd', status: 'failed', durationMs: 250 }],
|
|
156
|
+
timestamp: '2026-01-01T01:00:00.000Z',
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
};
|
|
160
|
+
await fs.writeFile(
|
|
161
|
+
path.join(tmp, '.ai-kit', 'state', 'experiences.json'),
|
|
162
|
+
JSON.stringify(experiences, null, 2),
|
|
163
|
+
'utf8',
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const ctx = makeCtx(['--dry-run'], tmp);
|
|
167
|
+
const r = await evolveCommand.run(ctx);
|
|
168
|
+
expect(r.exitCode).toBe(0);
|
|
169
|
+
// The output should reference the real distilled data, not demo data.
|
|
170
|
+
expect(ctx.out[0]).toContain('Experiences Loaded: 2');
|
|
171
|
+
expect(ctx.out[0]).toContain('Distilled Lessons: 1');
|
|
172
|
+
// The benchmark environment is not implemented, so the lab must say
|
|
173
|
+
// so instead of reporting COMPLETED with empty numbers (ADR-0018).
|
|
174
|
+
expect(ctx.out[0]).toContain('NOT RUN');
|
|
175
|
+
expect(ctx.out[0]).toContain('0 executed, 1 not run');
|
|
176
|
+
expect(ctx.out[0]).not.toContain('Evolution Lab: COMPLETED');
|
|
177
|
+
} finally {
|
|
178
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
});
|