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
@@ -17,6 +17,8 @@ const {
17
17
  } = require("../code/UcodeController");
18
18
  const { createEnvelope, encodeMessage } = require("../runtime/contracts/uiProtocol");
19
19
  const fmt = require("./format");
20
+ const { createAgentSurface } = require("./agentSurface");
21
+ const { buildPlanSetPayload, statusForAgentPhase } = require("./agentPresentation");
20
22
  const PACKAGE_VERSION = require("../../package.json").version;
21
23
 
22
24
  function stripTags(value) {
@@ -92,65 +94,6 @@ async function buildUcodeCompletionItems({
92
94
  });
93
95
  }
94
96
 
95
- function buildPlanSetPayload(executionState, options = {}) {
96
- try {
97
- const { buildPlanUiProjection } = require("../code/context/planProjection");
98
- const projection = buildPlanUiProjection(executionState, {
99
- cols: Number(options.cols) > 0 ? Number(options.cols) : 80,
100
- activityMessage: String(options.activityMessage || ""),
101
- });
102
- if (!projection || !projection.visible) {
103
- return {
104
- summary: "",
105
- lines: [],
106
- hash: projection && projection.hash || "",
107
- visible: false,
108
- idle_hint: String((projection && projection.idleHint) || ""),
109
- status_line: "",
110
- band_mode: String((projection && projection.bandMode) || ""),
111
- };
112
- }
113
- let lines = Array.isArray(projection.bandLines) ? projection.bandLines.slice() : [];
114
- const md = String(projection.roadmapMarkdown || "").trim();
115
- if (md) {
116
- try {
117
- const rendered = fmt.renderLogLinesWithMarkdownAnsi(md, { inCodeBlock: false });
118
- if (Array.isArray(rendered) && rendered.length > 0) {
119
- lines = rendered.map((line) => String(line || ""));
120
- }
121
- } catch {
122
- // keep bandLines
123
- }
124
- }
125
- const summary = String(
126
- projection.statusLine
127
- || projection.activityStatusLine
128
- || lines[0]
129
- || ""
130
- ).trim();
131
- return {
132
- summary,
133
- text: summary,
134
- lines,
135
- hash: projection.hash || "",
136
- visible: true,
137
- idle_hint: String(projection.idleHint || ""),
138
- status_line: String(projection.statusLine || projection.activityStatusLine || ""),
139
- activity_status_line: String(projection.activityStatusLine || ""),
140
- band_mode: String(projection.bandMode || ""),
141
- };
142
- } catch {
143
- return {
144
- summary: "",
145
- lines: [],
146
- hash: "",
147
- visible: false,
148
- idle_hint: "",
149
- status_line: "",
150
- band_mode: "",
151
- };
152
- }
153
- }
154
97
 
