u-foo 3.1.7 → 4.0.1

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 (266) hide show
  1. package/OBSERVABILITY.md +65 -0
  2. package/README.md +238 -21
  3. package/README.zh-CN.md +165 -20
  4. package/SKILLS/ufoo/SKILL.md +40 -4
  5. package/SKILLS/ufoo-bus/SKILL.md +46 -3
  6. package/bin/uclaude.js +4 -0
  7. package/bin/ucodex.js +4 -0
  8. package/bin/ufoo.js +6 -4
  9. package/dist/tui/darwin-arm64/ufoo-tui +0 -0
  10. package/dist/tui/darwin-x64/ufoo-tui +0 -0
  11. package/dist/tui/linux-arm64/ufoo-tui +0 -0
  12. package/dist/tui/linux-x64/ufoo-tui +0 -0
  13. package/package.json +14 -7
  14. package/scripts/postinstall-skills.js +53 -0
  15. package/scripts/postinstall.js +11 -16
  16. package/scripts/smoke-native-messages.js +214 -0
  17. package/src/agents/activity/activityDetector.js +1 -1
  18. package/src/agents/activity/activityStateWriter.js +37 -38
  19. package/src/agents/capabilities/agentManagement/index.js +4 -0
  20. package/src/agents/capabilities/agentManagement/service.js +140 -0
  21. package/src/agents/capabilities/agentRouting/index.js +4 -0
  22. package/src/agents/capabilities/coding/index.js +32 -0
  23. package/src/agents/capabilities/coordination/index.js +37 -0
  24. package/src/agents/capabilities/globalRouting/index.js +5 -0
  25. package/src/agents/capabilities/groups/index.js +3 -0
  26. package/src/agents/capabilities/index.js +25 -0
  27. package/src/agents/capabilities/planning/index.js +123 -0
  28. package/src/agents/capabilities/planning/main.js +28 -0
  29. package/src/agents/capabilities/projectDiscovery/index.js +3 -0
  30. package/src/agents/capabilities/scheduling/index.js +3 -0
  31. package/src/agents/capabilities/sharedMemory/index.js +4 -0
  32. package/src/agents/capabilities/skills/index.js +12 -0
  33. package/src/agents/capabilities/taskExecution/index.js +3 -0
  34. package/src/agents/capabilities/taskReports/index.js +6 -0
  35. package/src/agents/controller/controllerToolExecutor.js +40 -22
  36. package/src/agents/controller/index.js +1 -6
  37. package/src/agents/internal/internalRunner.js +181 -76
  38. package/src/agents/launch/index.js +0 -1
  39. package/src/agents/launch/launcher.js +96 -14
  40. package/src/agents/launch/nativeCapabilities.js +40 -0
  41. package/src/agents/launch/nativeMessages.js +362 -0
  42. package/src/agents/launch/notifier.js +15 -20
  43. package/src/agents/launch/readyDetector.js +28 -14
  44. package/src/agents/profiles/coding.js +6 -0
  45. package/src/agents/profiles/globalRouter.js +2 -0
  46. package/src/agents/profiles/main.js +5 -0
  47. package/src/agents/prompts/cooperation.js +14 -0
  48. package/src/agents/prompts/defaultBootstrap.js +1 -1
  49. package/src/agents/prompts/groupBootstrap.js +32 -6
  50. package/src/agents/prompts/mainAgent.js +48 -0
  51. package/src/agents/prompts/native/system.js +4 -1
  52. package/src/agents/prompts/native/tasks.js +2 -2
  53. package/src/agents/prompts/native/ufoo.js +14 -3
  54. package/src/agents/prompts/promptProfiles.js +2 -0
  55. package/src/agents/prompts/reporting.js +16 -0
  56. package/src/agents/providers/claudeEventTranslator.js +9 -1
  57. package/src/agents/providers/claudeThreadProvider.js +47 -4
  58. package/src/agents/providers/clientIdentity.js +75 -0
  59. package/src/agents/providers/codexEventTranslator.js +68 -7
  60. package/src/agents/providers/codexThreadProvider.js +18 -8
  61. package/src/agents/providers/credentials/claude.js +10 -3
  62. package/src/agents/providers/credentials/index.js +2 -0
  63. package/src/agents/providers/directAuthStatus.js +1 -1
  64. package/src/agents/providers/index.js +1 -1
  65. package/src/agents/providers/modelSettings.js +34 -0
  66. package/src/agents/providers/modelsCatalog.js +379 -0
  67. package/src/agents/providers/nativeTransport.js +1146 -0
  68. package/src/agents/providers/runtimeConfig.js +188 -0
  69. package/src/agents/providers/thinkingLevels.js +106 -0
  70. package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
  71. package/src/agents/providers/transports/index.js +10 -0
  72. package/src/agents/providers/transports/openaiChatTransport.js +117 -0
  73. package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
  74. package/src/agents/providers/transports/responsesProtocol.js +504 -0
  75. package/src/agents/providers/transports/systemBlocks.js +16 -0
  76. package/src/agents/providers/transports/transportContract.js +50 -0
  77. package/src/agents/providers/transports/visionBlocks.js +151 -0
  78. package/src/agents/providers/upstreamRuntime.js +135 -0
  79. package/src/agents/runtime/composeCapabilities.js +89 -0
  80. package/src/agents/runtime/context/checkpointStore.js +38 -0
  81. package/src/agents/runtime/context/commandStore.js +43 -0
  82. package/src/agents/runtime/context/compaction.js +151 -0
  83. package/src/agents/runtime/context/contextBudget.js +93 -0
  84. package/src/agents/runtime/context/contextWindow.js +119 -0
  85. package/src/agents/runtime/context/fileLock.js +36 -0
  86. package/src/agents/runtime/context/replayHistory.js +28 -0
  87. package/src/agents/runtime/context/runtimeStore.js +127 -0
  88. package/src/agents/runtime/context/sessionJournal.js +360 -0
  89. package/src/agents/runtime/context/sessionStore.js +57 -0
  90. package/src/agents/runtime/core/agentLoop.js +351 -0
  91. package/src/agents/runtime/core/executionBudget.js +36 -0
  92. package/src/agents/runtime/core/stableJson.js +29 -0
  93. package/src/agents/runtime/core/toolLoopGuard.js +55 -0
  94. package/src/agents/runtime/createAgentRuntime.js +259 -0
  95. package/src/agents/runtime/index.js +14 -0
  96. package/src/agents/runtime/prompts/responseLanguage.js +12 -0
  97. package/src/agents/runtime/protocol/faultHarness.js +90 -0
  98. package/src/agents/runtime/protocol/materialize.js +107 -0
  99. package/src/agents/runtime/protocol/runObservation.js +24 -0
  100. package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
  101. package/src/agents/runtime/protocol/traceContext.js +9 -0
  102. package/src/agents/runtime/tasks/resourceLease.js +66 -0
  103. package/src/agents/runtime/tasks/scheduler.js +73 -0
  104. package/src/agents/runtime/tools/registry.js +57 -0
  105. package/src/app/chat/ChatController.js +29 -45
  106. package/src/app/chat/agentDirectory.js +9 -18
  107. package/src/app/chat/bootstrap.js +1 -2
  108. package/src/app/chat/commandExecutor.js +111 -313
  109. package/src/app/chat/commands.js +39 -45
  110. package/src/app/chat/daemonConnection.js +58 -5
  111. package/src/app/chat/daemonMessageRouter.js +61 -48
  112. package/src/app/chat/historyStore.js +12 -48
  113. package/src/app/chat/inputSubmitHandler.js +21 -35
  114. package/src/app/chat/internalAgentLogHistory.js +19 -60
  115. package/src/app/chat/launchRequestContext.js +42 -0
  116. package/src/app/chat/multiWindow/paneManager.js +91 -164
  117. package/src/app/chat/streamState.js +3 -7
  118. package/src/app/chat/transport.js +1 -1
  119. package/src/app/cli/busCoreCommands.js +9 -0
  120. package/src/app/cli/features/doctor.js +33 -0
  121. package/src/app/cli/features/init.js +5 -5
  122. package/src/app/cli/features/skills.js +16 -4
  123. package/src/app/cli/metricsCommands.js +68 -0
  124. package/src/app/cli/reportCoreCommands.js +37 -0
  125. package/src/app/cli/run.js +82 -42
  126. package/src/app/cli/traceCommands.js +36 -0
  127. package/src/code/agent.js +34 -17
  128. package/src/code/busConsumer.js +1 -3
  129. package/src/code/commands.js +1 -1
  130. package/src/code/context/artifacts.js +12 -11
  131. package/src/code/context/assembler.js +9 -9
  132. package/src/code/context/promptLayers.js +1 -13
  133. package/src/code/context/stableJson.js +2 -27
  134. package/src/code/context/stateCommit.js +2 -1
  135. package/src/code/contextWindow.js +2 -117
  136. package/src/code/conversation/sessionJournal.js +3 -349
  137. package/src/code/internalThread.js +107 -0
  138. package/src/code/launcher/ucode.js +1 -1
  139. package/src/code/launcher/ucodeBootstrap.js +1 -1
  140. package/src/code/modelCommand.js +11 -35
  141. package/src/code/nativeRunner.js +104 -2697
  142. package/src/code/protocol/faultHarness.js +2 -88
  143. package/src/code/protocol/materialize.js +2 -105
  144. package/src/code/protocol/toolCallLedger.js +5 -215
  145. package/src/code/providers/anthropicMessagesTransport.js +2 -118
  146. package/src/code/providers/modelsCatalog.js +1 -317
  147. package/src/code/providers/openaiChatTransport.js +2 -114
  148. package/src/code/providers/openaiResponsesTransport.js +2 -117
  149. package/src/code/providers/responsesProtocol.js +2 -497
  150. package/src/code/providers/transportContract.js +2 -48
  151. package/src/code/providers/visionBlocks.js +2 -149
  152. package/src/code/repl.js +2 -11
  153. package/src/code/sessionStore.js +27 -99
  154. package/src/code/taskDecomposer.js +18 -0
  155. package/src/code/thinkingLevels.js +1 -130
  156. package/src/code/toolBudget.js +1 -17
  157. package/src/code/toolLoopGuard.js +3 -49
  158. package/src/code/tools/artifactRead.js +1 -1
  159. package/src/code/tools/executor.js +373 -0
  160. package/src/code/tools/specs.js +312 -0
  161. package/src/config.js +95 -131
  162. package/src/coordination/bus/deliveryQueue.js +16 -2
  163. package/src/coordination/bus/index.js +14 -9
  164. package/src/coordination/bus/inject.js +15 -7
  165. package/src/coordination/bus/message.js +15 -1
  166. package/src/coordination/bus/nativeReceipts.js +100 -0
  167. package/src/coordination/bus/nickname.js +1 -1
  168. package/src/coordination/bus/queue.js +1 -3
  169. package/src/coordination/bus/subscriber.js +3 -2
  170. package/src/coordination/bus/utils.js +8 -4
  171. package/src/coordination/history/agentPerformance.js +279 -0
  172. package/src/coordination/history/agentSurface.js +142 -0
  173. package/src/coordination/history/agentTrace.js +249 -0
  174. package/src/coordination/memory/index.js +5 -21
  175. package/src/coordination/report/store.js +103 -83
  176. package/src/coordination/state/agentsStore.js +57 -3
  177. package/src/coordination/state/fileLock.js +2 -0
  178. package/src/coordination/state/workspaceAccess.js +36 -0
  179. package/src/orchestration/controller/index.js +1 -8
  180. package/src/orchestration/controller/launchRouting.js +1 -1
  181. package/src/orchestration/solo/commands.js +3 -1
  182. package/src/runtime/contracts/agentMode.js +26 -0
  183. package/src/runtime/contracts/eventContract.js +3 -0
  184. package/src/runtime/contracts/uiProtocol.js +20 -17
  185. package/src/runtime/daemon/agentHost.js +407 -0
  186. package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
  187. package/src/runtime/daemon/busBridge.js +396 -0
  188. package/src/runtime/daemon/claudeChannel.js +159 -0
  189. package/src/runtime/daemon/controlPlaneService.js +28 -18
  190. package/src/runtime/daemon/cronOps.js +25 -17
  191. package/src/runtime/daemon/deliveryScheduler.js +32 -5
  192. package/src/runtime/daemon/globalDaemon.js +28 -1
  193. package/src/runtime/daemon/groupOrchestrator.js +21 -5
  194. package/src/runtime/daemon/groupStatus.js +20 -0
  195. package/src/runtime/daemon/index.js +120 -375
  196. package/src/runtime/daemon/ipcServer.js +32 -10
  197. package/src/runtime/daemon/mcpConfigure.js +113 -20
  198. package/src/runtime/daemon/mcpHttpServer.js +27 -5
  199. package/src/runtime/daemon/mcpServer.js +8 -5
  200. package/src/runtime/daemon/mcpStdioProxy.js +127 -10
  201. package/src/runtime/daemon/nicknameScope.js +1 -1
  202. package/src/runtime/daemon/ops.js +68 -40
  203. package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
  204. package/src/runtime/daemon/promptRequest.js +92 -570
  205. package/src/runtime/daemon/providerSessions.js +67 -33
  206. package/src/runtime/daemon/reportControlBus.js +59 -25
  207. package/src/runtime/daemon/status.js +9 -6
  208. package/src/runtime/privacy/redactor.js +2 -2
  209. package/src/runtime/projects/identity.js +2 -1
  210. package/src/runtime/projects/registry.js +98 -38
  211. package/src/tools/controllerSchemas.js +28 -0
  212. package/src/tools/handlers/dispatchMessage.js +5 -2
  213. package/src/tools/handlers/listAgents.js +3 -1
  214. package/src/tools/handlers/readBusSummary.js +3 -1
  215. package/src/tools/handlers/readProjectRegistry.js +29 -2
  216. package/src/tools/handlers/routeAgent.js +35 -0
  217. package/src/tools/handlers/tier2.js +4 -2
  218. package/src/tools/index.js +1 -0
  219. package/src/tools/registry.js +6 -0
  220. package/src/tools/schemaFixtures.js +42 -5
  221. package/src/tools/tier0/readAgentMetrics.js +14 -0
  222. package/src/tools/tier0/readAgentTrace.js +12 -0
  223. package/src/tools/tier1/routeAgent.js +2 -2
  224. package/src/tools/tier2/runtimeCoordination.js +38 -0
  225. package/src/tools/types.js +2 -0
  226. package/src/ui/agentPresentation.js +109 -0
  227. package/src/ui/agentSettingsController.js +107 -0
  228. package/src/ui/agentSurface.js +270 -0
  229. package/src/ui/dashboardBridge.js +1 -1
  230. package/src/ui/format/banner.js +9 -15
  231. package/src/ui/format/index.js +14 -10
  232. package/src/ui/format/loopSummary.js +50 -0
  233. package/src/ui/format/markdownRenderer.js +3 -4
  234. package/src/ui/format/startupBanner.js +50 -0
  235. package/src/ui/multiPaneBusMirror.js +29 -3
  236. package/src/ui/rustChatHost.js +316 -599
  237. package/src/ui/rustMultiSession.js +288 -73
  238. package/src/ui/rustUcodeHost.js +21 -88
  239. package/src/ui/settingsBridge.js +34 -14
  240. package/src/ui/toolMergeBridge.js +0 -4
  241. package/src/ui/uiHostServer.js +5 -8
  242. package/src/agents/controller/loopObservability.js +0 -200
  243. package/src/agents/controller/loopRuntime.js +0 -472
  244. package/src/agents/controller/ufooAgent.js +0 -829
  245. package/src/agents/launch/ptyRunner.js +0 -1135
  246. package/src/agents/providers/upstreamTransport.js +0 -689
  247. package/src/app/chat/agentBar.js +0 -135
  248. package/src/app/chat/agentEnter.js +0 -70
  249. package/src/app/chat/agentSockets.js +0 -225
  250. package/src/app/chat/dashboardView.js +0 -405
  251. package/src/app/chat/multiWindow/index.js +0 -310
  252. package/src/app/chat/multiWindow/paneLayout.js +0 -84
  253. package/src/app/chat/multiWindow/renderer.js +0 -420
  254. package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
  255. package/src/app/chat/multiWindow/vtFrame.js +0 -93
  256. package/src/app/chat/rawKeyMap.js +0 -42
  257. package/src/app/chat/settingsController.js +0 -111
  258. package/src/orchestration/controller/flags.js +0 -167
  259. package/src/orchestration/controller/gateRouter.js +0 -211
  260. package/src/orchestration/controller/routerFastPath.js +0 -22
  261. package/src/orchestration/controller/routerFinalize.js +0 -222
  262. package/src/orchestration/controller/shadowGuard.js +0 -280
  263. package/src/runtime/daemon/promptLoop.js +0 -136
  264. package/src/runtime/privacy/shadowDiff.js +0 -174
  265. package/src/ui/multiWindowHandoff.js +0 -232
  266. package/src/ui/ptyHandoff.js +0 -23
