@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.
Files changed (114) hide show
  1. package/dist/application/agent/execution-store.d.ts.map +1 -1
  2. package/dist/application/agent/execution-store.js +2 -1
  3. package/dist/application/agent/execution-store.js.map +1 -1
  4. package/dist/application/agent/orchestrator.d.ts.map +1 -1
  5. package/dist/application/agent/orchestrator.js +2 -2
  6. package/dist/application/agent/orchestrator.js.map +1 -1
  7. package/dist/application/dispatcher.d.ts.map +1 -1
  8. package/dist/application/dispatcher.js +12 -0
  9. package/dist/application/dispatcher.js.map +1 -1
  10. package/dist/application/version.d.ts +1 -1
  11. package/dist/application/version.js +1 -1
  12. package/dist/commands/attach-exclude.d.ts +8 -0
  13. package/dist/commands/attach-exclude.d.ts.map +1 -0
  14. package/dist/commands/attach-exclude.js +48 -0
  15. package/dist/commands/attach-exclude.js.map +1 -0
  16. package/dist/commands/attach-git.d.ts +11 -0
  17. package/dist/commands/attach-git.d.ts.map +1 -0
  18. package/dist/commands/attach-git.js +40 -0
  19. package/dist/commands/attach-git.js.map +1 -0
  20. package/dist/commands/attach-store.d.ts +10 -0
  21. package/dist/commands/attach-store.d.ts.map +1 -0
  22. package/dist/commands/attach-store.js +107 -0
  23. package/dist/commands/attach-store.js.map +1 -0
  24. package/dist/commands/attach.d.ts +8 -0
  25. package/dist/commands/attach.d.ts.map +1 -0
  26. package/dist/commands/attach.js +124 -0
  27. package/dist/commands/attach.js.map +1 -0
  28. package/dist/commands/fix.d.ts +1 -0
  29. package/dist/commands/fix.d.ts.map +1 -1
  30. package/dist/commands/fix.js +42 -50
  31. package/dist/commands/fix.js.map +1 -1
  32. package/dist/commands/host-apply.d.ts +12 -0
  33. package/dist/commands/host-apply.d.ts.map +1 -0
  34. package/dist/commands/host-apply.js +43 -0
  35. package/dist/commands/host-apply.js.map +1 -0
  36. package/dist/commands/host.d.ts +3 -0
  37. package/dist/commands/host.d.ts.map +1 -0
  38. package/dist/commands/host.js +107 -0
  39. package/dist/commands/host.js.map +1 -0
  40. package/dist/commands/index.d.ts +4 -0
  41. package/dist/commands/index.d.ts.map +1 -1
  42. package/dist/commands/index.js +4 -0
  43. package/dist/commands/index.js.map +1 -1
  44. package/dist/commands/init.d.ts.map +1 -1
  45. package/dist/commands/init.js +5 -3
  46. package/dist/commands/init.js.map +1 -1
  47. package/dist/commands/install.d.ts.map +1 -1
  48. package/dist/commands/install.js +15 -7
  49. package/dist/commands/install.js.map +1 -1
  50. package/dist/commands/plugin-linker.d.ts +10 -1
  51. package/dist/commands/plugin-linker.d.ts.map +1 -1
  52. package/dist/commands/plugin-linker.js +53 -14
  53. package/dist/commands/plugin-linker.js.map +1 -1
  54. package/dist/commands/skills-install-commit.d.ts +34 -0
  55. package/dist/commands/skills-install-commit.d.ts.map +1 -0
  56. package/dist/commands/skills-install-commit.js +113 -0
  57. package/dist/commands/skills-install-commit.js.map +1 -0
  58. package/dist/commands/skills-install-manifest.d.ts +35 -0
  59. package/dist/commands/skills-install-manifest.d.ts.map +1 -0
  60. package/dist/commands/skills-install-manifest.js +89 -0
  61. package/dist/commands/skills-install-manifest.js.map +1 -0
  62. package/dist/commands/skills-install-report.d.ts +12 -0
  63. package/dist/commands/skills-install-report.d.ts.map +1 -0
  64. package/dist/commands/skills-install-report.js +44 -0
  65. package/dist/commands/skills-install-report.js.map +1 -0
  66. package/dist/commands/skills-install-secure.d.ts +14 -0
  67. package/dist/commands/skills-install-secure.d.ts.map +1 -0
  68. package/dist/commands/skills-install-secure.js +96 -0
  69. package/dist/commands/skills-install-secure.js.map +1 -0
  70. package/dist/commands/skills-install.d.ts +15 -0
  71. package/dist/commands/skills-install.d.ts.map +1 -0
  72. package/dist/commands/skills-install.js +182 -0
  73. package/dist/commands/skills-install.js.map +1 -0
  74. package/dist/commands/skills.d.ts +3 -0
  75. package/dist/commands/skills.d.ts.map +1 -0
  76. package/dist/commands/skills.js +217 -0
  77. package/dist/commands/skills.js.map +1 -0
  78. package/dist/commands/uninstall.d.ts +3 -0
  79. package/dist/commands/uninstall.d.ts.map +1 -0
  80. package/dist/commands/uninstall.js +113 -0
  81. package/dist/commands/uninstall.js.map +1 -0
  82. package/package.json +4 -4
  83. package/src/application/agent/execution-store.ts +2 -1
  84. package/src/application/agent/orchestrator.ts +2 -1
  85. package/src/application/dispatcher.test.ts +22 -3
  86. package/src/application/dispatcher.ts +8 -0
  87. package/src/application/version.ts +1 -1
  88. package/src/commands/attach-exclude.ts +50 -0
  89. package/src/commands/attach-git.ts +50 -0
  90. package/src/commands/attach-store.ts +107 -0
  91. package/src/commands/attach.test.ts +192 -0
  92. package/src/commands/attach.ts +143 -0
  93. package/src/commands/doctor.test.ts +1 -1
  94. package/src/commands/fix.test.ts +95 -13
  95. package/src/commands/fix.ts +44 -55
  96. package/src/commands/host-apply.ts +61 -0
  97. package/src/commands/host.test.ts +120 -0
  98. package/src/commands/host.ts +125 -0
  99. package/src/commands/index.ts +4 -0
  100. package/src/commands/init.test.ts +22 -0
  101. package/src/commands/init.ts +10 -3
  102. package/src/commands/install.test.ts +31 -0
  103. package/src/commands/install.ts +21 -7
  104. package/src/commands/plugin-linker.test.ts +80 -0
  105. package/src/commands/plugin-linker.ts +62 -14
  106. package/src/commands/skills-install-commit.ts +149 -0
  107. package/src/commands/skills-install-manifest.ts +124 -0
  108. package/src/commands/skills-install-report.ts +60 -0
  109. package/src/commands/skills-install-secure.ts +113 -0
  110. package/src/commands/skills-install.ts +245 -0
  111. package/src/commands/skills.test.ts +449 -0
  112. package/src/commands/skills.ts +247 -0
  113. package/src/commands/uninstall.test.ts +122 -0
  114. package/src/commands/uninstall.ts +116 -0
