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.
- package/OBSERVABILITY.md +65 -0
- package/README.md +238 -21
- package/README.zh-CN.md +165 -20
- package/SKILLS/ufoo/SKILL.md +40 -4
- package/SKILLS/ufoo-bus/SKILL.md +46 -3
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +6 -4
- 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 +14 -7
- package/scripts/postinstall-skills.js +53 -0
- package/scripts/postinstall.js +11 -16
- package/scripts/smoke-native-messages.js +214 -0
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/activity/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +140 -0
- package/src/agents/capabilities/agentRouting/index.js +4 -0
- package/src/agents/capabilities/coding/index.js +32 -0
- package/src/agents/capabilities/coordination/index.js +37 -0
- package/src/agents/capabilities/globalRouting/index.js +5 -0
- package/src/agents/capabilities/groups/index.js +3 -0
- package/src/agents/capabilities/index.js +25 -0
- package/src/agents/capabilities/planning/index.js +123 -0
- package/src/agents/capabilities/planning/main.js +28 -0
- package/src/agents/capabilities/projectDiscovery/index.js +3 -0
- package/src/agents/capabilities/scheduling/index.js +3 -0
- package/src/agents/capabilities/sharedMemory/index.js +4 -0
- package/src/agents/capabilities/skills/index.js +12 -0
- package/src/agents/capabilities/taskExecution/index.js +3 -0
- package/src/agents/capabilities/taskReports/index.js +6 -0
- package/src/agents/controller/controllerToolExecutor.js +40 -22
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +181 -76
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +96 -14
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +15 -20
- package/src/agents/launch/readyDetector.js +28 -14
- package/src/agents/profiles/coding.js +6 -0
- package/src/agents/profiles/globalRouter.js +2 -0
- package/src/agents/profiles/main.js +5 -0
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +32 -6
- package/src/agents/prompts/mainAgent.js +48 -0
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +14 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +9 -1
- package/src/agents/providers/claudeThreadProvider.js +47 -4
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +68 -7
- package/src/agents/providers/codexThreadProvider.js +18 -8
- package/src/agents/providers/credentials/claude.js +10 -3
- 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 +1146 -0
- package/src/agents/providers/runtimeConfig.js +188 -0
- package/src/agents/providers/thinkingLevels.js +106 -0
- package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
- package/src/agents/providers/transports/index.js +10 -0
- package/src/agents/providers/transports/openaiChatTransport.js +117 -0
- package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
- package/src/agents/providers/transports/responsesProtocol.js +504 -0
- package/src/agents/providers/transports/systemBlocks.js +16 -0
- package/src/agents/providers/transports/transportContract.js +50 -0
- package/src/agents/providers/transports/visionBlocks.js +151 -0
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +127 -0
- package/src/agents/runtime/context/sessionJournal.js +360 -0
- package/src/agents/runtime/context/sessionStore.js +57 -0
- package/src/agents/runtime/core/agentLoop.js +351 -0
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/core/stableJson.js +29 -0
- package/src/agents/runtime/core/toolLoopGuard.js +55 -0
- package/src/agents/runtime/createAgentRuntime.js +259 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/agents/runtime/tasks/resourceLease.js +66 -0
- package/src/agents/runtime/tasks/scheduler.js +73 -0
- package/src/agents/runtime/tools/registry.js +57 -0
- package/src/app/chat/ChatController.js +29 -45
- package/src/app/chat/agentDirectory.js +9 -18
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +111 -313
- package/src/app/chat/commands.js +39 -45
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -48
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +21 -35
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +91 -164
- package/src/app/chat/streamState.js +3 -7
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/busCoreCommands.js +9 -0
- package/src/app/cli/features/doctor.js +33 -0
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/features/skills.js +16 -4
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +82 -42
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +34 -17
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +9 -9
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +107 -0
- 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 +104 -2697
- package/src/code/protocol/faultHarness.js +2 -88
- package/src/code/protocol/materialize.js +2 -105
- package/src/code/protocol/toolCallLedger.js +5 -215
- package/src/code/providers/anthropicMessagesTransport.js +2 -118
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/providers/openaiChatTransport.js +2 -114
- package/src/code/providers/openaiResponsesTransport.js +2 -117
- package/src/code/providers/responsesProtocol.js +2 -497
- package/src/code/providers/transportContract.js +2 -48
- package/src/code/providers/visionBlocks.js +2 -149
- package/src/code/repl.js +2 -11
- package/src/code/sessionStore.js +27 -99
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/thinkingLevels.js +1 -130
- package/src/code/toolBudget.js +1 -17
- package/src/code/toolLoopGuard.js +3 -49
- package/src/code/tools/artifactRead.js +1 -1
- package/src/code/tools/executor.js +373 -0
- package/src/code/tools/specs.js +312 -0
- package/src/config.js +95 -131
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +14 -9
- package/src/coordination/bus/inject.js +15 -7
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +8 -4
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/memory/index.js +5 -21
- package/src/coordination/report/store.js +103 -83
- package/src/coordination/state/agentsStore.js +57 -3
- package/src/coordination/state/fileLock.js +2 -0
- package/src/coordination/state/workspaceAccess.js +36 -0
- 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 +26 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +20 -17
- package/src/runtime/daemon/agentHost.js +407 -0
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +28 -18
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +21 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +120 -375
- package/src/runtime/daemon/ipcServer.js +32 -10
- package/src/runtime/daemon/mcpConfigure.js +113 -20
- package/src/runtime/daemon/mcpHttpServer.js +27 -5
- package/src/runtime/daemon/mcpServer.js +8 -5
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +68 -40
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -570
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +9 -6
- package/src/runtime/privacy/redactor.js +2 -2
- package/src/runtime/projects/identity.js +2 -1
- package/src/runtime/projects/registry.js +98 -38
- package/src/tools/controllerSchemas.js +28 -0
- package/src/tools/handlers/dispatchMessage.js +5 -2
- package/src/tools/handlers/listAgents.js +3 -1
- package/src/tools/handlers/readBusSummary.js +3 -1
- package/src/tools/handlers/readProjectRegistry.js +29 -2
- package/src/tools/handlers/routeAgent.js +35 -0
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/index.js +1 -0
- package/src/tools/registry.js +6 -0
- package/src/tools/schemaFixtures.js +42 -5
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/tools/tier1/routeAgent.js +2 -2
- package/src/tools/tier2/runtimeCoordination.js +38 -0
- package/src/tools/types.js +2 -0
- package/src/ui/agentPresentation.js +109 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +270 -0
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +9 -15
- 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/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +316 -599
- package/src/ui/rustMultiSession.js +288 -73
- package/src/ui/rustUcodeHost.js +21 -88
- package/src/ui/settingsBridge.js +34 -14
- 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 -472
- package/src/agents/controller/ufooAgent.js +0 -829
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/upstreamTransport.js +0 -689
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentEnter.js +0 -70
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/multiWindow/index.js +0 -310
- package/src/app/chat/multiWindow/paneLayout.js +0 -84
- package/src/app/chat/multiWindow/renderer.js +0 -420
- package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
- package/src/app/chat/multiWindow/vtFrame.js +0 -93
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- 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/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
- package/src/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Presentation state shared by the standalone coding TUI and embedded agents.
|
|
4
|
+
// Providers supply events; this module owns no model, process or terminal.
|
|
5
|
+
const fmt = require("./format");
|
|
6
|
+
const { toolStatus, statusForAgentPhase, planLinesFromItems } = require("./agentPresentation");
|
|
7
|
+
|
|
8
|
+
function createAgentSurface(options = {}) {
|
|
9
|
+
const maxEntries = options.maxEntries || 1000;
|
|
10
|
+
const maxText = options.maxText || 256000;
|
|
11
|
+
let entries = [];
|
|
12
|
+
let sequence = 0;
|
|
13
|
+
let turn = "turn-0";
|
|
14
|
+
let segment = 0;
|
|
15
|
+
let status = "ready";
|
|
16
|
+
let busy = false;
|
|
17
|
+
let usage = "";
|
|
18
|
+
let plan = [];
|
|
19
|
+
let idlePlanHint = "";
|
|
20
|
+
let revision = 0;
|
|
21
|
+
let startedAt = 0;
|
|
22
|
+
let waiting = false;
|
|
23
|
+
let submitted = [];
|
|
24
|
+
let activityOwnsStatus = false;
|
|
25
|
+
let runningTask = false;
|
|
26
|
+
const background = new Map();
|
|
27
|
+
let contextUsage = "";
|
|
28
|
+
const tools = new Map();
|
|
29
|
+
|
|
30
|
+
function bound() {
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
entry.text = String(entry.text || "").slice(-64000);
|
|
33
|
+
entry.detail = String(entry.detail || "").slice(-64000);
|
|
34
|
+
}
|
|
35
|
+
let size = entries.reduce((n, e) => n + e.text.length + e.detail.length, 0);
|
|
36
|
+
while (entries.length > maxEntries || (size > maxText && entries.length > 1)) {
|
|
37
|
+
const removed = entries.shift();
|
|
38
|
+
size -= removed.text.length + removed.detail.length;
|
|
39
|
+
tools.delete(removed.id);
|
|
40
|
+
}
|
|
41
|
+
revision += 1;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function entry(id, kind, text = "", detail = "") {
|
|
45
|
+
let row = entries.find((row) => row.id === id);
|
|
46
|
+
if (!row) {
|
|
47
|
+
row = { id, kind, text, detail, speaker: "", expanded: false };
|
|
48
|
+
entries.push(row);
|
|
49
|
+
}
|
|
50
|
+
return row;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function apply(name, payload = {}) {
|
|
54
|
+
if (name === "transcript.reset") {
|
|
55
|
+
entries = (payload.entries || []).map((row) => ({ detail: "", speaker: "", expanded: false, ...row }));
|
|
56
|
+
tools.clear();
|
|
57
|
+
} else if (name === "transcript.append") {
|
|
58
|
+
const row = payload.entry || payload;
|
|
59
|
+
Object.assign(entry(row.id || `entry-${++sequence}`, row.kind || "system"), row);
|
|
60
|
+
} else if (name === "transcript.patch") {
|
|
61
|
+
const row = entries.find((row) => row.id === payload.id);
|
|
62
|
+
if (row && typeof payload.text === "string") row.text = payload.text;
|
|
63
|
+
} else if (name === "stream.start") {
|
|
64
|
+
busy = true;
|
|
65
|
+
startedAt = Date.now();
|
|
66
|
+
} else if (name === "stream.delta") {
|
|
67
|
+
entry(payload.id || "stream", "assistant").text += String(payload.text || payload.delta || "");
|
|
68
|
+
busy = true;
|
|
69
|
+
if (!startedAt) startedAt = Date.now();
|
|
70
|
+
} else if (name === "thinking.start" || name === "thinking.delta") {
|
|
71
|
+
const row = entry(payload.id || "thinking", "thinking");
|
|
72
|
+
if (name === "thinking.delta") row.text += String(payload.text || "");
|
|
73
|
+
} else if (name === "stream.done") {
|
|
74
|
+
busy = false;
|
|
75
|
+
status = payload.reason === "error" ? "error" : "ready";
|
|
76
|
+
} else if (["tool.start", "tool.result", "tool.group"].includes(name)) {
|
|
77
|
+
const row = entry(payload.id || `tool-${++sequence}`, "tool");
|
|
78
|
+
row.text = String(payload.summary || payload.text || "tool");
|
|
79
|
+
row.detail = String(payload.detail || payload.expanded_text || "");
|
|
80
|
+
if (row.detail && !row.text.includes("Ctrl+O") && row.detail.includes("\n")) row.text += " (Ctrl+O expand)";
|
|
81
|
+
} else if (name === "status.set") {
|
|
82
|
+
status = String(payload.text || "ready");
|
|
83
|
+
if (typeof payload.busy === "boolean") busy = payload.busy;
|
|
84
|
+
if (busy && !startedAt) startedAt = Date.now();
|
|
85
|
+
} else if (name === "usage.set") {
|
|
86
|
+
usage = String(payload.label || payload.text || "");
|
|
87
|
+
} else if (name === "plan.set") {
|
|
88
|
+
plan = (payload.lines || []).map(String);
|
|
89
|
+
idlePlanHint = String(payload.idle_hint || "");
|
|
90
|
+
} else {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
bound();
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function accept(event = {}) {
|
|
98
|
+
const type = event.type;
|
|
99
|
+
if (type === "task_submitted") {
|
|
100
|
+
submitted.push({ message: String(event.message || ""), at: Date.now() });
|
|
101
|
+
waiting = false;
|
|
102
|
+
if (!busy) {
|
|
103
|
+
activityOwnsStatus = false;
|
|
104
|
+
startedAt = Date.now();
|
|
105
|
+
return apply("status.set", { text: "Waiting for agent…", busy: true });
|
|
106
|
+
}
|
|
107
|
+
bound();
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
if (type === "submission_failed") {
|
|
111
|
+
const index = submitted.findIndex((item) => item.message === event.message);
|
|
112
|
+
if (index >= 0) submitted.splice(index, 1);
|
|
113
|
+
apply("transcript.append", { kind: "error", text: event.error });
|
|
114
|
+
return runningTask ? true : apply("status.set", { text: "error", busy: false });
|
|
115
|
+
}
|
|
116
|
+
if (type === "task_started") {
|
|
117
|
+
const queued = submitted.findIndex((item) => item.message === String(event.message || ""));
|
|
118
|
+
if (queued >= 0) submitted.splice(queued, 1);
|
|
119
|
+
activityOwnsStatus = false;
|
|
120
|
+
runningTask = true;
|
|
121
|
+
waiting = false;
|
|
122
|
+
startedAt = 0;
|
|
123
|
+
turn = String(event.task_id || `turn-${++sequence}`);
|
|
124
|
+
segment = 0;
|
|
125
|
+
tools.clear();
|
|
126
|
+
const message = String(event.message || "");
|
|
127
|
+
const last = entries[entries.length - 1];
|
|
128
|
+
if (message && queued < 0 && !(last?.kind === "user" && last.text === message)) {
|
|
129
|
+
apply("transcript.append", { id: `${turn}-user`, kind: "user", text: message });
|
|
130
|
+
}
|
|
131
|
+
status = "Waiting for model…";
|
|
132
|
+
return apply("stream.start", {});
|
|
133
|
+
}
|
|
134
|
+
if (type === "turn_started" || type === "thread_started") {
|
|
135
|
+
waiting = false;
|
|
136
|
+
activityOwnsStatus = false;
|
|
137
|
+
return apply("status.set", { text: "Waiting for model…", busy: true });
|
|
138
|
+
}
|
|
139
|
+
if (type === "phase") {
|
|
140
|
+
const text = statusForAgentPhase(event.phase || {});
|
|
141
|
+
return text ? apply("status.set", { text, busy: true }) : false;
|
|
142
|
+
}
|
|
143
|
+
if (type === "status") {
|
|
144
|
+
waiting = event.state === "waiting_input";
|
|
145
|
+
return apply("status.set", { text: event.text || event.state, busy: event.busy ?? !waiting });
|
|
146
|
+
}
|
|
147
|
+
if (type === "context_usage") {
|
|
148
|
+
contextUsage = String(event.meter?.label || "");
|
|
149
|
+
return apply("usage.set", { text: contextUsage });
|
|
150
|
+
}
|
|
151
|
+
if (type === "plan") return apply("plan.set", { ...event, lines: event.lines || planLinesFromItems(event.items || []) });
|
|
152
|
+
if (type === "background_task") {
|
|
153
|
+
const id = String(event.task_id || "");
|
|
154
|
+
if (!id) return false;
|
|
155
|
+
background.set(id, { ...background.get(id), ...Object.fromEntries(Object.entries(event).filter(([, value]) => value !== undefined)) });
|
|
156
|
+
if (background.size > 100) background.delete(background.keys().next().value);
|
|
157
|
+
bound();
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
if (type === "text_delta") {
|
|
161
|
+
status = "Generating response…";
|
|
162
|
+
return apply("stream.delta", { id: `${turn}-text-${segment}`, text: event.delta });
|
|
163
|
+
}
|
|
164
|
+
if (type === "thinking_delta") {
|
|
165
|
+
status = "Thinking…";
|
|
166
|
+
busy = true;
|
|
167
|
+
return apply("thinking.delta", { id: `${turn}-thinking-${segment}`, text: event.delta });
|
|
168
|
+
}
|
|
169
|
+
if (type === "tool_call") {
|
|
170
|
+
segment += 1;
|
|
171
|
+
const id = `${turn}-tool-${String(event.toolCallId || segment)}`;
|
|
172
|
+
const name = String(event.name || "tool");
|
|
173
|
+
const args = event.args || {};
|
|
174
|
+
const detail = fmt.normalizeToolLogDetail(name.toLowerCase(), { ...args, path: args.path || args.file_path }, {});
|
|
175
|
+
const normalized = fmt.normalizeToolMergeEntry({ tool: name.toLowerCase(), detail, isError: false });
|
|
176
|
+
const summary = fmt.buildUcodeToolRowText([normalized]) || `• ${name}`;
|
|
177
|
+
tools.set(id, { summary, output: "" });
|
|
178
|
+
status = toolStatus(name);
|
|
179
|
+
busy = true;
|
|
180
|
+
if (["plan", "TodoWrite", "update_plan"].includes(name)) {
|
|
181
|
+
apply("plan.set", { lines: planLinesFromItems(args.items || args.todos || args.plan || []) });
|
|
182
|
+
}
|
|
183
|
+
return apply("tool.start", { id, summary });
|
|
184
|
+
}
|
|
185
|
+
if (type === "tool_result") {
|
|
186
|
+
const id = `${turn}-tool-${String(event.toolCallId || "tool")}`;
|
|
187
|
+
const tool = tools.get(id) || { summary: "• Tool", output: "" };
|
|
188
|
+
const output = typeof event.output === "string" ? event.output
|
|
189
|
+
: Array.isArray(event.output) ? event.output.map((block) => block?.text || "").join("\n")
|
|
190
|
+
: event.output == null ? "" : typeof event.output === "object"
|
|
191
|
+
? [event.output.stdout, event.output.stderr, event.output.content, event.output.error].filter((text) => typeof text === "string" && text).join("\n") || JSON.stringify(event.output)
|
|
192
|
+
: String(event.output);
|
|
193
|
+
tool.output = (tool.output + output).slice(-64000);
|
|
194
|
+
tools.set(id, tool);
|
|
195
|
+
if (event.is_error || (Number.isFinite(event.exitCode) && event.exitCode !== 0)) tool.summary = tool.summary.replace(/^• /, "• Failed: ");
|
|
196
|
+
const exit = Number.isFinite(event.exitCode) && event.exitCode !== 0 ? `\n[exit ${event.exitCode}]` : "";
|
|
197
|
+
const detail = [tool.summary.replace(/^• /, ""), tool.output + exit].filter(Boolean).join("\n");
|
|
198
|
+
if (event.status !== "in_progress") status = "Waiting for model…";
|
|
199
|
+
return apply("tool.result", { id, summary: tool.summary, detail });
|
|
200
|
+
}
|
|
201
|
+
if (["task_completed", "task_failed", "task_cancelled", "task_paused"].includes(type)) {
|
|
202
|
+
if (event.error) apply("transcript.append", { kind: "error", text: event.error });
|
|
203
|
+
if (event.usage) accept({ type: "usage", usage: event.usage });
|
|
204
|
+
apply("stream.done", { reason: type === "task_failed" ? "error" : "complete" });
|
|
205
|
+
activityOwnsStatus = false;
|
|
206
|
+
runningTask = false;
|
|
207
|
+
if (type === "task_cancelled") status = "cancelled";
|
|
208
|
+
if (waiting) status = "Waiting for reply…";
|
|
209
|
+
else if (submitted.length) apply("status.set", { text: "Waiting for agent…", busy: true });
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
if (type === "interaction") {
|
|
213
|
+
waiting = true;
|
|
214
|
+
status = "Waiting for reply…";
|
|
215
|
+
busy = false;
|
|
216
|
+
return apply("transcript.append", { id: `${turn}-interaction`, kind: "system", text: (event.lines || []).join("\n") });
|
|
217
|
+
}
|
|
218
|
+
if (type === "usage") {
|
|
219
|
+
const u = event.usage || {};
|
|
220
|
+
return apply("usage.set", { text: contextUsage || `${u.input_tokens ?? u.input ?? 0} in · ${u.output_tokens ?? u.output ?? 0} out` });
|
|
221
|
+
}
|
|
222
|
+
if (type === "activity") {
|
|
223
|
+
if (event.authoritative !== true && (busy || waiting)) return false;
|
|
224
|
+
const state = String(event.state || "ready");
|
|
225
|
+
const at = Date.parse(event.ts || "");
|
|
226
|
+
if (submitted.length && state !== "working" && state !== "busy" && (!at || at < submitted[0].at)) return false;
|
|
227
|
+
if (["working", "busy", "processing"].includes(state)) {
|
|
228
|
+
if (!activityOwnsStatus && submitted.length) submitted.shift();
|
|
229
|
+
activityOwnsStatus = true;
|
|
230
|
+
runningTask = true;
|
|
231
|
+
waiting = false;
|
|
232
|
+
if (!startedAt) startedAt = Number(event.started_at) || Date.now();
|
|
233
|
+
const detail = String(event.detail || "");
|
|
234
|
+
const text = detail.startsWith("tool ") ? toolStatus(detail.slice(5))
|
|
235
|
+
: detail === "thinking" ? "Thinking…" : detail || "Working…";
|
|
236
|
+
return apply("status.set", { text, busy: true });
|
|
237
|
+
}
|
|
238
|
+
activityOwnsStatus = false;
|
|
239
|
+
runningTask = false;
|
|
240
|
+
waiting = ["waiting_input", "waiting"].includes(state);
|
|
241
|
+
const text = waiting ? "Waiting for reply…" : ["blocked", "error"].includes(state)
|
|
242
|
+
? `blocked${event.detail ? ` · ${event.detail}` : ""}`
|
|
243
|
+
: state === "starting" ? "Starting agent…" : "ready";
|
|
244
|
+
return apply("status.set", { text, busy: state === "starting" });
|
|
245
|
+
}
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function toggleExpanded() {
|
|
250
|
+
const row = [...entries].reverse().find((row) => row.kind === "thinking" || (row.kind === "tool" && row.detail));
|
|
251
|
+
if (!row) return false;
|
|
252
|
+
row.expanded = !row.expanded;
|
|
253
|
+
revision += 1;
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function snapshot() {
|
|
258
|
+
const bg = [...background.values()];
|
|
259
|
+
const running = bg.filter((task) => ["running", "pending"].includes(task.status)).length;
|
|
260
|
+
const done = bg.filter((task) => task.status === "completed").length;
|
|
261
|
+
const failed = bg.filter((task) => ["failed", "stopped", "killed"].includes(task.status)).length;
|
|
262
|
+
const suffix = [running && `${running} running`, done && `${done} done`, failed && `${failed} failed`].filter(Boolean).join("/");
|
|
263
|
+
const label = `${status}${!busy && status === "ready" && idlePlanHint ? ` · ${idlePlanHint}` : ""}${submitted.length > 1 || (submitted.length && runningTask) ? ` · queued ${submitted.length}` : ""}${suffix ? ` · BG ${suffix}` : ""}`;
|
|
264
|
+
return { entries: entries.map((row) => ({ ...row })), status: label, busy, usage, plan: plan.slice(), revision, started_at: startedAt };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return { apply, accept, snapshot, toggleExpanded };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
module.exports = { createAgentSurface };
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Shared dashboard snapshot helpers for Rust chat host.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const { formatLoopSummary } = require("
|
|
7
|
+
const { formatLoopSummary } = require("./format/loopSummary");
|
|
8
8
|
|
|
9
9
|
function loadGlobalProjectRows(activeProjectRoot = "") {
|
|
10
10
|
const path = require("path");
|
package/src/ui/format/banner.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
const chalk = require("chalk");
|
|
2
|
+
const UFOO_BANNER_LINES = Object.freeze([
|
|
3
|
+
"█ █ █▀▀ █▀█ █▀█",
|
|
4
|
+
"█ █ █▀ █ █ █ █",
|
|
5
|
+
"▀▀▀ ▀ ▀▀▀ ▀▀▀",
|
|
6
|
+
]);
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* 显示 agent 启动横幅
|
|
@@ -7,21 +12,14 @@ function showBanner(options) {
|
|
|
7
12
|
const { agentType, sessionId, nickname, daemonStatus } = options;
|
|
8
13
|
|
|
9
14
|
// Compact logo (3 行)
|
|
10
|
-
const logo =
|
|
11
|
-
"█ █ █▀▀ █▀█ █▀█",
|
|
12
|
-
"█ █ █▀ █ █ █ █",
|
|
13
|
-
"▀▀▀ ▀ ▀▀▀ ▀▀▀",
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
// Normalize agent type display name
|
|
17
|
-
const displayAgentType = agentType === "ufoo-code" ? "ucode" : agentType;
|
|
15
|
+
const logo = UFOO_BANNER_LINES;
|
|
18
16
|
|
|
19
17
|
// 准备右侧信息行
|
|
20
18
|
const infoLines = [];
|
|
21
19
|
if (nickname) {
|
|
22
20
|
infoLines.push(`${chalk.dim("Nickname:")} ${chalk.cyan.bold(nickname)}`);
|
|
23
21
|
}
|
|
24
|
-
infoLines.push(`${chalk.dim("Agent:")} ${chalk.green.bold(
|
|
22
|
+
infoLines.push(`${chalk.dim("Agent:")} ${chalk.green.bold(agentType)}${chalk.dim(":")}${chalk.yellow(sessionId)}`);
|
|
25
23
|
if (daemonStatus) {
|
|
26
24
|
const statusColor = daemonStatus === "running" ? chalk.green : chalk.blue;
|
|
27
25
|
infoLines.push(`${chalk.dim("Daemon:")} ${statusColor(daemonStatus)}`);
|
|
@@ -50,11 +48,7 @@ function showUfooBanner(options = {}) {
|
|
|
50
48
|
const { version = "1.0.0" } = options;
|
|
51
49
|
|
|
52
50
|
// Compact logo (3 行)
|
|
53
|
-
const logo =
|
|
54
|
-
"█ █ █▀▀ █▀█ █▀█",
|
|
55
|
-
"█ █ █▀ █ █ █ █",
|
|
56
|
-
"▀▀▀ ▀ ▀▀▀ ▀▀▀",
|
|
57
|
-
];
|
|
51
|
+
const logo = UFOO_BANNER_LINES;
|
|
58
52
|
|
|
59
53
|
// 右侧信息
|
|
60
54
|
const infoLines = [
|
|
@@ -73,4 +67,4 @@ function showUfooBanner(options = {}) {
|
|
|
73
67
|
console.log("");
|
|
74
68
|
}
|
|
75
69
|
|
|
76
|
-
module.exports = { showBanner, showUfooBanner };
|
|
70
|
+
module.exports = { showBanner, showUfooBanner, UFOO_BANNER_LINES };
|
package/src/ui/format/index.js
CHANGED
|
@@ -1115,8 +1115,11 @@ function buildCompletions({
|
|
|
1115
1115
|
|
|
1116
1116
|
if (trimmed.startsWith("/")) {
|
|
1117
1117
|
const tokenParts = trimmed.trimEnd().split(/\s+/).filter(Boolean);
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1118
|
+
const dynamicHead = Object.keys(argumentLists || {}).filter((key) => key.includes(" ")
|
|
1119
|
+
&& !key.endsWith("/thinking") && tokenParts.slice(0, key.split(/\s+/).length).join(" ") === key)
|
|
1120
|
+
.sort((a, b) => b.length - a.length)[0];
|
|
1121
|
+
const head = dynamicHead || tokenParts[0] || "";
|
|
1122
|
+
const tail = tokenParts.slice(head.split(/\s+/).length);
|
|
1120
1123
|
const headKey = head.startsWith("/") ? head : `/${head}`;
|
|
1121
1124
|
const headNode = commandTree && typeof commandTree === "object" ? commandTree[headKey] : null;
|
|
1122
1125
|
const argListForHead = argumentLists && typeof argumentLists === "object"
|
|
@@ -1227,7 +1230,7 @@ function buildCompletions({
|
|
|
1227
1230
|
const secondaryList = argumentLists && typeof argumentLists === "object"
|
|
1228
1231
|
? argumentLists[`${headKey}/thinking`] || argumentLists[`${headKey}/think`]
|
|
1229
1232
|
: null;
|
|
1230
|
-
const supportsThinkingMenu =
|
|
1233
|
+
const supportsThinkingMenu = Array.isArray(secondaryList) && secondaryList.length > 0;
|
|
1231
1234
|
|
|
1232
1235
|
// Secondary menu: "/model <id> " or "/model <id> <partial>"
|
|
1233
1236
|
if (supportsThinkingMenu && (
|
|
@@ -1237,6 +1240,9 @@ function buildCompletions({
|
|
|
1237
1240
|
if (tail.length > 2) return [];
|
|
1238
1241
|
const modelId = String(tail[0] || "").trim();
|
|
1239
1242
|
if (!modelId) return [];
|
|
1243
|
+
const modelEntry = argListForHead.find((item) =>
|
|
1244
|
+
String((item && (item.alias || item.cmd || item.id || item.name)) || item || "") === modelId);
|
|
1245
|
+
if (modelEntry && modelEntry.hasChildren === false) return [];
|
|
1240
1246
|
const partial = tail.length >= 2 && !endsWithWhitespace
|
|
1241
1247
|
? String(tail[1] || "").toLowerCase()
|
|
1242
1248
|
: "";
|
|
@@ -1268,17 +1274,15 @@ function buildCompletions({
|
|
|
1268
1274
|
for (const item of argListForHead) {
|
|
1269
1275
|
const id = String((item && (item.alias || item.cmd || item.id || item.name)) || item || "");
|
|
1270
1276
|
if (!id) continue;
|
|
1271
|
-
|
|
1277
|
+
const label = String((item && item.label) || id);
|
|
1278
|
+
if (partial && !id.toLowerCase().startsWith(partial) && !label.toLowerCase().startsWith(partial)) continue;
|
|
1272
1279
|
const desc = String((item && (item.desc || item.summary || item.description || item.source)) || "");
|
|
1273
|
-
const hasChildren =
|
|
1274
|
-
(item && item.hasChildren)
|
|
1275
|
-
|| supportsThinkingMenu
|
|
1276
|
-
);
|
|
1280
|
+
const hasChildren = item && typeof item.hasChildren === "boolean" ? item.hasChildren : supportsThinkingMenu;
|
|
1277
1281
|
out.push({
|
|
1278
1282
|
kind: "argument",
|
|
1279
|
-
label: `${head} ${
|
|
1283
|
+
label: `${head} ${label}`,
|
|
1280
1284
|
// Trailing space keeps the popup open for the thinking submenu.
|
|
1281
|
-
replace:
|
|
1285
|
+
replace: `${head} ${id} `,
|
|
1282
1286
|
description: desc,
|
|
1283
1287
|
hasChildren,
|
|
1284
1288
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function formatToolDistribution(items = []) {
|
|
4
|
+
const tools = Array.isArray(items) ? items : [];
|
|
5
|
+
if (tools.length === 0) return "";
|
|
6
|
+
const visible = tools.slice(0, 2).map((item) => `${item.name}x${item.count}`);
|
|
7
|
+
if (tools.length > 2) {
|
|
8
|
+
visible.push(`+${tools.length - 2}`);
|
|
9
|
+
}
|
|
10
|
+
return visible.join(",");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function formatLoopSummary(loopSummary) {
|
|
14
|
+
if (!loopSummary || typeof loopSummary !== "object") return "";
|
|
15
|
+
const rounds = Number(loopSummary.rounds) || 0;
|
|
16
|
+
const toolCalls = Number(loopSummary.tool_calls) || 0;
|
|
17
|
+
const totalTokens = Number(loopSummary.total_tokens) || 0;
|
|
18
|
+
const inputTokens = Number(loopSummary.input_tokens) || 0;
|
|
19
|
+
const cacheReadTokens = Number(loopSummary.cache_read_tokens) || 0;
|
|
20
|
+
const cacheCreationTokens = Number(loopSummary.cache_creation_tokens) || 0;
|
|
21
|
+
const terminalReason = String(loopSummary.terminal_reason || "").trim();
|
|
22
|
+
const toolDistribution = formatToolDistribution(loopSummary.tools);
|
|
23
|
+
|
|
24
|
+
if (rounds <= 0 && toolCalls <= 0 && totalTokens <= 0 && !terminalReason && !toolDistribution) {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const parts = [
|
|
29
|
+
`r${rounds}`,
|
|
30
|
+
`tc${toolCalls}`,
|
|
31
|
+
`tok${totalTokens}`,
|
|
32
|
+
];
|
|
33
|
+
if (cacheReadTokens > 0 || cacheCreationTokens > 0) {
|
|
34
|
+
let cachePart = `cache${cacheReadTokens}/${cacheCreationTokens}`;
|
|
35
|
+
if (cacheReadTokens > 0) {
|
|
36
|
+
const hitRate = Math.round((cacheReadTokens / (cacheReadTokens + inputTokens)) * 100);
|
|
37
|
+
cachePart += `(${hitRate}%)`;
|
|
38
|
+
}
|
|
39
|
+
parts.push(cachePart);
|
|
40
|
+
}
|
|
41
|
+
if (toolDistribution) {
|
|
42
|
+
parts.push(toolDistribution);
|
|
43
|
+
}
|
|
44
|
+
if (terminalReason) {
|
|
45
|
+
parts.push(terminalReason);
|
|
46
|
+
}
|
|
47
|
+
return parts.join(" ");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = { formatLoopSummary };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared markdown renderer for TUI log output.
|
|
3
3
|
*
|
|
4
|
-
* Produces
|
|
4
|
+
* Produces markup tags for chat history or ANSI styles for terminal surfaces.
|
|
5
5
|
* Terminals cannot change font size, so headings/emphasis use color + weight
|
|
6
6
|
* instead of literal `#` / `**` markers. GFM pipe tables are aligned into a
|
|
7
7
|
* compact spreadsheet-like grid.
|
|
@@ -160,9 +160,8 @@ function createBlessedAdapters(escapeFn = (value) => String(value || "")) {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
function createAnsiAdapters() {
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
// (e.g. piped test harnesses that still render Ink).
|
|
163
|
+
// Surface renderers consume ANSI styles even when the host's stdout is
|
|
164
|
+
// piped, so preserve heading and emphasis colors independently of detection.
|
|
166
165
|
const paint = typeof chalk.Instance === "function"
|
|
167
166
|
? new chalk.Instance({ level: Math.max(Number(chalk.level) || 0, 2) })
|
|
168
167
|
: chalk;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const os = require("os");
|
|
5
|
+
const { displayCellWidth } = require("./index");
|
|
6
|
+
const { UFOO_BANNER_LINES: LOGO } = require("./banner");
|
|
7
|
+
|
|
8
|
+
function fit(text, width) {
|
|
9
|
+
const value = String(text || "").replace(/[\x00-\x1f\x7f]/g, "");
|
|
10
|
+
if (displayCellWidth(value) <= width) return value;
|
|
11
|
+
let out = "";
|
|
12
|
+
for (const char of value) {
|
|
13
|
+
if (displayCellWidth(out + char) > width - 1) break;
|
|
14
|
+
out += char;
|
|
15
|
+
}
|
|
16
|
+
return `${out}…`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Transient startup rows; hosts must not append these to conversation history. */
|
|
20
|
+
function buildUfooStartupEntries({ version = "dev", workspaceRoot = "", globalMode = false, width = 74 } = {}) {
|
|
21
|
+
const columns = Math.max(1, Math.floor(Number(width) || 74));
|
|
22
|
+
const home = os.homedir();
|
|
23
|
+
const root = String(workspaceRoot || process.cwd());
|
|
24
|
+
const directory = root === home ? "~" : root.startsWith(home + path.sep) ? `~${root.slice(home.length)}` : root;
|
|
25
|
+
const info = [
|
|
26
|
+
`ufoo v${version}`,
|
|
27
|
+
globalMode ? "Global workspace" : directory,
|
|
28
|
+
"Type a task or /help",
|
|
29
|
+
];
|
|
30
|
+
const logoWidth = Math.max(...LOGO.map(displayCellWidth));
|
|
31
|
+
let rows;
|
|
32
|
+
if (columns >= logoWidth + 26) {
|
|
33
|
+
rows = LOGO.map((text, index) => ({
|
|
34
|
+
text: text.padEnd(logoWidth),
|
|
35
|
+
detail: fit(info[index], columns - logoWidth - 2),
|
|
36
|
+
}));
|
|
37
|
+
} else if (columns >= logoWidth) {
|
|
38
|
+
rows = LOGO.map((text) => ({ text }));
|
|
39
|
+
rows.push(...info.filter(Boolean).map((detail) => ({ text: "", detail: fit(detail, columns) })));
|
|
40
|
+
} else {
|
|
41
|
+
rows = info.filter(Boolean).map((detail) => ({ text: "", detail: fit(detail, columns) }));
|
|
42
|
+
}
|
|
43
|
+
return [
|
|
44
|
+
{ id: "startup-before", kind: "spacer", text: "" },
|
|
45
|
+
...rows.map((row, index) => ({ id: `startup-${index}`, kind: "banner", speaker: "", ...row })),
|
|
46
|
+
{ id: "startup-after", kind: "spacer", text: "" },
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = { buildUfooStartupEntries };
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Mirror inbound bus events into multi/side internal panes.
|
|
5
|
-
* Rust host
|
|
6
|
-
*
|
|
5
|
+
* Rust host projects provider events independently of the main transcript
|
|
6
|
+
* and inbox routing.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
function parseInternalBusPayload(raw = "") {
|
|
@@ -64,6 +64,8 @@ function writeMultiPaneBusEvent(data = {}, options = {}) {
|
|
|
64
64
|
agentIds = [],
|
|
65
65
|
getMeta = () => ({}),
|
|
66
66
|
writeToPane = () => false,
|
|
67
|
+
acceptEvent = null,
|
|
68
|
+
hasStructuredEvents = () => false,
|
|
67
69
|
} = options;
|
|
68
70
|
|
|
69
71
|
const watched = agentIds instanceof Set
|
|
@@ -80,6 +82,30 @@ function writeMultiPaneBusEvent(data = {}, options = {}) {
|
|
|
80
82
|
const toAgent = aliases.has(target) || aliases.has(String(data.subscriber || ""));
|
|
81
83
|
if (!fromAgent && !toAgent) continue;
|
|
82
84
|
|
|
85
|
+
if (typeof acceptEvent === "function") {
|
|
86
|
+
if (data.event === "agent_surface" && fromAgent) {
|
|
87
|
+
acceptEvent(agentId, data.data?.surface || data.surface || {}, Number(data.seq) || 0);
|
|
88
|
+
handled = true;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (data.event === "activity_state_changed") {
|
|
92
|
+
acceptEvent(agentId, { type: "activity", state: data.state || data.data?.state,
|
|
93
|
+
detail: data.data?.detail || data.detail || "", ts: data.ts });
|
|
94
|
+
handled = true;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (fromAgent && hasStructuredEvents(agentId)) { handled = true; continue; }
|
|
98
|
+
if (!data.silent && !(toAgent && !fromAgent && ["rust-multi-window", "chat-direct", "chat-internal-agent-view"].includes(data.source))) {
|
|
99
|
+
const { displayMessage, streamPayload } = parseInternalBusPayload(data.message || "");
|
|
100
|
+
if (streamPayload) {
|
|
101
|
+
if (fromAgent && streamPayload.delta) acceptEvent(agentId, { type: "text_delta", delta: streamPayload.delta });
|
|
102
|
+
if (fromAgent && streamPayload.done) acceptEvent(agentId, { type: "task_completed", usage: streamPayload.usage });
|
|
103
|
+
} else if (displayMessage) acceptEvent(agentId, { type: fromAgent ? "text_delta" : "task_started", delta: displayMessage, message: displayMessage });
|
|
104
|
+
}
|
|
105
|
+
handled = true;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
83
109
|
if (data.silent) {
|
|
84
110
|
handled = true;
|
|
85
111
|
continue;
|
|
@@ -110,7 +136,7 @@ function writeMultiPaneBusEvent(data = {}, options = {}) {
|
|
|
110
136
|
? streamPayload.delta.replace(/\\r\\n/g, "\n").replace(/\\n/g, "\n").replace(/\\r/g, "\n")
|
|
111
137
|
: "";
|
|
112
138
|
try {
|
|
113
|
-
if (delta) writeToPane(agentId, delta);
|
|
139
|
+
if (delta) writeToPane(agentId, delta.replace(/\r\n?/g, "\n").replace(/\n/g, "\r\n"));
|
|
114
140
|
if (streamPayload.done) writeToPane(agentId, "\r\n");
|
|
115
141
|
} catch { /* ignore */ }
|
|
116
142
|
handled = true;
|