u-foo 3.1.7 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/OBSERVABILITY.md +65 -0
- package/README.md +238 -21
- package/README.zh-CN.md +165 -20
- package/SKILLS/ufoo/SKILL.md +40 -4
- package/SKILLS/ufoo-bus/SKILL.md +46 -3
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +6 -4
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/dist/tui/darwin-x64/ufoo-tui +0 -0
- package/dist/tui/linux-arm64/ufoo-tui +0 -0
- package/dist/tui/linux-x64/ufoo-tui +0 -0
- package/package.json +14 -7
- package/scripts/postinstall-skills.js +53 -0
- package/scripts/postinstall.js +11 -16
- package/scripts/smoke-native-messages.js +214 -0
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/activity/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +140 -0
- package/src/agents/capabilities/agentRouting/index.js +4 -0
- package/src/agents/capabilities/coding/index.js +32 -0
- package/src/agents/capabilities/coordination/index.js +37 -0
- package/src/agents/capabilities/globalRouting/index.js +5 -0
- package/src/agents/capabilities/groups/index.js +3 -0
- package/src/agents/capabilities/index.js +25 -0
- package/src/agents/capabilities/planning/index.js +123 -0
- package/src/agents/capabilities/planning/main.js +28 -0
- package/src/agents/capabilities/projectDiscovery/index.js +3 -0
- package/src/agents/capabilities/scheduling/index.js +3 -0
- package/src/agents/capabilities/sharedMemory/index.js +4 -0
- package/src/agents/capabilities/skills/index.js +12 -0
- package/src/agents/capabilities/taskExecution/index.js +3 -0
- package/src/agents/capabilities/taskReports/index.js +6 -0
- package/src/agents/controller/controllerToolExecutor.js +40 -22
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +181 -76
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +96 -14
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +15 -20
- package/src/agents/launch/readyDetector.js +28 -14
- package/src/agents/profiles/coding.js +6 -0
- package/src/agents/profiles/globalRouter.js +2 -0
- package/src/agents/profiles/main.js +5 -0
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +32 -6
- package/src/agents/prompts/mainAgent.js +48 -0
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +14 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +9 -1
- package/src/agents/providers/claudeThreadProvider.js +47 -4
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +68 -7
- package/src/agents/providers/codexThreadProvider.js +18 -8
- package/src/agents/providers/credentials/claude.js +10 -3
- package/src/agents/providers/credentials/index.js +2 -0
- package/src/agents/providers/directAuthStatus.js +1 -1
- package/src/agents/providers/index.js +1 -1
- package/src/agents/providers/modelSettings.js +34 -0
- package/src/agents/providers/modelsCatalog.js +379 -0
- package/src/agents/providers/nativeTransport.js +1146 -0
- package/src/agents/providers/runtimeConfig.js +188 -0
- package/src/agents/providers/thinkingLevels.js +106 -0
- package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
- package/src/agents/providers/transports/index.js +10 -0
- package/src/agents/providers/transports/openaiChatTransport.js +117 -0
- package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
- package/src/agents/providers/transports/responsesProtocol.js +504 -0
- package/src/agents/providers/transports/systemBlocks.js +16 -0
- package/src/agents/providers/transports/transportContract.js +50 -0
- package/src/agents/providers/transports/visionBlocks.js +151 -0
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +127 -0
- package/src/agents/runtime/context/sessionJournal.js +360 -0
- package/src/agents/runtime/context/sessionStore.js +57 -0
- package/src/agents/runtime/core/agentLoop.js +351 -0
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/core/stableJson.js +29 -0
- package/src/agents/runtime/core/toolLoopGuard.js +55 -0
- package/src/agents/runtime/createAgentRuntime.js +259 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/agents/runtime/tasks/resourceLease.js +66 -0
- package/src/agents/runtime/tasks/scheduler.js +73 -0
- package/src/agents/runtime/tools/registry.js +57 -0
- package/src/app/chat/ChatController.js +29 -45
- package/src/app/chat/agentDirectory.js +9 -18
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +111 -313
- package/src/app/chat/commands.js +39 -45
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -48
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +21 -35
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +91 -164
- package/src/app/chat/streamState.js +3 -7
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/busCoreCommands.js +9 -0
- package/src/app/cli/features/doctor.js +33 -0
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/features/skills.js +16 -4
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +82 -42
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +34 -17
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +9 -9
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +107 -0
- package/src/code/launcher/ucode.js +1 -1
- package/src/code/launcher/ucodeBootstrap.js +1 -1
- package/src/code/modelCommand.js +11 -35
- package/src/code/nativeRunner.js +104 -2697
- package/src/code/protocol/faultHarness.js +2 -88
- package/src/code/protocol/materialize.js +2 -105
- package/src/code/protocol/toolCallLedger.js +5 -215
- package/src/code/providers/anthropicMessagesTransport.js +2 -118
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/providers/openaiChatTransport.js +2 -114
- package/src/code/providers/openaiResponsesTransport.js +2 -117
- package/src/code/providers/responsesProtocol.js +2 -497
- package/src/code/providers/transportContract.js +2 -48
- package/src/code/providers/visionBlocks.js +2 -149
- package/src/code/repl.js +2 -11
- package/src/code/sessionStore.js +27 -99
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/thinkingLevels.js +1 -130
- package/src/code/toolBudget.js +1 -17
- package/src/code/toolLoopGuard.js +3 -49
- package/src/code/tools/artifactRead.js +1 -1
- package/src/code/tools/executor.js +373 -0
- package/src/code/tools/specs.js +312 -0
- package/src/config.js +95 -131
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +14 -9
- package/src/coordination/bus/inject.js +15 -7
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +8 -4
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/memory/index.js +5 -21
- package/src/coordination/report/store.js +103 -83
- package/src/coordination/state/agentsStore.js +57 -3
- package/src/coordination/state/fileLock.js +2 -0
- package/src/coordination/state/workspaceAccess.js +36 -0
- package/src/orchestration/controller/index.js +1 -8
- package/src/orchestration/controller/launchRouting.js +1 -1
- package/src/orchestration/solo/commands.js +3 -1
- package/src/runtime/contracts/agentMode.js +26 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +20 -17
- package/src/runtime/daemon/agentHost.js +407 -0
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +28 -18
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +21 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +120 -375
- package/src/runtime/daemon/ipcServer.js +32 -10
- package/src/runtime/daemon/mcpConfigure.js +113 -20
- package/src/runtime/daemon/mcpHttpServer.js +27 -5
- package/src/runtime/daemon/mcpServer.js +8 -5
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +68 -40
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -570
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +9 -6
- package/src/runtime/privacy/redactor.js +2 -2
- package/src/runtime/projects/identity.js +2 -1
- package/src/runtime/projects/registry.js +98 -38
- package/src/tools/controllerSchemas.js +28 -0
- package/src/tools/handlers/dispatchMessage.js +5 -2
- package/src/tools/handlers/listAgents.js +3 -1
- package/src/tools/handlers/readBusSummary.js +3 -1
- package/src/tools/handlers/readProjectRegistry.js +29 -2
- package/src/tools/handlers/routeAgent.js +35 -0
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/index.js +1 -0
- package/src/tools/registry.js +6 -0
- package/src/tools/schemaFixtures.js +42 -5
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/tools/tier1/routeAgent.js +2 -2
- package/src/tools/tier2/runtimeCoordination.js +38 -0
- package/src/tools/types.js +2 -0
- package/src/ui/agentPresentation.js +109 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +270 -0
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +9 -15
- package/src/ui/format/index.js +14 -10
- package/src/ui/format/loopSummary.js +50 -0
- package/src/ui/format/markdownRenderer.js +3 -4
- package/src/ui/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +316 -599
- package/src/ui/rustMultiSession.js +288 -73
- package/src/ui/rustUcodeHost.js +21 -88
- package/src/ui/settingsBridge.js +34 -14
- package/src/ui/toolMergeBridge.js +0 -4
- package/src/ui/uiHostServer.js +5 -8
- package/src/agents/controller/loopObservability.js +0 -200
- package/src/agents/controller/loopRuntime.js +0 -472
- package/src/agents/controller/ufooAgent.js +0 -829
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/upstreamTransport.js +0 -689
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentEnter.js +0 -70
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/multiWindow/index.js +0 -310
- package/src/app/chat/multiWindow/paneLayout.js +0 -84
- package/src/app/chat/multiWindow/renderer.js +0 -420
- package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
- package/src/app/chat/multiWindow/vtFrame.js +0 -93
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- package/src/orchestration/controller/flags.js +0 -167
- package/src/orchestration/controller/gateRouter.js +0 -211
- package/src/orchestration/controller/routerFastPath.js +0 -22
- package/src/orchestration/controller/routerFinalize.js +0 -222
- package/src/orchestration/controller/shadowGuard.js +0 -280
- package/src/runtime/daemon/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
- package/src/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const os = require("os");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
// Protocol baseline verified against CLIProxyAPI v8.0.22's xAI adapter.
|
|
8
|
+
const GROK_CLIENT_VERSION = "1.0.46";
|
|
9
|
+
|
|
10
|
+
function validClientVersion(value) {
|
|
11
|
+
const version = String(value || "").trim();
|
|
12
|
+
return /^\d+\.\d+\.\d+(?:[-+][\w.-]+)?$/.test(version) ? version : "";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function newestVersion(...versions) {
|
|
16
|
+
return versions.filter(Boolean).sort((left, right) => {
|
|
17
|
+
const a = left.match(/\d+/g).slice(0, 3).map(Number);
|
|
18
|
+
const b = right.match(/\d+/g).slice(0, 3).map(Number);
|
|
19
|
+
for (let i = 0; i < 3; i += 1) if (a[i] !== b[i]) return b[i] - a[i];
|
|
20
|
+
return 0;
|
|
21
|
+
})[0] || "";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function installedPackageVersion(packageName, { binary = "", env = process.env } = {}) {
|
|
25
|
+
const candidates = (require.resolve.paths(packageName) || []).map((directory) => path.join(directory, packageName, "package.json"));
|
|
26
|
+
if (binary) {
|
|
27
|
+
for (const directory of String(env.PATH || "").split(path.delimiter).filter(Boolean)) {
|
|
28
|
+
try {
|
|
29
|
+
let parent = path.dirname(fs.realpathSync(path.join(directory, binary)));
|
|
30
|
+
for (let i = 0; i < 4; i += 1) {
|
|
31
|
+
candidates.push(path.join(parent, "package.json"));
|
|
32
|
+
parent = path.dirname(parent);
|
|
33
|
+
}
|
|
34
|
+
} catch { /* CLI installation is optional; never invoke it. */ }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const versions = [];
|
|
38
|
+
for (const candidate of candidates) {
|
|
39
|
+
try {
|
|
40
|
+
const pkg = JSON.parse(fs.readFileSync(candidate, "utf8"));
|
|
41
|
+
const version = validClientVersion(pkg.version);
|
|
42
|
+
if (pkg.name === packageName && version) versions.push(version);
|
|
43
|
+
} catch { /* Try the next installation path. */ }
|
|
44
|
+
}
|
|
45
|
+
return newestVersion(...versions);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function resolveCodexClientVersion({ env = process.env, codexHome = "", clientVersion = "" } = {}) {
|
|
49
|
+
const override = validClientVersion(clientVersion) || validClientVersion(env.UFOO_CODEX_CLIENT_VERSION);
|
|
50
|
+
if (override) return override;
|
|
51
|
+
// Only the version is read from the cache. Models and account access still
|
|
52
|
+
// come from the live provider; credentials are never read or written here.
|
|
53
|
+
let cachedVersion = "";
|
|
54
|
+
try {
|
|
55
|
+
const home = codexHome || env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
56
|
+
cachedVersion = validClientVersion(JSON.parse(fs.readFileSync(path.join(home, "models_cache.json"), "utf8")).client_version);
|
|
57
|
+
} catch { /* Codex need not have populated its cache yet. */ }
|
|
58
|
+
return newestVersion(cachedVersion,
|
|
59
|
+
installedPackageVersion("@openai/codex", { binary: "codex", env }),
|
|
60
|
+
installedPackageVersion("@openai/codex-sdk", { env }));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function resolveCodexUserAgent(options = {}) {
|
|
64
|
+
const env = options.env || process.env;
|
|
65
|
+
if (String(env.UFOO_CODEX_USER_AGENT || "").trim()) return env.UFOO_CODEX_USER_AGENT.trim();
|
|
66
|
+
const version = resolveCodexClientVersion(options) || "dev";
|
|
67
|
+
return `codex-tui/${version} (${os.type()} ${os.release()}; ${process.arch})`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function resolveGrokClientVersion({ env = process.env } = {}) {
|
|
71
|
+
return validClientVersion(env.UFOO_GROK_CLIENT_VERSION)
|
|
72
|
+
|| newestVersion(GROK_CLIENT_VERSION, installedPackageVersion("@xai-official/grok", { binary: "grok", env }));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { resolveCodexClientVersion, resolveCodexUserAgent, resolveGrokClientVersion };
|
|
@@ -10,7 +10,11 @@ function getTextFromItem(item) {
|
|
|
10
10
|
return "";
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function
|
|
13
|
+
function createCodexEventState() {
|
|
14
|
+
return { items: new Map(), finalText: "" };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function normalizeCodexEvent(event = {}, state = createCodexEventState()) {
|
|
14
18
|
const type = String(event.type || "").trim();
|
|
15
19
|
if (!type) return null;
|
|
16
20
|
|
|
@@ -19,6 +23,7 @@ function normalizeCodexEvent(event = {}) {
|
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
if (type === "turn.started") {
|
|
26
|
+
state.finalText = "";
|
|
22
27
|
return { type: "turn_started", turnId: event.turn_id || event.turnId || "" };
|
|
23
28
|
}
|
|
24
29
|
|
|
@@ -27,6 +32,7 @@ function normalizeCodexEvent(event = {}) {
|
|
|
27
32
|
type: "turn_completed",
|
|
28
33
|
turnId: event.turn_id || event.turnId || "",
|
|
29
34
|
usage: event.usage || null,
|
|
35
|
+
finalText: state.finalText,
|
|
30
36
|
};
|
|
31
37
|
}
|
|
32
38
|
|
|
@@ -39,25 +45,79 @@ function normalizeCodexEvent(event = {}) {
|
|
|
39
45
|
};
|
|
40
46
|
}
|
|
41
47
|
|
|
42
|
-
if (type === "
|
|
48
|
+
if (type === "error") return { type: "turn_failed", error: String(event.message || "Codex stream failed") };
|
|
49
|
+
|
|
50
|
+
if (["item.started", "item.updated", "item.completed"].includes(type)) {
|
|
43
51
|
const item = event.item || {};
|
|
44
52
|
const itemType = String(item.type || "").trim();
|
|
45
53
|
const text = getTextFromItem(item);
|
|
54
|
+
const key = String(item.id || "");
|
|
55
|
+
const previous = key ? state.items.get(key) || {} : {};
|
|
56
|
+
const remember = (next) => { if (key) state.items.set(key, { ...previous, ...next }); };
|
|
57
|
+
|
|
58
|
+
if (itemType === "todo_list") return { type: "plan", items: item.items || [] };
|
|
46
59
|
|
|
47
|
-
if (
|
|
60
|
+
if (["message", "assistant_message", "agent_message"].includes(itemType)) {
|
|
61
|
+
if (type === "item.completed" && item.phase !== "commentary") state.finalText = text;
|
|
62
|
+
const delta = text.startsWith(previous.text || "") ? text.slice((previous.text || "").length) : text;
|
|
63
|
+
remember({ text });
|
|
64
|
+
if (!delta) return type === "item.started" ? { type: "phase", phase: { type: "text_delta" } } : null;
|
|
48
65
|
return {
|
|
49
66
|
type: "text_delta",
|
|
50
|
-
delta
|
|
67
|
+
delta,
|
|
51
68
|
itemType,
|
|
52
69
|
};
|
|
53
70
|
}
|
|
54
71
|
|
|
55
|
-
if (itemType === "
|
|
72
|
+
if (itemType === "reasoning") {
|
|
73
|
+
const delta = text.startsWith(previous.text || "") ? text.slice((previous.text || "").length) : text;
|
|
74
|
+
remember({ text });
|
|
75
|
+
return delta ? { type: "thinking_delta", delta }
|
|
76
|
+
: type === "item.started" ? { type: "phase", phase: { type: "thinking" } } : null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (["tool_call", "command_execution", "mcp_tool_call", "file_change", "web_search", "todo_list"].includes(itemType)) {
|
|
80
|
+
// A message before another tool is progress, not the final answer.
|
|
81
|
+
state.finalText = "";
|
|
82
|
+
if (previous.completed) return null;
|
|
83
|
+
if (["file_change", "web_search"].includes(itemType)) {
|
|
84
|
+
const tool = itemType === "file_change"
|
|
85
|
+
? { name: "apply_patch", args: { path: (item.changes || []).map(change => change.path).join(", ") } }
|
|
86
|
+
: { name: "web_search", args: { query: item.query || "" } };
|
|
87
|
+
const started = { type: "tool_call", toolCallId: key, ...tool };
|
|
88
|
+
if (type === "item.completed") {
|
|
89
|
+
remember({ started: true, completed: true });
|
|
90
|
+
const completed = { type: "tool_result", toolCallId: key, status: item.status || "completed",
|
|
91
|
+
is_error: item.status === "failed", output: itemType === "file_change" ? { changes: item.changes || [] } : { query: item.query || "", result: item.result || "" } };
|
|
92
|
+
return previous.started ? completed : [started, completed];
|
|
93
|
+
}
|
|
94
|
+
if (previous.started) return null;
|
|
95
|
+
remember({ started: true });
|
|
96
|
+
return started;
|
|
97
|
+
}
|
|
98
|
+
if (previous.started && ["command_execution", "mcp_tool_call"].includes(itemType)) {
|
|
99
|
+
const output = itemType === "command_execution" ? String(item.aggregated_output || "") : item.result || item.error || "";
|
|
100
|
+
const delta = typeof output === "string" && output.startsWith(previous.output || "")
|
|
101
|
+
? output.slice((previous.output || "").length) : output;
|
|
102
|
+
remember({ output, completed: type === "item.completed" });
|
|
103
|
+
if (!delta && type !== "item.completed") return null;
|
|
104
|
+
return { type: "tool_result", toolCallId: key, output: delta,
|
|
105
|
+
...(item.exit_code !== undefined ? { exitCode: item.exit_code } : {}), status: item.status || "" };
|
|
106
|
+
}
|
|
107
|
+
remember({ started: true, output: "" });
|
|
108
|
+
const nativeTools = {
|
|
109
|
+
command_execution: { name: "bash", args: { command: item.command || "" } },
|
|
110
|
+
file_change: { name: "apply_patch", args: { path: (item.changes || []).map((change) => change.path).join(", ") } },
|
|
111
|
+
mcp_tool_call: { name: `${item.server || "mcp"}.${item.tool || "tool"}`, args: item.arguments || {} },
|
|
112
|
+
web_search: { name: "web_search", args: { query: item.query || "" } },
|
|
113
|
+
todo_list: { name: "plan", args: { items: item.items || [] } },
|
|
114
|
+
};
|
|
115
|
+
const tool = nativeTools[itemType] || { name: item.name || "", args: item.arguments || item.args || {} };
|
|
56
116
|
return {
|
|
57
117
|
type: "tool_call",
|
|
58
|
-
name:
|
|
118
|
+
name: tool.name,
|
|
59
119
|
toolCallId: item.id || item.tool_call_id || "",
|
|
60
|
-
args:
|
|
120
|
+
args: tool.args,
|
|
61
121
|
};
|
|
62
122
|
}
|
|
63
123
|
|
|
@@ -74,5 +134,6 @@ function normalizeCodexEvent(event = {}) {
|
|
|
74
134
|
}
|
|
75
135
|
|
|
76
136
|
module.exports = {
|
|
137
|
+
createCodexEventState,
|
|
77
138
|
normalizeCodexEvent,
|
|
78
139
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { normalizeCodexEvent } = require("./codexEventTranslator");
|
|
1
|
+
const { createCodexEventState, normalizeCodexEvent } = require("./codexEventTranslator");
|
|
2
2
|
const { redactUfooEvent } = require("../../runtime/privacy/redactor");
|
|
3
3
|
|
|
4
4
|
async function resolveCodexSdk() {
|
|
@@ -42,6 +42,11 @@ function buildThreadOptions({
|
|
|
42
42
|
if (options.sandboxMode === undefined) {
|
|
43
43
|
options.sandboxMode = "workspace-write";
|
|
44
44
|
}
|
|
45
|
+
// SDK workspace-write disables sockets unless explicitly enabled. Coding
|
|
46
|
+
// tools need local services too (ADB, Gradle, dev servers), not just HTTP.
|
|
47
|
+
if (options.networkAccessEnabled === undefined) {
|
|
48
|
+
options.networkAccessEnabled = true;
|
|
49
|
+
}
|
|
45
50
|
return options;
|
|
46
51
|
}
|
|
47
52
|
|
|
@@ -50,11 +55,13 @@ function buildTurnOptions(opts = {}) {
|
|
|
50
55
|
history,
|
|
51
56
|
tools,
|
|
52
57
|
timeoutMs,
|
|
58
|
+
runtimeContext,
|
|
53
59
|
...turnOptions
|
|
54
60
|
} = opts || {};
|
|
55
61
|
void history;
|
|
56
62
|
void tools;
|
|
57
63
|
void timeoutMs;
|
|
64
|
+
void runtimeContext;
|
|
58
65
|
return turnOptions;
|
|
59
66
|
}
|
|
60
67
|
|
|
@@ -152,16 +159,19 @@ class CodexSdkThread {
|
|
|
152
159
|
opts: mergedOpts,
|
|
153
160
|
});
|
|
154
161
|
let outputText = "";
|
|
162
|
+
const eventState = createCodexEventState();
|
|
155
163
|
for await (const rawEvent of stream) {
|
|
156
|
-
const normalized = normalizeCodexEvent(rawEvent);
|
|
164
|
+
const normalized = normalizeCodexEvent(rawEvent, eventState);
|
|
157
165
|
if (!normalized) continue;
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
for (const item of Array.isArray(normalized) ? normalized : [normalized]) {
|
|
167
|
+
if (item.type === "thread_started" && item.threadId) {
|
|
168
|
+
this.id = item.threadId;
|
|
169
|
+
}
|
|
170
|
+
if (item.type === "text_delta" && item.delta) {
|
|
171
|
+
outputText += item.delta;
|
|
172
|
+
}
|
|
173
|
+
yield redactUfooEvent(item);
|
|
163
174
|
}
|
|
164
|
-
yield redactUfooEvent(normalized);
|
|
165
175
|
}
|
|
166
176
|
if (sdkThread && sdkThread.id) {
|
|
167
177
|
this.id = sdkThread.id;
|
|
@@ -22,7 +22,7 @@ function defaultClaudeConfigDir() {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function resolveClaudeOauthPaths(options = {}) {
|
|
25
|
-
const configDir = String(options.configDir || defaultClaudeConfigDir()).trim() || defaultClaudeConfigDir();
|
|
25
|
+
const configDir = String(options.configDir || (options.env || process.env).CLAUDE_CONFIG_DIR || defaultClaudeConfigDir()).trim() || defaultClaudeConfigDir();
|
|
26
26
|
const profile = String(options.profile || "").trim();
|
|
27
27
|
const explicitTokenPath = String(options.tokenPath || "").trim();
|
|
28
28
|
const explicitSettingsPath = String(options.settingsPath || "").trim();
|
|
@@ -234,6 +234,7 @@ class ClaudeUpstreamCredentialResolver {
|
|
|
234
234
|
apiKey: firstString(env.ANTHROPIC_API_KEY, env.CLAUDE_API_KEY),
|
|
235
235
|
apiKeySource,
|
|
236
236
|
authToken: firstString(env.ANTHROPIC_AUTH_TOKEN),
|
|
237
|
+
baseUrl: firstString(env.ANTHROPIC_BASE_URL),
|
|
237
238
|
};
|
|
238
239
|
}
|
|
239
240
|
|
|
@@ -332,7 +333,7 @@ class ClaudeUpstreamCredentialResolver {
|
|
|
332
333
|
});
|
|
333
334
|
}
|
|
334
335
|
|
|
335
|
-
async
|
|
336
|
+
async resolveAuthCredential(settingsEnv) {
|
|
336
337
|
const anthropicApiKey = firstString(this.env.ANTHROPIC_API_KEY);
|
|
337
338
|
const claudeApiKey = firstString(this.env.CLAUDE_API_KEY);
|
|
338
339
|
if (anthropicApiKey || claudeApiKey) {
|
|
@@ -347,7 +348,6 @@ class ClaudeUpstreamCredentialResolver {
|
|
|
347
348
|
return this.buildAuthTokenCredential(authToken, "env:ANTHROPIC_AUTH_TOKEN");
|
|
348
349
|
}
|
|
349
350
|
|
|
350
|
-
const settingsEnv = this.readSettingsEnv();
|
|
351
351
|
if (settingsEnv.apiKey) {
|
|
352
352
|
return this.buildApiKeyCredential(settingsEnv.apiKey, settingsEnv.apiKeySource || "settings:ANTHROPIC_API_KEY", this.paths.settingsPath);
|
|
353
353
|
}
|
|
@@ -373,6 +373,13 @@ class ClaudeUpstreamCredentialResolver {
|
|
|
373
373
|
|
|
374
374
|
return this.refreshIfNeeded(tokenRecord);
|
|
375
375
|
}
|
|
376
|
+
|
|
377
|
+
async resolveCredentials() {
|
|
378
|
+
const settings = this.readSettingsEnv();
|
|
379
|
+
const credential = await this.resolveAuthCredential(settings);
|
|
380
|
+
return { ...credential, metadata: { ...credential.metadata,
|
|
381
|
+
baseUrl: firstString(this.env.ANTHROPIC_BASE_URL, settings.baseUrl) } };
|
|
382
|
+
}
|
|
376
383
|
}
|
|
377
384
|
|
|
378
385
|
async function resolveClaudeUpstreamCredentials(options = {}) {
|
|
@@ -87,6 +87,8 @@ function buildUpstreamAuthFromCredential(descriptor = {}) {
|
|
|
87
87
|
return {
|
|
88
88
|
headers: {
|
|
89
89
|
authorization: `${tokenType} ${accessToken}`,
|
|
90
|
+
...(descriptor.provider === "claude" || descriptor.provider === "anthropic"
|
|
91
|
+
? { "anthropic-beta": "claude-code-20250219,oauth-2025-04-20" } : {}),
|
|
90
92
|
},
|
|
91
93
|
};
|
|
92
94
|
}
|
|
@@ -362,7 +362,7 @@ async function inspectGrokDirectAuth({
|
|
|
362
362
|
async function inspectDirectAuthStatus(options = {}) {
|
|
363
363
|
const { projectRoot, loadConfigImpl = loadConfig, provider = "" } = options;
|
|
364
364
|
const config = loadConfigImpl(projectRoot) || {};
|
|
365
|
-
const selected = normalizeDirectAuthProvider(provider || config.agentProvider ||
|
|
365
|
+
const selected = normalizeDirectAuthProvider(provider || config.agentProvider || "");
|
|
366
366
|
const nextOptions = {
|
|
367
367
|
...options,
|
|
368
368
|
loadConfigImpl: () => config,
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { loadConfig } = require("../../config");
|
|
4
|
+
const { resolveUpstreamRuntime } = require("./upstreamRuntime");
|
|
5
|
+
const { listProviderModels, confirmModelSupported, usesCustomModelEndpoint } = require("./modelsCatalog");
|
|
6
|
+
|
|
7
|
+
async function resolveAgentModelCatalog(projectRoot, options = {}) {
|
|
8
|
+
const config = options.config || loadConfig(projectRoot);
|
|
9
|
+
if (config.agentProvider === "custom") {
|
|
10
|
+
const { resolveTransport } = require("./runtimeConfig");
|
|
11
|
+
return { provider: "openai", transport: resolveTransport({ provider: "openai", baseUrl: config.agentBaseUrl }),
|
|
12
|
+
baseUrl: config.agentBaseUrl, apiKey: config.agentApiKey || "", allowUnlistedModels: true, fetchImpl: options.fetchImpl,
|
|
13
|
+
timeoutMs: options.timeoutMs, skipCache: options.skipCache };
|
|
14
|
+
}
|
|
15
|
+
const runtime = await (options.resolveRuntime || resolveUpstreamRuntime)({
|
|
16
|
+
projectRoot, provider: config.agentProvider, model: config.agentModel,
|
|
17
|
+
loadConfigImpl: () => config,
|
|
18
|
+
});
|
|
19
|
+
return { provider: runtime.provider, transport: runtime.transport, baseUrl: runtime.baseUrl,
|
|
20
|
+
apiKey: runtime.auth?.apiKey || "", requestHeaders: { ...runtime.auth?.headers,
|
|
21
|
+
...(runtime.provider === "codex" && runtime.credential?.accountId ? { "chatgpt-account-id": runtime.credential.accountId } : {}) },
|
|
22
|
+
fetchImpl: options.fetchImpl, timeoutMs: options.timeoutMs, skipCache: options.skipCache };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function listAgentModels(projectRoot, options = {}) {
|
|
26
|
+
const runtime = await resolveAgentModelCatalog(projectRoot, options);
|
|
27
|
+
return { ...await listProviderModels(runtime), allowUnlistedModels: usesCustomModelEndpoint(runtime) };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function confirmAgentModel(projectRoot, model, options = {}) {
|
|
31
|
+
return confirmModelSupported({ ...await resolveAgentModelCatalog(projectRoot, options), model });
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = { listAgentModels, confirmAgentModel, resolveAgentModelCatalog };
|