@agentic-sdlc-kit/cli 0.9.1 → 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/orchestrator.d.ts.map +1 -1
- package/dist/application/agent/orchestrator.js +4 -3
- 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 +24 -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/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/index.d.ts +8 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +8 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +7 -4
- 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/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/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/orchestrator.test.ts +39 -0
- package/src/application/agent/orchestrator.ts +6 -0
- 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 +4 -3
- package/src/application/dispatcher.ts +16 -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/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/index.ts +8 -0
- package/src/commands/install.ts +7 -4
- 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/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/verify.test.ts +115 -0
- package/src/commands/verify.ts +95 -7
- package/src/commands/version.test.ts +9 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// kit learning: record from a file, propose candidates, status, and a non-destructive migration.
|
|
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 { learningCommand } from './learning.js';
|
|
7
|
+
import type { CommandContext } from './types.js';
|
|
8
|
+
|
|
9
|
+
function ctx(argv: string[], cwd: string): CommandContext & { out: string[]; err: string[] } {
|
|
10
|
+
const out: string[] = [];
|
|
11
|
+
const err: string[] = [];
|
|
12
|
+
return { argv, cwd, stdout: (s) => void out.push(s), stderr: (s) => void err.push(s), out, err };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const event = (runId: string) => ({
|
|
16
|
+
schemaVersion: 1,
|
|
17
|
+
id: `ev-${runId}`,
|
|
18
|
+
occurredAt: '2026-11-28T10:00:00.000Z',
|
|
19
|
+
runId,
|
|
20
|
+
taskType: 'feature',
|
|
21
|
+
outcome: 'failed',
|
|
22
|
+
stacks: ['node-typescript'],
|
|
23
|
+
affectedFiles: ['packages/core/src/a.ts'],
|
|
24
|
+
ruleViolations: [{ ruleId: 'ARCH-CORE-001', path: 'packages/core/src/a.ts' }],
|
|
25
|
+
verification: { passed: 1, failed: 1, skipped: 0 },
|
|
26
|
+
durationMs: 10,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
let root: string;
|
|
30
|
+
beforeEach(async () => {
|
|
31
|
+
root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-learning-'));
|
|
32
|
+
});
|
|
33
|
+
afterEach(async () => {
|
|
34
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
async function recordRun(runId: string): Promise<void> {
|
|
38
|
+
const file = path.join(root, `${runId}.json`);
|
|
39
|
+
await fs.writeFile(file, JSON.stringify(event(runId)));
|
|
40
|
+
expect((await learningCommand.run(ctx(['record', '--file', file], root))).exitCode).toBe(0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('kit learning', () => {
|
|
44
|
+
it('record refuses an event with free text and writes nothing', async () => {
|
|
45
|
+
const file = path.join(root, 'bad.json');
|
|
46
|
+
await fs.writeFile(file, JSON.stringify({ ...event('r'), prompt: 'the user said' }));
|
|
47
|
+
const c = ctx(['record', '--file', file], root);
|
|
48
|
+
expect((await learningCommand.run(c)).exitCode).toBe(1);
|
|
49
|
+
expect(c.err.join('')).toContain('validation');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('propose adds candidates only after the recurrence threshold, and status counts them', async () => {
|
|
53
|
+
await recordRun('run-1');
|
|
54
|
+
await recordRun('run-2');
|
|
55
|
+
const early = ctx(['propose'], root);
|
|
56
|
+
await learningCommand.run(early);
|
|
57
|
+
expect(early.out.join('')).toContain('candidates added: 0');
|
|
58
|
+
await recordRun('run-3');
|
|
59
|
+
const p = ctx(['propose'], root);
|
|
60
|
+
await learningCommand.run(p);
|
|
61
|
+
expect(p.out.join('')).toContain('candidates added: 1');
|
|
62
|
+
const s = ctx(['status'], root);
|
|
63
|
+
await learningCommand.run(s);
|
|
64
|
+
expect(s.out.join('')).toContain('events: 3');
|
|
65
|
+
expect(s.out.join('')).toContain('candidates: 1');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('a second propose adds nothing and does not extend a candidate’s expiry', async () => {
|
|
69
|
+
for (const r of ['run-1', 'run-2', 'run-3']) await recordRun(r);
|
|
70
|
+
await learningCommand.run(ctx(['propose'], root));
|
|
71
|
+
const file = path.join(root, '.ai-kit', 'state', 'engineering-memory.json');
|
|
72
|
+
const first = await fs.readFile(file, 'utf8');
|
|
73
|
+
const again = ctx(['propose'], root);
|
|
74
|
+
await learningCommand.run(again);
|
|
75
|
+
expect(again.out.join('')).toContain('candidates added: 0');
|
|
76
|
+
expect(await fs.readFile(file, 'utf8')).toBe(first);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('migrate-memory copies legacy entries, keeps the original file, and is idempotent', async () => {
|
|
80
|
+
const legacyDir = path.join(root, '.ai-kit', 'state');
|
|
81
|
+
await fs.mkdir(legacyDir, { recursive: true });
|
|
82
|
+
const legacy = path.join(legacyDir, 'memory.json');
|
|
83
|
+
const original = JSON.stringify({
|
|
84
|
+
schemaVersion: 1,
|
|
85
|
+
entries: [{
|
|
86
|
+
id: 'mem-1', type: 'semantic', domain: 'billing', summary: 's', content: 'c', confidence: 0.7,
|
|
87
|
+
provenance: ['run-9'], appliedCount: 2, successCount: 1, createdAt: '2026-10-01T00:00:00.000Z', updatedAt: '2026-10-01T00:00:00.000Z',
|
|
88
|
+
}],
|
|
89
|
+
});
|
|
90
|
+
await fs.writeFile(legacy, original);
|
|
91
|
+
const first = ctx(['migrate-memory'], root);
|
|
92
|
+
expect((await learningCommand.run(first)).exitCode).toBe(0);
|
|
93
|
+
expect(first.out.join('')).toContain('migrated 1 of 1');
|
|
94
|
+
expect(first.out.join('')).toContain('lossy:');
|
|
95
|
+
expect(await fs.readFile(legacy, 'utf8')).toBe(original);
|
|
96
|
+
const second = ctx(['migrate-memory'], root);
|
|
97
|
+
await learningCommand.run(second);
|
|
98
|
+
expect(second.out.join('')).toContain('migrated 0 of 1');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('an unknown subcommand is a usage error', async () => {
|
|
102
|
+
expect((await learningCommand.run(ctx(['frobnicate'], root))).exitCode).toBe(2);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { routingCommand } from './routing.js';
|
|
6
|
+
import type { CommandContext } from './types.js';
|
|
7
|
+
|
|
8
|
+
function ctx(argv: string[], cwd: string): CommandContext & { out: string[]; err: string[] } {
|
|
9
|
+
const out: string[] = [];
|
|
10
|
+
const err: string[] = [];
|
|
11
|
+
return { argv, cwd, stdout: (s) => void out.push(s), stderr: (s) => void err.push(s), out, err };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const observation = (i: number, verdict: 'passed' | 'failed') => ({
|
|
15
|
+
schemaVersion: 1,
|
|
16
|
+
id: `obs-${i}`,
|
|
17
|
+
occurredAt: '2026-11-28T10:00:00.000Z',
|
|
18
|
+
taskType: 'feature',
|
|
19
|
+
model: 'model-a',
|
|
20
|
+
effort: 'low',
|
|
21
|
+
verdict,
|
|
22
|
+
tokensIn: 100,
|
|
23
|
+
tokensOut: 50,
|
|
24
|
+
costUnits: 1,
|
|
25
|
+
latencyMs: 900,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
let root: string;
|
|
29
|
+
beforeEach(async () => {
|
|
30
|
+
root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-cli-routing-'));
|
|
31
|
+
});
|
|
32
|
+
afterEach(async () => {
|
|
33
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('kit routing', () => {
|
|
37
|
+
it('refuses an observation with free text and records nothing', async () => {
|
|
38
|
+
const file = path.join(root, 'bad.json');
|
|
39
|
+
await fs.writeFile(file, JSON.stringify({ ...observation(1, 'passed'), prompt: 'secret' }));
|
|
40
|
+
const c = ctx(['observe', '--file', file], root);
|
|
41
|
+
expect((await routingCommand.run(c)).exitCode).toBe(1);
|
|
42
|
+
expect(c.err.join('')).toContain('no free text');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('table marks sparse cells and eligible ones, read-only', async () => {
|
|
46
|
+
const file = path.join(root, 'o.json');
|
|
47
|
+
for (let i = 0; i < 3; i += 1) {
|
|
48
|
+
await fs.writeFile(file, JSON.stringify(observation(i, 'passed')));
|
|
49
|
+
expect((await routingCommand.run(ctx(['observe', '--file', file], root))).exitCode).toBe(0);
|
|
50
|
+
}
|
|
51
|
+
const t = ctx(['table', '--min-samples', '3'], root);
|
|
52
|
+
await routingCommand.run(t);
|
|
53
|
+
expect(t.out.join('')).toContain('eligible');
|
|
54
|
+
const sparse = ctx(['table', '--min-samples', '10'], root);
|
|
55
|
+
await routingCommand.run(sparse);
|
|
56
|
+
expect(sparse.out.join('')).toContain('sparse (<10)');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('an empty table says so', async () => {
|
|
60
|
+
const c = ctx(['table'], root);
|
|
61
|
+
await routingCommand.run(c);
|
|
62
|
+
expect(c.out.join('')).toContain('No routing observations yet');
|
|
63
|
+
});
|
|
64
|
+
});
|