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,135 +0,0 @@
1
- const { stripAnsi, truncateAnsi } = require("./text");
2
-
3
- const ACTIVITY_INDICATORS = {
4
- working: "*",
5
- waiting_input: "?",
6
- blocked: "!",
7
- };
8
-
9
- const ACTIVITY_COLORS = {
10
- waiting_input: "\x1b[33m", // yellow
11
- blocked: "\x1b[31m", // red
12
- };
13
-
14
- function computeAgentBar(options = {}) {
15
- const {
16
- cols = 80,
17
- hintText = "",
18
- focusMode = "input",
19
- selectedAgentIndex = -1,
20
- activeAgents = [],
21
- viewingAgent = null,
22
- agentListWindowStart = 0,
23
- maxAgentWindow = 4,
24
- getAgentLabel = (id) => id,
25
- agentStates = {},
26
- } = options;
27
-
28
- const hintAnsi = `\x1b[90m│ ${hintText}\x1b[0m`;
29
- const selectionIndex = focusMode === "dashboard"
30
- ? (selectedAgentIndex > 0 ? selectedAgentIndex - 1 : -1)
31
- : activeAgents.indexOf(viewingAgent);
32
- const maxAgentLen = Math.max(0, cols - 1 - 2 - stripAnsi(hintAnsi).length);
33
- let windowItems = Math.max(1, Math.min(maxAgentWindow, activeAgents.length));
34
- let start = agentListWindowStart;
35
- const ufooItem = focusMode === "dashboard" && selectedAgentIndex === 0
36
- ? "\x1b[90;7mufoo\x1b[0m"
37
- : "\x1b[36mufoo\x1b[0m";
38
- const ufooLen = stripAnsi(ufooItem).length;
39
-
40
- const computeStart = (items) => {
41
- if (activeAgents.length === 0) return 0;
42
- let s = start;
43
- if (selectionIndex >= 0) {
44
- if (selectionIndex < s) {
45
- s = selectionIndex;
46
- } else if (selectionIndex >= s + items) {
47
- s = selectionIndex - items + 1;
48
- }
49
- }
50
- const maxStart = Math.max(0, activeAgents.length - items);
51
- if (s > maxStart) s = maxStart;
52
- if (s < 0) s = 0;
53
- return s;
54
- };
55
-
56
- const truncateLabel = (label, maxLen) => {
57
- const text = String(label || "");
58
- if (maxLen <= 0) return "";
59
- if (text.length <= maxLen) return text;
60
- if (maxLen <= 3) return text.slice(0, maxLen);
61
- return `${text.slice(0, maxLen - 3)}...`;
62
- };
63
-
64
- const buildAgentSegment = (items, maxLabelLen) => {
65
- const s = computeStart(items);
66
- const e = s + items;
67
- const visible = activeAgents.slice(s, e);
68
- const leftMore = s > 0 ? "\x1b[90m<\x1b[0m " : "";
69
- const rightMore = e < activeAgents.length ? " \x1b[90m>\x1b[0m" : "";
70
- let agentParts = [];
71
- if (activeAgents.length > 0) {
72
- agentParts = visible.map((agent, i) => {
73
- const rawLabel = getAgentLabel(agent);
74
- const label = maxLabelLen ? truncateLabel(rawLabel, maxLabelLen) : rawLabel;
75
- const actState = agentStates[agent] || "";
76
- const indicator = ACTIVITY_INDICATORS[actState] || "";
77
- const indicatorColor = ACTIVITY_COLORS[actState] || "";
78
- const prefix = indicator
79
- ? `${indicatorColor}${indicator}\x1b[0m`
80
- : "";
81
- const idx = s + i + 1; // +1 for ufoo chat at index 0
82
- if (focusMode === "dashboard" && idx === selectedAgentIndex) {
83
- return `${prefix}\x1b[90;7m${label}\x1b[0m`;
84
- }
85
- if (agent === viewingAgent) return `${prefix}\x1b[1;36m${label}\x1b[0m`;
86
- return `${prefix}\x1b[36m${label}\x1b[0m`;
87
- });
88
- }
89
- const agentsText = activeAgents.length > 0
90
- ? `${leftMore}${agentParts.join(" ")}${rightMore}`
91
- : "\x1b[36mnone\x1b[0m";
92
- return { segment: `${ufooItem} ${agentsText}`, start: s };
93
- };
94
-
95
- let segmentInfo = buildAgentSegment(windowItems, 0);
96
- while (windowItems > 0) {
97
- const s = computeStart(windowItems);
98
- const e = s + windowItems;
99
- const hasLeft = s > 0;
100
- const hasRight = e < activeAgents.length;
101
- const spacingLen = windowItems > 1 ? (windowItems - 1) * 2 : 0;
102
- const overhead = ufooLen + 2 + (hasLeft ? 2 : 0) + (hasRight ? 2 : 0) + spacingLen;
103
- const available = maxAgentLen - overhead;
104
- let maxLabelLen = windowItems > 0 ? Math.floor(available / windowItems) : 0;
105
- if (windowItems > 1 && maxLabelLen < 3) {
106
- windowItems -= 1;
107
- segmentInfo = buildAgentSegment(windowItems, 0);
108
- continue;
109
- }
110
- if (maxLabelLen < 1) maxLabelLen = 1;
111
- segmentInfo = buildAgentSegment(windowItems, maxLabelLen);
112
- if (stripAnsi(segmentInfo.segment).length <= maxAgentLen || windowItems === 1) break;
113
- windowItems -= 1;
114
- segmentInfo = buildAgentSegment(windowItems, 0);
115
- }
116
- start = segmentInfo.start;
117
- const agentSegment = segmentInfo.segment;
118
-
119
- let bar = ` ${agentSegment} ${hintAnsi}`;
120
- let barLen = stripAnsi(bar).length;
121
- if (barLen > cols) {
122
- bar = truncateAnsi(bar, cols);
123
- barLen = stripAnsi(bar).length;
124
- }
125
- const pad = Math.max(0, cols - barLen);
126
-
127
- return {
128
- bar: `${bar}${" ".repeat(pad)}`,
129
- windowStart: start,
130
- };
131
- }
132
-
133
- module.exports = {
134
- computeAgentBar,
135
- };
@@ -1,70 +0,0 @@
1
- "use strict";
2
-
3
- /**
4
- * Agent enter / dashboard navigation helpers (Phase 0B extraction).
5
- */
6
-
7
- const path = require("path");
8
-
9
- function resolveInjectSockPathForAgent(projectRoot, agentId) {
10
- const { getUfooPaths } = require("../../coordination/state/paths");
11
- const { subscriberToSafeName } = require("../../coordination/bus/utils");
12
- const safeName = subscriberToSafeName(agentId);
13
- return path.join(getUfooPaths(projectRoot || process.cwd()).busQueuesDir, safeName, "inject.sock");
14
- }
15
-
16
- function resolveAgentEnterRequest({
17
- agentId,
18
- projectRoot = "",
19
- activeAgentMeta = new Map(),
20
- settings = {},
21
- } = {}) {
22
- const id = String(agentId || "").trim();
23
- if (!id) return null;
24
-
25
- const metaMap = activeAgentMeta instanceof Map ? activeAgentMeta : new Map();
26
- const meta = metaMap.get(id) || {};
27
- const configuredLaunchMode = settings && settings.launchMode && settings.launchMode !== "auto"
28
- ? settings.launchMode
29
- : "";
30
- const launchMode = String(meta.launch_mode || meta.launchMode || configuredLaunchMode || "").trim();
31
- const { createTerminalAdapterRouter } = require("../../runtime/terminal/adapterRouter");
32
- const adapter = createTerminalAdapterRouter().getAdapter({ launchMode, agentId: id, meta });
33
- const caps = adapter && adapter.capabilities ? adapter.capabilities : {};
34
-
35
- return {
36
- agentId: id,
37
- projectRoot: String(projectRoot || ""),
38
- launchMode,
39
- useBus: Boolean(caps.supportsInternalQueueLoop && !caps.supportsSocketProtocol),
40
- supportsSocket: Boolean(caps.supportsSocketProtocol),
41
- supportsInternalQueue: Boolean(caps.supportsInternalQueueLoop),
42
- supportsActivate: Boolean(caps.supportsActivate),
43
- };
44
- }
45
-
46
- function resolveDashboardAgentEnterAction(enterRequest = {}) {
47
- if (!enterRequest || typeof enterRequest !== "object") return "none";
48
- if (enterRequest.useBus) return "internal";
49
- if (enterRequest.supportsActivate) return "activate";
50
- // No PTY mirror fallback — host must expose activate (or use terminal/tmux/internal).
51
- return "none";
52
- }
53
-
54
- function buildEmptyProjectsDownActions(state = {}, displayAgents = []) {
55
- if (!state.emptyProjectsDownArmed) {
56
- return [{ type: "projects/armEmptyDown" }];
57
- }
58
- const actions = [{ type: "view/set", view: "agents" }];
59
- if (displayAgents.length > 0 && state.selectedAgentIndex < 0) {
60
- actions.push({ type: "agents/select", index: 0 });
61
- }
62
- return actions;
63
- }
64
-
65
- module.exports = {
66
- resolveInjectSockPathForAgent,
67
- resolveAgentEnterRequest,
68
- resolveDashboardAgentEnterAction,
69
- buildEmptyProjectsDownActions,
70
- };
@@ -1,225 +0,0 @@
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
-
5
- function createAgentSockets(options = {}) {
6
- const {
7
- onTermWrite = () => {},
8
- onPlaceCursor = () => {},
9
- isAgentView = () => false,
10
- isBusMode = () => false,
11
- getViewingAgent = () => "",
12
- sendBusRaw = () => {},
13
- } = options;
14
-
15
- let outputClient = null;
16
- let outputBuffer = "";
17
- let inputClient = null;
18
- let pendingResize = null;
19
-
20
- function requestSnapshot(mode = PTY_SOCKET_SUBSCRIBE_MODES.SCREEN) {
21
- if (!outputClient || outputClient.destroyed) return false;
22
- const safeMode = mode === PTY_SOCKET_SUBSCRIBE_MODES.FULL
23
- ? PTY_SOCKET_SUBSCRIBE_MODES.FULL
24
- : PTY_SOCKET_SUBSCRIBE_MODES.SCREEN;
25
- try {
26
- outputClient.write(JSON.stringify({
27
- type: PTY_SOCKET_MESSAGE_TYPES.SUBSCRIBE,
28
- mode: safeMode,
29
- }) + "\n");
30
- return true;
31
- } catch {
32
- return false;
33
- }
34
- }
35
-
36
- function requestScreenSnapshot() {
37
- return requestSnapshot(PTY_SOCKET_SUBSCRIBE_MODES.SCREEN);
38
- }
39
-
40
- function connectOutput(sockPath) {
41
- if (outputClient) {
42
- disconnectOutput();
43
- }
44
- outputBuffer = "";
45
-
46
- if (!fs.existsSync(sockPath)) {
47
- onTermWrite("\x1b[1;31m[Error]\x1b[0m inject.sock not found\r\n");
48
- onTermWrite("\x1b[33m[Hint]\x1b[0m Agent may not be running in terminal mode\r\n");
49
- onTermWrite("Press Esc to return\r\n");
50
- return;
51
- }
52
-
53
- try {
54
- outputClient = net.createConnection(sockPath, () => {
55
- outputClient.write(JSON.stringify({
56
- type: PTY_SOCKET_MESSAGE_TYPES.SUBSCRIBE,
57
- mode: PTY_SOCKET_SUBSCRIBE_MODES.FULL,
58
- }) + "\n");
59
- });
60
-
61
- const connectTimeout = setTimeout(() => {
62
- if (outputClient && !outputClient.connecting) return;
63
- onTermWrite("\x1b[1;31m[Timeout]\x1b[0m Could not connect\r\nPress Esc to return\r\n");
64
- disconnectOutput();
65
- }, 5000);
66
-
67
- outputClient.on("connect", () => {
68
- clearTimeout(connectTimeout);
69
- });
70
-
71
- outputClient.on("data", (data) => {
72
- outputBuffer += data.toString("utf8");
73
- const lines = outputBuffer.split("\n");
74
- outputBuffer = lines.pop() || "";
75
-
76
- for (const line of lines) {
77
- if (!line.trim()) continue;
78
- try {
79
- const msg = JSON.parse(line);
80
- if (msg.type === PTY_SOCKET_MESSAGE_TYPES.OUTPUT) {
81
- if (msg.data) onTermWrite(msg.data);
82
- } else if (msg.type === PTY_SOCKET_MESSAGE_TYPES.REPLAY ||
83
- msg.type === PTY_SOCKET_MESSAGE_TYPES.SNAPSHOT) {
84
- if (msg.data) onTermWrite(msg.data);
85
- if (msg.type === PTY_SOCKET_MESSAGE_TYPES.SNAPSHOT && msg.cursor) {
86
- onPlaceCursor(msg.cursor);
87
- }
88
- }
89
- } catch {
90
- // ignore malformed messages
91
- }
92
- }
93
- });
94
-
95
- outputClient.on("error", (err) => {
96
- if (isAgentView()) {
97
- onTermWrite(`\r\n\x1b[1;31m[Connection error]\x1b[0m ${err.message}\r\nPress Esc to return\r\n`);
98
- }
99
- });
100
-
101
- outputClient.on("close", () => {
102
- outputClient = null;
103
- if (isAgentView()) {
104
- onTermWrite("\r\n\x1b[1;33m[Agent disconnected]\x1b[0m\r\nPress Esc to return\r\n");
105
- }
106
- });
107
- } catch (err) {
108
- onTermWrite(`\x1b[1;31m[Error]\x1b[0m ${err.message}\r\nPress Esc to return\r\n`);
109
- }
110
- }
111
-
112
- function disconnectOutput() {
113
- if (outputClient) {
114
- try {
115
- outputClient.removeAllListeners();
116
- outputClient.destroy();
117
- } catch {
118
- // ignore
119
- }
120
- outputClient = null;
121
- }
122
- outputBuffer = "";
123
- }
124
-
125
- function connectInput(sockPath) {
126
- if (inputClient) {
127
- disconnectInput();
128
- }
129
- try {
130
- inputClient = net.createConnection(sockPath);
131
- inputClient.on("connect", () => {
132
- if (pendingResize) {
133
- const { cols, rows } = pendingResize;
134
- pendingResize = null;
135
- try {
136
- inputClient.write(JSON.stringify({
137
- type: PTY_SOCKET_MESSAGE_TYPES.RESIZE,
138
- cols,
139
- rows,
140
- }) + "\n");
141
- } catch {
142
- // ignore write errors
143
- }
144
- }
145
- });
146
- inputClient.on("error", () => {
147
- inputClient = null;
148
- });
149
- inputClient.on("close", () => {
150
- inputClient = null;
151
- });
152
- } catch {
153
- inputClient = null;
154
- }
155
- }
156
-
157
- function disconnectInput() {
158
- if (inputClient) {
159
- try {
160
- inputClient.removeAllListeners();
161
- inputClient.destroy();
162
- } catch {
163
- // ignore
164
- }
165
- inputClient = null;
166
- }
167
- }
168
-
169
- function sendRaw(data) {
170
- if (inputClient && !inputClient.destroyed) {
171
- try {
172
- inputClient.write(JSON.stringify({
173
- type: PTY_SOCKET_MESSAGE_TYPES.RAW,
174
- data,
175
- }) + "\n");
176
- return;
177
- } catch {
178
- // ignore write errors
179
- }
180
- }
181
- if (isBusMode()) {
182
- const viewingAgent = getViewingAgent();
183
- if (viewingAgent) {
184
- sendBusRaw(viewingAgent, data);
185
- }
186
- }
187
- }
188
-
189
- function sendResize(cols, rows) {
190
- if (!inputClient || inputClient.destroyed) {
191
- pendingResize = { cols, rows };
192
- return;
193
- }
194
- try {
195
- inputClient.write(JSON.stringify({
196
- type: PTY_SOCKET_MESSAGE_TYPES.RESIZE,
197
- cols,
198
- rows,
199
- }) + "\n");
200
- } catch {
201
- // ignore write errors
202
- }
203
- }
204
-
205
- function disconnectAll() {
206
- disconnectOutput();
207
- disconnectInput();
208
- }
209
-
210
- return {
211
- connectOutput,
212
- disconnectOutput,
213
- connectInput,
214
- disconnectInput,
215
- disconnectAll,
216
- sendRaw,
217
- sendResize,
218
- requestSnapshot,
219
- requestScreenSnapshot,
220
- };
221
- }
222
-
223
- module.exports = {
224
- createAgentSockets,
225
- };