u-foo 4.0.0 → 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 +88 -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/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 +8 -8
- package/src/agents/launch/notifier.js +2 -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 +50 -39
- 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 +2 -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/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 +1 -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
package/src/ui/rustChatHost.js
CHANGED
|
@@ -16,6 +16,7 @@ const { createToolMergePublisher } = require("./toolMergeBridge");
|
|
|
16
16
|
const { createRustMultiSession } = require("./rustMultiSession");
|
|
17
17
|
const { writeMultiPaneBusEvent } = require("./multiPaneBusMirror");
|
|
18
18
|
const { buildSettingsSnapshot, applySettingsPatch } = require("./settingsBridge");
|
|
19
|
+
const { createAgentSettingsController } = require("./agentSettingsController");
|
|
19
20
|
const fmt = require("./format");
|
|
20
21
|
const { buildUfooStartupEntries } = require("./format/startupBanner");
|
|
21
22
|
const {
|
|
@@ -30,6 +31,7 @@ const {
|
|
|
30
31
|
createEnvelope,
|
|
31
32
|
encodeMessage,
|
|
32
33
|
MULTI_FRAMES_CAPABILITY,
|
|
34
|
+
WINDOW_MODES_CAPABILITY,
|
|
33
35
|
} = require("../runtime/contracts/uiProtocol");
|
|
34
36
|
const { IPC_REQUEST_TYPES, IPC_RESPONSE_TYPES } = require("../runtime/contracts/eventContract");
|
|
35
37
|
const { createDaemonMessageRouter } = require("../app/chat/daemonMessageRouter");
|
|
@@ -39,61 +41,81 @@ const {
|
|
|
39
41
|
} = require("../runtime/daemon/endpoint");
|
|
40
42
|
const PACKAGE_VERSION = require("../../package.json").version;
|
|
41
43
|
|
|
44
|
+
async function loadResumeCompletionSources(root, request = require("../app/chat/transport").requestDaemon) {
|
|
45
|
+
const result = await request(root, { type: IPC_REQUEST_TYPES.LIST_RECOVERABLE_AGENTS, internal_only: true }, {
|
|
46
|
+
retries: 1, timeoutMs: 5000,
|
|
47
|
+
});
|
|
48
|
+
const recovery = result.recoverable || {};
|
|
49
|
+
const agents = (recovery.recoverable || []).filter((item) => !item.group_id);
|
|
50
|
+
agents.sort((a, b) => String(b.lastSeen || "").localeCompare(String(a.lastSeen || "")) || a.id.localeCompare(b.id));
|
|
51
|
+
return [
|
|
52
|
+
...agents.map((item) => ({ id: item.id, label: item.display_nickname || item.nickname || item.id,
|
|
53
|
+
desc: `${item.agent} · session ${item.sessionId}` })),
|
|
54
|
+
...(recovery.groups || []).map((group) => ({ id: `group:${group.group_id}`,
|
|
55
|
+
desc: `Group · ${group.template_alias || group.group_id} · ${group.members.length} recoverable agents` })),
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function parseWindowModeArgs(args = []) {
|
|
60
|
+
const text = args.map((value) => String(value).trim()).join(" ").toLowerCase();
|
|
61
|
+
return ["main", "side", "multi"].includes(text) ? text : "";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function resolveSubmittedInputTarget(payload, currentTarget, isInternalAgent) {
|
|
65
|
+
const target = String(payload.target_agent || payload.targetAgent || "").trim();
|
|
66
|
+
if ((payload.has_target && !target) || (target && !isInternalAgent(target))) {
|
|
67
|
+
return { ok: false, error: "Unknown internal target" };
|
|
68
|
+
}
|
|
69
|
+
return { ok: true, target: target || (payload.input_target === "main" ? null : currentTarget) };
|
|
70
|
+
}
|
|
71
|
+
|
|
42
72
|
function stripTags(value) {
|
|
43
73
|
return String(value || "").replace(/\{[^}]+\}/g, "");
|
|
44
74
|
}
|
|
45
75
|
|
|
46
76
|
function historyToEntries(rows) {
|
|
47
77
|
const list = Array.isArray(rows) ? rows : [];
|
|
48
|
-
const markdownState = { inCodeBlock: false };
|
|
49
78
|
const MARKDOWN_KINDS = new Set(["assistant", "agent", "report", "error"]);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
79
|
+
const KINDS = new Set(["system", "user", "assistant", "error", "agent", "report",
|
|
80
|
+
"thinking", "tool", "spacer", "meta", "bus", "success", "banner"]);
|
|
81
|
+
const cleanText = (text) => String(text || "")
|
|
82
|
+
// Strip presentation tags without eating code such as { value: 1 }.
|
|
83
|
+
.replace(/\{\/?(?:[a-z]+(?:-[a-z]+)*-(?:fg|bg)|#[\da-f]{3,8}-(?:fg|bg)|bold|italic|underline|blink|inverse|invisible|normal|reset|escape)\}/gi, "")
|
|
84
|
+
.replace(/\{open\}/g, "{").replace(/\{close\}/g, "}");
|
|
85
|
+
return list.map((row, index) => {
|
|
86
|
+
const source = row && typeof row === "object" ? row : { text: row };
|
|
87
|
+
const meta = source.meta && typeof source.meta === "object" ? source.meta : {};
|
|
88
|
+
const sourceType = String(source.sourceType || source.type || source.kind || "system");
|
|
89
|
+
const streamed = sourceType === "bus" && meta.stream_done === true;
|
|
90
|
+
const kind = streamed || sourceType === "reply" ? "assistant"
|
|
91
|
+
: KINDS.has(sourceType) ? sourceType : "system";
|
|
92
|
+
let text = cleanText(source.text || source.content || "");
|
|
93
|
+
let speaker = String(source.speaker || meta.speaker || "");
|
|
94
|
+
if (streamed) {
|
|
95
|
+
// Stream persistence prefixes the display name, whereas the live TUI
|
|
96
|
+
// receives it separately. Restore that same identity and raw body.
|
|
97
|
+
const match = text.match(/^([^\n]+?): ([\s\S]*)$/);
|
|
98
|
+
if (match) { speaker = speaker || match[1]; text = match[2]; }
|
|
99
|
+
} else if (MARKDOWN_KINDS.has(kind)) {
|
|
70
100
|
try {
|
|
71
|
-
lines = fmt.renderLogLinesWithMarkdownAnsi(
|
|
72
|
-
if (
|
|
101
|
+
const lines = fmt.renderLogLinesWithMarkdownAnsi(text, { inCodeBlock: false });
|
|
102
|
+
if (Array.isArray(lines) && lines.length > 0) text = lines.map((line) => String(line || "")).join("\n");
|
|
73
103
|
} catch {
|
|
74
|
-
|
|
104
|
+
// Keep the original complete block if markdown rendering fails.
|
|
75
105
|
}
|
|
76
|
-
lines.forEach((line, lineIdx) => {
|
|
77
|
-
out.push({
|
|
78
|
-
id: `hist-${index}-${lineIdx}`,
|
|
79
|
-
kind,
|
|
80
|
-
text: String(line || ""),
|
|
81
|
-
speaker: lineIdx === 0 ? speaker : "",
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
return;
|
|
85
106
|
}
|
|
86
|
-
|
|
87
|
-
id: `hist-${index}
|
|
107
|
+
return {
|
|
108
|
+
id: String(source.id || `hist-${index}`),
|
|
88
109
|
kind,
|
|
89
|
-
text
|
|
110
|
+
text,
|
|
90
111
|
speaker,
|
|
91
|
-
|
|
112
|
+
detail: cleanText(source.detail || source.expanded_text || meta.detail || meta.expanded_text || ""),
|
|
113
|
+
expanded: false,
|
|
114
|
+
};
|
|
92
115
|
});
|
|
93
|
-
return out;
|
|
94
116
|
}
|
|
95
117
|
|
|
96
|
-
/**
|
|
118
|
+
/** Completion sources: `/group run` / `/solo run` dynamic argument lists. */
|
|
97
119
|
function loadDynamicCompletionSources(root) {
|
|
98
120
|
const sources = { groupTemplates: [], soloProfiles: [] };
|
|
99
121
|
try {
|
|
@@ -144,7 +166,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
144
166
|
await init.init({
|
|
145
167
|
targets: "context,bus",
|
|
146
168
|
project: projectRoot,
|
|
147
|
-
|
|
169
|
+
globalController: env.globalMode,
|
|
148
170
|
});
|
|
149
171
|
}
|
|
150
172
|
await ensureSubscriberId(projectRoot);
|
|
@@ -172,6 +194,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
172
194
|
|
|
173
195
|
let entrySeq = 0;
|
|
174
196
|
const streamIds = new Map();
|
|
197
|
+
const streamLabels = new Map();
|
|
175
198
|
let mainSubmissionRev = 0;
|
|
176
199
|
let hostRef = null;
|
|
177
200
|
let daemonSend = () => {};
|
|
@@ -192,6 +215,44 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
192
215
|
}
|
|
193
216
|
})();
|
|
194
217
|
|
|
218
|
+
async function applyAgentSettings(patch) {
|
|
219
|
+
const model = patch.agent_model ?? patch.agentModel;
|
|
220
|
+
if (model) {
|
|
221
|
+
const current = loadConfig(activeProjectRoot);
|
|
222
|
+
const provider = patch.agent_provider ?? patch.agentProvider ?? current.agentProvider;
|
|
223
|
+
const confirmation = await require("../agents/providers/modelSettings").confirmAgentModel(activeProjectRoot, model,
|
|
224
|
+
{ config: { ...current, agentProvider: provider } });
|
|
225
|
+
if (!confirmation.allowed) return { ok: false, error: confirmation.error };
|
|
226
|
+
}
|
|
227
|
+
const applied = applySettingsPatch(activeProjectRoot, patch);
|
|
228
|
+
if (!applied.ok) return applied;
|
|
229
|
+
Object.assign(settings, loadConfig(activeProjectRoot));
|
|
230
|
+
publish("settings.snapshot", applied.settings);
|
|
231
|
+
if (applied.providerChanged) appendLocal("system", `Provider: ${applied.settings.agent_provider} · new conversation`);
|
|
232
|
+
if (patch.agent_model != null || patch.agentModel != null) appendLocal("system", `Model: ${applied.settings.agent_model}`);
|
|
233
|
+
if (patch.agent_thinking != null || patch.agentThinking != null) appendLocal("system", `Thinking: ${applied.settings.agent_thinking}`);
|
|
234
|
+
const restart = applied.providerChanged || patch.agent_base_url != null || patch.agent_api_key != null
|
|
235
|
+
|| patch.agentBaseUrl != null || patch.agentApiKey != null;
|
|
236
|
+
if (restart && daemonCoordinator?.restart) {
|
|
237
|
+
publish("status.set", { text: "settings saved · restarting daemon…" });
|
|
238
|
+
await daemonCoordinator.restart();
|
|
239
|
+
}
|
|
240
|
+
publish("status.set", { text: "settings saved", busy: false });
|
|
241
|
+
publish("prompt.restore", {});
|
|
242
|
+
return applied;
|
|
243
|
+
}
|
|
244
|
+
const agentSettings = createAgentSettingsController({ getProjectRoot: () => activeProjectRoot,
|
|
245
|
+
applyPatch: applyAgentSettings, publish: (...args) => publish(...args), logMessage: (...args) => appendLocal(...args),
|
|
246
|
+
focusMain() {
|
|
247
|
+
if (multiSession?.isActive()) {
|
|
248
|
+
multiSession.handleFocus({ target: "chat" });
|
|
249
|
+
publish("window.set", multiSession.getSnapshot());
|
|
250
|
+
}
|
|
251
|
+
controller.session.targetAgent = null;
|
|
252
|
+
publish("prompt.set_prefix", { prefix: "› " });
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
|
|
195
256
|
function historyOptions() {
|
|
196
257
|
const { chatHistoryOptionsForScope } = require("../app/chat/historyStore");
|
|
197
258
|
return chatHistoryOptionsForScope({
|
|
@@ -443,20 +504,20 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
443
504
|
isInternalAgent(agentId) {
|
|
444
505
|
return isInternalAgentMeta(controller.session.metaMap.get(String(agentId || "").trim()));
|
|
445
506
|
},
|
|
446
|
-
/**
|
|
507
|
+
/** Activate an internal child in the one-child window mode. */
|
|
447
508
|
startSide(agentId) {
|
|
448
509
|
const id = String(agentId || "").trim();
|
|
449
510
|
if (!hostApi.isInternalAgent(id)) return { ok: false, error: "Dashboard supports internal agents only" };
|
|
450
511
|
if (!multiSession) return { ok: false, error: "split session not initialised" };
|
|
451
512
|
// Prefer capability check, but do not hard-fail — connected Rust child
|
|
452
|
-
// may be mid-handshake;
|
|
513
|
+
// may be mid-handshake; window.set is still the right wire.
|
|
453
514
|
const caps = hostRef && typeof hostRef.getClientCapabilities === "function"
|
|
454
515
|
? hostRef.getClientCapabilities()
|
|
455
516
|
: [];
|
|
456
|
-
if (caps.length > 0 && !caps.includes(
|
|
517
|
+
if (caps.length > 0 && !caps.includes(WINDOW_MODES_CAPABILITY)) {
|
|
457
518
|
return {
|
|
458
519
|
ok: false,
|
|
459
|
-
error: `Rust TUI lacks ${
|
|
520
|
+
error: `Rust TUI lacks ${WINDOW_MODES_CAPABILITY}; rebuild ufoo-tui`,
|
|
460
521
|
};
|
|
461
522
|
}
|
|
462
523
|
const result = multiSession.start({
|
|
@@ -472,7 +533,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
472
533
|
}
|
|
473
534
|
return result || { ok: false, error: "side start failed" };
|
|
474
535
|
},
|
|
475
|
-
|
|
536
|
+
activateInternalAgent(agentId) {
|
|
476
537
|
const id = String(agentId || "").trim();
|
|
477
538
|
if (!hostApi.isInternalAgent(id)) return { ok: false, error: "Dashboard supports internal agents only" };
|
|
478
539
|
if (multiSession && multiSession.isMultiKind()) {
|
|
@@ -483,44 +544,12 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
483
544
|
const result = hostApi.startSide(id);
|
|
484
545
|
return result && result.ok ? { ...result, mode: "side", agent_id: id } : result;
|
|
485
546
|
},
|
|
486
|
-
getAgentAdapter(agentId) {
|
|
487
|
-
try {
|
|
488
|
-
const { createTerminalAdapterRouter } = require("../runtime/terminal/adapterRouter");
|
|
489
|
-
const meta = controller.session.metaMap.get(agentId) || {};
|
|
490
|
-
if (!isInternalAgentMeta(meta)) return null;
|
|
491
|
-
const launchMode = "internal";
|
|
492
|
-
return createTerminalAdapterRouter().getAdapter({ launchMode, agentId, meta });
|
|
493
|
-
} catch {
|
|
494
|
-
return null;
|
|
495
|
-
}
|
|
496
|
-
},
|
|
497
547
|
};
|
|
498
548
|
|
|
499
549
|
function appendLocal(kind, text, speaker = "") {
|
|
500
|
-
const MARKDOWN_KINDS = new Set(["assistant", "agent", "report", "error"]);
|
|
501
550
|
const raw = String(text == null ? "" : text);
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
try {
|
|
505
|
-
if (!appendLocal._mdState) appendLocal._mdState = { inCodeBlock: false };
|
|
506
|
-
lines = fmt.renderLogLinesWithMarkdownAnsi(raw, appendLocal._mdState);
|
|
507
|
-
if (!Array.isArray(lines) || lines.length === 0) lines = raw.split(/\r?\n/);
|
|
508
|
-
} catch {
|
|
509
|
-
lines = raw.split(/\r?\n/);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
let last = null;
|
|
513
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
514
|
-
entrySeq += 1;
|
|
515
|
-
const line = String(lines[i] || "");
|
|
516
|
-
last = {
|
|
517
|
-
id: `live-${entrySeq}`,
|
|
518
|
-
kind,
|
|
519
|
-
text: /\x1b\[/.test(line) ? line : stripTags(line),
|
|
520
|
-
speaker: i === 0 ? speaker : "",
|
|
521
|
-
};
|
|
522
|
-
publish("transcript.append", last);
|
|
523
|
-
}
|
|
551
|
+
const last = { ...historyToEntries([{ kind, text: raw, speaker }])[0], id: `live-${++entrySeq}` };
|
|
552
|
+
publish("transcript.append", last);
|
|
524
553
|
try {
|
|
525
554
|
const { appendChatHistory } = require("../app/chat/historyStore");
|
|
526
555
|
appendChatHistory(
|
|
@@ -536,38 +565,23 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
536
565
|
return last;
|
|
537
566
|
}
|
|
538
567
|
|
|
539
|
-
function
|
|
540
|
-
if (!multiSession) return { ok: false, error: "
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
appendLocal("error",
|
|
544
|
-
return { ok: false, error
|
|
545
|
-
}
|
|
546
|
-
const value = String(values[0] || "").trim();
|
|
547
|
-
const layout = !value ? "toggle" : value === "on" ? "all" : value === "off" ? "main" : "single";
|
|
548
|
-
if (layout === "single") {
|
|
549
|
-
const label = value.replace(/^@/, "");
|
|
550
|
-
const matches = getActiveAgentIds().filter((id) => {
|
|
551
|
-
const meta = getAgentMetaForMulti(id);
|
|
552
|
-
return [id, meta.nickname, meta.scoped_nickname, meta.display_nickname].includes(label);
|
|
553
|
-
});
|
|
554
|
-
if (matches.length !== 1 || !hostApi.isInternalAgent(matches[0])) {
|
|
555
|
-
const error = matches.length > 1 ? `Ambiguous agent: ${label}` : `Internal agent not found: ${label}`;
|
|
556
|
-
appendLocal("error", error);
|
|
557
|
-
return { ok: false, error };
|
|
558
|
-
}
|
|
559
|
-
return hostApi.startSide(matches[0]);
|
|
568
|
+
function changeWindowLayout(mode) {
|
|
569
|
+
if (!multiSession) return { ok: false, error: "Window session not initialised" };
|
|
570
|
+
if (!["main", "side", "multi", "cycle"].includes(mode)) {
|
|
571
|
+
const error = "Usage: /window main | /window side | /window multi";
|
|
572
|
+
appendLocal("error", error);
|
|
573
|
+
return { ok: false, error };
|
|
560
574
|
}
|
|
561
|
-
if (
|
|
575
|
+
if (mode !== "main") {
|
|
562
576
|
const caps = hostRef && typeof hostRef.getClientCapabilities === "function"
|
|
563
577
|
? hostRef.getClientCapabilities() : [];
|
|
564
|
-
if (!caps.includes(
|
|
565
|
-
const error = `Rust TUI lacks ${
|
|
578
|
+
if (!caps.includes(WINDOW_MODES_CAPABILITY)) {
|
|
579
|
+
const error = `Rust TUI lacks ${WINDOW_MODES_CAPABILITY}; upgrade ufoo-tui`;
|
|
566
580
|
appendLocal("error", error);
|
|
567
581
|
return { ok: false, error };
|
|
568
582
|
}
|
|
569
583
|
}
|
|
570
|
-
const result = multiSession.setLayout(
|
|
584
|
+
const result = multiSession.setLayout(mode);
|
|
571
585
|
if (!result.ok) {
|
|
572
586
|
appendLocal("error", result.error || "Layout switch failed");
|
|
573
587
|
return result;
|
|
@@ -575,16 +589,12 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
575
589
|
reconcileMultiInternalWatches();
|
|
576
590
|
controller.session.targetAgent = null;
|
|
577
591
|
publish("prompt.set_prefix", { prefix: "› " });
|
|
578
|
-
appendLocal("system", multiSession.isActive()
|
|
579
|
-
? "Showing all agents."
|
|
580
|
-
: "Showing main agent.");
|
|
581
592
|
return result;
|
|
582
593
|
}
|
|
583
594
|
|
|
584
595
|
const controller = createChatController({
|
|
585
596
|
projectRoot,
|
|
586
597
|
globalMode: env.globalMode,
|
|
587
|
-
internalOnly: true,
|
|
588
598
|
ports: {
|
|
589
599
|
publish,
|
|
590
600
|
logMessage: (kind, text) => {
|
|
@@ -628,27 +638,24 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
628
638
|
const { isRunning } = require("../runtime/daemon");
|
|
629
639
|
return isRunning(root || activeProjectRoot || projectRoot);
|
|
630
640
|
},
|
|
631
|
-
|
|
632
|
-
getAgentAdapter: (...args) => hostApi.getAgentAdapter(...args),
|
|
641
|
+
activateInternalAgent: (...args) => hostApi.activateInternalAgent(...args),
|
|
633
642
|
focusMultiPane: async (agentId) => {
|
|
634
643
|
// Focus a visible internal pane.
|
|
635
644
|
if (multiSession && multiSession.isMultiKind && multiSession.isMultiKind()) {
|
|
636
645
|
try { multiSession.syncAgents(); } catch { /* ignore */ }
|
|
637
646
|
const focused = multiSession.focusAgent(agentId);
|
|
638
647
|
if (focused && focused.ok) {
|
|
639
|
-
appendLocal("system", `Multi focus → ${agentId}`);
|
|
640
648
|
return true;
|
|
641
649
|
}
|
|
642
650
|
return false;
|
|
643
651
|
}
|
|
644
|
-
//
|
|
652
|
+
// Activate the child in a one-child layout.
|
|
645
653
|
if (hostApi.isInternalAgent(agentId)) {
|
|
646
654
|
const side = hostApi.startSide(agentId);
|
|
647
655
|
return Boolean(side && side.ok);
|
|
648
656
|
}
|
|
649
657
|
return false;
|
|
650
658
|
},
|
|
651
|
-
activateAgent: async (agentId) => hostApi.enterAgentView(agentId),
|
|
652
659
|
listProjects: () => listProjectsForCommands(),
|
|
653
660
|
getCurrentProject: () => ({ project_root: activeProjectRoot }),
|
|
654
661
|
getActiveProjectRoot: () => activeProjectRoot,
|
|
@@ -667,6 +674,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
667
674
|
const speaker = String(action.publisher || "");
|
|
668
675
|
const id = `stream-${speaker || "agent"}-${Date.now()}`;
|
|
669
676
|
streamIds.set(speaker, id);
|
|
677
|
+
streamLabels.set(speaker, action.displayName || speaker);
|
|
670
678
|
publish("stream.start", { id, speaker: action.displayName || speaker });
|
|
671
679
|
return;
|
|
672
680
|
}
|
|
@@ -678,7 +686,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
678
686
|
streamIds.set(key, id);
|
|
679
687
|
publish("stream.start", { id, speaker: key });
|
|
680
688
|
}
|
|
681
|
-
publish("stream.delta", { id, text: String(action.delta || ""), speaker: key });
|
|
689
|
+
publish("stream.delta", { id, text: String(action.delta || ""), speaker: streamLabels.get(key) || key });
|
|
682
690
|
return;
|
|
683
691
|
}
|
|
684
692
|
if (action.type === "stream/end") {
|
|
@@ -687,6 +695,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
687
695
|
if (action.publisher && key !== action.publisher) continue;
|
|
688
696
|
publish("stream.done", { id });
|
|
689
697
|
streamIds.delete(key);
|
|
698
|
+
streamLabels.delete(key);
|
|
690
699
|
}
|
|
691
700
|
publish("status.set", { text: "ready", busy: false });
|
|
692
701
|
return;
|
|
@@ -695,9 +704,18 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
695
704
|
publish("transcript.reset", {});
|
|
696
705
|
}
|
|
697
706
|
},
|
|
698
|
-
|
|
707
|
+
setWindowLayout: (args) => changeWindowLayout(parseWindowModeArgs(args)).ok,
|
|
708
|
+
openAgentSettings: (section) => agentSettings.open(section),
|
|
709
|
+
applyAgentModel: (...args) => agentSettings.applyModel(...args),
|
|
710
|
+
applyAgentSettings,
|
|
711
|
+
openResumeMenu: () => {
|
|
712
|
+
if (multiSession?.isActive()) {
|
|
713
|
+
multiSession.handleFocus({ target: "chat" });
|
|
714
|
+
publish("window.set", multiSession.getSnapshot());
|
|
715
|
+
}
|
|
716
|
+
publish("prompt.set_text", { text: "/resume ", if_empty: true });
|
|
717
|
+
},
|
|
699
718
|
applyChatSettings: (patch = {}) => {
|
|
700
|
-
if (patch.launchMode != null) settings.launchMode = patch.launchMode;
|
|
701
719
|
if (patch.agentProvider != null) settings.agentProvider = patch.agentProvider;
|
|
702
720
|
publish("settings.snapshot", buildSettingsSnapshot(settings));
|
|
703
721
|
},
|
|
@@ -735,19 +753,19 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
735
753
|
}
|
|
736
754
|
|
|
737
755
|
function resolveMultiPaneOptions(agentId) {
|
|
738
|
-
let
|
|
756
|
+
let initialEntries = [];
|
|
739
757
|
try {
|
|
740
|
-
const {
|
|
741
|
-
|
|
758
|
+
const { loadInternalAgentTranscript } = require("../app/chat/internalAgentLogHistory");
|
|
759
|
+
initialEntries = loadInternalAgentTranscript(activeProjectRoot, agentId, {
|
|
742
760
|
maxEvents: 200,
|
|
743
|
-
|
|
761
|
+
maxEntries: 200,
|
|
744
762
|
}) || [];
|
|
745
763
|
} catch {
|
|
746
|
-
|
|
764
|
+
initialEntries = [];
|
|
747
765
|
}
|
|
748
766
|
return {
|
|
749
767
|
mode: "internal",
|
|
750
|
-
|
|
768
|
+
initialEntries,
|
|
751
769
|
};
|
|
752
770
|
}
|
|
753
771
|
|
|
@@ -759,8 +777,8 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
759
777
|
resolvePaneOptions: resolveMultiPaneOptions,
|
|
760
778
|
onInternalSubmit: (agentId, message) => {
|
|
761
779
|
// Layout commands belong to the workspace even when a child has focus.
|
|
762
|
-
if (/^\/
|
|
763
|
-
|
|
780
|
+
if (/^\/window(?:\s|$)/.test(String(message || "").trim())) {
|
|
781
|
+
changeWindowLayout(parseWindowModeArgs(String(message).trim().split(/\s+/).slice(1)));
|
|
764
782
|
return;
|
|
765
783
|
}
|
|
766
784
|
const requestId = `pane-send-${require("crypto").randomUUID()}`;
|
|
@@ -812,9 +830,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
812
830
|
input_history: Array.isArray(inputHistory) ? inputHistory.filter(Boolean) : [],
|
|
813
831
|
agents: agents.agents,
|
|
814
832
|
settings: settingsSnap,
|
|
815
|
-
launch_mode: settingsSnap.launch_mode,
|
|
816
833
|
agent_provider: settingsSnap.agent_provider,
|
|
817
|
-
mode_options: settingsSnap.mode_options,
|
|
818
834
|
provider_options: settingsSnap.provider_options,
|
|
819
835
|
global_mode: Boolean(env.globalMode),
|
|
820
836
|
controller_root: projectRoot,
|
|
@@ -824,7 +840,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
824
840
|
cron: agents.cron && agents.cron.tasks ? agents.cron.tasks : [],
|
|
825
841
|
loop: agents.loop || null,
|
|
826
842
|
loop_summary: require("./dashboardBridge").formatLoopSummary(agents.loop || null),
|
|
827
|
-
|
|
843
|
+
window: multiSession ? multiSession.getSnapshot() : { active: false, mode: "main" },
|
|
828
844
|
};
|
|
829
845
|
}
|
|
830
846
|
|
|
@@ -837,7 +853,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
837
853
|
const host = createUiHostServer({
|
|
838
854
|
socketPath: uiSocketPath,
|
|
839
855
|
authToken: uiAuthToken,
|
|
840
|
-
capabilities: ["chat", "scrollback", "prompt", MULTI_FRAMES_CAPABILITY],
|
|
856
|
+
capabilities: ["chat", "scrollback", "prompt", MULTI_FRAMES_CAPABILITY, WINDOW_MODES_CAPABILITY],
|
|
841
857
|
onClientReady(socket) {
|
|
842
858
|
const snap = createEnvelope({
|
|
843
859
|
kind: "snapshot",
|
|
@@ -847,6 +863,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
847
863
|
payload: buildSnapshot({ startup: true }),
|
|
848
864
|
});
|
|
849
865
|
socket.write(encodeMessage(snap));
|
|
866
|
+
multiSession?.publishFrames();
|
|
850
867
|
if (env.globalMode) publishProjects();
|
|
851
868
|
},
|
|
852
869
|
async onCommand(cmd) {
|
|
@@ -857,28 +874,45 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
857
874
|
}
|
|
858
875
|
if (name === "ui.resync.request") {
|
|
859
876
|
publish("app.snapshot", buildSnapshot());
|
|
877
|
+
multiSession?.publishFrames();
|
|
860
878
|
return { ok: true };
|
|
861
879
|
}
|
|
862
880
|
if (name === "completion.request") {
|
|
863
881
|
const fmt = require("./format");
|
|
864
|
-
const {
|
|
882
|
+
const { getChatCommandCatalog } = require("../app/chat/commands");
|
|
865
883
|
const agents = controller.session.agents.slice();
|
|
866
884
|
const agentLabels = agents.map((id) => {
|
|
867
885
|
const meta = controller.session.metaMap.get(id) || {};
|
|
868
886
|
return meta.display_nickname || meta.nickname || id;
|
|
869
887
|
});
|
|
870
888
|
const dynamic = loadDynamicCompletionSources(activeProjectRoot);
|
|
889
|
+
const completionRoot = activeProjectRoot;
|
|
890
|
+
const resumeQuery = /^\/resume(?:\s|$)/.test(String(payload.text || "").trimStart());
|
|
891
|
+
let resumeTargets = [];
|
|
892
|
+
if (resumeQuery) {
|
|
893
|
+
try { resumeTargets = await loadResumeCompletionSources(completionRoot); }
|
|
894
|
+
catch (error) {
|
|
895
|
+
appendLocal("error", `Could not load recoverable sessions: ${error.message}`);
|
|
896
|
+
}
|
|
897
|
+
if (completionRoot !== activeProjectRoot) return { ok: true, stale: true };
|
|
898
|
+
}
|
|
899
|
+
const settingsLists = /^\/settings\s+agent\s+(?:model|thinking)(?:\s|$)/.test(String(payload.text || "").trimStart())
|
|
900
|
+
? await agentSettings.completions(String(payload.text || "")) : {};
|
|
901
|
+
if (completionRoot !== activeProjectRoot) return { ok: true, stale: true };
|
|
871
902
|
const items = fmt.buildCompletions({
|
|
872
903
|
text: String(payload.text || ""),
|
|
873
904
|
agents,
|
|
874
905
|
agentLabels,
|
|
875
|
-
|
|
876
|
-
commandTree: COMMAND_TREE,
|
|
906
|
+
...getChatCommandCatalog({ globalMode: env.globalMode }),
|
|
877
907
|
groupTemplates: dynamic.groupTemplates,
|
|
878
908
|
soloProfiles: dynamic.soloProfiles,
|
|
879
|
-
|
|
909
|
+
argumentLists: { ...settingsLists, ...(resumeQuery ? { "/resume": resumeTargets } : {}) },
|
|
910
|
+
limit: Math.max(20, resumeTargets.length, ...Object.values(settingsLists).map((list) => list.length)),
|
|
880
911
|
});
|
|
881
912
|
publish("completions.set", { items, text: String(payload.text || "") });
|
|
913
|
+
if (resumeQuery && resumeTargets.length === 0 && String(payload.text || "").trim() === "/resume") {
|
|
914
|
+
appendLocal("system", "No recoverable internal agent sessions or groups.");
|
|
915
|
+
}
|
|
882
916
|
return { ok: true, count: items.length };
|
|
883
917
|
}
|
|
884
918
|
if (name === "task.cancel") {
|
|
@@ -899,21 +933,15 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
899
933
|
}
|
|
900
934
|
return { ok: true, agent_id: agentId };
|
|
901
935
|
}
|
|
902
|
-
if (name === "agent.open"
|
|
936
|
+
if (name === "agent.open") {
|
|
903
937
|
const agentId = String(payload.agent_id || payload.agentId || "").trim();
|
|
904
|
-
|
|
905
|
-
return hostApi.enterAgentView(agentId, payload) || { ok: true, agent_id: agentId };
|
|
906
|
-
}
|
|
907
|
-
// Suspend handoff removed (no PTY mirror). Ignore explicit suspend.
|
|
908
|
-
appendLocal("system", "ui.suspend ignored (PTY handoff removed)");
|
|
909
|
-
return { ok: true, suspend: false, agent_id: agentId };
|
|
938
|
+
return hostApi.activateInternalAgent(agentId) || { ok: true, agent_id: agentId };
|
|
910
939
|
}
|
|
911
|
-
if (name === "
|
|
912
|
-
if (payload.session_id && (!multiSession || payload.session_id !== multiSession.getSessionId())) {
|
|
940
|
+
if (name === "window.set" || name === "window.cycle") {
|
|
941
|
+
if (name === "window.set" && payload.session_id && (!multiSession || payload.session_id !== multiSession.getSessionId())) {
|
|
913
942
|
return { ok: false, error: "stale session_id" };
|
|
914
943
|
}
|
|
915
|
-
|
|
916
|
-
return changeMultiLayout(args);
|
|
944
|
+
return changeWindowLayout(name === "window.cycle" ? "cycle" : payload.mode);
|
|
917
945
|
}
|
|
918
946
|
if (name === "multi.focus") {
|
|
919
947
|
return multiSession
|
|
@@ -1013,57 +1041,17 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
1013
1041
|
return { ok: false, error: err && err.message ? err.message : String(err) };
|
|
1014
1042
|
}
|
|
1015
1043
|
}
|
|
1044
|
+
if (name === "settings.open") return agentSettings.open(payload.section || "model");
|
|
1016
1045
|
if (name === "settings.set") {
|
|
1017
|
-
try {
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
launchMode: applied.settings.launch_mode,
|
|
1022
|
-
agentProvider: applied.settings.agent_provider,
|
|
1023
|
-
});
|
|
1024
|
-
publish("settings.snapshot", applied.settings);
|
|
1025
|
-
if (payload.launch_mode || payload.launchMode) {
|
|
1026
|
-
appendLocal("system", `Launch mode: ${applied.settings.launch_mode}`);
|
|
1027
|
-
}
|
|
1028
|
-
if (payload.agent_provider || payload.agentProvider) {
|
|
1029
|
-
const label = applied.settings.provider_options.find(
|
|
1030
|
-
(opt) => opt.value === applied.settings.agent_provider
|
|
1031
|
-
);
|
|
1032
|
-
appendLocal(
|
|
1033
|
-
"system",
|
|
1034
|
-
`ufoo-agent: ${(label && label.label) || applied.settings.agent_provider}`
|
|
1035
|
-
);
|
|
1036
|
-
try {
|
|
1037
|
-
const { getUfooPaths } = require("../coordination/state/paths");
|
|
1038
|
-
const fs = require("fs");
|
|
1039
|
-
const pathMod = require("path");
|
|
1040
|
-
const agentDir = getUfooPaths(projectRoot).agentDir;
|
|
1041
|
-
fs.rmSync(pathMod.join(agentDir, "ufoo-agent.json"), { force: true });
|
|
1042
|
-
fs.rmSync(pathMod.join(agentDir, "ufoo-agent.history.jsonl"), { force: true });
|
|
1043
|
-
} catch {
|
|
1044
|
-
// ignore
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
publish("status.set", { text: "settings saved · restarting daemon…" });
|
|
1048
|
-
try {
|
|
1049
|
-
if (daemonCoordinator && typeof daemonCoordinator.restart === "function") {
|
|
1050
|
-
await daemonCoordinator.restart();
|
|
1051
|
-
}
|
|
1052
|
-
} catch (err) {
|
|
1053
|
-
appendLocal("error", `Daemon restart failed: ${err && err.message ? err.message : err}`);
|
|
1054
|
-
}
|
|
1055
|
-
try {
|
|
1056
|
-
daemonSend({ type: IPC_REQUEST_TYPES.STATUS });
|
|
1057
|
-
} catch {
|
|
1058
|
-
// ignore
|
|
1059
|
-
}
|
|
1060
|
-
publish("status.set", { text: "settings saved" });
|
|
1061
|
-
return { ok: true, settings: applied.settings };
|
|
1062
|
-
} catch (err) {
|
|
1063
|
-
return { ok: false, error: err && err.message ? err.message : String(err) };
|
|
1046
|
+
try { return await applyAgentSettings(payload); }
|
|
1047
|
+
catch (error) {
|
|
1048
|
+
appendLocal("error", `Settings failed: ${error.message}`);
|
|
1049
|
+
return { ok: false, error: error.message };
|
|
1064
1050
|
}
|
|
1065
1051
|
}
|
|
1066
1052
|
if (name === "interaction.respond") {
|
|
1053
|
+
const settingsReply = await agentSettings.respond(payload);
|
|
1054
|
+
if (settingsReply) return settingsReply;
|
|
1067
1055
|
appendLocal("system", payload.cancelled
|
|
1068
1056
|
? "interaction cancelled"
|
|
1069
1057
|
: `interaction answer: ${String(payload.text || "").slice(0, 200)}`);
|
|
@@ -1072,22 +1060,23 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
1072
1060
|
}
|
|
1073
1061
|
if (name === "input.submit") {
|
|
1074
1062
|
const text = String(payload.text || "");
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
if (
|
|
1079
|
-
|
|
1080
|
-
|
|
1063
|
+
// The submitted identity wins over mutable footer/focus state. Never
|
|
1064
|
+
// send an unresolved explicit child target to the main agent.
|
|
1065
|
+
const routing = resolveSubmittedInputTarget(payload, controller.session.targetAgent, hostApi.isInternalAgent);
|
|
1066
|
+
if (!routing.ok) return routing;
|
|
1067
|
+
controller.session.targetAgent = routing.target;
|
|
1068
|
+
const childOrLayout = Boolean(routing.target)
|
|
1069
|
+
|| text.trimStart().startsWith("@") || /^\/window(?:\s|$)/.test(text.trim());
|
|
1081
1070
|
// Empty ›@ Enter for internal: open side split directly (do not
|
|
1082
1071
|
// depend solely on tryActivate → focusMultiPane chain).
|
|
1083
1072
|
if (!text.trim()) {
|
|
1084
|
-
const target =
|
|
1073
|
+
const target = routing.target;
|
|
1085
1074
|
if (target && hostApi.isInternalAgent(target)
|
|
1086
1075
|
&& !(multiSession && multiSession.isMultiKind && multiSession.isMultiKind())) {
|
|
1087
1076
|
const side = hostApi.startSide(target);
|
|
1088
1077
|
if (!side || !side.ok) {
|
|
1089
1078
|
appendLocal("error", `side failed: ${(side && side.error) || "unknown"}`);
|
|
1090
|
-
//
|
|
1079
|
+
// Preserve the target and let the input handler report the failed focus.
|
|
1091
1080
|
} else {
|
|
1092
1081
|
return { ok: true, routed: "side", agent_id: target };
|
|
1093
1082
|
}
|
|
@@ -1265,14 +1254,7 @@ async function runChatRust(projectRoot, options = {}) {
|
|
|
1265
1254
|
});
|
|
1266
1255
|
}
|
|
1267
1256
|
|
|
1268
|
-
|
|
1269
|
-
const EXIT_SUSPEND = 75;
|
|
1270
|
-
let exitCode = await spawnTuiOnce();
|
|
1271
|
-
if (exitCode === EXIT_SUSPEND) {
|
|
1272
|
-
appendLocal("system", "Suspend exit ignored (PTY handoff removed); resuming chat.");
|
|
1273
|
-
publish("ui.resume", { ok: true });
|
|
1274
|
-
exitCode = await spawnTuiOnce();
|
|
1275
|
-
}
|
|
1257
|
+
const exitCode = await spawnTuiOnce();
|
|
1276
1258
|
|
|
1277
1259
|
if (multiSession && multiSession.isActive()) {
|
|
1278
1260
|
try { multiSession.stop(); } catch {}
|
|
@@ -1289,4 +1271,7 @@ module.exports = {
|
|
|
1289
1271
|
runChatRust,
|
|
1290
1272
|
historyToEntries,
|
|
1291
1273
|
loadDynamicCompletionSources,
|
|
1274
|
+
loadResumeCompletionSources,
|
|
1275
|
+
parseWindowModeArgs,
|
|
1276
|
+
resolveSubmittedInputTarget,
|
|
1292
1277
|
};
|