tailii-host 0.5.0 → 0.7.0
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/dist/approval/hook.js +11 -1
- package/dist/approval/hook.js.map +1 -1
- package/dist/backend/herdr.d.ts +60 -6
- package/dist/backend/herdr.js +180 -27
- package/dist/backend/herdr.js.map +1 -1
- package/dist/backend/sessionBackend.d.ts +22 -3
- package/dist/backend/sessionBackend.js +11 -2
- package/dist/backend/sessionBackend.js.map +1 -1
- package/dist/backend/tmux.d.ts +197 -3
- package/dist/backend/tmux.js +565 -16
- package/dist/backend/tmux.js.map +1 -1
- package/dist/chat/chatTailController.d.ts +4 -2
- package/dist/chat/chatTailController.js +19 -33
- package/dist/chat/chatTailController.js.map +1 -1
- package/dist/chat/imageService.d.ts +9 -1
- package/dist/chat/imageService.js +39 -0
- package/dist/chat/imageService.js.map +1 -1
- package/dist/chat/subagentTailer.d.ts +10 -0
- package/dist/chat/subagentTailer.js +234 -51
- package/dist/chat/subagentTailer.js.map +1 -1
- package/dist/chat/subagentTranscript.js +51 -5
- package/dist/chat/subagentTranscript.js.map +1 -1
- package/dist/chat/transcriptTailer.d.ts +53 -1
- package/dist/chat/transcriptTailer.js +313 -2
- package/dist/chat/transcriptTailer.js.map +1 -1
- package/dist/codex/codexAppServer.d.ts +54 -9
- package/dist/codex/codexAppServer.js +495 -76
- package/dist/codex/codexAppServer.js.map +1 -1
- package/dist/codex/codexNativeTurnController.d.ts +22 -1
- package/dist/codex/codexNativeTurnController.js +76 -11
- package/dist/codex/codexNativeTurnController.js.map +1 -1
- package/dist/codex/codexRolloutTailer.d.ts +3 -0
- package/dist/codex/codexRolloutTailer.js +85 -13
- package/dist/codex/codexRolloutTailer.js.map +1 -1
- package/dist/codex/codexSessionStore.js +54 -16
- package/dist/codex/codexSessionStore.js.map +1 -1
- package/dist/codex/codexSubagentTracker.d.ts +13 -0
- package/dist/codex/codexSubagentTracker.js +55 -1
- package/dist/codex/codexSubagentTracker.js.map +1 -1
- package/dist/codex/codexSystemNotice.d.ts +18 -0
- package/dist/codex/codexSystemNotice.js +212 -0
- package/dist/codex/codexSystemNotice.js.map +1 -0
- package/dist/commands/launch.js +50 -13
- package/dist/commands/launch.js.map +1 -1
- package/dist/engine/context.d.ts +32 -1
- package/dist/engine/context.js +39 -3
- package/dist/engine/context.js.map +1 -1
- package/dist/engine/engine.d.ts +5 -1
- package/dist/engine/engine.js +87 -4
- package/dist/engine/engine.js.map +1 -1
- package/dist/engine/handlers/accountUsage.d.ts +17 -0
- package/dist/engine/handlers/accountUsage.js +40 -6
- package/dist/engine/handlers/accountUsage.js.map +1 -1
- package/dist/engine/handlers/codex.js +37 -0
- package/dist/engine/handlers/codex.js.map +1 -1
- package/dist/engine/handlers/core.js +14 -1
- package/dist/engine/handlers/core.js.map +1 -1
- package/dist/engine/handlers/mode.js +105 -1
- package/dist/engine/handlers/mode.js.map +1 -1
- package/dist/engine/handlers/session.js +17 -33
- package/dist/engine/handlers/session.js.map +1 -1
- package/dist/engine/handlers/usage.js +4 -1
- package/dist/engine/handlers/usage.js.map +1 -1
- package/dist/engine/handlers/workspace.js +22 -1
- package/dist/engine/handlers/workspace.js.map +1 -1
- package/dist/hub/effortDialog.d.ts +15 -0
- package/dist/hub/effortDialog.js +60 -16
- package/dist/hub/effortDialog.js.map +1 -1
- package/dist/hub/engineRelaySocket.d.ts +7 -0
- package/dist/hub/engineRelaySocket.js +7 -1
- package/dist/hub/engineRelaySocket.js.map +1 -1
- package/dist/hub/hubDaemon.js +30 -5
- package/dist/hub/hubDaemon.js.map +1 -1
- package/dist/hub/hubProtocol.d.ts +10 -0
- package/dist/hub/hubProtocol.js +19 -2
- package/dist/hub/hubProtocol.js.map +1 -1
- package/dist/hub/panePreviewPump.d.ts +27 -0
- package/dist/hub/panePreviewPump.js +62 -1
- package/dist/hub/panePreviewPump.js.map +1 -1
- package/dist/hub/sessionHub.d.ts +125 -4
- package/dist/hub/sessionHub.js +413 -48
- package/dist/hub/sessionHub.js.map +1 -1
- package/dist/protocol/decode.js +84 -15
- package/dist/protocol/decode.js.map +1 -1
- package/dist/protocol/encode.js +2 -0
- package/dist/protocol/encode.js.map +1 -1
- package/dist/protocol/messages.d.ts +87 -1
- package/dist/services/accountIdentity.js +3 -1
- package/dist/services/accountIdentity.js.map +1 -1
- package/dist/services/fileService.d.ts +15 -0
- package/dist/services/fileService.js +176 -14
- package/dist/services/fileService.js.map +1 -1
- package/dist/services/officialApps.d.ts +21 -1
- package/dist/services/officialApps.js +201 -53
- package/dist/services/officialApps.js.map +1 -1
- package/dist/services/planUsageFetcher.d.ts +35 -3
- package/dist/services/planUsageFetcher.js +34 -6
- package/dist/services/planUsageFetcher.js.map +1 -1
- package/dist/services/previewServer.js +15 -6
- package/dist/services/previewServer.js.map +1 -1
- package/dist/sessions/claudeSessionStore.js +30 -0
- package/dist/sessions/claudeSessionStore.js.map +1 -1
- package/dist/sessions/heartbeat.d.ts +7 -1
- package/dist/sessions/heartbeat.js +3 -1
- package/dist/sessions/heartbeat.js.map +1 -1
- package/dist/sessions/sessionSearch.js +23 -5
- package/dist/sessions/sessionSearch.js.map +1 -1
- package/dist/sessions/transcriptPath.d.ts +3 -0
- package/dist/sessions/transcriptPath.js +15 -0
- package/dist/sessions/transcriptPath.js.map +1 -0
- package/dist/shared/clientBuild.d.ts +26 -0
- package/dist/shared/clientBuild.js +89 -0
- package/dist/shared/clientBuild.js.map +1 -0
- package/dist/shared/crossSession.d.ts +15 -0
- package/dist/shared/crossSession.js +75 -0
- package/dist/shared/crossSession.js.map +1 -0
- package/dist/shared/harnessReminder.d.ts +32 -0
- package/dist/shared/harnessReminder.js +124 -0
- package/dist/shared/harnessReminder.js.map +1 -0
- package/dist/shared/systemNotice.d.ts +30 -0
- package/dist/shared/systemNotice.js +209 -0
- package/dist/shared/systemNotice.js.map +1 -0
- package/package.json +3 -3
|
@@ -7,6 +7,7 @@ import { execFile } from "node:child_process";
|
|
|
7
7
|
import * as fs from "node:fs";
|
|
8
8
|
import * as path from "node:path";
|
|
9
9
|
import { PROTOCOL_V2 } from "../protocol.js";
|
|
10
|
+
import { injectedReminderBodies } from "../shared/harnessReminder.js";
|
|
10
11
|
import { abortableSleep } from "../shared/sleep.js";
|
|
11
12
|
import { extractToolActivities, TranscriptTailer } from "./transcriptTailer.js";
|
|
12
13
|
/** サブエージェント meta/jsonl と親 transcript の tool_result を監視する。 */
|
|
@@ -16,6 +17,7 @@ export class SubagentTailer {
|
|
|
16
17
|
orphanGraceMs;
|
|
17
18
|
orphanProbeIntervalMs;
|
|
18
19
|
agentOrphanGraceMs;
|
|
20
|
+
tentativeFinalGraceMs;
|
|
19
21
|
probeOutputOpen;
|
|
20
22
|
probeSessionAlive;
|
|
21
23
|
sessionStaleMs;
|
|
@@ -27,6 +29,7 @@ export class SubagentTailer {
|
|
|
27
29
|
this.orphanGraceMs = options.orphanGraceMs ?? 60_000;
|
|
28
30
|
this.orphanProbeIntervalMs = options.orphanProbeIntervalMs ?? 30_000;
|
|
29
31
|
this.agentOrphanGraceMs = options.agentOrphanGraceMs ?? 120_000;
|
|
32
|
+
this.tentativeFinalGraceMs = Math.max(this.agentOrphanGraceMs, options.tentativeFinalGraceMs ?? 600_000);
|
|
30
33
|
this.probeOutputOpen = options.probeOutputOpen ?? defaultProbeOutputOpen;
|
|
31
34
|
this.sessionStaleMs = options.sessionStaleMs ?? 6 * 60 * 60 * 1000;
|
|
32
35
|
this.probeSessionAlive = options.probeSessionAlive
|
|
@@ -72,8 +75,8 @@ export class SubagentTailer {
|
|
|
72
75
|
// 通知が握り潰された背景コマンドの孤児判定(taskId → 終了扱いにした ts)。
|
|
73
76
|
const bgOrphanTsByTaskId = new Map();
|
|
74
77
|
const bgFirstSeenMsByTaskId = new Map();
|
|
75
|
-
// 通知が配達されえない背景エージェントの孤児判定(nodeId → settle 扱いにした ts)。
|
|
76
|
-
const
|
|
78
|
+
// 通知が配達されえない背景エージェントの孤児判定(nodeId → settle 扱いにした ts/status)。
|
|
79
|
+
const agentOrphanByNodeId = new Map();
|
|
77
80
|
// 死亡セッションの一括 sweep マーク。生存へ転じたら全破棄して回復できるよう、
|
|
78
81
|
// 通常の孤児 settle とは別に持つ。
|
|
79
82
|
const deadSweepByNodeId = new Map();
|
|
@@ -106,6 +109,11 @@ export class SubagentTailer {
|
|
|
106
109
|
node.currentActivity = null;
|
|
107
110
|
node.lastJsonlTimestampMs = null;
|
|
108
111
|
node.finalReportMarker = null;
|
|
112
|
+
node.finalDefinite = false;
|
|
113
|
+
node.apiErrorMarker = false;
|
|
114
|
+
// model は「一度判明したら消えない」。truncate 直後の再読込で assistant 行が
|
|
115
|
+
// まだ無い tick に model 無しのノードを配信しないよう、直前値を保持する
|
|
116
|
+
// (再読込で別の値が出れば最新行が勝つ)。
|
|
109
117
|
}
|
|
110
118
|
}
|
|
111
119
|
if (node !== null)
|
|
@@ -155,21 +163,44 @@ export class SubagentTailer {
|
|
|
155
163
|
status: "completed",
|
|
156
164
|
exitCode: null,
|
|
157
165
|
ts: hit.ts ?? lineTs,
|
|
166
|
+
stopAck: true,
|
|
158
167
|
});
|
|
159
168
|
}
|
|
160
169
|
}
|
|
161
|
-
const notification
|
|
162
|
-
|
|
170
|
+
for (const notification of extractTaskNotifications(line)) {
|
|
171
|
+
// 同じ task-id の通知は enqueue ログと配達行(user / attachment / assistant 注入形)の
|
|
172
|
+
// 複数行に現れ、再開→再停止で複数回起こる。ファイル横断の集約と同じく最新 ts の
|
|
173
|
+
// 記録を採る(= 最後に起きた完了イベント)。TaskStop の ack は明示停止として常に優先。
|
|
174
|
+
const existing = read.state.notificationByTaskId.get(notification.taskId);
|
|
175
|
+
if (existing?.stopAck === true)
|
|
176
|
+
continue;
|
|
177
|
+
const ts = notification.ts ?? lineTs;
|
|
178
|
+
if (existing !== undefined && (existing.ts ?? 0) > (ts ?? 0))
|
|
179
|
+
continue;
|
|
180
|
+
// enqueue(完了時点の正確な ts)を、同じ完了イベントの遅い配達 ts で前進させない。
|
|
181
|
+
// 配達は停止境界までずれ込むため、その間の再開(自 transcript の追記)を「通知より
|
|
182
|
+
// 古い」と誤認して running のエージェントを completed に塗ってしまう。再完了は新しい
|
|
183
|
+
// enqueue が先に書かれるので latest-wins のまま拾える。
|
|
184
|
+
if (existing !== undefined && existing.enqueue === true && !notification.enqueue
|
|
185
|
+
&& existing.status === notification.status && existing.exitCode === notification.exitCode) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
163
188
|
read.state.notificationByTaskId.set(notification.taskId, {
|
|
164
189
|
status: notification.status,
|
|
165
190
|
exitCode: notification.exitCode,
|
|
166
|
-
ts
|
|
191
|
+
ts,
|
|
192
|
+
...(notification.enqueue ? { enqueue: true } : {}),
|
|
167
193
|
});
|
|
168
194
|
}
|
|
169
195
|
if (node !== null) {
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
node.finalReportMarker =
|
|
196
|
+
const shape = messageShape(line);
|
|
197
|
+
if (shape !== null) {
|
|
198
|
+
node.finalReportMarker = shape.final;
|
|
199
|
+
node.finalDefinite = shape.definite;
|
|
200
|
+
node.apiErrorMarker = shape.apiError;
|
|
201
|
+
if (shape.model !== null)
|
|
202
|
+
node.model = shape.model;
|
|
203
|
+
}
|
|
173
204
|
const activity = latestActivitySummary(line);
|
|
174
205
|
if (activity !== null)
|
|
175
206
|
node.currentActivity = activity;
|
|
@@ -191,7 +222,17 @@ export class SubagentTailer {
|
|
|
191
222
|
resultByToolUseId.set(id, result);
|
|
192
223
|
for (const [id, notification] of state.notificationByTaskId) {
|
|
193
224
|
const existing = notificationByTaskId.get(id);
|
|
194
|
-
if (existing ===
|
|
225
|
+
if (existing?.stopAck === true && notification.stopAck !== true)
|
|
226
|
+
continue;
|
|
227
|
+
// per-file と同じ規則: enqueue の正確な ts を、同じ完了イベントの遅い配達 ts で
|
|
228
|
+
// 前進させない。
|
|
229
|
+
if (existing?.enqueue === true && notification.enqueue !== true
|
|
230
|
+
&& notification.stopAck !== true
|
|
231
|
+
&& existing.status === notification.status && existing.exitCode === notification.exitCode) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (existing === undefined || notification.stopAck === true
|
|
235
|
+
|| (notification.ts ?? 0) >= (existing.ts ?? 0)) {
|
|
195
236
|
notificationByTaskId.set(id, notification);
|
|
196
237
|
}
|
|
197
238
|
}
|
|
@@ -223,7 +264,8 @@ export class SubagentTailer {
|
|
|
223
264
|
};
|
|
224
265
|
}
|
|
225
266
|
// バックグラウンド実行(または結果未着): task-notification が終了信号。
|
|
226
|
-
// 通知後に自分の transcript が伸びたら resume とみなし running
|
|
267
|
+
// 通知後に自分の transcript が伸びたら resume とみなし running へ戻す
|
|
268
|
+
// (再通知か、通知済み継続の settle(下記 notifiedContinuation)で再び終端する)。
|
|
227
269
|
const notification = notificationByTaskId.get(node.nodeId) ?? null;
|
|
228
270
|
const resumedAfter = notification !== null && notification.ts !== null
|
|
229
271
|
&& (node.lastJsonlTimestampMs ?? 0) > notification.ts;
|
|
@@ -237,15 +279,15 @@ export class SubagentTailer {
|
|
|
237
279
|
if (node.meta.stoppedByUser) {
|
|
238
280
|
return { status: "completed", ts: node.lastJsonlTimestampMs ?? mtimeMs(node.metaPath) };
|
|
239
281
|
}
|
|
240
|
-
// 通知が配達されえず孤児 settle
|
|
282
|
+
// 通知が配達されえず孤児 settle 済みなら終端。settle 後に transcript が
|
|
241
283
|
// 伸びたら resume とみなしマークを破棄して running へ戻す(孤児検知で再評価される)。
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
244
|
-
if ((node.lastJsonlTimestampMs ?? 0) >
|
|
245
|
-
|
|
284
|
+
const orphan = agentOrphanByNodeId.get(node.nodeId);
|
|
285
|
+
if (orphan !== undefined) {
|
|
286
|
+
if ((node.lastJsonlTimestampMs ?? 0) > orphan.ts) {
|
|
287
|
+
agentOrphanByNodeId.delete(node.nodeId);
|
|
246
288
|
}
|
|
247
289
|
else {
|
|
248
|
-
return { status:
|
|
290
|
+
return { status: orphan.status, ts: orphan.ts };
|
|
249
291
|
}
|
|
250
292
|
}
|
|
251
293
|
// 死亡セッションの sweep マーク。transcript が伸びたら破棄(誤判定からの回復)。
|
|
@@ -279,7 +321,8 @@ export class SubagentTailer {
|
|
|
279
321
|
// 終端した起動元」に根ざした木だけ。条件:
|
|
280
322
|
// - 背景起動(forked-skill、または async 起動 ack 済み)だが有効な完了信号がない
|
|
281
323
|
// - 最後の message 行が「text のみの assistant」(最終レポート済み。再開注入の
|
|
282
|
-
// user
|
|
324
|
+
// user 行や生成途中の thinking 行でマーカーが倒れるため、再開直後の長考中・
|
|
325
|
+
// 長い最終レポートのストリーミング中は候補にならない)
|
|
283
326
|
// - transcript が agentOrphanGraceMs 以上静止(transcript 時刻起点なので
|
|
284
327
|
// tail 張り直し直後でも古い孤児は即 settle できる)
|
|
285
328
|
// - 直下に running かつ非候補の子(エージェント/背景コマンド)がいない(fixpoint。
|
|
@@ -287,10 +330,19 @@ export class SubagentTailer {
|
|
|
287
330
|
// - 起動元が終端済み、または「終端済みに根ざして承認された候補」(承認は終端
|
|
288
331
|
// アンカーからの伝播のみ。候補同士の相互承認では settle しないので、壊れた
|
|
289
332
|
// meta の循環参照でも誤 settle しない)
|
|
333
|
+
// - 例外=「通知済み継続」: 完了通知が一度出た後に自 transcript が伸びたノードは、
|
|
334
|
+
// 起動元が root でも settle する。ハーネスは 1 回の走行につき最初の停止でしか
|
|
335
|
+
// 通知しないため、停止境界で自分の背景タスク通知([SYSTEM NOTIFICATION])を
|
|
336
|
+
// 受け取って続行した走行の 2 度目の停止には通知が来ない(実測: 通知後 3 分続行し
|
|
337
|
+
// 最終レポートで停止 → 20 時間「実行中」残留)。通知済み = 起動元へ完了が届いた
|
|
338
|
+
// 後なので、SendMessage 待機中の「未通知の生存エージェント」保護とは衝突しない。
|
|
339
|
+
// coordinator 再開(SendMessage)なら再通知が数秒で届き、そちらの ts が優先される。
|
|
290
340
|
const agentStatusById = new Map();
|
|
291
341
|
for (const node of tracked.values())
|
|
292
342
|
agentStatusById.set(node.nodeId, resolveAgentStatus(node).status);
|
|
293
343
|
const lastActivityMs = (node) => node.lastJsonlTimestampMs ?? mtimeMs(node.jsonlPath ?? node.metaPath);
|
|
344
|
+
// 最終レポートの形で止まっていれば完了、API エラーで途絶えていれば error。
|
|
345
|
+
const settledStatus = (node) => node.finalReportMarker === true && !node.apiErrorMarker ? "completed" : "error";
|
|
294
346
|
if (sessionAlive === false) {
|
|
295
347
|
for (const node of tracked.values()) {
|
|
296
348
|
if (agentStatusById.get(node.nodeId) !== "running")
|
|
@@ -300,11 +352,8 @@ export class SubagentTailer {
|
|
|
300
352
|
const lastTs = lastActivityMs(node);
|
|
301
353
|
if (lastTs <= 0 || nowMs - lastTs < this.agentOrphanGraceMs)
|
|
302
354
|
continue;
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
// 最終レポートの形で止まっていれば完了、tool_use のまま止まっていれば中断(error)。
|
|
306
|
-
status: node.finalReportMarker === true ? "completed" : "error",
|
|
307
|
-
});
|
|
355
|
+
// tool_use のまま止まっていれば中断(error)。
|
|
356
|
+
deadSweepByNodeId.set(node.nodeId, { ts: lastTs, status: settledStatus(node) });
|
|
308
357
|
}
|
|
309
358
|
}
|
|
310
359
|
else {
|
|
@@ -313,6 +362,7 @@ export class SubagentTailer {
|
|
|
313
362
|
if (deadSweepByNodeId.size > 0)
|
|
314
363
|
deadSweepByNodeId.clear();
|
|
315
364
|
const settleCandidates = new Set();
|
|
365
|
+
const notifiedContinuations = new Set();
|
|
316
366
|
for (const node of tracked.values()) {
|
|
317
367
|
if (agentStatusById.get(node.nodeId) !== "running")
|
|
318
368
|
continue;
|
|
@@ -326,9 +376,15 @@ export class SubagentTailer {
|
|
|
326
376
|
continue;
|
|
327
377
|
if (node.lastJsonlTimestampMs === null)
|
|
328
378
|
continue;
|
|
329
|
-
|
|
379
|
+
// stop_reason 無しの暫定的な最終行は「続きの tool_use を生成中」でもあり得るので長い猶予。
|
|
380
|
+
const graceMs = node.finalDefinite ? this.agentOrphanGraceMs : this.tentativeFinalGraceMs;
|
|
381
|
+
if (nowMs - node.lastJsonlTimestampMs < graceMs)
|
|
330
382
|
continue;
|
|
331
383
|
settleCandidates.add(node.nodeId);
|
|
384
|
+
const notification = notificationByTaskId.get(node.nodeId) ?? null;
|
|
385
|
+
if (notification !== null && notification.ts !== null && node.lastJsonlTimestampMs > notification.ts) {
|
|
386
|
+
notifiedContinuations.add(node.nodeId);
|
|
387
|
+
}
|
|
332
388
|
}
|
|
333
389
|
for (;;) {
|
|
334
390
|
const blockedOwners = new Set();
|
|
@@ -365,6 +421,12 @@ export class SubagentTailer {
|
|
|
365
421
|
const node = tracked.get(id);
|
|
366
422
|
if (node === undefined)
|
|
367
423
|
continue;
|
|
424
|
+
// 通知済み継続は起動元を問わず承認(起動元へは完了が届いている)。
|
|
425
|
+
if (notifiedContinuations.has(id)) {
|
|
426
|
+
approved.add(id);
|
|
427
|
+
changed = true;
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
368
430
|
const ownerId = ownerOf(node);
|
|
369
431
|
if (ownerId === undefined || ownerId === "root")
|
|
370
432
|
continue;
|
|
@@ -381,7 +443,7 @@ export class SubagentTailer {
|
|
|
381
443
|
const node = tracked.get(id);
|
|
382
444
|
if (node === undefined)
|
|
383
445
|
continue;
|
|
384
|
-
|
|
446
|
+
agentOrphanByNodeId.set(id, { ts: lastActivityMs(node), status: settledStatus(node) });
|
|
385
447
|
}
|
|
386
448
|
}
|
|
387
449
|
for (const node of tracked.values()) {
|
|
@@ -398,6 +460,7 @@ export class SubagentTailer {
|
|
|
398
460
|
status,
|
|
399
461
|
currentActivity: status === "running" ? node.currentActivity : null,
|
|
400
462
|
ts,
|
|
463
|
+
...(node.model !== null ? { model: node.model } : {}),
|
|
401
464
|
};
|
|
402
465
|
const key = stableNodeKey(messageNode);
|
|
403
466
|
if (key === node.lastKey)
|
|
@@ -516,7 +579,10 @@ function discoverMetaFiles(dir, tracked, refreshMetas) {
|
|
|
516
579
|
firstJsonlTimestampMs: null,
|
|
517
580
|
lastJsonlTimestampMs: null,
|
|
518
581
|
finalReportMarker: null,
|
|
582
|
+
finalDefinite: false,
|
|
583
|
+
apiErrorMarker: false,
|
|
519
584
|
currentActivity: null,
|
|
585
|
+
model: null,
|
|
520
586
|
lastKey: null,
|
|
521
587
|
});
|
|
522
588
|
changed = true;
|
|
@@ -730,37 +796,128 @@ function extractBackgroundSpawns(line) {
|
|
|
730
796
|
return out;
|
|
731
797
|
}
|
|
732
798
|
/**
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
*
|
|
799
|
+
* `<task-notification>` ブロックを運ぶ行の本文と出所(enqueue = 完了時点の正確な ts を
|
|
800
|
+
* 持つ)を返す。配達形は 4 つ:
|
|
801
|
+
* - user 行(文字列 content): 起動元がターン境界で受け取った通知(ts ≈ 完了時刻)
|
|
802
|
+
* - attachment(queued_command) 行: 起動元がターン中だったとき、次の tool_result 境界で
|
|
803
|
+
* 配達された通知(prompt に本文。user 行としては残らない。ts は enqueue 時刻)
|
|
804
|
+
* - queue-operation 行(content): ハーネスのキュー操作ログ。`enqueue` は完了時点で
|
|
805
|
+
* 配達より先に書かれる最速の信号。`remove` は配達後(実測で最大 268s 後)に書かれる
|
|
806
|
+
* ログなので読まない — その ts を通知時刻に採ると、配達遅延の間に起きた再開
|
|
807
|
+
* (SendMessage)を「通知より古い行」と誤認して completed に塗ってしまう。
|
|
808
|
+
* - assistant 行の text ブロック末尾(`<system-reminder>` 包み。Claude Code 2.1.251〜の
|
|
809
|
+
* 停止境界注入): 通知が user 行に残らない配達形。行頭形ブロックの中身だけを返す
|
|
810
|
+
* (引用・fence 内には反応しない。ts は assistant 行 ≈ 配達時刻)。
|
|
736
811
|
*/
|
|
737
|
-
function
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
812
|
+
function notificationText(line) {
|
|
813
|
+
try {
|
|
814
|
+
const obj = JSON.parse(line);
|
|
815
|
+
if (obj["type"] === "attachment") {
|
|
816
|
+
const attachment = typeof obj["attachment"] === "object" && obj["attachment"] !== null
|
|
817
|
+
? obj["attachment"]
|
|
818
|
+
: null;
|
|
819
|
+
if (attachment?.["type"] !== "queued_command")
|
|
820
|
+
return null;
|
|
821
|
+
return typeof attachment["prompt"] === "string" ? { text: attachment["prompt"], enqueue: false } : null;
|
|
822
|
+
}
|
|
823
|
+
if (obj["type"] === "queue-operation") {
|
|
824
|
+
if (obj["operation"] !== "enqueue")
|
|
825
|
+
return null;
|
|
826
|
+
return typeof obj["content"] === "string" ? { text: obj["content"], enqueue: true } : null;
|
|
827
|
+
}
|
|
828
|
+
const message = obj["message"];
|
|
829
|
+
if (typeof message === "object" && message !== null) {
|
|
830
|
+
const content = message["content"];
|
|
831
|
+
if (typeof content === "string")
|
|
832
|
+
return { text: content, enqueue: false };
|
|
833
|
+
// 停止境界の背景通知注入(Claude Code 2.1.251〜): 通知が user 行に残らず、直前の
|
|
834
|
+
// assistant text ブロック末尾へ <system-reminder> として追記される。行頭形ブロックの
|
|
835
|
+
// 中身だけを通知本文として読む(表示側の除去と同じ門番なので、モデルが本文や fence
|
|
836
|
+
// 内で引用した <task-notification> には反応しない)。
|
|
837
|
+
if (obj["type"] === "assistant" && Array.isArray(content)) {
|
|
838
|
+
const joined = content
|
|
839
|
+
.flatMap((block) => {
|
|
840
|
+
if (typeof block !== "object" || block === null)
|
|
841
|
+
return [];
|
|
842
|
+
const rec = block;
|
|
843
|
+
return rec["type"] === "text" && typeof rec["text"] === "string" ? [rec["text"]] : [];
|
|
844
|
+
})
|
|
845
|
+
.join("\n");
|
|
846
|
+
if (!joined.includes("<task-notification>"))
|
|
847
|
+
return null;
|
|
848
|
+
const bodies = injectedReminderBodies(joined);
|
|
849
|
+
return bodies.length > 0 ? { text: bodies.join("\n"), enqueue: false } : null;
|
|
850
|
+
}
|
|
851
|
+
return null;
|
|
852
|
+
}
|
|
853
|
+
return typeof obj["content"] === "string" ? { text: obj["content"], enqueue: false } : null;
|
|
854
|
+
}
|
|
855
|
+
catch {
|
|
743
856
|
return null;
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* 行に含まれる `<task-notification>` を全て解析する(1 行に複数ブロックが束ねられる:
|
|
861
|
+
* 同時に終わった背景コマンド 2 件が 1 つの [SYSTEM NOTIFICATION] で届く等)。
|
|
862
|
+
* バックグラウンドのエージェント/コマンド共通の完了信号で、task-id はエージェントの
|
|
863
|
+
* nodeId またはコマンドの taskId に一致する。同じ封筒は完了以外にも使われる
|
|
864
|
+
* (Monitor の進捗 `<event>`、背景コマンドの「対話入力待ちらしい」ヒント)。それらは
|
|
865
|
+
* `<status>` を持たないので、`<status>` のないブロックは完了信号として扱わない。
|
|
866
|
+
*/
|
|
867
|
+
function extractTaskNotifications(line) {
|
|
868
|
+
const carried = notificationText(line);
|
|
869
|
+
if (carried === null || !carried.text.includes("<task-notification>"))
|
|
870
|
+
return [];
|
|
871
|
+
const content = carried.text;
|
|
872
|
+
const ts = timestampMs(line);
|
|
873
|
+
const out = [];
|
|
874
|
+
const blockPattern = /<task-notification>([\s\S]*?)(?:<\/task-notification>|$)/g;
|
|
875
|
+
for (const match of content.matchAll(blockPattern)) {
|
|
876
|
+
const block = match[1] ?? "";
|
|
877
|
+
const taskId = /<task-id>([^<]+)<\/task-id>/.exec(block)?.[1];
|
|
878
|
+
if (taskId === undefined)
|
|
879
|
+
continue;
|
|
880
|
+
const status = /<status>([^<]+)<\/status>/.exec(block)?.[1];
|
|
881
|
+
if (status === undefined)
|
|
882
|
+
continue;
|
|
883
|
+
const summary = /<summary>([^<]*)<\/summary>/.exec(block)?.[1] ?? "";
|
|
884
|
+
const exitCode = /exit code (\d+)/.exec(summary)?.[1];
|
|
885
|
+
out.push({
|
|
886
|
+
taskId,
|
|
887
|
+
status,
|
|
888
|
+
exitCode: exitCode === undefined ? null : Number(exitCode),
|
|
889
|
+
ts,
|
|
890
|
+
enqueue: carried.enqueue,
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
return out;
|
|
753
894
|
}
|
|
895
|
+
/** message の生成完了を示す stop_reason(これ以外は「続きがある」か「不明」)。 */
|
|
896
|
+
const TERMINAL_STOP_REASONS = new Set(["end_turn", "stop_sequence", "max_tokens", "refusal"]);
|
|
897
|
+
/** 続きのブロック/ターンが確定している stop_reason(text のみ行でも最終レポートではない)。 */
|
|
898
|
+
const CONTINUING_STOP_REASONS = new Set(["tool_use", "pause_turn"]);
|
|
754
899
|
/**
|
|
755
900
|
* message 行の「最終レポートらしさ」を返す:
|
|
756
|
-
* true = text のみの assistant 行(サブエージェントはこの形で停止する)
|
|
757
|
-
* false = それ以外の message 行(user 行・tool_use を含む assistant
|
|
758
|
-
*
|
|
759
|
-
*
|
|
901
|
+
* final=true = text のみの assistant 行(サブエージェントはこの形で停止する)
|
|
902
|
+
* final=false = それ以外の message 行(user 行・tool_use を含む assistant 行・
|
|
903
|
+
* 生成途中の thinking のみの assistant 行・stop_reason が「続きあり」の text 行)
|
|
904
|
+
* null = message を持たない行(summary 等。判定を変えない)
|
|
905
|
+
* final のまま transcript が静止していればエージェントは停止済み。再開注入
|
|
760
906
|
* (task-notification / SendMessage)は user 行として届き false へ倒れるため、
|
|
761
907
|
* 再開直後の長考中を「最終レポート済み」と誤認しない。
|
|
908
|
+
* claude は content ブロックを 1 行ずつ書く(実データ: サブエージェント側 assistant 2.4 万行中
|
|
909
|
+
* 複数ブロックは 1 行、main 側 4.0 万行中 0)。
|
|
910
|
+
* thinking ブロックの行は後続の text/tool_use をまだ生成中の印(最終行になるのは中断時だけ)
|
|
911
|
+
* なので final=false。text 行の stop_reason は:
|
|
912
|
+
* - 終端(end_turn 等)→ definite(生成完了確定。確定形の猶予)
|
|
913
|
+
* - tool_use / pause_turn → 続きの tool_use/ターンが確定 → final=false(message 途中の text 行を
|
|
914
|
+
* main 側 writer はこの形で書く: main transcript で 3,685 行、サブエージェント側は 10 行。
|
|
915
|
+
* 99.9% が同一 message の tool_use 行に続かれ、最終行になった例は両側とも 0)
|
|
916
|
+
* - null / 欠落 / 未知 → 暫定(サブエージェント側 writer は message 途中の text 行を null で
|
|
917
|
+
* 書く(無音の最長は実測 135s、>120s は 0.4%)。一方で null のまま書かれた最終レポートも
|
|
918
|
+
* 版を問わず 6〜30%(全体 11.7%)あり判別不能)→ 呼び出し側が長い猶予で扱う
|
|
762
919
|
*/
|
|
763
|
-
function
|
|
920
|
+
function messageShape(line) {
|
|
764
921
|
try {
|
|
765
922
|
const obj = JSON.parse(line);
|
|
766
923
|
const message = obj["message"];
|
|
@@ -771,18 +928,43 @@ function finalReportMarker(line) {
|
|
|
771
928
|
if (content === undefined || content === null)
|
|
772
929
|
return null;
|
|
773
930
|
if (rec["role"] !== "assistant")
|
|
774
|
-
return false;
|
|
931
|
+
return { final: false, definite: false, apiError: false, model: null };
|
|
932
|
+
const model = executionModel(rec["model"]);
|
|
933
|
+
const notFinal = { final: false, definite: false, apiError: false, model };
|
|
934
|
+
const apiError = obj["isApiErrorMessage"] === true;
|
|
935
|
+
const stopReason = typeof rec["stop_reason"] === "string" ? rec["stop_reason"] : null;
|
|
936
|
+
if (stopReason !== null && CONTINUING_STOP_REASONS.has(stopReason))
|
|
937
|
+
return notFinal;
|
|
938
|
+
const definite = stopReason !== null && TERMINAL_STOP_REASONS.has(stopReason);
|
|
775
939
|
if (typeof content === "string")
|
|
776
|
-
return true;
|
|
940
|
+
return { final: true, definite, apiError, model };
|
|
777
941
|
if (!Array.isArray(content))
|
|
778
942
|
return null;
|
|
779
|
-
|
|
780
|
-
|
|
943
|
+
const types = content.map((block) => typeof block === "object" && block !== null
|
|
944
|
+
? block["type"]
|
|
945
|
+
: undefined);
|
|
946
|
+
if (types.includes("tool_use"))
|
|
947
|
+
return notFinal;
|
|
948
|
+
const thinkingOnly = types.length > 0
|
|
949
|
+
&& types.every((type) => type === "thinking" || type === "redacted_thinking");
|
|
950
|
+
if (thinkingOnly)
|
|
951
|
+
return notFinal;
|
|
952
|
+
return { final: true, definite, apiError, model };
|
|
781
953
|
}
|
|
782
954
|
catch {
|
|
783
955
|
return null;
|
|
784
956
|
}
|
|
785
957
|
}
|
|
958
|
+
/**
|
|
959
|
+
* assistant 行 `message.model` の値を実行モデルの slug として読む。
|
|
960
|
+
* `<synthetic>` 等の `<` 始まり(ハーネス合成行の印)と空文字は実行モデルではないので null。
|
|
961
|
+
*/
|
|
962
|
+
function executionModel(value) {
|
|
963
|
+
if (typeof value !== "string")
|
|
964
|
+
return null;
|
|
965
|
+
const trimmed = value.trim();
|
|
966
|
+
return trimmed.length === 0 || trimmed.startsWith("<") ? null : trimmed;
|
|
967
|
+
}
|
|
786
968
|
function latestActivitySummary(line) {
|
|
787
969
|
const activities = extractToolActivities(messageContent(line));
|
|
788
970
|
const latest = activities.at(-1);
|
|
@@ -979,6 +1161,7 @@ function stableNodeKey(node) {
|
|
|
979
1161
|
node.currentActivity ?? null,
|
|
980
1162
|
node.ts,
|
|
981
1163
|
node.kind ?? null,
|
|
1164
|
+
node.model ?? null,
|
|
982
1165
|
]);
|
|
983
1166
|
}
|
|
984
1167
|
//# sourceMappingURL=subagentTailer.js.map
|