@xingular/harness 1.1.1 → 1.3.1-unstable.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.
Files changed (264) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +36 -28
  3. package/dist/cli.js +10837 -6159
  4. package/dist/sdk/accounts/accounts.d.ts +27 -3
  5. package/dist/sdk/accounts/accounts.js +78 -24
  6. package/dist/sdk/accounts/secrets.d.ts +12 -0
  7. package/dist/sdk/accounts/secrets.js +114 -7
  8. package/dist/sdk/accounts/store.d.ts +26 -1
  9. package/dist/sdk/accounts/store.js +1 -1
  10. package/dist/sdk/agents/builtin.js +18 -4
  11. package/dist/sdk/agents/planResearch.d.ts +27 -0
  12. package/dist/sdk/agents/planResearch.js +82 -0
  13. package/dist/sdk/agents/profiles.d.ts +5 -1
  14. package/dist/sdk/agents/profiles.js +21 -5
  15. package/dist/sdk/annotations/pageScript.js +349 -48
  16. package/dist/sdk/annotations/part.js +34 -23
  17. package/dist/sdk/annotations/store.d.ts +7 -0
  18. package/dist/sdk/annotations/store.js +13 -5
  19. package/dist/sdk/browser/backend.d.ts +16 -0
  20. package/dist/sdk/browser/backend.js +17 -0
  21. package/dist/sdk/browser/contracts.d.ts +19 -0
  22. package/dist/sdk/browser/contracts.js +116 -0
  23. package/dist/sdk/browser/tools.d.ts +1 -4
  24. package/dist/sdk/browser/tools.js +14 -91
  25. package/dist/sdk/capabilities/runSnapshot.js +10 -4
  26. package/dist/sdk/cli.js +5 -4
  27. package/dist/sdk/commands/list.d.ts +3 -0
  28. package/dist/sdk/commands/list.js +75 -0
  29. package/dist/sdk/commands/registry.d.ts +258 -0
  30. package/dist/sdk/commands/registry.js +48 -0
  31. package/dist/sdk/commands/routes.d.ts +16 -0
  32. package/dist/sdk/commands/routes.js +33 -0
  33. package/dist/sdk/core/commandBudget.d.ts +23 -0
  34. package/dist/sdk/core/commandBudget.js +57 -0
  35. package/dist/sdk/core/index.js +17 -1
  36. package/dist/sdk/core/interactiveProfile.d.ts +46 -0
  37. package/dist/sdk/core/interactiveProfile.js +143 -0
  38. package/dist/sdk/core/shell.d.ts +20 -0
  39. package/dist/sdk/core/shell.js +73 -0
  40. package/dist/sdk/core/workspace.d.ts +13 -0
  41. package/dist/sdk/core/workspace.js +88 -0
  42. package/dist/sdk/core/workspaceBashTool.d.ts +20 -0
  43. package/dist/sdk/core/workspaceBashTool.js +50 -0
  44. package/dist/sdk/core/workspaceSandbox.d.ts +41 -0
  45. package/dist/sdk/core/workspaceSandbox.js +360 -0
  46. package/dist/sdk/core/workspaceWriteOperations.d.ts +33 -0
  47. package/dist/sdk/core/workspaceWriteOperations.js +224 -0
  48. package/dist/sdk/doctor/checks.js +71 -12
  49. package/dist/sdk/doctor/types.d.ts +2 -2
  50. package/dist/sdk/harness.d.ts +7 -0
  51. package/dist/sdk/harness.js +42 -2
  52. package/dist/sdk/hub/hub.js +5 -3
  53. package/dist/sdk/index.d.ts +8 -3
  54. package/dist/sdk/index.js +4 -1
  55. package/dist/sdk/pi/runtime.d.ts +2 -1
  56. package/dist/sdk/pi/runtime.js +2 -2
  57. package/dist/sdk/plugins/builtin.js +32 -15
  58. package/dist/sdk/plugins/builtinRegistry.d.ts +10 -3
  59. package/dist/sdk/plugins/builtinRegistry.js +30 -8
  60. package/dist/sdk/plugins/catalogue.js +2 -1
  61. package/dist/sdk/plugins/commandPrefix.d.ts +8 -0
  62. package/dist/sdk/plugins/commandPrefix.js +21 -0
  63. package/dist/sdk/plugins/firstParty.d.ts +1 -1
  64. package/dist/sdk/plugins/firstParty.js +8 -2
  65. package/dist/sdk/plugins/install.d.ts +6 -2
  66. package/dist/sdk/plugins/install.js +29 -5
  67. package/dist/sdk/plugins/inventory.js +6 -5
  68. package/dist/sdk/plugins/manifest.d.ts +2 -0
  69. package/dist/sdk/plugins/manifest.js +2 -1
  70. package/dist/sdk/plugins/surfaces.d.ts +5 -0
  71. package/dist/sdk/plugins/surfaces.js +11 -0
  72. package/dist/sdk/plugins/types.d.ts +15 -0
  73. package/dist/sdk/prompt/compile.d.ts +14 -0
  74. package/dist/sdk/prompt/compile.js +65 -31
  75. package/dist/sdk/prompt/standard.d.ts +17 -0
  76. package/dist/sdk/prompt/standard.js +21 -0
  77. package/dist/sdk/server/methods.js +22 -2
  78. package/dist/sdk/server/remote.js +36 -11
  79. package/dist/sdk/sessions/compactionCheckpoint.d.ts +11 -0
  80. package/dist/sdk/sessions/compactionCheckpoint.js +79 -0
  81. package/dist/sdk/sessions/continuation.d.ts +7 -2
  82. package/dist/sdk/sessions/continuation.js +11 -6
  83. package/dist/sdk/sessions/contracts.d.ts +190 -4
  84. package/dist/sdk/sessions/contracts.js +71 -8
  85. package/dist/sdk/sessions/control.d.ts +72 -0
  86. package/dist/sdk/sessions/control.js +158 -0
  87. package/dist/sdk/sessions/initialBash.d.ts +7 -0
  88. package/dist/sdk/sessions/initialBash.js +7 -0
  89. package/dist/sdk/sessions/planMode.d.ts +14 -3
  90. package/dist/sdk/sessions/planMode.js +74 -17
  91. package/dist/sdk/sessions/registry.d.ts +1 -1
  92. package/dist/sdk/sessions/registry.js +2 -2
  93. package/dist/sdk/sessions/runStore.d.ts +14 -0
  94. package/dist/sdk/sessions/runStore.js +38 -1
  95. package/dist/sdk/sessions/runner.d.ts +40 -2
  96. package/dist/sdk/sessions/runner.js +161 -13
  97. package/dist/sdk/sessions/sessions.d.ts +23 -3
  98. package/dist/sdk/sessions/sessions.js +225 -22
  99. package/dist/sdk/sessions/subagentService.d.ts +24 -0
  100. package/dist/sdk/sessions/subagentService.js +225 -26
  101. package/dist/sdk/sessions/subagents.d.ts +10 -1
  102. package/dist/sdk/sessions/subagents.js +4 -0
  103. package/dist/sdk/sessions/workSlice.d.ts +106 -0
  104. package/dist/sdk/sessions/workSlice.js +329 -0
  105. package/dist/sdk/sessions/workspaceBoundary.d.ts +15 -0
  106. package/dist/sdk/sessions/workspaceBoundary.js +46 -0
  107. package/dist/sdk/terminal/browserControl.js +2 -1
  108. package/dist/sdk/terminal/controller.d.ts +31 -3
  109. package/dist/sdk/terminal/controller.js +81 -29
  110. package/dist/sdk/terminal/opentui/ansi.d.ts +25 -0
  111. package/dist/sdk/terminal/opentui/ansi.js +192 -0
  112. package/dist/sdk/terminal/opentui/model.d.ts +163 -0
  113. package/dist/sdk/terminal/opentui/model.js +482 -0
  114. package/dist/sdk/terminal/opentui/subagentsWidget.d.ts +3 -3
  115. package/dist/sdk/terminal/opentui/subagentsWidget.js +7 -5
  116. package/dist/sdk/terminal/opentui/theme.d.ts +43 -0
  117. package/dist/sdk/terminal/opentui/theme.js +88 -0
  118. package/dist/sdk/terminal/piExtension.d.ts +6 -1
  119. package/dist/sdk/terminal/piExtension.js +177 -63
  120. package/dist/sdk/terminal/standalone.d.ts +7 -0
  121. package/dist/sdk/terminal/standalone.js +72 -13
  122. package/dist/sdk/terminal/subagentMonitor.d.ts +28 -6
  123. package/dist/sdk/terminal/subagentMonitor.js +61 -9
  124. package/dist/sdk/terminal/terminals.d.ts +26 -2
  125. package/dist/sdk/terminal/terminals.js +325 -43
  126. package/dist/sdk/terminal/trajectory.d.ts +6 -1
  127. package/dist/sdk/terminal/trajectory.js +8 -0
  128. package/dist/sdk/terminal/tui/annotateCommand.d.ts +1 -1
  129. package/dist/sdk/terminal/tui/annotateCommand.js +3 -3
  130. package/dist/sdk/terminal/tui/chrome.d.ts +4 -0
  131. package/dist/sdk/terminal/tui/chrome.js +13 -0
  132. package/dist/sdk/terminal/tui/commandPages.d.ts +3 -1
  133. package/dist/sdk/terminal/tui/commandPages.js +17 -4
  134. package/dist/sdk/terminal/tui/commands.d.ts +6 -0
  135. package/dist/sdk/terminal/tui/commands.js +213 -124
  136. package/dist/sdk/terminal/tui/list.d.ts +14 -1
  137. package/dist/sdk/terminal/tui/list.js +96 -14
  138. package/dist/sdk/terminal/tui/pageOverlay.js +21 -5
  139. package/dist/sdk/terminal/tui/pages/annotatePage.d.ts +1 -1
  140. package/dist/sdk/terminal/tui/pages/browserPage.js +5 -4
  141. package/dist/sdk/terminal/tui/pages/hubPage.d.ts +14 -1
  142. package/dist/sdk/terminal/tui/pages/hubPage.js +192 -28
  143. package/dist/sdk/terminal/tui/pages/notesPage.d.ts +5 -5
  144. package/dist/sdk/terminal/tui/pages/notesPage.js +18 -18
  145. package/dist/sdk/terminal/tui/pages/pluginsPage.d.ts +8 -6
  146. package/dist/sdk/terminal/tui/pages/pluginsPage.js +206 -28
  147. package/dist/sdk/terminal/tui/pages/subagentsPage.d.ts +1 -0
  148. package/dist/sdk/terminal/tui/pages/subagentsPage.js +104 -19
  149. package/dist/sdk/terminal/tui/pages/usagePage.d.ts +43 -0
  150. package/dist/sdk/terminal/tui/pages/usagePage.js +370 -0
  151. package/dist/sdk/terminal/tui/piAdapter.d.ts +1 -2
  152. package/dist/sdk/terminal/tui/piAdapter.js +3 -5
  153. package/dist/sdk/terminal/tui/pluginCommands.d.ts +2 -0
  154. package/dist/sdk/terminal/tui/pluginCommands.js +13 -9
  155. package/dist/sdk/terminal/tui/runtime.js +23 -3
  156. package/dist/sdk/terminal/tui/sessionPicker.d.ts +40 -0
  157. package/dist/sdk/terminal/tui/sessionPicker.js +141 -0
  158. package/dist/sdk/tools/checkpoint.d.ts +27 -0
  159. package/dist/sdk/tools/checkpoint.js +154 -0
  160. package/dist/sdk/tools/getCapabilities.d.ts +31 -0
  161. package/dist/sdk/tools/getCapabilities.js +34 -0
  162. package/dist/sdk/tools/sessionName.d.ts +2 -0
  163. package/dist/sdk/tools/sessionName.js +5 -3
  164. package/dist/sdk/tools/spawnSubagent.js +11 -8
  165. package/dist/sdk/tools/todo.d.ts +15 -0
  166. package/dist/sdk/tools/todo.js +64 -0
  167. package/dist/sdk/usage/analytics.d.ts +20 -0
  168. package/dist/sdk/usage/analytics.js +151 -0
  169. package/dist/sdk/usage/ledger.d.ts +38 -0
  170. package/dist/sdk/usage/ledger.js +142 -0
  171. package/dist/sdk/usage/limits/adapters.d.ts +11 -0
  172. package/dist/sdk/usage/limits/adapters.js +349 -0
  173. package/dist/sdk/usage/limits/capture.d.ts +8 -0
  174. package/dist/sdk/usage/limits/capture.js +47 -0
  175. package/dist/sdk/usage/limits/http.d.ts +12 -0
  176. package/dist/sdk/usage/limits/http.js +51 -0
  177. package/dist/sdk/usage/limits/normalize.d.ts +15 -0
  178. package/dist/sdk/usage/limits/normalize.js +211 -0
  179. package/dist/sdk/usage/limits/service.d.ts +30 -0
  180. package/dist/sdk/usage/limits/service.js +176 -0
  181. package/dist/sdk/usage/limits/types.d.ts +65 -0
  182. package/dist/sdk/usage/limits/types.js +1 -0
  183. package/dist/sdk/usage/serverMethods.d.ts +3 -0
  184. package/dist/sdk/usage/serverMethods.js +22 -0
  185. package/dist/sdk/usage/service.d.ts +32 -0
  186. package/dist/sdk/usage/service.js +66 -0
  187. package/dist/sdk/usage/settings.d.ts +7 -0
  188. package/dist/sdk/usage/settings.js +28 -0
  189. package/dist/sdk/usage/types.d.ts +60 -0
  190. package/dist/sdk/usage/types.js +4 -0
  191. package/dist/terminal-opentui.js +9204 -4812
  192. package/dist/terminal-pi.js +1848 -272
  193. package/docs/architecture/00-overview.md +1 -1
  194. package/docs/architecture/01-extension-points.md +1 -1
  195. package/docs/architecture/02-sessions-and-runs.md +169 -36
  196. package/docs/architecture/04-prompt.md +55 -15
  197. package/docs/architecture/06-plugins-and-capabilities.md +36 -15
  198. package/docs/architecture/07-tools-and-gate.md +131 -25
  199. package/docs/architecture/08-memory-and-history.md +4 -2
  200. package/docs/architecture/09-accounts-and-connectors.md +39 -3
  201. package/docs/architecture/10-server-protocol.md +71 -9
  202. package/docs/architecture/11-terminal.md +148 -60
  203. package/docs/architecture/12-storage.md +30 -2
  204. package/docs/architecture/13-world-tools.md +22 -1
  205. package/docs/architecture/14-surfaces-and-parity.md +58 -8
  206. package/docs/architecture/README.md +20 -17
  207. package/docs/architecture/proposals/PROP-0006-run-checklist.md +2 -0
  208. package/docs/architecture/proposals/PROP-0017-page-annotations.md +6 -2
  209. package/docs/architecture/proposals/PROP-0018-annotation-queue-and-app-targets.md +1 -1
  210. package/docs/architecture/proposals/PROP-0031-plugin-command-owner-namespaces.md +54 -0
  211. package/docs/architecture/proposals/PROP-0032-planning-quality.md +196 -0
  212. package/docs/architecture/proposals/PROP-0033-compaction-plan-checkpoints.md +75 -0
  213. package/docs/architecture/proposals/PROP-0034-conversation-fast-mode.md +120 -0
  214. package/docs/architecture/proposals/PROP-0035-retain-subagent-status.md +47 -0
  215. package/docs/architecture/proposals/PROP-0036-first-class-harness-commands.md +59 -0
  216. package/docs/architecture/proposals/PROP-0037-workspace-write-boundary.md +63 -0
  217. package/docs/architecture/proposals/PROP-0038-annotate-open-shadow-roots.md +73 -0
  218. package/docs/architecture/proposals/PROP-0039-workspace-boundary-hardening.md +139 -0
  219. package/docs/architecture/proposals/PROP-0040-one-launch-path.md +87 -0
  220. package/docs/architecture/proposals/PROP-0041-bounded-work-slices.md +258 -0
  221. package/docs/architecture/proposals/PROP-0042-usage-and-provider-limits.md +127 -0
  222. package/docs/architecture/proposals/PROP-0043-read-only-plan-bash.md +74 -0
  223. package/docs/architecture/proposals/PROP-0044-work-slice-defaults.md +93 -0
  224. package/docs/architecture/proposals/PROP-0045-rename-checklist-to-todo.md +132 -0
  225. package/docs/architecture/proposals/PROP-0046-progress-aware-stall-guards.md +82 -0
  226. package/docs/architecture/proposals/PROP-0047-plugins-hub-separation.md +122 -0
  227. package/docs/architecture/proposals/README.md +24 -6
  228. package/docs/decisions/ADR-0001-owned-terminal.md +1 -1
  229. package/docs/decisions/ADR-0021-required-command-namespaces.md +1 -1
  230. package/docs/decisions/ADR-0031-plugin-command-owner-namespaces.md +37 -0
  231. package/docs/decisions/ADR-0032-compaction-run-checkpoints.md +33 -0
  232. package/docs/decisions/ADR-0033-plan-mode-research-delegation.md +47 -0
  233. package/docs/decisions/ADR-0034-first-class-harness-terminal-commands.md +25 -0
  234. package/docs/decisions/ADR-0035-one-launch-path.md +40 -0
  235. package/docs/decisions/ADR-0036-workspace-write-operation-boundary.md +54 -0
  236. package/docs/decisions/ADR-0037-usage-ledger-and-provider-limits.md +44 -0
  237. package/docs/decisions/ADR-0038-plan-bash-os-read-only.md +29 -0
  238. package/docs/decisions/ADR-0039-progress-aware-stall-guards.md +39 -0
  239. package/docs/decisions/ADR-0040-architecture-change-workflow.md +31 -0
  240. package/docs/decisions/ADR-0041-plugins-hub-separation.md +41 -0
  241. package/docs/decisions/ADR-0042-windows-shell-without-sandbox.md +40 -0
  242. package/docs/decisions/ADR-0043-parents-continue-stopped-subagents.md +49 -0
  243. package/docs/doctor.md +14 -1
  244. package/docs/experiments/EXP-0003-performance-audit/data/session-runtime-replication.json +420 -0
  245. package/docs/experiments/EXP-0003-performance-audit/data/session-runtime.json +420 -0
  246. package/docs/experiments/EXP-0003-performance-audit/data/terminal-compact.json +376 -0
  247. package/docs/experiments/EXP-0003-performance-audit/data/terminal-history.json +422 -0
  248. package/docs/experiments/EXP-0003-performance-audit/data/terminal-question.json +95 -0
  249. package/docs/experiments/EXP-0003-performance-audit/data/terminal-wide.json +1036 -0
  250. package/docs/experiments/EXP-0003-performance-audit/plan.md +109 -0
  251. package/docs/experiments/EXP-0003-performance-audit/results.md +151 -0
  252. package/docs/handoff-2026-10-25-app-parity-and-solo-tabs.md +202 -0
  253. package/docs/parity.md +83 -27
  254. package/docs/releases/1.1.1.md +28 -0
  255. package/docs/releases/1.2.0.md +49 -0
  256. package/docs/releases/1.3.0.md +21 -0
  257. package/docs/releases/4.0.0.md +10 -9
  258. package/docs/releases/README.md +35 -30
  259. package/docs/study/00-index.md +3 -0
  260. package/docs/study/STUDY-0003-long-horizon-runs.md +210 -0
  261. package/docs/terminal-tui.md +162 -82
  262. package/package.json +4 -3
  263. package/dist/sdk/tools/checklist.d.ts +0 -9
  264. package/dist/sdk/tools/checklist.js +0 -54
