@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,160 @@
|
|
|
1
|
+
// packages/cli/src/application/agent-tools/dispatch.test.ts
|
|
2
|
+
//
|
|
3
|
+
// The typed tool surface a host calls instead of shelling out (item 4). Every
|
|
4
|
+
// tool validates its input against a strict contract schema before it runs,
|
|
5
|
+
// returns a result rather than throwing, and never accepts a command: a phase
|
|
6
|
+
// runs the verification command the plan declares, nothing else.
|
|
7
|
+
import { promises as fs } from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
11
|
+
import { AGENT_TOOL_NAMES } from '@agentic-sdlc-kit/contracts';
|
|
12
|
+
import { callAgentTool } from './dispatch.js';
|
|
13
|
+
|
|
14
|
+
const dirs: string[] = [];
|
|
15
|
+
|
|
16
|
+
async function emptyProject(): Promise<string> {
|
|
17
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-agent-tools-'));
|
|
18
|
+
dirs.push(dir);
|
|
19
|
+
return dir;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
afterEach(async () => {
|
|
23
|
+
for (const dir of dirs.splice(0)) await fs.rm(dir, { recursive: true, force: true });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('agent tool surface', () => {
|
|
27
|
+
it('exposes exactly the three protocol tools', () => {
|
|
28
|
+
expect([...AGENT_TOOL_NAMES]).toEqual([
|
|
29
|
+
'kit_next',
|
|
30
|
+
'kit_phase',
|
|
31
|
+
'kit_status',
|
|
32
|
+
'kit_rules_resolve',
|
|
33
|
+
'kit_rules_evaluate',
|
|
34
|
+
'kit_project_context',
|
|
35
|
+
'kit_rules_explain',
|
|
36
|
+
'kit_adr_search',
|
|
37
|
+
'kit_patterns_search',
|
|
38
|
+
'kit_verification_status',
|
|
39
|
+
'kit_learning_record',
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('refuses an unknown tool name', async () => {
|
|
44
|
+
const root = await emptyProject();
|
|
45
|
+
const res = await callAgentTool('kit_shell', { command: 'rm -rf /' }, { projectRoot: root });
|
|
46
|
+
expect(res.ok).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('refuses a phase request that smuggles in a command', async () => {
|
|
50
|
+
const root = await emptyProject();
|
|
51
|
+
const res = await callAgentTool(
|
|
52
|
+
'kit_phase',
|
|
53
|
+
{ featureId: 'FEATURE-001', taskId: 'TASK-001', phase: 'red', command: 'rm -rf /' },
|
|
54
|
+
{ projectRoot: root },
|
|
55
|
+
);
|
|
56
|
+
expect(res.ok).toBe(false);
|
|
57
|
+
if (!res.ok) expect(res.error).toMatch(/command/);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('refuses a phase outside red, green and refactor', async () => {
|
|
61
|
+
const root = await emptyProject();
|
|
62
|
+
const res = await callAgentTool(
|
|
63
|
+
'kit_phase',
|
|
64
|
+
{ featureId: 'FEATURE-001', taskId: 'TASK-001', phase: 'completed' },
|
|
65
|
+
{ projectRoot: root },
|
|
66
|
+
);
|
|
67
|
+
expect(res.ok).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('answers kit_next with the protocol action, and never throws on odd input', async () => {
|
|
71
|
+
const root = await emptyProject();
|
|
72
|
+
const next = await callAgentTool('kit_next', { featureId: 'FEATURE-001' }, { projectRoot: root });
|
|
73
|
+
expect(next.ok).toBe(true);
|
|
74
|
+
if (next.ok) expect(next.value).toMatchObject({ requiredAction: 'feature.start' });
|
|
75
|
+
|
|
76
|
+
for (const bad of [null, 'text', 42, []]) {
|
|
77
|
+
const res = await callAgentTool('kit_next', bad, { projectRoot: root });
|
|
78
|
+
expect(res.ok).toBe(false);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('reports a missing run as a failed result, not an exception', async () => {
|
|
83
|
+
const root = await emptyProject();
|
|
84
|
+
const status = await callAgentTool('kit_status', { featureId: 'FEATURE-404' }, { projectRoot: root });
|
|
85
|
+
expect(status.ok).toBe(false);
|
|
86
|
+
const phase = await callAgentTool(
|
|
87
|
+
'kit_phase',
|
|
88
|
+
{ featureId: 'FEATURE-404', taskId: 'TASK-001', phase: 'red' },
|
|
89
|
+
{ projectRoot: root },
|
|
90
|
+
);
|
|
91
|
+
expect(phase.ok).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe('constitution tools (ADR-0023, read-only)', () => {
|
|
96
|
+
it('kit_rules_resolve rejects unknown keys (no commands in tool input)', async () => {
|
|
97
|
+
const res = await callAgentTool(
|
|
98
|
+
'kit_rules_resolve',
|
|
99
|
+
{ files: ['a.ts'], command: ['rm', '-rf', '/'] },
|
|
100
|
+
{ projectRoot: '/nonexistent-kit-root' },
|
|
101
|
+
);
|
|
102
|
+
expect(res.ok).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('kit_rules_resolve requires at least one file', async () => {
|
|
106
|
+
const res = await callAgentTool('kit_rules_resolve', { files: [] }, { projectRoot: '/nonexistent-kit-root' });
|
|
107
|
+
expect(res.ok).toBe(false);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('kit_rules_evaluate reports an absent constitution as an explicit passing state', async () => {
|
|
111
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-dispatch-rules-'));
|
|
112
|
+
try {
|
|
113
|
+
const res = await callAgentTool('kit_rules_evaluate', {}, { projectRoot: root });
|
|
114
|
+
expect(res).toEqual({
|
|
115
|
+
ok: true,
|
|
116
|
+
value: { rulesDirPresent: false, results: [], gate: 'passed' },
|
|
117
|
+
});
|
|
118
|
+
} finally {
|
|
119
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('context tools (read-only)', () => {
|
|
125
|
+
it('kit_adr_search finds decision records by title', async () => {
|
|
126
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-dispatch-adr-'));
|
|
127
|
+
try {
|
|
128
|
+
await fs.mkdir(path.join(root, 'docs', 'adr'), { recursive: true });
|
|
129
|
+
await fs.writeFile(path.join(root, 'docs', 'adr', 'ADR-0007-use-postgres.md'), '# ADR-0007: Use PostgreSQL\n');
|
|
130
|
+
const res = await callAgentTool('kit_adr_search', { query: 'postgres' }, { projectRoot: root });
|
|
131
|
+
expect(res.ok && res.value).toEqual({
|
|
132
|
+
decisions: [{ id: 'ADR-0007', title: 'Use PostgreSQL', path: 'docs/adr/ADR-0007-use-postgres.md' }],
|
|
133
|
+
});
|
|
134
|
+
} finally {
|
|
135
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('kit_verification_status reports null when nothing was recorded', async () => {
|
|
140
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-dispatch-verify-'));
|
|
141
|
+
try {
|
|
142
|
+
expect(await callAgentTool('kit_verification_status', {}, { projectRoot: root })).toEqual({
|
|
143
|
+
ok: true,
|
|
144
|
+
value: { report: null },
|
|
145
|
+
});
|
|
146
|
+
} finally {
|
|
147
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('kit_project_context rejects unknown keys (no commands in tool input)', async () => {
|
|
152
|
+
const res = await callAgentTool('kit_project_context', { files: [], command: ['rm'] }, { projectRoot: '/x' });
|
|
153
|
+
expect(res.ok).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('kit_rules_explain rejects a malformed rule id before touching the filesystem', async () => {
|
|
157
|
+
const res = await callAgentTool('kit_rules_explain', { ruleId: '../../etc' }, { projectRoot: '/x' });
|
|
158
|
+
expect(res.ok).toBe(false);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// packages/cli/src/application/agent-tools/dispatch.ts
|
|
2
|
+
//
|
|
3
|
+
// Dispatches one typed agent tool call (item 4) to the core workflow APIs.
|
|
4
|
+
// Every call is validated against its contract schema first. Every outcome is
|
|
5
|
+
// a result, never an exception, so a host can act on any answer.
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
AGENT_TOOL_NAMES,
|
|
9
|
+
KitNextInputSchema,
|
|
10
|
+
KitPhaseInputSchema,
|
|
11
|
+
KitProjectContextInputSchema,
|
|
12
|
+
KitRulesEvaluateInputSchema,
|
|
13
|
+
KitRulesExplainInputSchema,
|
|
14
|
+
KitRulesResolveInputSchema,
|
|
15
|
+
KitSearchInputSchema,
|
|
16
|
+
KitStatusInputSchema,
|
|
17
|
+
KitLearningRecordInputSchema,
|
|
18
|
+
KitVerificationStatusInputSchema,
|
|
19
|
+
type AgentToolName,
|
|
20
|
+
} from '@agentic-sdlc-kit/contracts';
|
|
21
|
+
import {
|
|
22
|
+
computeNextAction,
|
|
23
|
+
evaluateConstitution,
|
|
24
|
+
explainRule,
|
|
25
|
+
getFeatureRunState,
|
|
26
|
+
appendLearningEvent,
|
|
27
|
+
listDecisionRecords,
|
|
28
|
+
listRepoFiles,
|
|
29
|
+
loadPatterns,
|
|
30
|
+
loadRules,
|
|
31
|
+
profileStacks,
|
|
32
|
+
projectContext,
|
|
33
|
+
readLastVerify,
|
|
34
|
+
recordNextOffer,
|
|
35
|
+
resolveRules,
|
|
36
|
+
runTddPhase,
|
|
37
|
+
} from '@agentic-sdlc-kit/core';
|
|
38
|
+
|
|
39
|
+
import { constitutionAdapters } from '../rule-adapters/index.js';
|
|
40
|
+
|
|
41
|
+
const SEARCH_LIMIT = 25;
|
|
42
|
+
|
|
43
|
+
function matches(query: string | undefined, fields: readonly string[]): boolean {
|
|
44
|
+
if (query === undefined || query.trim() === '') return true;
|
|
45
|
+
const needle = query.toLowerCase();
|
|
46
|
+
return fields.some((f) => f.toLowerCase().includes(needle));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type AgentToolResult =
|
|
50
|
+
| { readonly ok: true; readonly value: unknown }
|
|
51
|
+
| { readonly ok: false; readonly error: string };
|
|
52
|
+
|
|
53
|
+
export interface AgentToolContext {
|
|
54
|
+
readonly projectRoot: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The host calling a tool is an agent. The kit records it as such.
|
|
58
|
+
const ACTOR = { kind: 'agent' } as const;
|
|
59
|
+
|
|
60
|
+
function fail(error: string): AgentToolResult {
|
|
61
|
+
return { ok: false, error };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function messageOf(err: unknown): string {
|
|
65
|
+
return err instanceof Error ? err.message : String(err);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function kitNext(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
69
|
+
const parsed = KitNextInputSchema.safeParse(input);
|
|
70
|
+
if (!parsed.success) return fail(`invalid input for kit_next: ${parsed.error.message}`);
|
|
71
|
+
const res = await computeNextAction({ projectRoot: ctx.projectRoot, featureId: parsed.data.featureId });
|
|
72
|
+
if (!res.ok) return fail(res.error.message);
|
|
73
|
+
await recordNextOffer(ctx.projectRoot, res.value);
|
|
74
|
+
return { ok: true, value: res.value };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function kitPhase(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
78
|
+
const parsed = KitPhaseInputSchema.safeParse(input);
|
|
79
|
+
if (!parsed.success) return fail(`invalid input for kit_phase: ${parsed.error.message}`);
|
|
80
|
+
const { featureId, taskId, phase } = parsed.data;
|
|
81
|
+
const res = await runTddPhase({ featureId, projectRoot: ctx.projectRoot, taskId, phase, actor: ACTOR });
|
|
82
|
+
if (!res.ok) return fail(res.error.message);
|
|
83
|
+
return { ok: true, value: { featureId, taskId, phase, phaseNow: res.value.tasks[taskId]?.phase ?? null } };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function kitStatus(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
87
|
+
const parsed = KitStatusInputSchema.safeParse(input);
|
|
88
|
+
if (!parsed.success) return fail(`invalid input for kit_status: ${parsed.error.message}`);
|
|
89
|
+
const res = await getFeatureRunState(ctx.projectRoot, parsed.data.featureId);
|
|
90
|
+
if (!res.ok) return fail(res.error.message);
|
|
91
|
+
const tasks = Object.values(res.value.tasks).map((t) => ({
|
|
92
|
+
taskId: t.taskId,
|
|
93
|
+
phase: t.phase,
|
|
94
|
+
attempts: t.records.length,
|
|
95
|
+
}));
|
|
96
|
+
return { ok: true, value: { featureId: parsed.data.featureId, tasks } };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async function kitRulesResolve(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
100
|
+
const parsed = KitRulesResolveInputSchema.safeParse(input);
|
|
101
|
+
if (!parsed.success) return fail(`invalid input for kit_rules_resolve: ${parsed.error.message}`);
|
|
102
|
+
const loaded = await loadRules(ctx.projectRoot);
|
|
103
|
+
if (!loaded.ok) return fail(loaded.error.message);
|
|
104
|
+
const stacks = parsed.data.stacks ?? (await profileStacks(ctx.projectRoot));
|
|
105
|
+
const resolved = resolveRules(loaded.value.rules.map((l) => l.rule), { files: parsed.data.files, stacks });
|
|
106
|
+
if (!resolved.ok) return fail(resolved.error.message);
|
|
107
|
+
return {
|
|
108
|
+
ok: true,
|
|
109
|
+
value: {
|
|
110
|
+
rules: resolved.value.map((r) => ({
|
|
111
|
+
ruleId: r.rule.id,
|
|
112
|
+
title: r.rule.title,
|
|
113
|
+
statement: r.rule.statement,
|
|
114
|
+
mode: r.rule.mode,
|
|
115
|
+
matchedFiles: r.matchedFiles,
|
|
116
|
+
})),
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function kitRulesEvaluate(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
122
|
+
const parsed = KitRulesEvaluateInputSchema.safeParse(input);
|
|
123
|
+
if (!parsed.success) return fail(`invalid input for kit_rules_evaluate: ${parsed.error.message}`);
|
|
124
|
+
const stacks = parsed.data.stacks ?? (await profileStacks(ctx.projectRoot));
|
|
125
|
+
let files = parsed.data.files;
|
|
126
|
+
if (files === undefined) {
|
|
127
|
+
const listed = await listRepoFiles(ctx.projectRoot);
|
|
128
|
+
if (!listed.ok) return fail(listed.error.message);
|
|
129
|
+
files = listed.value;
|
|
130
|
+
}
|
|
131
|
+
const evaluation = await evaluateConstitution({
|
|
132
|
+
projectRoot: ctx.projectRoot,
|
|
133
|
+
stacks,
|
|
134
|
+
files,
|
|
135
|
+
adapters: constitutionAdapters(),
|
|
136
|
+
});
|
|
137
|
+
if (!evaluation.ok) return fail(evaluation.error.message);
|
|
138
|
+
return { ok: true, value: evaluation.value };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function kitProjectContext(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
142
|
+
const parsed = KitProjectContextInputSchema.safeParse(input);
|
|
143
|
+
if (!parsed.success) return fail(`invalid input for kit_project_context: ${parsed.error.message}`);
|
|
144
|
+
const res = await projectContext(ctx.projectRoot, { ...parsed.data, adapters: constitutionAdapters() });
|
|
145
|
+
return res.ok ? { ok: true, value: res.value } : fail(res.error.message);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async function kitRulesExplain(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
149
|
+
const parsed = KitRulesExplainInputSchema.safeParse(input);
|
|
150
|
+
if (!parsed.success) return fail(`invalid input for kit_rules_explain: ${parsed.error.message}`);
|
|
151
|
+
const res = await explainRule(ctx.projectRoot, parsed.data.ruleId);
|
|
152
|
+
return res.ok ? { ok: true, value: res.value } : fail(res.error.message);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function kitAdrSearch(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
156
|
+
const parsed = KitSearchInputSchema.safeParse(input);
|
|
157
|
+
if (!parsed.success) return fail(`invalid input for kit_adr_search: ${parsed.error.message}`);
|
|
158
|
+
const records = await listDecisionRecords(ctx.projectRoot);
|
|
159
|
+
const hits = records
|
|
160
|
+
.filter((r) => matches(parsed.data.query, [r.id, r.title]))
|
|
161
|
+
.slice(0, SEARCH_LIMIT);
|
|
162
|
+
return { ok: true, value: { decisions: hits } };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function kitPatternsSearch(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
166
|
+
const parsed = KitSearchInputSchema.safeParse(input);
|
|
167
|
+
if (!parsed.success) return fail(`invalid input for kit_patterns_search: ${parsed.error.message}`);
|
|
168
|
+
const loaded = await loadPatterns(ctx.projectRoot);
|
|
169
|
+
if (!loaded.ok) return fail(loaded.error.message);
|
|
170
|
+
const hits = loaded.value
|
|
171
|
+
.filter((p) => matches(parsed.data.query, [p.id, p.name, p.problem]))
|
|
172
|
+
.slice(0, SEARCH_LIMIT)
|
|
173
|
+
.map((p) => ({ id: p.id, name: p.name, problem: p.problem, whenToUse: p.whenToUse }));
|
|
174
|
+
return { ok: true, value: { patterns: hits } };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function kitLearningRecord(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
178
|
+
const parsed = KitLearningRecordInputSchema.safeParse(input);
|
|
179
|
+
if (!parsed.success) return fail(`invalid input for kit_learning_record: ${parsed.error.message}`);
|
|
180
|
+
const res = await appendLearningEvent(ctx.projectRoot, parsed.data);
|
|
181
|
+
return res.ok ? { ok: true, value: { recorded: res.value.id } } : fail(res.error.message);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
async function kitVerificationStatus(input: unknown, ctx: AgentToolContext): Promise<AgentToolResult> {
|
|
185
|
+
const parsed = KitVerificationStatusInputSchema.safeParse(input);
|
|
186
|
+
if (!parsed.success) return fail(`invalid input for kit_verification_status: ${parsed.error.message}`);
|
|
187
|
+
const res = await readLastVerify(ctx.projectRoot);
|
|
188
|
+
return res.ok ? { ok: true, value: { report: res.value } } : fail(res.error.message);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export async function callAgentTool(
|
|
192
|
+
name: unknown,
|
|
193
|
+
input: unknown,
|
|
194
|
+
ctx: AgentToolContext,
|
|
195
|
+
): Promise<AgentToolResult> {
|
|
196
|
+
try {
|
|
197
|
+
if (typeof name !== 'string' || !(AGENT_TOOL_NAMES as readonly string[]).includes(name)) {
|
|
198
|
+
return fail(`unknown tool '${String(name)}'`);
|
|
199
|
+
}
|
|
200
|
+
switch (name as AgentToolName) {
|
|
201
|
+
case 'kit_next':
|
|
202
|
+
return await kitNext(input, ctx);
|
|
203
|
+
case 'kit_phase':
|
|
204
|
+
return await kitPhase(input, ctx);
|
|
205
|
+
case 'kit_status':
|
|
206
|
+
return await kitStatus(input, ctx);
|
|
207
|
+
case 'kit_rules_resolve':
|
|
208
|
+
return await kitRulesResolve(input, ctx);
|
|
209
|
+
case 'kit_rules_evaluate':
|
|
210
|
+
return await kitRulesEvaluate(input, ctx);
|
|
211
|
+
case 'kit_project_context':
|
|
212
|
+
return await kitProjectContext(input, ctx);
|
|
213
|
+
case 'kit_rules_explain':
|
|
214
|
+
return await kitRulesExplain(input, ctx);
|
|
215
|
+
case 'kit_adr_search':
|
|
216
|
+
return await kitAdrSearch(input, ctx);
|
|
217
|
+
case 'kit_patterns_search':
|
|
218
|
+
return await kitPatternsSearch(input, ctx);
|
|
219
|
+
case 'kit_verification_status':
|
|
220
|
+
return await kitVerificationStatus(input, ctx);
|
|
221
|
+
case 'kit_learning_record':
|
|
222
|
+
return await kitLearningRecord(input, ctx);
|
|
223
|
+
}
|
|
224
|
+
} catch (err) {
|
|
225
|
+
return fail(messageOf(err));
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// packages/cli/src/application/agent-tools/mcp-server.test.ts
|
|
2
|
+
//
|
|
3
|
+
// The typed tool surface served over the Model Context Protocol (item 4). The
|
|
4
|
+
// tests run a real MCP client against the server over the SDK's in-memory
|
|
5
|
+
// transport, so they exercise the protocol path a host uses, not just the
|
|
6
|
+
// dispatcher underneath it.
|
|
7
|
+
import { promises as fs } from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
11
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
12
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
13
|
+
import { createAgentToolServer } from './mcp-server.js';
|
|
14
|
+
|
|
15
|
+
const dirs: string[] = [];
|
|
16
|
+
|
|
17
|
+
afterEach(async () => {
|
|
18
|
+
for (const dir of dirs.splice(0)) await fs.rm(dir, { recursive: true, force: true });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
async function connectedClient(): Promise<Client> {
|
|
22
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'kit-mcp-'));
|
|
23
|
+
dirs.push(root);
|
|
24
|
+
const server = createAgentToolServer({ projectRoot: root });
|
|
25
|
+
const [serverSide, clientSide] = InMemoryTransport.createLinkedPair();
|
|
26
|
+
await server.connect(serverSide);
|
|
27
|
+
const client = new Client({ name: 'kit-mcp-test', version: '0.0.0' });
|
|
28
|
+
await client.connect(clientSide);
|
|
29
|
+
return client;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function textOf(result: unknown): string {
|
|
33
|
+
const content = (result as { content?: Array<{ type: string; text?: string }> }).content ?? [];
|
|
34
|
+
return content.map((c) => c.text ?? '').join('');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('agent tool MCP server', () => {
|
|
38
|
+
it('lists the three protocol tools, each with a strict input schema', async () => {
|
|
39
|
+
const client = await connectedClient();
|
|
40
|
+
const { tools } = await client.listTools();
|
|
41
|
+
expect(tools.map((t) => t.name).sort()).toEqual([
|
|
42
|
+
'kit_adr_search',
|
|
43
|
+
'kit_learning_record',
|
|
44
|
+
'kit_next',
|
|
45
|
+
'kit_patterns_search',
|
|
46
|
+
'kit_phase',
|
|
47
|
+
'kit_project_context',
|
|
48
|
+
'kit_rules_evaluate',
|
|
49
|
+
'kit_rules_explain',
|
|
50
|
+
'kit_rules_resolve',
|
|
51
|
+
'kit_status',
|
|
52
|
+
'kit_verification_status',
|
|
53
|
+
]);
|
|
54
|
+
const phase = tools.find((t) => t.name === 'kit_phase');
|
|
55
|
+
expect(phase?.inputSchema.additionalProperties).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('answers kit_next with the protocol action over the wire', async () => {
|
|
59
|
+
const client = await connectedClient();
|
|
60
|
+
const result = await client.callTool({ name: 'kit_next', arguments: { featureId: 'FEATURE-001' } });
|
|
61
|
+
expect(result.isError).toBeFalsy();
|
|
62
|
+
expect(JSON.parse(textOf(result))).toMatchObject({ requiredAction: 'feature.start' });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('refuses a kit_phase call that carries a command, and runs nothing', async () => {
|
|
66
|
+
const client = await connectedClient();
|
|
67
|
+
const outcome = await client
|
|
68
|
+
.callTool({
|
|
69
|
+
name: 'kit_phase',
|
|
70
|
+
arguments: { featureId: 'FEATURE-001', taskId: 'TASK-001', phase: 'red', command: 'rm -rf /' },
|
|
71
|
+
})
|
|
72
|
+
.then(
|
|
73
|
+
(r) => (r.isError ? 'error' : 'ok'),
|
|
74
|
+
() => 'error',
|
|
75
|
+
);
|
|
76
|
+
expect(outcome).toBe('error');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('reports a missing run as a tool error, not a success', async () => {
|
|
80
|
+
const client = await connectedClient();
|
|
81
|
+
const outcome = await client
|
|
82
|
+
.callTool({ name: 'kit_status', arguments: { featureId: 'FEATURE-404' } })
|
|
83
|
+
.then((r) => (r.isError ? 'error' : 'ok'), () => 'error');
|
|
84
|
+
expect(outcome).toBe('error');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// packages/cli/src/application/agent-tools/mcp-server.ts
|
|
2
|
+
//
|
|
3
|
+
// Serves the agent tool surface over the Model Context Protocol (item 4).
|
|
4
|
+
//
|
|
5
|
+
// Each tool's input schema is the strict contract schema, so the protocol layer
|
|
6
|
+
// refuses an unrecognized key before any handler runs. The handler then calls
|
|
7
|
+
// callAgentTool, which validates the same schema again, so the two layers agree.
|
|
8
|
+
// stdout carries the protocol only, so nothing here writes to it.
|
|
9
|
+
|
|
10
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
11
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
12
|
+
import {
|
|
13
|
+
KitNextInputSchema,
|
|
14
|
+
KitPhaseInputSchema,
|
|
15
|
+
KitProjectContextInputSchema,
|
|
16
|
+
KitRulesEvaluateInputSchema,
|
|
17
|
+
KitRulesExplainInputSchema,
|
|
18
|
+
KitRulesResolveInputSchema,
|
|
19
|
+
KitSearchInputSchema,
|
|
20
|
+
KitStatusInputSchema,
|
|
21
|
+
KitVerificationStatusInputSchema,
|
|
22
|
+
KitLearningRecordInputSchema,
|
|
23
|
+
} from '@agentic-sdlc-kit/contracts';
|
|
24
|
+
import { VERSION } from '../version.js';
|
|
25
|
+
import { callAgentTool, type AgentToolContext } from './dispatch.js';
|
|
26
|
+
|
|
27
|
+
const TOOLS = [
|
|
28
|
+
{
|
|
29
|
+
name: 'kit_next',
|
|
30
|
+
description:
|
|
31
|
+
'The next protocol action for a feature run: what to do, against which task, and feedback on the last rejected attempt when one applies.',
|
|
32
|
+
inputSchema: KitNextInputSchema,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'kit_phase',
|
|
36
|
+
description:
|
|
37
|
+
"Run one TDD phase (red, green or refactor) for a task. The kit runs the plan's own verification command and records the verdict. It never accepts a command.",
|
|
38
|
+
inputSchema: KitPhaseInputSchema,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'kit_status',
|
|
42
|
+
description: 'The state of each task in a feature run: its phase and how many attempts it has had.',
|
|
43
|
+
inputSchema: KitStatusInputSchema,
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'kit_rules_resolve',
|
|
47
|
+
description:
|
|
48
|
+
'The engineering rules that apply to the given repository-relative files, with the files each rule matched. Read-only.',
|
|
49
|
+
inputSchema: KitRulesResolveInputSchema,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'kit_rules_evaluate',
|
|
53
|
+
description:
|
|
54
|
+
'Evaluate the project constitution (ADR-0023) over the given files, or the whole repository. Returns per-rule outcomes and the gate status. Read-only.',
|
|
55
|
+
inputSchema: KitRulesEvaluateInputSchema,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'kit_project_context',
|
|
59
|
+
description:
|
|
60
|
+
'Task-scoped project context for the given files: applicable rules, the constitution gate, patterns, decision titles and the last verification. Read-only.',
|
|
61
|
+
inputSchema: KitProjectContextInputSchema,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'kit_rules_explain',
|
|
65
|
+
description:
|
|
66
|
+
'One engineering rule: its statement, scope, where it came from in git history, and what it applies to. Read-only.',
|
|
67
|
+
inputSchema: KitRulesExplainInputSchema,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'kit_adr_search',
|
|
71
|
+
description: 'Architecture decision records whose id or title matches the query. Read-only.',
|
|
72
|
+
inputSchema: KitSearchInputSchema,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
name: 'kit_patterns_search',
|
|
76
|
+
description: 'Project design patterns whose id, name or problem matches the query. Read-only.',
|
|
77
|
+
inputSchema: KitSearchInputSchema,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'kit_verification_status',
|
|
81
|
+
description: 'The most recent recorded kit verify report in this checkout, or null. Read-only.',
|
|
82
|
+
inputSchema: KitVerificationStatusInputSchema,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'kit_learning_record',
|
|
86
|
+
description:
|
|
87
|
+
'Record one privacy-safe learning event: outcome, identifiers, repository paths and counts. Free text is refused by the schema. Writes to the kit state directory.',
|
|
88
|
+
inputSchema: KitLearningRecordInputSchema,
|
|
89
|
+
},
|
|
90
|
+
] as const;
|
|
91
|
+
|
|
92
|
+
function textResult(text: string, isError: boolean) {
|
|
93
|
+
return { content: [{ type: 'text' as const, text }], isError };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function createAgentToolServer(ctx: AgentToolContext): McpServer {
|
|
97
|
+
const server = new McpServer({ name: 'agentic-sdlc-kit', version: VERSION });
|
|
98
|
+
for (const tool of TOOLS) {
|
|
99
|
+
server.registerTool(
|
|
100
|
+
tool.name,
|
|
101
|
+
{ description: tool.description, inputSchema: tool.inputSchema },
|
|
102
|
+
async (args: unknown) => {
|
|
103
|
+
const result = await callAgentTool(tool.name, args, ctx);
|
|
104
|
+
return result.ok
|
|
105
|
+
? textResult(JSON.stringify(result.value, null, 2), false)
|
|
106
|
+
: textResult(result.error, true);
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return server;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Serve the tools on stdio until the host closes the connection. The promise
|
|
115
|
+
* resolves on close, not on connect: the CLI exits as soon as a command's
|
|
116
|
+
* promise settles, which would end the session before any request arrives.
|
|
117
|
+
*/
|
|
118
|
+
export function serveAgentTools(ctx: AgentToolContext): Promise<void> {
|
|
119
|
+
const server = createAgentToolServer(ctx);
|
|
120
|
+
const transport = new StdioServerTransport();
|
|
121
|
+
return new Promise<void>((resolve, reject) => {
|
|
122
|
+
transport.onclose = () => resolve();
|
|
123
|
+
transport.onerror = (err) => reject(err);
|
|
124
|
+
server.connect(transport).catch(reject);
|
|
125
|
+
});
|
|
126
|
+
}
|