@@ -0,0 +1,120 @@
1
+ // packages/cli/src/commands/host.test.ts
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 { hostCommand } from './host.js';
7
+ import type { CommandContext } from './types.js';
8
+
9
+ let tmp: string;
10
+ let home: string;
11
+ let proj: string;
12
+
13
+ beforeEach(async () => {
14
+ tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-host-'));
15
+ home = path.join(tmp, 'home');
16
+ proj = path.join(tmp, 'proj');
17
+ await fs.mkdir(home);
18
+ await fs.mkdir(proj);
19
+ });
20
+ afterEach(() => fs.rm(tmp, { recursive: true, force: true }));
21
+
22
+ const run = async (...argv: string[]) => {
23
+ const out: string[] = [];
24
+ const err: string[] = [];
25
+ const ctx: CommandContext = {
26
+ argv: [...argv, '--home', home, '--dir', proj],
27
+ cwd: tmp,
28
+ stdout: (s) => void out.push(s),
29
+ stderr: (s) => void err.push(s),
30
+ };
31
+ const r = await hostCommand.run(ctx);
32
+ return { ...r, out: out.join('\n'), err: err.join('\n') };
33
+ };
34
+ const read = (p: string) => fs.readFile(p, 'utf8');
35
+ const exists = (p: string) => fs.stat(p).then(() => true, () => false);
36
+
37
+ describe('kit host', () => {
38
+ it('list shows every host with its default scope', async () => {
39
+ const r = await run('list');
40
+ expect(r.exitCode).toBe(0);
41
+ for (const h of ['claude-code', 'codex', 'cursor', 'agy', 'gemini', 'aider']) {
42
+ expect(r.out).toContain(h);
43
+ }
44
+ });
45
+
46
+ it('claude-code installs slash commands and a skill at user scope, nothing in the project', async () => {
47
+ const r = await run('install', 'claude-code');
48
+ expect(r.exitCode).toBe(0);
49
+ const cmd = await read(path.join(home, '.claude/commands/kit-feature.md'));
50
+ expect(cmd).toContain('$ARGUMENTS');
51
+ expect(cmd).toContain('KIT_HOST=claude-code');
52
+ expect(await exists(path.join(home, '.claude/skills/agentic-sdlc-kit/SKILL.md'))).toBe(true);
53
+ expect(await fs.readdir(proj)).toEqual([]);
54
+ });
55
+
56
+ it('is idempotent: second install reports unchanged and rewrites nothing', async () => {
57
+ await run('install', 'claude-code');
58
+ const p = path.join(home, '.claude/commands/kit-fix.md');
59
+ const before = await fs.stat(p);
60
+ const r = await run('install', 'claude-code');
61
+ expect(r.exitCode).toBe(0);
62
+ expect(r.out).not.toMatch(/created|updated|refused/);
63
+ expect((await fs.stat(p)).mtimeMs).toBe(before.mtimeMs);
64
+ });
65
+
66
+ it('refuses to overwrite an edited file; --force replaces it', async () => {
67
+ await run('install', 'cursor');
68
+ const p = path.join(proj, '.cursor/rules/sdlc.mdc');
69
+ await fs.writeFile(p, (await read(p)).replace('kit doctor', 'MY OWN RULE'));
70
+ const refused = await run('install', 'cursor');
71
+ expect(refused.exitCode).toBe(1);
72
+ expect(refused.out).toContain('refused');
73
+ expect(await read(p)).toContain('MY OWN RULE');
74
+ expect((await run('install', 'cursor', '--force')).exitCode).toBe(0);
75
+ expect(await read(p)).not.toContain('MY OWN RULE');
76
+ });
77
+
78
+ it('refuses a pre-existing file the kit did not write', async () => {
79
+ const p = path.join(home, '.gemini/skills/agentic-sdlc-kit/SKILL.md');
80
+ await fs.mkdir(path.dirname(p), { recursive: true });
81
+ await fs.writeFile(p, 'my skill');
82
+ const r = await run('install', 'agy');
83
+ expect(r.exitCode).toBe(1);
84
+ expect(await read(p)).toBe('my skill');
85
+ });
86
+
87
+ it('shared files keep user text and only the managed block is replaced', async () => {
88
+ const p = path.join(proj, 'AGENTS.md');
89
+ await fs.writeFile(p, '# My project rules\nkeep me\n');
90
+ expect((await run('install', 'codex', '--scope', 'project')).exitCode).toBe(0);
91
+ const once = await read(p);
92
+ expect(once).toContain('keep me');
93
+ expect(once).toContain('KIT_HOST=codex');
94
+ await run('install', 'codex', '--scope', 'project');
95
+ expect(await read(p)).toBe(once);
96
+ });
97
+
98
+ it('dry-run writes nothing', async () => {
99
+ const r = await run('install', 'all', '--dry-run');
100
+ expect(r.exitCode).toBe(0);
101
+ expect(r.out).toContain('dry run');
102
+ expect(await fs.readdir(home)).toEqual([]);
103
+ expect(await fs.readdir(proj)).toEqual([]);
104
+ });
105
+
106
+ it('rejects unknown hosts, bad scopes and scopes a host lacks', async () => {
107
+ expect((await run('install', 'vim')).err).toContain("unknown host 'vim'");
108
+ expect((await run('install', 'codex', '--scope', 'galaxy')).err).toContain('--scope');
109
+ expect((await run('install', 'cursor', '--scope', 'user')).err).toContain('no user-scope');
110
+ });
111
+
112
+ it('install all uses each host default scope', async () => {
113
+ const r = await run('install', 'all');
114
+ expect(r.exitCode).toBe(0);
115
+ expect(await exists(path.join(home, '.codex/AGENTS.md'))).toBe(true);
116
+ expect(await exists(path.join(home, '.gemini/GEMINI.md'))).toBe(true);
117
+ expect(await exists(path.join(proj, '.cursor/rules/sdlc.mdc'))).toBe(true);
118
+ expect(await exists(path.join(proj, 'CONVENTIONS.md'))).toBe(true);
119
+ });
120
+ });
@@ -0,0 +1,125 @@
1
+ // packages/cli/src/commands/host.ts
2
+ //
3
+ // `kit host list | install <host|all> [--scope user|project] [--dir <p>]
4
+ // [--home <p>] [--force] [--dry-run] [--json]`
5
+ //
6
+ // Installs the standing agent procedure into each AI host's instruction
7
+ // surface once, so per ticket the user types a single line and the host
8
+ // drives the kit's evidence-gated loop (`kit next --json`) on its own.
9
+
10
+ import os from 'node:os';
11
+ import path from 'node:path';
12
+ import {
13
+ DEFAULT_SCOPE,
14
+ HOST_IDS,
15
+ isHostId,
16
+ planHostTargets,
17
+ type HostId,
18
+ type HostScope,
19
+ } from '@agentic-sdlc-kit/core';
20
+ import { applyTarget, type ApplyResult } from './host-apply.js';
21
+ import type { Command, CommandContext, CommandResult } from './types.js';
22
+
23
+ const USAGE = [
24
+ 'Usage: kit host list',
25
+ ' kit host install <host|all> [--scope user|project] [--dir <project>] [--home <dir>]',
26
+ ' [--force] [--dry-run] [--json]',
27
+ '',
28
+ `Hosts: ${HOST_IDS.join(', ')}`,
29
+ 'Default scope: user where the host has a global surface, otherwise project.',
30
+ 'Existing files you edited are never overwritten without --force; shared files',
31
+ '(AGENTS.md, GEMINI.md, CONVENTIONS.md) only get a replaceable managed block.',
32
+ ].join('\n');
33
+
34
+ function opt(argv: ReadonlyArray<string>, name: string): string | undefined {
35
+ const i = argv.indexOf(name);
36
+ const v = i === -1 ? undefined : argv[i + 1];
37
+ return v && !v.startsWith('-') ? v : undefined;
38
+ }
39
+
40
+ function listText(): string {
41
+ const lines = ['kit host: instruction surfaces', ''];
42
+ for (const host of HOST_IDS) {
43
+ const scope = DEFAULT_SCOPE[host];
44
+ const paths = planHostTargets(host, scope)!.map((t) => t.path);
45
+ lines.push(` ${host.padEnd(12)} [${scope}] ${paths.join(', ')}`);
46
+ }
47
+ return lines.join('\n');
48
+ }
49
+
50
+ interface Plan {
51
+ readonly host: HostId;
52
+ readonly scope: HostScope;
53
+ readonly root: string;
54
+ }
55
+
56
+ function resolvePlans(ctx: CommandContext, which: string): Plan[] | string {
57
+ const explicit = opt(ctx.argv, '--scope');
58
+ if (explicit !== undefined && explicit !== 'user' && explicit !== 'project') {
59
+ return `--scope must be 'user' or 'project' (got '${explicit}')`;
60
+ }
61
+ if (which !== 'all' && !isHostId(which)) return `unknown host '${which}'`;
62
+ const hosts: HostId[] = which === 'all' ? [...HOST_IDS] : [which as HostId];
63
+ const home = path.resolve(opt(ctx.argv, '--home') ?? os.homedir());
64
+ const project = path.resolve(ctx.cwd, opt(ctx.argv, '--dir') ?? '.');
65
+ const plans: Plan[] = [];
66
+ for (const host of hosts) {
67
+ const scope = (explicit as HostScope | undefined) ?? DEFAULT_SCOPE[host];
68
+ if (!planHostTargets(host, scope)) {
69
+ if (which === 'all') continue; // an explicit scope that some hosts lack is not an error for 'all'
70
+ return `${host} has no ${scope}-scope instruction surface`;
71
+ }
72
+ plans.push({ host, scope, root: scope === 'user' ? home : project });
73
+ }
74
+ return plans;
75
+ }
76
+
77
+ async function runInstall(ctx: CommandContext, which: string): Promise<CommandResult> {
78
+ const plans = resolvePlans(ctx, which);
79
+ if (typeof plans === 'string') {
80
+ ctx.stderr(`kit host: ${plans}`);
81
+ return { exitCode: 1 };
82
+ }
83
+ const opts = { force: ctx.argv.includes('--force'), dryRun: ctx.argv.includes('--dry-run') };
84
+ const results: Array<ApplyResult & { host: HostId; scope: HostScope }> = [];
85
+ for (const p of plans) {
86
+ for (const t of planHostTargets(p.host, p.scope)!) {
87
+ results.push({ host: p.host, scope: p.scope, ...(await applyTarget(p.root, t, opts)) });
88
+ }
89
+ }
90
+ const refused = results.some((r) => r.action === 'refused');
91
+ ctx.stdout(formatResults(results, opts.dryRun, ctx.argv.includes('--json')));
92
+ return { exitCode: refused ? 1 : 0 };
93
+ }
94
+
95
+ function formatResults(rs: ReadonlyArray<ApplyResult & { host: HostId }>, dry: boolean, json: boolean): string {
96
+ if (json) return JSON.stringify({ dryRun: dry, results: rs }, null, 2);
97
+ const lines = rs.map((r) => ` ${r.action.padEnd(9)} ${r.host.padEnd(12)} ${r.path}${r.reason ? ` (${r.reason})` : ''}`);
98
+ return [dry ? 'kit host install (dry run, nothing written)' : 'kit host install', ...lines].join('\n');
99
+ }
100
+
101
+ export const hostCommand: Command = {
102
+ name: 'host',
103
+ summary: 'Install the standing agent procedure into AI hosts (claude-code, codex, cursor, agy, gemini, aider).',
104
+ async run(ctx: CommandContext): Promise<CommandResult> {
105
+ const positional = ctx.argv.filter((a, i) => !a.startsWith('-') && !isOptValue(ctx.argv, i));
106
+ const [sub, which] = positional;
107
+ if (ctx.argv.includes('--help') || !sub) {
108
+ ctx.stdout(USAGE);
109
+ return { exitCode: sub || ctx.argv.includes('--help') ? 0 : 1 };
110
+ }
111
+ if (sub === 'list') {
112
+ ctx.stdout(listText());
113
+ return { exitCode: 0 };
114
+ }
115
+ if (sub === 'install' && which) return runInstall(ctx, which);
116
+ ctx.stderr(`kit host: unknown or incomplete subcommand\n${USAGE}`);
117
+ return { exitCode: 1 };
118
+ },
119
+ };
120
+
121
+ /** True when argv[i] is the value of a value-taking flag (so it is not a positional). */
122
+ function isOptValue(argv: ReadonlyArray<string>, i: number): boolean {
123
+ const prev = argv[i - 1];
124
+ return prev === '--scope' || prev === '--dir' || prev === '--home';
125
+ }
@@ -12,6 +12,7 @@ export * from './feature.js';
12
12
  export * from './new.js';
