aiterm-steer-delivery 0.4.2 → 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 +18 -0
- package/README.ja.md +2 -0
- package/README.md +2 -0
- package/dist/channel.js +19 -0
- package/dist/codex-binary.js +5 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
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
|
+
|
|
13
|
+
## 0.4.3
|
|
14
|
+
|
|
15
|
+
Windowsで、consoleを持たないprocessから呼ぶと端末の窓が一瞬出る所を直します。APIと返りは変わりません。
|
|
16
|
+
|
|
17
|
+
- **起きていた事。** Windowsでは、consoleを持たないprocess(Nodeの`detached: true`で切り離したprocess、予定の仕事から起きたprocessなど)がconsoleの子を窓を隠さずに起こすと、端末の窓(Windows Terminal)が一瞬出る。Codexの実行ファイルを探す所(`resolveCodexExecutable`の`where codex`)に`windowsHide`が無かった。ここを通るのは、`CODEX_BIN`も`~/.local/bin/codex`も無く、製品のCodex hookが有効でない(hookの設定に実行ファイルの場所が無い)時。0.4.0から、寝ている会話を起こす見張りが切り離したprocessとして動くので、その組で窓が出た(Windowsの実物で、窓が1つ出る事と、直した後は出ない事を測った)。hookが有効な製品(実行ファイルの場所が設定にある)では通らず、見張りの本番の道は窓を出していなかった。
|
|
18
|
+
- **子のprocessを起こす所の全部に`windowsHide`を付けた。** `where codex`のほか、macOSの導入先の確かめ(`codesign`・`--version`・`mdfind`・`PlistBuddy`)にも付ける(Windowsでは通らない所。抜けを無くすため)。
|
|
19
|
+
- 抜けを見張る試験(`test/windows-hide.test.mjs`)を足した。子を起こす呼び出しで`windowsHide`の無い物があると落ちる。
|
|
20
|
+
|
|
3
21
|
## 0.4.2
|
|
4
22
|
|
|
5
23
|
Claude Codeが起動し直して同じ会話を再開した後、channelの本文が届かなかったのを直します。今までの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/dist/codex-binary.js
CHANGED
|
@@ -74,7 +74,8 @@ export function resolveCodexExecutable() {
|
|
|
74
74
|
const fallback = path.join(home, ".local", "bin", "codex");
|
|
75
75
|
if (isUsableAgentExecutableFile(fallback))
|
|
76
76
|
return resolveWindowsCodexShim(fallback);
|
|
77
|
-
|
|
77
|
+
// windowsHide: consoleを持たないprocess(切り離した見張り、hookから切り離した処理)から起こすと、隠さない子は窓を一瞬出す。
|
|
78
|
+
const w = spawnSync(isWin ? "where" : "which", ["codex"], { encoding: "utf8", timeout: 5000, windowsHide: true });
|
|
78
79
|
if (w.status === 0 && (w.stdout ?? "").trim()) {
|
|
79
80
|
const found = w.stdout.trim().split(/\r?\n/).filter(Boolean);
|
|
80
81
|
const ordered = isWin
|
|
@@ -103,7 +104,7 @@ export function codexSpawnEnv(env = process.env, node = process.execPath, platfo
|
|
|
103
104
|
return listed ? env : { ...env, [key]: current ? `${directory}${delimiter}${current}` : directory };
|
|
104
105
|
}
|
|
105
106
|
function command(executable, args) {
|
|
106
|
-
const result = spawnSync(executable, args, { encoding: "utf8", timeout: 15_000, env: codexSpawnEnv() });
|
|
107
|
+
const result = spawnSync(executable, args, { encoding: "utf8", timeout: 15_000, env: codexSpawnEnv(), windowsHide: true });
|
|
107
108
|
if (result.error || result.status !== 0)
|
|
108
109
|
throw new SetupError("codex_steer_setup_failed", `${path.basename(executable)}を実行できません`);
|
|
109
110
|
return result.stdout.trim();
|
|
@@ -121,13 +122,13 @@ export function desktopBundledCodex(app) {
|
|
|
121
122
|
}
|
|
122
123
|
/** macOSの公式Codex Desktopが同梱するCLI。署名と版を確かめる。 */
|
|
123
124
|
export function findDesktopBinary() {
|
|
124
|
-
const search = spawnSync("/usr/bin/mdfind", ["kMDItemCFBundleIdentifier == 'com.openai.codex'"], { encoding: "utf8", timeout: 10_000 });
|
|
125
|
+
const search = spawnSync("/usr/bin/mdfind", ["kMDItemCFBundleIdentifier == 'com.openai.codex'"], { encoding: "utf8", timeout: 10_000, windowsHide: true });
|
|
125
126
|
const candidates = [...new Set(["/Applications/Codex.app", "/Applications/ChatGPT.app", ...(search.status === 0 ? search.stdout.trim().split("\n") : [])])];
|
|
126
127
|
const found = candidates.flatMap(app => {
|
|
127
128
|
const binary = app ? desktopBundledCodex(app) : null;
|
|
128
129
|
if (!binary)
|
|
129
130
|
return [];
|
|
130
|
-
const result = spawnSync("/usr/libexec/PlistBuddy", ["-c", "Print:CFBundleIdentifier", path.join(app, "Contents", "Info.plist")], { encoding: "utf8", timeout: 5_000 });
|
|
131
|
+
const result = spawnSync("/usr/libexec/PlistBuddy", ["-c", "Print:CFBundleIdentifier", path.join(app, "Contents", "Info.plist")], { encoding: "utf8", timeout: 5_000, windowsHide: true });
|
|
131
132
|
return result.status === 0 && result.stdout.trim() === "com.openai.codex" ? [binary] : [];
|
|
132
133
|
});
|
|
133
134
|
if (found.length !== 1)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-steer-delivery",
|
|
3
|
-
"version": "0.4.
|
|
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",
|