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
package/src/app/chat/commands.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const { SETTINGS_MODEL_DEFAULTS } = require("../../config");
|
|
2
|
+
const { DEFAULT_THINKING_LEVEL } = require("../../agents/providers/thinkingLevels");
|
|
3
|
+
|
|
1
4
|
const COMMAND_TREE = {
|
|
2
5
|
"/bus": {
|
|
3
6
|
desc: "Event bus operations",
|
|
@@ -35,17 +38,6 @@ const COMMAND_TREE = {
|
|
|
35
38
|
stop: { desc: "Stop cron task by id or all" },
|
|
36
39
|
},
|
|
37
40
|
},
|
|
38
|
-
"/mode": {
|
|
39
|
-
desc: "Set agent launch mode",
|
|
40
|
-
children: {
|
|
41
|
-
show: { desc: "Show current launch mode", order: 1 },
|
|
42
|
-
auto: { desc: "Auto-select launch mode", order: 2 },
|
|
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 },
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
41
|
"/provider": {
|
|
50
42
|
desc: "Set ufoo-agent provider",
|
|
51
43
|
children: {
|
|
@@ -54,6 +46,7 @@ const COMMAND_TREE = {
|
|
|
54
46
|
claude: { desc: "Use Claude", order: 3 },
|
|
55
47
|
agy: { desc: "Use Antigravity (agy)", order: 4 },
|
|
56
48
|
kimi: { desc: "Use Kimi Code", order: 5 },
|
|
49
|
+
custom: { desc: "Configure a custom OpenAI API endpoint", order: 6 },
|
|
57
50
|
},
|
|
58
51
|
},
|
|
59
52
|
"/clear": { desc: "Clear chat log on screen" },
|
|
@@ -69,7 +62,14 @@ const COMMAND_TREE = {
|
|
|
69
62
|
},
|
|
70
63
|
},
|
|
71
64
|
"/init": { desc: "Initialize workspace" },
|
|
72
|
-
"/
|
|
65
|
+
"/window": {
|
|
66
|
+
desc: "Choose the main, side or multi window layout",
|
|
67
|
+
children: {
|
|
68
|
+
main: { desc: "Show only the main agent", order: 1 },
|
|
69
|
+
side: { desc: "Show the main agent and the most recently activated child, or the first child", order: 2 },
|
|
70
|
+
multi: { desc: "Show the main agent and all internal children", order: 3 },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
73
|
"/mcp": {
|
|
74
74
|
desc: "MCP bridge diagnostics",
|
|
75
75
|
children: {
|
|
@@ -78,20 +78,18 @@ const COMMAND_TREE = {
|
|
|
78
78
|
help: { desc: "Show MCP setup hints", order: 3 },
|
|
79
79
|
},
|
|
80
80
|
},
|
|
81
|
-
"/open": { desc: "Open project path in global mode" },
|
|
81
|
+
"/open": { desc: "Open project path in global mode", globalOnly: true },
|
|
82
82
|
"/launch": {
|
|
83
83
|
desc: "Launch new agent",
|
|
84
84
|
children: {
|
|
85
85
|
claude: { desc: "Launch Claude agent", order: 1 },
|
|
86
86
|
codex: { desc: "Launch Codex agent", order: 2 },
|
|
87
|
-
agy: { desc: "Launch Antigravity (agy) agent", order: 3 },
|
|
88
|
-
grok: { desc: "Launch Grok Build agent", order: 4 },
|
|
89
87
|
ucode: { desc: "Launch ucode core agent", order: 5 },
|
|
90
|
-
kimi: { desc: "Launch Kimi Code agent", order: 6 },
|
|
91
88
|
},
|
|
92
89
|
},
|
|
93
90
|
"/project": {
|
|
94
91
|
desc: "Project switch operations (spike)",
|
|
92
|
+
globalOnly: true,
|
|
95
93
|
children: {
|
|
96
94
|
current: { desc: "Show current chat project" },
|
|
97
95
|
list: { desc: "List running projects from registry" },
|
|
@@ -113,10 +111,8 @@ const COMMAND_TREE = {
|
|
|
113
111
|
},
|
|
114
112
|
},
|
|
115
113
|
"/resume": {
|
|
116
|
-
desc: "Resume
|
|
117
|
-
|
|
118
|
-
list: { desc: "List recoverable agents (optional target)" },
|
|
119
|
-
},
|
|
114
|
+
desc: "Resume an internal agent session or a group",
|
|
115
|
+
hasArguments: true,
|
|
120
116
|
},
|
|
121
117
|
"/settings": {
|
|
122
118
|
desc: "Settings operations",
|
|
@@ -126,29 +122,17 @@ const COMMAND_TREE = {
|
|
|
126
122
|
order: 1,
|
|
127
123
|
},
|
|
128
124
|
agent: {
|
|
129
|
-
desc: "Manage main
|
|
125
|
+
desc: "Manage ufoo main agent provider/model",
|
|
130
126
|
order: 2,
|
|
131
127
|
children: {
|
|
132
128
|
show: { desc: "Show main agent provider/model", order: 1 },
|
|
133
129
|
set: { desc: "Set provider=<codex|claude> model=<id>", order: 2 },
|
|
134
130
|
clear: { desc: "Clear agent model or reset provider", order: 3 },
|
|
135
|
-
codex: { desc:
|
|
136
|
-
claude: { desc:
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
desc: "Manage gate router mode/provider/model",
|
|
141
|
-
order: 3,
|
|
142
|
-
children: {
|
|
143
|
-
show: { desc: "Show gate router mode/provider/model", order: 1 },
|
|
144
|
-
set: { desc: "Set mode/provider/model", order: 2 },
|
|
145
|
-
clear: { desc: "Clear gate router provider/model or reset mode", order: 3 },
|
|
146
|
-
main: { desc: "Set router mode to main", order: 4 },
|
|
147
|
-
loop: { desc: "Set router mode to loop", order: 5 },
|
|
148
|
-
legacy: { desc: "Set router mode to legacy", order: 6 },
|
|
149
|
-
shadow: { desc: "Set router mode to shadow", order: 7 },
|
|
150
|
-
codex: { desc: "Use Codex gate model (gpt-5.3-codex-spark)", order: 8 },
|
|
151
|
-
claude: { desc: "Use Claude gate model (sonnet-4.7)", order: 9 },
|
|
131
|
+
codex: { desc: `Use Codex default (${SETTINGS_MODEL_DEFAULTS.agent.codex} · ${DEFAULT_THINKING_LEVEL})`, order: 4 },
|
|
132
|
+
claude: { desc: `Use Claude default model (${SETTINGS_MODEL_DEFAULTS.agent.claude})`, order: 5 },
|
|
133
|
+
custom: { desc: "Configure custom API URL and key", order: 6 },
|
|
134
|
+
model: { desc: "Select a model for the current provider", hasArguments: true, order: 7 },
|
|
135
|
+
thinking: { desc: "Select thinking intensity", hasArguments: true, order: 8 },
|
|
152
136
|
},
|
|
153
137
|
},
|
|
154
138
|
ucode: {
|
|
@@ -171,6 +155,9 @@ const COMMAND_TREE = {
|
|
|
171
155
|
},
|
|
172
156
|
},
|
|
173
157
|
"/status": { desc: "Status display" },
|
|
158
|
+
"/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" } } },
|
|
159
|
+
"/answer": { desc: "Answer a runtime interaction: /answer <interaction-id> <reply>" },
|
|
160
|
+
"/session": { desc: "Main conversation", children: { show: { desc: "Show conversation ID" }, new: { desc: "Start a conversation with current settings" } } },
|
|
174
161
|
"/ufoo": { desc: "ufoo protocol" },
|
|
175
162
|
};
|
|
176
163
|
|
|
@@ -190,6 +177,7 @@ function buildCommandRegistry(tree) {
|
|
|
190
177
|
desc: node.desc || "",
|
|
191
178
|
order: Number.isFinite(node.order) ? node.order : undefined,
|
|
192
179
|
};
|
|
180
|
+
if (node.optionalArguments) entry.optionalArguments = true;
|
|
193
181
|
if (node.children) {
|
|
194
182
|
entry.subcommands = Object.keys(node.children)
|
|
195
183
|
.sort((a, b) => {
|
|
@@ -224,6 +212,16 @@ function buildCommandRegistry(tree) {
|
|
|
224
212
|
|
|
225
213
|
const COMMAND_REGISTRY = buildCommandRegistry(COMMAND_TREE);
|
|
226
214
|
|
|
215
|
+
function getChatCommandCatalog({ globalMode = false } = {}) {
|
|
216
|
+
if (globalMode) {
|
|
217
|
+
return { commands: COMMAND_REGISTRY, commandTree: COMMAND_TREE };
|
|
218
|
+
}
|
|
219
|
+
const commandTree = Object.fromEntries(
|
|
220
|
+
Object.entries(COMMAND_TREE).filter(([, node]) => !node.globalOnly)
|
|
221
|
+
);
|
|
222
|
+
return { commands: buildCommandRegistry(commandTree), commandTree };
|
|
223
|
+
}
|
|
224
|
+
|
|
227
225
|
function parseCommand(text) {
|
|
228
226
|
if (!text.startsWith("/")) return null;
|
|
229
227
|
|
|
@@ -260,7 +258,7 @@ function normalizeAgentLabel(value = "") {
|
|
|
260
258
|
if (raw === "agy" || raw === "antigravity" || raw === "uagy") return "agy";
|
|
261
259
|
if (raw === "grok" || raw === "ugrok" || raw === "grok-build" || raw === "xai") return "grok";
|
|
262
260
|
if (raw === "kimi" || raw === "kimi-cli" || raw === "kimi-code" || raw === "ukimi") return "kimi";
|
|
263
|
-
if (raw === "ucode"
|
|
261
|
+
if (raw === "ucode") return "ucode";
|
|
264
262
|
return raw || "agent";
|
|
265
263
|
}
|
|
266
264
|
|
|
@@ -338,11 +336,6 @@ function describeCommandForChat(text) {
|
|
|
338
336
|
return "Managing cron tasks";
|
|
339
337
|
}
|
|
340
338
|
|
|
341
|
-
if (command === "mode") {
|
|
342
|
-
if (!sub || sub === "show" || sub === "status") return "Showing launch mode";
|
|
343
|
-
return `Setting launch mode to ${sub}`;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
339
|
if (command === "provider") {
|
|
347
340
|
if (!sub || sub === "show" || sub === "status") return "Showing agent provider";
|
|
348
341
|
return `Setting agent provider to ${sub}`;
|
|
@@ -361,7 +354,7 @@ function describeCommandForChat(text) {
|
|
|
361
354
|
if (command === "clear") return "Clearing the chat log";
|
|
362
355
|
if (command === "multi") return "Toggling multi-pane view";
|
|
363
356
|
if (command === "open") return `Opening project ${args[0] || ""}`.trim();
|
|
364
|
-
if (command === "resume") return args[0]
|
|
357
|
+
if (command === "resume") return args[0] ? `Resuming ${args[0]}` : "Choose an agent or group to resume";
|
|
365
358
|
if (command === "init") return "Initializing ufoo workspace";
|
|
366
359
|
|
|
367
360
|
return `Running /${command}`;
|
|
@@ -391,6 +384,7 @@ module.exports = {
|
|
|
391
384
|
COMMAND_REGISTRY,
|
|
392
385
|
sortCommands,
|
|
393
386
|
buildCommandRegistry,
|
|
387
|
+
getChatCommandCatalog,
|
|
394
388
|
parseCommand,
|
|
395
389
|
describeCommandForChat,
|
|
396
390
|
shouldEchoCommandInChat,
|
|
@@ -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
|
|
|
@@ -16,12 +16,6 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
16
16
|
getPending = () => null,
|
|
17
17
|
setPending = () => {},
|
|
18
18
|
resolveAgentDisplayName = (value) => value,
|
|
19
|
-
getCurrentView = () => "main",
|
|
20
|
-
isAgentViewUsesBus = () => false,
|
|
21
|
-
getViewingAgent = () => "",
|
|
22
|
-
isAgentEventForViewingAgent = (data, viewingAgent, publisher) =>
|
|
23
|
-
Boolean(viewingAgent && (publisher === viewingAgent || data?.target === viewingAgent)),
|
|
24
|
-
writeToAgentTerm = () => {},
|
|
25
19
|
consumePendingDelivery = () => false,
|
|
26
20
|
getPendingState = () => null,
|
|
27
21
|
beginStream = () => null,
|
|
@@ -32,6 +26,59 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
32
26
|
clearTransientAgentState = () => {},
|
|
33
27
|
refreshDashboard = () => {},
|
|
34
28
|
} = options;
|
|
29
|
+
const runtimeSequences = new Map();
|
|
30
|
+
const runtimeStreams = new Map();
|
|
31
|
+
const runtimeFinished = new Set();
|
|
32
|
+
const runtimeInteractions = new Set();
|
|
33
|
+
function showInteraction(interaction) {
|
|
34
|
+
if (!interaction || runtimeInteractions.has(interaction.id)) return;
|
|
35
|
+
runtimeInteractions.add(interaction.id);
|
|
36
|
+
logMessage("system", escapeBlessed(`${interaction.prompt}\n${(interaction.options || []).map((option) => `[${option.key}] ${option.label}`).join(" ")}\n/answer ${interaction.id} <reply>`));
|
|
37
|
+
}
|
|
38
|
+
function handleRuntimeEvent(event) {
|
|
39
|
+
if (!event || !event.sessionId || !Number.isInteger(event.sequence)) return true;
|
|
40
|
+
const sessionKey = `${event.projectId || ""}:${event.sessionId}`;
|
|
41
|
+
if (event.sequence <= (runtimeSequences.get(sessionKey) || 0)) return true;
|
|
42
|
+
runtimeSequences.set(sessionKey, event.sequence);
|
|
43
|
+
const key = `${sessionKey}:${event.taskRunId}`;
|
|
44
|
+
const label = event.agentId === "ufoo-agent" ? "ufoo" : `task ${event.taskRunId}`;
|
|
45
|
+
if (event.type === "message.delta") {
|
|
46
|
+
const state = beginStream(key, speakerPrefix(label, "white"), " ", { runtime: true, sessionId: event.sessionId, taskRunId: event.taskRunId });
|
|
47
|
+
appendStreamDelta(state, event.text || "");
|
|
48
|
+
runtimeStreams.set(key, true);
|
|
49
|
+
} else if (["task.completed", "task.failed", "task.cancelled", "task.paused", "task.interrupted"].includes(event.type)) {
|
|
50
|
+
if (runtimeStreams.has(key)) {
|
|
51
|
+
finalizeStream(key, { sessionId: event.sessionId, taskRunId: event.taskRunId }, event.type);
|
|
52
|
+
runtimeStreams.delete(key);
|
|
53
|
+
} else if (event.type === "task.completed" && event.result?.text) {
|
|
54
|
+
let text = event.result.text;
|
|
55
|
+
if (event.global) { try { text = JSON.parse(text).reply || ""; } catch { text = ""; } }
|
|
56
|
+
if (text) logMessage("reply", `${speakerPrefix(label, "white")}${escapeBlessed(text)}`);
|
|
57
|
+
}
|
|
58
|
+
if (["task.failed", "task.interrupted"].includes(event.type)) logMessage("error", escapeBlessed(`${label}: ${event.error || event.type}`));
|
|
59
|
+
if (event.type === "task.paused") showInteraction(event.result?.executionState?.pendingUserInteraction);
|
|
60
|
+
runtimeFinished.add(event.taskRunId);
|
|
61
|
+
if (runtimeFinished.size > 500) runtimeFinished.delete(runtimeFinished.values().next().value);
|
|
62
|
+
requestStatus();
|
|
63
|
+
}
|
|
64
|
+
renderScreen();
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
function handleRuntimeResult(msg) {
|
|
68
|
+
const data = msg.data || {};
|
|
69
|
+
if (Array.isArray(data.events)) { data.events.forEach(handleRuntimeEvent); return true; }
|
|
70
|
+
const tasks = data.sessions ? [...data.sessions.flatMap((session) => session.tasks.map((task) => ({ ...task, sessionId: session.sessionId }))), ...(data.children || []), ...(data.delegated || [])]
|
|
71
|
+
: data.task ? [data.task] : [];
|
|
72
|
+
for (const task of tasks) {
|
|
73
|
+
const effects = Object.entries(task.effects || {}).map(([id, effect]) => `${id} (${effect.toolName}: ${effect.status})`).join(", ");
|
|
74
|
+
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}` : ""}`));
|
|
75
|
+
showInteraction(task.interaction);
|
|
76
|
+
}
|
|
77
|
+
for (const receipt of data.uncertainReceipts || []) logMessage("system", escapeBlessed(`Outcome unknown: ${receipt.commandId} (${receipt.kind}). Inspect effects before resubmitting.`));
|
|
78
|
+
if (!tasks.length) resolveStatusLine(escapeBlessed(data.status || (data.accepted ? "Accepted" : "Done")));
|
|
79
|
+
renderScreen();
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
35
82
|
|
|
36
83
|
function isLikelySubscriberId(value) {
|
|
37
84
|
const text = String(value || "");
|
|
@@ -139,6 +186,8 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
139
186
|
}
|
|
140
187
|
|
|
141
188
|
updateDashboard(data);
|
|
189
|
+
for (const session of data.agent_runtime?.sessions || []) for (const task of session.tasks || []) showInteraction(task.interaction);
|
|
190
|
+
for (const task of data.agent_runtime?.children || []) showInteraction(task.interaction);
|
|
142
191
|
return false;
|
|
143
192
|
}
|
|
144
193
|
|
|
@@ -247,7 +296,7 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
247
296
|
|
|
248
297
|
function handleResponseMessage(msg) {
|
|
249
298
|
const payload = msg.data || {};
|
|
250
|
-
if (payload.reply) {
|
|
299
|
+
if (payload.reply && !runtimeFinished.has(payload.runtime?.taskRunId)) {
|
|
251
300
|
const replyText = decodeEscapedNewlines(payload.reply);
|
|
252
301
|
resolveStatusLine(`{gray-fg}←{/gray-fg} ${escapeBlessed(replyText)}`);
|
|
253
302
|
const ops = Array.isArray(payload.ops) ? payload.ops : [];
|
|
@@ -345,7 +394,8 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
345
394
|
}
|
|
346
395
|
|
|
347
396
|
if (payload.dispatch && payload.dispatch.length > 0) {
|
|
348
|
-
const targets = payload.dispatch.map((d) => d.target || d).join(", ");
|
|
397
|
+
const targets = payload.dispatch.map((d) => resolveAgentDisplayName(d.target || d)).join(", ");
|
|
398
|
+
logMessage("system", `${speakerPrefix("ufoo", "white")}Task queued for: ${escapeBlessed(targets)}`);
|
|
349
399
|
resolveStatusLine(`{gray-fg}→{/gray-fg} Dispatched to: ${escapeBlessed(targets)}`);
|
|
350
400
|
}
|
|
351
401
|
|
|
@@ -376,7 +426,7 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
376
426
|
setPending(null);
|
|
377
427
|
}
|
|
378
428
|
|
|
379
|
-
if (!payload.reply && !payload.disambiguate) {
|
|
429
|
+
if (!payload.reply && !payload.disambiguate && !payload.dispatch?.length) {
|
|
380
430
|
resolveStatusLine("{gray-fg}✓{/gray-fg} Done");
|
|
381
431
|
}
|
|
382
432
|
|
|
@@ -431,47 +481,8 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
431
481
|
if (data.silent && !streamPayload) return true;
|
|
432
482
|
if (!displayMessage && !streamPayload) return true;
|
|
433
483
|
|
|
434
|
-
const viewingAgent = getViewingAgent();
|
|
435
|
-
const isOwnInternalPrompt =
|
|
436
|
-
data.source === "chat-internal-agent-view" &&
|
|
437
|
-
viewingAgent &&
|
|
438
|
-
data.target === viewingAgent &&
|
|
439
|
-
publisher !== viewingAgent;
|
|
440
|
-
if (
|
|
441
|
-
getCurrentView() === "agent" &&
|
|
442
|
-
isAgentViewUsesBus() &&
|
|
443
|
-
isOwnInternalPrompt
|
|
444
|
-
) {
|
|
445
|
-
return true;
|
|
446
|
-
}
|
|
447
|
-
const isAgentViewTarget =
|
|
448
|
-
getCurrentView() === "agent" &&
|
|
449
|
-
isAgentViewUsesBus() &&
|
|
450
|
-
viewingAgent &&
|
|
451
|
-
isAgentEventForViewingAgent(data, viewingAgent, publisher);
|
|
452
|
-
|
|
453
484
|
const displayName = resolveAgentDisplayName(publisher);
|
|
454
485
|
|
|
455
|
-
if (isAgentViewTarget) {
|
|
456
|
-
if (streamPayload) {
|
|
457
|
-
const delta = typeof streamPayload.delta === "string"
|
|
458
|
-
? decodeEscapedNewlines(streamPayload.delta)
|
|
459
|
-
: "";
|
|
460
|
-
if (delta || streamPayload.done) {
|
|
461
|
-
writeToAgentTerm(delta, {
|
|
462
|
-
data,
|
|
463
|
-
publisher,
|
|
464
|
-
streamPayload,
|
|
465
|
-
done: Boolean(streamPayload.done),
|
|
466
|
-
reason: streamPayload.reason || "",
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
} else if (displayMessage) {
|
|
470
|
-
writeToAgentTerm(`${displayMessage}\r\n`);
|
|
471
|
-
}
|
|
472
|
-
return true;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
486
|
if (data.event === "delivery" && consumePendingDelivery(publisher, displayName)) {
|
|
476
487
|
// Delivery confirmations are already shown in the status bar — suppress from chat.
|
|
477
488
|
requestStatus();
|
|
@@ -528,6 +539,8 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
528
539
|
|
|
529
540
|
function handleMessage(msg) {
|
|
530
541
|
if (!msg || typeof msg !== "object") return false;
|
|
542
|
+
if (msg.type === IPC_RESPONSE_TYPES.RUNTIME_EVENT) { handleRuntimeEvent(msg.data); return false; }
|
|
543
|
+
if (msg.type === IPC_RESPONSE_TYPES.RUNTIME_RESULT) { handleRuntimeResult(msg); return false; }
|
|
531
544
|
|
|
532
545
|
if (msg.type === IPC_RESPONSE_TYPES.STATUS) return handleStatusMessage(msg);
|
|
533
546
|
if (msg.type === IPC_RESPONSE_TYPES.RESPONSE) return handleResponseMessage(msg);
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const fs = require("fs");
|
|
9
9
|
const crypto = require("crypto");
|
|
10
|
-
const { stripBlessedTags } = require("../../ui/chatLogModel");
|
|
11
10
|
|
|
12
11
|
function projectRootToId(projectRoot) {
|
|
13
12
|
try {
|
|
@@ -44,11 +43,6 @@ function chatHistoryFilePath(projectRoot, options = {}) {
|
|
|
44
43
|
return path.join(getUfooPaths(projectRoot || process.cwd()).ufooDir, "chat", "history.jsonl");
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
function normalizeHistoryLogLines(text = "") {
|
|
48
|
-
const clean = stripBlessedTags(text);
|
|
49
|
-
return clean.split(/\r?\n/);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
46
|
function loadChatHistory(projectRoot, cap = 200, options = {}) {
|
|
53
47
|
const file = chatHistoryFilePath(projectRoot, options);
|
|
54
48
|
try {
|
|
@@ -56,56 +50,26 @@ function loadChatHistory(projectRoot, cap = 200, options = {}) {
|
|
|
56
50
|
const raw = fs.readFileSync(file, "utf8");
|
|
57
51
|
const lines = raw.split(/\r?\n/).filter(Boolean);
|
|
58
52
|
const out = [];
|
|
59
|
-
const pushLine = (line = "", sourceType = "") => {
|
|
60
|
-
const value = String(line || "");
|
|
61
|
-
if (!value.trim()) {
|
|
62
|
-
if (out.length > 0) {
|
|
63
|
-
const last = out[out.length - 1];
|
|
64
|
-
const lastText = typeof last === "object" ? last.text : last;
|
|
65
|
-
if (lastText !== "") out.push({ text: "", sourceType: sourceType || "system" });
|
|
66
|
-
}
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
out.push(sourceType ? { text: value, sourceType } : value);
|
|
70
|
-
};
|
|
71
53
|
for (const line of lines) {
|
|
72
54
|
try {
|
|
73
55
|
const entry = JSON.parse(line);
|
|
74
|
-
if (!entry) continue;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
pushLine(renderedLine, sourceType);
|
|
85
|
-
}
|
|
56
|
+
if (!entry || typeof entry !== "object") continue;
|
|
57
|
+
const sourceType = String(entry.type || entry.kind || "system");
|
|
58
|
+
const text = sourceType === "spacer" ? "" : String(entry.text || "").replace(/\r\n?/g, "\n");
|
|
59
|
+
if (!text && sourceType !== "spacer") continue;
|
|
60
|
+
if (!text.trim() && (!out.length || !out[out.length - 1].text.trim())) continue;
|
|
61
|
+
// A transcript block is the persistence unit. Splitting it into lines
|
|
62
|
+
// loses tool/thinking folds, speakers, paragraphs and fenced code.
|
|
63
|
+
out.push({ ...entry, text, sourceType,
|
|
64
|
+
meta: entry.meta && typeof entry.meta === "object" ? entry.meta : {},
|
|
65
|
+
});
|
|
86
66
|
} catch {
|
|
87
67
|
// ignore malformed lines
|
|
88
68
|
}
|
|
89
69
|
}
|
|
90
|
-
while (out.length > 0)
|
|
91
|
-
const first = out[0];
|
|
92
|
-
const firstText = typeof first === "object" ? first.text : first;
|
|
93
|
-
if (firstText !== "") break;
|
|
94
|
-
out.shift();
|
|
95
|
-
}
|
|
96
|
-
while (out.length > 0) {
|
|
97
|
-
const last = out[out.length - 1];
|
|
98
|
-
const lastText = typeof last === "object" ? last.text : last;
|
|
99
|
-
if (lastText !== "") break;
|
|
100
|
-
out.pop();
|
|
101
|
-
}
|
|
70
|
+
while (out.length > 0 && !out[out.length - 1].text.trim()) out.pop();
|
|
102
71
|
const capped = out.slice(-cap);
|
|
103
|
-
while (capped.length > 0)
|
|
104
|
-
const first = capped[0];
|
|
105
|
-
const firstText = typeof first === "object" ? first.text : first;
|
|
106
|
-
if (firstText !== "") break;
|
|
107
|
-
capped.shift();
|
|
108
|
-
}
|
|
72
|
+
while (capped.length > 0 && !capped[0].text.trim()) capped.shift();
|
|
109
73
|
return capped;
|
|
110
74
|
} catch {
|
|
111
75
|
return [];
|
|
@@ -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 = () => {},
|
|
@@ -17,10 +18,8 @@ function createInputSubmitHandler(options = {}) {
|
|
|
17
18
|
markPendingDelivery = () => {},
|
|
18
19
|
clearTargetAgent = () => {},
|
|
19
20
|
setTargetAgent = () => {},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
activateAgent = async () => {},
|
|
23
|
-
// When /multi is on: focus the in-window TUI pane instead of OS activate.
|
|
21
|
+
activateInternalAgent = () => {},
|
|
22
|
+
// In the all-children layout, focus an existing in-window TUI pane.
|
|
24
23
|
// Return true if handled.
|
|
25
24
|
focusMultiPane = null,
|
|
26
25
|
commitInputHistory = () => {},
|
|
@@ -50,38 +49,14 @@ function createInputSubmitHandler(options = {}) {
|
|
|
50
49
|
return true;
|
|
51
50
|
}
|
|
52
51
|
} catch {
|
|
53
|
-
//
|
|
52
|
+
// Try the host's internal side pane.
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (supportsActivate) {
|
|
63
|
-
clearTargetAgent();
|
|
64
|
-
try {
|
|
65
|
-
// Always use the host-wired activator. Bare adapterRouter adapters
|
|
66
|
-
// expose activate() that no-ops unless activateTerminal/activateTmux
|
|
67
|
-
// were injected — which chat hosts do not do.
|
|
68
|
-
const pendingActivation = activateAgent(agentId);
|
|
69
|
-
if (pendingActivation && typeof pendingActivation.catch === "function") {
|
|
70
|
-
pendingActivation.catch(() => {});
|
|
71
|
-
}
|
|
72
|
-
} catch {
|
|
73
|
-
// Best-effort activation.
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (supportsInternalQueue) {
|
|
79
|
-
clearTargetAgent();
|
|
80
|
-
enterAgentView(agentId, { useBus: true });
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return false;
|
|
56
|
+
const result = await activateInternalAgent(agentId);
|
|
57
|
+
if (!result || result.ok === false) return false;
|
|
58
|
+
clearTargetAgent();
|
|
59
|
+
return true;
|
|
85
60
|
}
|
|
86
61
|
|
|
87
62
|
async function handleSubmit(value) {
|
|
@@ -130,6 +105,12 @@ function createInputSubmitHandler(options = {}) {
|
|
|
130
105
|
}
|
|
131
106
|
|
|
132
107
|
if (state.targetAgent) {
|
|
108
|
+
if (requireKnownTarget && !resolveAgentId(state.targetAgent)) {
|
|
109
|
+
clearTargetAgent();
|
|
110
|
+
logMessage("error", "Unknown internal @target");
|
|
111
|
+
focusInput();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
133
114
|
const label = getAgentLabel(state.targetAgent);
|
|
134
115
|
logMessage(
|
|
135
116
|
"user",
|
|
@@ -159,11 +140,16 @@ function createInputSubmitHandler(options = {}) {
|
|
|
159
140
|
return;
|
|
160
141
|
}
|
|
161
142
|
setTargetAgent(resolvedTarget);
|
|
162
|
-
queueStatusLine(`Target selected: @${escapeBlessed(atTarget.target)}`);
|
|
143
|
+
if (!requireKnownTarget) queueStatusLine(`Target selected: @${escapeBlessed(atTarget.target)}`);
|
|
144
|
+
focusInput();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const resolvedTarget = resolveAgentId(atTarget.target) || (requireKnownTarget ? "" : atTarget.target);
|
|
148
|
+
if (!resolvedTarget) {
|
|
149
|
+
logMessage("error", "Unknown internal @target");
|
|
163
150
|
focusInput();
|
|
164
151
|
return;
|
|
165
152
|
}
|
|
166
|
-
const resolvedTarget = resolveAgentId(atTarget.target) || atTarget.target;
|
|
167
153
|
const message = atTarget.message.trim();
|
|
168
154
|
logMessage(
|
|
169
155
|
"user",
|