aiterm-steer-delivery 0.4.0 → 0.4.2
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 +23 -2
- package/README.md +2 -2
- package/dist/channel.d.ts +9 -0
- package/dist/channel.js +19 -4
- package/dist/codex-wake.d.ts +4 -3
- package/dist/codex-wake.js +11 -15
- package/dist/hook-main.js +7 -0
- package/dist/hook-setup.d.ts +4 -1
- package/dist/hook-setup.js +14 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.2
|
|
4
|
+
|
|
5
|
+
Claude Codeが起動し直して同じ会話を再開した後、channelの本文が届かなかったのを直します。今までのAPIの返りは変わりません。
|
|
6
|
+
|
|
7
|
+
- **起きていた事。** channelは、開いた時のClaude Codeのprocess(pidと開始時刻)に結んである。待機(`runClaudeChannelWaiter`)は、その会話の開いているchannelのうち、結んだprocessが生きている物が1つも無いと、すぐ0で終わっていた。アプリが配下のClaude Codeを起こし直すと、同じ会話(同じ`session_id`)が新しいprocessで再開される。会話のchannelは全部、居ないprocessに結ばれたままなので、PostToolUseとStopの待機が毎回すぐ終わり、本文は受信箱に残った(製品が新しいchannelを開くまで届かない)。Windowsの実物(Claude Code 2.1.295)で起き、Linuxの実物(2.1.293)で再現した。
|
|
8
|
+
- **待機は、そのhookを起こしたClaude Codeのprocessが生きている間、続ける。** 本文を出す先はそのprocessなので、生き死にもそのprocessで見る。同じ会話(`session_id`)のhookを今走らせているprocessへ、前のprocessが開いたchannelの本文も出す。別の会話のchannelからは取らない(今までどおり、会話ごとの索引で分ける)。hookを起こしたprocessが居なくなったら、本文を取らずに終わる。hookを起こしたprocessを確かめられない時だけ、今までどおりchannelを開いた時のprocessの生き死にで決める。
|
|
9
|
+
- **会話の始まり(`SessionStart`)でも待機を張る。** channelを使う製品(`profile.channels`がある)の登録に、`SessionStart`のhook(`asyncRewake`)を足す。再開した会話が番を1つも回さないうちから、止まっていた間に届いた本文で起きる(実物で、再開した席が入力待ちになって3〜5秒後)。開いているchannelの無い会話(新しい会話、`/clear`の後)では、何もせず0で終わる。
|
|
10
|
+
- 0.4.1までの登録には`SessionStart`が無い。そのままでも配送は成り立ち(`claudeParentHooksRegistered`は`SessionStart`を求めない)、再開した会話は最初の番の終わりから受け取る。製品のsetup(`mergeClaudeParentHooks`)をかけ直すと`SessionStart`だけが足される。`removeClaudeParentHooks`は一緒に外す。
|
|
11
|
+
- channelを使わない製品(Aitermなど)の登録と動きは変わらない。
|
|
12
|
+
- **同じ会話に開いているchannelが幾つかある時、届いた順に出す。** 今まではchannelごと(IDの並び順)にまとめて出していた。起動し直す前のchannelと後のchannelの両方に本文がある時も、届いた順に並ぶ。
|
|
13
|
+
- `runClaudeChannelWaiter`の`options`に`owner`(試験が、hookを起こしたprocessを差し替える口)を足す。
|
|
14
|
+
- 0.4.1の記述の言い足し: Linuxのアプリで寝ている会話が起きなかった端末は、アプリのログインの期限が切れていた(アプリの記録に`token_expired`)。リンクを開く口が効かないのか、ログインのせいかは、まだ分けられていない。Linuxで見張りを起こさない事は変わらない。
|
|
15
|
+
|
|
16
|
+
## 0.4.1
|
|
17
|
+
|
|
18
|
+
0.4.0の「寝ている会話を起こす見張り」の、3つの直しです。
|
|
19
|
+
|
|
20
|
+
- **Linuxでは見張りを起こさない。** 0.4.0は、画面のあるLinuxで`xdg-open`を使うと書いていた。実物(Linuxのアプリ、Codex 0.162.0-alpha.2)で、同じリンクを開かせても会話が載らず、キューは動かなかった。動く形を確かめるまで、Linuxでは何も開かない(今までどおり、会話が開かれた時に届く)。CodexがMCP serverへ渡す環境には`DISPLAY`も`WAYLAND_DISPLAY`も無いので、0.4.0でも製品の本番の道では起きていなかった。
|
|
21
|
+
- **リンクを開く命令を、場所を決めて呼ぶ。** macOSは`/usr/bin/open`、Windowsは`ComSpec`(無ければ`%SystemRoot%\\System32\\cmd.exe`)。CodexがMCP serverへ渡す環境は細く、`PATH`に頼ると見つからない事がある。
|
|
22
|
+
- 文書の、Linuxで動くという記述を直す。
|
|
23
|
+
|
|
3
24
|
## 0.4.0
|
|
4
25
|
|
|
5
26
|
Codexの寝ている会話へ入れた文が、人がその会話を開くまで動かなかったのを直します。今までのAPIの返りは変わりません。
|
|
@@ -7,11 +28,11 @@ Codexの寝ている会話へ入れた文が、人がその会話を開くまで
|
|
|
7
28
|
- **起きていた事。** Codexが公式キューの文を番にするのは、その会話を載せている(loaded)Codexのprocessだけ。Codexのアプリは、見ている接続が居なくなって動きの無い会話を60秒で下ろす(`thread_unload_delay_secs`。Codex 0.153.0までは30分)。下ろされた会話のキューは、人がその会話を開くまで誰も見ない。番の途中へ入れる道(hook)と、載っている会話の止まっている所へ届く道は、今までどおり通っていた。
|
|
8
29
|
- **`submitCodexParentAnswer`が、入れた後に「寝ていたら起こす見張り」を別のprocessで起こす。** 約15秒後にキューを見直す。
|
|
9
30
|
- 文がもう無い(会話が載っていて受け取った、hookが番の途中へ入れた): 何もしない。
|
|
10
|
-
- 文が残っていて、アプリの会話(`source`が`vscode`)で、最後の番が普通に終わっている(または番が1つも無い): OSの口で`codex://threads/<会話>`を開かせる。アプリが会話を載せ、公式キューが番を始める。アプリの画面はその会話へ切り替わる(macOSは`open -g`で、アプリを前面へは出さない。Windowsは`cmd /c start
|
|
31
|
+
- 文が残っていて、アプリの会話(`source`が`vscode`)で、最後の番が普通に終わっている(または番が1つも無い): OSの口で`codex://threads/<会話>`を開かせる。アプリが会話を載せ、公式キューが番を始める。アプリの画面はその会話へ切り替わる(macOSは`open -g`で、アプリを前面へは出さない。Windowsは`cmd /c start`。Linuxは0.4.1で外した)。Windowsでは、人の画面のあるsessionの時だけ開く(サービスやsshのsessionから開いたリンクは、人の画面のアプリへ届かない)。
|
|
11
32
|
- 番の途中、最後の番が途中で止められている(人が止めた、ほかの製品が作業を別の会話へ移した)、アプリの会話でない(CLIの席)、会話の記録を読めない: 起こさない。途中で止められた会話は、人が次の文を送るまでCodexがキューを動かさない。
|
|
12
33
|
- 同じ会話へ続けて届いた時は、30秒の間は開き直さない。
|
|
13
34
|
- **結果を残す。** `<config_root>/codex-parent-hooks/wake/<配送ID>.json`に3日間。`readCodexWakeResult(profile, deliveryId)`で読める(`delivered`・`running`・`interrupted`・`not_app_thread`・`unknown_state`・`no_opener`・`open_failed`・`woken`・`opened_still_queued`)。受付の返り(`queued_submission_id`)は、見張りの成否で変わらない。
|
|
14
|
-
- **見張りを起こすのは、リンクを開く口のある環境だけ。** macOS
|
|
35
|
+
- **見張りを起こすのは、リンクを開く口のある環境だけ。** macOSとWindows(Linuxは0.4.1で外した)。サーバーやコンテナでは何も起こさない。止める時は環境変数`AITERM_STEER_CODEX_WAKE=0`。
|
|
15
36
|
- **公開した物。** `wakeCodexParentIfAsleep(profile, parent, deliveryId, options?)`(今すぐ見直して起こす)、`startCodexWakeWatch`、`readCodexWakeResult`、`readCodexTurnTail`、`codexThreadUrl`、`codexThreadOpener`、`codexWakeWatchEnabled`、`codexWakeDirectory`。`CodexReceiverRuntime`に`wake`(`runtime`を渡す呼び出しでは、`true`の時だけ見張りを起こす)。
|
|
16
37
|
- **CLI。** `codex submit`は今までどおりすぐ返り、見張りを残す。`codex state`の返りは、見張りが結果を残した後だけ`wake`が付く(それまでは今までと同じ形)。`codex wake --thread --delivery [--delay-ms]`を足す。
|
|
17
38
|
- **Aitermへ頼む入口。** `codexDeliveryDetailViaAiterm`の返りは、Aiterm(0.58.0以上)が見張りの結果を返した時だけ`wake`が付く。
|
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ Codex starts a queued message only in a conversation that some running Codex pro
|
|
|
175
175
|
|
|
176
176
|
The outcome is saved under `<config_root>/codex-parent-hooks/wake/<delivery id>.json` for three days and can be read with `readCodexWakeResult(PROFILE, deliveryId)`: `delivered`, `running`, `interrupted`, `not_app_thread`, `unknown_state`, `no_opener`, `open_failed`, `woken`, or `opened_still_queued`. The acceptance returned by `submitCodexParentAnswer` does not depend on the watcher.
|
|
177
177
|
|
|
178
|
-
The watcher runs
|
|
178
|
+
The watcher runs on macOS and Windows. On Windows the link is opened only from an interactive session (a link opened from a service or an SSH session never reaches the app on the desktop; the outcome is `no_opener`). On Linux nothing is started yet: asking the Linux app to open the same link did not load the conversation in our tests, so a reply to a sleeping conversation still waits there until the conversation is opened. On servers and in containers nothing is started. Set `AITERM_STEER_CODEX_WAKE=0` to turn it off. To check and wake right now from your own process, call `wakeCodexParentIfAsleep(PROFILE, parent, deliveryId, { delay_ms: 0 })`.
|
|
179
179
|
|
|
180
180
|
**Many messages to one conversation** (channels, e.g. Peertable's room messages to the parent):
|
|
181
181
|
|
|
@@ -185,7 +185,7 @@ await steer.sendToChannel(PROFILE, channel.channel_id, randomUUID(), text);
|
|
|
185
185
|
steer.channelDeliveryState(PROFILE, channel.channel_id, id); // queued | sending | emitted | unknown | withdrawn
|
|
186
186
|
```
|
|
187
187
|
|
|
188
|
-
Claude Code re-arms its waiter at every `Stop
|
|
188
|
+
Claude Code re-arms its waiter at every `Stop`, and arms it at `SessionStart` as well. The waiter belongs to the Claude Code process that ran the hook: it keeps waiting while that process is alive, and it delivers every open channel of that conversation (`session_id`), including channels opened by an earlier process. So when Claude Code restarts and resumes the same conversation in a new process, messages that arrived while it was down wake the resumed conversation, even before it runs a turn. (A registration written by 0.4.1 or earlier has no `SessionStart` hook; it still works, and the resumed conversation starts receiving at the end of its first turn. Run your setup again to add the hook.) Cursor binds the channel with `steer.channelMarker(channel)` placed in your tool result, and idle Cursor/Grok parents run `steer.channelReceiveProcess(...)` in the background; each result carries `next_wait_process` to re-arm. `withdrawFromChannel` takes back text no receiver has claimed yet, so you can resend it on a new channel; `closeChannel` ends one.
|
|
189
189
|
|
|
190
190
|
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).
|
|
191
191
|
|
package/dist/channel.d.ts
CHANGED
|
@@ -58,10 +58,19 @@ export declare function withdrawFromChannel(profile: ProductProfile, channelId:
|
|
|
58
58
|
/**
|
|
59
59
|
* Claude Codeのhook(PostToolUse・Stop、asyncRewake)から呼ぶ。その会話のchannelに届いた本文を待ち、
|
|
60
60
|
* 出力したら2(親を起こす)、待つものが無い・他の待機が生きている・会話が終わったなら0を返す。
|
|
61
|
+
*
|
|
62
|
+
* 待機は、このhookを起こしたClaude Codeのprocessが生きている間だけ続ける。本文はそのprocessへ出すので、居なくなった後に取ると失う。
|
|
63
|
+
* channelを開いた時のprocess(`channel.claude.parent_pid`)が居なくなっていても、同じ会話(session_id)のhookを走らせている今のprocessへ出す。
|
|
64
|
+
* Claude Codeが起動し直して同じ会話を再開した後も、前のprocessが開いたchannelの本文が届く。
|
|
65
|
+
* hookを起こしたprocessを確かめられない時だけ、channelを開いた時のprocessの生き死にで決める。
|
|
61
66
|
*/
|
|
62
67
|
export declare function runClaudeChannelWaiter(profile: ProductProfile, input: unknown, emit: (text: string) => Promise<void> | void, options?: {
|
|
63
68
|
wait_ms?: number;
|
|
64
69
|
poll_ms?: number;
|
|
70
|
+
owner?: {
|
|
71
|
+
pid: number;
|
|
72
|
+
started_identity: string;
|
|
73
|
+
} | null;
|
|
65
74
|
}): Promise<0 | 2>;
|
|
66
75
|
/** Claude CodeのSessionEndで、その会話のchannelを閉じる。未取得の本文は残る。 */
|
|
67
76
|
export declare function closeClaudeSessionChannels(profile: ProductProfile, input: unknown): void;
|
package/dist/channel.js
CHANGED
|
@@ -12,7 +12,7 @@ import { randomUUID } from "node:crypto";
|
|
|
12
12
|
import { setTimeout as delay } from "node:timers/promises";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
import { writeJson0600 } from "./files.js";
|
|
15
|
-
import { readRuntimeProcesses } from "./process.js";
|
|
15
|
+
import { hookOwnerProcess, readRuntimeProcesses } from "./process.js";
|
|
16
16
|
import { channelRoot } from "./profile.js";
|
|
17
17
|
import { SteerDeliveryError } from "./errors.js";
|
|
18
18
|
import { submitCodexParentAnswer } from "./codex-receiver.js";
|
|
@@ -302,14 +302,25 @@ function releaseWaiter(index, identity) {
|
|
|
302
302
|
}
|
|
303
303
|
catch { /* 既に無い */ }
|
|
304
304
|
}
|
|
305
|
+
/** このhookを起こしたClaude Codeのprocess。shellを通す形のhookでは、直接の親のshellの先をたどる。分からなければnull。 */
|
|
306
|
+
function currentHookOwner() {
|
|
307
|
+
const owner = hookOwnerProcess(readRuntimeProcesses(), process.ppid);
|
|
308
|
+
return owner ? { pid: owner.pid, started_identity: owner.started_identity } : null;
|
|
309
|
+
}
|
|
305
310
|
/**
|
|
306
311
|
* Claude Codeのhook(PostToolUse・Stop、asyncRewake)から呼ぶ。その会話のchannelに届いた本文を待ち、
|
|
307
312
|
* 出力したら2(親を起こす)、待つものが無い・他の待機が生きている・会話が終わったなら0を返す。
|
|
313
|
+
*
|
|
314
|
+
* 待機は、このhookを起こしたClaude Codeのprocessが生きている間だけ続ける。本文はそのprocessへ出すので、居なくなった後に取ると失う。
|
|
315
|
+
* channelを開いた時のprocess(`channel.claude.parent_pid`)が居なくなっていても、同じ会話(session_id)のhookを走らせている今のprocessへ出す。
|
|
316
|
+
* Claude Codeが起動し直して同じ会話を再開した後も、前のprocessが開いたchannelの本文が届く。
|
|
317
|
+
* hookを起こしたprocessを確かめられない時だけ、channelを開いた時のprocessの生き死にで決める。
|
|
308
318
|
*/
|
|
309
319
|
export async function runClaudeChannelWaiter(profile, input, emit, options = {}) {
|
|
310
320
|
const event = z.object({ session_id: z.uuid() }).loose().parse(input);
|
|
311
321
|
if (!openClaudeChannels(profile, event.session_id).length)
|
|
312
322
|
return 0;
|
|
323
|
+
const owner = options.owner === undefined ? currentHookOwner() : options.owner;
|
|
313
324
|
const index = sessionIndex(profile, event.session_id);
|
|
314
325
|
const identity = acquireWaiter(index);
|
|
315
326
|
if (!identity)
|
|
@@ -323,11 +334,15 @@ export async function runClaudeChannelWaiter(profile, input, emit, options = {})
|
|
|
323
334
|
return 0;
|
|
324
335
|
if (Date.now() - lastParentCheck >= 5_000) {
|
|
325
336
|
lastParentCheck = Date.now();
|
|
326
|
-
//
|
|
327
|
-
|
|
337
|
+
// 本文を出す先(このhookを起こしたClaude process)が終わっていたら、本文を取らずに待機を終える。
|
|
338
|
+
const alive = owner ? processIdentity(owner.pid) === owner.started_identity
|
|
339
|
+
: channels.some(channel => processIdentity(channel.claude.parent_pid) === channel.claude.parent_started_identity);
|
|
340
|
+
if (!alive)
|
|
328
341
|
return 0;
|
|
329
342
|
}
|
|
330
|
-
|
|
343
|
+
// 同じ会話に開いているchannelが幾つかある時(起動し直す前のchannelと後のchannel)も、届いた順に出す。
|
|
344
|
+
const claimed = channels.flatMap(channel => claimPending(profile, channel.channel_id, "claude_hook"))
|
|
345
|
+
.sort((left, right) => left.item.at < right.item.at ? -1 : left.item.at > right.item.at ? 1 : 0);
|
|
331
346
|
if (claimed.length) {
|
|
332
347
|
await emitClaimed(claimed, "claude_hook", texts => emit(texts.join("\n\n")));
|
|
333
348
|
return 2;
|
package/dist/codex-wake.d.ts
CHANGED
|
@@ -21,8 +21,9 @@ export interface CodexThreadOpener {
|
|
|
21
21
|
export declare function windowsInteractiveSession(env?: NodeJS.ProcessEnv, sessionId?: () => string): boolean;
|
|
22
22
|
/**
|
|
23
23
|
* OSの口で、Codexのアプリにリンクを開かせる関数を返す。口の無い環境ではnull。
|
|
24
|
-
* macOS
|
|
25
|
-
* Linux
|
|
24
|
+
* macOSは`/usr/bin/open -g`(アプリを前面へ出さない)、Windowsは`cmd /c start`(人の画面のあるsessionの時だけ)。
|
|
25
|
+
* Linuxのアプリは、まだ起こせない(`xdg-open`で開かせても会話が載らなかった。実物で確かめた後に足す)。
|
|
26
|
+
* 命令は場所を決めて呼ぶ。CodexがMCP serverへ渡す環境は細く、PATHに頼ると見つからない事がある。
|
|
26
27
|
*/
|
|
27
28
|
export declare function codexThreadOpener(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv, interactive?: () => boolean): CodexThreadOpener | null;
|
|
28
29
|
export type CodexWakeOutcome =
|
|
@@ -76,7 +77,7 @@ export declare function readCodexWakeResult(profile: ProductProfile, deliveryId:
|
|
|
76
77
|
* 起こすのは、アプリの会話(sourceがvscode)で、最後の番が普通に終わっている(または番が1つも無い)時だけ。
|
|
77
78
|
*/
|
|
78
79
|
export declare function wakeCodexParentIfAsleep(profile: ProductProfile, parent: CodexParent, deliveryId: string, options?: CodexWakeOptions): Promise<CodexWakeResult>;
|
|
79
|
-
/** 見張りを別のprocess
|
|
80
|
+
/** 見張りを別のprocessで起こすかどうか。リンクを開く口の無いOS(Linuxなど)では、何も起こさない。 */
|
|
80
81
|
export declare function codexWakeWatchEnabled(platform?: NodeJS.Platform, env?: NodeJS.ProcessEnv): boolean;
|
|
81
82
|
export declare const CODEX_WAKE_PAYLOAD_ENV = "AITERM_STEER_CODEX_WAKE_PAYLOAD";
|
|
82
83
|
/** 見張りのprocessへ渡す、関数を含まない製品の識別情報。 */
|
package/dist/codex-wake.js
CHANGED
|
@@ -88,8 +88,9 @@ export function windowsInteractiveSession(env = process.env, sessionId = () => w
|
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
90
|
* OSの口で、Codexのアプリにリンクを開かせる関数を返す。口の無い環境ではnull。
|
|
91
|
-
* macOS
|
|
92
|
-
* Linux
|
|
91
|
+
* macOSは`/usr/bin/open -g`(アプリを前面へ出さない)、Windowsは`cmd /c start`(人の画面のあるsessionの時だけ)。
|
|
92
|
+
* Linuxのアプリは、まだ起こせない(`xdg-open`で開かせても会話が載らなかった。実物で確かめた後に足す)。
|
|
93
|
+
* 命令は場所を決めて呼ぶ。CodexがMCP serverへ渡す環境は細く、PATHに頼ると見つからない事がある。
|
|
93
94
|
*/
|
|
94
95
|
export function codexThreadOpener(platform = process.platform, env = process.env, interactive = () => windowsInteractiveSession(env)) {
|
|
95
96
|
const run = (command, args) => () => {
|
|
@@ -99,16 +100,13 @@ export function codexThreadOpener(platform = process.platform, env = process.env
|
|
|
99
100
|
return result.status === 0 ? { ok: true } : { ok: false, detail: `exit=${result.status} ${String(result.stderr ?? "").trim().slice(0, 200)}`.trim() };
|
|
100
101
|
};
|
|
101
102
|
if (platform === "darwin")
|
|
102
|
-
return url => run("open", ["-g", url])();
|
|
103
|
-
if (platform === "win32")
|
|
104
|
-
|
|
105
|
-
if (platform === "linux") {
|
|
106
|
-
if (!env.DISPLAY && !env.WAYLAND_DISPLAY)
|
|
103
|
+
return url => run("/usr/bin/open", ["-g", url])();
|
|
104
|
+
if (platform === "win32") {
|
|
105
|
+
if (!interactive())
|
|
107
106
|
return null;
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return url => run("xdg-open", [url])();
|
|
107
|
+
const key = (name) => Object.keys(env).find(candidate => candidate.toLowerCase() === name);
|
|
108
|
+
const comspec = env[key("comspec") ?? "ComSpec"] ?? path.win32.join(env[key("systemroot") ?? "SystemRoot"] ?? "C:\\Windows", "System32", "cmd.exe");
|
|
109
|
+
return url => run(comspec, ["/d", "/c", "start", "", url])();
|
|
112
110
|
}
|
|
113
111
|
return null;
|
|
114
112
|
}
|
|
@@ -243,13 +241,11 @@ export async function wakeCodexParentIfAsleep(profile, parent, deliveryId, optio
|
|
|
243
241
|
catch { /* 結果を残せなくても、起こした事は変わらない */ }
|
|
244
242
|
return result;
|
|
245
243
|
}
|
|
246
|
-
/** 見張りを別のprocess
|
|
244
|
+
/** 見張りを別のprocessで起こすかどうか。リンクを開く口の無いOS(Linuxなど)では、何も起こさない。 */
|
|
247
245
|
export function codexWakeWatchEnabled(platform = process.platform, env = process.env) {
|
|
248
246
|
if (env.AITERM_STEER_CODEX_WAKE === "0")
|
|
249
247
|
return false;
|
|
250
|
-
|
|
251
|
-
return true;
|
|
252
|
-
return platform === "linux" && Boolean(env.DISPLAY || env.WAYLAND_DISPLAY);
|
|
248
|
+
return platform === "darwin" || platform === "win32";
|
|
253
249
|
}
|
|
254
250
|
export const CODEX_WAKE_PAYLOAD_ENV = "AITERM_STEER_CODEX_WAKE_PAYLOAD";
|
|
255
251
|
/** 見張りのprocessへ渡す、関数を含まない製品の識別情報。 */
|
package/dist/hook-main.js
CHANGED
|
@@ -56,6 +56,13 @@ export async function runClaudeHookMain(profile, root = claudeHookRoot(profile))
|
|
|
56
56
|
throw new Error("CLAUDE_PARENT_HOOK_EVENT_INVALID: 未対応のhookです");
|
|
57
57
|
process.exitCode = await runClaudeChannelWaiter(profile, event, write);
|
|
58
58
|
break;
|
|
59
|
+
case "SessionStart":
|
|
60
|
+
// 会話が起動し直して再開された時は、番が1つも回らないうちから、前のprocessが開いたchannelの待機を張る。
|
|
61
|
+
// 開いているchannelが無い会話(新しい会話、/clearの後)では、何もせず0で終わる。
|
|
62
|
+
if (!profile.channels)
|
|
63
|
+
throw new Error("CLAUDE_PARENT_HOOK_EVENT_INVALID: 未対応のhookです");
|
|
64
|
+
process.exitCode = await runClaudeChannelWaiter(profile, event, write);
|
|
65
|
+
break;
|
|
59
66
|
case "SessionEnd":
|
|
60
67
|
closeClaudeParentSession(event, root);
|
|
61
68
|
if (profile.channels)
|
package/dist/hook-setup.d.ts
CHANGED
|
@@ -20,7 +20,10 @@ export declare function claudeParentHookEntries(profile: ProductProfile, hook: H
|
|
|
20
20
|
hooks: Record<string, unknown>[];
|
|
21
21
|
}[]>;
|
|
22
22
|
export declare function mergeClaudeParentHooks(profile: ProductProfile, file: string, hook: HookRuntime): "configured" | "unchanged";
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* 配送に要る全てのeventに、当製品のhookがあるか(設定を読むだけ。形は旧・新のどちらでもよい)。
|
|
25
|
+
* SessionStartは求めない。無い登録(0.4.1まで)でも配送は成り立ち、起動し直した会話は最初の番の終わりから受け取る。
|
|
26
|
+
*/
|
|
24
27
|
export declare function claudeParentHooksRegistered(profile: ProductProfile, document: unknown): boolean;
|
|
25
28
|
/** 登録済みの当製品のhookが指す入口のpath。入口のfileが残っているかを製品が確かめるために使う。 */
|
|
26
29
|
export declare function claudeParentHookScripts(profile: ProductProfile, document: unknown): string[];
|
package/dist/hook-setup.js
CHANGED
|
@@ -34,10 +34,17 @@ export function claudeParentHookEntries(profile, hook, platform = process.platfo
|
|
|
34
34
|
PreToolUse: [{ matcher, hooks: [{ ...command, timeout: 15 }] }],
|
|
35
35
|
PostToolUse: [{ matcher, hooks: [{ ...command, asyncRewake: true, timeout: 86400 }] }],
|
|
36
36
|
// 長く続く受信(channel)では、turnが終わるたびに待機を張り直す。
|
|
37
|
-
|
|
37
|
+
// 会話の始まり(SessionStart)でも張る。Claude Codeが起動し直して同じ会話を再開した時、番が1つも回らないうちから、
|
|
38
|
+
// 前のprocessが開いたchannelの本文を受け取れる。開いているchannelの無い会話では、何もせず終わる。
|
|
39
|
+
...(profile.channels ? {
|
|
40
|
+
Stop: [{ hooks: [{ ...command, asyncRewake: true, timeout: 86400 }] }],
|
|
41
|
+
SessionStart: [{ hooks: [{ ...command, asyncRewake: true, timeout: 86400 }] }],
|
|
42
|
+
} : {}),
|
|
38
43
|
SessionEnd: [{ hooks: [{ ...command, timeout: 15 }] }],
|
|
39
44
|
};
|
|
40
45
|
}
|
|
46
|
+
/** 無くても配送が成り立つevent。0.4.1までの登録には無いので、登録の確認では求めない(次のsetupで足される)。 */
|
|
47
|
+
const OPTIONAL_CLAUDE_EVENTS = new Set(["SessionStart"]);
|
|
41
48
|
export function mergeClaudeParentHooks(profile, file, hook) {
|
|
42
49
|
const target = existsSync(file) ? realpathSync(file) : file;
|
|
43
50
|
let current = {};
|
|
@@ -110,9 +117,13 @@ function ownedClaudeParentHooks(profile, document, event) {
|
|
|
110
117
|
return [];
|
|
111
118
|
return hooks.flatMap(group => record(group) && Array.isArray(group.hooks) ? group.hooks : []).filter(entry => isClaudeParentHook(profile, entry));
|
|
112
119
|
}
|
|
113
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* 配送に要る全てのeventに、当製品のhookがあるか(設定を読むだけ。形は旧・新のどちらでもよい)。
|
|
122
|
+
* SessionStartは求めない。無い登録(0.4.1まで)でも配送は成り立ち、起動し直した会話は最初の番の終わりから受け取る。
|
|
123
|
+
*/
|
|
114
124
|
export function claudeParentHooksRegistered(profile, document) {
|
|
115
125
|
return Object.keys(claudeParentHookEntries(profile, { command: "", script: profile.hooks.claude }))
|
|
126
|
+
.filter(event => !OPTIONAL_CLAUDE_EVENTS.has(event))
|
|
116
127
|
.every(event => ownedClaudeParentHooks(profile, document, event).length > 0);
|
|
117
128
|
}
|
|
118
129
|
/** 登録済みの当製品のhookが指す入口のpath。入口のfileが残っているかを製品が確かめるために使う。 */
|
|
@@ -134,7 +145,7 @@ export function removeClaudeParentHooks(profile, file) {
|
|
|
134
145
|
if (current.hooks === undefined)
|
|
135
146
|
return "unchanged";
|
|
136
147
|
const hooks = { ...current.hooks };
|
|
137
|
-
for (const event of ["PreToolUse", "PostToolUse", "Stop", "SessionEnd"]) {
|
|
148
|
+
for (const event of ["PreToolUse", "PostToolUse", "Stop", "SessionStart", "SessionEnd"]) {
|
|
138
149
|
if (hooks[event] === undefined)
|
|
139
150
|
continue;
|
|
140
151
|
if (!Array.isArray(hooks[event]))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aiterm-steer-delivery",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
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",
|