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
|
@@ -65,6 +65,26 @@ class RepoDoctor {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
reportBrowser() {
|
|
69
|
+
try {
|
|
70
|
+
const { computeBrowserSetupStatus } = require("../../../runtime/browser/installState");
|
|
71
|
+
const { checkNativeHostHealth } = require("../../../runtime/browser/nativeHost");
|
|
72
|
+
const status = computeBrowserSetupStatus();
|
|
73
|
+
console.log("Browser:");
|
|
74
|
+
console.log(`- state: ${status.state} (setupChoice=${status.setupChoice}, enabled=${status.enabled ? "yes" : "no"}, backend=${status.backend})`);
|
|
75
|
+
if (status.runtimeInstalled) {
|
|
76
|
+
const hostHealth = checkNativeHostHealth();
|
|
77
|
+
console.log(`- runtime: ${status.runtimeVersion} (${status.activeEntryPath})`);
|
|
78
|
+
console.log(`- native-host: ${hostHealth.ok ? "ok" : hostHealth.issues.join(", ")}`);
|
|
79
|
+
if (!hostHealth.ok) console.log("- fix: run `ufoo browser doctor`");
|
|
80
|
+
} else {
|
|
81
|
+
console.log("- note: optional component; run `ufoo setup` or `ufoo browser install` if needed.");
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
console.log(`Browser: unavailable (${err && err.message ? err.message : err})`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
68
88
|
run() {
|
|
69
89
|
const skillsDir = path.join(this.repoRoot, "SKILLS");
|
|
70
90
|
const contextSkill = path.join(skillsDir, "ufoo-context", "SKILL.md");
|
|
@@ -85,6 +105,7 @@ class RepoDoctor {
|
|
|
85
105
|
this.reportTui();
|
|
86
106
|
this.reportMcp();
|
|
87
107
|
this.reportNative();
|
|
108
|
+
this.reportBrowser();
|
|
88
109
|
|
|
89
110
|
if (this.failed) {
|
|
90
111
|
console.log("Status: FAILED");
|
|
@@ -50,7 +50,7 @@ function runMetricsCommand(taskId, options = {}) {
|
|
|
50
50
|
console.log(`Execution: ${summary.outcomes.completed} completed, ${summary.outcomes.failed} failed, ${summary.outcomes.cancelled} cancelled; completed/finished ${percentage(summary.completedOfFinished)}`);
|
|
51
51
|
console.log(`Latency: p50 ${duration(summary.latency.elapsedMs.p50)}, p95 ${duration(summary.latency.elapsedMs.p95)}; first text p50 ${duration(summary.latency.firstTextMs.p50)} (${summary.latency.firstTextMs.samples} samples)`);
|
|
52
52
|
console.log(`Models: ${summary.counts.modelCalls || 0} API attempts, ${summary.counts.sdkTurns || 0} SDK turns, ${summary.counts.modelFailures || 0} failures, ${summary.counts.modelRetries || 0} retries`);
|
|
53
|
-
console.log(`Usage: input ${display(summary.usage.input.sum)}, output ${display(summary.usage.output.sum)};
|
|
53
|
+
console.log(`Usage: input ${display(summary.usage.input.sum)}, output ${display(summary.usage.output.sum)}; context selections ${summary.counts.contextSelections || 0}, window projections ${summary.counts.windowProjections || 0}`);
|
|
54
54
|
console.log(`Cache: ${percentage(summary.cache.hitRate)} hit; read ${display(summary.cache.cachedTokens)}/${display(summary.cache.promptTokens)} prompt tokens, written ${display(summary.usage.cacheCreation.sum)} (${summary.cache.samples}/${summary.cache.usageSamples} usage samples)`);
|
|
55
55
|
console.log(`Tools: ${summary.counts.toolCalls || 0} executed, ${summary.counts.toolErrors || 0} errors, ${summary.counts.toolRejections || 0} rejected, ${summary.counts.repeatedToolCalls || 0} repeated arguments`);
|
|
56
56
|
console.log(`Delegation: ${report.delegations.accepted} accepted, ${report.delegations.rejected} rejected, ${report.delegations.awaitingAcceptance} awaiting acceptance`);
|
package/src/app/cli/run.js
CHANGED
|
@@ -1702,7 +1702,7 @@ async function runCli(argv) {
|
|
|
1702
1702
|
}
|
|
1703
1703
|
});
|
|
1704
1704
|
|
|
1705
|
-
program.command("trace").description("Inspect agent task, tool, report, queue and
|
|
1705
|
+
program.command("trace").description("Inspect agent task, tool, report, queue and context events")
|
|
1706
1706
|
.argument("[task-id]", "Delegated task ID or parent taskRunId")
|
|
1707
1707
|
.option("--task <id>", "Filter task")
|
|
1708
1708
|
.option("--agent <id>", "Filter subscriber ID or nickname")
|
|
@@ -1731,6 +1731,39 @@ async function runCli(argv) {
|
|
|
1731
1731
|
.option("--json", "Export a performance report")
|
|
1732
1732
|
.action((taskId, opts) => require("./metricsCommands").runMetricsCommand(taskId, opts));
|
|
1733
1733
|
|
|
1734
|
+
program
|
|
1735
|
+
.command("setup")
|
|
1736
|
+
.description("Interactive installation wizard for optional ufoo components (including ufoo Browser)")
|
|
1737
|
+
.option("--browser <choice>", "Explicitly choose browser setup (install|skip)")
|
|
1738
|
+
.option("--dev", "Register developer unpacked extension mode")
|
|
1739
|
+
.option("--source <path>", "Local component source directory")
|
|
1740
|
+
.option("--tarball <path>", "Component tarball path or URL")
|
|
1741
|
+
.option("--sha256 <digest>", "Expected sha256 digest for component tarball")
|
|
1742
|
+
.option("--no-open", "Do not open Chrome Web Store automatically")
|
|
1743
|
+
.option("-y, --yes", "Non-interactive defaults (does not auto-enable browser)")
|
|
1744
|
+
.option("--json", "Output JSON")
|
|
1745
|
+
.action(async (opts) => {
|
|
1746
|
+
const res = await require("./setupCommands").runSetupCommand(opts);
|
|
1747
|
+
if (res && res.exitCode) process.exitCode = res.exitCode;
|
|
1748
|
+
});
|
|
1749
|
+
|
|
1750
|
+
program
|
|
1751
|
+
.command("browser")
|
|
1752
|
+
.description("Manage optional ufoo Browser extension and runtime (install|status|doctor|enable|disable|update|uninstall)")
|
|
1753
|
+
.argument("[subcmd]", "Subcommand (install|status|doctor|enable|disable|update|uninstall)", "status")
|
|
1754
|
+
.argument("[subargs...]", "Subcommand arguments")
|
|
1755
|
+
.option("--dev", "Use unpacked developer extension mode")
|
|
1756
|
+
.option("--source <path>", "Local component source directory")
|
|
1757
|
+
.option("--tarball <path>", "Component tarball path or URL")
|
|
1758
|
+
.option("--sha256 <digest>", "Expected sha256 digest for component tarball")
|
|
1759
|
+
.option("--no-open", "Do not open Chrome Web Store automatically")
|
|
1760
|
+
.option("--no-repair", "Do not repair native host paths during doctor")
|
|
1761
|
+
.option("--json", "Output JSON")
|
|
1762
|
+
.action(async (subcmd, subargs, opts) => {
|
|
1763
|
+
const code = await require("./browserCommands").runBrowserCommand(subcmd, subargs, opts);
|
|
1764
|
+
if (code) process.exitCode = code;
|
|
1765
|
+
});
|
|
1766
|
+
|
|
1734
1767
|
const history = program.command("history").description("Agent input history timeline");
|
|
1735
1768
|
history
|
|
1736
1769
|
.command("build")
|
|
@@ -1793,6 +1826,8 @@ async function runCli(argv) {
|
|
|
1793
1826
|
console.log("");
|
|
1794
1827
|
console.log("Usage:");
|
|
1795
1828
|
console.log(" ufoo doctor");
|
|
1829
|
+
console.log(" ufoo setup [--browser=install|skip] [--dev] [--json]");
|
|
1830
|
+
console.log(" ufoo browser <install|status|doctor|enable|disable|update|uninstall> [--dev] [--json]");
|
|
1796
1831
|
console.log(" ufoo status");
|
|
1797
1832
|
console.log(" ufoo daemon --start|--stop|--status");
|
|
1798
1833
|
console.log(" ufoo -g");
|
|
@@ -1825,6 +1860,7 @@ async function runCli(argv) {
|
|
|
1825
1860
|
console.log(" ufoo online connect --nickname <name> [--join <ch>] [--room <id> --room-password <pwd>] [...]");
|
|
1826
1861
|
console.log(" ufoo online send --nickname <name> --text <msg> [--channel <ch>] [--room <id>]");
|
|
1827
1862
|
console.log(" ufoo online inbox <nickname> [--clear] [--unread]");
|
|
1863
|
+
console.log(" ufoo bus join <session> <agent-type> [nickname] --wake-url <url> --wake-key-file <path> [--wake-adapter bearer-json]");
|
|
1828
1864
|
console.log(" ufoo bus wake <target> [--reason <reason>] [--no-shake]");
|
|
1829
1865
|
console.log(" ufoo bus poll [subscriber] [--ack | --follow --interval <seconds>]");
|
|
1830
1866
|
console.log(" ufoo bus ack <subscriber> [--through <seq>]");
|
|
@@ -2586,6 +2622,50 @@ async function runCli(argv) {
|
|
|
2586
2622
|
return;
|
|
2587
2623
|
}
|
|
2588
2624
|
|
|
2625
|
+
if (cmd === "setup") {
|
|
2626
|
+
const readFlagValue = (flag) => {
|
|
2627
|
+
const prefix = `${flag}=`;
|
|
2628
|
+
const inline = rest.find((arg) => arg.startsWith(prefix));
|
|
2629
|
+
if (inline) return inline.slice(prefix.length);
|
|
2630
|
+
const idx = rest.indexOf(flag);
|
|
2631
|
+
return idx !== -1 && rest[idx + 1] && !rest[idx + 1].startsWith("-") ? rest[idx + 1] : "";
|
|
2632
|
+
};
|
|
2633
|
+
const res = await require("./setupCommands").runSetupCommand({
|
|
2634
|
+
browser: readFlagValue("--browser"),
|
|
2635
|
+
dev: rest.includes("--dev"),
|
|
2636
|
+
source: readFlagValue("--source"),
|
|
2637
|
+
tarball: readFlagValue("--tarball"),
|
|
2638
|
+
sha256: readFlagValue("--sha256"),
|
|
2639
|
+
noOpen: rest.includes("--no-open"),
|
|
2640
|
+
yes: rest.includes("--yes") || rest.includes("-y"),
|
|
2641
|
+
json: rest.includes("--json"),
|
|
2642
|
+
});
|
|
2643
|
+
if (res && res.exitCode) process.exitCode = res.exitCode;
|
|
2644
|
+
return;
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
if (cmd === "browser") {
|
|
2648
|
+
const sub = rest[0] || "status";
|
|
2649
|
+
const readFlagValue = (flag) => {
|
|
2650
|
+
const prefix = `${flag}=`;
|
|
2651
|
+
const inline = rest.find((arg) => arg.startsWith(prefix));
|
|
2652
|
+
if (inline) return inline.slice(prefix.length);
|
|
2653
|
+
const idx = rest.indexOf(flag);
|
|
2654
|
+
return idx !== -1 && rest[idx + 1] && !rest[idx + 1].startsWith("-") ? rest[idx + 1] : "";
|
|
2655
|
+
};
|
|
2656
|
+
const code = await require("./browserCommands").runBrowserCommand(sub, rest.slice(1), {
|
|
2657
|
+
dev: rest.includes("--dev"),
|
|
2658
|
+
source: readFlagValue("--source"),
|
|
2659
|
+
tarball: readFlagValue("--tarball"),
|
|
2660
|
+
sha256: readFlagValue("--sha256"),
|
|
2661
|
+
noOpen: rest.includes("--no-open"),
|
|
2662
|
+
noRepair: rest.includes("--no-repair"),
|
|
2663
|
+
json: rest.includes("--json"),
|
|
2664
|
+
});
|
|
2665
|
+
if (code) process.exitCode = code;
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2589
2669
|
help();
|
|
2590
2670
|
process.exitCode = 1;
|
|
2591
2671
|
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const readline = require("readline");
|
|
6
|
+
const lockfile = require("proper-lockfile");
|
|
7
|
+
const { loadGlobalBrowserConfig, saveGlobalBrowserConfig } = require("../../config");
|
|
8
|
+
const { setupLockPath } = require("../../runtime/browser/paths");
|
|
9
|
+
const {
|
|
10
|
+
runBrowserInstall,
|
|
11
|
+
formatStatusLines,
|
|
12
|
+
} = require("./browserCommands");
|
|
13
|
+
|
|
14
|
+
const FIRST_RUN_SKIP_COMMANDS = new Set([
|
|
15
|
+
"setup",
|
|
16
|
+
"browser",
|
|
17
|
+
"daemon",
|
|
18
|
+
"mcp",
|
|
19
|
+
"agent-runner",
|
|
20
|
+
"doctor",
|
|
21
|
+
"status",
|
|
22
|
+
"project",
|
|
23
|
+
"init",
|
|
24
|
+
"skills",
|
|
25
|
+
"group",
|
|
26
|
+
"solo",
|
|
27
|
+
"online",
|
|
28
|
+
"bus",
|
|
29
|
+
"ctx",
|
|
30
|
+
"history",
|
|
31
|
+
"trace",
|
|
32
|
+
"metrics",
|
|
33
|
+
"report",
|
|
34
|
+
"recover",
|
|
35
|
+
"ucode",
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
function renderChoicePromptLines() {
|
|
39
|
+
return [
|
|
40
|
+
"",
|
|
41
|
+
"选择可选组件",
|
|
42
|
+
"",
|
|
43
|
+
"[ ] ufoo Browser",
|
|
44
|
+
" 让 ufoo / ucode 操作日常 Chrome 中已登录的网页。",
|
|
45
|
+
" 启用后自动连接本机 ufoo,无需填写 key 或逐次确认连接。",
|
|
46
|
+
"",
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function askYesNo(promptText, { stdin = process.stdin, stdout = process.stdout } = {}) {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
const rl = readline.createInterface({ input: stdin, output: stdout, terminal: Boolean(stdout?.isTTY) });
|
|
53
|
+
rl.question(promptText, (answer) => {
|
|
54
|
+
rl.close();
|
|
55
|
+
const norm = String(answer || "").trim().toLowerCase();
|
|
56
|
+
resolve(norm === "y" || norm === "yes" || norm === "install" || norm === "1");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function parseBrowserFlag(value = "") {
|
|
62
|
+
const raw = String(value || "").trim().toLowerCase();
|
|
63
|
+
if (!raw) return "";
|
|
64
|
+
if (raw === "install" || raw === "enable" || raw === "yes") return "install";
|
|
65
|
+
if (raw === "skip" || raw === "no" || raw === "disable") return "skip";
|
|
66
|
+
throw new Error(`Invalid --browser value "${value}". Expected "install" or "skip".`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function runSetupCommand(opts = {}, {
|
|
70
|
+
env = process.env,
|
|
71
|
+
stdin = process.stdin,
|
|
72
|
+
stdout = process.stdout,
|
|
73
|
+
write = (line) => console.log(line),
|
|
74
|
+
writeError = (line) => console.error(line),
|
|
75
|
+
promptYesNo = askYesNo,
|
|
76
|
+
installImpl = runBrowserInstall,
|
|
77
|
+
} = {}) {
|
|
78
|
+
const outputJson = opts.json === true;
|
|
79
|
+
let choice = "";
|
|
80
|
+
try {
|
|
81
|
+
choice = parseBrowserFlag(opts.browser || "");
|
|
82
|
+
} catch (err) {
|
|
83
|
+
const msg = err.message || String(err);
|
|
84
|
+
if (outputJson) write(JSON.stringify({ ok: false, error: msg }, null, 2));
|
|
85
|
+
else writeError(msg);
|
|
86
|
+
return { ok: false, exitCode: 1, error: msg };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const interactive = Boolean(stdin?.isTTY && stdout?.isTTY && !env.CI && !outputJson);
|
|
90
|
+
if (!choice) {
|
|
91
|
+
if (!interactive) {
|
|
92
|
+
// Non-interactive setup (including --yes) defaults to skipping browser install.
|
|
93
|
+
choice = "skip";
|
|
94
|
+
} else {
|
|
95
|
+
for (const line of renderChoicePromptLines()) write(line);
|
|
96
|
+
const accepted = await promptYesNo("是否安装并启用 ufoo Browser?[y/N]: ", { stdin, stdout });
|
|
97
|
+
choice = accepted ? "install" : "skip";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (choice === "skip") {
|
|
102
|
+
const config = saveGlobalBrowserConfig({
|
|
103
|
+
setupChoice: "skip",
|
|
104
|
+
enabled: false,
|
|
105
|
+
});
|
|
106
|
+
const payload = { ok: true, choice: "skip", state: "not_installed", config };
|
|
107
|
+
if (outputJson) write(JSON.stringify(payload, null, 2));
|
|
108
|
+
else write("已跳过 ufoo Browser,完成 ufoo 基础配置。稍后可随时运行 `ufoo browser install`。");
|
|
109
|
+
return { ...payload, exitCode: 0 };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const installRes = await installImpl({
|
|
113
|
+
dev: opts.dev === true,
|
|
114
|
+
sourceDir: opts.source || "",
|
|
115
|
+
tarball: opts.tarball || "",
|
|
116
|
+
sha256: opts.sha256 || "",
|
|
117
|
+
openStore: opts.noOpen !== true && interactive,
|
|
118
|
+
env,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
if (outputJson) {
|
|
122
|
+
write(JSON.stringify({ choice: "install", ...installRes }, null, 2));
|
|
123
|
+
} else if (!installRes.ok) {
|
|
124
|
+
writeError(installRes.error || "ufoo Browser setup failed");
|
|
125
|
+
} else {
|
|
126
|
+
for (const line of formatStatusLines(installRes.status)) write(line);
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
choice: "install",
|
|
130
|
+
...installRes,
|
|
131
|
+
exitCode: installRes.ok ? 0 : 1,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function shouldOfferFirstRunSetup({ surface = "ufoo", argv = [], env = process.env, stdin = process.stdin, stdout = process.stdout } = {}) {
|
|
136
|
+
if (env.UFOO_SKIP_FIRST_RUN_SETUP === "1") return false;
|
|
137
|
+
if (env.CI) return false;
|
|
138
|
+
if (!stdin?.isTTY || !stdout?.isTTY) return false;
|
|
139
|
+
if (env.UFOO_DAEMON_CHILD === "1" || env.UFOO_INTERNAL_AGENT === "1" || env.UFOO_BROWSER_BROKER_CHILD === "1") return false;
|
|
140
|
+
if (env.UFOO_SUBSCRIBER_ID) return false;
|
|
141
|
+
|
|
142
|
+
const args = Array.isArray(argv) ? argv.map((v) => String(v || "").trim()) : [];
|
|
143
|
+
if (args.some((arg) => ["--help", "-h", "--version", "-V", "--json", "-p", "--print"].includes(arg))) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (surface === "ufoo") {
|
|
147
|
+
const nonFlag = args.find((arg) => arg && !arg.startsWith("-"));
|
|
148
|
+
if (nonFlag && FIRST_RUN_SKIP_COMMANDS.has(nonFlag) && nonFlag !== "chat") return false;
|
|
149
|
+
}
|
|
150
|
+
const cfg = loadGlobalBrowserConfig();
|
|
151
|
+
return cfg.setupChoice === "unset";
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* On the very first interactive launch of `ufoo` or `ucode`, ask once whether to install ufoo Browser.
|
|
156
|
+
* Protected by a user-level setup lock so concurrent first launches only prompt once.
|
|
157
|
+
*/
|
|
158
|
+
async function maybeRunFirstTimeSetup(options = {}) {
|
|
159
|
+
if (!shouldOfferFirstRunSetup(options)) return { prompted: false };
|
|
160
|
+
const env = options.env || process.env;
|
|
161
|
+
const lockFile = setupLockPath(env);
|
|
162
|
+
fs.mkdirSync(path.dirname(lockFile), { recursive: true, mode: 0o700 });
|
|
163
|
+
let release;
|
|
164
|
+
try {
|
|
165
|
+
release = await lockfile.lock(lockFile, {
|
|
166
|
+
realpath: false,
|
|
167
|
+
stale: 300000,
|
|
168
|
+
update: 10000,
|
|
169
|
+
retries: { retries: 3, minTimeout: 100, maxTimeout: 300 },
|
|
170
|
+
});
|
|
171
|
+
} catch (error) {
|
|
172
|
+
if (error && error.code === "ELOCKED") return { prompted: false, locked: true };
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
if (loadGlobalBrowserConfig().setupChoice !== "unset") {
|
|
177
|
+
return { prompted: false };
|
|
178
|
+
}
|
|
179
|
+
const result = await runSetupCommand({}, {
|
|
180
|
+
env,
|
|
181
|
+
stdin: options.stdin || process.stdin,
|
|
182
|
+
stdout: options.stdout || process.stdout,
|
|
183
|
+
write: options.write,
|
|
184
|
+
writeError: options.writeError,
|
|
185
|
+
promptYesNo: options.promptYesNo,
|
|
186
|
+
installImpl: options.installImpl,
|
|
187
|
+
});
|
|
188
|
+
return { prompted: true, result };
|
|
189
|
+
} finally {
|
|
190
|
+
await release().catch(() => {});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
module.exports = {
|
|
195
|
+
renderChoicePromptLines,
|
|
196
|
+
parseBrowserFlag,
|
|
197
|
+
runSetupCommand,
|
|
198
|
+
shouldOfferFirstRunSetup,
|
|
199
|
+
maybeRunFirstTimeSetup,
|
|
200
|
+
};
|
|
@@ -140,7 +140,7 @@ function createUcodeController({
|
|
|
140
140
|
if (activeTask) {
|
|
141
141
|
activeTask.cancelRequested = true;
|
|
142
142
|
try {
|
|
143
|
-
activeTask.controller.abort();
|
|
143
|
+
activeTask.controller.abort("runtime_closed");
|
|
144
144
|
} catch {
|
|
145
145
|
// ignore
|
|
146
146
|
}
|
|
@@ -223,6 +223,7 @@ function createUcodeController({
|
|
|
223
223
|
id,
|
|
224
224
|
kind: String(taskMeta.kind || "task").trim() || "task",
|
|
225
225
|
label: taskLabel(taskMeta, id),
|
|
226
|
+
promptText: String(taskMeta.promptText || ""),
|
|
226
227
|
enqueuedAt: Date.now(),
|
|
227
228
|
startedAt: 0,
|
|
228
229
|
status: "queued",
|
|
@@ -243,6 +244,34 @@ function createUcodeController({
|
|
|
243
244
|
return promise;
|
|
244
245
|
}
|
|
245
246
|
|
|
247
|
+
function drainQueuedPrompts() {
|
|
248
|
+
if (pendingTasks.length === 0) return [];
|
|
249
|
+
const drained = [];
|
|
250
|
+
const remaining = [];
|
|
251
|
+
for (const task of pendingTasks) {
|
|
252
|
+
if (task.kind === "prompt" && (task.promptText || task.label)) {
|
|
253
|
+
task.status = "injected";
|
|
254
|
+
if (!task.settled) {
|
|
255
|
+
task.settled = true;
|
|
256
|
+
task.resolve({ ok: true, injected: true });
|
|
257
|
+
}
|
|
258
|
+
drained.push({
|
|
259
|
+
id: task.id,
|
|
260
|
+
label: task.label,
|
|
261
|
+
text: String(task.promptText || task.label || ""),
|
|
262
|
+
});
|
|
263
|
+
} else {
|
|
264
|
+
remaining.push(task);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
pendingTasks.length = 0;
|
|
268
|
+
pendingTasks.push(...remaining);
|
|
269
|
+
if (drained.length > 0) {
|
|
270
|
+
notifyQueueChange("injected");
|
|
271
|
+
}
|
|
272
|
+
return drained;
|
|
273
|
+
}
|
|
274
|
+
|
|
246
275
|
return {
|
|
247
276
|
projectRoot,
|
|
248
277
|
view,
|
|
@@ -255,6 +284,7 @@ function createUcodeController({
|
|
|
255
284
|
cancelTask,
|
|
256
285
|
runExclusive,
|
|
257
286
|
clearQueue: () => clearPending("cleared"),
|
|
287
|
+
drainQueuedPrompts,
|
|
258
288
|
pauseQueue,
|
|
259
289
|
resumeQueue,
|
|
260
290
|
getQueueSnapshot: () => queueSnapshot("snapshot"),
|
package/src/code/agent.js
CHANGED
|
@@ -6,6 +6,7 @@ const { runNativeAgentTask } = require("./nativeRunner");
|
|
|
6
6
|
const { resolveTaskTimeoutMs: resolveNlTaskTimeoutMs, DEFAULT_TASK_TIMEOUT_MS: DEFAULT_NL_TASK_TIMEOUT_MS } = require("../agents/runtime/core/executionBudget");
|
|
7
7
|
const { runDecomposedTask } = require("./taskDecomposer");
|
|
8
8
|
const { loadConfig, defaultAgentModelForProvider, sameModelProvider } = require("../config");
|
|
9
|
+
const { resolveRuntimeConfig } = require("../agents/providers/runtimeConfig");
|
|
9
10
|
const {
|
|
10
11
|
resolveSessionId,
|
|
11
12
|
normalizeSessionId,
|
|
@@ -82,8 +83,7 @@ function ensureContextSessionState(state = {}) {
|
|
|
82
83
|
}
|
|
83
84
|
require("./context/planProjection").ensurePlanUiState(state.executionState);
|
|
84
85
|
if (!state.contextPolicy || typeof state.contextPolicy !== "object") {
|
|
85
|
-
|
|
86
|
-
state.contextPolicy = defaultContextPolicy();
|
|
86
|
+
state.contextPolicy = {};
|
|
87
87
|
}
|
|
88
88
|
if (!Number.isFinite(state.toolCallsSinceCommit)) state.toolCallsSinceCommit = 0;
|
|
89
89
|
ensureStateEpoch(state);
|
|
@@ -257,6 +257,10 @@ function resolveUcodeProviderModel({
|
|
|
257
257
|
|| ""
|
|
258
258
|
).trim();
|
|
259
259
|
const resolvedProvider = resolvePlannerProvider(explicitProvider || fallbackProviderFromAgent);
|
|
260
|
+
if (resolvedProvider === "agy") {
|
|
261
|
+
const runtime = resolveRuntimeConfig({ workspaceRoot: root, provider: resolvedProvider, model });
|
|
262
|
+
return { provider: runtime.provider, model: runtime.model };
|
|
263
|
+
}
|
|
260
264
|
const configuredModel = sameModelProvider(config.ucodeProvider || config.agentProvider, resolvedProvider)
|
|
261
265
|
? (config.ucodeModel || config.agentModel)
|
|
262
266
|
: "";
|
|
@@ -283,6 +287,7 @@ function resolvePlannerProvider(value = "") {
|
|
|
283
287
|
if (!text) return "";
|
|
284
288
|
if (text === "claude" || text === "claude-cli" || text === "claude-code" || text === "anthropic") return "anthropic";
|
|
285
289
|
if (text === "codex" || text === "codex-cli" || text === "codex-code") return "codex";
|
|
290
|
+
if (text === "agy" || text === "agy-cli" || text === "antigravity") return "agy";
|
|
286
291
|
if (text === "grok" || text === "grok-cli" || text === "grok-build" || text === "grok-shell" || text === "grok-api") return "grok-build";
|
|
287
292
|
if (text === "xai") return "xai";
|
|
288
293
|
if (text === "openai") return "openai";
|
|
@@ -374,7 +379,7 @@ function normalizeToolLogEvent(event = {}) {
|
|
|
374
379
|
if (!event || typeof event !== "object") return null;
|
|
375
380
|
const tool = String(event.tool || event.name || "").trim().toLowerCase();
|
|
376
381
|
if (!tool) return null;
|
|
377
|
-
if (tool !== "read" && tool !== "write" && tool !== "edit" && tool !== "bash" && tool !== "artifact_read") return null;
|
|
382
|
+
if (tool !== "read" && tool !== "write" && tool !== "edit" && tool !== "bash" && tool !== "artifact_read" && tool !== "recall_turn") return null;
|
|
378
383
|
const phase = String(event.phase || "update").trim().toLowerCase();
|
|
379
384
|
const normalizedPhase = phase === "error" ? "error" : (phase === "start" ? "start" : "");
|
|
380
385
|
if (!normalizedPhase) return null;
|
|
@@ -486,6 +491,18 @@ function buildNlFallbackSummary(logs = []) {
|
|
|
486
491
|
return "Done (no model text response).";
|
|
487
492
|
}
|
|
488
493
|
|
|
494
|
+
function commitConversationOutput(state, workspaceRoot, turnId, update = {}) {
|
|
495
|
+
const items = Array.isArray(update.turnItems) ? update.turnItems : [];
|
|
496
|
+
const appended = appendTurnMessages(workspaceRoot, state.sessionId, turnId, items, { scope: "output" });
|
|
497
|
+
if (!appended.ok) throw Object.assign(new Error(`failed to persist conversation output: ${appended.error}`), { code: "conversation_persistence_failed" });
|
|
498
|
+
if (update.executionState) state.executionState = update.executionState;
|
|
499
|
+
const transcript = loadTranscript(workspaceRoot, state.sessionId);
|
|
500
|
+
state.transcriptEvents = transcript.events;
|
|
501
|
+
state.nlMessages = stripSkillBlocksFromMessages(transcriptEventsToMessages(transcript.events, { preferArtifact: true }));
|
|
502
|
+
const saved = persistSessionState(state);
|
|
503
|
+
if (saved?.ok === false) throw Object.assign(new Error(`failed to persist session progress: ${saved.error}`), { code: "conversation_persistence_failed" });
|
|
504
|
+
}
|
|
505
|
+
|
|
489
506
|
async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
490
507
|
const taskText = String(task || "").trim();
|
|
491
508
|
if (!taskText) {
|
|
@@ -553,7 +570,7 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
553
570
|
}
|
|
554
571
|
|
|
555
572
|
ensureTaskContract(state, taskText);
|
|
556
|
-
if (!shouldFrameAsUserReminder(state.executionState)) {
|
|
573
|
+
if (options.runtimeContext?.requestKind !== "system_wake" && !shouldFrameAsUserReminder(state.executionState)) {
|
|
557
574
|
state.taskContract = patchTaskContractFromUserMessage(state.taskContract, taskText);
|
|
558
575
|
}
|
|
559
576
|
|
|
@@ -648,6 +665,7 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
648
665
|
toolEventsThisAttempt = 0;
|
|
649
666
|
const historyMessages = assembled.messages;
|
|
650
667
|
return runNativeAgentImpl({
|
|
668
|
+
runtimeHooks: state.runtimeHooks,
|
|
651
669
|
workspaceRoot,
|
|
652
670
|
provider,
|
|
653
671
|
model,
|
|
@@ -663,8 +681,14 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
663
681
|
onPhase,
|
|
664
682
|
onContextUsage: applyContextMeter,
|
|
665
683
|
executionState: state.executionState || null,
|
|
666
|
-
onArtifactPersisted: (persisted) => recordToolCallInSession(
|
|
684
|
+
onArtifactPersisted: (persisted) => recordToolCallInSession(
|
|
685
|
+
state,
|
|
686
|
+
persisted,
|
|
687
|
+
workspaceRoot,
|
|
688
|
+
),
|
|
689
|
+
onConversationUpdate: (update) => commitConversationOutput(state, workspaceRoot, turnId, update),
|
|
667
690
|
contextPolicy: state.contextPolicy || {},
|
|
691
|
+
logicalTurnId: turnId,
|
|
668
692
|
runtimeContext: options.runtimeContext || {},
|
|
669
693
|
onRuntimeEvent: options.onRuntimeEvent,
|
|
670
694
|
onToolEvent: (event) => {
|
|
@@ -708,6 +732,7 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
708
732
|
if (useDecomposition) {
|
|
709
733
|
const decomposedResult = await runDecomposedTask({
|
|
710
734
|
task: effectiveTaskPrompt,
|
|
735
|
+
timeoutMs,
|
|
711
736
|
onProgress: options.onProgress,
|
|
712
737
|
onToolEvent: (event) => {
|
|
713
738
|
pushToolLog(event);
|
|
@@ -724,6 +749,7 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
724
749
|
systemBlocks: assembled.systemBlocks || null,
|
|
725
750
|
runtimeContext: options.runtimeContext || {},
|
|
726
751
|
onRuntimeEvent: options.onRuntimeEvent,
|
|
752
|
+
onConversationUpdate: (update) => commitConversationOutput(state, workspaceRoot, turnId, update),
|
|
727
753
|
onStreamDelta: onStream,
|
|
728
754
|
onThinkingDelta,
|
|
729
755
|
onPhase,
|
|
@@ -751,9 +777,11 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
751
777
|
|
|
752
778
|
if (!cliRes || cliRes.ok === false) {
|
|
753
779
|
const errMsg = String((cliRes && cliRes.error) || "");
|
|
754
|
-
//
|
|
755
|
-
//
|
|
756
|
-
|
|
780
|
+
// Whole-invocation retry is safe only before any execution or output.
|
|
781
|
+
// A committed assistant message must keep its existing journal indices.
|
|
782
|
+
const hasProgress = streamed || cliRes?.streamed || Boolean(String(cliRes?.output || "").trim())
|
|
783
|
+
|| Boolean(cliRes?.turnItems?.length);
|
|
784
|
+
if (isCliTimeoutError(errMsg) && toolEventsThisAttempt === 0 && !hasProgress) {
|
|
757
785
|
const extendedTimeoutMs = computeExtendedTimeout(timeoutMs);
|
|
758
786
|
cliRes = await invokeNative(String(state.sessionId || ""), extendedTimeoutMs);
|
|
759
787
|
}
|
|
@@ -788,6 +816,22 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
788
816
|
transcriptEventsToMessages(transcript.events, { preferArtifact: true }),
|
|
789
817
|
);
|
|
790
818
|
|
|
819
|
+
// The turn coordinator owns session identity. Providers/runners receive it
|
|
820
|
+
// as correlation metadata but cannot redirect durable writes mid-turn.
|
|
821
|
+
if (cliRes && cliRes.executionState && typeof cliRes.executionState === "object") {
|
|
822
|
+
// Preserve planMode if the runner returned a fresh empty state without it.
|
|
823
|
+
const priorPlanMode = Boolean(state.executionState && state.executionState.planMode);
|
|
824
|
+
const priorSource = state.executionState && state.executionState.planModeSource
|
|
825
|
+
? String(state.executionState.planModeSource)
|
|
826
|
+
: "";
|
|
827
|
+
state.executionState = cliRes.executionState;
|
|
828
|
+
if (typeof state.executionState.planMode !== "boolean") {
|
|
829
|
+
state.executionState.planMode = priorPlanMode;
|
|
830
|
+
}
|
|
831
|
+
if (state.executionState.planMode && !state.executionState.planModeSource && priorSource) {
|
|
832
|
+
state.executionState.planModeSource = priorSource;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
791
835
|
if (!cliRes || cliRes.ok === false) {
|
|
792
836
|
const errMsg = String((cliRes && cliRes.error) || "");
|
|
793
837
|
if (isCliCancelledError(errMsg) && state.executionState) {
|
|
@@ -805,22 +849,6 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
805
849
|
streamLastChar,
|
|
806
850
|
};
|
|
807
851
|
}
|
|
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
852
|
const normalized = String(cliRes.output || "").trim();
|
|
825
853
|
const sideEffects = parseStructuredSideEffects(normalized);
|
|
826
854
|
if (sideEffects) {
|
|
@@ -845,6 +873,10 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
845
873
|
applyContextMeter(cliRes.contextMeter);
|
|
846
874
|
}
|
|
847
875
|
if (cliRes && cliRes.waitingUserInteraction) {
|
|
876
|
+
state.pendingLogicalTurnId = turnId;
|
|
877
|
+
state.pendingTurnHistoryOffset = Array.isArray(assembled.messages)
|
|
878
|
+
? assembled.messages.filter((m) => m && m.role !== "system").length
|
|
879
|
+
: 0;
|
|
848
880
|
return {
|
|
849
881
|
ok: true,
|
|
850
882
|
summary: resolvedSummary || "Waiting for your reply",
|
|
@@ -861,6 +893,8 @@ async function runNaturalLanguageTask(task = "", state = {}, options = {}) {
|
|
|
861
893
|
usage: cliRes.usage || null,
|
|
862
894
|
};
|
|
863
895
|
}
|
|
896
|
+
state.pendingLogicalTurnId = "";
|
|
897
|
+
state.pendingTurnHistoryOffset = null;
|
|
864
898
|
return {
|
|
865
899
|
ok: true,
|
|
866
900
|
summary: resolvedSummary,
|
|
@@ -992,6 +1026,10 @@ function buildSessionSnapshotFromState(state = {}) {
|
|
|
992
1026
|
contextPolicy: source.contextPolicy && typeof source.contextPolicy === "object"
|
|
993
1027
|
? source.contextPolicy
|
|
994
1028
|
: null,
|
|
1029
|
+
pendingLogicalTurnId: String(source.pendingLogicalTurnId || "").trim(),
|
|
1030
|
+
pendingTurnHistoryOffset: Number.isInteger(source.pendingTurnHistoryOffset)
|
|
1031
|
+
? source.pendingTurnHistoryOffset
|
|
1032
|
+
: null,
|
|
995
1033
|
toolCallsSinceCommit: Number.isFinite(source.toolCallsSinceCommit)
|
|
996
1034
|
? Math.max(0, Math.floor(source.toolCallsSinceCommit))
|
|
997
1035
|
: 0,
|
|
@@ -1033,7 +1071,7 @@ function persistSessionState(state = {}) {
|
|
|
1033
1071
|
return saved;
|
|
1034
1072
|
}
|
|
1035
1073
|
|
|
1036
|
-
function resumeSessionState(state = {}, sessionId = "", workspaceRoot = process.cwd()) {
|
|
1074
|
+
function resumeSessionState(state = {}, sessionId = "", workspaceRoot = (state && state.workspaceRoot) || process.cwd()) {
|
|
1037
1075
|
const targetId = normalizeSessionId(sessionId);
|
|
1038
1076
|
if (!targetId) {
|
|
1039
1077
|
return {
|
|
@@ -1069,6 +1107,10 @@ function resumeSessionState(state = {}, sessionId = "", workspaceRoot = process.
|
|
|
1069
1107
|
state.workingSet = Array.isArray(snapshot.workingSet) ? snapshot.workingSet : [];
|
|
1070
1108
|
state.executionState = snapshot.executionState || null;
|
|
1071
1109
|
state.contextPolicy = snapshot.contextPolicy || null;
|
|
1110
|
+
state.pendingLogicalTurnId = String(snapshot.pendingLogicalTurnId || "").trim();
|
|
1111
|
+
state.pendingTurnHistoryOffset = Number.isInteger(snapshot.pendingTurnHistoryOffset)
|
|
1112
|
+
? snapshot.pendingTurnHistoryOffset
|
|
1113
|
+
: null;
|
|
1072
1114
|
state.toolCallsSinceCommit = Number.isFinite(snapshot.toolCallsSinceCommit)
|
|
1073
1115
|
? snapshot.toolCallsSinceCommit
|
|
1074
1116
|
: 0;
|
|
@@ -1175,7 +1217,9 @@ async function resumeAfterUserInteraction(answerText = "", state = {}, options =
|
|
|
1175
1217
|
}
|
|
1176
1218
|
: null;
|
|
1177
1219
|
|
|
1220
|
+
const logicalTurnId = String(state.pendingLogicalTurnId || turnId).trim();
|
|
1178
1221
|
const cliRes = await runNativeAgentTask({
|
|
1222
|
+
runtimeHooks: state.runtimeHooks,
|
|
1179
1223
|
workspaceRoot,
|
|
1180
1224
|
provider: state.provider,
|
|
1181
1225
|
model: state.model,
|
|
@@ -1195,8 +1239,11 @@ async function resumeAfterUserInteraction(answerText = "", state = {}, options =
|
|
|
1195
1239
|
maxToolCalls: state.maxToolCalls,
|
|
1196
1240
|
onStreamDelta: trackingOnDelta,
|
|
1197
1241
|
contextPolicy: state.contextPolicy || {},
|
|
1242
|
+
logicalTurnId,
|
|
1243
|
+
historyOffset: Number.isInteger(state.pendingTurnHistoryOffset) ? state.pendingTurnHistoryOffset : null,
|
|
1198
1244
|
runtimeContext: options.runtimeContext || {},
|
|
1199
1245
|
onRuntimeEvent: options.onRuntimeEvent,
|
|
1246
|
+
onConversationUpdate: (update) => commitConversationOutput(state, workspaceRoot, turnId, update),
|
|
1200
1247
|
onThinkingDelta: typeof options.onThinkingDelta === "function" ? options.onThinkingDelta : null,
|
|
1201
1248
|
onPhase: typeof options.onPhase === "function" ? options.onPhase : null,
|
|
1202
1249
|
onContextUsage: (meter) => {
|
|
@@ -1211,6 +1258,10 @@ async function resumeAfterUserInteraction(answerText = "", state = {}, options =
|
|
|
1211
1258
|
resume: true,
|
|
1212
1259
|
});
|
|
1213
1260
|
|
|
1261
|
+
if (cliRes && !cliRes.waitingUserInteraction) {
|
|
1262
|
+
state.pendingLogicalTurnId = "";
|
|
1263
|
+
state.pendingTurnHistoryOffset = null;
|
|
1264
|
+
}
|
|
1214
1265
|
if (cliRes && cliRes.executionState) {
|
|
1215
1266
|
state.executionState = cliRes.executionState;
|
|
1216
1267
|
}
|