@excitedjs/agent-runtime-claude-code 0.7.1-beta.260 → 0.8.0-alpha.ged3454ecaaed
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 +22 -10
- package/dist/activity/cursor.d.ts +0 -1
- package/dist/activity/cursor.d.ts.map +1 -1
- package/dist/activity/cursor.js +5 -10
- package/dist/activity/cursor.js.map +1 -1
- package/dist/activity/native-hash.js +1 -3
- package/dist/activity/native-hash.js.map +1 -1
- package/dist/activity/opened-file.d.ts +1 -3
- package/dist/activity/opened-file.d.ts.map +1 -1
- package/dist/activity/opened-file.js +17 -20
- package/dist/activity/opened-file.js.map +1 -1
- package/dist/activity/parallel-tools.js.map +1 -1
- package/dist/activity/path.d.ts +8 -2
- package/dist/activity/path.d.ts.map +1 -1
- package/dist/activity/path.js +36 -36
- package/dist/activity/path.js.map +1 -1
- package/dist/activity/reader.d.ts +1 -4
- package/dist/activity/reader.d.ts.map +1 -1
- package/dist/activity/reader.js +38 -67
- package/dist/activity/reader.js.map +1 -1
- package/dist/activity/rewrites.d.ts.map +1 -1
- package/dist/activity/rewrites.js +1 -3
- package/dist/activity/rewrites.js.map +1 -1
- package/dist/args.d.ts +3 -3
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js.map +1 -1
- package/dist/config.d.ts +9 -22
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +13 -26
- package/dist/config.js.map +1 -1
- package/dist/control-rpc.d.ts +2 -2
- package/dist/control-rpc.d.ts.map +1 -1
- package/dist/control-rpc.js.map +1 -1
- package/dist/index.d.ts +8 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -12
- package/dist/index.js.map +1 -1
- package/dist/paths.d.ts +14 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +38 -0
- package/dist/paths.js.map +1 -0
- package/dist/plugin.d.ts +16 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +11 -0
- package/dist/plugin.js.map +1 -0
- package/dist/provider.d.ts +7 -24
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +8 -31
- package/dist/provider.js.map +1 -1
- package/dist/rpc.d.ts +16 -9
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +87 -95
- package/dist/rpc.js.map +1 -1
- package/dist/runtime-activity.d.ts +0 -1
- package/dist/runtime-activity.d.ts.map +1 -1
- package/dist/runtime-activity.js +53 -55
- package/dist/runtime-activity.js.map +1 -1
- package/dist/runtime-deps.d.ts +4 -5
- package/dist/runtime-deps.d.ts.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +26 -15
- package/dist/runtime.js.map +1 -1
- package/dist/skill-materializer.d.ts.map +1 -1
- package/dist/skill-materializer.js +1 -1
- package/dist/skill-materializer.js.map +1 -1
- package/dist/stream.d.ts +2 -9
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +12 -17
- package/dist/stream.js.map +1 -1
- package/dist/supervisor.d.ts.map +1 -1
- package/dist/supervisor.js +10 -5
- package/dist/supervisor.js.map +1 -1
- package/dist/tool-display.d.ts.map +1 -1
- package/dist/tool-display.js +66 -11
- package/dist/tool-display.js.map +1 -1
- package/dist/types.d.ts +7 -17
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -4
- package/dist/activity/budget.d.ts +0 -8
- package/dist/activity/budget.d.ts.map +0 -1
- package/dist/activity/budget.js +0 -9
- package/dist/activity/budget.js.map +0 -1
- package/dist/activity/error.d.ts +0 -16
- package/dist/activity/error.d.ts.map +0 -1
- package/dist/activity/error.js +0 -22
- package/dist/activity/error.js.map +0 -1
- package/dist/logger.d.ts +0 -7
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -26
- package/dist/logger.js.map +0 -1
- package/dist/provider-ref.d.ts +0 -8
- package/dist/provider-ref.d.ts.map +0 -1
- package/dist/provider-ref.js +0 -8
- package/dist/provider-ref.js.map +0 -1
- package/dist/runtime-session.d.ts +0 -8
- package/dist/runtime-session.d.ts.map +0 -1
- package/dist/runtime-session.js +0 -36
- package/dist/runtime-session.js.map +0 -1
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EACL,oCAAoC,EACpC,KAAK,qCAAqC,GAC3C,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,KAAK,0BAA0B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,uBAAuB,EACvB,mCAAmC,EACnC,oCAAoC,GACrC,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `@excitedjs/agent-runtime-claude-code` — the built-in Claude Code
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* `@excitedjs/agent-runtime-claude-code` — the built-in Claude Code plugin for
|
|
3
|
+
* Dreamux (`builtin:claude-code`). Its default export is the Dreamux plugin
|
|
4
|
+
* factory: the plugin contributes the Claude Code `AgentRuntimeProvider`,
|
|
5
|
+
* which implements the `@excitedjs/dreamux-types` contract.
|
|
6
|
+
* `createClaudeCodeAgentRuntimeProvider` is the named export for constructing
|
|
7
|
+
* the bare provider directly (embedders, tests). This package never imports
|
|
5
8
|
* `@excitedjs/dreamux` core.
|
|
6
9
|
*/
|
|
7
|
-
export { default
|
|
8
|
-
export {
|
|
9
|
-
export { ClaudeCodeStreamRpc, } from './rpc.js';
|
|
10
|
-
export { LineBuffer, TurnAggregator, assistantText, parseLine, buildUserMessage, buildRemoteControlEnable, buildCanUseToolAllow, buildControlAck, } from './stream.js';
|
|
11
|
-
export { claudeCodeMcpConfig, stringifyClaudeCodeMcpConfig, } from './mcp-config.js';
|
|
12
|
-
export { claudeCodeResidentArgs, claudeCodeSkillAddDirArgs, } from './args.js';
|
|
10
|
+
export { default } from './plugin.js';
|
|
11
|
+
export { createClaudeCodeAgentRuntimeProvider, } from './provider.js';
|
|
13
12
|
export { readDispatcherClaudeCodeConfig, defaultDispatcherClaudeCodeConfig, DEFAULT_CLAUDE_CODE_BIN, DEFAULT_CLAUDE_CODE_TURN_TIMEOUT_MS, ALLOWED_CLAUDE_CODE_PERMISSION_MODES, } from './config.js';
|
|
14
|
-
export { BUILTIN_CLAUDE_CODE_PROVIDER_REF } from './provider-ref.js';
|
|
15
|
-
// The claude-code diagnostic surface now lives in this package (issue #209 cleanup).
|
|
16
|
-
export { claudeCodeAgentRuntimeDiagnostic } from './diagnostic.js';
|
|
17
13
|
//# 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
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EACL,oCAAoC,GAErC,MAAM,eAAe,CAAC;AAEvB,OAAO,EAEL,8BAA8B,EAC9B,iCAAiC,EACjC,uBAAuB,EACvB,mCAAmC,EACnC,oCAAoC,GACrC,MAAM,aAAa,CAAC"}
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DreamuxEnvironment } from '@excitedjs/dreamux-types';
|
|
2
|
+
/** The process env a Claude Code child spawns with. */
|
|
3
|
+
export declare function claudeSpawnEnv(extraEnv?: Record<string, string>): NodeJS.ProcessEnv;
|
|
4
|
+
/**
|
|
5
|
+
* The Claude config home directory that applies for a given env and runtime
|
|
6
|
+
* cwd: an explicit `CLAUDE_CONFIG_DIR` override (resolved against
|
|
7
|
+
* `runtimeCwd` when relative), else `$HOME/.claude` (falling back to the
|
|
8
|
+
* running process's own home directory if the env carries no `HOME`). Pure
|
|
9
|
+
* and non-throwing — it only says what path applies; a caller that needs a
|
|
10
|
+
* missing-`HOME` failure mode (the activity reader) layers its own error
|
|
11
|
+
* semantics on top.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveClaudeConfigHomeDir(env: DreamuxEnvironment, runtimeCwd: string): string;
|
|
14
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,uDAAuD;AACvD,wBAAgB,cAAc,CAC5B,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACpC,MAAM,CAAC,UAAU,CAEnB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,kBAAkB,EACvB,UAAU,EAAE,MAAM,GACjB,MAAM,CASR"}
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code spawn-env and config-home-path resolution.
|
|
3
|
+
*
|
|
4
|
+
* The Claude Code child process spawns with the ambient process env (what a
|
|
5
|
+
* vanilla `claude` invocation would see) plus this provider's own
|
|
6
|
+
* `config.extra_env`. Claude Code itself resolves its config/session home
|
|
7
|
+
* from that same merged env — an explicit `CLAUDE_CONFIG_DIR` override, else
|
|
8
|
+
* `$HOME/.claude` — so both the runtime spawn path and anything that needs to
|
|
9
|
+
* know which config home a runtime will actually use (the activity reader)
|
|
10
|
+
* share one derivation here. It is claude-code-specific and carries no
|
|
11
|
+
* `~/.dreamux` knowledge, so it belongs to this package, not to Dreamux core.
|
|
12
|
+
*/
|
|
13
|
+
import { homedir } from 'node:os';
|
|
14
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
15
|
+
/** The process env a Claude Code child spawns with. */
|
|
16
|
+
export function claudeSpawnEnv(extraEnv = {}) {
|
|
17
|
+
return { ...globalThis.process.env, ...extraEnv };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The Claude config home directory that applies for a given env and runtime
|
|
21
|
+
* cwd: an explicit `CLAUDE_CONFIG_DIR` override (resolved against
|
|
22
|
+
* `runtimeCwd` when relative), else `$HOME/.claude` (falling back to the
|
|
23
|
+
* running process's own home directory if the env carries no `HOME`). Pure
|
|
24
|
+
* and non-throwing — it only says what path applies; a caller that needs a
|
|
25
|
+
* missing-`HOME` failure mode (the activity reader) layers its own error
|
|
26
|
+
* semantics on top.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveClaudeConfigHomeDir(env, runtimeCwd) {
|
|
29
|
+
const configured = env['CLAUDE_CONFIG_DIR'];
|
|
30
|
+
if (configured !== undefined && configured !== '') {
|
|
31
|
+
return isAbsolute(configured)
|
|
32
|
+
? configured
|
|
33
|
+
: resolve(runtimeCwd, configured);
|
|
34
|
+
}
|
|
35
|
+
const home = env['HOME'];
|
|
36
|
+
return join(home !== undefined && home !== '' ? home : homedir(), '.claude');
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../src/paths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAItD,uDAAuD;AACvD,MAAM,UAAU,cAAc,CAC5B,WAAmC,EAAE;IAErC,OAAO,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,QAAQ,EAAE,CAAC;AACpD,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CACxC,GAAuB,EACvB,UAAkB;IAElB,MAAM,UAAU,GAAG,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC5C,IAAI,UAAU,KAAK,SAAS,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;QAClD,OAAO,UAAU,CAAC,UAAU,CAAC;YAC3B,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC;IACD,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,SAAS,CAAC,CAAC;AAC/E,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in Claude Code plugin, always loaded by Dreamux.
|
|
3
|
+
*
|
|
4
|
+
* Contributes the Claude Code Agent Runtime provider under the name
|
|
5
|
+
* `claude-code`, which config addresses as `builtin:claude-code`. It
|
|
6
|
+
* constructs the provider on package defaults: `AgentRuntimeProvider` has no
|
|
7
|
+
* `ref`/`descriptor` member (Core owns registration identity in its registry,
|
|
8
|
+
* never echoed back to the provider), and
|
|
9
|
+
* `ClaudeCodeAgentRuntimeProviderOptions`'s bin-resolver/session-factory/
|
|
10
|
+
* session-id fields are test/embedder seams this plugin has no host-supplied
|
|
11
|
+
* value for.
|
|
12
|
+
*/
|
|
13
|
+
import type { DreamuxPlugin } from '@excitedjs/dreamux-types';
|
|
14
|
+
/** The zero-argument plugin factory Dreamux's plugin loader calls. */
|
|
15
|
+
export default function claudeCodePlugin(): DreamuxPlugin;
|
|
16
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAI9D,sEAAsE;AACtE,MAAM,CAAC,OAAO,UAAU,gBAAgB,IAAI,aAAa,CAUxD"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { createClaudeCodeAgentRuntimeProvider } from './provider.js';
|
|
2
|
+
/** The zero-argument plugin factory Dreamux's plugin loader calls. */
|
|
3
|
+
export default function claudeCodePlugin() {
|
|
4
|
+
return {
|
|
5
|
+
name: 'claude-code',
|
|
6
|
+
contribute(host) {
|
|
7
|
+
host.agentRuntimeProviders.contribute('claude-code', createClaudeCodeAgentRuntimeProvider());
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oCAAoC,EAAE,MAAM,eAAe,CAAC;AAErE,sEAAsE;AACtE,MAAM,CAAC,OAAO,UAAU,gBAAgB;IACtC,OAAO;QACL,IAAI,EAAE,aAAa;QACnB,UAAU,CAAC,IAAI;YACb,IAAI,CAAC,qBAAqB,CAAC,UAAU,CACnC,aAAa,EACb,oCAAoC,EAAE,CACvC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { ClaudeCodeRuntimeDeps } from './runtime-deps.js';
|
|
2
|
-
import {
|
|
2
|
+
import { type DispatcherClaudeCodeConfig } from './config.js';
|
|
3
3
|
import { type ClaudeCodeSessionFactory } from './supervisor.js';
|
|
4
|
-
import type { AgentRuntimeProvider, AgentRuntimeProviderCapabilities
|
|
4
|
+
import type { AgentRuntimeProvider, AgentRuntimeProviderCapabilities } from '@excitedjs/dreamux-types';
|
|
5
5
|
/**
|
|
6
|
-
* Construction options for the built-in Claude Code provider.
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* without changing the provider.
|
|
6
|
+
* Construction options for the built-in Claude Code provider. Registration
|
|
7
|
+
* identity is Core's: the provider carries no descriptor. What remains here
|
|
8
|
+
* are the test/host seams (the resident-session factory, an optional host bin
|
|
9
|
+
* resolver) that let core and tests wire behavior without changing the
|
|
10
|
+
* provider.
|
|
12
11
|
*/
|
|
13
12
|
export interface ClaudeCodeAgentRuntimeProviderOptions {
|
|
14
13
|
/** Optional host-level bin resolver (default: identity on the config bin). */
|
|
@@ -35,20 +34,4 @@ export declare const CLAUDE_CODE_AGENT_RUNTIME_CAPABILITIES: AgentRuntimeProvide
|
|
|
35
34
|
* the neutral opaque session id.
|
|
36
35
|
*/
|
|
37
36
|
export declare function createClaudeCodeAgentRuntimeProvider(options?: ClaudeCodeAgentRuntimeProviderOptions): AgentRuntimeProvider<DispatcherClaudeCodeConfig>;
|
|
38
|
-
/** Re-export the typed accessor for a runtime's resolved claude-code config. */
|
|
39
|
-
export { dispatcherClaudeCodeConfig };
|
|
40
|
-
/**
|
|
41
|
-
* Default export — the factory Dreamux core's generic provider-loader selects
|
|
42
|
-
* for the `builtin:claude-code` ref (it imports this package and calls the
|
|
43
|
-
* default export with `{ ref }`). It returns a provider on package defaults:
|
|
44
|
-
* the real resident-session factory and an identity bin resolver.
|
|
45
|
-
*
|
|
46
|
-
* This is the production path. Core drives the loaded provider through the
|
|
47
|
-
* neutral facade alone — it holds no adapter for this package — and supplies
|
|
48
|
-
* every host contract (state lease, path context, skill sources, MCP servers)
|
|
49
|
-
* through the neutral create context. The options argument of
|
|
50
|
-
* {@link createClaudeCodeAgentRuntimeProvider} exists for embedders and tests.
|
|
51
|
-
*/
|
|
52
|
-
declare const claudeCodeAgentRuntimeProviderFactory: AgentRuntimeProviderFactory<DispatcherClaudeCodeConfig>;
|
|
53
|
-
export default claudeCodeAgentRuntimeProviderFactory;
|
|
54
37
|
//# sourceMappingURL=provider.d.ts.map
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAGL,KAAK,0BAA0B,EAChC,MAAM,aAAa,CAAC;AACrB,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,iBAAiB,CAAC;AAIzB,OAAO,KAAK,EAGV,oBAAoB,EACpB,gCAAgC,EACjC,MAAM,0BAA0B,CAAC;AASlC;;;;;;GAMG;AACH,MAAM,WAAW,qCAAqC;IACpD,8EAA8E;IAC9E,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACzC,mEAAmE;IACnE,cAAc,CAAC,EAAE,wBAAwB,CAAC;IAC1C,uEAAuE;IACvE,iBAAiB,CAAC,EAAE,qBAAqB,CAAC,mBAAmB,CAAC,CAAC;CAChE;AAED;;;;GAIG;AACH,eAAO,MAAM,sCAAsC,EAAE,gCACvC,CAAC;AAEf;;;;;;;;;GASG;AACH,wBAAgB,oCAAoC,CAClD,OAAO,GAAE,qCAA0C,GAClD,oBAAoB,CAAC,0BAA0B,CAAC,CAwDlD"}
|
package/dist/provider.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ClaudeCodeRuntime } from './runtime.js';
|
|
2
|
-
import { DEFAULT_CLAUDE_CODE_BIN,
|
|
2
|
+
import { DEFAULT_CLAUDE_CODE_BIN, readDispatcherClaudeCodeConfig, } from './config.js';
|
|
3
3
|
import { createDefaultClaudeCodeSession, } from './supervisor.js';
|
|
4
4
|
import { claudeCodeAgentRuntimeDiagnostic } from './diagnostic.js';
|
|
5
5
|
import { readClaudeRecentActivity } from './activity/reader.js';
|
|
6
|
+
import { resolveClaudeConfigHomeDir } from './paths.js';
|
|
6
7
|
function normalizedSystemPromptAppend(append) {
|
|
7
8
|
const normalized = (append ?? []).filter((prompt) => prompt !== '');
|
|
8
9
|
return normalized.length > 0 ? normalized : undefined;
|
|
@@ -29,6 +30,7 @@ export function createClaudeCodeAgentRuntimeProvider(options = {}) {
|
|
|
29
30
|
return {
|
|
30
31
|
getCapabilities: () => CLAUDE_CODE_AGENT_RUNTIME_CAPABILITIES,
|
|
31
32
|
diagnostic: claudeCodeAgentRuntimeDiagnostic,
|
|
33
|
+
operatorStateRoot: (env) => resolveClaudeConfigHomeDir(env, process.cwd()),
|
|
32
34
|
onboard: {
|
|
33
35
|
async collect(_context, prompts) {
|
|
34
36
|
const bin = await prompts.text({
|
|
@@ -51,47 +53,22 @@ export function createClaudeCodeAgentRuntimeProvider(options = {}) {
|
|
|
51
53
|
config: context.config,
|
|
52
54
|
cwd: context.cwd,
|
|
53
55
|
state: context.state,
|
|
54
|
-
activitySink: context.activity
|
|
56
|
+
activitySink: context.activity,
|
|
55
57
|
paths: context.paths,
|
|
56
58
|
mcpServers: context.mcpServers,
|
|
57
59
|
sessionFactory,
|
|
58
60
|
resolveBinPath,
|
|
59
|
-
|
|
60
|
-
? { injectEnv: context.injectEnv }
|
|
61
|
-
: {}),
|
|
62
|
-
...(context.skillSources !== undefined
|
|
63
|
-
? { skillSources: context.skillSources }
|
|
64
|
-
: {}),
|
|
61
|
+
skillSources: context.skillSources,
|
|
65
62
|
// Neutral seam name in, provider-native name out: `disableFeatures` is
|
|
66
63
|
// this package's own internal wording and stops at the adapter.
|
|
67
64
|
disableFeatures: context.disabledFeatures,
|
|
68
65
|
outputSchema: context.outputSchema,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
...(systemPromptAppend !== undefined
|
|
73
|
-
? { systemPromptAppend }
|
|
74
|
-
: {}),
|
|
75
|
-
...(context.logger !== undefined ? { logger: context.logger } : {}),
|
|
66
|
+
generateSessionId: options.generateSessionId,
|
|
67
|
+
systemPromptAppend,
|
|
68
|
+
logger: context.logger,
|
|
76
69
|
};
|
|
77
70
|
return new ClaudeCodeRuntime(context.identity, deps);
|
|
78
71
|
},
|
|
79
72
|
};
|
|
80
73
|
}
|
|
81
|
-
/** Re-export the typed accessor for a runtime's resolved claude-code config. */
|
|
82
|
-
export { dispatcherClaudeCodeConfig };
|
|
83
|
-
/**
|
|
84
|
-
* Default export — the factory Dreamux core's generic provider-loader selects
|
|
85
|
-
* for the `builtin:claude-code` ref (it imports this package and calls the
|
|
86
|
-
* default export with `{ ref }`). It returns a provider on package defaults:
|
|
87
|
-
* the real resident-session factory and an identity bin resolver.
|
|
88
|
-
*
|
|
89
|
-
* This is the production path. Core drives the loaded provider through the
|
|
90
|
-
* neutral facade alone — it holds no adapter for this package — and supplies
|
|
91
|
-
* every host contract (state lease, path context, skill sources, MCP servers)
|
|
92
|
-
* through the neutral create context. The options argument of
|
|
93
|
-
* {@link createClaudeCodeAgentRuntimeProvider} exists for embedders and tests.
|
|
94
|
-
*/
|
|
95
|
-
const claudeCodeAgentRuntimeProviderFactory = () => createClaudeCodeAgentRuntimeProvider();
|
|
96
|
-
export default claudeCodeAgentRuntimeProviderFactory;
|
|
97
74
|
//# sourceMappingURL=provider.js.map
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EACL,uBAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/prov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
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
/** Resident Claude input admission, request settlement and native stream handling. */
|
|
2
2
|
import type { Writable } from 'node:stream';
|
|
3
|
-
import type { TurnSubmitOptions } from './types.js';
|
|
4
|
-
import type { RuntimeAdmission } from '@excitedjs/dreamux-types';
|
|
3
|
+
import type { TurnOutcome, TurnSubmitOptions } from './types.js';
|
|
4
|
+
import type { RuntimeAdmission, RuntimeCompletion } from '@excitedjs/dreamux-types';
|
|
5
5
|
export interface ClaudeCodeStreamRpcOptions {
|
|
6
6
|
sessionId: string | null;
|
|
7
|
-
outputSchemaEnabled?: boolean;
|
|
7
|
+
outputSchemaEnabled?: boolean | undefined;
|
|
8
8
|
turnTimeoutMs: number;
|
|
9
|
-
log?: (level: 'info' | 'warn' | 'error', msg: string, err?: unknown) => void;
|
|
9
|
+
log?: ((level: 'info' | 'warn' | 'error', msg: string, err?: unknown) => void) | undefined;
|
|
10
10
|
reapOnTimeout: (error: Error) => void;
|
|
11
|
-
onRemoteControlUrl?: (url: string) => void;
|
|
12
|
-
onProtocolEvent?: import('./types.js').ClaudeCodeSessionSpec['onProtocolEvent'];
|
|
11
|
+
onRemoteControlUrl?: ((url: string) => void) | undefined;
|
|
12
|
+
onProtocolEvent?: import('./types.js').ClaudeCodeSessionSpec['onProtocolEvent'] | undefined;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* One resident transport, one association from UUID to unanswered request.
|
|
16
|
+
* Native results consume requests directly; no aggregate execution window waits
|
|
17
|
+
* for terminal lifecycle frames. The consumed set also includes native internal
|
|
18
|
+
* commands so cancellation is scoped to work that actually entered a turn.
|
|
19
|
+
*/
|
|
14
20
|
export declare class ClaudeCodeStreamRpc {
|
|
15
21
|
private readonly stdin;
|
|
16
22
|
private readonly options;
|
|
@@ -18,7 +24,6 @@ export declare class ClaudeCodeStreamRpc {
|
|
|
18
24
|
private readonly aggregator;
|
|
19
25
|
private readonly requests;
|
|
20
26
|
private readonly consumed;
|
|
21
|
-
private lifecycleSupported;
|
|
22
27
|
private timer;
|
|
23
28
|
private closed;
|
|
24
29
|
private readonly control;
|
|
@@ -55,7 +60,9 @@ export declare class ClaudeCodeStreamRpc {
|
|
|
55
60
|
/** Outstanding work has a max-idle deadline; pure background work has none. */
|
|
56
61
|
private armIdleTimer;
|
|
57
62
|
private onLine;
|
|
58
|
-
private decideLifecycleSupport;
|
|
59
|
-
private rejectWaitingRequests;
|
|
60
63
|
}
|
|
64
|
+
/** One immutable completion per native result, shared by every answered request. */
|
|
65
|
+
export declare function completionFromTurnOutcome(outcome: TurnOutcome, expectedSessionId: string | null, requiresStructuredOutput: boolean): RuntimeCompletion;
|
|
66
|
+
/** Claude's own explanation for a failed native result. */
|
|
67
|
+
export declare function turnFailureMessage(outcome: TurnOutcome): string;
|
|
61
68
|
//# sourceMappingURL=rpc.d.ts.map
|
package/dist/rpc.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../src/rpc.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAU5C,OAAO,KAAK,EAAc,WAAW,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAGlB,MAAM,0BAA0B,CAAC;AASlC,MAAM,WAAW,0BAA0B;IACzC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,EACA,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAA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AOG;IACG,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAWjD,mBAAmB,IAAI,IAAI;IAK3B,OAAO,CAAC,gBAAgB;IAOxB,+EAA+E;IAC/E,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,MAAM;CA+Hf;AAMD,oFAAoF;AACpF,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,WAAW,EACpB,iBAAiB,EAAE,MAAM,GAAG,IAAI,EAChC,wBAAwB,EAAE,OAAO,GAChC,iBAAiB,CAwBnB;AAED,2DAA2D;AAC3D,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,CAQ/D"}
|
package/dist/rpc.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { buildUserMessage, LineBuffer, parseLine, TurnAggregator, } from './stream.js';
|
|
3
3
|
import { ClaudeCodeControlRpc } from './control-rpc.js';
|
|
4
|
-
import { completionFromTurnOutcome } from './runtime-session.js';
|
|
5
|
-
/**
|
|
6
|
-
* One resident transport, one association from UUID to unanswered request.
|
|
7
|
-
* Native results consume requests directly; no aggregate execution window waits
|
|
8
|
-
* for terminal lifecycle frames. The consumed set also includes native internal
|
|
9
|
-
* commands so cancellation is scoped to work that actually entered a turn.
|
|
10
|
-
*/
|
|
11
4
|
/**
|
|
12
5
|
* The two `terminal_reason` values that mean the turn was aborted rather than
|
|
13
6
|
* answered, from the Agent SDK's documented set. The other reasons all name a
|
|
@@ -16,7 +9,16 @@ import { completionFromTurnOutcome } from './runtime-session.js';
|
|
|
16
9
|
* own `interrupt` control request: the other documented cause, a permission
|
|
17
10
|
* callback denying with `interrupt`, cannot happen where every callback allows.
|
|
18
11
|
*/
|
|
19
|
-
const INTERRUPT_TERMINAL_REASONS = new Set([
|
|
12
|
+
const INTERRUPT_TERMINAL_REASONS = new Set([
|
|
13
|
+
'aborted_streaming',
|
|
14
|
+
'aborted_tools',
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* One resident transport, one association from UUID to unanswered request.
|
|
18
|
+
* Native results consume requests directly; no aggregate execution window waits
|
|
19
|
+
* for terminal lifecycle frames. The consumed set also includes native internal
|
|
20
|
+
* commands so cancellation is scoped to work that actually entered a turn.
|
|
21
|
+
*/
|
|
20
22
|
export class ClaudeCodeStreamRpc {
|
|
21
23
|
stdin;
|
|
22
24
|
options;
|
|
@@ -24,7 +26,6 @@ export class ClaudeCodeStreamRpc {
|
|
|
24
26
|
aggregator = new TurnAggregator();
|
|
25
27
|
requests = new Map();
|
|
26
28
|
consumed = new Set();
|
|
27
|
-
lifecycleSupported = null;
|
|
28
29
|
timer = null;
|
|
29
30
|
closed = false;
|
|
30
31
|
control;
|
|
@@ -44,47 +45,35 @@ export class ClaudeCodeStreamRpc {
|
|
|
44
45
|
}
|
|
45
46
|
submit(prompt, options = {}, commandUuid = randomUUID()) {
|
|
46
47
|
if (this.closed || !this.stdin.writable) {
|
|
47
|
-
return Promise.resolve({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return Promise.resolve({ status: 'failed', error: lifecycleUnsupportedError() });
|
|
48
|
+
return Promise.resolve({
|
|
49
|
+
status: 'failed',
|
|
50
|
+
error: new Error('claude resident child is not running'),
|
|
51
|
+
});
|
|
52
52
|
}
|
|
53
53
|
let settle;
|
|
54
54
|
const submission = Object.freeze({
|
|
55
|
-
settled: new Promise((resolve) => {
|
|
55
|
+
settled: new Promise((resolve) => {
|
|
56
|
+
settle = resolve;
|
|
57
|
+
}),
|
|
56
58
|
});
|
|
57
59
|
return new Promise((admit) => {
|
|
58
|
-
const request = {
|
|
59
|
-
submission,
|
|
60
|
-
settle,
|
|
61
|
-
admit,
|
|
62
|
-
write: () => {
|
|
63
|
-
request.write = null;
|
|
64
|
-
this.armIdleTimer();
|
|
65
|
-
try {
|
|
66
|
-
this.stdin.write(`${buildUserMessage(prompt, options, commandUuid)}\n`, (error) => {
|
|
67
|
-
if (error != null)
|
|
68
|
-
this.failWrite(commandUuid, request, error);
|
|
69
|
-
else
|
|
70
|
-
this.acceptRequest(request);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
this.failWrite(commandUuid, request, asError(error));
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
};
|
|
60
|
+
const request = { submission, settle, admit };
|
|
78
61
|
// Registration precedes writing: a transport may synchronously acknowledge
|
|
79
|
-
// or answer this message before write
|
|
62
|
+
// or answer this message before the stdin write returns or invokes its
|
|
63
|
+
// callback.
|
|
80
64
|
this.requests.set(commandUuid, request);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
65
|
+
this.armIdleTimer();
|
|
66
|
+
try {
|
|
67
|
+
this.stdin.write(`${buildUserMessage(prompt, options, commandUuid)}\n`, (error) => {
|
|
68
|
+
if (error != null)
|
|
69
|
+
this.failWrite(commandUuid, request, error);
|
|
70
|
+
else
|
|
71
|
+
this.acceptRequest(request);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
this.failWrite(commandUuid, request, asError(error));
|
|
85
76
|
}
|
|
86
|
-
else if (!concurrent)
|
|
87
|
-
request.write();
|
|
88
77
|
});
|
|
89
78
|
}
|
|
90
79
|
acceptRequest(request) {
|
|
@@ -123,10 +112,12 @@ export class ClaudeCodeStreamRpc {
|
|
|
123
112
|
const error = settlement.kind === 'failed'
|
|
124
113
|
? settlement.error
|
|
125
114
|
: new Error('claude resident session stopped before write acknowledgement');
|
|
115
|
+
// Every request here has already been written: submit() writes to stdin
|
|
116
|
+
// synchronously, in the same tick as registration, so nothing in this map
|
|
117
|
+
// is ever unwritten. What is unknown is only whether claude received or
|
|
118
|
+
// acted on it before the session ended.
|
|
126
119
|
for (const request of this.requests.values()) {
|
|
127
|
-
request.admit?.(
|
|
128
|
-
? { status: 'ambiguous', error }
|
|
129
|
-
: settlement.kind === 'stopped' ? { status: 'stopped' } : { status: 'failed', error });
|
|
120
|
+
request.admit?.({ status: 'ambiguous', error });
|
|
130
121
|
request.admit = null;
|
|
131
122
|
request.settle(settlement);
|
|
132
123
|
}
|
|
@@ -190,7 +181,6 @@ export class ClaudeCodeStreamRpc {
|
|
|
190
181
|
switch (line.kind) {
|
|
191
182
|
case 'init':
|
|
192
183
|
this.aggregator.accept(line);
|
|
193
|
-
this.decideLifecycleSupport(line.capabilities.includes('msg_lifecycle_v1'));
|
|
194
184
|
break;
|
|
195
185
|
case 'assistant':
|
|
196
186
|
this.aggregator.accept(line);
|
|
@@ -207,22 +197,29 @@ export class ClaudeCodeStreamRpc {
|
|
|
207
197
|
if (state === 'started')
|
|
208
198
|
this.consumed.add(commandUuid);
|
|
209
199
|
const request = this.requests.get(commandUuid);
|
|
210
|
-
if (request
|
|
200
|
+
if (request !== undefined) {
|
|
211
201
|
this.acceptRequest(request);
|
|
212
202
|
// Consumed commands can report cancelled before their failure result.
|
|
213
203
|
// Keep the result's members; lifecycle alone cannot supply its outcome.
|
|
214
|
-
if (state === 'discarded' ||
|
|
204
|
+
if (state === 'discarded' ||
|
|
205
|
+
state === 'refused' ||
|
|
215
206
|
(state === 'cancelled' && !this.consumed.has(commandUuid))) {
|
|
216
207
|
this.requests.delete(commandUuid);
|
|
217
|
-
request.settle({
|
|
208
|
+
request.settle({
|
|
209
|
+
kind: 'failed',
|
|
210
|
+
error: new Error(`claude command was ${state}`),
|
|
211
|
+
});
|
|
218
212
|
this.clearIdleIfEmpty();
|
|
219
213
|
}
|
|
220
214
|
}
|
|
221
215
|
// An unconsumed command's cancellation cannot discard generating text.
|
|
222
216
|
if (state === 'cancelled' && this.consumed.has(commandUuid))
|
|
223
217
|
this.aggregator.discard();
|
|
224
|
-
this.options.onProtocolEvent?.({
|
|
225
|
-
|
|
218
|
+
this.options.onProtocolEvent?.({
|
|
219
|
+
kind: 'command_lifecycle',
|
|
220
|
+
commandUuid,
|
|
221
|
+
state,
|
|
222
|
+
});
|
|
226
223
|
break;
|
|
227
224
|
}
|
|
228
225
|
case 'result': {
|
|
@@ -233,21 +230,13 @@ export class ClaudeCodeStreamRpc {
|
|
|
233
230
|
const uuid = line.outcome.userMessageUuid;
|
|
234
231
|
if (uuid !== null)
|
|
235
232
|
commandUuids.add(uuid);
|
|
236
|
-
if (this.lifecycleSupported !== true && uuid === null) {
|
|
237
|
-
for (const [id, request] of this.requests) {
|
|
238
|
-
if (request.write === null)
|
|
239
|
-
commandUuids.add(id);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
233
|
const answered = [];
|
|
243
|
-
const submittedUuids = [];
|
|
244
234
|
for (const id of commandUuids) {
|
|
245
235
|
const request = this.requests.get(id);
|
|
246
|
-
if (request === undefined
|
|
236
|
+
if (request === undefined)
|
|
247
237
|
continue;
|
|
248
238
|
this.requests.delete(id);
|
|
249
239
|
answered.push(request);
|
|
250
|
-
submittedUuids.push(id);
|
|
251
240
|
}
|
|
252
241
|
this.clearIdleIfEmpty();
|
|
253
242
|
// What ended this turn is the turn's own fact. An aborted turn reports
|
|
@@ -264,18 +253,20 @@ export class ClaudeCodeStreamRpc {
|
|
|
264
253
|
this.interruptRequested = false;
|
|
265
254
|
this.control.settleInterrupt(undefined, interrupted);
|
|
266
255
|
}
|
|
267
|
-
const completion = interrupted || answered.length === 0
|
|
256
|
+
const completion = interrupted || answered.length === 0
|
|
257
|
+
? null
|
|
258
|
+
: completionFromTurnOutcome(outcome, this.options.sessionId, this.options.outputSchemaEnabled === true);
|
|
268
259
|
// Remove the answered requests before callbacks can admit or stop work.
|
|
269
260
|
// Native end is still delivered before these submissions settle.
|
|
270
261
|
this.options.onProtocolEvent?.(interrupted
|
|
271
|
-
? { kind: 'interrupted', outcome }
|
|
272
|
-
: { kind: 'result',
|
|
262
|
+
? { kind: 'interrupted', uuid: line.uuid, outcome }
|
|
263
|
+
: { kind: 'result', uuid: line.uuid, outcome });
|
|
273
264
|
for (const request of answered) {
|
|
274
265
|
this.acceptRequest(request);
|
|
275
|
-
request.settle(interrupted
|
|
266
|
+
request.settle(interrupted
|
|
267
|
+
? { kind: 'stopped' }
|
|
268
|
+
: { kind: 'completion', completion: completion });
|
|
276
269
|
}
|
|
277
|
-
if (this.lifecycleSupported !== true)
|
|
278
|
-
this.rejectWaitingRequests();
|
|
279
270
|
break;
|
|
280
271
|
}
|
|
281
272
|
case 'control_request':
|
|
@@ -291,37 +282,38 @@ export class ClaudeCodeStreamRpc {
|
|
|
291
282
|
break;
|
|
292
283
|
}
|
|
293
284
|
}
|
|
294
|
-
decideLifecycleSupport(supported) {
|
|
295
|
-
if (this.lifecycleSupported === true)
|
|
296
|
-
return;
|
|
297
|
-
if (!supported && this.lifecycleSupported !== null)
|
|
298
|
-
return;
|
|
299
|
-
this.lifecycleSupported = supported;
|
|
300
|
-
if (!supported) {
|
|
301
|
-
this.rejectWaitingRequests();
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
for (const request of this.requests.values())
|
|
305
|
-
request.write?.();
|
|
306
|
-
}
|
|
307
|
-
rejectWaitingRequests() {
|
|
308
|
-
const error = this.lifecycleSupported === false ? lifecycleUnsupportedError()
|
|
309
|
-
: new Error('claude result arrived before concurrent-input capability was decided');
|
|
310
|
-
for (const [uuid, request] of this.requests) {
|
|
311
|
-
if (request.write === null)
|
|
312
|
-
continue;
|
|
313
|
-
this.requests.delete(uuid);
|
|
314
|
-
request.admit?.({ status: 'failed', error });
|
|
315
|
-
request.admit = null;
|
|
316
|
-
request.settle({ kind: 'failed', error });
|
|
317
|
-
}
|
|
318
|
-
this.clearIdleIfEmpty();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
function lifecycleUnsupportedError() {
|
|
322
|
-
return new Error('claude resident session cannot attribute concurrent inputs: msg_lifecycle_v1 is unavailable');
|
|
323
285
|
}
|
|
324
286
|
function asError(error) {
|
|
325
287
|
return error instanceof Error ? error : new Error(String(error));
|
|
326
288
|
}
|
|
289
|
+
/** One immutable completion per native result, shared by every answered request. */
|
|
290
|
+
export function completionFromTurnOutcome(outcome, expectedSessionId, requiresStructuredOutput) {
|
|
291
|
+
let error = null;
|
|
292
|
+
if (outcome.sessionId !== null &&
|
|
293
|
+
outcome.sessionId !== '' &&
|
|
294
|
+
outcome.sessionId !== expectedSessionId) {
|
|
295
|
+
error = new Error('claude-code returned a session id that differs from the pinned native session');
|
|
296
|
+
}
|
|
297
|
+
else if (outcome.isError) {
|
|
298
|
+
error = new Error(turnFailureMessage(outcome));
|
|
299
|
+
}
|
|
300
|
+
else if (requiresStructuredOutput && !outcome.hasStructuredOutput) {
|
|
301
|
+
error = new Error('claude turn did not return structured_output for a ' +
|
|
302
|
+
'--json-schema session');
|
|
303
|
+
}
|
|
304
|
+
return error !== null
|
|
305
|
+
? Object.freeze({ status: 'failed', error })
|
|
306
|
+
: Object.freeze({
|
|
307
|
+
status: 'completed',
|
|
308
|
+
resultText: outcome.text === '' ? null : outcome.text,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/** Claude's own explanation for a failed native result. */
|
|
312
|
+
export function turnFailureMessage(outcome) {
|
|
313
|
+
return (outcome.errors.join('; ') ||
|
|
314
|
+
(outcome.subtype === 'success' ? outcome.text : '') ||
|
|
315
|
+
outcome.terminalReason ||
|
|
316
|
+
outcome.subtype ||
|
|
317
|
+
'claude turn failed');
|
|
318
|
+
}
|
|
327
319
|
//# sourceMappingURL=rpc.js.map
|