@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,92 @@
|
|
|
1
|
+
// packages/cli/src/commands/install.test.ts
|
|
2
|
+
//
|
|
3
|
+
// Regression: `kit install --dir <target>` must write into <target>, never
|
|
4
|
+
// into the process cwd. Before this fix --dir was not parsed at all, so the
|
|
5
|
+
// profile, ownership manifest and plugin links all landed in cwd.
|
|
6
|
+
import { promises as fs } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
9
|
+
import { makeTempDir, type TempDir } from '@agentic-sdlc-kit/testing';
|
|
10
|
+
import { installCommand } from './install.js';
|
|
11
|
+
import type { CommandContext } from './types.js';
|
|
12
|
+
|
|
13
|
+
const makeCtx = (argv: string[], cwd: string): CommandContext & { err: string[] } => {
|
|
14
|
+
const err: string[] = [];
|
|
15
|
+
return { argv, cwd, stdout: () => undefined, stderr: (s) => void err.push(s), err };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const exists = (p: string): Promise<boolean> =>
|
|
19
|
+
fs.access(p).then(
|
|
20
|
+
() => true,
|
|
21
|
+
() => false,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
describe('installCommand --dir', () => {
|
|
25
|
+
let target: TempDir;
|
|
26
|
+
let elsewhere: TempDir;
|
|
27
|
+
|
|
28
|
+
beforeEach(async () => {
|
|
29
|
+
target = await makeTempDir('kit-install-target-');
|
|
30
|
+
elsewhere = await makeTempDir('kit-install-cwd-');
|
|
31
|
+
});
|
|
32
|
+
afterEach(async () => {
|
|
33
|
+
await target.cleanup();
|
|
34
|
+
await elsewhere.cleanup();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('writes the profile and ownership manifest under --dir, not under cwd', async () => {
|
|
38
|
+
const ctx = makeCtx(['--profile', 'minimal', '--dir', target.path], elsewhere.path);
|
|
39
|
+
const r = await installCommand.run(ctx);
|
|
40
|
+
expect(r.exitCode).toBe(0);
|
|
41
|
+
expect(await exists(path.join(target.path, '.ai-kit', 'project.yml'))).toBe(true);
|
|
42
|
+
expect(await exists(path.join(target.path, '.ai-kit', 'ownership-manifest.json'))).toBe(true);
|
|
43
|
+
expect(await exists(path.join(elsewhere.path, '.ai-kit'))).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('fails with exit 1 when --dir does not exist, and writes nothing', async () => {
|
|
47
|
+
const missing = path.join(elsewhere.path, 'nope');
|
|
48
|
+
const ctx = makeCtx(['--profile', 'minimal', '--dir', missing], elsewhere.path);
|
|
49
|
+
const r = await installCommand.run(ctx);
|
|
50
|
+
expect(r.exitCode).toBe(1);
|
|
51
|
+
expect(ctx.err.join('')).toMatch(/does not exist/);
|
|
52
|
+
expect(await exists(path.join(elsewhere.path, '.ai-kit'))).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('fails with exit 1 when --dir has no value', async () => {
|
|
56
|
+
const ctx = makeCtx(['--profile', 'minimal', '--dir'], elsewhere.path);
|
|
57
|
+
const r = await installCommand.run(ctx);
|
|
58
|
+
expect(r.exitCode).toBe(1);
|
|
59
|
+
expect(await exists(path.join(elsewhere.path, '.ai-kit'))).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('installCommand plugin ownership', () => {
|
|
64
|
+
let target: TempDir;
|
|
65
|
+
beforeEach(async () => {
|
|
66
|
+
target = await makeTempDir('kit-install-own-');
|
|
67
|
+
});
|
|
68
|
+
afterEach(() => target.cleanup());
|
|
69
|
+
|
|
70
|
+
const manifest = async (): Promise<{ entries: Array<{ path: string; target?: string }> }> =>
|
|
71
|
+
JSON.parse(await fs.readFile(path.join(target.path, '.ai-kit/ownership-manifest.json'), 'utf8'));
|
|
72
|
+
|
|
73
|
+
it('records the link target for the links it creates', async () => {
|
|
74
|
+
const r = await installCommand.run(makeCtx(['--profile', 'full-sdlc', '--dir', target.path], target.path));
|
|
75
|
+
expect(r.exitCode).toBe(0);
|
|
76
|
+
const link = (await manifest()).entries.find((e) => e.path === '.claude/plugins/sdlc-guard');
|
|
77
|
+
expect(link?.target).toBe(await fs.realpath(path.join(target.path, '.claude/plugins/sdlc-guard')));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('does not record a foreign symlink as kit-owned, leaves it alone, and exits non-zero', async () => {
|
|
81
|
+
const foreign = await makeTempDir('kit-foreign-');
|
|
82
|
+
const linkPath = path.join(target.path, '.claude/plugins/sdlc-guard');
|
|
83
|
+
await fs.mkdir(path.dirname(linkPath), { recursive: true });
|
|
84
|
+
await fs.symlink(foreign.path, linkPath, 'dir');
|
|
85
|
+
const ctx = makeCtx(['--profile', 'full-sdlc', '--dir', target.path], target.path);
|
|
86
|
+
const r = await installCommand.run(ctx);
|
|
87
|
+
expect(r.exitCode).toBe(1);
|
|
88
|
+
expect(await fs.readlink(linkPath)).toBe(foreign.path);
|
|
89
|
+
expect((await manifest()).entries.some((e) => e.path === '.claude/plugins/sdlc-guard')).toBe(false);
|
|
90
|
+
await foreign.cleanup();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
// packages/cli/src/commands/install.ts
|
|
2
|
+
//
|
|
3
|
+
// `kit install [--profile minimal|full-sdlc|runtime] [--stack <stack>] [--dry-run] [--json]`.
|
|
4
|
+
// M15 CLI installer: writes configuration files, tracks ownership, supports
|
|
5
|
+
// dry-run preview and idempotent re-installation.
|
|
6
|
+
|
|
7
|
+
import { promises as fs } from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { resolveStackPack } from '@agentic-sdlc-kit/core';
|
|
10
|
+
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
11
|
+
import type { OwnershipEntry } from '@agentic-sdlc-kit/contracts';
|
|
12
|
+
import { linkRuntimePlugins, type PluginLinkResult } from './plugin-linker.js';
|
|
13
|
+
|
|
14
|
+
// Profiles that also link the four runtime guard plugins into the
|
|
15
|
+
// project's `.claude/plugins/` directory (as documented in
|
|
16
|
+
// docs/HOST_INTEGRATIONS.md). `minimal` is plugin-free.
|
|
17
|
+
const PROFILES_WITH_PLUGINS: ReadonlySet<string> = new Set(['full-sdlc', 'runtime']);
|
|
18
|
+
|
|
19
|
+
interface InstallOperation {
|
|
20
|
+
path: string;
|
|
21
|
+
kind: 'create' | 'skip-existing' | 'overwrite-approved';
|
|
22
|
+
content: string;
|
|
23
|
+
sha256: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const FILES_BY_PROFILE: Record<string, ReadonlyArray<{ path: string; content: string }>> = {
|
|
27
|
+
minimal: [
|
|
28
|
+
{
|
|
29
|
+
path: '.ai-kit/project.yml',
|
|
30
|
+
content: [
|
|
31
|
+
'# Generated by kit install --profile minimal',
|
|
32
|
+
'# Run `kit init` to populate this file with detected values.',
|
|
33
|
+
'schemaVersion: 1',
|
|
34
|
+
'name: ""',
|
|
35
|
+
'stack: []',
|
|
36
|
+
'commands: {}',
|
|
37
|
+
'',
|
|
38
|
+
].join('\n'),
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
'full-sdlc': [
|
|
42
|
+
{
|
|
43
|
+
path: '.ai-kit/project.yml',
|
|
44
|
+
content: [
|
|
45
|
+
'# Generated by kit install --profile full-sdlc',
|
|
46
|
+
'# Run `kit init` to populate this file with detected values.',
|
|
47
|
+
'schemaVersion: 1',
|
|
48
|
+
'name: ""',
|
|
49
|
+
'stack: []',
|
|
50
|
+
'commands: {}',
|
|
51
|
+
'',
|
|
52
|
+
].join('\n'),
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
path: 'docs/specifications/.gitkeep',
|
|
56
|
+
content: '',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
path: 'docs/plans/.gitkeep',
|
|
60
|
+
content: '',
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
path: 'docs/architecture/adr/.gitkeep',
|
|
64
|
+
content: '',
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
path: 'docs/releases/.gitkeep',
|
|
68
|
+
content: '',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
runtime: [
|
|
72
|
+
{
|
|
73
|
+
path: '.ai-kit/state/.gitkeep',
|
|
74
|
+
content: '',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
path: '.ai-kit/reports/.gitkeep',
|
|
78
|
+
content: '',
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
async function sha256(text: string): Promise<string> {
|
|
84
|
+
const crypto = await import('node:crypto');
|
|
85
|
+
return crypto.createHash('sha256').update(text, 'utf8').digest('hex');
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function fileExists(p: string): Promise<boolean> {
|
|
89
|
+
try {
|
|
90
|
+
await fs.access(p);
|
|
91
|
+
return true;
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const installCommand: Command = {
|
|
98
|
+
name: 'install',
|
|
99
|
+
summary: 'Install and configure kit environment, instructions, and stack packs (M15).',
|
|
100
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
101
|
+
if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
|
|
102
|
+
ctx.stdout(formatHelp());
|
|
103
|
+
return { exitCode: 0 };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const isJson = ctx.argv.includes('--json');
|
|
107
|
+
const isDryRun = ctx.argv.includes('--dry-run');
|
|
108
|
+
const stackIdx = ctx.argv.indexOf('--stack');
|
|
109
|
+
const stackName = stackIdx !== -1 ? ctx.argv[stackIdx + 1] : undefined;
|
|
110
|
+
const profileIdx = ctx.argv.indexOf('--profile');
|
|
111
|
+
const installProfile = profileIdx !== -1 ? ctx.argv[profileIdx + 1] : 'full-sdlc';
|
|
112
|
+
|
|
113
|
+
// --dir selects the project to install into. Every write, plugin link and
|
|
114
|
+
// the ownership manifest resolve under this root; without it they used to
|
|
115
|
+
// land in the process cwd regardless of what the user asked for.
|
|
116
|
+
const dirIdx = ctx.argv.indexOf('--dir');
|
|
117
|
+
const dirArg = dirIdx !== -1 ? ctx.argv[dirIdx + 1] : undefined;
|
|
118
|
+
if (dirIdx !== -1 && (!dirArg || dirArg.startsWith('-'))) {
|
|
119
|
+
ctx.stderr('kit install: --dir requires a directory path\n');
|
|
120
|
+
return { exitCode: 1, message: 'missing --dir value' };
|
|
121
|
+
}
|
|
122
|
+
const targetRoot = path.resolve(ctx.cwd, dirArg ?? '.');
|
|
123
|
+
const targetStat = await fs.stat(targetRoot).catch(() => null);
|
|
124
|
+
if (!targetStat?.isDirectory()) {
|
|
125
|
+
ctx.stderr(`kit install: target directory does not exist: ${targetRoot}\n`);
|
|
126
|
+
return { exitCode: 1, message: `target directory not found: ${targetRoot}` };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!installProfile || !FILES_BY_PROFILE[installProfile]) {
|
|
130
|
+
ctx.stderr(`kit install: unknown profile '${installProfile ?? '(missing)'}'\n`);
|
|
131
|
+
return { exitCode: 1, message: `unknown profile: ${installProfile ?? '(missing)'}` };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Plan: compute operations for the selected profile.
|
|
135
|
+
const filesToWrite = FILES_BY_PROFILE[installProfile]!;
|
|
136
|
+
const operations: InstallOperation[] = [];
|
|
137
|
+
|
|
138
|
+
for (const file of filesToWrite) {
|
|
139
|
+
const targetPath = path.join(targetRoot, file.path);
|
|
140
|
+
const exists = await fileExists(targetPath);
|
|
141
|
+
let kind: InstallOperation['kind'] = 'create';
|
|
142
|
+
if (exists) {
|
|
143
|
+
// Idempotent: skip files that already exist unless they're .gitkeep
|
|
144
|
+
// (which are safe to overwrite).
|
|
145
|
+
if (file.path.endsWith('.gitkeep')) {
|
|
146
|
+
kind = 'overwrite-approved';
|
|
147
|
+
} else {
|
|
148
|
+
kind = 'skip-existing';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const hash = await sha256(file.content);
|
|
152
|
+
operations.push({ path: file.path, kind, content: file.content, sha256: hash });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// If a stack is specified, record it in the plan.
|
|
156
|
+
let stackInfo = 'none';
|
|
157
|
+
if (stackName) {
|
|
158
|
+
const pack = resolveStackPack(stackName);
|
|
159
|
+
stackInfo = pack ? pack.name : stackName;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Plugin-enabled profiles also link the runtime guard plugins.
|
|
163
|
+
const withPlugins = PROFILES_WITH_PLUGINS.has(installProfile);
|
|
164
|
+
|
|
165
|
+
// In dry-run mode, print the plan and exit without writing.
|
|
166
|
+
if (isDryRun) {
|
|
167
|
+
const plan = {
|
|
168
|
+
profile: installProfile,
|
|
169
|
+
stack: stackInfo,
|
|
170
|
+
dryRun: true,
|
|
171
|
+
plugins: withPlugins ? ['sdlc-guard', 'secret-guard', 'model-router', 'run-observer'] : [],
|
|
172
|
+
operations: operations.map((op) => ({
|
|
173
|
+
path: op.path,
|
|
174
|
+
kind: op.kind,
|
|
175
|
+
sha256: op.sha256,
|
|
176
|
+
})),
|
|
177
|
+
};
|
|
178
|
+
if (isJson) {
|
|
179
|
+
ctx.stdout(JSON.stringify(plan, null, 2) + '\n');
|
|
180
|
+
} else {
|
|
181
|
+
ctx.stdout(formatDryRun(plan));
|
|
182
|
+
}
|
|
183
|
+
return { exitCode: 0 };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Execute: write files that are create or overwrite-approved.
|
|
187
|
+
const writtenFiles: string[] = [];
|
|
188
|
+
const skippedFiles: string[] = [];
|
|
189
|
+
const ownershipEntries: OwnershipEntry[] = [];
|
|
190
|
+
const now = new Date().toISOString();
|
|
191
|
+
|
|
192
|
+
for (const op of operations) {
|
|
193
|
+
if (op.kind === 'skip-existing') {
|
|
194
|
+
skippedFiles.push(op.path);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const targetPath = path.join(targetRoot, op.path);
|
|
198
|
+
await fs.mkdir(path.dirname(targetPath), { recursive: true });
|
|
199
|
+
await fs.writeFile(targetPath, op.content, 'utf8');
|
|
200
|
+
writtenFiles.push(op.path);
|
|
201
|
+
// By this point, the file was written (create or overwrite-approved);
|
|
202
|
+
// preserved is false because we did not skip it.
|
|
203
|
+
ownershipEntries.push({
|
|
204
|
+
packageId: 'agentic-sdlc-kit',
|
|
205
|
+
packageVersion: '0.9.1',
|
|
206
|
+
path: op.path,
|
|
207
|
+
sha256: op.sha256,
|
|
208
|
+
installedAt: now,
|
|
209
|
+
preserved: false,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Link the runtime guard plugins for plugin-enabled profiles. This is
|
|
214
|
+
// what HOST_INTEGRATIONS.md documents: the plugins land in
|
|
215
|
+
// `<project>/.claude/plugins/` with validated hooks module paths.
|
|
216
|
+
let pluginResults: PluginLinkResult[] = [];
|
|
217
|
+
if (withPlugins) {
|
|
218
|
+
pluginResults = await linkRuntimePlugins(targetRoot);
|
|
219
|
+
for (const pr of pluginResults) {
|
|
220
|
+
if (pr.status === 'linked' || pr.status === 'already-linked') {
|
|
221
|
+
// Ownership hash for a plugin link: the content hash of the
|
|
222
|
+
// linked plugin's identity file (what the symlink resolves to),
|
|
223
|
+
// NOT the hash of the path string.
|
|
224
|
+
let pluginHash = '';
|
|
225
|
+
try {
|
|
226
|
+
const pluginJson = await fs.readFile(
|
|
227
|
+
path.join(pr.linkPath, '.claude-plugin', 'plugin.json'),
|
|
228
|
+
'utf8',
|
|
229
|
+
);
|
|
230
|
+
pluginHash = await sha256(pluginJson);
|
|
231
|
+
} catch {
|
|
232
|
+
pluginHash = await sha256(`${pr.name}:${pr.status}`);
|
|
233
|
+
}
|
|
234
|
+
ownershipEntries.push({
|
|
235
|
+
packageId: 'agentic-sdlc-kit',
|
|
236
|
+
packageVersion: '0.9.1',
|
|
237
|
+
path: path.relative(targetRoot, pr.linkPath),
|
|
238
|
+
sha256: pluginHash,
|
|
239
|
+
installedAt: now,
|
|
240
|
+
preserved: pr.status === 'already-linked',
|
|
241
|
+
...(pr.target !== undefined ? { target: pr.target } : {}),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Write ownership manifest so kit uninstall knows what we own.
|
|
248
|
+
const manifestPath = path.join(targetRoot, '.ai-kit', 'ownership-manifest.json');
|
|
249
|
+
await fs.mkdir(path.dirname(manifestPath), { recursive: true });
|
|
250
|
+
// A re-install skips files it already owns, so carry earlier entries
|
|
251
|
+
// forward; dropping them would orphan those files from `kit uninstall`.
|
|
252
|
+
const written = new Set(ownershipEntries.map((e) => e.path));
|
|
253
|
+
const earlier = await fs.readFile(manifestPath, 'utf8').then(
|
|
254
|
+
(raw) => (JSON.parse(raw) as { entries?: OwnershipEntry[] }).entries ?? [],
|
|
255
|
+
() => [] as OwnershipEntry[],
|
|
256
|
+
);
|
|
257
|
+
const manifest = {
|
|
258
|
+
schemaVersion: 1,
|
|
259
|
+
root: targetRoot,
|
|
260
|
+
scope: 'project',
|
|
261
|
+
entries: [...earlier.filter((e) => !written.has(e.path)), ...ownershipEntries],
|
|
262
|
+
};
|
|
263
|
+
await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n', 'utf8');
|
|
264
|
+
|
|
265
|
+
const result = {
|
|
266
|
+
installed: true,
|
|
267
|
+
profile: installProfile,
|
|
268
|
+
stack: stackInfo,
|
|
269
|
+
writtenFiles,
|
|
270
|
+
skippedFiles,
|
|
271
|
+
plugins: pluginResults,
|
|
272
|
+
ownershipManifest: '.ai-kit/ownership-manifest.json',
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// A plugin that is not linked (conflict, incomplete, not found) means the
|
|
276
|
+
// guards the profile promised are not active: that is not a success.
|
|
277
|
+
const problems = pluginResults.filter(
|
|
278
|
+
(pr) => pr.status !== 'linked' && pr.status !== 'already-linked',
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
if (isJson) {
|
|
282
|
+
ctx.stdout(JSON.stringify({ ...result, installed: problems.length === 0 }, null, 2) + '\n');
|
|
283
|
+
} else {
|
|
284
|
+
ctx.stdout(formatResult({ ...result, installed: problems.length === 0 }));
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return { exitCode: problems.length === 0 ? 0 : 1 };
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
interface DryRunPlan {
|
|
292
|
+
profile: string;
|
|
293
|
+
stack: string;
|
|
294
|
+
dryRun: boolean;
|
|
295
|
+
plugins: string[];
|
|
296
|
+
operations: Array<{ path: string; kind: string; sha256: string }>;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function formatDryRun(plan: DryRunPlan): string {
|
|
300
|
+
const lines: string[] = [
|
|
301
|
+
'kit install --dry-run',
|
|
302
|
+
` Profile: ${plan.profile}`,
|
|
303
|
+
` Stack: ${plan.stack}`,
|
|
304
|
+
'',
|
|
305
|
+
'Planned operations:',
|
|
306
|
+
];
|
|
307
|
+
for (const op of plan.operations) {
|
|
308
|
+
lines.push(` ${op.kind.padEnd(20)} ${op.path}`);
|
|
309
|
+
}
|
|
310
|
+
if (plan.plugins.length > 0) {
|
|
311
|
+
lines.push(` link${' '.repeat(17)}.claude/plugins/ (${plan.plugins.join(', ')})`);
|
|
312
|
+
}
|
|
313
|
+
lines.push('');
|
|
314
|
+
lines.push(`${plan.operations.length} operation(s) planned. Run without --dry-run to execute.`);
|
|
315
|
+
lines.push('');
|
|
316
|
+
return lines.join('\n');
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
interface InstallResult {
|
|
320
|
+
installed: boolean;
|
|
321
|
+
profile: string;
|
|
322
|
+
stack: string;
|
|
323
|
+
writtenFiles: string[];
|
|
324
|
+
skippedFiles: string[];
|
|
325
|
+
plugins: PluginLinkResult[];
|
|
326
|
+
ownershipManifest: string;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function formatResult(r: InstallResult): string {
|
|
330
|
+
const lines: string[] = [
|
|
331
|
+
r.installed ? 'kit install: SUCCESS' : 'kit install: COMPLETED WITH PROBLEMS (see plugin status below)',
|
|
332
|
+
` Profile: ${r.profile}`,
|
|
333
|
+
` Stack: ${r.stack}`,
|
|
334
|
+
` Written: ${r.writtenFiles.length} file(s)`,
|
|
335
|
+
];
|
|
336
|
+
for (const f of r.writtenFiles) {
|
|
337
|
+
lines.push(` + ${f}`);
|
|
338
|
+
}
|
|
339
|
+
if (r.skippedFiles.length > 0) {
|
|
340
|
+
lines.push(` Skipped: ${r.skippedFiles.length} existing file(s)`);
|
|
341
|
+
for (const f of r.skippedFiles) {
|
|
342
|
+
lines.push(` ~ ${f}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (r.plugins.length > 0) {
|
|
346
|
+
lines.push(` Plugins: ${r.plugins.length} runtime plugin(s)`);
|
|
347
|
+
for (const p of r.plugins) {
|
|
348
|
+
if (p.status === 'linked') {
|
|
349
|
+
lines.push(` + ${p.name} -> ${p.linkPath}`);
|
|
350
|
+
} else if (p.status === 'already-linked') {
|
|
351
|
+
lines.push(` ~ ${p.name} (already linked)`);
|
|
352
|
+
} else {
|
|
353
|
+
// incomplete / not-found: a plugin the profile promised but could
|
|
354
|
+
// not deliver. Report loudly; never claim it is installed.
|
|
355
|
+
lines.push(` ! ${p.name}: ${p.status} — ${p.detail ?? ''}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
lines.push(` Ownership: ${r.ownershipManifest}`);
|
|
360
|
+
lines.push('');
|
|
361
|
+
return lines.join('\n');
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function formatHelp(): string {
|
|
365
|
+
return [
|
|
366
|
+
'Usage: kit install [--profile <profile>] [--stack <stack>] [--dry-run] [--json]',
|
|
367
|
+
'',
|
|
368
|
+
'Install and configure kit environment, instructions, commands, and stack packs.',
|
|
369
|
+
'',
|
|
370
|
+
'Profiles:',
|
|
371
|
+
' minimal Core instructions and essential skills only (no plugins)',
|
|
372
|
+
' full-sdlc Complete workflows, templates, and the runtime guard plugins (default)',
|
|
373
|
+
' runtime Runtime governance, secret protection, and model routing plugins',
|
|
374
|
+
'',
|
|
375
|
+
'The full-sdlc and runtime profiles link the four guard plugins',
|
|
376
|
+
'(sdlc-guard, secret-guard, model-router, run-observer) into',
|
|
377
|
+
'.claude/plugins/. They are Claude Code Mods: Claude Code loads each',
|
|
378
|
+
'plugin\'s TypeScript hooks module (hooks/register.ts) directly, so they',
|
|
379
|
+
'work from a fresh clone with no build step (Claude Code v2.1.287+).',
|
|
380
|
+
'',
|
|
381
|
+
'Options:',
|
|
382
|
+
' --stack <id> Stack pack to activate (e.g. node-typescript, ruby-rails)',
|
|
383
|
+
' --dir <path> Project directory to install into (default: current directory)',
|
|
384
|
+
' --dry-run Preview planned operations without writing files',
|
|
385
|
+
' --json Output machine-readable installation status',
|
|
386
|
+
' --help Show this message',
|
|
387
|
+
'',
|
|
388
|
+
].join('\n');
|
|
389
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// packages/cli/src/commands/journal.ts
|
|
2
|
+
//
|
|
3
|
+
// `kit journal <feature-id> [--verify] [--json] [--limit N]`
|
|
4
|
+
//
|
|
5
|
+
// Read and verify the hash-chained execution journal (ADR-0021 §3),
|
|
6
|
+
// persisted at .ai-kit/journal/feature-runs/<featureId>.jsonl.
|
|
7
|
+
//
|
|
8
|
+
// The journal is the EXECUTED record — what happened, in order, with a
|
|
9
|
+
// tamper-evident hash chain. The run state remains the authority for
|
|
10
|
+
// phase advancement; this command observes, it never decides.
|
|
11
|
+
//
|
|
12
|
+
// Honest limits: --verify detects modification, insertion, and
|
|
13
|
+
// reordering. Tail truncation is NOT detectable from the journal alone
|
|
14
|
+
// (ADR-0021 §3.4); the verification output includes the last verified
|
|
15
|
+
// hash so it can be anchored externally.
|
|
16
|
+
|
|
17
|
+
import path from 'node:path';
|
|
18
|
+
import { readJournal, verifyJournal } from '@agentic-sdlc-kit/core';
|
|
19
|
+
import type { JournalEvent } from '@agentic-sdlc-kit/contracts';
|
|
20
|
+
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
21
|
+
|
|
22
|
+
const DEFAULT_HUMAN_LIMIT = 50;
|
|
23
|
+
|
|
24
|
+
function fail(ctx: CommandContext, message: string): CommandResult {
|
|
25
|
+
ctx.stderr(`kit journal: ${message}\n`);
|
|
26
|
+
return { exitCode: 1, message };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const journalCommand: Command = {
|
|
30
|
+
name: 'journal',
|
|
31
|
+
summary: 'Read or verify the hash-chained execution journal for a feature run (ADR-0021).',
|
|
32
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
33
|
+
if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
|
|
34
|
+
ctx.stdout(formatHelp());
|
|
35
|
+
return { exitCode: 0 };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isJson = ctx.argv.includes('--json');
|
|
39
|
+
const verify = ctx.argv.includes('--verify');
|
|
40
|
+
const positional = ctx.argv.filter((a) => !a.startsWith('-'));
|
|
41
|
+
const featureId = positional[0];
|
|
42
|
+
if (!featureId) {
|
|
43
|
+
return fail(ctx, 'missing required feature identifier (e.g. FEATURE-001)');
|
|
44
|
+
}
|
|
45
|
+
const root = path.resolve(ctx.cwd, '.');
|
|
46
|
+
|
|
47
|
+
if (verify) {
|
|
48
|
+
const res = await verifyJournal(root, featureId);
|
|
49
|
+
if (!res.ok) return fail(ctx, res.error.message);
|
|
50
|
+
if (isJson) {
|
|
51
|
+
ctx.stdout(JSON.stringify({ featureId, valid: true, ...res.value }, null, 2) + '\n');
|
|
52
|
+
} else {
|
|
53
|
+
const hash = res.value.lastHash ? ` (last hash ${res.value.lastHash.slice(0, 12)}…)` : '';
|
|
54
|
+
ctx.stdout(`Journal verified for ${featureId}: ${res.value.eventCount} event(s)${hash}\n`);
|
|
55
|
+
}
|
|
56
|
+
return { exitCode: 0 };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const res = await readJournal(root, featureId);
|
|
60
|
+
if (!res.ok) return fail(ctx, res.error.message);
|
|
61
|
+
const events = res.value;
|
|
62
|
+
|
|
63
|
+
if (isJson) {
|
|
64
|
+
ctx.stdout(JSON.stringify(events, null, 2) + '\n');
|
|
65
|
+
return { exitCode: 0 };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const limitIdx = ctx.argv.indexOf('--limit');
|
|
69
|
+
const limitArg = limitIdx >= 0 ? ctx.argv[limitIdx + 1] : undefined;
|
|
70
|
+
const limit =
|
|
71
|
+
limitArg && Number.isInteger(Number(limitArg)) && Number(limitArg) > 0
|
|
72
|
+
? Number(limitArg)
|
|
73
|
+
: DEFAULT_HUMAN_LIMIT;
|
|
74
|
+
const shown = events.slice(-limit);
|
|
75
|
+
if (shown.length < events.length) {
|
|
76
|
+
ctx.stdout(`… ${events.length - shown.length} earlier event(s) hidden (use --limit) …\n`);
|
|
77
|
+
}
|
|
78
|
+
for (const event of shown) {
|
|
79
|
+
ctx.stdout(formatEvent(event));
|
|
80
|
+
}
|
|
81
|
+
if (events.length === 0) {
|
|
82
|
+
ctx.stdout(`Journal for ${featureId} is empty.\n`);
|
|
83
|
+
}
|
|
84
|
+
return { exitCode: 0 };
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
function formatEvent(event: JournalEvent): string {
|
|
89
|
+
const actor =
|
|
90
|
+
event.actor.host !== undefined ? `${event.actor.kind}:${event.actor.host}` : event.actor.kind;
|
|
91
|
+
const task = event.taskId !== undefined ? ` ${event.taskId}` : '';
|
|
92
|
+
const detail = Object.entries(event.payload)
|
|
93
|
+
.filter(([, v]) => v !== null && v !== undefined)
|
|
94
|
+
.map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`)
|
|
95
|
+
.join(' ');
|
|
96
|
+
return `[${event.seq}] ${event.ts} ${event.kind}${task} (${actor})${detail ? ` ${detail}` : ''}\n`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function formatHelp(): string {
|
|
100
|
+
return [
|
|
101
|
+
'Usage: kit journal <feature-id> [--verify] [--json] [--limit N]',
|
|
102
|
+
'',
|
|
103
|
+
'Read or verify the hash-chained execution journal for a feature run:',
|
|
104
|
+
'every workflow event, in order, with a tamper-evident hash chain',
|
|
105
|
+
'(ADR-0021). The journal observes; it never decides.',
|
|
106
|
+
'',
|
|
107
|
+
'Options:',
|
|
108
|
+
' --verify verify the chain (seq continuity + hash linkage + digests)',
|
|
109
|
+
' --json machine-readable events (or verification result)',
|
|
110
|
+
' --limit N list only the last N events (default 50, human output only)',
|
|
111
|
+
' --help Show this message',
|
|
112
|
+
'',
|
|
113
|
+
'Exit codes:',
|
|
114
|
+
' 0 listed or verified',
|
|
115
|
+
' 1 error: journal missing, unreadable, or (with --verify) chain violated',
|
|
116
|
+
'',
|
|
117
|
+
].join('\n');
|
|
118
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// packages/cli/src/commands/memory.ts
|
|
2
|
+
//
|
|
3
|
+
// `kit memory [query] [--domain <domain>] [--list] [--json]`.
|
|
4
|
+
// Inspects and queries hierarchical episodic, semantic, and procedural memories (M29).
|
|
5
|
+
//
|
|
6
|
+
// Reads from persisted memory at .ai-kit/state/memory.json.
|
|
7
|
+
// If no persisted memory exists, reports honestly that no memories have been
|
|
8
|
+
// accumulated yet (rather than seeding fake demo data).
|
|
9
|
+
|
|
10
|
+
import { MemoryStore } from '@agentic-sdlc-kit/core';
|
|
11
|
+
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
12
|
+
|
|
13
|
+
export const memoryCommand: Command = {
|
|
14
|
+
name: 'memory',
|
|
15
|
+
summary: 'Query hierarchical episodic, semantic, and procedural engineering memories (M29).',
|
|
16
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
17
|
+
if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
|
|
18
|
+
ctx.stdout(formatHelp());
|
|
19
|
+
return { exitCode: 0 };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isJson = ctx.argv.includes('--json');
|
|
23
|
+
const isList = ctx.argv.includes('--list') || ctx.argv.includes('-l');
|
|
24
|
+
const domainIdx = ctx.argv.indexOf('--domain');
|
|
25
|
+
const domain = domainIdx !== -1 ? ctx.argv[domainIdx + 1] : undefined;
|
|
26
|
+
const query = ctx.argv.find((a) => !a.startsWith('-') && a !== '--list' && a !== '-l') ?? '';
|
|
27
|
+
|
|
28
|
+
const store = new MemoryStore();
|
|
29
|
+
|
|
30
|
+
// Load persisted memory from .ai-kit/state/memory.json.
|
|
31
|
+
// This file is written by `kit evolve` and by workflow runs that
|
|
32
|
+
// produce distilled lessons.
|
|
33
|
+
const loaded = await store.loadFromDisk(ctx.cwd);
|
|
34
|
+
|
|
35
|
+
if (loaded === 0) {
|
|
36
|
+
const msg =
|
|
37
|
+
'kit memory: no memory entries found at .ai-kit/state/memory.json.\n' +
|
|
38
|
+
'Run `kit evolve` to distill lessons from accumulated experiences, or\n' +
|
|
39
|
+
'run workflows (`kit feature`) to produce experience records that\n' +
|
|
40
|
+
'the evolution engine can learn from.\n';
|
|
41
|
+
if (isJson) {
|
|
42
|
+
ctx.stdout(JSON.stringify({ entries: [], message: msg.trim() }) + '\n');
|
|
43
|
+
} else {
|
|
44
|
+
ctx.stdout(msg);
|
|
45
|
+
}
|
|
46
|
+
return { exitCode: 0 };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// If --list, show all entries (optionally filtered by domain).
|
|
50
|
+
// Otherwise, search by query.
|
|
51
|
+
const results = isList
|
|
52
|
+
? store.list().filter((e) => !domain || e.domain === domain)
|
|
53
|
+
: store.search(query, domain);
|
|
54
|
+
|
|
55
|
+
if (isJson) {
|
|
56
|
+
ctx.stdout(JSON.stringify(results, null, 2) + '\n');
|
|
57
|
+
} else {
|
|
58
|
+
ctx.stdout(formatResults(results));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { exitCode: 0 };
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
function formatResults(results: ReturnType<MemoryStore['list']>): string {
|
|
66
|
+
if (results.length === 0) return 'No matching engineering memories found.\n';
|
|
67
|
+
const lines: string[] = [`Found ${results.length} memory entries:`];
|
|
68
|
+
for (const r of results) {
|
|
69
|
+
lines.push(
|
|
70
|
+
` [${r.type.toUpperCase()}] ${r.id} (${r.domain}) - conf: ${(r.confidence * 100).toFixed(0)}%`,
|
|
71
|
+
);
|
|
72
|
+
lines.push(` ${r.summary}`);
|
|
73
|
+
lines.push(` ${r.content}`);
|
|
74
|
+
if (r.appliedCount > 0) {
|
|
75
|
+
lines.push(` applied: ${r.appliedCount}x, success: ${r.successCount}x`);
|
|
76
|
+
}
|
|
77
|
+
lines.push('');
|
|
78
|
+
}
|
|
79
|
+
return lines.join('\n');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function formatHelp(): string {
|
|
83
|
+
return [
|
|
84
|
+
'Usage: kit memory [query] [--domain <domain>] [--list] [--json]',
|
|
85
|
+
'',
|
|
86
|
+
'Search accumulated hierarchical engineering memories (episodic, semantic, procedural).',
|
|
87
|
+
'Reads from .ai-kit/state/memory.json (produced by `kit evolve`).',
|
|
88
|
+
'',
|
|
89
|
+
'Options:',
|
|
90
|
+
' --domain <name> Filter by domain (e.g. architecture, tdd, security)',
|
|
91
|
+
' --list, -l List all entries (ignores query argument)',
|
|
92
|
+
' --json Output machine-readable memory entries',
|
|
93
|
+
' --help Show this message',
|
|
94
|
+
'',
|
|
95
|
+
].join('\n');
|
|
96
|
+
}
|