aiterm-steer-delivery 0.4.6 → 0.4.7

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.7
4
+
5
+ Codexの受け口が断った配送の所有記録が残り、同じ配送IDの渡し直しが通らなくなっていたのを直します。関数の名前・引数・返りの形と置き場の作りは変わりません。符号が1つ増えます。
6
+
7
+ - **起きていた事。** `submitCodexParentAnswer`(CLIの`codex submit`)は、hookが有効な製品では、送る前に所有記録
8
+ (`inputs/<homeのhash>/<会話>/pending/<配送ID>.json`)を書く。送信が断られた後も、この記録と`settled`が残っていた。
9
+ 記録を片付けるのは、その会話で走るhook(PostToolUse/Stop)だけ。片付け済み(archived)の会話や止まっている会話ではhookが走らないので、
10
+ 記録が残り続け、同じ配送IDの渡し直しが`EEXIST: file already exists`(素のファイルの誤り)で失敗していた。
11
+ 2026-10-13、片付け済みの会話へ入れて`CODEX_RECEIVER_REJECTED`で断られた配送が、`codex unarchive`で会話を戻した後も通らなかった。
12
+ - **公式キューへ入らなかった配送の所有記録は、送信が自分で消す。** 受け口が断った時(`CODEX_RECEIVER_REJECTED`)と、キューへ頼む前に止まった時
13
+ (Codexを起こせない、`initialize`が返らない・断られる)。`outcome_unknown`がfalseの失敗の後は、`pending`も`settled`も残らず、同じ配送IDで送り直せる。
14
+ - **受け付けたか分からない失敗(`outcome_unknown`がtrue)の後と、受け付けた後は、今までどおり記録を残す。** キューに入っているかも知れない本文を、
15
+ hookが取り出せるようにするため。
16
+ - **記録が在る配送IDをもう一度渡した時の誤りが、符号つきになる。** `CODEX_DELIVERY_DUPLICATE`(`outcome_unknown`はfalse。この呼び出しでは何も送っていない)。
17
+ 今までは素の`EEXIST`で、CLIの返りの`code`は`EEXIST`、文面にファイルの場所が入っていた。
18
+ - 足した口: `withdrawCodexHookInput(home, thread, id, root)`(所有記録を自分で書いて送る製品が、キューに入らなかった時に呼ぶ)。
19
+ - **残っていた記録は本文を持たない**(配送ID・会話・本文のhashだけ)。会話が後で動いた時、hookはキューに在る項目しか取り出さないので、
20
+ 断られた配送の本文が会話へ入る事は無い。0.4.6までの記録が残っている会話では、次にhookが走った時に片付く。それまでは同じ配送IDが
21
+ `CODEX_DELIVERY_DUPLICATE`になる。
22
+ - 試験: 偽の受け口で、断り・キューの前の止まり・分からない失敗・受け付けた後・hookが無効な製品・前の版の残り。CLIの`codex submit`の返り。
23
+ 公式Codex 0.162.1で、片付け済みの会話に断られ、戻した後に同じ配送IDで入る所。
24
+
3
25
  ## 0.4.6
4
26
 
5
27
  動いている最中にNodeが更新されて前の版の場所が消えると、Nodeを起こせなくなっていたのを直します。関数の名前・引数・返りの形、置き場の作り、符号は変わりません。
package/README.ja.md CHANGED
@@ -143,6 +143,8 @@ await steer.verifyCodexParent(PROFILE, parent);
143
143
  const { queued_submission_id } = await steer.submitCodexParentAnswer(PROFILE, parent, deliveryId, text);
