@esso0428/pi-subagents 0.17.6 → 0.17.8

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.
Files changed (260) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/CONTRIBUTING.md +4 -0
  3. package/dist/abortable.d.ts +13 -0
  4. package/dist/abortable.d.ts.map +1 -0
  5. package/dist/abortable.js +43 -0
  6. package/dist/abortable.js.map +1 -0
  7. package/dist/agent-color.d.ts +36 -0
  8. package/dist/agent-color.d.ts.map +1 -0
  9. package/dist/agent-color.js +124 -0
  10. package/dist/agent-color.js.map +1 -0
  11. package/dist/agent-file-toggle.d.ts +126 -0
  12. package/dist/agent-file-toggle.d.ts.map +1 -0
  13. package/dist/agent-file-toggle.js +259 -0
  14. package/dist/agent-file-toggle.js.map +1 -0
  15. package/dist/agent-history.d.ts +4 -0
  16. package/dist/agent-history.d.ts.map +1 -1
  17. package/dist/agent-history.js +47 -1
  18. package/dist/agent-history.js.map +1 -1
  19. package/dist/agent-manager.d.ts +370 -56
  20. package/dist/agent-manager.d.ts.map +1 -1
  21. package/dist/agent-manager.js +1123 -409
  22. package/dist/agent-manager.js.map +1 -1
  23. package/dist/agent-runner.d.ts +100 -10
  24. package/dist/agent-runner.d.ts.map +1 -1
  25. package/dist/agent-runner.js +166 -21
  26. package/dist/agent-runner.js.map +1 -1
  27. package/dist/agent-types.d.ts +57 -5
  28. package/dist/agent-types.d.ts.map +1 -1
  29. package/dist/agent-types.js +164 -32
  30. package/dist/agent-types.js.map +1 -1
  31. package/dist/child-context.d.ts +3 -0
  32. package/dist/child-context.d.ts.map +1 -0
  33. package/dist/child-context.js +13 -0
  34. package/dist/child-context.js.map +1 -0
  35. package/dist/cross-extension-rpc.d.ts +23 -3
  36. package/dist/cross-extension-rpc.d.ts.map +1 -1
  37. package/dist/cross-extension-rpc.js +79 -17
  38. package/dist/cross-extension-rpc.js.map +1 -1
  39. package/dist/custom-agents.d.ts +38 -1
  40. package/dist/custom-agents.d.ts.map +1 -1
  41. package/dist/custom-agents.js +164 -12
  42. package/dist/custom-agents.js.map +1 -1
  43. package/dist/index.d.ts +34 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +1912 -492
  46. package/dist/index.js.map +1 -1
  47. package/dist/invocation-config.d.ts +87 -2
  48. package/dist/invocation-config.d.ts.map +1 -1
  49. package/dist/invocation-config.js +71 -3
  50. package/dist/invocation-config.js.map +1 -1
  51. package/dist/mention-clone.d.ts +88 -0
  52. package/dist/mention-clone.d.ts.map +1 -0
  53. package/dist/mention-clone.js +154 -0
  54. package/dist/mention-clone.js.map +1 -0
  55. package/dist/mention.d.ts +82 -0
  56. package/dist/mention.d.ts.map +1 -0
  57. package/dist/mention.js +132 -0
  58. package/dist/mention.js.map +1 -0
  59. package/dist/model-resolver.d.ts +17 -0
  60. package/dist/model-resolver.d.ts.map +1 -1
  61. package/dist/model-resolver.js +15 -0
  62. package/dist/model-resolver.js.map +1 -1
  63. package/dist/model-scope.d.ts +50 -0
  64. package/dist/model-scope.d.ts.map +1 -0
  65. package/dist/model-scope.js +49 -0
  66. package/dist/model-scope.js.map +1 -0
  67. package/dist/nested-tools.d.ts +57 -0
  68. package/dist/nested-tools.d.ts.map +1 -0
  69. package/dist/nested-tools.js +301 -0
  70. package/dist/nested-tools.js.map +1 -0
  71. package/dist/output-file.d.ts +22 -3
  72. package/dist/output-file.d.ts.map +1 -1
  73. package/dist/output-file.js +58 -7
  74. package/dist/output-file.js.map +1 -1
  75. package/dist/prompts.d.ts +23 -0
  76. package/dist/prompts.d.ts.map +1 -1
  77. package/dist/prompts.js +20 -2
  78. package/dist/prompts.js.map +1 -1
  79. package/dist/schedule.d.ts.map +1 -1
  80. package/dist/schedule.js +36 -15
  81. package/dist/schedule.js.map +1 -1
  82. package/dist/settings.d.ts +228 -2
  83. package/dist/settings.d.ts.map +1 -1
  84. package/dist/settings.js +94 -0
  85. package/dist/settings.js.map +1 -1
  86. package/dist/status-note.d.ts +49 -1
  87. package/dist/status-note.d.ts.map +1 -1
  88. package/dist/status-note.js +62 -1
  89. package/dist/status-note.js.map +1 -1
  90. package/dist/structured-output.d.ts +62 -0
  91. package/dist/structured-output.d.ts.map +1 -0
  92. package/dist/structured-output.js +113 -0
  93. package/dist/structured-output.js.map +1 -0
  94. package/dist/types.d.ts +176 -10
  95. package/dist/types.d.ts.map +1 -1
  96. package/dist/ui/agent-mention.d.ts +83 -0
  97. package/dist/ui/agent-mention.d.ts.map +1 -0
  98. package/dist/ui/agent-mention.js +188 -0
  99. package/dist/ui/agent-mention.js.map +1 -0
  100. package/dist/ui/agent-widget.d.ts +97 -75
  101. package/dist/ui/agent-widget.d.ts.map +1 -1
  102. package/dist/ui/agent-widget.js +398 -420
  103. package/dist/ui/agent-widget.js.map +1 -1
  104. package/dist/ui/conversation-blocks.d.ts.map +1 -1
  105. package/dist/ui/conversation-blocks.js +6 -0
  106. package/dist/ui/conversation-blocks.js.map +1 -1
  107. package/dist/ui/conversation-timeline.d.ts +10 -2
  108. package/dist/ui/conversation-timeline.d.ts.map +1 -1
  109. package/dist/ui/conversation-timeline.js +130 -23
  110. package/dist/ui/conversation-timeline.js.map +1 -1
  111. package/dist/ui/conversation-viewer.d.ts +15 -5
  112. package/dist/ui/conversation-viewer.d.ts.map +1 -1
  113. package/dist/ui/conversation-viewer.js +202 -50
  114. package/dist/ui/conversation-viewer.js.map +1 -1
  115. package/dist/ui/fleet-list.d.ts +198 -0
  116. package/dist/ui/fleet-list.d.ts.map +1 -0
  117. package/dist/ui/fleet-list.js +487 -0
  118. package/dist/ui/fleet-list.js.map +1 -0
  119. package/dist/ui/schedule-menu.d.ts.map +1 -1
  120. package/dist/ui/schedule-menu.js +6 -7
  121. package/dist/ui/schedule-menu.js.map +1 -1
  122. package/dist/ui/select-item.d.ts +28 -0
  123. package/dist/ui/select-item.d.ts.map +1 -0
  124. package/dist/ui/select-item.js +35 -0
  125. package/dist/ui/select-item.js.map +1 -0
  126. package/dist/ui/workflow-card.d.ts +176 -0
  127. package/dist/ui/workflow-card.d.ts.map +1 -0
  128. package/dist/ui/workflow-card.js +333 -0
  129. package/dist/ui/workflow-card.js.map +1 -0
  130. package/dist/ui/workflow-dialog.d.ts +306 -0
  131. package/dist/ui/workflow-dialog.d.ts.map +1 -0
  132. package/dist/ui/workflow-dialog.js +844 -0
  133. package/dist/ui/workflow-dialog.js.map +1 -0
  134. package/dist/ui/workflow-menu.d.ts +61 -0
  135. package/dist/ui/workflow-menu.d.ts.map +1 -0
  136. package/dist/ui/workflow-menu.js +148 -0
  137. package/dist/ui/workflow-menu.js.map +1 -0
  138. package/dist/usage.d.ts +86 -1
  139. package/dist/usage.d.ts.map +1 -1
  140. package/dist/usage.js +72 -1
  141. package/dist/usage.js.map +1 -1
  142. package/dist/workflow/collisions.d.ts +96 -0
  143. package/dist/workflow/collisions.d.ts.map +1 -0
  144. package/dist/workflow/collisions.js +89 -0
  145. package/dist/workflow/collisions.js.map +1 -0
  146. package/dist/workflow/entry.d.ts +33 -0
  147. package/dist/workflow/entry.d.ts.map +1 -0
  148. package/dist/workflow/entry.js +30 -0
  149. package/dist/workflow/entry.js.map +1 -0
  150. package/dist/workflow/host.d.ts +63 -0
  151. package/dist/workflow/host.d.ts.map +1 -0
  152. package/dist/workflow/host.js +363 -0
  153. package/dist/workflow/host.js.map +1 -0
  154. package/dist/workflow/journal.d.ts +98 -0
  155. package/dist/workflow/journal.d.ts.map +1 -0
  156. package/dist/workflow/journal.js +121 -0
  157. package/dist/workflow/journal.js.map +1 -0
  158. package/dist/workflow/json-schema.d.ts +52 -0
  159. package/dist/workflow/json-schema.d.ts.map +1 -0
  160. package/dist/workflow/json-schema.js +112 -0
  161. package/dist/workflow/json-schema.js.map +1 -0
  162. package/dist/workflow/meta.d.ts +68 -0
  163. package/dist/workflow/meta.d.ts.map +1 -0
  164. package/dist/workflow/meta.js +318 -0
  165. package/dist/workflow/meta.js.map +1 -0
  166. package/dist/workflow/progress.d.ts +225 -0
  167. package/dist/workflow/progress.d.ts.map +1 -0
  168. package/dist/workflow/progress.js +362 -0
  169. package/dist/workflow/progress.js.map +1 -0
  170. package/dist/workflow/runtime.d.ts +335 -0
  171. package/dist/workflow/runtime.d.ts.map +1 -0
  172. package/dist/workflow/runtime.js +831 -0
  173. package/dist/workflow/runtime.js.map +1 -0
  174. package/dist/workflow/saved.d.ts +91 -0
  175. package/dist/workflow/saved.d.ts.map +1 -0
  176. package/dist/workflow/saved.js +204 -0
  177. package/dist/workflow/saved.js.map +1 -0
  178. package/dist/workflow/task.d.ts +137 -0
  179. package/dist/workflow/task.d.ts.map +1 -0
  180. package/dist/workflow/task.js +208 -0
  181. package/dist/workflow/task.js.map +1 -0
  182. package/dist/workflow/tool-description.d.ts +39 -0
  183. package/dist/workflow/tool-description.d.ts.map +1 -0
  184. package/dist/workflow/tool-description.js +200 -0
  185. package/dist/workflow/tool-description.js.map +1 -0
  186. package/dist/workflow/worker-source.d.ts +48 -0
  187. package/dist/workflow/worker-source.d.ts.map +1 -0
  188. package/dist/workflow/worker-source.js +779 -0
  189. package/dist/workflow/worker-source.js.map +1 -0
  190. package/dist/worktree.d.ts +10 -3
  191. package/dist/worktree.d.ts.map +1 -1
  192. package/dist/worktree.js +58 -54
  193. package/dist/worktree.js.map +1 -1
  194. package/dist/xml.d.ts +11 -0
  195. package/dist/xml.d.ts.map +1 -0
  196. package/dist/xml.js +13 -0
  197. package/dist/xml.js.map +1 -0
  198. package/docs/rpc.md +183 -0
  199. package/docs/superpowers/plans/2026-09-30-upstream-event-workflow-partial-history.md +195 -0
  200. package/docs/superpowers/specs/2026-09-30-upstream-event-workflow-partial-history-design.md +49 -0
  201. package/docs/workflows.md +437 -0
  202. package/examples/agent-tool-description.md +7 -7
  203. package/examples/workflows/compose.js +51 -0
  204. package/examples/workflows/fan-out-audit.js +47 -0
  205. package/examples/workflows/gated-fix.js +60 -0
  206. package/examples/workflows/lib/count-child.js +27 -0
  207. package/examples/workflows/review-panel.js +63 -0
  208. package/examples/workflows/structured-findings.js +78 -0
  209. package/package.json +1 -1
  210. package/src/abortable.ts +43 -0
  211. package/src/agent-color.ts +161 -0
  212. package/src/agent-file-toggle.ts +269 -0
  213. package/src/agent-history.ts +54 -2
  214. package/src/agent-manager.ts +1263 -402
  215. package/src/agent-runner.ts +251 -27
  216. package/src/agent-types.ts +188 -32
  217. package/src/child-context.ts +15 -0
  218. package/src/cross-extension-rpc.ts +96 -20
  219. package/src/custom-agents.ts +170 -13
  220. package/src/index.ts +2029 -536
  221. package/src/invocation-config.ts +118 -3
  222. package/src/mention-clone.ts +196 -0
  223. package/src/mention.ts +141 -0
  224. package/src/model-resolver.ts +18 -0
  225. package/src/model-scope.ts +70 -0
  226. package/src/nested-tools.ts +424 -0
  227. package/src/output-file.ts +61 -6
  228. package/src/prompts.ts +45 -2
  229. package/src/schedule.ts +35 -14
  230. package/src/settings.ts +312 -2
  231. package/src/status-note.ts +66 -1
  232. package/src/structured-output.ts +130 -0
  233. package/src/types.ts +177 -10
  234. package/src/ui/agent-mention.ts +216 -0
  235. package/src/ui/agent-widget.ts +393 -441
  236. package/src/ui/conversation-blocks.ts +6 -0
  237. package/src/ui/conversation-timeline.ts +139 -25
  238. package/src/ui/conversation-viewer.ts +212 -48
  239. package/src/ui/fleet-list.ts +558 -0
  240. package/src/ui/schedule-menu.ts +9 -8
  241. package/src/ui/select-item.ts +45 -0
  242. package/src/ui/workflow-card.ts +470 -0
  243. package/src/ui/workflow-dialog.ts +1115 -0
  244. package/src/ui/workflow-menu.ts +193 -0
  245. package/src/usage.ts +109 -2
  246. package/src/workflow/collisions.ts +123 -0
  247. package/src/workflow/entry.ts +47 -0
  248. package/src/workflow/host.ts +403 -0
  249. package/src/workflow/journal.ts +164 -0
  250. package/src/workflow/json-schema.ts +128 -0
  251. package/src/workflow/meta.ts +325 -0
  252. package/src/workflow/progress.ts +550 -0
  253. package/src/workflow/runtime.ts +1219 -0
  254. package/src/workflow/saved.ts +217 -0
  255. package/src/workflow/task.ts +302 -0
  256. package/src/workflow/tool-description.ts +200 -0
  257. package/src/workflow/worker-source.ts +781 -0
  258. package/src/worktree.ts +69 -55
  259. package/src/xml.ts +13 -0
  260. package/vitest.config.ts +0 -18