@@ -1,405 +0,0 @@
1
- const { clampAgentWindowWithSelection } = require("./agentDirectory");
2
-
3
- const DEFAULT_MODE_OPTIONS = ["auto", "host", "terminal", "tmux", "internal"];
4
-
5
- function providerLabel(value) {
6
- if (value === "claude-cli") return "claude";
7
- if (value === "agy-cli" || value === "agy" || value === "antigravity") return "agy";
8
- if (value === "kimi-cli" || value === "kimi" || value === "kimi-code") return "kimi";
9
- if (value === "ucode" || value === "ufoo" || value === "ufoo-code") return "ucode";
10
- return "codex";
11
- }
12
-
13
- function ensureAtPrefix(value) {
14
- const text = String(value || "").trim();
15
- if (!text) return text;
16
- return text.startsWith("@") ? text : `@${text}`;
17
- }
18
-
19
- function activityMarker(state = "") {
20
- const normalized = String(state || "").trim().toLowerCase();
21
- if (normalized === "working") return "*";
22
- if (normalized === "waiting_input") return "?";
23
- if (normalized === "blocked") return "!";
24
- return "";
25
- }
26
-
27
- function withActivityMarker(label = "", state = "") {
28
- const marker = activityMarker(state);
29
- if (!marker) return label;
30
- return `${marker}${label}`;
31
- }
32
-
33
- function buildSummaryLine(options = {}) {
34
- const {
35
- activeAgents = [],
36
- getAgentLabel = (id) => id,
37
- getAgentState = () => "",
38
- launchMode = "terminal",
39
- agentProvider = "codex-cli",
40
- cronTasks = [],
41
- loopSummary = null,
42
- } = options;
43
- const agents = activeAgents.length > 0
44
- ? activeAgents.slice(0, 3)
45
- .map((id) => withActivityMarker(ensureAtPrefix(getAgentLabel(id)), getAgentState(id)))
46
- .join(", ")
47
- + (activeAgents.length > 3 ? ` +${activeAgents.length - 3}` : "")
48
- : "none";
49
- let line = `{gray-fg}Agents:{/gray-fg} {cyan-fg}${agents}{/cyan-fg}`
50
- + ` {gray-fg}Mode:{/gray-fg} {cyan-fg}${launchMode}{/cyan-fg}`
51
- + ` {gray-fg}Agent:{/gray-fg} {cyan-fg}${providerLabel(agentProvider)}{/cyan-fg}`;
52
- const cronCount = Array.isArray(cronTasks) ? cronTasks.length : 0;
53
- if (cronCount > 0) {
54
- line += ` {gray-fg}Cron:{/gray-fg} {cyan-fg}${cronCount}{/cyan-fg}`;
55
- }
56
- const loopPart = formatLoopSummary(loopSummary);
57
- if (loopPart) {
58
- line += ` {gray-fg}Loop:{/gray-fg} {cyan-fg}${loopPart}{/cyan-fg}`;
59
- }
60
- return line;
61
- }
62
-
63
- function formatToolDistribution(items = []) {
64
- const tools = Array.isArray(items) ? items : [];
65
- if (tools.length === 0) return "";
66
- const visible = tools.slice(0, 2).map((item) => `${item.name}x${item.count}`);
67
- if (tools.length > 2) {
68
- visible.push(`+${tools.length - 2}`);
69
- }
70
- return visible.join(",");
71
- }
72
-
73
- function formatLoopSummary(loopSummary) {
74
- if (!loopSummary || typeof loopSummary !== "object") return "";
75
- const rounds = Number(loopSummary.rounds) || 0;
76
- const toolCalls = Number(loopSummary.tool_calls) || 0;
77
- const totalTokens = Number(loopSummary.total_tokens) || 0;
78
- const inputTokens = Number(loopSummary.input_tokens) || 0;
79
- const cacheReadTokens = Number(loopSummary.cache_read_tokens) || 0;
80
- const cacheCreationTokens = Number(loopSummary.cache_creation_tokens) || 0;
81
- const terminalReason = String(loopSummary.terminal_reason || "").trim();
82
- const toolDistribution = formatToolDistribution(loopSummary.tools);
83
-
84
- if (rounds <= 0 && toolCalls <= 0 && totalTokens <= 0 && !terminalReason && !toolDistribution) {
85
- return "";
86
- }
87
-
88
- const parts = [
89
- `r${rounds}`,
90
- `tc${toolCalls}`,
91
- `tok${totalTokens}`,
92
- ];
93
- if (cacheReadTokens > 0 || cacheCreationTokens > 0) {
94
- let cachePart = `cache${cacheReadTokens}/${cacheCreationTokens}`;
95
- if (cacheReadTokens > 0) {
96
- const hitRate = Math.round((cacheReadTokens / (cacheReadTokens + inputTokens)) * 100);
97
- cachePart += `(${hitRate}%)`;
98
- }
99
- parts.push(cachePart);
100
- }
101
- if (toolDistribution) {
102
- parts.push(toolDistribution);
103
- }
104
- if (terminalReason) {
105
- parts.push(terminalReason);
106
- }
107
- return parts.join(" ");
108
- }
109
-
110
- function buildProjectRailLine(options = {}) {
111
- const {
112
- projects = [],
113
- selectedProjectIndex = -1,
114
- projectListWindowStart = 0,
115
- maxProjectWindow = 5,
116
- activeProjectRoot = "",
117
- projectsFocused = false,
118
- globalScope = "",
119
- dashboardHint = "",
120
- } = options;
121
- const rows = Array.isArray(projects) ? projects : [];
122
- let windowStart = projectListWindowStart;
123
- if (rows.length === 0) {
124
- return {
125
- hasProjects: false,
126
- line: " {gray-fg}Projects:{/gray-fg} {cyan-fg}none{/cyan-fg}",
127
- windowStart,
128
- };
129
- }
130
-
131
- const activeRoot = String(activeProjectRoot || "");
132
- const fallbackIndex = rows.findIndex((row) => String((row || {}).project_root || "") === activeRoot);
133
- const normalizedSelectedIndex = Number.isFinite(selectedProjectIndex)
134
- ? Math.trunc(selectedProjectIndex)
135
- : -1;
136
- const safeSelectedIndex = normalizedSelectedIndex >= 0 && normalizedSelectedIndex < rows.length
137
- ? normalizedSelectedIndex
138
- : (fallbackIndex >= 0 ? fallbackIndex : 0);
139
-
140
- windowStart = clampAgentWindowWithSelection({
141
- activeCount: rows.length,
142
- maxWindow: Math.max(1, maxProjectWindow),
143
- windowStart,
144
- selectionIndex: safeSelectedIndex,
145
- });
146
-
147
- const maxItems = Math.max(1, Math.min(Math.max(1, maxProjectWindow), rows.length));
148
- const start = windowStart;
149
- const end = start + maxItems;
150
- const visibleRows = rows.slice(start, end);
151
- const projectParts = visibleRows.map((row, i) => {
152
- const absoluteIndex = start + i;
153
- const name = String((row && row.project_name) || (row && row.project_root) || "-");
154
- const rowRoot = String((row && row.project_root) || "");
155
- const isActiveProject = globalScope !== "controller" && Boolean(activeRoot && rowRoot === activeRoot);
156
- const isSelected = absoluteIndex === safeSelectedIndex;
157
- if (projectsFocused && isSelected) {
158
- return `{inverse}${name}{/inverse}`;
159
- }
160
- if (isActiveProject) {
161
- return `{bold}{cyan-fg}${name}{/cyan-fg}{/bold}`;
162
- }
163
- return `{cyan-fg}${name}{/cyan-fg}`;
164
- });
165
-
166
- const leftMore = start > 0 ? "{gray-fg}<{/gray-fg} " : "";
167
- const rightMore = end < rows.length ? " {gray-fg}>{/gray-fg}" : "";
168
- const hintPart = dashboardHint ? `{|}{gray-fg}${dashboardHint}{/gray-fg}` : "";
169
- return {
170
- hasProjects: true,
171
- line: ` {gray-fg}Projects:{/gray-fg} ${leftMore}${projectParts.join(" ")}${rightMore}${hintPart}`,
172
- windowStart,
173
- };
174
- }
175
-
176
- function buildDashboardDetailLine(options = {}) {
177
- const {
178
- globalMode = false,
179
- dashboardView = "agents",
180
- activeAgents = [],
181
- selectedAgentIndex = -1,
182
- agentListWindowStart = 0,
183
- maxAgentWindow = 4,
184
- getAgentLabel = (id) => id,
185
- getAgentState = () => "",
186
- selectedModeIndex = 0,
187
- selectedProviderIndex = 0,
188
- selectedCronIndex = -1,
189
- cronTasks = [],
190
- providerOptions = [],
191
- dashHints = {},
192
- modeOptions = DEFAULT_MODE_OPTIONS,
193
- } = options;
194
-
195
- let content = " ";
196
- let windowStart = agentListWindowStart;
197
-
198
- if (dashboardView === "mode") {
199
- const modeParts = modeOptions.map((mode, i) => {
200
- if (i === selectedModeIndex) {
201
- return `{inverse}${mode}{/inverse}`;
202
- }
203
- return `{cyan-fg}${mode}{/cyan-fg}`;
204
- });
205
- content += `{gray-fg}Mode:{/gray-fg} ${modeParts.join(" ")}`;
206
- content += ` {gray-fg}│ ${dashHints.mode || ""}{/gray-fg}`;
207
- return { content, windowStart };
208
- }
209
-
210
- if (dashboardView === "provider") {
211
- const providerParts = providerOptions.map((opt, i) => {
212
- if (i === selectedProviderIndex) {
213
- return `{inverse}${opt.label}{/inverse}`;
214
- }
215
- return `{cyan-fg}${opt.label}{/cyan-fg}`;
216
- });
217
- content += `{gray-fg}Agent:{/gray-fg} ${providerParts.join(" ")}`;
218
- content += ` {gray-fg}│ ${dashHints.provider || ""}{/gray-fg}`;
219
- return { content, windowStart };
220
- }
221
-
222
- if (dashboardView === "cron") {
223
- const items = Array.isArray(cronTasks) ? cronTasks : [];
224
- const summary = items.length > 0
225
- ? items.map((item, index) => {
226
- const label = item.label || item.summary || item.id || "";
227
- if (!label) return "";
228
- return index === selectedCronIndex
229
- ? `{inverse}${label}{/inverse}`
230
- : `{cyan-fg}${label}{/cyan-fg}`;
231
- }).filter(Boolean).join(", ")
232
- : "{cyan-fg}none{/cyan-fg}";
233
- content += `{gray-fg}Cron:{/gray-fg} ${summary}`;
234
- content += ` {gray-fg}│ ${dashHints.cron || ""}{/gray-fg}`;
235
- return { content, windowStart };
236
- }
237
-
238
- if (activeAgents.length > 0) {
239
- windowStart = clampAgentWindowWithSelection({
240
- activeCount: activeAgents.length,
241
- maxWindow: maxAgentWindow,
242
- windowStart,
243
- selectionIndex: selectedAgentIndex,
244
- });
245
- const maxItems = Math.max(1, Math.min(maxAgentWindow, activeAgents.length));
246
- const start = windowStart;
247
- const end = start + maxItems;
248
- const visibleAgents = activeAgents.slice(start, end);
249
- const agentParts = visibleAgents.map((agent, i) => {
250
- const absoluteIndex = start + i;
251
- const label = withActivityMarker(
252
- ensureAtPrefix(getAgentLabel(agent)),
253
- getAgentState(agent)
254
- );
255
- if (absoluteIndex === selectedAgentIndex) {
256
- return `{inverse}${label}{/inverse}`;
257
- }
258
- return `{cyan-fg}${label}{/cyan-fg}`;
259
- });
260
- const leftMore = start > 0 ? "{gray-fg}<{/gray-fg} " : "";
261
- const rightMore = end < activeAgents.length ? " {gray-fg}>{/gray-fg}" : "";
262
- content += `{gray-fg}Agents:{/gray-fg} ${leftMore}${agentParts.join(" ")}${rightMore}`;
263
- const agentsHint = globalMode
264
- ? (dashHints.agentsGlobal || dashHints.agents || "")
265
- : (dashHints.agents || "");
266
- content += ` {gray-fg}│ ${agentsHint}{/gray-fg}`;
267
- } else {
268
- content += "{gray-fg}Agents:{/gray-fg} {cyan-fg}none{/cyan-fg}";
269
- content += ` {gray-fg}│ ${dashHints.agentsEmpty || ""}{/gray-fg}`;
270
- }
271
- return { content, windowStart };
272
- }
273
-
274
- function computeDashboardContent(options = {}) {
275
- const {
276
- globalMode = false,
277
- globalScope = "controller",
278
- focusMode = "input",
279
- dashboardView = "agents",
280
- activeAgents = [],
281
- projects = [],
282
- selectedProjectIndex = -1,
283
- projectListWindowStart = 0,
284
- maxProjectWindow = 5,
285
- activeProjectRoot = "",
286
- selectedAgentIndex = -1,
287
- agentListWindowStart = 0,
288
- maxAgentWindow = 4,
289
- getAgentLabel = (id) => id,
290
- getAgentState = () => "",
291
- launchMode = "terminal",
292
- agentProvider = "codex-cli",
293
- selectedModeIndex = 0,
294
- selectedProviderIndex = 0,
295
- selectedCronIndex = -1,
296
- cronTasks = [],
297
- loopSummary = null,
298
- pendingReports = 0,
299
- providerOptions = [],
300
- dashHints = {},
301
- modeOptions = DEFAULT_MODE_OPTIONS,
302
- } = options;
303
-
304
- if (globalMode) {
305
- const projectsFocused = focusMode === "dashboard" && dashboardView === "projects";
306
- let dashboardHint = "";
307
- if (projectsFocused) {
308
- dashboardHint = globalScope === "controller" ? "Enter\u2192project" : "Esc\u2192global";
309
- }
310
- const rail = buildProjectRailLine({
311
- projects,
312
- selectedProjectIndex,
313
- projectListWindowStart,
314
- maxProjectWindow,
315
- activeProjectRoot,
316
- projectsFocused,
317
- globalScope,
318
- dashboardHint,
319
- });
320
- if (!rail.hasProjects) {
321
- const line2 = ` {gray-fg}${dashHints.projectsEmpty || "Run ufoo chat/daemon in projects to populate registry"}{/gray-fg}`;
322
- return {
323
- content: `${rail.line}\n${line2}`,
324
- windowStart: rail.windowStart,
325
- };
326
- }
327
-
328
- if (focusMode !== "dashboard" || projectsFocused) {
329
- const line2 = buildSummaryLine({
330
- activeAgents,
331
- getAgentLabel,
332
- getAgentState,
333
- launchMode,
334
- agentProvider,
335
- cronTasks,
336
- loopSummary,
337
- });
338
- return {
339
- content: `${rail.line}\n ${line2}`,
340
- windowStart: rail.windowStart,
341
- };
342
- }
343
-
344
- const detail = buildDashboardDetailLine({
345
- globalMode,
346
- dashboardView,
347
- activeAgents,
348
- selectedAgentIndex,
349
- agentListWindowStart,
350
- maxAgentWindow,
351
- getAgentLabel,
352
- getAgentState,
353
- selectedModeIndex,
354
- selectedProviderIndex,
355
- selectedCronIndex,
356
- cronTasks,
357
- providerOptions,
358
- dashHints,
359
- modeOptions,
360
- });
361
- return {
362
- content: `${rail.line}\n${detail.content}`,
363
- windowStart: detail.windowStart,
364
- };
365
- }
366
-
367
- if (focusMode === "dashboard") {
368
- return buildDashboardDetailLine({
369
- globalMode,
370
- dashboardView,
371
- activeAgents,
372
- selectedAgentIndex,
373
- agentListWindowStart,
374
- maxAgentWindow,
375
- getAgentLabel,
376
- getAgentState,
377
- selectedModeIndex,
378
- selectedProviderIndex,
379
- selectedCronIndex,
380
- cronTasks,
381
- providerOptions,
382
- dashHints,
383
- modeOptions,
384
- });
385
- }
386
-
387
- let content = " ";
388
- content += buildSummaryLine({
389
- activeAgents,
390
- getAgentLabel,
391
- getAgentState,
392
- launchMode,
393
- agentProvider,
394
- cronTasks,
395
- loopSummary,
396
- });
397
-
398
- return { content, windowStart: agentListWindowStart };
399
- }
400
-
401
- module.exports = {
402
- computeDashboardContent,
403
- providerLabel,
404
- formatLoopSummary,
405
- };
@@ -1,310 +0,0 @@
1
- const { calculatePaneLayout } = require("./paneLayout");
2
- const { createPaneManager } = require("./paneManager");
3
- const { createRenderer } = require("./renderer");
4
-
5
- // Pane output bursts are coalesced into short batches; full chrome repaints
6
- // are throttled with a trailing frame so the final state always renders.
7
- const PANE_OUTPUT_BATCH_MS = 50;
8
- const RENDER_ALL_MIN_INTERVAL_MS = 100;
9
-
10
- function createMultiWindowController(options = {}) {
11
- const {
12
- processStdout = process.stdout,
13
- getRows = () => process.stdout.rows || 24,
14
- getCols = () => process.stdout.columns || 80,
15
- getInjectSockPath = () => "",
16
- getActiveAgents = () => [],
17
- getAgentPaneOptions = () => ({}),
18
- getChatLogLines = () => [],
19
- getStatusText = () => "",
20
- getPromptPrefix = () => "› ",
21
- getCurrentDraft = () => "",
22
- getCursorPos = () => 0,
23
- getCompletions = () => ({ items: [], index: -1, windowStart: 0, pageSize: 8 }),
24
- getAgentLabel = (id) => id,
25
- getInternalPaneInfo = () => ({}),
26
- getDashboardLines = () => [],
27
- getTerminalFocused = () => false,
28
- freezeScreen = () => {},
29
- restoreTerminal = () => {},
30
- onExit = () => {},
31
- onFocusAgent = () => {},
32
- onInternalSubmit = () => {},
33
- } = options;
34
-
35
- let active = false;
36
- let renderThrottleTimer = null;
37
- let dirtyPanes = new Set();
38
- let renderAllTimer = null;
39
- let renderAllTrailing = false;
40
- let lastRenderAllAt = 0;
41
- let lastCompletionPopup = null;
42
- const renderer = createRenderer({ write: (d) => processStdout.write(d) });
43
- const paneManager = createPaneManager({
44
- getInjectSockPath,
45
- onInternalSubmit,
46
- onPaneOutput: (agentId) => {
47
- if (!active) return;
48
- dirtyPanes.add(agentId);
49
- if (!renderThrottleTimer) {
50
- renderThrottleTimer = setTimeout(() => {
51
- renderThrottleTimer = null;
52
- const panes = [...dirtyPanes];
53
- dirtyPanes.clear();
54
- for (const id of panes) renderSinglePane(id);
55
- }, PANE_OUTPUT_BATCH_MS);
56
- }
57
- },
58
- });
59
-
60
- function enter() {
61
- const agents = getActiveAgents();
62
- if (agents.length === 0) return false;
63
- if (active) return false;
64
- active = true;
65
- freezeScreen(true);
66
- renderer.hideCursor();
67
- renderer.clear();
68
- syncAgents();
69
- renderAllNow();
70
- return true;
71
- }
72
-
73
- function exit() {
74
- if (!active) return;
75
- active = false;
76
- if (renderThrottleTimer) {
77
- clearTimeout(renderThrottleTimer);
78
- renderThrottleTimer = null;
79
- dirtyPanes.clear();
80
- }
81
- if (renderAllTimer) {
82
- clearTimeout(renderAllTimer);
83
- renderAllTimer = null;
84
- renderAllTrailing = false;
85
- }
86
- paneManager.disconnectAll();
87
- renderer.showCursor();
88
- restoreTerminal();
89
- freezeScreen(false);
90
- onExit();
91
- }
92
-
93
- function syncAgents() {
94
- const agents = getActiveAgents();
95
- const current = new Set(paneManager.getAgentIds());
96
- const layout = calculatePaneLayout(getCols(), getRows(), agents.length);
97
-
98
- for (let i = 0; i < agents.length; i++) {
99
- const id = agents[i];
100
- const pane = layout.agentPanes[i];
101
- if (!pane) continue;
102
- const innerW = Math.max(1, pane.width - 2);
103
- const innerH = Math.max(1, pane.height - 2);
104
- if (!current.has(id)) {
105
- paneManager.addAgent(id, innerW, innerH, getAgentPaneOptions(id) || {});
106
- } else {
107
- paneManager.sendResize(id, innerW, innerH);
108
- }
109
- }
110
- for (const id of current) {
111
- if (!agents.includes(id)) {
112
- paneManager.removeAgent(id);
113
- }
114
- }
115
- }
116
-
117
- function renderSinglePane(agentId) {
118
- if (!active) return;
119
- try {
120
- const agents = paneManager.getAgentIds();
121
- const layout = calculatePaneLayout(getCols(), getRows(), agents.length);
122
- const idx = agents.indexOf(agentId);
123
- if (idx < 0 || !layout.agentPanes[idx]) return;
124
- const pane = paneManager.getPane(agentId);
125
- if (!pane) return;
126
- const isFocused = getTerminalFocused() && agentId === paneManager.getFocused();
127
- if (pane.mode === "internal" && typeof renderer.renderInternalPane === "function") {
128
- renderer.renderInternalPane(pane.vt, layout.agentPanes[idx], isFocused, {
129
- label: getAgentLabel(agentId),
130
- ...(getInternalPaneInfo(agentId) || {}),
131
- input: pane.internalInput || "",
132
- cursor: pane.internalCursor || 0,
133
- });
134
- } else {
135
- renderer.renderPane(pane.vt, layout.agentPanes[idx], isFocused, getAgentLabel(agentId));
136
- }
137
- } catch {
138
- // swallow render errors to prevent crash
139
- }
140
- }
141
-
142
- function renderAllNow() {
143
- if (!active) return;
144
- lastRenderAllAt = Date.now();
145
- try {
146
- const agents = paneManager.getAgentIds();
147
- const layout = calculatePaneLayout(getCols(), getRows(), agents.length);
148
- const cols = getCols();
149
-
150
- // Resolve the completion popup up front so stale rows are cleared
151
- // before anything repaints (clearing also invalidates renderer caches).
152
- const cmp = getCompletions();
153
- let nextCompletionPopup = null;
154
- let nextCompletionItems = null;
155
- let nextCompletionStart = 0;
156
- if (cmp && Array.isArray(cmp.items) && cmp.items.length > 0 && layout.inputPane) {
157
- const start = Math.min(cmp.windowStart || 0, Math.max(0, cmp.items.length - (cmp.pageSize || 8)));
158
- const end = Math.min(cmp.items.length, start + (cmp.pageSize || 8));
159
- const visible = cmp.items.slice(start, end);
160
- const popupTop = layout.inputPane.top - visible.length - 1;
161
- if (popupTop >= 0) {
162
- nextCompletionPopup = { top: popupTop, left: 0, width: cols, height: visible.length + 1 };
163
- nextCompletionItems = visible;
164
- nextCompletionStart = start;
165
- }
166
- }
167
- const prevPopup = lastCompletionPopup;
168
- const samePopupRect = prevPopup && nextCompletionPopup &&
169
- prevPopup.top === nextCompletionPopup.top &&
170
- prevPopup.width === nextCompletionPopup.width &&
171
- prevPopup.height === nextCompletionPopup.height &&
172
- (prevPopup.left || 0) === (nextCompletionPopup.left || 0);
173
- if (prevPopup && !samePopupRect && typeof renderer.clearRows === "function") {
174
- renderer.clearRows(prevPopup.top, prevPopup.height, prevPopup.width, prevPopup.left || 0);
175
- }
176
-
177
- renderer.renderChatLog(layout.chatPane, getChatLogLines());
178
-
179
- const focused = getTerminalFocused() ? paneManager.getFocused() : null;
180
- for (let i = 0; i < agents.length; i++) {
181
- const pane = paneManager.getPane(agents[i]);
182
- if (!pane || !layout.agentPanes[i]) continue;
183
- if (pane.mode === "internal" && typeof renderer.renderInternalPane === "function") {
184
- renderer.renderInternalPane(pane.vt, layout.agentPanes[i], agents[i] === focused, {
185
- label: getAgentLabel(agents[i]),
186
- ...(getInternalPaneInfo(agents[i]) || {}),
187
- input: pane.internalInput || "",
188
- cursor: pane.internalCursor || 0,
189
- });
190
- } else {
191
- renderer.renderPane(pane.vt, layout.agentPanes[i], agents[i] === focused, getAgentLabel(agents[i]));
192
- }
193
- }
194
-
195
- const chatFocused = !getTerminalFocused();
196
- if (layout.separatorPane) {
197
- renderer.renderSeparator(layout.separatorPane, chatFocused);
198
- }
199
- if (layout.statusPane) {
200
- renderer.renderStatusLine(layout.statusPane, getStatusText());
201
- }
202
- if (layout.inputPane) {
203
- renderer.renderInputPrompt(layout.inputPane, getPromptPrefix(), getCurrentDraft(), getCursorPos());
204
- }
205
- if (layout.inputSepPane) {
206
- renderer.renderSeparator(layout.inputSepPane, chatFocused);
207
- }
208
- if (layout.dashboardPane) {
209
- const lines = getDashboardLines();
210
- renderer.renderDashboard(layout.dashboardPane, lines);
211
- }
212
-
213
- if (nextCompletionPopup && nextCompletionItems) {
214
- const popupTop = nextCompletionPopup.top;
215
- renderer.renderSeparator({ top: popupTop, left: 0, width: cols });
216
- for (let i = 0; i < nextCompletionItems.length; i++) {
217
- const idx = nextCompletionStart + i;
218
- const selected = idx === cmp.index;
219
- const label = nextCompletionItems[i].label || "";
220
- const desc = nextCompletionItems[i].description || "";
221
- const line = selected
222
- ? `\x1b[7;36m${label}\x1b[0m \x1b[90m${desc}\x1b[0m`
223
- : `\x1b[90m${label} ${desc}\x1b[0m`;
224
- const pad = Math.max(0, cols - renderer.visibleLength(line));
225
- renderer.write(renderer.moveTo(popupTop + 1 + i, 0) + line + " ".repeat(pad) + "\x1b[0m");
226
- }
227
- }
228
- lastCompletionPopup = nextCompletionPopup;
229
- } catch {
230
- // swallow render errors to prevent crash
231
- }
232
- }
233
-
234
- // Throttled entry point for external callers: renders immediately when idle,
235
- // otherwise coalesces bursts into one trailing frame so state stays consistent.
236
- function renderAll() {
237
- if (!active) return;
238
- const elapsed = Date.now() - lastRenderAllAt;
239
- if (!renderAllTimer && elapsed >= RENDER_ALL_MIN_INTERVAL_MS) {
240
- renderAllNow();
241
- return;
242
- }
243
- renderAllTrailing = true;
244
- if (!renderAllTimer) {
245
- renderAllTimer = setTimeout(() => {
246
- renderAllTimer = null;
247
- if (!renderAllTrailing) return;
248
- renderAllTrailing = false;
249
- renderAllNow();
250
- }, Math.max(RENDER_ALL_MIN_INTERVAL_MS - elapsed, 16));
251
- if (typeof renderAllTimer.unref === "function") renderAllTimer.unref();
252
- }
253
- }
254
-
255
- function handleKey(key) {
256
- if (!active) return false;
257
-
258
- if (key.name === "c" && key.ctrl) {
259
- return false;
260
- }
261
-
262
- if (key.name === "w" && key.ctrl) {
263
- paneManager.cycleFocus();
264
- renderAllNow();
265
- return true;
266
- }
267
-
268
- if (key.name === "q" && key.ctrl) {
269
- exit();
270
- return true;
271
- }
272
-
273
- return false;
274
- }
275
-
276
- function focusAgent(agentId) {
277
- if (!active) return;
278
- const agents = paneManager.getAgentIds();
279
- if (!agents.includes(agentId)) return;
280
- paneManager.setFocused(agentId);
281
- onFocusAgent(agentId);
282
- renderAllNow();
283
- }
284
-
285
- function handleResize() {
286
- if (!active) return;
287
- syncAgents();
288
- renderer.clear();
289
- renderAllNow();
290
- }
291
-
292
- function isActive() { return active; }
293
-
294
- return {
295
- enter,
296
- exit,
297
- isActive,
298
- handleKey,
299
- handleResize,
300
- syncAgents,
301
- renderAll,
302
- focusAgent,
303
- sendInput: (data) => paneManager.sendInput(data),
304
- writeToPane: (agentId, data) => paneManager.writeToPane(agentId, data),
305
- getFocused: () => paneManager.getFocused(),
306
- getAgentIds: () => paneManager.getAgentIds(),
307
- };
308
- }
309
-
310
- module.exports = { createMultiWindowController };