144
144
  ```
145
145
 
146
+ Codex への送信が失敗した時、本文が公式キューに入っていないと言える失敗(`outcome_unknown` が false。受け口が断った時、キューへ頼む前に止まった時)は、同じ配送IDでもう一度送れます。片付け済み(archived)の会話は Codex が `CODEX_RECEIVER_REJECTED` で断るので、`codex unarchive` で戻した後に同じ配送IDで送り直せます。受け付けた後と、受け付けたか分からない失敗(`outcome_unknown` が true)の後は、hook が有効な製品では、所有記録(`pending/<配送ID>.json`)が在る間、同じ配送IDを `CODEX_DELIVERY_DUPLICATE` で断り、何も送りません。配送IDは本文ごとに決め、別の本文で使い回しません。
147
+
146
148
  Claude Code は `claudeParentFromRequest`/`bindClaudeParentDelivery`/`submitClaudeParentAnswer`、Cursor は `cursorParentFromRequest`/`prepareCursorDelivery`/`submitCursorParentAnswer` で同じ流れになります。各 `…ParentFromRequest` は呼び出し元が別のクライアントなら `null` を返すので、順に試せます。Cursor では、hook が会話に結び付けられるよう、ツール結果に配送IDを入れます。`structuredContent` には `parent_delivery: { delivery_id }`、本文には `delivery_id=<uuid>` の行を書きます。
147
149
 
148
150
  Claude Code は、ツールの返りが誤り(`isError`)の時に `PostToolUse` の hook を走らせません。誤りで返す時は、返す前に `discardClaudeHookRequest(clientName, request.params._meta, claudeHookRoot(PROFILE))` を呼び、その呼び出しの置き場を消します。配送を結んだ置き場は消しません。呼ばなくても、残った置き場は1日後に次の依頼の hook が消します。
package/README.md CHANGED
@@ -143,6 +143,8 @@ await steer.verifyCodexParent(PROFILE, parent);
143
143
  const { queued_submission_id } = await steer.submitCodexParentAnswer(PROFILE, parent, deliveryId, text);
144
144
  ```
145
145
 
146
+ When a Codex submission fails and the text is known not to be in the official queue (`outcome_unknown` is false: the receiver rejected it, or the call stopped before asking the queue), you can submit again with the same delivery id. Codex rejects an archived thread with `CODEX_RECEIVER_REJECTED`, so after `codex unarchive` the same delivery id goes through. After an accepted submission, or a failure whose outcome is unknown (`outcome_unknown` is true), a product with hooks enabled gets `CODEX_DELIVERY_DUPLICATE` for the same delivery id while the ownership record (`pending/<delivery id>.json`) exists, and nothing is sent. Use one delivery id per text; never reuse an id for a different text.
147
+
146
148
  Claude Code and Cursor follow the same shape with `claudeParentFromRequest` / `bindClaudeParentDelivery` / `submitClaudeParentAnswer` and `cursorParentFromRequest` / `prepareCursorDelivery` / `submitCursorParentAnswer`. Each `…ParentFromRequest` returns `null` when the caller is a different client, so you can try them in turn. For Cursor, put the delivery id in your tool result, as `parent_delivery: { delivery_id }` in `structuredContent` and as a `delivery_id=<uuid>` line in the text, so the hook can bind it to the conversation.
147
149
 
148
150
  Claude Code does not run the `PostToolUse` hook when a tool result is an error (`isError`). When you return an error, call `discardClaudeHookRequest(clientName, request.params._meta, claudeHookRoot(PROFILE))` before returning, to remove that call's request directory. A directory with a bound delivery is kept. If you do not call it, the next request's hook removes the leftover after one day.
@@ -38,6 +38,8 @@ export declare const hookInputSchema: z.ZodObject<{
38
38
  }, z.core.$strict>;
39
39
  export declare function answerDigest(text: string): string;
40
40
  export declare function registerCodexHookInput(home: string, thread: string, id: string, text: string, root: string): void;
41
+ /** 公式キューへ入らなかった配送の所有記録を消す。呼ぶのは、その記録を書いた送信だけ。 */
42
+ export declare function withdrawCodexHookInput(home: string, thread: string, id: string, root: string): void;
41
43
  export declare function finishCodexHookSubmission(home: string, thread: string, id: string, root: string): void;
42
44
  export declare function codexHookDeliveryState(home: string, thread: string, id: string, root: string): "sending" | "unknown" | null;
43
45
  export declare function ownedCodexHooks(profile: ProductProfile, response: any, command: string, file: string): any[];
@@ -41,7 +41,20 @@ export function registerCodexHookInput(home, thread, id, text, root) {
41
41
  const directory = codexInputDirectory(root, home, thread);
42
42
  fs.mkdirSync(path.join(directory, "pending"), { recursive: true, mode: 0o700 });
43
43
  // 一つの配送IDを別の本文で再使用しない。送信前の所有記録は再送の指示にはしない。
44
- fs.writeFileSync(path.join(directory, "pending", `${id}.json`), JSON.stringify(input) + "\n", { flag: "wx", mode: 0o600 });
44
+ try {
45
+ fs.writeFileSync(path.join(directory, "pending", `${id}.json`), JSON.stringify(input) + "\n", { flag: "wx", mode: 0o600 });
46
+ }
47
+ catch (error) {
48
+ if (error.code !== "EEXIST")
49
+ throw error;
50
+ // 記録が在るのは、送っている最中・受け付けた後・受け付けたか分からない送信の後。この呼び出しでは何も送っていない。
51
+ throw new CodexDeliveryError("CODEX_DELIVERY_DUPLICATE", "同じ配送IDの所有記録がすでにあります。本文は送っていません");
52
+ }
53
+ }
54
+ /** 公式キューへ入らなかった配送の所有記録を消す。呼ぶのは、その記録を書いた送信だけ。 */
55
+ export function withdrawCodexHookInput(home, thread, id, root) {
56
+ // settledを書いていないので、hookはこの記録に触っていない(片付けるのはsettledが在る記録、取り出すのはキューに在る項目だけ)。
57
+ fs.rmSync(path.join(codexInputDirectory(root, home, thread), "pending", `${id}.json`), { force: true });
45
58
  }
