@agentic-sdlc-kit/cli 0.8.0 → 1.0.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 +5 -4
- package/dist/application/agent/orchestrator.js.map +1 -1
- package/dist/application/agent/providers/claude-code/permission-config.d.ts.map +1 -1
- package/dist/application/agent/providers/claude-code/permission-config.js +8 -2
- package/dist/application/agent/providers/claude-code/permission-config.js.map +1 -1
- package/dist/application/agent-tools/dispatch.d.ts +12 -0
- package/dist/application/agent-tools/dispatch.d.ts.map +1 -0
- package/dist/application/agent-tools/dispatch.js +189 -0
- package/dist/application/agent-tools/dispatch.js.map +1 -0
- package/dist/application/agent-tools/mcp-server.d.ts +10 -0
- package/dist/application/agent-tools/mcp-server.d.ts.map +1 -0
- package/dist/application/agent-tools/mcp-server.js +100 -0
- package/dist/application/agent-tools/mcp-server.js.map +1 -0
- package/dist/application/bench/harness.d.ts +5 -0
- package/dist/application/bench/harness.d.ts.map +1 -0
- package/dist/application/bench/harness.js +82 -0
- package/dist/application/bench/harness.js.map +1 -0
- package/dist/application/dispatcher.d.ts.map +1 -1
- package/dist/application/dispatcher.js +36 -0
- package/dist/application/dispatcher.js.map +1 -1
- package/dist/application/rule-adapters/ast-grep.d.ts +3 -0
- package/dist/application/rule-adapters/ast-grep.d.ts.map +1 -0
- package/dist/application/rule-adapters/ast-grep.js +112 -0
- package/dist/application/rule-adapters/ast-grep.js.map +1 -0
- package/dist/application/rule-adapters/index.d.ts +3 -0
- package/dist/application/rule-adapters/index.d.ts.map +1 -0
- package/dist/application/rule-adapters/index.js +15 -0
- package/dist/application/rule-adapters/index.js.map +1 -0
- package/dist/application/rule-adapters/linter.d.ts +31 -0
- package/dist/application/rule-adapters/linter.d.ts.map +1 -0
- package/dist/application/rule-adapters/linter.js +242 -0
- package/dist/application/rule-adapters/linter.js.map +1 -0
- package/dist/application/rule-adapters/process.d.ts +10 -0
- package/dist/application/rule-adapters/process.d.ts.map +1 -0
- package/dist/application/rule-adapters/process.js +38 -0
- package/dist/application/rule-adapters/process.js.map +1 -0
- package/dist/application/version.d.ts +1 -1
- package/dist/application/version.d.ts.map +1 -1
- package/dist/application/version.js +7 -4
- package/dist/application/version.js.map +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/bench.d.ts +3 -0
- package/dist/commands/bench.d.ts.map +1 -0
- package/dist/commands/bench.js +75 -0
- package/dist/commands/bench.js.map +1 -0
- package/dist/commands/context.d.ts +3 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +56 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +38 -0
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/feature.d.ts.map +1 -1
- package/dist/commands/feature.js +48 -6
- package/dist/commands/feature.js.map +1 -1
- 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 +12 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +12 -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 +19 -8
- package/dist/commands/install.js.map +1 -1
- package/dist/commands/knowledge.d.ts +3 -0
- package/dist/commands/knowledge.d.ts.map +1 -0
- package/dist/commands/knowledge.js +59 -0
- package/dist/commands/knowledge.js.map +1 -0
- package/dist/commands/learning.d.ts +3 -0
- package/dist/commands/learning.d.ts.map +1 -0
- package/dist/commands/learning.js +126 -0
- package/dist/commands/learning.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +26 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/next.d.ts.map +1 -1
- package/dist/commands/next.js +3 -1
- package/dist/commands/next.js.map +1 -1
- package/dist/commands/onboard.d.ts +5 -0
- package/dist/commands/onboard.d.ts.map +1 -0
- package/dist/commands/onboard.js +137 -0
- package/dist/commands/onboard.js.map +1 -0
- 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/routing.d.ts +3 -0
- package/dist/commands/routing.d.ts.map +1 -0
- package/dist/commands/routing.js +107 -0
- package/dist/commands/routing.js.map +1 -0
- package/dist/commands/rules-format.d.ts +4 -0
- package/dist/commands/rules-format.d.ts.map +1 -0
- package/dist/commands/rules-format.js +16 -0
- package/dist/commands/rules-format.js.map +1 -0
- package/dist/commands/rules.d.ts +3 -0
- package/dist/commands/rules.d.ts.map +1 -0
- package/dist/commands/rules.js +270 -0
- package/dist/commands/rules.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/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/verify.d.ts.map +1 -1
- package/dist/commands/verify.js +78 -6
- package/dist/commands/verify.js.map +1 -1
- package/package.json +11 -5
- package/src/application/agent/execution-store.ts +2 -1
- package/src/application/agent/orchestrator.test.ts +39 -0
- package/src/application/agent/orchestrator.ts +8 -1
- package/src/application/agent/providers/claude-code/claude-code-smoke.test.ts +1 -1
- package/src/application/agent/providers/claude-code/permission-config.test.ts +4 -4
- package/src/application/agent/providers/claude-code/permission-config.ts +8 -2
- package/src/application/agent/providers/claude-code/provider.test.ts +2 -2
- package/src/application/agent-tools/dispatch.test.ts +160 -0
- package/src/application/agent-tools/dispatch.ts +227 -0
- package/src/application/agent-tools/mcp-server.test.ts +86 -0
- package/src/application/agent-tools/mcp-server.ts +126 -0
- package/src/application/bench/harness.ts +95 -0
- package/src/application/dispatcher.test.ts +23 -3
- package/src/application/dispatcher.ts +24 -0
- package/src/application/rule-adapters/adapters.test.ts +224 -0
- package/src/application/rule-adapters/ast-grep.ts +126 -0
- package/src/application/rule-adapters/index.ts +16 -0
- package/src/application/rule-adapters/linter-paths.test.ts +95 -0
- package/src/application/rule-adapters/linter.ts +263 -0
- package/src/application/rule-adapters/process.ts +48 -0
- package/src/application/version.ts +9 -4
- 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/bench.test.ts +136 -0
- package/src/commands/bench.ts +74 -0
- package/src/commands/context.test.ts +47 -0
- package/src/commands/context.ts +59 -0
- package/src/commands/doctor-isolation.test.ts +76 -0
- package/src/commands/doctor.test.ts +2 -1
- package/src/commands/doctor.ts +36 -0
- package/src/commands/feature.test.ts +36 -4
- package/src/commands/feature.ts +71 -8
- 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 +12 -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 +25 -8
- package/src/commands/knowledge.test.ts +39 -0
- package/src/commands/knowledge.ts +63 -0
- package/src/commands/learning.test.ts +104 -0
- package/src/commands/learning.ts +134 -0
- package/src/commands/mcp.ts +30 -0
- package/src/commands/next.ts +3 -1
- package/src/commands/onboard.test.ts +83 -0
- package/src/commands/onboard.ts +146 -0
- package/src/commands/plugin-linker.test.ts +80 -0
- package/src/commands/plugin-linker.ts +62 -14
- package/src/commands/routing.test.ts +64 -0
- package/src/commands/routing.ts +107 -0
- package/src/commands/rules-format.ts +22 -0
- package/src/commands/rules.test.ts +153 -0
- package/src/commands/rules.ts +286 -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/uninstall.test.ts +122 -0
- package/src/commands/uninstall.ts +116 -0
- package/src/commands/verify.test.ts +115 -0
- package/src/commands/verify.ts +95 -7
- package/src/commands/version.test.ts +9 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// packages/cli/src/commands/learning.ts
|
|
2
|
+
//
|
|
3
|
+
// `kit learning record|propose|status|migrate-memory` (platform roadmap Phase 6, ADR-0025).
|
|
4
|
+
// record append one privacy-safe LearningEvent from a JSON file
|
|
5
|
+
// propose distill recurring rule violations into memory candidates (never rules)
|
|
6
|
+
// status counts of events and candidates, including expired ones
|
|
7
|
+
// migrate-memory copy legacy MemoryEntry records into the canonical file; keeps the original
|
|
8
|
+
|
|
9
|
+
import { promises as fs } from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import {
|
|
12
|
+
appendLearningEvent,
|
|
13
|
+
distillCandidates,
|
|
14
|
+
expiredCandidates,
|
|
15
|
+
migrateMemoryEntries,
|
|
16
|
+
readEngineeringMemory,
|
|
17
|
+
readLearningEvents,
|
|
18
|
+
writeEngineeringMemory,
|
|
19
|
+
} from '@agentic-sdlc-kit/core';
|
|
20
|
+
import type { EngineeringMemoryEntry, MemoryEntry } from '@agentic-sdlc-kit/contracts';
|
|
21
|
+
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
22
|
+
|
|
23
|
+
const HELP = `Usage: kit learning <record|propose|status|migrate-memory>
|
|
24
|
+
|
|
25
|
+
record --file <event.json> Append one learning event (no free text is accepted).
|
|
26
|
+
propose Propose memory candidates from recurring rule violations.
|
|
27
|
+
status Show event and candidate counts, including expired candidates.
|
|
28
|
+
migrate-memory Copy legacy memory into the canonical file; the original is kept.
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
function flag(argv: readonly string[], name: string): string | undefined {
|
|
32
|
+
const i = argv.indexOf(name);
|
|
33
|
+
return i >= 0 ? argv[i + 1] : undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function record(ctx: CommandContext, root: string): Promise<CommandResult> {
|
|
37
|
+
const file = flag(ctx.argv, '--file');
|
|
38
|
+
if (file === undefined) return fail(ctx, 'record needs --file <event.json>', 2);
|
|
39
|
+
let input: unknown;
|
|
40
|
+
try {
|
|
41
|
+
input = JSON.parse(await fs.readFile(path.resolve(ctx.cwd, file), 'utf8'));
|
|
42
|
+
} catch (cause) {
|
|
43
|
+
return fail(ctx, `cannot read ${file} as JSON: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
44
|
+
}
|
|
45
|
+
const res = await appendLearningEvent(root, input);
|
|
46
|
+
if (!res.ok) return fail(ctx, res.error.message);
|
|
47
|
+
ctx.stdout(`recorded ${res.value.id}\n`);
|
|
48
|
+
return { exitCode: 0 };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function propose(ctx: CommandContext, root: string): Promise<CommandResult> {
|
|
52
|
+
const events = await readLearningEvents(root);
|
|
53
|
+
if (!events.ok) return fail(ctx, events.error.message);
|
|
54
|
+
const existing = await readEngineeringMemory(root);
|
|
55
|
+
if (!existing.ok) return fail(ctx, existing.error.message);
|
|
56
|
+
const known = new Set(existing.value.map((e) => e.id));
|
|
57
|
+
const fresh = distillCandidates(events.value, new Date()).filter((c) => !known.has(c.id));
|
|
58
|
+
const merged: EngineeringMemoryEntry[] = [...existing.value, ...fresh];
|
|
59
|
+
const written = await writeEngineeringMemory(root, merged);
|
|
60
|
+
if (!written.ok) return fail(ctx, written.error.message);
|
|
61
|
+
const expired = expiredCandidates(merged, new Date());
|
|
62
|
+
ctx.stdout(`candidates added: ${fresh.length}; expired and unreviewed: ${expired.length} (kept, never deleted)\n`);
|
|
63
|
+
return { exitCode: 0 };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function status(ctx: CommandContext, root: string): Promise<CommandResult> {
|
|
67
|
+
const events = await readLearningEvents(root);
|
|
68
|
+
if (!events.ok) return fail(ctx, events.error.message);
|
|
69
|
+
const memory = await readEngineeringMemory(root);
|
|
70
|
+
if (!memory.ok) return fail(ctx, memory.error.message);
|
|
71
|
+
const candidates = memory.value.filter((e) => e.tags.includes('candidate'));
|
|
72
|
+
const reviewed = candidates.filter((e) => e.tags.includes('reviewed')).length;
|
|
73
|
+
const expired = expiredCandidates(memory.value, new Date()).length;
|
|
74
|
+
ctx.stdout(
|
|
75
|
+
`events: ${events.value.length}\ncandidates: ${candidates.length} (reviewed ${reviewed}, expired unreviewed ${expired})\n`,
|
|
76
|
+
);
|
|
77
|
+
return { exitCode: 0 };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function migrateMemory(ctx: CommandContext, root: string): Promise<CommandResult> {
|
|
81
|
+
// The legacy store has always been written under <root>/.ai-kit, independent of KIT_STATE_DIR.
|
|
82
|
+
const legacyFile = path.join(root, '.ai-kit', 'state', 'memory.json');
|
|
83
|
+
let legacy: MemoryEntry[];
|
|
84
|
+
try {
|
|
85
|
+
const data = JSON.parse(await fs.readFile(legacyFile, 'utf8')) as { entries?: MemoryEntry[] };
|
|
86
|
+
legacy = Array.isArray(data.entries) ? data.entries : [];
|
|
87
|
+
} catch (cause) {
|
|
88
|
+
if ((cause as { code?: string }).code === 'ENOENT') {
|
|
89
|
+
ctx.stdout('no legacy memory to migrate\n');
|
|
90
|
+
return { exitCode: 0 };
|
|
91
|
+
}
|
|
92
|
+
return fail(ctx, `cannot read the legacy memory file: ${cause instanceof Error ? cause.message : String(cause)}`);
|
|
93
|
+
}
|
|
94
|
+
const existing = await readEngineeringMemory(root);
|
|
95
|
+
if (!existing.ok) return fail(ctx, existing.error.message);
|
|
96
|
+
const known = new Set(existing.value.map((e) => e.id));
|
|
97
|
+
const { entries, lossy } = migrateMemoryEntries(legacy);
|
|
98
|
+
const added = entries.filter((e) => !known.has(e.id));
|
|
99
|
+
const written = await writeEngineeringMemory(root, [...existing.value, ...added]);
|
|
100
|
+
if (!written.ok) return fail(ctx, written.error.message);
|
|
101
|
+
ctx.stdout(`migrated ${added.length} of ${legacy.length} legacy entr${legacy.length === 1 ? 'y' : 'ies'}; the original is kept\n`);
|
|
102
|
+
for (const line of lossy) ctx.stdout(` lossy: ${line}\n`);
|
|
103
|
+
return { exitCode: 0 };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function fail(ctx: CommandContext, message: string, exitCode = 1): CommandResult {
|
|
107
|
+
ctx.stderr(`kit learning: ${message}\n`);
|
|
108
|
+
return { exitCode, message };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const learningCommand: Command = {
|
|
112
|
+
name: 'learning',
|
|
113
|
+
summary: 'Record outcomes, propose memory candidates, and migrate legacy memory (ADR-0025).',
|
|
114
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
115
|
+
const sub = ctx.argv.find((a) => !a.startsWith('-'));
|
|
116
|
+
if (ctx.argv.includes('--help') || ctx.argv.includes('-h') || sub === undefined) {
|
|
117
|
+
ctx.stdout(HELP);
|
|
118
|
+
return { exitCode: sub === undefined && !ctx.argv.includes('--help') ? 2 : 0 };
|
|
119
|
+
}
|
|
120
|
+
const root = path.resolve(ctx.cwd);
|
|
121
|
+
switch (sub) {
|
|
122
|
+
case 'record':
|
|
123
|
+
return record(ctx, root);
|
|
124
|
+
case 'propose':
|
|
125
|
+
return propose(ctx, root);
|
|
126
|
+
case 'status':
|
|
127
|
+
return status(ctx, root);
|
|
128
|
+
case 'migrate-memory':
|
|
129
|
+
return migrateMemory(ctx, root);
|
|
130
|
+
default:
|
|
131
|
+
return fail(ctx, `unknown subcommand "${sub}"\n${HELP}`, 2);
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// packages/cli/src/commands/mcp.ts
|
|
2
|
+
//
|
|
3
|
+
// `kit mcp` serves the agent tool surface (kit_next, kit_phase, kit_status) over
|
|
4
|
+
// the Model Context Protocol on stdio, so a host can call the kit's typed tools
|
|
5
|
+
// instead of shelling out. Stdout carries the protocol only.
|
|
6
|
+
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { serveAgentTools } from '../application/agent-tools/mcp-server.js';
|
|
9
|
+
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
10
|
+
|
|
11
|
+
export const mcpCommand: Command = {
|
|
12
|
+
name: 'mcp',
|
|
13
|
+
summary: 'Serve the agent tool surface over MCP on stdio (kit_next, kit_phase, kit_status).',
|
|
14
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
15
|
+
if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
|
|
16
|
+
ctx.stdout(
|
|
17
|
+
[
|
|
18
|
+
'Usage: kit mcp',
|
|
19
|
+
'',
|
|
20
|
+
'Serve kit_next, kit_phase and kit_status over the Model Context Protocol on',
|
|
21
|
+
'stdio. The working directory is the project. Stdout carries the protocol only.',
|
|
22
|
+
'',
|
|
23
|
+
].join('\n'),
|
|
24
|
+
);
|
|
25
|
+
return { exitCode: 0 };
|
|
26
|
+
}
|
|
27
|
+
await serveAgentTools({ projectRoot: path.resolve(ctx.cwd) });
|
|
28
|
+
return { exitCode: 0 };
|
|
29
|
+
},
|
|
30
|
+
};
|
package/src/commands/next.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
// guess.
|
|
19
19
|
|
|
20
20
|
import path from 'node:path';
|
|
21
|
-
import { computeNextAction, listFeatureRunStates } from '@agentic-sdlc-kit/core';
|
|
21
|
+
import { computeNextAction, listFeatureRunStates, recordNextOffer } from '@agentic-sdlc-kit/core';
|
|
22
22
|
import type { NextAction } from '@agentic-sdlc-kit/contracts';
|
|
23
23
|
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
24
24
|
|
|
@@ -69,6 +69,8 @@ export const nextCommand: Command = {
|
|
|
69
69
|
const res = await computeNextAction({ projectRoot: root, featureId });
|
|
70
70
|
if (!res.ok) return fail(ctx, res.error.message);
|
|
71
71
|
const action = res.value;
|
|
72
|
+
// Trace only: a failed record must not block the protocol answer.
|
|
73
|
+
await recordNextOffer(root, action);
|
|
72
74
|
|
|
73
75
|
if (isJson) {
|
|
74
76
|
ctx.stdout(JSON.stringify(action, null, 2) + '\n');
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// packages/cli/src/commands/onboard.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 { execFile } from 'node:child_process';
|
|
7
|
+
import { promisify } from 'node:util';
|
|
8
|
+
import { onboardCommand } from './onboard.js';
|
|
9
|
+
|
|
10
|
+
const execFileAsync = promisify(execFile);
|
|
11
|
+
import type { CommandContext } from './types.js';
|
|
12
|
+
|
|
13
|
+
function ctx(argv: string[], cwd: string): CommandContext & { out: string[]; err: string[] } {
|
|
14
|
+
const out: string[] = [];
|
|
15
|
+
const err: string[] = [];
|
|
16
|
+
return { argv, cwd, stdout: (s) => void out.push(s), stderr: (s) => void err.push(s), out, err };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let root: string;
|
|
20
|
+
beforeEach(async () => {
|
|
21
|
+
root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-onboard-'));
|
|
22
|
+
await fs.writeFile(path.join(root, 'AGENTS.md'), '- Never commit secrets.\n');
|
|
23
|
+
});
|
|
24
|
+
afterEach(async () => {
|
|
25
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('kit onboard', () => {
|
|
29
|
+
it('without --dry-run refuses outside git and writes nothing', async () => {
|
|
30
|
+
const c = ctx([], root);
|
|
31
|
+
expect((await onboardCommand.run(c)).exitCode).toBe(1);
|
|
32
|
+
expect(c.err.join('')).toContain('git revision');
|
|
33
|
+
await expect(fs.access(path.join(root, '.ai-kit'))).rejects.toThrow();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('without --dry-run inside git adds proposed rules and a baseline', async () => {
|
|
37
|
+
await execFileAsync('git', ['init', '-q'], { cwd: root });
|
|
38
|
+
await execFileAsync('git', ['-c', 'user.email=t@t', '-c', 'user.name=t', 'add', '-A'], { cwd: root });
|
|
39
|
+
await execFileAsync(
|
|
40
|
+
'git',
|
|
41
|
+
['-c', 'user.email=t@t', '-c', 'user.name=t', 'commit', '-q', '--allow-empty', '-m', 'init'],
|
|
42
|
+
{ cwd: root },
|
|
43
|
+
);
|
|
44
|
+
const c = ctx([], root);
|
|
45
|
+
expect((await onboardCommand.run(c)).exitCode).toBe(0);
|
|
46
|
+
const text = c.out.join('');
|
|
47
|
+
expect(text).toContain('proposed rules added');
|
|
48
|
+
expect(text).toContain('Rules written: ONB-AGENT-001');
|
|
49
|
+
const rule = await fs.readFile(path.join(root, '.ai-kit', 'constitution', 'rules', 'ONB-AGENT-001.yml'), 'utf8');
|
|
50
|
+
expect(rule).toContain('mode: off');
|
|
51
|
+
expect(rule).toContain('status: proposed');
|
|
52
|
+
await expect(fs.access(path.join(root, '.ai-kit', 'constitution', 'baseline.json'))).resolves.toBeUndefined();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('--dry-run prints the report and states that nothing was written', async () => {
|
|
56
|
+
const c = ctx(['--dry-run'], root);
|
|
57
|
+
expect((await onboardCommand.run(c)).exitCode).toBe(0);
|
|
58
|
+
const text = c.out.join('');
|
|
59
|
+
expect(text).toContain('Onboarding dry run: nothing was written.');
|
|
60
|
+
expect(text).toContain('Never commit secrets.');
|
|
61
|
+
expect(text).toContain('Files written: 0');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('--dry-run --json emits a report with filesWritten 0', async () => {
|
|
65
|
+
const c = ctx(['--dry-run', '--json'], root);
|
|
66
|
+
expect((await onboardCommand.run(c)).exitCode).toBe(0);
|
|
67
|
+
const parsed = JSON.parse(c.out.join(''));
|
|
68
|
+
expect(parsed.filesWritten).toBe(0);
|
|
69
|
+
expect(parsed.candidates[0].statement).toBe('Never commit secrets.');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('leaves the repository unchanged', async () => {
|
|
73
|
+
const before = await fs.readdir(root);
|
|
74
|
+
await onboardCommand.run(ctx(['--dry-run'], root));
|
|
75
|
+
expect(await fs.readdir(root)).toEqual(before);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('shows help', async () => {
|
|
79
|
+
const c = ctx(['--help'], root);
|
|
80
|
+
expect((await onboardCommand.run(c)).exitCode).toBe(0);
|
|
81
|
+
expect(c.out.join('')).toContain('Usage: kit onboard');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// packages/cli/src/commands/onboard.ts
|
|
2
|
+
//
|
|
3
|
+
// `kit onboard [path] [--dry-run] [--json]` (ADR-0023 §7).
|
|
4
|
+
// Reports the standards a repository already declares (--dry-run writes
|
|
5
|
+
// nothing). Without --dry-run it adds proposed rules under .ai-kit/constitution
|
|
6
|
+
// and records the baseline at the current git revision. It never overwrites.
|
|
7
|
+
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { runOnboardDryRun, writeOnboardProposals } from '@agentic-sdlc-kit/core';
|
|
10
|
+
import type { OnboardReport, OnboardWriteResult } from '@agentic-sdlc-kit/contracts';
|
|
11
|
+
import { constitutionAdapters } from '../application/rule-adapters/index.js';
|
|
12
|
+
import type { Command, CommandContext, CommandResult } from './types.js';
|
|
13
|
+
|
|
14
|
+
const HELP = `Usage: kit onboard [path] [--dry-run] [--json]
|
|
15
|
+
|
|
16
|
+
--dry-run Report the standards this repository already declares. Writes nothing.
|
|
17
|
+
(default) Add proposed rules to .ai-kit/constitution/rules and, if none exists,
|
|
18
|
+
write the baseline pinned to the current git revision. Existing
|
|
19
|
+
rules and baseline are never overwritten. Requires a git commit.
|
|
20
|
+
--json Emit the result as JSON.
|
|
21
|
+
|
|
22
|
+
Proposed rules are status "proposed" and mode "off": they affect nothing until
|
|
23
|
+
a person reviews them and changes their mode.
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
function renderWriteResult(result: OnboardWriteResult): string {
|
|
27
|
+
const list = (ids: readonly string[]): string => (ids.length > 0 ? ids.join(', ') : 'none');
|
|
28
|
+
return [
|
|
29
|
+
'Onboarding write: proposed rules added under .ai-kit/constitution/rules.',
|
|
30
|
+
`Revision: ${result.revision}`,
|
|
31
|
+
`Rules written: ${list(result.rulesWritten)}`,
|
|
32
|
+
`Already proposed: ${list(result.rulesAlreadyProposed)}`,
|
|
33
|
+
`Stale proposals: ${list(result.staleProposals)}`,
|
|
34
|
+
`Baseline: ${result.baseline.status} (${result.baseline.entries} accepted entr${result.baseline.entries === 1 ? 'y' : 'ies'})`,
|
|
35
|
+
'',
|
|
36
|
+
'Review the proposed rules, then change their mode (shadow, advisory or blocking) to enforce them.',
|
|
37
|
+
'',
|
|
38
|
+
].join('\n');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function list(values: readonly string[]): string {
|
|
42
|
+
return values.length > 0 ? values.join(', ') : 'none detected';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function renderSources(report: OnboardReport): string[] {
|
|
46
|
+
if (report.sources.length === 0) return [' none found'];
|
|
47
|
+
return report.sources.map((s) => {
|
|
48
|
+
const state = s.parsed ? 'parsed' : 'not parsed';
|
|
49
|
+
const note = s.note ? ` — ${s.note}` : '';
|
|
50
|
+
return ` ${s.kind.padEnd(18)} ${s.path.padEnd(30)} ${state}${note}`;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function renderCandidates(report: OnboardReport): string[] {
|
|
55
|
+
if (report.candidates.length === 0) return [' none'];
|
|
56
|
+
return report.candidates.map((c) => {
|
|
57
|
+
const at = c.source.line !== undefined ? `:${c.source.line}` : '';
|
|
58
|
+
return ` [${c.kind}] ${c.source.path}${at} ${c.statement}`;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function renderDecisions(report: OnboardReport): string[] {
|
|
63
|
+
if (report.decisions.length === 0) return [' none found'];
|
|
64
|
+
return report.decisions.map((d) => ` ${d.id} ${d.title} (${d.path})`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function renderConflicts(report: OnboardReport): string[] {
|
|
68
|
+
if (report.conflicts.length === 0) return [' none'];
|
|
69
|
+
return report.conflicts.map((c) => ` [${c.kind}] ${c.paths.join(', ')} ${c.detail}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function renderMissingTools(report: OnboardReport): string[] {
|
|
73
|
+
if (report.missingTools.length === 0) return [' none'];
|
|
74
|
+
return report.missingTools.map((t) => ` ${t.tool} (named in ${t.declaredIn})`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function renderNotes(report: OnboardReport): string[] {
|
|
78
|
+
return report.notes.map((n) => ` ${n.severity}: ${n.message}`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function renderOnboardReport(report: OnboardReport): string {
|
|
82
|
+
return [
|
|
83
|
+
'Onboarding dry run: nothing was written.',
|
|
84
|
+
`Revision: ${report.revision ?? 'not a git repository'}`,
|
|
85
|
+
`Stacks: ${list(report.stacks)}`,
|
|
86
|
+
`Package managers: ${list(report.packageManagers)}`,
|
|
87
|
+
`Test frameworks: ${list(report.testFrameworks)}`,
|
|
88
|
+
`CI: ${report.hasCi ? 'yes' : 'no'}`,
|
|
89
|
+
'',
|
|
90
|
+
'Declared sources:',
|
|
91
|
+
...renderSources(report),
|
|
92
|
+
'',
|
|
93
|
+
`Candidate standards (proposed, not enforced): ${report.candidates.length}`,
|
|
94
|
+
...renderCandidates(report),
|
|
95
|
+
'',
|
|
96
|
+
`Decision records: ${report.decisions.length}`,
|
|
97
|
+
...renderDecisions(report),
|
|
98
|
+
'',
|
|
99
|
+
`Declaration conflicts: ${report.conflicts.length}`,
|
|
100
|
+
...renderConflicts(report),
|
|
101
|
+
'',
|
|
102
|
+
'Tools named in configuration but not installed (depends on this machine):',
|
|
103
|
+
...renderMissingTools(report),
|
|
104
|
+
'',
|
|
105
|
+
'Notes:',
|
|
106
|
+
...(report.notes.length > 0 ? renderNotes(report) : [' none']),
|
|
107
|
+
'',
|
|
108
|
+
`Files written: ${report.filesWritten}`,
|
|
109
|
+
'',
|
|
110
|
+
].join('\n');
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function runDryRun(ctx: CommandContext, target: string, json: boolean): Promise<CommandResult> {
|
|
114
|
+
const result = await runOnboardDryRun(target);
|
|
115
|
+
if (!result.ok) {
|
|
116
|
+
ctx.stderr(`kit onboard: ${result.error.message}\n`);
|
|
117
|
+
return { exitCode: 1, message: result.error.message };
|
|
118
|
+
}
|
|
119
|
+
ctx.stdout(json ? `${JSON.stringify(result.value, null, 2)}\n` : renderOnboardReport(result.value));
|
|
120
|
+
return { exitCode: 0 };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
async function runWrite(ctx: CommandContext, target: string, json: boolean): Promise<CommandResult> {
|
|
124
|
+
const result = await writeOnboardProposals(target, { adapters: constitutionAdapters() });
|
|
125
|
+
if (!result.ok) {
|
|
126
|
+
ctx.stderr(`kit onboard: ${result.error.message}\n`);
|
|
127
|
+
return { exitCode: 1, message: result.error.message };
|
|
128
|
+
}
|
|
129
|
+
ctx.stdout(json ? `${JSON.stringify(result.value, null, 2)}\n` : renderWriteResult(result.value));
|
|
130
|
+
return { exitCode: 0 };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const onboardCommand: Command = {
|
|
134
|
+
name: 'onboard',
|
|
135
|
+
summary: 'Report declared standards (--dry-run) or add proposed rules and a baseline.',
|
|
136
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
137
|
+
if (ctx.argv.includes('--help') || ctx.argv.includes('-h')) {
|
|
138
|
+
ctx.stdout(HELP);
|
|
139
|
+
return { exitCode: 0 };
|
|
140
|
+
}
|
|
141
|
+
const target = path.resolve(ctx.cwd, ctx.argv.find((a) => !a.startsWith('-')) ?? '.');
|
|
142
|
+
const json = ctx.argv.includes('--json');
|
|
143
|
+
if (ctx.argv.includes('--dry-run')) return runDryRun(ctx, target, json);
|
|
144
|
+
return runWrite(ctx, target, json);
|
|
145
|
+
},
|
|
146
|
+
};
|
|
@@ -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
|
-
|
|
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
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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: '
|
|
177
|
-
detail: 'path
|
|
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,
|