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,327 +0,0 @@
1
- const DEFAULT_ATTR = { fg: 7, bg: 0, bold: false, dim: false, italic: false, underline: false, inverse: false, fgRgb: null, bgRgb: null };
2
-
3
- function isWide(ch) {
4
- if (!ch) return false;
5
- const code = ch.codePointAt(0);
6
- if (code < 0x1100) return false;
7
- return (
8
- (code >= 0x1100 && code <= 0x115f) ||
9
- (code >= 0x2e80 && code <= 0xa4cf && code !== 0x303f) ||
10
- (code >= 0xac00 && code <= 0xd7a3) ||
11
- (code >= 0xf900 && code <= 0xfaff) ||
12
- (code >= 0xfe10 && code <= 0xfe6f) ||
13
- (code >= 0xff01 && code <= 0xff60) ||
14
- (code >= 0xffe0 && code <= 0xffe6) ||
15
- (code >= 0x20000 && code <= 0x2fffd) ||
16
- (code >= 0x30000 && code <= 0x3fffd) ||
17
- (code >= 0x1f300 && code <= 0x1f9ff)
18
- );
19
- }
20
-
21
- function cellWidth(ch) {
22
- return isWide(ch) ? 2 : 1;
23
- }
24
-
25
- function createCell(char = " ", attr = DEFAULT_ATTR, wideContinuation = false) {
26
- return { char, attr: { ...attr }, wideContinuation };
27
- }
28
-
29
- function createVirtualTerminal(cols = 80, rows = 24) {
30
- let buffer = [];
31
- let cursorRow = 0;
32
- let cursorCol = 0;
33
- let savedCursor = { row: 0, col: 0 };
34
- let currentAttr = { ...DEFAULT_ATTR };
35
- let scrollTop = 0;
36
- let scrollBottom = rows - 1;
37
- let dirty = true;
38
-
39
- function initBuffer() {
40
- buffer = [];
41
- for (let r = 0; r < rows; r++) {
42
- buffer.push(createRow(cols));
43
- }
44
- }
45
-
46
- function createRow(width) {
47
- const row = [];
48
- for (let c = 0; c < width; c++) {
49
- row.push(createCell());
50
- }
51
- return row;
52
- }
53
-
54
- function clamp() {
55
- if (cursorRow < 0) cursorRow = 0;
56
- if (cursorRow >= rows) cursorRow = rows - 1;
57
- if (cursorCol < 0) cursorCol = 0;
58
- if (cursorCol >= cols) cursorCol = cols - 1;
59
- }
60
-
61
- function scrollUp(top = scrollTop, bottom = scrollBottom) {
62
- buffer.splice(top, 1);
63
- buffer.splice(bottom, 0, createRow(cols));
64
- dirty = true;
65
- }
66
-
67
- function scrollDown(top = scrollTop, bottom = scrollBottom) {
68
- buffer.splice(bottom, 1);
69
- buffer.splice(top, 0, createRow(cols));
70
- dirty = true;
71
- }
72
-
73
- function clearWideAt(row, col) {
74
- const line = buffer[row];
75
- if (!line || col < 0 || col >= cols) return;
76
- if (line[col]?.wideContinuation && col > 0) {
77
- line[col - 1] = createCell();
78
- line[col] = createCell();
79
- } else if (isWide(line[col]?.char) && col + 1 < cols && line[col + 1]?.wideContinuation) {
80
- line[col] = createCell();
81
- line[col + 1] = createCell();
82
- }
83
- }
84
-
85
- function putChar(ch) {
86
- const width = cellWidth(ch);
87
- if (cursorCol >= cols || (width === 2 && cursorCol >= cols - 1)) {
88
- cursorCol = 0;
89
- cursorRow++;
90
- if (cursorRow > scrollBottom) {
91
- cursorRow = scrollBottom;
92
- scrollUp();
93
- }
94
- }
95
- if (buffer[cursorRow]) {
96
- clearWideAt(cursorRow, cursorCol);
97
- if (width === 2) clearWideAt(cursorRow, cursorCol + 1);
98
- buffer[cursorRow][cursorCol] = createCell(ch, currentAttr);
99
- if (width === 2 && cursorCol + 1 < cols) {
100
- buffer[cursorRow][cursorCol + 1] = createCell("", currentAttr, true);
101
- }
102
- }
103
- cursorCol += width;
104
- dirty = true;
105
- }
106
-
107
- function eraseLine(mode, row) {
108
- if (!buffer[row]) return;
109
- if (mode === 0) {
110
- for (let c = cursorCol; c < cols; c++) buffer[row][c] = createCell();
111
- } else if (mode === 1) {
112
- for (let c = 0; c <= cursorCol; c++) buffer[row][c] = createCell();
113
- } else {
114
- for (let c = 0; c < cols; c++) buffer[row][c] = createCell();
115
- }
116
- dirty = true;
117
- }
118
-
119
- function eraseDisplay(mode) {
120
- if (mode === 0) {
121
- eraseLine(0, cursorRow);
122
- for (let r = cursorRow + 1; r < rows; r++) buffer[r] = createRow(cols);
123
- } else if (mode === 1) {
124
- for (let r = 0; r < cursorRow; r++) buffer[r] = createRow(cols);
125
- eraseLine(1, cursorRow);
126
- } else {
127
- for (let r = 0; r < rows; r++) buffer[r] = createRow(cols);
128
- cursorRow = 0;
129
- cursorCol = 0;
130
- }
131
- dirty = true;
132
- }
133
-
134
- function applySGR(params) {
135
- for (let i = 0; i < params.length; i++) {
136
- const p = params[i];
137
- if (p === 0) { Object.assign(currentAttr, DEFAULT_ATTR); }
138
- else if (p === 1) { currentAttr.bold = true; }
139
- else if (p === 2) { currentAttr.dim = true; }
140
- else if (p === 3) { currentAttr.italic = true; }
141
- else if (p === 4) { currentAttr.underline = true; }
142
- else if (p === 7) { currentAttr.inverse = true; }
143
- else if (p === 22) { currentAttr.bold = false; currentAttr.dim = false; }
144
- else if (p === 23) { currentAttr.italic = false; }
145
- else if (p === 24) { currentAttr.underline = false; }
146
- else if (p === 27) { currentAttr.inverse = false; }
147
- else if (p >= 30 && p <= 37) { currentAttr.fg = p - 30; currentAttr.fgRgb = null; }
148
- else if (p === 38) {
149
- if (params[i + 1] === 5) { currentAttr.fg = params[i + 2] || 0; currentAttr.fgRgb = null; i += 2; }
150
- else if (params[i + 1] === 2) { currentAttr.fgRgb = [params[i + 2] || 0, params[i + 3] || 0, params[i + 4] || 0]; i += 4; }
151
- }
152
- else if (p === 39) { currentAttr.fg = 7; currentAttr.fgRgb = null; }
153
- else if (p >= 40 && p <= 47) { currentAttr.bg = p - 40; currentAttr.bgRgb = null; }
154
- else if (p === 48) {
155
- if (params[i + 1] === 5) { currentAttr.bg = params[i + 2] || 0; currentAttr.bgRgb = null; i += 2; }
156
- else if (params[i + 1] === 2) { currentAttr.bgRgb = [params[i + 2] || 0, params[i + 3] || 0, params[i + 4] || 0]; i += 4; }
157
- }
158
- else if (p === 49) { currentAttr.bg = 0; currentAttr.bgRgb = null; }
159
- else if (p >= 90 && p <= 97) { currentAttr.fg = p - 90 + 8; currentAttr.fgRgb = null; }
160
- else if (p >= 100 && p <= 107) { currentAttr.bg = p - 100 + 8; currentAttr.bgRgb = null; }
161
- }
162
- dirty = true;
163
- }
164
-
165
- function handleCSI(params, code) {
166
- const p = params.length > 0 ? params : [0];
167
- switch (code) {
168
- case "A": cursorRow -= (p[0] || 1); break;
169
- case "B": cursorRow += (p[0] || 1); break;
170
- case "C": cursorCol += (p[0] || 1); break;
171
- case "D": cursorCol -= (p[0] || 1); break;
172
- case "E": cursorRow += (p[0] || 1); cursorCol = 0; break;
173
- case "F": cursorRow -= (p[0] || 1); cursorCol = 0; break;
174
- case "G": cursorCol = (p[0] || 1) - 1; break;
175
- case "H": case "f":
176
- cursorRow = (p[0] || 1) - 1;
177
- cursorCol = (p.length > 1 ? (p[1] || 1) : 1) - 1;
178
- break;
179
- case "J": eraseDisplay(p[0] || 0); break;
180
- case "K": eraseLine(p[0] || 0, cursorRow); break;
181
- case "L": {
182
- const n = p[0] || 1;
183
- for (let i = 0; i < n; i++) scrollDown(cursorRow, scrollBottom);
184
- break;
185
- }
186
- case "M": {
187
- const n = p[0] || 1;
188
- for (let i = 0; i < n; i++) scrollUp(cursorRow, scrollBottom);
189
- break;
190
- }
191
- case "S": { const n = p[0] || 1; for (let i = 0; i < n; i++) scrollUp(); break; }
192
- case "T": { const n = p[0] || 1; for (let i = 0; i < n; i++) scrollDown(); break; }
193
- case "d": cursorRow = (p[0] || 1) - 1; break;
194
- case "m": applySGR(p); break;
195
- case "r":
196
- scrollTop = (p[0] || 1) - 1;
197
- scrollBottom = (p.length > 1 ? (p[1] || rows) : rows) - 1;
198
- cursorRow = 0; cursorCol = 0;
199
- break;
200
- case "s": savedCursor = { row: cursorRow, col: cursorCol }; break;
201
- case "u": cursorRow = savedCursor.row; cursorCol = savedCursor.col; break;
202
- }
203
- clamp();
204
- dirty = true;
205
- }
206
- function write(data) {
207
- const str = typeof data === "string" ? data : data.toString("utf8");
208
- let i = 0;
209
- while (i < str.length) {
210
- const ch = str[i];
211
- if (ch === "\x1b") {
212
- if (str[i + 1] === "[") {
213
- i += 2;
214
- let paramStr = "";
215
- while (i < str.length && str[i] >= "\x20" && str[i] <= "\x3f") {
216
- paramStr += str[i++];
217
- }
218
- const code = str[i++] || "";
219
- const params = paramStr ? paramStr.split(";").map(Number) : [];
220
- handleCSI(params, code);
221
- } else if (str[i + 1] === "7") {
222
- savedCursor = { row: cursorRow, col: cursorCol };
223
- i += 2;
224
- } else if (str[i + 1] === "8") {
225
- cursorRow = savedCursor.row;
226
- cursorCol = savedCursor.col;
227
- i += 2;
228
- } else if (str[i + 1] === "M") {
229
- scrollUp();
230
- i += 2;
231
- } else if (str[i + 1] === "D") {
232
- cursorRow++;
233
- if (cursorRow > scrollBottom) {
234
- cursorRow = scrollBottom;
235
- scrollUp();
236
- }
237
- i += 2;
238
- } else if (str[i + 1] === "]" || str[i + 1] === "P" || str[i + 1] === "_") {
239
- i += 2;
240
- while (i < str.length) {
241
- if (str[i] === "\x07") { i++; break; }
242
- if (str[i] === "\x1b" && str[i + 1] === "\\") { i += 2; break; }
243
- i++;
244
- }
245
- } else {
246
- i += 2;
247
- }
248
- } else if (ch === "\r") {
249
- cursorCol = 0;
250
- i++;
251
- } else if (ch === "\n") {
252
- cursorRow++;
253
- if (cursorRow > scrollBottom) {
254
- cursorRow = scrollBottom;
255
- scrollUp();
256
- }
257
- i++;
258
- } else if (ch === "\b") {
259
- if (cursorCol > 0) cursorCol--;
260
- i++;
261
- } else if (ch === "\t") {
262
- cursorCol = Math.min(cols - 1, (Math.floor(cursorCol / 8) + 1) * 8);
263
- i++;
264
- } else if (ch.charCodeAt(0) < 32) {
265
- i++;
266
- } else {
267
- const glyph = Array.from(str.slice(i))[0] || ch;
268
- putChar(glyph);
269
- i += glyph.length;
270
- }
271
- }
272
- }
273
-
274
- function getScreen() {
275
- return { buffer, rows, cols, cursorRow, cursorCol };
276
- }
277
-
278
- function getLine(row) {
279
- if (row < 0 || row >= rows) return "";
280
- return buffer[row].map((c) => c.char).join("");
281
- }
282
-
283
- function getCursor() {
284
- return { row: cursorRow, col: cursorCol };
285
- }
286
-
287
- function isDirty() {
288
- return dirty;
289
- }
290
-
291
- function clearDirty() {
292
- dirty = false;
293
- }
294
-
295
- function resize(newCols, newRows) {
296
- const oldBuffer = buffer;
297
- const oldRows = rows;
298
- cols = newCols;
299
- rows = newRows;
300
- scrollTop = 0;
301
- scrollBottom = rows - 1;
302
- initBuffer();
303
- const copyRows = Math.min(oldRows, rows);
304
- for (let r = 0; r < copyRows; r++) {
305
- const copyLen = Math.min(oldBuffer[r].length, cols);
306
- for (let c = 0; c < copyLen; c++) {
307
- buffer[r][c] = oldBuffer[r][c];
308
- }
309
- }
310
- clamp();
311
- dirty = true;
312
- }
313
-
314
- initBuffer();
315
-
316
- return {
317
- write,
318
- getScreen,
319
- getLine,
320
- getCursor,
321
- isDirty,
322
- clearDirty,
323
- resize,
324
- };
325
- }
326
-
327
- module.exports = { createVirtualTerminal, DEFAULT_ATTR };
@@ -1,93 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Convert a virtual-terminal screen into ANSI-styled text lines suitable for
5
- * shipping over `multi.pane.frame`. Rust decodes these with `ansi-to-tui`.
6
- *
7
- * The colour/attribute-to-ANSI logic mirrors renderer.js so the rendered
8
- * frame matches the Ink multi-window presentation.
9
- */
10
-
11
- const MAX_LINE_BYTES = 4096;
12
-
13
- function attrToAnsi(attr) {
14
- const parts = [];
15
- if (attr.bold) parts.push("1");
16
- if (attr.dim) parts.push("2");
17
- if (attr.italic) parts.push("3");
18
- if (attr.underline) parts.push("4");
19
- if (attr.inverse) parts.push("7");
20
- if (attr.fgRgb) {
21
- parts.push(`38;2;${attr.fgRgb[0]};${attr.fgRgb[1]};${attr.fgRgb[2]}`);
22
- } else if (attr.fg !== 7) {
23
- if (attr.fg < 8) parts.push(String(30 + attr.fg));
24
- else if (attr.fg < 16) parts.push(String(90 + attr.fg - 8));
25
- else parts.push(`38;5;${attr.fg}`);
26
- }
27
- if (attr.bgRgb) {
28
- parts.push(`48;2;${attr.bgRgb[0]};${attr.bgRgb[1]};${attr.bgRgb[2]}`);
29
- } else if (attr.bg > 0) {
30
- if (attr.bg < 8) parts.push(String(40 + attr.bg));
31
- else if (attr.bg < 16) parts.push(String(100 + attr.bg - 8));
32
- else parts.push(`48;5;${attr.bg}`);
33
- }
34
- return parts.length > 0 ? `\x1b[${parts.join(";")}m` : "";
35
- }
36
-
37
- function truncateLineBytes(line, maxBytes) {
38
- if (!line) return "";
39
- if (Buffer.byteLength(line, "utf8") <= maxBytes) return line;
40
- const buf = Buffer.from(line, "utf8");
41
- return buf.slice(0, maxBytes).toString("utf8");
42
- }
43
-
44
- function vtScreenToAnsiLines(vt, options = {}) {
45
- if (!vt || typeof vt.getScreen !== "function") return [];
46
- const { buffer, rows, cols, cursorRow, cursorCol } = vt.getScreen();
47
- const maxRows = Number.isFinite(options.maxRows) && options.maxRows > 0
48
- ? Math.floor(options.maxRows)
49
- : rows;
50
- const maxCols = Number.isFinite(options.maxCols) && options.maxCols > 0
51
- ? Math.floor(options.maxCols)
52
- : cols;
53
- const cursorInverse = Boolean(options.cursorInverse);
54
- const reset = "\x1b[0m";
55
- const limit = Math.min(rows, maxRows);
56
- const out = [];
57
- for (let r = 0; r < limit; r++) {
58
- const row = buffer[r] || [];
59
- let line = "";
60
- let lastAttr = "";
61
- let col = 0;
62
- let c = 0;
63
- while (col < maxCols && c < cols) {
64
- const cell = row[c];
65
- if (!cell) {
66
- line += " ";
67
- col += 1;
68
- c += 1;
69
- continue;
70
- }
71
- if (cell.wideContinuation) {
72
- c += 1;
73
- continue;
74
- }
75
- const isCursor = cursorInverse && r === cursorRow && c === cursorCol;
76
- const attr = isCursor ? { ...cell.attr, inverse: !cell.attr.inverse } : cell.attr;
77
- const ansi = attrToAnsi(attr);
78
- if (ansi !== lastAttr) {
79
- if (lastAttr) line += reset;
80
- line += ansi;
81
- lastAttr = ansi;
82
- }
83
- line += cell.char || " ";
84
- col += 1;
85
- c += 1;
86
- }
87
- if (lastAttr) line += reset;
88
- out.push(truncateLineBytes(line, MAX_LINE_BYTES));
89
- }
90
- return out;
91
- }
92
-
93
- module.exports = { vtScreenToAnsiLines, MAX_LINE_BYTES };
@@ -1,232 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Multi-window handoff after Rust TUI suspend (exit 75, reason=multi).
5
- * Reuses createMultiWindowController (same VT/pane code as Ink).
6
- */
7
-
8
- const { createMultiWindowController } = require("../app/chat/multiWindow");
9
- const { resolveAgentEnterRequest, resolveInjectSockPathForAgent } = require("../app/chat/agentEnter");
10
- const { restoreStdinAfterHandoff } = require("./ptyHandoff");
11
-
12
- function agentIdsFromMeta(activeAgentMeta) {
13
- if (activeAgentMeta instanceof Map) {
14
- return Array.from(activeAgentMeta.keys()).map(String).filter(Boolean);
15
- }
16
- if (activeAgentMeta && typeof activeAgentMeta === "object") {
17
- return Object.keys(activeAgentMeta);
18
- }
19
- return [];
20
- }
21
-
22
- function labelForAgent(activeAgentMeta, agentId) {
23
- const meta = activeAgentMeta instanceof Map
24
- ? activeAgentMeta.get(agentId)
25
- : (activeAgentMeta && activeAgentMeta[agentId]);
26
- if (!meta || typeof meta !== "object") return agentId;
27
- return String(meta.display_nickname || meta.nickname || meta.scoped_nickname || agentId);
28
- }
29
-
30
- /**
31
- * @returns {Promise<{ ok: boolean, error?: string }>}
32
- */
33
- async function runMultiWindowHandoff({
34
- projectRoot = process.cwd(),
35
- activeAgentMeta = new Map(),
36
- settings = {},
37
- getChatLogLines = () => [],
38
- getStatusText = () => "",
39
- getDashboardLines = () => [],
40
- onInternalSubmit = null,
41
- stdin = process.stdin,
42
- stdout = process.stdout,
43
- } = {}) {
44
- const agents = agentIdsFromMeta(activeAgentMeta);
45
- if (agents.length === 0) {
46
- return { ok: false, error: "No active agents for multi-window mode" };
47
- }
48
-
49
- let terminalFocused = false;
50
- let done = false;
51
- let resolveDone = null;
52
- const finished = new Promise((resolve) => {
53
- resolveDone = resolve;
54
- });
55
-
56
- const originalWrite = stdout.write.bind(stdout);
57
- const controller = createMultiWindowController({
58
- processStdout: {
59
- write: originalWrite,
60
- rows: stdout.rows,
61
- columns: stdout.columns,
62
- },
63
- getRows: () => stdout.rows || 24,
64
- getCols: () => stdout.columns || 80,
65
- getInjectSockPath: (agentId) => resolveInjectSockPathForAgent(projectRoot, agentId),
66
- getActiveAgents: () => agentIdsFromMeta(activeAgentMeta),
67
- getAgentPaneOptions: (agentId) => {
68
- const enterRequest = resolveAgentEnterRequest({
69
- agentId,
70
- projectRoot,
71
- activeAgentMeta,
72
- settings,
73
- });
74
- if (!enterRequest || !enterRequest.useBus) return { mode: "socket" };
75
- let initialLines = [];
76
- try {
77
- const { loadInternalAgentLogHistory } = require("../app/chat/internalAgentLogHistory");
78
- initialLines = loadInternalAgentLogHistory(projectRoot, agentId, {
79
- maxEvents: 200,
80
- maxLines: 200,
81
- });
82
- } catch {
83
- initialLines = [];
84
- }
85
- return {
86
- mode: "internal",
87
- initialLines: [
88
- `ufoo internal agent · ${labelForAgent(activeAgentMeta, agentId)}`,
89
- `agent: ${agentId}`,
90
- "",
91
- ...initialLines,
92
- ],
93
- };
94
- },
95
- getChatLogLines,
96
- getStatusText,
97
- getPromptPrefix: () => "› ",
98
- getCurrentDraft: () => "",
99
- getCursorPos: () => 0,
100
- getCompletions: () => ({ items: [], index: -1, windowStart: 0, pageSize: 8 }),
101
- getAgentLabel: (id) => labelForAgent(activeAgentMeta, id),
102
- getInternalPaneInfo: (id) => {
103
- const meta = activeAgentMeta instanceof Map
104
- ? activeAgentMeta.get(id)
105
- : (activeAgentMeta && activeAgentMeta[id]);
106
- return {
107
- status: String((meta && meta.activity_state) || ""),
108
- detail: String((meta && meta.activity_detail) || ""),
109
- input: "",
110
- cursor: 0,
111
- };
112
- },
113
- getDashboardLines,
114
- getTerminalFocused: () => terminalFocused,
115
- freezeScreen: (frozen) => {
116
- if (frozen) stdout.write = () => true;
117
- else stdout.write = originalWrite;
118
- },
119
- restoreTerminal: () => {
120
- const rows = stdout.rows || 24;
121
- originalWrite(`\x1b[1;${rows}r`);
122
- originalWrite("\x1b[2J\x1b[H");
123
- },
124
- onInternalSubmit: (agentId, message) => {
125
- if (typeof onInternalSubmit === "function") {
126
- onInternalSubmit(agentId, message);
127
- }
128
- },
129
- onExit: () => {
130
- done = true;
131
- if (typeof resolveDone === "function") resolveDone();
132
- },
133
- });
134
-
135
- if (!controller.enter()) {
136
- return { ok: false, error: "No active agents for multi-window mode" };
137
- }
138
-
139
- const wasRaw = typeof stdin.isRaw === "boolean" ? stdin.isRaw : false;
140
- try {
141
- if (typeof stdin.setRawMode === "function" && stdin.isTTY) {
142
- stdin.setRawMode(true);
143
- }
144
- if (typeof stdin.resume === "function") stdin.resume();
145
- } catch {
146
- // ignore
147
- }
148
-
149
- const onResize = () => {
150
- try {
151
- controller.handleResize();
152
- } catch {
153
- // ignore
154
- }
155
- };
156
- if (stdout && typeof stdout.on === "function") {
157
- stdout.on("resize", onResize);
158
- }
159
-
160
- const onData = (chunk) => {
161
- if (done) return;
162
- const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk || ""), "utf8");
163
- if (buf.length === 0) return;
164
-
165
- // Ctrl+C → exit multi
166
- if (buf.includes(0x03)) {
167
- controller.exit();
168
- return;
169
- }
170
- // Ctrl+Q → exit multi
171
- if (buf.includes(0x11)) {
172
- controller.handleKey({ name: "q", ctrl: true, sequence: "" });
173
- terminalFocused = false;
174
- return;
175
- }
176
- // Ctrl+W → cycle focus (chat chrome ↔ agent panes)
177
- if (buf.includes(0x17)) {
178
- const ids = controller.getAgentIds();
179
- if (ids.length === 0) return;
180
- if (!terminalFocused) {
181
- controller.focusAgent(ids[0]);
182
- terminalFocused = true;
183
- } else {
184
- const current = controller.getFocused();
185
- const idx = current ? ids.indexOf(current) : -1;
186
- if (idx >= 0 && idx < ids.length - 1) {
187
- controller.focusAgent(ids[idx + 1]);
188
- } else {
189
- terminalFocused = false;
190
- controller.focusAgent(ids[0]);
191
- }
192
- }
193
- controller.renderAll();
194
- return;
195
- }
196
-
197
- if (terminalFocused) {
198
- controller.sendInput(buf.toString("utf8"));
199
- }
200
- };
201
-
202
- stdin.on("data", onData);
203
-
204
- try {
205
- await finished;
206
- return { ok: true };
207
- } finally {
208
- stdin.removeListener("data", onData);
209
- if (stdout && typeof stdout.off === "function") {
210
- stdout.off("resize", onResize);
211
- } else if (stdout && typeof stdout.removeListener === "function") {
212
- stdout.removeListener("resize", onResize);
213
- }
214
- try {
215
- if (controller.isActive()) controller.exit();
216
- } catch {
217
- // ignore
218
- }
219
- try {
220
- if (typeof stdin.setRawMode === "function" && stdin.isTTY) {
221
- stdin.setRawMode(wasRaw);
222
- }
223
- } catch {
224
- // ignore
225
- }
226
- restoreStdinAfterHandoff(stdin);
227
- }
228
- }
229
-
230
- module.exports = {
231
- runMultiWindowHandoff,
232
- };
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Stdin restore helpers after any fullscreen handoff (e.g. legacy multi).
5
- * Agent PTY mirror handoff has been removed — activate / side / multi only.
6
- */
7
-
8
- function restoreStdinAfterHandoff(stdin = process.stdin) {
9
- try {
10
- if (stdin && typeof stdin.setRawMode === "function" && stdin.isTTY) {
11
- stdin.setRawMode(false);
12
- }
13
- if (stdin && typeof stdin.resume === "function") {
14
- stdin.resume();
15
- }
16
- } catch {
17
- // ignore — next TUI will reconfigure
18
- }
19
- }
20
-
21
- module.exports = {
22
- restoreStdinAfterHandoff,
23
- };