@shardworks/claude-code-apparatus 0.1.183 → 0.1.185
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/README.md +1 -19
- package/dist/detached.d.ts +5 -4
- package/dist/detached.d.ts.map +1 -1
- package/dist/detached.js +69 -53
- package/dist/detached.js.map +1 -1
- package/dist/index.d.ts +6 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -338
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/dist/mcp-server.d.ts +0 -61
- package/dist/mcp-server.d.ts.map +0 -1
- package/dist/mcp-server.js +0 -155
- package/dist/mcp-server.js.map +0 -1
package/README.md
CHANGED
|
@@ -37,24 +37,6 @@ The provider implements `launch()` and `cancel()`:
|
|
|
37
37
|
- `processInfo` polls the SessionDoc for `cancelMetadata.pid` (set by the babysitter via `session-running`)
|
|
38
38
|
- **`cancel(cancelMetadata)`** — sends SIGTERM to the claude process using the PID from `cancelMetadata`. Works cross-process regardless of parent-child relationships.
|
|
39
39
|
|
|
40
|
-
An **attached mode** (`launchAttached()`) is preserved as an internal export for debugging — it spawns claude as a direct child process with in-process MCP server and streaming.
|
|
41
|
-
|
|
42
|
-
### MCP Server
|
|
43
|
-
|
|
44
|
-
The package exports functions for running MCP tool servers:
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { createMcpServer, startMcpHttpServer } from '@shardworks/claude-code-apparatus';
|
|
48
|
-
|
|
49
|
-
// Create an MCP server with resolved tool definitions
|
|
50
|
-
const mcpServer = await createMcpServer(toolDefinitions);
|
|
51
|
-
|
|
52
|
-
// Or start an HTTP server on an ephemeral port
|
|
53
|
-
const handle = await startMcpHttpServer(toolDefinitions);
|
|
54
|
-
console.log(handle.url); // "http://127.0.0.1:PORT/sse"
|
|
55
|
-
await handle.close(); // cleanup
|
|
56
|
-
```
|
|
57
|
-
|
|
58
40
|
### Stream Parsing
|
|
59
41
|
|
|
60
42
|
Exported utilities for parsing Claude's NDJSON output:
|
|
@@ -135,7 +117,7 @@ interface SerializedTool {
|
|
|
135
117
|
|
|
136
118
|
| Entry point | Description |
|
|
137
119
|
|---|---|
|
|
138
|
-
| `.` (`src/index.ts`) | Session provider plugin,
|
|
120
|
+
| `.` (`src/index.ts`) | Session provider plugin, stream parsing utilities |
|
|
139
121
|
| `./babysitter` (`src/babysitter.ts`) | Babysitter module — `runBabysitter()`, config parsing, proxy server, transcript DB |
|
|
140
122
|
|
|
141
123
|
### Internal Modules
|
package/dist/detached.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { spawn } from 'node:child_process';
|
|
11
11
|
import type { SessionProviderConfig, SessionProviderResult, SessionChunk, SessionDoc } from '@shardworks/animator-apparatus';
|
|
12
|
-
import type { ReadOnlyBook } from '@shardworks/stacks-apparatus';
|
|
12
|
+
import type { ReadOnlyBook, Book } from '@shardworks/stacks-apparatus';
|
|
13
13
|
import type { ResolvedTool } from '@shardworks/tools-apparatus';
|
|
14
14
|
import type { BabysitterConfig, SerializedTool } from './babysitter.ts';
|
|
15
15
|
/**
|
|
@@ -53,8 +53,10 @@ export interface DetachedLaunchOptions {
|
|
|
53
53
|
pollIntervalMs?: number;
|
|
54
54
|
/** Override poll timeout in ms (for testing). */
|
|
55
55
|
pollTimeoutMs?: number;
|
|
56
|
-
/** Override sessions book (for testing). */
|
|
56
|
+
/** Override sessions book for polling (for testing). */
|
|
57
57
|
sessionsBook?: ReadOnlyBook<SessionDoc>;
|
|
58
|
+
/** Override writable sessions book for the pending pre-write (for testing). */
|
|
59
|
+
writableSessionsBook?: Book<SessionDoc>;
|
|
58
60
|
/** Override spawn function (for testing). */
|
|
59
61
|
spawnFn?: typeof spawn;
|
|
60
62
|
/** Session metadata from the AnimateRequest. */
|
|
@@ -84,8 +86,7 @@ export declare function pollForProcessInfo(sessionsBook: ReadOnlyBook<SessionDoc
|
|
|
84
86
|
/**
|
|
85
87
|
* Launch a detached babysitter process.
|
|
86
88
|
*
|
|
87
|
-
* Returns
|
|
88
|
-
* provider, but:
|
|
89
|
+
* Returns { chunks, result, processInfo } where:
|
|
89
90
|
* - chunks: completes immediately (empty) — transcripts stream to SQLite
|
|
90
91
|
* - result: polls sessions book for terminal status
|
|
91
92
|
* - processInfo: polls SessionDoc for cancelMetadata (contains claude PID)
|
package/dist/detached.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detached.d.ts","sourceRoot":"","sources":["../src/detached.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAQ3C,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,UAAU,EACX,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAa,YAAY,
|
|
1
|
+
{"version":3,"file":"detached.d.ts","sourceRoot":"","sources":["../src/detached.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAQ3C,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,YAAY,EACZ,UAAU,EACX,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAa,YAAY,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAaxE;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,YAAY,GAAG,cAAc,CAc9D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,cAAc,EAAE,CAEtE;AAID,6CAA6C;AAC7C,wBAAgB,mBAAmB,IAAI,MAAM,CAO5C;AAED,uDAAuD;AACvD,wBAA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Ac,CAC5B,MAAM,EAAE,qBAAqB,EAC7B,IAAI,CAAC,EAAE,qBAAqB,GAC3B;IACD,MAAM,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACpC,MAAM,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACvC,WAAW,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAChD,CAmJA"}
|
package/dist/detached.js
CHANGED
|
@@ -87,8 +87,8 @@ export function resolveBabysitterPath() {
|
|
|
87
87
|
* infrastructure paths, and constructs the base CLI args for claude.
|
|
88
88
|
*/
|
|
89
89
|
export function buildBabysitterConfig(config, opts) {
|
|
90
|
-
// Build claude CLI args (
|
|
91
|
-
// --
|
|
90
|
+
// Build claude CLI args (the babysitter adds --print, --output-format,
|
|
91
|
+
// --verbose, --mcp-config).
|
|
92
92
|
const claudeArgs = [
|
|
93
93
|
'--setting-sources', 'user',
|
|
94
94
|
'--dangerously-skip-permissions',
|
|
@@ -191,8 +191,7 @@ function docToProviderResult(doc) {
|
|
|
191
191
|
/**
|
|
192
192
|
* Launch a detached babysitter process.
|
|
193
193
|
*
|
|
194
|
-
* Returns
|
|
195
|
-
* provider, but:
|
|
194
|
+
* Returns { chunks, result, processInfo } where:
|
|
196
195
|
* - chunks: completes immediately (empty) — transcripts stream to SQLite
|
|
197
196
|
* - result: polls sessions book for terminal status
|
|
198
197
|
* - processInfo: polls SessionDoc for cancelMetadata (contains claude PID)
|
|
@@ -210,6 +209,8 @@ export function launchDetached(config, opts) {
|
|
|
210
209
|
return stacks.readBook('animator', 'sessions');
|
|
211
210
|
};
|
|
212
211
|
const getWritableSessionsBook = () => {
|
|
212
|
+
if (opts?.writableSessionsBook)
|
|
213
|
+
return opts.writableSessionsBook;
|
|
213
214
|
const stacks = guild().apparatus('stacks');
|
|
214
215
|
return stacks.book('animator', 'sessions');
|
|
215
216
|
};
|
|
@@ -222,55 +223,53 @@ export function launchDetached(config, opts) {
|
|
|
222
223
|
...(config.tools?.map((rt) => rt.definition.name) ?? []),
|
|
223
224
|
'session-running',
|
|
224
225
|
'session-record',
|
|
226
|
+
'session-heartbeat',
|
|
225
227
|
];
|
|
226
|
-
//
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
//
|
|
228
|
+
// Shared initialization promise: pre-write the pending record, then
|
|
229
|
+
// spawn the babysitter. Both `result` and `processInfo` await this
|
|
230
|
+
// before proceeding — the pre-write MUST succeed before the babysitter
|
|
231
|
+
// is spawned, because the tool API's authorization reads the session
|
|
232
|
+
// record to decide whether a session host is allowed to make tool calls.
|
|
230
233
|
//
|
|
231
|
-
//
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
234
|
+
// See: docs/architecture/detached-sessions.md § Authorization
|
|
235
|
+
const init = (async () => {
|
|
236
|
+
// Pre-write the `pending` SessionDoc. This is the authorization anchor:
|
|
237
|
+
// the record must exist before the babysitter's first tool call arrives.
|
|
238
|
+
// Seeds `lastActivityAt` so the reconciler has a fair starting point
|
|
239
|
+
// for the staleness calculation.
|
|
240
|
+
const sessions = getWritableSessionsBook();
|
|
241
|
+
await sessions.put({
|
|
242
|
+
id: config.sessionId,
|
|
243
|
+
status: 'pending',
|
|
244
|
+
startedAt: new Date().toISOString(),
|
|
245
|
+
provider: 'claude-code',
|
|
246
|
+
authorizedTools,
|
|
247
|
+
lastActivityAt: new Date().toISOString(),
|
|
248
|
+
...(opts?.metadata ? { metadata: opts.metadata } : {}),
|
|
249
|
+
});
|
|
250
|
+
// Spawn the babysitter as a detached process.
|
|
251
|
+
// stdio: ['pipe', 'ignore', 'inherit'] — config via stdin, no stdout, stderr to parent
|
|
252
|
+
//
|
|
253
|
+
// In source mode (.ts babysitter), forward the parent's execArgv so that
|
|
254
|
+
// --experimental-transform-types (and friends) reach the child. Without
|
|
255
|
+
// this, node would try to load a .ts file as plain CommonJS and crash.
|
|
256
|
+
const isSource = babysitterPath.endsWith('.ts');
|
|
257
|
+
const nodeArgs = isSource
|
|
258
|
+
? [...process.execArgv, babysitterPath]
|
|
259
|
+
: [babysitterPath];
|
|
260
|
+
const proc = spawnFn(process.execPath, nodeArgs, {
|
|
261
|
+
cwd: config.cwd,
|
|
262
|
+
stdio: ['pipe', 'ignore', 'inherit'],
|
|
263
|
+
detached: true,
|
|
264
|
+
env: { ...process.env, ...config.environment },
|
|
265
|
+
});
|
|
266
|
+
// Write config to the babysitter's stdin, then close it.
|
|
267
|
+
proc.stdin.write(JSON.stringify(babysitterConfig));
|
|
268
|
+
proc.stdin.end();
|
|
269
|
+
// Detach — guild doesn't wait for the babysitter.
|
|
270
|
+
proc.unref();
|
|
271
|
+
return proc;
|
|
252
272
|
})();
|
|
253
|
-
// Spawn the babysitter as a detached process.
|
|
254
|
-
// stdio: ['pipe', 'ignore', 'inherit'] — config via stdin, no stdout, stderr to parent
|
|
255
|
-
//
|
|
256
|
-
// In source mode (.ts babysitter), forward the parent's execArgv so that
|
|
257
|
-
// --experimental-transform-types (and friends) reach the child. Without
|
|
258
|
-
// this, node would try to load a .ts file as plain CommonJS and crash.
|
|
259
|
-
const isSource = babysitterPath.endsWith('.ts');
|
|
260
|
-
const nodeArgs = isSource
|
|
261
|
-
? [...process.execArgv, babysitterPath]
|
|
262
|
-
: [babysitterPath];
|
|
263
|
-
const proc = spawnFn(process.execPath, nodeArgs, {
|
|
264
|
-
cwd: config.cwd,
|
|
265
|
-
stdio: ['pipe', 'ignore', 'inherit'],
|
|
266
|
-
detached: true,
|
|
267
|
-
env: { ...process.env, ...config.environment },
|
|
268
|
-
});
|
|
269
|
-
// Write config to the babysitter's stdin, then close it.
|
|
270
|
-
proc.stdin.write(JSON.stringify(babysitterConfig));
|
|
271
|
-
proc.stdin.end();
|
|
272
|
-
// Detach — guild doesn't wait for the babysitter.
|
|
273
|
-
proc.unref();
|
|
274
273
|
// Empty chunks — real-time output is via the transcripts book, not in-memory.
|
|
275
274
|
const chunks = {
|
|
276
275
|
[Symbol.asyncIterator]() {
|
|
@@ -281,8 +280,18 @@ export function launchDetached(config, opts) {
|
|
|
281
280
|
};
|
|
282
281
|
},
|
|
283
282
|
};
|
|
284
|
-
// Result: poll sessions book
|
|
283
|
+
// Result: await init (pre-write + spawn), then poll sessions book.
|
|
285
284
|
const result = (async () => {
|
|
285
|
+
try {
|
|
286
|
+
await init;
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
return {
|
|
290
|
+
status: 'failed',
|
|
291
|
+
exitCode: 1,
|
|
292
|
+
error: `Failed to initialize detached session: ${err instanceof Error ? err.message : String(err)}`,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
286
295
|
try {
|
|
287
296
|
const sessionsBook = getSessionsBook();
|
|
288
297
|
const doc = await pollForTerminalStatus(sessionsBook, config.sessionId, pollIntervalMs, pollTimeoutMs);
|
|
@@ -296,9 +305,16 @@ export function launchDetached(config, opts) {
|
|
|
296
305
|
};
|
|
297
306
|
}
|
|
298
307
|
})();
|
|
299
|
-
// processInfo: poll for cancelMetadata (contains claude PID
|
|
300
|
-
// Falls back to the babysitter's own PID.
|
|
308
|
+
// processInfo: await init, then poll for cancelMetadata (contains claude PID
|
|
309
|
+
// from babysitter). Falls back to the babysitter's own PID.
|
|
301
310
|
const processInfo = (async () => {
|
|
311
|
+
let proc;
|
|
312
|
+
try {
|
|
313
|
+
proc = await init;
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
return {};
|
|
317
|
+
}
|
|
302
318
|
try {
|
|
303
319
|
const sessionsBook = getSessionsBook();
|
|
304
320
|
const info = await pollForProcessInfo(sessionsBook, config.sessionId, pollIntervalMs);
|
package/dist/detached.js.map
CHANG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@@ -6,15 +6,15 @@
|
|
|
6
6
|
*
|
|
7
7
|
* guild.json["animator"]["sessionProvider"] = "claude-code"
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* All sessions launch in detached mode: a babysitter process is spawned
|
|
10
|
+
* that survives guild restarts, hosts the MCP server, spawns claude,
|
|
11
|
+
* streams transcripts to SQLite, and reports lifecycle events via HTTP.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* and future concurrent session support.
|
|
13
|
+
* This module also exports the NDJSON stream parsing utilities used by
|
|
14
|
+
* both the provider and the babysitter.
|
|
15
15
|
*/
|
|
16
16
|
import type { Plugin } from '@shardworks/nexus-core';
|
|
17
|
-
import type {
|
|
17
|
+
import type { SessionChunk } from '@shardworks/animator-apparatus';
|
|
18
18
|
/**
|
|
19
19
|
* Extract the final assistant text from a transcript.
|
|
20
20
|
*
|
|
@@ -24,19 +24,6 @@ import type { SessionProviderConfig, SessionProviderResult, SessionChunk } from
|
|
|
24
24
|
* @internal Exported for testing only.
|
|
25
25
|
*/
|
|
26
26
|
export declare function extractFinalAssistantText(transcript: Record<string, unknown>[]): string | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* Launch a session in attached mode — claude as a direct child process.
|
|
29
|
-
*
|
|
30
|
-
* Preserved for debugging and potential future "attached mode" escape hatch.
|
|
31
|
-
* Not currently wired into the provider, but all supporting code is kept.
|
|
32
|
-
*
|
|
33
|
-
* @internal
|
|
34
|
-
*/
|
|
35
|
-
export declare function launchAttached(config: SessionProviderConfig): {
|
|
36
|
-
chunks: AsyncIterable<SessionChunk>;
|
|
37
|
-
result: Promise<SessionProviderResult>;
|
|
38
|
-
processInfo?: Promise<Record<string, unknown>>;
|
|
39
|
-
};
|
|
40
27
|
/**
|
|
41
28
|
* Create the Claude Code session provider apparatus.
|
|
42
29
|
*
|
|
@@ -47,8 +34,6 @@ export declare function launchAttached(config: SessionProviderConfig): {
|
|
|
47
34
|
export declare function createClaudeCodeProvider(): Plugin;
|
|
48
35
|
declare const _default: Plugin;
|
|
49
36
|
export default _default;
|
|
50
|
-
export { createMcpServer, startMcpHttpServer } from './mcp-server.ts';
|
|
51
|
-
export type { McpHttpHandle } from './mcp-server.ts';
|
|
52
37
|
/** Parsed result from stream-json output. @internal */
|
|
53
38
|
export interface StreamJsonResult {
|
|
54
39
|
exitCode: number;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAIV,YAAY,EACb,MAAM,gCAAgC,CAAC;AAMxC;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,GAAG,SAAS,CAiBnG;AAgCD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,CAWjD;;AAED,wBAA0C;AAI1C,uDAAuD;AACvD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE;QACX,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,GAAG,EAAE;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAC5C,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,GACA,YAAY,EAAE,CAgDhB;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GAC9C,MAAM,CAgBR"}
|
package/dist/index.js
CHANGED
|
@@ -6,64 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* guild.json["animator"]["sessionProvider"] = "claude-code"
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* All sessions launch in detached mode: a babysitter process is spawned
|
|
10
|
+
* that survives guild restarts, hosts the MCP server, spawns claude,
|
|
11
|
+
* streams transcripts to SQLite, and reports lifecycle events via HTTP.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* and future concurrent session support.
|
|
13
|
+
* This module also exports the NDJSON stream parsing utilities used by
|
|
14
|
+
* both the provider and the babysitter.
|
|
15
15
|
*/
|
|
16
|
-
import { spawn } from 'node:child_process';
|
|
17
|
-
import fs from 'node:fs';
|
|
18
|
-
import os from 'node:os';
|
|
19
|
-
import path from 'node:path';
|
|
20
|
-
import { guild } from '@shardworks/nexus-core';
|
|
21
|
-
import { startMcpHttpServer } from "./mcp-server.js";
|
|
22
16
|
import { launchDetached } from "./detached.js";
|
|
23
|
-
/**
|
|
24
|
-
* Prepare session files and build base CLI args.
|
|
25
|
-
*
|
|
26
|
-
* Writes system prompt to a temp directory. Builds the base args array
|
|
27
|
-
* including --resume support. When tools are provided, starts an
|
|
28
|
-
* in-process MCP HTTP server and writes --mcp-config.
|
|
29
|
-
*
|
|
30
|
-
* Caller is responsible for cleaning up tmpDir and calling mcpHandle.close().
|
|
31
|
-
*/
|
|
32
|
-
async function prepareSession(config) {
|
|
33
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'nsg-session-'));
|
|
34
|
-
const args = [
|
|
35
|
-
'--setting-sources', 'user',
|
|
36
|
-
'--dangerously-skip-permissions',
|
|
37
|
-
'--model', config.model,
|
|
38
|
-
];
|
|
39
|
-
if (config.systemPrompt) {
|
|
40
|
-
const systemPromptPath = path.join(tmpDir, 'system-prompt.md');
|
|
41
|
-
fs.writeFileSync(systemPromptPath, config.systemPrompt);
|
|
42
|
-
args.push('--system-prompt-file', systemPromptPath);
|
|
43
|
-
}
|
|
44
|
-
// Resume an existing conversation
|
|
45
|
-
if (config.conversationId) {
|
|
46
|
-
args.push('--resume', config.conversationId);
|
|
47
|
-
}
|
|
48
|
-
// Tool-equipped session: start MCP HTTP server, write --mcp-config
|
|
49
|
-
let mcpHandle;
|
|
50
|
-
if (config.tools && config.tools.length > 0) {
|
|
51
|
-
const tools = config.tools.map((rt) => rt.definition);
|
|
52
|
-
mcpHandle = await startMcpHttpServer(tools);
|
|
53
|
-
const mcpConfig = {
|
|
54
|
-
mcpServers: {
|
|
55
|
-
'nexus-guild': {
|
|
56
|
-
type: 'sse',
|
|
57
|
-
url: mcpHandle.url,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
const mcpConfigPath = path.join(tmpDir, 'mcp-config.json');
|
|
62
|
-
fs.writeFileSync(mcpConfigPath, JSON.stringify(mcpConfig));
|
|
63
|
-
args.push('--mcp-config', mcpConfigPath, '--strict-mcp-config');
|
|
64
|
-
}
|
|
65
|
-
return { tmpDir, args, mcpHandle };
|
|
66
|
-
}
|
|
67
17
|
// ── Output extraction ───────────────────────────────────────────────
|
|
68
18
|
/**
|
|
69
19
|
* Extract the final assistant text from a transcript.
|
|
@@ -90,21 +40,6 @@ export function extractFinalAssistantText(transcript) {
|
|
|
90
40
|
}
|
|
91
41
|
return undefined;
|
|
92
42
|
}
|
|
93
|
-
// ── Result builder ──────────────────────────────────────────────────
|
|
94
|
-
function buildResult(raw) {
|
|
95
|
-
const status = raw.exitCode === 0 ? 'completed' : 'failed';
|
|
96
|
-
return {
|
|
97
|
-
status,
|
|
98
|
-
exitCode: raw.exitCode,
|
|
99
|
-
error: status === 'failed' ? `claude exited with code ${raw.exitCode}` : undefined,
|
|
100
|
-
costUsd: raw.costUsd,
|
|
101
|
-
tokenUsage: raw.tokenUsage,
|
|
102
|
-
providerSessionId: raw.providerSessionId,
|
|
103
|
-
transcript: raw.transcript,
|
|
104
|
-
output: extractFinalAssistantText(raw.transcript),
|
|
105
|
-
signal: raw.signal,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
43
|
// ── Provider implementation ──────────────────────────────────────────
|
|
109
44
|
const provider = {
|
|
110
45
|
name: 'claude-code',
|
|
@@ -124,130 +59,9 @@ const provider = {
|
|
|
124
59
|
}
|
|
125
60
|
},
|
|
126
61
|
launch(config) {
|
|
127
|
-
|
|
128
|
-
// guild restarts, hosts the MCP server, spawns claude, streams transcripts
|
|
129
|
-
// to SQLite, and reports lifecycle events via HTTP.
|
|
130
|
-
//
|
|
131
|
-
// Escape hatch: guild.json["animator"]["detached"] = false opts out and
|
|
132
|
-
// runs claude in-process (attached mode) for debugging.
|
|
133
|
-
let detached = true;
|
|
134
|
-
try {
|
|
135
|
-
const animatorConfig = guild().guildConfig().animator;
|
|
136
|
-
if (animatorConfig?.detached === false)
|
|
137
|
-
detached = false;
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
// No guild bound (e.g. unit tests) — fall back to detached default.
|
|
141
|
-
}
|
|
142
|
-
return detached ? launchDetached(config) : launchAttached(config);
|
|
62
|
+
return launchDetached(config);
|
|
143
63
|
},
|
|
144
64
|
};
|
|
145
|
-
// ── Attached launch (preserved for debugging / non-detached mode) ──────
|
|
146
|
-
/**
|
|
147
|
-
* Launch a session in attached mode — claude as a direct child process.
|
|
148
|
-
*
|
|
149
|
-
* Preserved for debugging and potential future "attached mode" escape hatch.
|
|
150
|
-
* Not currently wired into the provider, but all supporting code is kept.
|
|
151
|
-
*
|
|
152
|
-
* @internal
|
|
153
|
-
*/
|
|
154
|
-
export function launchAttached(config) {
|
|
155
|
-
// prepareSession is async (MCP server start), so we wrap the launch
|
|
156
|
-
// in a promise. The chunks iterable bridges the async gap — it waits
|
|
157
|
-
// for prep to complete before yielding.
|
|
158
|
-
let chunkResolve = null;
|
|
159
|
-
let innerChunks = null;
|
|
160
|
-
let innerIterator = null;
|
|
161
|
-
let prepDone = false;
|
|
162
|
-
let prepError = null;
|
|
163
|
-
let done = false;
|
|
164
|
-
// processInfo promise — resolved with { pid } once the process spawns.
|
|
165
|
-
let resolveProcessInfo = null;
|
|
166
|
-
let rejectProcessInfo = null;
|
|
167
|
-
const processInfo = new Promise((resolve, reject) => {
|
|
168
|
-
resolveProcessInfo = resolve;
|
|
169
|
-
rejectProcessInfo = reject;
|
|
170
|
-
});
|
|
171
|
-
const result = prepareSession(config).then(async ({ tmpDir, args, mcpHandle }) => {
|
|
172
|
-
// Autonomous mode: prompt piped via stdin (--print - reads from stdin).
|
|
173
|
-
// This avoids Commander parsing issues when the prompt starts with '-'
|
|
174
|
-
// (e.g. YAML frontmatter '---') and also avoids OS arg length limits.
|
|
175
|
-
const prompt = config.initialPrompt ?? '';
|
|
176
|
-
args.push('--print', '-', '--output-format', 'stream-json', '--verbose');
|
|
177
|
-
const cleanup = async () => {
|
|
178
|
-
await mcpHandle?.close().catch(() => { });
|
|
179
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
180
|
-
};
|
|
181
|
-
try {
|
|
182
|
-
if (config.streaming) {
|
|
183
|
-
const spawned = spawnClaudeStreamingJson(args, config.cwd, config.environment, prompt);
|
|
184
|
-
resolveProcessInfo({ pid: spawned.pid });
|
|
185
|
-
innerChunks = spawned.chunks;
|
|
186
|
-
prepDone = true;
|
|
187
|
-
if (chunkResolve) {
|
|
188
|
-
chunkResolve();
|
|
189
|
-
chunkResolve = null;
|
|
190
|
-
}
|
|
191
|
-
const raw = await spawned.result;
|
|
192
|
-
await cleanup();
|
|
193
|
-
return buildResult(raw);
|
|
194
|
-
}
|
|
195
|
-
// Non-streaming
|
|
196
|
-
const { result: spawnResult, pid } = spawnClaudeStreamJson(args, config.cwd, config.environment, prompt);
|
|
197
|
-
resolveProcessInfo({ pid });
|
|
198
|
-
prepDone = true;
|
|
199
|
-
done = true;
|
|
200
|
-
if (chunkResolve) {
|
|
201
|
-
chunkResolve();
|
|
202
|
-
chunkResolve = null;
|
|
203
|
-
}
|
|
204
|
-
const raw = await spawnResult;
|
|
205
|
-
await cleanup();
|
|
206
|
-
return buildResult(raw);
|
|
207
|
-
}
|
|
208
|
-
catch (err) {
|
|
209
|
-
await cleanup();
|
|
210
|
-
throw err;
|
|
211
|
-
}
|
|
212
|
-
}).catch((err) => {
|
|
213
|
-
// If prep itself failed, unblock the chunk iterator and processInfo
|
|
214
|
-
prepError = err instanceof Error ? err : new Error(String(err));
|
|
215
|
-
prepDone = true;
|
|
216
|
-
done = true;
|
|
217
|
-
if (chunkResolve) {
|
|
218
|
-
chunkResolve();
|
|
219
|
-
chunkResolve = null;
|
|
220
|
-
}
|
|
221
|
-
rejectProcessInfo(prepError);
|
|
222
|
-
throw err;
|
|
223
|
-
});
|
|
224
|
-
// Chunks iterable that bridges the async prep gap. In non-streaming
|
|
225
|
-
// mode or on error, it completes immediately with no items.
|
|
226
|
-
const chunks = {
|
|
227
|
-
[Symbol.asyncIterator]() {
|
|
228
|
-
return {
|
|
229
|
-
async next() {
|
|
230
|
-
// Wait for prep to complete
|
|
231
|
-
while (!prepDone) {
|
|
232
|
-
await new Promise((resolve) => { chunkResolve = resolve; });
|
|
233
|
-
}
|
|
234
|
-
if (prepError || done) {
|
|
235
|
-
return { value: undefined, done: true };
|
|
236
|
-
}
|
|
237
|
-
// Delegate to inner streaming iterator
|
|
238
|
-
if (innerChunks && !innerIterator) {
|
|
239
|
-
innerIterator = innerChunks[Symbol.asyncIterator]();
|
|
240
|
-
}
|
|
241
|
-
if (innerIterator) {
|
|
242
|
-
return innerIterator.next();
|
|
243
|
-
}
|
|
244
|
-
return { value: undefined, done: true };
|
|
245
|
-
},
|
|
246
|
-
};
|
|
247
|
-
},
|
|
248
|
-
};
|
|
249
|
-
return { chunks, result, processInfo };
|
|
250
|
-
}
|
|
251
65
|
// ── Apparatus export ─────────────────────────────────────────────────
|
|
252
66
|
/**
|
|
253
67
|
* Create the Claude Code session provider apparatus.
|
|
@@ -268,11 +82,6 @@ export function createClaudeCodeProvider() {
|
|
|
268
82
|
};
|
|
269
83
|
}
|
|
270
84
|
export default createClaudeCodeProvider();
|
|
271
|
-
// ── MCP server re-exports ───────────────────────────────────────────
|
|
272
|
-
// The MCP server module is used by the session provider to attach tools
|
|
273
|
-
// to sessions via --mcp-config, and can be imported directly for
|
|
274
|
-
// testing or custom integrations.
|
|
275
|
-
export { createMcpServer, startMcpHttpServer } from "./mcp-server.js";
|
|
276
85
|
/**
|
|
277
86
|
* Parse a single NDJSON message from stream-json output.
|
|
278
87
|
*
|
|
@@ -351,145 +160,4 @@ export function processNdjsonBuffer(buffer, handler) {
|
|
|
351
160
|
}
|
|
352
161
|
return buffer;
|
|
353
162
|
}
|
|
354
|
-
/**
|
|
355
|
-
* Spawn Claude in autonomous mode with --output-format stream-json.
|
|
356
|
-
*
|
|
357
|
-
* Captures stdout (NDJSON lines), parses each line to extract:
|
|
358
|
-
* - assistant messages → transcript
|
|
359
|
-
* - result message → cost, token usage, session ID
|
|
360
|
-
*
|
|
361
|
-
* Forwards assistant text content to stderr so it's visible during execution.
|
|
362
|
-
*/
|
|
363
|
-
function spawnClaudeStreamJson(args, cwd, env, stdinData) {
|
|
364
|
-
const proc = spawn('claude', args, {
|
|
365
|
-
cwd,
|
|
366
|
-
stdio: ['pipe', 'pipe', 'inherit'],
|
|
367
|
-
env: { ...process.env, ...env },
|
|
368
|
-
});
|
|
369
|
-
// Pipe prompt via stdin (--print - reads from stdin)
|
|
370
|
-
if (stdinData !== undefined) {
|
|
371
|
-
proc.stdin.write(stdinData);
|
|
372
|
-
proc.stdin.end();
|
|
373
|
-
}
|
|
374
|
-
const acc = { transcript: [] };
|
|
375
|
-
let buffer = '';
|
|
376
|
-
proc.stdout.on('data', (chunk) => {
|
|
377
|
-
buffer += chunk.toString();
|
|
378
|
-
buffer = processNdjsonBuffer(buffer, (msg) => {
|
|
379
|
-
const chunks = parseStreamJsonMessage(msg, acc);
|
|
380
|
-
for (const c of chunks) {
|
|
381
|
-
if (c.type === 'text') {
|
|
382
|
-
process.stderr.write(c.text);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
const result = new Promise((resolve, reject) => {
|
|
388
|
-
proc.on('error', (err) => {
|
|
389
|
-
reject(new Error(`Failed to spawn claude: ${err.message}`));
|
|
390
|
-
});
|
|
391
|
-
proc.on('close', (code, signal) => {
|
|
392
|
-
if (acc.transcript.length > 0) {
|
|
393
|
-
process.stderr.write('\n');
|
|
394
|
-
}
|
|
395
|
-
resolve({
|
|
396
|
-
exitCode: code ?? 1,
|
|
397
|
-
transcript: acc.transcript,
|
|
398
|
-
costUsd: acc.costUsd,
|
|
399
|
-
tokenUsage: acc.tokenUsage,
|
|
400
|
-
providerSessionId: acc.providerSessionId,
|
|
401
|
-
signal: signal ?? undefined,
|
|
402
|
-
});
|
|
403
|
-
});
|
|
404
|
-
});
|
|
405
|
-
return { result, pid: proc.pid };
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Spawn Claude with streaming — yields SessionChunks as they arrive
|
|
409
|
-
* while also accumulating the full result.
|
|
410
|
-
*
|
|
411
|
-
* Returns an async iterable of chunks for real-time consumption and
|
|
412
|
-
* a promise for the final StreamJsonResult.
|
|
413
|
-
*/
|
|
414
|
-
function spawnClaudeStreamingJson(args, cwd, env, stdinData) {
|
|
415
|
-
const chunkQueue = [];
|
|
416
|
-
let chunkResolve = null;
|
|
417
|
-
let done = false;
|
|
418
|
-
const acc = { transcript: [] };
|
|
419
|
-
const proc = spawn('claude', args, {
|
|
420
|
-
cwd,
|
|
421
|
-
stdio: ['pipe', 'pipe', 'inherit'],
|
|
422
|
-
env: { ...process.env, ...env },
|
|
423
|
-
});
|
|
424
|
-
// Pipe prompt via stdin (--print - reads from stdin)
|
|
425
|
-
if (stdinData !== undefined) {
|
|
426
|
-
proc.stdin.write(stdinData);
|
|
427
|
-
proc.stdin.end();
|
|
428
|
-
}
|
|
429
|
-
let buffer = '';
|
|
430
|
-
proc.stdout.on('data', (chunk) => {
|
|
431
|
-
buffer += chunk.toString();
|
|
432
|
-
buffer = processNdjsonBuffer(buffer, (msg) => {
|
|
433
|
-
const newChunks = parseStreamJsonMessage(msg, acc);
|
|
434
|
-
for (const c of newChunks) {
|
|
435
|
-
if (c.type === 'text') {
|
|
436
|
-
process.stderr.write(c.text);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
if (newChunks.length > 0) {
|
|
440
|
-
chunkQueue.push(...newChunks);
|
|
441
|
-
if (chunkResolve) {
|
|
442
|
-
chunkResolve();
|
|
443
|
-
chunkResolve = null;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
});
|
|
448
|
-
const result = new Promise((resolve, reject) => {
|
|
449
|
-
proc.on('error', (err) => {
|
|
450
|
-
done = true;
|
|
451
|
-
if (chunkResolve) {
|
|
452
|
-
chunkResolve();
|
|
453
|
-
chunkResolve = null;
|
|
454
|
-
}
|
|
455
|
-
reject(new Error(`Failed to spawn claude: ${err.message}`));
|
|
456
|
-
});
|
|
457
|
-
proc.on('close', (code, signal) => {
|
|
458
|
-
if (acc.transcript.length > 0) {
|
|
459
|
-
process.stderr.write('\n');
|
|
460
|
-
}
|
|
461
|
-
done = true;
|
|
462
|
-
if (chunkResolve) {
|
|
463
|
-
chunkResolve();
|
|
464
|
-
chunkResolve = null;
|
|
465
|
-
}
|
|
466
|
-
resolve({
|
|
467
|
-
exitCode: code ?? 1,
|
|
468
|
-
transcript: acc.transcript,
|
|
469
|
-
costUsd: acc.costUsd,
|
|
470
|
-
tokenUsage: acc.tokenUsage,
|
|
471
|
-
providerSessionId: acc.providerSessionId,
|
|
472
|
-
signal: signal ?? undefined,
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
});
|
|
476
|
-
const chunks = {
|
|
477
|
-
[Symbol.asyncIterator]() {
|
|
478
|
-
return {
|
|
479
|
-
async next() {
|
|
480
|
-
while (true) {
|
|
481
|
-
if (chunkQueue.length > 0) {
|
|
482
|
-
return { value: chunkQueue.shift(), done: false };
|
|
483
|
-
}
|
|
484
|
-
if (done) {
|
|
485
|
-
return { value: undefined, done: true };
|
|
486
|
-
}
|
|
487
|
-
await new Promise((resolve) => { chunkResolve = resolve; });
|
|
488
|
-
}
|
|
489
|
-
},
|
|
490
|
-
};
|
|
491
|
-
},
|
|
492
|
-
};
|
|
493
|
-
return { chunks, result, pid: proc.pid };
|
|
494
|
-
}
|
|
495
163
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAQ/C,OAAO,EAAE,kBA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;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shardworks/claude-code-apparatus",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.185",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"@modelcontextprotocol/sdk": "1.27.1",
|
|
27
27
|
"better-sqlite3": "12.8.0",
|
|
28
28
|
"zod": "4.3.6",
|
|
29
|
-
"@shardworks/
|
|
30
|
-
"@shardworks/
|
|
31
|
-
"@shardworks/
|
|
29
|
+
"@shardworks/stacks-apparatus": "0.1.185",
|
|
30
|
+
"@shardworks/tools-apparatus": "0.1.185",
|
|
31
|
+
"@shardworks/animator-apparatus": "0.1.185"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/better-sqlite3": "7.6.13",
|
|
35
35
|
"@types/node": "25.5.0",
|
|
36
|
-
"@shardworks/nexus-core": "0.1.
|
|
36
|
+
"@shardworks/nexus-core": "0.1.185"
|
|
37
37
|
},
|
|
38
38
|
"files": [
|
|
39
39
|
"dist"
|
package/dist/mcp-server.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Tool Server — serves guild tools as typed MCP tools during anima sessions.
|
|
3
|
-
*
|
|
4
|
-
* Two entry points:
|
|
5
|
-
*
|
|
6
|
-
* 1. **`createMcpServer(tools)`** — library function. Takes an array of
|
|
7
|
-
* ToolDefinitions (already resolved by the Instrumentarium) and returns
|
|
8
|
-
* a configured McpServer.
|
|
9
|
-
*
|
|
10
|
-
* 2. **`startMcpHttpServer(tools)`** — starts an in-process HTTP server
|
|
11
|
-
* serving the MCP tool set via Streamable HTTP on an ephemeral localhost
|
|
12
|
-
* port. Returns a handle with the URL (for --mcp-config) and a close()
|
|
13
|
-
* function for cleanup.
|
|
14
|
-
*
|
|
15
|
-
* The MCP server is one-per-session. The claude-code provider owns the
|
|
16
|
-
* lifecycle — starts before the Claude process, stops after it exits.
|
|
17
|
-
*
|
|
18
|
-
* See: docs/architecture/apparatus/claude-code.md
|
|
19
|
-
*/
|
|
20
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
21
|
-
import type { ToolDefinition } from '@shardworks/tools-apparatus';
|
|
22
|
-
/**
|
|
23
|
-
* Handle returned by startMcpHttpServer().
|
|
24
|
-
*
|
|
25
|
-
* Provides the URL for --mcp-config and a close() function for cleanup.
|
|
26
|
-
*/
|
|
27
|
-
export interface McpHttpHandle {
|
|
28
|
-
/** URL for --mcp-config (e.g. "http://127.0.0.1:PORT/mcp"). */
|
|
29
|
-
url: string;
|
|
30
|
-
/** Shut down the HTTP server and MCP transport. */
|
|
31
|
-
close(): Promise<void>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Create and configure an MCP server with the given tools.
|
|
35
|
-
*
|
|
36
|
-
* Each tool's Zod param schema is registered directly with the MCP SDK
|
|
37
|
-
* (which handles JSON Schema conversion). The handler is wrapped to
|
|
38
|
-
* validate params via Zod and format the result as MCP tool output.
|
|
39
|
-
*
|
|
40
|
-
* Tools with `callableBy` set that does not include `'anima'` are
|
|
41
|
-
* filtered out. Tools without `callableBy` are included (available
|
|
42
|
-
* to all callers by default).
|
|
43
|
-
*/
|
|
44
|
-
export declare function createMcpServer(tools: ToolDefinition[]): Promise<McpServer>;
|
|
45
|
-
/**
|
|
46
|
-
* Start an in-process HTTP server serving the MCP tool set via SSE.
|
|
47
|
-
*
|
|
48
|
-
* Uses the MCP SDK's SSE transport: the client GETs /sse to establish
|
|
49
|
-
* the event stream, then POSTs messages to /message. Claude Code's
|
|
50
|
-
* --mcp-config expects `type: "sse"` for HTTP-based MCP servers.
|
|
51
|
-
*
|
|
52
|
-
* The server binds to 127.0.0.1 only — not network-accessible.
|
|
53
|
-
*
|
|
54
|
-
* Returns a handle with the URL (for --mcp-config) and a close() function.
|
|
55
|
-
* The caller is responsible for calling close() after the session exits.
|
|
56
|
-
*
|
|
57
|
-
* Each session gets its own server instance. Concurrent sessions get
|
|
58
|
-
* independent servers on different ports.
|
|
59
|
-
*/
|
|
60
|
-
export declare function startMcpHttpServer(tools: ToolDefinition[]): Promise<McpHttpHandle>;
|
|
61
|
-
//# sourceMappingURL=mcp-server.d.ts.map
|
package/dist/mcp-server.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAIlE;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,GAAG,EAAE,MAAM,CAAC;IACZ,mDAAmD;IACnD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAID;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAwCjF;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAuExF"}
|
package/dist/mcp-server.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Tool Server — serves guild tools as typed MCP tools during anima sessions.
|
|
3
|
-
*
|
|
4
|
-
* Two entry points:
|
|
5
|
-
*
|
|
6
|
-
* 1. **`createMcpServer(tools)`** — library function. Takes an array of
|
|
7
|
-
* ToolDefinitions (already resolved by the Instrumentarium) and returns
|
|
8
|
-
* a configured McpServer.
|
|
9
|
-
*
|
|
10
|
-
* 2. **`startMcpHttpServer(tools)`** — starts an in-process HTTP server
|
|
11
|
-
* serving the MCP tool set via Streamable HTTP on an ephemeral localhost
|
|
12
|
-
* port. Returns a handle with the URL (for --mcp-config) and a close()
|
|
13
|
-
* function for cleanup.
|
|
14
|
-
*
|
|
15
|
-
* The MCP server is one-per-session. The claude-code provider owns the
|
|
16
|
-
* lifecycle — starts before the Claude process, stops after it exits.
|
|
17
|
-
*
|
|
18
|
-
* See: docs/architecture/apparatus/claude-code.md
|
|
19
|
-
*/
|
|
20
|
-
import http from 'node:http';
|
|
21
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
22
|
-
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
23
|
-
import { VERSION } from '@shardworks/nexus-core';
|
|
24
|
-
// ── Library API ─────────────────────────────────────────────────────────
|
|
25
|
-
/**
|
|
26
|
-
* Create and configure an MCP server with the given tools.
|
|
27
|
-
*
|
|
28
|
-
* Each tool's Zod param schema is registered directly with the MCP SDK
|
|
29
|
-
* (which handles JSON Schema conversion). The handler is wrapped to
|
|
30
|
-
* validate params via Zod and format the result as MCP tool output.
|
|
31
|
-
*
|
|
32
|
-
* Tools with `callableBy` set that does not include `'anima'` are
|
|
33
|
-
* filtered out. Tools without `callableBy` are included (available
|
|
34
|
-
* to all callers by default).
|
|
35
|
-
*/
|
|
36
|
-
export async function createMcpServer(tools) {
|
|
37
|
-
const server = new McpServer({
|
|
38
|
-
name: 'nexus-guild',
|
|
39
|
-
version: VERSION,
|
|
40
|
-
});
|
|
41
|
-
for (const def of tools) {
|
|
42
|
-
// Filter by callableBy — only serve tools callable by animas.
|
|
43
|
-
// Tools with no callableBy default to all callers (available everywhere).
|
|
44
|
-
if (def.callableBy && !def.callableBy.includes('anima')) {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
server.tool(def.name, def.description, def.params.shape, async (params) => {
|
|
48
|
-
try {
|
|
49
|
-
const validated = def.params.parse(params);
|
|
50
|
-
const result = await def.handler(validated);
|
|
51
|
-
return {
|
|
52
|
-
content: [{
|
|
53
|
-
type: 'text',
|
|
54
|
-
text: typeof result === 'string' ? result : JSON.stringify(result, null, 2),
|
|
55
|
-
}],
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
catch (err) {
|
|
59
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
60
|
-
return {
|
|
61
|
-
content: [{ type: 'text', text: `Error: ${message}` }],
|
|
62
|
-
isError: true,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return server;
|
|
68
|
-
}
|
|
69
|
-
// ── HTTP Server ─────────────────────────────────────────────────────────
|
|
70
|
-
/**
|
|
71
|
-
* Start an in-process HTTP server serving the MCP tool set via SSE.
|
|
72
|
-
*
|
|
73
|
-
* Uses the MCP SDK's SSE transport: the client GETs /sse to establish
|
|
74
|
-
* the event stream, then POSTs messages to /message. Claude Code's
|
|
75
|
-
* --mcp-config expects `type: "sse"` for HTTP-based MCP servers.
|
|
76
|
-
*
|
|
77
|
-
* The server binds to 127.0.0.1 only — not network-accessible.
|
|
78
|
-
*
|
|
79
|
-
* Returns a handle with the URL (for --mcp-config) and a close() function.
|
|
80
|
-
* The caller is responsible for calling close() after the session exits.
|
|
81
|
-
*
|
|
82
|
-
* Each session gets its own server instance. Concurrent sessions get
|
|
83
|
-
* independent servers on different ports.
|
|
84
|
-
*/
|
|
85
|
-
export async function startMcpHttpServer(tools) {
|
|
86
|
-
const mcpServer = await createMcpServer(tools);
|
|
87
|
-
// SSE transport: the client GETs /sse, the transport tells it to POST
|
|
88
|
-
// messages to /message. One transport per connection (single-session).
|
|
89
|
-
// Promise-gate: POST /message waits for the SSE transport to be fully connected,
|
|
90
|
-
// eliminating the race where a POST arrives before GET /sse completes.
|
|
91
|
-
let resolveTransport;
|
|
92
|
-
let rejectTransport;
|
|
93
|
-
const transportReady = new Promise((resolve, reject) => {
|
|
94
|
-
resolveTransport = resolve;
|
|
95
|
-
rejectTransport = reject;
|
|
96
|
-
});
|
|
97
|
-
// Direct reference for close() — null until connected.
|
|
98
|
-
let transport = null;
|
|
99
|
-
const httpServer = http.createServer(async (req, res) => {
|
|
100
|
-
try {
|
|
101
|
-
if (req.method === 'GET' && req.url === '/sse') {
|
|
102
|
-
const t = new SSEServerTransport('/message', res);
|
|
103
|
-
try {
|
|
104
|
-
await mcpServer.connect(t);
|
|
105
|
-
transport = t;
|
|
106
|
-
resolveTransport(t);
|
|
107
|
-
}
|
|
108
|
-
catch (err) {
|
|
109
|
-
rejectTransport(err instanceof Error ? err : new Error(String(err)));
|
|
110
|
-
throw err;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
else if (req.method === 'POST' && req.url?.startsWith('/message')) {
|
|
114
|
-
let t;
|
|
115
|
-
try {
|
|
116
|
-
t = await transportReady;
|
|
117
|
-
}
|
|
118
|
-
catch {
|
|
119
|
-
res.writeHead(503).end('SSE transport failed to initialize');
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
await t.handlePostMessage(req, res);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
res.writeHead(404).end('Not found');
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch {
|
|
129
|
-
if (!res.headersSent) {
|
|
130
|
-
res.writeHead(500).end('Internal Server Error');
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
// Listen on ephemeral port, localhost only.
|
|
135
|
-
await new Promise((resolve) => {
|
|
136
|
-
httpServer.listen(0, '127.0.0.1', resolve);
|
|
137
|
-
});
|
|
138
|
-
const addr = httpServer.address();
|
|
139
|
-
if (!addr || typeof addr === 'string') {
|
|
140
|
-
throw new Error('Failed to get server address');
|
|
141
|
-
}
|
|
142
|
-
const url = `http://127.0.0.1:${addr.port}/sse`;
|
|
143
|
-
return {
|
|
144
|
-
url,
|
|
145
|
-
async close() {
|
|
146
|
-
if (transport) {
|
|
147
|
-
await transport.close();
|
|
148
|
-
}
|
|
149
|
-
await new Promise((resolve, reject) => {
|
|
150
|
-
httpServer.close((err) => (err ? reject(err) : resolve()));
|
|
151
|
-
});
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
//# sourceMappingURL=mcp-server.js.map
|
package/dist/mcp-server.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAiBjD,2EAA2E;AAE3E;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,KAAuB;IAC3D,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,aAAa;QACnB,OAAO,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE,CAAC;QACxB,8DAA8D;QAC9D,0EAA0E;QAC1E,IAAI,GAAG,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACxD,SAAS;QACX,CAAC;QAED,MAAM,CAAC,IAAI,CACT,GAAG,CAAC,IAAI,EACR,GAAG,CAAC,WAAW,EACf,GAAG,CAAC,MAAM,CAAC,KAAK,EAChB,KAAK,EAAE,MAAM,EAAE,EAAE;YACf,IAAI,CAAC;gBACH,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;gBAC3C,MAA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