u-foo 3.1.6 → 4.0.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 (193) hide show
  1. package/README.md +172 -13
  2. package/README.zh-CN.md +108 -13
  3. package/SKILLS/ufoo/SKILL.md +15 -3
  4. package/SKILLS/ufoo-bus/SKILL.md +21 -1
  5. package/bin/uclaude.js +4 -0
  6. package/bin/ucodex.js +4 -0
  7. package/bin/ufoo.js +3 -1
  8. package/dist/tui/darwin-arm64/ufoo-tui +0 -0
  9. package/dist/tui/darwin-x64/ufoo-tui +0 -0
  10. package/dist/tui/linux-arm64/ufoo-tui +0 -0
  11. package/dist/tui/linux-x64/ufoo-tui +0 -0
  12. package/package.json +10 -3
  13. package/scripts/postinstall-skills.js +53 -0
  14. package/scripts/postinstall.js +11 -16
  15. package/scripts/smoke-native-messages.js +214 -0
  16. package/src/agents/activity/activityStateWriter.js +37 -38
  17. package/src/agents/capabilities/agentManagement/index.js +4 -0
  18. package/src/agents/capabilities/agentManagement/service.js +113 -0
  19. package/src/agents/capabilities/agentRouting/index.js +4 -0
  20. package/src/agents/capabilities/coding/index.js +32 -0
  21. package/src/agents/capabilities/coordination/index.js +37 -0
  22. package/src/agents/capabilities/globalRouting/index.js +5 -0
  23. package/src/agents/capabilities/groups/index.js +3 -0
  24. package/src/agents/capabilities/index.js +25 -0
  25. package/src/agents/capabilities/planning/index.js +123 -0
  26. package/src/agents/capabilities/planning/main.js +28 -0
  27. package/src/agents/capabilities/projectDiscovery/index.js +3 -0
  28. package/src/agents/capabilities/scheduling/index.js +3 -0
  29. package/src/agents/capabilities/sharedMemory/index.js +4 -0
  30. package/src/agents/capabilities/skills/index.js +12 -0
  31. package/src/agents/capabilities/taskExecution/index.js +3 -0
  32. package/src/agents/capabilities/taskReports/index.js +6 -0
  33. package/src/agents/controller/controllerToolExecutor.js +6 -4
  34. package/src/agents/controller/loopRuntime.js +85 -221
  35. package/src/agents/controller/ufooAgent.js +1 -0
  36. package/src/agents/internal/internalRunner.js +103 -32
  37. package/src/agents/launch/launcher.js +88 -6
  38. package/src/agents/launch/nativeCapabilities.js +40 -0
  39. package/src/agents/launch/nativeMessages.js +362 -0
  40. package/src/agents/launch/notifier.js +13 -18
  41. package/src/agents/launch/readyDetector.js +26 -12
  42. package/src/agents/profiles/coding.js +6 -0
  43. package/src/agents/profiles/globalRouter.js +2 -0
  44. package/src/agents/profiles/main.js +5 -0
  45. package/src/agents/prompts/groupBootstrap.js +10 -0
  46. package/src/agents/prompts/mainAgent.js +39 -0
  47. package/src/agents/prompts/native/tasks.js +2 -2
  48. package/src/agents/prompts/native/ufoo.js +3 -0
  49. package/src/agents/providers/claudeEventTranslator.js +6 -1
  50. package/src/agents/providers/claudeThreadProvider.js +44 -2
  51. package/src/agents/providers/codexEventTranslator.js +47 -7
  52. package/src/agents/providers/codexThreadProvider.js +3 -2
  53. package/src/agents/providers/controllerJsonTransport.js +28 -0
  54. package/src/agents/providers/credentials/claude.js +10 -3
  55. package/src/agents/providers/nativeTransport.js +1135 -0
  56. package/src/agents/providers/runtimeConfig.js +186 -0
  57. package/src/agents/providers/thinkingLevels.js +132 -0
  58. package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
  59. package/src/agents/providers/transports/index.js +10 -0
  60. package/src/agents/providers/transports/openaiChatTransport.js +117 -0
  61. package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
  62. package/src/agents/providers/transports/responsesProtocol.js +499 -0
  63. package/src/agents/providers/transports/systemBlocks.js +16 -0
  64. package/src/agents/providers/transports/transportContract.js +50 -0
  65. package/src/agents/providers/transports/visionBlocks.js +151 -0
  66. package/src/agents/providers/upstreamTransport.js +13 -4
  67. package/src/agents/runtime/composeCapabilities.js +89 -0
  68. package/src/agents/runtime/context/commandStore.js +43 -0
  69. package/src/agents/runtime/context/contextWindow.js +119 -0
  70. package/src/agents/runtime/context/fileLock.js +36 -0
  71. package/src/agents/runtime/context/runtimeStore.js +126 -0
  72. package/src/agents/runtime/context/sessionJournal.js +360 -0
  73. package/src/agents/runtime/context/sessionStore.js +57 -0
  74. package/src/agents/runtime/core/agentLoop.js +270 -0
  75. package/src/agents/runtime/core/stableJson.js +29 -0
  76. package/src/agents/runtime/core/toolLoopGuard.js +55 -0
  77. package/src/agents/runtime/createAgentRuntime.js +247 -0
  78. package/src/agents/runtime/index.js +14 -0
  79. package/src/agents/runtime/protocol/faultHarness.js +90 -0
  80. package/src/agents/runtime/protocol/materialize.js +107 -0
  81. package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
  82. package/src/agents/runtime/tasks/resourceLease.js +66 -0
  83. package/src/agents/runtime/tasks/scheduler.js +73 -0
  84. package/src/agents/runtime/tools/registry.js +57 -0
  85. package/src/app/chat/ChatController.js +14 -3
  86. package/src/app/chat/agentDirectory.js +8 -2
  87. package/src/app/chat/commandExecutor.js +36 -46
  88. package/src/app/chat/commands.js +14 -7
  89. package/src/app/chat/daemonConnection.js +58 -5
  90. package/src/app/chat/daemonMessageRouter.js +61 -3
  91. package/src/app/chat/inputSubmitHandler.js +14 -2
  92. package/src/app/chat/launchRequestContext.js +42 -0
  93. package/src/app/chat/multiWindow/paneManager.js +85 -165
  94. package/src/app/chat/streamState.js +3 -3
  95. package/src/app/chat/transport.js +1 -1
  96. package/src/app/cli/busCoreCommands.js +9 -0
  97. package/src/app/cli/features/doctor.js +33 -0
  98. package/src/app/cli/features/skills.js +16 -4
  99. package/src/app/cli/reportCoreCommands.js +37 -0
  100. package/src/app/cli/run.js +40 -39
  101. package/src/code/agent.js +16 -4
  102. package/src/code/context/artifacts.js +12 -11
  103. package/src/code/context/assembler.js +2 -1
  104. package/src/code/context/promptLayers.js +1 -13
  105. package/src/code/context/stableJson.js +2 -27
  106. package/src/code/contextWindow.js +2 -117
  107. package/src/code/conversation/sessionJournal.js +3 -349
  108. package/src/code/internalThread.js +100 -0
  109. package/src/code/nativeRunner.js +36 -2668
  110. package/src/code/protocol/faultHarness.js +2 -88
  111. package/src/code/protocol/materialize.js +2 -105
  112. package/src/code/protocol/toolCallLedger.js +5 -215
  113. package/src/code/providers/anthropicMessagesTransport.js +2 -118
  114. package/src/code/providers/openaiChatTransport.js +2 -114
  115. package/src/code/providers/openaiResponsesTransport.js +2 -117
  116. package/src/code/providers/responsesProtocol.js +2 -497
  117. package/src/code/providers/transportContract.js +2 -48
  118. package/src/code/providers/visionBlocks.js +2 -149
  119. package/src/code/sessionStore.js +24 -96
  120. package/src/code/thinkingLevels.js +1 -130
  121. package/src/code/toolLoopGuard.js +3 -49
  122. package/src/code/tools/artifactRead.js +1 -1
  123. package/src/code/tools/executor.js +373 -0
  124. package/src/code/tools/specs.js +312 -0
  125. package/src/config.js +81 -67
  126. package/src/coordination/bus/deliveryQueue.js +16 -2
  127. package/src/coordination/bus/index.js +2 -6
  128. package/src/coordination/bus/inject.js +13 -5
  129. package/src/coordination/bus/nativeReceipts.js +100 -0
  130. package/src/coordination/bus/queue.js +1 -3
  131. package/src/coordination/bus/utils.js +7 -3
  132. package/src/coordination/history/agentSurface.js +142 -0
  133. package/src/coordination/history/controllerSummary.js +23 -0
  134. package/src/coordination/memory/index.js +5 -21
  135. package/src/coordination/report/store.js +103 -83
  136. package/src/coordination/state/agentsStore.js +57 -3
  137. package/src/coordination/state/fileLock.js +2 -0
  138. package/src/coordination/state/workspaceAccess.js +36 -0
  139. package/src/runtime/contracts/agentMode.js +17 -0
  140. package/src/runtime/contracts/eventContract.js +3 -0
  141. package/src/runtime/contracts/uiProtocol.js +4 -0
  142. package/src/runtime/daemon/agentHost.js +375 -0
  143. package/src/runtime/daemon/busBridge.js +396 -0
  144. package/src/runtime/daemon/claudeChannel.js +159 -0
  145. package/src/runtime/daemon/controlPlaneService.js +27 -17
  146. package/src/runtime/daemon/cronOps.js +25 -17
  147. package/src/runtime/daemon/deliveryScheduler.js +32 -5
  148. package/src/runtime/daemon/executionPaths.js +30 -0
  149. package/src/runtime/daemon/globalDaemon.js +28 -1
  150. package/src/runtime/daemon/groupOrchestrator.js +1 -0
  151. package/src/runtime/daemon/index.js +114 -344
  152. package/src/runtime/daemon/ipcServer.js +32 -10
  153. package/src/runtime/daemon/mcpConfigure.js +113 -20
  154. package/src/runtime/daemon/mcpHttpServer.js +27 -5
  155. package/src/runtime/daemon/mcpServer.js +7 -4
  156. package/src/runtime/daemon/mcpStdioProxy.js +127 -10
  157. package/src/runtime/daemon/ops.js +22 -17
  158. package/src/runtime/daemon/promptRequest.js +23 -4
  159. package/src/runtime/daemon/providerSessions.js +67 -33
  160. package/src/runtime/daemon/reportControlBus.js +59 -25
  161. package/src/runtime/daemon/status.js +4 -0
  162. package/src/runtime/privacy/redactor.js +2 -2
  163. package/src/runtime/projects/identity.js +2 -1
  164. package/src/runtime/projects/registry.js +98 -38
  165. package/src/tools/controllerSchemas.js +24 -0
  166. package/src/tools/handlers/dispatchMessage.js +5 -2
  167. package/src/tools/handlers/listAgents.js +3 -1
  168. package/src/tools/handlers/readBusSummary.js +3 -1
  169. package/src/tools/handlers/readProjectRegistry.js +29 -2
  170. package/src/tools/handlers/routeAgent.js +35 -0
  171. package/src/tools/index.js +1 -0
  172. package/src/tools/registry.js +2 -0
  173. package/src/tools/schemaFixtures.js +16 -3
  174. package/src/tools/tier1/routeAgent.js +2 -2
  175. package/src/tools/tier2/runtimeCoordination.js +38 -0
  176. package/src/tools/types.js +2 -0
  177. package/src/ui/agentPresentation.js +109 -0
  178. package/src/ui/agentSurface.js +270 -0
  179. package/src/ui/format/banner.js +8 -11
  180. package/src/ui/format/startupBanner.js +50 -0
  181. package/src/ui/multiPaneBusMirror.js +29 -3
  182. package/src/ui/rustChatHost.js +170 -438
  183. package/src/ui/rustMultiSession.js +225 -51
  184. package/src/ui/rustUcodeHost.js +20 -87
  185. package/src/ui/settingsBridge.js +7 -4
  186. package/src/app/chat/agentEnter.js +0 -70
  187. package/src/app/chat/multiWindow/index.js +0 -310
  188. package/src/app/chat/multiWindow/paneLayout.js +0 -84
  189. package/src/app/chat/multiWindow/renderer.js +0 -420
  190. package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
  191. package/src/app/chat/multiWindow/vtFrame.js +0 -93
  192. package/src/ui/multiWindowHandoff.js +0 -232
  193. package/src/ui/ptyHandoff.js +0 -23
