aiterm-steer-delivery 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.3
4
+
5
+ - **`discardClaudeHookRequest`を公開する。** 製品が、toolの返りを誤り(`isError`)にする時に、返す前に呼ぶ。その呼び出しの置き場(`<state_root>/claude-parent-hooks/<tool_use_id>/`)を消し、消したかを返す。Claude Codeは誤りの返りで`PostToolUse`を走らせないので、配送の無い呼び出しの片付けが走らず、`request.json`だけの置き場が1日後の見回りまで残っていた(連携元の本番で、引数の検査で断った呼び出しの置き場が残っているのを見た。Claude Code 2.1.291)。
6
+ - 配送を結んだ置き場(`delivery.json`がある)は消さない。送り手が待っているか、届かなかった時に原因を調べる材料になる。今までどおり見回りが後で消す。
7
+ - Claude Codeでない呼び出し元、`toolUseId`の無い要求、置き場の無い番号、この製品の依頼の記録でないfileが入ったdirectoryでは、何もせず`false`を返す。
8
+ - 投げない。消せなかった置き場は、今までどおり見回りが消す。
9
+ - 呼ばない製品の動きは変わらない。Claude側で断られた呼び出し(引数がtoolの定義に合わない)と打ち切られた呼び出しは、製品へ返りが渡らないので、今までどおり1日後の見回りが消す。
10
+
3
11
  ## 0.2.2
4
12
 
5
13
  Claude Codeの親への単発配送で、依頼ごとの置き場(`<state_root>/claude-parent-hooks/<tool_use_id>/`)が届いた後も残っていたのを片付けます。APIと記録の形は変わりません。
package/README.ja.md CHANGED
@@ -145,6 +145,8 @@ const { queued_submission_id } = await steer.submitCodexParentAnswer(PROFILE, pa
145
145
 
146
146
  Claude Code は `claudeParentFromRequest`/`bindClaudeParentDelivery`/`submitClaudeParentAnswer`、Cursor は `cursorParentFromRequest`/`prepareCursorDelivery`/`submitCursorParentAnswer` で同じ流れになります。各 `…ParentFromRequest` は呼び出し元が別のクライアントなら `null` を返すので、順に試せます。Cursor では、hook が会話に結び付けられるよう、ツール結果に配送IDを入れます。`structuredContent` には `parent_delivery: { delivery_id }`、本文には `delivery_id=<uuid>` の行を書きます。
147
147
 
148
+ Claude Code は、ツールの返りが誤り(`isError`)の時に `PostToolUse` の hook を走らせません。誤りで返す時は、返す前に `discardClaudeHookRequest(clientName, request.params._meta, claudeHookRoot(PROFILE))` を呼び、その呼び出しの置き場を消します。配送を結んだ置き場は消しません。呼ばなくても、残った置き場は1日後に次の依頼の hook が消します。
149
+
148
150
  **同じ会話へ何通も送る**(channel。例: Peertable がルームの発言を親へ届ける):
149
151
 
150
152
  ```js
package/README.md CHANGED
@@ -145,6 +145,8 @@ const { queued_submission_id } = await steer.submitCodexParentAnswer(PROFILE, pa
145
145
 
146
146
  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
147
 
148
+ 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.
149
+
148
150
  **Many messages to one conversation** (channels, e.g. Peertable's room messages to the parent):
149
151
 
150
152
  ```js
@@ -16,6 +16,13 @@ export declare function prepareClaudeHookRequest(input: unknown, root: string):
16
16
  * まだ出し終えていない置き場は、何日たっても残す(子が長く動いている配送)。1日は、届かなかった時に原因を調べる間。
17
17
  */
18
18
  export declare function sweepClaudeHookRequests(root: string, rows: readonly RuntimeProcess[], now?: number): number;
19
+ /**
20
+ * 誤りで返す呼び出しの置き場を消し、消したかを返す。製品は、toolの返りを誤り(`isError`)にする時に、返す前に呼ぶ。
21
+ * Claude Codeは誤りの返りでPostToolUseを走らせないので、配送の無い呼び出しの片付け(runClaudeResultHook)が走らない。
22
+ * 配送を結んだ置き場は消さない(届かなかった時に原因を調べる材料。見回りが後で消す)。
23
+ * 片付けの失敗でtoolの返りを変えないよう、投げない。消せなかった置き場は見回りが消す。
24
+ */
25
+ export declare function discardClaudeHookRequest(clientName: string | undefined, metadata: unknown, root: string): Promise<boolean>;
19
26
  /** 起動時envのsession IDは/clearで古くなるため、実際のPreToolUseとの相関だけを使う。 */
20
27
  export declare function claudeParentFromRequest(profile: ProductProfile, clientName: string | undefined, metadata: unknown, root: string): ClaudeParent | null;
21
28
  export declare function verifyClaudeParent(profile: ProductProfile, parent: ClaudeParent): void;
@@ -102,6 +102,30 @@ export function sweepClaudeHookRequests(root, rows, now = Date.now()) {
102
102
  }
103
103
  return removed;
104
104
  }
