@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,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
|
+
};
|