u-foo 3.1.6 → 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 -2668
  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,11 +1,8 @@
1
- const fs = require("fs");
2
- const net = require("net");
3
- const { PTY_SOCKET_MESSAGE_TYPES, PTY_SOCKET_SUBSCRIBE_MODES } = require("../../../runtime/contracts/ptySocketContract");
4
- const { createVirtualTerminal } = require("./virtualTerminal");
1
+ const { moveCursorVertically, deleteWordBeforeCursor, charDisplayWidth } = require("../../../ui/format");
2
+ const { createAgentSurface } = require("../../../ui/agentSurface");
5
3
 
6
4
  function createPaneManager(options = {}) {
7
5
  const {
8
- getInjectSockPath = () => "",
9
6
  onPaneOutput = () => {},
10
7
  onInternalSubmit = () => {},
11
8
  } = options;
@@ -15,35 +12,32 @@ function createPaneManager(options = {}) {
15
12
 
16
13
  function addAgent(agentId, cols, rows, options = {}) {
17
14
  if (panes.has(agentId)) return;
18
- const vt = createVirtualTerminal(cols, rows);
19
- const mode = options.mode === "internal" ? "internal" : "socket";
15
+ if (options.mode && options.mode !== "internal") throw new Error("Dashboard panes support internal agents only");
16
+ const mode = "internal";
17
+ const surface = options.surface || createAgentSurface();
20
18
  const pane = {
21
19
  agentId,
22
20
  mode,
23
- vt,
24
- outputClient: null,
25
- inputClient: null,
26
- buffer: "",
27
- internalInput: "",
28
- internalCursor: 0,
21
+ surface,
22
+ cols,
23
+ inputCols: cols,
24
+ rows,
25
+ scrollOffset: Number(options.scrollOffset) || 0,
26
+ internalInput: String(options.initialInput || ""),
27
+ internalCursor: Math.max(0, Math.min(String(options.initialInput || "").length, Number(options.initialCursor) || 0)),
29
28
  };
30
29
  panes.set(agentId, pane);
31
- if (mode === "internal") {
32
- const initialOutput = Array.isArray(options.initialLines)
33
- ? options.initialLines.join("\r\n")
34
- : String(options.initialOutput || "");
35
- if (initialOutput) pane.vt.write(`${initialOutput}\r\n`);
36
- onPaneOutput(pane.agentId);
37
- } else {
38
- connectOutput(pane);
39
- }
30
+ const initialOutput = Array.isArray(options.initialLines)
31
+ ? options.initialLines.join("\r\n")
32
+ : String(options.initialOutput || "");
33
+ if (initialOutput && !options.surface) surface.apply("transcript.append", { kind: "system", text: initialOutput });
34
+ onPaneOutput(pane.agentId);
40
35
  if (!focusedAgent) focusedAgent = agentId;
41
36
  }
42
37
 
43
38
  function removeAgent(agentId) {
44
39
  const pane = panes.get(agentId);
45
40
  if (!pane) return;
46
- disconnect(pane);
47
41
  panes.delete(agentId);
48
42
  if (focusedAgent === agentId) {
49
43
  const keys = [...panes.keys()];
@@ -51,92 +45,6 @@ function createPaneManager(options = {}) {
51
45
  }
52
46
  }
53
47
 
54
- function connectOutput(pane) {
55
- const sockPath = getInjectSockPath(pane.agentId);
56
- if (!sockPath || !fs.existsSync(sockPath)) {
57
- pane.vt.write("\x1b[33m[waiting]\x1b[0m inject.sock not found\r\n");
58
- onPaneOutput(pane.agentId);
59
- return;
60
- }
61
-
62
- try {
63
- const client = net.createConnection(sockPath, () => {
64
- const { cols, rows } = pane.vt.getScreen();
65
- client.write(JSON.stringify({
66
- type: PTY_SOCKET_MESSAGE_TYPES.RESIZE,
67
- cols,
68
- rows,
69
- }) + "\n");
70
- client.write(JSON.stringify({
71
- type: PTY_SOCKET_MESSAGE_TYPES.SUBSCRIBE,
72
- mode: PTY_SOCKET_SUBSCRIBE_MODES.FULL,
73
- }) + "\n");
74
- });
75
-
76
- client.on("data", (data) => {
77
- pane.buffer += data.toString("utf8");
78
- const lines = pane.buffer.split("\n");
79
- pane.buffer = lines.pop() || "";
80
- for (const line of lines) {
81
- if (!line.trim()) continue;
82
- try {
83
- const msg = JSON.parse(line);
84
- if (msg.type === PTY_SOCKET_MESSAGE_TYPES.OUTPUT) {
85
- if (msg.data) {
86
- pane.vt.write(msg.data);
87
- onPaneOutput(pane.agentId);
88
- }
89
- } else if (msg.type === PTY_SOCKET_MESSAGE_TYPES.REPLAY) {
90
- if (msg.data) {
91
- pane.vt.write(msg.data);
92
- onPaneOutput(pane.agentId);
93
- }
94
- } else if (msg.type === PTY_SOCKET_MESSAGE_TYPES.SNAPSHOT) {
95
- if (msg.data) {
96
- pane.vt.write(msg.data);
97
- onPaneOutput(pane.agentId);
98
- }
99
- }
100
- } catch {
101
- // ignore malformed messages or render errors
102
- }
103
- }
104
- });
105
-
106
- client.on("error", (err) => {
107
- pane.outputClient = null;
108
- pane.vt.write(`\r\n\x1b[31m[connection error]\x1b[0m ${err && err.message ? err.message : "socket error"}\r\n`);
109
- onPaneOutput(pane.agentId);
110
- });
111
- client.on("close", () => {
112
- pane.outputClient = null;
113
- pane.vt.write("\r\n\x1b[33m[disconnected]\x1b[0m\r\n");
114
- onPaneOutput(pane.agentId);
115
- });
116
- pane.outputClient = client;
117
- } catch (err) {
118
- pane.vt.write(`\x1b[31m[connection error]\x1b[0m ${err && err.message ? err.message : "connection failed"}\r\n`);
119
- onPaneOutput(pane.agentId);
120
- }
121
- }
122
-
123
- function disconnect(pane) {
124
- if (pane.outputClient) {
125
- try {
126
- pane.outputClient.removeAllListeners();
127
- pane.outputClient.destroy();
128
- } catch {}
129
- pane.outputClient = null;
130
- }
131
- if (pane.inputClient) {
132
- try {
133
- pane.inputClient.removeAllListeners();
134
- pane.inputClient.destroy();
135
- } catch {}
136
- pane.inputClient = null;
137
- }
138
- }
139
-
140
48
  function sendInput(data) {
141
49
  if (!focusedAgent) return;
142
50
  sendInputToPane(panes.get(focusedAgent), data);
@@ -149,39 +57,7 @@ function createPaneManager(options = {}) {
149
57
 
150
58
  function sendInputToPane(pane, data) {
151
59
  if (!pane) return;
152
- if (pane.mode === "internal") {
153
- handleInternalInput(pane, data);
154
- return;
155
- }
156
- const sockPath = getInjectSockPath(pane.agentId);
157
- if (!sockPath) return;
158
-
159
- if (!pane.inputClient || pane.inputClient.destroyed) {
160
- try {
161
- const client = net.createConnection(sockPath);
162
- pane.inputClient = client;
163
- client.on("error", () => { pane.inputClient = null; });
164
- client.on("close", () => { pane.inputClient = null; });
165
- client.once("connect", () => {
166
- try {
167
- client.write(JSON.stringify({
168
- type: PTY_SOCKET_MESSAGE_TYPES.RAW,
169
- data,
170
- }) + "\n");
171
- } catch {}
172
- });
173
- } catch { return; }
174
- return;
175
- }
176
-
177
- try {
178
- pane.inputClient.write(JSON.stringify({
179
- type: PTY_SOCKET_MESSAGE_TYPES.RAW,
180
- data,
181
- }) + "\n");
182
- } catch {
183
- pane.inputClient = null;
184
- }
60
+ handleInternalInput(pane, data);
185
61
  }
186
62
 
187
63
  function previousInputBoundary(text = "", cursor = 0) {
@@ -199,13 +75,22 @@ function createPaneManager(options = {}) {
199
75
  function handleInternalInput(pane, data) {
200
76
  const raw = String(data || "");
201
77
  if (!raw) return;
202
- if (raw === "\r" || raw === "\n") {
78
+ if (raw === "\r") {
203
79
  const message = String(pane.internalInput || "").trim();
204
80
  pane.internalInput = "";
205
81
  pane.internalCursor = 0;
206
82
  if (message) {
207
- pane.vt.write(`\r\n> ${message.replace(/\r?\n/g, "\r\n ")}\r\n`);
208
- try { onInternalSubmit(pane.agentId, message); } catch {}
83
+ pane.surface.apply("transcript.append", { kind: "user", text: message });
84
+ if (!/^\/multi(?:\s|$)/.test(message)) pane.surface.accept({ type: "task_submitted", message });
85
+ const failed = (error) => {
86
+ pane.surface.accept({ type: "submission_failed", message, error: `Message delivery failed: ${error?.message || error}` });
87
+ if (!pane.internalInput) { pane.internalInput = message; pane.internalCursor = message.length; }
88
+ onPaneOutput(pane.agentId);
89
+ };
90
+ try {
91
+ const result = onInternalSubmit(pane.agentId, message);
92
+ if (result?.catch) result.catch(failed);
93
+ } catch (error) { failed(error); }
209
94
  }
210
95
  onPaneOutput(pane.agentId);
211
96
  return;
@@ -231,7 +116,47 @@ function createPaneManager(options = {}) {
231
116
  onPaneOutput(pane.agentId);
232
117
  return;
233
118
  }
234
- if (raw === "\x1b[A" || raw === "\x1b[B" || raw === "\t" || raw === "\x1b") return;
119
+ if (raw === "\x1b[H" || raw === "\x1b[F") {
120
+ pane.internalCursor = raw === "\x1b[H" ? 0 : pane.internalInput.length;
121
+ onPaneOutput(pane.agentId);
122
+ return;
123
+ }
124
+ if (["\x01", "\x05", "\x15", "\x0b"].includes(raw)) {
125
+ const before = pane.internalInput.slice(0, pane.internalCursor);
126
+ const start = before.lastIndexOf("\n") + 1;
127
+ const nextLine = pane.internalInput.indexOf("\n", pane.internalCursor);
128
+ const end = nextLine < 0 ? pane.internalInput.length : nextLine;
129
+ if (raw === "\x01") pane.internalCursor = start;
130
+ else if (raw === "\x05") pane.internalCursor = end;
131
+ else if (raw === "\x15") {
132
+ pane.internalInput = pane.internalInput.slice(0, start) + pane.internalInput.slice(pane.internalCursor);
133
+ pane.internalCursor = start;
134
+ } else pane.internalInput = before + pane.internalInput.slice(end);
135
+ onPaneOutput(pane.agentId);
136
+ return;
137
+ }
138
+ if (raw === "\x1b[A" || raw === "\x1b[B") {
139
+ const move = moveCursorVertically({ inputValue: pane.internalInput, cursorPos: pane.internalCursor,
140
+ width: pane.inputCols, direction: raw === "\x1b[A" ? "up" : "down",
141
+ strWidth: (text) => Array.from(text).reduce((sum, ch) => sum + charDisplayWidth(ch), 0) });
142
+ pane.internalCursor = move.nextCursorPos;
143
+ onPaneOutput(pane.agentId);
144
+ return;
145
+ }
146
+ if (raw === "\x1b[3~") {
147
+ const next = Array.from(pane.internalInput.slice(pane.internalCursor))[0] || "";
148
+ pane.internalInput = pane.internalInput.slice(0, pane.internalCursor) + pane.internalInput.slice(pane.internalCursor + next.length);
149
+ onPaneOutput(pane.agentId);
150
+ return;
151
+ }
152
+ if (raw === "\x17") {
153
+ const deleted = deleteWordBeforeCursor(pane.internalInput, pane.internalCursor);
154
+ pane.internalInput = deleted.value;
155
+ pane.internalCursor = deleted.cursorPos;
156
+ onPaneOutput(pane.agentId);
157
+ return;
158
+ }
159
+ if (raw === "\t" || raw === "\x1b") return;
235
160
 
236
161
  const clean = raw.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/[\x00-\x08\x0b-\x0c\x0e-\x1f\x7f]/g, "");
237
162
  if (!clean) return;
@@ -240,25 +165,12 @@ function createPaneManager(options = {}) {
240
165
  onPaneOutput(pane.agentId);
241
166
  }
242
167
 
243
- function sendResize(agentId, cols, rows) {
168
+ function sendResize(agentId, cols, rows, inputCols = cols) {
244
169
  const pane = panes.get(agentId);
245
170
  if (!pane) return;
246
- pane.vt.resize(cols, rows);
247
- if (pane.mode === "internal") return;
248
- const sockPath = getInjectSockPath(pane.agentId);
249
- if ((!pane.outputClient || pane.outputClient.destroyed) && sockPath && fs.existsSync(sockPath)) {
250
- connectOutput(pane);
251
- return;
252
- }
253
- if (pane.outputClient && !pane.outputClient.destroyed) {
254
- try {
255
- pane.outputClient.write(JSON.stringify({
256
- type: PTY_SOCKET_MESSAGE_TYPES.RESIZE,
257
- cols,
258
- rows,
259
- }) + "\n");
260
- } catch {}
261
- }
171
+ pane.cols = cols;
172
+ pane.inputCols = inputCols;
173
+ pane.rows = rows;
262
174
  }
263
175
 
264
176
  function cycleFocus() {
@@ -277,13 +189,20 @@ function createPaneManager(options = {}) {
277
189
  function writeToPane(agentId, data) {
278
190
  const pane = panes.get(agentId);
279
191
  if (!pane) return false;
280
- pane.vt.write(data);
192
+ pane.surface.accept({ type: "text_delta", delta: String(data || "").replace(/\r\n/g, "\n") });
281
193
  onPaneOutput(pane.agentId);
282
194
  return true;
283
195
  }
284
196
 
197
+ function scrollPane(agentId, lines, maxOffset = 2000) {
198
+ const pane = panes.get(agentId);
199
+ if (!pane) return false;
200
+ pane.scrollOffset = Math.max(0, Math.min(maxOffset, pane.scrollOffset + lines));
201
+ onPaneOutput(agentId);
202
+ return true;
203
+ }
204
+
285
205
  function disconnectAll() {
286
- for (const pane of panes.values()) disconnect(pane);
287
206
  panes.clear();
288
207
  focusedAgent = null;
289
208
  }
@@ -301,6 +220,7 @@ function createPaneManager(options = {}) {
301
220
  getAllPanes,
302
221
  getAgentIds,
303
222
  writeToPane,
223
+ scrollPane,
304
224
  disconnectAll,
305
225
  };
306
226
  }
@@ -122,7 +122,7 @@ function createChatStreamState({
122
122
  meta: meta || {},
123
123
  };
124
124
  streams.set(key, state);
125
- dispatch({ type: "stream/begin", publisher: displayName });
125
+ dispatch({ type: "stream/begin", publisher: key, displayName });
126
126
  return state;
127
127
  }
128
128
 
@@ -132,7 +132,7 @@ function createChatStreamState({
132
132
  state.parts.push(text);
133
133
  let batch = pendingDeltas.get(state.publisher);
134
134
  if (!batch) {
135
- batch = { publisher: state.displayName || state.publisher, parts: [] };
135
+ batch = { publisher: state.publisher, parts: [] };
136
136
  pendingDeltas.set(state.publisher, batch);
137
137
  }
138
138
  batch.parts.push(text);
@@ -144,7 +144,7 @@ function createChatStreamState({
144
144
  const state = streams.get(key);
145
145
  if (!state) return;
146
146
  flushDeltas();
147
- dispatch({ type: "stream/end" });
147
+ dispatch({ type: "stream/end", publisher: key });
148
148
  if (typeof appendHistory === "function") {
149
149
  const full = state.parts.join("");
150
150
  const text = state.displayName
@@ -52,7 +52,7 @@ function connectSocket(sockPath, options = {}) {
52
52
  function resolveProjectFile(projectRoot, relativePath, fallbackRelativePath) {
53
53
  const local = path.join(projectRoot, relativePath);
54
54
  if (fs.existsSync(local)) return local;
55
- return path.join(__dirname, "..", "..", fallbackRelativePath);
55
+ return path.join(__dirname, "..", "..", "..", fallbackRelativePath);
56
56
  }
57
57
 
58
58
  function startDaemon(projectRoot, options = {}) {
@@ -142,6 +142,15 @@ function resolveAckArgs(cmdArgs = []) {
142
142
 
143
143
  async function runBusCoreCommand(eventBus, cmd, cmdArgs = []) {
144
144
  switch (cmd) {
145
+ case "deliveries": {
146
+ const { listNativeReceipts, resolveNativeReceipt } = require("../../coordination/bus/nativeReceipts");
147
+ const [subscriber, id, resolution, ...extra] = cmdArgs;
148
+ if (!subscriber || extra.length || (id && !resolution)) throw new Error("Usage: ufoo bus deliveries <subscriber> [<receipt-id> accepted|retry]");
149
+ const result = id ? resolveNativeReceipt(eventBus.projectRoot, subscriber, id, resolution)
150
+ : listNativeReceipts(eventBus.projectRoot, subscriber);
151
+ console.log(JSON.stringify(result, null, 2));
152
+ return {};
153
+ }
145
154
  case "init":
146
155
  await eventBus.init();
147
156
  return {};
@@ -34,6 +34,37 @@ class RepoDoctor {
34
34
  }
35
35
  }
36
36
 
37
+ reportMcp() {
38
+ try {
39
+ const { inspectCodexMcpConfig } = require("../../../runtime/daemon/mcpConfigure");
40
+ const status = inspectCodexMcpConfig();
41
+ if (!status.configured) return;
42
+ if (status.changed) this.fail(`Codex ufoo MCP config is outdated: ${status.target}; run ufoo mcp configure codex`);
43
+ else console.log("MCP: Codex normal tools and resident wait configuration are current.");
44
+ } catch {
45
+ console.log("MCP: configuration check unavailable; start the daemon and run ufoo mcp configure codex.");
46
+ }
47
+ }
48
+
49
+ reportNative() {
50
+ const { probeNativeCapabilities } = require("../../../agents/launch/nativeCapabilities");
51
+ const { loadAgentsData } = require("../../../coordination/state/agentsStore");
52
+ const { getUfooPaths } = require("../../../coordination/state/paths");
53
+ const { listNativeReceipts } = require("../../../coordination/bus/nativeReceipts");
54
+ console.log("Native message delivery:");
55
+ for (const agentType of ["codex", "claude-code"]) {
56
+ const capability = probeNativeCapabilities({ agentType });
57
+ console.log(`- ${agentType}: ${capability.version || "unavailable"} (${capability.supported ? "version compatible; runtime readiness still required" : capability.reason})`);
58
+ }
59
+ const agentsFile = getUfooPaths(process.cwd()).agentsFile;
60
+ if (!fs.existsSync(agentsFile)) return;
61
+ for (const [id, meta] of Object.entries(loadAgentsData(agentsFile).agents)) {
62
+ if (meta.native_delivery) console.log(`- ${id}: ${meta.native_delivery}, ready=${meta.native_delivery_ready === true}${meta.native_delivery_diagnostic ? `, ${meta.native_delivery_diagnostic}` : ""}`);
63
+ const uncertain = listNativeReceipts(process.cwd(), id).filter((receipt) => ["unknown", "inflight"].includes(receipt.state));
64
+ if (uncertain.length) console.log(`- ${id}: ${uncertain.length} uncertain receipt(s); inspect with ufoo bus deliveries ${id}`);
65
+ }
66
+ }
67
+
37
68
  run() {
38
69
  const skillsDir = path.join(this.repoRoot, "SKILLS");
39
70
  const contextSkill = path.join(skillsDir, "ufoo-context", "SKILL.md");
@@ -52,6 +83,8 @@ class RepoDoctor {
52
83
  if (fs.existsSync(contextSkill)) console.log(`- ufoo-context: ${contextSkill}`);
53
84
  if (fs.existsSync(busSkill)) console.log(`- ufoo-bus: ${busSkill}`);
54
85
  this.reportTui();
86
+ this.reportMcp();
87
+ this.reportNative();
55
88
 
56
89
  if (this.failed) {
57
90
  console.log("Status: FAILED");
@@ -67,6 +67,7 @@ class SkillsManager {
67
67
  * 查找技能路径
68
68
  */
69
69
  findSkill(name) {
70
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_-]*$/.test(name)) throw new Error(`Invalid skill name: ${name}`);
70
71
  for (const root of [...this.skillRoots, ...this.optionalSkillRoots]) {
71
72
  const skillPath = path.join(root, name);
72
73
  if (fs.existsSync(skillPath)) {
@@ -103,7 +104,12 @@ class SkillsManager {
103
104
 
104
105
  if (name === "all") {
105
106
  // 安装所有技能
106
- const skills = this.list();
107
+ const skills = [
108
+ ...this.list(),
109
+ ...this.list({ optionalOnly: true }).filter((skill) => {
110
+ try { return Boolean(fs.lstatSync(path.join(target, skill))); } catch { return false; }
111
+ }),
112
+ ];
107
113
  for (const skill of skills) {
108
114
  await this.installOne(skill, target);
109
115
  }
@@ -126,9 +132,15 @@ class SkillsManager {
126
132
 
127
133
  const targetPath = path.join(target, name);
128
134
 
129
- // 如果目标已存在,先删除
130
- if (fs.existsSync(targetPath)) {
131
- fs.rmSync(targetPath, { recursive: true, force: true });
135
+ // Explicit installs preserve the previous skill, including custom files and
136
+ // symlinks. npm postinstall uses the stricter managed-link policy instead.
137
+ try {
138
+ fs.lstatSync(targetPath);
139
+ const backup = `${targetPath}.backup-${Date.now()}-${require("crypto").randomBytes(4).toString("hex")}`;
140
+ fs.renameSync(targetPath, backup);
141
+ console.log(` Previous skill saved to: ${backup}`);
142
+ } catch (error) {
143
+ if (error.code !== "ENOENT") throw error;
132
144
  }
133
145
 
134
146
  // 复制技能目录
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ async function sendAgentReportRequest(projectRoot, report) {
4
+ const { enqueueAgentReport } = require("../../runtime/daemon/reportControlBus");
5
+ const queued = await enqueueAgentReport(projectRoot, report);
6
+ const entry = queued.report;
7
+ return {
8
+ type: "response",
9
+ data: {
10
+ reply: `Report queued (${entry.phase})`,
11
+ report: entry,
12
+ queued,
13
+ },
14
+ };
15
+ }
16
+
17
+ function getReportDetail(out = {}) {
18
+ if (out.phase === "error") {
19
+ return out.error || out.summary || out.message || out.task_id;
20
+ }
21
+ return out.summary || out.message || out.task_id;
22
+ }
23
+
24
+ function printReportOutput(out, json = false, queued = null) {
25
+ if (json) {
26
+ console.log(JSON.stringify({
27
+ status: "queued",
28
+ report: out,
29
+ queued,
30
+ }, null, 2));
31
+ return;
32
+ }
33
+ const detail = getReportDetail(out);
34
+ console.log(`[report] queued ${out.phase} ${out.agent_id} ${out.task_id} ${detail}`);
35
+ }
36
+
37
+ module.exports = { sendAgentReportRequest, printReportOutput };
@@ -8,6 +8,7 @@ const {
8
8
  resolveDaemonEndpoint,
9
9
  routeDaemonRequest,
10
10
  } = require("../../runtime/daemon/endpoint");
11
+ const { sendAgentReportRequest, printReportOutput } = require("./reportCoreCommands");
11
12
  const { runBusCoreCommand } = require("./busCoreCommands");
12
13
  const { runCtxCommand } = require("./ctxCoreCommands");
13
14
  const { runOnlineCommand } = require("./onlineCoreCommands");
@@ -15,7 +16,7 @@ const { runGroupCoreCommand } = require("./groupCoreCommands");
15
16
  const { loadConfig } = require("../../config");
16
17
  const { loadPromptProfileRegistry } = require("../../orchestration/groups/promptProfiles");
17
18
  const { resolveSoloAgentType } = require("../../orchestration/solo/commands");
18
- const { listProjectRuntimes, getCurrentProjectRuntime } = require("../../runtime/projects/registry");
19
+ const { listProjectRuntimes, getCurrentProjectRuntime, archiveMissingProjectRuntimes } = require("../../runtime/projects/registry");
19
20
  const { canonicalProjectRoot, buildProjectId } = require("../../runtime/projects/projectId");
20
21
  const { getUfooPaths } = require("../../coordination/state/paths");
21
22
  const { resolveNodeExecutable } = require("../../runtime/process/nodeExecutable");
@@ -148,41 +149,6 @@ async function sendDaemonRequest(projectRoot, payload) {
148
149
  });
149
150
  }
150
151
 
151
- async function sendAgentReportRequest(projectRoot, report) {
152
- const { normalizeReportInput } = require("../../coordination/report/store");
153
- const { enqueueAgentReport } = require("../../runtime/daemon/reportControlBus");
154
- const entry = normalizeReportInput(report);
155
- const queued = await enqueueAgentReport(projectRoot, entry);
156
- return {
157
- type: "response",
158
- data: {
159
- reply: `Report queued (${entry.phase})`,
160
- report: entry,
161
- queued,
162
- },
163
- };
164
- }
165
-
166
- function getReportDetail(out = {}) {
167
- if (out.phase === "error") {
168
- return out.error || out.summary || out.message || out.task_id;
169
- }
170
- return out.summary || out.message || out.task_id;
171
- }
172
-
173
- function printReportOutput(out, json = false, queued = null) {
174
- if (json) {
175
- console.log(JSON.stringify({
176
- status: "queued",
177
- report: out,
178
- queued,
179
- }, null, 2));
180
- return;
181
- }
182
- const detail = getReportDetail(out);
183
- console.log(`[report] queued ${out.phase} ${out.agent_id} ${out.task_id} ${detail}`);
184
- }
185
-
186
152
  function requireOptional(name) {
187
153
  try {
188
154
  // eslint-disable-next-line global-require, import/no-dynamic-require
@@ -487,6 +453,7 @@ function runMemoryCommand({
487
453
  function runProjectCommand({
488
454
  subcommand = "list",
489
455
  outputJson = false,
456
+ apply = false,
490
457
  cwd = process.cwd(),
491
458
  write = (line) => console.log(line),
492
459
  writeError = (line) => console.error(line),
@@ -512,12 +479,21 @@ function runProjectCommand({
512
479
  printCurrentProject(current, write);
513
480
  return 0;
514
481
  }
482
+ if (sub === "prune") {
483
+ const result = archiveMissingProjectRuntimes({ dryRun: !apply });
484
+ if (outputJson) write(JSON.stringify({ ...result, dry_run: !apply }, null, 2));
485
+ else {
486
+ write(`${apply ? "Archived" : "Would archive"} ${result.count} abandoned project record(s).`);
487
+ write(apply ? `Archive: ${result.archive_dir}` : "Use --apply to archive these records; existing workspaces and live daemons are retained.");
488
+ }
489
+ return 0;
490
+ }
515
491
  if (sub === "switch") {
516
492
  const err = projectSwitchV1Error();
517
493
  writeError(err.message);
518
494
  return err.exitCode || 2;
519
495
  }
520
- writeError("project requires list|current|switch subcommand");
496
+ writeError("project requires list|current|prune|switch subcommand");
521
497
  return 1;
522
498
  } catch (err) {
523
499
  writeError(err.message || String(err));
@@ -650,6 +626,14 @@ async function runCli(argv) {
650
626
  cwd: process.cwd(),
651
627
  });
652
628
  });
629
+ project
630
+ .command("prune")
631
+ .description("Archive abandoned registrations for deleted workspaces")
632
+ .option("--apply", "Move records into the recoverable archive (default: preview)")
633
+ .option("--json", "Output as JSON")
634
+ .action((opts) => {
635
+ process.exitCode = runProjectCommand({ subcommand: "prune", apply: opts.apply === true, outputJson: opts.json === true });
636
+ });
653
637
  project
654
638
  .command("switch")
655
639
  .description("Switch active project (chat-only in v1)")
@@ -1043,7 +1027,7 @@ async function runCli(argv) {
1043
1027
  }
1044
1028
 
1045
1029
  const agentId = String(opts.agent || process.env.UFOO_SUBSCRIBER_ID || "unknown-agent").trim() || "unknown-agent";
1046
- const taskId = String(opts.task || `task-${Date.now()}`).trim();
1030
+ const taskId = String(opts.task || "").trim();
1047
1031
  const summary = String(opts.summary || (normalized === "done" ? text : "")).trim();
1048
1032
  const error = String(opts.error || (normalized === "error" ? text : "")).trim();
1049
1033
  const report = {
@@ -1515,6 +1499,21 @@ async function runCli(argv) {
1515
1499
  });
1516
1500
 
1517
1501
  const bus = program.command("bus").description("Project bus commands");
1502
+ bus
1503
+ .command("deliveries")
1504
+ .description("Inspect native receipts or explicitly resolve an uncertain delivery")
1505
+ .argument("<subscriber>", "Subscriber ID")
1506
+ .argument("[receipt-id]", "Uncertain receipt ID")
1507
+ .argument("[resolution]", "accepted|retry (retry can duplicate already accepted work)")
1508
+ .action(async (subscriber, id, resolution) => {
1509
+ const EventBus = require("../../coordination/bus");
1510
+ try {
1511
+ await runBusCoreCommand(new EventBus(process.cwd()), "deliveries", [subscriber, id, resolution].filter(Boolean));
1512
+ } catch (error) {
1513
+ console.error(error.message);
1514
+ process.exitCode = 1;
1515
+ }
1516
+ });
1518
1517
  bus
1519
1518
  .command("alert")
1520
1519
  .description("Start/stop background notification daemon")
@@ -1770,6 +1769,7 @@ async function runCli(argv) {
1770
1769
  console.log(" ufoo -g");
1771
1770
  console.log(" ufoo chat [-g]");
1772
1771
  console.log(" ufoo project list [--json]");
1772
+ console.log(" ufoo project prune [--apply] [--json]");
1773
1773
  console.log(" ufoo project current [--json]");
1774
1774
  console.log(" ufoo project switch <index|path>");
1775
1775
  console.log(" ufoo resume [nickname]");
@@ -1857,6 +1857,7 @@ async function runCli(argv) {
1857
1857
  process.exitCode = runProjectCommand({
1858
1858
  subcommand: sub,
1859
1859
  outputJson,
1860
+ apply: rest.includes("--apply"),
1860
1861
  cwd: process.cwd(),
1861
1862
  });
1862
1863
  return;
@@ -2016,7 +2017,7 @@ async function runCli(argv) {
2016
2017
 
2017
2018
  const report = {
2018
2019
  phase: normalized,
2019
- task_id: getOpt("--task", `task-${Date.now()}`),
2020
+ task_id: getOpt("--task", ""),
2020
2021
  agent_id: getOpt("--agent", process.env.UFOO_SUBSCRIBER_ID || "unknown-agent"),
2021
2022
  message,
2022
2023
  summary: getOpt("--summary", normalized === "done" ? message : ""),