@@ -3,18 +3,23 @@
3
3
  /**
4
4
  * In-process split-pane session for the Rust TUI host.
5
5
  *
6
- * Two kinds share the same draw/keys (Ctrl+W / Ctrl+Q) and multi.* wire:
7
- * - "multi" — /multi; panes track all active agents
6
+ * Both kinds use Tab to cycle focus and Esc to return focus to chat, then exit.
7
+ * They share draw and the multi.* wire:
8
+ * - "multi" — /multi; panes track active internal agents
8
9
  * - "side" — internal-only activate; single locked agent on the right
9
10
  * (not a user-facing mode name; looks like multi with one agent)
10
11
  *
11
- * The Rust TUI owns TTY / layout / focus. Node owns paneManager (VT +
12
- * inject.sock) and ships bounded, lossy `multi.pane.frame` events.
12
+ * The Rust TUI owns TTY / layout / focus. Node owns internal pane buffers
13
+ * and ships bounded, lossy `multi.pane.frame` events.
13
14
  */
14
15
 
15
16
  const crypto = require("crypto");
17
+ const fs = require("fs");
18
+ const { getUfooPaths } = require("../coordination/state/paths");
19
+ const { isInternalAgentMeta } = require("../runtime/contracts/agentMode");
16
20
  const { createPaneManager } = require("../app/chat/multiWindow/paneManager");
