@agentic-sdlc-kit/cli 0.8.0 → 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/dist/application/agent/execution-store.d.ts.map +1 -1
- package/dist/application/agent/execution-store.js +2 -1
- package/dist/application/agent/execution-store.js.map +1 -1
- package/dist/application/agent/orchestrator.d.ts.map +1 -1
- package/dist/application/agent/orchestrator.js +2 -2
- package/dist/application/agent/orchestrator.js.map +1 -1
- package/dist/application/dispatcher.d.ts.map +1 -1
- package/dist/application/dispatcher.js +12 -0
- package/dist/application/dispatcher.js.map +1 -1
- package/dist/application/version.d.ts +1 -1
- package/dist/application/version.js +1 -1
- 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/fix.d.ts +1 -0
- package/dist/commands/fix.d.ts.map +1 -1
- package/dist/commands/fix.js +42 -50
- package/dist/commands/fix.js.map +1 -1
- 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 +4 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +4 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +5 -3
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +15 -7
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/plugin-linker.d.ts +10 -1
- package/dist/commands/plugin-linker.d.ts.map +1 -1
- package/dist/commands/plugin-linker.js +53 -14
- package/dist/commands/plugin-linker.js.map +1 -1
- 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/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/package.json +4 -4
- package/src/application/agent/execution-store.ts +2 -1
- package/src/application/agent/orchestrator.ts +2 -1
- package/src/application/dispatcher.test.ts +22 -3
- package/src/application/dispatcher.ts +8 -0
- package/src/application/version.ts +1 -1
- 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/doctor.test.ts +1 -1
- package/src/commands/fix.test.ts +95 -13
- package/src/commands/fix.ts +44 -55
- 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 +4 -0
- package/src/commands/init.test.ts +22 -0
- package/src/commands/init.ts +10 -3
- package/src/commands/install.test.ts +31 -0
- package/src/commands/install.ts +21 -7
- package/src/commands/plugin-linker.test.ts +80 -0
- package/src/commands/plugin-linker.ts +62 -14
- 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/uninstall.test.ts +122 -0
- package/src/commands/uninstall.ts +116 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// packages/cli/src/commands/attach.test.ts
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { promises as fs } from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
7
|
+
import { attachCommand } from './attach.js';
|
|
8
|
+
import { BLOCK_BEGIN, stripBlock, withBlock } from './attach-exclude.js';
|
|
9
|
+
import type { CommandContext } from './types.js';
|
|
10
|
+
|
|
11
|
+
const git = (cwd: string, ...args: string[]): string =>
|
|
12
|
+
execFileSync('git', args, { cwd, encoding: 'utf8' });
|
|
13
|
+
|
|
14
|
+
async function mkrepo(dir: string, files: Record<string, string> = { 'README.md': 'hi' }) {
|
|
15
|
+
await fs.mkdir(dir, { recursive: true });
|
|
16
|
+
git(dir, 'init', '-q');
|
|
17
|
+
git(dir, 'config', 'user.email', 't@t');
|
|
18
|
+
git(dir, 'config', 'user.name', 't');
|
|
19
|
+
for (const [rel, body] of Object.entries(files)) {
|
|
20
|
+
await fs.mkdir(path.dirname(path.join(dir, rel)), { recursive: true });
|
|
21
|
+
await fs.writeFile(path.join(dir, rel), body);
|
|
22
|
+
}
|
|
23
|
+
git(dir, 'add', '-A');
|
|
24
|
+
git(dir, 'commit', '-qm', 'init');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const run = async (cwd: string, ...argv: string[]) => {
|
|
28
|
+
const out: string[] = [];
|
|
29
|
+
const err: string[] = [];
|
|
30
|
+
const ctx: CommandContext = {
|
|
31
|
+
argv,
|
|
32
|
+
cwd,
|
|
33
|
+
stdout: (s) => void out.push(s),
|
|
34
|
+
stderr: (s) => void err.push(s),
|
|
35
|
+
};
|
|
36
|
+
const r = await attachCommand.run(ctx);
|
|
37
|
+
return { ...r, out: out.join('\n'), err: err.join('\n') };
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const clean = (dir: string): boolean => git(dir, 'status', '--porcelain').trim() === '';
|
|
41
|
+
const exists = (p: string) => fs.lstat(p).then(() => true, () => false);
|
|
42
|
+
|
|
43
|
+
let tmp: string;
|
|
44
|
+
let store: string;
|
|
45
|
+
beforeEach(async () => {
|
|
46
|
+
tmp = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'kit-attach-')));
|
|
47
|
+
store = path.join(tmp, 'store');
|
|
48
|
+
process.env['KIT_ATTACH_HOME'] = store;
|
|
49
|
+
});
|
|
50
|
+
afterEach(async () => {
|
|
51
|
+
delete process.env['KIT_ATTACH_HOME'];
|
|
52
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('attach exclude block (pure)', () => {
|
|
56
|
+
it('is idempotent and preserves foreign lines', () => {
|
|
57
|
+
const once = withBlock('node_modules\n', ['a', 'b']);
|
|
58
|
+
expect(withBlock(once, ['a', 'b'])).toBe(once);
|
|
59
|
+
expect(stripBlock(once)).toBe('node_modules\n');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('kit attach', () => {
|
|
64
|
+
it('local: invisible to git, writes work, idempotent', async () => {
|
|
65
|
+
const repo = path.join(tmp, 'a');
|
|
66
|
+
await mkrepo(repo);
|
|
67
|
+
const r = await run(repo, 'local');
|
|
68
|
+
expect(r.exitCode).toBe(0);
|
|
69
|
+
await fs.writeFile(path.join(repo, '.ai-kit', 'project.yml'), 'x');
|
|
70
|
+
expect(clean(repo)).toBe(true);
|
|
71
|
+
expect((await run(repo, 'local')).exitCode).toBe(0);
|
|
72
|
+
const ex = await fs.readFile(path.join(repo, '.git', 'info', 'exclude'), 'utf8');
|
|
73
|
+
expect(ex.split(BLOCK_BEGIN).length - 1).toBe(1);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('global: symlink is ignored and bytes land in the store', async () => {
|
|
77
|
+
const repo = path.join(tmp, 'b');
|
|
78
|
+
await mkrepo(repo);
|
|
79
|
+
expect((await run(repo, 'global')).exitCode).toBe(0);
|
|
80
|
+
await fs.writeFile(path.join(repo, '.ai-kit', 'project.yml'), 'x');
|
|
81
|
+
expect((await fs.lstat(path.join(repo, '.ai-kit'))).isSymbolicLink()).toBe(true);
|
|
82
|
+
expect(clean(repo)).toBe(true);
|
|
83
|
+
const target = await fs.readlink(path.join(repo, '.ai-kit'));
|
|
84
|
+
expect(target.startsWith(store)).toBe(true);
|
|
85
|
+
expect(await fs.readFile(path.join(target, 'project.yml'), 'utf8')).toBe('x');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('refuses when a managed path has tracked files, changing nothing', async () => {
|
|
89
|
+
const repo = path.join(tmp, 'c');
|
|
90
|
+
await mkrepo(repo, { 'README.md': 'hi', 'docs/plans/keep.md': 'k' });
|
|
91
|
+
for (const mode of ['local', 'global']) {
|
|
92
|
+
const r = await run(repo, mode);
|
|
93
|
+
expect(r.exitCode).toBe(1);
|
|
94
|
+
expect(r.err).toContain('tracked files');
|
|
95
|
+
}
|
|
96
|
+
expect(await exists(path.join(repo, '.ai-kit'))).toBe(false);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('global without --adopt refuses untracked content and is atomic', async () => {
|
|
100
|
+
const repo = path.join(tmp, 'd1');
|
|
101
|
+
await mkrepo(repo);
|
|
102
|
+
await fs.mkdir(path.join(repo, 'docs/plans'), { recursive: true });
|
|
103
|
+
await fs.writeFile(path.join(repo, 'docs/plans/old.md'), 'old');
|
|
104
|
+
const r = await run(repo, 'global');
|
|
105
|
+
expect(r.exitCode).toBe(1);
|
|
106
|
+
expect(r.err).toContain('--adopt');
|
|
107
|
+
expect(await exists(path.join(repo, '.ai-kit'))).toBe(false); // no half-attach
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('global --adopt migrates untracked content into the store', async () => {
|
|
111
|
+
const repo = path.join(tmp, 'd2');
|
|
112
|
+
await mkrepo(repo);
|
|
113
|
+
await fs.mkdir(path.join(repo, 'docs/plans'), { recursive: true });
|
|
114
|
+
await fs.writeFile(path.join(repo, 'docs/plans/old.md'), 'old');
|
|
115
|
+
expect((await run(repo, 'global', '--adopt')).exitCode).toBe(0);
|
|
116
|
+
expect(await fs.readFile(path.join(repo, 'docs/plans/old.md'), 'utf8')).toBe('old');
|
|
117
|
+
expect((await fs.lstat(path.join(repo, 'docs/plans'))).isSymbolicLink()).toBe(true);
|
|
118
|
+
expect(clean(repo)).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('--adopt is rejected for local', async () => {
|
|
122
|
+
const repo = path.join(tmp, 'e1');
|
|
123
|
+
await mkrepo(repo);
|
|
124
|
+
const r = await run(repo, 'local', '--adopt');
|
|
125
|
+
expect(r.exitCode).toBe(1);
|
|
126
|
+
expect(r.err).toContain("only valid with 'global'");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('local refuses to run over a global symlink', async () => {
|
|
130
|
+
const repo = path.join(tmp, 'e2');
|
|
131
|
+
await mkrepo(repo);
|
|
132
|
+
await run(repo, 'global');
|
|
133
|
+
const r = await run(repo, 'local');
|
|
134
|
+
expect(r.exitCode).toBe(1);
|
|
135
|
+
expect(r.err).toContain('detach');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('detach removes symlinks and exclusion but keeps store data', async () => {
|
|
139
|
+
const repo = path.join(tmp, 'f');
|
|
140
|
+
await mkrepo(repo);
|
|
141
|
+
await run(repo, 'global');
|
|
142
|
+
await fs.writeFile(path.join(repo, '.ai-kit', 'project.yml'), 'x');
|
|
143
|
+
const target = await fs.readlink(path.join(repo, '.ai-kit'));
|
|
144
|
+
expect((await run(repo, 'detach')).exitCode).toBe(0);
|
|
145
|
+
expect(await exists(path.join(repo, '.ai-kit'))).toBe(false);
|
|
146
|
+
expect(await fs.readFile(path.join(target, 'project.yml'), 'utf8')).toBe('x');
|
|
147
|
+
const ex = await fs.readFile(path.join(repo, '.git', 'info', 'exclude'), 'utf8');
|
|
148
|
+
expect(ex).not.toContain(BLOCK_BEGIN);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('detach leaves symlinks that point outside the store alone', async () => {
|
|
152
|
+
const repo = path.join(tmp, 'g');
|
|
153
|
+
await mkrepo(repo);
|
|
154
|
+
const foreign = path.join(tmp, 'foreign');
|
|
155
|
+
await fs.mkdir(foreign);
|
|
156
|
+
await fs.symlink(foreign, path.join(repo, '.ai-kit'), 'dir');
|
|
157
|
+
await run(repo, 'detach');
|
|
158
|
+
expect((await fs.lstat(path.join(repo, '.ai-kit'))).isSymbolicLink()).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('linked worktree: exclude lives in the common git dir', async () => {
|
|
162
|
+
const repo = path.join(tmp, 'h');
|
|
163
|
+
await mkrepo(repo);
|
|
164
|
+
const wt = path.join(tmp, 'h-wt');
|
|
165
|
+
git(repo, 'worktree', 'add', '-q', wt, '-b', 'wt');
|
|
166
|
+
expect((await run(wt, 'local')).exitCode).toBe(0);
|
|
167
|
+
expect(await fs.readFile(path.join(repo, '.git', 'info', 'exclude'), 'utf8')).toContain(BLOCK_BEGIN);
|
|
168
|
+
expect(clean(wt)).toBe(true);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('status reports mode and invisibility; fails closed when not attached', async () => {
|
|
172
|
+
const repo = path.join(tmp, 'i');
|
|
173
|
+
await mkrepo(repo);
|
|
174
|
+
await fs.mkdir(path.join(repo, '.ai-kit'));
|
|
175
|
+
await fs.writeFile(path.join(repo, '.ai-kit', 'x'), 'x');
|
|
176
|
+
const before = await run(repo, 'status');
|
|
177
|
+
expect(before.exitCode).toBe(1); // leaking
|
|
178
|
+
await run(repo, 'local');
|
|
179
|
+
const after = await run(repo, 'status');
|
|
180
|
+
expect(after.exitCode).toBe(0);
|
|
181
|
+
expect(after.out).toContain('exclude block: present');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('errors outside a git repo and on unknown subcommand', async () => {
|
|
185
|
+
const plain = path.join(tmp, 'plain');
|
|
186
|
+
await fs.mkdir(plain);
|
|
187
|
+
expect((await run(plain, 'local')).err).toContain('not inside a git repository');
|
|
188
|
+
expect((await run(plain, 'bogus')).exitCode).toBe(1);
|
|
189
|
+
expect((await run(plain)).exitCode).toBe(1);
|
|
190
|
+
expect((await run(plain, '--help')).exitCode).toBe(0);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// packages/cli/src/commands/attach.ts
|
|
2
|
+
//
|
|
3
|
+
// `kit attach <local|global|status|detach> [--adopt]`
|
|
4
|
+
//
|
|
5
|
+
// Provisions the kit's working paths (.ai-kit, .claude, docs/specifications,
|
|
6
|
+
// docs/plans) WITHOUT touching tracked files, and proves git-invisibility
|
|
7
|
+
// before reporting success (fail closed).
|
|
8
|
+
// local real directories, hidden via .git/info/exclude
|
|
9
|
+
// global symlinks into $KIT_ATTACH_HOME/<repo>-<hash>/ (default
|
|
10
|
+
// ~/.agentic-sdlc/projects)
|
|
11
|
+
//
|
|
12
|
+
// Mode 1 (`kit feature <id> run`) needs committed artifacts and therefore
|
|
13
|
+
// cannot be used while attached; Mode 2 / `kit next` is unaffected.
|
|
14
|
+
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import {
|
|
17
|
+
hasTrackedFiles,
|
|
18
|
+
isIgnored,
|
|
19
|
+
resolveRepo,
|
|
20
|
+
statusLeaks,
|
|
21
|
+
type RepoInfo,
|
|
22
|
+
} from './attach-git.js';
|
|
23
|
+
import { hasBlock, removeBlock, writeBlock } from './attach-exclude.js';
|
|
24
|
+
import {
|
|
25
|
+
AttachError,
|
|
26
|
+
MANAGED_PATHS,
|
|
27
|
+
attachGlobal,
|
|
28
|
+
attachLocal,
|
|
29
|
+
describePath,
|
|
30
|
+
detachLinks,
|
|
31
|
+
storeBase,
|
|
32
|
+
storeDirFor,
|
|
33
|
+
} from './attach-store.js';
|
|
34
|
+
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
35
|
+
|
|
36
|
+
const USAGE = [
|
|
37
|
+
'Usage: kit attach <local|global|status|detach> [--adopt]',
|
|
38
|
+
' local real dirs in the repo, hidden via .git/info/exclude',
|
|
39
|
+
' global symlinks into $KIT_ATTACH_HOME/<repo>-<hash>/',
|
|
40
|
+
' status show mode per path and prove git invisibility',
|
|
41
|
+
' detach remove exclude block; remove global symlinks (store data kept)',
|
|
42
|
+
' --adopt global only: migrate existing UNTRACKED content into the store',
|
|
43
|
+
].join('\n');
|
|
44
|
+
|
|
45
|
+
const excludeFile = (repo: RepoInfo): string => path.join(repo.commonDir, 'info', 'exclude');
|
|
46
|
+
|
|
47
|
+
/** Returns report lines; `leaked` is true when any managed path is visible to git. */
|
|
48
|
+
export function verifyInvisible(root: string): { lines: string[]; leaked: boolean } {
|
|
49
|
+
const lines: string[] = [];
|
|
50
|
+
let leaked = false;
|
|
51
|
+
for (const rel of MANAGED_PATHS) {
|
|
52
|
+
const ignored = isIgnored(root, rel);
|
|
53
|
+
lines.push(` ${ignored ? 'ignored: ' : 'NOT IGNORED:'} ${rel}`);
|
|
54
|
+
if (!ignored) leaked = true;
|
|
55
|
+
}
|
|
56
|
+
const leaks = statusLeaks(root, MANAGED_PATHS);
|
|
57
|
+
for (const l of leaks) lines.push(` git status LEAK: ${l}`);
|
|
58
|
+
return { lines, leaked: leaked || leaks.length > 0 };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function assertUntracked(root: string): void {
|
|
62
|
+
for (const rel of MANAGED_PATHS) {
|
|
63
|
+
if (hasTrackedFiles(root, rel)) {
|
|
64
|
+
throw new AttachError(
|
|
65
|
+
`REFUSED: '${rel}' contains tracked files. Untrack first (git rm -r --cached '${rel}').`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function proof(root: string, header: string): CommandResult & { text: string } {
|
|
72
|
+
const v = verifyInvisible(root);
|
|
73
|
+
if (v.leaked) {
|
|
74
|
+
const text = [...v.lines, 'verification failed: managed paths are visible to git'].join('\n');
|
|
75
|
+
return { exitCode: 1, text };
|
|
76
|
+
}
|
|
77
|
+
return { exitCode: 0, text: [header, ...v.lines, ' git status: clean for all managed paths.'].join('\n') };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function runMode(mode: 'local' | 'global', repo: RepoInfo, adopt: boolean): Promise<string> {
|
|
81
|
+
assertUntracked(repo.root);
|
|
82
|
+
const store = storeDirFor(repo.root);
|
|
83
|
+
if (mode === 'local') await attachLocal(repo.root);
|
|
84
|
+
else await attachGlobal(repo.root, store, adopt);
|
|
85
|
+
await writeBlock(excludeFile(repo), MANAGED_PATHS);
|
|
86
|
+
return mode === 'local' ? `Attached (local). Exclude: ${excludeFile(repo)}` : `Attached (global). Store: ${store}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function runStatus(repo: RepoInfo): Promise<CommandResult & { text: string }> {
|
|
90
|
+
const lines = [`repo: ${repo.root}`, `store: ${storeDirFor(repo.root)}`];
|
|
91
|
+
for (const rel of MANAGED_PATHS) lines.push(` ${await describePath(repo.root, rel)}`);
|
|
92
|
+
const present = await hasBlock(excludeFile(repo));
|
|
93
|
+
lines.push(`exclude block: ${present ? 'present' : 'absent'}`);
|
|
94
|
+
const v = verifyInvisible(repo.root);
|
|
95
|
+
lines.push(...v.lines);
|
|
96
|
+
return { exitCode: v.leaked ? 1 : 0, text: lines.join('\n') };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function runDetach(repo: RepoInfo): Promise<string> {
|
|
100
|
+
await removeBlock(excludeFile(repo));
|
|
101
|
+
const removed = await detachLinks(repo.root, storeBase(storeDirFor(repo.root)));
|
|
102
|
+
const lines = removed.map((r) => ` removed symlink: ${r} (data kept in store)`);
|
|
103
|
+
lines.push('Detached. Local directories (if any) left untouched.');
|
|
104
|
+
return lines.join('\n');
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function execute(sub: string, repo: RepoInfo, adopt: boolean): Promise<CommandResult & { text: string }> {
|
|
108
|
+
if (sub === 'status') return runStatus(repo);
|
|
109
|
+
if (sub === 'detach') return { exitCode: 0, text: await runDetach(repo) };
|
|
110
|
+
if (adopt && sub !== 'global') throw new AttachError("--adopt is only valid with 'global'");
|
|
111
|
+
const header = await runMode(sub as 'local' | 'global', repo, adopt);
|
|
112
|
+
return proof(repo.root, header);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export const attachCommand: Command = {
|
|
116
|
+
name: 'attach',
|
|
117
|
+
summary: 'Attach kit working paths to a repo without tracking them (local|global).',
|
|
118
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
119
|
+
const positional = ctx.argv.filter((a) => !a.startsWith('-'));
|
|
120
|
+
const sub = positional[0];
|
|
121
|
+
if (ctx.argv.includes('--help') || !sub) {
|
|
122
|
+
ctx.stdout(USAGE);
|
|
123
|
+
return { exitCode: sub || ctx.argv.includes('--help') ? 0 : 1 };
|
|
124
|
+
}
|
|
125
|
+
if (!['local', 'global', 'status', 'detach'].includes(sub)) {
|
|
126
|
+
ctx.stderr(`kit attach: unknown subcommand '${sub}'\n${USAGE}`);
|
|
127
|
+
return { exitCode: 1 };
|
|
128
|
+
}
|
|
129
|
+
const repo = resolveRepo(ctx.cwd);
|
|
130
|
+
if (!repo) {
|
|
131
|
+
ctx.stderr('kit attach: not inside a git repository');
|
|
132
|
+
return { exitCode: 1 };
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
const r = await execute(sub, repo, ctx.argv.includes('--adopt'));
|
|
136
|
+
(r.exitCode === 0 ? ctx.stdout : ctx.stderr)(r.text);
|
|
137
|
+
return { exitCode: r.exitCode };
|
|
138
|
+
} catch (e) {
|
|
139
|
+
ctx.stderr(`kit attach: ${e instanceof Error ? e.message : String(e)}`);
|
|
140
|
+
return { exitCode: 1 };
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
};
|
|
@@ -20,7 +20,7 @@ describe('doctorCommand', () => {
|
|
|
20
20
|
const r = await doctorCommand.run(ctx);
|
|
21
21
|
expect(r.exitCode).toBeLessThanOrEqual(2); // 0 if healthy, 2 if not
|
|
22
22
|
const text = ctx.out[0] ?? '';
|
|
23
|
-
expect(text).toContain('kit 0.
|
|
23
|
+
expect(text).toContain('kit 0.9.1');
|
|
24
24
|
expect(text).toContain('node');
|
|
25
25
|
expect(text).toContain('pnpm');
|
|
26
26
|
expect(text).toContain('workspace');
|
package/src/commands/fix.test.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
// packages/cli/src/commands/fix.test.ts
|
|
2
|
-
import {
|
|
2
|
+
import { promises as fs } from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
6
|
+
import { scaffoldSpecification, serializeProfileYaml } from '@agentic-sdlc-kit/core';
|
|
3
7
|
import { fixCommand } from './fix.js';
|
|
4
8
|
import type { CommandContext } from './types.js';
|
|
5
9
|
|
|
@@ -9,28 +13,106 @@ const makeCtx = (
|
|
|
9
13
|
): CommandContext & { out: string[]; err: string[] } => {
|
|
10
14
|
const out: string[] = [];
|
|
11
15
|
const err: string[] = [];
|
|
12
|
-
return {
|
|
13
|
-
argv,
|
|
14
|
-
cwd,
|
|
15
|
-
stdout: (s) => void out.push(s),
|
|
16
|
-
stderr: (s) => void err.push(s),
|
|
17
|
-
out,
|
|
18
|
-
err,
|
|
19
|
-
};
|
|
16
|
+
return { argv, cwd, stdout: (s) => void out.push(s), stderr: (s) => void err.push(s), out, err };
|
|
20
17
|
};
|
|
21
18
|
|
|
19
|
+
let root: string;
|
|
20
|
+
let marker: string;
|
|
21
|
+
|
|
22
|
+
/** The test script fails with a real AssertionError until the marker (the "fix") exists. */
|
|
23
|
+
beforeEach(async () => {
|
|
24
|
+
root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-fix-'));
|
|
25
|
+
marker = path.join(root, '.fixed');
|
|
26
|
+
const script = path.join(root, 'check.js');
|
|
27
|
+
await fs.writeFile(
|
|
28
|
+
script,
|
|
29
|
+
[
|
|
30
|
+
'const fs = require("node:fs");',
|
|
31
|
+
`if (!fs.existsSync(${JSON.stringify(marker)})) {`,
|
|
32
|
+
' console.error("AssertionError: expected defect to be fixed");',
|
|
33
|
+
' process.exit(1);',
|
|
34
|
+
'}',
|
|
35
|
+
].join('\n'),
|
|
36
|
+
);
|
|
37
|
+
await fs.mkdir(path.join(root, '.ai-kit'), { recursive: true });
|
|
38
|
+
await fs.writeFile(
|
|
39
|
+
path.join(root, '.ai-kit', 'project.yml'),
|
|
40
|
+
serializeProfileYaml({
|
|
41
|
+
schemaVersion: 1,
|
|
42
|
+
name: 'fix-app',
|
|
43
|
+
stack: ['node-typescript'],
|
|
44
|
+
commands: { test: [['node', script]] },
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
await scaffoldSpecification({
|
|
48
|
+
id: 'BUG-101',
|
|
49
|
+
title: 'Transfer accepts negative amounts',
|
|
50
|
+
targetDir: path.join(root, 'docs', 'specifications', 'features'),
|
|
51
|
+
});
|
|
52
|
+
const planDir = path.join(root, 'docs', 'plans', 'BUG-101');
|
|
53
|
+
await fs.mkdir(planDir, { recursive: true });
|
|
54
|
+
await fs.writeFile(
|
|
55
|
+
path.join(planDir, 'plan.json'),
|
|
56
|
+
JSON.stringify({
|
|
57
|
+
featureId: 'BUG-101',
|
|
58
|
+
tasks: [
|
|
59
|
+
{
|
|
60
|
+
id: 'TASK-001',
|
|
61
|
+
description: 'Reject negative transfer amounts',
|
|
62
|
+
acceptanceCriteria: ['negative amount is rejected'],
|
|
63
|
+
verification: { command: ['node', script], expectedStatus: 'passed' },
|
|
64
|
+
dependencies: [],
|
|
65
|
+
likelyFiles: ['src/transfer.js'],
|
|
66
|
+
estimatedScope: 'xs',
|
|
67
|
+
risk: 'low',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
edges: [],
|
|
71
|
+
verticalSlices: [['TASK-001']],
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
afterEach(() => fs.rm(root, { recursive: true, force: true }));
|
|
76
|
+
|
|
22
77
|
describe('fixCommand', () => {
|
|
23
78
|
it('shows help when --help is passed', async () => {
|
|
24
79
|
const ctx = makeCtx(['--help'], '/');
|
|
25
|
-
|
|
26
|
-
expect(r.exitCode).toBe(0);
|
|
80
|
+
expect((await fixCommand.run(ctx)).exitCode).toBe(0);
|
|
27
81
|
expect(ctx.out[0]).toContain('Usage: kit fix');
|
|
28
82
|
});
|
|
29
83
|
|
|
30
84
|
it('fails if issue ID is missing', async () => {
|
|
31
85
|
const ctx = makeCtx([], '/');
|
|
32
|
-
|
|
33
|
-
expect(r.exitCode).toBe(1);
|
|
86
|
+
expect((await fixCommand.run(ctx)).exitCode).toBe(1);
|
|
34
87
|
expect(ctx.err[0]).toContain('missing required issue identifier');
|
|
35
88
|
});
|
|
89
|
+
|
|
90
|
+
it('no longer reports success without a failing test: green before red is rejected', async () => {
|
|
91
|
+
expect((await fixCommand.run(makeCtx(['BUG-101', 'start'], root))).exitCode).toBe(0);
|
|
92
|
+
await fs.writeFile(marker, 'fixed'); // the defect is "fixed" but Red was never observed
|
|
93
|
+
const green = makeCtx(['BUG-101', 'green', 'TASK-001'], root);
|
|
94
|
+
expect((await fixCommand.run(green)).exitCode).toBe(1);
|
|
95
|
+
expect(green.err.join('\n')).toMatch(/red/i);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('drives red -> green -> refactor -> verify with recorded evidence', async () => {
|
|
99
|
+
expect((await fixCommand.run(makeCtx(['BUG-101', 'start'], root))).exitCode).toBe(0);
|
|
100
|
+
expect((await fixCommand.run(makeCtx(['BUG-101', 'red', 'TASK-001'], root))).exitCode).toBe(0);
|
|
101
|
+
await fs.writeFile(marker, 'fixed');
|
|
102
|
+
expect((await fixCommand.run(makeCtx(['BUG-101', 'green', 'TASK-001'], root))).exitCode).toBe(0);
|
|
103
|
+
expect((await fixCommand.run(makeCtx(['BUG-101', 'refactor', 'TASK-001'], root))).exitCode).toBe(0);
|
|
104
|
+
const verify = makeCtx(['BUG-101', 'verify'], root);
|
|
105
|
+
expect((await fixCommand.run(verify)).exitCode).toBe(0);
|
|
106
|
+
expect(verify.out.join('\n')).toContain('red:failed green:passed refactor:passed');
|
|
107
|
+
const journal = await fs.readdir(path.join(root, '.ai-kit', 'journal', 'feature-runs'));
|
|
108
|
+
expect(journal).toContain('BUG-101.jsonl');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('with no action it starts the run, then reports status', async () => {
|
|
112
|
+
const first = makeCtx(['BUG-101'], root);
|
|
113
|
+
expect((await fixCommand.run(first)).exitCode).toBe(0);
|
|
114
|
+
const again = makeCtx(['BUG-101'], root);
|
|
115
|
+
expect((await fixCommand.run(again)).exitCode).toBe(0);
|
|
116
|
+
expect(again.out.join('\n')).toContain('BUG-101');
|
|
117
|
+
});
|
|
36
118
|
});
|
package/src/commands/fix.ts
CHANGED
|
@@ -1,69 +1,58 @@
|
|
|
1
1
|
// packages/cli/src/commands/fix.ts
|
|
2
2
|
//
|
|
3
|
-
// `kit fix <issue-id> [
|
|
4
|
-
//
|
|
3
|
+
// `kit fix <issue-id> [action] [task-id] [options]`.
|
|
4
|
+
//
|
|
5
|
+
// A defect is driven through the SAME evidence-gated engine as a feature
|
|
6
|
+
// (`kit feature`): the regression test must fail as an ASSERTION (Red) before
|
|
7
|
+
// the correction is accepted (Green), then the suite must stay green
|
|
8
|
+
// (Refactor), with a hash-chained journal and `kit next` guidance.
|
|
9
|
+
//
|
|
10
|
+
// This command used to run the whole-profile verification and report a
|
|
11
|
+
// "confirmed" regression without ever observing a failing test. It no longer
|
|
12
|
+
// carries any workflow of its own: it only delegates, so it cannot assert more
|
|
13
|
+
// than the engine has measured.
|
|
5
14
|
|
|
6
|
-
import
|
|
7
|
-
import { runBugfixWorkflow, type BugfixReport } from '@agentic-sdlc-kit/core';
|
|
15
|
+
import { featureCommand } from './feature.js';
|
|
8
16
|
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
9
17
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ctx.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const targetRoot = path.resolve(ctx.cwd, '.');
|
|
29
|
-
|
|
30
|
-
const res = await runBugfixWorkflow({ issueId, projectRoot: targetRoot, dryRun: isDryRun });
|
|
31
|
-
if (!res.ok) {
|
|
32
|
-
ctx.stderr(`kit fix: workflow error: ${res.error.message}\n`);
|
|
33
|
-
return { exitCode: 1, message: res.error.message };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (isJson) {
|
|
37
|
-
ctx.stdout(JSON.stringify(res.value, null, 2) + '\n');
|
|
38
|
-
} else {
|
|
39
|
-
ctx.stdout(formatSummary(res.value));
|
|
40
|
-
}
|
|
41
|
-
return { exitCode: res.value.status === 'passed' ? 0 : 1 };
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
function formatSummary(report: BugfixReport): string {
|
|
46
|
-
const lines: string[] = [
|
|
47
|
-
`Bugfix Run: ${report.issueId}`,
|
|
48
|
-
`Status: ${report.status.toUpperCase()}`,
|
|
49
|
-
`Regression Cover: ${report.regressionCovered ? 'CONFIRMED' : 'MISSING'}`,
|
|
50
|
-
`Verification: ${report.verification.status.toUpperCase()}`,
|
|
51
|
-
`Duration: ${report.durationMs}ms`,
|
|
52
|
-
];
|
|
53
|
-
return lines.join('\n') + '\n';
|
|
18
|
+
export function createFixCommand(engine: Command = featureCommand): Command {
|
|
19
|
+
return {
|
|
20
|
+
name: 'fix',
|
|
21
|
+
summary:
|
|
22
|
+
'Fix a defect through the evidence-gated engine: failing regression test first (Red/Green/Refactor).',
|
|
23
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
24
|
+
if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
|
|
25
|
+
ctx.stdout(formatHelp());
|
|
26
|
+
return { exitCode: 0 };
|
|
27
|
+
}
|
|
28
|
+
const issueId = ctx.argv.find((a) => !a.startsWith('-'));
|
|
29
|
+
if (!issueId) {
|
|
30
|
+
ctx.stderr('kit fix: error: missing required issue identifier (e.g. BUG-001)\n');
|
|
31
|
+
return { exitCode: 1, message: 'Missing issue ID' };
|
|
32
|
+
}
|
|
33
|
+
return engine.run(ctx);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
54
36
|
}
|
|
55
37
|
|
|
38
|
+
export const fixCommand: Command = createFixCommand();
|
|
39
|
+
|
|
56
40
|
function formatHelp(): string {
|
|
57
41
|
return [
|
|
58
|
-
'Usage: kit fix <issue-id> [
|
|
42
|
+
'Usage: kit fix <issue-id> [start|red|green|refactor|status|verify|run] [task-id] [options]',
|
|
43
|
+
'',
|
|
44
|
+
'Drive a bug fix through the same evidence gates as a feature. The issue id is the',
|
|
45
|
+
'run id (e.g. BUG-101): author docs/specifications/features/<id>/SPEC.md (expected vs',
|
|
46
|
+
'actual behavior) and docs/plans/<id>/plan.json, then:',
|
|
59
47
|
'',
|
|
60
|
-
'
|
|
61
|
-
'
|
|
48
|
+
' kit fix BUG-101 start begin the run (no action: start, or status if it exists)',
|
|
49
|
+
' kit fix BUG-101 red TASK-001 the regression test must FAIL as an assertion',
|
|
50
|
+
' kit fix BUG-101 green TASK-001 the smallest correction must pass it',
|
|
51
|
+
' kit fix BUG-101 refactor TASK-001 the suite must stay green',
|
|
52
|
+
' kit fix BUG-101 verify audit every chain + whole-profile regression',
|
|
62
53
|
'',
|
|
63
|
-
'Options
|
|
64
|
-
'
|
|
65
|
-
' --json Output machine-readable BugfixReport',
|
|
66
|
-
' --help Show this message',
|
|
54
|
+
'Options are those of `kit feature` (--json, --host <id>, --dry-run, ...).',
|
|
55
|
+
'Do not combine a behavior fix with a refactor in one run.',
|
|
67
56
|
'',
|
|
68
57
|
].join('\n');
|
|
69
58
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// packages/cli/src/commands/host-apply.ts
|
|
2
|
+
//
|
|
3
|
+
// Applies planned host-instruction targets to disk. Never overwrites a file
|
|
4
|
+
// the user edited (or one the kit did not write) unless --force is given.
|
|
5
|
+
|
|
6
|
+
import { promises as fs } from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { inspectManaged, upsertBlock, type HostTarget } from '@agentic-sdlc-kit/core';
|
|
9
|
+
|
|
10
|
+
export type ApplyAction = 'created' | 'updated' | 'unchanged' | 'refused';
|
|
11
|
+
|
|
12
|
+
export interface ApplyResult {
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly action: ApplyAction;
|
|
15
|
+
readonly reason?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function readOrNull(p: string): Promise<string | null> {
|
|
19
|
+
try {
|
|
20
|
+
return await fs.readFile(p, 'utf8');
|
|
21
|
+
} catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface Decision {
|
|
27
|
+
readonly action: ApplyAction;
|
|
28
|
+
readonly next?: string;
|
|
29
|
+
readonly reason?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function decideBlock(existing: string | null, target: HostTarget): Decision {
|
|
33
|
+
const next = upsertBlock(existing, target.content);
|
|
34
|
+
if (existing === null) return { action: 'created', next };
|
|
35
|
+
return next === existing ? { action: 'unchanged' } : { action: 'updated', next };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function decideFile(existing: string | null, target: HostTarget, force: boolean): Decision {
|
|
39
|
+
const state = inspectManaged(existing);
|
|
40
|
+
if (state === 'absent') return { action: 'created', next: target.content };
|
|
41
|
+
if (existing === target.content) return { action: 'unchanged' };
|
|
42
|
+
if (state === 'unmodified' || force) return { action: 'updated', next: target.content };
|
|
43
|
+
const why = state === 'modified' ? 'edited since install' : 'not written by the kit';
|
|
44
|
+
return { action: 'refused', reason: `${why}; re-run with --force to replace` };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function applyTarget(
|
|
48
|
+
root: string,
|
|
49
|
+
target: HostTarget,
|
|
50
|
+
opts: { force: boolean; dryRun: boolean },
|
|
51
|
+
): Promise<ApplyResult> {
|
|
52
|
+
const abs = path.join(root, target.path);
|
|
53
|
+
const existing = await readOrNull(abs);
|
|
54
|
+
const d =
|
|
55
|
+
target.mode === 'block' ? decideBlock(existing, target) : decideFile(existing, target, opts.force);
|
|
56
|
+
if (d.next !== undefined && !opts.dryRun) {
|
|
57
|
+
await fs.mkdir(path.dirname(abs), { recursive: true });
|
|
58
|
+
await fs.writeFile(abs, d.next, 'utf8');
|
|
59
|
+
}
|
|
60
|
+
return { path: abs, action: d.action, ...(d.reason ? { reason: d.reason } : {}) };
|
|
61
|
+
}
|