13
13
  export * from './fix.js';
14
14
  export * from './install.js';
15
+ export * from './uninstall.js';
15
16
  export * from './memory.js';
16
17
  export * from './evolve.js';
17
18
  export * from './refactor.js';
@@ -19,3 +20,6 @@ export * from './optimize.js';
19
20
  export * from './elicit.js';
20
21
  export * from './next.js';
21
22
  export * from './journal.js';
23
+ export * from './skills.js';
24
+ export * from './attach.js';
25
+ export * from './host.js';
@@ -62,4 +62,26 @@ describe('initCommand', () => {
62
62
  await fs.rm(tmp, { recursive: true, force: true });
63
63
  }
64
64
  });
65
+
66
+ it('creates state/reports under KIT_STATE_DIR, not in the project', async () => {
67
+ const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-init-state-'));
68
+ const proj = path.join(tmp, 'proj');
69
+ const stateDir = path.join(tmp, 'state');
70
+ await fs.mkdir(proj);
71
+ await fs.writeFile(
72
+ path.join(proj, 'package.json'),
73
+ JSON.stringify({ name: 'p', scripts: { test: 'node --test' } }),
74
+ );
75
+ process.env['KIT_STATE_DIR'] = stateDir;
76
+ try {
77
+ const r = await initCommand.run(makeCtx([], proj));
78
+ expect(r.exitCode).toBe(0);
79
+ expect(await fs.readdir(path.join(proj, '.ai-kit'))).toEqual(['project.yml']);
80
+ const [sub] = await fs.readdir(stateDir);
81
+ expect((await fs.readdir(path.join(stateDir, sub!))).sort()).toEqual(['reports', 'state']);
82
+ } finally {
83
+ delete process.env['KIT_STATE_DIR'];
84
+ await fs.rm(tmp, { recursive: true, force: true });
85
+ }
86
+ });
65
87
  });