155
98
  function normalizeToolLogEntry(entry = {}) {
156
99
  const tool = String(entry.tool || "").trim().toLowerCase();
@@ -266,6 +209,7 @@ async function runUcodeRust(props = {}) {
266
209
  let backgroundSeq = 0;
267
210
  let requestExit = false;
268
211
  const MARKDOWN_LOG_KINDS = new Set(["assistant", "error"]);
212
+ const surface = createAgentSurface({ maxEntries: 4000 });
269
213
  const controller = createUcodeController({
270
214
  projectRoot: workspaceRoot,
271
215
  ports: {
@@ -274,6 +218,7 @@ async function runUcodeRust(props = {}) {
274
218
  });
275
219
 
276
220
  function publish(name, payload) {
221
+ surface.apply(name, payload);
277
222
  if (!hostRef) return;
278
223
  hostRef.broadcast(hostRef.createEvent(name, payload, {
279
224
  surface: "ucode",
@@ -533,8 +478,16 @@ async function runUcodeRust(props = {}) {
533
478
  ),
534
479
  });
535
480
 
481
+ surface.apply("transcript.reset", {
482
+ entries: banner.map((line, idx) => {
483
+ const { logo, metadata } = splitUcodeBannerRow(line, idx);
484
+ return { id: `b-${idx}`, kind: "banner", text: logo, detail: metadata, speaker: "" };
485
+ }).concat([{ id: `b-${banner.length}`, kind: "spacer", text: "", speaker: "" }]),
486
+ });
487
+
536
488
  function buildSnapshot() {
537
489
  const meter = props.state && props.state.contextMeter;
490
+ const view = surface.snapshot();
538
491
  const agentsSnap = buildUcodeAgentsSnapshot(
539
492
  workspaceRoot,
540
493
  String(
@@ -544,30 +497,15 @@ async function runUcodeRust(props = {}) {
544
497
  ).trim()
545
498
  );
546
499
  return {
547
- status: "ready",
500
+ status: view.status,
501
+ busy: view.busy,
548
502
  package_version: PACKAGE_VERSION,
549
503
  footer: agentsSnap.footer,
550
- entries: banner.map((line, idx) => {
551
- const { logo, metadata } = splitUcodeBannerRow(line, idx);
552
- return {
553
- id: `b-${idx}`,
554
- kind: "banner",
555
- // Logo and metadata are separate raw renderer segments. Neither
556
- // ever passes through the ordinary log formatter.
557
- text: logo,
558
- detail: metadata,
559
- speaker: "",
560
- };
561
- }).concat([{
562
- id: `b-${banner.length}`,
563
- kind: "spacer",
564
- text: "",
565
- speaker: "",
566
- }]),
504
+ entries: view.entries,
567
505
  input_history: [],
568
506
  agents: agentsSnap.agents,
569
507
  attachment_count: pendingAttachments.length,
570
- usage: String((meter && meter.label) || ""),
508
+ usage: String((meter && meter.label) || view.usage || ""),
571
509
  task_queue: controller.getQueueSnapshot(),
572
510
  };
573
511
  }
@@ -699,15 +637,10 @@ async function runUcodeRust(props = {}) {
699
637
  onToolLog: ingestToolLog,
700
638
  onPhase: (event) => {
701
639
  if (!event || typeof event !== "object") return;
702
- if (event.type === "request_start") {
703
- publish("status.set", { text: "Waiting for model…", busy: true });
704
- } else if (event.type === "text_delta") {
705
- beginResponse();
706
- } else if (event.type === "tool_request") {
707
- const tool = String(event.name || "tool").trim() || "tool";
708
- const label = (fmt.TOOL_LABELS && fmt.TOOL_LABELS[tool.toLowerCase()])
709
- || `Calling ${tool}`;
710
- publish("status.set", { text: `${label}…`, busy: true });
640
+ if (event.type === "text_delta") beginResponse();
641
+ else {
642
+ const text = statusForAgentPhase(event);
643
+ if (text) publish("status.set", { text, busy: true });
711
644
  }
712
645
  },
713
646
  });
@@ -860,7 +793,7 @@ async function runUcodeRust(props = {}) {
860
793
  state: props.state || {},
861
794
  selfSubscriberId,
862
795
  remoteModels,
863
- limit: 20,
796
+ limit: Math.max(20, remoteModels.length + 1),
864
797
  });
865
798
  publish("completions.set", { items });
866
799
  return { ok: true, count: items.length };
@@ -1,48 +1,68 @@
1
1
  "use strict";
2
2
 
3
3
  /**
4
- * Shared launch-mode / agent-provider options for Ink + Rust chat hosts.
4
+ * Dashboard settings snapshots never carry provider credentials.
5
5
  */
6
6
 
7
- const MODE_OPTIONS = Object.freeze(["auto", "host", "terminal", "tmux", "internal"]);
8
-
9
7
  const PROVIDER_OPTIONS = Object.freeze([
10
8
  { label: "codex", value: "codex-cli" },
11
9
  { label: "claude", value: "claude-cli" },
12
10
  { label: "agy", value: "agy-cli" },
13
11
  { label: "kimi", value: "kimi-cli" },
12
+ { label: "grok", value: "grok-cli" },
13
+ { label: "custom", value: "custom" },
14
14
  ]);
15
15
 
16
16
  function buildSettingsSnapshot(settings = {}) {
17
- const { normalizeLaunchMode, normalizeAgentProvider } = require("../config");
18
- const launchMode = normalizeLaunchMode(settings.launchMode || "auto");
17
+ const { normalizeAgentProvider } = require("../config");
19
18
  const agentProvider = normalizeAgentProvider(settings.agentProvider || "codex-cli");
20
19
  return {
21
- launch_mode: launchMode,
22
20
  agent_provider: agentProvider,
23
- mode_options: MODE_OPTIONS.slice(),
21
+ agent_model: settings.agentModel || "",
22
+ agent_thinking: settings.agentThinking || "medium",
23
+ custom_base_url: settings.agentBaseUrl || "",
24
+ custom_key_set: Boolean(settings.agentApiKey),
24
25
  provider_options: PROVIDER_OPTIONS.map((opt) => ({ ...opt })),
25
26
  };
26
27
  }
27
28
 
28
29
  function applySettingsPatch(projectRoot, patch = {}) {
29
- const { saveConfig, normalizeLaunchMode, normalizeAgentProvider } = require("../config");
30
+ const { loadConfig, saveConfig, normalizeAgentProvider, defaultAgentModelForProvider } = require("../config");
31
+ const { normalizeThinkingLevel } = require("../agents/providers/thinkingLevels");
32
+ const current = loadConfig(projectRoot);
30
33
  const next = {};
31
- if (patch.launch_mode != null || patch.launchMode != null) {
32
- next.launchMode = normalizeLaunchMode(patch.launch_mode || patch.launchMode);
33
- }
34
34
  if (patch.agent_provider != null || patch.agentProvider != null) {
35
35
  next.agentProvider = normalizeAgentProvider(patch.agent_provider || patch.agentProvider);
36
+ if (next.agentProvider !== current.agentProvider) next.agentModel = defaultAgentModelForProvider(next.agentProvider);
37
+ }
38
+ for (const [snake, camel] of [["agent_model", "agentModel"], ["agent_base_url", "agentBaseUrl"], ["agent_api_key", "agentApiKey"]]) {
39
+ if (patch[snake] != null || patch[camel] != null) next[camel] = String(patch[snake] ?? patch[camel]).trim();
40
+ }
41
+ if (next.agentBaseUrl) {
42
+ try {
43
+ const url = new URL(next.agentBaseUrl);
44
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) throw new Error();
45
+ } catch { return { ok: false, error: "API URL must be an http(s) URL without embedded credentials" }; }
36
46
  }
47
+ if (next.agentProvider === "custom" && !(next.agentBaseUrl ?? current.agentBaseUrl)) {
48
+ return { ok: false, error: "Configure the custom API URL first" };
49
+ }
50
+ if (patch.agent_thinking != null || patch.agentThinking != null) {
51
+ next.agentThinking = normalizeThinkingLevel(patch.agent_thinking ?? patch.agentThinking);
52
+ if (!next.agentThinking) return { ok: false, error: "Thinking must be off, low, medium, high, xhigh or max" };
53
+ }
54
+ if (next.agentModel != null && next.agentModel !== current.agentModel) next.agentModelRevision = (Number(current.agentModelRevision) || 0) + 1;
37
55
  if (Object.keys(next).length === 0) {
38
56
  return { ok: false, error: "empty settings patch" };
39
57
  }
40
- saveConfig(projectRoot, next);
41
- return { ok: true, settings: buildSettingsSnapshot({ ...patch, ...next }) };
58
+ if (next.agentProvider && next.agentProvider !== current.agentProvider) {
59
+ next.agentConversationId = `main-${require("crypto").randomUUID()}`;
60
+ }
61
+ const saved = saveConfig(projectRoot, next);
62
+ return { ok: true, providerChanged: current.agentProvider !== saved.agentProvider, settings: buildSettingsSnapshot(loadConfig(projectRoot)) };
42
63
  }
43
64
 
44
65
  module.exports = {
45
- MODE_OPTIONS,
46
66
  PROVIDER_OPTIONS,
47
67
  buildSettingsSnapshot,
48
68
  applySettingsPatch,
@@ -6,8 +6,6 @@
6
6
 
7
7
  const fmt = require("./format");
8
8
 
9
- const EXIT_SUSPEND = 75;
10
-
11
9
  function createToolMergePublisher(publish) {
12
10
  let merge = null;
13
11
  let mergeId = 1;
@@ -58,11 +56,9 @@ function createToolMergePublisher(publish) {
58
56
  beginScope,
59
57
  flush,
60
58
  pushTool,
61
- EXIT_SUSPEND,
62
59
  };
63
60
  }
64
61
 
65
62
  module.exports = {
66
- EXIT_SUSPEND,
67
63
  createToolMergePublisher,
68
64
  };
@@ -95,11 +95,12 @@ function createUiHostServer({
95
95
  const entries = [...pending.entries()];
96
96
  pending.clear();
97
97
  for (let i = 0; i < entries.length; i += 1) {
98
- const [key, env] = entries[i];
98
+ const [, env] = entries[i];
99
99
  try {
100
100
  const ok = client.write(encodeMessage(env));
101
101
  if (ok === false) {
102
- pending.set(key, env);
102
+ // false means this frame was queued, not rejected. Retrying it on
103
+ // drain would resend a large frame forever and starve other panes.
103
104
  for (let j = i + 1; j < entries.length; j += 1) {
104
105
  pending.set(entries[j][0], entries[j][1]);
105
106
  }
@@ -141,12 +142,8 @@ function createUiHostServer({
141
142
  if (ok === false && lossy) {
142
143
  client.__ufooBackpressure = true;
143
144
  ensureDrainHook(client);
144
- let pending = lossyPendingByClient.get(client);
145
- if (!pending) {
146
- pending = new Map();
147
- lossyPendingByClient.set(client, pending);
148
- }
149
- pending.set(lossyKey(envelope), envelope);
145
+ // The socket owns this accepted frame. Only later updates belong
146
+ // in the per-agent pending map until it drains.
150
147
  }
151
148
  } catch {
152
149
  clients.delete(client);
@@ -1,200 +0,0 @@
1
- "use strict";
2
-
3
- const fs = require("fs");
4
- const path = require("path");
5
- const { getUfooPaths } = require("../../coordination/state/paths");
6
- const { redactSecrets } = require("../../runtime/privacy/redactor");
7
-
8
- const LOOP_EVENT_SCHEMA_VERSION = 1;
9
-
10
- function getLoopObservabilityPaths(projectRoot) {
11
- const { agentDir } = getUfooPaths(projectRoot);
12
- return {
13
- eventsFile: path.join(agentDir, "ufoo-agent.loop-events.jsonl"),
14
- auditFile: path.join(agentDir, "ufoo-agent.audit.jsonl"),
15
- };
16
- }
17
-
18
- function getShadowObservabilityPaths(projectRoot, now = new Date()) {
19
- const { ufooDir } = getUfooPaths(projectRoot);
20
- const stamp = now.toISOString().slice(0, 10);
21
- return {
22
- shadowDir: path.join(ufooDir, "shadow"),
23
- diffFile: path.join(ufooDir, "shadow", `diff-${stamp}.jsonl`),
24
- };
25
- }
26
-
27
- function appendJsonLine(file, payload) {
28
- fs.mkdirSync(path.dirname(file), { recursive: true });
29
- fs.appendFileSync(file, `${JSON.stringify(redactSecrets(payload))}\n`, "utf8");
30
- }
31
-
32
- function appendShadowDiff(projectRoot, payload = {}, now = new Date()) {
33
- if (!projectRoot) return null;
34
- const { diffFile } = getShadowObservabilityPaths(projectRoot, now);
35
- appendJsonLine(diffFile, {
36
- schema_version: LOOP_EVENT_SCHEMA_VERSION,
37
- ts: now.toISOString(),
38
- shadow_only: true,
39
- ...payload,
40
- });
41
- return diffFile;
42
- }
43
-
44
- function createLoopObserver({ projectRoot, enabled = true, defaults = {} } = {}) {
45
- const paths = projectRoot ? getLoopObservabilityPaths(projectRoot) : null;
46
- const baseDefaults = defaults && typeof defaults === "object" ? { ...defaults } : {};
47
-
48
- function emit(event, payload = {}) {
49
- if (!enabled || !paths) return;
50
- appendJsonLine(paths.eventsFile, {
51
- schema_version: LOOP_EVENT_SCHEMA_VERSION,
52
- ts: new Date().toISOString(),
53
- event: String(event || "").trim() || "unknown",
54
- ...baseDefaults,
55
- ...payload,
56
- });
57
- }
58
-
59
- function audit(payload = {}) {
60
- if (!enabled || !paths) return;
61
- appendJsonLine(paths.auditFile, {
62
- schema_version: LOOP_EVENT_SCHEMA_VERSION,
63
- ts: new Date().toISOString(),
64
- ...baseDefaults,
65
- ...payload,
66
- });
67
- }
68
-
69
- return {
70
- emit,
71
- audit,
72
- paths,
73
- };
74
- }
75
-
76
- function readRecentLoopSummary(projectRoot, options = {}) {
77
- if (!projectRoot) return null;
78
- const { eventsFile } = getLoopObservabilityPaths(projectRoot);
79
- if (!fs.existsSync(eventsFile)) return null;
80
-
81
- const maxLines = Number.isFinite(options.maxLines) && options.maxLines > 0
82
- ? Math.floor(options.maxLines)
83
- : 400;
84
-
85
- let rows = [];
86
- try {
87
- rows = fs.readFileSync(eventsFile, "utf8")
88
- .split(/\r?\n/)
89
- .filter(Boolean)
90
- .slice(-maxLines)
91
- .map((line) => {
92
- try {
93
- return JSON.parse(line);
94
- } catch {
95
- return null;
96
- }
97
- })
98
- .filter(Boolean);
99
- } catch {
100
- return null;
101
- }
102
-
103
- if (rows.length === 0) return null;
104
-
105
- let startIndex = 0;
106
- let endIndex = rows.length;
107
- let terminalIndex = -1;
108
- for (let i = rows.length - 1; i >= 0; i -= 1) {
109
- if (rows[i] && rows[i].event === "loop_terminal") {
110
- terminalIndex = i;
111
- endIndex = i + 1;
112
- break;
113
- }
114
- }
115
- if (terminalIndex >= 0) {
116
- for (let i = terminalIndex - 1; i >= 0; i -= 1) {
117
- if (rows[i] && rows[i].event === "loop_terminal") {
118
- startIndex = i + 1;
119
- break;
120
- }
121
- }
122
- }
123
-
124
- const segment = rows.slice(startIndex, endIndex);
125
- if (segment.length === 0) return null;
126
-
127
- const toolCounts = new Map();
128
- const summary = {
129
- status: terminalIndex >= 0 ? "completed" : "in_progress",
130
- event_count: segment.length,
131
- model_calls: 0,
132
- rounds: 0,
133
- tool_calls: 0,
134
- input_tokens: 0,
135
- output_tokens: 0,
136
- cache_read_tokens: 0,
137
- cache_creation_tokens: 0,
138
- cache_semistatic_hit: 0,
139
- cache_semistatic_miss: 0,
140
- memory_prefix_tokens: 0,
141
- dynamic_memory_tokens: 0,
142
- total_tokens: 0,
143
- total_latency_ms: 0,
144
- first_token_ms: 0,
145
- terminal_reason: "",
146
- started_at: "",
147
- ended_at: "",
148
- tools: [],
149
- };
150
-
151
- for (const row of segment) {
152
- if (!summary.started_at && row.ts) summary.started_at = String(row.ts);
153
- if (row.ts) summary.ended_at = String(row.ts);
154
- if (row.event === "model_call") {
155
- summary.model_calls += 1;
156
- summary.rounds = Math.max(summary.rounds, Number(row.round) || 0);
157
- summary.input_tokens += Number(row.input_tokens) || 0;
158
- summary.output_tokens += Number(row.output_tokens) || 0;
159
- summary.cache_read_tokens += Number(row.cache_read_tokens) || 0;
160
- summary.cache_creation_tokens += Number(row.cache_creation_tokens) || 0;
161
- summary.cache_semistatic_hit += Number(row.cache_semistatic_hit) || 0;
162
- summary.cache_semistatic_miss += Number(row.cache_semistatic_miss) || 0;
163
- summary.memory_prefix_tokens += Number(row.memory_prefix_tokens) || 0;
164
- summary.dynamic_memory_tokens += Number(row.dynamic_memory_tokens) || 0;
165
- summary.total_latency_ms += Number(row.latency_ms) || 0;
166
- summary.first_token_ms += Number(row.first_token_ms) || 0;
167
- } else if (row.event === "tool_call") {
168
- summary.tool_calls += 1;
169
- const name = String(row.tool_name || "").trim() || "unknown";
170
- toolCounts.set(name, (toolCounts.get(name) || 0) + 1);
171
- summary.dynamic_memory_tokens += Number(row.dynamic_memory_tokens) || 0;
172
- } else if (row.event === "loop_terminal") {
173
- summary.terminal_reason = String(row.terminal_reason || "").trim();
174
- if ((Number(row.rounds) || 0) > 0) summary.rounds = Number(row.rounds) || summary.rounds;
175
- if ((Number(row.tool_calls) || 0) >= 0) summary.tool_calls = Number(row.tool_calls) || summary.tool_calls;
176
- if ((Number(row.total_tokens) || 0) > 0) summary.total_tokens = Number(row.total_tokens) || 0;
177
- if ((Number(row.total_latency_ms) || 0) > 0) summary.total_latency_ms = Number(row.total_latency_ms) || 0;
178
- if ((Number(row.dynamic_memory_tokens) || 0) > 0) summary.dynamic_memory_tokens = Number(row.dynamic_memory_tokens) || summary.dynamic_memory_tokens;
179
- }
180
- }
181
-
182
- if (summary.total_tokens <= 0) {
183
- summary.total_tokens = summary.input_tokens + summary.output_tokens;
184
- }
185
-
186
- summary.tools = Array.from(toolCounts.entries())
187
- .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
188
- .map(([name, count]) => ({ name, count }));
189
-
190
- return summary;
191
- }
192
-
193
- module.exports = {
194
- LOOP_EVENT_SCHEMA_VERSION,
195
- appendShadowDiff,
196
- getLoopObservabilityPaths,
197
- getShadowObservabilityPaths,
198
- createLoopObserver,
199
- readRecentLoopSummary,
200
- };