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
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+
3
+ // Presentation state shared by the standalone coding TUI and embedded agents.
4
+ // Providers supply events; this module owns no model, process or terminal.
5
+ const fmt = require("./format");
6
+ const { toolStatus, statusForAgentPhase, planLinesFromItems } = require("./agentPresentation");
7
+
8
+ function createAgentSurface(options = {}) {
9
+ const maxEntries = options.maxEntries || 1000;
10
+ const maxText = options.maxText || 256000;
11
+ let entries = [];
12
+ let sequence = 0;
13
+ let turn = "turn-0";
14
+ let segment = 0;
15
+ let status = "ready";
16
+ let busy = false;
17
+ let usage = "";
18
+ let plan = [];
19
+ let idlePlanHint = "";
20
+ let revision = 0;
21
+ let startedAt = 0;
22
+ let waiting = false;
23
+ let submitted = [];
24
+ let activityOwnsStatus = false;
25
+ let runningTask = false;
26
+ const background = new Map();
27
+ let contextUsage = "";
28
+ const tools = new Map();
29
+
30
+ function bound() {
31
+ for (const entry of entries) {
32
+ entry.text = String(entry.text || "").slice(-64000);
33
+ entry.detail = String(entry.detail || "").slice(-64000);
34
+ }
35
+ let size = entries.reduce((n, e) => n + e.text.length + e.detail.length, 0);
36
+ while (entries.length > maxEntries || (size > maxText && entries.length > 1)) {
37
+ const removed = entries.shift();
38
+ size -= removed.text.length + removed.detail.length;
39
+ tools.delete(removed.id);
40
+ }
41
+ revision += 1;
42
+ }
43
+
44
+ function entry(id, kind, text = "", detail = "") {
45
+ let row = entries.find((row) => row.id === id);
46
+ if (!row) {
47
+ row = { id, kind, text, detail, speaker: "", expanded: false };
48
+ entries.push(row);
49
+ }
50
+ return row;
51
+ }
52
+
53
+ function apply(name, payload = {}) {
54
+ if (name === "transcript.reset") {
55
+ entries = (payload.entries || []).map((row) => ({ detail: "", speaker: "", expanded: false, ...row }));
56
+ tools.clear();
57
+ } else if (name === "transcript.append") {
58
+ const row = payload.entry || payload;
59
+ Object.assign(entry(row.id || `entry-${++sequence}`, row.kind || "system"), row);
60
+ } else if (name === "transcript.patch") {
61
+ const row = entries.find((row) => row.id === payload.id);
62
+ if (row && typeof payload.text === "string") row.text = payload.text;
63
+ } else if (name === "stream.start") {
64
+ busy = true;
65
+ startedAt = Date.now();
66
+ } else if (name === "stream.delta") {
67
+ entry(payload.id || "stream", "assistant").text += String(payload.text || payload.delta || "");
68
+ busy = true;
69
+ if (!startedAt) startedAt = Date.now();
70
+ } else if (name === "thinking.start" || name === "thinking.delta") {
71
+ const row = entry(payload.id || "thinking", "thinking");
72
+ if (name === "thinking.delta") row.text += String(payload.text || "");
73
+ } else if (name === "stream.done") {
74
+ busy = false;
75
+ status = payload.reason === "error" ? "error" : "ready";
76
+ } else if (["tool.start", "tool.result", "tool.group"].includes(name)) {
77
+ const row = entry(payload.id || `tool-${++sequence}`, "tool");
78
+ row.text = String(payload.summary || payload.text || "tool");
79
+ row.detail = String(payload.detail || payload.expanded_text || "");
80
+ if (row.detail && !row.text.includes("Ctrl+O") && row.detail.includes("\n")) row.text += " (Ctrl+O expand)";
81
+ } else if (name === "status.set") {
82
+ status = String(payload.text || "ready");
83
+ if (typeof payload.busy === "boolean") busy = payload.busy;
84
+ if (busy && !startedAt) startedAt = Date.now();
85
+ } else if (name === "usage.set") {
86
+ usage = String(payload.label || payload.text || "");
87
+ } else if (name === "plan.set") {
88
+ plan = (payload.lines || []).map(String);
89
+ idlePlanHint = String(payload.idle_hint || "");
90
+ } else {
91
+ return false;
92
+ }
93
+ bound();
94
+ return true;
95
+ }
96
+
97
+ function accept(event = {}) {
98
+ const type = event.type;
99
+ if (type === "task_submitted") {
100
+ submitted.push({ message: String(event.message || ""), at: Date.now() });
101
+ waiting = false;
102
+ if (!busy) {
103
+ activityOwnsStatus = false;
104
+ startedAt = Date.now();
105
+ return apply("status.set", { text: "Waiting for agent…", busy: true });
106
+ }
107
+ bound();
108
+ return true;
109
+ }
110
+ if (type === "submission_failed") {
111
+ const index = submitted.findIndex((item) => item.message === event.message);
112
+ if (index >= 0) submitted.splice(index, 1);
113
+ apply("transcript.append", { kind: "error", text: event.error });
114
+ return runningTask ? true : apply("status.set", { text: "error", busy: false });
115
+ }
116
+ if (type === "task_started") {
117
+ const queued = submitted.findIndex((item) => item.message === String(event.message || ""));
118
+ if (queued >= 0) submitted.splice(queued, 1);
119
+ activityOwnsStatus = false;
120
+ runningTask = true;
121
+ waiting = false;
122
+ startedAt = 0;
123
+ turn = String(event.task_id || `turn-${++sequence}`);
124
+ segment = 0;
125
+ tools.clear();
126
+ const message = String(event.message || "");
127
+ const last = entries[entries.length - 1];
128
+ if (message && queued < 0 && !(last?.kind === "user" && last.text === message)) {
129
+ apply("transcript.append", { id: `${turn}-user`, kind: "user", text: message });
130
+ }
131
+ status = "Waiting for model…";
132
+ return apply("stream.start", {});
133
+ }
134
+ if (type === "turn_started" || type === "thread_started") {
135
+ waiting = false;
136
+ activityOwnsStatus = false;
137
+ return apply("status.set", { text: "Waiting for model…", busy: true });
138
+ }
139
+ if (type === "phase") {
140
+ const text = statusForAgentPhase(event.phase || {});
141
+ return text ? apply("status.set", { text, busy: true }) : false;
142
+ }
143
+ if (type === "status") {
144
+ waiting = event.state === "waiting_input";
145
+ return apply("status.set", { text: event.text || event.state, busy: event.busy ?? !waiting });
146
+ }
147
+ if (type === "context_usage") {
148
+ contextUsage = String(event.meter?.label || "");
149
+ return apply("usage.set", { text: contextUsage });
150
+ }
151
+ if (type === "plan") return apply("plan.set", { ...event, lines: event.lines || planLinesFromItems(event.items || []) });
152
+ if (type === "background_task") {
153
+ const id = String(event.task_id || "");
154
+ if (!id) return false;
155
+ background.set(id, { ...background.get(id), ...Object.fromEntries(Object.entries(event).filter(([, value]) => value !== undefined)) });
156
+ if (background.size > 100) background.delete(background.keys().next().value);
157
+ bound();
158
+ return true;
159
+ }
160
+ if (type === "text_delta") {
161
+ status = "Generating response…";
162
+ return apply("stream.delta", { id: `${turn}-text-${segment}`, text: event.delta });
163
+ }
164
+ if (type === "thinking_delta") {
165
+ status = "Thinking…";
166
+ busy = true;
167
+ return apply("thinking.delta", { id: `${turn}-thinking-${segment}`, text: event.delta });
168
+ }
169
+ if (type === "tool_call") {
170
+ segment += 1;
171
+ const id = `${turn}-tool-${String(event.toolCallId || segment)}`;
172
+ const name = String(event.name || "tool");
173
+ const args = event.args || {};
174
+ const detail = fmt.normalizeToolLogDetail(name.toLowerCase(), { ...args, path: args.path || args.file_path }, {});
175
+ const normalized = fmt.normalizeToolMergeEntry({ tool: name.toLowerCase(), detail, isError: false });
176
+ const summary = fmt.buildUcodeToolRowText([normalized]) || `• ${name}`;
177
+ tools.set(id, { summary, output: "" });
178
+ status = toolStatus(name);
179
+ busy = true;
180
+ if (["plan", "TodoWrite", "update_plan"].includes(name)) {
181
+ apply("plan.set", { lines: planLinesFromItems(args.items || args.todos || args.plan || []) });
182
+ }
183
+ return apply("tool.start", { id, summary });
184
+ }
185
+ if (type === "tool_result") {
186
+ const id = `${turn}-tool-${String(event.toolCallId || "tool")}`;
187
+ const tool = tools.get(id) || { summary: "• Tool", output: "" };
188
+ const output = typeof event.output === "string" ? event.output
189
+ : Array.isArray(event.output) ? event.output.map((block) => block?.text || "").join("\n")
190
+ : event.output == null ? "" : typeof event.output === "object"
191
+ ? [event.output.stdout, event.output.stderr, event.output.content, event.output.error].filter((text) => typeof text === "string" && text).join("\n") || JSON.stringify(event.output)
192
+ : String(event.output);
193
+ tool.output = (tool.output + output).slice(-64000);
194
+ tools.set(id, tool);
195
+ if (event.is_error || (Number.isFinite(event.exitCode) && event.exitCode !== 0)) tool.summary = tool.summary.replace(/^• /, "• Failed: ");
196
+ const exit = Number.isFinite(event.exitCode) && event.exitCode !== 0 ? `\n[exit ${event.exitCode}]` : "";
197
+ const detail = [tool.summary.replace(/^• /, ""), tool.output + exit].filter(Boolean).join("\n");
198
+ if (event.status !== "in_progress") status = "Waiting for model…";
199
+ return apply("tool.result", { id, summary: tool.summary, detail });
200
+ }
201
+ if (["task_completed", "task_failed", "task_cancelled"].includes(type)) {
202
+ if (event.error) apply("transcript.append", { kind: "error", text: event.error });
203
+ if (event.usage) accept({ type: "usage", usage: event.usage });
204
+ apply("stream.done", { reason: type === "task_failed" ? "error" : "complete" });
205
+ activityOwnsStatus = false;
206
+ runningTask = false;
207
+ if (type === "task_cancelled") status = "cancelled";
208
+ if (waiting) status = "Waiting for reply…";
209
+ else if (submitted.length) apply("status.set", { text: "Waiting for agent…", busy: true });
210
+ return true;
211
+ }
212
+ if (type === "interaction") {
213
+ waiting = true;
214
+ status = "Waiting for reply…";
215
+ busy = false;
216
+ return apply("transcript.append", { id: `${turn}-interaction`, kind: "system", text: (event.lines || []).join("\n") });
217
+ }
218
+ if (type === "usage") {
219
+ const u = event.usage || {};
220
+ return apply("usage.set", { text: contextUsage || `${u.input_tokens ?? u.input ?? 0} in · ${u.output_tokens ?? u.output ?? 0} out` });
221
+ }
222
+ if (type === "activity") {
223
+ if (event.authoritative !== true && (busy || waiting)) return false;
224
+ const state = String(event.state || "ready");
225
+ const at = Date.parse(event.ts || "");
226
+ if (submitted.length && state !== "working" && state !== "busy" && (!at || at < submitted[0].at)) return false;
227
+ if (["working", "busy", "processing"].includes(state)) {
228
+ if (!activityOwnsStatus && submitted.length) submitted.shift();
229
+ activityOwnsStatus = true;
230
+ runningTask = true;
231
+ waiting = false;
232
+ if (!startedAt) startedAt = Number(event.started_at) || Date.now();
233
+ const detail = String(event.detail || "");
234
+ const text = detail.startsWith("tool ") ? toolStatus(detail.slice(5))
235
+ : detail === "thinking" ? "Thinking…" : detail || "Working…";
236
+ return apply("status.set", { text, busy: true });
237
+ }
238
+ activityOwnsStatus = false;
239
+ runningTask = false;
240
+ waiting = ["waiting_input", "waiting"].includes(state);
241
+ const text = waiting ? "Waiting for reply…" : ["blocked", "error"].includes(state)
242
+ ? `blocked${event.detail ? ` · ${event.detail}` : ""}`
243
+ : state === "starting" ? "Starting agent…" : "ready";
244
+ return apply("status.set", { text, busy: state === "starting" });
245
+ }
246
+ return false;
247
+ }
248
+
249
+ function toggleExpanded() {
250
+ const row = [...entries].reverse().find((row) => row.kind === "thinking" || (row.kind === "tool" && row.detail));
251
+ if (!row) return false;
252
+ row.expanded = !row.expanded;
253
+ revision += 1;
254
+ return true;
255
+ }
256
+
257
+ function snapshot() {
258
+ const bg = [...background.values()];
259
+ const running = bg.filter((task) => ["running", "pending"].includes(task.status)).length;
260
+ const done = bg.filter((task) => task.status === "completed").length;
261
+ const failed = bg.filter((task) => ["failed", "stopped", "killed"].includes(task.status)).length;
262
+ const suffix = [running && `${running} running`, done && `${done} done`, failed && `${failed} failed`].filter(Boolean).join("/");
263
+ const label = `${status}${!busy && status === "ready" && idlePlanHint ? ` · ${idlePlanHint}` : ""}${submitted.length > 1 || (submitted.length && runningTask) ? ` · queued ${submitted.length}` : ""}${suffix ? ` · BG ${suffix}` : ""}`;
264
+ return { entries: entries.map((row) => ({ ...row })), status: label, busy, usage, plan: plan.slice(), revision, started_at: startedAt };
265
+ }
266
+
267
+ return { apply, accept, snapshot, toggleExpanded };
268
+ }
269
+
270
+ module.exports = { createAgentSurface };
@@ -1,4 +1,9 @@
1
1
  const chalk = require("chalk");
