@zhushanwen/pi-subagent-workflow 9.2.0 → 9.3.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/package.json +16 -16
- package/src/host/__tests__/inflight-reporter.test.ts +44 -56
- package/src/host/__tests__/journal-reporter.test.ts +230 -0
- package/src/host/__tests__/staged-discovery.test.ts +147 -0
- package/src/host/inflight-reporter.ts +29 -82
- package/src/host/journal-reporter.ts +204 -0
- package/src/host/pi-host.ts +54 -6
- package/src/interface/command/subagents.ts +2 -2
- package/src/interface/tool/subagent-tool.ts +6 -5
- package/src/interface/tool/tool-workflow-script.ts +13 -9
- package/src/session-lifecycle.ts +4 -6
- package/src/workflow-events.ts +30 -5
package/src/workflow-events.ts
CHANGED
|
@@ -52,6 +52,9 @@ import { getSubagentService } from "@zhushanwen/subagent-core";
|
|
|
52
52
|
import type { LauncherDeps } from "@zhushanwen/subagent-core";
|
|
53
53
|
import { terminateRunningRuns } from "@zhushanwen/subagent-core";
|
|
54
54
|
import { setInFlightListener } from "@zhushanwen/subagent-core";
|
|
55
|
+
// [event-push-channel W-P1] journal 落盘事件出口接线:core 两域落盘提交点 → 出口
|
|
56
|
+
// 回调 → 壳层 journal reporter(select marker 通道带回执推送 runtime 派生视图)。
|
|
57
|
+
import { setJournalAppendListener } from "@zhushanwen/subagent-core";
|
|
55
58
|
import {
|
|
56
59
|
evictDoneRunsBeyondCap,
|
|
57
60
|
MAX_RETAINED_DONE_RUNS,
|
|
@@ -65,6 +68,10 @@ import { WorkflowScriptRegistryImpl } from "@zhushanwen/subagent-core";
|
|
|
65
68
|
// [u7a D5] 在途上报出口:实例由本 seam 创建并接线 setInFlightListener(组合根零
|
|
66
69
|
// 管道),session_start / session_shutdown 驱动 attach/detach;测试可注入 fake。
|
|
67
70
|
import { createInFlightReporter, type InFlightReporter } from "./host/inflight-reporter.ts";
|
|
71
|
+
// [event-push-channel W-P1] journal 推送出口:实例由本 seam 创建并接线
|
|
72
|
+
// setJournalAppendListener(与 inflight reporter 同 seam 同款),session_start /
|
|
73
|
+
// session_shutdown 驱动 attach/detach;测试可注入 fake。
|
|
74
|
+
import { createJournalReporter, type JournalReporter } from "./host/journal-reporter.ts";
|
|
68
75
|
// [W2/V1 D1 第 8 行] 判活类消费面(isScriptRunning)经 core 投影单点
|
|
69
76
|
//(runSummary.status 三态投影——终局判定源 = 终局记录注册表)。
|
|
70
77
|
import { type RunSettlementRecord } from "./jsonl-run-store.ts";
|
|
@@ -274,7 +281,7 @@ export interface WorkflowDomainHandle {
|
|
|
274
281
|
*/
|
|
275
282
|
export function setupWorkflowDomain(
|
|
276
283
|
pi: ExtensionAPI,
|
|
277
|
-
wiring: { inflightReporter?: InFlightReporter } = {},
|
|
284
|
+
wiring: { inflightReporter?: InFlightReporter; journalReporter?: JournalReporter } = {},
|
|
278
285
|
): WorkflowDomainHandle {
|
|
279
286
|
// [u7a D5] 在途聚合上报接线(自组合根 index.ts 收编):core 状态迁移
|
|
280
287
|
// (spawn/close/arm/disarm)→ 出口回调 → reporter 经 select 通道推绝对计数帧。
|
|
@@ -285,6 +292,14 @@ export function setupWorkflowDomain(
|
|
|
285
292
|
// 组合根对实例零知识(纯管道参数已删)。
|
|
286
293
|
const inflightReporter = wiring.inflightReporter ?? createInFlightReporter();
|
|
287
294
|
setInFlightListener(inflightReporter.onInFlightChanged);
|
|
295
|
+
// [event-push-channel W-P1] journal 推送出口接线(与 inflight reporter 同 seam 同款):
|
|
296
|
+
// core 两域落盘提交点 → 出口回调 → reporter 按 (domain,fileKey) 分组合并 → select
|
|
297
|
+
// marker 通道带回执推送 runtime。出口为进程级单监听,后注册覆盖先注册(jiti 重载
|
|
298
|
+
// 幂等);回调同步 void,不进任何落盘 await 链。ctx 由 session_start 注入
|
|
299
|
+
// (factory 阶段无 ui)。wiring.journalReporter 是测试注入面(fake reporter 观察
|
|
300
|
+
// attach/detach 驱动时点);生产路径缺省真实创建——组合根对实例零知识。
|
|
301
|
+
const journalReporter = wiring.journalReporter ?? createJournalReporter();
|
|
302
|
+
setJournalAppendListener(journalReporter.onJournalAppended);
|
|
288
303
|
// [skill-reload D2] handle.state 即槽对象本身(不做解构重包装——否则容器每次
|
|
289
304
|
// factory 重跑新建,调用方拿不到「同一 domain state 引用」的接管前提)。
|
|
290
305
|
const domainState = getOrCreateWorkflowDomainState();
|
|
@@ -436,16 +451,20 @@ export function setupWorkflowDomain(
|
|
|
436
451
|
// 开头一致)+ 装配结果写入 per-session sessionState。
|
|
437
452
|
// ════════════════════════════════════════════════════════════
|
|
438
453
|
pi.on("session_start", async (event: SessionStartEvent, ctx: ExtensionContext) => {
|
|
439
|
-
// 装配链异常不向 pi 事件分发逃逸(
|
|
440
|
-
// 直接炸进程——E1
|
|
454
|
+
// 装配链异常不向 pi 事件分发逃逸(0.84.4 的 extension handler 未捕获 rejection
|
|
455
|
+
// 直接炸进程——E1 同机制;1.0.0 起 runner.emit 以 try/catch 吸收转 emitError 上报,
|
|
456
|
+
// 围栏仍保留——handler 不依赖 pi 侧异常处理语义):error 留痕(含 sessionId)后保持 handler 不抛。
|
|
441
457
|
// lsRef 在 try 内先行赋值:getSessionId 自身抛错时 catch 里拿到的是上一 session
|
|
442
458
|
// 的 id(留痕仍可检索)。
|
|
443
459
|
try {
|
|
444
460
|
lsRef.lastSessionId = ctx.sessionManager.getSessionId();
|
|
445
461
|
// [u7a D5] 初始上报(count=当下绝对计数):触发时点 = extension 加载完成 / session
|
|
446
|
-
// 就绪(factory 无 ctx/ui,session_start 是最早带 ctx
|
|
447
|
-
//
|
|
462
|
+
// 就绪(factory 无 ctx/ui,session_start 是最早带 ctx 的钩子)。fire-and-forget
|
|
463
|
+
// 在 await 装配链之前发起,不阻塞也不被阻塞。
|
|
448
464
|
inflightReporter.attachSession(ctx);
|
|
465
|
+
// [event-push-channel W-P1] journal 推送出口 attach(事件驱动,无初始帧——
|
|
466
|
+
// 报告语义是增量事件,缺席语义归消费方冷读)。
|
|
467
|
+
journalReporter.attachSession(ctx);
|
|
449
468
|
// [skill-reload D4] adoption 入参接线:reason 是 handler 独占信息(event 参数),
|
|
450
469
|
// existing 是 sessionState(domainState 闭包)里的既有条目——两者都是
|
|
451
470
|
// session-lifecycle seam 的 adoption 分流判据,经 SessionStartOptions 传入。
|
|
@@ -546,6 +565,9 @@ export function setupWorkflowDomain(
|
|
|
546
565
|
getSubagentService()?.invalidatePiBinding("session replacement (reload)");
|
|
547
566
|
// b 动作保留(理由见上方 D1 分支说明)。
|
|
548
567
|
inflightReporter.detachSession();
|
|
568
|
+
// [event-push-channel W-P1] journal 推送通道随 reload 同步摘 ctx(旧 ctx 的
|
|
569
|
+
// session 已被 pi 替换,推送帧无法归属;新 session_start 重新 attach)。
|
|
570
|
+
journalReporter.detachSession();
|
|
549
571
|
|
|
550
572
|
// [skill-reload D8] reload 分支归因日志:preserved 计数取自跳过清理时的存活
|
|
551
573
|
// 对象真实统计(runs = 各 session 内存 run 聚合根数;records = run.state.calls
|
|
@@ -582,6 +604,9 @@ export function setupWorkflowDomain(
|
|
|
582
604
|
// [u7a D5] 在途上报通道随 session 终结:摘 ctx + 停重试(session 已死,重试直至
|
|
583
605
|
// 成功的语义只对活 session 成立;进程级出口监听保留——后续 /new 重新 attach)。
|
|
584
606
|
inflightReporter.detachSession();
|
|
607
|
+
// [event-push-channel W-P1] journal 推送通道随 session 终结:摘 ctx + 丢弃待推
|
|
608
|
+
// 缓冲(未推事件由消费方冷读/缺口补读收敛,不重推——设计 D5)。
|
|
609
|
+
journalReporter.detachSession();
|
|
585
610
|
|
|
586
611
|
// ── workflow 域:terminate 所有 running run + store 收尾 + 清理 temp files ──
|
|
587
612
|
// H-5: 遍历所有 sessionState 条目清理(而不只 lastSessionId——
|