@alpacakit/agents 0.1.0-beta.39 → 0.2.0-beta.3

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 (134) hide show
  1. package/README.md +142 -1
  2. package/dist/agents/builtin.d.ts +2 -2
  3. package/dist/agents/builtin.d.ts.map +1 -1
  4. package/dist/agents/builtin.js +6 -4
  5. package/dist/agents/claude/cli.d.ts +133 -0
  6. package/dist/agents/claude/cli.d.ts.map +1 -0
  7. package/dist/agents/claude/cli.js +182 -0
  8. package/dist/agents/claude/host.d.ts +14 -0
  9. package/dist/agents/claude/host.d.ts.map +1 -0
  10. package/dist/agents/claude/host.js +319 -0
  11. package/dist/agents/{claude.d.ts → claude/index.d.ts} +11 -11
  12. package/dist/agents/claude/index.d.ts.map +1 -0
  13. package/dist/agents/claude/index.js +134 -0
  14. package/dist/agents/claude/session.d.ts +25 -0
  15. package/dist/agents/claude/session.d.ts.map +1 -0
  16. package/dist/agents/claude/session.js +321 -0
  17. package/dist/agents/codex/cli.d.ts +132 -0
  18. package/dist/agents/codex/cli.d.ts.map +1 -0
  19. package/dist/agents/codex/cli.js +110 -0
  20. package/dist/agents/codex/host.d.ts +14 -0
  21. package/dist/agents/codex/host.d.ts.map +1 -0
  22. package/dist/agents/codex/host.js +221 -0
  23. package/dist/agents/codex/index.d.ts +14 -0
  24. package/dist/agents/codex/index.d.ts.map +1 -0
  25. package/dist/agents/codex/index.js +127 -0
  26. package/dist/agents/codex/session.d.ts +21 -0
  27. package/dist/agents/codex/session.d.ts.map +1 -0
  28. package/dist/agents/codex/session.js +390 -0
  29. package/dist/agents/openai-compatible/fetch-engine.d.ts.map +1 -1
  30. package/dist/agents/openai-compatible/fetch-engine.js +3 -2
  31. package/dist/agents/openai-compatible/pi/engine.js +1 -1
  32. package/dist/agents/openai-compatible/pi/{session.d.ts → run.d.ts} +1 -1
  33. package/dist/agents/openai-compatible/pi/run.d.ts.map +1 -0
  34. package/dist/agents/openai-compatible/pi/sandbox.d.ts.map +1 -1
  35. package/dist/auth/login-probe.d.ts +6 -4
  36. package/dist/auth/login-probe.d.ts.map +1 -1
  37. package/dist/auth/login-probe.js +19 -13
  38. package/dist/auth/material.d.ts +1 -1
  39. package/dist/auth/material.d.ts.map +1 -1
  40. package/dist/codex/app-server.d.ts +50 -1
  41. package/dist/codex/app-server.d.ts.map +1 -1
  42. package/dist/codex/app-server.js +140 -66
  43. package/dist/codex/index.d.ts +3 -2
  44. package/dist/codex/index.d.ts.map +1 -1
  45. package/dist/codex/index.js +2 -1
  46. package/dist/codex/protocol.d.ts +101 -0
  47. package/dist/codex/protocol.d.ts.map +1 -1
  48. package/dist/codex/protocol.js +78 -0
  49. package/dist/config/agent-config-validation.d.ts +1 -1
  50. package/dist/config/agent-config-validation.d.ts.map +1 -1
  51. package/dist/config/agent-configs.d.ts.map +1 -1
  52. package/dist/config/agent-configs.js +3 -3
  53. package/dist/config/compose.d.ts.map +1 -1
  54. package/dist/config/config.d.ts +1 -1
  55. package/dist/config/config.d.ts.map +1 -1
  56. package/dist/config/index.d.ts +2 -2
  57. package/dist/config/index.d.ts.map +1 -1
  58. package/dist/config/index.js +1 -1
  59. package/dist/config/model.d.ts +0 -1
  60. package/dist/config/model.d.ts.map +1 -1
  61. package/dist/config/schema.d.ts.map +1 -1
  62. package/dist/config/schema.js +1 -1
  63. package/dist/config/store.d.ts.map +1 -1
  64. package/dist/config/store.js +6 -24
  65. package/dist/config/support.d.ts +0 -1
  66. package/dist/config/support.d.ts.map +1 -1
  67. package/dist/config/support.js +0 -9
  68. package/dist/core/cli-child.d.ts +56 -0
  69. package/dist/core/cli-child.d.ts.map +1 -0
  70. package/dist/core/cli-child.js +105 -0
  71. package/dist/core/fs.d.ts +1 -1
  72. package/dist/core/fs.d.ts.map +1 -1
  73. package/dist/core/fs.js +10 -2
  74. package/dist/core/node-ports.d.ts.map +1 -1
  75. package/dist/core/node-ports.js +1 -5
  76. package/dist/core/session.d.ts +104 -0
  77. package/dist/core/session.d.ts.map +1 -0
  78. package/dist/core/session.js +29 -0
  79. package/dist/fleet/store.d.ts.map +1 -1
  80. package/dist/fleet/store.js +4 -3
  81. package/dist/host/availability.d.ts +2 -1
  82. package/dist/host/availability.d.ts.map +1 -1
  83. package/dist/host/github-dir.d.ts.map +1 -1
  84. package/dist/host/github-dir.js +2 -1
  85. package/dist/host/mcp-list.d.ts.map +1 -1
  86. package/dist/host/mcp-list.js +5 -6
  87. package/dist/host/run-command.d.ts +2 -1
  88. package/dist/host/run-command.d.ts.map +1 -1
  89. package/dist/host/run-command.js +10 -19
  90. package/dist/host/session-files.d.ts +23 -0
  91. package/dist/host/session-files.d.ts.map +1 -0
  92. package/dist/host/session-files.js +92 -0
  93. package/dist/index.d.ts +9 -4
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +5 -2
  96. package/dist/internal/controlled-process/supervisor-runtime.js +27 -1
  97. package/dist/kernel/classify.d.ts +1 -2
  98. package/dist/kernel/classify.d.ts.map +1 -1
  99. package/dist/kernel/classify.js +1 -1
  100. package/dist/kernel/cli-agent.d.ts.map +1 -1
  101. package/dist/kernel/cli-agent.js +26 -85
  102. package/dist/kernel/cli-login.d.ts.map +1 -1
  103. package/dist/kernel/cli-login.js +9 -30
  104. package/dist/kernel/definition.d.ts +11 -2
  105. package/dist/kernel/definition.d.ts.map +1 -1
  106. package/dist/kernel/facets.d.ts +38 -1
  107. package/dist/kernel/facets.d.ts.map +1 -1
  108. package/dist/kernel/facets.js +20 -0
  109. package/dist/kernel/login.d.ts.map +1 -1
  110. package/dist/kernel/login.js +2 -1
  111. package/dist/kernel/options.d.ts +1 -1
  112. package/dist/kernel/options.d.ts.map +1 -1
  113. package/dist/kernel/run.d.ts.map +1 -1
  114. package/dist/kernel/run.js +2 -1
  115. package/dist/kernel/runtime.d.ts +10 -6
  116. package/dist/kernel/runtime.d.ts.map +1 -1
  117. package/dist/kernel/runtime.js +4 -1
  118. package/dist/kernel/session.d.ts +104 -0
  119. package/dist/kernel/session.d.ts.map +1 -0
  120. package/dist/kernel/session.js +314 -0
  121. package/dist/testing/fake-exec.d.ts +10 -5
  122. package/dist/testing/fake-exec.d.ts.map +1 -1
  123. package/dist/testing/fake-exec.js +17 -2
  124. package/dist/testing/index.d.ts +1 -1
  125. package/dist/testing/index.d.ts.map +1 -1
  126. package/dist/testing/index.js +1 -1
  127. package/package.json +2 -2
  128. package/dist/agents/claude.d.ts.map +0 -1
  129. package/dist/agents/claude.js +0 -543
  130. package/dist/agents/codex.d.ts +0 -19
  131. package/dist/agents/codex.d.ts.map +0 -1
  132. package/dist/agents/codex.js +0 -377
  133. package/dist/agents/openai-compatible/pi/session.d.ts.map +0 -1
  134. /package/dist/agents/openai-compatible/pi/{session.js → run.js} +0 -0
