aiterm-steer-delivery 0.1.12 → 0.1.13
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 +5 -0
- package/README.ja.md +20 -1
- package/README.md +20 -1
- package/dist/claude-inbox.d.ts +31 -0
- package/dist/claude-inbox.js +128 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.13
|
|
4
|
+
|
|
5
|
+
- `sendClaudeInbox`を公開する。ClaudeのSessionStartが渡すinbox socketとtokenへuserメッセージを1通送る。MCPを呼んでいない新規会話にも使え、既存のClaudeParent・channel・asyncRewake配送は変えない。Windowsはauthを必須とし、POSIXでもtokenを渡せる。
|
|
6
|
+
- raw投稿の書き込みを受付済みとはしない。利用製品がUserPromptSubmit等を照合する`confirm_acceptance`を渡し、確認できた時だけ`accepted`にする。書き込み前の失敗は`not_sent`、書き込み後の確認不能は`unknown`と`outcome_unknown:true`。token・本文・宛先を結果へ含めず、自動再送しない。
|
|
7
|
+
|
|
3
8
|
## 0.1.12
|
|
4
9
|
|
|
5
10
|
- Cursor親の背景受信(`runCursorReceive`)が、読み手の居ない時に回答を引き取らない。Cursorは受信processを切り離して起こすので、親が終わった後も受信processは残る。残ったprocessが回答を引き取り、送り主は誰も読んでいない回答を配送済みにしていた(実物のCursor CLI 2026.10.01で、席を再起動して20回中20回)。受信processは最長24時間残っていた。
|
package/README.ja.md
CHANGED
|
@@ -122,7 +122,7 @@ Cursor の親は、1回の回答の受信 process を切り離して起こすの
|
|
|
122
122
|
|
|
123
123
|
### 4. 届ける
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
MCPを呼んだ親への届け方は2つあります。
|
|
126
126
|
|
|
127
127
|
**1回の依頼に1つの答え**(Aiterm の使い方): MCP 要求から親を見分け、配送IDを結び付け、確定した本文を一度だけ送ります。
|
|
128
128
|
|
|
@@ -148,6 +148,25 @@ Claude Code は `Stop` のたびに待機を張り直します。Cursor はツ
|
|
|
148
148
|
|
|
149
149
|
marker と受信コマンドは、`structuredContent` だけでなくツール結果の**本文**にも書いてください。Cursor CLI のモデルは structured content を読みません。`steer.waitProcessCommandLine(steer.channelReceiveProcess(script, channel.channel_id))` で、受信コマンドをシェルの1行にできます(POSIX sh、Windows では PowerShell)。
|
|
150
150
|
|
|
151
|
+
### 新しいClaude会話へ送る
|
|
152
|
+
|
|
153
|
+
`sendClaudeInbox(target, text, options)` はClaude Codeの[会話のinbox](https://code.claude.com/docs/en/cross-session-messaging#the-sessions-inbox-socket)へuserメッセージを1通送ります。宛先の`SessionStart` hookで`CLAUDE_CODE_MESSAGING_SOCKET`と`CLAUDE_CODE_MESSAGING_TOKEN`を取得します。その会話がMCPを呼ぶ前にも使え、`ProductProfile`や`ClaudeParent`は要りません。
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
import { sendClaudeInbox } from "aiterm-steer-delivery";
|
|
157
|
+
|
|
158
|
+
const text = "作業を続けて";
|
|
159
|
+
const result = await sendClaudeInbox({ socket_path, token }, text, {
|
|
160
|
+
timeout_ms: 30_000,
|
|
161
|
+
// UserPromptSubmitの受領記録を観測する処理は、利用製品が用意します。
|
|
162
|
+
confirm_acceptance: signal => productReceipts.waitForPrompt({ session_id, text, signal }),
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
宛先はhookから得て、PIDから推測しません。Windowsではtokenが必須で、POSIXでも渡したtokenは先頭のauth行で送ります。tokenは非公開で扱います。`confirm_acceptance`は接続前に開始します。受領票の事前登録が必要なら呼出前に済ませ、対象sessionと今回の文を照合します。古い記録や時刻の変化だけでは確認しません。終了時は`AbortSignal`で観測を取り消します。`false`は未確認を意味します。
|
|
167
|
+
|
|
168
|
+
raw投稿には同じ接続上の受付票がありません。`accepted`はUserPromptSubmitなどの受領観測が一致した時だけ返し、作業の完了までは示しません。`not_sent`はメッセージの書き込みを試みていない場合です。書き込みを試みた後の失敗や確認不能は`unknown`と`outcome_unknown:true`を返します。観測処理を渡さなければ、書き込みが成功しても`unknown`です。自動再送はしません。Claudeの受信制御はそのまま適用されます。結果は`status`・`reason`・`outcome_unknown`だけで、token・本文・宛先を含めません。
|
|
169
|
+
|
|
151
170
|
## エラーと配送の状態
|
|
152
171
|
|
|
153
172
|
配送のエラーは `SteerDeliveryError`(`CodexDeliveryError`、`ClaudeDeliveryError`、`CursorDeliveryError`、`ChannelError`)で、次を持ちます。
|
package/README.md
CHANGED
|
@@ -122,7 +122,7 @@ They keep other products' and the user's hooks and their order, and back up the
|
|
|
122
122
|
|
|
123
123
|
### 4. Deliver
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
The MCP parent-delivery APIs offer two ways to deliver.
|
|
126
126
|
|
|
127
127
|
**One answer per request** (what Aiterm does): identify the parent from the MCP request, bind a delivery id, and submit the final text once.
|
|
128
128
|
|
|
@@ -148,6 +148,25 @@ Claude Code re-arms its waiter at every `Stop`. Cursor binds the channel with `s
|
|
|
148
148
|
|
|
149
149
|
Put both the marker and the receiver command in the **text** of your tool result, not only in `structuredContent`: the Cursor CLI model does not read structured content. `steer.waitProcessCommandLine(steer.channelReceiveProcess(script, channel.channel_id))` gives the command as one shell line (POSIX sh, or PowerShell on Windows).
|
|
150
150
|
|
|
151
|
+
### Send to a new Claude conversation
|
|
152
|
+
|
|
153
|
+
`sendClaudeInbox(target, text, options)` sends one user message to Claude Code's [session inbox](https://code.claude.com/docs/en/cross-session-messaging#the-sessions-inbox-socket). Capture `CLAUDE_CODE_MESSAGING_SOCKET` and `CLAUDE_CODE_MESSAGING_TOKEN` in the target's `SessionStart` hook. This API works before that conversation has called an MCP tool, and needs no `ProductProfile` or `ClaudeParent`.
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
import { sendClaudeInbox } from "aiterm-steer-delivery";
|
|
157
|
+
|
|
158
|
+
const text = "Continue the work.";
|
|
159
|
+
const result = await sendClaudeInbox({ socket_path, token }, text, {
|
|
160
|
+
timeout_ms: 30_000,
|
|
161
|
+
// Your product observes the target's UserPromptSubmit receipt.
|
|
162
|
+
confirm_acceptance: signal => productReceipts.waitForPrompt({ session_id, text, signal }),
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Capture the endpoint from the target hook; do not infer it from a PID. Windows requires a token; POSIX sends the authentication line when a token is supplied. Keep the token private. `confirm_acceptance` starts before connecting; arm any receipt registration before calling. Match the target session and this message, rather than an older receipt or merely a new timestamp. The observer receives an `AbortSignal` when the call finishes. Its `false` result means unconfirmed.
|
|
167
|
+
|
|
168
|
+
The raw inbox post has no same-connection acknowledgement proving conversation acceptance. `accepted` requires your observer to confirm receipt, for example at `UserPromptSubmit`; it does not prove task completion. `not_sent` means no message write was attempted. After a write is attempted, a failure or missing confirmation returns `unknown` with `outcome_unknown:true`. With no observer, even a successful write returns `unknown`. The library never retries. Claude's inbound controls still apply. The result contains only `status`, `reason`, and `outcome_unknown` and excludes the token, message, and endpoint.
|
|
169
|
+
|
|
151
170
|
## Errors and delivery states
|
|
152
171
|
|
|
153
172
|
Delivery errors are `SteerDeliveryError` (`CodexDeliveryError`, `ClaudeDeliveryError`, `CursorDeliveryError`, `ChannelError`) with:
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface ClaudeInboxTarget {
|
|
2
|
+
/** CLAUDE_CODE_MESSAGING_SOCKETの値。PIDから推測せず、宛先のSessionStartで取得する。 */
|
|
3
|
+
socket_path: string;
|
|
4
|
+
/** 宛先のCLAUDE_CODE_MESSAGING_TOKEN。Windowsでは必須。receiptやエラーには含めない。 */
|
|
5
|
+
token?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ClaudeInboxSendOptions {
|
|
8
|
+
/** 接続・書き込み・受領確認を合わせた期限。既定30秒。 */
|
|
9
|
+
timeout_ms?: number;
|
|
10
|
+
/**
|
|
11
|
+
* 接続前に開始する受領観測。対象sessionと今回の文のUserPromptSubmit等を照合してtrueを返す。
|
|
12
|
+
* falseは「まだ観測できていない」であり、未送信の証明ではない。終了時はsignalで取り消される。
|
|
13
|
+
* ライブラリは観測開始が解決するのを待たずに接続する。受信票の事前登録が必要なら、呼出元で登録を済ませておく。
|
|
14
|
+
*/
|
|
15
|
+
confirm_acceptance?: (signal: AbortSignal) => Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
export type ClaudeInboxSendResult = {
|
|
18
|
+
status: "accepted";
|
|
19
|
+
outcome_unknown: false;
|
|
20
|
+
reason: "receiver_confirmed";
|
|
21
|
+
} | {
|
|
22
|
+
status: "not_sent";
|
|
23
|
+
outcome_unknown: false;
|
|
24
|
+
reason: "invalid_request" | "token_required" | "connect_failed" | "confirmation_failed" | "timeout";
|
|
25
|
+
} | {
|
|
26
|
+
status: "unknown";
|
|
27
|
+
outcome_unknown: true;
|
|
28
|
+
reason: "unconfirmed" | "confirmation_failed" | "write_failed" | "timeout";
|
|
29
|
+
};
|
|
30
|
+
/** 明示した会話のinboxへ1通だけ送る。自動再送、他の宛先へのfallback、設定変更は行わない。 */
|
|
31
|
+
export declare function sendClaudeInbox(target: ClaudeInboxTarget, text: string, options?: ClaudeInboxSendOptions): Promise<ClaudeInboxSendResult>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// ClaudeがSessionStartへ渡すinboxへ1通送る。MCPの要求記録やasyncRewake hookは不要。
|
|
2
|
+
// raw user行には受付票が無い。書き込みを受付済みとはせず、呼出元の受領観測でのみacceptedにする。
|
|
3
|
+
import * as net from "node:net";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
/** 明示した会話のinboxへ1通だけ送る。自動再送、他の宛先へのfallback、設定変更は行わない。 */
|
|
6
|
+
export async function sendClaudeInbox(target, text, options = {}) {
|
|
7
|
+
if (!options || typeof options !== "object")
|
|
8
|
+
return { status: "not_sent", outcome_unknown: false, reason: "invalid_request" };
|
|
9
|
+
const timeout = options.timeout_ms ?? 30_000;
|
|
10
|
+
if (!target || typeof target.socket_path !== "string" || !target.socket_path || target.socket_path.includes("\0")
|
|
11
|
+
|| typeof text !== "string" || !text || !Number.isSafeInteger(timeout) || timeout < 1 || timeout > 300_000
|
|
12
|
+
|| (target.token !== undefined && (typeof target.token !== "string" || !target.token))
|
|
13
|
+
|| (options.confirm_acceptance !== undefined && typeof options.confirm_acceptance !== "function")
|
|
14
|
+
|| (process.platform !== "win32" && !path.isAbsolute(target.socket_path))) {
|
|
15
|
+
return { status: "not_sent", outcome_unknown: false, reason: "invalid_request" };
|
|
16
|
+
}
|
|
17
|
+
if (process.platform === "win32" && !target.token) {
|
|
18
|
+
return { status: "not_sent", outcome_unknown: false, reason: "token_required" };
|
|
19
|
+
}
|
|
20
|
+
const message = JSON.stringify({ type: "user", message: { role: "user", content: text } }) + "\n";
|
|
21
|
+
// Claudeの同一端末配送の上限より小さいフレームだけ送る。送信前に拒否する。
|
|
22
|
+
if (Buffer.byteLength(message) > 1_000_000) {
|
|
23
|
+
return { status: "not_sent", outcome_unknown: false, reason: "invalid_request" };
|
|
24
|
+
}
|
|
25
|
+
const auth = target.token === undefined ? "" : JSON.stringify({ type: "auth", token: target.token }) + "\n";
|
|
26
|
+
if (Buffer.byteLength(auth + message) > 1_000_000)
|
|
27
|
+
return { status: "not_sent", outcome_unknown: false, reason: "invalid_request" };
|
|
28
|
+
const controller = new AbortController();
|
|
29
|
+
return await new Promise(resolve => {
|
|
30
|
+
let settled = false;
|
|
31
|
+
let attempted = false;
|
|
32
|
+
let written = false;
|
|
33
|
+
let confirmed;
|
|
34
|
+
let confirmationFailed = false;
|
|
35
|
+
let socket;
|
|
36
|
+
const finish = (result) => {
|
|
37
|
+
if (settled)
|
|
38
|
+
return;
|
|
39
|
+
settled = true;
|
|
40
|
+
clearTimeout(timer);
|
|
41
|
+
controller.abort();
|
|
42
|
+
socket?.destroy();
|
|
43
|
+
resolve(result);
|
|
44
|
+
};
|
|
45
|
+
const unknown = (reason) => finish({ status: "unknown", outcome_unknown: true, reason });
|
|
46
|
+
const afterWrite = () => {
|
|
47
|
+
if (!written)
|
|
48
|
+
return;
|
|
49
|
+
if (confirmed === true)
|
|
50
|
+
finish({ status: "accepted", outcome_unknown: false, reason: "receiver_confirmed" });
|
|
51
|
+
else if (confirmationFailed)
|
|
52
|
+
unknown("confirmation_failed");
|
|
53
|
+
else if (!options.confirm_acceptance || confirmed === false)
|
|
54
|
+
unknown("unconfirmed");
|
|
55
|
+
};
|
|
56
|
+
const timer = setTimeout(() => {
|
|
57
|
+
if (attempted)
|
|
58
|
+
unknown("timeout");
|
|
59
|
+
else
|
|
60
|
+
finish({ status: "not_sent", outcome_unknown: false, reason: "timeout" });
|
|
61
|
+
}, timeout);
|
|
62
|
+
if (options.confirm_acceptance) {
|
|
63
|
+
// 観測側がthrow/rejectしても、書き込み後を未送信へ戻さない。
|
|
64
|
+
let observing;
|
|
65
|
+
try {
|
|
66
|
+
observing = options.confirm_acceptance(controller.signal);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
finish({ status: "not_sent", outcome_unknown: false, reason: "confirmation_failed" });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
Promise.resolve(observing).then(value => {
|
|
73
|
+
if (value === true && !attempted) {
|
|
74
|
+
// 今回の書き込み前に届いた「受付済み」は、今回の送信を証明できない。
|
|
75
|
+
finish({ status: "not_sent", outcome_unknown: false, reason: "confirmation_failed" });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
confirmed = value === true;
|
|
79
|
+
afterWrite();
|
|
80
|
+
}, () => {
|
|
81
|
+
if (!attempted) {
|
|
82
|
+
finish({ status: "not_sent", outcome_unknown: false, reason: "confirmation_failed" });
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
confirmationFailed = true;
|
|
86
|
+
afterWrite();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
socket = net.createConnection({ path: target.socket_path });
|
|
91
|
+
socket.once("error", () => {
|
|
92
|
+
if (attempted)
|
|
93
|
+
unknown("write_failed");
|
|
94
|
+
else
|
|
95
|
+
finish({ status: "not_sent", outcome_unknown: false, reason: "connect_failed" });
|
|
96
|
+
});
|
|
97
|
+
socket.once("connect", () => {
|
|
98
|
+
if (settled)
|
|
99
|
+
return;
|
|
100
|
+
attempted = true;
|
|
101
|
+
socket.end(auth + message, (error) => {
|
|
102
|
+
if (error)
|
|
103
|
+
unknown("write_failed");
|
|
104
|
+
else {
|
|
105
|
+
written = true;
|
|
106
|
+
afterWrite();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
socket.on("data", () => { }); // raw投稿には受付票の仕様が無い。任意の返信を成功と解釈しない。
|
|
111
|
+
socket.once("close", () => {
|
|
112
|
+
if (settled)
|
|
113
|
+
return;
|
|
114
|
+
if (!attempted)
|
|
115
|
+
finish({ status: "not_sent", outcome_unknown: false, reason: "connect_failed" });
|
|
116
|
+
else if (!written)
|
|
117
|
+
unknown("write_failed");
|
|
118
|
+
// 書き込み後の切断でも、別経路の受領確認を期限まで待つ。
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
if (attempted)
|
|
123
|
+
unknown("write_failed");
|
|
124
|
+
else
|
|
125
|
+
finish({ status: "not_sent", outcome_unknown: false, reason: "connect_failed" });
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { codexParentFromRequest, withCodexReceiver, verifyCodexParent, submitCod
|
|
|
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
12
|
export { claudeParentSchema, prepareClaudeHookRequest, claudeParentFromRequest, verifyClaudeParent, bindClaudeParentDelivery, closeClaudeParentSession, submitClaudeParentAnswer, runClaudeResultHook, type ClaudeParent, } from "./claude-receiver.js";
|
|
13
|
+
export { sendClaudeInbox, type ClaudeInboxTarget, type ClaudeInboxSendOptions, type ClaudeInboxSendResult, } from "./claude-inbox.js";
|
|
13
14
|
export { cursorParentSchema, isCursorMcpClient, cursorHooksFile, cursorParentHooksRegistered, verifyCursorParent, cursorParentFromRequest, prepareCursorDelivery, submitCursorParentAnswer, handleCursorHook, receiveCursorAnswer, type CursorParent, type CursorReceiveResult, type CursorReceiveReader, } from "./cursor-receiver.js";
|
|
14
15
|
export { cursorReceiveProcess, runCursorReceive, stdoutOutput, waitProcessCommandLine, type WaitProcess, type ReceiveOutput } from "./cursor-receive.js";
|
|
15
16
|
export { claudeParentHookEntries, mergeClaudeParentHooks, removeClaudeParentHooks, cursorParentHookCommand, mergeCursorParentHooks, removeCursorParentHooks, commandNamesFile, type HookRuntime, } from "./hook-setup.js";
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export { codexParentFromRequest, withCodexReceiver, verifyCodexParent, submitCod
|
|
|
12
12
|
export { runCodexResultHook } from "./codex-hooks.js";
|
|
13
13
|
export { codexHookCommand, processCodexHome, mergeCodexParentHooks, planCodexParentHooks, writeCodexHookPlan, applyCodexHookPlan, verifyCodexHookRegistration, configureCodexSteer, } from "./codex-setup.js";
|
|
14
14
|
export { claudeParentSchema, prepareClaudeHookRequest, claudeParentFromRequest, verifyClaudeParent, bindClaudeParentDelivery, closeClaudeParentSession, submitClaudeParentAnswer, runClaudeResultHook, } from "./claude-receiver.js";
|
|
15
|
+
export { sendClaudeInbox, } from "./claude-inbox.js";
|
|
15
16
|
export { cursorParentSchema, isCursorMcpClient, cursorHooksFile, cursorParentHooksRegistered, verifyCursorParent, cursorParentFromRequest, prepareCursorDelivery, submitCursorParentAnswer, handleCursorHook, receiveCursorAnswer, } from "./cursor-receiver.js";
|
|
16
17
|
export { cursorReceiveProcess, runCursorReceive, stdoutOutput, waitProcessCommandLine } from "./cursor-receive.js";
|
|
17
18
|
export { claudeParentHookEntries, mergeClaudeParentHooks, removeClaudeParentHooks, cursorParentHookCommand, mergeCursorParentHooks, removeCursorParentHooks, commandNamesFile, } from "./hook-setup.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-steer-delivery",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
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",
|