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,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,42 +0,0 @@
1
- function keyToRaw(ch, key) {
2
- if (ch && ch.length === 1) return ch;
3
- if (!key) return null;
4
-
5
- switch (key.name) {
6
- case "return":
7
- case "enter":
8
- return "\r";
9
- case "backspace":
10
- return "\x7f";
11
- case "tab":
12
- return "\t";
13
- case "escape":
14
- return "\x1b";
15
- case "up":
16
- return "\x1b[A";
17
- case "down":
18
- return "\x1b[B";
19
- case "right":
20
- return "\x1b[C";
21
- case "left":
22
- return "\x1b[D";
23
- case "home":
24
- return "\x1b[H";
25
- case "end":
26
- return "\x1b[F";
27
- case "pageup":
28
- return "\x1b[5~";
29
- case "pagedown":
30
- return "\x1b[6~";
31
- case "delete":
32
- return "\x1b[3~";
33
- case "insert":
34
- return "\x1b[2~";
35
- default:
36
- return ch || null;
37
- }
38
- }
39
-
40
- module.exports = {
41
- keyToRaw,
42
- };
@@ -1,111 +0,0 @@
1
- const path = require("path");
2
-
3
- function createSettingsController(options = {}) {
4
- const {
5
- projectRoot,
6
- saveConfig = () => {},
7
- normalizeLaunchMode = (value) => value,
8
- normalizeAgentProvider = (value) => value,
9
- fsModule,
10
- getUfooPaths = () => ({ agentDir: "" }),
11
- logMessage = () => {},
12
- resolveStatusLine = null,
13
- renderDashboard = () => {},
14
- renderScreen = () => {},
15
- restartDaemon = () => {},
16
- getLaunchMode = () => "terminal",
17
- setLaunchModeState = () => {},
18
- setSelectedModeIndex = () => {},
19
- getAgentProvider = () => "codex-cli",
20
- setAgentProviderState = () => {},
21
- setSelectedProviderIndex = () => {},
22
- providerOptions = [],
23
- modeOptions = [],
24
- getAutoResume = () => true,
25
- setAutoResumeState = () => {},
26
- setSelectedResumeIndex = () => {},
27
- } = options;
28
-
29
- if (!projectRoot) {
30
- throw new Error("createSettingsController requires projectRoot");
31
- }
32
- if (!fsModule) {
33
- throw new Error("createSettingsController requires fsModule");
34
- }
35
-
36
- function providerLabel(value) {
37
- return value === "claude-cli" ? "claude" : "codex";
38
- }
39
-
40
- function clearUfooAgentIdentity() {
41
- const agentDir = getUfooPaths(projectRoot).agentDir;
42
- const stateFile = path.join(agentDir, "ufoo-agent.json");
43
- const historyFile = path.join(agentDir, "ufoo-agent.history.jsonl");
44
- try {
45
- fsModule.rmSync(stateFile, { force: true });
46
- } catch {
47
- // Ignore cleanup failures.
48
- }
49
- try {
50
- fsModule.rmSync(historyFile, { force: true });
51
- } catch {
52
- // Ignore cleanup failures.
53
- }
54
- }
55
-
56
- function setLaunchMode(mode) {
57
- const next = normalizeLaunchMode(mode);
58
- if (next === getLaunchMode()) return false;
59
- setLaunchModeState(next);
60
- const nextIndex = modeOptions.findIndex((opt) => opt === next);
61
- setSelectedModeIndex(nextIndex >= 0 ? nextIndex : 0);
62
- saveConfig(projectRoot, { launchMode: next });
63
- const statusMsg = resolveStatusLine || ((text) => logMessage("status", text));
64
- statusMsg(`{gray-fg}⚙{/gray-fg} Launch mode: ${next}`);
65
- renderDashboard();
66
- renderScreen();
67
- void restartDaemon();
68
- return true;
69
- }
70
-
71
- function setAgentProvider(provider) {
72
- const next = normalizeAgentProvider(provider);
73
- if (next === getAgentProvider()) return false;
74
- setAgentProviderState(next);
75
- setSelectedProviderIndex(Math.max(0, providerOptions.findIndex((opt) => opt.value === next)));
76
- saveConfig(projectRoot, { agentProvider: next });
77
- clearUfooAgentIdentity();
78
- const statusMsg = resolveStatusLine || ((text) => logMessage("status", text));
79
- statusMsg(`{gray-fg}⚙{/gray-fg} ufoo-agent: ${providerLabel(next)}`);
80
- renderDashboard();
81
- renderScreen();
82
- void restartDaemon();
83
- return true;
84
- }
85
-
86
- function setAutoResume(value) {
87
- const next = value !== false;
88
- if (next === getAutoResume()) return false;
89
- setAutoResumeState(next);
90
- setSelectedResumeIndex(next ? 0 : 1);
91
- saveConfig(projectRoot, { autoResume: next });
92
- const label = next ? "Resume previous session" : "Start new session";
93
- const statusMsg = resolveStatusLine || ((text) => logMessage("status", text));
94
- statusMsg(`{gray-fg}⚙{/gray-fg} Resume mode: ${label}`);
95
- renderDashboard();
96
- renderScreen();
97
- return true;
98
- }
99
-
100
- return {
101
- providerLabel,
102
- clearUfooAgentIdentity,
103
- setLaunchMode,
104
- setAgentProvider,
105
- setAutoResume,
106
- };
107
- }
108
-
109
- module.exports = {
110
- createSettingsController,
111
- };