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,84 +0,0 @@
1
- function calculatePaneLayout(termCols, termRows, agentCount) {
2
- const bottomRows = 5;
3
- const safeRows = termRows - 1;
4
- const contentHeight = Math.max(1, safeRows - bottomRows);
5
- const bottomTop = contentHeight;
6
-
7
- const statusPane = { top: bottomTop, left: 0, width: termCols };
8
- const separatorPane = { top: bottomTop + 1, left: 0, width: termCols };
9
- const inputPane = { top: bottomTop + 2, left: 0, width: termCols };
10
- const inputSepPane = { top: bottomTop + 3, left: 0, width: termCols };
11
- const dashboardPane = { top: bottomTop + 4, left: 0, width: termCols };
12
-
13
- if (agentCount <= 0) {
14
- return {
15
- separatorPane,
16
- statusPane,
17
- inputPane,
18
- inputSepPane,
19
- dashboardPane,
20
- chatPane: { top: 0, left: 0, width: termCols, height: contentHeight },
21
- agentPanes: [],
22
- };
23
- }
24
-
25
- const chatWidth = Math.floor(termCols / 3);
26
- const rightLeft = chatWidth + 1;
27
- const rightWidth = termCols - chatWidth - 1;
28
-
29
- const chatPane = { top: 0, left: 0, width: chatWidth, height: contentHeight };
30
-
31
- if (rightWidth < 4 || contentHeight < 3) {
32
- return {
33
- separatorPane,
34
- statusPane,
35
- inputPane,
36
- inputSepPane,
37
- dashboardPane,
38
- chatPane: { top: 0, left: 0, width: termCols, height: contentHeight },
39
- agentPanes: [],
40
- };
41
- }
42
-
43
- const agentPanes = layoutAgentPanes(rightLeft, rightWidth, contentHeight, agentCount, 0);
44
- return { separatorPane, statusPane, inputPane, inputSepPane, dashboardPane, chatPane, agentPanes };
45
- }
46
-
47
- function layoutAgentPanes(left, width, height, count, topOffset = 0) {
48
- if (count === 1) {
49
- return [{ top: topOffset, left, width, height }];
50
- }
51
- if (count === 2) {
52
- const h1 = Math.floor(height / 2);
53
- return [
54
- { top: topOffset, left, width, height: h1 },
55
- { top: topOffset + h1, left, width, height: height - h1 },
56
- ];
57
- }
58
-
59
- const rowCount = Math.ceil(count / 2);
60
- const rowHeight = Math.floor(height / rowCount);
61
- const panes = [];
62
- let placed = 0;
63
-
64
- for (let row = 0; row < rowCount; row++) {
65
- const rowTop = topOffset + row * rowHeight;
66
- const actualHeight = row === rowCount - 1 ? height - row * rowHeight : rowHeight;
67
- const remaining = count - placed;
68
- const isOddRow = remaining % 2 === 1 && row === 0 && count % 2 === 1;
69
-
70
- if (isOddRow) {
71
- panes.push({ top: rowTop, left, width, height: actualHeight });
72
- placed++;
73
- } else {
74
- const halfWidth = Math.floor(width / 2);
75
- panes.push({ top: rowTop, left, width: halfWidth, height: actualHeight });
76
- panes.push({ top: rowTop, left: left + halfWidth + 1, width: width - halfWidth - 1, height: actualHeight });
77
- placed += 2;
78
- }
79
- }
80
-
81
- return panes;
82
- }
83
-
84
- module.exports = { calculatePaneLayout };
@@ -1,420 +0,0 @@
1
- const BOX = { h: "─", v: "│", tl: "┌", tr: "┐", bl: "└", br: "┘", t: "┬", b: "┴", l: "├", r: "┤", x: "┼" };
2
- const {
3
- classifyChatLogLine,
4
- compactContinuationIndent,
5
- compactDividerLabel,
6
- } = require("../../../ui/chatLogModel");
7
-
8
- function createRenderer(options = {}) {
9
- const {
10
- write: rawWrite = process.stdout.write.bind(process.stdout),
11
- } = options;
12
-
13
- // Last-write caches used to skip redundant output. Both are reset by
14
- // clear()/clearRows() so a blanked region is always repainted.
15
- let slotCache = new Map();
16
- let paneSigs = new WeakMap();
17
-
18
- function write(data) {
19
- try { rawWrite(data); } catch {}
20
- }
21
-
22
- function writeIfChanged(slot, data, top, height) {
23
- const prev = slotCache.get(slot);
24
- if (prev && prev.data === data && prev.top === top) return;
25
- slotCache.set(slot, { data, top, height });
26
- write(data);
27
- }
28
-
29
- function paneSignature(pane, focused, extra) {
30
- return [pane.top, pane.left, pane.width, pane.height, focused ? 1 : 0, extra || ""].join("|");
31
- }
32
-
33
- function shouldSkipPane(vt, sig, force) {
34
- if (force || paneSigs.get(vt) !== sig) return false;
35
- return typeof vt.isDirty === "function" ? !vt.isDirty() : false;
36
- }
37
-
38
- function markPaneRendered(vt, sig) {
39
- paneSigs.set(vt, sig);
40
- if (vt && typeof vt.clearDirty === "function") vt.clearDirty();
41
- }
42
-
43
- function moveTo(row, col) {
44
- return `\x1b[${row + 1};${col + 1}H`;
45
- }
46
-
47
- function attrToAnsi(attr) {
48
- const parts = [];
49
- if (attr.bold) parts.push("1");
50
- if (attr.dim) parts.push("2");
51
- if (attr.italic) parts.push("3");
52
- if (attr.underline) parts.push("4");
53
- if (attr.inverse) parts.push("7");
54
- if (attr.fgRgb) {
55
- parts.push(`38;2;${attr.fgRgb[0]};${attr.fgRgb[1]};${attr.fgRgb[2]}`);
56
- } else if (attr.fg !== 7) {
57
- if (attr.fg < 8) parts.push(String(30 + attr.fg));
58
- else if (attr.fg < 16) parts.push(String(90 + attr.fg - 8));
59
- else parts.push(`38;5;${attr.fg}`);
60
- }
61
- if (attr.bgRgb) {
62
- parts.push(`48;2;${attr.bgRgb[0]};${attr.bgRgb[1]};${attr.bgRgb[2]}`);
63
- } else if (attr.bg > 0) {
64
- if (attr.bg < 8) parts.push(String(40 + attr.bg));
65
- else if (attr.bg < 16) parts.push(String(100 + attr.bg - 8));
66
- else parts.push(`48;5;${attr.bg}`);
67
- }
68
- return parts.length > 0 ? `\x1b[${parts.join(";")}m` : "";
69
- }
70
-
71
- function isWide(ch) {
72
- const code = ch.codePointAt(0);
73
- if (code < 0x1100) return false;
74
- return (
75
- (code >= 0x1100 && code <= 0x115f) ||
76
- (code >= 0x2e80 && code <= 0xa4cf && code !== 0x303f) ||
77
- (code >= 0xac00 && code <= 0xd7a3) ||
78
- (code >= 0xf900 && code <= 0xfaff) ||
79
- (code >= 0xfe10 && code <= 0xfe6f) ||
80
- (code >= 0xff01 && code <= 0xff60) ||
81
- (code >= 0xffe0 && code <= 0xffe6) ||
82
- (code >= 0x20000 && code <= 0x2fffd) ||
83
- (code >= 0x30000 && code <= 0x3fffd) ||
84
- (code >= 0x1f300 && code <= 0x1f9ff)
85
- );
86
- }
87
-
88
- function renderPane(vt, pane, focused, label, opts = {}) {
89
- const sig = paneSignature(pane, focused, label || "");
90
- if (shouldSkipPane(vt, sig, opts.force)) return;
91
- const { buffer, rows, cols, cursorRow, cursorCol } = vt.getScreen();
92
- const { top, left, width, height } = pane;
93
-
94
- let out = "";
95
- const borderColor = focused ? "\x1b[1;36m" : "\x1b[90m";
96
- const reset = "\x1b[0m";
97
-
98
- const labelText = label ? ` ${label} ` : "";
99
- const topLine = BOX.tl + labelText +
100
- BOX.h.repeat(Math.max(0, width - 2 - labelText.length)) + BOX.tr;
101
- out += moveTo(top, left) + borderColor + topLine + reset;
102
-
103
- const innerWidth = width - 2;
104
- const innerHeight = height - 2;
105
- for (let r = 0; r < innerHeight; r++) {
106
- out += moveTo(top + 1 + r, left) + borderColor + BOX.v + reset;
107
- const bufRow = r < rows ? buffer[r] : null;
108
- let lastAttr = "";
109
- let col = 0;
110
- let c = 0;
111
- while (col < innerWidth && c < (bufRow ? cols : 0)) {
112
- const cell = bufRow[c];
113
- if (cell.wideContinuation) {
114
- c++;
115
- continue;
116
- }
117
- const atCursor = focused && r === cursorRow && c === cursorCol;
118
- const w = isWide(cell.char) ? 2 : 1;
119
- if (col + w > innerWidth) break;
120
- const attr = atCursor ? { ...cell.attr, inverse: !cell.attr.inverse } : cell.attr;
121
- const ansi = attrToAnsi(attr);
122
- if (ansi !== lastAttr) {
123
- out += reset + ansi;
124
- lastAttr = ansi;
125
- }
126
- out += cell.char || " ";
127
- col += w;
128
- c++;
129
- }
130
- if (lastAttr) out += reset;
131
- if (col < innerWidth) out += " ".repeat(innerWidth - col);
132
- out += borderColor + BOX.v + reset;
133
- }
134
-
135
- const botLine = BOX.bl + BOX.h.repeat(Math.max(0, width - 2)) + BOX.br;
136
- out += moveTo(top + height - 1, left) + borderColor + botLine + reset;
137
-
138
- write(out);
139
- markPaneRendered(vt, sig);
140
- }
141
-
142
- function renderCells(cells, maxWidth, cursorCol = -1) {
143
- let out = "";
144
- let lastAttr = "";
145
- let col = 0;
146
- let c = 0;
147
- while (col < maxWidth && c < cells.length) {
148
- const cell = cells[c];
149
- if (cell.wideContinuation) {
150
- c++;
151
- continue;
152
- }
153
- const w = isWide(cell.char) ? 2 : 1;
154
- if (col + w > maxWidth) break;
155
- const atCursor = c === cursorCol;
156
- const attr = atCursor ? { ...cell.attr, inverse: !cell.attr.inverse } : cell.attr;
157
- const ansi = attrToAnsi(attr);
158
- if (ansi !== lastAttr) {
159
- out += "\x1b[0m" + ansi;
160
- lastAttr = ansi;
161
- }
162
- out += cell.char || " ";
163
- col += w;
164
- c++;
165
- }
166
- if (lastAttr) out += "\x1b[0m";
167
- if (col < maxWidth) out += " ".repeat(maxWidth - col);
168
- return out;
169
- }
170
-
171
- function renderPlainLine(text, width, color = "") {
172
- const reset = "\x1b[0m";
173
- const raw = String(text || "");
174
- const truncated = truncateVisible(raw, width);
175
- const pad = Math.max(0, width - visibleLength(truncated));
176
- return `${color}${truncated}${" ".repeat(pad)}${reset}`;
177
- }
178
-
179
- function renderInternalPane(vt, pane, focused, info = {}, opts = {}) {
180
- const extra = JSON.stringify([
181
- info.label || "", info.status || "", info.detail || "",
182
- info.input || "", info.cursor ?? "",
183
- ]);
184
- const sig = paneSignature(pane, focused, extra);
185
- if (shouldSkipPane(vt, sig, opts.force)) return;
186
- const { buffer, rows, cols } = vt.getScreen();
187
- const { top, left, width, height } = pane;
188
-
189
- let out = "";
190
- const borderColor = focused ? "\x1b[1;36m" : "\x1b[90m";
191
- const reset = "\x1b[0m";
192
- const cyan = "\x1b[36m";
193
- const gray = "\x1b[90m";
194
- const red = "\x1b[31m";
195
- const magenta = "\x1b[35m";
196
-
197
- const label = info.label || "";
198
- const labelText = label ? ` ${label} ` : "";
199
- const topLine = BOX.tl + labelText +
200
- BOX.h.repeat(Math.max(0, width - 2 - labelText.length)) + BOX.tr;
201
- out += moveTo(top, left) + borderColor + topLine + reset;
202
-
203
- const innerWidth = width - 2;
204
- const innerHeight = height - 2;
205
- const chromeRows = innerHeight >= 6 ? 3 : 0;
206
- const logHeight = Math.max(1, innerHeight - chromeRows);
207
- let lastContentRow = -1;
208
- for (let r = rows - 1; r >= 0; r--) {
209
- const line = buffer[r] || [];
210
- const hasContent = line.some((cell) => cell && !cell.wideContinuation && cell.char && cell.char !== " ");
211
- if (hasContent) {
212
- lastContentRow = r;
213
- break;
214
- }
215
- }
216
- const sourceStart = lastContentRow >= 0
217
- ? Math.max(0, lastContentRow - logHeight + 1)
218
- : Math.max(0, rows - logHeight);
219
-
220
- for (let r = 0; r < logHeight; r++) {
221
- const bufRow = buffer[sourceStart + r] || [];
222
- out += moveTo(top + 1 + r, left) + borderColor + BOX.v + reset;
223
- out += renderCells(bufRow, innerWidth);
224
- out += borderColor + BOX.v + reset;
225
- }
226
-
227
- if (chromeRows > 0) {
228
- const status = String(info.status || "ready").toLowerCase();
229
- const detail = String(info.detail || "").trim();
230
- const statusColor = status === "blocked" || status === "error" ? red : (status === "ready" || status === "idle" ? gray : cyan);
231
- const statusLabel = status === "idle" ? "ready" : status;
232
- const statusText = `ufoo · ${label || "agent"} · ${statusLabel}${detail ? ` · ${detail}` : ""}`;
233
- const input = String(info.input || "");
234
- const inputCursor = Number.isFinite(info.cursor) ? Math.max(0, Math.min(input.length, info.cursor)) : input.length;
235
- const before = input.slice(0, inputCursor);
236
- const cursorChar = inputCursor < input.length ? input[inputCursor] : " ";
237
- const after = inputCursor < input.length ? input.slice(inputCursor + 1) : "";
238
- const baseRow = top + 1 + logHeight;
239
-
240
- out += moveTo(baseRow, left) + borderColor + BOX.v + reset +
241
- renderPlainLine(statusText, innerWidth, statusColor) +
242
- borderColor + BOX.v + reset;
243
- out += moveTo(baseRow + 1, left) + borderColor + BOX.v + reset +
244
- gray + BOX.h.repeat(innerWidth) + reset +
245
- borderColor + BOX.v + reset;
246
- out += moveTo(baseRow + 2, left) + borderColor + BOX.v + reset +
247
- renderPlainLine(`${magenta}› ${reset}${before}\x1b[7m${cursorChar}${reset}${after}`, innerWidth) +
248
- borderColor + BOX.v + reset;
249
- }
250
-
251
- const botLine = BOX.bl + BOX.h.repeat(Math.max(0, width - 2)) + BOX.br;
252
- out += moveTo(top + height - 1, left) + borderColor + botLine + reset;
253
-
254
- write(out);
255
- markPaneRendered(vt, sig);
256
- }
257
-
258
- function stripControl(str) {
259
- return str.replace(/[\x00-\x08\x0a-\x1f]/g, "");
260
- }
261
-
262
- function visibleLength(str) {
263
- return str.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, "").length;
264
- }
265
-
266
- function truncateVisible(str, maxWidth) {
267
- let visible = 0;
268
- let i = 0;
269
- while (i < str.length && visible < maxWidth) {
270
- if (str[i] === "\x1b" && str[i + 1] === "[") {
271
- const start = i;
272
- i += 2;
273
- while (i < str.length && str[i] >= "\x20" && str[i] <= "\x3f") i++;
274
- if (i < str.length) i++;
275
- continue;
276
- }
277
- visible++;
278
- i++;
279
- }
280
- return str.slice(0, i);
281
- }
282
-
283
- function formatChatLogLine(raw = "", width = 80) {
284
- const row = classifyChatLogLine(stripControl(raw));
285
- const reset = "\x1b[0m";
286
- if (row.kind === "spacer") return " ".repeat(width);
287
- if (row.kind === "banner") return `\x1b[36;1m${truncateVisible(row.body, width)}${reset}`;
288
- if (row.kind === "divider") return `\x1b[90m${truncateVisible(` ${compactDividerLabel(row.body)}`, width)}${reset}`;
289
-
290
- const palette = {
291
- assistant: { marker: "\x1b[36m", speaker: "\x1b[37;1m", body: "" },
292
- agent: { marker: "\x1b[36m", speaker: "\x1b[36m", body: "" },
293
- error: { marker: "\x1b[31;1m", speaker: "\x1b[31m", body: "\x1b[31m" },
294
- success: { marker: "\x1b[32m", speaker: "\x1b[32m", body: "\x1b[32m" },
295
- meta: { marker: "\x1b[90m", speaker: "\x1b[90m", body: "\x1b[90m" },
296
- plain: { marker: "\x1b[90m", speaker: "\x1b[90m", body: "" },
297
- };
298
- const colors = palette[row.kind] || palette.plain;
299
- const speaker = row.speaker ? `${colors.speaker}${row.speaker}${reset}\x1b[90m · ${reset}` : "";
300
- const markerGlyph = row.kind === "agent" ? "●" : row.marker;
301
- const marker = markerGlyph
302
- ? `${colors.marker}${markerGlyph}${reset} `
303
- : " ";
304
- const body = row.kind === "plain"
305
- ? compactContinuationIndent(row.body || row.text || " ")
306
- : (row.body || row.text || " ");
307
- const line = `${marker}${speaker}${colors.body || ""}${body}${reset}`;
308
- return truncateVisible(line, width);
309
- }
310
-
311
- function renderChatLog(pane, lines) {
312
- const { top, left, width, height } = pane;
313
- const innerWidth = width - 1;
314
- let out = "";
315
- const dim = "\x1b[90m";
316
- const reset = "\x1b[0m";
317
-
318
- for (let r = 0; r < height; r++) {
319
- out += moveTo(top + r, left);
320
- const idx = lines.length - height + r;
321
- const raw = (idx >= 0 && idx < lines.length) ? lines[idx] || "" : "";
322
- const truncated = formatChatLogLine(raw, innerWidth);
323
- const pad = Math.max(0, innerWidth - visibleLength(truncated));
324
- out += truncated + reset + " ".repeat(pad);
325
- out += dim + BOX.v + reset;
326
- }
327
- writeIfChanged("chatlog", out, top, height);
328
- }
329
-
330
- function renderSeparator(pane, highlighted) {
331
- const { top, left, width } = pane;
332
- const reset = "\x1b[0m";
333
- const color = highlighted ? "\x1b[36m" : "\x1b[90m";
334
- writeIfChanged(`sep:${top}:${left}`, moveTo(top, left) + color + "─".repeat(width) + reset, top, 1);
335
- }
336
-
337
- function renderStatusLine(pane, text) {
338
- const { top, left, width } = pane;
339
- const reset = "\x1b[0m";
340
- const dim = "\x1b[90m";
341
- const truncated = truncateVisible(text || "", width);
342
- const pad = Math.max(0, width - visibleLength(truncated));
343
- writeIfChanged("status", moveTo(top, left) + dim + truncated + " ".repeat(pad) + reset, top, 1);
344
- }
345
-
346
- function renderDashboard(pane, lines) {
347
- const { top, left, width } = pane;
348
- const reset = "\x1b[0m";
349
- let out = "";
350
- for (let i = 0; i < lines.length; i++) {
351
- const line = lines[i] || "";
352
- const pad = Math.max(0, width - visibleLength(line));
353
- out += moveTo(top + i, left) + line + " ".repeat(pad) + reset;
354
- }
355
- writeIfChanged("dashboard", out, top, lines.length);
356
- }
357
-
358
- function renderInputPrompt(pane, prefix, draft, cursor) {
359
- const { top, left, width } = pane;
360
- const reset = "\x1b[0m";
361
- const cyan = "\x1b[36m";
362
- const inverse = "\x1b[7m";
363
- const prefixStr = prefix || "› ";
364
- const text = draft || "";
365
- const cursorPos = typeof cursor === "number" ? Math.max(0, Math.min(text.length, cursor)) : text.length;
366
- const before = text.slice(0, cursorPos);
367
- const cursorChar = cursorPos < text.length ? text[cursorPos] : " ";
368
- const after = cursorPos < text.length ? text.slice(cursorPos + 1) : "";
369
- const promptLine = cyan + prefixStr + reset + before + inverse + cursorChar + reset + after;
370
- const truncated = truncateVisible(promptLine, width);
371
- const pad = Math.max(0, width - visibleLength(truncated));
372
- writeIfChanged("input", moveTo(top, left) + truncated + " ".repeat(pad) + reset, top, 1);
373
- }
374
-
375
- function hideCursor() { write("\x1b[?25l"); }
376
- function showCursor() { write("\x1b[?25h"); }
377
- function clear() {
378
- slotCache = new Map();
379
- paneSigs = new WeakMap();
380
- write("\x1b[2J\x1b[H");
381
- }
382
-
383
- function clearRows(top, count, width, left = 0) {
384
- const rows = Math.max(0, Number(count) || 0);
385
- const cols = Math.max(0, Number(width) || 0);
386
- if (rows === 0 || cols === 0) return;
387
- // Blanked rows must be repainted on the next pass: drop every cached
388
- // slot overlapping the cleared range and reset pane signatures (kept
389
- // in a WeakMap, so they cannot be filtered selectively).
390
- for (const [slot, entry] of slotCache) {
391
- if (entry.top < top + rows && top < entry.top + entry.height) slotCache.delete(slot);
392
- }
393
- paneSigs = new WeakMap();
394
- let out = "";
395
- const blank = " ".repeat(cols);
396
- for (let i = 0; i < rows; i++) {
397
- out += moveTo(top + i, left) + blank;
398
- }
399
- write(out);
400
- }
401
-
402
- return {
403
- renderPane,
404
- renderInternalPane,
405
- renderChatLog,
406
- renderSeparator,
407
- renderStatusLine,
408
- renderDashboard,
409
- renderInputPrompt,
410
- hideCursor,
411
- showCursor,
412
- clear,
413
- clearRows,
414
- moveTo,
415
- write,
416
- visibleLength,
417
- };
418
- }
419
-
420
- module.exports = { createRenderer };