aiterm-steer-delivery 0.4.3 → 0.4.4

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,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.4
4
+
5
+ channelへ同じ配送IDの本文を送り直した時に、親へ同じ文が2回出る事があったのを直します。関数の形、置き場の作り、符号は変わりません。
6
+
7
+ - **起きていた事。** `sendToChannel`は、同じ配送IDの本文を2回は受け付けない(`CHANNEL_DELIVERY_DUPLICATE`)。ところが見ていたのは、受け口が取った後の記録(`claims`・`emitted`)だけだった。前の本文がまだ受信箱にある間(会話が番の途中で待機が居ない間、会話が止まっている間)に同じ配送IDで送ると、断らずに2通目も受信箱へ入り、受け口が1通ずつ取り出して、親へ同じ文が2回出た。受信箱の中の重なりを断る枝はあったが、fileの名前に時刻と通し番号が入るので、当たる事が無かった。
8
+ - **受信箱にある間も断る。** `sendToChannel`は、受信箱・`claims`・`emitted`の順(本文が移る向き)に同じ配送IDを探し、あれば`CHANNEL_DELIVERY_DUPLICATE`で断る。本文は足さない。前の本文の状態(`channelDeliveryState`)は変わらない。
9
+ - **二重に入っていた分は、親へ二度出さない。** 0.4.3までの送信が受信箱へ二重に入れた本文や、同じ配送IDを2つのprocessが同時に送った時の分は、受け口が取り出す時に見分ける。同じ配送IDがすでに親へ出ていれば(`emitted`の記録がある)、取り出した分は出さずに捨てる。`withdrawFromChannel`も、すでに親へ出た配送IDには`false`を返す(今までは、残っていた2通目を取り下げて`true`を返した)。
10
+ - 製品の側で変わる事: 同じchannelへ同じ配送IDで送り直す製品は、前の本文がまだ取り出されていない時にも`CHANNEL_DELIVERY_DUPLICATE`を受け取る。その時の状態は`queued`。今までは2通目が入って`queued`で返っていた。
11
+ - 通話MCP(call-bridge)が直接呼んでいる関数・符号・置き場の形を押さえる試験(`test/call-bridge-surface.test.mjs`)を足した。
12
+
3
13
  ## 0.4.3
4
14
 
5
15
  Windowsで、consoleを持たないprocessから呼ぶと端末の窓が一瞬出る所を直します。APIと返りは変わりません。
package/README.ja.md CHANGED
@@ -213,6 +213,8 @@ channel の配送状態:
213
213
  | `unknown` | 受け口が取った後に止まりました。親に届いたかどうか分かりません。 |
214
214
  | `withdrawn` | 受け口が取る前に `withdrawFromChannel` で取り下げました。 |
215
215
 
216
+ channel は、同じ配送IDを1回だけ受け付けます。同じ channel へ同じ配送IDでもう一度送ると、前の本文がどの状態でも(`queued` の間も)`CHANNEL_DELIVERY_DUPLICATE` で断ります。本文は足されません。前の本文がどこにあるかは `channelDeliveryState` で読めます。
217
+
216
218
  Codex の channel では、`sendToChannel` が公式キューの `queued_submission_id` とともに `submitted` を返し、`channelDeliveryState` は `null` を返します。
217
219
 
218
220
  既知の制限: `agent_id` を持つ Claude Code の会話(`--agent` で起動したもの、ネイティブのサブエージェント)は、親として対応していません。
package/README.md CHANGED
@@ -227,6 +227,8 @@ Channel delivery states:
227
227
  | `unknown` | The receiver stopped after claiming it; it may or may not have reached the parent. |
228
228
  | `withdrawn` | Taken back with `withdrawFromChannel` before any receiver claimed it. |
229
229
 
230
+ A channel accepts a delivery id once. Sending the same id to the same channel again is refused with `CHANNEL_DELIVERY_DUPLICATE`, whichever state the first one is in (including `queued`); nothing is added, and `channelDeliveryState` tells you where the first one is.
231
+
230
232
  On a Codex channel, `sendToChannel` returns `submitted` with the official queue's `queued_submission_id`, and `channelDeliveryState` returns `null`.
231
233
 
232
234
  Known limit: Claude Code sessions that carry an `agent_id` (started with `--agent`, or native subagents) are not supported as parents.
package/dist/channel.js CHANGED
@@ -106,6 +106,10 @@ export async function sendToChannel(profile, channelId, deliveryId, text, runtim
106
106
  return { state: "submitted", queued_submission_id: result.queued_submission_id };
107
107
  }
108
108
  const dir = channelDir(profile, channelId);
109
+ // 本文は 受信箱 → claims → emitted の順に移る。同じ向きに見るので、移っている途中の本文も見落とさない。
110
+ if (fs.readdirSync(path.join(dir, "inbox")).some(entry => entry.endsWith(`-${deliveryId}.json`))) {
111
+ throw new ChannelError("CHANNEL_DELIVERY_DUPLICATE", "同じ配送IDの本文がすでに受信箱にあります");
112
+ }
109
113
  for (const sub of ["claims", "emitted"]) {
110
114
  if (fs.existsSync(path.join(dir, sub, `${deliveryId}.json`)))
111
115
  throw new ChannelError("CHANNEL_DELIVERY_DUPLICATE", "同じ配送IDの本文はすでに受け取られています");
@@ -179,9 +183,20 @@ export function withdrawFromChannel(profile, channelId, deliveryId) {
179
183
  return false;
180
184
  throw error;
181
185
  }
186
+ if (alreadyEmitted(dir, deliveryId)) {
187
+ fs.rmSync(claim, { force: true });
188
+ return false;
189
+ }
182
190
  writeJson0600(claim, { delivery_id: deliveryId, state: "withdrawn", at: new Date().toISOString() });
183
191
  return true;
184
192
  }
193
+ /**
194
+ * 受信箱から取った本文と同じ配送IDが、すでに親へ出ているか。出し終えた記録(emitted)はclaimを消す前に書くので、
195
+ * claimを取れた後に見れば確実に分かる。同じ配送IDが受信箱に二重に入っていた時(0.4.3までの送信)に、二度目を親へ出さないため。
196
+ */
197
+ function alreadyEmitted(dir, deliveryId) {
198
+ return fs.existsSync(path.join(dir, "emitted", `${deliveryId}.json`));
199
+ }
185
200
  /** 受信箱の本文を到着順にclaimする。hard linkの作成で、同じ本文を二つの受け口が取らないようにする。 */
186
201
  function claimPending(profile, channelId, by, limit = Infinity) {
187
202
  const dir = channelDir(profile, channelId);
@@ -213,6 +228,10 @@ function claimPending(profile, channelId, by, limit = Infinity) {
213
228
  continue;
214
229
  throw error;
215
230
  }
231
+ if (alreadyEmitted(dir, item.delivery_id)) {
232
+ fs.rmSync(claim, { force: true });
233
+ continue;
234
+ }
216
235
  identity ??= processIdentity(process.pid) ?? "unknown";
217
236
  writeJson0600(claim, { ...item, state: "sending", by, pid: process.pid, started_identity: identity });
218
237
  claimed.push({ channel_id: channelId, item, claim, dir });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aiterm-steer-delivery",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
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",