approval-box 0.1.16 → 0.1.19

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.
@@ -18,9 +18,9 @@ var __commonJS = (cb, mod) => function __require2() {
18
18
  throw mod = 0, e;
19
19
  }
20
20
  };
21
- var __export = (target, all) => {
21
+ var __export = (target2, all) => {
22
22
  for (var name in all)
23
- __defProp(target, name, { get: all[name], enumerable: true });
23
+ __defProp(target2, name, { get: all[name], enumerable: true });
24
24
  };
25
25
  var __copyProps = (to, from, except, desc) => {
26
26
  if (from && typeof from === "object" || typeof from === "function") {
@@ -30,12 +30,12 @@ var __copyProps = (to, from, except, desc) => {
30
30
  }
31
31
  return to;
32
32
  };
33
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
33
+ var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
34
  // If the importer is in node compatibility mode or this is not an ESM
35
35
  // file that has been converted to a CommonJS file using a Babel-
36
36
  // compatible transform (i.e. "__esModule" has not been set), then set
37
37
  // "default" to the CommonJS "module.exports" for node compatibility.
38
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
39
39
  mod
40
40
  ));
41
41
 
@@ -83,10 +83,6 @@ function channelRoot(profile) {
83
83
  return path.join(profile.state_root(), "steer-channels");
84
84
  }
85
85
 
86
- // ../../node_modules/aiterm-steer-delivery/dist/codex-hooks.js
87
- import * as fs4 from "node:fs";
88
- import * as path7 from "node:path";
89
-
90
86
  // ../../node_modules/zod/v4/classic/external.js
91
87
  var external_exports = {};
