agent-kb 0.1.0
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/LICENSE +19 -0
- package/README.md +139 -0
- package/dist/api/index.d.ts +756 -0
- package/dist/api/index.js +8 -0
- package/dist/chunk-I77A4URT.js +5963 -0
- package/dist/cli/index.d.ts +84 -0
- package/dist/cli/index.js +1022 -0
- package/package.json +68 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { AgentKbEngine, OpenKbDeps, OpenedKb, Config } from '../api/index.js';
|
|
3
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* MCP server construction (T23, T38, T40).
|
|
7
|
+
*
|
|
8
|
+
* `createMcpServer` is the config-gated entry point: it throws `FEATURE_DISABLED`
|
|
9
|
+
* when `opts.mcpEnabled` is false, and otherwise constructs a `McpServer` with
|
|
10
|
+
* the 16 tools registered. The server holds NO state — every tool call is routed
|
|
11
|
+
* straight to the engine passed in.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface CreateMcpServerOpts {
|
|
15
|
+
engine: AgentKbEngine;
|
|
16
|
+
mcpEnabled: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* `agent-kb mcp` — config-gated stdio MCP launcher.
|
|
21
|
+
*
|
|
22
|
+
* Transport layer ONLY (mirrors `src/cli/index.ts`'s charter). This module wires
|
|
23
|
+
* the SDK's `StdioServerTransport` to the existing `createMcpServer`, so the MCP
|
|
24
|
+
* transport becomes reachable via `npx agent-kb mcp`. No business logic lives
|
|
25
|
+
* here — gating + tool definitions belong to `@/config` and `@/mcp`.
|
|
26
|
+
*
|
|
27
|
+
* `runMcp` is async (the stdio transport keeps the event loop alive until the
|
|
28
|
+
* client disconnects), unlike the synchronous `runCli`. All side-effecting
|
|
29
|
+
* collaborators (openKb / loadConfig / createServer / connect) are injectable so
|
|
30
|
+
* the launcher is fully unit-testable without touching real stdio.
|
|
31
|
+
*
|
|
32
|
+
* Dependency direction: this file imports `@/mcp` (which transitively pulls the
|
|
33
|
+
* SDK into `dist/cli/index.js` via tsup). It MUST NOT import `@/cli/index` — the
|
|
34
|
+
* router (`main`) lives there and imports from here, keeping the edge one-way.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
interface RunMcpDeps {
|
|
38
|
+
openKb?: (deps: OpenKbDeps) => OpenedKb;
|
|
39
|
+
loadConfig?: (root: string) => Config;
|
|
40
|
+
createServer?: (opts: CreateMcpServerOpts) => McpServer;
|
|
41
|
+
connect?: (server: McpServer) => Promise<void>;
|
|
42
|
+
out?: NodeJS.WritableStream;
|
|
43
|
+
err?: NodeJS.WritableStream;
|
|
44
|
+
cwd?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Agent KB CLI — T22
|
|
49
|
+
*
|
|
50
|
+
* Transport layer ONLY. Each subcommand maps to exactly ONE engine method.
|
|
51
|
+
* No business logic lives here — it's all in the engine.
|
|
52
|
+
*
|
|
53
|
+
* Convention: `from: 'node'` — argv is expected to include the node executable
|
|
54
|
+
* and script name as the first two entries (i.e. full process.argv). Tests pass
|
|
55
|
+
* `['node', 'agent-kb', ...]`.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
interface RunCliDeps {
|
|
59
|
+
openKb?: (deps: OpenKbDeps) => OpenedKb;
|
|
60
|
+
out?: NodeJS.WritableStream;
|
|
61
|
+
err?: NodeJS.WritableStream;
|
|
62
|
+
cwd?: string;
|
|
63
|
+
/**
|
|
64
|
+
* Override `os.homedir()` — inject a temp path in tests to avoid writing to
|
|
65
|
+
* the real ~/.claude when testing global skill installation.
|
|
66
|
+
*/
|
|
67
|
+
homedir?: () => string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Build and run the CLI. Returns the exit code — does NOT call process.exit.
|
|
71
|
+
* argv is expected in full node form: ['node', 'agent-kb', ...args].
|
|
72
|
+
*/
|
|
73
|
+
declare function runCli(argv: string[], deps?: RunCliDeps): number;
|
|
74
|
+
/**
|
|
75
|
+
* Async entry router. Routes a `mcp` invocation to the async `runMcp` launcher
|
|
76
|
+
* (which wires the stdio transport and runs until the client disconnects); every
|
|
77
|
+
* other invocation goes to the synchronous `runCli`. argv is full node form.
|
|
78
|
+
*
|
|
79
|
+
* Returns an exit code — does NOT call process.exit. `runCli` stays synchronous;
|
|
80
|
+
* this wrapper simply lifts its result into the Promise the `mcp` path needs.
|
|
81
|
+
*/
|
|
82
|
+
declare function main(argv: string[], deps?: RunMcpDeps): Promise<number>;
|
|
83
|
+
|
|
84
|
+
export { type RunCliDeps, main, runCli };
|