@excitedjs/agent-runtime-claude-code 0.5.0-beta.168 → 1.0.0-beta.170
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 +41 -1
- package/dist/args.d.ts +2 -0
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +5 -0
- package/dist/args.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +5 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +9 -4
- package/dist/provider.js.map +1 -1
- package/dist/rpc.d.ts +14 -1
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +194 -53
- package/dist/rpc.js.map +1 -1
- package/dist/runtime-deps.d.ts +29 -0
- package/dist/runtime-deps.d.ts.map +1 -0
- package/dist/runtime-deps.js +2 -0
- package/dist/runtime-deps.js.map +1 -0
- package/dist/runtime-session.d.ts +13 -0
- package/dist/runtime-session.d.ts.map +1 -0
- package/dist/runtime-session.js +41 -0
- package/dist/runtime-session.js.map +1 -0
- package/dist/runtime-turn.d.ts +7 -0
- package/dist/runtime-turn.d.ts.map +1 -0
- package/dist/runtime-turn.js +21 -0
- package/dist/runtime-turn.js.map +1 -0
- package/dist/runtime.d.ts +30 -131
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +258 -225
- package/dist/runtime.js.map +1 -1
- package/dist/skill-adapter.d.ts +11 -1
- package/dist/skill-adapter.d.ts.map +1 -1
- package/dist/skill-adapter.js +60 -7
- package/dist/skill-adapter.js.map +1 -1
- package/dist/skill-materializer.d.ts +6 -0
- package/dist/skill-materializer.d.ts.map +1 -0
- package/dist/skill-materializer.js +45 -0
- package/dist/skill-materializer.js.map +1 -0
- package/dist/source-reservation.d.ts +6 -0
- package/dist/source-reservation.d.ts.map +1 -0
- package/dist/source-reservation.js +48 -0
- package/dist/source-reservation.js.map +1 -0
- package/dist/stream.d.ts +1 -1
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +21 -1
- package/dist/stream.js.map +1 -1
- package/dist/supervisor.d.ts.map +1 -1
- package/dist/supervisor.js +63 -10
- package/dist/supervisor.js.map +1 -1
- package/dist/transcript/budget.d.ts +8 -0
- package/dist/transcript/budget.d.ts.map +1 -0
- package/dist/transcript/budget.js +9 -0
- package/dist/transcript/budget.js.map +1 -0
- package/dist/transcript/completion.d.ts +8 -0
- package/dist/transcript/completion.d.ts.map +1 -0
- package/dist/transcript/completion.js +44 -0
- package/dist/transcript/completion.js.map +1 -0
- package/dist/transcript/cursor.d.ts +25 -0
- package/dist/transcript/cursor.d.ts.map +1 -0
- package/dist/transcript/cursor.js +62 -0
- package/dist/transcript/cursor.js.map +1 -0
- package/dist/transcript/error.d.ts +9 -0
- package/dist/transcript/error.d.ts.map +1 -0
- package/dist/transcript/error.js +9 -0
- package/dist/transcript/error.js.map +1 -0
- package/dist/transcript/native-hash.d.ts +2 -0
- package/dist/transcript/native-hash.d.ts.map +1 -0
- package/dist/transcript/native-hash.js +79 -0
- package/dist/transcript/native-hash.js.map +1 -0
- package/dist/transcript/opened-file.d.ts +13 -0
- package/dist/transcript/opened-file.d.ts.map +1 -0
- package/dist/transcript/opened-file.js +110 -0
- package/dist/transcript/opened-file.js.map +1 -0
- package/dist/transcript/parallel-tools.d.ts +6 -0
- package/dist/transcript/parallel-tools.d.ts.map +1 -0
- package/dist/transcript/parallel-tools.js +123 -0
- package/dist/transcript/parallel-tools.js.map +1 -0
- package/dist/transcript/path.d.ts +25 -0
- package/dist/transcript/path.d.ts.map +1 -0
- package/dist/transcript/path.js +253 -0
- package/dist/transcript/path.js.map +1 -0
- package/dist/transcript/reader.d.ts +7 -0
- package/dist/transcript/reader.d.ts.map +1 -0
- package/dist/transcript/reader.js +476 -0
- package/dist/transcript/reader.js.map +1 -0
- package/dist/transcript/rewrites.d.ts +5 -0
- package/dist/transcript/rewrites.d.ts.map +1 -0
- package/dist/transcript/rewrites.js +65 -0
- package/dist/transcript/rewrites.js.map +1 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { AgentRuntimeMcpServer, AgentRuntimePathContext, AgentRuntimeSkillSource, AgentRuntimeStateCallbacks, DreamuxLogger } from '@excitedjs/dreamux-types';
|
|
2
|
+
import type { DispatcherClaudeCodeConfig } from './config.js';
|
|
3
|
+
import type { ClaudeCodeSessionFactory } from './supervisor.js';
|
|
4
|
+
/** Neutral host capabilities required by one resident Claude Code runtime. */
|
|
5
|
+
export interface ClaudeCodeRuntimeDeps {
|
|
6
|
+
config: DispatcherClaudeCodeConfig;
|
|
7
|
+
cwd: string;
|
|
8
|
+
state: AgentRuntimeStateCallbacks;
|
|
9
|
+
paths: AgentRuntimePathContext;
|
|
10
|
+
mcpServers: readonly AgentRuntimeMcpServer[];
|
|
11
|
+
sessionFactory: ClaudeCodeSessionFactory;
|
|
12
|
+
resolveBinPath: (bin: string) => string;
|
|
13
|
+
injectEnv?: Record<string, string>;
|
|
14
|
+
systemPromptAppend?: readonly string[];
|
|
15
|
+
skillSources?: readonly AgentRuntimeSkillSource[];
|
|
16
|
+
disableFeatures?: readonly string[];
|
|
17
|
+
outputSchema?: Record<string, unknown>;
|
|
18
|
+
generateSessionId?: () => string;
|
|
19
|
+
resolveTranscriptPath?: (input: {
|
|
20
|
+
sessionId: string;
|
|
21
|
+
cwd: string;
|
|
22
|
+
locator: string | null;
|
|
23
|
+
env: NodeJS.ProcessEnv;
|
|
24
|
+
resume: boolean;
|
|
25
|
+
}) => Promise<string>;
|
|
26
|
+
sourceIdDedupeWindow?: number;
|
|
27
|
+
logger?: DreamuxLogger;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=runtime-deps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-deps.d.ts","sourceRoot":"","sources":["../src/runtime-deps.ts"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@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-deps.js","sourceRoot":"","sources":["../src/runtime-deps.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TurnOutcome } from './supervisor.js';
|
|
2
|
+
export interface ResolveRuntimeTranscriptPathInput {
|
|
3
|
+
sessionId: string;
|
|
4
|
+
cwd: string;
|
|
5
|
+
locator: string | null;
|
|
6
|
+
env: NodeJS.ProcessEnv;
|
|
7
|
+
resume: boolean;
|
|
8
|
+
override?: (input: Omit<ResolveRuntimeTranscriptPathInput, 'override'>) => Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
export declare function buildClaudeProcessEnv(injectEnv: Record<string, string> | undefined, extraEnv: Record<string, string>): NodeJS.ProcessEnv;
|
|
11
|
+
export declare function resolveRuntimeTranscriptPath(input: ResolveRuntimeTranscriptPathInput): Promise<string>;
|
|
12
|
+
export declare function resultTextFromTurnOutcome(outcome: TurnOutcome, expectedSessionId: string | null, requiresStructuredOutput: boolean): string | null;
|
|
13
|
+
//# sourceMappingURL=runtime-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-session.d.ts","sourceRoot":"","sources":["../src/runtime-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAMnD,MAAM,WAAW,iCAAiC;IAChD,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,CAAC,EAAE,CACT,KAAK,EAAE,IAAI,CAAC,iCAAiC,EAAE,UAAU,CAAC,KACvD,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB;AAED,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC7C,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,MAAM,CAAC,UAAU,CAMnB;AAED,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,iCAAiC,GACvC,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,WAAW,EACpB,iBAAiB,EAAE,MAAM,GAAG,IAAI,EAChC,wBAAwB,EAAE,OAAO,GAChC,MAAM,GAAG,IAAI,CA0Bf"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { deriveClaudeTranscriptPath, locateClaudeTranscript, } from './transcript/path.js';
|
|
2
|
+
export function buildClaudeProcessEnv(injectEnv, extraEnv) {
|
|
3
|
+
return {
|
|
4
|
+
...globalThis.process.env,
|
|
5
|
+
...(injectEnv ?? {}),
|
|
6
|
+
...extraEnv,
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function resolveRuntimeTranscriptPath(input) {
|
|
10
|
+
const { override, ...pathInput } = input;
|
|
11
|
+
if (override !== undefined)
|
|
12
|
+
return override(pathInput);
|
|
13
|
+
return input.resume
|
|
14
|
+
? locateClaudeTranscript({
|
|
15
|
+
sessionId: input.sessionId,
|
|
16
|
+
cwd: input.cwd,
|
|
17
|
+
locator: input.locator,
|
|
18
|
+
env: input.env,
|
|
19
|
+
}).then((located) => located.path)
|
|
20
|
+
: deriveClaudeTranscriptPath(input.sessionId, input.cwd, input.env);
|
|
21
|
+
}
|
|
22
|
+
export function resultTextFromTurnOutcome(outcome, expectedSessionId, requiresStructuredOutput) {
|
|
23
|
+
if (outcome.sessionId !== null &&
|
|
24
|
+
outcome.sessionId !== '' &&
|
|
25
|
+
outcome.sessionId !== expectedSessionId) {
|
|
26
|
+
throw new Error('claude-code returned a session id that differs from the pinned native session');
|
|
27
|
+
}
|
|
28
|
+
const resultText = outcome.isError || outcome.text === '' ? null : outcome.text;
|
|
29
|
+
if (outcome.isError) {
|
|
30
|
+
const detail = outcome.errors.length > 0
|
|
31
|
+
? outcome.errors.join('; ')
|
|
32
|
+
: (outcome.subtype ?? 'unknown error');
|
|
33
|
+
throw new Error(`claude turn returned an error result: ${detail}`);
|
|
34
|
+
}
|
|
35
|
+
if (requiresStructuredOutput && !outcome.hasStructuredOutput) {
|
|
36
|
+
throw new Error('claude turn did not return structured_output for a ' +
|
|
37
|
+
'--json-schema session');
|
|
38
|
+
}
|
|
39
|
+
return resultText;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=runtime-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-session.js","sourceRoot":"","sources":["../src/runtime-session.ts"],"names":[],"mappings":"AACA,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAa9B,MAAM,UAAU,qBAAqB,CACnC,SAA6C,EAC7C,QAAgC;IAEhC,OAAO;QACL,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG;QACzB,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC;QACpB,GAAG,QAAQ;KACZ,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,4BAA4B,CAC1C,KAAwC;IAExC,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IACzC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC;IACvD,OAAO,KAAK,CAAC,MAAM;QACjB,CAAC,CAAC,sBAAsB,CAAC;YACrB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,GAAG,EAAE,KAAK,CAAC,GAAG;YACd,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,GAAG,EAAE,KAAK,CAAC,GAAG;SACf,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;QACpC,CAAC,CAAC,0BAA0B,CAAC,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;AACxE,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,OAAoB,EACpB,iBAAgC,EAChC,wBAAiC;IAEjC,IACE,OAAO,CAAC,SAAS,KAAK,IAAI;QAC1B,OAAO,CAAC,SAAS,KAAK,EAAE;QACxB,OAAO,CAAC,SAAS,KAAK,iBAAiB,EACvC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,+EAA+E,CAChF,CAAC;IACJ,CAAC;IACD,MAAM,UAAU,GACd,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IAC/D,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YACvB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;YAC3B,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,IAAI,eAAe,CAAC,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,yCAAyC,MAAM,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,IAAI,wBAAwB,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAC7D,MAAM,IAAI,KAAK,CACb,qDAAqD;YACnD,uBAAuB,CAC1B,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RuntimeTurn, RuntimeTurnOutcome } from '@excitedjs/dreamux-types';
|
|
2
|
+
/** Create one stable logical Turn object with an exactly-once outcome latch. */
|
|
3
|
+
export declare function createRuntimeTurn(): {
|
|
4
|
+
turn: RuntimeTurn;
|
|
5
|
+
settle: (outcome: RuntimeTurnOutcome) => boolean;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=runtime-turn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-turn.d.ts","sourceRoot":"","sources":["../src/runtime-turn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EACnB,MAAM,0BAA0B,CAAC;AAElC,gFAAgF;AAChF,wBAAgB,iBAAiB,IAAI;IACnC,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC;CAClD,CAiBA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Create one stable logical Turn object with an exactly-once outcome latch. */
|
|
2
|
+
export function createRuntimeTurn() {
|
|
3
|
+
let resolve;
|
|
4
|
+
let settled = false;
|
|
5
|
+
const turn = Object.freeze({
|
|
6
|
+
settled: new Promise((value) => {
|
|
7
|
+
resolve = value;
|
|
8
|
+
}),
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
turn,
|
|
12
|
+
settle(outcome) {
|
|
13
|
+
if (settled)
|
|
14
|
+
return false;
|
|
15
|
+
settled = true;
|
|
16
|
+
resolve(outcome);
|
|
17
|
+
return true;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=runtime-turn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-turn.js","sourceRoot":"","sources":["../src/runtime-turn.ts"],"names":[],"mappings":"AAKA,gFAAgF;AAChF,MAAM,UAAU,iBAAiB;IAI/B,IAAI,OAA+C,CAAC;IACpD,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;QACzB,OAAO,EAAE,IAAI,OAAO,CAAqB,CAAC,KAAK,EAAE,EAAE;YACjD,OAAO,GAAG,KAAK,CAAC;QAClB,CAAC,CAAC;KACH,CAAC,CAAC;IACH,OAAO;QACL,IAAI;QACJ,MAAM,CAAC,OAAO;YACZ,IAAI,OAAO;gBAAE,OAAO,KAAK,CAAC;YAC1B,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,CAAC,OAAO,CAAC,CAAC;YACjB,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,119 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* in issue #209).
|
|
5
|
-
*
|
|
6
|
-
* A real second agent runtime that proves the AgentRuntimeProvider abstraction
|
|
7
|
-
* is not "Codex renamed". Like Codex it runs a **resident child process**
|
|
8
|
-
* supervised for the runtime's lifetime — but it differs in every
|
|
9
|
-
* runtime-specific dimension:
|
|
10
|
-
*
|
|
11
|
-
* - **Stream-json over stdio, not an app-server WebSocket.** The resident child
|
|
12
|
-
* is `claude --print --input-format stream-json --output-format stream-json`
|
|
13
|
-
* (see `./args.ts`); turns are NDJSON `user` lines on stdin and
|
|
14
|
-
* `init`/`assistant`/`result` envelopes on stdout (see `./stream.ts`). There
|
|
15
|
-
* is no `initialize` handshake — the child emits `init` lazily with the first
|
|
16
|
-
* turn — so readiness is "child spawned", not "handshake completed".
|
|
17
|
-
* - **MCP injection is an inline JSON config document** (`--mcp-config <json>`),
|
|
18
|
-
* not Codex's `-c mcp_servers.*` TOML CLI flags.
|
|
19
|
-
* - **Runtime-owned config** is `DispatcherClaudeCodeConfig` (bin / model /
|
|
20
|
-
* permission_mode / remote_control / extra_args / extra_env), distinct from
|
|
21
|
-
* the Codex config.
|
|
22
|
-
* - **Completion delivery** is a plain user turn (no fake task-notification),
|
|
23
|
-
* not the Codex inbox-then-trigger path.
|
|
24
|
-
*
|
|
25
|
-
* Process spawning goes through an injectable {@link ClaudeCodeSessionFactory}
|
|
26
|
-
* seam (mirroring Codex's process-factory seam), so the lifecycle contract is
|
|
27
|
-
* fully unit-testable with a fake session. A live `claude` binary is exercised
|
|
28
|
-
* only by the opt-in live test.
|
|
29
|
-
*
|
|
30
|
-
* Failure contract (unchanged by #120): a turn failure (spawn error, child
|
|
31
|
-
* exit, error `result`) is never swallowed. For inbound/restart turns it drives
|
|
32
|
-
* the runtime to `degraded` with a persisted `last_error` (observable via
|
|
33
|
-
* status/doctor). For `completionInput` it surfaces as a `failed`
|
|
34
|
-
* result the caller can act on (PR8 delivery retry). `channelInput` still
|
|
35
|
-
* returns after accept (submit != completion) so the channel can ack promptly.
|
|
36
|
-
*
|
|
37
|
-
* Restart: an unexpected child exit marks the runtime `degraded`; the next turn
|
|
38
|
-
* re-spawns the resident child with `--resume <session_id>`, restoring the
|
|
39
|
-
* conversation. There is no background backoff timer — re-spawn is lazy and
|
|
40
|
-
* bound to the (serialized) turn queue, so it stays deterministic.
|
|
41
|
-
*
|
|
42
|
-
* Per-turn idle deadline: a turn whose still-alive child goes silent — never
|
|
43
|
-
* emitting another stream line (a stall, or a wait on input the runtime cannot
|
|
44
|
-
* satisfy) — would otherwise pend forever and wedge the serial queue, and behind
|
|
45
|
-
* it TeamMate completion delivery, which awaits this runtime. `turn_timeout_ms`
|
|
46
|
-
* is a *max-idle* window (issue #156): it is reset on every inbound stream line,
|
|
47
|
-
* so a long but continuously-streaming turn (e.g. a deep audit running many
|
|
48
|
-
* tool calls for far longer than the window) is never reaped, while a child that
|
|
49
|
-
* emits nothing for the whole window still is — turning an infinite hang into a
|
|
50
|
-
* normal degraded + `last_error` (inbound) or `failed` delivery result.
|
|
51
|
-
*
|
|
52
|
-
* Reference: the resident stream-json protocol model and process-supervision
|
|
53
|
-
* shape are adapted from the Claudemux `next` implementation; the AgentRuntime /
|
|
54
|
-
* Channel / DispatcherService boundaries (provider seam, runtime-owned MCP
|
|
55
|
-
* injection, degraded/last_error status, TeamMate delivery result contract) are
|
|
56
|
-
* Dreamux's own, per `.agents/decisions/agent-runtime-provider.md`.
|
|
57
|
-
*/
|
|
58
|
-
import type { DispatcherClaudeCodeConfig } from './config.js';
|
|
59
|
-
import { type ClaudeCodeSessionFactory } from './supervisor.js';
|
|
60
|
-
import type { AgentRuntimeCapabilities, AgentRuntime, AgentRuntimeIdentity, AgentRuntimeLastResult, AgentRuntimeMcpServer, AgentRuntimePathContext, AgentRuntimeSkillSource, AgentRuntimeStateCallbacks, AgentRuntimeStatus, AgentRuntimeTextInput, AgentRuntimeTurnResult, DreamuxLogger, InboundTurnInput, TurnSettledSignal } from '@excitedjs/dreamux-types';
|
|
61
|
-
/**
|
|
62
|
-
* Everything the Claude Code runtime needs, assembled by the provider from the
|
|
63
|
-
* neutral create context plus host-supplied hooks. The host contracts the
|
|
64
|
-
* package must not reconstruct — the per-dispatcher path context, the durable
|
|
65
|
-
* state sink, and the base process env (`PATH` seeded with the host package
|
|
66
|
-
* bins) — arrive here; nothing references a Dreamux host module.
|
|
67
|
-
*/
|
|
68
|
-
export interface ClaudeCodeRuntimeDeps {
|
|
69
|
-
/** Provider-parsed Claude Code runtime config. */
|
|
70
|
-
config: DispatcherClaudeCodeConfig;
|
|
71
|
-
/** Working directory the resident `claude` child runs in. */
|
|
72
|
-
cwd: string;
|
|
73
|
-
/** Neutral state sink for status/thread transitions. */
|
|
74
|
-
state: AgentRuntimeStateCallbacks;
|
|
75
|
-
/** Neutral path context: the runtime derives its cache/log subpaths here. */
|
|
76
|
-
paths: AgentRuntimePathContext;
|
|
77
|
-
/** MCP server descriptors translated into the `--mcp-config` JSON document. */
|
|
78
|
-
mcpServers: readonly AgentRuntimeMcpServer[];
|
|
79
|
-
/** Resident-session factory (tests inject a fake). */
|
|
80
|
-
sessionFactory: ClaudeCodeSessionFactory;
|
|
81
|
-
/** Host-level bin resolver (default: identity on the config bin). */
|
|
82
|
-
resolveBinPath: (bin: string) => string;
|
|
83
|
-
/**
|
|
84
|
-
* The host's neutral env-injection entries from the create context, merged
|
|
85
|
-
* into the resident child env before this provider's own `extra_env`.
|
|
86
|
-
* Empty/omitted means inject nothing (the common case).
|
|
87
|
-
*/
|
|
88
|
-
injectEnv?: Record<string, string>;
|
|
89
|
-
/**
|
|
90
|
-
* Launcher-supplied ordered role/system-prompt content, applied as an APPEND
|
|
91
|
-
* via `--append-system-prompt`. Omitted for launches that supply none.
|
|
92
|
-
*/
|
|
93
|
-
systemPromptAppend?: readonly string[];
|
|
94
|
-
/**
|
|
95
|
-
* Role-gated skill sources core selected (issue #209 slice 6). The
|
|
96
|
-
* add-dir-compatible ones become `--add-dir` flags on every (re)spawn.
|
|
97
|
-
*/
|
|
98
|
-
skillSources?: readonly AgentRuntimeSkillSource[];
|
|
99
|
-
/**
|
|
100
|
-
* Neutral feature names the host asked this runtime to disable. Args mapping
|
|
101
|
-
* is applied on every resident (re)spawn.
|
|
102
|
-
*/
|
|
103
|
-
disableFeatures?: readonly string[];
|
|
104
|
-
/**
|
|
105
|
-
* Optional JSON Schema constraining every turn's final assistant message for
|
|
106
|
-
* the resident session's lifetime. Passed straight through to
|
|
107
|
-
* `claudeCodeResidentArgs` as the native `--json-schema` flag on every
|
|
108
|
-
* (re)spawn. In-memory only — never persisted to identity, so a resumed
|
|
109
|
-
* session that did not start with a schema does not silently gain one.
|
|
110
|
-
*/
|
|
111
|
-
outputSchema?: Record<string, unknown>;
|
|
112
|
-
/** Fired each time a delivered turn reaches a terminal state. */
|
|
113
|
-
onTurnSettled?: (settled: TurnSettledSignal) => void;
|
|
114
|
-
/** Structured logger; falls back to a minimal `console.error` sink. */
|
|
115
|
-
logger?: DreamuxLogger;
|
|
116
|
-
}
|
|
1
|
+
/** Resident Claude Code AgentRuntime using stream-json stdio. */
|
|
2
|
+
import type { ClaudeCodeRuntimeDeps } from './runtime-deps.js';
|
|
3
|
+
import type { AgentRuntimeCapabilities, AgentRuntime, AgentRuntimeIdentity, AgentRuntimeStatus, AgentRuntimeTextInput, InboundTurnInput, RuntimeAdmission } from '@excitedjs/dreamux-types';
|
|
117
4
|
/**
|
|
118
5
|
* The Claude Code agent runtime for one dispatcher. A single resident
|
|
119
6
|
* stream-json child serves every turn. Turns run serially (one at a time) and
|
|
@@ -133,15 +20,24 @@ export declare class ClaudeCodeRuntime implements AgentRuntime {
|
|
|
133
20
|
private readonly logger;
|
|
134
21
|
private status;
|
|
135
22
|
private threadId;
|
|
23
|
+
private transcriptLocator;
|
|
24
|
+
private resumeOnNextSpawn;
|
|
136
25
|
private resumed;
|
|
137
26
|
private stopped;
|
|
138
27
|
private readonly seen;
|
|
28
|
+
private readonly seenOrder;
|
|
139
29
|
private readonly seenTextInputIds;
|
|
30
|
+
private readonly seenTextInputIdOrder;
|
|
31
|
+
private readonly sourceIdDedupeWindow;
|
|
32
|
+
private readonly pendingChannelSources;
|
|
33
|
+
private readonly pendingTextSources;
|
|
34
|
+
private readonly pendingAdmissions;
|
|
140
35
|
private queue;
|
|
141
|
-
private readonly runtimeInstanceId;
|
|
142
|
-
private turnCounter;
|
|
143
36
|
private session;
|
|
144
|
-
private
|
|
37
|
+
private sessionStarting;
|
|
38
|
+
private startTask;
|
|
39
|
+
private stopTask;
|
|
40
|
+
private generation;
|
|
145
41
|
private activeTurn;
|
|
146
42
|
private queuedTurnCount;
|
|
147
43
|
private idlePromise;
|
|
@@ -151,15 +47,23 @@ export declare class ClaudeCodeRuntime implements AgentRuntime {
|
|
|
151
47
|
getCapabilities(): AgentRuntimeCapabilities;
|
|
152
48
|
getCheckpoint(): {
|
|
153
49
|
id: string;
|
|
50
|
+
transcript_locator?: string | null;
|
|
154
51
|
} | null;
|
|
155
52
|
wasCheckpointResumed(): boolean;
|
|
156
|
-
getLast(): Promise<AgentRuntimeLastResult | null>;
|
|
157
53
|
getContext(): Promise<null>;
|
|
158
54
|
resume(): Promise<void>;
|
|
159
55
|
start(): Promise<void>;
|
|
56
|
+
private startRuntime;
|
|
160
57
|
stop(): Promise<void>;
|
|
161
|
-
|
|
162
|
-
|
|
58
|
+
private stopRuntime;
|
|
59
|
+
completionInput(input: AgentRuntimeTextInput): Promise<RuntimeAdmission>;
|
|
60
|
+
private completionInputImpl;
|
|
61
|
+
private acceptTextInput;
|
|
62
|
+
channelInput(input: InboundTurnInput): Promise<RuntimeAdmission>;
|
|
63
|
+
private channelInputImpl;
|
|
64
|
+
private acceptChannelInput;
|
|
65
|
+
private trackAdmission;
|
|
66
|
+
private drainAdmissions;
|
|
163
67
|
waitIdle(): Promise<void>;
|
|
164
68
|
private runActiveTurnOnQueue;
|
|
165
69
|
private runActiveTurn;
|
|
@@ -169,18 +73,13 @@ export declare class ClaudeCodeRuntime implements AgentRuntime {
|
|
|
169
73
|
private recordQueuedTurnStart;
|
|
170
74
|
private recordQueuedTurnEnd;
|
|
171
75
|
private resolveIdleWaitersIfIdle;
|
|
172
|
-
/**
|
|
173
|
-
* Ensure a live resident session exists, spawning (or re-spawning after an
|
|
174
|
-
* unexpected exit) as needed. Re-spawn resumes the persisted session id so the
|
|
175
|
-
* conversation survives a crash.
|
|
176
|
-
*/
|
|
76
|
+
/** Ensure a live resident session exists, resuming after a child exit. */
|
|
177
77
|
private ensureSession;
|
|
178
|
-
private
|
|
78
|
+
private createSession;
|
|
79
|
+
private resolveTranscriptPath;
|
|
179
80
|
/** React to an unexpected resident-child exit: degrade and drop the session. */
|
|
180
81
|
private onSessionExit;
|
|
181
|
-
private
|
|
182
|
-
private nextTurnId;
|
|
183
|
-
private buildProcessEnv;
|
|
82
|
+
private assertGeneration;
|
|
184
83
|
private setStatus;
|
|
185
84
|
private log;
|
|
186
85
|
}
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAwBjE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAW/D,OAAO,KAAK,EACV,wBAAwB,EACxB,YAAY,EAC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