@ycodium-ai/agent-codex 0.2.2972 → 0.2.2974

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 +150 -5
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -2998,6 +2998,150 @@ function mapServerRequestToEvents(input) {
2998
2998
  ];
2999
2999
  }
3000
3000
 
3001
+ // src/openCommands.ts
3002
+ var WINDOWS_POWERSHELL_PREFIX = "try { [Console]::OutputEncoding=[System.Text.Encoding]::UTF8 } catch {}\n";
3003
+ var POWERSHELL_EXECUTABLES = /* @__PURE__ */ new Set(["powershell.exe", "pwsh.exe", "powershell", "pwsh"]);
3004
+ function splitPosixCommand(display) {
3005
+ const argv = [];
3006
+ let current = "";
3007
+ let inWord = false;
3008
+ let index = 0;
3009
+ while (index < display.length) {
3010
+ const char = display[index] ?? "";
3011
+ if (char === "'") {
3012
+ const end = display.indexOf("'", index + 1);
3013
+ if (end === -1) return null;
3014
+ current += display.slice(index + 1, end);
3015
+ inWord = true;
3016
+ index = end + 1;
3017
+ continue;
3018
+ }
3019
+ if (char === '"') {
3020
+ index += 1;
3021
+ let closed = false;
3022
+ while (index < display.length) {
3023
+ const inner = display[index] ?? "";
3024
+ if (inner === '"') {
3025
+ closed = true;
3026
+ index += 1;
3027
+ break;
3028
+ }
3029
+ const next = display[index + 1];
3030
+ if (inner === "\\" && next !== void 0 && '$`"\\\n'.includes(next)) {
3031
+ current += next;
3032
+ index += 2;
3033
+ continue;
3034
+ }
3035
+ current += inner;
3036
+ index += 1;
3037
+ }
3038
+ if (!closed) return null;
3039
+ inWord = true;
3040
+ continue;
3041
+ }
3042
+ if (char === "\\") {
3043
+ const next = display[index + 1];
3044
+ if (next === void 0) return null;
3045
+ current += next;
3046
+ inWord = true;
3047
+ index += 2;
3048
+ continue;
3049
+ }
3050
+ if (char === " " || char === " " || char === "\n") {
3051
+ if (inWord) argv.push(current);
3052
+ current = "";
3053
+ inWord = false;
3054
+ index += 1;
3055
+ continue;
3056
+ }
3057
+ current += char;
3058
+ inWord = true;
3059
+ index += 1;
3060
+ }
3061
+ if (inWord) argv.push(current);
3062
+ return argv;
3063
+ }
3064
+ var sameArgv = (left, right) => left.length === right.length && left.every((arg, index) => arg === right[index]);
3065
+ var SHELL_COMMAND_FLAGS = /* @__PURE__ */ new Set(["-lc", "-c"]);
3066
+ var posixBasename = (path) => path.slice(path.lastIndexOf("/") + 1);
3067
+ function posixCommandMatches(expected, argv) {
3068
+ if (sameArgv(argv, expected)) return true;
3069
+ const [shell, flag, script] = expected;
3070
+ if (expected.length !== 3 || shell === void 0 || script === void 0) return false;
3071
+ if (flag === void 0 || !SHELL_COMMAND_FLAGS.has(flag)) return false;
3072
+ if (argv.length === 3 && argv[0] === shell && SHELL_COMMAND_FLAGS.has(argv[1] ?? "") && argv[2] === script) {
3073
+ return true;
3074
+ }
3075
+ const words = splitPosixCommand(script);
3076
+ if (words === null || words.length === 0) return false;
3077
+ if (sameArgv(argv, words)) return true;
3078
+ return argv.length === words.length + 1 && posixBasename(argv[1] ?? "") === posixBasename(words[0] ?? "") && sameArgv(argv.slice(2), words.slice(1));
3079
+ }
3080
+ var windowsPath = (path) => path.replaceAll("/", "\\").toLowerCase();
3081
+ function basename(path) {
3082
+ const parts = path.split(/[\\/]/);
3083
+ return (parts[parts.length - 1] ?? "").toLowerCase();
3084
+ }
3085
+ function codexCommandMatcher(display) {
3086
+ const expected = splitPosixCommand(display);
3087
+ if (expected === null || expected.length === 0) return void 0;
3088
+ return (argv, platform2) => {
3089
+ if (platform2 !== "win32") return posixCommandMatches(expected, argv);
3090
+ if (argv.length !== expected.length) return false;
3091
+ const [actualExe, ...actualRest] = argv;
3092
+ const [expectedExe, ...expectedRest] = expected;
3093
+ if (actualExe === void 0 || expectedExe === void 0) return false;
3094
+ if (windowsPath(actualExe) !== windowsPath(expectedExe)) return false;
3095
+ const lastIndex = expectedRest.length - 1;
3096
+ return expectedRest.every((arg, index) => {
3097
+ const actual = actualRest[index];
3098
+ if (actual === arg) return true;
3099
+ return index === lastIndex && index >= 1 && expectedRest[index - 1]?.toLowerCase() === "-command" && POWERSHELL_EXECUTABLES.has(basename(expectedExe)) && actual === WINDOWS_POWERSHELL_PREFIX + arg;
3100
+ });
3101
+ };
3102
+ }
3103
+ function trackOpenCommand(open, method, params) {
3104
+ if (!isRecord3(params)) return;
3105
+ const turnId = turnIdOf(params);
3106
+ if (method === "turn/completed") {
3107
+ for (const [id2, entry] of open) {
3108
+ if (turnId === void 0 || entry.turnId === turnId) open.delete(id2);
3109
+ }
3110
+ return;
3111
+ }
3112
+ const item = params["item"];
3113
+ if (!isRecord3(item) || item["type"] !== "commandExecution") return;
3114
+ const id = item["id"];
3115
+ if (typeof id !== "string") return;
3116
+ if (method === "item/completed") {
3117
+ open.delete(id);
3118
+ return;
3119
+ }
3120
+ if (method !== "item/started") return;
3121
+ const startedAtMs = params["startedAtMs"];
3122
+ const command = item["command"];
3123
+ if (typeof startedAtMs !== "number" || typeof command !== "string") return;
3124
+ open.set(id, { turnId, startedAtMs, command });
3125
+ }
3126
+ function codexSessionProcessMatcher(appServerArgs) {
3127
+ return (argv) => argv.length === appServerArgs.length + 1 && sameArgv(argv.slice(1), appServerArgs);
3128
+ }
3129
+ function openCommandsOf(booked) {
3130
+ if (booked === void 0) return void 0;
3131
+ const activeTurn = booked.runtime.activeTurnId;
3132
+ const commands = [...booked.runtime.openCommands].flatMap(([toolCallId, entry]) => {
3133
+ if (activeTurn !== void 0 && entry.turnId !== activeTurn) return [];
3134
+ const matches = codexCommandMatcher(entry.command);
3135
+ return matches === void 0 ? [] : [{ toolCallId, startedAtMs: entry.startedAtMs, matches }];
3136
+ });
3137
+ if (commands.length === 0) return void 0;
3138
+ return {
3139
+ rootPid: booked.handle.pid,
3140
+ sessionProcess: codexSessionProcessMatcher(booked.runtime.appServerArgs),
3141
+ commands
3142
+ };
3143
+ }
3144
+
3001
3145
  // src/sessionRuntime.ts