92
88
  __export(external_exports, {
@@ -834,8 +830,8 @@ function defineLazy(object2, key, getter) {
834
830
  function objectClone(obj) {
835
831
  return Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
836
832
  }
837
- function assignProp(target, prop, value) {
838
- Object.defineProperty(target, prop, {
833
+ function assignProp(target2, prop, value) {
834
+ Object.defineProperty(target2, prop, {
839
835
  value,
840
836
  writable: true,
841
837
  enumerable: true,
@@ -849,8 +845,8 @@ function rawShape(def) {
849
845
  function sourceShape(schema) {
850
846
  return rawShape(schema._zod.def) ?? schema._zod.def.shape;
851
847
  }
852
- function deferProp(target, key, getter) {
853
- Object.defineProperty(target, key, {
848
+ function deferProp(target2, key, getter) {
849
+ Object.defineProperty(target2, key, {
854
850
  get() {
855
851
  const value = getter();
856
852
  assignProp(this, key, value);
@@ -860,36 +856,36 @@ function deferProp(target, key, getter) {
860
856
  configurable: true
861
857
  });
862
858
  }
863
- function putProp(target, key, value) {
864
- if (key in target)
865
- assignProp(target, key, value);
859
+ function putProp(target2, key, value) {
860
+ if (key in target2)
861
+ assignProp(target2, key, value);
866
862
  else
867
- target[key] = value;
863
+ target2[key] = value;
868
864
  }
869
- function mirrorShape(target, source, keys, wrap) {
865
+ function mirrorShape(target2, source, keys, wrap) {
870
866
  const raw = sourceShape(source);
871
867
  for (const key of keys) {
872
868
  const desc = Object.getOwnPropertyDescriptor(raw, key);
873
869
  if (!desc.enumerable)
874
870
  continue;
875
871
  if (desc.get) {
876
- deferProp(target, key, () => {
872
+ deferProp(target2, key, () => {
877
873
  const value = source._zod.def.shape[key];
878
874
  return wrap ? wrap(value, key) : value;
879
875
  });
880
876
  } else
881
- putProp(target, key, wrap ? wrap(desc.value, key) : desc.value);
877
+ putProp(target2, key, wrap ? wrap(desc.value, key) : desc.value);
882
878
  }
883
879
  }
884
- function mirrorProps(target, source) {
880
+ function mirrorProps(target2, source) {
885
881
  for (const key of Reflect.ownKeys(source)) {
886
882
  const desc = Object.getOwnPropertyDescriptor(source, key);
887
883
  if (!desc.enumerable)
888
884
  continue;
889
885
  if (desc.get)
890
- deferProp(target, key, () => source[key]);
886
+ deferProp(target2, key, () => source[key]);
891
887
  else
892
- putProp(target, key, desc.value);
888
+ putProp(target2, key, desc.value);
893
889
  }
894
890
  }
895
891
  function mergeDefs(...defs) {
@@ -910,8 +906,8 @@ function getElementAtPath(obj, path12) {
910
906
  }
911
907
  function promiseAllObject(promisesObj) {
912
908
  const keys = Object.keys(promisesObj);
913
- const promises = keys.map((key) => promisesObj[key]);
914
- return Promise.all(promises).then((results) => {
909
+ const promises2 = keys.map((key) => promisesObj[key]);
910
+ return Promise.all(promises2).then((results) => {
915
911
  const resolvedObj = {};
916
912
  for (let i = 0; i < keys.length; i++) {
917
913
  resolvedObj[keys[i]] = results[i];
@@ -1068,35 +1064,35 @@ function normalizeParams(_params) {
1068
1064
  return params;
1069
1065
  }
1070
1066
  function createTransparentProxy(getter) {
1071
- let target;
1067
+ let target2;
1072
1068
  return new Proxy({}, {
1073
1069
  get(_, prop, receiver) {
1074
- target ?? (target = getter());
1075
- return Reflect.get(target, prop, receiver);
1070
+ target2 ?? (target2 = getter());
1071
+ return Reflect.get(target2, prop, receiver);
1076
1072
  },
1077
1073
  set(_, prop, value, receiver) {
1078
- target ?? (target = getter());
1079
- return Reflect.set(target, prop, value, receiver);
1074
+ target2 ?? (target2 = getter());
1075
+ return Reflect.set(target2, prop, value, receiver);
1080
1076
  },
1081
1077
  has(_, prop) {
1082
- target ?? (target = getter());
1083
- return Reflect.has(target, prop);
1078
+ target2 ?? (target2 = getter());
1079
+ return Reflect.has(target2, prop);
1084
1080
  },
1085
1081
  deleteProperty(_, prop) {
1086
- target ?? (target = getter());
1087
- return Reflect.deleteProperty(target, prop);
1082
+ target2 ?? (target2 = getter());
1083
+ return Reflect.deleteProperty(target2, prop);
1088
1084
  },
1089
1085
  ownKeys(_) {
1090
- target ?? (target = getter());
1091
- return Reflect.ownKeys(target);
1086
+ target2 ?? (target2 = getter());
1087
+ return Reflect.ownKeys(target2);
1092
1088
  },
1093
1089
  getOwnPropertyDescriptor(_, prop) {
1094
- target ?? (target = getter());
1095
- return Reflect.getOwnPropertyDescriptor(target, prop);
1090
+ target2 ?? (target2 = getter());
1091
+ return Reflect.getOwnPropertyDescriptor(target2, prop);
1096
1092
  },
1097
1093
  defineProperty(_, prop, descriptor) {
1098
- target ?? (target = getter());
1099
- return Reflect.defineProperty(target, prop, descriptor);
1094
+ target2 ?? (target2 = getter());
1095
+ return Reflect.defineProperty(target2, prop, descriptor);
1100
1096
  }
1101
1097
  });
1102
1098
  }
@@ -1567,10 +1563,10 @@ function $constructor(name, initializer3, proto, params) {
1567
1563
  let up = own2;
1568
1564
  while (up && up !== ctorProto)
1569
1565
  up = Object.getPrototypeOf(up);
1570
- const target = up ?? own2;
1571
- if (!initialized.has(target)) {
1572
- initialized.add(target);
1573
- members(target, protoMembers);
1566
+ const target2 = up ?? own2;
1567
+ if (!initialized.has(target2)) {
1568
+ initialized.add(target2);
1569
+ members(target2, protoMembers);
1574
1570
  }
1575
1571
  }
1576
1572
  const proto2 = _.prototype;
@@ -2084,8 +2080,8 @@ function emoji() {
2084
2080
  }
2085
2081
  var ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
2086
2082
  var ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
2087
- var mac = (delimiter) => {
2088
- const escapedDelim = escapeRegex(delimiter ?? ":");
2083
+ var mac = (delimiter2) => {
2084
+ const escapedDelim = escapeRegex(delimiter2 ?? ":");
2089
2085
  return new RegExp(`^(?:[0-9A-F]{2}${escapedDelim}){5}[0-9A-F]{2}$|^(?:[0-9a-f]{2}${escapedDelim}){5}[0-9a-f]{2}$`);
2090
2086
  };
2091
2087
  var cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
@@ -13054,8 +13050,8 @@ function withParser(schema, parser) {
13054
13050
  installCompiledUserMethods(clone2, schema, parser);
13055
13051
  return clone2;
13056
13052
  }
13057
- function installCompiledUserMethods(target, source, parser) {
13058
- const targetAny = target;
13053
+ function installCompiledUserMethods(target2, source, parser) {
13054
+ const targetAny = target2;
13059
13055
  const sourceAny = source;
13060
13056
  if (typeof sourceAny.safeParse === "function") {
13061
13057
  const originalSafeParse = sourceAny.safeParse;
@@ -15650,26 +15646,26 @@ function _stringFormat(Class2, format, fnOrRegex, _params = {}) {
15650
15646
  }
15651
15647
 
15652
15648
  // ../../node_modules/zod/v4/core/to-json-schema.js
15653
- function assignProps(target, ...sources) {
15649
+ function assignProps(target2, ...sources) {
15654
15650
  for (const source of sources) {
15655
15651
  for (const key of Reflect.ownKeys(source)) {
15656
15652
  if (Object.prototype.propertyIsEnumerable.call(source, key)) {
15657
- assignProp(target, key, source[key]);
15653
+ assignProp(target2, key, source[key]);
15658
15654
  }
15659
15655
  }
15660
15656
  }
15661
- return target;
15657
+ return target2;
15662
15658
  }
15663
15659
  function initializeContext(params) {
15664
- let target = params?.target ?? "draft-2020-12";
15665
- if (target === "draft-4")
15666
- target = "draft-04";
15667
- if (target === "draft-7")
15668
- target = "draft-07";
15660
+ let target2 = params?.target ?? "draft-2020-12";
15661
+ if (target2 === "draft-4")
15662
+ target2 = "draft-04";
15663
+ if (target2 === "draft-7")
15664
+ target2 = "draft-07";
15669
15665
  return {
15670
15666
  processors: params.processors ?? {},
15671
15667
  metadataRegistry: params?.metadata ?? globalRegistry,
15672
- target,
15668
+ target: target2,
15673
15669
  unrepresentable: params?.unrepresentable ?? "throw",
15674
15670
  override: params?.override ?? (() => {
15675
15671
  }),
@@ -16172,8 +16168,8 @@ var createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
16172
16168
  return finalize(ctx, schema);
16173
16169
  };
16174
16170
  var createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
16175
- const { libraryOptions, target } = params ?? {};
16176
- const ctx = initializeContext({ ...libraryOptions ?? {}, target, io, processors });
16171
+ const { libraryOptions, target: target2 } = params ?? {};
16172
+ const ctx = initializeContext({ ...libraryOptions ?? {}, target: target2, io, processors });
16177
16173
  processSchema(schema, ctx);
16178
16174
  extractDefs(ctx, schema);
16179
16175
  return finalize(ctx, schema);
@@ -17367,8 +17363,8 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
17367
17363
  catch(params) {
17368
17364
  return _catch2(this, params);
17369
17365
  },
17370
- pipe(target) {
17371
- return pipe(this, target);
17366
+ pipe(target2) {
17367
+ return pipe(this, target2);
17372
17368
  },
17373
17369
  readonly() {
17374
17370
  return readonly(this);
@@ -19997,8 +19993,8 @@ function resolveWindowsCodexShim(candidate) {
19997
19993
  try {
19998
19994
  for (const platformPackage of fs2.readdirSync(packageRoot).filter((name) => name.startsWith("codex-win32-"))) {
19999
19995
  const vendorRoot = path4.join(packageRoot, platformPackage, "vendor");
20000
- for (const target of fs2.readdirSync(vendorRoot)) {
20001
- const executable = path4.join(vendorRoot, target, "bin", "codex.exe");
19996
+ for (const target2 of fs2.readdirSync(vendorRoot)) {
19997
+ const executable = path4.join(vendorRoot, target2, "bin", "codex.exe");
20002
19998
  if (isUsableExecutableFile(executable))
20003
19999
  return executable;
20004
20000
  }
@@ -20319,26 +20315,6 @@ function assertCodexHooksReady(profile, response, command2, file2) {
20319
20315
  throw new CodexDeliveryError("CODEX_HOOK_UNTRUSTED", `${profile.display_name}\u306ECodex hook\u304C\u7121\u52B9\u307E\u305F\u306F\u672A\u627F\u8A8D\u3067\u3059\u3002${profile.setup_command}\u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044`);
20320
20316
  }
20321
20317
  }
20322
- function assertCodexHookParentCurrent(profile, config2, rows, pid = process.pid) {
20323
- try {
20324
- fs3.accessSync(config2.node, fs3.constants.X_OK);
20325
- fs3.accessSync(config2.hook, fs3.constants.R_OK);
20326
- } catch {
20327
- throw new CodexDeliveryError("CODEX_HOOK_RUNTIME_UNAVAILABLE", `Codex\u89AAhook\u306E\u5B9F\u884C\u30D5\u30A1\u30A4\u30EB\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3002${profile.setup_command}\u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044`);
20328
- }
20329
- if (!config2.stale_processes.length)
20330
- return;
20331
- const processes = new Map((rows ?? readRuntimeProcesses()).map((row) => [row.pid, row]));
20332
- const seen = /* @__PURE__ */ new Set();
20333
- let current = processes.get(pid);
20334
- while (current && !seen.has(current.pid)) {
20335
- seen.add(current.pid);
20336
- if (config2.stale_processes.some((stale) => stale.pid === current.pid && stale.started_identity === current.started_identity)) {
20337
- throw new CodexDeliveryError("CODEX_STEER_RESTART_REQUIRED", "\u89AA\u306ECodex\u306Fhook\u306E\u5C0E\u5165\u524D\u304B\u3089\u52D5\u3044\u3066\u3044\u307E\u3059\u3002\u5B8C\u5168\u7D42\u4E86\u3057\u3066\u518D\u8D77\u52D5\u3057\u3066\u304F\u3060\u3055\u3044");
20338
- }
20339
- current = processes.get(current.parent_pid);
20340
- }
20341
- }
20342
20318
 
20343
20319
  // ../../node_modules/aiterm-steer-delivery/dist/codex-receiver.js
20344
20320
  function codexParentFromRequest(clientName, metadata) {
@@ -20357,7 +20333,7 @@ async function withCodexReceiver(profile, parent, action, runtime = {}) {
20357
20333
  throw new CodexDeliveryError("CODEX_RECEIVER_UNAVAILABLE", "Codex\u306E\u5B9F\u884C\u30D5\u30A1\u30A4\u30EB\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093");
20358
20334
  const child = spawn(executable, runtime.args ?? ["app-server", "--listen", "stdio://"], {
20359
20335
  stdio: ["pipe", "pipe", "ignore"],
20360
- env: { ...process.env, CODEX_HOME: parent.codex_home },
20336
+ env: { ...runtime.env ?? process.env, CODEX_HOME: parent.codex_home },
20361
20337
  windowsHide: true
20362
20338
  });
20363
20339
  const pending = /* @__PURE__ */ new Map();
@@ -20429,25 +20405,6 @@ async function withCodexReceiver(profile, parent, action, runtime = {}) {
20429
20405
  reader.close();
20430
20406
  }
20431
20407
  }
20432
- async function verifyCodexParent(profile, parent, runtime) {
20433
- return await withCodexReceiver(profile, parent, async (request) => {
20434
- const response = await request("thread/read", { threadId: parent.thread_id, includeTurns: false });
20435
- if (response?.thread?.id !== parent.thread_id) {
20436
- throw new CodexDeliveryError("CODEX_PARENT_UNAVAILABLE", "\u540C\u3058Codex\u74B0\u5883\u3067\u89AAthread\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093");
20437
- }
20438
- const subagent = response.thread.source?.subAgent;
20439
- if (subagent && typeof subagent === "object" && "thread_spawn" in subagent) {
20440
- throw new CodexDeliveryError("CODEX_PARENT_UNSUPPORTED", "Codex\u306Enative sub-agent\u306F\u5916\u90E8process\u304B\u3089\u306E\u30AD\u30E5\u30FC\u5165\u529B\u3092\u53D7\u3051\u4ED8\u3051\u307E\u305B\u3093");
20441
- }
20442
- await request("thread/queue/list", { threadId: parent.thread_id, limit: 1 });
20443
- const config2 = runtime ? runtime.hook_directory ? readCodexHookConfig(profile, runtime.hook_directory) : null : readCodexHookConfig(profile);
20444
- if (config2?.enabled) {
20445
- assertCodexHookParentCurrent(profile, config2);
20446
- assertCodexHooksReady(profile, await request("hooks/list", { cwds: [response.thread.cwd] }), config2.command, path6.join(parent.codex_home, "hooks.json"));
20447
- }
20448
- return { thread_id: parent.thread_id, cwd: typeof response.thread.cwd === "string" ? response.thread.cwd : null, source: response.thread.source ?? null };
20449
- }, runtime);
20450
- }
20451
20408
  async function submitCodexParentAnswer(profile, parent, deliveryId, text, runtime) {
20452
20409
  const root = runtime ? runtime.hook_directory : codexHookDirectory(profile);
20453
20410
  const hook = root && readCodexHookConfig(profile, root)?.enabled;
@@ -20471,116 +20428,9 @@ async function submitCodexParentAnswer(profile, parent, deliveryId, text, runtim
20471
20428
  }
20472
20429
  }
20473
20430
 
20474
- // ../../node_modules/aiterm-steer-delivery/dist/codex-hooks.js
20475
- async function runCodexResultHook(profile, input2, emit, options = {}) {
20476
- const event = external_exports.object({
20477
- session_id: external_exports.uuid(),
20478
- turn_id: external_exports.string().min(1),
20479
- hook_event_name: external_exports.enum(["PostToolUse", "Stop"])
20480
- }).parse(input2);
20481
- const root = options.directory ?? codexHookDirectory(profile);
20482
- const config2 = readCodexHookConfig(profile, root);
20483
- if (!config2?.enabled) {
20484
- await emit({});
20485
- return;
20486
- }
20487
- const home2 = options.codex_home ?? realCodexHome();
20488
- if (fs4.realpathSync(home2) !== fs4.realpathSync(config2.codex_home)) {
20489
- throw new CodexDeliveryError("CODEX_HOOK_HOME_MISMATCH", "hook\u3068\u914D\u9001\u8A2D\u5B9A\u306ECodex\u74B0\u5883\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093");
20490
- }
20491
- const directory2 = codexInputDirectory(root, home2, event.session_id);
20492
- const pending = path7.join(directory2, "pending");
20493
- if (!fs4.existsSync(pending) || !fs4.readdirSync(pending).length) {
20494
- await emit({});
20495
- return;
20496
- }
20497
- const claims = path7.join(directory2, "claims");
20498
- fs4.mkdirSync(claims, { recursive: true, mode: 448 });
20499
- const taken = [];
20500
- const identity = readRuntimeProcesses().find((row) => row.pid === process.pid);
20501
- if (!identity)
20502
- throw new CodexDeliveryError("CODEX_HOOK_PROCESS_UNAVAILABLE", "\u53D7\u4FE1hook\u306Eprocess\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093");
20503
- try {
20504
- await withCodexReceiver(profile, { thread_id: event.session_id, codex_home: home2 }, async (request) => {
20505
- const entries = [];
20506
- let cursor = null;
20507
- do {
20508
- const page = await request("thread/queue/list", { threadId: event.session_id, cursor, limit: 100 });
20509
- if (!Array.isArray(page?.data) || !(page.nextCursor === null || typeof page.nextCursor === "string")) {
20510
- throw new CodexDeliveryError("CODEX_HOOK_QUEUE_INVALID", "\u516C\u5F0F\u30AD\u30E5\u30FC\u306E\u4E00\u89A7\u5FDC\u7B54\u3092\u8A8D\u8B58\u3067\u304D\u307E\u305B\u3093");
20511
- }
20512
- entries.push(...page.data);
20513
- cursor = page.nextCursor;
20514
- } while (cursor);
20515
- const queued = new Set(entries.map((entry) => entry.clientUserMessageId));
20516
- for (const name of fs4.readdirSync(pending)) {
20517
- const ack = path7.join(directory2, "settled", name);
20518
- if (name.endsWith(".json") && !queued.has(name.slice(0, -5)) && fs4.existsSync(ack)) {
20519
- fs4.rmSync(path7.join(pending, name), { force: true });
20520
- fs4.rmSync(ack, { force: true });
20521
- }
20522
- }
20523
- for (const entry of entries) {
20524
- const id = external_exports.uuid().safeParse(entry.clientUserMessageId);
20525
- if (!id.success)
20526
- continue;
20527
- const source = path7.join(pending, `${id.data}.json`);
20528
- let owner;
20529
- try {
20530
- owner = hookInputSchema.parse(JSON.parse(fs4.readFileSync(source, "utf8")));
20531
- } catch (error62) {
20532
- if (error62.code === "ENOENT")
20533
- continue;
20534
- throw error62;
20535
- }
20536
- const text2 = entry.input?.length === 1 && entry.input[0].type === "text" ? entry.input[0].text : void 0;
20537
- if (owner.delivery_id !== id.data || owner.thread_id !== event.session_id || typeof text2 !== "string" || answerDigest(text2) !== owner.text_sha256) {
20538
- throw new CodexDeliveryError("CODEX_HOOK_INPUT_CHANGED", `${profile.display_name}\u306E\u914D\u9001\u8A18\u9332\u3068\u30AD\u30E5\u30FC\u672C\u6587\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093\u3002\u53D6\u308A\u51FA\u3057\u3066\u3044\u307E\u305B\u3093`);
20539
- }
20540
- const file2 = path7.join(claims, `${id.data}.json`);
20541
- try {
20542
- fs4.linkSync(source, file2);
20543
- fs4.unlinkSync(source);
20544
- } catch (error62) {
20545
- if (["ENOENT", "EEXIST"].includes(error62.code ?? ""))
20546
- continue;
20547
- throw error62;
20548
- }
20549
- fs4.rmSync(path7.join(directory2, "settled", `${id.data}.json`), { force: true });
20550
- const item = { file: file2, delivery_id: id.data, text: text2 };
20551
- taken.push(item);
20552
- writeHookJson(file2, {
20553
- ...owner,
20554
- text: text2,
20555
- state: "deleting",
20556
- turn_id: event.turn_id,
20557
- queued_submission_id: entry.id,
20558
- pid: identity.pid,
20559
- started_identity: identity.started_identity
20560
- });
20561
- const result = await request("thread/queue/delete", { threadId: event.session_id, queuedSubmissionId: entry.id });
20562
- if (typeof result?.deleted !== "boolean")
20563
- throw new CodexDeliveryError("CODEX_HOOK_QUEUE_INVALID", "\u30AD\u30E5\u30FC\u524A\u9664\u306E\u7D50\u679C\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093", true);
20564
- if (!result.deleted) {
20565
- writeHookJson(file2, { ...owner, state: "not_in_queue", turn_id: event.turn_id });
20566
- taken.pop();
20567
- }
20568
- }
20569
- }, options.runtime ?? { executable: await currentCodexDesktopBinary(profile, config2, { directory: root }), timeout_ms: 5e3 });
20570
- const text = taken.map((item) => item.text).join("\n\n");
20571
- await emit(!taken.length ? {} : event.hook_event_name === "Stop" ? { decision: "block", reason: text } : { hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: text } });
20572
- for (const item of taken)
20573
- writeHookJson(item.file, { delivery_id: item.delivery_id, state: "emitted", turn_id: event.turn_id, text: item.text });
20574
- } catch (error62) {
20575
- for (const item of taken)
20576
- writeHookJson(item.file, { delivery_id: item.delivery_id, state: "unknown", turn_id: event.turn_id, text: item.text });
20577
- throw error62;
20578
- }
20579
- }
20580
-
20581
20431
  // ../../node_modules/aiterm-steer-delivery/dist/claude-receiver.js
20582
- import * as fs5 from "node:fs";
20583
- import * as path8 from "node:path";
20432
+ import * as fs4 from "node:fs";
20433
+ import * as path7 from "node:path";
20584
20434
  var requestId = external_exports.string().regex(/^[A-Za-z0-9_-]{1,160}$/);
20585
20435
  var invocationSchema = external_exports.object({
20586
20436
  request_id: requestId,
@@ -20599,12 +20449,12 @@ function processIdentity(pid) {
20599
20449
  return readRuntimeProcesses().find((entry) => entry.pid === pid)?.started_identity;
20600
20450
  }
20601
20451
  function directory(parent) {
20602
- return path8.join(parent.hook_root, parent.request_id);
20452
+ return path7.join(parent.hook_root, parent.request_id);
20603
20453
  }
20604
20454
  function readInvocation(profile, parent) {
20605
20455
  let value;
20606
20456
  try {
20607
- value = invocationSchema.parse(JSON.parse(fs5.readFileSync(path8.join(directory(parent), "request.json"), "utf8")));
20457
+ value = invocationSchema.parse(JSON.parse(fs4.readFileSync(path7.join(directory(parent), "request.json"), "utf8")));
20608
20458
  } catch {
20609
20459
  throw new ClaudeDeliveryError("CLAUDE_PARENT_HOOK_UNAVAILABLE", `\u89AA\u306Ehook\u8A18\u9332\u304C\u3042\u308A\u307E\u305B\u3093\u3002${profile.setup_command}\u3092\u5B9F\u884C\u3057\u3001Claude Code\u306Ehook\u3092\u6709\u52B9\u306B\u3057\u3066\u304F\u3060\u3055\u3044`);
20610
20460
  }
@@ -20614,24 +20464,67 @@ function readInvocation(profile, parent) {
20614
20464
  return value;
20615
20465
  }
20616
20466
  function assertOpen(parent) {
20617
- if (fs5.existsSync(path8.join(directory(parent), "closed.json"))) {
20467
+ if (fs4.existsSync(path7.join(directory(parent), "closed.json"))) {
20618
20468
  throw new ClaudeDeliveryError("CLAUDE_PARENT_SESSION_CLOSED", "\u4F9D\u983C\u5143\u306E\u4F1A\u8A71\u306F\u7D42\u4E86\u3057\u307E\u3057\u305F\u3002\u56DE\u7B54\u3092\u5225\u306E\u4F1A\u8A71\u3078\u9001\u3063\u3066\u3044\u307E\u305B\u3093");
20619
20469
  }
20620
20470
  }
20621
20471
  function prepareClaudeHookRequest(input2, root) {
20622
20472
  const event = external_exports.object({ session_id: external_exports.uuid(), tool_use_id: requestId, agent_id: external_exports.string().optional() }).parse(input2);
20623
- const owner = hookOwnerProcess(readRuntimeProcesses(), process.ppid);
20473
+ const rows = readRuntimeProcesses();
20474
+ const owner = hookOwnerProcess(rows, process.ppid);
20624
20475
  if (!owner)
20625
20476
  throw new ClaudeDeliveryError("CLAUDE_PARENT_PROCESS_UNAVAILABLE", "hook\u3092\u8D77\u52D5\u3057\u305F\u89AAprocess\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093");
20626
- const dir = path8.join(root, event.tool_use_id);
20627
- fs5.mkdirSync(dir, { recursive: true, mode: 448 });
20628
- writeJson0600(path8.join(dir, "request.json"), {
20477
+ const dir = path7.join(root, event.tool_use_id);
20478
+ fs4.mkdirSync(dir, { recursive: true, mode: 448 });
20479
+ writeJson0600(path7.join(dir, "request.json"), {
20629
20480
  request_id: event.tool_use_id,
20630
20481
  session_id: event.session_id,
20631
20482
  agent_id: event.agent_id ?? null,
20632
20483
  parent_pid: owner.pid,
20633
20484
  parent_started_identity: owner.started_identity
20634
20485
  });
20486
+ try {
20487
+ sweepClaudeHookRequests(root, rows);
20488
+ } catch {
20489
+ }
20490
+ }
20491
+ var STALE_REQUEST_MS = 24 * 60 * 60 * 1e3;
20492
+ var REQUEST_FILES = /* @__PURE__ */ new Set(["request.json", "delivery.json", "answer.json", "hook.json", "sending.json", "emitted.json", "failed.json", "closed.json"]);
20493
+ function sweepClaudeHookRequests(root, rows, now = Date.now()) {
20494
+ let entries;
20495
+ try {
20496
+ entries = fs4.readdirSync(root, { withFileTypes: true });
20497
+ } catch {
20498
+ return 0;
20499
+ }
20500
+ let removed = 0;
20501
+ for (const entry of entries) {
20502
+ if (!entry.isDirectory())
20503
+ continue;
20504
+ const dir = path7.join(root, entry.name);
20505
+ try {
20506
+ if (now - fs4.statSync(dir).mtimeMs < STALE_REQUEST_MS)
20507
+ continue;
20508
+ const names = fs4.readdirSync(dir);
20509
+ if (!names.every((name) => REQUEST_FILES.has(name) || name.endsWith(".tmp")))
20510
+ continue;
20511
+ if (names.some((name) => now - fs4.statSync(path7.join(dir, name)).mtimeMs < STALE_REQUEST_MS))
20512
+ continue;
20513
+ if (names.includes("delivery.json") && !names.includes("emitted.json")) {
20514
+ let invocation;
20515
+ try {
20516
+ invocation = invocationSchema.parse(JSON.parse(fs4.readFileSync(path7.join(dir, "request.json"), "utf8")));
20517
+ } catch {
20518
+ }
20519
+ if (invocation && rows.find((row) => row.pid === invocation.parent_pid)?.started_identity === invocation.parent_started_identity)
20520
+ continue;
20521
+ }
20522
+ fs4.rmSync(dir, { recursive: true, force: true });
20523
+ removed += 1;
20524
+ } catch {
20525
+ }
20526
+ }
20527
+ return removed;
20635
20528
  }
20636
20529
  function claudeParentFromRequest(profile, clientName, metadata, root) {
20637
20530
  if (clientName !== "claude-code")
@@ -20641,7 +20534,7 @@ function claudeParentFromRequest(profile, clientName, metadata, root) {
20641
20534
  throw new ClaudeDeliveryError("CLAUDE_PARENT_ID_UNAVAILABLE", "MCP\u8981\u6C42\u306BtoolUseId\u304C\u3042\u308A\u307E\u305B\u3093\u3002\u5BFE\u5FDC\u3059\u308BClaude Code\u3078\u66F4\u65B0\u3057\u3066\u304F\u3060\u3055\u3044");
20642
20535
  let invocation;
20643
20536
  try {
20644
- invocation = invocationSchema.parse(JSON.parse(fs5.readFileSync(path8.join(root, parsed.data, "request.json"), "utf8")));
20537
+ invocation = invocationSchema.parse(JSON.parse(fs4.readFileSync(path7.join(root, parsed.data, "request.json"), "utf8")));
20645
20538
  } catch {
20646
20539
  throw new ClaudeDeliveryError("CLAUDE_PARENT_HOOK_UNAVAILABLE", `\u89AA\u306EPreToolUse hook\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093\u3002${profile.setup_command}\u3092\u5B9F\u884C\u3057\u3001hook\u3092\u6709\u52B9\u306B\u3057\u3066\u304F\u3060\u3055\u3044`);
20647
20540
  }
@@ -20657,18 +20550,29 @@ function verifyClaudeParent(profile, parent) {
20657
20550
  }
20658
20551
  function closeClaudeParentSession(input2, root) {
20659
20552
  const { session_id } = external_exports.object({ session_id: external_exports.uuid() }).parse(input2);
20660
- if (!fs5.existsSync(root))
20553
+ if (!fs4.existsSync(root))
20661
20554
  return;
20662
- for (const entry of fs5.readdirSync(root, { withFileTypes: true })) {
20555
+ let failure2;
20556
+ for (const entry of fs4.readdirSync(root, { withFileTypes: true })) {
20663
20557
  if (!entry.isDirectory())
20664
20558
  continue;
20665
- const file2 = path8.join(root, entry.name, "request.json");
20666
- if (!fs5.existsSync(file2))
20559
+ let invocation;
20560
+ try {
20561
+ invocation = invocationSchema.parse(JSON.parse(fs4.readFileSync(path7.join(root, entry.name, "request.json"), "utf8")));
20562
+ } catch {
20667
20563
  continue;
20668
- const invocation = invocationSchema.parse(JSON.parse(fs5.readFileSync(file2, "utf8")));
20669
- if (invocation.session_id === session_id)
20670
- writeJson0600(path8.join(root, entry.name, "closed.json"), { session_id });
20564
+ }
20565
+ if (invocation.session_id !== session_id)
20566
+ continue;
20567
+ try {
20568
+ writeJson0600(path7.join(root, entry.name, "closed.json"), { session_id });
20569
+ } catch (error62) {
20570
+ if (error62.code !== "ENOENT")
20571
+ failure2 ??= error62;
20572
+ }
20671
20573
  }
20574
+ if (failure2)
20575
+ throw failure2;
20672
20576
  }
20673
20577
  function assertParentAlive(invocation) {
20674
20578
  if (processIdentity(invocation.parent_pid) !== invocation.parent_started_identity) {
@@ -20680,25 +20584,25 @@ async function runClaudeResultHook(profile, input2, emit, root) {
20680
20584
  const parent = { kind: "claude", request_id: event.tool_use_id, session_id: event.session_id, hook_root: root };
20681
20585
  const invocation = readInvocation(profile, parent);
20682
20586
  const dir = directory(parent);
20683
- const binding = path8.join(dir, "delivery.json");
20684
- if (!fs5.existsSync(binding)) {
20685
- fs5.rmSync(dir, { recursive: true });
20587
+ const binding = path7.join(dir, "delivery.json");
20588
+ if (!fs4.existsSync(binding)) {
20589
+ fs4.rmSync(dir, { recursive: true });
20686
20590
  return 0;
20687
20591
  }
20688
- const deliveryId = external_exports.uuid().parse(JSON.parse(fs5.readFileSync(binding, "utf8")).delivery_id);
20592
+ const deliveryId = external_exports.uuid().parse(JSON.parse(fs4.readFileSync(binding, "utf8")).delivery_id);
20689
20593
  const identity = processIdentity(process.pid);
20690
20594
  if (!identity)
20691
20595
  throw new ClaudeDeliveryError("CLAUDE_PARENT_HOOK_UNAVAILABLE", "\u53D7\u4FE1hook\u306Eprocess\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093");
20692
- writeJson0600(path8.join(dir, "hook.json"), { pid: process.pid, started_identity: identity });
20596
+ writeJson0600(path7.join(dir, "hook.json"), { pid: process.pid, started_identity: identity });
20693
20597
  try {
20694
20598
  const answer = await waitForFileState(dir, () => {
20695
- if (fs5.existsSync(path8.join(dir, "closed.json")))
20599
+ if (fs4.existsSync(path7.join(dir, "closed.json")))
20696
20600
  return null;
20697
20601
  assertParentAlive(invocation);
20698
- const file2 = path8.join(dir, "answer.json");
20699
- if (!fs5.existsSync(file2))
20602
+ const file2 = path7.join(dir, "answer.json");
20603
+ if (!fs4.existsSync(file2))
20700
20604
  return void 0;
20701
- const value = external_exports.object({ delivery_id: external_exports.uuid(), text: external_exports.string() }).strict().parse(JSON.parse(fs5.readFileSync(file2, "utf8")));
20605
+ const value = external_exports.object({ delivery_id: external_exports.uuid(), text: external_exports.string() }).strict().parse(JSON.parse(fs4.readFileSync(file2, "utf8")));
20702
20606
  if (value.delivery_id !== deliveryId)
20703
20607
  throw new ClaudeDeliveryError("CLAUDE_PARENT_DELIVERY_MISMATCH", "\u4FDD\u5B58\u3055\u308C\u305F\u56DE\u7B54\u306E\u914D\u9001ID\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093");
20704
20608
  return value;
@@ -20706,23 +20610,23 @@ async function runClaudeResultHook(profile, input2, emit, root) {
20706
20610
  if (!answer)
20707
20611
  return 0;
20708
20612
  assertOpen(parent);
20709
- writeJson0600(path8.join(dir, "sending.json"), { delivery_id: deliveryId });
20613
+ writeJson0600(path7.join(dir, "sending.json"), { delivery_id: deliveryId });
20710
20614
  await emit(answer.text);
20711
- writeJson0600(path8.join(dir, "emitted.json"), { delivery_id: deliveryId });
20615
+ writeJson0600(path7.join(dir, "emitted.json"), { delivery_id: deliveryId });
20712
20616
  return 2;
20713
20617
  } catch (error62) {
20714
- writeJson0600(path8.join(dir, "failed.json"), { outcome_unknown: fs5.existsSync(path8.join(dir, "sending.json")) });
20618
+ writeJson0600(path7.join(dir, "failed.json"), { outcome_unknown: fs4.existsSync(path7.join(dir, "sending.json")) });
20715
20619
  throw error62;
20716
20620
  }
20717
20621
  }
20718
20622
 
20719
20623
  // ../../node_modules/aiterm-steer-delivery/dist/cursor-receiver.js
20720
- import * as fs6 from "node:fs";
20624
+ import * as fs5 from "node:fs";
20721
20625
  import { homedir as homedir3 } from "node:os";
20722
- import * as path9 from "node:path";
20626
+ import * as path8 from "node:path";
20723
20627
 
20724
20628
  // ../../node_modules/aiterm-steer-delivery/dist/hook-setup.js
20725
- import { copyFileSync, existsSync as existsSync6, lstatSync, mkdirSync as mkdirSync5, readFileSync as readFileSync5, realpathSync as realpathSync4, renameSync as renameSync2, unlinkSync as unlinkSync3, writeFileSync as writeFileSync3 } from "node:fs";
20629
+ import { copyFileSync, existsSync as existsSync5, lstatSync, mkdirSync as mkdirSync4, readFileSync as readFileSync4, realpathSync as realpathSync3, renameSync as renameSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "node:fs";
20726
20630
  import { dirname as dirname3 } from "node:path";
20727
20631
  import { randomUUID as randomUUID2 } from "node:crypto";
20728
20632
  import { isDeepStrictEqual } from "node:util";
@@ -20753,11 +20657,11 @@ function claudeParentHookEntries(profile, hook, platform = process.platform) {
20753
20657
  };
20754
20658
  }
20755
20659
  function mergeClaudeParentHooks(profile, file2, hook) {
20756
- const target = existsSync6(file2) ? realpathSync4(file2) : file2;
20660
+ const target2 = existsSync5(file2) ? realpathSync3(file2) : file2;
20757
20661
  let current = {};
20758
- if (existsSync6(target)) {
20662
+ if (existsSync5(target2)) {
20759
20663
  try {
20760
- current = JSON.parse(readFileSync5(target, "utf8"));
20664
+ current = JSON.parse(readFileSync4(target2, "utf8"));
20761
20665
  } catch {
20762
20666
  throw new SetupError("config_invalid", "Claude\u306Ehook\u8A2D\u5B9AJSON\u3092\u8AAD\u3081\u307E\u305B\u3093");
20763
20667
  }
@@ -20785,19 +20689,19 @@ function mergeClaudeParentHooks(profile, file2, hook) {
20785
20689
  const next = { ...current, hooks };
20786
20690
  if (isDeepStrictEqual(current, next))
20787
20691
  return "unchanged";
20788
- mkdirSync5(dirname3(target), { recursive: true });
20789
- const temporary = `${target}.${profile.id}-${randomUUID2()}`;
20692
+ mkdirSync4(dirname3(target2), { recursive: true });
20693
+ const temporary = `${target2}.${profile.id}-${randomUUID2()}`;
20790
20694
  try {
20791
20695
  writeFileSync3(temporary, `${JSON.stringify(next, null, 2)}
20792
20696
  `, { mode: 384, flag: "wx" });
20793
- if (existsSync6(target))
20794
- copyFileSync(target, `${target}${profile.backup_suffix}`);
20795
- renameSync2(temporary, target);
20697
+ if (existsSync5(target2))
20698
+ copyFileSync(target2, `${target2}${profile.backup_suffix}`);
20699
+ renameSync2(temporary, target2);
20796
20700
  } finally {
20797
- if (existsSync6(temporary))
20798
- unlinkSync3(temporary);
20701
+ if (existsSync5(temporary))
20702
+ unlinkSync2(temporary);
20799
20703
  }
20800
- if (!isDeepStrictEqual(JSON.parse(readFileSync5(target, "utf8")), next)) {
20704
+ if (!isDeepStrictEqual(JSON.parse(readFileSync4(target2, "utf8")), next)) {
20801
20705
  throw new SetupError("config_readback_failed", "Claude\u306Ehook\u767B\u9332\u306E\u8AAD\u623B\u3057\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093");
20802
20706
  }
20803
20707
  return "configured";
@@ -20819,10 +20723,10 @@ function claudeParentHooksRegistered(profile, document) {
20819
20723
  return Object.keys(claudeParentHookEntries(profile, { command: "", script: profile.hooks.claude })).every((event) => ownedClaudeParentHooks(profile, document, event).length > 0);
20820
20724
  }
20821
20725
  function removeClaudeParentHooks(profile, file2) {
20822
- if (!existsSync6(file2))
20726
+ if (!existsSync5(file2))
20823
20727
  return "unchanged";
20824
- const target = realpathSync4(file2);
20825
- const current = JSON.parse(readFileSync5(target, "utf8"));
20728
+ const target2 = realpathSync3(file2);
20729
+ const current = JSON.parse(readFileSync4(target2, "utf8"));
20826
20730
  if (!record2(current) || current.hooks !== void 0 && !record2(current.hooks)) {
20827
20731
  throw new SetupError("config_invalid", "Claude\u306Ehook\u8A2D\u5B9A\u3092\u8AAD\u3081\u307E\u305B\u3093");
20828
20732
  }
@@ -20843,17 +20747,17 @@ function removeClaudeParentHooks(profile, file2) {
20843
20747
  const next = { ...current, hooks };
20844
20748
  if (isDeepStrictEqual(current, next))
20845
20749
  return "unchanged";
20846
- const temporary = `${target}.${profile.id}-${randomUUID2()}`;
20750
+ const temporary = `${target2}.${profile.id}-${randomUUID2()}`;
20847
20751
  try {
20848
20752
  writeFileSync3(temporary, `${JSON.stringify(next, null, 2)}
20849
20753
  `, { mode: 384, flag: "wx" });
20850
- copyFileSync(target, `${target}${profile.backup_suffix}`);
20851
- renameSync2(temporary, target);
20754
+ copyFileSync(target2, `${target2}${profile.backup_suffix}`);
20755
+ renameSync2(temporary, target2);
20852
20756
  } finally {
20853
- if (existsSync6(temporary))
20854
- unlinkSync3(temporary);
20757
+ if (existsSync5(temporary))
20758
+ unlinkSync2(temporary);
20855
20759
  }
20856
- if (!isDeepStrictEqual(JSON.parse(readFileSync5(target, "utf8")), next))
20760
+ if (!isDeepStrictEqual(JSON.parse(readFileSync4(target2, "utf8")), next))
20857
20761
  throw new SetupError("config_readback_failed", "Claude hook\u89E3\u9664\u306E\u8AAD\u623B\u3057\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093");
20858
20762
  return "removed";
20859
20763
  }
@@ -20869,11 +20773,11 @@ function ownsCursorParentHook(profile, hook) {
20869
20773
  return record2(hook) && typeof hook.command === "string" && commandNamesFile(hook.command, profile.hooks.cursor);
20870
20774
  }
20871
20775
  function mergeCursorParentHooks(profile, file2, hook) {
20872
- const target = existsSync6(file2) ? realpathSync4(file2) : file2;
20776
+ const target2 = existsSync5(file2) ? realpathSync3(file2) : file2;
20873
20777
  let current = { version: 1, hooks: {} };
20874
- if (existsSync6(target)) {
20778
+ if (existsSync5(target2)) {
20875
20779
  try {
20876
- current = JSON.parse(readFileSync5(target, "utf8"));
20780
+ current = JSON.parse(readFileSync4(target2, "utf8"));
20877
20781
  } catch {
20878
20782
  throw new SetupError("config_invalid", "Cursor\u306Ehook\u8A2D\u5B9AJSON\u3092\u8AAD\u3081\u307E\u305B\u3093");
20879
20783
  }
@@ -20905,28 +20809,28 @@ function mergeCursorParentHooks(profile, file2, hook) {
20905
20809
  const next = { ...current, version: current.version ?? 1, hooks };
20906
20810
  if (isDeepStrictEqual(current, next))
20907
20811
  return "unchanged";
20908
- mkdirSync5(dirname3(target), { recursive: true });
20909
- const temporary = `${target}.${profile.id}-${randomUUID2()}`;
20812
+ mkdirSync4(dirname3(target2), { recursive: true });
20813
+ const temporary = `${target2}.${profile.id}-${randomUUID2()}`;
20910
20814
  try {
20911
20815
  writeFileSync3(temporary, `${JSON.stringify(next, null, 2)}
20912
20816
  `, { mode: 384, flag: "wx" });
20913
- if (existsSync6(target))
20914
- copyFileSync(target, `${target}${profile.backup_suffix}`);
20915
- renameSync2(temporary, target);
20817
+ if (existsSync5(target2))
20818
+ copyFileSync(target2, `${target2}${profile.backup_suffix}`);
20819
+ renameSync2(temporary, target2);
20916
20820
  } finally {
20917
- if (existsSync6(temporary))
20918
- unlinkSync3(temporary);
20821
+ if (existsSync5(temporary))
20822
+ unlinkSync2(temporary);
20919
20823
  }
20920
- if (!isDeepStrictEqual(JSON.parse(readFileSync5(target, "utf8")), next)) {
20824
+ if (!isDeepStrictEqual(JSON.parse(readFileSync4(target2, "utf8")), next)) {
20921
20825
  throw new SetupError("config_readback_failed", "Cursor\u306Ehook\u767B\u9332\u306E\u8AAD\u623B\u3057\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093");
20922
20826
  }
20923
20827
  return "configured";
20924
20828
  }
20925
20829
  function removeCursorParentHooks(profile, file2) {
20926
- if (!existsSync6(file2))
20830
+ if (!existsSync5(file2))
20927
20831
  return "unchanged";
20928
- const target = realpathSync4(file2);
20929
- const current = JSON.parse(readFileSync5(target, "utf8"));
20832
+ const target2 = realpathSync3(file2);
20833
+ const current = JSON.parse(readFileSync4(target2, "utf8"));
20930
20834
  if (!record2(current) || current.hooks !== void 0 && !record2(current.hooks)) {
20931
20835
  throw new SetupError("config_invalid", "Cursor\u306Ehook\u8A2D\u5B9A\u3092\u8AAD\u3081\u307E\u305B\u3093");
20932
20836
  }
@@ -20947,17 +20851,17 @@ function removeCursorParentHooks(profile, file2) {
20947
20851
  const next = { ...current, hooks };
20948
20852
  if (isDeepStrictEqual(current, next))
20949
20853
  return "unchanged";
20950
- const temporary = `${target}.${profile.id}-${randomUUID2()}`;
20854
+ const temporary = `${target2}.${profile.id}-${randomUUID2()}`;
20951
20855
  try {
20952
20856
  writeFileSync3(temporary, `${JSON.stringify(next, null, 2)}
20953
20857
  `, { mode: 384, flag: "wx" });
20954
- copyFileSync(target, `${target}${profile.backup_suffix}`);
20955
- renameSync2(temporary, target);
20858
+ copyFileSync(target2, `${target2}${profile.backup_suffix}`);
20859
+ renameSync2(temporary, target2);
20956
20860
  } finally {
20957
- if (existsSync6(temporary))
20958
- unlinkSync3(temporary);
20861
+ if (existsSync5(temporary))
20862
+ unlinkSync2(temporary);
20959
20863
  }
20960
- if (!isDeepStrictEqual(JSON.parse(readFileSync5(target, "utf8")), next)) {
20864
+ if (!isDeepStrictEqual(JSON.parse(readFileSync4(target2, "utf8")), next)) {
20961
20865
  throw new SetupError("config_readback_failed", "Cursor hook\u89E3\u9664\u306E\u8AAD\u623B\u3057\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093");
20962
20866
  }
20963
20867
  return "removed";
@@ -20975,7 +20879,7 @@ function isCursorMcpClient(clientName) {
20975
20879
  return clientName === "cursor-vscode" || clientName.startsWith("cursor-vscode ") || clientName === "Cursor";
20976
20880
  }
20977
20881
  function cursorHooksFile(home2 = process.env.HOME ?? homedir3()) {
20978
- return path9.join(process.env.CURSOR_HOME ?? path9.join(home2, ".cursor"), "hooks.json");
20882
+ return path8.join(process.env.CURSOR_HOME ?? path8.join(home2, ".cursor"), "hooks.json");
20979
20883
  }
20980
20884
  function cursorParentHooksRegistered(profile, document) {
20981
20885
  if (document === null || typeof document !== "object" || Array.isArray(document))
@@ -20998,7 +20902,7 @@ function verifyCursorParent(profile, parent, hooksFile = cursorHooksFile()) {
20998
20902
  cursorParentSchema.parse(parent);
20999
20903
  let document;
21000
20904
  try {
21001
- document = JSON.parse(fs6.readFileSync(hooksFile, "utf8"));
20905
+ document = JSON.parse(fs5.readFileSync(hooksFile, "utf8"));
21002
20906
  } catch {
21003
20907
  throw new CursorDeliveryError("CURSOR_PARENT_HOOK_UNAVAILABLE", `Cursor\u306Ehook\u304C\u767B\u9332\u3055\u308C\u3066\u3044\u307E\u305B\u3093\u3002${profile.setup_command}\u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044`);
21004
20908
  }
@@ -21064,7 +20968,7 @@ function toolBaseName(profile, name) {
21064
20968
  }
21065
20969
  function claim2(dir, channel) {
21066
20970
  try {
21067
- fs6.writeFileSync(path9.join(dir, "claim.json"), JSON.stringify({ channel, at: (/* @__PURE__ */ new Date()).toISOString() }), { flag: "wx", mode: 384 });
20971
+ fs5.writeFileSync(path8.join(dir, "claim.json"), JSON.stringify({ channel, at: (/* @__PURE__ */ new Date()).toISOString() }), { flag: "wx", mode: 384 });
21068
20972
  return true;
21069
20973
  } catch (error62) {
21070
20974
  if (error62.code === "EEXIST")
@@ -21073,45 +20977,45 @@ function claim2(dir, channel) {
21073
20977
  }
21074
20978
  }
21075
20979
  function bind(hookRoot, deliveryId, conv) {
21076
- const dir = path9.join(hookRoot, "deliveries", deliveryId);
21077
- if (!fs6.existsSync(dir))
20980
+ const dir = path8.join(hookRoot, "deliveries", deliveryId);
20981
+ if (!fs5.existsSync(dir))
21078
20982
  return;
21079
- const bindFile = path9.join(dir, "bind.json");
21080
- if (!fs6.existsSync(bindFile)) {
20983
+ const bindFile = path8.join(dir, "bind.json");
20984
+ if (!fs5.existsSync(bindFile)) {
21081
20985
  writeJson0600(bindFile, { conversation_id: conv, created_at: (/* @__PURE__ */ new Date()).toISOString() });
21082
20986
  }
21083
- const indexDir = path9.join(hookRoot, "conversations", conv);
21084
- fs6.mkdirSync(indexDir, { recursive: true, mode: 448 });
21085
- const index = path9.join(indexDir, deliveryId);
21086
- if (!fs6.existsSync(index))
21087
- fs6.writeFileSync(index, "", { mode: 384 });
20987
+ const indexDir = path8.join(hookRoot, "conversations", conv);
20988
+ fs5.mkdirSync(indexDir, { recursive: true, mode: 448 });
20989
+ const index = path8.join(indexDir, deliveryId);
20990
+ if (!fs5.existsSync(index))
20991
+ fs5.writeFileSync(index, "", { mode: 384 });
21088
20992
  }
21089
20993
  function inject(hookRoot, conv) {
21090
- const indexDir = path9.join(hookRoot, "conversations", conv);
21091
- if (!fs6.existsSync(indexDir))
20994
+ const indexDir = path8.join(hookRoot, "conversations", conv);
20995
+ if (!fs5.existsSync(indexDir))
21092
20996
  return [];
21093
- const pending = fs6.readdirSync(indexDir).flatMap((deliveryId) => {
21094
- const dir = path9.join(hookRoot, "deliveries", deliveryId);
21095
- const answerFile = path9.join(dir, "answer.json");
21096
- const bindFile = path9.join(dir, "bind.json");
21097
- if (!fs6.existsSync(answerFile) || !fs6.existsSync(bindFile))
20997
+ const pending = fs5.readdirSync(indexDir).flatMap((deliveryId) => {
20998
+ const dir = path8.join(hookRoot, "deliveries", deliveryId);
20999
+ const answerFile = path8.join(dir, "answer.json");
21000
+ const bindFile = path8.join(dir, "bind.json");
21001
+ if (!fs5.existsSync(answerFile) || !fs5.existsSync(bindFile))
21098
21002
  return [];
21099
- const answer = external_exports.object({ delivery_id: external_exports.string(), text: external_exports.string() }).parse(JSON.parse(fs6.readFileSync(answerFile, "utf8")));
21100
- const bound = external_exports.object({ conversation_id: external_exports.string(), created_at: external_exports.string() }).parse(JSON.parse(fs6.readFileSync(bindFile, "utf8")));
21003
+ const answer = external_exports.object({ delivery_id: external_exports.string(), text: external_exports.string() }).parse(JSON.parse(fs5.readFileSync(answerFile, "utf8")));
21004
+ const bound = external_exports.object({ conversation_id: external_exports.string(), created_at: external_exports.string() }).parse(JSON.parse(fs5.readFileSync(bindFile, "utf8")));
21101
21005
  if (answer.delivery_id !== deliveryId || bound.conversation_id !== conv)
21102
21006
  return [];
21103
21007
  return [{ deliveryId, dir, created_at: bound.created_at, text: answer.text }];
21104
21008
  }).sort((a, b) => a.created_at.localeCompare(b.created_at));
21105
21009
  const texts = [];
21106
21010
  for (const item of pending) {
21107
- const index = path9.join(indexDir, item.deliveryId);
21011
+ const index = path8.join(indexDir, item.deliveryId);
21108
21012
  if (!claim2(item.dir, "hook")) {
21109
- if (fs6.existsSync(path9.join(item.dir, "claim.json")))
21110
- fs6.rmSync(index, { force: true });
21013
+ if (fs5.existsSync(path8.join(item.dir, "claim.json")))
21014
+ fs5.rmSync(index, { force: true });
21111
21015
  continue;
21112
21016
  }
21113
21017
  texts.push(item.text);
21114
- fs6.rmSync(index, { force: true });
21018
+ fs5.rmSync(index, { force: true });
21115
21019
  }
21116
21020
  return texts;
21117
21021
  }
@@ -21155,8 +21059,8 @@ function waitProcessCommandLine(wait, platform = process.platform) {
21155
21059
  }
21156
21060
 
21157
21061
  // ../../node_modules/aiterm-steer-delivery/dist/channel.js
21158
- import * as fs7 from "node:fs";
21159
- import * as path10 from "node:path";
21062
+ import * as fs6 from "node:fs";
21063
+ import * as path9 from "node:path";
21160
21064
  import { randomUUID as randomUUID3 } from "node:crypto";
21161
21065
  import { setTimeout as delay } from "node:timers/promises";
21162
21066
  var uuid3 = external_exports.uuid();
@@ -21173,14 +21077,14 @@ var ChannelError = class extends SteerDeliveryError {
21173
21077
  var sendSequence = 0;
21174
21078
  var itemSchema = external_exports.object({ delivery_id: external_exports.uuid(), text: external_exports.string(), at: external_exports.string() }).strict();
21175
21079
  function channelDir(profile, channelId) {
21176
- return path10.join(channelRoot(profile), uuid3.parse(channelId));
21080
+ return path9.join(channelRoot(profile), uuid3.parse(channelId));
21177
21081
  }
21178
21082
  function processIdentity2(pid) {
21179
21083
  return readRuntimeProcesses().find((entry) => entry.pid === pid)?.started_identity;
21180
21084
  }
21181
21085
  function mkdirs(...dirs) {
21182
21086
  for (const dir of dirs)
21183
- fs7.mkdirSync(dir, { recursive: true, mode: 448 });
21087
+ fs6.mkdirSync(dir, { recursive: true, mode: 448 });
21184
21088
  }
21185
21089
  function openChannel(profile, parent) {
21186
21090
  const channel_id = randomUUID3();
@@ -21194,7 +21098,7 @@ function openChannel(profile, parent) {
21194
21098
  else if (parent.kind === "cursor")
21195
21099
  channel = { schema: "aiterm-steer.channel.v1", channel_id, kind: "cursor", created_at };
21196
21100
  else {
21197
- const request = external_exports.object({ session_id: external_exports.uuid(), parent_pid: external_exports.number().int().positive(), parent_started_identity: external_exports.string() }).loose().parse(JSON.parse(fs7.readFileSync(path10.join(parent.hook_root, parent.request_id, "request.json"), "utf8")));
21101
+ const request = external_exports.object({ session_id: external_exports.uuid(), parent_pid: external_exports.number().int().positive(), parent_started_identity: external_exports.string() }).loose().parse(JSON.parse(fs6.readFileSync(path9.join(parent.hook_root, parent.request_id, "request.json"), "utf8")));
21198
21102
  if (request.session_id !== parent.session_id)
21199
21103
  throw new ChannelError("CHANNEL_PARENT_SESSION_MISMATCH", "\u8981\u6C42\u3068hook\u306E\u4F1A\u8A71\u304C\u4E00\u81F4\u3057\u307E\u305B\u3093");
21200
21104
  channel = {
@@ -21205,19 +21109,19 @@ function openChannel(profile, parent) {
21205
21109
  claude: { session_id: request.session_id, parent_pid: request.parent_pid, parent_started_identity: request.parent_started_identity }
21206
21110
  };
21207
21111
  }
21208
- mkdirs(path10.join(dir, "inbox"), path10.join(dir, "claims"), path10.join(dir, "emitted"));
21209
- writeJson0600(path10.join(dir, "channel.json"), channel);
21112
+ mkdirs(path9.join(dir, "inbox"), path9.join(dir, "claims"), path9.join(dir, "emitted"));
21113
+ writeJson0600(path9.join(dir, "channel.json"), channel);
21210
21114
  if (channel.claude) {
21211
- const index = path10.join(channelRoot(profile), "claude-sessions", channel.claude.session_id);
21115
+ const index = path9.join(channelRoot(profile), "claude-sessions", channel.claude.session_id);
21212
21116
  mkdirs(index);
21213
- fs7.writeFileSync(path10.join(index, channel_id), "", { mode: 384 });
21117
+ fs6.writeFileSync(path9.join(index, channel_id), "", { mode: 384 });
21214
21118
  }
21215
21119
  return channel;
21216
21120
  }
21217
21121
  function readChannel(profile, channelId) {
21218
- const file2 = path10.join(channelDir(profile, channelId), "channel.json");
21122
+ const file2 = path9.join(channelDir(profile, channelId), "channel.json");
21219
21123
  try {
21220
- return channelSchema.parse(JSON.parse(fs7.readFileSync(file2, "utf8")));
21124
+ return channelSchema.parse(JSON.parse(fs6.readFileSync(file2, "utf8")));
21221
21125
  } catch (error62) {
21222
21126
  if (error62.code === "ENOENT")
21223
21127
  throw new ChannelError("CHANNEL_UNKNOWN", "channel\u306E\u8A18\u9332\u304C\u3042\u308A\u307E\u305B\u3093");
@@ -21225,13 +21129,13 @@ function readChannel(profile, channelId) {
21225
21129
  }
21226
21130
  }
21227
21131
  function channelClosed(profile, channelId) {
21228
- return fs7.existsSync(path10.join(channelDir(profile, channelId), "closed.json"));
21132
+ return fs6.existsSync(path9.join(channelDir(profile, channelId), "closed.json"));
21229
21133
  }
21230
21134
  function closeChannel(profile, channelId, reason = "closed") {
21231
21135
  const dir = channelDir(profile, channelId);
21232
- if (!fs7.existsSync(dir))
21136
+ if (!fs6.existsSync(dir))
21233
21137
  return;
21234
- writeJson0600(path10.join(dir, "closed.json"), { reason, at: (/* @__PURE__ */ new Date()).toISOString() });
21138
+ writeJson0600(path9.join(dir, "closed.json"), { reason, at: (/* @__PURE__ */ new Date()).toISOString() });
21235
21139
  }
21236
21140
  async function sendToChannel(profile, channelId, deliveryId, text, runtime) {
21237
21141
  uuid3.parse(deliveryId);
@@ -21244,21 +21148,21 @@ async function sendToChannel(profile, channelId, deliveryId, text, runtime) {
21244
21148
  }
21245
21149
  const dir = channelDir(profile, channelId);
21246
21150
  for (const sub of ["claims", "emitted"]) {
21247
- if (fs7.existsSync(path10.join(dir, sub, `${deliveryId}.json`)))
21151
+ if (fs6.existsSync(path9.join(dir, sub, `${deliveryId}.json`)))
21248
21152
  throw new ChannelError("CHANNEL_DELIVERY_DUPLICATE", "\u540C\u3058\u914D\u9001ID\u306E\u672C\u6587\u306F\u3059\u3067\u306B\u53D7\u3051\u53D6\u3089\u308C\u3066\u3044\u307E\u3059");
21249
21153
  }
21250
21154
  const name = `${Date.now().toString().padStart(15, "0")}-${(sendSequence++).toString().padStart(9, "0")}-${deliveryId}.json`;
21251
21155
  const item = { delivery_id: deliveryId, text, at: (/* @__PURE__ */ new Date()).toISOString() };
21252
- const temporary = path10.join(dir, `.${deliveryId}.${randomUUID3()}.tmp`);
21253
- fs7.writeFileSync(temporary, JSON.stringify(item) + "\n", { flag: "wx", mode: 384 });
21156
+ const temporary = path9.join(dir, `.${deliveryId}.${randomUUID3()}.tmp`);
21157
+ fs6.writeFileSync(temporary, JSON.stringify(item) + "\n", { flag: "wx", mode: 384 });
21254
21158
  try {
21255
- fs7.linkSync(temporary, path10.join(dir, "inbox", name));
21159
+ fs6.linkSync(temporary, path9.join(dir, "inbox", name));
21256
21160
  } catch (error62) {
21257
21161
  if (error62.code === "EEXIST")
21258
21162
  throw new ChannelError("CHANNEL_DELIVERY_DUPLICATE", "\u540C\u3058\u914D\u9001ID\u306E\u672C\u6587\u304C\u3059\u3067\u306B\u53D7\u4FE1\u7BB1\u306B\u3042\u308A\u307E\u3059");
21259
21163
  throw error62;
21260
21164
  } finally {
21261
- fs7.rmSync(temporary, { force: true });
21165
+ fs6.rmSync(temporary, { force: true });
21262
21166
  }
21263
21167
  return { state: "queued", queued_submission_id: null };
21264
21168
  }
@@ -21268,13 +21172,13 @@ function channelDeliveryState(profile, channelId, deliveryId) {
21268
21172
  if (channel.kind === "codex")
21269
21173
  return null;
21270
21174
  const dir = channelDir(profile, channelId);
21271
- if (fs7.existsSync(path10.join(dir, "emitted", `${deliveryId}.json`)))
21175
+ if (fs6.existsSync(path9.join(dir, "emitted", `${deliveryId}.json`)))
21272
21176
  return "emitted";
21273
- const claim3 = path10.join(dir, "claims", `${deliveryId}.json`);
21274
- if (fs7.existsSync(claim3)) {
21177
+ const claim3 = path9.join(dir, "claims", `${deliveryId}.json`);
21178
+ if (fs6.existsSync(claim3)) {
21275
21179
  let value;
21276
21180
  try {
21277
- value = JSON.parse(fs7.readFileSync(claim3, "utf8"));
21181
+ value = JSON.parse(fs6.readFileSync(claim3, "utf8"));
21278
21182
  } catch {
21279
21183
  return "sending";
21280
21184
  }
@@ -21286,19 +21190,19 @@ function channelDeliveryState(profile, channelId, deliveryId) {
21286
21190
  return "unknown";
21287
21191
  return "sending";
21288
21192
  }
21289
- return fs7.readdirSync(path10.join(dir, "inbox")).some((name) => name.endsWith(`-${deliveryId}.json`)) ? "queued" : null;
21193
+ return fs6.readdirSync(path9.join(dir, "inbox")).some((name) => name.endsWith(`-${deliveryId}.json`)) ? "queued" : null;
21290
21194
  }
21291
21195
  function withdrawFromChannel(profile, channelId, deliveryId) {
21292
21196
  uuid3.parse(deliveryId);
21293
21197
  const dir = channelDir(profile, channelId);
21294
- const inbox = path10.join(dir, "inbox");
21295
- const name = fs7.existsSync(inbox) ? fs7.readdirSync(inbox).find((entry) => entry.endsWith(`-${deliveryId}.json`)) : void 0;
21198
+ const inbox = path9.join(dir, "inbox");
21199
+ const name = fs6.existsSync(inbox) ? fs6.readdirSync(inbox).find((entry) => entry.endsWith(`-${deliveryId}.json`)) : void 0;
21296
21200
  if (!name)
21297
21201
  return false;
21298
- const claim3 = path10.join(dir, "claims", `${deliveryId}.json`);
21202
+ const claim3 = path9.join(dir, "claims", `${deliveryId}.json`);
21299
21203
  try {
21300
- fs7.linkSync(path10.join(inbox, name), claim3);
21301
- fs7.unlinkSync(path10.join(inbox, name));
21204
+ fs6.linkSync(path9.join(inbox, name), claim3);
21205
+ fs6.unlinkSync(path9.join(inbox, name));
21302
21206
  } catch (error62) {
21303
21207
  if (["ENOENT", "EEXIST"].includes(error62.code ?? ""))
21304
21208
  return false;
@@ -21309,27 +21213,27 @@ function withdrawFromChannel(profile, channelId, deliveryId) {
21309
21213
  }
21310
21214
  function claimPending(profile, channelId, by, limit = Infinity) {
21311
21215
  const dir = channelDir(profile, channelId);
21312
- const inbox = path10.join(dir, "inbox");
21313
- if (!fs7.existsSync(inbox))
21216
+ const inbox = path9.join(dir, "inbox");
21217
+ if (!fs6.existsSync(inbox))
21314
21218
  return [];
21315
21219
  let identity;
21316
21220
  const claimed = [];
21317
- for (const name of fs7.readdirSync(inbox).filter((entry) => entry.endsWith(".json")).sort()) {
21221
+ for (const name of fs6.readdirSync(inbox).filter((entry) => entry.endsWith(".json")).sort()) {
21318
21222
  if (claimed.length >= limit)
21319
21223
  break;
21320
- const source = path10.join(inbox, name);
21224
+ const source = path9.join(inbox, name);
21321
21225
  let item;
21322
21226
  try {
21323
- item = itemSchema.parse(JSON.parse(fs7.readFileSync(source, "utf8")));
21227
+ item = itemSchema.parse(JSON.parse(fs6.readFileSync(source, "utf8")));
21324
21228
  } catch (error62) {
21325
21229
  if (error62.code === "ENOENT")
21326
21230
  continue;
21327
21231
  throw error62;
21328
21232
  }
21329
- const claim3 = path10.join(dir, "claims", `${item.delivery_id}.json`);
21233
+ const claim3 = path9.join(dir, "claims", `${item.delivery_id}.json`);
21330
21234
  try {
21331
- fs7.linkSync(source, claim3);
21332
- fs7.unlinkSync(source);
21235
+ fs6.linkSync(source, claim3);
21236
+ fs6.unlinkSync(source);
21333
21237
  } catch (error62) {
21334
21238
  if (["ENOENT", "EEXIST"].includes(error62.code ?? ""))
21335
21239
  continue;
@@ -21344,8 +21248,8 @@ function claimPending(profile, channelId, by, limit = Infinity) {
21344
21248
  function settle2(entries, by, state) {
21345
21249
  for (const entry of entries) {
21346
21250
  if (state === "emitted") {
21347
- writeJson0600(path10.join(entry.dir, "emitted", `${entry.item.delivery_id}.json`), { delivery_id: entry.item.delivery_id, by, at: (/* @__PURE__ */ new Date()).toISOString() });
21348
- fs7.rmSync(entry.claim, { force: true });
21251
+ writeJson0600(path9.join(entry.dir, "emitted", `${entry.item.delivery_id}.json`), { delivery_id: entry.item.delivery_id, by, at: (/* @__PURE__ */ new Date()).toISOString() });
21252
+ fs6.rmSync(entry.claim, { force: true });
21349
21253
  } else {
21350
21254
  writeJson0600(entry.claim, { ...entry.item, state: "unknown", by });
21351
21255
  }
@@ -21361,13 +21265,13 @@ async function emitClaimed(entries, by, emit) {
21361
21265
  settle2(entries, by, "emitted");
21362
21266
  }
21363
21267
  function sessionIndex(profile, sessionId) {
21364
- return path10.join(channelRoot(profile), "claude-sessions", uuid3.parse(sessionId));
21268
+ return path9.join(channelRoot(profile), "claude-sessions", uuid3.parse(sessionId));
21365
21269
  }
21366
21270
  function openClaudeChannels(profile, sessionId) {
21367
21271
  const index = sessionIndex(profile, sessionId);
21368
- if (!fs7.existsSync(index))
21272
+ if (!fs6.existsSync(index))
21369
21273
  return [];
21370
- return fs7.readdirSync(index).filter((name) => uuid3.safeParse(name).success).flatMap((name) => {
21274
+ return fs6.readdirSync(index).filter((name) => uuid3.safeParse(name).success).flatMap((name) => {
21371
21275
  try {
21372
21276
  const channel = readChannel(profile, name);
21373
21277
  return channel.claude?.session_id === sessionId && !channelClosed(profile, name) ? [channel] : [];
@@ -21379,13 +21283,13 @@ function openClaudeChannels(profile, sessionId) {
21379
21283
  });
21380
21284
  }
21381
21285
  function acquireWaiter(index) {
21382
- const file2 = path10.join(index, "waiter.json");
21286
+ const file2 = path9.join(index, "waiter.json");
21383
21287
  const identity = processIdentity2(process.pid);
21384
21288
  if (!identity)
21385
21289
  throw new ChannelError("CHANNEL_WAITER_UNAVAILABLE", "\u53D7\u4FE1hook\u306Eprocess\u3092\u78BA\u8A8D\u3067\u304D\u307E\u305B\u3093");
21386
21290
  for (let attempt = 0; attempt < 3; attempt += 1) {
21387
21291
  try {
21388
- fs7.writeFileSync(file2, JSON.stringify({ pid: process.pid, started_identity: identity }) + "\n", { flag: "wx", mode: 384 });
21292
+ fs6.writeFileSync(file2, JSON.stringify({ pid: process.pid, started_identity: identity }) + "\n", { flag: "wx", mode: 384 });
21389
21293
  return identity;
21390
21294
  } catch (error62) {
21391
21295
  if (error62.code !== "EEXIST")
@@ -21393,26 +21297,26 @@ function acquireWaiter(index) {
21393
21297
  }
21394
21298
  let owner = {};
21395
21299
  try {
21396
- owner = JSON.parse(fs7.readFileSync(file2, "utf8"));
21300
+ owner = JSON.parse(fs6.readFileSync(file2, "utf8"));
21397
21301
  } catch {
21398
21302
  }
21399
21303
  if (typeof owner.pid === "number" && typeof owner.started_identity === "string" && processIdentity2(owner.pid) === owner.started_identity)
21400
21304
  return null;
21401
21305
  try {
21402
- fs7.renameSync(file2, path10.join(index, `waiter.${randomUUID3()}.stale`));
21306
+ fs6.renameSync(file2, path9.join(index, `waiter.${randomUUID3()}.stale`));
21403
21307
  } catch {
21404
21308
  }
21405
- for (const name of fs7.readdirSync(index).filter((entry) => entry.endsWith(".stale")))
21406
- fs7.rmSync(path10.join(index, name), { force: true });
21309
+ for (const name of fs6.readdirSync(index).filter((entry) => entry.endsWith(".stale")))
21310
+ fs6.rmSync(path9.join(index, name), { force: true });
21407
21311
  }
21408
21312
  return null;
21409
21313
  }
21410
21314
  function releaseWaiter(index, identity) {
21411
- const file2 = path10.join(index, "waiter.json");
21315
+ const file2 = path9.join(index, "waiter.json");
21412
21316
  try {
21413
- const owner = JSON.parse(fs7.readFileSync(file2, "utf8"));
21317
+ const owner = JSON.parse(fs6.readFileSync(file2, "utf8"));
21414
21318
  if (owner.pid === process.pid && owner.started_identity === identity)
21415
- fs7.rmSync(file2, { force: true });
21319
+ fs6.rmSync(file2, { force: true });
21416
21320
  } catch {
21417
21321
  }
21418
21322
  }
@@ -21520,26 +21424,26 @@ async function handleCursorChannelHook(profile, event, emit) {
21520
21424
  return false;
21521
21425
  const payload = name === "afterMCPExecution" ? event.result_json : event.tool_output;
21522
21426
  const bound = channelIdFromResult(payload);
21523
- const conversations = path10.join(channelRoot(profile), "cursor-conversations");
21524
- if (bound && fs7.existsSync(channelDir(profile, bound))) {
21427
+ const conversations = path9.join(channelRoot(profile), "cursor-conversations");
21428
+ if (bound && fs6.existsSync(channelDir(profile, bound))) {
21525
21429
  const channel = readChannel(profile, bound);
21526
21430
  if (channel.kind === "cursor") {
21527
- const bindFile = path10.join(channelDir(profile, bound), "bind.json");
21528
- if (!fs7.existsSync(bindFile))
21431
+ const bindFile = path9.join(channelDir(profile, bound), "bind.json");
21432
+ if (!fs6.existsSync(bindFile))
21529
21433
  writeJson0600(bindFile, { conversation_id: conv, at: (/* @__PURE__ */ new Date()).toISOString() });
21530
- const bindConv = JSON.parse(fs7.readFileSync(bindFile, "utf8")).conversation_id;
21434
+ const bindConv = JSON.parse(fs6.readFileSync(bindFile, "utf8")).conversation_id;
21531
21435
  if (bindConv === conv) {
21532
- mkdirs(path10.join(conversations, conv));
21533
- fs7.writeFileSync(path10.join(conversations, conv, bound), "", { mode: 384 });
21436
+ mkdirs(path9.join(conversations, conv));
21437
+ fs6.writeFileSync(path9.join(conversations, conv, bound), "", { mode: 384 });
21534
21438
  }
21535
21439
  }
21536
21440
  }
21537
21441
  if (name === "afterMCPExecution")
21538
21442
  return false;
21539
- const index = path10.join(conversations, conv);
21540
- if (!fs7.existsSync(index))
21443
+ const index = path9.join(conversations, conv);
21444
+ if (!fs6.existsSync(index))
21541
21445
  return false;
21542
- const claimed = fs7.readdirSync(index).filter((id) => uuid3.safeParse(id).success && !channelClosed(profile, id)).flatMap((id) => claimPending(profile, id, "cursor_hook"));
21446
+ const claimed = fs6.readdirSync(index).filter((id) => uuid3.safeParse(id).success && !channelClosed(profile, id)).flatMap((id) => claimPending(profile, id, "cursor_hook"));
21543
21447
  if (!claimed.length)
21544
21448
  return false;
21545
21449
  await emitClaimed(claimed, "cursor_hook", (texts) => emit(texts.join("\n\n")));
@@ -21586,18 +21490,6 @@ async function readStdin() {
21586
21490
  input2 += chunk;
21587
21491
  return withoutBom(input2);
21588
21492
  }
21589
- async function runCodexHookMain(profile, directory2 = process.argv[2]) {
21590
- try {
21591
- const input2 = await readStdin();
21592
- await runCodexResultHook(profile, JSON.parse(input2), (value) => new Promise((resolve2, reject) => {
21593
- process.stdout.write(JSON.stringify(value) + "\n", (error62) => error62 ? reject(error62) : resolve2());
21594
- }), { directory: directory2 });
21595
- } catch (error62) {
21596
- process.stderr.write(`CODEX_PARENT_HOOK_FAILED: ${error62 instanceof Error ? error62.message : String(error62)}
21597
- `);
21598
- process.exitCode = 1;
21599
- }
21600
- }
21601
21493
  async function runClaudeHookMain(profile, root = claudeHookRoot(profile)) {
21602
21494
  try {
21603
21495
  const event = JSON.parse(await readStdin());
@@ -21670,6 +21562,133 @@ function setupNodeExecutable(executable = process.execPath) {
21670
21562
  return node2;
21671
21563
  }
21672
21564
 
21565
+ // ../../node_modules/aiterm-steer-delivery/dist/aiterm-provider.js
21566
+ import { spawn as spawn2 } from "node:child_process";
21567
+ import * as fs7 from "node:fs";
21568
+ import * as os2 from "node:os";
21569
+ import * as path10 from "node:path";
21570
+ var AITERM_PARENT_DELIVERY_SCHEMA = "aiterm.parent-delivery.v1";
21571
+ var AITERM_DELIVERY_PROVIDER_SCHEMA = "aiterm.delivery-provider.v1";
21572
+ var recordSchema = external_exports.object({
21573
+ schema: external_exports.literal(AITERM_DELIVERY_PROVIDER_SCHEMA),
21574
+ version: external_exports.string().min(1),
21575
+ node: external_exports.string().refine((value) => path10.isAbsolute(value)),
21576
+ cli: external_exports.string().refine((value) => path10.isAbsolute(value))
21577
+ }).strict();
21578
+ var isFile = (file2) => {
21579
+ try {
21580
+ return fs7.statSync(file2).isFile();
21581
+ } catch {
21582
+ return false;
21583
+ }
21584
+ };
21585
+ function findAitermDeliveryProvider(options = {}) {
21586
+ const env = options.env ?? process.env;
21587
+ const explicit = options.cli ?? env.AITERM_PARENT_DELIVERY_CLI;
21588
+ if (explicit) {
21589
+ return path10.isAbsolute(explicit) && isFile(explicit) ? { node: options.node ?? process.execPath, cli: explicit, version: null, source: "explicit" } : null;
21590
+ }
21591
+ const home2 = options.home ?? env.HOME ?? os2.homedir();
21592
+ try {
21593
+ const record3 = recordSchema.parse(JSON.parse(fs7.readFileSync(path10.join(home2, ".config", "aiterm-mcp", "delivery-provider.json"), "utf8")));
21594
+ const node2 = options.node ?? record3.node;
21595
+ if (isFile(record3.cli) && isFile(node2))
21596
+ return { node: node2, cli: record3.cli, version: record3.version, source: "record" };
21597
+ } catch {
21598
+ }
21599
+ for (const directory2 of (env.PATH ?? env.Path ?? "").split(path10.delimiter).filter(Boolean)) {
21600
+ if (process.platform === "win32") {
21601
+ const cli = path10.join(directory2, "node_modules", "aiterm-mcp", "dist", "parent-delivery-cli.js");
21602
+ if (isFile(path10.join(directory2, "aiterm-parent-delivery.cmd")) && isFile(cli))
21603
+ return { node: options.node ?? process.execPath, cli, version: null, source: "path" };
21604
+ continue;
21605
+ }
21606
+ const shim = path10.join(directory2, "aiterm-parent-delivery");
21607
+ if (!isFile(shim))
21608
+ continue;
21609
+ try {
21610
+ return { node: options.node ?? process.execPath, cli: fs7.realpathSync(shim), version: null, source: "path" };
21611
+ } catch {
21612
+ }
21613
+ }
21614
+ return null;
21615
+ }
21616
+ var unavailable = (message, outcomeUnknown = false) => new CodexDeliveryError("AITERM_PROVIDER_UNAVAILABLE", message, outcomeUnknown);
21617
+ async function callAiterm(args, input2, options, sends) {
21618
+ const provider = findAitermDeliveryProvider(options);
21619
+ if (!provider) {
21620
+ throw unavailable("Aiterm\u306E\u914D\u9001\u306E\u5165\u53E3\uFF08aiterm-parent-delivery\uFF09\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093\u3002Aiterm 0.56.0\u4EE5\u4E0A\u3092\u5C0E\u5165\u3057\u3001aiterm-setup\u3092\u5B9F\u884C\u3057\u3066\u304F\u3060\u3055\u3044\u3002\u672C\u6587\u306F\u9001\u3063\u3066\u3044\u307E\u305B\u3093");
21621
+ }
21622
+ const result = await new Promise((resolve2) => {
21623
+ let stdout = "";
21624
+ let started = false;
21625
+ let settled = false;
21626
+ const finish = (failure2) => {
21627
+ if (settled)
21628
+ return;
21629
+ settled = true;
21630
+ clearTimeout(timer);
21631
+ resolve2({ stdout, started, failure: failure2 });
21632
+ };
21633
+ const child = spawn2(provider.node, [provider.cli, ...args], { stdio: ["pipe", "pipe", "ignore"], env: options.env ?? process.env, windowsHide: true });
21634
+ const timer = setTimeout(() => {
21635
+ child.kill("SIGKILL");
21636
+ finish("\u6642\u9593\u5185\u306B\u8FD4\u308A\u304C\u3042\u308A\u307E\u305B\u3093");
21637
+ }, options.timeout_ms ?? 9e4);
21638
+ child.once("spawn", () => {
21639
+ started = true;
21640
+ });
21641
+ child.once("error", (error62) => finish(`\u8D77\u52D5\u3067\u304D\u307E\u305B\u3093\uFF08${error62.code ?? "unknown"}\uFF09`));
21642
+ child.stdout.setEncoding("utf8").on("data", (chunk) => {
21643
+ stdout += chunk;
21644
+ });
21645
+ child.stdin.on("error", () => {
21646
+ });
21647
+ child.once("close", () => finish(null));
21648
+ child.stdin.end(input2 ?? "");
21649
+ });
21650
+ if (result.failure)
21651
+ throw unavailable(`Aiterm\u306E\u914D\u9001\u306E\u5165\u53E3\u3092\u547C\u3079\u307E\u305B\u3093: ${result.failure}`, sends && result.started);
21652
+ let value;
21653
+ try {
21654
+ value = JSON.parse(result.stdout.split("\n").filter(Boolean).at(-1) ?? "");
21655
+ } catch {
21656
+ throw unavailable("Aiterm\u306E\u914D\u9001\u306E\u5165\u53E3\u304C\u3001\u8AAD\u3081\u306A\u3044\u8FD4\u308A\u3092\u51FA\u3057\u307E\u3057\u305F", sends);
21657
+ }
21658
+ if (value?.schema !== AITERM_PARENT_DELIVERY_SCHEMA || typeof value.ok !== "boolean") {
21659
+ throw unavailable("Aiterm\u306E\u914D\u9001\u306E\u5165\u53E3\u306E\u8FD4\u308A\u306E\u5F62\u304C\u5408\u3044\u307E\u305B\u3093\u3002Aiterm\u3092\u66F4\u65B0\u3057\u3066\u304F\u3060\u3055\u3044", sends);
21660
+ }
21661
+ if (!value.ok) {
21662
+ const code = typeof value.code === "string" ? value.code : "AITERM_PROVIDER_FAILED";
21663
+ const message = typeof value.message === "string" ? value.message : "Aiterm\u304C\u914D\u9001\u3092\u65AD\u308A\u307E\u3057\u305F";
21664
+ throw new CodexDeliveryError(code, message.startsWith(`${code}: `) ? message.slice(code.length + 2) : message, value.outcome_unknown === true);
21665
+ }
21666
+ return value;
21667
+ }
21668
+ var target = (parent) => ["--thread", parent.thread_id, "--codex-home", parent.codex_home];
21669
+ async function submitCodexParentAnswerViaAiterm(parent, deliveryId, text, options = {}) {
21670
+ external_exports.uuid().parse(deliveryId);
21671
+ const value = await callAiterm(["codex", "submit", ...target(parent), "--delivery", deliveryId, "--text-file", "-"], text, options, true);
21672
+ if (!(value.queued_submission_id === null || typeof value.queued_submission_id === "string")) {
21673
+ throw unavailable("Aiterm\u306E\u914D\u9001\u306E\u5165\u53E3\u306E\u8FD4\u308A\u306E\u5F62\u304C\u5408\u3044\u307E\u305B\u3093\u3002Aiterm\u3092\u66F4\u65B0\u3057\u3066\u304F\u3060\u3055\u3044", true);
21674
+ }
21675
+ return { queued_submission_id: value.queued_submission_id };
21676
+ }
21677
+ async function codexDeliveryDetailViaAiterm(parent, deliveryId, options = {}) {
21678
+ external_exports.uuid().parse(deliveryId);
21679
+ const value = await callAiterm(["codex", "state", ...target(parent), "--delivery", deliveryId], null, options, false);
21680
+ return {
21681
+ state: value.state ?? null,
21682
+ hook: value.hook ?? null,
21683
+ turn_id: value.turn_id ?? null,
21684
+ queued: value.queued ?? null,
21685
+ ...typeof value.queue_error === "string" ? { queue_error: value.queue_error } : {}
21686
+ };
21687
+ }
21688
+ async function codexDeliveryStateViaAiterm(parent, deliveryId, options = {}) {
21689
+ return (await codexDeliveryDetailViaAiterm(parent, deliveryId, options)).state;
21690
+ }
21691
+
21673
21692
  // ../../node_modules/aiterm-steer-delivery/dist/codex-setup.js
21674
21693
  import * as fs8 from "node:fs";
21675
21694
  import * as path11 from "node:path";
@@ -21691,11 +21710,11 @@ function planCodexParentHooks(file2, command2, previousCommand) {
21691
21710
  throw error62;
21692
21711
  }
21693
21712
  }
21694
- const target = fs8.existsSync(file2) ? fs8.realpathSync(file2) : file2;
21713
+ const target2 = fs8.existsSync(file2) ? fs8.realpathSync(file2) : file2;
21695
21714
  let current = {};
21696
- if (fs8.existsSync(target)) {
21715
+ if (fs8.existsSync(target2)) {
21697
21716
  try {
21698
- current = JSON.parse(fs8.readFileSync(target, "utf8"));
21717
+ current = JSON.parse(fs8.readFileSync(target2, "utf8"));
21699
21718
  } catch {
21700
21719
  throw new SetupError("codex_hook_config_invalid", "Codex\u306Ehook\u8A2D\u5B9AJSON\u3092\u8AAD\u3081\u307E\u305B\u3093");
21701
21720
  }
@@ -21743,7 +21762,7 @@ function planCodexParentHooks(file2, command2, previousCommand) {
21743
21762
  delete hooks[event];
21744
21763
  }
21745
21764
  const next = { ...current, hooks };
21746
- return { target, current, next, changed: !isDeepStrictEqual2(current, next), moves, owned: ownedAt };
21765
+ return { target: target2, current, next, changed: !isDeepStrictEqual2(current, next), moves, owned: ownedAt };
21747
21766
  }
21748
21767
  function writeCodexHookPlan(profile, plan) {
21749
21768
  if (!plan.changed)
@@ -21779,11 +21798,11 @@ async function applyCodexHookPlan(profile, plan, codexHome, executable) {
21779
21798
  const key = (event, [g, h]) => `${prefix}:${snake(event)}:${g}:${h}`;
21780
21799
  const state = (await request("config/read", { includeLayers: false }))?.config?.hooks?.state ?? {};
21781
21800
  const configFile = path11.join(codexHome, "config.toml");
21782
- const field = (target, name, value) => ({ keyPath: `hooks.state.${JSON.stringify(target)}.${name}`, value, mergeStrategy: "replace" });
21801
+ const field = (target2, name, value) => ({ keyPath: `hooks.state.${JSON.stringify(target2)}.${name}`, value, mergeStrategy: "replace" });
21783
21802
  const copy = plan.moves.filter((move) => move.to).flatMap((move) => {
21784
21803
  const saved = state[key(move.event, move.from)];
21785
- const target = key(move.event, move.to);
21786
- return saved && typeof saved === "object" ? [field(target, "trusted_hash", saved.trusted_hash ?? null), field(target, "enabled", saved.enabled ?? null)] : [{ keyPath: `hooks.state.${JSON.stringify(target)}`, value: null, mergeStrategy: "replace" }];
21804
+ const target2 = key(move.event, move.to);
21805
+ return saved && typeof saved === "object" ? [field(target2, "trusted_hash", saved.trusted_hash ?? null), field(target2, "enabled", saved.enabled ?? null)] : [{ keyPath: `hooks.state.${JSON.stringify(target2)}`, value: null, mergeStrategy: "replace" }];
21787
21806
  });
21788
21807
  if (copy.length)
21789
21808
  await request("config/batchWrite", { edits: copy, filePath: configFile });
@@ -21958,6 +21977,7 @@ export {
21958
21977
  PROFILE,
21959
21978
  claudeHookRoot,
21960
21979
  cursorHookRoot,
21980
+ CodexDeliveryError,
21961
21981
  withoutBom,
21962
21982
  setupNodeExecutable,
21963
21983
  safeParse,
@@ -21981,7 +22001,8 @@ export {
21981
22001
  iso_exports,
21982
22002
  codexParentFromRequest,
21983
22003
  withCodexReceiver,
21984
- verifyCodexParent,
22004
+ submitCodexParentAnswerViaAiterm,
22005
+ codexDeliveryStateViaAiterm,
21985
22006
  configureCodexSteer,
21986
22007
  claudeParentFromRequest,
21987
22008
  mergeClaudeParentHooks,
@@ -22004,7 +22025,6 @@ export {
22004
22025
  channelMarker,
22005
22026
  handleCursorChannelHook,
22006
22027
  channelReceiveProcess,
22007
- runCodexHookMain,
22008
22028
  runClaudeHookMain,
22009
22029
  runChannelReceiveMain
22010
22030
  };