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
|
@@ -1,405 +0,0 @@
|
|
|
1
|
-
const { clampAgentWindowWithSelection } = require("./agentDirectory");
|
|
2
|
-
|
|
3
|
-
const DEFAULT_MODE_OPTIONS = ["auto", "host", "terminal", "tmux", "internal"];
|
|
4
|
-
|
|
5
|
-
function providerLabel(value) {
|
|
6
|
-
if (value === "claude-cli") return "claude";
|
|
7
|
-
if (value === "agy-cli" || value === "agy" || value === "antigravity") return "agy";
|
|
8
|
-
if (value === "kimi-cli" || value === "kimi" || value === "kimi-code") return "kimi";
|
|
9
|
-
if (value === "ucode" || value === "ufoo" || value === "ufoo-code") return "ucode";
|
|
10
|
-
return "codex";
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function ensureAtPrefix(value) {
|
|
14
|
-
const text = String(value || "").trim();
|
|
15
|
-
if (!text) return text;
|
|
16
|
-
return text.startsWith("@") ? text : `@${text}`;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function activityMarker(state = "") {
|
|
20
|
-
const normalized = String(state || "").trim().toLowerCase();
|
|
21
|
-
if (normalized === "working") return "*";
|
|
22
|
-
if (normalized === "waiting_input") return "?";
|
|
23
|
-
if (normalized === "blocked") return "!";
|
|
24
|
-
return "";
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function withActivityMarker(label = "", state = "") {
|
|
28
|
-
const marker = activityMarker(state);
|
|
29
|
-
if (!marker) return label;
|
|
30
|
-
return `${marker}${label}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function buildSummaryLine(options = {}) {
|
|
34
|
-
const {
|
|
35
|
-
activeAgents = [],
|
|
36
|
-
getAgentLabel = (id) => id,
|
|
37
|
-
getAgentState = () => "",
|
|
38
|
-
launchMode = "terminal",
|
|
39
|
-
agentProvider = "codex-cli",
|
|
40
|
-
cronTasks = [],
|
|
41
|
-
loopSummary = null,
|
|
42
|
-
} = options;
|
|
43
|
-
const agents = activeAgents.length > 0
|
|
44
|
-
? activeAgents.slice(0, 3)
|
|
45
|
-
.map((id) => withActivityMarker(ensureAtPrefix(getAgentLabel(id)), getAgentState(id)))
|
|
46
|
-
.join(", ")
|
|
47
|
-
+ (activeAgents.length > 3 ? ` +${activeAgents.length - 3}` : "")
|
|
48
|
-
: "none";
|
|
49
|
-
let line = `{gray-fg}Agents:{/gray-fg} {cyan-fg}${agents}{/cyan-fg}`
|
|
50
|
-
+ ` {gray-fg}Mode:{/gray-fg} {cyan-fg}${launchMode}{/cyan-fg}`
|
|
51
|
-
+ ` {gray-fg}Agent:{/gray-fg} {cyan-fg}${providerLabel(agentProvider)}{/cyan-fg}`;
|
|
52
|
-
const cronCount = Array.isArray(cronTasks) ? cronTasks.length : 0;
|
|
53
|
-
if (cronCount > 0) {
|
|
54
|
-
line += ` {gray-fg}Cron:{/gray-fg} {cyan-fg}${cronCount}{/cyan-fg}`;
|
|
55
|
-
}
|
|
56
|
-
const loopPart = formatLoopSummary(loopSummary);
|
|
57
|
-
if (loopPart) {
|
|
58
|
-
line += ` {gray-fg}Loop:{/gray-fg} {cyan-fg}${loopPart}{/cyan-fg}`;
|
|
59
|
-
}
|
|
60
|
-
return line;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function formatToolDistribution(items = []) {
|
|
64
|
-
const tools = Array.isArray(items) ? items : [];
|
|
65
|
-
if (tools.length === 0) return "";
|
|
66
|
-
const visible = tools.slice(0, 2).map((item) => `${item.name}x${item.count}`);
|
|
67
|
-
if (tools.length > 2) {
|
|
68
|
-
visible.push(`+${tools.length - 2}`);
|
|
69
|
-
}
|
|
70
|
-
return visible.join(",");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function formatLoopSummary(loopSummary) {
|
|
74
|
-
if (!loopSummary || typeof loopSummary !== "object") return "";
|
|
75
|
-
const rounds = Number(loopSummary.rounds) || 0;
|
|
76
|
-
const toolCalls = Number(loopSummary.tool_calls) || 0;
|
|
77
|
-
const totalTokens = Number(loopSummary.total_tokens) || 0;
|
|
78
|
-
const inputTokens = Number(loopSummary.input_tokens) || 0;
|
|
79
|
-
const cacheReadTokens = Number(loopSummary.cache_read_tokens) || 0;
|
|
80
|
-
const cacheCreationTokens = Number(loopSummary.cache_creation_tokens) || 0;
|
|
81
|
-
const terminalReason = String(loopSummary.terminal_reason || "").trim();
|
|
82
|
-
const toolDistribution = formatToolDistribution(loopSummary.tools);
|
|
83
|
-
|
|
84
|
-
if (rounds <= 0 && toolCalls <= 0 && totalTokens <= 0 && !terminalReason && !toolDistribution) {
|
|
85
|
-
return "";
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const parts = [
|
|
89
|
-
`r${rounds}`,
|
|
90
|
-
`tc${toolCalls}`,
|
|
91
|
-
`tok${totalTokens}`,
|
|
92
|
-
];
|
|
93
|
-
if (cacheReadTokens > 0 || cacheCreationTokens > 0) {
|
|
94
|
-
let cachePart = `cache${cacheReadTokens}/${cacheCreationTokens}`;
|
|
95
|
-
if (cacheReadTokens > 0) {
|
|
96
|
-
const hitRate = Math.round((cacheReadTokens / (cacheReadTokens + inputTokens)) * 100);
|
|
97
|
-
cachePart += `(${hitRate}%)`;
|
|
98
|
-
}
|
|
99
|
-
parts.push(cachePart);
|
|
100
|
-
}
|
|
101
|
-
if (toolDistribution) {
|
|
102
|
-
parts.push(toolDistribution);
|
|
103
|
-
}
|
|
104
|
-
if (terminalReason) {
|
|
105
|
-
parts.push(terminalReason);
|
|
106
|
-
}
|
|
107
|
-
return parts.join(" ");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function buildProjectRailLine(options = {}) {
|
|
111
|
-
const {
|
|
112
|
-
projects = [],
|
|
113
|
-
selectedProjectIndex = -1,
|
|
114
|
-
projectListWindowStart = 0,
|
|
115
|
-
maxProjectWindow = 5,
|
|
116
|
-
activeProjectRoot = "",
|
|
117
|
-
projectsFocused = false,
|
|
118
|
-
globalScope = "",
|
|
119
|
-
dashboardHint = "",
|
|
120
|
-
} = options;
|
|
121
|
-
const rows = Array.isArray(projects) ? projects : [];
|
|
122
|
-
let windowStart = projectListWindowStart;
|
|
123
|
-
if (rows.length === 0) {
|
|
124
|
-
return {
|
|
125
|
-
hasProjects: false,
|
|
126
|
-
line: " {gray-fg}Projects:{/gray-fg} {cyan-fg}none{/cyan-fg}",
|
|
127
|
-
windowStart,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const activeRoot = String(activeProjectRoot || "");
|
|
132
|
-
const fallbackIndex = rows.findIndex((row) => String((row || {}).project_root || "") === activeRoot);
|
|
133
|
-
const normalizedSelectedIndex = Number.isFinite(selectedProjectIndex)
|
|
134
|
-
? Math.trunc(selectedProjectIndex)
|
|
135
|
-
: -1;
|
|
136
|
-
const safeSelectedIndex = normalizedSelectedIndex >= 0 && normalizedSelectedIndex < rows.length
|
|
137
|
-
? normalizedSelectedIndex
|
|
138
|
-
: (fallbackIndex >= 0 ? fallbackIndex : 0);
|
|
139
|
-
|
|
140
|
-
windowStart = clampAgentWindowWithSelection({
|
|
141
|
-
activeCount: rows.length,
|
|
142
|
-
maxWindow: Math.max(1, maxProjectWindow),
|
|
143
|
-
windowStart,
|
|
144
|
-
selectionIndex: safeSelectedIndex,
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
const maxItems = Math.max(1, Math.min(Math.max(1, maxProjectWindow), rows.length));
|
|
148
|
-
const start = windowStart;
|
|
149
|
-
const end = start + maxItems;
|
|
150
|
-
const visibleRows = rows.slice(start, end);
|
|
151
|
-
const projectParts = visibleRows.map((row, i) => {
|
|
152
|
-
const absoluteIndex = start + i;
|
|
153
|
-
const name = String((row && row.project_name) || (row && row.project_root) || "-");
|
|
154
|
-
const rowRoot = String((row && row.project_root) || "");
|
|
155
|
-
const isActiveProject = globalScope !== "controller" && Boolean(activeRoot && rowRoot === activeRoot);
|
|
156
|
-
const isSelected = absoluteIndex === safeSelectedIndex;
|
|
157
|
-
if (projectsFocused && isSelected) {
|
|
158
|
-
return `{inverse}${name}{/inverse}`;
|
|
159
|
-
}
|
|
160
|
-
if (isActiveProject) {
|
|
161
|
-
return `{bold}{cyan-fg}${name}{/cyan-fg}{/bold}`;
|
|
162
|
-
}
|
|
163
|
-
return `{cyan-fg}${name}{/cyan-fg}`;
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const leftMore = start > 0 ? "{gray-fg}<{/gray-fg} " : "";
|
|
167
|
-
const rightMore = end < rows.length ? " {gray-fg}>{/gray-fg}" : "";
|
|
168
|
-
const hintPart = dashboardHint ? `{|}{gray-fg}${dashboardHint}{/gray-fg}` : "";
|
|
169
|
-
return {
|
|
170
|
-
hasProjects: true,
|
|
171
|
-
line: ` {gray-fg}Projects:{/gray-fg} ${leftMore}${projectParts.join(" ")}${rightMore}${hintPart}`,
|
|
172
|
-
windowStart,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function buildDashboardDetailLine(options = {}) {
|
|
177
|
-
const {
|
|
178
|
-
globalMode = false,
|
|
179
|
-
dashboardView = "agents",
|
|
180
|
-
activeAgents = [],
|
|
181
|
-
selectedAgentIndex = -1,
|
|
182
|
-
agentListWindowStart = 0,
|
|
183
|
-
maxAgentWindow = 4,
|
|
184
|
-
getAgentLabel = (id) => id,
|
|
185
|
-
getAgentState = () => "",
|
|
186
|
-
selectedModeIndex = 0,
|
|
187
|
-
selectedProviderIndex = 0,
|
|
188
|
-
selectedCronIndex = -1,
|
|
189
|
-
cronTasks = [],
|
|
190
|
-
providerOptions = [],
|
|
191
|
-
dashHints = {},
|
|
192
|
-
modeOptions = DEFAULT_MODE_OPTIONS,
|
|
193
|
-
} = options;
|
|
194
|
-
|
|
195
|
-
let content = " ";
|
|
196
|
-
let windowStart = agentListWindowStart;
|
|
197
|
-
|
|
198
|
-
if (dashboardView === "mode") {
|
|
199
|
-
const modeParts = modeOptions.map((mode, i) => {
|
|
200
|
-
if (i === selectedModeIndex) {
|
|
201
|
-
return `{inverse}${mode}{/inverse}`;
|
|
202
|
-
}
|
|
203
|
-
return `{cyan-fg}${mode}{/cyan-fg}`;
|
|
204
|
-
});
|
|
205
|
-
content += `{gray-fg}Mode:{/gray-fg} ${modeParts.join(" ")}`;
|
|
206
|
-
content += ` {gray-fg}│ ${dashHints.mode || ""}{/gray-fg}`;
|
|
207
|
-
return { content, windowStart };
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (dashboardView === "provider") {
|
|
211
|
-
const providerParts = providerOptions.map((opt, i) => {
|
|
212
|
-
if (i === selectedProviderIndex) {
|
|
213
|
-
return `{inverse}${opt.label}{/inverse}`;
|
|
214
|
-
}
|
|
215
|
-
return `{cyan-fg}${opt.label}{/cyan-fg}`;
|
|
216
|
-
});
|
|
217
|
-
content += `{gray-fg}Agent:{/gray-fg} ${providerParts.join(" ")}`;
|
|
218
|
-
content += ` {gray-fg}│ ${dashHints.provider || ""}{/gray-fg}`;
|
|
219
|
-
return { content, windowStart };
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (dashboardView === "cron") {
|
|
223
|
-
const items = Array.isArray(cronTasks) ? cronTasks : [];
|
|
224
|
-
const summary = items.length > 0
|
|
225
|
-
? items.map((item, index) => {
|
|
226
|
-
const label = item.label || item.summary || item.id || "";
|
|
227
|
-
if (!label) return "";
|
|
228
|
-
return index === selectedCronIndex
|
|
229
|
-
? `{inverse}${label}{/inverse}`
|
|
230
|
-
: `{cyan-fg}${label}{/cyan-fg}`;
|
|
231
|
-
}).filter(Boolean).join(", ")
|
|
232
|
-
: "{cyan-fg}none{/cyan-fg}";
|
|
233
|
-
content += `{gray-fg}Cron:{/gray-fg} ${summary}`;
|
|
234
|
-
content += ` {gray-fg}│ ${dashHints.cron || ""}{/gray-fg}`;
|
|
235
|
-
return { content, windowStart };
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (activeAgents.length > 0) {
|
|
239
|
-
windowStart = clampAgentWindowWithSelection({
|
|
240
|
-
activeCount: activeAgents.length,
|
|
241
|
-
maxWindow: maxAgentWindow,
|
|
242
|
-
windowStart,
|
|
243
|
-
selectionIndex: selectedAgentIndex,
|
|
244
|
-
});
|
|
245
|
-
const maxItems = Math.max(1, Math.min(maxAgentWindow, activeAgents.length));
|
|
246
|
-
const start = windowStart;
|
|
247
|
-
const end = start + maxItems;
|
|
248
|
-
const visibleAgents = activeAgents.slice(start, end);
|
|
249
|
-
const agentParts = visibleAgents.map((agent, i) => {
|
|
250
|
-
const absoluteIndex = start + i;
|
|
251
|
-
const label = withActivityMarker(
|
|
252
|
-
ensureAtPrefix(getAgentLabel(agent)),
|
|
253
|
-
getAgentState(agent)
|
|
254
|
-
);
|
|
255
|
-
if (absoluteIndex === selectedAgentIndex) {
|
|
256
|
-
return `{inverse}${label}{/inverse}`;
|
|
257
|
-
}
|
|
258
|
-
return `{cyan-fg}${label}{/cyan-fg}`;
|
|
259
|
-
});
|
|
260
|
-
const leftMore = start > 0 ? "{gray-fg}<{/gray-fg} " : "";
|
|
261
|
-
const rightMore = end < activeAgents.length ? " {gray-fg}>{/gray-fg}" : "";
|
|
262
|
-
content += `{gray-fg}Agents:{/gray-fg} ${leftMore}${agentParts.join(" ")}${rightMore}`;
|
|
263
|
-
const agentsHint = globalMode
|
|
264
|
-
? (dashHints.agentsGlobal || dashHints.agents || "")
|
|
265
|
-
: (dashHints.agents || "");
|
|
266
|
-
content += ` {gray-fg}│ ${agentsHint}{/gray-fg}`;
|
|
267
|
-
} else {
|
|
268
|
-
content += "{gray-fg}Agents:{/gray-fg} {cyan-fg}none{/cyan-fg}";
|
|
269
|
-
content += ` {gray-fg}│ ${dashHints.agentsEmpty || ""}{/gray-fg}`;
|
|
270
|
-
}
|
|
271
|
-
return { content, windowStart };
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
function computeDashboardContent(options = {}) {
|
|
275
|
-
const {
|
|
276
|
-
globalMode = false,
|
|
277
|
-
globalScope = "controller",
|
|
278
|
-
focusMode = "input",
|
|
279
|
-
dashboardView = "agents",
|
|
280
|
-
activeAgents = [],
|
|
281
|
-
projects = [],
|
|
282
|
-
selectedProjectIndex = -1,
|
|
283
|
-
projectListWindowStart = 0,
|
|
284
|
-
maxProjectWindow = 5,
|
|
285
|
-
activeProjectRoot = "",
|
|
286
|
-
selectedAgentIndex = -1,
|
|
287
|
-
agentListWindowStart = 0,
|
|
288
|
-
maxAgentWindow = 4,
|
|
289
|
-
getAgentLabel = (id) => id,
|
|
290
|
-
getAgentState = () => "",
|
|
291
|
-
launchMode = "terminal",
|
|
292
|
-
agentProvider = "codex-cli",
|
|
293
|
-
selectedModeIndex = 0,
|
|
294
|
-
selectedProviderIndex = 0,
|
|
295
|
-
selectedCronIndex = -1,
|
|
296
|
-
cronTasks = [],
|
|
297
|
-
loopSummary = null,
|
|
298
|
-
pendingReports = 0,
|
|
299
|
-
providerOptions = [],
|
|
300
|
-
dashHints = {},
|
|
301
|
-
modeOptions = DEFAULT_MODE_OPTIONS,
|
|
302
|
-
} = options;
|
|
303
|
-
|
|
304
|
-
if (globalMode) {
|
|
305
|
-
const projectsFocused = focusMode === "dashboard" && dashboardView === "projects";
|
|
306
|
-
let dashboardHint = "";
|
|
307
|
-
if (projectsFocused) {
|
|
308
|
-
dashboardHint = globalScope === "controller" ? "Enter\u2192project" : "Esc\u2192global";
|
|
309
|
-
}
|
|
310
|
-
const rail = buildProjectRailLine({
|
|
311
|
-
projects,
|
|
312
|
-
selectedProjectIndex,
|
|
313
|
-
projectListWindowStart,
|
|
314
|
-
maxProjectWindow,
|
|
315
|
-
activeProjectRoot,
|
|
316
|
-
projectsFocused,
|
|
317
|
-
globalScope,
|
|
318
|
-
dashboardHint,
|
|
319
|
-
});
|
|
320
|
-
if (!rail.hasProjects) {
|
|
321
|
-
const line2 = ` {gray-fg}${dashHints.projectsEmpty || "Run ufoo chat/daemon in projects to populate registry"}{/gray-fg}`;
|
|
322
|
-
return {
|
|
323
|
-
content: `${rail.line}\n${line2}`,
|
|
324
|
-
windowStart: rail.windowStart,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (focusMode !== "dashboard" || projectsFocused) {
|
|
329
|
-
const line2 = buildSummaryLine({
|
|
330
|
-
activeAgents,
|
|
331
|
-
getAgentLabel,
|
|
332
|
-
getAgentState,
|
|
333
|
-
launchMode,
|
|
334
|
-
agentProvider,
|
|
335
|
-
cronTasks,
|
|
336
|
-
loopSummary,
|
|
337
|
-
});
|
|
338
|
-
return {
|
|
339
|
-
content: `${rail.line}\n ${line2}`,
|
|
340
|
-
windowStart: rail.windowStart,
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
const detail = buildDashboardDetailLine({
|
|
345
|
-
globalMode,
|
|
346
|
-
dashboardView,
|
|
347
|
-
activeAgents,
|
|
348
|
-
selectedAgentIndex,
|
|
349
|
-
agentListWindowStart,
|
|
350
|
-
maxAgentWindow,
|
|
351
|
-
getAgentLabel,
|
|
352
|
-
getAgentState,
|
|
353
|
-
selectedModeIndex,
|
|
354
|
-
selectedProviderIndex,
|
|
355
|
-
selectedCronIndex,
|
|
356
|
-
cronTasks,
|
|
357
|
-
providerOptions,
|
|
358
|
-
dashHints,
|
|
359
|
-
modeOptions,
|
|
360
|
-
});
|
|
361
|
-
return {
|
|
362
|
-
content: `${rail.line}\n${detail.content}`,
|
|
363
|
-
windowStart: detail.windowStart,
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (focusMode === "dashboard") {
|
|
368
|
-
return buildDashboardDetailLine({
|
|
369
|
-
globalMode,
|
|
370
|
-
dashboardView,
|
|
371
|
-
activeAgents,
|
|
372
|
-
selectedAgentIndex,
|
|
373
|
-
agentListWindowStart,
|
|
374
|
-
maxAgentWindow,
|
|
375
|
-
getAgentLabel,
|
|
376
|
-
getAgentState,
|
|
377
|
-
selectedModeIndex,
|
|
378
|
-
selectedProviderIndex,
|
|
379
|
-
selectedCronIndex,
|
|
380
|
-
cronTasks,
|
|
381
|
-
providerOptions,
|
|
382
|
-
dashHints,
|
|
383
|
-
modeOptions,
|
|
384
|
-
});
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
let content = " ";
|
|
388
|
-
content += buildSummaryLine({
|
|
389
|
-
activeAgents,
|
|
390
|
-
getAgentLabel,
|
|
391
|
-
getAgentState,
|
|
392
|
-
launchMode,
|
|
393
|
-
agentProvider,
|
|
394
|
-
cronTasks,
|
|
395
|
-
loopSummary,
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
return { content, windowStart: agentListWindowStart };
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
module.exports = {
|
|
402
|
-
computeDashboardContent,
|
|
403
|
-
providerLabel,
|
|
404
|
-
formatLoopSummary,
|
|
405
|
-
};
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
const { calculatePaneLayout } = require("./paneLayout");
|
|
2
|
-
const { createPaneManager } = require("./paneManager");
|
|
3
|
-
const { createRenderer } = require("./renderer");
|
|
4
|
-
|
|
5
|
-
// Pane output bursts are coalesced into short batches; full chrome repaints
|
|
6
|
-
// are throttled with a trailing frame so the final state always renders.
|
|
7
|
-
const PANE_OUTPUT_BATCH_MS = 50;
|
|
8
|
-
const RENDER_ALL_MIN_INTERVAL_MS = 100;
|
|
9
|
-
|
|
10
|
-
function createMultiWindowController(options = {}) {
|
|
11
|
-
const {
|
|
12
|
-
processStdout = process.stdout,
|
|
13
|
-
getRows = () => process.stdout.rows || 24,
|
|
14
|
-
getCols = () => process.stdout.columns || 80,
|
|
15
|
-
getInjectSockPath = () => "",
|
|
16
|
-
getActiveAgents = () => [],
|
|
17
|
-
getAgentPaneOptions = () => ({}),
|
|
18
|
-
getChatLogLines = () => [],
|
|
19
|
-
getStatusText = () => "",
|
|
20
|
-
getPromptPrefix = () => "› ",
|
|
21
|
-
getCurrentDraft = () => "",
|
|
22
|
-
getCursorPos = () => 0,
|
|
23
|
-
getCompletions = () => ({ items: [], index: -1, windowStart: 0, pageSize: 8 }),
|
|
24
|
-
getAgentLabel = (id) => id,
|
|
25
|
-
getInternalPaneInfo = () => ({}),
|
|
26
|
-
getDashboardLines = () => [],
|
|
27
|
-
getTerminalFocused = () => false,
|
|
28
|
-
freezeScreen = () => {},
|
|
29
|
-
restoreTerminal = () => {},
|
|
30
|
-
onExit = () => {},
|
|
31
|
-
onFocusAgent = () => {},
|
|
32
|
-
onInternalSubmit = () => {},
|
|
33
|
-
} = options;
|
|
34
|
-
|
|
35
|
-
let active = false;
|
|
36
|
-
let renderThrottleTimer = null;
|
|
37
|
-
let dirtyPanes = new Set();
|
|
38
|
-
let renderAllTimer = null;
|
|
39
|
-
let renderAllTrailing = false;
|
|
40
|
-
let lastRenderAllAt = 0;
|
|
41
|
-
let lastCompletionPopup = null;
|
|
42
|
-
const renderer = createRenderer({ write: (d) => processStdout.write(d) });
|
|
43
|
-
const paneManager = createPaneManager({
|
|
44
|
-
getInjectSockPath,
|
|
45
|
-
onInternalSubmit,
|
|
46
|
-
onPaneOutput: (agentId) => {
|
|
47
|
-
if (!active) return;
|
|
48
|
-
dirtyPanes.add(agentId);
|
|
49
|
-
if (!renderThrottleTimer) {
|
|
50
|
-
renderThrottleTimer = setTimeout(() => {
|
|
51
|
-
renderThrottleTimer = null;
|
|
52
|
-
const panes = [...dirtyPanes];
|
|
53
|
-
dirtyPanes.clear();
|
|
54
|
-
for (const id of panes) renderSinglePane(id);
|
|
55
|
-
}, PANE_OUTPUT_BATCH_MS);
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
function enter() {
|
|
61
|
-
const agents = getActiveAgents();
|
|
62
|
-
if (agents.length === 0) return false;
|
|
63
|
-
if (active) return false;
|
|
64
|
-
active = true;
|
|
65
|
-
freezeScreen(true);
|
|
66
|
-
renderer.hideCursor();
|
|
67
|
-
renderer.clear();
|
|
68
|
-
syncAgents();
|
|
69
|
-
renderAllNow();
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function exit() {
|
|
74
|
-
if (!active) return;
|
|
75
|
-
active = false;
|
|
76
|
-
if (renderThrottleTimer) {
|
|
77
|
-
clearTimeout(renderThrottleTimer);
|
|
78
|
-
renderThrottleTimer = null;
|
|
79
|
-
dirtyPanes.clear();
|
|
80
|
-
}
|
|
81
|
-
if (renderAllTimer) {
|
|
82
|
-
clearTimeout(renderAllTimer);
|
|
83
|
-
renderAllTimer = null;
|
|
84
|
-
renderAllTrailing = false;
|
|
85
|
-
}
|
|
86
|
-
paneManager.disconnectAll();
|
|
87
|
-
renderer.showCursor();
|
|
88
|
-
restoreTerminal();
|
|
89
|
-
freezeScreen(false);
|
|
90
|
-
onExit();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function syncAgents() {
|
|
94
|
-
const agents = getActiveAgents();
|
|
95
|
-
const current = new Set(paneManager.getAgentIds());
|
|
96
|
-
const layout = calculatePaneLayout(getCols(), getRows(), agents.length);
|
|
97
|
-
|
|
98
|
-
for (let i = 0; i < agents.length; i++) {
|
|
99
|
-
const id = agents[i];
|
|
100
|
-
const pane = layout.agentPanes[i];
|
|
101
|
-
if (!pane) continue;
|
|
102
|
-
const innerW = Math.max(1, pane.width - 2);
|
|
103
|
-
const innerH = Math.max(1, pane.height - 2);
|
|
104
|
-
if (!current.has(id)) {
|
|
105
|
-
paneManager.addAgent(id, innerW, innerH, getAgentPaneOptions(id) || {});
|
|
106
|
-
} else {
|
|
107
|
-
paneManager.sendResize(id, innerW, innerH);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
for (const id of current) {
|
|
111
|
-
if (!agents.includes(id)) {
|
|
112
|
-
paneManager.removeAgent(id);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function renderSinglePane(agentId) {
|
|
118
|
-
if (!active) return;
|
|
119
|
-
try {
|
|
120
|
-
const agents = paneManager.getAgentIds();
|
|
121
|
-
const layout = calculatePaneLayout(getCols(), getRows(), agents.length);
|
|
122
|
-
const idx = agents.indexOf(agentId);
|
|
123
|
-
if (idx < 0 || !layout.agentPanes[idx]) return;
|
|
124
|
-
const pane = paneManager.getPane(agentId);
|
|
125
|
-
if (!pane) return;
|
|
126
|
-
const isFocused = getTerminalFocused() && agentId === paneManager.getFocused();
|
|
127
|
-
if (pane.mode === "internal" && typeof renderer.renderInternalPane === "function") {
|
|
128
|
-
renderer.renderInternalPane(pane.vt, layout.agentPanes[idx], isFocused, {
|
|
129
|
-
label: getAgentLabel(agentId),
|
|
130
|
-
...(getInternalPaneInfo(agentId) || {}),
|
|
131
|
-
input: pane.internalInput || "",
|
|
132
|
-
cursor: pane.internalCursor || 0,
|
|
133
|
-
});
|
|
134
|
-
} else {
|
|
135
|
-
renderer.renderPane(pane.vt, layout.agentPanes[idx], isFocused, getAgentLabel(agentId));
|
|
136
|
-
}
|
|
137
|
-
} catch {
|
|
138
|
-
// swallow render errors to prevent crash
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function renderAllNow() {
|
|
143
|
-
if (!active) return;
|
|
144
|
-
lastRenderAllAt = Date.now();
|
|
145
|
-
try {
|
|
146
|
-
const agents = paneManager.getAgentIds();
|
|
147
|
-
const layout = calculatePaneLayout(getCols(), getRows(), agents.length);
|
|
148
|
-
const cols = getCols();
|
|
149
|
-
|
|
150
|
-
// Resolve the completion popup up front so stale rows are cleared
|
|
151
|
-
// before anything repaints (clearing also invalidates renderer caches).
|
|
152
|
-
const cmp = getCompletions();
|
|
153
|
-
let nextCompletionPopup = null;
|
|
154
|
-
let nextCompletionItems = null;
|
|
155
|
-
let nextCompletionStart = 0;
|
|
156
|
-
if (cmp && Array.isArray(cmp.items) && cmp.items.length > 0 && layout.inputPane) {
|
|
157
|
-
const start = Math.min(cmp.windowStart || 0, Math.max(0, cmp.items.length - (cmp.pageSize || 8)));
|
|
158
|
-
const end = Math.min(cmp.items.length, start + (cmp.pageSize || 8));
|
|
159
|
-
const visible = cmp.items.slice(start, end);
|
|
160
|
-
const popupTop = layout.inputPane.top - visible.length - 1;
|
|
161
|
-
if (popupTop >= 0) {
|
|
162
|
-
nextCompletionPopup = { top: popupTop, left: 0, width: cols, height: visible.length + 1 };
|
|
163
|
-
nextCompletionItems = visible;
|
|
164
|
-
nextCompletionStart = start;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
const prevPopup = lastCompletionPopup;
|
|
168
|
-
const samePopupRect = prevPopup && nextCompletionPopup &&
|
|
169
|
-
prevPopup.top === nextCompletionPopup.top &&
|
|
170
|
-
prevPopup.width === nextCompletionPopup.width &&
|
|
171
|
-
prevPopup.height === nextCompletionPopup.height &&
|
|
172
|
-
(prevPopup.left || 0) === (nextCompletionPopup.left || 0);
|
|
173
|
-
if (prevPopup && !samePopupRect && typeof renderer.clearRows === "function") {
|
|
174
|
-
renderer.clearRows(prevPopup.top, prevPopup.height, prevPopup.width, prevPopup.left || 0);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
renderer.renderChatLog(layout.chatPane, getChatLogLines());
|
|
178
|
-
|
|
179
|
-
const focused = getTerminalFocused() ? paneManager.getFocused() : null;
|
|
180
|
-
for (let i = 0; i < agents.length; i++) {
|
|
181
|
-
const pane = paneManager.getPane(agents[i]);
|
|
182
|
-
if (!pane || !layout.agentPanes[i]) continue;
|
|
183
|
-
if (pane.mode === "internal" && typeof renderer.renderInternalPane === "function") {
|
|
184
|
-
renderer.renderInternalPane(pane.vt, layout.agentPanes[i], agents[i] === focused, {
|
|
185
|
-
label: getAgentLabel(agents[i]),
|
|
186
|
-
...(getInternalPaneInfo(agents[i]) || {}),
|
|
187
|
-
input: pane.internalInput || "",
|
|
188
|
-
cursor: pane.internalCursor || 0,
|
|
189
|
-
});
|
|
190
|
-
} else {
|
|
191
|
-
renderer.renderPane(pane.vt, layout.agentPanes[i], agents[i] === focused, getAgentLabel(agents[i]));
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const chatFocused = !getTerminalFocused();
|
|
196
|
-
if (layout.separatorPane) {
|
|
197
|
-
renderer.renderSeparator(layout.separatorPane, chatFocused);
|
|
198
|
-
}
|
|
199
|
-
if (layout.statusPane) {
|
|
200
|
-
renderer.renderStatusLine(layout.statusPane, getStatusText());
|
|
201
|
-
}
|
|
202
|
-
if (layout.inputPane) {
|
|
203
|
-
renderer.renderInputPrompt(layout.inputPane, getPromptPrefix(), getCurrentDraft(), getCursorPos());
|
|
204
|
-
}
|
|
205
|
-
if (layout.inputSepPane) {
|
|
206
|
-
renderer.renderSeparator(layout.inputSepPane, chatFocused);
|
|
207
|
-
}
|
|
208
|
-
if (layout.dashboardPane) {
|
|
209
|
-
const lines = getDashboardLines();
|
|
210
|
-
renderer.renderDashboard(layout.dashboardPane, lines);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (nextCompletionPopup && nextCompletionItems) {
|
|
214
|
-
const popupTop = nextCompletionPopup.top;
|
|
215
|
-
renderer.renderSeparator({ top: popupTop, left: 0, width: cols });
|
|
216
|
-
for (let i = 0; i < nextCompletionItems.length; i++) {
|
|
217
|
-
const idx = nextCompletionStart + i;
|
|
218
|
-
const selected = idx === cmp.index;
|
|
219
|
-
const label = nextCompletionItems[i].label || "";
|
|
220
|
-
const desc = nextCompletionItems[i].description || "";
|
|
221
|
-
const line = selected
|
|
222
|
-
? `\x1b[7;36m${label}\x1b[0m \x1b[90m${desc}\x1b[0m`
|
|
223
|
-
: `\x1b[90m${label} ${desc}\x1b[0m`;
|
|
224
|
-
const pad = Math.max(0, cols - renderer.visibleLength(line));
|
|
225
|
-
renderer.write(renderer.moveTo(popupTop + 1 + i, 0) + line + " ".repeat(pad) + "\x1b[0m");
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
lastCompletionPopup = nextCompletionPopup;
|
|
229
|
-
} catch {
|
|
230
|
-
// swallow render errors to prevent crash
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Throttled entry point for external callers: renders immediately when idle,
|
|
235
|
-
// otherwise coalesces bursts into one trailing frame so state stays consistent.
|
|
236
|
-
function renderAll() {
|
|
237
|
-
if (!active) return;
|
|
238
|
-
const elapsed = Date.now() - lastRenderAllAt;
|
|
239
|
-
if (!renderAllTimer && elapsed >= RENDER_ALL_MIN_INTERVAL_MS) {
|
|
240
|
-
renderAllNow();
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
renderAllTrailing = true;
|
|
244
|
-
if (!renderAllTimer) {
|
|
245
|
-
renderAllTimer = setTimeout(() => {
|
|
246
|
-
renderAllTimer = null;
|
|
247
|
-
if (!renderAllTrailing) return;
|
|
248
|
-
renderAllTrailing = false;
|
|
249
|
-
renderAllNow();
|
|
250
|
-
}, Math.max(RENDER_ALL_MIN_INTERVAL_MS - elapsed, 16));
|
|
251
|
-
if (typeof renderAllTimer.unref === "function") renderAllTimer.unref();
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function handleKey(key) {
|
|
256
|
-
if (!active) return false;
|
|
257
|
-
|
|
258
|
-
if (key.name === "c" && key.ctrl) {
|
|
259
|
-
return false;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (key.name === "w" && key.ctrl) {
|
|
263
|
-
paneManager.cycleFocus();
|
|
264
|
-
renderAllNow();
|
|
265
|
-
return true;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
if (key.name === "q" && key.ctrl) {
|
|
269
|
-
exit();
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
return false;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function focusAgent(agentId) {
|
|
277
|
-
if (!active) return;
|
|
278
|
-
const agents = paneManager.getAgentIds();
|
|
279
|
-
if (!agents.includes(agentId)) return;
|
|
280
|
-
paneManager.setFocused(agentId);
|
|
281
|
-
onFocusAgent(agentId);
|
|
282
|
-
renderAllNow();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function handleResize() {
|
|
286
|
-
if (!active) return;
|
|
287
|
-
syncAgents();
|
|
288
|
-
renderer.clear();
|
|
289
|
-
renderAllNow();
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function isActive() { return active; }
|
|
293
|
-
|
|
294
|
-
return {
|
|
295
|
-
enter,
|
|
296
|
-
exit,
|
|
297
|
-
isActive,
|
|
298
|
-
handleKey,
|
|
299
|
-
handleResize,
|
|
300
|
-
syncAgents,
|
|
301
|
-
renderAll,
|
|
302
|
-
focusAgent,
|
|
303
|
-
sendInput: (data) => paneManager.sendInput(data),
|
|
304
|
-
writeToPane: (agentId, data) => paneManager.writeToPane(agentId, data),
|
|
305
|
-
getFocused: () => paneManager.getFocused(),
|
|
306
|
-
getAgentIds: () => paneManager.getAgentIds(),
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
module.exports = { createMultiWindowController };
|