@agentic-sdlc-kit/cli 0.0.0-stage → 0.9.1
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 +91 -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 +116 -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/attach-exclude.d.ts +8 -0
- package/dist/commands/attach-exclude.d.ts.map +1 -0
- package/dist/commands/attach-exclude.js +48 -0
- package/dist/commands/attach-exclude.js.map +1 -0
- package/dist/commands/attach-git.d.ts +11 -0
- package/dist/commands/attach-git.d.ts.map +1 -0
- package/dist/commands/attach-git.js +40 -0
- package/dist/commands/attach-git.js.map +1 -0
- package/dist/commands/attach-store.d.ts +10 -0
- package/dist/commands/attach-store.d.ts.map +1 -0
- package/dist/commands/attach-store.js +107 -0
- package/dist/commands/attach-store.js.map +1 -0
- package/dist/commands/attach.d.ts +8 -0
- package/dist/commands/attach.d.ts.map +1 -0
- package/dist/commands/attach.js +124 -0
- package/dist/commands/attach.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 +4 -0
- package/dist/commands/fix.d.ts.map +1 -0
- package/dist/commands/fix.js +53 -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/host-apply.d.ts +12 -0
- package/dist/commands/host-apply.d.ts.map +1 -0
- package/dist/commands/host-apply.js +43 -0
- package/dist/commands/host-apply.js.map +1 -0
- package/dist/commands/host.d.ts +3 -0
- package/dist/commands/host.d.ts.map +1 -0
- package/dist/commands/host.js +107 -0
- package/dist/commands/host.js.map +1 -0
- package/dist/commands/index.d.ts +25 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +26 -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 +92 -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 +337 -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 +43 -0
- package/dist/commands/plugin-linker.d.ts.map +1 -0
- package/dist/commands/plugin-linker.js +216 -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/skills-install-commit.d.ts +34 -0
- package/dist/commands/skills-install-commit.d.ts.map +1 -0
- package/dist/commands/skills-install-commit.js +113 -0
- package/dist/commands/skills-install-commit.js.map +1 -0
- package/dist/commands/skills-install-manifest.d.ts +35 -0
- package/dist/commands/skills-install-manifest.d.ts.map +1 -0
- package/dist/commands/skills-install-manifest.js +89 -0
- package/dist/commands/skills-install-manifest.js.map +1 -0
- package/dist/commands/skills-install-report.d.ts +12 -0
- package/dist/commands/skills-install-report.d.ts.map +1 -0
- package/dist/commands/skills-install-report.js +44 -0
- package/dist/commands/skills-install-report.js.map +1 -0
- package/dist/commands/skills-install-secure.d.ts +14 -0
- package/dist/commands/skills-install-secure.d.ts.map +1 -0
- package/dist/commands/skills-install-secure.js +96 -0
- package/dist/commands/skills-install-secure.js.map +1 -0
- package/dist/commands/skills-install.d.ts +15 -0
- package/dist/commands/skills-install.d.ts.map +1 -0
- package/dist/commands/skills-install.js +182 -0
- package/dist/commands/skills-install.js.map +1 -0
- package/dist/commands/skills.d.ts +3 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +217 -0
- package/dist/commands/skills.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/uninstall.d.ts +3 -0
- package/dist/commands/uninstall.d.ts.map +1 -0
- package/dist/commands/uninstall.js +113 -0
- package/dist/commands/uninstall.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 +163 -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 +629 -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 +108 -0
- package/src/application/dispatcher.ts +106 -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/attach-exclude.ts +50 -0
- package/src/commands/attach-git.ts +50 -0
- package/src/commands/attach-store.ts +107 -0
- package/src/commands/attach.test.ts +192 -0
- package/src/commands/attach.ts +143 -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 +118 -0
- package/src/commands/fix.ts +58 -0
- package/src/commands/help.test.ts +33 -0
- package/src/commands/help.ts +35 -0
- package/src/commands/host-apply.ts +61 -0
- package/src/commands/host.test.ts +120 -0
- package/src/commands/host.ts +125 -0
- package/src/commands/index.ts +25 -0
- package/src/commands/init.test.ts +87 -0
- package/src/commands/init.ts +110 -0
- package/src/commands/inspect.test.ts +57 -0
- package/src/commands/inspect.ts +73 -0
- package/src/commands/install.test.ts +92 -0
- package/src/commands/install.ts +389 -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 +219 -0
- package/src/commands/plugin-linker.ts +244 -0
- package/src/commands/refactor.ts +34 -0
- package/src/commands/skills-install-commit.ts +149 -0
- package/src/commands/skills-install-manifest.ts +124 -0
- package/src/commands/skills-install-report.ts +60 -0
- package/src/commands/skills-install-secure.ts +113 -0
- package/src/commands/skills-install.ts +245 -0
- package/src/commands/skills.test.ts +449 -0
- package/src/commands/skills.ts +247 -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/uninstall.test.ts +122 -0
- package/src/commands/uninstall.ts +116 -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,67 @@
|
|
|
1
|
+
// CLI-level check that `kit new` and `kit init` derive commands from the stack
|
|
2
|
+
// pack. Regression: every stack used to receive npm commands.
|
|
3
|
+
import { promises as fs } from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
6
|
+
import { makeTempDir, type TempDir } from '@agentic-sdlc-kit/testing';
|
|
7
|
+
import { initCommand } from './init.js';
|
|
8
|
+
import { newCommand } from './new.js';
|
|
9
|
+
import type { CommandContext } from './types.js';
|
|
10
|
+
|
|
11
|
+
const ctxFor = (argv: string[], cwd: string): CommandContext & { out: string[]; err: string[] } => {
|
|
12
|
+
const out: string[] = [];
|
|
13
|
+
const err: string[] = [];
|
|
14
|
+
return { argv, cwd, stdout: (s) => void out.push(s), stderr: (s) => void err.push(s), out, err };
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('kit new / kit init stack commands', () => {
|
|
18
|
+
let dir: TempDir;
|
|
19
|
+
beforeEach(async () => {
|
|
20
|
+
dir = await makeTempDir('kit-stack-cmds-');
|
|
21
|
+
});
|
|
22
|
+
afterEach(async () => dir.cleanup());
|
|
23
|
+
|
|
24
|
+
it('kit new --stack python writes pytest, not npm', async () => {
|
|
25
|
+
const c = ctxFor(['demo', '--stack', 'python', '--dir', dir.path], dir.path);
|
|
26
|
+
expect((await newCommand.run(c)).exitCode).toBe(0);
|
|
27
|
+
const yml = await fs.readFile(path.join(dir.path, 'demo', '.ai-kit', 'project.yml'), 'utf8');
|
|
28
|
+
expect(yml).toContain("['python3', '-m', 'pytest']");
|
|
29
|
+
expect(yml).not.toContain('npm');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('kit new --stack react-spa is accepted and stored under the canonical id', async () => {
|
|
33
|
+
const c = ctxFor(['web', '--stack', 'react-spa', '--dir', dir.path], dir.path);
|
|
34
|
+
expect((await newCommand.run(c)).exitCode).toBe(0);
|
|
35
|
+
const yml = await fs.readFile(path.join(dir.path, 'web', '.ai-kit', 'project.yml'), 'utf8');
|
|
36
|
+
expect(yml).toContain('- react-typescript');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('kit new rejects an unknown stack with exit 1', async () => {
|
|
40
|
+
const c = ctxFor(['x', '--stack', 'cobol', '--dir', dir.path], dir.path);
|
|
41
|
+
expect((await newCommand.run(c)).exitCode).toBe(1);
|
|
42
|
+
expect(c.err.join('')).toMatch(/unknown stack/);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('kit init on a Python repo derives pytest and nothing it cannot confirm', async () => {
|
|
46
|
+
const repo = path.join(dir.path, 'py-shop');
|
|
47
|
+
await fs.mkdir(path.join(repo, 'app'), { recursive: true });
|
|
48
|
+
await fs.writeFile(path.join(repo, 'pyproject.toml'), "[project]\nname='py'\n[tool.pytest.ini_options]\ntestpaths=['tests']\n");
|
|
49
|
+
const c = ctxFor([repo], dir.path);
|
|
50
|
+
expect((await initCommand.run(c)).exitCode).toBe(0);
|
|
51
|
+
const yml = await fs.readFile(path.join(repo, '.ai-kit', 'project.yml'), 'utf8');
|
|
52
|
+
expect(yml).toContain("['python3', '-m', 'pytest']");
|
|
53
|
+
expect(yml).not.toContain('ruff');
|
|
54
|
+
expect(yml).not.toContain('mypy');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('kit init on a plain Ruby repo derives bundle-exec RSpec, not Rails commands', async () => {
|
|
58
|
+
const repo = path.join(dir.path, 'rb-lib');
|
|
59
|
+
await fs.mkdir(path.join(repo, 'spec'), { recursive: true });
|
|
60
|
+
await fs.writeFile(path.join(repo, 'Gemfile'), "source 'https://rubygems.org'\ngem 'rspec'\n");
|
|
61
|
+
const c = ctxFor([repo], dir.path);
|
|
62
|
+
expect((await initCommand.run(c)).exitCode).toBe(0);
|
|
63
|
+
const yml = await fs.readFile(path.join(repo, '.ai-kit', 'project.yml'), 'utf8');
|
|
64
|
+
expect(yml).toContain("['bundle', 'exec', 'rspec']");
|
|
65
|
+
expect(yml).not.toContain('rails');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// packages/cli/src/commands/tier-c-conformance.test.ts
|
|
2
|
+
//
|
|
3
|
+
// Tier C conformance for the REAL CLI (ADR-0021 §5): every driver
|
|
4
|
+
// operation goes through the actual commands — feature, next, journal —
|
|
5
|
+
// against a real fixture project. This is the executable proof that
|
|
6
|
+
// the kit's own CLI implements the host-driven agent protocol a Tier C
|
|
7
|
+
// host (Cursor, AGY, CI) depends on. Any future host adapter runs the
|
|
8
|
+
// SAME golden trace through its own driver and must observe the same
|
|
9
|
+
// sequence.
|
|
10
|
+
import { promises as fs } from 'node:fs';
|
|
11
|
+
import os from 'node:os';
|
|
12
|
+
import path from 'node:path';
|
|
13
|
+
import { describe, expect, it } from 'vitest';
|
|
14
|
+
import { scaffoldSpecification, serializeProfileYaml } from '@agentic-sdlc-kit/core';
|
|
15
|
+
import type { JournalEvent, NextAction } from '@agentic-sdlc-kit/contracts';
|
|
16
|
+
import { runTierCConformanceTrace, type TierCConformanceDriver } from '@agentic-sdlc-kit/testing';
|
|
17
|
+
import { featureCommand } from './feature.js';
|
|
18
|
+
import { journalCommand } from './journal.js';
|
|
19
|
+
import { nextCommand } from './next.js';
|
|
20
|
+
import type { CommandContext } from './types.js';
|
|
21
|
+
|
|
22
|
+
function makeCtx(argv: string[], cwd: string): CommandContext {
|
|
23
|
+
return {
|
|
24
|
+
argv,
|
|
25
|
+
cwd,
|
|
26
|
+
stdout: () => undefined,
|
|
27
|
+
stderr: () => undefined,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function setupProject(): Promise<string> {
|
|
32
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-tier-c-'));
|
|
33
|
+
|
|
34
|
+
await fs.mkdir(path.join(tmp, '.git'), { recursive: true });
|
|
35
|
+
await fs.writeFile(path.join(tmp, '.git', 'HEAD'), 'ref: refs/heads/main\n');
|
|
36
|
+
|
|
37
|
+
// Per-task markers: each task's verification fails with a REAL
|
|
38
|
+
// assertion error until ITS OWN marker exists, so a multi-task golden
|
|
39
|
+
// trace can implement tasks one at a time (same shape as the Mode 1
|
|
40
|
+
// orchestration fixture).
|
|
41
|
+
const script = path.join(tmp, 'check.js');
|
|
42
|
+
await fs.writeFile(
|
|
43
|
+
script,
|
|
44
|
+
[
|
|
45
|
+
'const task = process.argv[2];',
|
|
46
|
+
'if (!task) { console.error("AssertionError: missing task argument"); process.exit(1); }',
|
|
47
|
+
'const fs = require("node:fs");',
|
|
48
|
+
'if (!fs.existsSync(".done-" + task)) {',
|
|
49
|
+
' console.error("AssertionError: expected target for " + task + " to be implemented");',
|
|
50
|
+
' process.exit(1);',
|
|
51
|
+
'}',
|
|
52
|
+
'process.exit(0);',
|
|
53
|
+
].join('\n'),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const aiKit = path.join(tmp, '.ai-kit');
|
|
57
|
+
await fs.mkdir(aiKit, { recursive: true });
|
|
58
|
+
await fs.writeFile(
|
|
59
|
+
path.join(aiKit, 'project.yml'),
|
|
60
|
+
serializeProfileYaml({
|
|
61
|
+
schemaVersion: 1,
|
|
62
|
+
name: 'tier-c-conformance-app',
|
|
63
|
+
stack: ['node-typescript'],
|
|
64
|
+
commands: {
|
|
65
|
+
test: [
|
|
66
|
+
['node', 'check.js', 'TASK-001'],
|
|
67
|
+
['node', 'check.js', 'TASK-002'],
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
await scaffoldSpecification({
|
|
74
|
+
id: 'FEATURE-001',
|
|
75
|
+
title: 'Tier C Conformance',
|
|
76
|
+
targetDir: path.join(tmp, 'docs', 'specifications', 'features'),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const planDir = path.join(tmp, 'docs', 'plans', 'FEATURE-001');
|
|
80
|
+
await fs.mkdir(planDir, { recursive: true });
|
|
81
|
+
await fs.writeFile(
|
|
82
|
+
path.join(planDir, 'plan.json'),
|
|
83
|
+
JSON.stringify(
|
|
84
|
+
{
|
|
85
|
+
featureId: 'FEATURE-001',
|
|
86
|
+
tasks: ['TASK-001', 'TASK-002'].map((id) => ({
|
|
87
|
+
id,
|
|
88
|
+
description: `Implement ${id}`,
|
|
89
|
+
acceptanceCriteria: [`${id} works`],
|
|
90
|
+
verification: { command: ['node', 'check.js', id], expectedStatus: 'passed' },
|
|
91
|
+
dependencies: [],
|
|
92
|
+
likelyFiles: [`src/${id}.ts`],
|
|
93
|
+
estimatedScope: 's',
|
|
94
|
+
risk: 'low',
|
|
95
|
+
})),
|
|
96
|
+
edges: [],
|
|
97
|
+
verticalSlices: [['TASK-001'], ['TASK-002']],
|
|
98
|
+
},
|
|
99
|
+
null,
|
|
100
|
+
2,
|
|
101
|
+
),
|
|
102
|
+
);
|
|
103
|
+
return tmp;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The CLI driver: every protocol action is a REAL command invocation. */
|
|
107
|
+
function cliDriver(root: string): TierCConformanceDriver {
|
|
108
|
+
const runCommand = async (
|
|
109
|
+
command: { run(ctx: CommandContext): Promise<{ exitCode: number; message?: string }> },
|
|
110
|
+
argv: string[],
|
|
111
|
+
): Promise<{ ok: boolean; message?: string }> => {
|
|
112
|
+
const result = await command.run(makeCtx(argv, root));
|
|
113
|
+
return result.exitCode === 0
|
|
114
|
+
? { ok: true }
|
|
115
|
+
: { ok: false, message: result.message ?? `exit ${result.exitCode}` };
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
start: (featureId) => runCommand(featureCommand, [featureId, 'start']),
|
|
120
|
+
async next(featureId) {
|
|
121
|
+
const out: string[] = [];
|
|
122
|
+
const result = await nextCommand.run({
|
|
123
|
+
argv: [featureId, '--json'],
|
|
124
|
+
cwd: root,
|
|
125
|
+
stdout: (s) => void out.push(s),
|
|
126
|
+
stderr: () => undefined,
|
|
127
|
+
});
|
|
128
|
+
expect(result.exitCode).toBe(0);
|
|
129
|
+
return JSON.parse(out.join('')) as NextAction;
|
|
130
|
+
},
|
|
131
|
+
runPhase: (featureId, taskId, phase) =>
|
|
132
|
+
runCommand(featureCommand, [featureId, phase, taskId, '--host', 'conformance-test']),
|
|
133
|
+
verify: (featureId) => runCommand(featureCommand, [featureId, 'verify']),
|
|
134
|
+
async journal(featureId) {
|
|
135
|
+
const out: string[] = [];
|
|
136
|
+
const result = await journalCommand.run({
|
|
137
|
+
argv: [featureId, '--json'],
|
|
138
|
+
cwd: root,
|
|
139
|
+
stdout: (s) => void out.push(s),
|
|
140
|
+
stderr: () => undefined,
|
|
141
|
+
});
|
|
142
|
+
expect(result.exitCode).toBe(0);
|
|
143
|
+
return JSON.parse(out.join('')) as JournalEvent[];
|
|
144
|
+
},
|
|
145
|
+
async verifyJournal(featureId) {
|
|
146
|
+
const out: string[] = [];
|
|
147
|
+
const result = await journalCommand.run({
|
|
148
|
+
argv: [featureId, '--verify', '--json'],
|
|
149
|
+
cwd: root,
|
|
150
|
+
stdout: (s) => void out.push(s),
|
|
151
|
+
stderr: () => undefined,
|
|
152
|
+
});
|
|
153
|
+
const parsed = JSON.parse(out.join('')) as {
|
|
154
|
+
valid: boolean;
|
|
155
|
+
eventCount: number;
|
|
156
|
+
};
|
|
157
|
+
return { ...parsed, ...(result.exitCode !== 0 ? { reason: 'verify command failed' } : {}) };
|
|
158
|
+
},
|
|
159
|
+
async applyImplementation(_featureId: string, taskId: string) {
|
|
160
|
+
// The fixture's "implementation" is the task's marker file — exactly
|
|
161
|
+
// where a real host's code edits would land between phases.
|
|
162
|
+
await fs.writeFile(path.join(root, `.done-${taskId}`), 'implemented\n', 'utf8');
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
describe('Tier C conformance: the real CLI drives the golden trace', () => {
|
|
168
|
+
it('passes the full golden trace for a two-task feature', async () => {
|
|
169
|
+
const root = await setupProject();
|
|
170
|
+
const report = await runTierCConformanceTrace(cliDriver(root), {
|
|
171
|
+
featureId: 'FEATURE-001',
|
|
172
|
+
taskIds: ['TASK-001', 'TASK-002'],
|
|
173
|
+
});
|
|
174
|
+
const failures = report.steps.filter((s) => !s.passed);
|
|
175
|
+
expect(failures).toEqual([]);
|
|
176
|
+
expect(report.passed).toBe(true);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('records the host declaration in the journal actor for phase events', async () => {
|
|
180
|
+
const root = await setupProject();
|
|
181
|
+
const report = await runTierCConformanceTrace(cliDriver(root), {
|
|
182
|
+
featureId: 'FEATURE-001',
|
|
183
|
+
taskIds: ['TASK-001', 'TASK-002'],
|
|
184
|
+
});
|
|
185
|
+
expect(report.passed).toBe(true);
|
|
186
|
+
const driver = cliDriver(root);
|
|
187
|
+
const events = await driver.journal('FEATURE-001');
|
|
188
|
+
const phaseEvents = events.filter((e) => e.kind.startsWith('phase.'));
|
|
189
|
+
expect(phaseEvents.length).toBeGreaterThan(0);
|
|
190
|
+
for (const event of phaseEvents) {
|
|
191
|
+
expect(event.actor).toEqual({ kind: 'agent', host: 'conformance-test' });
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// packages/cli/src/commands/types.ts
|
|
2
|
+
//
|
|
3
|
+
// Command interface. Every command implements this. The dispatcher
|
|
4
|
+
// (application/dispatcher.ts) is the only place that knows the full
|
|
5
|
+
// command list. Adding a command = adding one file + one registry entry.
|
|
6
|
+
|
|
7
|
+
export interface CommandContext {
|
|
8
|
+
argv: ReadonlyArray<string>;
|
|
9
|
+
cwd: string;
|
|
10
|
+
stdout: (s: string) => void;
|
|
11
|
+
stderr: (s: string) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface CommandResult {
|
|
15
|
+
exitCode: number;
|
|
16
|
+
message?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface Command {
|
|
20
|
+
/** Command name as invoked on the CLI: `doctor`, `version`, etc. */
|
|
21
|
+
readonly name: string;
|
|
22
|
+
/** One-line summary for `kit --help`. */
|
|
23
|
+
readonly summary: string;
|
|
24
|
+
/** Run the command. MUST NOT throw; failures return a non-zero exitCode. */
|
|
25
|
+
run(ctx: CommandContext): Promise<CommandResult> | CommandResult;
|
|
26
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
4
|
+
import { makeTempDir, type TempDir } from '@agentic-sdlc-kit/testing';
|
|
5
|
+
import { installCommand } from './install.js';
|
|
6
|
+
import { uninstallCommand } from './uninstall.js';
|
|
7
|
+
import type { CommandContext } from './types.js';
|
|
8
|
+
|
|
9
|
+
const ctxFor = (argv: string[], cwd: string): CommandContext => ({
|
|
10
|
+
argv,
|
|
11
|
+
cwd,
|
|
12
|
+
stdout: () => undefined,
|
|
13
|
+
stderr: () => undefined,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const exists = (p: string): Promise<boolean> =>
|
|
17
|
+
fs.access(p).then(
|
|
18
|
+
() => true,
|
|
19
|
+
() => false,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
describe('uninstallCommand', () => {
|
|
23
|
+
let dir: TempDir;
|
|
24
|
+
beforeEach(async () => {
|
|
25
|
+
dir = await makeTempDir('kit-uninstall-');
|
|
26
|
+
await installCommand.run(ctxFor(['--profile', 'full-sdlc', '--dir', dir.path], dir.path));
|
|
27
|
+
});
|
|
28
|
+
afterEach(() => dir.cleanup());
|
|
29
|
+
|
|
30
|
+
it('removes unchanged installed files and the manifest', async () => {
|
|
31
|
+
const r = await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
|
|
32
|
+
expect(r.exitCode).toBe(0);
|
|
33
|
+
expect(await exists(path.join(dir.path, 'docs/specifications/.gitkeep'))).toBe(false);
|
|
34
|
+
expect(await exists(path.join(dir.path, '.ai-kit/ownership-manifest.json'))).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('keeps a file the user edited after install', async () => {
|
|
38
|
+
const yml = path.join(dir.path, '.ai-kit/project.yml');
|
|
39
|
+
await fs.appendFile(yml, 'name: mine\n');
|
|
40
|
+
await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
|
|
41
|
+
expect(await exists(yml)).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('removes nothing on --dry-run', async () => {
|
|
45
|
+
await uninstallCommand.run(ctxFor(['--dry-run', '--dir', dir.path], dir.path));
|
|
46
|
+
expect(await exists(path.join(dir.path, '.ai-kit/ownership-manifest.json'))).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('still owns first-install files after a second install', async () => {
|
|
50
|
+
await installCommand.run(ctxFor(['--profile', 'full-sdlc', '--dir', dir.path], dir.path));
|
|
51
|
+
await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
|
|
52
|
+
expect(await exists(path.join(dir.path, 'docs/specifications/.gitkeep'))).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('fails when there is no manifest', async () => {
|
|
56
|
+
const empty = await makeTempDir('kit-uninstall-empty-');
|
|
57
|
+
const r = await uninstallCommand.run(ctxFor(['--dir', empty.path], empty.path));
|
|
58
|
+
await empty.cleanup();
|
|
59
|
+
expect(r.exitCode).toBe(1);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('ownership integrity', () => {
|
|
63
|
+
const manifestPath = (): string => path.join(dir.path, '.ai-kit/ownership-manifest.json');
|
|
64
|
+
const readManifest = async (): Promise<{ entries: Array<Record<string, unknown>> }> =>
|
|
65
|
+
JSON.parse(await fs.readFile(manifestPath(), 'utf8'));
|
|
66
|
+
const writeManifest = (m: unknown): Promise<void> =>
|
|
67
|
+
fs.writeFile(manifestPath(), JSON.stringify(m, null, 2));
|
|
68
|
+
const pluginLink = (): string => path.join(dir.path, '.claude/plugins/sdlc-guard');
|
|
69
|
+
|
|
70
|
+
it('removes the kit-created plugin links (the link, never its target)', async () => {
|
|
71
|
+
const target = await fs.realpath(pluginLink());
|
|
72
|
+
await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
|
|
73
|
+
expect(await exists(pluginLink())).toBe(false);
|
|
74
|
+
expect(await exists(path.join(target, '.claude-plugin/plugin.json'))).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('keeps a recorded link the user has since re-pointed elsewhere', async () => {
|
|
78
|
+
const mine = await makeTempDir('kit-mine-');
|
|
79
|
+
await fs.rm(pluginLink());
|
|
80
|
+
await fs.symlink(mine.path, pluginLink(), 'dir');
|
|
81
|
+
const r = await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
|
|
82
|
+
expect(r.exitCode).toBe(0);
|
|
83
|
+
expect(await fs.readlink(pluginLink())).toBe(mine.path);
|
|
84
|
+
await mine.cleanup();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('keeps a real directory at a recorded path and still removes the rest (no crash)', async () => {
|
|
88
|
+
await fs.rm(pluginLink());
|
|
89
|
+
await fs.mkdir(pluginLink());
|
|
90
|
+
await fs.writeFile(path.join(pluginLink(), 'mine.txt'), 'user data');
|
|
91
|
+
const r = await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
|
|
92
|
+
expect(r.exitCode).toBe(0);
|
|
93
|
+
expect(await exists(path.join(pluginLink(), 'mine.txt'))).toBe(true);
|
|
94
|
+
expect(await exists(path.join(dir.path, 'docs/specifications/.gitkeep'))).toBe(false);
|
|
95
|
+
expect(await exists(manifestPath())).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('never deletes outside the root, even if the manifest says so', async () => {
|
|
99
|
+
const outside = await makeTempDir('kit-outside-');
|
|
100
|
+
const victim = path.join(outside.path, 'victim.txt');
|
|
101
|
+
await fs.writeFile(victim, 'precious');
|
|
102
|
+
const m = await readManifest();
|
|
103
|
+
m.entries.push({
|
|
104
|
+
...m.entries[0]!,
|
|
105
|
+
path: path.relative(dir.path, victim),
|
|
106
|
+
sha256: (await import('node:crypto')).createHash('sha256').update('precious').digest('hex'),
|
|
107
|
+
});
|
|
108
|
+
await writeManifest(m);
|
|
109
|
+
await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
|
|
110
|
+
expect(await exists(victim)).toBe(true);
|
|
111
|
+
await outside.cleanup();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('still removes a legacy link entry (no recorded target) that points at the kit plugin', async () => {
|
|
115
|
+
const m = await readManifest();
|
|
116
|
+
for (const e of m.entries) delete e['target'];
|
|
117
|
+
await writeManifest(m);
|
|
118
|
+
await uninstallCommand.run(ctxFor(['--dir', dir.path], dir.path));
|
|
119
|
+
expect(await exists(pluginLink())).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// packages/cli/src/commands/uninstall.ts
|
|
2
|
+
//
|
|
3
|
+
// `kit uninstall [--dir <path>] [--dry-run] [--json]`. Removes only what
|
|
4
|
+
// `kit install` recorded in the ownership manifest: files whose content is
|
|
5
|
+
// unchanged since install, and plugin symlinks (the link, never its target).
|
|
6
|
+
// Files the user edited or that were never ours are kept and reported.
|
|
7
|
+
|
|
8
|
+
import crypto from 'node:crypto';
|
|
9
|
+
import { promises as fs } from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { OwnershipManifestSchema, type OwnershipEntry } from '@agentic-sdlc-kit/contracts';
|
|
12
|
+
import { linkTarget } from './plugin-linker.js';
|
|
13
|
+
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
14
|
+
|
|
15
|
+
const MANIFEST_PATH = '.ai-kit/ownership-manifest.json';
|
|
16
|
+
|
|
17
|
+
type Verdict = 'remove' | 'keep-modified' | 'keep-foreign' | 'missing';
|
|
18
|
+
|
|
19
|
+
const sha256 = (text: string): string => crypto.createHash('sha256').update(text, 'utf8').digest('hex');
|
|
20
|
+
|
|
21
|
+
/** True only when `full` stays inside `root` (a manifest must never reach outside it). */
|
|
22
|
+
function isInside(root: string, full: string): boolean {
|
|
23
|
+
const rel = path.relative(root, full);
|
|
24
|
+
return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A recorded link is the kit's only while it still points where the kit
|
|
29
|
+
* pointed it. Entries from before `target` existed are verified by content:
|
|
30
|
+
* the plugin identity file read through the link must hash to the recorded value.
|
|
31
|
+
*/
|
|
32
|
+
async function ownsLink(full: string, entry: OwnershipEntry): Promise<boolean> {
|
|
33
|
+
if (entry.target !== undefined) return (await linkTarget(full)) === entry.target;
|
|
34
|
+
const identity = await fs
|
|
35
|
+
.readFile(path.join(full, '.claude-plugin', 'plugin.json'), 'utf8')
|
|
36
|
+
.catch(() => undefined);
|
|
37
|
+
return identity !== undefined && sha256(identity) === entry.sha256;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function judge(root: string, entry: OwnershipEntry): Promise<Verdict> {
|
|
41
|
+
const full = path.resolve(root, entry.path);
|
|
42
|
+
if (!isInside(root, full)) return 'keep-foreign';
|
|
43
|
+
const stat = await fs.lstat(full).catch(() => null);
|
|
44
|
+
if (!stat) return 'missing';
|
|
45
|
+
if (stat.isSymbolicLink()) return (await ownsLink(full, entry)) ? 'remove' : 'keep-foreign';
|
|
46
|
+
if (!stat.isFile()) return 'keep-foreign'; // a real directory is never ours to delete
|
|
47
|
+
const content = await fs.readFile(full, 'utf8');
|
|
48
|
+
return sha256(content) === entry.sha256 ? 'remove' : 'keep-modified';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** One bad entry must not abort the run half-way: anything unjudgeable is kept. */
|
|
52
|
+
async function safeJudge(root: string, entry: OwnershipEntry): Promise<Verdict> {
|
|
53
|
+
try {
|
|
54
|
+
return await judge(root, entry);
|
|
55
|
+
} catch {
|
|
56
|
+
return 'keep-foreign';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function readManifest(root: string): Promise<OwnershipEntry[] | undefined> {
|
|
61
|
+
const raw = await fs.readFile(path.join(root, MANIFEST_PATH), 'utf8').catch(() => undefined);
|
|
62
|
+
if (raw === undefined) return undefined;
|
|
63
|
+
return OwnershipManifestSchema.parse(JSON.parse(raw)).entries;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const uninstallCommand: Command = {
|
|
67
|
+
name: 'uninstall',
|
|
68
|
+
summary: 'Remove files and plugin links that kit install created and you have not edited.',
|
|
69
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
70
|
+
const dryRun = ctx.argv.includes('--dry-run');
|
|
71
|
+
const dirIdx = ctx.argv.indexOf('--dir');
|
|
72
|
+
const dirArg = dirIdx !== -1 ? ctx.argv[dirIdx + 1] : undefined;
|
|
73
|
+
if (dirIdx !== -1 && (!dirArg || dirArg.startsWith('-'))) {
|
|
74
|
+
ctx.stderr('kit uninstall: --dir requires a directory path\n');
|
|
75
|
+
return { exitCode: 1, message: 'missing --dir value' };
|
|
76
|
+
}
|
|
77
|
+
const root = path.resolve(ctx.cwd, dirArg ?? '.');
|
|
78
|
+
|
|
79
|
+
let entries: OwnershipEntry[] | undefined;
|
|
80
|
+
try {
|
|
81
|
+
entries = await readManifest(root);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
ctx.stderr(`kit uninstall: unreadable ownership manifest in ${root}: ${String(err)}\n`);
|
|
84
|
+
return { exitCode: 1, message: 'invalid ownership manifest' };
|
|
85
|
+
}
|
|
86
|
+
if (!entries) {
|
|
87
|
+
ctx.stderr(`kit uninstall: no ${MANIFEST_PATH} in ${root}; nothing owned to remove\n`);
|
|
88
|
+
return { exitCode: 1, message: 'no ownership manifest' };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const removed: string[] = [];
|
|
92
|
+
const kept: string[] = [];
|
|
93
|
+
const foreign: string[] = [];
|
|
94
|
+
for (const entry of entries) {
|
|
95
|
+
const verdict = await safeJudge(root, entry);
|
|
96
|
+
if (verdict === 'keep-modified') kept.push(entry.path);
|
|
97
|
+
if (verdict === 'keep-foreign') foreign.push(entry.path);
|
|
98
|
+
if (verdict !== 'remove') continue;
|
|
99
|
+
if (!dryRun) await fs.rm(path.resolve(root, entry.path), { force: true });
|
|
100
|
+
removed.push(entry.path);
|
|
101
|
+
}
|
|
102
|
+
if (!dryRun) await fs.rm(path.join(root, MANIFEST_PATH), { force: true });
|
|
103
|
+
|
|
104
|
+
const label = dryRun ? 'would remove' : 'removed';
|
|
105
|
+
ctx.stdout(
|
|
106
|
+
[
|
|
107
|
+
`kit uninstall${dryRun ? ' --dry-run' : ''}`,
|
|
108
|
+
...removed.map((p) => ` ${label} ${p}`),
|
|
109
|
+
...kept.map((p) => ` kept (edited since install) ${p}`),
|
|
110
|
+
...foreign.map((p) => ` kept (not a file or link the kit created) ${p}`),
|
|
111
|
+
'',
|
|
112
|
+
].join('\n'),
|
|
113
|
+
);
|
|
114
|
+
return { exitCode: 0 };
|
|
115
|
+
},
|
|
116
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// packages/cli/src/commands/validate-plan.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 { validatePlanCommand } from './validate-plan.js';
|
|
7
|
+
import type { CommandContext } from './types.js';
|
|
8
|
+
|
|
9
|
+
const makeCtx = (
|
|
10
|
+
argv: string[],
|
|
11
|
+
cwd: string,
|
|
12
|
+
): CommandContext & { out: string[]; err: string[] } => {
|
|
13
|
+
const out: string[] = [];
|
|
14
|
+
const err: string[] = [];
|
|
15
|
+
return {
|
|
16
|
+
argv,
|
|
17
|
+
cwd,
|
|
18
|
+
stdout: (s) => void out.push(s),
|
|
19
|
+
stderr: (s) => void err.push(s),
|
|
20
|
+
out,
|
|
21
|
+
err,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('validatePlanCommand', () => {
|
|
26
|
+
it('shows help when --help is passed', async () => {
|
|
27
|
+
const ctx = makeCtx(['--help'], '/');
|
|
28
|
+
const r = await validatePlanCommand.run(ctx);
|
|
29
|
+
expect(r.exitCode).toBe(0);
|
|
30
|
+
expect(ctx.out[0]).toContain('Usage: kit validate-plan');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('validates a valid implementation plan', async () => {
|
|
34
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-plan-'));
|
|
35
|
+
try {
|
|
36
|
+
const planFile = path.join(tmp, 'plan.json');
|
|
37
|
+
const plan = {
|
|
38
|
+
featureId: 'FEATURE-001',
|
|
39
|
+
tasks: [
|
|
40
|
+
{
|
|
41
|
+
id: 'TASK-001',
|
|
42
|
+
description: 'Build domain logic',
|
|
43
|
+
acceptanceCriteria: ['Valid behavior'],
|
|
44
|
+
verification: { command: ['npm', 'test'], expectedStatus: 'passed' },
|
|
45
|
+
dependencies: [],
|
|
46
|
+
likelyFiles: ['src/index.ts'],
|
|
47
|
+
estimatedScope: 's',
|
|
48
|
+
risk: 'low',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
edges: [],
|
|
52
|
+
verticalSlices: [['TASK-001']],
|
|
53
|
+
};
|
|
54
|
+
await fs.writeFile(planFile, JSON.stringify(plan, null, 2), 'utf8');
|
|
55
|
+
|
|
56
|
+
const ctx = makeCtx([planFile], tmp);
|
|
57
|
+
const r = await validatePlanCommand.run(ctx);
|
|
58
|
+
expect(r.exitCode).toBe(0);
|
|
59
|
+
expect(ctx.out[0]).toContain('kit validate-plan: PASS');
|
|
60
|
+
expect(ctx.out[0]).toContain('FEATURE-001');
|
|
61
|
+
} finally {
|
|
62
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('fails when plan has dependency cycle', async () => {
|
|
67
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-plan-cycle-'));
|
|
68
|
+
try {
|
|
69
|
+
const planFile = path.join(tmp, 'plan.json');
|
|
70
|
+
const plan = {
|
|
71
|
+
featureId: 'FEATURE-001',
|
|
72
|
+
tasks: [
|
|
73
|
+
{
|
|
74
|
+
id: 'TASK-001',
|
|
75
|
+
description: 'Task A',
|
|
76
|
+
acceptanceCriteria: ['OK'],
|
|
77
|
+
verification: { command: ['npm', 'test'], expectedStatus: 'passed' },
|
|
78
|
+
dependencies: ['TASK-002'],
|
|
79
|
+
likelyFiles: [],
|
|
80
|
+
estimatedScope: 's',
|
|
81
|
+
risk: 'low',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 'TASK-002',
|
|
85
|
+
description: 'Task B',
|
|
86
|
+
acceptanceCriteria: ['OK'],
|
|
87
|
+
verification: { command: ['npm', 'test'], expectedStatus: 'passed' },
|
|
88
|
+
dependencies: ['TASK-001'],
|
|
89
|
+
likelyFiles: [],
|
|
90
|
+
estimatedScope: 's',
|
|
91
|
+
risk: 'low',
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
edges: [],
|
|
95
|
+
verticalSlices: [['TASK-001', 'TASK-002']],
|
|
96
|
+
};
|
|
97
|
+
await fs.writeFile(planFile, JSON.stringify(plan, null, 2), 'utf8');
|
|
98
|
+
|
|
99
|
+
const ctx = makeCtx([planFile], tmp);
|
|
100
|
+
const r = await validatePlanCommand.run(ctx);
|
|
101
|
+
expect(r.exitCode).toBe(1);
|
|
102
|
+
expect(ctx.err[0]).toContain('Dependency cycle detected');
|
|
103
|
+
} finally {
|
|
104
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|