17
- const { vtScreenToAnsiLines } = require("../app/chat/multiWindow/vtFrame");
21
+ const { createAgentSurface } = require("./agentSurface");
22
+ const { readAgentSurfaceEvents, createAgentSurfaceReader } = require("../coordination/history/agentSurface");
18
23
 
19
24
  const DEFAULT_COLS = 40;
20
25
  const DEFAULT_ROWS = 12;
@@ -52,12 +57,13 @@ function createRustMultiSession(options = {}) {
52
57
  const {
53
58
  getActiveAgents = () => [],
54
59
  getAgentMeta = () => ({}),
55
- getInjectSockPath = () => "",
56
- resolvePaneOptions = () => ({ mode: "socket" }),
60
+ resolvePaneOptions = () => ({ mode: "internal" }),
57
61
  onInternalSubmit = () => {},
58
62
  publish = () => {},
59
63
  publishLossy = null,
60
64
  getLabel = (id) => id,
65
+ projectRoot = "",
66
+ getProjectRoot = () => projectRoot,
61
67
  } = options;
62
68
 
63
69
  let sessionId = null;
@@ -74,36 +80,151 @@ function createRustMultiSession(options = {}) {
74
80
  let paneManager = null;
75
81
  /** @type {Map<string, number>} last successful frame emit per agent */
76
82
  const lastEmitAt = new Map();
83
+ const internalDrafts = new Map();
84
+ const surfaces = new Map();
85
+ const replayedAgents = new Set();
86
+ let observationRoot = "";
87
+ let surfaceReader = null;
88
+ let surfaceWatch = null;
89
+ let surfacePoll = null;
90
+ let surfaceRefresh = null;
91
+
92
+ function closeSurfaceObservation() {
93
+ surfaceWatch?.close();
94
+ surfaceWatch = null;
95
+ clearInterval(surfacePoll);
96
+ surfacePoll = null;
97
+ clearTimeout(surfaceRefresh);
98
+ surfaceRefresh = null;
99
+ }
100
+
101
+ function refreshSurfaceObservations() {
102
+ if (!active) return;
103
+ const root = getProjectRoot();
104
+ if (!root) return;
105
+ if (root !== observationRoot) {
106
+ closeSurfaceObservation();
107
+ observationRoot = root;
108
+ surfaceReader = createAgentSurfaceReader(root);
109
+ }
110
+ for (const event of surfaceReader.read(listInternalAgentIds())) {
111
+ acceptEvent(event.publisher, event.data.surface, event.seq);
112
+ }
113
+ if (!surfaceWatch) {
114
+ try {
115
+ const watch = fs.watch(getUfooPaths(root).busEventsDir, () => {
116
+ if (surfaceRefresh) return;
117
+ surfaceRefresh = setTimeout(() => {
118
+ surfaceRefresh = null;
119
+ refreshSurfaceObservations();
120
+ }, 25);
121
+ surfaceRefresh.unref?.();
122
+ });
123
+ surfaceWatch = watch;
124
+ watch.unref?.();
125
+ watch.on("error", () => {
126
+ watch.close();
127
+ if (surfaceWatch === watch) surfaceWatch = null;
128
+ });
129
+ } catch { /* Retry from the poll after the first provider event. */ }
130
+ }
131
+ if (!surfacePoll) {
132
+ surfacePoll = setInterval(refreshSurfaceObservations, 500);
133
+ surfacePoll.unref?.();
134
+ }
135
+ }
136
+
137
+ function surfaceFor(agentId) {
138
+ if (!isInternalAgentMeta(getAgentMeta(agentId))) return null;
139
+ if (!surfaces.has(agentId)) {
140
+ const surface = createAgentSurface();
141
+ const opts = ensurePaneMeta(agentId);
142
+ const initial = (opts.initialLines || []).join("\n");
143
+ if (initial) surface.apply("transcript.append", { kind: "meta", text: initial });
144
+ surfaces.set(agentId, { surface, seq: 0, structured: false });
145
+ }
146
+ return surfaces.get(agentId);
147
+ }
148
+
149
+ function syncActivity(agentId) {
150
+ const view = surfaceFor(agentId);
151
+ if (!view || view.structured) return;
152
+ const meta = getAgentMeta(agentId) || {};
153
+ const key = JSON.stringify([meta.activity_state, meta.activity_detail, meta.activity_since]);
154
+ if (view.activityKey === key) return;
155
+ view.activityKey = key;
156
+ if (meta.activity_state) acceptEvent(agentId, { type: "activity", state: meta.activity_state,
157
+ detail: meta.activity_detail || "", ts: meta.activity_since, started_at: Date.parse(meta.activity_since) || 0,
158
+ authoritative: true });
159
+ }
160
+
161
+ function acceptEvent(agentId, event, seq = 0) {
162
+ const view = surfaceFor(agentId);
163
+ if (!view || (seq > 0 && seq <= view.seq)) return false;
164
+ if (event.type === "submission_failed") {
165
+ const pane = paneManager?.getPane(agentId);
166
+ if (pane && !pane.internalInput) {
167
+ pane.internalInput = String(event.message || "");
168
+ pane.internalCursor = pane.internalInput.length;
169
+ } else if (!pane && !internalDrafts.get(agentId)?.initialInput) {
170
+ internalDrafts.set(agentId, { initialInput: String(event.message || ""), initialCursor: String(event.message || "").length });
171
+ }
172
+ }
173
+ if (seq > 0) { view.seq = seq; view.structured = true; }
174
+ if (event.type === "activity") event = { ...event, authoritative: !view.structured };
175
+ const changed = view.surface.accept(event);
176
+ if (changed) markDirty(agentId);
177
+ return changed;
178
+ }
179
+
180
+ function replaySurfaces() {
181
+ const ids = listInternalAgentIds().filter((id) => !replayedAgents.has(id));
182
+ const root = getProjectRoot();
183
+ if (!root || !ids.length) return;
184
+ const events = readAgentSurfaceEvents(root, ids);
185
+ for (const id of new Set(events.map((event) => event.publisher))) {
186
+ const view = surfaceFor(id);
187
+ if (view && !view.structured) view.surface.apply("transcript.reset", { entries: [] });
188
+ }
189
+ for (const event of events) {
190
+ acceptEvent(event.publisher, event.data.surface, event.seq);
191
+ }
192
+ for (const id of ids) replayedAgents.add(id);
193
+ }
194
+
195
+ function rememberDraft(agentId) {
196
+ const pane = paneManager && paneManager.getPane(agentId);
197
+ if (pane && pane.mode === "internal") {
198
+ internalDrafts.set(agentId, { initialInput: pane.internalInput, initialCursor: pane.internalCursor, scrollOffset: pane.scrollOffset });
199
+ }
200
+ }
77
201
 
78
202
  function paneAgentIds() {
79
203
  if (kind === KIND_SIDE && lockedAgentIds.length > 0) {
80
- return lockedAgentIds.slice();
204
+ return lockedAgentIds.filter((id) => isInternalAgentMeta(getAgentMeta(id)));
81
205
  }
82
- return normalizeAgentList(getActiveAgents);
206
+ return normalizeAgentList(getActiveAgents).filter((id) => isInternalAgentMeta(getAgentMeta(id)));
83
207
  }
84
208
 
85
209
  function currentPanesDesc() {
86
210
  return paneAgentIds().map((id) => {
87
- const opts = paneMeta.get(id) || (() => {
88
- try { return resolvePaneOptions(id) || {}; } catch { return {}; }
89
- })();
90
211
  return {
91
212
  agent_id: id,
92
213
  label: String(getLabel(id) || id),
93
- mode: opts.mode === "internal" ? "internal" : "socket",
214
+ mode: "internal",
94
215
  };
95
216
  });
96
217
  }
97
218
 
98
219
  function ensurePaneMeta(id) {
99
220
  if (paneMeta.has(id)) return paneMeta.get(id);
100
- let opts = { mode: "socket" };
221
+ let opts = { mode: "internal" };
101
222
  try {
102
223
  opts = resolvePaneOptions(id) || opts;
103
224
  } catch {
104
225
  // ignore
105
226
  }
106
- if (!opts.mode) opts.mode = "socket";
227
+ if (!opts.mode) opts = { ...opts, mode: "internal" };
107
228
  paneMeta.set(id, opts);
108
229
  return opts;
109
230
  }
@@ -134,7 +255,7 @@ function createRustMultiSession(options = {}) {
134
255
  const last = lastEmitAt.get(id) || 0;
135
256
  if (now - last < MIN_EMIT_GAP_MS) {
136
257
  // Keep dirty; schedule another pass — drop intermediate by only
137
- // re-emitting once the gap elapses (VT snapshot is always current).
258
+ // re-emitting once the gap elapses (transcript snapshot is always current).
138
259
  dirty.add(id);
139
260
  deferred = true;
140
261
  continue;
@@ -149,12 +270,7 @@ function createRustMultiSession(options = {}) {
149
270
  if (!active || !paneManager) return;
150
271
  const pane = paneManager.getPane(agentId);
151
272
  if (!pane) return;
152
- const size = paneSizes.get(agentId) || { cols: DEFAULT_COLS, rows: DEFAULT_ROWS };
153
- const lines = vtScreenToAnsiLines(pane.vt, {
154
- maxCols: Math.max(1, size.cols),
155
- maxRows: Math.max(1, size.rows),
156
- });
157
- const opts = paneMeta.get(agentId) || {};
273
+ const view = pane.surface.snapshot();
158
274
  const meta = (() => {
159
275
  try { return getAgentMeta(agentId) || {}; } catch { return {}; }
160
276
  })();
@@ -162,15 +278,20 @@ function createRustMultiSession(options = {}) {
162
278
  session_id: sessionId,
163
279
  agent_id: agentId,
164
280
  label: String(getLabel(agentId) || agentId),
165
- mode: opts.mode === "internal" ? "internal" : "socket",
166
- lines,
167
- status: String(meta.activity_state || meta.state || "ready"),
281
+ mode: "internal",
282
+ entries: view.entries,
283
+ status: view.status || String(meta.activity_state || "ready"),
284
+ busy: view.busy,
285
+ usage: view.usage,
286
+ plan: view.plan,
287
+ revision: view.revision,
288
+ started_at: view.started_at,
289
+ activity_detail: String(meta.activity_detail || ""),
168
290
  viewport_rev: viewportRev,
291
+ scroll_offset: pane.scrollOffset,
169
292
  };
170
- if (opts.mode === "internal") {
171
- payload.input = String(pane.internalInput || "");
172
- payload.cursor = Number.isFinite(pane.internalCursor) ? pane.internalCursor : 0;
173
- }
293
+ payload.input = String(pane.internalInput || "");
294
+ payload.cursor = Number.isFinite(pane.internalCursor) ? pane.internalCursor : 0;
174
295
  const emit = typeof publishLossy === "function" ? publishLossy : publish;
175
296
  try { emit("multi.pane.frame", payload); } catch {}
176
297
  }
@@ -185,17 +306,25 @@ function createRustMultiSession(options = {}) {
185
306
  function ensurePaneManager() {
186
307
  if (paneManager) return paneManager;
187
308
  paneManager = createPaneManager({
188
- getInjectSockPath,
189
309
  onPaneOutput: (agentId) => markDirty(agentId),
190
310
  onInternalSubmit: (agentId, message) => {
191
- try { onInternalSubmit(agentId, message); } catch {}
192
311
  markDirty(agentId);
312
+ return onInternalSubmit(agentId, message);
193
313
  },
194
314
  });
195
315
  return paneManager;
196
316
  }
197
317
 
198
318
  function syncAgents() {
319
+ const live = new Set(listInternalAgentIds());
320
+ for (const id of surfaces.keys()) if (!live.has(id)) {
321
+ surfaces.delete(id); replayedAgents.delete(id); internalDrafts.delete(id);
322
+ }
323
+ replaySurfaces();
324
+ // Observe durable provider output independently of daemon inbox delivery.
325
+ // This also covers daemons already running when the package was upgraded.
326
+ refreshSurfaceObservations();
327
+ for (const id of live) syncActivity(id);
199
328
  if (!paneManager) return;
200
329
  const ids = paneAgentIds();
201
330
  const existing = new Set(paneManager.getAgentIds());
@@ -204,13 +333,17 @@ function createRustMultiSession(options = {}) {
204
333
  const opts = ensurePaneMeta(id);
205
334
  const size = paneSizes.get(id) || { cols: DEFAULT_COLS, rows: DEFAULT_ROWS };
206
335
  if (!existing.has(id)) {
207
- paneManager.addAgent(id, size.cols, size.rows, opts);
336
+ paneManager.addAgent(id, size.cols, size.rows, { ...opts, surface: surfaceFor(id).surface, ...internalDrafts.get(id) });
337
+ paneManager.sendResize(id, size.cols, size.rows, size.inputCols || size.cols);
208
338
  markDirty(id);
209
339
  changed = true;
340
+ } else {
341
+ markDirty(id);
210
342
  }
211
343
  }
212
344
  for (const id of existing) {
213
345
  if (!ids.includes(id)) {
346
+ rememberDraft(id);
214
347
  paneManager.removeAgent(id);
215
348
  paneSizes.delete(id);
216
349
  paneMeta.delete(id);
@@ -220,7 +353,7 @@ function createRustMultiSession(options = {}) {
220
353
  }
221
354
  // Only republish multi.set when membership actually changes. Spamming
222
355
  // multi.set on every daemon status tick forced Rust to bump viewport_rev
223
- // and drop in-flight pane frames (Ctrl+W felt stuck).
356
+ // and drop in-flight pane frames (focus switching felt stuck).
224
357
  if (active && changed) {
225
358
  rev += 1;
226
359
  publishSet();
@@ -258,10 +391,6 @@ function createRustMultiSession(options = {}) {
258
391
  if (active && kind === nextKind && nextKind === KIND_MULTI) {
259
392
  return { ok: true, session_id: sessionId, kind };
260
393
  }
261
- if (active) {
262
- stop();
263
- }
264
-
265
394
  let ids;
266
395
  if (nextKind === KIND_SIDE) {
267
396
  const raw = Array.isArray(options.agentIds) ? options.agentIds : [];
@@ -269,23 +398,27 @@ function createRustMultiSession(options = {}) {
269
398
  if (!id) {
270
399
  return { ok: false, error: "side requires one agent_id" };
271
400
  }
401
+ if (!isInternalAgentMeta(getAgentMeta(id))) return { ok: false, error: "Dashboard supports internal agents only" };
272
402
  ids = [id];
273
- lockedAgentIds = [id];
274
403
  } else {
275
- lockedAgentIds = [];
276
- ids = normalizeAgentList(getActiveAgents);
404
+ ids = normalizeAgentList(getActiveAgents).filter((id) => isInternalAgentMeta(getAgentMeta(id)));
277
405
  if (ids.length === 0) {
278
406
  return { ok: false, error: "No active agents for multi-window mode" };
279
407
  }
280
408
  }
281
409
 
410
+ const previousFocus = active ? { ...focus } : null;
411
+ if (active) stop();
412
+ lockedAgentIds = nextKind === KIND_SIDE ? ids.slice() : [];
413
+
282
414
  kind = nextKind;
283
415
  sessionId = generateSessionId(kind);
284
416
  active = true;
285
417
  rev = 1;
286
418
  viewportRev = 0;
287
- const focusOpt = options.focus && typeof options.focus === "object" ? options.focus : null;
288
- if (focusOpt && focusOpt.target === "agent" && String(focusOpt.agent_id || "").trim()) {
419
+ const focusOpt = options.focus && typeof options.focus === "object" ? options.focus
420
+ : nextKind === KIND_MULTI ? previousFocus : null;
421
+ if (focusOpt && focusOpt.target === "agent" && ids.includes(String(focusOpt.agent_id || "").trim())) {
289
422
  focus = {
290
423
  target: "agent",
291
424
  agent_id: String(focusOpt.agent_id).trim(),
@@ -305,7 +438,12 @@ function createRustMultiSession(options = {}) {
305
438
  return { ok: true, session_id: sessionId, kind };
306
439
  }
307
440
 
308
- function stop() {
441
+ function stop({ clearDrafts = false } = {}) {
442
+ closeSurfaceObservation();
443
+ if (clearDrafts) {
444
+ internalDrafts.clear(); surfaces.clear(); replayedAgents.clear();
445
+ surfaceReader = null; observationRoot = "";
446
+ }
309
447
  if (!active && !paneManager) return;
310
448
  if (flushTimer) {
311
449
  clearTimeout(flushTimer);
@@ -313,6 +451,7 @@ function createRustMultiSession(options = {}) {
313
451
  }
314
452
  dirty.clear();
315
453
  if (paneManager) {
454
+ if (!clearDrafts) for (const id of paneManager.getAgentIds()) rememberDraft(id);
316
455
  try { paneManager.disconnectAll(); } catch {}
317
456
  paneManager = null;
318
457
  }
@@ -337,6 +476,16 @@ function createRustMultiSession(options = {}) {
337
476
  focus = { target: "chat", agent_id: "" };
338
477
  }
339
478
 
479
+ function setLayout(layout = "toggle", agentId = "") {
480
+ if (layout === "main" || (layout === "toggle" && isMultiKind())) {
481
+ stop();
482
+ return { ok: true, layout: "main" };
483
+ }
484
+ if (layout === "all" || layout === "toggle") return start({ kind: KIND_MULTI });
485
+ if (layout === "single") return start({ kind: KIND_SIDE, agentIds: [agentId] });
486
+ return { ok: false, error: "unknown layout" };
487
+ }
488
+
340
489
  function handleViewport(payload = {}) {
341
490
  if (!active || !paneManager) return { ok: false, error: "multi not active" };
342
491
  if (payload.session_id && payload.session_id !== sessionId) {
@@ -354,9 +503,10 @@ function createRustMultiSession(options = {}) {
354
503
  if (!id) continue;
355
504
  const cols = Math.max(1, Math.floor(Number(spec.cols) || DEFAULT_COLS));
356
505
  const rows = Math.max(1, Math.floor(Number(spec.rows) || DEFAULT_ROWS));
357
- paneSizes.set(id, { cols, rows });
506
+ const inputCols = Math.max(1, Math.floor(Number(spec.input_cols) || cols));
507
+ paneSizes.set(id, { cols, rows, inputCols });
358
508
  if (paneManager.getPane(id)) {
359
- try { paneManager.sendResize(id, cols, rows); } catch {}
509
+ try { paneManager.sendResize(id, cols, rows, inputCols); } catch {}
360
510
  markDirty(id);
361
511
  }
362
512
  }
@@ -381,6 +531,21 @@ function createRustMultiSession(options = {}) {
381
531
  return { ok: true };
382
532
  }
383
533
 
534
+ function handleScroll(payload = {}) {
535
+ if (!active || !paneManager) return { ok: false, error: "multi not active" };
536
+ if (payload.session_id && payload.session_id !== sessionId) return { ok: false, error: "stale session_id" };
537
+ const agentId = String(payload.agent_id || "").trim();
538
+ const lines = Math.max(-2000, Math.min(2000, Math.trunc(Number(payload.lines) || 0)));
539
+ const maxOffset = Number.isFinite(Number(payload.max_offset)) ? Math.max(0, Number(payload.max_offset)) : 2000;
540
+ const pane = paneManager.getPane(agentId);
541
+ if (!pane) return { ok: false, error: "agent pane not found" };
542
+ if (Number.isFinite(Number(payload.offset))) {
543
+ pane.scrollOffset = Math.max(0, Math.min(maxOffset, Math.trunc(Number(payload.offset))));
544
+ markDirty(agentId);
545
+ } else paneManager.scrollPane(agentId, lines, maxOffset);
546
+ return { ok: true };
547
+ }
548
+
384
549
  function handleFocus(payload = {}) {
385
550
  if (!active || !paneManager) return { ok: false, error: "multi not active" };
386
551
  if (payload.session_id && payload.session_id !== sessionId) {
@@ -445,12 +610,16 @@ function createRustMultiSession(options = {}) {
445
610
  }
446
611
 
447
612
  function listInternalAgentIds() {
448
- const out = [];
449
- for (const id of paneAgentIds()) {
450
- const opts = paneMeta.get(id) || ensurePaneMeta(id);
451
- if (opts && opts.mode === "internal") out.push(id);
452
- }
453
- return out;
613
+ return normalizeAgentList(getActiveAgents).filter((id) => isInternalAgentMeta(getAgentMeta(id)));
614
+ }
615
+
616
+ function handleExpand(payload = {}) {
617
+ if (!active || payload.session_id !== sessionId) return { ok: false, error: "stale session_id" };
618
+ const view = surfaces.get(payload.agent_id);
619
+ if (!view || !paneManager?.getPane(payload.agent_id)) return { ok: false, error: "agent pane not found" };
620
+ view.surface.toggleExpanded();
621
+ markDirty(payload.agent_id);
622
+ return { ok: true };
454
623
  }
455
624
 
456
625
  function writeToPane(agentId, data) {
@@ -466,6 +635,7 @@ function createRustMultiSession(options = {}) {
466
635
 
467
636
  return {
468
637
  start,
638
+ setLayout,
469
639
  stop,
470
640
  isActive,
471
641
  getSessionId,
@@ -475,6 +645,7 @@ function createRustMultiSession(options = {}) {
475
645
  getSnapshot,
476
646
  handleViewport,
477
647
  handleRaw,
648
+ handleScroll,
478
649
  handleFocus,
479
650
  focusAgent,
480
651
  handleExit,
@@ -482,6 +653,9 @@ function createRustMultiSession(options = {}) {
482
653
  markDirty,
483
654
  writeToPane,
484
655
  listInternalAgentIds,
656
+ acceptEvent,
657
+ hasStructuredEvents: (id) => Boolean(surfaces.get(id)?.structured),
658
+ handleExpand,
485
659
  };
486
660
  }
487
661
 
@@ -17,6 +17,8 @@ const {
17
17
  } = require("../code/UcodeController");
18
18
  const { createEnvelope, encodeMessage } = require("../runtime/contracts/uiProtocol");
19
19
  const fmt = require("./format");
20
+ const { createAgentSurface } = require("./agentSurface");
21
+ const { buildPlanSetPayload, statusForAgentPhase } = require("./agentPresentation");
20
22
  const PACKAGE_VERSION = require("../../package.json").version;
21
23
 
22
24
  function stripTags(value) {
@@ -92,65 +94,6 @@ async function buildUcodeCompletionItems({
92
94
  });
93
95
  }
94
96
 
95
- function buildPlanSetPayload(executionState, options = {}) {
96
- try {
97
- const { buildPlanUiProjection } = require("../code/context/planProjection");
98
- const projection = buildPlanUiProjection(executionState, {
99
- cols: Number(options.cols) > 0 ? Number(options.cols) : 80,
100
- activityMessage: String(options.activityMessage || ""),
101
- });
102
- if (!projection || !projection.visible) {
103
- return {
104
- summary: "",
105
- lines: [],
106
- hash: projection && projection.hash || "",
107
- visible: false,
108
- idle_hint: String((projection && projection.idleHint) || ""),
109
- status_line: "",
110
- band_mode: String((projection && projection.bandMode) || ""),
111
- };
112
- }
113
- let lines = Array.isArray(projection.bandLines) ? projection.bandLines.slice() : [];
114
- const md = String(projection.roadmapMarkdown || "").trim();
115
- if (md) {
116
- try {
117
- const rendered = fmt.renderLogLinesWithMarkdownAnsi(md, { inCodeBlock: false });
118
- if (Array.isArray(rendered) && rendered.length > 0) {
119
- lines = rendered.map((line) => String(line || ""));
120
- }
121
- } catch {
122
- // keep bandLines
123
- }
124
- }
125
- const summary = String(
126
- projection.statusLine
127
- || projection.activityStatusLine
128
- || lines[0]
129
- || ""
130
- ).trim();
131
- return {
132
- summary,
133
- text: summary,
134
- lines,
135
- hash: projection.hash || "",
136
- visible: true,
137
- idle_hint: String(projection.idleHint || ""),
138
- status_line: String(projection.statusLine || projection.activityStatusLine || ""),
139
- activity_status_line: String(projection.activityStatusLine || ""),
140
- band_mode: String(projection.bandMode || ""),
141
- };
142
- } catch {
143
- return {
144
- summary: "",
145
- lines: [],
146
- hash: "",
147
- visible: false,
148
- idle_hint: "",
149
- status_line: "",
150
- band_mode: "",
151
- };
152
- }
153
- }
154
97
 
155
98
  function normalizeToolLogEntry(entry = {}) {
156
99
  const tool = String(entry.tool || "").trim().toLowerCase();
@@ -266,6 +209,7 @@ async function runUcodeRust(props = {}) {
266
209
  let backgroundSeq = 0;
267
210
  let requestExit = false;
268
211
  const MARKDOWN_LOG_KINDS = new Set(["assistant", "error"]);
212
+ const surface = createAgentSurface({ maxEntries: 4000 });
269
213
  const controller = createUcodeController({
270
214
  projectRoot: workspaceRoot,
271
215
  ports: {
@@ -274,6 +218,7 @@ async function runUcodeRust(props = {}) {
274
218
  });
275
219
 
276
220
  function publish(name, payload) {
221
+ surface.apply(name, payload);
277
222
  if (!hostRef) return;
278
223
  hostRef.broadcast(hostRef.createEvent(name, payload, {
279
224
  surface: "ucode",
@@ -533,8 +478,16 @@ async function runUcodeRust(props = {}) {
533
478
  ),
534
479
  });
535
480
 
481
+ surface.apply("transcript.reset", {
482
+ entries: banner.map((line, idx) => {
483
+ const { logo, metadata } = splitUcodeBannerRow(line, idx);
484
+ return { id: `b-${idx}`, kind: "banner", text: logo, detail: metadata, speaker: "" };
485
+ }).concat([{ id: `b-${banner.length}`, kind: "spacer", text: "", speaker: "" }]),
486
+ });
487
+
536
488
  function buildSnapshot() {
537
489
  const meter = props.state && props.state.contextMeter;
490
+ const view = surface.snapshot();
538
491
  const agentsSnap = buildUcodeAgentsSnapshot(
539
492
  workspaceRoot,
540
493
  String(
@@ -544,30 +497,15 @@ async function runUcodeRust(props = {}) {
544
497
  ).trim()
545
498
  );
546
499
  return {
547
- status: "ready",
500
+ status: view.status,
501
+ busy: view.busy,
548
502
  package_version: PACKAGE_VERSION,
549
503
  footer: agentsSnap.footer,
550
- entries: banner.map((line, idx) => {
551
- const { logo, metadata } = splitUcodeBannerRow(line, idx);
552
- return {
553
- id: `b-${idx}`,
554
- kind: "banner",
555
- // Logo and metadata are separate raw renderer segments. Neither
556
- // ever passes through the ordinary log formatter.
557
- text: logo,
558
- detail: metadata,
559
- speaker: "",
560
- };
561
- }).concat([{
562
- id: `b-${banner.length}`,
563
- kind: "spacer",
564
- text: "",
565
- speaker: "",
566
- }]),
504
+ entries: view.entries,
567
505
  input_history: [],
568
506
  agents: agentsSnap.agents,
569
507
  attachment_count: pendingAttachments.length,
570
- usage: String((meter && meter.label) || ""),
508
+ usage: String((meter && meter.label) || view.usage || ""),
571
509
  task_queue: controller.getQueueSnapshot(),
572
510
  };
573
511
  }
@@ -699,15 +637,10 @@ async function runUcodeRust(props = {}) {
699
637
  onToolLog: ingestToolLog,
700
638
  onPhase: (event) => {
701
639
  if (!event || typeof event !== "object") return;
702
- if (event.type === "request_start") {
703
- publish("status.set", { text: "Waiting for model…", busy: true });
704
- } else if (event.type === "text_delta") {
705
- beginResponse();
706
- } else if (event.type === "tool_request") {
707
- const tool = String(event.name || "tool").trim() || "tool";
708
- const label = (fmt.TOOL_LABELS && fmt.TOOL_LABELS[tool.toLowerCase()])
709
- || `Calling ${tool}`;
710
- publish("status.set", { text: `${label}…`, busy: true });
640
+ if (event.type === "text_delta") beginResponse();
641
+ else {
642
+ const text = statusForAgentPhase(event);
643
+ if (text) publish("status.set", { text, busy: true });
711
644
  }
712
645
  },
713
646
  });
@@ -4,7 +4,7 @@
4
4
  * Shared launch-mode / agent-provider options for Ink + Rust chat hosts.
5
5
  */
6
6
 
7
- const MODE_OPTIONS = Object.freeze(["auto", "host", "terminal", "tmux", "internal"]);
7
+ const MODE_OPTIONS = Object.freeze(["internal"]);
8
8
 
9
9
  const PROVIDER_OPTIONS = Object.freeze([
10
10
  { label: "codex", value: "codex-cli" },
@@ -14,8 +14,8 @@ const PROVIDER_OPTIONS = Object.freeze([
14
14
  ]);
15
15
 
16
16
  function buildSettingsSnapshot(settings = {}) {
17
- const { normalizeLaunchMode, normalizeAgentProvider } = require("../config");
18
- const launchMode = normalizeLaunchMode(settings.launchMode || "auto");
17
+ const { normalizeAgentProvider } = require("../config");
18
+ const launchMode = "internal";
19
19
  const agentProvider = normalizeAgentProvider(settings.agentProvider || "codex-cli");
20
20
  return {
21
21
  launch_mode: launchMode,
@@ -29,7 +29,10 @@ function applySettingsPatch(projectRoot, patch = {}) {
29
29
  const { saveConfig, normalizeLaunchMode, normalizeAgentProvider } = require("../config");
30
30
  const next = {};
31
31
  if (patch.launch_mode != null || patch.launchMode != null) {
32
- next.launchMode = normalizeLaunchMode(patch.launch_mode || patch.launchMode);
32
+ if (normalizeLaunchMode(patch.launch_mode || patch.launchMode) !== "internal") {
33
+ return { ok: false, error: "ufoo dashboard uses internal agents only" };
34
+ }
35
+ next.launchMode = "internal";
33
36
  }
34
37
  if (patch.agent_provider != null || patch.agentProvider != null) {
35
38
  next.agentProvider = normalizeAgentProvider(patch.agent_provider || patch.agentProvider);