@@ -0,0 +1,390 @@
1
+ /**
2
+ * Codex session adapter: one `codex app-server` process holding one thread.
3
+ *
4
+ * Protocol facts (codex 0.153.4, T53 / T57 / T61 lab runs):
5
+ * - `thread/start {cwd, sandbox, approvalPolicy, approvalsReviewer}` creates
6
+ * the thread and takes its writer lock; with a writable sandbox Codex also
7
+ * appends a `trust_level` entry for `cwd` to `~/.codex/config.toml`;
8
+ * - `thread/resume` must repeat the permissions — without `sandbox` the
9
+ * resumed turns ran as danger-full-access; it answers -32600 "already has
10
+ * an active writer" while another process holds the thread and -32600
11
+ * "… is archived" for an archived one (`thread/unarchive` first, opt-in);
12
+ * - `turn/start` answers the turn id at once; `turn/steer {expectedTurnId}`
13
+ * appends to it; `turn/interrupt` ends it with `turn/completed`
14
+ * status `interrupted` (the command's own `item/completed` may trail by ~36 s);
15
+ * - `item/commandExecution/requestApproval` is a server request answered by
16
+ * `{"decision": "accept" | "decline"}`; closing stdin releases the lock.
17
+ */
18
+ import path from "node:path";
19
+ import { CODEX_INCOMING_KIND, createCodexAppServer, } from "../../codex/app-server.js";
20
+ import { CODEX_APP_SERVER_INCOMING, CODEX_APP_SERVER_METHOD, CODEX_SANDBOX_MODE, encodeCodexThreadPermissions, } from "../../codex/protocol.js";
21
+ import { isAgentError } from "../../core/error.js";
22
+ import { readArray, readBoolean, readRecord, readString, } from "../../core/json.js";
23
+ import { APPROVAL_DECISION, SESSION_OWNER_KIND, TURN_OUTCOME, } from "../../core/session.js";
24
+ import { fileExists, readDirectoryNames, scanJsonlFirstLast, } from "../../host/session-files.js";
25
+ import { assertHostSessionId, driveSession, } from "../../kernel/session.js";
26
+ import { CODEX, CODEX_APPROVAL_POLICY, CODEX_APPROVALS_REVIEWER, } from "./cli.js";
27
+ const USER_INPUT_TEXT = "text";
28
+ const APPROVAL_METHODS = [
29
+ CODEX_APP_SERVER_INCOMING.commandExecutionRequestApproval,
30
+ CODEX_APP_SERVER_INCOMING.fileChangeRequestApproval,
31
+ ];
32
+ const NON_TOOL_ITEM_TYPES = [
33
+ CODEX.notification.agentMessage,
34
+ CODEX.notification.userMessage,
35
+ CODEX.notification.reasoning,
36
+ ];
37
+ function wirePermissions(permissions) {
38
+ const sandbox = permissions.sandbox;
39
+ return encodeCodexThreadPermissions({
40
+ sandbox: sandbox.type,
41
+ approvalPolicy: permissions.approvalPolicy,
42
+ approvalsReviewer: permissions.approvalsReviewer,
43
+ workspaceWrite: sandbox.type === CODEX_SANDBOX_MODE.workspaceWrite
44
+ ? {
45
+ writableRoots: sandbox.writableRoots,
46
+ networkAccess: sandbox.networkAccess,
47
+ excludeTmpdirEnvVar: sandbox.excludeTmpdirEnvVar,
48
+ excludeSlashTmp: sandbox.excludeSlashTmp,
49
+ }
50
+ : null,
51
+ });
52
+ }
53
+ function turnOutcomeFrom(status) {
54
+ if (status === CODEX.turnStatus.interrupted) {
55
+ return TURN_OUTCOME.interrupted;
56
+ }
57
+ if (status === CODEX.turnStatus.completed) {
58
+ return TURN_OUTCOME.completed;
59
+ }
60
+ return TURN_OUTCOME.failed;
61
+ }
62
+ /** The last `agentMessage` with phase `final_answer` among a completed turn's items. */
63
+ function finalAnswerOf(turn) {
64
+ let text = null;
65
+ for (const value of readArray(turn, CODEX.notification.items) ?? []) {
66
+ const item = value !== null && typeof value === "object"
67
+ ? value
68
+ : null;
69
+ if (item !== null &&
70
+ readString(item, CODEX.notification.type) ===
71
+ CODEX.notification.agentMessage &&
72
+ readString(item, CODEX.notification.phase) ===
73
+ CODEX.notification.finalAnswer) {
74
+ text = readString(item, CODEX.notification.text) ?? text;
75
+ }
76
+ }
77
+ return text;
78
+ }
79
+ /**
80
+ * Codex accepts `decline` for every approval request even when its
81
+ * `availableDecisions` lists only `accept` plus amendment / `cancel`
82
+ * variants (T53 h2), so the caller is always offered both answers.
83
+ */
84
+ /**
85
+ * The Codex side of a Session: JSON-RPC requests out, notifications and
86
+ * server requests in. Turn ids are the host's own (`turn/start` answers
87
+ * one), so `steer` and `interrupt` name them.
88
+ */
89
+ class CodexProtocol {
90
+ threadId;
91
+ client;
92
+ incoming;
93
+ ctx;
94
+ constructor(threadId, client, incoming, ctx) {
95
+ this.threadId = threadId;
96
+ this.client = client;
97
+ this.incoming = incoming;
98
+ this.ctx = ctx;
99
+ }
100
+ get exit() {
101
+ return this.client.exit;
102
+ }
103
+ get stderrTail() {
104
+ return this.client.stderrTail;
105
+ }
106
+ async startTurn(text) {
107
+ const { turnId } = await this.client.request(CODEX_APP_SERVER_METHOD.turnStart, {
108
+ threadId: this.threadId,
109
+ input: [{ type: USER_INPUT_TEXT, text }],
110
+ });
111
+ return turnId;
112
+ }
113
+ async steer(turnId, text) {
114
+ await this.client.request(CODEX_APP_SERVER_METHOD.turnSteer, {
115
+ threadId: this.threadId,
116
+ expectedTurnId: turnId,
117
+ input: [{ type: USER_INPUT_TEXT, text }],
118
+ });
119
+ }
120
+ async interrupt(turnId) {
121
+ await this.client.request(CODEX_APP_SERVER_METHOD.turnInterrupt, {
122
+ threadId: this.threadId,
123
+ turnId,
124
+ });
125
+ }
126
+ respond(id, decision) {
127
+ this.client.respond(id, {
128
+ result: {
129
+ decision: decision === APPROVAL_DECISION.accept
130
+ ? CODEX.decision.accept
131
+ : CODEX.decision.decline,
132
+ },
133
+ });
134
+ }
135
+ close() {
136
+ return this.client.close();
137
+ }
138
+ decode(item, sink) {
139
+ if (item.kind === CODEX_INCOMING_KIND.request) {
140
+ this.decodeServerRequest(item, sink);
141
+ }
142
+ else {
143
+ this.decodeNotification(item.method, item.params, sink);
144
+ }
145
+ }
146
+ forThread(params) {
147
+ if (params === null ||
148
+ readString(params, CODEX.notification.threadId) !== this.threadId) {
149
+ return null;
150
+ }
151
+ return params;
152
+ }
153
+ decodeNotification(method, raw, sink) {
154
+ const params = this.forThread(raw);
155
+ if (params === null) {
156
+ return;
157
+ }
158
+ const active = sink.activeTurnId;
159
+ if (method === CODEX_APP_SERVER_INCOMING.turnCompleted) {
160
+ const turn = readRecord(params, CODEX.notification.turn);
161
+ if (turn === null || readString(turn, CODEX.notification.id) !== active) {
162
+ return;
163
+ }
164
+ sink.endTurn(turnOutcomeFrom(readString(turn, CODEX.notification.status)), finalAnswerOf(turn));
165
+ return;
166
+ }
167
+ if (readString(params, CODEX.notification.turnId) !== active) {
168
+ return;
169
+ }
170
+ const item = readRecord(params, CODEX.notification.item);
171
+ const itemType = item === null ? null : readString(item, CODEX.notification.type);
172
+ if (item === null || itemType === null) {
173
+ return;
174
+ }
175
+ if (method === CODEX_APP_SERVER_INCOMING.itemStarted &&
176
+ !NON_TOOL_ITEM_TYPES.includes(itemType)) {
177
+ sink.tool(itemType);
178
+ return;
179
+ }
180
+ if (method === CODEX_APP_SERVER_INCOMING.itemCompleted &&
181
+ itemType === CODEX.notification.agentMessage) {
182
+ const text = readString(item, CODEX.notification.text);
183
+ if (text !== null && text !== "") {
184
+ sink.message(text);
185
+ }
186
+ }
187
+ }
188
+ decodeServerRequest(request, sink) {
189
+ const params = this.forThread(request.params);
190
+ if (params === null || !APPROVAL_METHODS.includes(request.method)) {
191
+ // An unanswered server request would hang the turn; refusing it lets
192
+ // the model see the failure and go on.
193
+ this.ctx.logger.log("warn", `refusing unsupported codex server request "${request.method}"`);
194
+ this.client.respond(request.id, {
195
+ error: {
196
+ code: CODEX.error.methodNotFound,
197
+ message: CODEX.error.unsupported,
198
+ },
199
+ });
200
+ return;
201
+ }
202
+ sink.approvalRequested(String(request.id), readString(params, CODEX.notification.command) ??
203
+ readString(params, CODEX.notification.reason) ??
204
+ request.method, request.id);
205
+ }
206
+ }
207
+ /** Subscribe before the first request so no server traffic is missed; single-use. */
208
+ function subscribe(client) {
209
+ const iterator = client.incoming[Symbol.asyncIterator]();
210
+ return { [Symbol.asyncIterator]: () => iterator };
211
+ }
212
+ function codexSession(threadId, client, incoming, ctx) {
213
+ return driveSession({
214
+ id: threadId,
215
+ agentId: CODEX.id,
216
+ protocol: new CodexProtocol(threadId, client, incoming, ctx),
217
+ logger: ctx.logger,
218
+ });
219
+ }
220
+ async function openCodexSession(options, ctx) {
221
+ const client = createCodexAppServer({
222
+ exec: ctx.exec,
223
+ clock: ctx.clock,
224
+ env: ctx.env,
225
+ cwd: options.workspace,
226
+ command: CODEX.command,
227
+ });
228
+ const incoming = subscribe(client);
229
+ try {
230
+ const { threadId } = await client.request(CODEX_APP_SERVER_METHOD.threadStart, {
231
+ cwd: options.workspace,
232
+ ...wirePermissions(options.permissions),
233
+ });
234
+ return codexSession(threadId, client, incoming, ctx);
235
+ }
236
+ catch (error) {
237
+ await client.close();
238
+ throw error;
239
+ }
240
+ }
241
+ async function resumeCodexSession(id, options, ctx) {
242
+ assertHostSessionId(id, CODEX.id);
243
+ const client = createCodexAppServer({
244
+ exec: ctx.exec,
245
+ clock: ctx.clock,
246
+ env: ctx.env,
247
+ cwd: options.workspace,
248
+ command: CODEX.command,
249
+ });
250
+ const incoming = subscribe(client);
251
+ const params = {
252
+ threadId: id,
253
+ excludeTurns: true,
254
+ ...wirePermissions(options.permissions),
255
+ };
256
+ try {
257
+ let resumed;
258
+ try {
259
+ resumed = await client.request(CODEX_APP_SERVER_METHOD.threadResume, params);
260
+ }
261
+ catch (error) {
262
+ // Unarchiving is a visible side effect (the thread returns to the
263
+ // ChatGPT app's active list), so it happens only on request.
264
+ if (!options.unarchive || !isArchivedError(error)) {
265
+ throw error;
266
+ }
267
+ await client.request(CODEX_APP_SERVER_METHOD.threadUnarchive, {
268
+ threadId: id,
269
+ });
270
+ resumed = await client.request(CODEX_APP_SERVER_METHOD.threadResume, params);
271
+ }
272
+ return codexSession(resumed.threadId, client, incoming, ctx);
273
+ }
274
+ catch (error) {
275
+ await client.close();
276
+ throw error;
277
+ }
278
+ }
279
+ function isArchivedError(error) {
280
+ return (isAgentError(error, "failed") &&
281
+ error.message.includes(CODEX.error.archived));
282
+ }
283
+ function codexRoot(ctx, ...segments) {
284
+ return path.join(ctx.location.homeDir, CODEX.files.root, ...segments);
285
+ }
286
+ /** `rollout-<time>-<id>.jsonl` under `sessions/YYYY/MM/DD/` (live) or `archived_sessions/` (archived). */
287
+ async function findCodexRollout(ctx, id) {
288
+ const suffix = `-${id.toLowerCase()}${CODEX.files.rolloutExtension}`;
289
+ const matches = (name) => name.toLowerCase().endsWith(suffix);
290
+ const root = codexRoot(ctx, CODEX.files.sessions);
291
+ for (const year of (await readDirectoryNames(root)).sort().reverse()) {
292
+ for (const month of (await readDirectoryNames(path.join(root, year)))
293
+ .sort()
294
+ .reverse()) {
295
+ const monthDir = path.join(root, year, month);
296
+ for (const day of (await readDirectoryNames(monthDir)).sort().reverse()) {
297
+ const dayDir = path.join(monthDir, day);
298
+ const file = (await readDirectoryNames(dayDir)).find(matches);
299
+ if (file !== undefined) {
300
+ return { file: path.join(dayDir, file), archived: false };
301
+ }
302
+ }
303
+ }
304
+ }
305
+ const archivedRoot = codexRoot(ctx, CODEX.files.archivedSessions);
306
+ const archived = (await readDirectoryNames(archivedRoot)).find(matches);
307
+ return archived === undefined
308
+ ? null
309
+ : { file: path.join(archivedRoot, archived), archived: true };
310
+ }
311
+ function oneOf(values, value) {
312
+ return value !== null && values.includes(value)
313
+ ? value
314
+ : null;
315
+ }
316
+ /** Only shapes seen in rollouts decode; anything unfamiliar is `null`, never a guess. */
317
+ function sandboxPolicyFrom(policy) {
318
+ const type = policy === null ? null : readString(policy, CODEX.files.type);
319
+ if (type === CODEX_SANDBOX_MODE.readOnly ||
320
+ type === CODEX_SANDBOX_MODE.dangerFullAccess) {
321
+ return { type };
322
+ }
323
+ if (policy === null || type !== CODEX_SANDBOX_MODE.workspaceWrite) {
324
+ return null;
325
+ }
326
+ const roots = readArray(policy, CODEX.files.writableRoots) ?? [];
327
+ const networkAccess = readBoolean(policy, CODEX.files.networkAccess);
328
+ const excludeTmpdirEnvVar = readBoolean(policy, CODEX.files.excludeTmpdirEnvVar);
329
+ const excludeSlashTmp = readBoolean(policy, CODEX.files.excludeSlashTmp);
330
+ if (!roots.every((root) => typeof root === "string") ||
331
+ networkAccess === null ||
332
+ excludeTmpdirEnvVar === null ||
333
+ excludeSlashTmp === null) {
334
+ return null;
335
+ }
336
+ return {
337
+ type,
338
+ writableRoots: roots,
339
+ networkAccess,
340
+ excludeTmpdirEnvVar,
341
+ excludeSlashTmp,
342
+ };
343
+ }
344
+ function permissionsFrom(context) {
345
+ const approvalPolicy = oneOf(Object.values(CODEX_APPROVAL_POLICY), readString(context, CODEX.files.approvalPolicy));
346
+ const approvalsReviewer = oneOf(Object.values(CODEX_APPROVALS_REVIEWER), readString(context, CODEX.files.approvalsReviewer));
347
+ const sandbox = sandboxPolicyFrom(readRecord(context, CODEX.files.sandboxPolicy));
348
+ if (approvalPolicy === null ||
349
+ approvalsReviewer === null ||
350
+ sandbox === null) {
351
+ return null;
352
+ }
353
+ return { approvalPolicy, approvalsReviewer, sandbox };
354
+ }
355
+ function payloadOfType(record, type) {
356
+ return readString(record, CODEX.files.type) === type
357
+ ? readRecord(record, CODEX.files.payload)
358
+ : null;
359
+ }
360
+ async function inspectCodexSession(id, ctx) {
361
+ assertHostSessionId(id, CODEX.id);
362
+ const rollout = await findCodexRollout(ctx, id);
363
+ if (rollout === null) {
364
+ return null;
365
+ }
366
+ const cwd = await scanJsonlFirstLast(rollout.file, (record) => {
367
+ const meta = payloadOfType(record, CODEX.files.sessionMeta);
368
+ return meta === null ? null : readString(meta, CODEX.files.cwd);
369
+ });
370
+ if (cwd.first === null) {
371
+ return null;
372
+ }
373
+ const contexts = await scanJsonlFirstLast(rollout.file, (record) => payloadOfType(record, CODEX.files.turnContext));
374
+ const locked = await fileExists(codexRoot(ctx, CODEX.files.writerLocks, `${id}${CODEX.files.lockExtension}`));
375
+ return {
376
+ workspace: cwd.first,
377
+ lastPermissions: contexts.last === null ? null : permissionsFrom(contexts.last),
378
+ owner: locked
379
+ ? { kind: SESSION_OWNER_KIND.process, pid: null, entrypoint: null }
380
+ : { kind: SESSION_OWNER_KIND.none },
381
+ archived: rollout.archived,
382
+ };
383
+ }
384
+ export function codexSessions() {
385
+ return {
386
+ open: openCodexSession,
387
+ resume: resumeCodexSession,
388
+ inspect: inspectCodexSession,
389
+ };
390
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-engine.d.ts","sourceRoot":"","sources":["../../../src/agents/openai-compatible/fetch-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EAIX,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAa,8BAA8B,EAAE,MAAM,YAAY,CAAC;AA+C5E,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1D;AAED,MAAM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3B,GAAG,EAAE,UAAU,GACd,QAAQ;IA+CX,OAAO,CAAC,UAAU;CAenB;AAED,qBAAa,kCACX,YAAW,2BAA2B;IAEtC,QAAQ,CAAC,WAAW,KAAwB;IAE5C,WAAW,CAAC,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;CAGzD;AAED,qBAAa,wCACX,YAAW,iCAAiC;IAE5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAIvB;IAEI,QAAQ,CACZ,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;CAM9B;AAmJD,eAAO,MAAM,6BAA6B,6BAAoC,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { NO_FAILURE_EVIDENCE } from "../../core/cli-child.js";
1
2
  import { AGENT_ERROR_CODE, AgentError, AUTH_FAILURE_REASON, isAgentError, NOT_AVAILABLE_CAUSE, } from "../../core/error.js";
2
3
  import { redactSecrets } from "../../core/redact.js";
3
4
  import { parseCooldownHint } from "../../kernel/classify.js";
@@ -94,7 +95,7 @@ export class FetchOpenAiCompatibleEngine {
94
95
  code: AGENT_ERROR_CODE.failed,
95
96
  classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
96
97
  message: "OpenAI-compatible endpoint returned an unsupported response",
97
- data: { exitCode: null, stdoutTail: null, stderrTail: null },
98
+ data: NO_FAILURE_EVIDENCE,
98
99
  });