@@ -1,3 +1,6 @@
1
+ import { usagePayloadSchema } from "../sessions/contracts.js";
2
+ /** The main agent's row: the parent run itself, shown by name rather than by a profile. */
3
+ export const MAIN_PROFILE = { name: 'main', color: 'main' };
1
4
  export const ACTIVE_SUBAGENT_STATUSES = new Set(['queued', 'running', 'waiting_for_approval', 'waiting_for_input']);
2
5
  export function terminalSubagentDuration(activity, now = Date.now()) {
3
6
  const start = Date.parse(activity.startedAt);
@@ -41,7 +44,7 @@ function stringOf(value) {
41
44
  function latestTool(tools) {
42
45
  return [...tools.values()].sort((left, right) => right.sequence - left.sequence)[0]?.text;
43
46
  }
44
- /** Volatile, read-only activity projection for the active terminal parent run. */
47
+ /** Volatile, read-only activity projection for the latest terminal parent run. */
45
48
  export class SubagentMonitor {
46
49
  parentRunId = null;
47
50
  activities = new Map();
@@ -49,8 +52,11 @@ export class SubagentMonitor {
49
52
  this.parentRunId = parentRunId;
50
53
  this.activities.clear();
51
54
  }
55
+ /** Folds one event of the tracked parent (`main`) or one of its descendants; `null` seeds the row. */
52
56
  observe(parentRunId, run, event) {
53
- if (this.parentRunId !== parentRunId || run.relation !== 'subagent')
57
+ if (this.parentRunId !== parentRunId)
58
+ return;
59
+ if ((run.relation === 'main') !== (run.id === parentRunId))
54
60
  return;
55
61
  const row = this.activities.get(run.id) ?? {
56
62
  id: run.id,
@@ -62,21 +68,34 @@ export class SubagentMonitor {
62
68
  startedAt: run.startedAt,
63
69
  endedAt: run.endedAt,
64
70
  activity: statusActivity(run.status),
65
- checklist: null,
71
+ todo: null,
66
72
  profile: run.profile ?? null,
73
+ accountLabel: run.accountLabel ?? null,
74
+ model: run.model ?? null,
75
+ effort: run.effort ?? null,
76
+ usage: null,
67
77
  tools: new Map(),
68
78
  lastTool: null
69
79
  };
70
80
  row.parentRunId = run.parentRunId;
71
81
  if (run.profile !== undefined)
72
82
  row.profile = run.profile;
83
+ if (run.accountLabel !== undefined)
84
+ row.accountLabel = run.accountLabel;
85
+ if (run.model !== undefined && !row.usage?.model)
86
+ row.model = run.model;
87
+ if (run.effort !== undefined)
88
+ row.effort = run.effort;
73
89
  row.title = run.title;
74
90
  row.goal = run.goal;
75
91
  row.status = run.status;
76
92
  row.startedAt = run.startedAt;
77
93
  row.endedAt = run.endedAt;
78
- const payload = payloadOf(event);
79
- if (event.type === 'tool.started') {
94
+ const payload = event ? payloadOf(event) : {};
95
+ if (!event) {
96
+ // A seeded row keeps what it already folded.
97
+ }
98
+ else if (event.type === 'tool.started') {
80
99
  const toolCallId = stringOf(payload.toolCallId);
81
100
  const name = stringOf(payload.name) ?? 'Tool';
82
101
  if (toolCallId)
@@ -94,22 +113,55 @@ export class SubagentMonitor {
94
113
  row.lastTool = null;
95
114
  row.activity = 'Responding';
96
115
  }
97
- else if (event.type === 'checklist.updated') {
116
+ else if (event.type === 'usage.updated') {
117
+ const parsed = usagePayloadSchema.safeParse(payload);
118
+ if (parsed.success) {
119
+ const usage = parsed.data;
120
+ row.usage = {
121
+ ...(usage.provider === undefined ? {} : { provider: usage.provider }),
122
+ ...(usage.model === undefined ? {} : { model: usage.model }),
123
+ ...(usage.inputTokens === undefined ? {} : { inputTokens: usage.inputTokens }),
124
+ ...(usage.outputTokens === undefined ? {} : { outputTokens: usage.outputTokens }),
125
+ ...(usage.cacheReadTokens === undefined ? {} : { cacheReadTokens: usage.cacheReadTokens }),
126
+ ...(usage.cacheWriteTokens === undefined ? {} : { cacheWriteTokens: usage.cacheWriteTokens }),
127
+ ...(usage.reasoningTokens === undefined ? {} : { reasoningTokens: usage.reasoningTokens }),
128
+ ...(usage.costUsd === undefined ? {} : { costUsd: usage.costUsd }),
129
+ ...(usage.costSource === undefined ? {} : { costSource: usage.costSource }),
130
+ ...(usage.requests === undefined ? {} : { requests: usage.requests }),
131
+ ...(usage.contextTokens === undefined ? {} : { contextTokens: usage.contextTokens }),
132
+ ...(usage.contextWindow === undefined ? {} : { contextWindow: usage.contextWindow })
133
+ };
134
+ }
135
+ }
136
+ else if (event.type === 'todo.updated' || event.type === 'checklist.updated') {
98
137
  const items = Array.isArray(payload.items) ? payload.items : [];
99
- row.checklist = items.length ? { done: items.filter(item => item?.status === 'completed').length, total: items.length } : null;
138
+ row.todo = items.length ? { done: items.filter(item => item?.status === 'completed').length, total: items.length } : null;
100
139
  }
101
140
  if (run.status !== 'running')
102
141
  row.tools.clear();
103
142
  row.activity = run.status === 'running'
104
- ? latestTool(row.tools) ?? row.lastTool?.text ?? (event.type === 'message.delta' ? 'Responding' : 'Working')
143
+ ? latestTool(row.tools) ?? row.lastTool?.text ?? (event?.type === 'message.delta' || (!event && row.activity === 'Responding') ? 'Responding' : 'Working')
105
144
  : statusActivity(run.status);
106
145
  this.activities.set(run.id, row);
107
146
  }
147
+ /**
148
+ * Rebuilds the rows of a parent run that is no longer live, such as the latest one of a reopened
149
+ * conversation, by folding each run's saved events. Rows keep their final status.
150
+ */
151
+ restore(parentRunId, runs) {
152
+ this.begin(parentRunId);
153
+ for (const { run, events } of runs) {
154
+ this.observe(parentRunId, run, null);
155
+ for (const event of events)
156
+ this.observe(parentRunId, run, event);
157
+ }
158
+ }
159
+ /** The main row first, then children in start order. */
108
160
  snapshot(parentRunId) {
109
161
  if (this.parentRunId !== parentRunId)
110
162
  return [];
111
163
  return [...this.activities.values()]
112
- .sort((left, right) => left.startedAt.localeCompare(right.startedAt) || left.id.localeCompare(right.id))
164
+ .sort((left, right) => Number(right.relation === 'main') - Number(left.relation === 'main') || left.startedAt.localeCompare(right.startedAt) || left.id.localeCompare(right.id))
113
165
  .map(({ tools: _tools, lastTool: _lastTool, ...activity }) => activity);
114
166
  }
115
167
  clear(parentRunId) {
@@ -22,6 +22,8 @@ import type { World } from "../world/world.js";
22
22
  import type { Worktrees } from "../worktrees/service.js";
23
23
  import type { AnnotationCapture } from "../annotations/capture.js";
24
24
  import type { NoteDeliveries } from "../annotations/delivery.js";
25
+ import type { Usage } from "../usage/service.js";
26
+ import type { UsageLimits } from "../usage/limits/service.js";
25
27
  /** The files a terminal session needs on disk, outside this process. */
26
28
  export interface TerminalAssets {
27
29
  /** The Node binary that runs the commands. */
@@ -103,6 +105,10 @@ export interface TerminalsOptions {
103
105
  noteCapture?: AnnotationCapture;
104
106
  /** Page notes on their way to a session (PROP-0018). */
105
107
  pageNotes?: NoteDeliveries;
108
+ /** Usage analytics over the derived ledger (`/usage:analysis`). */
109
+ usage?: Usage;
110
+ /** Provider plan windows, balances and rate limits (`/usage:limit`). */
111
+ usageLimits?: UsageLimits;
106
112
  }
107
113
  /** What `/plugins` in a terminal can do. Each takes the session's folder, account and project. */
108
114
  export interface PluginControl {
@@ -144,13 +150,27 @@ export declare class Terminals {
144
150
  /** Each child's profile name and colour, looked up once per child run. */
145
151
  private readonly childProfiles;
146
152
  private subagentProfile;
153
+ /** Account, model and effort for a monitor row, from the run record. */
154
+ private monitorRuntime;
155
+ /**
156
+ * Shows the reopened conversation's latest parent run again: the last owner on its native branch
157
+ * that ran in this folder, with every descendant flat, as each ended.
158
+ */
159
+ private hydrateMonitor;
147
160
  constructor(options: TerminalsOptions);
148
161
  /** The commands a terminal session finds on PATH. Rewritten only when they change. */
149
162
  private ensureCommands;
150
- /** The broker's tools, then the world tools whose plugins are on for this session. */
163
+ /**
164
+ * The harness's own History, Wiki and skill tools, then the broker's, then the world tools whose
165
+ * plugins are on for this session: the same tools a structured session has (INV-PAR-1).
166
+ */
151
167
  private tools;
168
+ private readonly ownNames;
169
+ private ownTools;
152
170
  /** The world tools a new session will have, named in its instructions. */
153
171
  private worldToolNames;
172
+ /** The harness's own History, Wiki and skill tools a new session will have. */
173
+ private ownToolNames;
154
174
  /** Whether a world tool's plugin is switched on for a session's folder, account and project. */
155
175
  private worldOn;
156
176
  private appsCall;
@@ -169,7 +189,9 @@ export declare class Terminals {
169
189
  private agentsCall;
170
190
  /** `/worktree`: the managed worktrees of the repository this session works in. */
171
191
  private worktreesCall;
172
- /** `/plugin:notes` and `/plugin:annotate`: the page notes a person keeps, and the visible browser they capture them in. */
192
+ /** `/usage:analysis` and `/usage:limit`: usage for this session's own account, project or session. */
193
+ private usageCall;
194
+ /** `/annotate:notes` and `/annotate:`: Web annotations and their visible capture browser. */
173
195
  private annotationsCall;
174
196
  /** The account a session asked to switch to. Taken once, after its Pi process has ended and before `dispose`. */
175
197
  takeRelaunch(sessionId: string): TerminalRelaunch | null;
@@ -179,6 +201,8 @@ export declare class Terminals {
179
201
  /** The run a native turn reports into: the one reserved by `send`, or a new one for what the person typed. */
180
202
  private begin;
181
203
  private decide;
204
+ private workspaceEscape;
205
+ private workspaceBoundaryBypass;
182
206
  private subagentsCall;
183
207
  private componentsCall;
184
208
  private trajectoryCall;