u-foo 3.1.7 → 4.0.0
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/README.md +172 -13
- package/README.zh-CN.md +108 -13
- package/SKILLS/ufoo/SKILL.md +15 -3
- package/SKILLS/ufoo-bus/SKILL.md +21 -1
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +3 -1
- 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 +10 -3
- 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/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +113 -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 +6 -4
- package/src/agents/controller/loopRuntime.js +85 -221
- package/src/agents/controller/ufooAgent.js +1 -0
- package/src/agents/internal/internalRunner.js +103 -32
- package/src/agents/launch/launcher.js +88 -6
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +13 -18
- package/src/agents/launch/readyDetector.js +26 -12
- 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/groupBootstrap.js +10 -0
- package/src/agents/prompts/mainAgent.js +39 -0
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +3 -0
- package/src/agents/providers/claudeEventTranslator.js +6 -1
- package/src/agents/providers/claudeThreadProvider.js +44 -2
- package/src/agents/providers/codexEventTranslator.js +47 -7
- package/src/agents/providers/codexThreadProvider.js +3 -2
- package/src/agents/providers/controllerJsonTransport.js +28 -0
- package/src/agents/providers/credentials/claude.js +10 -3
- package/src/agents/providers/nativeTransport.js +1135 -0
- package/src/agents/providers/runtimeConfig.js +186 -0
- package/src/agents/providers/thinkingLevels.js +132 -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 +499 -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/upstreamTransport.js +13 -4
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/runtimeStore.js +126 -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 +270 -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 +247 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -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 +14 -3
- package/src/app/chat/agentDirectory.js +8 -2
- package/src/app/chat/commandExecutor.js +36 -46
- package/src/app/chat/commands.js +14 -7
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -3
- package/src/app/chat/inputSubmitHandler.js +14 -2
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +85 -165
- package/src/app/chat/streamState.js +3 -3
- 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/skills.js +16 -4
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +40 -39
- package/src/code/agent.js +16 -4
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +2 -1
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +100 -0
- package/src/code/nativeRunner.js +36 -2667
- 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/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/sessionStore.js +24 -96
- package/src/code/thinkingLevels.js +1 -130
- 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 +81 -67
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +2 -6
- package/src/coordination/bus/inject.js +13 -5
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/utils.js +7 -3
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/controllerSummary.js +23 -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/runtime/contracts/agentMode.js +17 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +4 -0
- package/src/runtime/daemon/agentHost.js +375 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +27 -17
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/executionPaths.js +30 -0
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +1 -0
- package/src/runtime/daemon/index.js +114 -344
- 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 +7 -4
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/ops.js +22 -17
- package/src/runtime/daemon/promptRequest.js +23 -4
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +4 -0
- 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 +24 -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/index.js +1 -0
- package/src/tools/registry.js +2 -0
- package/src/tools/schemaFixtures.js +16 -3
- 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/agentSurface.js +270 -0
- package/src/ui/format/banner.js +8 -11
- package/src/ui/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +170 -438
- package/src/ui/rustMultiSession.js +225 -51
- package/src/ui/rustUcodeHost.js +20 -87
- package/src/ui/settingsBridge.js +7 -4
- package/src/app/chat/agentEnter.js +0 -70
- 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/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { isInternalAgentMeta } = require("../../runtime/contracts/agentMode");
|
|
2
|
+
|
|
1
3
|
function buildAgentMaps(activeAgents = [], metaList = [], fallbackMap = null) {
|
|
2
4
|
const labelMap = new Map();
|
|
3
5
|
const metaMap = new Map();
|
|
@@ -83,9 +85,13 @@ function clampAgentWindowWithSelection({
|
|
|
83
85
|
* Normalize daemon STATUS payload into agents list + footer string.
|
|
84
86
|
* Shared by Ink dashboard and Rust `agents.snapshot`.
|
|
85
87
|
*/
|
|
86
|
-
function normalizeStatusToAgentsSnapshot(data = {}) {
|
|
87
|
-
|
|
88
|
+
function normalizeStatusToAgentsSnapshot(data = {}, { internalOnly = false } = {}) {
|
|
89
|
+
let activeIds = Array.isArray(data.active) ? data.active : [];
|
|
88
90
|
const metaList = Array.isArray(data.active_meta) ? data.active_meta : [];
|
|
91
|
+
if (internalOnly) {
|
|
92
|
+
const internalIds = new Set(metaList.filter(isInternalAgentMeta).map((meta) => meta.id));
|
|
93
|
+
activeIds = activeIds.filter((id) => internalIds.has(id));
|
|
94
|
+
}
|
|
89
95
|
const { labelMap, metaMap } = buildAgentMaps(activeIds, metaList);
|
|
90
96
|
const agents = activeIds.map((id) => {
|
|
91
97
|
const meta = metaMap.get(id) || {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { defaultResolveTerminalApp, collectHostLaunchRequestContext, collectTerminalLaunchRequestContext, collectTmuxLaunchRequestContext } = require("./launchRequestContext");
|
|
1
2
|
const path = require("path");
|
|
2
3
|
const EventBus = require("../../coordination/bus");
|
|
3
4
|
const { IPC_REQUEST_TYPES } = require("../../runtime/contracts/eventContract");
|
|
@@ -54,13 +55,6 @@ function defaultCreateSkills(projectRoot) {
|
|
|
54
55
|
return new UfooSkills(projectRoot);
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
function defaultResolveTerminalApp() {
|
|
58
|
-
const program = String(process.env.TERM_PROGRAM || "").trim();
|
|
59
|
-
if (program === "Apple_Terminal") return "terminal";
|
|
60
|
-
if (program === "iTerm.app" || process.env.ITERM_SESSION_ID) return "iterm2";
|
|
61
|
-
return "";
|
|
62
|
-
}
|
|
63
|
-
|
|
64
58
|
function normalizeSettingsProvider(value = "", fallback = "codex-cli") {
|
|
65
59
|
const text = String(value || "").trim().toLowerCase();
|
|
66
60
|
if (text === "claude" || text === "claude-cli" || text === "claude-code" || text === "anthropic") {
|
|
@@ -94,38 +88,6 @@ function defaultGateModelForProvider(value = "") {
|
|
|
94
88
|
return defaultRouterModelForProvider(value);
|
|
95
89
|
}
|
|
96
90
|
|
|
97
|
-
function collectHostLaunchRequestContext(env = process.env) {
|
|
98
|
-
const hostInjectSock = String(env.UFOO_HOST_INJECT_SOCK || env.HORIZON_INJECT_SOCK || "").trim();
|
|
99
|
-
const hostDaemonSock = String(env.UFOO_HOST_DAEMON_SOCK || "").trim();
|
|
100
|
-
const hostName = String(env.UFOO_HOST_NAME || "").trim();
|
|
101
|
-
const hostSessionId = String(env.UFOO_HOST_SESSION_ID || env.HORIZON_SESSION_ID || "").trim();
|
|
102
|
-
const context = {};
|
|
103
|
-
if (hostInjectSock) context.host_inject_sock = hostInjectSock;
|
|
104
|
-
if (hostDaemonSock) context.host_daemon_sock = hostDaemonSock;
|
|
105
|
-
if (hostName) context.host_name = hostName;
|
|
106
|
-
if (hostSessionId) context.host_session_id = hostSessionId;
|
|
107
|
-
return context;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function collectTerminalLaunchRequestContext(resolveTerminalApp = defaultResolveTerminalApp) {
|
|
111
|
-
const terminalApp = String(resolveTerminalApp() || "").trim().toLowerCase();
|
|
112
|
-
if (terminalApp === "terminal" || terminalApp === "iterm2") {
|
|
113
|
-
return { terminal_app: terminalApp };
|
|
114
|
-
}
|
|
115
|
-
return {};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function collectTmuxLaunchRequestContext(env = process.env) {
|
|
119
|
-
const tmuxTarget = String(env.UFOO_TMUX_TARGET || "").trim();
|
|
120
|
-
const tmuxPane = String(env.UFOO_TMUX_PANE || env.TMUX_PANE || "").trim();
|
|
121
|
-
const tmuxSession = String(env.UFOO_TMUX_SESSION || "").trim();
|
|
122
|
-
const context = {};
|
|
123
|
-
if (tmuxTarget) context.tmux_target = tmuxTarget;
|
|
124
|
-
if (tmuxPane) context.tmux_pane = tmuxPane;
|
|
125
|
-
if (tmuxSession) context.tmux_session = tmuxSession;
|
|
126
|
-
return context;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
91
|
async function withCapturedConsole(capture, fn) {
|
|
130
92
|
const originalLog = console.log;
|
|
131
93
|
const originalError = console.error;
|
|
@@ -149,6 +111,7 @@ function createCommandExecutor(options = {}) {
|
|
|
149
111
|
const hasRestartDaemon = typeof options.restartDaemon === "function";
|
|
150
112
|
const {
|
|
151
113
|
projectRoot,
|
|
114
|
+
internalOnly = false,
|
|
152
115
|
getActiveProjectRoot = () => projectRoot,
|
|
153
116
|
parseCommand = () => null,
|
|
154
117
|
escapeBlessed = (value) => String(value || ""),
|
|
@@ -722,9 +685,11 @@ function createCommandExecutor(options = {}) {
|
|
|
722
685
|
nickname,
|
|
723
686
|
prompt_profile: promptProfile,
|
|
724
687
|
launch_scope: launchScope,
|
|
725
|
-
...
|
|
726
|
-
|
|
727
|
-
|
|
688
|
+
...(internalOnly ? { internal_only: true, launch_scope: "inplace" } : {
|
|
689
|
+
...collectHostLaunchRequestContext(),
|
|
690
|
+
...collectTerminalLaunchRequestContext(resolveTerminalApp),
|
|
691
|
+
...collectTmuxLaunchRequestContext(),
|
|
692
|
+
}),
|
|
728
693
|
};
|
|
729
694
|
send(request);
|
|
730
695
|
schedule(requestStatus, 1000);
|
|
@@ -1056,6 +1021,11 @@ function createCommandExecutor(options = {}) {
|
|
|
1056
1021
|
|
|
1057
1022
|
async function handleModeCommand(args = []) {
|
|
1058
1023
|
const action = String(args[0] || "").trim().toLowerCase();
|
|
1024
|
+
if (internalOnly) {
|
|
1025
|
+
logMessage(action && !["internal", "show", "status"].includes(action) ? "error" : "system",
|
|
1026
|
+
"ufoo dashboard uses internal agents only.");
|
|
1027
|
+
return;
|
|
1028
|
+
}
|
|
1059
1029
|
const config = loadConfig(projectRoot) || {};
|
|
1060
1030
|
const current = normalizeLaunchMode(config.launchMode || "auto");
|
|
1061
1031
|
|
|
@@ -1367,9 +1337,11 @@ function createCommandExecutor(options = {}) {
|
|
|
1367
1337
|
alias,
|
|
1368
1338
|
instance,
|
|
1369
1339
|
dry_run: dryRun,
|
|
1370
|
-
...
|
|
1371
|
-
|
|
1372
|
-
|
|
1340
|
+
...(internalOnly ? { internal_only: true } : {
|
|
1341
|
+
...collectHostLaunchRequestContext(),
|
|
1342
|
+
...collectTerminalLaunchRequestContext(resolveTerminalApp),
|
|
1343
|
+
...collectTmuxLaunchRequestContext(),
|
|
1344
|
+
}),
|
|
1373
1345
|
});
|
|
1374
1346
|
schedule(requestStatus, 1000);
|
|
1375
1347
|
return;
|
|
@@ -1930,6 +1902,24 @@ function createCommandExecutor(options = {}) {
|
|
|
1930
1902
|
const { command, args } = parsed;
|
|
1931
1903
|
|
|
1932
1904
|
switch (command) {
|
|
1905
|
+
case "session": {
|
|
1906
|
+
if (args[0] === "new") options.setRuntimeSession?.(`main-${require("crypto").randomUUID()}`);
|
|
1907
|
+
logMessage("system", `Conversation: ${options.getRuntimeSession?.() || "main-default"}`);
|
|
1908
|
+
return true;
|
|
1909
|
+
}
|
|
1910
|
+
case "task": {
|
|
1911
|
+
const operation = args[0] || "list";
|
|
1912
|
+
if (operation === "list") send({ type: IPC_REQUEST_TYPES.AGENT_RUNTIME, operation: "status" });
|
|
1913
|
+
else if (operation === "cancel" && args[1]) send({ type: IPC_REQUEST_TYPES.AGENT_RUNTIME, operation: "cancel", task_run_id: args[1] });
|
|
1914
|
+
else if (operation === "inspect" && args[1]) send({ type: IPC_REQUEST_TYPES.AGENT_RUNTIME, operation: "tasks", arguments: { operation: "inspect", task_run_id: args[1] } });
|
|
1915
|
+
else logMessage("error", "Usage: /task list | inspect <run-id> | cancel <run-id>");
|
|
1916
|
+
return true;
|
|
1917
|
+
}
|
|
1918
|
+
case "answer": {
|
|
1919
|
+
if (args.length < 2) logMessage("error", "Usage: /answer <interaction-id> <reply>");
|
|
1920
|
+
else send({ type: IPC_REQUEST_TYPES.AGENT_RUNTIME, operation: "resume", interaction_id: args[0], answer: args.slice(1).join(" ") });
|
|
1921
|
+
return true;
|
|
1922
|
+
}
|
|
1933
1923
|
case "clear":
|
|
1934
1924
|
if (typeof clearLog === "function") {
|
|
1935
1925
|
clearLog();
|
|
@@ -1939,7 +1929,7 @@ function createCommandExecutor(options = {}) {
|
|
|
1939
1929
|
return true;
|
|
1940
1930
|
case "multi":
|
|
1941
1931
|
if (typeof options.toggleMultiWindow === "function") {
|
|
1942
|
-
options.toggleMultiWindow();
|
|
1932
|
+
await (args.length ? options.toggleMultiWindow(args) : options.toggleMultiWindow());
|
|
1943
1933
|
} else {
|
|
1944
1934
|
logMessage("error", "{white-fg}✗{/white-fg} Multi-window mode is not available");
|
|
1945
1935
|
}
|
package/src/app/chat/commands.js
CHANGED
|
@@ -36,14 +36,10 @@ const COMMAND_TREE = {
|
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
38
|
"/mode": {
|
|
39
|
-
desc: "
|
|
39
|
+
desc: "Show internal dashboard launch mode",
|
|
40
40
|
children: {
|
|
41
41
|
show: { desc: "Show current launch mode", order: 1 },
|
|
42
|
-
|
|
43
|
-
host: { desc: "Launch via host inject", order: 3 },
|
|
44
|
-
terminal: { desc: "Launch in external terminal", order: 4 },
|
|
45
|
-
tmux: { desc: "Launch in tmux", order: 5 },
|
|
46
|
-
internal: { desc: "Launch as internal agent", order: 6 },
|
|
42
|
+
internal: { desc: "Launch as internal agent", order: 2 },
|
|
47
43
|
},
|
|
48
44
|
},
|
|
49
45
|
"/provider": {
|
|
@@ -69,7 +65,14 @@ const COMMAND_TREE = {
|
|
|
69
65
|
},
|
|
70
66
|
},
|
|
71
67
|
"/init": { desc: "Initialize workspace" },
|
|
72
|
-
"/multi": {
|
|
68
|
+
"/multi": {
|
|
69
|
+
desc: "Toggle all agent panes; /multi @agent opens one",
|
|
70
|
+
optionalArguments: true,
|
|
71
|
+
children: {
|
|
72
|
+
on: { desc: "Show all agent panes" },
|
|
73
|
+
off: { desc: "Return to the main agent" },
|
|
74
|
+
},
|
|
75
|
+
},
|
|
73
76
|
"/mcp": {
|
|
74
77
|
desc: "MCP bridge diagnostics",
|
|
75
78
|
children: {
|
|
@@ -171,6 +174,9 @@ const COMMAND_TREE = {
|
|
|
171
174
|
},
|
|
172
175
|
},
|
|
173
176
|
"/status": { desc: "Status display" },
|
|
177
|
+
"/task": { desc: "Main agent tasks", children: { list: { desc: "List durable tasks" }, inspect: { desc: "Inspect a child task" }, cancel: { desc: "Cancel a task by run ID" } } },
|
|
178
|
+
"/answer": { desc: "Answer a runtime interaction: /answer <interaction-id> <reply>" },
|
|
179
|
+
"/session": { desc: "Main conversation", children: { show: { desc: "Show conversation ID" }, new: { desc: "Start a conversation with current settings" } } },
|
|
174
180
|
"/ufoo": { desc: "ufoo protocol" },
|
|
175
181
|
};
|
|
176
182
|
|
|
@@ -190,6 +196,7 @@ function buildCommandRegistry(tree) {
|
|
|
190
196
|
desc: node.desc || "",
|
|
191
197
|
order: Number.isFinite(node.order) ? node.order : undefined,
|
|
192
198
|
};
|
|
199
|
+
if (node.optionalArguments) entry.optionalArguments = true;
|
|
193
200
|
if (node.children) {
|
|
194
201
|
entry.subcommands = Object.keys(node.children)
|
|
195
202
|
.sort((a, b) => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const { IPC_REQUEST_TYPES } = require("../../runtime/contracts/eventContract");
|
|
1
|
+
const { IPC_REQUEST_TYPES, IPC_RESPONSE_TYPES } = require("../../runtime/contracts/eventContract");
|
|
2
|
+
const { randomUUID } = require("crypto");
|
|
2
3
|
|
|
3
4
|
function createDaemonConnection(options = {}) {
|
|
4
5
|
const {
|
|
@@ -21,6 +22,59 @@ function createDaemonConnection(options = {}) {
|
|
|
21
22
|
const MAX_PENDING_REQUESTS = 50;
|
|
22
23
|
const STATUS_KEY_RECONNECT = "daemon-reconnect";
|
|
23
24
|
const STATUS_KEY_SWITCH = "daemon-switch";
|
|
25
|
+
const runtimeCursors = new Map();
|
|
26
|
+
const runtimeReplays = new Map();
|
|
27
|
+
const replayByScope = new Map();
|
|
28
|
+
const scopeFor = (event) => `${event.projectRoot || ""}:${event.sessionId}`;
|
|
29
|
+
function requestReplay(cursor, allowedTasks = null) {
|
|
30
|
+
const scope = scopeFor(cursor);
|
|
31
|
+
if (!client || replayByScope.has(scope)) return;
|
|
32
|
+
const requestId = `replay-${randomUUID()}`;
|
|
33
|
+
const replay = { ...cursor, scope, requestId, events: [], buffered: [], allowedTasks };
|
|
34
|
+
replayByScope.set(scope, replay); runtimeReplays.set(requestId, replay);
|
|
35
|
+
writeReplay(replay);
|
|
36
|
+
}
|
|
37
|
+
function writeReplay(replay) {
|
|
38
|
+
client.write(`${JSON.stringify(transformRequest({ type: IPC_REQUEST_TYPES.AGENT_RUNTIME, operation: "events", request_id: replay.requestId,
|
|
39
|
+
project_root: replay.projectRoot, session_id: replay.sessionId, after_sequence: replay.sequence || 0 }))}\n`);
|
|
40
|
+
}
|
|
41
|
+
function deliverRuntime(event) {
|
|
42
|
+
const scope = scopeFor(event);
|
|
43
|
+
runtimeCursors.set(scope, { projectRoot: event.projectRoot, sessionId: event.sessionId, sequence: Math.max(runtimeCursors.get(scope)?.sequence || 0, event.sequence || 0) });
|
|
44
|
+
handleMessage({ type: IPC_RESPONSE_TYPES.RUNTIME_EVENT, data: event });
|
|
45
|
+
}
|
|
46
|
+
function receive(msg) {
|
|
47
|
+
if (msg.type === IPC_RESPONSE_TYPES.RUNTIME_EVENT) {
|
|
48
|
+
const replay = replayByScope.get(scopeFor(msg.data || {}));
|
|
49
|
+
if (replay) { replay.buffered.push(msg.data); if (replay.buffered.length > 4096) replay.buffered.shift(); }
|
|
50
|
+
else deliverRuntime(msg.data);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const replay = runtimeReplays.get(msg.request_id);
|
|
54
|
+
if (msg.type === IPC_RESPONSE_TYPES.ERROR && replay) {
|
|
55
|
+
runtimeReplays.delete(replay.requestId); replayByScope.delete(replay.scope);
|
|
56
|
+
replay.buffered.sort((a, b) => a.sequence - b.sequence).forEach(deliverRuntime);
|
|
57
|
+
}
|
|
58
|
+
if (msg.type === IPC_RESPONSE_TYPES.RUNTIME_RESULT && replay) {
|
|
59
|
+
(msg.data.events || []).filter((event) => !replay.allowedTasks || replay.allowedTasks.has(event.taskRunId)).forEach(deliverRuntime);
|
|
60
|
+
if (msg.data.has_more) { replay.sequence = msg.data.next_sequence; writeReplay(replay); return; }
|
|
61
|
+
runtimeReplays.delete(replay.requestId); replayByScope.delete(replay.scope);
|
|
62
|
+
const events = replay.buffered;
|
|
63
|
+
events.sort((a, b) => a.sequence - b.sequence).forEach(deliverRuntime);
|
|
64
|
+
runtimeCursors.set(replay.scope, { projectRoot: replay.projectRoot, sessionId: replay.sessionId, sequence: Math.max(runtimeCursors.get(replay.scope)?.sequence || 0, msg.data.next_sequence || 0) });
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (msg.type === IPC_RESPONSE_TYPES.STATUS && msg.data?.agent_runtime) {
|
|
68
|
+
const runtime = msg.data.agent_runtime;
|
|
69
|
+
const scopes = [...(runtime.sessions || []), ...(runtime.children || []).map((task) => ({ sessionId: task.sessionId, tasks: [task] }))];
|
|
70
|
+
for (const session of scopes) {
|
|
71
|
+
const active = session.tasks.filter((task) => ["queued", "running", "waiting_user"].includes(task.status));
|
|
72
|
+
const cursor = { projectRoot: msg.data.project_root || msg.data.projectRoot || "", sessionId: session.sessionId, sequence: 0 };
|
|
73
|
+
if (active.length && !runtimeCursors.has(scopeFor(cursor))) requestReplay(cursor, new Set(active.map((task) => task.taskRunId)));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
handleMessage(msg);
|
|
77
|
+
}
|
|
24
78
|
const DEFAULT_SWITCH_TIMEOUT_MS = Number.isFinite(switchConnectionTimeoutMs)
|
|
25
79
|
&& switchConnectionTimeoutMs > 0
|
|
26
80
|
? Math.trunc(switchConnectionTimeoutMs)
|
|
@@ -94,10 +148,7 @@ function createDaemonConnection(options = {}) {
|
|
|
94
148
|
for (const line of lines.filter((l) => l.trim())) {
|
|
95
149
|
try {
|
|
96
150
|
const msg = JSON.parse(line);
|
|
97
|
-
|
|
98
|
-
if (shouldStop) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
151
|
+
receive(msg);
|
|
101
152
|
} catch {
|
|
102
153
|
// ignore
|
|
103
154
|
}
|
|
@@ -115,6 +166,8 @@ function createDaemonConnection(options = {}) {
|
|
|
115
166
|
};
|
|
116
167
|
client.on("close", handleDisconnect);
|
|
117
168
|
client.on("error", handleDisconnect);
|
|
169
|
+
runtimeReplays.clear(); replayByScope.clear();
|
|
170
|
+
for (const cursor of runtimeCursors.values()) requestReplay(cursor);
|
|
118
171
|
flushPendingRequests();
|
|
119
172
|
}
|
|
120
173
|
|
|
@@ -32,6 +32,59 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
32
32
|
clearTransientAgentState = () => {},
|
|
33
33
|
refreshDashboard = () => {},
|
|
34
34
|
} = options;
|
|
35
|
+
const runtimeSequences = new Map();
|
|
36
|
+
const runtimeStreams = new Map();
|
|
37
|
+
const runtimeFinished = new Set();
|
|
38
|
+
const runtimeInteractions = new Set();
|
|
39
|
+
function showInteraction(interaction) {
|
|
40
|
+
if (!interaction || runtimeInteractions.has(interaction.id)) return;
|
|
41
|
+
runtimeInteractions.add(interaction.id);
|
|
42
|
+
logMessage("system", escapeBlessed(`${interaction.prompt}\n${(interaction.options || []).map((option) => `[${option.key}] ${option.label}`).join(" ")}\n/answer ${interaction.id} <reply>`));
|
|
43
|
+
}
|
|
44
|
+
function handleRuntimeEvent(event) {
|
|
45
|
+
if (!event || !event.sessionId || !Number.isInteger(event.sequence)) return true;
|
|
46
|
+
const sessionKey = `${event.projectId || ""}:${event.sessionId}`;
|
|
47
|
+
if (event.sequence <= (runtimeSequences.get(sessionKey) || 0)) return true;
|
|
48
|
+
runtimeSequences.set(sessionKey, event.sequence);
|
|
49
|
+
const key = `${sessionKey}:${event.taskRunId}`;
|
|
50
|
+
const label = event.agentId === "ufoo-agent" ? "ufoo" : `task ${event.taskRunId}`;
|
|
51
|
+
if (event.type === "message.delta") {
|
|
52
|
+
const state = beginStream(key, speakerPrefix(label, "white"), " ", { runtime: true, sessionId: event.sessionId, taskRunId: event.taskRunId });
|
|
53
|
+
appendStreamDelta(state, event.text || "");
|
|
54
|
+
runtimeStreams.set(key, true);
|
|
55
|
+
} else if (["task.completed", "task.failed", "task.cancelled", "task.paused", "task.interrupted"].includes(event.type)) {
|
|
56
|
+
if (runtimeStreams.has(key)) {
|
|
57
|
+
finalizeStream(key, { sessionId: event.sessionId, taskRunId: event.taskRunId }, event.type);
|
|
58
|
+
runtimeStreams.delete(key);
|
|
59
|
+
} else if (event.type === "task.completed" && event.result?.text) {
|
|
60
|
+
let text = event.result.text;
|
|
61
|
+
if (event.global) { try { text = JSON.parse(text).reply || ""; } catch { text = ""; } }
|
|
62
|
+
if (text) logMessage("reply", `${speakerPrefix(label, "white")}${escapeBlessed(text)}`);
|
|
63
|
+
}
|
|
64
|
+
if (["task.failed", "task.interrupted"].includes(event.type)) logMessage("error", escapeBlessed(`${label}: ${event.error || event.type}`));
|
|
65
|
+
if (event.type === "task.paused") showInteraction(event.result?.executionState?.pendingUserInteraction);
|
|
66
|
+
runtimeFinished.add(event.taskRunId);
|
|
67
|
+
if (runtimeFinished.size > 500) runtimeFinished.delete(runtimeFinished.values().next().value);
|
|
68
|
+
requestStatus();
|
|
69
|
+
}
|
|
70
|
+
renderScreen();
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
function handleRuntimeResult(msg) {
|
|
74
|
+
const data = msg.data || {};
|
|
75
|
+
if (Array.isArray(data.events)) { data.events.forEach(handleRuntimeEvent); return true; }
|
|
76
|
+
const tasks = data.sessions ? [...data.sessions.flatMap((session) => session.tasks.map((task) => ({ ...task, sessionId: session.sessionId }))), ...(data.children || []), ...(data.delegated || [])]
|
|
77
|
+
: data.task ? [data.task] : [];
|
|
78
|
+
for (const task of tasks) {
|
|
79
|
+
const effects = Object.entries(task.effects || {}).map(([id, effect]) => `${id} (${effect.toolName}: ${effect.status})`).join(", ");
|
|
80
|
+
logMessage("system", escapeBlessed(`${task.taskRunId || task.taskId || task.id}: ${task.status}${task.error ? ` (${task.error})` : ""}${task.summary ? `\n${task.summary}` : ""}${effects ? `\nEffects to inspect: ${effects}` : ""}`));
|
|
81
|
+
showInteraction(task.interaction);
|
|
82
|
+
}
|
|
83
|
+
for (const receipt of data.uncertainReceipts || []) logMessage("system", escapeBlessed(`Outcome unknown: ${receipt.commandId} (${receipt.kind}). Inspect effects before resubmitting.`));
|
|
84
|
+
if (!tasks.length) resolveStatusLine(escapeBlessed(data.status || (data.accepted ? "Accepted" : "Done")));
|
|
85
|
+
renderScreen();
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
35
88
|
|
|
36
89
|
function isLikelySubscriberId(value) {
|
|
37
90
|
const text = String(value || "");
|
|
@@ -139,6 +192,8 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
139
192
|
}
|
|
140
193
|
|
|
141
194
|
updateDashboard(data);
|
|
195
|
+
for (const session of data.agent_runtime?.sessions || []) for (const task of session.tasks || []) showInteraction(task.interaction);
|
|
196
|
+
for (const task of data.agent_runtime?.children || []) showInteraction(task.interaction);
|
|
142
197
|
return false;
|
|
143
198
|
}
|
|
144
199
|
|
|
@@ -247,7 +302,7 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
247
302
|
|
|
248
303
|
function handleResponseMessage(msg) {
|
|
249
304
|
const payload = msg.data || {};
|
|
250
|
-
if (payload.reply) {
|
|
305
|
+
if (payload.reply && !runtimeFinished.has(payload.runtime?.taskRunId)) {
|
|
251
306
|
const replyText = decodeEscapedNewlines(payload.reply);
|
|
252
307
|
resolveStatusLine(`{gray-fg}←{/gray-fg} ${escapeBlessed(replyText)}`);
|
|
253
308
|
const ops = Array.isArray(payload.ops) ? payload.ops : [];
|
|
@@ -345,7 +400,8 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
345
400
|
}
|
|
346
401
|
|
|
347
402
|
if (payload.dispatch && payload.dispatch.length > 0) {
|
|
348
|
-
const targets = payload.dispatch.map((d) => d.target || d).join(", ");
|
|
403
|
+
const targets = payload.dispatch.map((d) => resolveAgentDisplayName(d.target || d)).join(", ");
|
|
404
|
+
logMessage("system", `${speakerPrefix("ufoo", "white")}Task queued for: ${escapeBlessed(targets)}`);
|
|
349
405
|
resolveStatusLine(`{gray-fg}→{/gray-fg} Dispatched to: ${escapeBlessed(targets)}`);
|
|
350
406
|
}
|
|
351
407
|
|
|
@@ -376,7 +432,7 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
376
432
|
setPending(null);
|
|
377
433
|
}
|
|
378
434
|
|
|
379
|
-
if (!payload.reply && !payload.disambiguate) {
|
|
435
|
+
if (!payload.reply && !payload.disambiguate && !payload.dispatch?.length) {
|
|
380
436
|
resolveStatusLine("{gray-fg}✓{/gray-fg} Done");
|
|
381
437
|
}
|
|
382
438
|
|
|
@@ -528,6 +584,8 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
528
584
|
|
|
529
585
|
function handleMessage(msg) {
|
|
530
586
|
if (!msg || typeof msg !== "object") return false;
|
|
587
|
+
if (msg.type === IPC_RESPONSE_TYPES.RUNTIME_EVENT) { handleRuntimeEvent(msg.data); return false; }
|
|
588
|
+
if (msg.type === IPC_RESPONSE_TYPES.RUNTIME_RESULT) { handleRuntimeResult(msg); return false; }
|
|
531
589
|
|
|
532
590
|
if (msg.type === IPC_RESPONSE_TYPES.STATUS) return handleStatusMessage(msg);
|
|
533
591
|
if (msg.type === IPC_RESPONSE_TYPES.RESPONSE) return handleResponseMessage(msg);
|
|
@@ -8,6 +8,7 @@ function createInputSubmitHandler(options = {}) {
|
|
|
8
8
|
state,
|
|
9
9
|
parseAtTarget = () => null,
|
|
10
10
|
resolveAgentId = () => null,
|
|
11
|
+
requireKnownTarget = false,
|
|
11
12
|
executeCommand = async () => false,
|
|
12
13
|
queueStatusLine = () => {},
|
|
13
14
|
send = () => {},
|
|
@@ -130,6 +131,12 @@ function createInputSubmitHandler(options = {}) {
|
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
if (state.targetAgent) {
|
|
134
|
+
if (requireKnownTarget && !resolveAgentId(state.targetAgent)) {
|
|
135
|
+
clearTargetAgent();
|
|
136
|
+
logMessage("error", "Unknown internal @target");
|
|
137
|
+
focusInput();
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
133
140
|
const label = getAgentLabel(state.targetAgent);
|
|
134
141
|
logMessage(
|
|
135
142
|
"user",
|
|
@@ -159,11 +166,16 @@ function createInputSubmitHandler(options = {}) {
|
|
|
159
166
|
return;
|
|
160
167
|
}
|
|
161
168
|
setTargetAgent(resolvedTarget);
|
|
162
|
-
queueStatusLine(`Target selected: @${escapeBlessed(atTarget.target)}`);
|
|
169
|
+
if (!requireKnownTarget) queueStatusLine(`Target selected: @${escapeBlessed(atTarget.target)}`);
|
|
170
|
+
focusInput();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const resolvedTarget = resolveAgentId(atTarget.target) || (requireKnownTarget ? "" : atTarget.target);
|
|
174
|
+
if (!resolvedTarget) {
|
|
175
|
+
logMessage("error", "Unknown internal @target");
|
|
163
176
|
focusInput();
|
|
164
177
|
return;
|
|
165
178
|
}
|
|
166
|
-
const resolvedTarget = resolveAgentId(atTarget.target) || atTarget.target;
|
|
167
179
|
const message = atTarget.message.trim();
|
|
168
180
|
logMessage(
|
|
169
181
|
"user",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function defaultResolveTerminalApp() {
|
|
4
|
+
const program = String(process.env.TERM_PROGRAM || "").trim();
|
|
5
|
+
if (program === "Apple_Terminal") return "terminal";
|
|
6
|
+
if (program === "iTerm.app" || process.env.ITERM_SESSION_ID) return "iterm2";
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function collectHostLaunchRequestContext(env = process.env) {
|
|
11
|
+
const hostInjectSock = String(env.UFOO_HOST_INJECT_SOCK || env.HORIZON_INJECT_SOCK || "").trim();
|
|
12
|
+
const hostDaemonSock = String(env.UFOO_HOST_DAEMON_SOCK || "").trim();
|
|
13
|
+
const hostName = String(env.UFOO_HOST_NAME || "").trim();
|
|
14
|
+
const hostSessionId = String(env.UFOO_HOST_SESSION_ID || env.HORIZON_SESSION_ID || "").trim();
|
|
15
|
+
const context = {};
|
|
16
|
+
if (hostInjectSock) context.host_inject_sock = hostInjectSock;
|
|
17
|
+
if (hostDaemonSock) context.host_daemon_sock = hostDaemonSock;
|
|
18
|
+
if (hostName) context.host_name = hostName;
|
|
19
|
+
if (hostSessionId) context.host_session_id = hostSessionId;
|
|
20
|
+
return context;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function collectTerminalLaunchRequestContext(resolveTerminalApp = defaultResolveTerminalApp) {
|
|
24
|
+
const terminalApp = String(resolveTerminalApp() || "").trim().toLowerCase();
|
|
25
|
+
if (terminalApp === "terminal" || terminalApp === "iterm2") {
|
|
26
|
+
return { terminal_app: terminalApp };
|
|
27
|
+
}
|
|
28
|
+
return {};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function collectTmuxLaunchRequestContext(env = process.env) {
|
|
32
|
+
const tmuxTarget = String(env.UFOO_TMUX_TARGET || "").trim();
|
|
33
|
+
const tmuxPane = String(env.UFOO_TMUX_PANE || env.TMUX_PANE || "").trim();
|
|
34
|
+
const tmuxSession = String(env.UFOO_TMUX_SESSION || "").trim();
|
|
35
|
+
const context = {};
|
|
36
|
+
if (tmuxTarget) context.tmux_target = tmuxTarget;
|
|
37
|
+
if (tmuxPane) context.tmux_pane = tmuxPane;
|
|
38
|
+
if (tmuxSession) context.tmux_session = tmuxSession;
|
|
39
|
+
return context;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = { defaultResolveTerminalApp, collectHostLaunchRequestContext, collectTerminalLaunchRequestContext, collectTmuxLaunchRequestContext };
|