@slopus/rig-codemode-codex 0.0.0-bootstrap.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +201 -0
  2. package/LICENSE-CODEX +201 -0
  3. package/NOTICE-CODEX +6 -0
  4. package/README.md +124 -0
  5. package/THIRD-PARTY-LICENSES.json +966 -0
  6. package/THIRD-PARTY-NOTICES.md +9 -0
  7. package/UPSTREAM.md +26 -0
  8. package/dist/CodeMode.d.ts +13 -0
  9. package/dist/CodeMode.d.ts.map +1 -0
  10. package/dist/CodeMode.js +64 -0
  11. package/dist/CodeMode.js.map +1 -0
  12. package/dist/CodeModeHostCommand.d.ts +15 -0
  13. package/dist/CodeModeHostCommand.d.ts.map +1 -0
  14. package/dist/CodeModeHostCommand.js +2 -0
  15. package/dist/CodeModeHostCommand.js.map +1 -0
  16. package/dist/CodeModeSession.d.ts +38 -0
  17. package/dist/CodeModeSession.d.ts.map +1 -0
  18. package/dist/CodeModeSession.js +207 -0
  19. package/dist/CodeModeSession.js.map +1 -0
  20. package/dist/Deferred.d.ts +7 -0
  21. package/dist/Deferred.d.ts.map +1 -0
  22. package/dist/Deferred.js +12 -0
  23. package/dist/Deferred.js.map +1 -0
  24. package/dist/FramedProcess.d.ts +21 -0
  25. package/dist/FramedProcess.d.ts.map +1 -0
  26. package/dist/FramedProcess.js +125 -0
  27. package/dist/FramedProcess.js.map +1 -0
  28. package/dist/HostClient.d.ts +41 -0
  29. package/dist/HostClient.d.ts.map +1 -0
  30. package/dist/HostClient.js +261 -0
  31. package/dist/HostClient.js.map +1 -0
  32. package/dist/assertJsonValue.d.ts +3 -0
  33. package/dist/assertJsonValue.d.ts.map +1 -0
  34. package/dist/assertJsonValue.js +39 -0
  35. package/dist/assertJsonValue.js.map +1 -0
  36. package/dist/createCodeMode.d.ts +4 -0
  37. package/dist/createCodeMode.d.ts.map +1 -0
  38. package/dist/createCodeMode.js +5 -0
  39. package/dist/createCodeMode.js.map +1 -0
  40. package/dist/createCodeModeHostCommand.d.ts +3 -0
  41. package/dist/createCodeModeHostCommand.d.ts.map +1 -0
  42. package/dist/createCodeModeHostCommand.js +22 -0
  43. package/dist/createCodeModeHostCommand.js.map +1 -0
  44. package/dist/createLinuxSandboxCommand.d.ts +3 -0
  45. package/dist/createLinuxSandboxCommand.d.ts.map +1 -0
  46. package/dist/createLinuxSandboxCommand.js +27 -0
  47. package/dist/createLinuxSandboxCommand.js.map +1 -0
  48. package/dist/createMacOsSandboxCommand.d.ts +3 -0
  49. package/dist/createMacOsSandboxCommand.d.ts.map +1 -0
  50. package/dist/createMacOsSandboxCommand.js +9 -0
  51. package/dist/createMacOsSandboxCommand.js.map +1 -0
  52. package/dist/createMacOsSandboxProfile.d.ts +2 -0
  53. package/dist/createMacOsSandboxProfile.d.ts.map +1 -0
  54. package/dist/createMacOsSandboxProfile.js +50 -0
  55. package/dist/createMacOsSandboxProfile.js.map +1 -0
  56. package/dist/index.d.ts +7 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +6 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/platform.d.ts +46 -0
  61. package/dist/platform.d.ts.map +1 -0
  62. package/dist/platform.js +45 -0
  63. package/dist/platform.js.map +1 -0
  64. package/dist/protocol.d.ts +113 -0
  65. package/dist/protocol.d.ts.map +1 -0
  66. package/dist/protocol.js +2 -0
  67. package/dist/protocol.js.map +1 -0
  68. package/dist/resolveCodeModeBinary.d.ts +2 -0
  69. package/dist/resolveCodeModeBinary.d.ts.map +1 -0
  70. package/dist/resolveCodeModeBinary.js +44 -0
  71. package/dist/resolveCodeModeBinary.js.map +1 -0
  72. package/dist/resolveCodeModeSandboxExecutable.d.ts +2 -0
  73. package/dist/resolveCodeModeSandboxExecutable.d.ts.map +1 -0
  74. package/dist/resolveCodeModeSandboxExecutable.js +28 -0
  75. package/dist/resolveCodeModeSandboxExecutable.js.map +1 -0
  76. package/dist/runCode.d.ts +3 -0
  77. package/dist/runCode.d.ts.map +1 -0
  78. package/dist/runCode.js +22 -0
  79. package/dist/runCode.js.map +1 -0
  80. package/dist/toCodeModeResponse.d.ts +4 -0
  81. package/dist/toCodeModeResponse.d.ts.map +1 -0
  82. package/dist/toCodeModeResponse.js +26 -0
  83. package/dist/toCodeModeResponse.js.map +1 -0
  84. package/dist/types.d.ts +79 -0
  85. package/dist/types.d.ts.map +1 -0
  86. package/dist/types.js +2 -0
  87. package/dist/types.js.map +1 -0
  88. package/package.json +49 -0
