u-foo 3.1.7 → 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 -2667
  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
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Agent enter / dashboard navigation helpers (Phase 0B extraction).
5
- */
6
-
7
- const path = require("path");
8
-
9
- function resolveInjectSockPathForAgent(projectRoot, agentId) {
10
- const { getUfooPaths } = require("../../coordination/state/paths");
11
- const { subscriberToSafeName } = require("../../coordination/bus/utils");
12
- const safeName = subscriberToSafeName(agentId);
13
- return path.join(getUfooPaths(projectRoot || process.cwd()).busQueuesDir, safeName, "inject.sock");
14
- }
15
-
16
- function resolveAgentEnterRequest({
17
- agentId,
18
- projectRoot = "",
19
- activeAgentMeta = new Map(),
20
- settings = {},
21
- } = {}) {
22
- const id = String(agentId || "").trim();
23
- if (!id) return null;
24
-
25
- const metaMap = activeAgentMeta instanceof Map ? activeAgentMeta : new Map();
26
- const meta = metaMap.get(id) || {};
27
- const configuredLaunchMode = settings && settings.launchMode && settings.launchMode !== "auto"
28
- ? settings.launchMode
29
- : "";
30
- const launchMode = String(meta.launch_mode || meta.launchMode || configuredLaunchMode || "").trim();
31
- const { createTerminalAdapterRouter } = require("../../runtime/terminal/adapterRouter");
32
- const adapter = createTerminalAdapterRouter().getAdapter({ launchMode, agentId: id, meta });
33
- const caps = adapter && adapter.capabilities ? adapter.capabilities : {};
34
-
35
- return {
36
- agentId: id,
37
- projectRoot: String(projectRoot || ""),
38
- launchMode,
39
- useBus: Boolean(caps.supportsInternalQueueLoop && !caps.supportsSocketProtocol),
40
- supportsSocket: Boolean(caps.supportsSocketProtocol),
41
- supportsInternalQueue: Boolean(caps.supportsInternalQueueLoop),
42
- supportsActivate: Boolean(caps.supportsActivate),
43
- };
44
- }
45
-
46
- function resolveDashboardAgentEnterAction(enterRequest = {}) {
47
- if (!enterRequest || typeof enterRequest !== "object") return "none";
48
- if (enterRequest.useBus) return "internal";
49
- if (enterRequest.supportsActivate) return "activate";
50
- // No PTY mirror fallback — host must expose activate (or use terminal/tmux/internal).
51
- return "none";
52
- }
53
-
54
- function buildEmptyProjectsDownActions(state = {}, displayAgents = []) {
55
- if (!state.emptyProjectsDownArmed) {
56
- return [{ type: "projects/armEmptyDown" }];
57
- }
58
- const actions = [{ type: "view/set", view: "agents" }];
59
- if (displayAgents.length > 0 && state.selectedAgentIndex < 0) {
60
- actions.push({ type: "agents/select", index: 0 });
61
- }
62
- return actions;
63
- }
64
-
65
- module.exports = {
66
- resolveInjectSockPathForAgent,
67
- resolveAgentEnterRequest,
68
- resolveDashboardAgentEnterAction,
69
- buildEmptyProjectsDownActions,
70
- };
@@ -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 };
@@ -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 };