@@ -5,7 +5,12 @@
5
5
 
6
6
  import { promises as fs } from 'node:fs';
7
7
  import path from 'node:path';
8
- import { FileSystemRepositoryScanner, generateProfile, writeProfile } from '@agentic-sdlc-kit/core';
8
+ import {
9
+ FileSystemRepositoryScanner,
10
+ generateProfile,
11
+ kitStateRoot,
12
+ writeProfile,
13
+ } from '@agentic-sdlc-kit/core';
9
14
  import type { ProjectProfile } from '@agentic-sdlc-kit/contracts';
10
15
  import type { Command, CommandContext, CommandResult } from './types.js';
11
16
 
@@ -71,8 +76,10 @@ async function fileExists(p: string): Promise<boolean> {
71
76
  }
72
77
 
73
78
  async function ensureDirectories(root: string): Promise<void> {
74
- await fs.mkdir(path.join(root, '.ai-kit', 'state'), { recursive: true });
75
- await fs.mkdir(path.join(root, '.ai-kit', 'reports'), { recursive: true });
79
+ // Machinery dirs follow KIT_STATE_DIR; project.yml itself stays project-rooted.
80
+ const stateRoot = kitStateRoot(root);
81
+ await fs.mkdir(path.join(stateRoot, 'state'), { recursive: true });
82
+ await fs.mkdir(path.join(stateRoot, 'reports'), { recursive: true });
76
83
  }