99
100
  }
100
101
  return decoder;
@@ -216,7 +217,7 @@ function unreachableError() {
216
217
  code: AGENT_ERROR_CODE.failed,
217
218
  classification: AgentError.agentFailure(AGENT_ERROR_CODE.failed),
218
219
  message: "OpenAI-compatible endpoint failed without an error",
219
- data: { exitCode: null, stdoutTail: null, stderrTail: null },
220
+ data: NO_FAILURE_EVIDENCE,
220
221
  });
221
222
  }
222
223
  export const defaultOpenAiCompatibleEngine = new FetchOpenAiCompatibleEngine();
@@ -1,7 +1,7 @@
1
1
  import { AGENT_ERROR_CODE, isAgentError } from "../../../core/error.js";
2
2
  import { DOCTOR_CHECK_STATUS, } from "../../../host/capabilities.js";
3
3
  import { defaultPiModuleLoader, loadPiModule, } from "./module.js";
4
- import { runPiSession } from "./session.js";
4
+ import { runPiSession } from "./run.js";
5
5
  /**
6
6
  * Placeholder model capabilities: the resolved config has no metadata to
7
7
  * derive them from, so these defaults assume a large-context model. Callers
@@ -14,4 +14,4 @@ type PiSessionRunInput = {
14
14
  };
15
15
  export declare function runPiSession(input: PiSessionRunInput): AgentRun;
16
16
  export {};
17
- //# sourceMappingURL=session.d.ts.map
17
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../../src/agents/openai-compatible/pi/run.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAkB,QAAQ,EAAE,MAAM,aAAa,CAAC;AA8E5D,KAAK,iBAAiB,GAAG;IACvB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,8BAA8B,CAAC;IAChD,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC;IACrC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;CAC1B,CAAC;AAWF,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,QAAQ,CAE/D"}
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../../src/agents/openai-compatible/pi/sandbox.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,KAAK,EACV,KAAK,eAAe,EACpB,YAAY,EACZ,KAAK,WAAW,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,QAAQ,EAAoB,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,WAAW,IAAI,CAC1D,OAAO,EAAE,OAAO,CAAC,eAAe,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,EAC9C,KAAK,EAAE,oBAAoB,KACxB,YAAY,CAAC;AAWlB,eAAO,MAAM,qBAAqB;;;;;;;;CAMjC,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,oBAAoB,GAC1B,YAAY,CASd"}
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../../../../src/agents/openai-compatible/pi/sandbox.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,KAAK,KAAK,EACV,KAAK,eAAe,EACpB,YAAY,EACZ,KAAK,WAAW,EACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAoB,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE7E,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,WAAW,IAAI,CAC1D,OAAO,EAAE,OAAO,CAAC,eAAe,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,EAC9C,KAAK,EAAE,oBAAoB,KACxB,YAAY,CAAC;AAWlB,eAAO,MAAM,qBAAqB;;;;;;;;CAMjC,CAAC;AAEF,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,eAAe,EACxB,KAAK,EAAE,oBAAoB,GAC1B,YAAY,CASd"}
@@ -3,14 +3,15 @@
3
3
  * under the candidate's auth env and map its exit code to an `AuthStatus`.
4
4
  * Only the exit code matters — output is drained and discarded. A hung probe
5
5
  * is killed after the timeout and reported as "unknown"; a hang proves
6
- * nothing about the credential (probe-owned time mechanics, mirroring the run
7
- * plane's kill escalation). Home-dir material handlers reuse this so the two
8
- * built-in agents do not each carry a copy of the probe loop.
6
+ * nothing about the credential. A probe that cannot start (no binary, PATH or
7
+ * spawn fault) proves nothing either and is `unknown`, never a thrown fault —
8
+ * the same policy as the availability probe. Home-dir material handlers reuse
9
+ * this so the built-in agents do not each carry a copy of the probe loop.
9
10
  */
