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
|
@@ -267,12 +267,6 @@ function parseStructuredSideEffects(text = "") {
|
|
|
267
267
|
return null;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
function resolveCommitInterval(env = process.env) {
|
|
271
|
-
const parsed = Number.parseInt(String(env.UFOO_UCODE_COMMIT_INTERVAL || ""), 10);
|
|
272
|
-
if (Number.isFinite(parsed) && parsed > 0) return Math.floor(parsed);
|
|
273
|
-
return 4;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
270
|
function validateStateCommit(commit = {}) {
|
|
277
271
|
const normalized = normalizeStateCommit(commit);
|
|
278
272
|
const errors = [];
|
|
@@ -296,29 +290,6 @@ function validateStateCommit(commit = {}) {
|
|
|
296
290
|
return { ok: errors.length === 0, errors, commit: normalized };
|
|
297
291
|
}
|
|
298
292
|
|
|
299
|
-
function buildDeterministicToolCommit(toolEvent = {}) {
|
|
300
|
-
const source = toolEvent && typeof toolEvent === "object" ? toolEvent : {};
|
|
301
|
-
const tool = String(source.tool || "").trim().toLowerCase();
|
|
302
|
-
const preview = String(source.preview || source.summary || "").trim();
|
|
303
|
-
const artifactId = String(source.artifactId || "").trim();
|
|
304
|
-
if (!tool && !preview) return null;
|
|
305
|
-
const fact = [
|
|
306
|
-
tool ? `tool:${tool}` : "",
|
|
307
|
-
artifactId ? `artifact:${artifactId}` : "",
|
|
308
|
-
preview ? preview.slice(0, 180) : "",
|
|
309
|
-
].filter(Boolean).join(" ");
|
|
310
|
-
if (!fact) return null;
|
|
311
|
-
return {
|
|
312
|
-
factsAdd: [fact],
|
|
313
|
-
nextObjective: "",
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function shouldCommitAfterToolCall(session = {}, interval = resolveCommitInterval()) {
|
|
318
|
-
const count = Number(session.toolCallsSinceCommit) || 0;
|
|
319
|
-
return count >= interval;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
293
|
function appendCommitLog(workspaceRoot = process.cwd(), sessionId = "", commitEntry = {}) {
|
|
323
294
|
if (!sessionId) return { ok: false, error: "invalid session id" };
|
|
324
295
|
const fs = require("fs");
|
|
@@ -398,11 +369,8 @@ module.exports = {
|
|
|
398
369
|
renderTaskContract,
|
|
399
370
|
normalizeStateCommit,
|
|
400
371
|
validateStateCommit,
|
|
401
|
-
buildDeterministicToolCommit,
|
|
402
|
-
resolveCommitInterval,
|
|
403
372
|
resolveCommitFoldThreshold,
|
|
404
373
|
foldCommitsIfNeeded,
|
|
405
|
-
shouldCommitAfterToolCall,
|
|
406
374
|
appendCommitLog,
|
|
407
375
|
applyValidatedStateCommit,
|
|
408
376
|
applyStateCommit,
|
|
@@ -124,12 +124,15 @@ function transcriptEventsToMessages(events = [], options = {}) {
|
|
|
124
124
|
const messages = [];
|
|
125
125
|
for (const event of list) {
|
|
126
126
|
if (preferArtifact && event.artifactId) {
|
|
127
|
+
const hasFullContent = event.content !== undefined && event.content !== null && event.content !== "";
|
|
127
128
|
messages.push({
|
|
128
129
|
role: event.role || "tool",
|
|
129
|
-
content:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
content: hasFullContent
|
|
131
|
+
? event.content
|
|
132
|
+
: JSON.stringify({
|
|
133
|
+
artifactId: event.artifactId,
|
|
134
|
+
preview: event.preview || "",
|
|
135
|
+
}),
|
|
133
136
|
tool_call_id: event.toolCallId,
|
|
134
137
|
});
|
|
135
138
|
continue;
|
|
@@ -18,6 +18,12 @@ function createInternalCodingThread(options = {}) {
|
|
|
18
18
|
if (restored?.ok === false) throw new Error(restored.error || `Could not resume session: ${options.sessionId}`);
|
|
19
19
|
}
|
|
20
20
|
let abort = null;
|
|
21
|
+
let wakeDelivery = null;
|
|
22
|
+
const wakeHost = require("./runtime/backgroundWakeHost").createUcodeWakeHost({ state,
|
|
23
|
+
canDeliver: () => !abort && Boolean(wakeDelivery),
|
|
24
|
+
deliver: (event, claim, text) => wakeDelivery(event, claim, text),
|
|
25
|
+
onError: error => options.onError?.(error),
|
|
26
|
+
});
|
|
21
27
|
|
|
22
28
|
async function* runStreamed(input, runOptions = {}) {
|
|
23
29
|
if (abort) throw new Error("internal coding thread is already running");
|
|
@@ -101,7 +107,9 @@ function createInternalCodingThread(options = {}) {
|
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
109
|
|
|
104
|
-
return { id: state.sessionId, runStreamed,
|
|
110
|
+
return { id: state.sessionId, runStreamed,
|
|
111
|
+
async pollWakes(deliver) { wakeDelivery = deliver; try { await wakeHost.tick(); } finally { wakeDelivery = null; } },
|
|
112
|
+
close: async () => { wakeHost.close(); if (abort) abort.abort("runtime_closed"); } };
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
module.exports = { createInternalCodingThread };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { loadConfig } = require("../../config");
|
|
1
|
+
const { loadConfig, sameModelProvider } = require("../../config");
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
|
|
@@ -95,9 +95,11 @@ function resolveUcodeLaunch({
|
|
|
95
95
|
|| config.ucodeProvider
|
|
96
96
|
|| ""
|
|
97
97
|
).trim();
|
|
98
|
+
const requestedProvider = readLastArgValue(argv, "--provider") || configuredProvider || config.agentProvider;
|
|
99
|
+
const useConfiguredModel = !sameModelProvider(requestedProvider, "agy") || sameModelProvider(config.ucodeProvider, "agy");
|
|
98
100
|
const configuredModel = String(
|
|
99
101
|
env.UFOO_UCODE_MODEL
|
|
100
|
-
|| config.ucodeModel
|
|
102
|
+
|| (useConfiguredModel ? config.ucodeModel : "")
|
|
101
103
|
|| ""
|
|
102
104
|
).trim();
|
|
103
105
|
|
package/src/code/modelCommand.js
CHANGED
|
@@ -14,12 +14,13 @@ const {
|
|
|
14
14
|
} = require("./thinkingLevels");
|
|
15
15
|
|
|
16
16
|
function resolveModelRuntime(state = {}, options = {}) {
|
|
17
|
-
//
|
|
18
|
-
const {
|
|
19
|
-
return
|
|
17
|
+
// Resolve the same refreshed auth used for inference, including Codex OAuth.
|
|
18
|
+
const { resolveAuthenticatedRuntime } = require("../agents/providers/runtimeConfig");
|
|
19
|
+
return resolveAuthenticatedRuntime({
|
|
20
20
|
workspaceRoot: options.workspaceRoot || process.cwd(),
|
|
21
21
|
provider: options.provider || (state && state.provider) || "",
|
|
22
22
|
model: options.model || (state && state.model) || "",
|
|
23
|
+
fetchImpl: options.fetchImpl,
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -55,7 +56,7 @@ function persistThinkingLevel(state = {}, level = "") {
|
|
|
55
56
|
* Fetch models from the configured provider's /models route.
|
|
56
57
|
*/
|
|
57
58
|
async function listUcodeModels(state = {}, options = {}) {
|
|
58
|
-
const runtime = resolveModelRuntime(state, options);
|
|
59
|
+
const runtime = await resolveModelRuntime(state, options);
|
|
59
60
|
const listed = await listProviderModels({
|
|
60
61
|
...runtime,
|
|
61
62
|
fetchImpl: options.fetchImpl,
|
|
@@ -130,7 +131,7 @@ async function applyUcodeModelCommand(state = {}, result = {}, options = {}) {
|
|
|
130
131
|
};
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
const runtime = resolveModelRuntime(state, { ...options, model: next });
|
|
134
|
+
const runtime = await resolveModelRuntime(state, { ...options, model: next });
|
|
134
135
|
const confirmation = await confirmModelSupported({
|
|
135
136
|
...runtime,
|
|
136
137
|
model: next,
|
package/src/code/nativeRunner.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const { randomUUID } = require("crypto");
|
|
4
|
-
const {
|
|
5
|
-
const { resolveKimiUpstreamCredentials } = require("../agents/providers/credentials/kimi");
|
|
6
|
-
const { resolveCodexUpstreamCredentials } = require("../agents/providers/credentials/codex");
|
|
7
|
-
const { resolveRuntimeConfig, resolveTransport, resolveCompletionUrl, resolveResponsesUrl, resolveAnthropicMessagesUrl, DEFAULT_OPENAI_BASE_URL } = require("../agents/providers/runtimeConfig");
|
|
4
|
+
const { resolveRuntimeConfig, resolveAuthenticatedRuntime, resolveTransport, resolveCompletionUrl, resolveResponsesUrl, resolveAnthropicMessagesUrl } = require("../agents/providers/runtimeConfig");
|
|
8
5
|
const { getNativeTransport, createNativeSseDispatcher, resolveReasoningEffort, normalizeTimeoutMs, createUsageTotals, cloneMessageList } = require("../agents/providers/nativeTransport");
|
|
9
6
|
const { createAgentRuntime } = require("../agents/runtime/createAgentRuntime");
|
|
10
7
|
const { createCodingCapability } = require("../agents/capabilities/coding");
|
|
11
8
|
const { createPlanningCapability } = require("../agents/capabilities/planning");
|
|
12
9
|
const { createSkillsCapability } = require("../agents/capabilities/skills");
|
|
10
|
+
const { createTurnRecallCapability } = require("../agents/capabilities/turnRecall");
|
|
11
|
+
const { createBrowserCapability } = require("../agents/capabilities/browser");
|
|
13
12
|
const codingProfile = require("../agents/profiles/coding");
|
|
13
|
+
const { loadConfig, defaultAuxModelForProvider, sameModelProvider } = require("../config");
|
|
14
14
|
const { runCoreToolAsync } = require("./tools/executor");
|
|
15
15
|
const { sanitizeModelMessages } = require("./context/assembler");
|
|
16
16
|
const { retireMessageImages } = require("../agents/providers/transports/visionBlocks");
|
|
@@ -19,8 +19,10 @@ const { clearUserPrompts } = require("./context/userNudge");
|
|
|
19
19
|
const { runProviderTurnGate, resolveCall, checkFaultPoint, materializeAnswerToolResult } = require("./protocol");
|
|
20
20
|
const { appendUsageRecord } = require("./usageStore");
|
|
21
21
|
const { buildCoreToolSpecs, buildAnthropicToolSpecs } = require("./tools/specs");
|
|
22
|
-
const {
|
|
23
|
-
const {
|
|
22
|
+
const { createTurnIndexStore } = require("../agents/runtime/context/turnIndexStore");
|
|
23
|
+
const { buildDeterministicTurnRecord, backfillMissingTurns, createAsyncTurnEnricher } = require("../agents/runtime/context/turnAnalyzer");
|
|
24
|
+
const { createTopicSelector } = require("../agents/runtime/context/topicSelector");
|
|
25
|
+
const { createSlidingWindowManager } = require("../agents/runtime/context/slidingWindowManager");
|
|
24
26
|
const { createRuntimeStore } = require("../agents/runtime/context/runtimeStore");
|
|
25
27
|
const { normalizeTraceContext } = require("../agents/runtime/protocol/traceContext");
|
|
26
28
|
const { redactSecrets } = require("../runtime/privacy/redactor");
|
|
@@ -52,12 +54,39 @@ function createGuards({ signal = null, timeoutMs = DEFAULT_NATIVE_TIMEOUT_MS } =
|
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
56
|
|
|
57
|
+
function resolveDurableTurnSlice(resultObj = {}, { preTurnOffset = 0, resume = false, promptText = "" } = {}) {
|
|
58
|
+
const runNonSystem = Array.isArray(resultObj.messages)
|
|
59
|
+
? resultObj.messages.filter((m) => m && m.role !== "system")
|
|
60
|
+
: [];
|
|
61
|
+
const rawSlice = runNonSystem.slice(preTurnOffset);
|
|
62
|
+
if (Array.isArray(resultObj.turnItems) && (resultObj.turnItems.length > 0 || !rawSlice.length)) {
|
|
63
|
+
const candidate = [
|
|
64
|
+
...(!resume && promptText ? [{ role: "user", content: promptText }] : []),
|
|
65
|
+
...resultObj.turnItems,
|
|
66
|
+
];
|
|
67
|
+
const sanitized = sanitizeModelMessages(candidate);
|
|
68
|
+
if (sanitized.length > 0) return sanitized;
|
|
69
|
+
}
|
|
70
|
+
const sanitizedFallback = sanitizeModelMessages(rawSlice);
|
|
71
|
+
if (sanitizedFallback.length > 0) return sanitizedFallback;
|
|
72
|
+
if (!rawSlice.length && !resume && promptText) {
|
|
73
|
+
return [{ role: "user", content: promptText }];
|
|
74
|
+
}
|
|
75
|
+
return rawSlice;
|
|
76
|
+
}
|
|
77
|
+
|
|
55
78
|
async function runNativeLoop(options = {}) {
|
|
56
79
|
const runtime = createAgentRuntime({
|
|
57
80
|
profile: codingProfile,
|
|
58
81
|
transport: options.transport,
|
|
59
|
-
capabilities: [
|
|
60
|
-
|
|
82
|
+
capabilities: [
|
|
83
|
+
createCodingCapability(),
|
|
84
|
+
createPlanningCapability(),
|
|
85
|
+
createSkillsCapability(),
|
|
86
|
+
createTurnRecallCapability({ projectRoot: options.workspaceRoot }, { defaultNamespace: "ucode" }),
|
|
87
|
+
createBrowserCapability(),
|
|
88
|
+
],
|
|
89
|
+
host: { runtimeHooks: options.runtimeHooks, grantedPermissions: ["workspace.read", "workspace.write", "workspace.execute", "execution.control", "interaction.request", "browser.control"] },
|
|
61
90
|
defaults: {
|
|
62
91
|
sanitizeMessages: sanitizeModelMessages,
|
|
63
92
|
retireImages: retireMessageImages,
|
|
@@ -112,16 +141,22 @@ async function runNativeAgentTask({
|
|
|
112
141
|
contextPolicy = {},
|
|
113
142
|
runtimeContext = {},
|
|
114
143
|
onRuntimeEvent = null,
|
|
144
|
+
onConversationUpdate = null,
|
|
145
|
+
logicalTurnId = "",
|
|
146
|
+
historyOffset: restoredTurnOffset = null,
|
|
147
|
+
runtimeHooks = null,
|
|
115
148
|
} = {}) {
|
|
116
149
|
const guards = createGuards({ signal, timeoutMs });
|
|
117
150
|
const nextSessionId = String(sessionId || "").trim() || `native-${randomUUID()}`;
|
|
118
151
|
const promptText = String(prompt || "").trim();
|
|
119
152
|
const ids = normalizeTraceContext(runtimeContext);
|
|
120
|
-
ids.taskRunId ||= `native-run-${randomUUID()}`;
|
|
153
|
+
ids.taskRunId ||= String(logicalTurnId || "").trim() || `native-run-${randomUUID()}`;
|
|
121
154
|
ids.taskId ||= ids.taskRunId;
|
|
122
155
|
ids.traceId ||= ids.taskId;
|
|
123
156
|
ids.requestId ||= ids.taskRunId;
|
|
124
157
|
ids.attemptId ||= `attempt-${randomUUID()}`;
|
|
158
|
+
const effectiveTurnId = String(logicalTurnId || ids.taskRunId).trim();
|
|
159
|
+
const requestKind = runtimeContext.requestKind || (runtimeContext.taskRunId ? "unknown" : "user");
|
|
125
160
|
const observation = createRuntimeStore({ workspaceRoot, namespace: "ucode", sessionId: nextSessionId, redact: redactSecrets });
|
|
126
161
|
const observationWarnings = [];
|
|
127
162
|
const observe = async event => {
|
|
@@ -155,6 +190,11 @@ async function runNativeAgentTask({
|
|
|
155
190
|
}
|
|
156
191
|
};
|
|
157
192
|
|
|
193
|
+
let turnIndexStore = null;
|
|
194
|
+
let enricher = null;
|
|
195
|
+
let abortEnricherListener = null;
|
|
196
|
+
let preTurnOffset = 0;
|
|
197
|
+
|
|
158
198
|
try {
|
|
159
199
|
await observe({ type: "request.accepted", request: { ...ids, text: promptText } });
|
|
160
200
|
await observe({ type: "task.started" });
|
|
@@ -171,64 +211,108 @@ async function runNativeAgentTask({
|
|
|
171
211
|
};
|
|
172
212
|
}
|
|
173
213
|
|
|
174
|
-
const runtime =
|
|
214
|
+
const runtime = await resolveAuthenticatedRuntime({
|
|
175
215
|
workspaceRoot,
|
|
176
216
|
provider,
|
|
177
217
|
model,
|
|
178
218
|
});
|
|
179
219
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const credential = await resolveCodexUpstreamCredentials({
|
|
185
|
-
authPath: config.codexAuthPath,
|
|
186
|
-
refreshWindowMs: Number(config.codexOauthRefreshWindowSec || 300) * 1000,
|
|
187
|
-
env: process.env,
|
|
188
|
-
});
|
|
189
|
-
const token = String(credential && (credential.accessToken || credential.apiKey) || "").trim();
|
|
190
|
-
if (token) {
|
|
191
|
-
runtime.apiKey = token;
|
|
192
|
-
runtime.apiKeySource = String(credential.source || "codex-credential");
|
|
193
|
-
}
|
|
194
|
-
const credentialKind = String(credential && credential.credentialKind || "").trim();
|
|
195
|
-
if (
|
|
196
|
-
credentialKind === "api-key"
|
|
197
|
-
&& !String(process.env.UFOO_UCODE_BASE_URL || "").trim()
|
|
198
|
-
&& !String(config.ucodeBaseUrl || "").trim()
|
|
199
|
-
) {
|
|
200
|
-
runtime.baseUrl = String(process.env.OPENAI_BASE_URL || DEFAULT_OPENAI_BASE_URL).trim();
|
|
201
|
-
}
|
|
202
|
-
if (credentialKind === "oauth") {
|
|
203
|
-
accountId = String(credential && credential.accountId || "").trim();
|
|
204
|
-
}
|
|
205
|
-
} catch {
|
|
206
|
-
// The request will report the provider's auth error when no Codex
|
|
207
|
-
// credential is available; keep runtime resolution non-throwing.
|
|
208
|
-
}
|
|
209
|
-
}
|
|
220
|
+
const accountId = runtime.accountId;
|
|
221
|
+
|
|
222
|
+
const transport = getNativeTransport(runtime.transport);
|
|
223
|
+
await observe({ type: "runtime.binding", binding: { provider: runtime.provider, model: runtime.model, transport: runtime.transport } });
|
|
210
224
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
)
|
|
225
|
+
turnIndexStore = createTurnIndexStore({ workspaceRoot, namespace: "ucode", sessionId: nextSessionId, redact: redactSecrets });
|
|
226
|
+
const productConfig = loadConfig(workspaceRoot);
|
|
227
|
+
const effectivePolicy = {
|
|
228
|
+
...(productConfig.context && typeof productConfig.context === "object" ? productConfig.context : {}),
|
|
229
|
+
...(contextPolicy && typeof contextPolicy === "object" ? contextPolicy : {}),
|
|
230
|
+
};
|
|
231
|
+
const baseMessages = Array.isArray(messages) ? messages : [];
|
|
232
|
+
const nonSystemBase = baseMessages.filter((m) => m && m.role !== "system");
|
|
233
|
+
if (Number.isInteger(restoredTurnOffset) && restoredTurnOffset >= 0) {
|
|
234
|
+
preTurnOffset = restoredTurnOffset;
|
|
235
|
+
} else if (resume) {
|
|
219
236
|
try {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
if (token) runtime.apiKey = token;
|
|
237
|
+
const existingTurn = turnIndexStore.getTurn(effectiveTurnId);
|
|
238
|
+
preTurnOffset = existingTurn && Number.isInteger(existingTurn.historyOffset) ? existingTurn.historyOffset : 0;
|
|
223
239
|
} catch {
|
|
224
|
-
|
|
240
|
+
preTurnOffset = 0;
|
|
225
241
|
}
|
|
242
|
+
} else {
|
|
243
|
+
preTurnOffset = nonSystemBase.length;
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
backfillMissingTurns({ store: turnIndexStore, journalMessages: nonSystemBase.slice(0, preTurnOffset) });
|
|
247
|
+
} catch {
|
|
248
|
+
turnIndexStore = null;
|
|
226
249
|
}
|
|
227
250
|
|
|
228
|
-
const
|
|
229
|
-
|
|
251
|
+
const useConfiguredAuxModel = runtime.provider !== "agy" || sameModelProvider(productConfig.ucodeProvider, "agy");
|
|
252
|
+
const explicitAuxModel = String(
|
|
253
|
+
effectivePolicy?.auxModel
|
|
254
|
+
|| (useConfiguredAuxModel ? productConfig.ucodeAuxModel : "")
|
|
255
|
+
|| process.env.UFOO_UCODE_AUX_MODEL
|
|
256
|
+
|| ""
|
|
257
|
+
).trim();
|
|
258
|
+
const allowDefaultAux = !process.env.JEST_WORKER_ID
|
|
259
|
+
|| Boolean(effectivePolicy?.enableModelSelector || effectivePolicy?.backgroundEnrich);
|
|
260
|
+
const configuredAuxModel = explicitAuxModel
|
|
261
|
+
|| (allowDefaultAux ? String(runtime.auxModel || defaultAuxModelForProvider(runtime.provider) || "").trim() : "");
|
|
262
|
+
const runAuxModel = typeof effectivePolicy?.runAuxModel === "function"
|
|
263
|
+
? effectivePolicy.runAuxModel
|
|
264
|
+
: configuredAuxModel
|
|
265
|
+
? async ({ purpose, currentQuery, activeTopics, candidates, turn, existingTopics, signal: auxSignal }) => {
|
|
266
|
+
const url = typeof transport.resolveUrl === "function" ? transport.resolveUrl(runtime.baseUrl) : runtime.baseUrl;
|
|
267
|
+
if (!url) return null;
|
|
268
|
+
const sysPrompt = purpose === "topic_select"
|
|
269
|
+
? "Select relevant historical turns and topics as strict JSON: {\"isNewTopic\":boolean,\"matchedTopics\":string[],\"referencedTurnIds\":string[]}. Do not include markdown or prose."
|
|
270
|
+
: "Summarize the completed agent turn as strict JSON: {\"topic\":string,\"userSummary\":string,\"assistantSummary\":string,\"decisions\":string[],\"keywords\":string[]}. Do not include markdown or prose.";
|
|
271
|
+
const userPayload = purpose === "topic_select"
|
|
272
|
+
? { currentQuery, activeTopics, candidates }
|
|
273
|
+
: { turn, existingTopics };
|
|
274
|
+
const res = await transport.runTurn({
|
|
275
|
+
url,
|
|
276
|
+
apiKey: runtime.apiKey,
|
|
277
|
+
model: configuredAuxModel,
|
|
278
|
+
provider: runtime.provider,
|
|
279
|
+
accountId,
|
|
280
|
+
systemPrompt: sysPrompt,
|
|
281
|
+
messages: [{ role: "user", content: JSON.stringify(userPayload) }],
|
|
282
|
+
tools: [],
|
|
283
|
+
maxOutputTokens: 512,
|
|
284
|
+
sessionId: `${nextSessionId}:aux`,
|
|
285
|
+
signal: auxSignal,
|
|
286
|
+
});
|
|
287
|
+
return res && res.text ? res.text : "";
|
|
288
|
+
}
|
|
289
|
+
: null;
|
|
290
|
+
const topicSelector = createTopicSelector({
|
|
291
|
+
...effectivePolicy,
|
|
292
|
+
runAuxModel,
|
|
293
|
+
enableModelSelector: Boolean(runAuxModel && (effectivePolicy?.enableModelSelector ?? true)),
|
|
294
|
+
});
|
|
295
|
+
enricher = createAsyncTurnEnricher({
|
|
296
|
+
store: turnIndexStore,
|
|
297
|
+
runAuxModel,
|
|
298
|
+
enabled: Boolean(runAuxModel && (effectivePolicy?.backgroundEnrich ?? true)),
|
|
299
|
+
timeoutMs: effectivePolicy?.enrichTimeoutMs || 8000,
|
|
300
|
+
onEvent: (ev) => {
|
|
301
|
+
observe({ ...ev, taskRunId: ids.taskRunId }).catch(() => {});
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
if (signal && typeof signal.addEventListener === "function") {
|
|
305
|
+
abortEnricherListener = () => { if (enricher) enricher.close(); };
|
|
306
|
+
signal.addEventListener("abort", abortEnricherListener, { once: true });
|
|
307
|
+
}
|
|
308
|
+
const contextManager = createSlidingWindowManager({
|
|
309
|
+
policy: effectivePolicy,
|
|
310
|
+
turnIndexStore,
|
|
311
|
+
topicSelector,
|
|
312
|
+
});
|
|
230
313
|
|
|
231
314
|
const runResult = await runNativeLoop({
|
|
315
|
+
runtimeHooks,
|
|
232
316
|
transport,
|
|
233
317
|
workspaceRoot,
|
|
234
318
|
prompt: resume ? "" : promptText,
|
|
@@ -236,7 +320,7 @@ async function runNativeAgentTask({
|
|
|
236
320
|
systemBlocks,
|
|
237
321
|
historyMessages: messages,
|
|
238
322
|
model: runtime.model,
|
|
239
|
-
requestKind
|
|
323
|
+
requestKind,
|
|
240
324
|
baseUrl: runtime.baseUrl,
|
|
241
325
|
apiKey: runtime.apiKey,
|
|
242
326
|
provider: runtime.provider,
|
|
@@ -248,14 +332,15 @@ async function runNativeAgentTask({
|
|
|
248
332
|
onPhase,
|
|
249
333
|
onToolEvent,
|
|
250
334
|
onArtifactPersisted,
|
|
335
|
+
onConversationUpdate,
|
|
251
336
|
onContextUsage,
|
|
252
337
|
sessionId: nextSessionId,
|
|
253
338
|
signal,
|
|
254
339
|
guards,
|
|
255
340
|
executionState,
|
|
256
341
|
resume: Boolean(resume),
|
|
257
|
-
|
|
258
|
-
|
|
342
|
+
...(resume ? { historyOffset: preTurnOffset } : {}),
|
|
343
|
+
contextManager,
|
|
259
344
|
...ids,
|
|
260
345
|
agentId: process.env.UFOO_SUBSCRIBER_ID || "ucode",
|
|
261
346
|
onEvent: observe,
|
|
@@ -285,6 +370,48 @@ async function runNativeAgentTask({
|
|
|
285
370
|
cacheRead: usage.cacheRead,
|
|
286
371
|
cacheCreation: usage.cacheCreation,
|
|
287
372
|
});
|
|
373
|
+
const settledOutcome = signal?.aborted || runResult.stopReason === "cancelled"
|
|
374
|
+
? "cancelled"
|
|
375
|
+
: (runResult.waitingUserInteraction ? "paused" : (runResult.error || runResult.stopReason ? "failed" : "completed"));
|
|
376
|
+
if (turnIndexStore) {
|
|
377
|
+
try {
|
|
378
|
+
const existingTurns = turnIndexStore.listTurns();
|
|
379
|
+
const existing = existingTurns.find((item) => item.turnId === effectiveTurnId) || null;
|
|
380
|
+
const turnSlice = resolveDurableTurnSlice(runResult, {
|
|
381
|
+
preTurnOffset,
|
|
382
|
+
resume: Boolean(resume),
|
|
383
|
+
promptText,
|
|
384
|
+
});
|
|
385
|
+
const indexed = turnIndexStore.upsertTurn(buildDeterministicTurnRecord({
|
|
386
|
+
turnId: effectiveTurnId,
|
|
387
|
+
turnIndex: existing ? existing.turnIndex : existingTurns.length,
|
|
388
|
+
historyOffset: preTurnOffset,
|
|
389
|
+
historyEnd: preTurnOffset + turnSlice.length,
|
|
390
|
+
turnMessages: turnSlice,
|
|
391
|
+
requestKind,
|
|
392
|
+
prompt: promptText,
|
|
393
|
+
outcome: settledOutcome,
|
|
394
|
+
error: runResult.error || runResult.stopReason || "",
|
|
395
|
+
previousTurns: existingTurns,
|
|
396
|
+
resume: Boolean(resume),
|
|
397
|
+
}), { phase: "A" });
|
|
398
|
+
await observe({
|
|
399
|
+
type: "context.turn_indexed",
|
|
400
|
+
turnId: indexed.turnId,
|
|
401
|
+
topic: indexed.topic,
|
|
402
|
+
turnKind: indexed.turnKind,
|
|
403
|
+
outcome: indexed.outcome,
|
|
404
|
+
});
|
|
405
|
+
if (settledOutcome === "completed" && enricher) {
|
|
406
|
+
enricher.enqueue(indexed);
|
|
407
|
+
if (effectivePolicy?.awaitEnrich) {
|
|
408
|
+
await enricher.flush();
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
} catch {
|
|
412
|
+
// Read-only or unavailable context storage must not fail completed turns.
|
|
413
|
+
}
|
|
414
|
+
}
|
|
288
415
|
await observe({ type: signal?.aborted || runResult.stopReason === "cancelled" ? "task.cancelled" : runResult.error || runResult.stopReason ? "task.failed" : runResult.waitingUserInteraction ? "task.paused" : "task.completed",
|
|
289
416
|
error: runResult.error || runResult.stopReason || "", result: { text: runResult.finalText || outputText, usage } });
|
|
290
417
|
|
|
@@ -309,20 +436,63 @@ async function runNativeAgentTask({
|
|
|
309
436
|
...(observationWarnings.length ? { observationWarnings } : {}),
|
|
310
437
|
};
|
|
311
438
|
} catch (err) {
|
|
312
|
-
|
|
439
|
+
const recovered = err.result || {};
|
|
440
|
+
const cancelled = Boolean(signal?.aborted || err.code === "cancelled");
|
|
441
|
+
if (turnIndexStore) {
|
|
442
|
+
try {
|
|
443
|
+
const existingTurns = turnIndexStore.listTurns();
|
|
444
|
+
const existing = existingTurns.find((item) => item.turnId === effectiveTurnId) || null;
|
|
445
|
+
const turnSlice = resolveDurableTurnSlice(recovered, {
|
|
446
|
+
preTurnOffset,
|
|
447
|
+
resume: Boolean(resume),
|
|
448
|
+
promptText,
|
|
449
|
+
});
|
|
450
|
+
const indexed = turnIndexStore.upsertTurn(buildDeterministicTurnRecord({
|
|
451
|
+
turnId: effectiveTurnId,
|
|
452
|
+
turnIndex: existing ? existing.turnIndex : existingTurns.length,
|
|
453
|
+
historyOffset: preTurnOffset,
|
|
454
|
+
historyEnd: preTurnOffset + turnSlice.length,
|
|
455
|
+
turnMessages: turnSlice,
|
|
456
|
+
requestKind,
|
|
457
|
+
prompt: promptText,
|
|
458
|
+
outcome: cancelled ? "cancelled" : "failed",
|
|
459
|
+
error: (err && err.message) || "native runner failed",
|
|
460
|
+
previousTurns: existingTurns,
|
|
461
|
+
resume: Boolean(resume),
|
|
462
|
+
}), { phase: "A" });
|
|
463
|
+
await observe({
|
|
464
|
+
type: "context.turn_indexed",
|
|
465
|
+
turnId: indexed.turnId,
|
|
466
|
+
topic: indexed.topic,
|
|
467
|
+
turnKind: indexed.turnKind,
|
|
468
|
+
outcome: indexed.outcome,
|
|
469
|
+
});
|
|
470
|
+
} catch {}
|
|
471
|
+
}
|
|
472
|
+
await observe({ type: cancelled ? "task.cancelled" : "task.failed", error: err.message || "native runner failed" });
|
|
313
473
|
const message = err && err.message ? err.message : "native runner failed";
|
|
314
|
-
|
|
315
|
-
|
|
474
|
+
const recoveredState = recovered.executionState || executionState;
|
|
475
|
+
if (recoveredState && typeof recoveredState === "object") {
|
|
476
|
+
clearUserPrompts(recoveredState);
|
|
316
477
|
}
|
|
317
478
|
return {
|
|
318
479
|
ok: false,
|
|
319
480
|
error: message,
|
|
320
481
|
output: partialOutput.trim(),
|
|
321
482
|
sessionId: nextSessionId,
|
|
322
|
-
streamed:
|
|
323
|
-
|
|
483
|
+
streamed: Boolean(partialOutput) && typeof onStreamDelta === "function",
|
|
484
|
+
messages: cloneMessageList(recovered.messages),
|
|
485
|
+
turnItems: cloneMessageList(recovered.turnItems),
|
|
486
|
+
usage: recovered.usage || createUsageTotals(),
|
|
487
|
+
protocolLedger: recovered.protocolLedger || null,
|
|
488
|
+
executionState: recoveredState || null,
|
|
324
489
|
...(observationWarnings.length ? { observationWarnings } : {}),
|
|
325
490
|
};
|
|
491
|
+
} finally {
|
|
492
|
+
if (abortEnricherListener && signal && typeof signal.removeEventListener === "function") {
|
|
493
|
+
signal.removeEventListener("abort", abortEnricherListener);
|
|
494
|
+
}
|
|
495
|
+
if (enricher && (signal?.aborted || enricher.pendingCount() === 0)) enricher.close();
|
|
326
496
|
}
|
|
327
497
|
}
|
|
328
498
|
|
package/src/code/repl.js
CHANGED
|
@@ -404,6 +404,31 @@ async function runUcodeCoreAgent({
|
|
|
404
404
|
let queuedWork = 0;
|
|
405
405
|
let queueGeneration = 0;
|
|
406
406
|
let activeAbortController = null;
|
|
407
|
+
const wakeHost = require("./runtime/backgroundWakeHost").createUcodeWakeHost({ state,
|
|
408
|
+
canDeliver: () => !closing && !taskInFlight && !queuedWork && !autoBusQueued,
|
|
409
|
+
deliver: (event, claim, text) => {
|
|
410
|
+
const pending = chain.then(async () => {
|
|
411
|
+
const { hasPendingUserInteraction } = require("./context/userInteraction");
|
|
412
|
+
if (closing || hasPendingUserInteraction(state.executionState) || !claim()) return false;
|
|
413
|
+
const abort = new AbortController();
|
|
414
|
+
activeAbortController = abort;
|
|
415
|
+
taskInFlight = true;
|
|
416
|
+
try {
|
|
417
|
+
stdout.write(`\n[${event.type}]\n`);
|
|
418
|
+
const result = await runNaturalLanguageTask(text, state, { signal: abort.signal,
|
|
419
|
+
runtimeContext: { requestKind: "system_wake", parentTaskRunId: event.ownerTaskRunId } });
|
|
420
|
+
stdout.write(`${formatNlResult(result, state.jsonOutput)}\n`);
|
|
421
|
+
persistSessionState(state);
|
|
422
|
+
printPrompt(stdout);
|
|
423
|
+
} finally { taskInFlight = false; if (activeAbortController === abort) activeAbortController = null; }
|
|
424
|
+
return true;
|
|
425
|
+
});
|
|
426
|
+
chain = pending.catch(() => {});
|
|
427
|
+
return pending;
|
|
428
|
+
},
|
|
429
|
+
onError: error => stdout.write(`Background notification: ${error.message}\n`),
|
|
430
|
+
});
|
|
431
|
+
wakeHost.start();
|
|
407
432
|
|
|
408
433
|
function formatCoreQueueStatus() {
|
|
409
434
|
return `Queue: ${taskInFlight ? "active" : "idle"} · pending ${queuedWork}`;
|
|
@@ -801,7 +826,8 @@ async function runUcodeCoreAgent({
|
|
|
801
826
|
|
|
802
827
|
rl.on("close", () => {
|
|
803
828
|
closing = true;
|
|
804
|
-
|
|
829
|
+
wakeHost.close();
|
|
830
|
+
if (activeAbortController) activeAbortController.abort("runtime_closed");
|
|
805
831
|
if (autoBusTimer) {
|
|
806
832
|
clearInterval(autoBusTimer);
|
|
807
833
|
autoBusTimer = null;
|
|
@@ -94,18 +94,35 @@ function shouldAutoContinueForTaskWake(executionState = null) {
|
|
|
94
94
|
function buildTaskRunWakeReminder(executionState = null) {
|
|
95
95
|
const runs = listTaskRunsAwaitingModel(executionState);
|
|
96
96
|
if (runs.length === 0 && !hasPendingAgentMailbox(executionState)) return "";
|
|
97
|
+
const graphs = executionState && executionState.graphs && typeof executionState.graphs === "object"
|
|
98
|
+
? executionState.graphs
|
|
99
|
+
: {};
|
|
97
100
|
const lines = [
|
|
98
101
|
"Runtime wake (not a user message): active TaskRun(s) still need the Agent Loop.",
|
|
99
|
-
"Continue serving them now.
|
|
100
|
-
"call plan_graph operation=patch with graphId=<childGraphId> and expand_node on nodeId=root",
|
|
101
|
-
"(tool children). Do not ask the user to /plan off. Do not end with text only.",
|
|
102
|
+
"Continue serving them now. Do not ask the user to /plan off. Do not end with text only.",
|
|
102
103
|
];
|
|
103
104
|
for (const run of runs.slice(0, 4)) {
|
|
104
105
|
const label = run.title || run.objective || run.parentNodeId || run.id;
|
|
106
|
+
const child = run.childGraphId ? graphs[run.childGraphId] : null;
|
|
107
|
+
const childWaiting = child && child.waitingFor && child.waitingFor.id
|
|
108
|
+
? String(child.waitingFor.id)
|
|
109
|
+
: "";
|
|
110
|
+
const childNodes = child && Array.isArray(child.nodes) ? child.nodes : [];
|
|
111
|
+
let actionHint = "";
|
|
112
|
+
if (run.childGraphId && childWaiting) {
|
|
113
|
+
actionHint = ` -> call plan_graph operation="patch" graphId="${run.childGraphId}" with expand_node on nodeId="${childWaiting}" (tool children)`;
|
|
114
|
+
} else if (run.childGraphId && childNodes.length > 0 && !childWaiting) {
|
|
115
|
+
actionHint = run.parentNodeId
|
|
116
|
+
? ` -> all child nodes finished; call plan_graph operation="control" actions=[{"op":"complete_task","taskRunId":"${run.id}","result":{"summary":"..."}}] (or patch graphId="${run.childGraphId}" to add more steps)`
|
|
117
|
+
: ` -> all child nodes finished; call task_run operation="complete" taskRunId="${run.id}" result={"summary":"..."} (or patch graphId="${run.childGraphId}" to add more steps)`;
|
|
118
|
+
} else if (run.childGraphId) {
|
|
119
|
+
actionHint = ` -> call plan_graph operation="patch" graphId="${run.childGraphId}" with expand_node on nodeId="root" (tool children)`;
|
|
120
|
+
}
|
|
105
121
|
lines.push(
|
|
106
122
|
`- taskRunId=${run.id} phase=${run.phase || ""} status=${run.status || ""}`
|
|
107
123
|
+ (run.childGraphId ? ` childGraphId=${run.childGraphId}` : "")
|
|
108
124
|
+ (label ? ` — ${String(label).slice(0, 120)}` : "")
|
|
125
|
+
+ actionHint
|
|
109
126
|
);
|
|
110
127
|
}
|
|
111
128
|
return lines.join("\n");
|