@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,41 @@
1
+ import type { HostMessage, HostOperationResponse, WireRuntimeResponse, WireWaitOutcome } from "./protocol.js";
2
+ import type { CodeModeSandboxMode, JsonValue } from "./types.js";
3
+ type DelegateRequestMessage = Extract<HostMessage, {
4
+ readonly type: "delegate/request";
5
+ }>;
6
+ type DelegateResponse = {
7
+ readonly type: "notification/delivered";
8
+ } | {
9
+ readonly type: "tool/result";
10
+ readonly result: JsonValue;
11
+ };
12
+ export declare class HostClient {
13
+ private readonly onDelegate;
14
+ private readonly onCellClosed;
15
+ private closed;
16
+ private readonly delegates;
17
+ private readonly handshake;
18
+ private nextRequestId;
19
+ private readonly pendingInitial;
20
+ private readonly pendingOperations;
21
+ private readonly process;
22
+ constructor(binaryPath: string, env: NodeJS.ProcessEnv | undefined, sandbox: CodeModeSandboxMode, onDelegate: (message: DelegateRequestMessage, signal: AbortSignal) => Promise<DelegateResponse>, onCellClosed: (sessionId: string, cellId: string) => void);
23
+ connect(): Promise<void>;
24
+ openSession(sessionId: string): Promise<HostOperationResponse>;
25
+ execute(sessionId: string, request: Readonly<Record<string, unknown>>, onStarted: (cellId: string) => void, signal?: AbortSignal): Promise<WireRuntimeResponse>;
26
+ wait(sessionId: string, cellId: string, yieldTimeMs: number, signal?: AbortSignal): Promise<WireWaitOutcome>;
27
+ terminate(sessionId: string, cellId: string): Promise<WireWaitOutcome>;
28
+ shutdownSession(sessionId: string): Promise<HostOperationResponse>;
29
+ close(): Promise<void>;
30
+ private allocateRequestId;
31
+ private attachAbort;
32
+ private fail;
33
+ private operation;
34
+ private throwIfAborted;
35
+ private receive;
36
+ private receiveOperation;
37
+ private receiveInitial;
38
+ private receiveDelegate;
39
+ }
40
+ export {};
41
+ //# sourceMappingURL=HostClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HostClient.d.ts","sourceRoot":"","sources":["../sources/HostClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACR,WAAW,EACX,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjE,KAAK,sBAAsB,GAAG,OAAO,CAAC,WAAW,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC,CAAC;AAC1F,KAAK,gBAAgB,GACf;IAAE,QAAQ,CAAC,IAAI,EAAE,wBAAwB,CAAA;CAAE,GAC3C;IAAE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC;AAOnE,qBAAa,UAAU;IAaf,OAAO,CAAC,QAAQ,CAAC,UAAU;IAI3B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAhBjC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsC;IAChE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwB;IAClD,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoD;IACnF,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAuC;IACzE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;gBAGpC,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,SAAS,EAClC,OAAO,EAAE,mBAAmB,EACX,UAAU,EAAE,CACzB,OAAO,EAAE,sBAAsB,EAC/B,MAAM,EAAE,WAAW,KAClB,OAAO,CAAC,gBAAgB,CAAC,EACb,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI;IAiBxE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB9B,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAIxD,OAAO,CACT,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAC1C,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,EACnC,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,mBAAmB,CAAC;IAoCzB,IAAI,CACN,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,eAAe,CAAC;IAerB,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAQ5E,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAI5D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,IAAI;YAgBE,SAAS;IAmBvB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,OAAO;IAyCf,OAAO,CAAC,gBAAgB;IAiBxB,OAAO,CAAC,cAAc;IAkBtB,OAAO,CAAC,eAAe;CA4B1B"}
@@ -0,0 +1,261 @@
1
+ import { spawn } from "node:child_process";
2
+ import { Deferred } from "./Deferred.js";
3
+ import { FramedProcess } from "./FramedProcess.js";
4
+ import { createCodeModeHostCommand } from "./createCodeModeHostCommand.js";
5
+ export class HostClient {
6
+ onDelegate;
7
+ onCellClosed;
8
+ closed = false;
9
+ delegates = new Map();
10
+ handshake = new Deferred();
11
+ nextRequestId = 1;
12
+ pendingInitial = new Map();
13
+ pendingOperations = new Map();
14
+ process;
15
+ constructor(binaryPath, env, sandbox, onDelegate, onCellClosed) {
16
+ this.onDelegate = onDelegate;
17
+ this.onCellClosed = onCellClosed;
18
+ const childEnv = env === undefined ? process.env : { ...process.env, ...env };
19
+ const command = createCodeModeHostCommand({ binaryPath, env: childEnv, sandbox });
20
+ const child = spawn(command.command, command.args, {
21
+ ...(command.cwd === undefined ? {} : { cwd: command.cwd }),
22
+ env: childEnv,
23
+ stdio: "pipe",
24
+ windowsHide: true,
25
+ });
26
+ this.process = new FramedProcess(child, (message) => this.receive(message), (error) => this.fail(error));
27
+ }
28
+ async connect() {
29
+ const timeout = setTimeout(() => this.handshake.reject(new Error("Timed out connecting to the Code Mode host.")), 10_000);
30
+ timeout.unref();
31
+ try {
32
+ await this.process.send({
33
+ type: "connection/hello",
34
+ supportedVersions: [1],
35
+ requiredCapabilities: [],
36
+ optionalCapabilities: [],
37
+ });
38
+ await this.handshake.promise;
39
+ }
40
+ catch (error) {
41
+ this.process.kill();
42
+ throw error;
43
+ }
44
+ finally {
45
+ clearTimeout(timeout);
46
+ }
47
+ }
48
+ openSession(sessionId) {
49
+ return this.operation({ method: "session/open", sessionId });
50
+ }
51
+ async execute(sessionId, request, onStarted, signal) {
52
+ this.throwIfAborted(signal);
53
+ const id = this.allocateRequestId();
54
+ const operation = new Deferred();
55
+ const initial = new Deferred();
56
+ this.pendingOperations.set(id, {
57
+ deferred: operation,
58
+ onResponse: (response) => {
59
+ if (response.type === "execution/started") {
60
+ onStarted(response.cellId);
61
+ }
62
+ },
63
+ });
64
+ this.pendingInitial.set(id, initial);
65
+ let removeAbort = () => undefined;
66
+ try {
67
+ await this.process.send({
68
+ type: "operation/request",
69
+ id,
70
+ request: { method: "session/execute", sessionId, request },
71
+ });
72
+ removeAbort = this.attachAbort(id, signal);
73
+ const response = await operation.promise;
74
+ if (response.type !== "execution/started") {
75
+ throw new Error(`Expected execution/started, received ${response.type}.`);
76
+ }
77
+ return await initial.promise;
78
+ }
79
+ catch (error) {
80
+ this.pendingOperations.delete(id);
81
+ this.pendingInitial.delete(id);
82
+ throw error;
83
+ }
84
+ finally {
85
+ removeAbort();
86
+ }
87
+ }
88
+ async wait(sessionId, cellId, yieldTimeMs, signal) {
89
+ const response = await this.operation({
90
+ method: "session/wait",
91
+ sessionId,
92
+ request: { cell_id: cellId, yield_time_ms: yieldTimeMs },
93
+ }, signal);
94
+ if (response.type !== "wait/completed") {
95
+ throw new Error(`Expected wait/completed, received ${response.type}.`);
96
+ }
97
+ return response.outcome;
98
+ }
99
+ async terminate(sessionId, cellId) {
100
+ const response = await this.operation({ method: "session/terminate", sessionId, cellId });
101
+ if (response.type !== "wait/completed") {
102
+ throw new Error(`Expected wait/completed, received ${response.type}.`);
103
+ }
104
+ return response.outcome;
105
+ }
106
+ shutdownSession(sessionId) {
107
+ return this.operation({ method: "session/shutdown", sessionId });
108
+ }
109
+ async close() {
110
+ if (this.closed) {
111
+ return;
112
+ }
113
+ this.closed = true;
114
+ this.fail(new Error("Code Mode host client closed."));
115
+ await this.process.close();
116
+ }
117
+ allocateRequestId() {
118
+ if (!Number.isSafeInteger(this.nextRequestId)) {
119
+ throw new Error("Code Mode request IDs exhausted the JavaScript safe integer range.");
120
+ }
121
+ return this.nextRequestId++;
122
+ }
123
+ attachAbort(id, signal) {
124
+ if (signal === undefined) {
125
+ return () => undefined;
126
+ }
127
+ const cancel = () => {
128
+ void this.process.send({ type: "operation/cancel", id }).catch(() => undefined);
129
+ };
130
+ if (signal.aborted) {
131
+ cancel();
132
+ }
133
+ else {
134
+ signal.addEventListener("abort", cancel, { once: true });
135
+ }
136
+ return () => signal.removeEventListener("abort", cancel);
137
+ }
138
+ fail(error) {
139
+ this.handshake.reject(error);
140
+ for (const pending of this.pendingOperations.values()) {
141
+ pending.deferred.reject(error);
142
+ }
143
+ for (const pending of this.pendingInitial.values()) {
144
+ pending.reject(error);
145
+ }
146
+ this.pendingOperations.clear();
147
+ this.pendingInitial.clear();
148
+ for (const controller of this.delegates.values()) {
149
+ controller.abort(error);
150
+ }
151
+ this.delegates.clear();
152
+ }
153
+ async operation(request, signal) {
154
+ this.throwIfAborted(signal);
155
+ const id = this.allocateRequestId();
156
+ const deferred = new Deferred();
157
+ this.pendingOperations.set(id, { deferred });
158
+ let removeAbort = () => undefined;
159
+ try {
160
+ await this.process.send({ type: "operation/request", id, request });
161
+ removeAbort = this.attachAbort(id, signal);
162
+ return await deferred.promise;
163
+ }
164
+ finally {
165
+ removeAbort();
166
+ this.pendingOperations.delete(id);
167
+ }
168
+ }
169
+ throwIfAborted(signal) {
170
+ if (signal?.aborted === true) {
171
+ throw signal.reason instanceof Error
172
+ ? signal.reason
173
+ : new DOMException("Code Mode operation aborted.", "AbortError");
174
+ }
175
+ }
176
+ receive(message) {
177
+ switch (message.type) {
178
+ case "connection/ready":
179
+ if (message.selectedVersion !== 1) {
180
+ this.handshake.reject(new Error(`Unsupported Code Mode protocol version ${String(message.selectedVersion)}.`));
181
+ }
182
+ else {
183
+ this.handshake.resolve();
184
+ }
185
+ break;
186
+ case "connection/rejected":
187
+ this.handshake.reject(new Error(`Code Mode host rejected the connection: ${JSON.stringify(message.reason)}`));
188
+ break;
189
+ case "operation/response":
190
+ this.receiveOperation(message.id, message.result);
191
+ break;
192
+ case "execute/initialResponse":
193
+ this.receiveInitial(message.id, message.result);
194
+ break;
195
+ case "delegate/request":
196
+ this.receiveDelegate(message);
197
+ break;
198
+ case "delegate/cancel":
199
+ this.delegates
200
+ .get(message.id)
201
+ ?.abort(new Error("Code Mode delegate call cancelled."));
202
+ this.delegates.delete(message.id);
203
+ break;
204
+ case "cell/closed":
205
+ this.onCellClosed(message.sessionId, message.cellId);
206
+ break;
207
+ }
208
+ }
209
+ receiveOperation(id, result) {
210
+ const pending = this.pendingOperations.get(id);
211
+ if (pending === undefined) {
212
+ throw new Error(`Received a response for unknown Code Mode request ${String(id)}.`);
213
+ }
214
+ this.pendingOperations.delete(id);
215
+ if (result.status === "error") {
216
+ pending.deferred.reject(new Error(result.message));
217
+ }
218
+ else {
219
+ pending.onResponse?.(result.value);
220
+ pending.deferred.resolve(result.value);
221
+ }
222
+ }
223
+ receiveInitial(id, result) {
224
+ const pending = this.pendingInitial.get(id);
225
+ if (pending === undefined) {
226
+ throw new Error(`Received an initial response for unknown Code Mode request ${String(id)}.`);
227
+ }
228
+ this.pendingInitial.delete(id);
229
+ if (result.status === "error") {
230
+ pending.reject(new Error(result.message));
231
+ }
232
+ else {
233
+ pending.resolve(result.value);
234
+ }
235
+ }
236
+ receiveDelegate(message) {
237
+ const controller = new AbortController();
238
+ this.delegates.set(message.id, controller);
239
+ void this.onDelegate(message, controller.signal)
240
+ .then((value) => controller.signal.aborted
241
+ ? undefined
242
+ : this.process.send({
243
+ type: "delegate/response",
244
+ id: message.id,
245
+ result: { status: "ok", value },
246
+ }))
247
+ .catch((error) => controller.signal.aborted
248
+ ? undefined
249
+ : this.process.send({
250
+ type: "delegate/response",
251
+ id: message.id,
252
+ result: {
253
+ status: "error",
254
+ message: error instanceof Error ? error.message : String(error),
255
+ },
256
+ }))
257
+ .finally(() => this.delegates.delete(message.id))
258
+ .catch(() => undefined);
259
+ }
260
+ }
261
+ //# sourceMappingURL=HostClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HostClient.js","sourceRoot":"","sources":["../sources/HostClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAmB3E,MAAM,OAAO,UAAU;IAaE;IAIA;IAhBb,MA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,CAAC,MAAM,CAAC;aAC3C,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CACZ,UAAU,CAAC,MAAM,CAAC,OAAO;YACrB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBACd,IAAI,EAAE,mBAAmB;gBACzB,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE;aAClC,CAAC,CACX;aACA,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,CACtB,UAAU,CAAC,MAAM,CAAC,OAAO;YACrB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBACd,IAAI,EAAE,mBAAmB;gBACzB,EAAE,EAAE,OAAO,CAAC,EAAE;gBACd,MAAM,EAAE;oBACJ,MAAM,EAAE,OAAO;oBACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;iBAClE;aACJ,CAAC,CACX;aACA,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;aAChD,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;CACJ"}
@@ -0,0 +1,3 @@
1
+ export declare const MAX_JSON_DEPTH = 100;
2
+ export declare function assertJsonValue(value: unknown, path?: string, ancestors?: Set<object>, depth?: number): asserts value is import("./types.js").JsonValue;
3
+ //# sourceMappingURL=assertJsonValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertJsonValue.d.ts","sourceRoot":"","sources":["../sources/assertJsonValue.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,wBAAgB,eAAe,CAC3B,KAAK,EAAE,OAAO,EACd,IAAI,SAAM,EACV,SAAS,GAAE,GAAG,CAAC,MAAM,CAAa,EAClC,KAAK,SAAI,GACV,OAAO,CAAC,KAAK,IAAI,OAAO,YAAY,EAAE,SAAS,CAuCjD"}
@@ -0,0 +1,39 @@
1
+ export const MAX_JSON_DEPTH = 100;
2
+ export function assertJsonValue(value, path = "$", ancestors = new Set(), depth = 0) {
3
+ if (depth > MAX_JSON_DEPTH) {
4
+ throw new Error(`Code Mode protocol value at ${path} exceeds the maximum JSON depth of ${String(MAX_JSON_DEPTH)}.`);
5
+ }
6
+ if (value === null || typeof value === "boolean" || typeof value === "string") {
7
+ return;
8
+ }
9
+ if (typeof value === "number") {
10
+ if (!Number.isFinite(value)) {
11
+ throw new Error(`Code Mode protocol value at ${path} contains a non-finite number.`);
12
+ }
13
+ return;
14
+ }
15
+ if (typeof value !== "object") {
16
+ throw new Error(`Code Mode protocol value at ${path} is not JSON-serializable.`);
17
+ }
18
+ if (ancestors.has(value)) {
19
+ throw new Error(`Code Mode protocol value at ${path} contains a cycle.`);
20
+ }
21
+ ancestors.add(value);
22
+ try {
23
+ if (Array.isArray(value)) {
24
+ value.forEach((item, index) => assertJsonValue(item, `${path}[${String(index)}]`, ancestors, depth + 1));
25
+ return;
26
+ }
27
+ const prototype = Object.getPrototypeOf(value);
28
+ if (prototype !== Object.prototype && prototype !== null) {
29
+ throw new Error(`Code Mode protocol value at ${path} is not a plain JSON object.`);
30
+ }
31
+ for (const [key, item] of Object.entries(value)) {
32
+ assertJsonValue(item, `${path}.${key}`, ancestors, depth + 1);
33
+ }
34
+ }
35
+ finally {
36
+ ancestors.delete(value);
37
+ }
38
+ }
39
+ //# sourceMappingURL=assertJsonValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assertJsonValue.js","sourceRoot":"","sources":["../sources/assertJsonValue.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC;AAElC,MAAM,UAAU,eAAe,CAC3B,KA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CAAY,CAAC;QAC1D,IAAI,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;YACvD,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,8BAA8B,CAAC,CAAC;QACvF,CAAC;QACD,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9C,eAAe,CAAC,IAAI,EAAE,GAAG,IAAI,IAAI,GAAG,EAAE,EAAE,SAAS,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;QAClE,CAAC;IACL,CAAC;YAAS,CAAC;QACP,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { CodeMode } from "./CodeMode.js";
2
+ import type { CodeModeOptions } from "./types.js";
3
+ export declare function createCodeMode(options?: CodeModeOptions): Promise<CodeMode>;
4
+ //# sourceMappingURL=createCodeMode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCodeMode.d.ts","sourceRoot":"","sources":["../sources/createCodeMode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,wBAAgB,cAAc,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE/E"}
@@ -0,0 +1,5 @@
1
+ import { CodeMode } from "./CodeMode.js";
2
+ export function createCodeMode(options = {}) {
3
+ return CodeMode.create(options);
4
+ }
5
+ //# sourceMappingURL=createCodeMode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCodeMode.js","sourceRoot":"","sources":["../sources/createCodeMode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,UAAU,cAAc,CAAC,UAA2B,EAAE;IACxD,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CodeModeHostCommand, CreateCodeModeHostCommandOptions } from "./CodeModeHostCommand.js";
2
+ export declare function createCodeModeHostCommand({ binaryPath, env, platform, resolveSandboxExecutable, sandbox, systemPathExists, }: CreateCodeModeHostCommandOptions): CodeModeHostCommand;
3
+ //# sourceMappingURL=createCodeModeHostCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCodeModeHostCommand.d.ts","sourceRoot":"","sources":["../sources/createCodeModeHostCommand.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACR,mBAAmB,EACnB,gCAAgC,EACnC,MAAM,0BAA0B,CAAC;AAKlC,wBAAgB,yBAAyB,CAAC,EACtC,UAAU,EACV,GAAG,EACH,QAA2B,EAC3B,wBAA2D,EAC3D,OAAO,EACP,gBAA6B,GAChC,EAAE,gCAAgC,GAAG,mBAAmB,CAmBxD"}
@@ -0,0 +1,22 @@
1
+ import { existsSync } from "node:fs";
2
+ import { createLinuxSandboxCommand } from "./createLinuxSandboxCommand.js";
3
+ import { createMacOsSandboxCommand } from "./createMacOsSandboxCommand.js";
4
+ import { resolveCodeModeSandboxExecutable } from "./resolveCodeModeSandboxExecutable.js";
5
+ export function createCodeModeHostCommand({ binaryPath, env, platform = process.platform, resolveSandboxExecutable = resolveCodeModeSandboxExecutable, sandbox, systemPathExists = existsSync, }) {
6
+ if (sandbox === "disabled") {
7
+ return { args: [], command: binaryPath };
8
+ }
9
+ const sandboxExecutable = resolveSandboxExecutable(platform, env);
10
+ if (sandboxExecutable !== undefined && platform === "darwin") {
11
+ return createMacOsSandboxCommand(sandboxExecutable, binaryPath);
12
+ }
13
+ if (sandboxExecutable !== undefined && platform === "linux") {
14
+ return createLinuxSandboxCommand(sandboxExecutable, binaryPath, systemPathExists);
15
+ }
16
+ if (sandbox === "required") {
17
+ throw new Error(`Code Mode system sandbox is required but unavailable on ${platform}. ` +
18
+ "Install Bubblewrap on Linux or use macOS sandbox-exec.");
19
+ }
20
+ return { args: [], command: binaryPath };
21
+ }
22
+ //# sourceMappingURL=createCodeModeHostCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCodeModeHostCommand.js","sourceRoot":"","sources":["../sources/createCodeModeHostCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAMrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AAEzF,MAAM,UAAU,yBAAyB,CAAC,EACtC,UAAU,EACV,GAAG,EACH,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAC3B,wBAAwB,GAAG,gCAAgC,EAC3D,OAAO,EACP,gBAAgB,GAAG,UAAU,GACE;IAC/B,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;QACzB,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;IAC7C,CAAC;IAED,MAAM,iBAAiB,GAAG,wBAAwB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAClE,IAAI,iBAAiB,KAAK,SAAS,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC3D,OAAO,yBAAyB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IACpE,CAAC;IACD,IAAI,iBAAiB,KAAK,SAAS,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC1D,OAAO,yBAAyB,CAAC,iBAAiB,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;IACtF,CAAC;IACD,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACX,2DAA2D,QAAQ,IAAI;YACnE,wDAAwD,CAC/D,CAAC;IACN,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CodeModeHostCommand } from "./CodeModeHostCommand.js";
2
+ export declare function createLinuxSandboxCommand(sandboxExecutable: string, binaryPath: string, systemPathExists: (path: string) => boolean): CodeModeHostCommand;
3
+ //# sourceMappingURL=createLinuxSandboxCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createLinuxSandboxCommand.d.ts","sourceRoot":"","sources":["../sources/createLinuxSandboxCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAIpE,wBAAgB,yBAAyB,CACrC,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAC5C,mBAAmB,CAyCrB"}
@@ -0,0 +1,27 @@
1
+ const SANDBOX_BINARY = "/rig-codemode-codex-host";
2
+ export function createLinuxSandboxCommand(sandboxExecutable, binaryPath, systemPathExists) {
3
+ const args = [
4
+ "--die-with-parent",
5
+ "--new-session",
6
+ "--unshare-user",
7
+ "--unshare-ipc",
8
+ "--unshare-pid",
9
+ "--unshare-net",
10
+ "--unshare-uts",
11
+ "--unshare-cgroup-try",
12
+ "--proc",
13
+ "/proc",
14
+ "--dev",
15
+ "/dev",
16
+ "--tmpfs",
17
+ "/tmp",
18
+ ];
19
+ for (const runtimePath of ["/lib", "/lib64", "/usr/lib", "/usr/lib64"]) {
20
+ if (systemPathExists(runtimePath)) {
21
+ args.push("--ro-bind", runtimePath, runtimePath);
22
+ }
23
+ }
24
+ args.push("--ro-bind", binaryPath, SANDBOX_BINARY, "--setenv", "HOME", "/nonexistent", "--setenv", "TMPDIR", "/tmp", "--chdir", "/", "--", SANDBOX_BINARY);
25
+ return { args, command: sandboxExecutable, cwd: "/" };
26
+ }
27
+ //# sourceMappingURL=createLinuxSandboxCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createLinuxSandboxCommand.js","sourceRoot":"","sources":["../sources/createLinuxSandboxCommand.ts"],"names":[],"mappings":"AAEA,MAAM,cAAc,GAAG,0BAA0B,CAAC;AAElD,MAAM,UAAU,yBAAyB,CACrC,iBAAyB,EACzB,UAAkB,EAClB,gBAA2C;IAE3C,MAAM,IAAI,GAAG;QACT,mBAAmB;QACnB,eAAe;QACf,gBAAgB;QAChB,eAAe;QACf,eAAe;QACf,eAAe;QACf,eAAe;QACf,sBAAsB;QACtB,QAAQ;QACR,OAAO;QACP,OAAO;QACP,MAAM;QACN,SAAS;QACT,MAAM;KACT,CAAC;IAEF,KAAK,MAAM,WAAW,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,CAAC,EAAE,CAAC;QACrE,IAAI,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;IAED,IAAI,CAAC,IAAI,CACL,WAAW,EACX,UAAU,EACV,cAAc,EACd,UAAU,EACV,MAAM,EACN,cAAc,EACd,UAAU,EACV,QAAQ,EACR,MAAM,EACN,SAAS,EACT,GAAG,EACH,IAAI,EACJ,cAAc,CACjB,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { CodeModeHostCommand } from "./CodeModeHostCommand.js";
2
+ export declare function createMacOsSandboxCommand(sandboxExecutable: string, binaryPath: string): CodeModeHostCommand;
3
+ //# sourceMappingURL=createMacOsSandboxCommand.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMacOsSandboxCommand.d.ts","sourceRoot":"","sources":["../sources/createMacOsSandboxCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAGpE,wBAAgB,yBAAyB,CACrC,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,GACnB,mBAAmB,CAMrB"}
@@ -0,0 +1,9 @@
1
+ import { createMacOsSandboxProfile } from "./createMacOsSandboxProfile.js";
2
+ export function createMacOsSandboxCommand(sandboxExecutable, binaryPath) {
3
+ return {
4
+ args: ["-p", createMacOsSandboxProfile(binaryPath), binaryPath],
5
+ command: sandboxExecutable,
6
+ cwd: "/",
7
+ };
8
+ }
9
+ //# sourceMappingURL=createMacOsSandboxCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMacOsSandboxCommand.js","sourceRoot":"","sources":["../sources/createMacOsSandboxCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,UAAU,yBAAyB,CACrC,iBAAyB,EACzB,UAAkB;IAElB,OAAO;QACH,IAAI,EAAE,CAAC,IAAI,EAAE,yBAAyB,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;QAC/D,OAAO,EAAE,iBAAiB;QAC1B,GAAG,EAAE,GAAG;KACX,CAAC;AACN,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function createMacOsSandboxProfile(binaryPath: string): string;
2
+ //# sourceMappingURL=createMacOsSandboxProfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMacOsSandboxProfile.d.ts","sourceRoot":"","sources":["../sources/createMacOsSandboxProfile.ts"],"names":[],"mappings":"AAAA,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAgDpE"}
@@ -0,0 +1,50 @@
1
+ export function createMacOsSandboxProfile(binaryPath) {
2
+ const binary = JSON.stringify(binaryPath);
3
+ return `(version 1)
4
+ (deny default)
5
+
6
+ ; Permit the initial Code Mode exec and normal in-sandbox process bookkeeping.
7
+ (allow process-exec (literal ${binary}))
8
+ (allow process-info* (target same-sandbox))
9
+ (allow signal (target same-sandbox))
10
+
11
+ ; V8 runtime and CPU feature detection.
12
+ (allow sysctl-read)
13
+ (allow iokit-open (iokit-registry-entry-class "RootDomainUserClient"))
14
+ (allow mach-lookup (global-name "com.apple.PowerManagement.control"))
15
+ (allow system-mac-syscall)
16
+
17
+ ; The host executable, Apple runtime libraries, and standard read-only data.
18
+ (allow file-read* file-test-existence
19
+ (literal ${binary})
20
+ (literal "/")
21
+ (subpath "/Library/Apple")
22
+ (subpath "/System/Library")
23
+ (subpath "/usr/lib")
24
+ (subpath "/usr/share")
25
+ (subpath "/private/var/db/timezone")
26
+ (literal "/private/etc/localtime")
27
+ (literal "/dev/null")
28
+ (literal "/dev/zero")
29
+ (literal "/dev/random")
30
+ (literal "/dev/urandom")
31
+ (subpath "/dev/fd"))
32
+
33
+ (allow file-map-executable
34
+ (literal ${binary})
35
+ (subpath "/Library/Apple")
36
+ (subpath "/System/Library")
37
+ (subpath "/usr/lib"))
38
+
39
+ ; Protocol I/O remains on the inherited pipes. No general filesystem writes.
40
+ (allow file-read-data (subpath "/dev/fd"))
41
+ (allow file-write-data
42
+ (literal "/dev/null")
43
+ (subpath "/dev/fd"))
44
+
45
+ ; Defense in depth: networking remains denied even if defaults change.
46
+ (deny network-inbound)
47
+ (deny network-outbound)
48
+ `;
49
+ }
50
+ //# sourceMappingURL=createMacOsSandboxProfile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createMacOsSandboxProfile.js","sourceRoot":"","sources":["../sources/createMacOsSandboxProfile.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,yBAAyB,CAAC,UAAkB;IACxD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAC1C,OAAO;;;;+BAIoB,MAAM;;;;;;;;;;;;aAYxB,MAAM;;;;;;;;;;;;;;;aAeN,MAAM;;;;;;;;;;;;;;CAclB,CAAC;AACF,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { CodeMode } from "./CodeMode.js";
2
+ export { CodeModeSession } from "./CodeModeSession.js";
3
+ export { createCodeMode } from "./createCodeMode.js";
4
+ export { resolveCodeModeBinary } from "./resolveCodeModeBinary.js";
5
+ export { runCode } from "./runCode.js";
6
+ export type * from "./types.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../sources/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,mBAAmB,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export { CodeMode } from "./CodeMode.js";
2
+ export { CodeModeSession } from "./CodeModeSession.js";
3
+ export { createCodeMode } from "./createCodeMode.js";
4
+ export { resolveCodeModeBinary } from "./resolveCodeModeBinary.js";
5
+ export { runCode } from "./runCode.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../sources/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,46 @@
1
+ export declare const PLATFORM_TARGETS: {
2
+ readonly "darwin-arm64": {
3
+ readonly alias: "@slopus/rig-codemode-codex-darwin-arm64";
4
+ readonly arch: "arm64";
5
+ readonly os: "darwin";
6
+ readonly tag: "darwin-arm64";
7
+ readonly target: "aarch64-apple-darwin";
8
+ };
9
+ readonly "darwin-x64": {
10
+ readonly alias: "@slopus/rig-codemode-codex-darwin-x64";
11
+ readonly arch: "x64";
12
+ readonly os: "darwin";
13
+ readonly tag: "darwin-x64";
14
+ readonly target: "x86_64-apple-darwin";
15
+ };
16
+ readonly "linux-arm64": {
17
+ readonly alias: "@slopus/rig-codemode-codex-linux-arm64";
18
+ readonly arch: "arm64";
19
+ readonly os: "linux";
20
+ readonly tag: "linux-arm64";
21
+ readonly target: "aarch64-unknown-linux-musl";
22
+ };
23
+ readonly "linux-x64": {
24
+ readonly alias: "@slopus/rig-codemode-codex-linux-x64";
25
+ readonly arch: "x64";
26
+ readonly os: "linux";
27
+ readonly tag: "linux-x64";
28
+ readonly target: "x86_64-unknown-linux-musl";
29
+ };
30
+ readonly "win32-arm64": {
31
+ readonly alias: "@slopus/rig-codemode-codex-win32-arm64";
32
+ readonly arch: "arm64";
33
+ readonly os: "win32";
34
+ readonly tag: "win32-arm64";
35
+ readonly target: "aarch64-pc-windows-msvc";
36
+ };
37
+ readonly "win32-x64": {
38
+ readonly alias: "@slopus/rig-codemode-codex-win32-x64";
39
+ readonly arch: "x64";
40
+ readonly os: "win32";
41
+ readonly tag: "win32-x64";
42
+ readonly target: "x86_64-pc-windows-msvc";
43
+ };
44
+ };
45
+ export type PlatformKey = keyof typeof PLATFORM_TARGETS;
46
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../sources/platform.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CnB,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,gBAAgB,CAAC"}