77
84
 
78
85
  function formatOutput(root: string, profile: ProjectProfile): string {
@@ -59,3 +59,34 @@ describe('installCommand --dir', () => {
59
59
  expect(await exists(path.join(elsewhere.path, '.ai-kit'))).toBe(false);
60
60
  });
61
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
+ });
@@ -202,7 +202,7 @@ export const installCommand: Command = {
202
202
  // preserved is false because we did not skip it.
203
203
  ownershipEntries.push({
204
204
  packageId: 'agentic-sdlc-kit',
205
- packageVersion: '0.8.0',
205
+ packageVersion: '0.9.1',
206
206
  path: op.path,
207
207
  sha256: op.sha256,
208
208
  installedAt: now,
@@ -233,11 +233,12 @@ export const installCommand: Command = {
233
233
  }
234
234
  ownershipEntries.push({
235
235
  packageId: 'agentic-sdlc-kit',
236
- packageVersion: '0.8.0',
236
+ packageVersion: '0.9.1',
237
237
  path: path.relative(targetRoot, pr.linkPath),
238
238
  sha256: pluginHash,
239
239
  installedAt: now,
240
240
  preserved: pr.status === 'already-linked',
241
+ ...(pr.target !== undefined ? { target: pr.target } : {}),
241
242
  });
242
243
  }
243
244
  }
@@ -246,11 +247,18 @@ export const installCommand: Command = {
246
247
  // Write ownership manifest so kit uninstall knows what we own.
247
248
  const manifestPath = path.join(targetRoot, '.ai-kit', 'ownership-manifest.json');
248
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
+ );
249
257
  const manifest = {
250
258
  schemaVersion: 1,
251
259
  root: targetRoot,
252
260
  scope: 'project',
253
- entries: ownershipEntries,
261
+ entries: [...earlier.filter((e) => !written.has(e.path)), ...ownershipEntries],
254
262
  };
255
263
  await fs.writeFile(manifestPath, JSON.stringify(manifest, null, 2) + '\n', 'utf8');
256
264
 
@@ -264,13 +272,19 @@ export const installCommand: Command = {
264
272
  ownershipManifest: '.ai-kit/ownership-manifest.json',
265
273
  };
266
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
+
267
281
  if (isJson) {
268
- ctx.stdout(JSON.stringify(result, null, 2) + '\n');
282
+ ctx.stdout(JSON.stringify({ ...result, installed: problems.length === 0 }, null, 2) + '\n');
269
283
  } else {
270
- ctx.stdout(formatResult(result));
284
+ ctx.stdout(formatResult({ ...result, installed: problems.length === 0 }));
271
285
  }
272
286
 
273
- return { exitCode: 0 };
287
+ return { exitCode: problems.length === 0 ? 0 : 1 };
274
288
  },
