u-foo 4.0.0 → 4.0.2
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.
- package/OBSERVABILITY.md +65 -0
- package/README.md +90 -30
- package/README.zh-CN.md +76 -26
- package/SKILLS/ufoo/SKILL.md +25 -1
- package/SKILLS/ufoo-bus/SKILL.md +25 -2
- package/bin/ucode.js +4 -0
- package/bin/ufoo.js +3 -3
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/dist/tui/darwin-x64/ufoo-tui +0 -0
- package/dist/tui/linux-arm64/ufoo-tui +0 -0
- package/dist/tui/linux-x64/ufoo-tui +0 -0
- package/package.json +6 -6
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/capabilities/agentManagement/service.js +40 -13
- package/src/agents/capabilities/coordination/index.js +1 -1
- package/src/agents/capabilities/taskReports/index.js +1 -1
- package/src/agents/controller/controllerToolExecutor.js +36 -20
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +90 -56
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +38 -29
- package/src/agents/launch/launcherReadiness.js +35 -0
- package/src/agents/launch/notifier.js +2 -2
- package/src/agents/launch/ptyWrapper.js +5 -2
- package/src/agents/launch/readyDetector.js +2 -2
- package/src/agents/profiles/main.js +1 -1
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +23 -7
- package/src/agents/prompts/mainAgent.js +11 -2
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/ufoo.js +11 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +3 -0
- package/src/agents/providers/claudeThreadProvider.js +3 -2
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +23 -2
- package/src/agents/providers/codexThreadProvider.js +15 -6
- package/src/agents/providers/credentials/index.js +2 -0
- package/src/agents/providers/directAuthStatus.js +1 -1
- package/src/agents/providers/index.js +1 -1
- package/src/agents/providers/modelSettings.js +34 -0
- package/src/agents/providers/modelsCatalog.js +379 -0
- package/src/agents/providers/nativeTransport.js +58 -40
- package/src/agents/providers/runtimeConfig.js +10 -8
- package/src/agents/providers/thinkingLevels.js +10 -36
- package/src/agents/providers/transports/responsesProtocol.js +11 -6
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +2 -1
- package/src/agents/runtime/core/agentLoop.js +99 -18
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/createAgentRuntime.js +16 -4
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/app/chat/ChatController.js +26 -53
- package/src/app/chat/agentDirectory.js +1 -16
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +93 -285
- package/src/app/chat/commands.js +32 -45
- package/src/app/chat/daemonMessageRouter.js +0 -45
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +7 -33
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/multiWindow/paneManager.js +10 -3
- package/src/app/chat/streamState.js +0 -4
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/run.js +42 -3
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +18 -13
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/assembler.js +7 -8
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/internalThread.js +10 -3
- package/src/code/launcher/ucode.js +1 -1
- package/src/code/launcher/ucodeBootstrap.js +1 -1
- package/src/code/modelCommand.js +11 -35
- package/src/code/nativeRunner.js +55 -17
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/repl.js +4 -11
- package/src/code/sessionStore.js +3 -3
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/toolBudget.js +1 -17
- package/src/config.js +22 -72
- package/src/coordination/bus/index.js +12 -3
- package/src/coordination/bus/inject.js +2 -2
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +1 -1
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/state/workspaceAccess.js +1 -1
- package/src/orchestration/controller/index.js +1 -8
- package/src/orchestration/controller/launchRouting.js +1 -1
- package/src/orchestration/solo/commands.js +3 -1
- package/src/runtime/contracts/agentMode.js +11 -2
- package/src/runtime/contracts/uiProtocol.js +18 -19
- package/src/runtime/daemon/agentHost.js +57 -25
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +1 -1
- package/src/runtime/daemon/controlPlaneService.js +1 -1
- package/src/runtime/daemon/groupOrchestrator.js +20 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +19 -44
- package/src/runtime/daemon/mcpHttpServer.js +39 -10
- package/src/runtime/daemon/mcpServer.js +1 -1
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +46 -23
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -589
- package/src/runtime/daemon/status.js +5 -6
- package/src/tools/controllerSchemas.js +6 -2
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/registry.js +4 -0
- package/src/tools/schemaFixtures.js +26 -2
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +1 -1
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +1 -4
- package/src/ui/format/index.js +14 -10
- package/src/ui/format/loopSummary.js +50 -0
- package/src/ui/format/markdownRenderer.js +3 -4
- package/src/ui/rustChatHost.js +191 -206
- package/src/ui/rustMultiSession.js +77 -36
- package/src/ui/rustUcodeHost.js +6 -1
- package/src/ui/settingsBridge.js +33 -16
- package/src/ui/toolMergeBridge.js +0 -4
- package/src/ui/uiHostServer.js +5 -8
- package/src/agents/controller/loopObservability.js +0 -200
- package/src/agents/controller/loopRuntime.js +0 -336
- package/src/agents/controller/ufooAgent.js +0 -830
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/controllerJsonTransport.js +0 -28
- package/src/agents/providers/upstreamTransport.js +0 -698
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- package/src/coordination/history/controllerSummary.js +0 -23
- package/src/orchestration/controller/flags.js +0 -167
- package/src/orchestration/controller/gateRouter.js +0 -211
- package/src/orchestration/controller/routerFastPath.js +0 -22
- package/src/orchestration/controller/routerFinalize.js +0 -222
- package/src/orchestration/controller/shadowGuard.js +0 -280
- package/src/runtime/daemon/executionPaths.js +0 -30
- package/src/runtime/daemon/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* In-process split-pane session for the Rust TUI host.
|
|
5
5
|
*
|
|
6
|
-
* Both kinds use Tab to cycle focus and Esc to return focus to chat,
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Both kinds use Tab to cycle focus and Esc / Ctrl+C to return focus to chat,
|
|
7
|
+
* then close the split. Only Ctrl+C exits the application at the root.
|
|
8
|
+
* Window modes are main, side and multi, including when no children exist.
|
|
9
|
+
* They share draw and the multi.* pane wire:
|
|
10
|
+
* - "multi" — all internal agents
|
|
9
11
|
* - "side" — internal-only activate; single locked agent on the right
|
|
10
|
-
* (
|
|
12
|
+
* (shares its pane renderer with multi)
|
|
11
13
|
*
|
|
12
14
|
* The Rust TUI owns TTY / layout / focus. Node owns internal pane buffers
|
|
13
15
|
* and ships bounded, lossy `multi.pane.frame` events.
|
|
@@ -73,6 +75,7 @@ function createRustMultiSession(options = {}) {
|
|
|
73
75
|
let rev = 0;
|
|
74
76
|
let viewportRev = 0;
|
|
75
77
|
let focus = { target: "chat", agent_id: "" };
|
|
78
|
+
let lastActiveAgentId = "";
|
|
76
79
|
const paneSizes = new Map();
|
|
77
80
|
const paneMeta = new Map();
|
|
78
81
|
const dirty = new Set();
|
|
@@ -139,8 +142,12 @@ function createRustMultiSession(options = {}) {
|
|
|
139
142
|
if (!surfaces.has(agentId)) {
|
|
140
143
|
const surface = createAgentSurface();
|
|
141
144
|
const opts = ensurePaneMeta(agentId);
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
if (Array.isArray(opts.initialEntries)) {
|
|
146
|
+
surface.apply("transcript.reset", { entries: opts.initialEntries });
|
|
147
|
+
} else {
|
|
148
|
+
const initial = (opts.initialLines || []).join("\n");
|
|
149
|
+
if (initial) surface.apply("transcript.append", { kind: "meta", text: initial });
|
|
150
|
+
}
|
|
144
151
|
surfaces.set(agentId, { surface, seq: 0, structured: false });
|
|
145
152
|
}
|
|
146
153
|
return surfaces.get(agentId);
|
|
@@ -195,15 +202,27 @@ function createRustMultiSession(options = {}) {
|
|
|
195
202
|
function rememberDraft(agentId) {
|
|
196
203
|
const pane = paneManager && paneManager.getPane(agentId);
|
|
197
204
|
if (pane && pane.mode === "internal") {
|
|
198
|
-
internalDrafts.set(agentId, { initialInput: pane.internalInput, initialCursor: pane.internalCursor,
|
|
205
|
+
internalDrafts.set(agentId, { initialInput: pane.internalInput, initialCursor: pane.internalCursor,
|
|
206
|
+
inputRevision: pane.inputRevision, scrollOffset: pane.scrollOffset });
|
|
199
207
|
}
|
|
200
208
|
}
|
|
201
209
|
|
|
202
210
|
function paneAgentIds() {
|
|
203
|
-
|
|
204
|
-
|
|
211
|
+
const ids = listInternalAgentIds();
|
|
212
|
+
if (kind === KIND_SIDE) {
|
|
213
|
+
const selected = lockedAgentIds.find((id) => ids.includes(id)) || preferredAgentId(ids);
|
|
214
|
+
lockedAgentIds = selected ? [selected] : [];
|
|
215
|
+
return lockedAgentIds;
|
|
205
216
|
}
|
|
206
|
-
return
|
|
217
|
+
return ids;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function preferredAgentId(ids = listInternalAgentIds()) {
|
|
221
|
+
return ids.includes(lastActiveAgentId) ? lastActiveAgentId : ids[0] || "";
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function getMode() {
|
|
225
|
+
return active ? kind : "main";
|
|
207
226
|
}
|
|
208
227
|
|
|
209
228
|
function currentPanesDesc() {
|
|
@@ -292,6 +311,7 @@ function createRustMultiSession(options = {}) {
|
|
|
292
311
|
};
|
|
293
312
|
payload.input = String(pane.internalInput || "");
|
|
294
313
|
payload.cursor = Number.isFinite(pane.internalCursor) ? pane.internalCursor : 0;
|
|
314
|
+
payload.input_revision = pane.inputRevision || 0;
|
|
295
315
|
const emit = typeof publishLossy === "function" ? publishLossy : publish;
|
|
296
316
|
try { emit("multi.pane.frame", payload); } catch {}
|
|
297
317
|
}
|
|
@@ -315,6 +335,11 @@ function createRustMultiSession(options = {}) {
|
|
|
315
335
|
return paneManager;
|
|
316
336
|
}
|
|
317
337
|
|
|
338
|
+
function publishFrames() {
|
|
339
|
+
if (!active || !paneManager) return;
|
|
340
|
+
for (const id of paneManager.getAgentIds()) publishFrame(id);
|
|
341
|
+
}
|
|
342
|
+
|
|
318
343
|
function syncAgents() {
|
|
319
344
|
const live = new Set(listInternalAgentIds());
|
|
320
345
|
for (const id of surfaces.keys()) if (!live.has(id)) {
|
|
@@ -351,8 +376,8 @@ function createRustMultiSession(options = {}) {
|
|
|
351
376
|
changed = true;
|
|
352
377
|
}
|
|
353
378
|
}
|
|
354
|
-
// Only republish
|
|
355
|
-
//
|
|
379
|
+
// Only republish window.set when membership actually changes. Spamming
|
|
380
|
+
// window.set on every daemon status tick forced Rust to bump viewport_rev
|
|
356
381
|
// and drop in-flight pane frames (focus switching felt stuck).
|
|
357
382
|
if (active && changed) {
|
|
358
383
|
rev += 1;
|
|
@@ -369,10 +394,10 @@ function createRustMultiSession(options = {}) {
|
|
|
369
394
|
focus = { target: "chat", agent_id: "" };
|
|
370
395
|
}
|
|
371
396
|
}
|
|
372
|
-
publish("
|
|
397
|
+
publish("window.set", {
|
|
373
398
|
session_id: sessionId,
|
|
374
399
|
active,
|
|
375
|
-
|
|
400
|
+
mode: getMode(),
|
|
376
401
|
rev,
|
|
377
402
|
panes,
|
|
378
403
|
focus,
|
|
@@ -383,28 +408,22 @@ function createRustMultiSession(options = {}) {
|
|
|
383
408
|
/**
|
|
384
409
|
* @param {object} [options]
|
|
385
410
|
* @param {"multi"|"side"} [options.kind]
|
|
386
|
-
* @param {string[]} [options.agentIds] —
|
|
411
|
+
* @param {string[]} [options.agentIds] — optional selected child for kind "side"
|
|
387
412
|
* @param {{ target?: string, agent_id?: string }} [options.focus]
|
|
388
413
|
*/
|
|
389
414
|
function start(options = {}) {
|
|
390
415
|
const nextKind = options.kind === KIND_SIDE ? KIND_SIDE : KIND_MULTI;
|
|
391
416
|
if (active && kind === nextKind && nextKind === KIND_MULTI) {
|
|
392
|
-
return { ok: true, session_id: sessionId,
|
|
417
|
+
return { ok: true, session_id: sessionId, mode: getMode() };
|
|
393
418
|
}
|
|
394
419
|
let ids;
|
|
395
420
|
if (nextKind === KIND_SIDE) {
|
|
396
421
|
const raw = Array.isArray(options.agentIds) ? options.agentIds : [];
|
|
397
|
-
const id = String(raw[0] || "").trim();
|
|
398
|
-
if (!id) {
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
if (!isInternalAgentMeta(getAgentMeta(id))) return { ok: false, error: "Dashboard supports internal agents only" };
|
|
402
|
-
ids = [id];
|
|
422
|
+
const id = String(raw[0] || "").trim() || preferredAgentId();
|
|
423
|
+
if (id && !listInternalAgentIds().includes(id)) return { ok: false, error: "Dashboard supports active internal agents only" };
|
|
424
|
+
ids = id ? [id] : [];
|
|
403
425
|
} else {
|
|
404
426
|
ids = normalizeAgentList(getActiveAgents).filter((id) => isInternalAgentMeta(getAgentMeta(id)));
|
|
405
|
-
if (ids.length === 0) {
|
|
406
|
-
return { ok: false, error: "No active agents for multi-window mode" };
|
|
407
|
-
}
|
|
408
427
|
}
|
|
409
428
|
|
|
410
429
|
const previousFocus = active ? { ...focus } : null;
|
|
@@ -423,11 +442,12 @@ function createRustMultiSession(options = {}) {
|
|
|
423
442
|
target: "agent",
|
|
424
443
|
agent_id: String(focusOpt.agent_id).trim(),
|
|
425
444
|
};
|
|
426
|
-
} else if (nextKind === KIND_SIDE) {
|
|
445
|
+
} else if (!focusOpt && nextKind === KIND_SIDE && ids.length) {
|
|
427
446
|
focus = { target: "agent", agent_id: ids[0] };
|
|
428
447
|
} else {
|
|
429
448
|
focus = { target: "chat", agent_id: "" };
|
|
430
449
|
}
|
|
450
|
+
if (focus.target === "agent") lastActiveAgentId = focus.agent_id;
|
|
431
451
|
paneSizes.clear();
|
|
432
452
|
paneMeta.clear();
|
|
433
453
|
dirty.clear();
|
|
@@ -435,12 +455,14 @@ function createRustMultiSession(options = {}) {
|
|
|
435
455
|
ensurePaneManager();
|
|
436
456
|
syncAgents();
|
|
437
457
|
publishSet();
|
|
438
|
-
|
|
458
|
+
publishFrames();
|
|
459
|
+
return { ok: true, session_id: sessionId, mode: getMode() };
|
|
439
460
|
}
|
|
440
461
|
|
|
441
462
|
function stop({ clearDrafts = false } = {}) {
|
|
442
463
|
closeSurfaceObservation();
|
|
443
464
|
if (clearDrafts) {
|
|
465
|
+
lastActiveAgentId = "";
|
|
444
466
|
internalDrafts.clear(); surfaces.clear(); replayedAgents.clear();
|
|
445
467
|
surfaceReader = null; observationRoot = "";
|
|
446
468
|
}
|
|
@@ -459,10 +481,10 @@ function createRustMultiSession(options = {}) {
|
|
|
459
481
|
paneMeta.clear();
|
|
460
482
|
lastEmitAt.clear();
|
|
461
483
|
active = false;
|
|
462
|
-
publish("
|
|
484
|
+
publish("window.set", {
|
|
463
485
|
session_id: sessionId,
|
|
464
486
|
active: false,
|
|
465
|
-
|
|
487
|
+
mode: "main",
|
|
466
488
|
rev: rev + 1,
|
|
467
489
|
panes: [],
|
|
468
490
|
focus: { target: "chat", agent_id: "" },
|
|
@@ -476,13 +498,16 @@ function createRustMultiSession(options = {}) {
|
|
|
476
498
|
focus = { target: "chat", agent_id: "" };
|
|
477
499
|
}
|
|
478
500
|
|
|
479
|
-
function setLayout(layout = "
|
|
480
|
-
|
|
501
|
+
function setLayout(layout = "cycle", agentId = "") {
|
|
502
|
+
const mode = layout === "cycle"
|
|
503
|
+
? getMode() === "main" ? "side" : getMode() === "side" ? "multi" : "main"
|
|
504
|
+
: layout;
|
|
505
|
+
if (mode === "main") {
|
|
481
506
|
stop();
|
|
482
|
-
return { ok: true,
|
|
507
|
+
return { ok: true, mode: "main" };
|
|
483
508
|
}
|
|
484
|
-
if (
|
|
485
|
-
if (
|
|
509
|
+
if (mode === "multi") return start({ kind: KIND_MULTI });
|
|
510
|
+
if (mode === "side") return start({ kind: KIND_SIDE, agentIds: [agentId], focus: { ...focus } });
|
|
486
511
|
return { ok: false, error: "unknown layout" };
|
|
487
512
|
}
|
|
488
513
|
|
|
@@ -520,6 +545,19 @@ function createRustMultiSession(options = {}) {
|
|
|
520
545
|
}
|
|
521
546
|
const agentId = String(payload.agent_id || "").trim();
|
|
522
547
|
if (!agentId) return { ok: false, error: "missing agent_id" };
|
|
548
|
+
const pane = paneManager.getPane(agentId);
|
|
549
|
+
if (!pane || !listInternalAgentIds().includes(agentId)) return { ok: false, error: "Unknown internal agent" };
|
|
550
|
+
if (typeof payload.input === "string") {
|
|
551
|
+
const revision = Number(payload.input_revision);
|
|
552
|
+
if (!Number.isSafeInteger(revision) || revision < 1) return { ok: false, error: "invalid input_revision" };
|
|
553
|
+
if (revision <= (pane.inputRevision || 0)) return { ok: true, stale: true };
|
|
554
|
+
pane.inputRevision = revision;
|
|
555
|
+
pane.internalInput = payload.input;
|
|
556
|
+
pane.internalCursor = Math.max(0, Math.min(payload.input.length, Math.trunc(Number(payload.cursor) || 0)));
|
|
557
|
+
if (payload.submit === true) paneManager.sendInputToAgent(agentId, "\r");
|
|
558
|
+
markDirty(agentId);
|
|
559
|
+
return { ok: true, agent_id: agentId, input_revision: revision };
|
|
560
|
+
}
|
|
523
561
|
let data = "";
|
|
524
562
|
if (payload.data_encoding === "base64" && typeof payload.data === "string") {
|
|
525
563
|
try { data = Buffer.from(payload.data, "base64").toString("utf8"); } catch { data = ""; }
|
|
@@ -555,6 +593,7 @@ function createRustMultiSession(options = {}) {
|
|
|
555
593
|
const agentId = String(payload.agent_id || "").trim();
|
|
556
594
|
if (target === "agent" && agentId && paneManager.getPane(agentId)) {
|
|
557
595
|
focus = { target, agent_id: agentId };
|
|
596
|
+
lastActiveAgentId = agentId;
|
|
558
597
|
try { paneManager.setFocused(agentId); } catch {}
|
|
559
598
|
} else {
|
|
560
599
|
focus = { target: "chat", agent_id: "" };
|
|
@@ -597,10 +636,10 @@ function createRustMultiSession(options = {}) {
|
|
|
597
636
|
function isSideKind() { return active && kind === KIND_SIDE; }
|
|
598
637
|
|
|
599
638
|
function getSnapshot() {
|
|
600
|
-
if (!active) return { active: false,
|
|
639
|
+
if (!active) return { active: false, mode: "main" };
|
|
601
640
|
return {
|
|
602
641
|
active: true,
|
|
603
|
-
|
|
642
|
+
mode: getMode(),
|
|
604
643
|
session_id: sessionId,
|
|
605
644
|
rev,
|
|
606
645
|
viewport_rev: viewportRev,
|
|
@@ -636,6 +675,7 @@ function createRustMultiSession(options = {}) {
|
|
|
636
675
|
return {
|
|
637
676
|
start,
|
|
638
677
|
setLayout,
|
|
678
|
+
getMode,
|
|
639
679
|
stop,
|
|
640
680
|
isActive,
|
|
641
681
|
getSessionId,
|
|
@@ -654,6 +694,7 @@ function createRustMultiSession(options = {}) {
|
|
|
654
694
|
writeToPane,
|
|
655
695
|
listInternalAgentIds,
|
|
656
696
|
acceptEvent,
|
|
697
|
+
publishFrames,
|
|
657
698
|
hasStructuredEvents: (id) => Boolean(surfaces.get(id)?.structured),
|
|
658
699
|
handleExpand,
|
|
659
700
|
};
|
package/src/ui/rustUcodeHost.js
CHANGED
|
@@ -208,6 +208,7 @@ async function runUcodeRust(props = {}) {
|
|
|
208
208
|
const backgroundTasks = new Map();
|
|
209
209
|
let backgroundSeq = 0;
|
|
210
210
|
let requestExit = false;
|
|
211
|
+
let clientReady = false;
|
|
211
212
|
const MARKDOWN_LOG_KINDS = new Set(["assistant", "error"]);
|
|
212
213
|
const surface = createAgentSurface({ maxEntries: 4000 });
|
|
213
214
|
const controller = createUcodeController({
|
|
@@ -761,6 +762,10 @@ async function runUcodeRust(props = {}) {
|
|
|
761
762
|
socket.write(encodeMessage(snap));
|
|
762
763
|
publishPendingInteraction();
|
|
763
764
|
publishPlan();
|
|
765
|
+
if (!clientReady) {
|
|
766
|
+
clientReady = true;
|
|
767
|
+
if (typeof props.onReady === "function") props.onReady();
|
|
768
|
+
}
|
|
764
769
|
},
|
|
765
770
|
async onCommand(cmd) {
|
|
766
771
|
const name = String(cmd.name || "");
|
|
@@ -793,7 +798,7 @@ async function runUcodeRust(props = {}) {
|
|
|
793
798
|
state: props.state || {},
|
|
794
799
|
selfSubscriberId,
|
|
795
800
|
remoteModels,
|
|
796
|
-
limit: 20,
|
|
801
|
+
limit: Math.max(20, remoteModels.length + 1),
|
|
797
802
|
});
|
|
798
803
|
publish("completions.set", { items });
|
|
799
804
|
return { ok: true, count: items.length };
|
package/src/ui/settingsBridge.js
CHANGED
|
@@ -1,51 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Dashboard settings snapshots never carry provider credentials.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const MODE_OPTIONS = Object.freeze(["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
17
|
const { normalizeAgentProvider } = require("../config");
|
|
18
|
-
const launchMode = "internal";
|
|
19
18
|
const agentProvider = normalizeAgentProvider(settings.agentProvider || "codex-cli");
|
|
20
19
|
return {
|
|
21
|
-
launch_mode: launchMode,
|
|
22
20
|
agent_provider: agentProvider,
|
|
23
|
-
|
|
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 {
|
|
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
|
-
if (normalizeLaunchMode(patch.launch_mode || patch.launchMode) !== "internal") {
|
|
33
|
-
return { ok: false, error: "ufoo dashboard uses internal agents only" };
|
|
34
|
-
}
|
|
35
|
-
next.launchMode = "internal";
|
|
36
|
-
}
|
|
37
34
|
if (patch.agent_provider != null || patch.agentProvider != null) {
|
|
38
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" }; }
|
|
39
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;
|
|
40
55
|
if (Object.keys(next).length === 0) {
|
|
41
56
|
return { ok: false, error: "empty settings patch" };
|
|
42
57
|
}
|
|
43
|
-
|
|
44
|
-
|
|
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)) };
|
|
45
63
|
}
|
|
46
64
|
|
|
47
65
|
module.exports = {
|
|
48
|
-
MODE_OPTIONS,
|
|
49
66
|
PROVIDER_OPTIONS,
|
|
50
67
|
buildSettingsSnapshot,
|
|
51
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
|
};
|
package/src/ui/uiHostServer.js
CHANGED
|
@@ -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 [
|
|
98
|
+
const [, env] = entries[i];
|
|
99
99
|
try {
|
|
100
100
|
const ok = client.write(encodeMessage(env));
|
|
101
101
|
if (ok === false) {
|
|
102
|
-
|
|
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
|
-
|
|
145
|
-
|
|
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
|
-
};
|