2
+ const UFOO_BANNER_LINES = Object.freeze([
3
+ "█ █ █▀▀ █▀█ █▀█",
4
+ "█ █ █▀ █ █ █ █",
5
+ "▀▀▀ ▀ ▀▀▀ ▀▀▀",
6
+ ]);
2
7
 
3
8
  /**
4
9
  * 显示 agent 启动横幅
@@ -7,11 +12,7 @@ function showBanner(options) {
7
12
  const { agentType, sessionId, nickname, daemonStatus } = options;
8
13
 
9
14
  // Compact logo (3 行)
10
- const logo = [
11
- "█ █ █▀▀ █▀█ █▀█",
12
- "█ █ █▀ █ █ █ █",
13
- "▀▀▀ ▀ ▀▀▀ ▀▀▀",
14
- ];
15
+ const logo = UFOO_BANNER_LINES;
15
16
 
16
17
  // Normalize agent type display name
17
18
  const displayAgentType = agentType === "ufoo-code" ? "ucode" : agentType;
@@ -50,11 +51,7 @@ function showUfooBanner(options = {}) {
50
51
  const { version = "1.0.0" } = options;
51
52
 
52
53
  // Compact logo (3 行)
53
- const logo = [
54
- "█ █ █▀▀ █▀█ █▀█",
55
- "█ █ █▀ █ █ █ █",
56
- "▀▀▀ ▀ ▀▀▀ ▀▀▀",
57
- ];
54
+ const logo = UFOO_BANNER_LINES;
58
55
 
59
56
  // 右侧信息
60
57
  const infoLines = [
@@ -73,4 +70,4 @@ function showUfooBanner(options = {}) {
73
70
  console.log("");
74
71
  }
75
72
 
76
- module.exports = { showBanner, showUfooBanner };
73
+ module.exports = { showBanner, showUfooBanner, UFOO_BANNER_LINES };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ const path = require("path");
4
+ const os = require("os");
5
+ const { displayCellWidth } = require("./index");
6
+ const { UFOO_BANNER_LINES: LOGO } = require("./banner");
7
+
8
+ function fit(text, width) {
9
+ const value = String(text || "").replace(/[\x00-\x1f\x7f]/g, "");
10
+ if (displayCellWidth(value) <= width) return value;
11
+ let out = "";
12
+ for (const char of value) {
13
+ if (displayCellWidth(out + char) > width - 1) break;
14
+ out += char;
15
+ }
16
+ return `${out}…`;
17
+ }
18
+
19
+ /** Transient startup rows; hosts must not append these to conversation history. */
20
+ function buildUfooStartupEntries({ version = "dev", workspaceRoot = "", globalMode = false, width = 74 } = {}) {
21
+ const columns = Math.max(1, Math.floor(Number(width) || 74));
22
+ const home = os.homedir();
23
+ const root = String(workspaceRoot || process.cwd());
24
+ const directory = root === home ? "~" : root.startsWith(home + path.sep) ? `~${root.slice(home.length)}` : root;
25
+ const info = [
26
+ `ufoo v${version}`,
27
+ globalMode ? "Global workspace" : directory,
28
+ "Type a task or /help",
29
+ ];
30
+ const logoWidth = Math.max(...LOGO.map(displayCellWidth));
31
+ let rows;
32
+ if (columns >= logoWidth + 26) {
33
+ rows = LOGO.map((text, index) => ({
34
+ text: text.padEnd(logoWidth),
35
+ detail: fit(info[index], columns - logoWidth - 2),
36
+ }));
37
+ } else if (columns >= logoWidth) {
38
+ rows = LOGO.map((text) => ({ text }));
39
+ rows.push(...info.filter(Boolean).map((detail) => ({ text: "", detail: fit(detail, columns) })));
40
+ } else {
41
+ rows = info.filter(Boolean).map((detail) => ({ text: "", detail: fit(detail, columns) }));
42
+ }
43
+ return [
44
+ { id: "startup-before", kind: "spacer", text: "" },
45
+ ...rows.map((row, index) => ({ id: `startup-${index}`, kind: "banner", speaker: "", ...row })),
46
+ { id: "startup-after", kind: "spacer", text: "" },
47
+ ];
48
+ }
49
+
50
+ module.exports = { buildUfooStartupEntries };
@@ -2,8 +2,8 @@
2
2
 