3002
3146
  var COLLAB_META_LOOKUP_TIMEOUT_MS = 5e3;
3003
3147
  function metaValue(value) {
@@ -3057,6 +3201,7 @@ var CodexSessionRuntime = class {
3057
3201
  collabChildren = /* @__PURE__ */ new Map();
3058
3202
  collabChildMeta = /* @__PURE__ */ new Map();
3059
3203
  liveForeignTurns = /* @__PURE__ */ new Map();
3204
+ openCommands = /* @__PURE__ */ new Map();
3060
3205
  collabReceiverTurns = /* @__PURE__ */ new Map();
3061
3206
  memoryThreadIds = /* @__PURE__ */ new Set();
3062
3207
  /** 这个会话见过的主额度快照(按字段合并),额度用尽停轮时点名窗口用。 */
@@ -3217,6 +3362,7 @@ var CodexSessionRuntime = class {
3217
3362
  });
3218
3363
  return;
3219
3364
  }
3365
+ trackOpenCommand(this.openCommands, method, params);
3220
3366
  if (method === "account/rateLimits/updated" && isRecord3(params)) {
3221
3367
  this.rateLimits = mergeCodexRateLimits(this.rateLimits, params["rateLimits"]);
3222
3368
  }
@@ -3230,7 +3376,7 @@ var CodexSessionRuntime = class {
3230
3376
  this.emit(event);
3231
3377
  }