@@ -0,0 +1,195 @@
1
+ # 上游事件管理、Workflow 與中途歷史實作計畫
2
+
3
+ > [!NOTE]
4
+ > **給 agentic workers:** 本計畫以目前 fork `64bbbb0` 與 `upstream/master` `e955e29` 的實際差異為準。所有步驟使用 checkbox 追蹤;不得刪除 fork 的 durable history/recovery 與 ConversationViewer 特性。
5
+
6
+ **目標:** 接收上游 Workflow、lifecycle/RPC 與 render-cost 改善,同時讓所有子代理 launch path 都留下可重新開啟的 stopped/aborted/partial `.pi-subagents` 歷史。
7
+
8
+ **架構:** 先將上游功能整合進現有 manager/runner/index seam,再把 durable transcript 附掛下沉到 `AgentManager.spawn()`,使 Agent tool、scheduler、RPC、Workflow 共用同一歷史介面。`.output` 僅是可選的外部串流檔;`.pi-subagents` 是 UI/history/checkpoint 的永久資料源。
9
+
10
+ **技術:** TypeScript、pi ExtensionAPI、pi-tui、Vitest、worker-thread Workflow runtime、JSONL transcript、atomic checkpoint。
11
+
12
+ ## 全域限制
13
+
14
+ - 保留套件名稱 `@esso0428/pi-subagents` 與 JSON agent override。
15
+ - 保留 pi peer floor `>=0.80.8`,除非 typecheck 證明不可行且另有相容性處理。
16
+ - `output_transcript: false` 僅停用 temp `.output`,不得停用 `.pi-subagents` durable history。
17
+ - 不刪除 `src/agent-history.ts`、`src/agent-history-list.ts`、`src/agent-recovery.ts`。
18
+ - 不覆蓋 fork 的 ConversationViewer scrollbar、`[preview] [Esc]`、`w` focused-tool preview、in-place Tool Preview。
19
+ - 任何新日期型路徑使用當天 `2026-09-30`。
20
+ - 完成前執行 lint、typecheck、`npm test`、`npm run test:e2e`、build、pack;使用者已明確要求 commit、push、publish。
21
+
22
+ ---
23
+
24
+ ### Task 1:建立上游整合基線
25
+
26
+ **Files:**
27
+ - Modify: `src/agent-manager.ts`, `src/agent-runner.ts`, `src/agent-types.ts`, `src/types.ts`, `src/settings.ts`
28
+ - Modify: `src/index.ts`, `src/cross-extension-rpc.ts`, `src/output-file.ts`, `src/ui/agent-widget.ts`, `src/ui/fleet-list.ts`
29
+ - Add: `src/workflow/*.ts`, `src/ui/workflow-*.ts`, `docs/workflows.md`, `docs/rpc.md`, `examples/workflows/*`
30
+ - Test: upstream workflow/RPC/lifecycle tests selected from `test/workflow-*.test.ts`, `test/rpc-result-consumption.test.ts`, `test/child-session-shutdown.test.ts`
31
+
32
+ **Interfaces:**
33
+ - Consumes: current fork manager/history/UI interfaces and `upstream/master` workflow/runtime/event contracts.
34
+ - Produces: `SubagentWorkflow` registration, workflow host/runtime/task/journal modules, RPC `consume`, lifecycle event ordering, and RPC activity tracking.
35
+
36
+ - [ ] **Step 1: Record the merge inventory.**
37
+
38
+ In `/tmp/pi-canonical/pi-subagents-work`, compare `git diff --name-status 64bbbb0..upstream/master` and group changes into workflow, lifecycle/RPC, UI, package metadata, and deleted history modules. Treat upstream deletions of fork history/recovery as rejected changes.
39
+
40
+ - [ ] **Step 2: Integrate upstream workflow/event files without replacing fork metadata.**
41
+
42
+ Bring in `src/workflow/`, workflow UI, workflow docs/examples, RPC consume/result-consumption changes, session shutdown ordering, scope-model validation, and RPC-spawn activity tracking. Resolve `src/index.ts`, `src/agent-manager.ts`, `src/agent-runner.ts`, `src/types.ts`, `src/settings.ts`, `src/ui/agent-widget.ts`, `src/ui/fleet-list.ts`, and `src/ui/conversation-viewer.ts` manually. Keep `src/nico-overrides.ts` and fork package identity.
43
+
44
+ - [ ] **Step 3: Keep event semantics explicit.**
45
+
46
+ Ensure readiness is emitted only after the extension is bound; normal Agent tool emits `created`, `started`, terminal `completed`/`failed`, compaction emits `compacted`, steering emits `steered`, and shutdown emits `session_shutdown` before child session disposal. RPC-spawned agents must be observable from returned id and must not rely on `created`.
47
+
48
+ - [ ] **Step 4: Run integration-focused tests.**
49
+
50
+ Run:
51
+ ```bash
52
+ npx vitest run test/cross-extension-rpc.test.ts test/rpc-result-consumption.test.ts test/rpc-lifecycle-gating.test.ts test/child-session-shutdown.test.ts test/workflow-tool.test.ts test/workflow-runtime.test.ts test/workflow.e2e.test.ts
53
+ ```
54
+ Expected: all selected tests pass; failures caused by the history/UI seam remain for Tasks 2–3, not hidden by deleting assertions.
55
+
56
+ ---
57
+
58
+ ### Task 2:把 durable partial history 下沉到 manager seam
59
+
60
+ **Files:**
61
+ - Modify: `src/agent-manager.ts`
62
+ - Modify: `src/index.ts`, `src/output-file.ts`
63
+ - Modify: `src/agent-history.ts`, `src/agent-history-list.ts`, `src/agent-recovery.ts`
64
+ - Modify: `src/types.ts`
65
+ - Test: `test/agent-manager-history.test.ts`, `test/agent-history.test.ts`, `test/agent-history-list.test.ts`, `test/agent-recovery.test.ts`, `test/output-file-history.test.ts`, new `test/partial-history-lifecycle.test.ts`
66
+
67
+ **Interfaces:**
68
+ - Consumes: `createAgentHistoryPath`, `agentHistoryLocator`, `writeInitialEntry`, `streamToOutputFile`, `setTranscript`, `checkpoint`, `restoreRecovered`.
69
+ - Produces: every `manager.spawn()` record has a project-local transcript before queue/start; `output_transcript` only controls `.output`; terminal records retain `transcriptPath`.
70
+
71
+ - [ ] **Step 1: Add one manager-owned durable attach operation.**
72
+
73
+ Add a private operation in `AgentManager` that, for a new record, creates `.pi-subagents/agent-transcripts/<safe-id>.jsonl`, writes the initial user entry, assigns `historyFile`/`transcriptPath`, and checkpoints. Make it idempotent so Agent tool callers do not duplicate the initial entry. Invoke it before the external `onSpawned` callback and clean only the checkpoint/record on a failed spawn; do not discard a successfully created transcript.
74
+
75
+ - [ ] **Step 2: Separate `.output` gating from durable history.**
76
+
77
+ Change `attachTranscript()` in `src/index.ts` so `outputTranscript === false` skips only `createOutputFilePath()` and the temp initial entry. It must still use the manager-provided `historyFile` and `transcriptPath`. Keep `streamToOutputFile()` dual-write behavior when `record.outputFile` exists, and ensure no duplicate JSONL entry is written to history.
78
+
79
+ - [ ] **Step 3: Flush before every terminal checkpoint.**
80
+
81
+ In manager stop/abort/queue cancellation, runner completion/error, resume failure, parent abort, and session shutdown paths, call `flushOutput(record)` before `checkpoint(record)`. Preserve status precedence: externally stopped remains `stopped`; hard max-turn interruption becomes `aborted`; provider/length failure becomes `error`; partial assistant text remains in JSONL even when `record.result` is empty.
82
+
83
+ - [ ] **Step 4: Make history visibly partial and reopenable.**
84
+
85
+ Extend `AgentHistoryStatus`/formatting only as needed to label `stopped`, `aborted`, and `error` as terminal partial-capable states. Keep `canOpenAgentHistory()` based on live session or durable locator. In `ConversationViewer`, use the persisted status/read-only source and show a concise status marker in the header/footer without removing `[preview] [Esc]` or existing scrollbar geometry.
86
+
87
+ - [ ] **Step 5: Add path matrix regression tests.**
88
+
89
+ Cover:
90
+ - tool call in progress followed by `manager.abort()`;
91
+ - queued agent cancellation;
92
+ - provider error after an assistant partial delta;
93
+ - max-turn abort/steer;
94
+ - parent signal abort and `abortAll()`;
95
+ - manager restore of running checkpoint as stopped;
96
+ - scheduler and RPC spawn creating `.pi-subagents` history;
97
+ - `output_transcript: false` still retaining durable history;
98
+ - history menu and viewer reopening after live session disposal.
99
+
100
+ Run the focused history/lifecycle tests before proceeding.
101
+
102
+ ---
103
+
104
+ ### Task 3:合併 UI render-cost 與事件刷新防閃動
105
+
106
+ **Files:**
107
+ - Modify: `src/ui/conversation-viewer.ts`
108
+ - Modify: `src/ui/agent-widget.ts`, `src/ui/fleet-list.ts`
109
+ - Test: `test/ui/conversation-viewer.test.ts`, `test/conversation-viewer.test.ts`, `test/agent-widget.test.ts`, `test/fleet-list.test.ts`, `test/perf/render-invariants.perf.test.ts` if integrated
110
+
111
+ **Interfaces:**
112
+ - Consumes: `ConversationTimeline` cache, fork parent-owned `FullToolPreview`, existing deferred/coalesced refresh behavior, upstream `3d91023` render bound.
113
+ - Produces: stable render cost under rapid text/tool events, no nested overlay/input theft, and regression evidence for the original Tool Output failure.
114
+
115
+ - [ ] **Step 1: Port only the upstream render-cost changes.**
116
+
117
+ Inspect upstream `3d91023` and port bounded hidden-tail/truncation and Markdown fallback behavior into the fork's current viewer. Do not replace the fork's scrollbar rail, header action hitboxes, or `openFocusedToolPreview()` path.
118
+
119
+ - [ ] **Step 2: Coalesce live refreshes.**
120
+
121
+ On session event bursts, invalidate only changed timeline/cache state and schedule one `requestRender()` per event-loop turn. Ensure preview mode owns all input/mouse events and returns to the parent viewer without a nested `ctx.ui.custom` overlay.
122
+
123
+ - [ ] **Step 3: Test the event sequence.**
124
+
125
+ Assert that repeated `message_update`/tool activity does not rebuild unchanged rows indefinitely, that the visible scrollbar thumb remains stable, that Tool Output cannot close the underlying subagent panel, and that `Esc`/`q` restore parent focus. Run all focused UI tests.
126
+
127
+ ---
128
+
129
+ ### Task 4:文件、文件說明與相容性整理
130
+
131
+ **Files:**
132
+ - Modify: `README.md`, `CHANGELOG.md`, `AGENTS.md`
133
+ - Modify: `docs/rpc.md`, `docs/workflows.md`
134
+ - Add/modify: `examples/workflows/*`
135
+ - Preserve: `package.json` identity and peer floor unless verification requires a documented change
136
+
137
+ **Interfaces:**
138
+ - Consumes: implemented lifecycle/workflow/history behavior and test evidence.
139
+ - Produces: user-facing documentation that explains event channels, Workflow ownership, durable partial history, and `.output` opt-out distinction.
140
+
141
+ - [ ] **Step 1: Document partial-history guarantees.**
142
+
143
+ State that `.pi-subagents` is always the durable diagnostic/history source, including stopped/aborted/error/partial runs; `output_transcript` controls only the temp `.output` mirror. Document reopenability and status labels.
144
+
145
+ - [ ] **Step 2: Reconcile upstream docs.**
146
+
147
+ Add the upstream RPC/Workflow usage and caveats, including RPC readiness, no `created` guarantee for RPC spawns, workflow-owned hidden children, and journal replay rules. Keep fork branding and JSON override instructions.
148
+
149
+ - [ ] **Step 3: Add Unreleased entries.**
150
+
151
+ Add separate changelog bullets for Workflow/event management, durable partial history, and UI render stability. Do not rewrite released sections.
152
+
153
+ ---
154
+
155
+ ### Task 5:完整驗證、版本、commit、push、publish
156
+
157
+ **Files:**
158
+ - Modify: `package.json`, `package-lock.json`, `CHANGELOG.md`, `README.md` only if release metadata requires it
159
+ - Test: all repository gates
160
+
161
+ - [ ] **Step 1: Run the full local gates from the canonical checkout.**
162
+
163
+ ```bash
164
+ npm run lint
165
+ npm run typecheck
166
+ npm test
167
+ npm run test:e2e
168
+ npm run build
169
+ npm pack --dry-run
170
+ ```
171
+ Fix every failure; do not weaken durable-history, RPC lifecycle, Workflow, or UI regression assertions.
172
+
173
+ - [ ] **Step 2: Select a release version.**
174
+
175
+ Because Workflow and lifecycle management are notable additions, update the package to the next minor version after `0.17.6` only after all gates pass. Move Unreleased entries into that version and create a fresh Unreleased section.
176
+
177
+ - [ ] **Step 3: Commit the complete integration.**
178
+
179
+ ```bash
180
+ git add docs src test README.md CHANGELOG.md package.json package-lock.json AGENTS.md examples
181
+ git commit -m "feat: integrate upstream workflows and durable partial history"
182
+ ```
183
+
184
+ - [ ] **Step 4: Push and publish only after verification.**
185
+
186
+ ```bash
187
+ git push origin master
188
+ npm publish
189
+ ```
190
+ Then independently verify:
191
+ ```bash
192
+ git ls-remote origin refs/heads/master
193
+ npm view @esso0428/pi-subagents version dist-tags.latest
194
+ ```
195
+ Confirm the remote commit and npm version match the committed release.
@@ -0,0 +1,49 @@
1
+ # 上游事件管理、Workflow 與中途歷史設計規格
2
+
3
+ ## 目標
4
+
5
+ 在保留 fork 既有 JSON agent override、ConversationViewer scrollbar、in-place Tool Output preview 與 `.pi-subagents` 本地資料層的前提下,接收上游的 Workflow 與 lifecycle/RPC 事件管理;任何子代理即使被停止、逾時、達到 turn limit、父程序中斷或 session shutdown,都要留下可重新開啟、可解釋的中途歷史。
6
+
7
+ ## 範圍
8
+
9
+ ### 必須接收
10
+
11
+ - 上游 `SubagentWorkflow`:`agent`、`parallel`、`pipeline`、`workflow`、`phase`、`log`、schema/gate、retry/resume、journal、saved workflow、worker-thread sandbox、Workflow UI。
12
+ - 上游 lifecycle/RPC 管理:`subagents:ready`、`created`、`started`、`completed`、`failed`、`steered`、`compacted`、`session_shutdown`,以及 `ping`、`spawn`、`stop`、`consume` reply channels。
13
+ - 上游 RPC spawned agent 的 activity tracking、scopeModels 驗證、completion consume 去重與 shutdown 順序。
14
+ - 上游 ConversationViewer render-cost bound;但不覆蓋 fork 已有的 scrollbar、`[preview] [Esc]`、focused-tool preview 與 in-place overlay 行為。
15
+
16
+ ### 必須保留或強化
17
+
18
+ - `src/agent-history.ts`、`src/agent-history-list.ts`、`src/agent-recovery.ts` 與相關測試不可因上游刪檔而移除。
19
+ - `.pi-subagents/agent-transcripts/<agent-id>.jsonl` 是 UI 與診斷所需的 durable source of truth;`.output` 是可選的 Claude-compatible side transcript。`output_transcript: false` 只能停用 `.output`,不可停用 `.pi-subagents` 歷史。
20
+ - durable transcript 必須涵蓋 Agent tool、foreground/background、scheduler、cross-extension RPC 與 Workflow child 所有 manager spawn path。
21
+ - transcript 必須逐步保存 user prompt、assistant partial text、tool call、tool result/error、steering message、compaction 前後可恢復內容與終止狀態。
22
+ - checkpoint 必須在 spawn/queued、session 建立、turn/compaction、stop/abort/error/completion/shutdown 等關鍵時點更新;重新啟動時 running/queued checkpoint 若有 transcript,一律還原為可開啟的 `stopped` partial record。
23
+ - `/agents` 與 ConversationViewer 必須把 `stopped`、`aborted`、`error`、`steered` 等終止狀態顯示清楚,歷史可重新開啟且 read-only。
24
+
25
+ ## 設計決策
26
+
27
+ 1. **事件管理採上游協定,資料層採 fork durable history。** `pi.events` 只負責 lifecycle/RPC 通知與跨 extension 協調;`.pi-subagents` 保存完整可解釋過程,兩者不互相取代。
28
+ 2. **歷史附掛下沉至 `AgentManager.spawn()`。** 不再只由 Agent tool 的 `attachTranscript()` 建立歷史;manager 在 caller callback 前確保 project-local transcript 已建立並寫入 initial user entry,因此 scheduler、RPC、Workflow child 也不會漏記。
29
+ 3. **輸出與歷史分離。** `record.outputFile` 仍受 `output_transcript` 控制;`record.historyFile`/`record.transcriptPath` 永遠建立(若檔案系統失敗,checkpoint 仍保存 metadata 並以 warning 呈現)。streamer 同時寫入兩個檔案時必須去重。
30
+ 4. **終止狀態不是刪除。** abort/stop 先停止 session、flush transcript、寫 checkpoint,再釋放 live handle;TTL 只釋放 session,不刪除有 `transcriptPath` 的 record。清理與 session shutdown 不得讓已寫入的歷史消失。
31
+ 5. **Workflow child 的生命週期由 Workflow 管理,但 manager 仍是歷史附掛的單一 seam。** Workflow 事件可維持上游的 hidden child 語義;`.pi-subagents` 以 child id 保存每個 worker 的工具與結果,Workflow journal 另外保存 orchestration progress。
32
+ 6. **UI 閃動採上游 render-cost bound 加 fork 的 deferred/coalesced refresh。** 不引入第二個 overlay,也不讓 spinner/timer 直接重建整個 viewer;只在有效 session change 時 invalidate/requestRender,並以 render key/cache 保持穩定行數。
33
+ 7. **套件身份與相容性不盲目照搬。** 保留 `@esso0428/pi-subagents`、JSON override 與 pi `>=0.80.8` peer floor;只在 typecheck/test 證明 API 必須提高時才調整。
34
+
35
+ ## 驗收條件
36
+
37
+ - upstream Workflow 文件、實作、examples、tests 均可在 fork 中使用,且與 JSON override / existing Agents UI 共存。
38
+ - RPC `consume` 可抑制重複 completion notification;RPC spawn/stop/ready/failed 流程有測試。
39
+ - 各 spawn path 的 `.pi-subagents` transcript 都存在;在 tool call 尚未完成時 stop/abort,重新開啟仍可看到 prompt、tool call、tool result/error 與 partial assistant output。
40
+ - turn limit、provider failure、父 signal abort、session shutdown、SIGKILL 後的 checkpoint restore 都標成 stopped/aborted/error/partial,而不是消失或誤報 completed。
41
+ - ConversationViewer 仍保有 scrollbar rail、`[preview] [Esc]`、`w` 同一路徑與 in-place Tool Preview,並有 render cost regression coverage。
42
+ - 通過 lint、typecheck、完整 unit、E2E、build、pack;版本更新、commit、push、publish 後以 GitHub 與 npm 狀態獨立確認。
43
+
44
+ ## 不在本次範圍
45
+
46
+ - 不刪除 fork 的 durable history/recovery 模組來追上游檔案布局。
47
+ - 不把上游 package name、作者、README branding 或 peer floor 直接覆蓋到 fork。
48
+ - 不以「有 output transcript」替代 `.pi-subagents` durable history。
49
+ - 不把 UI flicker 宣稱為上游已完全解決;上游 0.19.0 的 3d91023 是 render cost bound,仍需以 fork regression test 驗證實際事件序列。