u-foo 4.0.2 → 4.0.5
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 +22 -4
- package/README.zh-CN.md +5 -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 +3 -3
- package/src/agents/providers/nativeTransport.js +109 -53
- package/src/agents/providers/runtimeConfig.js +41 -1
- package/src/agents/runtime/context/checkpointStore.js +15 -1
- package/src/agents/runtime/context/compaction.js +27 -7
- package/src/agents/runtime/context/runtimeStore.js +1 -0
- package/src/agents/runtime/core/agentLoop.js +48 -6
- package/src/app/cli/busCoreCommands.js +63 -3
- package/src/app/cli/run.js +1 -0
- package/src/code/agent.js +36 -19
- package/src/code/context/planGraphService.js +41 -0
- package/src/code/modelCommand.js +6 -5
- package/src/code/nativeRunner.js +15 -56
- package/src/code/taskDecomposer.js +3 -0
- package/src/code/tools/executor.js +1 -0
- package/src/code/tools/planGraph.js +1 -0
- package/src/code/tools/specs.js +2 -1
- 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/state/paths.js +4 -0
- package/src/runtime/daemon/agentHost.js +2 -0
- package/src/runtime/daemon/deliveryScheduler.js +70 -2
- package/src/runtime/daemon/index.js +1 -0
- package/src/runtime/daemon/mcpStdioProxy.js +130 -10
- package/src/ui/agentSurface.js +34 -3
- package/src/ui/format/markdownRenderer.js +4 -2
- package/src/ui/rustUcodeHost.js +3 -3
|
@@ -1,5 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
const { readWakeKeyFile } = require("../../coordination/bus/wakeEndpoint");
|
|
4
|
+
|
|
5
|
+
function parseJoinArgs(cmdArgs = []) {
|
|
6
|
+
const positionals = [];
|
|
7
|
+
let wakeUrl = "";
|
|
8
|
+
let wakeKeyFile = "";
|
|
9
|
+
let wakeAdapter = "";
|
|
10
|
+
|
|
11
|
+
for (let index = 0; index < cmdArgs.length; index += 1) {
|
|
12
|
+
const arg = String(cmdArgs[index] || "");
|
|
13
|
+
if (arg === "--wake-url") {
|
|
14
|
+
wakeUrl = String(cmdArgs[index + 1] || "").trim();
|
|
15
|
+
if (!wakeUrl || wakeUrl.startsWith("--")) throw new Error("join --wake-url requires <url>");
|
|
16
|
+
index += 1;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (arg === "--wake-key-file") {
|
|
20
|
+
wakeKeyFile = String(cmdArgs[index + 1] || "").trim();
|
|
21
|
+
if (!wakeKeyFile || wakeKeyFile.startsWith("--")) throw new Error("join --wake-key-file requires <path>");
|
|
22
|
+
index += 1;
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (arg === "--wake-adapter") {
|
|
26
|
+
wakeAdapter = String(cmdArgs[index + 1] || "").trim();
|
|
27
|
+
if (!wakeAdapter || wakeAdapter.startsWith("--")) throw new Error("join --wake-adapter requires <name>");
|
|
28
|
+
index += 1;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (arg.startsWith("--")) throw new Error(`Unknown join option: ${arg}`);
|
|
32
|
+
positionals.push(arg);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if ((positionals[1] || "").toLowerCase() === "grok-bot") positionals[1] = "grok-bot";
|
|
36
|
+
const wakeRequested = Boolean(wakeUrl || wakeKeyFile || wakeAdapter);
|
|
37
|
+
if (wakeRequested && !positionals[1]) {
|
|
38
|
+
throw new Error("join wake requires <agent-type>");
|
|
39
|
+
}
|
|
40
|
+
if (wakeRequested && (!wakeUrl || !wakeKeyFile)) {
|
|
41
|
+
throw new Error("join wake requires --wake-url and --wake-key-file");
|
|
42
|
+
}
|
|
43
|
+
if (positionals[1] === "grok-bot" && !wakeRequested) {
|
|
44
|
+
throw new Error("grok-bot join requires --wake-url and --wake-key-file");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
sessionId: positionals[0] || "",
|
|
49
|
+
agentType: positionals[1] || "",
|
|
50
|
+
nickname: positionals[2] || "",
|
|
51
|
+
wake: wakeRequested ? {
|
|
52
|
+
adapter: wakeAdapter || "bearer-json",
|
|
53
|
+
url: wakeUrl,
|
|
54
|
+
key: readWakeKeyFile(wakeKeyFile),
|
|
55
|
+
} : null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
3
59
|
function parseSendArgs(cmdArgs = []) {
|
|
4
60
|
let injectionMode = "immediate";
|
|
5
61
|
let source = "";
|
|
@@ -155,9 +211,13 @@ async function runBusCoreCommand(eventBus, cmd, cmdArgs = []) {
|
|
|
155
211
|
await eventBus.init();
|
|
156
212
|
return {};
|
|
157
213
|
case "join":
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
214
|
+
{
|
|
215
|
+
const parsed = parseJoinArgs(cmdArgs);
|
|
216
|
+
const subscriber = parsed.wake
|
|
217
|
+
? await eventBus.join(parsed.sessionId, parsed.agentType, parsed.nickname, { wake: parsed.wake })
|
|
218
|
+
: await eventBus.join(parsed.sessionId, parsed.agentType, parsed.nickname);
|
|
219
|
+
return { subscriber };
|
|
220
|
+
}
|
|
161
221
|
case "leave":
|
|
162
222
|
await eventBus.leave(cmdArgs[0]);
|
|
163
223
|
return {};
|
package/src/app/cli/run.js
CHANGED
|
@@ -1825,6 +1825,7 @@ async function runCli(argv) {
|
|
|
1825
1825
|
console.log(" ufoo online connect --nickname <name> [--join <ch>] [--room <id> --room-password <pwd>] [...]");
|
|
1826
1826
|
console.log(" ufoo online send --nickname <name> --text <msg> [--channel <ch>] [--room <id>]");
|
|
1827
1827
|
console.log(" ufoo online inbox <nickname> [--clear] [--unread]");
|
|
1828
|
+
console.log(" ufoo bus join <session> <agent-type> [nickname] --wake-url <url> --wake-key-file <path> [--wake-adapter bearer-json]");
|
|
1828
1829
|
console.log(" ufoo bus wake <target> [--reason <reason>] [--no-shake]");
|
|
1829
1830
|
console.log(" ufoo bus poll [subscriber] [--ack | --follow --interval <seconds>]");
|
|
1830
1831
|
console.log(" ufoo bus ack <subscriber> [--through <seq>]");
|
package/src/code/agent.js
CHANGED
|
@@ -486,6 +486,18 @@ function buildNlFallbackSummary(logs = []) {
|
|
|
486
486
|
return "Done (no model text response).";
|
|
487
487
|
}
|
|
488
488
|
|
|
489
|
+
function commitConversationOutput(state, workspaceRoot, turnId, update = {}) {
|
|
490
|
+
const items = Array.isArray(update.turnItems) ? update.turnItems : [];
|
|
491
|
+
const appended = appendTurnMessages(workspaceRoot, state.sessionId, turnId, items, { scope: "output" });
|
|
492
|
+
if (!appended.ok) throw Object.assign(new Error(`failed to persist conversation output: ${appended.error}`), { code: "conversation_persistence_failed" });
|
|
493
|
+
if (update.executionState) state.executionState = update.executionState;
|
|
494
|
+
const transcript = loadTranscript(workspaceRoot, state.sessionId);
|
|
495
|
+
state.transcriptEvents = transcript.events;
|
|
496
|
+
state.nlMessages = stripSkillBlocksFromMessages(transcriptEventsToMessages(transcript.events, { preferArtifact: true }));
|
|
497
|
+
const saved = persistSessionState(state);
|
|
498
|
+
if (saved?.ok === false) throw Object.assign(new Error(`failed to persist session progress: ${saved.error}`), { code: "conversation_persistence_failed" });
|
|
499
|
+
}
|
|
500
|
+
|
|
489
501
|
async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
490
502
|
const taskText = String(task || "").trim();
|
|
491
503
|
if (!taskText) {
|
|
@@ -664,6 +676,7 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
664
676
|
onContextUsage: applyContextMeter,
|
|
665
677
|
executionState: state.executionState || null,
|
|
666
678
|
onArtifactPersisted: (persisted) => recordToolCallInSession(state, persisted, workspaceRoot),
|
|
679
|
+
onConversationUpdate: (update) => commitConversationOutput(state, workspaceRoot, turnId, update),
|
|
667
680
|
contextPolicy: state.contextPolicy || {},
|
|
668
681
|
runtimeContext: options.runtimeContext || {},
|
|
669
682
|
onRuntimeEvent: options.onRuntimeEvent,
|
|
@@ -724,6 +737,7 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
724
737
|
systemBlocks: assembled.systemBlocks || null,
|
|
725
738
|
runtimeContext: options.runtimeContext || {},
|
|
726
739
|
onRuntimeEvent: options.onRuntimeEvent,
|
|
740
|
+
onConversationUpdate: (update) => commitConversationOutput(state, workspaceRoot, turnId, update),
|
|
727
741
|
onStreamDelta: onStream,
|
|
728
742
|
onThinkingDelta,
|
|
729
743
|
onPhase,
|
|
@@ -751,9 +765,11 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
751
765
|
|
|
752
766
|
if (!cliRes || cliRes.ok === false) {
|
|
753
767
|
const errMsg = String((cliRes && cliRes.error) || "");
|
|
754
|
-
//
|
|
755
|
-
//
|
|
756
|
-
|
|
768
|
+
// Whole-invocation retry is safe only before any execution or output.
|
|
769
|
+
// A committed assistant message must keep its existing journal indices.
|
|
770
|
+
const hasProgress = streamed || cliRes?.streamed || Boolean(String(cliRes?.output || "").trim())
|
|
771
|
+
|| Boolean(cliRes?.turnItems?.length);
|
|
772
|
+
if (isCliTimeoutError(errMsg) && toolEventsThisAttempt === 0 && !hasProgress) {
|
|
757
773
|
const extendedTimeoutMs = computeExtendedTimeout(timeoutMs);
|
|
758
774
|
cliRes = await invokeNative(String(state.sessionId || ""), extendedTimeoutMs);
|
|
759
775
|
}
|
|
@@ -788,6 +804,22 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
788
804
|
transcriptEventsToMessages(transcript.events, { preferArtifact: true }),
|
|
789
805
|
);
|
|
790
806
|
|
|
807
|
+
// The turn coordinator owns session identity. Providers/runners receive it
|
|
808
|
+
// as correlation metadata but cannot redirect durable writes mid-turn.
|
|
809
|
+
if (cliRes && cliRes.executionState && typeof cliRes.executionState === "object") {
|
|
810
|
+
// Preserve planMode if the runner returned a fresh empty state without it.
|
|
811
|
+
const priorPlanMode = Boolean(state.executionState && state.executionState.planMode);
|
|
812
|
+
const priorSource = state.executionState && state.executionState.planModeSource
|
|
813
|
+
? String(state.executionState.planModeSource)
|
|
814
|
+
: "";
|
|
815
|
+
state.executionState = cliRes.executionState;
|
|
816
|
+
if (typeof state.executionState.planMode !== "boolean") {
|
|
817
|
+
state.executionState.planMode = priorPlanMode;
|
|
818
|
+
}
|
|
819
|
+
if (!state.executionState.planModeSource && priorSource) {
|
|
820
|
+
state.executionState.planModeSource = priorSource;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
791
823
|
if (!cliRes || cliRes.ok === false) {
|
|
792
824
|
const errMsg = String((cliRes && cliRes.error) || "");
|
|
793
825
|
if (isCliCancelledError(errMsg) && state.executionState) {
|
|
@@ -805,22 +837,6 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
805
837
|
streamLastChar,
|
|
806
838
|
};
|
|
807
839
|
}
|
|
808
|
-
// The turn coordinator owns session identity. Providers/runners receive it
|
|
809
|
-
// as correlation metadata but cannot redirect durable writes mid-turn.
|
|
810
|
-
if (cliRes && cliRes.executionState && typeof cliRes.executionState === "object") {
|
|
811
|
-
// Preserve planMode if the runner returned a fresh empty state without it.
|
|
812
|
-
const priorPlanMode = Boolean(state.executionState && state.executionState.planMode);
|
|
813
|
-
const priorSource = state.executionState && state.executionState.planModeSource
|
|
814
|
-
? String(state.executionState.planModeSource)
|
|
815
|
-
: "";
|
|
816
|
-
state.executionState = cliRes.executionState;
|
|
817
|
-
if (typeof state.executionState.planMode !== "boolean") {
|
|
818
|
-
state.executionState.planMode = priorPlanMode;
|
|
819
|
-
}
|
|
820
|
-
if (!state.executionState.planModeSource && priorSource) {
|
|
821
|
-
state.executionState.planModeSource = priorSource;
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
840
|
const normalized = String(cliRes.output || "").trim();
|
|
825
841
|
const sideEffects = parseStructuredSideEffects(normalized);
|
|
826
842
|
if (sideEffects) {
|
|
@@ -1197,6 +1213,7 @@ async function resumeAfterUserInteraction(answerText = "", state = {}, options =
|
|
|
1197
1213
|
contextPolicy: state.contextPolicy || {},
|
|
1198
1214
|
runtimeContext: options.runtimeContext || {},
|
|
1199
1215
|
onRuntimeEvent: options.onRuntimeEvent,
|
|
1216
|
+
onConversationUpdate: (update) => commitConversationOutput(state, workspaceRoot, turnId, update),
|
|
1200
1217
|
onThinkingDelta: typeof options.onThinkingDelta === "function" ? options.onThinkingDelta : null,
|
|
1201
1218
|
onPhase: typeof options.onPhase === "function" ? options.onPhase : null,
|
|
1202
1219
|
onContextUsage: (meter) => {
|
|
@@ -200,6 +200,36 @@ function rejected(errors = [], extras = {}) {
|
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
+
function validateCommandNodes(command, validateToolArgs = false) {
|
|
204
|
+
const errors = [];
|
|
205
|
+
const specs = validateToolArgs ? new Map(require("../tools/specs").buildCoreToolSpecs()
|
|
206
|
+
.map(({ function: spec }) => [spec.name, spec.parameters])) : null;
|
|
207
|
+
const visit = (node, field) => {
|
|
208
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) return;
|
|
209
|
+
if (node.type === "tool" || node.tool) {
|
|
210
|
+
if (Object.hasOwn(node, "arguments")) errors.push({ code: "INVALID_NODE_ARGUMENTS", field: `${field}.arguments`, nodeId: node.id || "",
|
|
211
|
+
message: `${field}.arguments is unsupported; use ${field}.args for tool parameters` });
|
|
212
|
+
if (node.args != null && (typeof node.args !== "object" || Array.isArray(node.args))) errors.push({ code: "INVALID_NODE_ARGUMENTS", field: `${field}.args`, nodeId: node.id || "", message: `${field}.args must be an object` });
|
|
213
|
+
if (!Object.hasOwn(node, "arguments")) for (const key of specs?.get(node.tool)?.required || []) {
|
|
214
|
+
if (!Object.hasOwn(node.args || {}, key)) errors.push({ code: "MISSING_TOOL_ARGUMENT", field: `${field}.args.${key}`, nodeId: node.id || "",
|
|
215
|
+
message: `${field}.args.${key} is required for ${node.tool}; correct the node and resubmit the command` });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
for (const key of ["nodes", "children", "steps"]) if (Array.isArray(node[key])) node[key].forEach((child, index) => visit(child, `${field}.${key}[${index}]`));
|
|
219
|
+
for (const key of ["node", "with", "subgraph"]) if (node[key]) visit(node[key], `${field}.${key}`);
|
|
220
|
+
};
|
|
221
|
+
if (command.operation === "create") visit(command.graph, "graph");
|
|
222
|
+
if (command.operation === "patch") (command.operations || []).forEach((op, index) => visit(op, `operations[${index}]`));
|
|
223
|
+
return errors;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function planRecovery(nodes = []) {
|
|
227
|
+
const failures = nodes.filter(node => node.status === "failed" || node.status === "blocked")
|
|
228
|
+
.map(node => ({ nodeId: node.id, tool: node.tool || "", error: String(node.error || node.result?.error || node.result?.summary || "blocked").slice(0, 1000) }));
|
|
229
|
+
return failures.length ? { needed: true, failures,
|
|
230
|
+
hint: "Inspect is read-only and cannot retry failed nodes. Correct the plan using patch, or use control.skip_node/control.cancel_subtree for obsolete nodes. If recovery requires user input, explain the concrete blocker." } : null;
|
|
231
|
+
}
|
|
232
|
+
|
|
203
233
|
function accepted(payload = {}) {
|
|
204
234
|
return {
|
|
205
235
|
ok: true,
|
|
@@ -383,6 +413,7 @@ function buildAdvanceSummary(result = {}, beforeStatuses = new Map()) {
|
|
|
383
413
|
type: node.type,
|
|
384
414
|
status: node.status,
|
|
385
415
|
summary: (node.result && node.result.summary) || node.error || node.status,
|
|
416
|
+
...(node.error || node.result?.error ? { error: String(node.error || node.result.error).slice(0, 1000) } : {}),
|
|
386
417
|
};
|
|
387
418
|
if (node.status === "succeeded") executedNodes.push(entry);
|
|
388
419
|
if (node.status === "failed") failedNodes.push(entry);
|
|
@@ -482,6 +513,7 @@ function projectPlanView(planGraph = {}) {
|
|
|
482
513
|
execution: node.execution || "",
|
|
483
514
|
generated: Boolean(node.generated),
|
|
484
515
|
summary: (node.result && node.result.summary) || "",
|
|
516
|
+
...(node.error || node.result?.error ? { error: String(node.error || node.result.error).slice(0, 1000) } : {}),
|
|
485
517
|
children: byParent.get(node.id) || [],
|
|
486
518
|
}));
|
|
487
519
|
}
|
|
@@ -514,8 +546,10 @@ function inspectPlanGraph(planGraph = {}) {
|
|
|
514
546
|
parentTaskId: node.parentTaskId || "",
|
|
515
547
|
execution: node.execution || "",
|
|
516
548
|
generated: Boolean(node.generated),
|
|
549
|
+
...(node.error || node.result?.error ? { error: String(node.error || node.result.error).slice(0, 1000) } : {}),
|
|
517
550
|
})),
|
|
518
551
|
planView: projectPlanView(planGraph),
|
|
552
|
+
recovery: planRecovery(nodes),
|
|
519
553
|
validationWarnings: [],
|
|
520
554
|
});
|
|
521
555
|
}
|
|
@@ -591,6 +625,11 @@ function runPlanGraphCommand(commandInput = {}, options = {}) {
|
|
|
591
625
|
const payload = rejected([{ code: "MISSING_OPERATION", message: "operation is required" }]);
|
|
592
626
|
return { ...payload, executionState, modelPayload: payload };
|
|
593
627
|
}
|
|
628
|
+
const nodeErrors = validateCommandNodes(command, options.validateToolArgs === true);
|
|
629
|
+
if (nodeErrors.length) {
|
|
630
|
+
const payload = rejected(nodeErrors);
|
|
631
|
+
return { ...payload, executionState, modelPayload: payload };
|
|
632
|
+
}
|
|
594
633
|
|
|
595
634
|
// create/control always target the primary agent graph; patch/inspect may
|
|
596
635
|
// select a TaskLoop child via command.graphId.
|
|
@@ -748,6 +787,7 @@ function runPlanGraphCommand(commandInput = {}, options = {}) {
|
|
|
748
787
|
waitingFor: terminal ? null : (live.waitingFor || null),
|
|
749
788
|
advance,
|
|
750
789
|
planView: terminal ? [] : projectPlanView(live),
|
|
790
|
+
recovery: terminal ? null : planRecovery(live.nodes),
|
|
751
791
|
validationWarnings: [],
|
|
752
792
|
...(terminal ? {
|
|
753
793
|
planCompleted: true,
|
|
@@ -1114,6 +1154,7 @@ function runPlanGraphCommand(commandInput = {}, options = {}) {
|
|
|
1114
1154
|
stoppedAt: terminal ? "graph_terminal" : (live.lastStoppedAt || ""),
|
|
1115
1155
|
advance,
|
|
1116
1156
|
planView: terminal ? [] : projectPlanView(live),
|
|
1157
|
+
recovery: terminal ? null : planRecovery(live.nodes),
|
|
1117
1158
|
validationWarnings: preferredCompile.warnings || [],
|
|
1118
1159
|
summary: terminal
|
|
1119
1160
|
? terminal.completionSummary
|
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,10 +1,7 @@
|
|
|
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");
|
|
@@ -112,6 +109,7 @@ async function runNativeAgentTask({
|
|
|
112
109
|
contextPolicy = {},
|
|
113
110
|
runtimeContext = {},
|
|
114
111
|
onRuntimeEvent = null,
|
|
112
|
+
onConversationUpdate = null,
|
|
115
113
|
} = {}) {
|
|
116
114
|
const guards = createGuards({ signal, timeoutMs });
|
|
117
115
|
const nextSessionId = String(sessionId || "").trim() || `native-${randomUUID()}`;
|
|
@@ -171,59 +169,13 @@ async function runNativeAgentTask({
|
|
|
171
169
|
};
|
|
172
170
|
}
|
|
173
171
|
|
|
174
|
-
const runtime =
|
|
172
|
+
const runtime = await resolveAuthenticatedRuntime({
|
|
175
173
|
workspaceRoot,
|
|
176
174
|
provider,
|
|
177
175
|
model,
|
|
178
176
|
});
|
|
179
177
|
|
|
180
|
-
|
|
181
|
-
if (runtime.provider === "codex" && !runtime.apiKey) {
|
|
182
|
-
try {
|
|
183
|
-
const config = loadConfig(workspaceRoot) || {};
|
|
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
|
-
}
|
|
210
|
-
|
|
211
|
-
// Kimi tokens expire; resolveRuntimeConfig reads the credential file
|
|
212
|
-
// synchronously, so refresh it here (async) when the key came from that
|
|
213
|
-
// file and the token is outside the fresh window.
|
|
214
|
-
if (
|
|
215
|
-
runtime.provider === "kimi"
|
|
216
|
-
&& runtime.apiKeySource === "kimi-credential"
|
|
217
|
-
&& runtime.kimiCredentialState !== "fresh"
|
|
218
|
-
) {
|
|
219
|
-
try {
|
|
220
|
-
const credential = await resolveKimiUpstreamCredentials({ env: process.env });
|
|
221
|
-
const token = String(credential && credential.accessToken || "").trim();
|
|
222
|
-
if (token) runtime.apiKey = token;
|
|
223
|
-
} catch {
|
|
224
|
-
// Keep the file token; the request itself will surface auth failures.
|
|
225
|
-
}
|
|
226
|
-
}
|
|
178
|
+
const accountId = runtime.accountId;
|
|
227
179
|
|
|
228
180
|
const transport = getNativeTransport(runtime.transport);
|
|
229
181
|
await observe({ type: "runtime.binding", binding: { provider: runtime.provider, model: runtime.model, transport: runtime.transport } });
|
|
@@ -248,6 +200,7 @@ async function runNativeAgentTask({
|
|
|
248
200
|
onPhase,
|
|
249
201
|
onToolEvent,
|
|
250
202
|
onArtifactPersisted,
|
|
203
|
+
onConversationUpdate,
|
|
251
204
|
onContextUsage,
|
|
252
205
|
sessionId: nextSessionId,
|
|
253
206
|
signal,
|
|
@@ -311,16 +264,22 @@ async function runNativeAgentTask({
|
|
|
311
264
|
} catch (err) {
|
|
312
265
|
await observe({ type: signal?.aborted || err.code === "cancelled" ? "task.cancelled" : "task.failed", error: err.message || "native runner failed" });
|
|
313
266
|
const message = err && err.message ? err.message : "native runner failed";
|
|
314
|
-
|
|
315
|
-
|
|
267
|
+
const recovered = err.result || {};
|
|
268
|
+
const recoveredState = recovered.executionState || executionState;
|
|
269
|
+
if (recoveredState && typeof recoveredState === "object") {
|
|
270
|
+
clearUserPrompts(recoveredState);
|
|
316
271
|
}
|
|
317
272
|
return {
|
|
318
273
|
ok: false,
|
|
319
274
|
error: message,
|
|
320
275
|
output: partialOutput.trim(),
|
|
321
276
|
sessionId: nextSessionId,
|
|
322
|
-
streamed:
|
|
323
|
-
|
|
277
|
+
streamed: Boolean(partialOutput) && typeof onStreamDelta === "function",
|
|
278
|
+
messages: cloneMessageList(recovered.messages),
|
|
279
|
+
turnItems: cloneMessageList(recovered.turnItems),
|
|
280
|
+
usage: recovered.usage || createUsageTotals(),
|
|
281
|
+
protocolLedger: recovered.protocolLedger || null,
|
|
282
|
+
executionState: recoveredState || null,
|
|
324
283
|
...(observationWarnings.length ? { observationWarnings } : {}),
|
|
325
284
|
};
|
|
326
285
|
}
|
|
@@ -166,6 +166,7 @@ async function runDecomposedTask({
|
|
|
166
166
|
systemBlocks = null,
|
|
167
167
|
runtimeContext = {},
|
|
168
168
|
onRuntimeEvent = null,
|
|
169
|
+
onConversationUpdate = null,
|
|
169
170
|
onStreamDelta = null,
|
|
170
171
|
onThinkingDelta = null,
|
|
171
172
|
onPhase = null,
|
|
@@ -236,6 +237,8 @@ async function runDecomposedTask({
|
|
|
236
237
|
runtimeContext: inherited.taskRunId ? { ...inherited, parentTaskRunId: inherited.taskRunId,
|
|
237
238
|
taskRunId: `segment-${randomUUID()}`, requestId: `${inherited.requestId || "step"}:${step.id}`, attemptId: `attempt-${randomUUID()}` } : inherited,
|
|
238
239
|
onRuntimeEvent,
|
|
240
|
+
onConversationUpdate: onConversationUpdate
|
|
241
|
+
? update => onConversationUpdate({ ...update, turnItems: [...turnItems, ...update.turnItems] }) : null,
|
|
239
242
|
onStreamDelta,
|
|
240
243
|
onThinkingDelta,
|
|
241
244
|
onPhase,
|
|
@@ -109,6 +109,7 @@ function runCoreToolUnlocked({
|
|
|
109
109
|
const result = runPlanGraphCommand(safeArgs, {
|
|
110
110
|
executionState: state,
|
|
111
111
|
autoAdvance: true,
|
|
112
|
+
validateToolArgs: true,
|
|
112
113
|
parallel: true,
|
|
113
114
|
runTool: ({ node, args: nestedArgs, tool: nestedTool, stepId }) => {
|
|
114
115
|
const nested = runCoreTool({
|
package/src/code/tools/specs.js
CHANGED
|
@@ -152,13 +152,14 @@ function buildCoreToolSpecs() {
|
|
|
152
152
|
},
|
|
153
153
|
graph: {
|
|
154
154
|
type: "object",
|
|
155
|
-
description:
|
|
155
|
+
description: 'Full graph for create (objective + nodes). Tool nodes use {id,type:"tool",tool,args:{...}}; tool parameters belong in args. group is input sugar only.',
|
|
156
156
|
},
|
|
157
157
|
operations: {
|
|
158
158
|
type: "array",
|
|
159
159
|
description: [
|
|
160
160
|
"Patch ops only: add_node, expand_node, add_dependency, remove_dependency.",
|
|
161
161
|
"Status actions (complete_task, skip_node, cancel_subtree) belong under control.actions.",
|
|
162
|
+
'Tool children use {id,type:"tool",tool:"read",args:{path:"AGENTS.md"}}. Use args, not arguments.',
|
|
162
163
|
].join(" "),
|
|
163
164
|
items: { type: "object" },
|
|
164
165
|
},
|
|
@@ -179,7 +179,7 @@ class EventBus {
|
|
|
179
179
|
sessionId,
|
|
180
180
|
agentType,
|
|
181
181
|
nickname,
|
|
182
|
-
options
|
|
182
|
+
{ ...options, projectRoot: options.projectRoot || this.projectRoot }
|
|
183
183
|
);
|
|
184
184
|
|
|
185
185
|
this.saveBusData();
|
|
@@ -197,7 +197,7 @@ class EventBus {
|
|
|
197
197
|
this.ensureBus();
|
|
198
198
|
this.loadBusData();
|
|
199
199
|
|
|
200
|
-
const success = await this.subscriberManager.leave(subscriber);
|
|
200
|
+
const success = await this.subscriberManager.leave(subscriber, { projectRoot: this.projectRoot });
|
|
201
201
|
|
|
202
202
|
if (success) {
|
|
203
203
|
this.saveBusData();
|
|
@@ -16,6 +16,7 @@ const { getUfooPaths } = require("../state/paths");
|
|
|
16
16
|
const { applyProjectNicknamePrefix } = require("../../runtime/daemon/nicknameScope");
|
|
17
17
|
const { QUEUE_TYPES, normalizeQueueEnvelope } = require("./deliveryQueue");
|
|
18
18
|
const { isInternalAgentMeta } = require("../../runtime/contracts/agentMode");
|
|
19
|
+
const { isWakeMeta } = require("./wakeEndpoint");
|
|
19
20
|
|
|
20
21
|
const SEQ_LOCK_TIMEOUT_MS = 5000;
|
|
21
22
|
const SEQ_LOCK_POLL_MS = 25;
|
|
@@ -463,7 +464,15 @@ class MessageManager {
|
|
|
463
464
|
// 检查订阅者的 offset,如果已经消费过这个 seq,不再添加
|
|
464
465
|
const offset = await this.queueManager.getOffset(targetSubscriber);
|
|
465
466
|
if (seq > offset) {
|
|
466
|
-
|
|
467
|
+
const wakeTarget = isWakeMeta(this.busData.agents?.[targetSubscriber]);
|
|
468
|
+
const queued = wakeTarget
|
|
469
|
+
? normalizeQueueEnvelope(event, {
|
|
470
|
+
queueType: QUEUE_TYPES.AGENT_MESSAGE,
|
|
471
|
+
delivery: { mode: "wake", gate: "none", max_inflight: 1 },
|
|
472
|
+
ack: { policy: "on_consume" },
|
|
473
|
+
})
|
|
474
|
+
: queueEvent;
|
|
475
|
+
await this.queueManager.appendPending(targetSubscriber, queued);
|
|
467
476
|
}
|
|
468
477
|
}
|
|
469
478
|
|
|
@@ -7,6 +7,7 @@ const AUTO_NICKNAME_PREFIXES = new Set([
|
|
|
7
7
|
"cursor",
|
|
8
8
|
"agy",
|
|
9
9
|
"grok",
|
|
10
|
+
"grok-bot",
|
|
10
11
|
"kimi",
|
|
11
12
|
"ucode",
|
|
12
13
|
]);
|
|
@@ -74,11 +75,12 @@ class NicknameManager {
|
|
|
74
75
|
const prefix = resolveAutoNicknamePrefix(agentType);
|
|
75
76
|
|
|
76
77
|
// 找出所有相同前缀的昵称
|
|
78
|
+
const numberPattern = new RegExp(`^${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}-(\\d+)$`);
|
|
77
79
|
const existing = Object.values(subscribers)
|
|
78
80
|
.map((meta) => meta.nickname)
|
|
79
81
|
.filter((nick) => nick && nick.startsWith(`${prefix}-`))
|
|
80
82
|
.map((nick) => {
|
|
81
|
-
const match = nick.match(
|
|
83
|
+
const match = String(nick).match(numberPattern);
|
|
82
84
|
return match ? parseInt(match[1], 10) : 0;
|
|
83
85
|
})
|
|
84
86
|
.filter((n) => !isNaN(n));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const { getTimestamp, isAgentPidAlive, isMetaActive, isValidTty, getTtyProcessInfo, normalizeAgentTypeAlias } = require("./utils");
|
|
4
|
+
const { isWakeMeta, removeWakeEndpoint, writeWakeEndpoint } = require("./wakeEndpoint");
|
|
4
5
|
const NicknameManager = require("./nickname");
|
|
5
6
|
const { isMismatchedAutoNickname } = require("./nickname");
|
|
6
7
|
const { spawnSync } = require("child_process");
|
|
@@ -280,9 +281,10 @@ class SubscriberManager {
|
|
|
280
281
|
: (existingMeta?.scoped_nickname || finalNickname);
|
|
281
282
|
}
|
|
282
283
|
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
const wakeJoin = options.wake && typeof options.wake === "object";
|
|
285
|
+
const explicitLaunchMode = wakeJoin
|
|
286
|
+
? "wake"
|
|
287
|
+
: (typeof options.launchMode === "string" ? options.launchMode.trim() : "");
|
|
286
288
|
const envLaunchMode = typeof process.env.UFOO_LAUNCH_MODE === "string"
|
|
287
289
|
? process.env.UFOO_LAUNCH_MODE.trim()
|
|
288
290
|
: "";
|
|
@@ -296,18 +298,18 @@ class SubscriberManager {
|
|
|
296
298
|
const overrideTty = (typeof options.tty === "string" && isValidTty(options.tty.trim()))
|
|
297
299
|
? options.tty.trim()
|
|
298
300
|
: "";
|
|
299
|
-
const detectedTty = hasOverrideTty ? overrideTty : getTtyPath();
|
|
301
|
+
const detectedTty = wakeJoin ? "" : (hasOverrideTty ? overrideTty : getTtyPath());
|
|
300
302
|
const tty = overrideTty || (isValidTty(detectedTty) ? detectedTty : "");
|
|
301
303
|
const preservedTty = !tty && launchMode !== "internal" && isValidTty(existingMeta?.tty)
|
|
302
304
|
? existingMeta.tty
|
|
303
305
|
: "";
|
|
304
|
-
const finalTty = tty || preservedTty;
|
|
306
|
+
const finalTty = wakeJoin ? "" : (tty || preservedTty);
|
|
305
307
|
const ttyInfo = finalTty ? getTtyProcessInfo(finalTty) : null;
|
|
306
308
|
|
|
307
309
|
// 清理同一 tty 的旧订阅者(避免重复启动污染)
|
|
308
310
|
// Inherit nickname from displaced entry when this is a new subscriber
|
|
309
311
|
// with no explicit nickname (e.g. session restart on same TTY)
|
|
310
|
-
const inheritedNickname = await this.cleanupDuplicateTty(subscriber, finalTty, { agentType });
|
|
312
|
+
const inheritedNickname = wakeJoin ? null : await this.cleanupDuplicateTty(subscriber, finalTty, { agentType });
|
|
311
313
|
if (inheritedNickname && !nickname && !existingMeta) {
|
|
312
314
|
finalNickname = inheritedNickname;
|
|
313
315
|
if (!finalScopedNickname) finalScopedNickname = inheritedNickname;
|
|
@@ -320,7 +322,7 @@ class SubscriberManager {
|
|
|
320
322
|
const explicitTmuxPane = typeof options.tmuxPane === "string" ? options.tmuxPane.trim() : "";
|
|
321
323
|
const envTmuxPane = typeof process.env.TMUX_PANE === "string" ? process.env.TMUX_PANE.trim() : "";
|
|
322
324
|
const preservedTmuxPane = typeof existingMeta?.tmux_pane === "string" ? existingMeta.tmux_pane.trim() : "";
|
|
323
|
-
const tmuxPane = explicitTmuxPane || envTmuxPane || preservedTmuxPane;
|
|
325
|
+
const tmuxPane = wakeJoin ? "" : (explicitTmuxPane || envTmuxPane || preservedTmuxPane);
|
|
324
326
|
|
|
325
327
|
const hostInjectSock = typeof options.hostInjectSock === "string"
|
|
326
328
|
? options.hostInjectSock.trim()
|
|
@@ -348,12 +350,23 @@ class SubscriberManager {
|
|
|
348
350
|
activity_since: getTimestamp(),
|
|
349
351
|
joined_at: existingMeta?.joined_at || getTimestamp(),
|
|
350
352
|
last_seen: getTimestamp(),
|
|
351
|
-
pid: overridePid || getJoinedPid(),
|
|
352
|
-
tty: finalTty,
|
|
353
|
+
pid: wakeJoin ? 0 : (overridePid || getJoinedPid()),
|
|
354
|
+
tty: wakeJoin ? "" : finalTty,
|
|
353
355
|
tty_shell_pid: ttyInfo?.shellPid || 0,
|
|
354
356
|
tmux_pane: tmuxPane,
|
|
355
357
|
launch_mode: launchMode,
|
|
358
|
+
...(wakeJoin ? { activity_state: "idle" } : {}),
|
|
356
359
|
};
|
|
360
|
+
if (wakeJoin) {
|
|
361
|
+
try {
|
|
362
|
+
const saved = writeWakeEndpoint(options.projectRoot, subscriber, options.wake);
|
|
363
|
+
this.busData.agents[subscriber].wake_adapter = saved.adapter;
|
|
364
|
+
} catch (error) {
|
|
365
|
+
if (existingMeta) this.busData.agents[subscriber] = existingMeta;
|
|
366
|
+
else delete this.busData.agents[subscriber];
|
|
367
|
+
throw error;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
357
370
|
|
|
358
371
|
if (hostInjectSock) {
|
|
359
372
|
this.busData.agents[subscriber].host_inject_sock = hostInjectSock;
|
|
@@ -412,7 +425,7 @@ class SubscriberManager {
|
|
|
412
425
|
/**
|
|
413
426
|
* 离开总线
|
|
414
427
|
*/
|
|
415
|
-
async leave(subscriber) {
|
|
428
|
+
async leave(subscriber, options = {}) {
|
|
416
429
|
if (!this.busData.agents || !this.busData.agents[subscriber]) {
|
|
417
430
|
return false;
|
|
418
431
|
}
|
|
@@ -420,6 +433,7 @@ class SubscriberManager {
|
|
|
420
433
|
this.busData.agents[subscriber].status = "inactive";
|
|
421
434
|
this.busData.agents[subscriber].activity_state = "";
|
|
422
435
|
this.busData.agents[subscriber].last_seen = getTimestamp();
|
|
436
|
+
if (options.projectRoot) removeWakeEndpoint(options.projectRoot, subscriber);
|
|
423
437
|
this.cleanupSubscriberArtifacts(subscriber);
|
|
424
438
|
|
|
425
439
|
return true;
|
|
@@ -485,6 +499,7 @@ class SubscriberManager {
|
|
|
485
499
|
if (!this.busData.agents) return;
|
|
486
500
|
|
|
487
501
|
for (const [id, meta] of Object.entries(this.busData.agents)) {
|
|
502
|
+
if (isWakeMeta(meta)) continue;
|
|
488
503
|
if (isManagedMcpRegistration(meta)) {
|
|
489
504
|
const expiresAtMs = Date.parse(String(meta.mcp_lease_expires_at || ""));
|
|
490
505
|
const expired = !Number.isFinite(expiresAtMs) || expiresAtMs <= Date.now();
|