275
289
  };
276
290
 
@@ -314,7 +328,7 @@ interface InstallResult {
314
328
 
315
329
  function formatResult(r: InstallResult): string {
316
330
  const lines: string[] = [
317
- 'kit install: SUCCESS',
331
+ r.installed ? 'kit install: SUCCESS' : 'kit install: COMPLETED WITH PROBLEMS (see plugin status below)',
318
332
  ` Profile: ${r.profile}`,
319
333
  ` Stack: ${r.stack}`,
320
334
  ` Written: ${r.writtenFiles.length} file(s)`,
@@ -136,4 +136,84 @@ describe('plugin-linker', () => {
136
136
  await fs.rm(empty, { recursive: true, force: true });
137
137
  }
138
138
  });
139
+
140
+ describe('ownership: never adopt or replace something the kit did not create', () => {
141
+ const withKit = async (
142
+ fn: (kitRoot: string, project: string, linkPath: (n: string) => string) => Promise<void>,
143
+ ): Promise<void> => {
144
+ const kitRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-kitroot-'));
145
+ const project = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-project-'));
146
+ try {
147
+ await makeFakeKit(kitRoot, true);
148
+ await fn(kitRoot, project, (n) => path.join(project, '.claude', 'plugins', n));
149
+ } finally {
150
+ await fs.rm(kitRoot, { recursive: true, force: true });
151
+ await fs.rm(project, { recursive: true, force: true });
152
+ }
153
+ };
154
+ const only = (rs: Awaited<ReturnType<typeof linkRuntimePlugins>>, name: string) =>
155
+ rs.find((r) => r.name === name)!;
156
+
157
+ it('reports conflict for a symlink to somewhere else and leaves it untouched', async () => {
158
+ await withKit(async (kitRoot, project, link) => {
159
+ const foreign = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-foreign-'));
160
+ await fs.mkdir(path.dirname(link('sdlc-guard')), { recursive: true });
161
+ await fs.symlink(foreign, link('sdlc-guard'), 'dir');
162
+ const r = only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard');
163
+ expect(r.status).toBe('conflict');
164
+ expect(await fs.readlink(link('sdlc-guard'))).toBe(foreign);
165
+ await fs.rm(foreign, { recursive: true, force: true });
166
+ });
167
+ });
168
+
169
+ it('reports conflict for a dangling symlink', async () => {
170
+ await withKit(async (kitRoot, project, link) => {
171
+ await fs.mkdir(path.dirname(link('sdlc-guard')), { recursive: true });
172
+ await fs.symlink('/nonexistent/kit-target', link('sdlc-guard'), 'dir');
173
+ expect(only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard').status).toBe('conflict');
174
+ });
175
+ });
176
+
177
+ it('reports conflict (not already-linked) for a real directory at the path', async () => {
178
+ await withKit(async (kitRoot, project, link) => {
179
+ await fs.mkdir(link('sdlc-guard'), { recursive: true });
180
+ await fs.writeFile(path.join(link('sdlc-guard'), 'mine.txt'), 'user data');
181
+ const r = only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard');
182
+ expect(r.status).toBe('conflict');
183
+ expect(await fs.readFile(path.join(link('sdlc-guard'), 'mine.txt'), 'utf8')).toBe('user data');
184
+ });
185
+ });
186
+
187
+ it("reports the verified target for the kit's own link, on create and on re-run", async () => {
188
+ await withKit(async (kitRoot, project) => {
189
+ const first = only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard');
190
+ const second = only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard');
191
+ expect(first.status).toBe('linked');
192
+ expect(second.status).toBe('already-linked');
193
+ expect(second.target).toBe(first.target);
194
+ expect(first.target).toBe(path.join(kitRoot, 'plugins', 'sdlc-guard'));
195
+ });
196
+ });
197
+
198
+ it('refuses to write through a symlinked .claude directory', async () => {
199
+ await withKit(async (kitRoot, project) => {
200
+ const elsewhere = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-elsewhere-'));
201
+ await fs.symlink(elsewhere, path.join(project, '.claude'), 'dir');
202
+ const results = await linkRuntimePlugins(project, kitRoot);
203
+ for (const r of results) expect(r.status).toBe('conflict');
204
+ expect(await fs.readdir(elsewhere)).toEqual([]);
205
+ await fs.rm(elsewhere, { recursive: true, force: true });
206
+ });
207
+ });
208
+
209
+ it('treats a hooks.json that declares no modules as incomplete', async () => {
210
+ await withKit(async (kitRoot, project) => {
211
+ await fs.writeFile(
212
+ path.join(kitRoot, 'plugins', 'sdlc-guard', 'hooks', 'hooks.json'),
213
+ JSON.stringify({ modules: [] }),
214
+ );
215
+ expect(only(await linkRuntimePlugins(project, kitRoot), 'sdlc-guard').status).toBe('incomplete');
216
+ });
217
+ });
218
+ });
139
219
  });
@@ -40,7 +40,14 @@ export interface PluginLinkResult {
40
40
  name: string;
41
41
  /** Where the symlink was created (or already existed) inside the project. */
42
42
  linkPath: string;
43
- status: 'linked' | 'already-linked' | 'incomplete' | 'not-found';
43
+ /**
44
+ * `conflict`: something that is not the kit's own link to this plugin
45
+ * occupies the path (foreign or dangling symlink, real file/dir, or a
46
+ * symlinked parent). Left untouched and never recorded as kit-owned.
47
+ */
48
+ status: 'linked' | 'already-linked' | 'incomplete' | 'not-found' | 'conflict';
49
+ /** For linked/already-linked: the absolute path the link points at. */
50
+ target?: string;
44
51
  detail?: string;
45
52
  }
46
53
 
@@ -86,6 +93,9 @@ export async function validatePluginHooks(
86
93
  } catch {
87
94
  return { ok: false, missing: [manifestPath] };
88
95
  }
96
+ if (modules.length === 0) {
97
+ return { ok: false, missing: [`${manifestPath} (declares no hooks modules)`] };
98
+ }
89
99
  const missing: string[] = [];
90
100
  for (const mod of modules) {
91
101
  const resolved = path.resolve(hooksDir, mod);
@@ -98,6 +108,37 @@ export async function validatePluginHooks(
98
108
  return { ok: missing.length === 0, missing };
99
109
  }
100
110
 
111
+ /** Where a symlink points, resolved to an absolute path (works for dangling links). */
112
+ export async function linkTarget(linkPath: string): Promise<string> {
113
+ return path.resolve(path.dirname(linkPath), await fs.readlink(linkPath));
114
+ }
115
+
116
+ type Occupant = 'none' | 'ours' | 'foreign';
117
+
118
+ /**
119
+ * Classify what already sits at `linkPath`. Only a symlink that resolves to
120
+ * this kit's own plugin directory is "ours"; a foreign or dangling symlink,
121
+ * a real file or directory are all "foreign".
122
+ */
123
+ async function classifyOccupant(linkPath: string, pluginDir: string): Promise<Occupant> {
124
+ const stat = await fs.lstat(linkPath).catch(() => null);
125
+ if (!stat) return 'none';
126
+ if (!stat.isSymbolicLink()) return 'foreign';
127
+ try {
128
+ return (await fs.realpath(linkPath)) === (await fs.realpath(pluginDir)) ? 'ours' : 'foreign';
129
+ } catch {
130
+ return 'foreign'; // dangling
131
+ }
132
+ }
133
+
134
+ /** A symlinked .claude or .claude/plugins would redirect every write elsewhere. */
135
+ async function symlinkedParent(projectRoot: string): Promise<string | null> {
136
+ for (const dir of [path.join(projectRoot, '.claude'), path.join(projectRoot, '.claude', 'plugins')]) {
137
+ if ((await fs.lstat(dir).catch(() => null))?.isSymbolicLink()) return dir;
138
+ }
139
+ return null;
140
+ }
141
+
101
142
  /**
102
143
  * Link the runtime plugins into `<project>/.claude/plugins/`.
103
144
  * Never throws: every failure is reported per-plugin in the results.
@@ -121,6 +162,15 @@ export async function linkRuntimePlugins(
121
162
  }
122
163
 
123
164
  const targetBase = path.join(projectRoot, '.claude', 'plugins');
165
+ const redirected = await symlinkedParent(projectRoot);
166
+ if (redirected !== null) {
167
+ return RUNTIME_PLUGIN_NAMES.map((name) => ({
168
+ name,
169
+ linkPath: path.join(targetBase, name),
170
+ status: 'conflict' as const,
171
+ detail: `refusing to link: ${redirected} is a symlink, so links would land outside the project`,
172
+ }));
173
+ }
124
174
  await fs.mkdir(targetBase, { recursive: true });
125
175
 
126
176
  for (const name of RUNTIME_PLUGIN_NAMES) {
@@ -162,27 +212,25 @@ export async function linkRuntimePlugins(
162
212
  continue;
163
213
  }
164
214
 
165
- // Idempotent linking: replace a symlink we own; keep anything else.
166
- try {
167
- const stat = await fs.lstat(linkPath);
168
- if (stat.isSymbolicLink()) {
169
- results.push({ name, linkPath, status: 'already-linked' });
170
- continue;
171
- }
172
- // A real file/dir already occupies the path: do not clobber it.
215
+ // Idempotent linking. Only our own link counts as already linked;
216
+ // anything else at the path is a conflict and is never adopted.
217
+ const occupant = await classifyOccupant(linkPath, pluginDir);
218
+ if (occupant === 'ours') {
219
+ results.push({ name, linkPath, status: 'already-linked', target: await linkTarget(linkPath) });
220
+ continue;
221
+ }
222
+ if (occupant === 'foreign') {
173
223
  results.push({
174
224
  name,
175
225
  linkPath,
176
- status: 'already-linked',
177
- detail: 'path already exists and is not a kit symlink; left untouched',
226
+ status: 'conflict',
227
+ detail: 'path exists and is not a link to this kit plugin; left untouched and not recorded as kit-owned',
178
228
  });
179
229
  continue;
180
- } catch {
181
- // Path does not exist: create the symlink.
182
230
  }
183
231
  try {
184
232
  await fs.symlink(pluginDir, linkPath, 'dir');
185
- results.push({ name, linkPath, status: 'linked' });
233
+ results.push({ name, linkPath, status: 'linked', target: await linkTarget(linkPath) });
186
234
  } catch (err) {
187
235
  results.push({
188
236
  name,