@@ -0,0 +1,9 @@
1
+ # Third-party notices
2
+
3
+ This package includes source code from OpenAI Codex at commit
4
+ `37eef7baccebaeb00e42a88b323054cdbfe418c5`. That source is licensed under the
5
+ Apache License 2.0; see `LICENSE-CODEX`.
6
+
7
+ The native binary statically links the Rust dependencies recorded in
8
+ `native/Cargo.lock`, including `rusty_v8`. Consumers can inspect the lockfile
9
+ for the exact dependency versions used by this package.
package/UPSTREAM.md ADDED
@@ -0,0 +1,26 @@
1
+ # Upstream source
2
+
3
+ The native runtime in `native/code-mode`, `native/code-mode-protocol`, and
4
+ `native/code-mode-host` is copied from OpenAI Codex:
5
+
6
+ - Repository: https://github.com/openai/codex
7
+ - Commit: `37eef7baccebaeb00e42a88b323054cdbfe418c5`
8
+ - Commit date: `2026-07-21T22:16:27Z`
9
+ - Retrieved: `2026-07-21`
10
+ - Source directory: `codex-rs`
11
+ - Upstream workspace version: `0.0.0`
12
+ - Rust toolchain at that commit: `1.95.0`
13
+ - V8 crate at that commit: `149.2.0`
14
+ - License: Apache-2.0
15
+
16
+ The copied code-mode crates are unmodified. `native/protocol` contains only the
17
+ upstream `codex-rs/protocol/src/tool_name.rs` type required by those crates,
18
+ plus a minimal crate manifest and re-export. The smaller protocol slice keeps
19
+ this standalone build independent from the rest of Codex.
20
+
21
+ The package's TypeScript process client, npm staging scripts, tests, and release
22
+ workflow are original integration code.
23
+
24
+ `release/rusty-v8-checksums` pins the archive and generated-binding hashes from
25
+ the upstream `rusty-v8-v149.2.0` release. Release builds use these checked-in
26
+ manifests rather than trusting checksums downloaded beside the payloads.
@@ -0,0 +1,13 @@
1
+ import { CodeModeSession } from "./CodeModeSession.js";
2
+ import type { CodeModeOptions, CodeModeSessionOptions } from "./types.js";
3
+ export declare class CodeMode {
4
+ private readonly client;
5
+ private closed;
6
+ private readonly pendingSessionIds;
7
+ private readonly sessions;
8
+ private constructor();
9
+ static create(options?: CodeModeOptions): Promise<CodeMode>;
10
+ createSession(options?: CodeModeSessionOptions): Promise<CodeModeSession>;
11
+ close(): Promise<void>;
12
+ }
13
+ //# sourceMappingURL=CodeMode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeMode.d.ts","sourceRoot":"","sources":["../sources/CodeMode.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,KAAK,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAE1E,qBAAa,QAAQ;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IACpC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAqB;IACvD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAE/D,OAAO;WAkBM,MAAM,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAM/D,aAAa,CAAC,OAAO,GAAE,sBAA2B,GAAG,OAAO,CAAC,eAAe,CAAC;IA4B7E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAe/B"}
@@ -0,0 +1,64 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { CodeModeSession } from "./CodeModeSession.js";
3
+ import { HostClient } from "./HostClient.js";
4
+ import { resolveCodeModeBinary } from "./resolveCodeModeBinary.js";
5
+ export class CodeMode {
6
+ client;
7
+ closed = false;
8
+ pendingSessionIds = new Set();
9
+ sessions = new Map();
10
+ constructor(options) {
11
+ this.client = new HostClient(resolveCodeModeBinary(options.binaryPath), options.env, options.sandbox ?? "auto", async (message, signal) => {
12
+ const session = this.sessions.get(message.sessionId);
13
+ if (session === undefined) {
14
+ throw new Error(`Code Mode requested a delegate for unknown session ${message.sessionId}.`);
15
+ }
16
+ return session.handleDelegate(message, signal);
17
+ }, (sessionId, cellId) => this.sessions.get(sessionId)?.handleCellClosed(cellId));
18
+ }
19
+ static async create(options = {}) {
20
+ const codeMode = new CodeMode(options);
21
+ await codeMode.client.connect();
22
+ return codeMode;
23
+ }
24
+ async createSession(options = {}) {
25
+ if (this.closed) {
26
+ throw new Error("Code Mode host is closed.");
27
+ }
28
+ const sessionId = options.sessionId ?? `session-${randomUUID()}`;
29
+ if (this.sessions.has(sessionId) || this.pendingSessionIds.has(sessionId)) {
30
+ throw new Error(`Code Mode session ${sessionId} is already open.`);
31
+ }
32
+ this.pendingSessionIds.add(sessionId);
33
+ try {
34
+ const response = await this.client.openSession(sessionId);
35
+ if (response.type !== "session/ready") {
36
+ throw new Error(`Expected session/ready, received ${response.type}.`);
37
+ }
38
+ if (this.closed) {
39
+ await this.client.shutdownSession(sessionId).catch(() => undefined);
40
+ throw new Error("Code Mode host is closed.");
41
+ }
42
+ const session = new CodeModeSession(this.client, sessionId, options, () => this.sessions.delete(sessionId));
43
+ this.sessions.set(sessionId, session);
44
+ return session;
45
+ }
46
+ finally {
47
+ this.pendingSessionIds.delete(sessionId);
48
+ }
49
+ }
50
+ async close() {
51
+ if (this.closed) {
52
+ return;
53
+ }
54
+ this.closed = true;
55
+ const sessions = [...this.sessions.values()];
56
+ const results = await Promise.allSettled(sessions.map((session) => session.close()));
57
+ await this.client.close();
58
+ const failure = results.find((result) => result.status === "rejected");
59
+ if (failure !== undefined) {
60
+ throw failure.reason;
61
+ }
62
+ }
63
+ }
64
+ //# sourceMappingURL=CodeMode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeMode.js","sourceRoot":"","sources":["../sources/CodeMode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C,OAAO,OAAO,CAAC;QACnB,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAC7C,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACP,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,OAAO;QACX,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;QAC7C,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACrF,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CACxB,CAAC,MAAM,EAAmC,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,UAAU,CAC5E,CAAC;QACF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,OAAO,CAAC,MAAM,CAAC;QACzB,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,15 @@
1
+ import type { CodeModeSandboxMode } from "./types.js";
2
+ export interface CodeModeHostCommand {
3
+ readonly args: readonly string[];
4
+ readonly command: string;
5
+ readonly cwd?: string;
6
+ }
7
+ export interface CreateCodeModeHostCommandOptions {
8
+ readonly binaryPath: string;
9
+ readonly env: NodeJS.ProcessEnv;
10
+ readonly platform?: NodeJS.Platform;
11
+ readonly resolveSandboxExecutable?: (platform: NodeJS.Platform, env: NodeJS.ProcessEnv) => string | undefined;
12
+ readonly sandbox: CodeModeSandboxMode;
13
+ readonly systemPathExists?: (path: string) => boolean;
14
+ }
15
+ //# sourceMappingURL=CodeModeHostCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeModeHostCommand.d.ts","sourceRoot":"","sources":["../sources/CodeModeHostCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,WAAW,mBAAmB;IAChC,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,gCAAgC;IAC7C,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IACpC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAChC,QAAQ,EAAE,MAAM,CAAC,QAAQ,EACzB,GAAG,EAAE,MAAM,CAAC,UAAU,KACrB,MAAM,GAAG,SAAS,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;CACzD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=CodeModeHostCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeModeHostCommand.js","sourceRoot":"","sources":["../sources/CodeModeHostCommand.ts"],"names":[],"mappings":""}
@@ -0,0 +1,38 @@
1
+ import type { HostClient } from "./HostClient.js";
2
+ import type { HostMessage } from "./protocol.js";
3
+ import type { CodeModeRunOptions, CodeModeRunResult, CodeModeSessionOptions, CodeModeResponse, JsonValue } from "./types.js";
4
+ type DelegateRequestMessage = Extract<HostMessage, {
5
+ readonly type: "delegate/request";
6
+ }>;
7
+ export declare class CodeModeSession {
8
+ private readonly client;
9
+ readonly id: string;
10
+ private readonly options;
11
+ private readonly onClose;
12
+ private readonly cellTools;
13
+ private closed;
14
+ private readonly defaultTools;
15
+ constructor(client: HostClient, id: string, options: CodeModeSessionOptions, onClose: () => void);
16
+ execute(source: string, options?: CodeModeRunOptions): Promise<CodeModeResponse>;
17
+ wait(cellId: string, yieldTimeMs?: number, signal?: AbortSignal): Promise<CodeModeResponse>;
18
+ terminate(cellId: string): Promise<CodeModeResponse>;
19
+ run(source: string, options?: CodeModeRunOptions): Promise<CodeModeRunResult>;
20
+ close(): Promise<void>;
21
+ handleDelegate(message: DelegateRequestMessage, signal: AbortSignal): Promise<{
22
+ readonly type: "notification/delivered";
23
+ } | {
24
+ readonly type: "tool/result";
25
+ readonly result: JsonValue;
26
+ }>;
27
+ handleCellClosed(cellId: string): void;
28
+ private assertOpen;
29
+ private indexTools;
30
+ private mergeTools;
31
+ private throwIfAborted;
32
+ private toolKey;
33
+ private toWireTool;
34
+ private unwrapWait;
35
+ private validateTools;
36
+ }
37
+ export {};
38
+ //# sourceMappingURL=CodeModeSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeModeSession.d.ts","sourceRoot":"","sources":["../sources/CodeModeSession.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAuC,MAAM,eAAe,CAAC;AAEtF,OAAO,KAAK,EACR,kBAAkB,EAClB,iBAAiB,EAEjB,sBAAsB,EAGtB,gBAAgB,EAChB,SAAS,EACZ,MAAM,YAAY,CAAC;AAEpB,KAAK,sBAAsB,GAAG,OAAO,CAAC,WAAW,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAAC;AAE1F,qBAAa,eAAe;IAMpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM;IACnB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ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ponse } from "./toCodeModeResponse.js";
3
+ export class CodeModeSession {
4
+ client;
5
+ id;
6
+ options;
7
+ onClose;
8
+ cellTools = new Map();
9
+ closed = false;
10
+ defaultTools;
11
+ constructor(client, id, options, onClose) {
12
+ this.client = client;
13
+ this.id = id;
14
+ this.options = options;
15
+ this.onClose = onClose;
16
+ this.defaultTools = options.tools ?? [];
17
+ this.validateTools(this.defaultTools);
18
+ }
19
+ async execute(source, options = {}) {
20
+ this.assertOpen();
21
+ this.throwIfAborted(options.signal);
22
+ const tools = this.mergeTools(options.tools);
23
+ this.validateTools(tools);
24
+ let cellId;
25
+ const abort = () => {
26
+ if (cellId !== undefined) {
27
+ void this.client.terminate(this.id, cellId).catch(() => undefined);
28
+ }
29
+ };
30
+ options.signal?.addEventListener("abort", abort, { once: true });
31
+ try {
32
+ const response = await this.client.execute(this.id, {
33
+ tool_call_id: options.toolCallId ?? randomUUID(),
34
+ enabled_tools: tools.map((tool) => this.toWireTool(tool)),
35
+ source,
36
+ yield_time_ms: options.yieldTimeMs ?? null,
37
+ max_output_tokens: null,
38
+ }, (startedCellId) => {
39
+ cellId = startedCellId;
40
+ this.cellTools.set(startedCellId, this.indexTools(tools));
41
+ if (options.signal?.aborted === true) {
42
+ abort();
43
+ }
44
+ }, options.signal);
45
+ this.throwIfAborted(options.signal);
46
+ return toCodeModeResponse(response);
47
+ }
48
+ finally {
49
+ options.signal?.removeEventListener("abort", abort);
50
+ }
51
+ }
52
+ async wait(cellId, yieldTimeMs = 10_000, signal) {
53
+ this.assertOpen();
54
+ this.throwIfAborted(signal);
55
+ const outcome = await this.client.wait(this.id, cellId, yieldTimeMs, signal);
56
+ this.throwIfAborted(signal);
57
+ return this.unwrapWait(outcome);
58
+ }
59
+ async terminate(cellId) {
60
+ this.assertOpen();
61
+ return this.unwrapWait(await this.client.terminate(this.id, cellId));
62
+ }
63
+ async run(source, options = {}) {
64
+ const responses = [];
65
+ const contentItems = [];
66
+ let response = await this.execute(source, options);
67
+ for (;;) {
68
+ responses.push(response);
69
+ contentItems.push(...response.contentItems);
70
+ if (response.state !== "yielded") {
71
+ const text = contentItems
72
+ .filter((item) => item.type === "input_text")
73
+ .map((item) => item.text)
74
+ .join("\n");
75
+ return response.errorText === undefined
76
+ ? {
77
+ state: response.state,
78
+ cellId: response.cellId,
79
+ contentItems,
80
+ responses,
81
+ text,
82
+ }
83
+ : {
84
+ state: response.state,
85
+ cellId: response.cellId,
86
+ contentItems,
87
+ errorText: response.errorText,
88
+ responses,
89
+ text,
90
+ };
91
+ }
92
+ response = await this.wait(response.cellId, options.yieldTimeMs ?? 10_000, options.signal);
93
+ }
94
+ }
95
+ async close() {
96
+ if (this.closed) {
97
+ return;
98
+ }
99
+ this.closed = true;
100
+ try {
101
+ const response = await this.client.shutdownSession(this.id);
102
+ if (response.type !== "session/closed") {
103
+ throw new Error(`Expected session/closed, received ${response.type}.`);
104
+ }
105
+ }
106
+ finally {
107
+ this.cellTools.clear();
108
+ this.onClose();
109
+ }
110
+ }
111
+ async handleDelegate(message, signal) {
112
+ if (message.request.type === "notification/send") {
113
+ await this.options.onNotification?.({
114
+ callId: message.request.callId,
115
+ cellId: message.request.cellId,
116
+ text: message.request.text,
117
+ });
118
+ return { type: "notification/delivered" };
119
+ }
120
+ const invocation = message.request.invocation;
121
+ const tools = this.cellTools.get(invocation.cell_id);
122
+ const tool = tools?.get(this.toolKey(invocation.tool_name));
123
+ if (tool === undefined) {
124
+ throw new Error(`Code Mode requested an unknown tool: ${this.toolKey(invocation.tool_name)}`);
125
+ }
126
+ const context = {
127
+ cellId: invocation.cell_id,
128
+ runtimeToolCallId: invocation.runtime_tool_call_id,
129
+ signal,
130
+ toolKind: invocation.tool_kind,
131
+ toolName: invocation.tool_name.namespace === null
132
+ ? { name: invocation.tool_name.name }
133
+ : {
134
+ name: invocation.tool_name.name,
135
+ namespace: invocation.tool_name.namespace,
136
+ },
137
+ };
138
+ const result = await tool.execute(invocation.input ?? undefined, context);
139
+ return { type: "tool/result", result };
140
+ }
141
+ handleCellClosed(cellId) {
142
+ this.cellTools.delete(cellId);
143
+ this.options.onCellClosed?.(cellId);
144
+ }
145
+ assertOpen() {
146
+ if (this.closed) {
147
+ throw new Error(`Code Mode session ${this.id} is closed.`);
148
+ }
149
+ }
150
+ indexTools(tools) {
151
+ return new Map(tools.map((tool) => [
152
+ this.toolKey(tool.toolName ?? { name: tool.name, namespace: null }),
153
+ tool,
154
+ ]));
155
+ }
156
+ mergeTools(overrides) {
157
+ if (overrides === undefined) {
158
+ return this.defaultTools;
159
+ }
160
+ const merged = new Map(this.defaultTools.map((tool) => [tool.name, tool]));
161
+ for (const tool of overrides) {
162
+ merged.set(tool.name, tool);
163
+ }
164
+ return [...merged.values()];
165
+ }
166
+ throwIfAborted(signal) {
167
+ if (signal?.aborted === true) {
168
+ throw signal.reason instanceof Error
169
+ ? signal.reason
170
+ : new DOMException("Code Mode execution aborted.", "AbortError");
171
+ }
172
+ }
173
+ toolKey(toolName) {
174
+ return `${toolName.namespace ?? ""}\u0000${toolName.name}`;
175
+ }
176
+ toWireTool(tool) {
177
+ const toolName = tool.toolName ?? { name: tool.name };
178
+ return {
179
+ name: tool.name,
180
+ tool_name: { name: toolName.name, namespace: toolName.namespace ?? null },
181
+ description: tool.description ?? "",
182
+ kind: tool.kind ?? "function",
183
+ input_schema: tool.inputSchema ?? null,
184
+ output_schema: tool.outputSchema ?? null,
185
+ };
186
+ }
187
+ unwrapWait(outcome) {
188
+ return toCodeModeResponse("LiveCell" in outcome ? outcome.LiveCell : outcome.MissingCell);
189
+ }
190
+ validateTools(tools) {
191
+ const globalNames = new Set();
192
+ const toolNames = new Set();
193
+ for (const tool of tools) {
194
+ if (tool.name.trim() === "") {
195
+ throw new Error("Code Mode tool names must not be empty.");
196
+ }
197
+ if (!globalNames.add(tool.name)) {
198
+ throw new Error(`Duplicate Code Mode global tool name: ${tool.name}`);
199
+ }
200
+ const key = this.toolKey(tool.toolName ?? { name: tool.name });
201
+ if (!toolNames.add(key)) {
202
+ throw new Error(`Duplicate Code Mode tool identity: ${key.replace("\u0000", "")}`);
203
+ }
204
+ }
205
+ }
206
+ }
207
+ //# sourceMappingURL=CodeModeSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeModeSession.js","sourceRoot":"","sources":["../sources/CodeModeSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAc7D,MAAM,OAAO,eAAe;IAMH;IACR;IACQ;IACA;IARJ,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IAClE,MAAM,GAAG,KAAK,CAAC;IACN,YAAY,CAA0B;IAEvD,YACqB,MAAkB,EAC1B,EAAU,EACF,OAA+B,EAC/B,OAAmB;QAHnB,WAAM,GAAN,MAAM,CAAY;QAC1B,OAAE,GAAF,EAAE,CAAQ;QACF,YAAO,GAAP,OAAO,CAAwB;QAC/B,YAAO,GAAP,OAAO,CAAY;QAEpC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,UAA8B,EAAE;QAC1D,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACpC,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,MAA0B,CAAC;QAC/B,MAAM,KAAK,GAAG,GAAG,EAAE;YACf,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACvB,KAAK,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE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AI,KAAK,CAAC,yCAAyC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAC1E,CAAC;YACD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAC/D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBACtB,MAAM,IAAI,KAAK,CAAC,sCAAsC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;YACvF,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,7 @@
1
+ export declare class Deferred<T> {
2
+ readonly promise: Promise<T>;
3
+ resolve: (value: T | PromiseLike<T>) => void;
4
+ reject: (reason?: unknown) => void;
5
+ constructor();
6
+ }
7
+ //# sourceMappingURL=Deferred.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Deferred.d.ts","sourceRoot":"","sources":["../sources/Deferred.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ,CAAC,CAAC;IACnB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7B,OAAO,EAAG,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC9C,MAAM,EAAG,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;;CAQvC"}
@@ -0,0 +1,12 @@
1
+ export class Deferred {
2
+ promise;
3
+ resolve;
4
+ reject;
5
+ constructor() {
6
+ this.promise = new Promise((resolve, reject) => {
7
+ this.resolve = resolve;
8
+ this.reject = reject;
9
+ });
10
+ }
11
+ }
12
+ //# sourceMappingURL=Deferred.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Deferred.js","sourceRoot":"","sources":["../sources/Deferred.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,QAAQ;IACR,OAAO,CAAa;IAC7B,OAAO,CAAuC;IAC9C,MAAM,CAA8B;IAEpC;QACI,IAAI,CAAC,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACzB,CAAC,CAAC,CAAC;IACP,CAAC;CACJ"}
@@ -0,0 +1,21 @@
1
+ import type { ChildProcessWithoutNullStreams } from "node:child_process";
2
+ import { type ClientMessage, type HostMessage } from "./protocol.js";
3
+ export declare class FramedProcess {
4
+ private readonly child;
5
+ private readonly onMessage;
6
+ private readonly onFailure;
7
+ private buffer;
8
+ private closed;
9
+ private readonly exitPromise;
10
+ private failure;
11
+ private stderr;
12
+ private writeTail;
13
+ constructor(child: ChildProcessWithoutNullStreams, onMessage: (message: HostMessage) => void, onFailure: (error: Error) => void);
14
+ send(message: ClientMessage): Promise<void>;
15
+ close(): Promise<void>;
16
+ kill(): void;
17
+ private fail;
18
+ private read;
19
+ private readStderr;
20
+ }
21
+ //# sourceMappingURL=FramedProcess.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FramedProcess.d.ts","sourceRoot":"","sources":["../sources/FramedProcess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AAGzE,OAAO,EAAmB,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAItF,qBAAa,aAAa;IASlB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAV9B,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;IAC5C,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,SAAS,CAAqB;gBAGjB,KAAK,EAAE,8BAA8B,EACrC,SAAS,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,EACzC,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI;IA0BtD,IAAI,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BrC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAoB5B,IAAI,IAAI,IAAI;IAIZ,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,IAAI;IAyBZ,OAAO,CAAC,UAAU;CAMrB"}
@@ -0,0 +1,125 @@
1
+ import { assertJsonValue } from "./assertJsonValue.js";
2
+ import { MAX_FRAME_BYTES } from "./protocol.js";
3
+ const MAX_STDERR_BYTES = 64 * 1024;
4
+ export class FramedProcess {
5
+ child;
6
+ onMessage;
7
+ onFailure;
8
+ buffer = Buffer.alloc(0);
9
+ closed = false;
10
+ exitPromise;
11
+ failure;
12
+ stderr = Buffer.alloc(0);
13
+ writeTail = Promise.resolve();
14
+ constructor(child, onMessage, onFailure) {
15
+ this.child = child;
16
+ this.onMessage = onMessage;
17
+ this.onFailure = onFailure;
18
+ this.child.stdout.on("data", (chunk) => this.read(chunk));
19
+ this.child.stderr.on("data", (chunk) => this.readStderr(chunk));
20
+ this.child.stdin.on("error", (error) => this.fail(error));
21
+ this.child.stdout.on("error", (error) => this.fail(error));
22
+ this.child.stderr.on("error", (error) => this.fail(error));
23
+ this.child.once("error", (error) => this.fail(error));
24
+ this.exitPromise = new Promise((resolve) => {
25
+ this.child.once("exit", (code, signal) => {
26
+ if (!this.closed) {
27
+ const suffix = this.stderr.length === 0 ? "" : `\n${this.stderr.toString("utf8")}`;
28
+ this.fail(new Error(signal === null
29
+ ? `Code Mode host exited with code ${String(code)}.${suffix}`
30
+ : `Code Mode host exited from signal ${signal}.${suffix}`));
31
+ }
32
+ resolve();
33
+ });
34
+ });
35
+ }
36
+ send(message) {
37
+ if (this.failure !== undefined) {
38
+ return Promise.reject(this.failure);
39
+ }
40
+ assertJsonValue(message);
41
+ const payload = Buffer.from(JSON.stringify(message), "utf8");
42
+ if (payload.length > MAX_FRAME_BYTES) {
43
+ return Promise.reject(new Error(`Code Mode frame exceeds ${String(MAX_FRAME_BYTES)} bytes.`));
44
+ }
45
+ const header = Buffer.allocUnsafe(4);
46
+ header.writeUInt32LE(payload.length);
47
+ const frame = Buffer.concat([header, payload]);
48
+ const sent = this.writeTail.then(() => new Promise((resolve, reject) => {
49
+ this.child.stdin.write(frame, (error) => {
50
+ if (error === null || error === undefined) {
51
+ resolve();
52
+ }
53
+ else {
54
+ reject(error);
55
+ }
56
+ });
57
+ }));
58
+ this.writeTail = sent.catch(() => undefined);
59
+ return sent;
60
+ }
61
+ async close() {
62
+ if (this.closed) {
63
+ return this.exitPromise;
64
+ }
65
+ this.closed = true;
66
+ const timeout = setTimeout(() => this.child.kill("SIGKILL"), 6_000);
67
+ timeout.unref();
68
+ try {
69
+ await this.writeTail;
70
+ this.child.stdin.end();
71
+ await this.exitPromise;
72
+ }
73
+ catch (error) {
74
+ this.child.kill("SIGKILL");
75
+ await this.exitPromise;
76
+ throw error;
77
+ }
78
+ finally {
79
+ clearTimeout(timeout);
80
+ }
81
+ }
82
+ kill() {
83
+ this.child.kill();
84
+ }
85
+ fail(error) {
86
+ if (this.failure !== undefined || this.closed) {
87
+ return;
88
+ }
89
+ this.failure = error;
90
+ this.onFailure(error);
91
+ this.child.kill("SIGKILL");
92
+ }
93
+ read(chunk) {
94
+ if (this.failure !== undefined) {
95
+ return;
96
+ }
97
+ this.buffer = Buffer.concat([this.buffer, chunk]);
98
+ while (this.buffer.length >= 4) {
99
+ const length = this.buffer.readUInt32LE(0);
100
+ if (length > MAX_FRAME_BYTES) {
101
+ this.fail(new Error(`Code Mode frame exceeds ${String(MAX_FRAME_BYTES)} bytes.`));
102
+ return;
103
+ }
104
+ if (this.buffer.length < length + 4) {
105
+ return;
106
+ }
107
+ const payload = this.buffer.subarray(4, length + 4);
108
+ this.buffer = this.buffer.subarray(length + 4);
109
+ try {
110
+ this.onMessage(JSON.parse(payload.toString("utf8")));
111
+ }
112
+ catch (error) {
113
+ this.fail(error instanceof Error ? error : new Error(String(error)));
114
+ return;
115
+ }
116
+ }
117
+ }
118
+ readStderr(chunk) {
119
+ this.stderr = Buffer.concat([this.stderr, chunk]);
120
+ if (this.stderr.length > MAX_STDERR_BYTES) {
121
+ this.stderr = this.stderr.subarray(this.stderr.length - MAX_STDERR_BYTES);
122
+ }
123
+ }
124
+ }
125
+ //# sourceMappingURL=FramedProcess.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FramedProcess.js","sourceRoot":"","sources":["../sources/FramedProcess.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAwC,MAAM,eAAe,CAAC;AAEtF,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,MAAM,OAAO,aAAa;IASD;IACA;IACA;IAVb,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,MAAM,GAAG,KAAK,CAAC;IACN,WAAW,CAAgB;IACpC,OAAO,CAAoB;IAC3B,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,SAAS,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAEtC,YACqB,KAAqC,EACrC,SAAyC,EACzC,SAAiC;QAFjC,UAAK,GAAL,KAAK,CAAgC;QACrC,cAAS,GAAT,SAAS,CAAgC;QACzC,cAAS,GAAT,SAAS,CAAwB;QAElD,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAClE,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