u-foo 4.0.3 → 4.0.10
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 +239 -19
- package/README.zh-CN.md +3 -3
- package/bin/ucode.js +10 -2
- package/bin/ufoo.js +3 -0
- 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/{OBSERVABILITY.md → docs/OBSERVABILITY.md} +3 -3
- package/docs/README.md +27 -0
- package/extensions/ufoo-browser/LICENSE +152 -0
- package/extensions/ufoo-browser/NOTICE +10 -0
- package/extensions/ufoo-browser/README.md +30 -0
- package/extensions/ufoo-browser/background.js +409 -0
- package/extensions/ufoo-browser/icons/icon-128.png +0 -0
- package/extensions/ufoo-browser/icons/icon-16.png +0 -0
- package/extensions/ufoo-browser/icons/icon-256.png +0 -0
- package/extensions/ufoo-browser/icons/icon-32.png +0 -0
- package/extensions/ufoo-browser/icons/icon-48.png +0 -0
- package/extensions/ufoo-browser/icons/logo.png +0 -0
- package/extensions/ufoo-browser/icons/toolbar-16.png +0 -0
- package/extensions/ufoo-browser/icons/toolbar-32.png +0 -0
- package/extensions/ufoo-browser/icons/toolbar-logo.png +0 -0
- package/extensions/ufoo-browser/manifest.json +30 -0
- package/extensions/ufoo-browser/popup.css +71 -0
- package/extensions/ufoo-browser/popup.html +44 -0
- package/extensions/ufoo-browser/popup.js +153 -0
- package/package.json +7 -5
- package/scripts/postinstall.js +6 -0
- package/src/agents/capabilities/browser/index.js +49 -0
- package/src/agents/capabilities/coding/backgroundHooks.js +94 -0
- package/src/agents/capabilities/coding/index.js +30 -1
- package/src/agents/capabilities/index.js +5 -2
- package/src/agents/capabilities/planning/index.js +44 -5
- package/src/agents/capabilities/turnRecall/index.js +341 -0
- package/src/agents/controller/controllerToolExecutor.js +2 -2
- package/src/agents/internal/internalRunner.js +30 -8
- package/src/agents/internal/taskControl.js +107 -0
- package/src/agents/profiles/coding.js +1 -1
- package/src/agents/profiles/main.js +1 -1
- package/src/agents/prompts/mainAgent.js +1 -0
- package/src/agents/prompts/native/toolDescriptions/bash.js +7 -1
- package/src/agents/providers/claudeSessionFiles.js +1 -1
- package/src/agents/providers/codexThreadProvider.js +6 -1
- package/src/agents/providers/credentials/agy.js +171 -0
- package/src/agents/providers/directAuthStatus.js +20 -2
- package/src/agents/providers/modelsCatalog.js +26 -5
- package/src/agents/providers/nativeTransport.js +145 -73
- package/src/agents/providers/providerId.js +17 -0
- package/src/agents/providers/runtimeConfig.js +67 -20
- package/src/agents/providers/transports/antigravityTransport.js +242 -0
- package/src/agents/providers/transports/index.js +1 -0
- package/src/agents/providers/transports/openaiChatTransport.js +3 -2
- package/src/agents/providers/transports/openaiResponsesTransport.js +2 -1
- package/src/agents/providers/transports/responsesProtocol.js +119 -18
- package/src/agents/providers/transports/transportContract.js +1 -0
- package/src/agents/providers/upstreamRuntime.js +3 -1
- package/src/agents/runtime/context/contextBudget.js +1 -19
- package/src/agents/runtime/context/contextWindow.js +5 -0
- package/src/agents/runtime/context/replayHistory.js +16 -10
- package/src/agents/runtime/context/runtimeStore.js +0 -1
- package/src/agents/runtime/context/sessionJournal.js +1 -1
- package/src/agents/runtime/context/slidingWindowManager.js +792 -0
- package/src/agents/runtime/context/topicSelector.js +338 -0
- package/src/agents/runtime/context/turnAnalyzer.js +767 -0
- package/src/agents/runtime/context/turnIndexStore.js +515 -0
- package/src/agents/runtime/core/agentLoop.js +140 -35
- package/src/agents/runtime/core/executionBudget.js +2 -1
- package/src/agents/runtime/core/toolErrorGuard.js +39 -0
- package/src/agents/runtime/createAgentRuntime.js +80 -7
- package/src/agents/runtime/index.js +5 -0
- package/src/agents/runtime/protocol/materialize.js +1 -1
- package/src/agents/runtime/tasks/hooks.js +137 -0
- package/src/app/chat/ChatController.js +8 -4
- package/src/app/chat/daemonMessageRouter.js +3 -1
- package/src/app/chat/inputSubmitHandler.js +2 -2
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/browserCommands.js +340 -0
- package/src/app/cli/busCoreCommands.js +63 -3
- package/src/app/cli/features/doctor.js +21 -0
- package/src/app/cli/metricsCommands.js +1 -1
- package/src/app/cli/run.js +81 -1
- package/src/app/cli/setupCommands.js +200 -0
- package/src/code/UcodeController.js +31 -1
- package/src/code/agent.js +76 -25
- package/src/code/busConsumer.js +13 -12
- package/src/code/commands.js +0 -1
- package/src/code/context/assembler.js +11 -88
- package/src/code/context/planGraphService.js +121 -6
- package/src/code/context/planProjection.js +10 -2
- package/src/code/context/reducers.js +172 -4
- package/src/code/context/stateCommit.js +0 -32
- package/src/code/context/transcript.js +7 -4
- package/src/code/internalThread.js +9 -1
- package/src/code/launcher/ucode.js +4 -2
- package/src/code/modelCommand.js +6 -5
- package/src/code/nativeRunner.js +232 -62
- package/src/code/repl.js +27 -1
- package/src/code/runtime/agentWakeup.js +20 -3
- package/src/code/runtime/backgroundWakeHost.js +45 -0
- package/src/code/runtime/taskFocusContext.js +7 -0
- package/src/code/runtime/taskLoop.js +24 -1
- package/src/code/sessionStore.js +14 -10
- package/src/code/taskDecomposer.js +16 -7
- package/src/code/tools/backgroundProcess.js +23 -0
- package/src/code/tools/bash.js +764 -12
- package/src/code/tools/executor.js +13 -4
- package/src/code/tools/planGraph.js +1 -0
- package/src/code/tools/specs.js +62 -4
- package/src/code/tools/taskRun.js +38 -0
- package/src/config.js +92 -6
- package/src/coordination/bus/index.js +2 -2
- package/src/coordination/bus/message.js +10 -1
- package/src/coordination/bus/nickname.js +3 -1
- package/src/coordination/bus/subscriber.js +25 -10
- package/src/coordination/bus/utils.js +4 -0
- package/src/coordination/bus/wakeEndpoint.js +198 -0
- package/src/coordination/history/agentPerformance.js +18 -18
- package/src/coordination/history/agentTrace.js +7 -3
- package/src/coordination/state/paths.js +4 -0
- package/src/coordination/state/workspaceAccess.js +3 -1
- package/src/orchestration/groups/modelConfig.js +66 -0
- package/src/orchestration/groups/validateTemplate.js +2 -0
- package/src/runtime/browser/broker.js +1027 -0
- package/src/runtime/browser/brokerClient.js +108 -0
- package/src/runtime/browser/componentInstaller.js +275 -0
- package/src/runtime/browser/installState.js +329 -0
- package/src/runtime/browser/manifest.js +145 -0
- package/src/runtime/browser/native-host-runner.js +198 -0
- package/src/runtime/browser/nativeHost.js +213 -0
- package/src/runtime/browser/nativeMessagingProtocol.js +50 -0
- package/src/runtime/browser/paths.js +134 -0
- package/src/runtime/browser/playwrightSession.js +614 -0
- package/src/runtime/daemon/agentHost.js +175 -28
- package/src/runtime/daemon/busBridge.js +2 -1
- package/src/runtime/daemon/deliveryScheduler.js +70 -2
- package/src/runtime/daemon/globalDaemon.js +20 -0
- package/src/runtime/daemon/groupOrchestrator.js +20 -1
- package/src/runtime/daemon/index.js +6 -4
- package/src/runtime/daemon/ops.js +14 -8
- package/src/tools/handlers/listAgents.js +1 -1
- package/src/tools/handlers/readBusSummary.js +1 -1
- package/src/tools/handlers/routeAgent.js +122 -5
- package/src/tools/schemaFixtures.js +1 -1
- package/src/ui/agentSurface.js +60 -6
- package/src/ui/format/index.js +34 -2
- package/src/ui/format/markdownRenderer.js +4 -2
- package/src/ui/rustChatHost.js +22 -7
- package/src/ui/rustMultiSession.js +14 -2
- package/src/ui/rustUcodeHost.js +249 -80
- package/src/ui/ucodeAgentSession.js +88 -0
- package/templates/groups/build-lane.json +57 -3
- package/templates/groups/build-ultra.json +114 -6
- package/templates/groups/design-system.json +57 -3
- package/templates/groups/product-discovery.json +57 -3
- package/templates/groups/ui-plan-review.json +57 -3
- package/templates/groups/ui-polish.json +57 -3
- package/templates/groups/verify-ship.json +57 -3
- package/src/agents/runtime/context/checkpointStore.js +0 -38
- package/src/agents/runtime/context/compaction.js +0 -151
|
@@ -7,8 +7,10 @@ const { stableStringify } = require("../../agents/runtime/core/stableJson");
|
|
|
7
7
|
const { resolveToolBudget, resolveTaskTimeoutMs } = require("../../agents/runtime/core/executionBudget");
|
|
8
8
|
const { spawnSync } = require("child_process");
|
|
9
9
|
const { createAgentRuntime, createRuntimeStore, createTaskScheduler } = require("../../agents/runtime");
|
|
10
|
-
const { createMainCapabilities, createGlobalCapabilities } = require("../../agents/capabilities");
|
|
10
|
+
const { createMainCapabilities, createGlobalCapabilities, createTurnRecallCapability } = require("../../agents/capabilities");
|
|
11
|
+
const { createBrowserCapability } = require("../../agents/capabilities/browser");
|
|
11
12
|
const { createCodingCapability } = require("../../agents/capabilities/coding");
|
|
13
|
+
const { createBackgroundHookSource } = require("../../agents/capabilities/coding/backgroundHooks");
|
|
12
14
|
const { createMainPlanningCapability } = require("../../agents/capabilities/planning/main");
|
|
13
15
|
const { createSkillsCapability } = require("../../agents/capabilities/skills");
|
|
14
16
|
const { createAgentManagementService } = require("../../agents/capabilities/agentManagement/service");
|
|
@@ -17,7 +19,7 @@ const { TOOL_PERMISSIONS } = require("../../agents/capabilities/coordination");
|
|
|
17
19
|
const { getNativeTransport } = require("../../agents/providers/nativeTransport");
|
|
18
20
|
const { resolveRuntimeConfig } = require("../../agents/providers/runtimeConfig");
|
|
19
21
|
const { resolveUpstreamRuntime, normalizeProvider } = require("../../agents/providers/upstreamRuntime");
|
|
20
|
-
const { loadConfig, defaultAgentModelForProvider, sameModelProvider } = require("../../config");
|
|
22
|
+
const { loadConfig, defaultAgentModelForProvider, defaultAuxModelForProvider, sameModelProvider } = require("../../config");
|
|
21
23
|
const mainProfile = require("../../agents/profiles/main");
|
|
22
24
|
const globalProfile = require("../../agents/profiles/globalRouter");
|
|
23
25
|
const { buildMainAgentPrompt, buildCodingTaskPrompt } = require("../../agents/prompts/mainAgent");
|
|
@@ -35,12 +37,15 @@ const { canonicalProjectRoot, buildProjectId } = require("../projects/projectId"
|
|
|
35
37
|
const { resolveWorkspacePath } = require("../../code/tools/common");
|
|
36
38
|
const { listControllerInboxEntries } = require("../../coordination/report/store");
|
|
37
39
|
const { redactSecrets } = require("../privacy/redactor");
|
|
38
|
-
const {
|
|
40
|
+
const { createTurnIndexStore } = require("../../agents/runtime/context/turnIndexStore");
|
|
41
|
+
const { buildDeterministicTurnRecord, backfillMissingTurns, createAsyncTurnEnricher } = require("../../agents/runtime/context/turnAnalyzer");
|
|
42
|
+
const { createTopicSelector } = require("../../agents/runtime/context/topicSelector");
|
|
43
|
+
const { createSlidingWindowManager } = require("../../agents/runtime/context/slidingWindowManager");
|
|
39
44
|
const { replayHistory } = require("../../agents/runtime/context/replayHistory");
|
|
40
45
|
|
|
41
46
|
const hash = (value) => createHash("sha256").update(value).digest("hex").slice(0, 32);
|
|
42
47
|
const safeId = (value) => /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,100}$/.test(value || "");
|
|
43
|
-
const MAIN_GRANTS = ["workspace.read", "workspace.write", "workspace.execute", "interaction.request", "coordination.read", "coordination.write", "agents.manage", "memory.write", "tasks.accept", "tasks.execute", "groups.manage", "schedules.manage"];
|
|
48
|
+
const MAIN_GRANTS = ["workspace.read", "workspace.write", "workspace.execute", "interaction.request", "coordination.read", "coordination.write", "agents.manage", "memory.write", "tasks.accept", "tasks.execute", "groups.manage", "schedules.manage", "browser.control"];
|
|
44
49
|
|
|
45
50
|
function resolveTaskWorkspace(projectRoot, requested = "") {
|
|
46
51
|
const target = canonicalProjectRoot(requested || projectRoot);
|
|
@@ -92,16 +97,17 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
92
97
|
const workspaceAccess = createWorkspaceAccess({ projectRoot: root, externalWriters(context) {
|
|
93
98
|
const tasks = Object.values(management.snapshot().tasks);
|
|
94
99
|
const pending = tasks.filter((task) => ["planning", "awaiting_registration"].includes(task.status) && !task.workerId).map((task) => task.taskId);
|
|
95
|
-
return [...pending, ...readBusSummaryHandler({ projectRoot: root
|
|
100
|
+
return [...pending, ...readBusSummaryHandler({ projectRoot: root }).active_agents.filter((agent) => {
|
|
96
101
|
if (agent.id === context.agentId || agent.id === "ufoo-agent") return false;
|
|
97
102
|
const assigned = tasks.filter((task) => task.workerId === agent.id);
|
|
103
|
+
if (!isInternalAgentMeta(agent) && !assigned.length) return false;
|
|
98
104
|
return !assigned.length || assigned.some((task) => ["planning", "queued", "delivered", "delivery_uncertain", "running"].includes(task.status))
|
|
99
105
|
|| ["working", "starting", "running"].includes(agent.activity_state);
|
|
100
106
|
}).map((agent) => agent.id)];
|
|
101
107
|
} });
|
|
102
108
|
const management = createAgentManagementService({ store: control,
|
|
103
109
|
resolveTarget(target) {
|
|
104
|
-
const matches = readBusSummaryHandler({ projectRoot: root
|
|
110
|
+
const matches = readBusSummaryHandler({ projectRoot: root }).active_agents.filter((agent) => agent.id !== "ufoo-agent"
|
|
105
111
|
&& [agent.id, agent.nickname, agent.scoped_nickname, agent.display_nickname].includes(target));
|
|
106
112
|
return matches.length === 1 ? matches[0].id : "";
|
|
107
113
|
},
|
|
@@ -171,6 +177,10 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
171
177
|
return { ok: true, task: publicChild(jobs()[job.id]) };
|
|
172
178
|
} };
|
|
173
179
|
async function coordinatedOps(project, ops, manager) {
|
|
180
|
+
const registered = loadAgentsData(getUfooPaths(project).agentsFile).agents;
|
|
181
|
+
for (const op of ops) if (["close", "rename"].includes(op.action) && !isInternalAgentMeta(registered[op.agent_id])) {
|
|
182
|
+
throw Object.assign(new Error("External agents own their lifecycle; use messages instead"), { code: "external_lifecycle" });
|
|
183
|
+
}
|
|
174
184
|
ops = ops.map((op) => op.action === "launch" ? { ...op, internal_only: true } : op);
|
|
175
185
|
if (!ops.some((op) => op.action === "launch")) return ports.handleOps(project, ops, manager);
|
|
176
186
|
const ownerId = `launch-${randomUUID()}`;
|
|
@@ -188,20 +198,72 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
188
198
|
}
|
|
189
199
|
function makeRuntime({ sessionId, namespace, profile, capabilities, host, workspaceRoot = root, child = null }) {
|
|
190
200
|
const productConfig = loadConfig(root);
|
|
201
|
+
const effectivePolicy = {
|
|
202
|
+
...(productConfig.context && typeof productConfig.context === "object" ? productConfig.context : {}),
|
|
203
|
+
...(contextPolicy && typeof contextPolicy === "object" ? contextPolicy : {}),
|
|
204
|
+
};
|
|
191
205
|
const store = createRuntimeStore({ workspaceRoot: root, namespace, sessionId, redact: redactSecrets });
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
const turnIndexStore = createTurnIndexStore({ workspaceRoot: root, namespace, sessionId, redact: redactSecrets });
|
|
207
|
+
backfillMissingTurns({ store: turnIndexStore, runtimeEvents: store.events() });
|
|
208
|
+
let latestResolvedAuth = null;
|
|
209
|
+
const explicitAuxModel = String(effectivePolicy?.auxModel || productConfig.agentAuxModel || "").trim();
|
|
210
|
+
const allowDefaultAux = !process.env.JEST_WORKER_ID
|
|
211
|
+
|| Boolean(effectivePolicy?.enableModelSelector || effectivePolicy?.backgroundEnrich);
|
|
212
|
+
const canUseAuxModel = typeof effectivePolicy?.runAuxModel === "function"
|
|
213
|
+
|| Boolean(explicitAuxModel)
|
|
214
|
+
|| allowDefaultAux;
|
|
215
|
+
const runAuxModel = typeof effectivePolicy?.runAuxModel === "function"
|
|
216
|
+
? effectivePolicy.runAuxModel
|
|
217
|
+
: canUseAuxModel
|
|
218
|
+
? async ({ purpose, currentQuery, activeTopics, candidates, turn, existingTopics, signal }) => {
|
|
219
|
+
const auth = latestResolvedAuth;
|
|
220
|
+
if (!auth || !auth.url || !auth.transport) return null;
|
|
221
|
+
const targetAuxModel = explicitAuxModel
|
|
222
|
+
|| (allowDefaultAux ? defaultAuxModelForProvider(auth.provider) : "");
|
|
223
|
+
if (!targetAuxModel) return null;
|
|
224
|
+
const systemPrompt = purpose === "topic_select"
|
|
225
|
+
? "Select relevant historical turns and topics as strict JSON: {\"isNewTopic\":boolean,\"matchedTopics\":string[],\"referencedTurnIds\":string[]}. Do not include markdown or prose."
|
|
226
|
+
: "Summarize the completed agent turn as strict JSON: {\"topic\":string,\"userSummary\":string,\"assistantSummary\":string,\"decisions\":string[],\"keywords\":string[]}. Do not include markdown or prose.";
|
|
227
|
+
const userPayload = purpose === "topic_select"
|
|
228
|
+
? { currentQuery, activeTopics, candidates }
|
|
229
|
+
: { turn, existingTopics };
|
|
230
|
+
const res = await auth.transport.runTurn({
|
|
231
|
+
url: auth.url,
|
|
232
|
+
apiKey: auth.apiKey,
|
|
233
|
+
model: targetAuxModel,
|
|
234
|
+
provider: auth.provider,
|
|
235
|
+
accountId: auth.accountId,
|
|
236
|
+
requestHeaders: auth.requestHeaders,
|
|
237
|
+
requestProfile: auth.requestProfile,
|
|
238
|
+
systemPrompt,
|
|
239
|
+
messages: [{ role: "user", content: JSON.stringify(userPayload) }],
|
|
240
|
+
tools: [],
|
|
241
|
+
maxOutputTokens: 512,
|
|
242
|
+
sessionId: `${sessionId}:aux`,
|
|
243
|
+
signal,
|
|
244
|
+
});
|
|
245
|
+
return res && res.text ? res.text : "";
|
|
246
|
+
}
|
|
247
|
+
: null;
|
|
248
|
+
const topicSelector = createTopicSelector({
|
|
249
|
+
...effectivePolicy,
|
|
250
|
+
runAuxModel,
|
|
251
|
+
enableModelSelector: Boolean(runAuxModel && (effectivePolicy?.enableModelSelector ?? true)),
|
|
252
|
+
});
|
|
253
|
+
const enricher = createAsyncTurnEnricher({
|
|
254
|
+
store: turnIndexStore,
|
|
255
|
+
runAuxModel,
|
|
256
|
+
enabled: Boolean(runAuxModel && (effectivePolicy?.backgroundEnrich ?? true)),
|
|
257
|
+
timeoutMs: effectivePolicy?.enrichTimeoutMs || 8000,
|
|
258
|
+
onEvent: (ev) => {
|
|
259
|
+
try { store.append(ev); } catch {}
|
|
203
260
|
},
|
|
204
|
-
}
|
|
261
|
+
});
|
|
262
|
+
const contextManager = createSlidingWindowManager({
|
|
263
|
+
policy: effectivePolicy,
|
|
264
|
+
turnIndexStore,
|
|
265
|
+
topicSelector,
|
|
266
|
+
});
|
|
205
267
|
const previousBinding = store.read().binding;
|
|
206
268
|
const configuredProvider = normalizeProvider(provider || productConfig.agentProvider || "ucode");
|
|
207
269
|
const useCodingConfig = previousBinding?.codingConfig ?? configuredProvider === "ucode";
|
|
@@ -209,7 +271,8 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
209
271
|
const modelRevision = Number(productConfig.agentModelRevision) || 0;
|
|
210
272
|
const changedModel = !useCodingConfig && modelRevision > (Number(previousBinding?.modelRevision) || 0)
|
|
211
273
|
&& sameModelProvider(productConfig.agentProvider, selectedProvider);
|
|
212
|
-
const selectedModel = (changedModel ? productConfig.agentModel : "") || previousBinding?.model || model || (useCodingConfig ? "" :
|
|
274
|
+
const selectedModel = (changedModel ? productConfig.agentModel : "") || previousBinding?.model || model || (useCodingConfig ? "" :
|
|
275
|
+
(sameModelProvider(productConfig.agentProvider, selectedProvider) ? productConfig.agentModel : "") || defaultAgentModelForProvider(selectedProvider));
|
|
213
276
|
const config = resolveRuntimeConfig({ workspaceRoot: root, provider: selectedProvider, model: selectedModel, useCodingConfig });
|
|
214
277
|
const transport = transportFactory(config.transport);
|
|
215
278
|
const binding = { provider: selectedProvider || config.provider, model: config.model, transport: config.transport, codingConfig: useCodingConfig,
|
|
@@ -234,12 +297,12 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
234
297
|
if (useCodingConfig) resolved.baseUrl = config.baseUrl;
|
|
235
298
|
const expected = resolved.transport === "codex-responses" ? "openai-responses" : resolved.transport;
|
|
236
299
|
if (expected !== config.transport) throw new Error("provider transport changed; start a new session");
|
|
237
|
-
const context = child ? [] : [readBusSummaryHandler({ projectRoot: root
|
|
300
|
+
const context = child ? [] : [readBusSummaryHandler({ projectRoot: root }), readOpenDecisionsHandler({ projectRoot: root }, { limit: 20 }),
|
|
238
301
|
{ memory: buildCachedMemoryPrefix(root, { limit: 30, maxTokens: 1500 }).prefix || "" }, { delegatedTasks: Object.values(management.snapshot().tasks).slice(-30) }];
|
|
239
302
|
if (!child) {
|
|
240
303
|
const registered = loadAgentsData(getUfooPaths(root).agentsFile).agents;
|
|
241
304
|
context.push({ requestMeta: request.requestMeta || {}, reports: listControllerInboxEntries(root, "ufoo-agent", { num: 30 })
|
|
242
|
-
.filter((report) =>
|
|
305
|
+
.filter((report) => Boolean(registered[report.agent_id])) });
|
|
243
306
|
}
|
|
244
307
|
const sources = await runtime.buildContext({ workspaceRoot, prompt: request.text, promptText: request.text });
|
|
245
308
|
const skillSource = sources.find((source) => source.capabilityId === "skills")?.value;
|
|
@@ -248,14 +311,24 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
248
311
|
if (skillSource) context.push({ skills: { active: skillSource.activeSkills, warnings: skillSource.warnings } });
|
|
249
312
|
const instructionFile = path.join(workspaceRoot, "AGENTS.md");
|
|
250
313
|
const instructions = fs.existsSync(instructionFile) ? fs.readFileSync(instructionFile, "utf8").slice(0, 16000) : "";
|
|
251
|
-
const history = child ? [] : replayHistory(store.events(), task.taskRunId);
|
|
314
|
+
const history = child && !request.runtimeEvent ? [] : replayHistory(store.events(), task.taskRunId);
|
|
252
315
|
const attachments = (request.attachments || []).map((attachment) => resolveWorkspacePath(workspaceRoot, typeof attachment === "string" ? attachment : attachment.path).resolved);
|
|
316
|
+
const resolvedUrl = typeof transport.resolveUrl === "function" ? transport.resolveUrl(resolved.baseUrl) : resolved.baseUrl;
|
|
317
|
+
latestResolvedAuth = {
|
|
318
|
+
transport,
|
|
319
|
+
url: resolvedUrl,
|
|
320
|
+
apiKey: resolved.auth?.apiKey || "",
|
|
321
|
+
provider: resolved.provider === "claude" ? "anthropic" : resolved.provider,
|
|
322
|
+
accountId: resolved.credential?.accountId || "",
|
|
323
|
+
requestHeaders: resolved.auth?.headers || {},
|
|
324
|
+
requestProfile: resolved.requestProfile || "",
|
|
325
|
+
};
|
|
253
326
|
return { workspaceRoot, sessionId, projectId, agentId: child ? child.id : "ufoo-agent", artifactNamespace: namespace,
|
|
254
327
|
model: resolved.model, provider: resolved.provider === "claude" ? "anthropic" : resolved.provider,
|
|
255
328
|
baseUrl: resolved.baseUrl, apiKey: resolved.auth?.apiKey || "", requestHeaders: resolved.auth?.headers || {},
|
|
256
329
|
accountId: resolved.credential?.accountId || "", requestProfile: resolved.requestProfile || "",
|
|
257
330
|
thinkingLevel: currentConfig.agentThinking || "medium",
|
|
258
|
-
requestKind: child ? "coding-task" : request.report ? "worker-report" : request.parentTaskRunId ? "task-result" : "user",
|
|
331
|
+
requestKind: request.runtimeEvent ? "system_wake" : child ? "coding-task" : request.report ? "worker-report" : request.parentTaskRunId ? "task-result" : "user",
|
|
259
332
|
prompt: resumed ? "" : request.text + (attachments.length ? `\n\nWorkspace attachments (read with read/read_image): ${JSON.stringify(attachments)}` : ""), historyMessages: history,
|
|
260
333
|
systemPrompt: child ? buildCodingTaskPrompt({ workspaceRoot, instructions, skillBlocks, toolNames: runtime.tools.names() }) : buildMainAgentPrompt({ global, workspaceRoot, skillBlocks, toolNames: runtime.tools.names(), promptSections: runtime.promptSections, context, instructions: global ? "" : instructions }),
|
|
261
334
|
timeoutMs: resolveTaskTimeoutMs(), toolBudget: resolveToolBudget(),
|
|
@@ -263,7 +336,75 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
263
336
|
};
|
|
264
337
|
};
|
|
265
338
|
runtime = createAgentRuntime({ profile, capabilities, transport,
|
|
266
|
-
host: { ...host, projectId, agentId: child ? child.id : "ufoo-agent", sessionStore: store, prepareRequest: prepare,
|
|
339
|
+
host: { ...host, ...(!global && (!child || !child.readOnly) ? { hookSources: { background: createBackgroundHookSource(workspaceRoot) } } : {}), contextNamespace: namespace, projectId, agentId: child ? child.id : "ufoo-agent", sessionStore: store, prepareRequest: prepare,
|
|
340
|
+
onTasksInterrupted(tasks = []) {
|
|
341
|
+
const existing = turnIndexStore.listTurns();
|
|
342
|
+
for (const task of tasks) {
|
|
343
|
+
const turnId = task.taskRunId;
|
|
344
|
+
if (!turnId || turnIndexStore.getTurn(turnId)) continue;
|
|
345
|
+
const requestKind = task.request?.runtimeEvent ? "system_wake" : child ? "coding-task" : task.request?.report ? "worker-report" : task.request?.parentTaskRunId ? "task-result" : "user";
|
|
346
|
+
const baseHistory = child ? [] : replayHistory(store.events(), turnId);
|
|
347
|
+
const record = buildDeterministicTurnRecord({
|
|
348
|
+
turnId,
|
|
349
|
+
turnIndex: existing.length,
|
|
350
|
+
historyOffset: baseHistory.length,
|
|
351
|
+
historyEnd: baseHistory.length + (task.request?.text ? 1 : 0),
|
|
352
|
+
turnMessages: task.request?.text ? [{ role: "user", content: task.request.text }] : [],
|
|
353
|
+
requestKind,
|
|
354
|
+
prompt: task.request?.text || "",
|
|
355
|
+
outcome: "interrupted",
|
|
356
|
+
error: "owner stopped; inspect effects before resubmitting",
|
|
357
|
+
startedAt: task.startedAt || task.createdAt,
|
|
358
|
+
previousTurns: existing,
|
|
359
|
+
});
|
|
360
|
+
const saved = turnIndexStore.upsertTurn(record, { phase: "A" });
|
|
361
|
+
existing.push(saved);
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
async onTurnSettled({ task, outcome = "completed", error = "", messages = [], historyOffset = 0 } = {}) {
|
|
365
|
+
if (!task || !task.taskRunId) return null;
|
|
366
|
+
const existingTurns = turnIndexStore.listTurns();
|
|
367
|
+
const existing = existingTurns.find((item) => item.turnId === task.taskRunId) || null;
|
|
368
|
+
const requestKind = task.request?.runtimeEvent ? "system_wake" : child ? "coding-task" : task.request?.report ? "worker-report" : task.request?.parentTaskRunId ? "task-result" : "user";
|
|
369
|
+
const promptText = String(task.request?.text || "");
|
|
370
|
+
const turnMessages = Array.isArray(messages) ? messages.slice() : [];
|
|
371
|
+
if (!turnMessages.length && promptText) {
|
|
372
|
+
turnMessages.push({ role: "user", content: promptText });
|
|
373
|
+
}
|
|
374
|
+
const resolvedOffset = child
|
|
375
|
+
? 0
|
|
376
|
+
: (Number.isInteger(historyOffset) && historyOffset >= 0 ? historyOffset : replayHistory(store.events(), task.taskRunId).length);
|
|
377
|
+
const record = buildDeterministicTurnRecord({
|
|
378
|
+
turnId: task.taskRunId,
|
|
379
|
+
turnIndex: existing ? existing.turnIndex : existingTurns.length,
|
|
380
|
+
historyOffset: resolvedOffset,
|
|
381
|
+
historyEnd: resolvedOffset + turnMessages.length,
|
|
382
|
+
turnMessages,
|
|
383
|
+
requestKind,
|
|
384
|
+
prompt: promptText,
|
|
385
|
+
outcome,
|
|
386
|
+
error: error || "",
|
|
387
|
+
startedAt: task.startedAt || task.createdAt,
|
|
388
|
+
previousTurns: existingTurns,
|
|
389
|
+
resume: task.answer !== undefined,
|
|
390
|
+
});
|
|
391
|
+
const saved = turnIndexStore.upsertTurn(record, { phase: "A" });
|
|
392
|
+
if (outcome === "completed") {
|
|
393
|
+
enricher.enqueue(saved);
|
|
394
|
+
if (effectivePolicy?.awaitEnrich) {
|
|
395
|
+
await enricher.flush();
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return {
|
|
399
|
+
type: "context.turn_indexed",
|
|
400
|
+
taskRunId: task.taskRunId,
|
|
401
|
+
turnId: saved.turnId,
|
|
402
|
+
topic: saved.topic,
|
|
403
|
+
turnKind: saved.turnKind,
|
|
404
|
+
outcome: saved.outcome,
|
|
405
|
+
};
|
|
406
|
+
},
|
|
407
|
+
onClose: () => enricher.close(),
|
|
267
408
|
validateAnswer(task, answer) {
|
|
268
409
|
const parsed = parseUserInteractionInput(task.result.executionState.pendingUserInteraction, typeof answer === "string" ? answer : JSON.stringify(answer));
|
|
269
410
|
if (!parsed.ok) throw new Error(parsed.error);
|
|
@@ -290,10 +431,11 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
290
431
|
function getSession(sessionId = "main-default") {
|
|
291
432
|
if (closed || !safeId(sessionId)) throw new Error("invalid or closed main session");
|
|
292
433
|
if (sessions.has(sessionId)) return sessions.get(sessionId);
|
|
293
|
-
const
|
|
434
|
+
const namespace = global ? "global-router" : "main";
|
|
435
|
+
const host = { grantedPermissions: global ? ["coordination.read"] : MAIN_GRANTS, contextNamespace: namespace, workspaceAccess,
|
|
294
436
|
taskScheduler: conversationScheduler,
|
|
295
437
|
projectRouting: { list: () => listProjectRuntimes({ validate: true }) },
|
|
296
|
-
coordination: { ...ports, internalAgentsOnly: true, handleOps: coordinatedOps, projectRoot: root, agentManagement: management, taskScheduler: taskPort } };
|
|
438
|
+
coordination: { ...ports, internalAgentsOnly: true, includeExternalAgents: true, handleOps: coordinatedOps, projectRoot: root, agentManagement: management, taskScheduler: taskPort } };
|
|
297
439
|
host.coordination.execute = (ctx, call) => {
|
|
298
440
|
const permission = TOOL_PERMISSIONS[call.name];
|
|
299
441
|
const readOnly = ["manage_tasks", "manage_group", "resume_agents", "manage_cron"].includes(call.name)
|
|
@@ -314,10 +456,10 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
314
456
|
}
|
|
315
457
|
function getChild(job) {
|
|
316
458
|
if (children.has(job.id)) return children.get(job.id);
|
|
317
|
-
const grants = job.readOnly ? ["workspace.read"] : ["workspace.read", "workspace.write", "workspace.execute", "interaction.request"];
|
|
459
|
+
const grants = job.readOnly ? ["workspace.read"] : ["workspace.read", "workspace.write", "workspace.execute", "interaction.request", "browser.control"];
|
|
318
460
|
const coding = createCodingCapability({ workspaceAccess });
|
|
319
461
|
coding.tools = coding.tools.filter((tool) => tool.permissions.every((permission) => grants.includes(permission)));
|
|
320
|
-
const capabilities = [coding, createSkillsCapability(), ...(job.readOnly ? [] : [createMainPlanningCapability()])];
|
|
462
|
+
const capabilities = [coding, createSkillsCapability(), createTurnRecallCapability({ projectRoot: job.workspaceRoot, contextNamespace: "main-task" }, { defaultNamespace: "main-task" }), ...(job.readOnly ? [] : [createMainPlanningCapability(), createBrowserCapability()])];
|
|
321
463
|
const host = { grantedPermissions: grants, taskScheduler: { schedule(options, work) {
|
|
322
464
|
return scheduler.schedule(options, (signal) => job.readOnly ? work(signal)
|
|
323
465
|
: workspaceAccess.runTask({ workspaceRoot: job.workspaceRoot, taskRunId: options.id, signal }, () => work(signal)).then((result) => {
|
|
@@ -344,6 +486,11 @@ function createAgentHost({ projectRoot, provider, model, ports = {}, onEvent = (
|
|
|
344
486
|
}
|
|
345
487
|
return Object.freeze({
|
|
346
488
|
getSession, resolveRuntime, taskPort, management, publicEvent, workspaceAccess, projectRoot: root,
|
|
489
|
+
hasPendingHooks: () => [...sessions.values(), ...children.values()].some(runtime => {
|
|
490
|
+
const state = runtime.hooks?.snapshot();
|
|
491
|
+
return state && (Object.values(state.subscriptions).some(sub => sub.status === "active")
|
|
492
|
+
|| Object.values(state.events).some(event => ["pending", "claimed"].includes(event.status)));
|
|
493
|
+
}),
|
|
347
494
|
findRuntime({ taskRunId, interactionId, sessionId } = {}) {
|
|
348
495
|
for (const runtime of [...sessions.values(), ...children.values()]) if (Object.values(runtime.snapshot().tasks).some((task) => taskRunId ? task.taskRunId === taskRunId : interactionId && [task.interactionId, task.answeredInteractionId].includes(interactionId))) return runtime;
|
|
349
496
|
return resolveRuntime(sessionId);
|
|
@@ -319,7 +319,8 @@ function startBusBridge(
|
|
|
319
319
|
}
|
|
320
320
|
try {
|
|
321
321
|
if (evt.event === "message" && typeof options.onMessage === "function"
|
|
322
|
-
&& (!options.internalOnly || acceptsEvent(evt)
|
|
322
|
+
&& (!options.internalOnly || acceptsEvent(evt)
|
|
323
|
+
|| (options.includeExternalMessages && Boolean(readAgentsData().agents?.[evt.publisher])))) await options.onMessage(toBridgeEvent(evt));
|
|
323
324
|
emitBusEvent(evt);
|
|
324
325
|
queue.completeClaim(claim);
|
|
325
326
|
} catch {
|
|
@@ -6,6 +6,13 @@ const { buildPromptInjectionText } = require("../../coordination/bus/promptEnvel
|
|
|
6
6
|
const { createTerminalAdapterRouter } = require("../terminal/adapterRouter");
|
|
7
7
|
const { normalizeQueueEnvelope } = require("../../coordination/bus/deliveryQueue");
|
|
8
8
|
const { writeActivityState } = require("../../agents/activity/activityStateWriter");
|
|
9
|
+
const {
|
|
10
|
+
hasWakeAccepted,
|
|
11
|
+
isWakeMeta,
|
|
12
|
+
markWakeAccepted,
|
|
13
|
+
readWakeEndpoint,
|
|
14
|
+
wakeSubscriber,
|
|
15
|
+
} = require("../../coordination/bus/wakeEndpoint");
|
|
9
16
|
|
|
10
17
|
function asState(value = "") {
|
|
11
18
|
return String(value || "").trim().toLowerCase();
|
|
@@ -74,6 +81,8 @@ class DeliveryScheduler {
|
|
|
74
81
|
});
|
|
75
82
|
};
|
|
76
83
|
this.log = typeof options.log === "function" ? options.log : () => {};
|
|
84
|
+
this.wakeFetch = typeof options.wakeFetch === "function" ? options.wakeFetch : global.fetch;
|
|
85
|
+
this.wakeTimeoutMs = positiveMs(options.wakeTimeoutMs, 10000);
|
|
77
86
|
this.now = typeof options.now === "function" ? options.now : () => Date.now();
|
|
78
87
|
this.deferWarnAfterMs = positiveMs(options.deferWarnAfterMs, DEFAULT_DEFER_WARN_AFTER_MS);
|
|
79
88
|
this.warnIntervalMs = positiveMs(options.warnIntervalMs, DEFAULT_WARN_INTERVAL_MS);
|
|
@@ -188,6 +197,9 @@ class DeliveryScheduler {
|
|
|
188
197
|
if (!meta || meta.status === "inactive") {
|
|
189
198
|
return { ok: false, reason: "missing_or_inactive" };
|
|
190
199
|
}
|
|
200
|
+
if (isWakeMeta(meta)) {
|
|
201
|
+
return { ok: true, reason: "wake" };
|
|
202
|
+
}
|
|
191
203
|
if (meta.mcp_bridge === true) {
|
|
192
204
|
return { ok: false, reason: "external_receive" };
|
|
193
205
|
}
|
|
@@ -350,6 +362,49 @@ class DeliveryScheduler {
|
|
|
350
362
|
};
|
|
351
363
|
}
|
|
352
364
|
|
|
365
|
+
async deliverWake(subscriber) {
|
|
366
|
+
const queue = this.queueFactory(subscriber);
|
|
367
|
+
const pending = this.readPendingEvents(queue).filter((event) => (
|
|
368
|
+
event
|
|
369
|
+
&& event.event === "message"
|
|
370
|
+
&& event.data
|
|
371
|
+
&& typeof event.data.message === "string"
|
|
372
|
+
));
|
|
373
|
+
const next = pending[0];
|
|
374
|
+
if (!next || hasWakeAccepted(this.projectRoot, subscriber, next.seq)) {
|
|
375
|
+
return { ok: true, delivered: 0, reason: "wake_waiting_ack" };
|
|
376
|
+
}
|
|
377
|
+
const endpoint = readWakeEndpoint(this.projectRoot, subscriber);
|
|
378
|
+
if (!endpoint) {
|
|
379
|
+
return { ok: false, delivered: 0, reason: "wake_endpoint_missing" };
|
|
380
|
+
}
|
|
381
|
+
const claim = queue.claimNext((event) => Number(event && event.seq) === Number(next.seq));
|
|
382
|
+
if (!claim) return { ok: true, delivered: 0, reason: "empty" };
|
|
383
|
+
try {
|
|
384
|
+
const result = await wakeSubscriber(endpoint, {
|
|
385
|
+
source: "ufoo",
|
|
386
|
+
project_root: this.projectRoot,
|
|
387
|
+
subscriber,
|
|
388
|
+
seq: Number(next.seq) || 0,
|
|
389
|
+
publisher: next.publisher || "",
|
|
390
|
+
message: next.data.message,
|
|
391
|
+
}, this.wakeFetch, { timeoutMs: this.wakeTimeoutMs });
|
|
392
|
+
if (!result.accepted) {
|
|
393
|
+
queue.restoreClaim(claim);
|
|
394
|
+
this.log(`wake not accepted subscriber=${subscriber} seq=${next.seq} status=${result.status}`);
|
|
395
|
+
return { ok: false, delivered: 0, reason: "wake_not_accepted", status: result.status };
|
|
396
|
+
}
|
|
397
|
+
markWakeAccepted(this.projectRoot, subscriber, next.seq);
|
|
398
|
+
queue.restoreClaim(claim);
|
|
399
|
+
return { ok: true, delivered: 0, woken: true, seq: Number(next.seq) || 0 };
|
|
400
|
+
} catch (err) {
|
|
401
|
+
queue.restoreClaim(claim);
|
|
402
|
+
const message = err && err.message ? err.message : String(err || "wake failed");
|
|
403
|
+
this.log(`wake failed subscriber=${subscriber} seq=${next.seq}`);
|
|
404
|
+
return { ok: false, delivered: 0, reason: "wake_failed", error: message };
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
353
408
|
async deliverSubscriber(subscriber) {
|
|
354
409
|
if (!subscriber) return { ok: false, delivered: 0, reason: "missing_subscriber" };
|
|
355
410
|
if (this.locks.has(subscriber)) {
|
|
@@ -361,6 +416,9 @@ class DeliveryScheduler {
|
|
|
361
416
|
try {
|
|
362
417
|
const queue = this.queueFactory(subscriber);
|
|
363
418
|
const transportGate = this.shouldDeliver(subscriber, { requireIdle: false });
|
|
419
|
+
if (transportGate.reason === "wake") {
|
|
420
|
+
return await this.deliverWake(subscriber);
|
|
421
|
+
}
|
|
364
422
|
if (!transportGate.ok) {
|
|
365
423
|
this.noteDeferral(subscriber, transportGate.reason);
|
|
366
424
|
return { ok: true, delivered: 0, deferred: true, reason: transportGate.reason };
|
|
@@ -510,7 +568,13 @@ class DeliveryScheduler {
|
|
|
510
568
|
continue;
|
|
511
569
|
}
|
|
512
570
|
const queue = this.queueFactory(subscriber);
|
|
513
|
-
|
|
571
|
+
let pending = [];
|
|
572
|
+
try {
|
|
573
|
+
pending = queue.readPending();
|
|
574
|
+
} catch {
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (pending.length > 0) {
|
|
514
578
|
subscribers.push(subscriber);
|
|
515
579
|
pendingSubscribers.add(subscriber);
|
|
516
580
|
} else {
|
|
@@ -533,7 +597,11 @@ class DeliveryScheduler {
|
|
|
533
597
|
this.running = true;
|
|
534
598
|
const run = () => {
|
|
535
599
|
this.tick().catch((err) => {
|
|
536
|
-
|
|
600
|
+
try {
|
|
601
|
+
this.log(`delivery scheduler tick failed: ${err && err.message ? err.message : String(err)}`);
|
|
602
|
+
} catch {
|
|
603
|
+
// A full project volume must not take down the controller.
|
|
604
|
+
}
|
|
537
605
|
});
|
|
538
606
|
};
|
|
539
607
|
run();
|
|
@@ -7,8 +7,10 @@ const path = require("path");
|
|
|
7
7
|
const {
|
|
8
8
|
defaultAgentModelForProvider,
|
|
9
9
|
loadConfig,
|
|
10
|
+
loadGlobalBrowserConfig,
|
|
10
11
|
normalizeDaemonTopology,
|
|
11
12
|
} = require("../../config");
|
|
13
|
+
const { BrowserBroker } = require("../browser/broker");
|
|
12
14
|
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
13
15
|
const {
|
|
14
16
|
loadAgentsData,
|
|
@@ -123,6 +125,8 @@ class GlobalDaemon {
|
|
|
123
125
|
};
|
|
124
126
|
this.disposed = false;
|
|
125
127
|
this.startedAt = "";
|
|
128
|
+
this.browserBrokerEnabled = options.browserBroker !== false;
|
|
129
|
+
this.browserBroker = null;
|
|
126
130
|
this.rehydration = {
|
|
127
131
|
state: this.rehydrateProjects ? "pending" : "disabled",
|
|
128
132
|
restored: [],
|
|
@@ -513,6 +517,17 @@ class GlobalDaemon {
|
|
|
513
517
|
beforeCleanup: () => this.disposeProjectRuntimes("global-controller-cleanup"),
|
|
514
518
|
});
|
|
515
519
|
this.startedAt = new Date().toISOString();
|
|
520
|
+
if (
|
|
521
|
+
this.browserBrokerEnabled
|
|
522
|
+
&& isGlobalControllerProjectRoot(this.controllerRoot)
|
|
523
|
+
&& !this.browserBroker
|
|
524
|
+
&& loadGlobalBrowserConfig().enabled === true
|
|
525
|
+
) {
|
|
526
|
+
this.browserBroker = new BrowserBroker();
|
|
527
|
+
void this.browserBroker.start().catch(() => {
|
|
528
|
+
this.browserBroker = null;
|
|
529
|
+
});
|
|
530
|
+
}
|
|
516
531
|
if (this.rehydrateProjects) {
|
|
517
532
|
this.rehydrationPromise = this.restoreRegisteredProjectRuntimes().catch((err) => {
|
|
518
533
|
this.rehydration = {
|
|
@@ -542,6 +557,11 @@ class GlobalDaemon {
|
|
|
542
557
|
stop(reason = "global-daemon-stop") {
|
|
543
558
|
if (this.disposed) return;
|
|
544
559
|
this.disposed = true;
|
|
560
|
+
if (this.browserBroker) {
|
|
561
|
+
const broker = this.browserBroker;
|
|
562
|
+
this.browserBroker = null;
|
|
563
|
+
void broker.stop().catch(() => {});
|
|
564
|
+
}
|
|
545
565
|
this.disposeProjectRuntimes(reason);
|
|
546
566
|
const controller = this.controller;
|
|
547
567
|
this.controller = null;
|
|
@@ -5,6 +5,7 @@ const path = require("path");
|
|
|
5
5
|
const EventBus = require("../../coordination/bus");
|
|
6
6
|
const { prepareUcodeBootstrap } = require("../../code/launcher/ucodeBootstrap");
|
|
7
7
|
const { loadConfig } = require("../../config");
|
|
8
|
+
const { normalizeProvider } = require("../../agents/providers/providerId");
|
|
8
9
|
const {
|
|
9
10
|
buildGroupPromptMetadata,
|
|
10
11
|
composeGroupBootstrapPrompt,
|
|
@@ -12,6 +13,7 @@ const {
|
|
|
12
13
|
computeRosterVersion,
|
|
13
14
|
} = require("../../orchestration/groups/bootstrap");
|
|
14
15
|
const { validateTemplateTarget: validateGroupTemplateTarget } = require("../../orchestration/groups/templateValidation");
|
|
16
|
+
const { resolveGroupModelConfig, buildGroupModelArgs, buildGroupModelEnv } = require("../../orchestration/groups/modelConfig");
|
|
15
17
|
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
16
18
|
const { associateAgentWithGroup } = require("./agentRecoveryGroups");
|
|
17
19
|
const { reconcileGroupStatus } = require("./groupStatus");
|
|
@@ -103,6 +105,7 @@ function buildLaunchPlan(templateDoc = {}) {
|
|
|
103
105
|
type: asTrimmedString(agent.type),
|
|
104
106
|
role: asTrimmedString(agent.role),
|
|
105
107
|
prompt_profile: asTrimmedString(agent.prompt_profile),
|
|
108
|
+
...(agent.model_config ? { model_config: agent.model_config } : {}),
|
|
106
109
|
startup_order: startupOrder,
|
|
107
110
|
depends_on: dependsOn,
|
|
108
111
|
accept_from: asStringArray(agent.accept_from),
|
|
@@ -429,11 +432,20 @@ function buildExecutionPlan({
|
|
|
429
432
|
})
|
|
430
433
|
: "";
|
|
431
434
|
|
|
435
|
+
const config = loadConfig(projectRoot);
|
|
436
|
+
// Auto agy groups intentionally use agy even when standalone ucode differs.
|
|
437
|
+
// Explicit ucode members follow the same provider precedence as native ucode.
|
|
438
|
+
const nativeProvider = (item.requested_type || item.type) === "auto"
|
|
439
|
+
&& normalizeProvider(config.agentProvider) === "agy"
|
|
440
|
+
? "agy"
|
|
441
|
+
: process.env.UFOO_UCODE_PROVIDER || config.ucodeProvider || config.agentProvider;
|
|
432
442
|
return {
|
|
433
443
|
...item,
|
|
434
444
|
requested_type: item.requested_type || item.type,
|
|
435
445
|
type: resolvedType,
|
|
436
446
|
scoped_nickname: runtimeNickname,
|
|
447
|
+
...resolveGroupModelConfig(item.model_config, resolvedType,
|
|
448
|
+
nativeProvider),
|
|
437
449
|
resolved_profile: profile ? profile.resolved_profile : "",
|
|
438
450
|
display_name: profile ? profile.display_name : "",
|
|
439
451
|
short_name: profile ? profile.short_name : "",
|
|
@@ -495,6 +507,8 @@ function buildDefaultRuntime({
|
|
|
495
507
|
requested_type: item.requested_type || item.type,
|
|
496
508
|
type: item.type,
|
|
497
509
|
role: item.role || "",
|
|
510
|
+
...(item.model_source ? { model: item.model, reasoning_effort: item.reasoning_effort, model_source: item.model_source } : {}),
|
|
511
|
+
...(item.model_provider ? { model_provider: item.model_provider } : {}),
|
|
498
512
|
prompt_profile: item.prompt_profile || "",
|
|
499
513
|
resolved_profile: item.resolved_profile || "",
|
|
500
514
|
display_name: item.display_name || "",
|
|
@@ -834,6 +848,8 @@ function createGroupOrchestrator(options = {}) {
|
|
|
834
848
|
scoped_nickname: item.scoped_nickname,
|
|
835
849
|
type: item.type,
|
|
836
850
|
role: item.role,
|
|
851
|
+
...(item.model_source ? { model: item.model, reasoning_effort: item.reasoning_effort, model_source: item.model_source } : {}),
|
|
852
|
+
...(item.model_provider ? { model_provider: item.model_provider } : {}),
|
|
837
853
|
startup_order: item.startup_order,
|
|
838
854
|
depends_on: item.depends_on.slice(),
|
|
839
855
|
accept_from: item.accept_from.slice(),
|
|
@@ -871,7 +887,7 @@ function createGroupOrchestrator(options = {}) {
|
|
|
871
887
|
for (let i = 0; i < compiled.executionPlan.length; i += 1) {
|
|
872
888
|
const item = compiled.executionPlan[i];
|
|
873
889
|
const member = runtime.members[i];
|
|
874
|
-
const extraEnv =
|
|
890
|
+
const extraEnv = buildGroupModelEnv(item.type, item);
|
|
875
891
|
if (item.bootstrap_required) {
|
|
876
892
|
extraEnv.UFOO_SKIP_DEFAULT_BOOTSTRAP = "1";
|
|
877
893
|
}
|
|
@@ -956,6 +972,9 @@ function createGroupOrchestrator(options = {}) {
|
|
|
956
972
|
}
|
|
957
973
|
}
|
|
958
974
|
|
|
975
|
+
// Options precede the positional Codex bootstrap prompt; the internal
|
|
976
|
+
// runner consumes that final prompt separately from model options.
|
|
977
|
+
extraArgs = [...buildGroupModelArgs(item.type, item), ...extraArgs];
|
|
959
978
|
const op = {
|
|
960
979
|
action: "launch",
|
|
961
980
|
internal_only: params.internal_only === true,
|
|
@@ -950,6 +950,7 @@ function startDaemon({
|
|
|
950
950
|
if (manageProcessState) writePid(projectRoot);
|
|
951
951
|
|
|
952
952
|
const logFile = fs.createWriteStream(logPath(projectRoot), { flags: "a" });
|
|
953
|
+
logFile.on("error", () => {});
|
|
953
954
|
const formatLogLine = (msg) => `[daemon] ${new Date().toISOString()} ${msg}\n`;
|
|
954
955
|
const log = (msg) => {
|
|
955
956
|
logFile.write(formatLogLine(msg));
|
|
@@ -1121,9 +1122,9 @@ function startDaemon({
|
|
|
1121
1122
|
log,
|
|
1122
1123
|
});
|
|
1123
1124
|
publishAgentReportResult(entry);
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1125
|
+
// Management validates the exact task/worker association. Communication
|
|
1126
|
+
// eligibility does not depend on who owns the worker's process or pane.
|
|
1127
|
+
await mainAgentHost.management.report(entry);
|
|
1127
1128
|
return entry;
|
|
1128
1129
|
};
|
|
1129
1130
|
|
|
@@ -1140,6 +1141,7 @@ function startDaemon({
|
|
|
1140
1141
|
}
|
|
1141
1142
|
}, {
|
|
1142
1143
|
internalOnly: true,
|
|
1144
|
+
includeExternalMessages: true,
|
|
1143
1145
|
onMessage: (event) => {
|
|
1144
1146
|
if (!event.message || event.publisher === "ufoo-agent") return;
|
|
1145
1147
|
try { if (JSON.parse(event.message)?.stream) return; } catch { /* ordinary text */ }
|
|
@@ -1161,7 +1163,7 @@ function startDaemon({
|
|
|
1161
1163
|
}));
|
|
1162
1164
|
void mainAgentHost.recover().catch((error) => log(`main runtime recovery failed: ${error.message}`));
|
|
1163
1165
|
runtimeServices.workspaceAccess = mainAgentHost.workspaceAccess;
|
|
1164
|
-
projectRuntime.canSuspendHook = () => !mainAgentHost.snapshot().sessions.some((session) => session.tasks.some((task) => ["queued", "running"].includes(task.status)))
|
|
1166
|
+
projectRuntime.canSuspendHook = () => !mainAgentHost.hasPendingHooks() && !mainAgentHost.snapshot().sessions.some((session) => session.tasks.some((task) => ["queued", "running"].includes(task.status)))
|
|
1165
1167
|
&& !mainAgentHost.snapshot().children.some((task) => ["queued", "running"].includes(task.status));
|
|
1166
1168
|
const deliveryScheduler = new DeliveryScheduler(projectRoot, {
|
|
1167
1169
|
log,
|