46
59
  export function finishCodexHookSubmission(home, thread, id, root) {
47
60
  const directory = codexInputDirectory(root, home, thread);
@@ -4,10 +4,10 @@
4
4
  import { spawn } from "node:child_process";
5
5
  import { createInterface } from "node:readline";
6
6
  import * as path from "node:path";
7
- import { CodexDeliveryError } from "./errors.js";
7
+ import { CodexDeliveryError, SteerDeliveryError } from "./errors.js";
8
8
  import { codexHookDirectory } from "./profile.js";
9
9
  import { codexSpawnEnv, currentCodexDesktopBinary, realCodexHome, resolveCodexExecutable } from "./codex-binary.js";
10
- import { finishCodexHookSubmission, assertCodexHookParentCurrent, assertCodexHooksReady, readCodexHookConfig, registerCodexHookInput } from "./codex-hook-state.js";
10
+ import { finishCodexHookSubmission, assertCodexHookParentCurrent, assertCodexHooksReady, readCodexHookConfig, registerCodexHookInput, withdrawCodexHookInput } from "./codex-hook-state.js";
11
11
  import { startCodexWakeWatch } from "./codex-wake.js";
12
12
  /** modelの引数ではなく、CodexがMCP要求へ付けるmetadataだけを宛先にする。 */
13
13
  export function codexParentFromRequest(clientName, metadata) {
@@ -132,8 +132,10 @@ export async function submitCodexParentAnswer(profile, parent, deliveryId, text,
132
132
  if (hook)
133
133
  registerCodexHookInput(parent.codex_home, parent.thread_id, deliveryId, text, root);
134
134
  let accepted;
135
+ let asked = false;
135
136
  try {
136
137
  accepted = await withCodexReceiver(profile, parent, async (request) => {
138
+ asked = true;
137
139
  const result = await request("thread/queue/add", {
138
140
  threadId: parent.thread_id,
139
141
  input: [{ type: "text", text, text_elements: [] }],
@@ -145,10 +147,20 @@ export async function submitCodexParentAnswer(profile, parent, deliveryId, text,
145
147
  return { queued_submission_id: result.queuedSubmission.id };
146
148
  }, runtime);
147
149
  }
148
- finally {
149
- if (hook)
150
- finishCodexHookSubmission(parent.codex_home, parent.thread_id, deliveryId, root);
150
+ catch (error) {
151
+ if (hook) {
152
+ // 受け口が断った時と、キューへ頼む前に止まった時は、キューに入っていない。所有記録を残すと、hookが走るまで同じ配送IDの渡し直しが通らない
153
+ // (片付け済みの会話や止まっている会話では、hookが走らない)。受け付けたか分からない時は、hookが取り出せるように残す。
154
+ const maybeQueued = error instanceof SteerDeliveryError ? error.outcome_unknown : asked;
155
+ if (maybeQueued)
156
+ finishCodexHookSubmission(parent.codex_home, parent.thread_id, deliveryId, root);
157
+ else
158
+ withdrawCodexHookInput(parent.codex_home, parent.thread_id, deliveryId, root);
159
+ }
160
+ throw error;
151
161
  }
162
+ if (hook)
163
+ finishCodexHookSubmission(parent.codex_home, parent.thread_id, deliveryId, root);
152
164
  if (runtime?.wake ?? !runtime)
153
165
  startCodexWakeWatch(profile, parent, deliveryId);
154
166
  return accepted;
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { readRuntimeProcesses, readProcessIdentities, readProcessLineage, proces
5
5
  export { resolveWindowsPowerShell7, quotePowerShell, windowsPowerShellSync, windowsStartProcessArgumentList } from "./windows.js";
6
6
  export { setupNodeExecutable, liveNodeExecutable } from "./setup-node.js";
7
7
  export { realCodexHome, resolveCodexExecutable, codexSpawnEnv, desktopBundledCodex, findDesktopBinary, findWindowsCodexCache, findWindowsCodexBinary, findLinuxDesktopBinary, findCliBinary, findSteerBinary, platformDesktopFinder, currentCodexDesktopBinary, type DesktopBinaryFinder, } from "./codex-binary.js";
8
- export { codexHookConfigSchema, readCodexHookConfig, codexInputDirectory, hookInputSchema, answerDigest, registerCodexHookInput, finishCodexHookSubmission, codexHookDeliveryState, ownedCodexHooks, assertCodexHooksReady, assertCodexHookParentCurrent, type CodexHookConfig, } from "./codex-hook-state.js";
8
+ export { codexHookConfigSchema, readCodexHookConfig, codexInputDirectory, hookInputSchema, answerDigest, registerCodexHookInput, withdrawCodexHookInput, finishCodexHookSubmission, codexHookDeliveryState, ownedCodexHooks, assertCodexHooksReady, assertCodexHookParentCurrent, type CodexHookConfig, } from "./codex-hook-state.js";
9
9
  export { codexParentFromRequest, withCodexReceiver, verifyCodexParent, submitCodexParentAnswer, type CodexParent, type CodexParentThread, type CodexReceiverRuntime, } from "./codex-receiver.js";
10
10
  export { runCodexResultHook } from "./codex-hooks.js";
11
11
  export { readCodexTurnTail, codexThreadUrl, codexThreadOpener, windowsInteractiveSession, codexWakeDirectory, readCodexWakeResult, wakeCodexParentIfAsleep, codexWakeWatchEnabled, startCodexWakeWatch, runCodexWakeMain, serializeWakeProfile, CODEX_WAKE_PAYLOAD_ENV, type CodexTurnTail, type CodexThreadOpener, type CodexWakeOutcome, type CodexWakeResult, type CodexWakeOptions, } from "./codex-wake.js";
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ export { readRuntimeProcesses, readProcessIdentities, readProcessLineage, proces
7
7
  export { resolveWindowsPowerShell7, quotePowerShell, windowsPowerShellSync, windowsStartProcessArgumentList } from "./windows.js";
8
8
  export { setupNodeExecutable, liveNodeExecutable } from "./setup-node.js";
9
9
  export { realCodexHome, resolveCodexExecutable, codexSpawnEnv, desktopBundledCodex, findDesktopBinary, findWindowsCodexCache, findWindowsCodexBinary, findLinuxDesktopBinary, findCliBinary, findSteerBinary, platformDesktopFinder, currentCodexDesktopBinary, } from "./codex-binary.js";
10
- export { codexHookConfigSchema, readCodexHookConfig, codexInputDirectory, hookInputSchema, answerDigest, registerCodexHookInput, finishCodexHookSubmission, codexHookDeliveryState, ownedCodexHooks, assertCodexHooksReady, assertCodexHookParentCurrent, } from "./codex-hook-state.js";
10
+ export { codexHookConfigSchema, readCodexHookConfig, codexInputDirectory, hookInputSchema, answerDigest, registerCodexHookInput, withdrawCodexHookInput, finishCodexHookSubmission, codexHookDeliveryState, ownedCodexHooks, assertCodexHooksReady, assertCodexHookParentCurrent, } from "./codex-hook-state.js";
11
11
  export { codexParentFromRequest, withCodexReceiver, verifyCodexParent, submitCodexParentAnswer, } from "./codex-receiver.js";
12
12
  export { runCodexResultHook } from "./codex-hooks.js";
13
13
  export { readCodexTurnTail, codexThreadUrl, codexThreadOpener, windowsInteractiveSession, codexWakeDirectory, readCodexWakeResult, wakeCodexParentIfAsleep, codexWakeWatchEnabled, startCodexWakeWatch, runCodexWakeMain, serializeWakeProfile, CODEX_WAKE_PAYLOAD_ENV, } from "./codex-wake.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-steer-delivery",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "Aiterm's steer delivery as a library: deliver text to the parent AI session that called your MCP tool — steered into the running turn when it is busy, delivered normally when it is idle. Codex (official queue + sync hooks), Claude Code (asyncRewake hooks), Cursor (hooks + background receiver).",
5
5
  "type": "module",
6
6
  "license": "MIT",