105
+ /**
106
+ * 誤りで返す呼び出しの置き場を消し、消したかを返す。製品は、toolの返りを誤り(`isError`)にする時に、返す前に呼ぶ。
107
+ * Claude Codeは誤りの返りでPostToolUseを走らせないので、配送の無い呼び出しの片付け(runClaudeResultHook)が走らない。
108
+ * 配送を結んだ置き場は消さない(届かなかった時に原因を調べる材料。見回りが後で消す)。
109
+ * 片付けの失敗でtoolの返りを変えないよう、投げない。消せなかった置き場は見回りが消す。
110
+ */
111
+ export async function discardClaudeHookRequest(clientName, metadata, root) {
112
+ if (clientName !== "claude-code")
113
+ return false;
114
+ const parsed = requestId.safeParse(metadata?.["claudecode/toolUseId"]);
115
+ if (!parsed.success)
116
+ return false;
117
+ const dir = path.join(root, parsed.data);
118
+ try {
119
+ const names = fs.readdirSync(dir);
120
+ if (names.includes("delivery.json") || !names.every(name => REQUEST_FILES.has(name) || name.endsWith(".tmp")))
121
+ return false;
122
+ await fs.promises.rm(dir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
123
+ return true;
124
+ }
125
+ catch {
126
+ return false;
127
+ }
128
+ }
105
129
  /** 起動時envのsession IDは/clearで古くなるため、実際のPreToolUseとの相関だけを使う。 */
106
130
  export function claudeParentFromRequest(profile, clientName, metadata, root) {
107
131
  if (clientName !== "claude-code")
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export { codexHookConfigSchema, readCodexHookConfig, codexInputDirectory, hookIn
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 { codexHookCommand, processCodexHome, mergeCodexParentHooks, planCodexParentHooks, writeCodexHookPlan, applyCodexHookPlan, verifyCodexHookRegistration, configureCodexSteer, type CodexHookMove, type CodexHookPlan, type CodexSteerAction, type CodexSteerResult, type CodexSteerRuntime, } from "./codex-setup.js";
12
- export { claudeParentSchema, prepareClaudeHookRequest, claudeParentFromRequest, verifyClaudeParent, bindClaudeParentDelivery, closeClaudeParentSession, submitClaudeParentAnswer, runClaudeResultHook, type ClaudeParent, } from "./claude-receiver.js";
12
+ export { claudeParentSchema, prepareClaudeHookRequest, claudeParentFromRequest, verifyClaudeParent, bindClaudeParentDelivery, closeClaudeParentSession, submitClaudeParentAnswer, runClaudeResultHook, discardClaudeHookRequest, type ClaudeParent, } from "./claude-receiver.js";
13
13
  export { sendClaudeInbox, type ClaudeInboxTarget, type ClaudeInboxSendOptions, type ClaudeInboxSendResult, } from "./claude-inbox.js";
14
14
  export { cursorParentSchema, isCursorMcpClient, cursorHooksFile, cursorParentHooksRegistered, verifyCursorParent, cursorParentFromRequest, prepareCursorDelivery, submitCursorParentAnswer, handleCursorHook, receiveCursorAnswer, type CursorParent, type CursorReceiveResult, type CursorReceiveReader, } from "./cursor-receiver.js";
15
15
  export { cursorReceiveProcess, runCursorReceive, stdoutOutput, waitProcessCommandLine, type WaitProcess, type ReceiveOutput } from "./cursor-receive.js";
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ export { codexHookConfigSchema, readCodexHookConfig, codexInputDirectory, hookIn
11
11
  export { codexParentFromRequest, withCodexReceiver, verifyCodexParent, submitCodexParentAnswer, } from "./codex-receiver.js";
12
12
  export { runCodexResultHook } from "./codex-hooks.js";
13
13
  export { codexHookCommand, processCodexHome, mergeCodexParentHooks, planCodexParentHooks, writeCodexHookPlan, applyCodexHookPlan, verifyCodexHookRegistration, configureCodexSteer, } from "./codex-setup.js";
14
- export { claudeParentSchema, prepareClaudeHookRequest, claudeParentFromRequest, verifyClaudeParent, bindClaudeParentDelivery, closeClaudeParentSession, submitClaudeParentAnswer, runClaudeResultHook, } from "./claude-receiver.js";
14
+ export { claudeParentSchema, prepareClaudeHookRequest, claudeParentFromRequest, verifyClaudeParent, bindClaudeParentDelivery, closeClaudeParentSession, submitClaudeParentAnswer, runClaudeResultHook, discardClaudeHookRequest, } from "./claude-receiver.js";
15
15
  export { sendClaudeInbox, } from "./claude-inbox.js";
16
16
  export { cursorParentSchema, isCursorMcpClient, cursorHooksFile, cursorParentHooksRegistered, verifyCursorParent, cursorParentFromRequest, prepareCursorDelivery, submitCursorParentAnswer, handleCursorHook, receiveCursorAnswer, } from "./cursor-receiver.js";
17
17
  export { cursorReceiveProcess, runCursorReceive, stdoutOutput, waitProcessCommandLine } from "./cursor-receive.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-steer-delivery",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
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",