@ycodium-ai/agent-codex 0.2.5448 → 0.2.5542

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 (2) hide show
  1. package/dist/index.js +378 -97
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { definePlugin } from "@ycodium-ai/plugin-api";
3
3
 
4
4
  // ../../packages/plugin-api/src/version.ts
5
- var PLUGIN_API_VERSION = 171;
5
+ var PLUGIN_API_VERSION = 174;
6
6
 
7
7
  // src/index.ts
8
8
  import {
@@ -160,8 +160,8 @@ import * as NodePath3 from "node:path";
160
160
  // ../../packages/ycodium-credential-account/src/credentialAccount.ts
161
161
  import * as NodeFS from "node:fs";
162
162
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
163
- var readTrimmedString = (record, key) => {
164
- const value = record[key];
163
+ var readTrimmedString = (record2, key) => {
164
+ const value = record2[key];
165
165
  if (typeof value !== "string") return void 0;
166
166
  const trimmed = value.trim();
167
167
  return trimmed.length > 0 ? trimmed : void 0;
@@ -395,8 +395,8 @@ function homeExists(homePath) {
395
395
 
396
396
  // src/codexAccount.ts
397
397
  var AUTH_FILE_NAME = "auth.json";
398
- var readNumber = (record, key) => {
399
- const value = record[key];
398
+ var readNumber = (record2, key) => {
399
+ const value = record2[key];
400
400
  return typeof value === "number" && Number.isFinite(value) ? value : void 0;
401
401
  };
402
402
  function decodeJwtClaims(token) {
@@ -1181,9 +1181,9 @@ async function* readJsonlEntries(fs, path, options) {
1181
1181
  };
1182
1182
  const takeLine = () => {
1183
1183
  if (parser !== null) {
1184
- const record = parser.finish();
1184
+ const record2 = parser.finish();
1185
1185
  parser = null;
1186
- return { oversized: record };
1186
+ return { oversized: record2 };
1187
1187
  }
1188
1188
  if (pending2 === 0) return null;
1189
1189
  let line = pieces.length === 1 ? pieces[0] ?? "" : pieces.join("");
@@ -2401,6 +2401,10 @@ async function readCodexCliVersion(input) {
2401
2401
  return null;
2402
2402
  }
2403
2403
  }
2404
+ function missingBinaryDetail(binaryPath) {
2405
+ const relyOnPath = !/[\\/]/.test(binaryPath);
2406
+ return `Could not start Codex (${binaryPath}). Check the "Program path" setting of this provider on this machine.` + (relyOnPath ? " The Codex desktop app may not add codex to PATH; enter the full path to the codex executable there." : " Make sure the configured file exists and can be run.");
2407
+ }
2404
2408
 
2405
2409
  // src/failureCategory.ts
2406
2410
  var codexProcessExitCategory = (session) => session !== void 0 && !session.stopRequested && typeof session.nativeThreadId === "string" && session.nativeThreadId.length > 0 ? "process-exit" : void 0;
@@ -4348,12 +4352,12 @@ function toApplyPatchFileChanges(params) {
4348
4352
  return out;
4349
4353
  }
4350
4354
  function describeCommandApproval(params) {
4351
- const record = isRecord2(params) ? params : {};
4352
- const commandValue = record["command"];
4355
+ const record2 = isRecord2(params) ? params : {};
4356
+ const commandValue = record2["command"];
4353
4357
  const command = Array.isArray(commandValue) ? commandValue.filter((entry) => typeof entry === "string").join(" ") : asString(commandValue) ?? "";
4354
- const cwd = asString(record["cwd"]);
4355
- const reason = trimText(record["reason"]);
4356
- const callId = asString(record["callId"]);
4358
+ const cwd = asString(record2["cwd"]);
4359
+ const reason = trimText(record2["reason"]);
4360
+ const callId = asString(record2["callId"]);
4357
4361
  return {
4358
4362
  command,
4359
4363
  ...cwd ? { cwd } : {},
@@ -4362,22 +4366,22 @@ function describeCommandApproval(params) {
4362
4366
  };
4363
4367
  }
4364
4368
  function describeFileChangeApproval(params) {
4365
- const record = isRecord2(params) ? params : {};
4366
- const reason = trimText(record["reason"]);
4367
- const grantRoot = asString(record["grantRoot"]);
4368
- const callId = asString(record["callId"]);
4369
- const detail = reason ?? describeFileChanges(record) ?? trimText(grantRoot);
4369
+ const record2 = isRecord2(params) ? params : {};
4370
+ const reason = trimText(record2["reason"]);
4371
+ const grantRoot = asString(record2["grantRoot"]);
4372
+ const callId = asString(record2["callId"]);
4373
+ const detail = reason ?? describeFileChanges(record2) ?? trimText(grantRoot);
4370
4374
  return {
4371
4375
  ...reason ? { reason } : {},
4372
4376
  ...detail ? { detail } : {},
4373
4377
  ...grantRoot ? { grantRoot } : {},
4374
4378
  ...callId ? { callId } : {},
4375
- fileChanges: toApplyPatchFileChanges(record)
4379
+ fileChanges: toApplyPatchFileChanges(record2)
4376
4380
  };
4377
4381
  }
4378
4382
  function describePermissionsApproval(params) {
4379
- const record = isRecord2(params) ? params : {};
4380
- const permissions = isRecord2(record["permissions"]) ? record["permissions"] : {};
4383
+ const record2 = isRecord2(params) ? params : {};
4384
+ const permissions = isRecord2(record2["permissions"]) ? record2["permissions"] : {};
4381
4385
  const fileSystem = isRecord2(permissions["fileSystem"]) ? permissions["fileSystem"] : {};
4382
4386
  const network = isRecord2(permissions["network"]) ? permissions["network"] : {};
4383
4387
  const pathsOf = (value) => Array.isArray(value) ? value.flatMap((entry) => typeof entry === "string" && entry.length > 0 ? [entry] : []) : [];
@@ -4392,7 +4396,7 @@ function describePermissionsApproval(params) {
4392
4396
  if (entry["access"] === "read") read.push(path);
4393
4397
  if (entry["access"] === "write") write.push(path);
4394
4398
  }
4395
- const reason = trimText(record["reason"]);
4399
+ const reason = trimText(record2["reason"]);
4396
4400
  return {
4397
4401
  ...reason ? { reason } : {},
4398
4402
  read: [...new Set(read)],
@@ -4412,11 +4416,11 @@ function toPermissionsResponse(decision, params, persistent) {
4412
4416
  };
4413
4417
  }
4414
4418
  function describeMcpElicitation(params) {
4415
- const record = isRecord2(params) ? params : {};
4416
- const appName = asString(record["appName"]) ?? asString(record["serverName"]) ?? void 0;
4417
- const serverName = asString(record["serverName"]);
4418
- const message = trimText(record["message"]);
4419
- const url = asString(record["url"]) ?? asString(record["authorizationUrl"]);
4419
+ const record2 = isRecord2(params) ? params : {};
4420
+ const appName = asString(record2["appName"]) ?? asString(record2["serverName"]) ?? void 0;
4421
+ const serverName = asString(record2["serverName"]);
4422
+ const message = trimText(record2["message"]);
4423
+ const url = asString(record2["url"]) ?? asString(record2["authorizationUrl"]);
4420
4424
  const identity = appName ?? url ?? "unknown";
4421
4425
  return {
4422
4426
  ...appName ? { appName } : {},
@@ -4425,7 +4429,7 @@ function describeMcpElicitation(params) {
4425
4429
  ...url ? { url } : {},
4426
4430
  identity,
4427
4431
  mode: url ? "url" : "form",
4428
- ...record["requestedSchema"] !== void 0 ? { schema: record["requestedSchema"] } : {}
4432
+ ...record2["requestedSchema"] !== void 0 ? { schema: record2["requestedSchema"] } : {}
4429
4433
  };
4430
4434
  }
4431
4435
  function persistFromMeta(meta) {
@@ -6046,26 +6050,26 @@ async function readCodexRolloutModel(input, rolloutPath, sameDirectory) {
6046
6050
  fields: ROLLOUT_FIELDS
6047
6051
  });
6048
6052
  for await (const entry of entries) {
6049
- let record;
6053
+ let record2;
6050
6054
  if ("oversized" in entry) {
6051
- record = asRecord3(entry.oversized);
6055
+ record2 = asRecord3(entry.oversized);
6052
6056
  } else {
6053
6057
  if (!entry.line.includes('"session_meta"') && !entry.line.includes('"turn_context"')) {
6054
6058
  continue;
6055
6059
  }
6056
6060
  try {
6057
- record = asRecord3(JSON.parse(entry.line));
6061
+ record2 = asRecord3(JSON.parse(entry.line));
6058
6062
  } catch {
6059
6063
  continue;
6060
6064
  }
6061
6065
  }
6062
- const payload = asRecord3(record?.payload);
6063
- if (!record || !payload) continue;
6064
- if (record.type === "session_meta" && !verified) {
6066
+ const payload = asRecord3(record2?.payload);
6067
+ if (!record2 || !payload) continue;
6068
+ if (record2.type === "session_meta" && !verified) {
6065
6069
  if ((payload.id ?? payload.session_id) !== input.threadId || typeof payload.cwd !== "string" || !path.isAbsolute(payload.cwd) || !sameDirectory(payload.cwd, input.cwd))
6066
6070
  return null;
6067
6071
  verified = true;
6068
- } else if (record.type === "turn_context" && verified) {
6072
+ } else if (record2.type === "turn_context" && verified) {
6069
6073
  model = nativeCodexModel(payload.model) ?? model;
6070
6074
  }
6071
6075
  }
@@ -6075,6 +6079,237 @@ async function readCodexRolloutModel(input, rolloutPath, sameDirectory) {
6075
6079
  return model;
6076
6080
  }
6077
6081
 
6082
+ // ../../packages/ycodium-jsonl-stream/src/sessionTranscript.ts
6083
+ import * as NodeCrypto5 from "node:crypto";
6084
+ var SESSION_IMPORT_ACTIVITY_TEXT_LIMIT = 32e3;
6085
+ var record = (value) => value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
6086
+ var nonempty = (value) => typeof value === "string" && value.trim().length > 0 ? value : void 0;
6087
+ function isoTranscriptTimestamp(value) {
6088
+ return typeof value === "number" && Math.abs(value) <= 864e13 ? new Date(value).toISOString() : void 0;
6089
+ }
6090
+ function fallbackId(value) {
6091
+ let text;
6092
+ try {
6093
+ text = JSON.stringify(value) ?? "";
6094
+ } catch {
6095
+ text = "";
6096
+ }
6097
+ return `record:${NodeCrypto5.createHash("sha256").update(text).digest("hex").slice(0, 20)}`;
6098
+ }
6099
+ function readableContent(value, textTypes) {
6100
+ if (typeof value === "string") return value;
6101
+ if (!Array.isArray(value)) return "";
6102
+ return value.flatMap((entry) => {
6103
+ if (typeof entry === "string") return [entry];
6104
+ const block = record(entry);
6105
+ return block && textTypes.includes(String(block.type)) && typeof block.text === "string" ? [block.text] : [];
6106
+ }).join("\n\n");
6107
+ }
6108
+ function toolInput(value) {
6109
+ if (typeof value === "string") return value;
6110
+ const input = record(value);
6111
+ if (input && Object.keys(input).length === 1 && typeof input.command === "string")
6112
+ return input.command;
6113
+ if (input && Object.keys(input).length === 1 && typeof input.cmd === "string") return input.cmd;
6114
+ if (value === void 0 || value === null) return void 0;
6115
+ try {
6116
+ return JSON.stringify(value, null, 2);
6117
+ } catch {
6118
+ return void 0;
6119
+ }
6120
+ }
6121
+ function bounded(value, tail = false) {
6122
+ if (value.length <= SESSION_IMPORT_ACTIVITY_TEXT_LIMIT) return { text: value, truncated: false };
6123
+ const offset = tail ? value.length - SESSION_IMPORT_ACTIVITY_TEXT_LIMIT : SESSION_IMPORT_ACTIVITY_TEXT_LIMIT;
6124
+ const character = value.charCodeAt(offset);
6125
+ const previous = value.charCodeAt(offset - 1);
6126
+ const splitPair = character >= 56320 && character <= 57343 && previous >= 55296 && previous <= 56319;
6127
+ return {
6128
+ text: tail ? value.slice(offset + (splitPair ? 1 : 0)) : value.slice(0, offset - (splitPair ? 1 : 0)),
6129
+ truncated: true
6130
+ };
6131
+ }
6132
+ function inputPayload(input) {
6133
+ if (input === void 0) return {};
6134
+ const result = bounded(input);
6135
+ return { input: result.text, ...result.truncated ? { inputTruncated: true } : {} };
6136
+ }
6137
+ function outputPayload(output) {
6138
+ if (output === void 0) return {};
6139
+ const result = bounded(output, true);
6140
+ return { output: result.text, ...result.truncated ? { outputTruncated: true } : {} };
6141
+ }
6142
+ function reasoning(identity, text, streamKind) {
6143
+ const result = bounded(text);
6144
+ return {
6145
+ ...identity,
6146
+ kind: "reasoning",
6147
+ tone: "info",
6148
+ summary: "Reasoning",
6149
+ payload: {
6150
+ text: result.text,
6151
+ streamKind,
6152
+ chars: result.text.length,
6153
+ streaming: false,
6154
+ ...result.truncated ? { truncated: true } : {}
6155
+ }
6156
+ };
6157
+ }
6158
+
6159
+ // src/sessionTranscript.ts
6160
+ var nativeText = (value) => readableContent(value, ["text", "input_text", "output_text", "summary_text", "reasoning_text"]);
6161
+ function nativeModel(value) {
6162
+ const model = nonempty(value);
6163
+ return model?.trim() === "<synthetic>" ? void 0 : model;
6164
+ }
6165
+ function codexStatus(item) {
6166
+ if (item.status === "failed" || item.error != null) return "failed";
6167
+ if (item.status === "completed" || item.status === "done") return "completed";
6168
+ if (item.status === "declined") return "declined";
6169
+ if (item.status === "inProgress" || item.status === "in_progress" || item.status === "running")
6170
+ return "inProgress";
6171
+ if (typeof item.exitCode === "number" && Number.isInteger(item.exitCode))
6172
+ return item.exitCode === 0 ? "completed" : "failed";
6173
+ return void 0;
6174
+ }
6175
+ function codexOutput(item) {
6176
+ if (typeof item.aggregatedOutput === "string") return item.aggregatedOutput;
6177
+ if (typeof item.output === "string") return item.output;
6178
+ const result = record(item.result);
6179
+ if (typeof item.result === "string") return item.result;
6180
+ if (result?.content !== void 0) return nativeText(result.content);
6181
+ if (item.contentItems !== void 0) return nativeText(item.contentItems);
6182
+ const error = record(item.error);
6183
+ return typeof error?.message === "string" ? error.message : void 0;
6184
+ }
6185
+ function readCodexTranscript(turns) {
6186
+ const messages = [];
6187
+ const activities = [];
6188
+ const items = /* @__PURE__ */ new Map();
6189
+ for (const turn of turns) {
6190
+ for (const raw of turn.items) {
6191
+ const item = record(raw);
6192
+ if (!item) continue;
6193
+ const sourceId = `codex:${turn.id ?? "unassigned"}:${nonempty(item.id) ?? fallbackId(raw)}`;
6194
+ const previous = items.get(sourceId);
6195
+ items.set(sourceId, {
6196
+ item: { ...previous?.item, ...item },
6197
+ turn: previous ? {
6198
+ ...previous.turn,
6199
+ ...turn,
6200
+ startedAt: turn.startedAt ?? previous.turn.startedAt,
6201
+ model: turn.model ?? previous.turn.model
6202
+ } : turn,
6203
+ sourceId
6204
+ });
6205
+ }
6206
+ }
6207
+ let sourceOrder = 0;
6208
+ for (const { item, turn, sourceId } of items.values()) {
6209
+ const milliseconds = typeof turn.startedAt === "number" ? turn.startedAt * 1e3 : NaN;
6210
+ const createdAt = isoTranscriptTimestamp(milliseconds) ?? "";
6211
+ const model = nativeModel(item.model) ?? nativeModel(turn.model);
6212
+ const nativeTurnId = nonempty(turn.id);
6213
+ const identity = {
6214
+ sourceId,
6215
+ sourceOrder,
6216
+ createdAt,
6217
+ ...nativeTurnId !== void 0 ? { nativeTurnId } : {},
6218
+ ...model !== void 0 ? { model } : {}
6219
+ };
6220
+ sourceOrder += 4;
6221
+ if (item.type === "userMessage" || item.type === "agentMessage") {
6222
+ const text = item.type === "userMessage" ? nativeText(item.content) : typeof item.text === "string" ? item.text : "";
6223
+ if (text.trim().length > 0)
6224
+ messages.push({
6225
+ ...identity,
6226
+ role: item.type === "userMessage" ? "user" : "assistant",
6227
+ text
6228
+ });
6229
+ continue;
6230
+ }
6231
+ if (item.type === "reasoning") {
6232
+ const summary2 = nativeText(item.summary);
6233
+ const text = nativeText(item.content) || (typeof item.text === "string" ? item.text : "");
6234
+ if (summary2.trim().length > 0)
6235
+ activities.push(
6236
+ reasoning(
6237
+ { ...identity, sourceId: `${sourceId}:summary` },
6238
+ summary2,
6239
+ "reasoning_summary_text"
6240
+ )
6241
+ );
6242
+ if (text.trim().length > 0 && text !== summary2)
6243
+ activities.push(
6244
+ reasoning(
6245
+ {
6246
+ ...identity,
6247
+ sourceId: `${sourceId}:text`,
6248
+ sourceOrder: summary2 ? identity.sourceOrder + 1 : identity.sourceOrder
6249
+ },
6250
+ text,
6251
+ "reasoning_text"
6252
+ )
6253
+ );
6254
+ continue;
6255
+ }
6256
+ const itemTypes = {
6257
+ commandExecution: "command_execution",
6258
+ fileChange: "file_change",
6259
+ mcpToolCall: "mcp_tool_call",
6260
+ dynamicToolCall: "dynamic_tool_call",
6261
+ collabAgentToolCall: "dynamic_tool_call",
6262
+ webSearch: "web_search",
6263
+ imageView: "image_view"
6264
+ };
6265
+ const itemType = itemTypes[String(item.type)];
6266
+ const toolCallId = nonempty(item.id);
6267
+ if (!itemType || !toolCallId) continue;
6268
+ const input = toolInput(item.command ?? item.arguments ?? item.input ?? item.changes);
6269
+ const output = codexOutput(item);
6270
+ const status = codexStatus(item);
6271
+ const summary = nonempty(item.tool) ?? nonempty(item.name) ?? (itemType === "command_execution" ? "Command" : itemType === "file_change" ? "File changes" : "Tool");
6272
+ const payload = {
6273
+ toolCallId,
6274
+ itemType,
6275
+ startedAt: createdAt,
6276
+ ...inputPayload(input),
6277
+ ...status === "inProgress" ? { status } : {}
6278
+ };
6279
+ activities.push({
6280
+ ...identity,
6281
+ kind: "tool.started",
6282
+ tone: "tool",
6283
+ summary,
6284
+ payload: {
6285
+ ...payload,
6286
+ ...status === void 0 ? outputPayload(output) : {}
6287
+ }
6288
+ });
6289
+ if (status && status !== "inProgress")
6290
+ activities.push({
6291
+ ...identity,
6292
+ sourceId: `${sourceId}:completed`,
6293
+ sourceOrder: identity.sourceOrder + 1,
6294
+ kind: "tool.completed",
6295
+ tone: status === "failed" ? "error" : "tool",
6296
+ summary,
6297
+ payload: {
6298
+ ...payload,
6299
+ status,
6300
+ ...outputPayload(output),
6301
+ ...typeof item.exitCode === "number" && Number.isInteger(item.exitCode) ? { exitCode: item.exitCode } : {}
6302
+ }
6303
+ });
6304
+ }
6305
+ return {
6306
+ messages,
6307
+ activities,
6308
+ availableMessages: messages.length,
6309
+ availableActivities: activities.length
6310
+ };
6311
+ }
6312
+
6078
6313
  // src/sessions.ts
6079
6314
  var rolloutSource = { createReadStream: (path) => NodeFS5.createReadStream(path) };
6080
6315
  function itemText(item) {
@@ -6096,13 +6331,15 @@ async function scanCodexSessions(input) {
6096
6331
  openElsewhere: false
6097
6332
  }));
6098
6333
  }
6099
- async function readCodexSession(input) {
6334
+ async function readNativeCodexSession(input) {
6335
+ input.signal?.throwIfAborted();
6100
6336
  const response = await input.client.request("thread/read", {
6101
6337
  threadId: input.threadId,
6102
6338
  includeTurns: true
6103
6339
  });
6104
- const record = isRecord2(response) ? response : null;
6105
- const thread = record && isRecord2(record.thread) ? record.thread : null;
6340
+ input.signal?.throwIfAborted();
6341
+ const record2 = isRecord2(response) ? response : null;
6342
+ const thread = record2 && isRecord2(record2.thread) ? record2.thread : null;
6106
6343
  const path = input.caseInsensitive ? NodePath8.win32 : NodePath8;
6107
6344
  const sameDirectory = (left, right) => isWithinDirectory(path.resolve(left), path.resolve(right), input.caseInsensitive) && isWithinDirectory(path.resolve(right), path.resolve(left), input.caseInsensitive);
6108
6345
  if (!isRecord2(thread) || thread.id !== input.threadId || typeof thread.cwd !== "string" || !path.isAbsolute(thread.cwd) || !path.isAbsolute(input.cwd) || !sameDirectory(thread.cwd, input.cwd)) {
@@ -6110,7 +6347,7 @@ async function readCodexSession(input) {
6110
6347
  }
6111
6348
  const model = nativeCodexModel(thread.model) ?? await readCodexRolloutModel(
6112
6349
  {
6113
- fs: rolloutSource,
6350
+ fs: input.signal ? { createReadStream: (path2) => NodeFS5.createReadStream(path2, { signal: input.signal }) } : rolloutSource,
6114
6351
  threadId: input.threadId,
6115
6352
  cwd: input.cwd,
6116
6353
  homePath: input.homePath,
@@ -6120,8 +6357,13 @@ async function readCodexSession(input) {
6120
6357
  thread.path,
6121
6358
  sameDirectory
6122
6359
  );
6360
+ input.signal?.throwIfAborted();
6361
+ return { title: asString(thread.name), model, turns: readThreadTurns(response) };
6362
+ }
6363
+ async function readCodexSession(input) {
6364
+ const { model, turns } = await readNativeCodexSession(input);
6123
6365
  const messages = [];
6124
- for (const turn of readThreadTurns(response)) {
6366
+ for (const turn of turns) {
6125
6367
  for (const item of turn.items) {
6126
6368
  const mapped = itemText(item);
6127
6369
  if (mapped) {
@@ -6139,6 +6381,18 @@ async function readCodexSession(input) {
6139
6381
  model
6140
6382
  };
6141
6383
  }
6384
+ async function readCodexSessionImport(input) {
6385
+ const { title, model, turns } = await readNativeCodexSession(input);
6386
+ return {
6387
+ ...readCodexTranscript(turns),
6388
+ resumeCursor: { threadId: input.threadId },
6389
+ title,
6390
+ model
6391
+ };
6392
+ }
6393
+
6394
+ // src/codexInstance.ts
6395
+ import { withProcessOperation } from "@ycodium-ai/plugin-api/process-operation";
6142
6396
 
6143
6397
  // src/mcpOAuth.ts
6144
6398
  function codexMcpOAuthLaunchConfig(name, transport) {
@@ -7461,8 +7715,8 @@ async function readAppendedJsonl(filePath, resumeFrom, openParser) {
7461
7715
  for (; ; ) {
7462
7716
  const newlineIndex = buffer.indexOf(NEWLINE, lineStart);
7463
7717
  if (newlineIndex === -1) break;
7464
- const record = parser.line(toLineString(buffer.subarray(lineStart, newlineIndex)));
7465
- if (record !== null) records.push(record);
7718
+ const record2 = parser.line(toLineString(buffer.subarray(lineStart, newlineIndex)));
7719
+ if (record2 !== null) records.push(record2);
7466
7720
  lineStart = newlineIndex + 1;
7467
7721
  }
7468
7722
  resumeOffset += lineStart;
@@ -7474,8 +7728,8 @@ async function readAppendedJsonl(filePath, resumeFrom, openParser) {
7474
7728
  if (pendingChunks.length > 0) {
7475
7729
  const pending2 = pendingChunks.length === 1 ? pendingChunks[0] : Buffer.concat(pendingChunks);
7476
7730
  if (pending2.length > 0) {
7477
- const record = parser.tail(toLineString(pending2));
7478
- if (record !== null) tailRecords.push(record);
7731
+ const record2 = parser.tail(toLineString(pending2));
7732
+ if (record2 !== null) tailRecords.push(record2);
7479
7733
  }
7480
7734
  }
7481
7735
  return {
@@ -7564,15 +7818,15 @@ var CODEX_SCAN_CACHE_VERSION = 1;
7564
7818
  var encodeScanCache = (cache) => {
7565
7819
  const models = createStringTable();
7566
7820
  const sessions = createStringTable();
7567
- const serializeRecord = (record) => [
7568
- record.timestampMs,
7569
- models.intern(record.model),
7570
- sessions.intern(record.sessionId),
7571
- record.totals.uncachedInputTokens,
7572
- record.totals.cachedInputTokens,
7573
- record.totals.cacheCreationTokens,
7574
- record.totals.outputTokens,
7575
- record.totals.reasoningTokens
7821
+ const serializeRecord = (record2) => [
7822
+ record2.timestampMs,
7823
+ models.intern(record2.model),
7824
+ sessions.intern(record2.sessionId),
7825
+ record2.totals.uncachedInputTokens,
7826
+ record2.totals.cachedInputTokens,
7827
+ record2.totals.cacheCreationTokens,
7828
+ record2.totals.outputTokens,
7829
+ record2.totals.reasoningTokens
7576
7830
  ];
7577
7831
  const files = {};
7578
7832
  for (const [path, entry] of cache) {
@@ -7610,9 +7864,9 @@ var decodeScanCache = (document) => {
7610
7864
  const records = [];
7611
7865
  for (const row of rows) {
7612
7866
  if (!isArray(row) || row.length < 8) return null;
7613
- const [timestampMs, modelIdx, sessionIdx, uncached, cached, creation, output, reasoning] = row;
7867
+ const [timestampMs, modelIdx, sessionIdx, uncached, cached, creation, output, reasoning2] = row;
7614
7868
  const model = typeof modelIdx === "number" ? models[modelIdx] : void 0;
7615
- if (typeof timestampMs !== "number" || !Number.isFinite(timestampMs) || model === void 0 || !Number.isFinite(uncached) || !Number.isFinite(cached) || !Number.isFinite(creation) || !Number.isFinite(output) || !Number.isFinite(reasoning)) {
7869
+ if (typeof timestampMs !== "number" || !Number.isFinite(timestampMs) || model === void 0 || !Number.isFinite(uncached) || !Number.isFinite(cached) || !Number.isFinite(creation) || !Number.isFinite(output) || !Number.isFinite(reasoning2)) {
7616
7870
  return null;
7617
7871
  }
7618
7872
  records.push({
@@ -7624,7 +7878,7 @@ var decodeScanCache = (document) => {
7624
7878
  cachedInputTokens: cached,
7625
7879
  cacheCreationTokens: creation,
7626
7880
  outputTokens: output,
7627
- reasoningTokens: reasoning
7881
+ reasoningTokens: reasoning2
7628
7882
  }
7629
7883
  });
7630
7884
  }
@@ -7686,29 +7940,29 @@ var parseCodexLine = (line, state) => {
7686
7940
  } catch {
7687
7941
  return null;
7688
7942
  }
7689
- const record = asRecord4(parsed);
7690
- const payload = asRecord4(record?.["payload"]);
7691
- if (record === null || payload === null) return null;
7692
- if (record["type"] === "session_meta") {
7943
+ const record2 = asRecord4(parsed);
7944
+ const payload = asRecord4(record2?.["payload"]);
7945
+ if (record2 === null || payload === null) return null;
7946
+ if (record2["type"] === "session_meta") {
7693
7947
  if (state.sawSessionMeta) return null;
7694
7948
  state.sawSessionMeta = true;
7695
7949
  const id = payload["id"] ?? payload["session_id"];
7696
7950
  if (typeof id === "string") state.sessionId = id;
7697
- const metaTimestampMs = parseTimestampMs(record["timestamp"]);
7951
+ const metaTimestampMs = parseTimestampMs(record2["timestamp"]);
7698
7952
  if (metaTimestampMs !== null && isForkedSessionMeta(payload)) {
7699
7953
  state.suppressingForkCopies = true;
7700
7954
  state.forkCopyAnchorMs = metaTimestampMs;
7701
7955
  }
7702
7956
  return null;
7703
7957
  }
7704
- if (record["type"] === "turn_context") {
7958
+ if (record2["type"] === "turn_context") {
7705
7959
  if (typeof payload["model"] === "string") state.model = payload["model"];
7706
7960
  return null;
7707
7961
  }
7708
7962
  if (payload["type"] !== "token_count") return null;
7709
7963
  const last = asRecord4(asRecord4(payload["info"])?.["last_token_usage"]);
7710
7964
  if (last === null) return null;
7711
- const timestampMs = parseTimestampMs(record["timestamp"]);
7965
+ const timestampMs = parseTimestampMs(record2["timestamp"]);
7712
7966
  if (timestampMs === null) return null;
7713
7967
  if (state.model.length === 0) return null;
7714
7968
  const signature = JSON.stringify(last);
@@ -7812,11 +8066,11 @@ var readFileRecords = async (state, filePath, size, mtimeMs) => {
7812
8066
  state.dirty = true;
7813
8067
  return parsed.tailRecords.length === 0 ? records : [...records, ...parsed.tailRecords];
7814
8068
  };
7815
- var toRecord = (record) => ({
7816
- at: new Date(record.timestampMs).toISOString(),
7817
- model: record.model,
7818
- ...record.sessionId.length === 0 ? {} : { sessionId: record.sessionId },
7819
- totals: record.totals
8069
+ var toRecord = (record2) => ({
8070
+ at: new Date(record2.timestampMs).toISOString(),
8071
+ model: record2.model,
8072
+ ...record2.sessionId.length === 0 ? {} : { sessionId: record2.sessionId },
8073
+ totals: record2.totals
7820
8074
  });
7821
8075
  var readOnce = async (input) => {
7822
8076
  const sinceMs = Date.parse(input.since);
@@ -7860,9 +8114,9 @@ var readOnce = async (input) => {
7860
8114
  continue;
7861
8115
  }
7862
8116
  let inWindow = 0;
7863
- for (const record of fileRecords) {
7864
- if (record.timestampMs < sinceMs || record.timestampMs >= untilMs) continue;
7865
- records.push(toRecord(record));
8117
+ for (const record2 of fileRecords) {
8118
+ if (record2.timestampMs < sinceMs || record2.timestampMs >= untilMs) continue;
8119
+ records.push(toRecord(record2));
7866
8120
  inWindow += 1;
7867
8121
  }
7868
8122
  if (inWindow === 0) skippedFiles += 1;
@@ -7985,10 +8239,6 @@ var createCodexUsage = (input) => {
7985
8239
  };
7986
8240
 
7987
8241
  // src/codexInstance.ts
7988
- function missingBinaryDetail(binaryPath) {
7989
- const relyOnPath = !/[\\/]/.test(binaryPath);
7990
- return `Could not start Codex (${binaryPath}). Check the "Program path" setting of this provider on this machine.` + (relyOnPath ? " The Codex desktop app may not add codex to PATH; enter the full path to the codex executable there." : " Make sure the configured file exists and can be run.");
7991
- }
7992
8242
  var yieldTick = () => new Promise((resolve5) => {
7993
8243
  setImmediate(resolve5);
7994
8244
  });
@@ -8109,6 +8359,32 @@ var createCodexInstance = (config, host, attachments, cache) => {
8109
8359
  await handle.kill("SIGTERM").catch(() => void 0);
8110
8360
  }
8111
8361
  };
8362
+ const withSessionQuery = async (cwd, signal, query) => {
8363
+ if (recipe.binaryPath.length === 0) {
8364
+ throw new Error("Codex program path is not configured");
8365
+ }
8366
+ const layout = layoutFor(recipe);
8367
+ return await withProcessOperation(host, { signal }, async (operation) => {
8368
+ const { handle, args } = await spawnCodexAppServer({
8369
+ host: { ...host, process: { ...host.process, spawn: operation.spawn } },
8370
+ recipe,
8371
+ layout,
8372
+ cwd,
8373
+ signal: operation.signal
8374
+ });
8375
+ trackHandle(handle, [recipe.binaryPath, ...args].join(" "));
8376
+ const rpc = await createCodexRpcClient(handle, {
8377
+ onNotification: () => void 0,
8378
+ onServerRequest: () => void 0,
8379
+ onStderrLine: () => void 0
8380
+ });
8381
+ operation.defer(() => rpc.close());
8382
+ await rpc.request("initialize", CODEX_INITIALIZE_PARAMS);
8383
+ operation.signal.throwIfAborted();
8384
+ await rpc.notify("initialized");
8385
+ return query(rpc, layout, operation.signal);
8386
+ });
8387
+ };
8112
8388
  const trackHandle = (handle, command, threadId) => {
8113
8389
  live.set(handle.pid, { command, ...threadId === void 0 ? {} : { threadId } });
8114
8390
  void handle.exited.finally(() => live.delete(handle.pid));
@@ -8347,32 +8623,37 @@ var createCodexInstance = (config, host, attachments, cache) => {
8347
8623
  inheritedEnvironment: process.env
8348
8624
  }),
8349
8625
  sessions: {
8626
+ readImport: async ({ nativeSessionId, cwd, signal }) => {
8627
+ if (cwd === void 0)
8628
+ throw new Error("Codex session import requires a working directory.");
8629
+ return withSessionQuery(
8630
+ cwd,
8631
+ signal,
8632
+ (rpc, layout, signal2) => readCodexSessionImport({
8633
+ client: rpc,
8634
+ threadId: nativeSessionId,
8635
+ cwd,
8636
+ homePath: accountHomeFromLayout(layout),
8637
+ caseInsensitive: NodeProcess2.platform === "win32",
8638
+ signal: signal2
8639
+ })
8640
+ );
8641
+ },
8350
8642
  openHistory: async (input) => openCodexHistory({ ...input, homePath: layoutFor(recipe).sharedHomePath }),
8351
8643
  scan: async (input) => {
8352
- if (recipe.binaryPath.length === 0) {
8353
- throw new Error("Codex program path is not configured");
8354
- }
8355
- const layout = layoutFor(recipe);
8356
- const cwd = input.directory ?? host.workspacePath(input.projectId);
8357
- const { handle, args } = await spawnCodexAppServer({ host, recipe, layout, cwd });
8358
- trackHandle(handle, [recipe.binaryPath, ...args].join(" "));
8359
- const rpc = await createCodexRpcClient(handle, {
8360
- onNotification: () => void 0,
8361
- onServerRequest: () => void 0,
8362
- onStderrLine: () => void 0
8363
- });
8364
- try {
8365
- await rpc.request("initialize", CODEX_INITIALIZE_PARAMS);
8366
- await rpc.notify("initialized");
8367
- const candidates = await scanCodexSessions({
8368
- client: rpc,
8369
- directory: input.directory ?? host.workspacePath(input.projectId),
8644
+ const directory = input.directory ?? host.workspacePath(input.projectId);
8645
+ return withSessionQuery(directory, input.signal, async (rpc, _layout, signal) => ({
8646
+ candidates: await scanCodexSessions({
8647
+ client: {
8648
+ request: async (method, params) => {
8649
+ signal.throwIfAborted();
8650
+ return rpc.request(method, params);
8651
+ }
8652
+ },
8653
+ directory,
8370
8654
  caseInsensitive: NodeProcess2.platform === "win32"
8371
- });
8372
- return { candidates };
8373
- } finally {
8374
- await rpc.close().catch(() => void 0);
8375
- }
8655
+ })
8656
+ }));
8376
8657
  },
8377
8658
  read: async (input) => {
8378
8659
  if (recipe.binaryPath.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-codex",
3
- "version": "0.2.5448",
3
+ "version": "0.2.5542",
4
4
  "description": "Codex executor: Codex CLI over the app-server JSON-RPC protocol.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -29,12 +29,12 @@
29
29
  "tailwindcss": "^4.0.0",
30
30
  "typescript": "~6.0.3",
31
31
  "vite-plus": "0.2.2",
32
- "@ycodium-ai/plugin-api": "0.2.5448",
32
+ "@ycodium-ai/plugin-api": "0.2.5542",
33
33
  "ycodium-credential-account": "0.0.0",
34
34
  "ycodium-duration-format": "0.0.0",
35
- "ycodium-executor-testing": "0.0.0",
36
35
  "ycodium-instance-config": "0.0.0",
37
36
  "ycodium-react-test-harness": "0.0.0",
37
+ "ycodium-executor-testing": "0.0.0",
38
38
  "ycodium-jsonl-stream": "0.0.0",
39
39
  "ycodium-text-generation": "0.0.0",
40
40
  "ycodium-workspace-path": "0.0.0"