3
3
  /**
4
4
  * Mirror inbound bus events into multi/side internal panes.
5
- * Rust host uses this so pane VT stays live while the main transcript
6
- * router still runs.
5
+ * Rust host projects provider events independently of the main transcript
6
+ * and inbox routing.
7
7
  */
8
8
 
9
9
  function parseInternalBusPayload(raw = "") {
@@ -64,6 +64,8 @@ function writeMultiPaneBusEvent(data = {}, options = {}) {
64
64
  agentIds = [],
65
65
  getMeta = () => ({}),
66
66
  writeToPane = () => false,
67
+ acceptEvent = null,
68
+ hasStructuredEvents = () => false,
67
69
  } = options;
68
70
 
69
71
  const watched = agentIds instanceof Set
@@ -80,6 +82,30 @@ function writeMultiPaneBusEvent(data = {}, options = {}) {
80
82
  const toAgent = aliases.has(target) || aliases.has(String(data.subscriber || ""));
81
83
  if (!fromAgent && !toAgent) continue;
82
84
 
85
+ if (typeof acceptEvent === "function") {
86
+ if (data.event === "agent_surface" && fromAgent) {
87
+ acceptEvent(agentId, data.data?.surface || data.surface || {}, Number(data.seq) || 0);
88
+ handled = true;
89
+ continue;
90
+ }
91
+ if (data.event === "activity_state_changed") {
92
+ acceptEvent(agentId, { type: "activity", state: data.state || data.data?.state,
93
+ detail: data.data?.detail || data.detail || "", ts: data.ts });
94
+ handled = true;
95
+ continue;
96
+ }
97
+ if (fromAgent && hasStructuredEvents(agentId)) { handled = true; continue; }
98
+ if (!data.silent && !(toAgent && !fromAgent && ["rust-multi-window", "chat-direct", "chat-internal-agent-view"].includes(data.source))) {
99
+ const { displayMessage, streamPayload } = parseInternalBusPayload(data.message || "");
100
+ if (streamPayload) {
101
+ if (fromAgent && streamPayload.delta) acceptEvent(agentId, { type: "text_delta", delta: streamPayload.delta });
102
+ if (fromAgent && streamPayload.done) acceptEvent(agentId, { type: "task_completed", usage: streamPayload.usage });
103
+ } else if (displayMessage) acceptEvent(agentId, { type: fromAgent ? "text_delta" : "task_started", delta: displayMessage, message: displayMessage });
104
+ }
105
+ handled = true;
106
+ continue;
107
+ }
108
+
83
109
  if (data.silent) {
84
110
  handled = true;
85
111
  continue;
@@ -110,7 +136,7 @@ function writeMultiPaneBusEvent(data = {}, options = {}) {
110
136
  ? streamPayload.delta.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n").replace(/\\r/g, "\n")
111
137
  : "";
112
138
  try {
113
- if (delta) writeToPane(agentId, delta);
139
+ if (delta) writeToPane(agentId, delta.replace(/\r\n?/g, "\n").replace(/\n/g, "\r\n"));
114
140
  if (streamPayload.done) writeToPane(agentId, "\r\n");
115
141
  } catch { /* ignore */ }
116
142
  handled = true;