3232
3378
  if (method === "turn/started") {
3233
- const turnId = isRecord3(params) ? asString(params["turnId"]) ?? (isRecord3(params["turn"]) ? asString(params["turn"]["id"]) : null) : null;
3379
+ const turnId = turnIdOf(params);
3234
3380
  if (turnId) this.activeTurnId = turnId;
3235
3381
  }
3236
3382
  if (method === "turn/completed") {
@@ -3283,7 +3429,7 @@ var CodexSessionRuntime = class {
3283
3429
  const child = this.collabChildren.get(conversationId);
3284
3430
  if (method === "turn/started") {
3285
3431
  this.reopenCollabChildMeta(conversationId);
3286
- const turnId = isRecord3(params) ? asString(params["turnId"]) ?? (isRecord3(params["turn"]) ? asString(params["turn"]["id"]) : null) : null;
3432
+ const turnId = turnIdOf(params);
3287
3433
  if (turnId) this.liveForeignTurns.set(conversationId, turnId);
3288
3434
  }
3289
3435
  if (method === "turn/completed" || method === "thread/closed") {
@@ -5749,9 +5895,7 @@ var createCodexInstance = (config, host, attachments, cache) => {
5749
5895
  };
5750
5896
  const trackHandle = (handle, command, threadId) => {
5751
5897
  live.set(handle.pid, { command, ...threadId === void 0 ? {} : { threadId } });
5752
- void handle.exited.finally(() => {
5753
- live.delete(handle.pid);
5754
- });
5898
+ void handle.exited.finally(() => live.delete(handle.pid));
5755
5899
  };
5756
5900
  const stopBooked = async (booked) => {
5757
5901
  await booked.runtime.close().catch(() => void 0);
@@ -6081,6 +6225,7 @@ var createCodexInstance = (config, host, attachments, cache) => {
6081
6225
  ...entry.threadId === void 0 ? {} : { threadId: entry.threadId },
6082
6226
  bindingId: host.bindingId
6083
6227
  })),
6228
+ openCommandProcesses: async (threadId) => openCommandsOf(threads.get(threadId)),
6084
6229
  drain: async (signal) => {
6085
6230
  const waiters = [...live.keys()].map((pid) => {
6086
6231
  const booked = [...threads.values()].find((entry) => entry.handle.pid === pid);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-codex",
3
- "version": "0.2.2972",
3
+ "version": "0.2.2974",
4
4
  "description": "Codex executor: Codex CLI over the app-server JSON-RPC protocol.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -29,8 +29,8 @@
29
29
  "tailwindcss": "^4.0.0",
30
30
  "typescript": "~6.0.3",
31
31
  "vite-plus": "0.2.2",
32
- "ycodium-executor-testing": "0.0.0",
33
- "@ycodium-ai/plugin-api": "0.2.2972"
32
+ "@ycodium-ai/plugin-api": "0.2.2974",
33
+ "ycodium-executor-testing": "0.0.0"
34
34
  },
35
35
  "ycodium": {
36
36
  "plugin": "./dist/index.js",