10
11
  import type { EnvPatch } from "../core/env.js";
11
12
  import type { HostContext } from "../host/context.js";
12
13
  import { type AuthStatus } from "./material.js";
13
- export type CliLoginProbeOptions = {
14
+ type CliLoginProbeOptions = {
14
15
  readonly command: string;
15
16
  readonly args: readonly string[];
16
17
  readonly envPatch: EnvPatch;
@@ -18,4 +19,5 @@ export type CliLoginProbeOptions = {
18
19
  readonly timeoutMs?: number;
19
20
  };
20
21
  export declare function cliLoginProbe(options: CliLoginProbeOptions): Promise<AuthStatus>;
22
+ export {};
21
23
  //# sourceMappingURL=login-probe.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"login-probe.d.ts","sourceRoot":"","sources":["../../src/auth/login-probe.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAI7D,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,wBAAsB,aAAa,CACjC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,UAAU,CAAC,CAgCrB"}
1
+ {"version":3,"file":"login-probe.d.ts","sourceRoot":"","sources":["../../src/auth/login-probe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAI7D,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,wBAAsB,aAAa,CACjC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,UAAU,CAAC,CAoCrB"}
@@ -3,9 +3,10 @@
3
3
  * under the candidate's auth env and map its exit code to an `AuthStatus`.
4
4
  * Only the exit code matters — output is drained and discarded. A hung probe
5
5
  * is killed after the timeout and reported as "unknown"; a hang proves
6
- * nothing about the credential (probe-owned time mechanics, mirroring the run
7
- * plane's kill escalation). Home-dir material handlers reuse this so the two
8
- * built-in agents do not each carry a copy of the probe loop.
6
+ * nothing about the credential. A probe that cannot start (no binary, PATH or
7
+ * spawn fault) proves nothing either and is `unknown`, never a thrown fault —
8
+ * the same policy as the availability probe. Home-dir material handlers reuse
9
+ * this so the built-in agents do not each carry a copy of the probe loop.
9
10
  */
10
11
  import { applyEnvPatch } from "../core/env.js";
11
12
  import { PROCESS_SIGNAL } from "../core/values.js";
@@ -14,18 +15,23 @@ const DEFAULT_LOGIN_PROBE_TIMEOUT_MS = 30_000;
14
15
  export async function cliLoginProbe(options) {
15
16
  const timeoutMs = options.timeoutMs ?? DEFAULT_LOGIN_PROBE_TIMEOUT_MS;
16
17
  const env = applyEnvPatch(options.ctx.env, options.envPatch);
17
- const command = await options.ctx.exec.which(options.command, env);
18
- if (command === null) {
19
- // No binary on PATH: the probe cannot run, so it proves nothing.
18
+ let probe;
19
+ try {
20
+ const command = await options.ctx.exec.which(options.command, env);
21
+ if (command === null) {
22
+ return AUTH_STATUS.unknown;
23
+ }
24
+ probe = options.ctx.exec.spawn({
25
+ command,
26
+ args: [...options.args],
27
+ cwd: options.ctx.location.homeDir,
28
+ env,
29
+ stdin: null,
30
+ });
31
+ }
32
+ catch {
20
33
  return AUTH_STATUS.unknown;
21
34
  }
22
- const probe = options.ctx.exec.spawn({
23
- command,
24
- args: [...options.args],
25
- cwd: options.ctx.location.homeDir,
26
- env,
27
- stdin: null,
28
- });
29
35
  let timedOut = false;
30
36
  const cancelTimeout = options.ctx.clock.setTimeout(() => {
31
37
  timedOut = true;
@@ -64,7 +64,7 @@ export type MaterialHandler<K extends AuthMaterialKind> = {
64
64
  kind: K;
65
65
  }>, ctx: HostContext): Promise<AuthStatus>;
66
66
  };
67
- export type EnvVarAuthMaterialOptions<K extends AuthMaterialKind> = {
67
+ type EnvVarAuthMaterialOptions<K extends AuthMaterialKind> = {
68
68
  readonly set: (material: Extract<AuthMaterial, {
69
69
  kind: K;
70
70
  }>, secrets: SecretResolvers) => Promise<Record<string, string>> | Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"material.d.ts","sourceRoot":"","sources":["../../src/auth/material.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,eAAO,MAAM,kBAAkB;;;CAGrB,CAAC;AAEX,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,OAAO,kBAAkB,CAAC,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzD;IAAE,IAAI,EAAE,OAAO,kBAAkB,CAAC,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC;AAElE,MAAM,MAAM,gBAAgB,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;AAYpD,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAE1E;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG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KAAE,CAAC,EAC5C,OAAO,EAAE,eAAe,KACrB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9D,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,CACf,QAAQ,EAAE,OAAO,CAAC,YAAY,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,EAC5C,GAAG,EAAE,WAAW,KACb,OAAO,CAAC,UAAU,CAAC,CAAC;CAC1B,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,gBAAgB,EAC3D,OAAO,EAAE,yBAAyB,CAAC,CAAC,CAAC,GACpC,eAAe,CAAC,CAAC,CAAC,CAWpB;AAED;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG;KAC5B,CAAC,IAAI,gBAAgB,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,gBAAgB,CAAC;CAC7B"}
@@ -1,4 +1,15 @@
1
- import type { Clock, Exec } from "../core/ports.js";
1
+ /**
2
+ * Codex app-server client over stdio JSON-RPC. One client is one child
3
+ * process, held as long as the caller wants: host-plane calls create one
4
+ * per call (`withCodexAppServer`), a Session keeps one for the thread's
5
+ * whole life. Both directions are modeled — client requests get typed,
6
+ * decoded results; server notifications and server-initiated requests
7
+ * (approval prompts) arrive on `incoming`, and `respond` answers the latter.
8
+ * A request timeout fails that request only; it never kills the process,
9
+ * because a Session's other traffic shares it.
10
+ */
11
+ import { type UnknownRecord } from "../core/json.js";
12
+ import type { Clock, Exec, ExecExit } from "../core/ports.js";
2
13
  import type { CodexAppServerMethods, CodexMcpServerStatus } from "./protocol.js";
3
14
  /**
4
15
  * How the client identifies itself to the codex app-server `initialize`
@@ -20,8 +31,46 @@ export type CodexAppServerOptions = {
20
31
  readonly requestTimeoutMs?: number;
21
32
  readonly clientInfo?: AppServerClientInfo;
22
33
  };
34
+ export declare const CODEX_INCOMING_KIND: {
35
+ readonly notification: "notification";
36
+ readonly request: "request";
37
+ };
38
+ /** JSON-RPC ids the server chooses for its own requests. */
39
+ export type CodexServerRequestId = number | string;
40
+ /** What the server sends on its own: notifications, or requests it awaits an answer to. */
41
+ export type CodexIncoming = {
42
+ readonly kind: typeof CODEX_INCOMING_KIND.notification;
43
+ readonly method: string;
44
+ readonly params: UnknownRecord | null;
45
+ } | {
46
+ readonly kind: typeof CODEX_INCOMING_KIND.request;
47
+ readonly id: CodexServerRequestId;
48
+ readonly method: string;
49
+ readonly params: UnknownRecord | null;
50
+ };
51
+ export type CodexServerRequestAnswer = {
52
+ readonly result: unknown;
53
+ } | {
54
+ readonly error: {
55
+ readonly code: number;
56
+ readonly message: string;
57
+ };
58
+ };
23
59
  export interface CodexAppServer {
24
60
  request<M extends keyof CodexAppServerMethods>(method: M, params: CodexAppServerMethods[M]["params"]): Promise<CodexAppServerMethods[M]["result"]>;
61
+ /**
62
+ * Server-originated traffic in arrival order. Each iteration is its own
63
+ * subscription that starts at the moment of subscribing; nothing is
64
+ * buffered for consumers that never subscribe.
65
+ */
66
+ readonly incoming: AsyncIterable<CodexIncoming>;
67
+ /** Answer a server-initiated request by its id. */
68
+ respond(id: CodexServerRequestId, answer: CodexServerRequestAnswer): void;
69
+ /** Resolves when the child has exited (after `close()`, or on its own). */
70
+ readonly exit: Promise<ExecExit>;
71
+ /** The last ~2 KB of the server's stderr, for failure evidence. */
72
+ readonly stderrTail: string;
73
+ /** End stdin (the server exits on EOF), escalate to SIGTERM then SIGKILL after graces, wait for exit. */
25
74
  close(): Promise<void>;
26
75
  }
27
76
  export declare function createCodexAppServer(options: CodexAppServerOptions): CodexAppServer;
@@ -1 +1 @@
1
- {"version":3,"file":"app-server.d.ts","sourceRoot":"","sources":["../../src/codex/app-server.ts"],"names":[],"mappings":"A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