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
package/src/code/repl.js
CHANGED
|
@@ -79,7 +79,6 @@ function extractAgentNickname(agentId = "") {
|
|
|
79
79
|
// Common agent nickname mappings
|
|
80
80
|
if (base === "ufoo-agent") return "ufoo";
|
|
81
81
|
if (base === "claude-code") return "claude";
|
|
82
|
-
if (base === "ufoo-code") return "ucode";
|
|
83
82
|
|
|
84
83
|
// Return base name as-is for others
|
|
85
84
|
return base;
|
|
@@ -142,7 +141,7 @@ function runSingleCommand(line = "", workspaceRoot = process.cwd()) {
|
|
|
142
141
|
if (!modelId || parts.length > 2) {
|
|
143
142
|
return {
|
|
144
143
|
kind: "error",
|
|
145
|
-
output: "usage: /model [model-id] [off|low|medium|high|max]",
|
|
144
|
+
output: "usage: /model [model-id] [off|low|medium|high|xhigh|max]",
|
|
146
145
|
};
|
|
147
146
|
}
|
|
148
147
|
return {
|
|
@@ -318,7 +317,6 @@ async function runUcodeCoreAgent({
|
|
|
318
317
|
currentThinkingLevel,
|
|
319
318
|
} = require("./modelCommand");
|
|
320
319
|
const {
|
|
321
|
-
resolveThinkingFromEnvAndConfig,
|
|
322
320
|
applyThinkingLevelToEnv,
|
|
323
321
|
} = require("./thinkingLevels");
|
|
324
322
|
const { loadGlobalUcodeConfig } = require("../config");
|
|
@@ -328,10 +326,6 @@ async function runUcodeCoreAgent({
|
|
|
328
326
|
} catch {
|
|
329
327
|
initialThinking = "";
|
|
330
328
|
}
|
|
331
|
-
const thinkingResolved = resolveThinkingFromEnvAndConfig({
|
|
332
|
-
env: process.env,
|
|
333
|
-
configLevel: initialThinking,
|
|
334
|
-
});
|
|
335
329
|
const state = {
|
|
336
330
|
workspaceRoot: resolvedWorkspaceRoot,
|
|
337
331
|
provider: resolvedUcode.provider,
|
|
@@ -351,10 +345,7 @@ async function runUcodeCoreAgent({
|
|
|
351
345
|
maxToolCalls,
|
|
352
346
|
jsonOutput,
|
|
353
347
|
};
|
|
354
|
-
|
|
355
|
-
if (thinkingResolved.source !== "env-budget") {
|
|
356
|
-
applyThinkingLevelToEnv(state.thinking, process.env);
|
|
357
|
-
}
|
|
348
|
+
applyThinkingLevelToEnv(state.thinking, process.env);
|
|
358
349
|
persistSessionState(state);
|
|
359
350
|
|
|
360
351
|
if (shouldUseUcodeTui({
|
package/src/code/sessionStore.js
CHANGED
|
@@ -16,10 +16,24 @@ const { emptyTaskContract } = require("./context/stateCommit");
|
|
|
16
16
|
const { emptyWorkingSet } = require("./context/workingSet");
|
|
17
17
|
const { emptyExecutionState } = require("./context/executionSegment");
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
19
|
+
const { createSessionStore } = require("../agents/runtime/context/sessionStore");
|
|
20
|
+
const sessionStore = createSessionStore({
|
|
21
|
+
namespace: "ucode",
|
|
22
|
+
encode: (input, { workspaceRoot }) => buildSessionSnapshot({ ...input, workspaceRoot }),
|
|
23
|
+
toDisk: (payload) => {
|
|
24
|
+
const stored = { ...payload };
|
|
25
|
+
// Explicit turn commits own conversation truth; snapshots only save metadata.
|
|
26
|
+
if (stored.version >= 2) delete stored.nlMessages;
|
|
27
|
+
return stored;
|
|
28
|
+
},
|
|
29
|
+
decode: (parsed, { workspaceRoot, sessionId }) => hydrateSessionFromDisk({
|
|
30
|
+
...parsed, sessionId, workspaceRoot,
|
|
31
|
+
createdAt: parsed && parsed.createdAt || "",
|
|
32
|
+
nlMessages: parsed && parsed.nlMessages || [],
|
|
33
|
+
}, workspaceRoot),
|
|
34
|
+
prepareSave: (workspaceRoot) => fs.mkdirSync(getTranscriptsDir(workspaceRoot), { recursive: true }),
|
|
35
|
+
});
|
|
36
|
+
const getSessionsDir = sessionStore.getDirectory;
|
|
23
37
|
|
|
24
38
|
function normalizeSessionId(value = "") {
|
|
25
39
|
const raw = String(value || "").trim();
|
|
@@ -60,9 +74,8 @@ function normalizeContextPolicy(value = {}) {
|
|
|
60
74
|
return {
|
|
61
75
|
...defaults,
|
|
62
76
|
...source,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
: defaults.transcriptWindow,
|
|
77
|
+
maxMessages: Number.isFinite(source.maxMessages) ? Math.max(1, Math.floor(source.maxMessages)) : defaults.maxMessages,
|
|
78
|
+
keepRecentUnits: Number.isFinite(source.keepRecentUnits) ? Math.max(1, Math.floor(source.keepRecentUnits)) : defaults.keepRecentUnits,
|
|
66
79
|
};
|
|
67
80
|
}
|
|
68
81
|
|
|
@@ -212,50 +225,14 @@ function listSessionSummaries(workspaceRoot = process.cwd(), { limit = 40 } = {}
|
|
|
212
225
|
return rows.slice(0, cap);
|
|
213
226
|
}
|
|
214
227
|
|
|
215
|
-
|
|
216
|
-
const normalizedId = normalizeSessionId(sessionId);
|
|
217
|
-
if (!normalizedId) return "";
|
|
218
|
-
return path.join(getSessionsDir(workspaceRoot), `${normalizedId}.json`);
|
|
219
|
-
}
|
|
228
|
+
const getSessionFilePath = sessionStore.getFilePath;
|
|
220
229
|
|
|
221
230
|
function saveSessionSnapshot(workspaceRoot = process.cwd(), snapshot = {}) {
|
|
222
231
|
const normalizedRoot = path.resolve(workspaceRoot || process.cwd());
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const filePath = getSessionFilePath(normalizedRoot, payload.sessionId);
|
|
228
|
-
if (!filePath) {
|
|
229
|
-
return {
|
|
230
|
-
ok: false,
|
|
231
|
-
error: "invalid session id",
|
|
232
|
-
sessionId: "",
|
|
233
|
-
filePath: "",
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const toWrite = { ...payload };
|
|
238
|
-
if (toWrite.version >= 2) {
|
|
239
|
-
// Conversation content is committed explicitly by the turn coordinator.
|
|
240
|
-
// Session snapshot saves projections/metadata only and never tries to infer
|
|
241
|
-
// missing events from a mutable provider message array.
|
|
242
|
-
delete toWrite.nlMessages;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
try {
|
|
246
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
247
|
-
fs.mkdirSync(getTranscriptsDir(normalizedRoot), { recursive: true });
|
|
248
|
-
const tmpFile = `${filePath}.${process.pid}-${randomUUID()}.tmp`;
|
|
249
|
-
fs.writeFileSync(tmpFile, `${JSON.stringify(toWrite, null, 2)}\n`, "utf8");
|
|
250
|
-
fs.renameSync(tmpFile, filePath);
|
|
251
|
-
} catch (err) {
|
|
252
|
-
return {
|
|
253
|
-
ok: false,
|
|
254
|
-
error: err && err.message ? err.message : "failed to save session",
|
|
255
|
-
sessionId: payload.sessionId,
|
|
256
|
-
filePath,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
232
|
+
const saved = sessionStore.save(normalizedRoot, snapshot);
|
|
233
|
+
if (!saved.ok) return saved;
|
|
234
|
+
const payload = saved.snapshot;
|
|
235
|
+
const filePath = saved.filePath;
|
|
259
236
|
|
|
260
237
|
// Artifact GC is throttled (default 2m) so long sessions do not accumulate
|
|
261
238
|
// unbounded tool result files between explicit maintenance runs.
|
|
@@ -278,57 +255,7 @@ function saveSessionSnapshot(workspaceRoot = process.cwd(), snapshot = {}) {
|
|
|
278
255
|
};
|
|
279
256
|
}
|
|
280
257
|
|
|
281
|
-
|
|
282
|
-
const normalizedRoot = path.resolve(workspaceRoot || process.cwd());
|
|
283
|
-
const normalizedId = normalizeSessionId(sessionId);
|
|
284
|
-
if (!normalizedId) {
|
|
285
|
-
return {
|
|
286
|
-
ok: false,
|
|
287
|
-
error: "invalid session id",
|
|
288
|
-
sessionId: "",
|
|
289
|
-
snapshot: null,
|
|
290
|
-
filePath: "",
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const filePath = getSessionFilePath(normalizedRoot, normalizedId);
|
|
295
|
-
if (!filePath || !fs.existsSync(filePath)) {
|
|
296
|
-
return {
|
|
297
|
-
ok: false,
|
|
298
|
-
error: `session not found: ${normalizedId}`,
|
|
299
|
-
sessionId: normalizedId,
|
|
300
|
-
snapshot: null,
|
|
301
|
-
filePath: filePath || "",
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
try {
|
|
306
|
-
const raw = fs.readFileSync(filePath, "utf8");
|
|
307
|
-
const parsed = JSON.parse(raw);
|
|
308
|
-
const snapshot = hydrateSessionFromDisk({
|
|
309
|
-
...parsed,
|
|
310
|
-
sessionId: normalizedId,
|
|
311
|
-
workspaceRoot: normalizedRoot,
|
|
312
|
-
createdAt: parsed && parsed.createdAt ? parsed.createdAt : "",
|
|
313
|
-
nlMessages: parsed && parsed.nlMessages ? parsed.nlMessages : [],
|
|
314
|
-
}, normalizedRoot);
|
|
315
|
-
return {
|
|
316
|
-
ok: true,
|
|
317
|
-
error: "",
|
|
318
|
-
sessionId: normalizedId,
|
|
319
|
-
snapshot,
|
|
320
|
-
filePath,
|
|
321
|
-
};
|
|
322
|
-
} catch (err) {
|
|
323
|
-
return {
|
|
324
|
-
ok: false,
|
|
325
|
-
error: err && err.message ? err.message : "failed to load session",
|
|
326
|
-
sessionId: normalizedId,
|
|
327
|
-
snapshot: null,
|
|
328
|
-
filePath,
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
}
|
|
258
|
+
const loadSessionSnapshot = sessionStore.load;
|
|
332
259
|
|
|
333
260
|
function deleteSessionData(workspaceRoot = process.cwd(), sessionId = "") {
|
|
334
261
|
const normalizedId = normalizeSessionId(sessionId);
|
|
@@ -340,6 +267,7 @@ function deleteSessionData(workspaceRoot = process.cwd(), sessionId = "") {
|
|
|
340
267
|
deleteTranscript(workspaceRoot, normalizedId);
|
|
341
268
|
deleteSessionArtifacts(workspaceRoot, normalizedId);
|
|
342
269
|
deleteSessionCommitLog(workspaceRoot, normalizedId);
|
|
270
|
+
require("../agents/runtime/context/checkpointStore").createCheckpointStore({ workspaceRoot, namespace: "ucode", sessionId: normalizedId }).remove();
|
|
343
271
|
return { ok: true, error: "" };
|
|
344
272
|
} catch (err) {
|
|
345
273
|
return {
|
|
@@ -11,6 +11,8 @@ const {
|
|
|
11
11
|
renderActiveSkillBlock,
|
|
12
12
|
} = require("./skills");
|
|
13
13
|
const { sanitizeSkillContent } = require("./skills/injection");
|
|
14
|
+
const { randomUUID } = require("crypto");
|
|
15
|
+
const { normalizeTraceContext } = require("../agents/runtime/protocol/traceContext");
|
|
14
16
|
|
|
15
17
|
function renderActiveSkillBodiesFromState(state = {}) {
|
|
16
18
|
const skills = Array.isArray(state.activeSkills) ? state.activeSkills : [];
|
|
@@ -162,6 +164,13 @@ async function runDecomposedTask({
|
|
|
162
164
|
sessionId = "",
|
|
163
165
|
state = null,
|
|
164
166
|
systemBlocks = null,
|
|
167
|
+
runtimeContext = {},
|
|
168
|
+
onRuntimeEvent = null,
|
|
169
|
+
onStreamDelta = null,
|
|
170
|
+
onThinkingDelta = null,
|
|
171
|
+
onPhase = null,
|
|
172
|
+
onContextUsage = null,
|
|
173
|
+
contextPolicy = {},
|
|
165
174
|
}) {
|
|
166
175
|
const steps = decomposeBugFixTask(task);
|
|
167
176
|
const results = [];
|
|
@@ -211,6 +220,7 @@ async function runDecomposedTask({
|
|
|
211
220
|
stepSystemPrompt = assembled.systemPrompt;
|
|
212
221
|
stepSystemBlocks = assembled.systemBlocks;
|
|
213
222
|
}
|
|
223
|
+
const inherited = normalizeTraceContext(runtimeContext);
|
|
214
224
|
const stepResult = await runNativeAgentTask({
|
|
215
225
|
workspaceRoot,
|
|
216
226
|
provider,
|
|
@@ -223,6 +233,14 @@ async function runDecomposedTask({
|
|
|
223
233
|
timeoutMs: step.timeoutMs,
|
|
224
234
|
maxToolCalls: state ? state.maxToolCalls : undefined,
|
|
225
235
|
onToolEvent,
|
|
236
|
+
runtimeContext: inherited.taskRunId ? { ...inherited, parentTaskRunId: inherited.taskRunId,
|
|
237
|
+
taskRunId: `segment-${randomUUID()}`, requestId: `${inherited.requestId || "step"}:${step.id}`, attemptId: `attempt-${randomUUID()}` } : inherited,
|
|
238
|
+
onRuntimeEvent,
|
|
239
|
+
onStreamDelta,
|
|
240
|
+
onThinkingDelta,
|
|
241
|
+
onPhase,
|
|
242
|
+
onContextUsage,
|
|
243
|
+
contextPolicy,
|
|
226
244
|
signal,
|
|
227
245
|
onArtifactPersisted: state
|
|
228
246
|
? (persisted) => recordToolCallInSession(state, persisted, workspaceRoot)
|
|
@@ -1,132 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* Ucode thinking-intensity levels.
|
|
5
|
-
*
|
|
6
|
-
* Used as the secondary `/model <id> <level>` menu after picking a model.
|
|
7
|
-
* Maps to Anthropic extended-thinking budget_tokens and OpenAI-compatible
|
|
8
|
-
* reasoning_effort where the transport supports it.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const THINKING_LEVELS = Object.freeze([
|
|
12
|
-
{
|
|
13
|
-
id: "off",
|
|
14
|
-
desc: "disable extended thinking",
|
|
15
|
-
budgetTokens: 0,
|
|
16
|
-
reasoningEffort: "",
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
id: "low",
|
|
20
|
-
desc: "light thinking",
|
|
21
|
-
budgetTokens: 2048,
|
|
22
|
-
reasoningEffort: "low",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
id: "medium",
|
|
26
|
-
desc: "default thinking",
|
|
27
|
-
budgetTokens: 10000,
|
|
28
|
-
reasoningEffort: "medium",
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
id: "high",
|
|
32
|
-
desc: "deeper thinking",
|
|
33
|
-
budgetTokens: 32000,
|
|
34
|
-
reasoningEffort: "high",
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
id: "max",
|
|
38
|
-
desc: "maximum thinking budget",
|
|
39
|
-
budgetTokens: 48000,
|
|
40
|
-
reasoningEffort: "high",
|
|
41
|
-
},
|
|
42
|
-
]);
|
|
43
|
-
|
|
44
|
-
const DEFAULT_THINKING_LEVEL = "medium";
|
|
45
|
-
const THINKING_LEVEL_IDS = new Set(THINKING_LEVELS.map((item) => item.id));
|
|
46
|
-
|
|
47
|
-
function normalizeThinkingLevel(value = "") {
|
|
48
|
-
const raw = String(value || "").trim().toLowerCase();
|
|
49
|
-
if (!raw) return "";
|
|
50
|
-
if (raw === "none" || raw === "disable" || raw === "disabled" || raw === "0") return "off";
|
|
51
|
-
if (raw === "med" || raw === "default") return "medium";
|
|
52
|
-
if (raw === "maximum" || raw === "xhigh" || raw === "ultra") return "max";
|
|
53
|
-
if (THINKING_LEVEL_IDS.has(raw)) return raw;
|
|
54
|
-
return "";
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function getThinkingLevel(id = "") {
|
|
58
|
-
const normalized = normalizeThinkingLevel(id) || DEFAULT_THINKING_LEVEL;
|
|
59
|
-
return THINKING_LEVELS.find((item) => item.id === normalized) || THINKING_LEVELS[2];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function suggestThinkingLevels(options = {}) {
|
|
63
|
-
const current = normalizeThinkingLevel(options.current || "") || DEFAULT_THINKING_LEVEL;
|
|
64
|
-
return THINKING_LEVELS.map((item) => ({
|
|
65
|
-
id: item.id,
|
|
66
|
-
desc: item.id === current ? `${item.desc} · current` : item.desc,
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function resolveThinkingFromEnvAndConfig({
|
|
71
|
-
env = process.env,
|
|
72
|
-
configLevel = "",
|
|
73
|
-
} = {}) {
|
|
74
|
-
// Explicit numeric budget still wins (advanced override).
|
|
75
|
-
const rawBudget = env && env.UFOO_UCODE_THINKING_BUDGET_TOKENS;
|
|
76
|
-
if (rawBudget !== undefined && rawBudget !== null && String(rawBudget).trim() !== "") {
|
|
77
|
-
const parsed = Number.parseInt(String(rawBudget), 10);
|
|
78
|
-
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
79
|
-
return {
|
|
80
|
-
level: "off",
|
|
81
|
-
budgetTokens: 0,
|
|
82
|
-
reasoningEffort: "",
|
|
83
|
-
source: "env-budget",
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
return {
|
|
87
|
-
level: "",
|
|
88
|
-
budgetTokens: Math.floor(parsed),
|
|
89
|
-
reasoningEffort: "",
|
|
90
|
-
source: "env-budget",
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const fromEnv = normalizeThinkingLevel(env && env.UFOO_UCODE_THINKING);
|
|
95
|
-
const fromConfig = normalizeThinkingLevel(configLevel);
|
|
96
|
-
const level = fromEnv || fromConfig || DEFAULT_THINKING_LEVEL;
|
|
97
|
-
const spec = getThinkingLevel(level);
|
|
98
|
-
return {
|
|
99
|
-
level: spec.id,
|
|
100
|
-
budgetTokens: spec.budgetTokens,
|
|
101
|
-
reasoningEffort: spec.reasoningEffort,
|
|
102
|
-
source: fromEnv ? "env" : (fromConfig ? "config" : "default"),
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function applyThinkingLevelToEnv(level = "", env = process.env) {
|
|
107
|
-
const normalized = normalizeThinkingLevel(level);
|
|
108
|
-
if (!normalized) return "";
|
|
109
|
-
const spec = getThinkingLevel(normalized);
|
|
110
|
-
try {
|
|
111
|
-
env.UFOO_UCODE_THINKING = spec.id;
|
|
112
|
-
if (spec.budgetTokens > 0) {
|
|
113
|
-
env.UFOO_UCODE_THINKING_BUDGET_TOKENS = String(spec.budgetTokens);
|
|
114
|
-
} else {
|
|
115
|
-
env.UFOO_UCODE_THINKING_BUDGET_TOKENS = "0";
|
|
116
|
-
}
|
|
117
|
-
} catch {
|
|
118
|
-
// ignore env write failures
|
|
119
|
-
}
|
|
120
|
-
return spec.id;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
module.exports = {
|
|
124
|
-
THINKING_LEVELS,
|
|
125
|
-
THINKING_LEVEL_IDS,
|
|
126
|
-
DEFAULT_THINKING_LEVEL,
|
|
127
|
-
normalizeThinkingLevel,
|
|
128
|
-
getThinkingLevel,
|
|
129
|
-
suggestThinkingLevels,
|
|
130
|
-
resolveThinkingFromEnvAndConfig,
|
|
131
|
-
applyThinkingLevelToEnv,
|
|
132
|
-
};
|
|
3
|
+
module.exports = require("../agents/providers/thinkingLevels");
|
package/src/code/toolBudget.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
if (value == null || String(value).trim().toLowerCase() === "none") return null;
|
|
5
|
-
const text = String(value).trim();
|
|
6
|
-
const count = Number(text);
|
|
7
|
-
if (!/^\d+$/.test(text) || !Number.isSafeInteger(count) || count <= 0) {
|
|
8
|
-
throw new Error("max tool calls must be a positive integer or none");
|
|
9
|
-
}
|
|
10
|
-
return count;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function resolveMaxToolCalls(value, env = process.env) {
|
|
14
|
-
if (value !== undefined) return parseMaxToolCalls(value);
|
|
15
|
-
const configured = env.UFOO_UCODE_MAX_TOOL_CALLS;
|
|
16
|
-
return configured == null || String(configured).trim() === ""
|
|
17
|
-
? null
|
|
18
|
-
: parseMaxToolCalls(configured);
|
|
19
|
-
}
|
|
3
|
+
const { parseMaxToolCalls, resolveMaxToolCalls } = require("../agents/runtime/core/executionBudget");
|
|
20
4
|
|
|
21
5
|
module.exports = { parseMaxToolCalls, resolveMaxToolCalls };
|
|
@@ -1,55 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const TIGHT_TOOLS = new Set(["read", "read_image", "artifact_read", "plan_graph"]);
|
|
7
|
-
|
|
8
|
-
// One observation is a model step, including its complete parallel tool batch.
|
|
9
|
-
// Ignore call IDs, JSON key order, and parallel ordering when comparing steps.
|
|
10
|
-
class ToolLoopGuard {
|
|
3
|
+
const { ToolLoopGuard: RuntimeToolLoopGuard } = require("../agents/runtime/core/toolLoopGuard");
|
|
4
|
+
class ToolLoopGuard extends RuntimeToolLoopGuard {
|
|
11
5
|
constructor() {
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
reset() {
|
|
16
|
-
this.signature = "";
|
|
17
|
-
this.count = 0;
|
|
18
|
-
this.warned = false;
|
|
19
|
-
this.names = [];
|
|
20
|
-
this.tight = false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
observe(calls) {
|
|
24
|
-
if (!calls.length) return this.reset();
|
|
25
|
-
const parts = calls.map((call) => stableStringify({ name: call.name, args: call.args }));
|
|
26
|
-
const signature = createHash("sha256").update(JSON.stringify(parts.sort())).digest("hex");
|
|
27
|
-
if (signature !== this.signature) this.reset();
|
|
28
|
-
this.signature = signature;
|
|
29
|
-
this.count += 1;
|
|
30
|
-
this.names = [...new Set(calls.map((call) => call.name))].sort();
|
|
31
|
-
this.tight = calls.every((call) => TIGHT_TOOLS.has(call.name));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
nextAction() {
|
|
35
|
-
const warnAt = this.tight ? 4 : 8;
|
|
36
|
-
const stopAt = this.tight ? 8 : 12;
|
|
37
|
-
const tools = this.names.join(", ");
|
|
38
|
-
if (this.count >= stopAt) {
|
|
39
|
-
return {
|
|
40
|
-
kind: "stop",
|
|
41
|
-
message: `Stopped repeated tool calls: ${tools} used identical arguments for ${this.count} consecutive model steps after a warning. Change the approach or provide new information to continue.`,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
if (this.count >= warnAt && !this.warned) {
|
|
45
|
-
this.warned = true;
|
|
46
|
-
return {
|
|
47
|
-
kind: "warn",
|
|
48
|
-
message: `You have repeated the same tool batch (${tools}) with identical arguments for ${this.count} consecutive model steps. Stop repeating it and use a different approach. If waiting for a task, use its supported waiting mechanism instead of repeatedly checking. If blocked, explain the blocker to the user. This run will stop at ${stopAt} consecutive identical steps.`,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return null;
|
|
6
|
+
super({ tightTools: ["read", "read_image", "artifact_read", "plan_graph"] });
|
|
52
7
|
}
|
|
53
8
|
}
|
|
54
|
-
|
|
55
9
|
module.exports = { ToolLoopGuard };
|
|
@@ -13,7 +13,7 @@ function runArtifactReadTool(args = {}, options = {}) {
|
|
|
13
13
|
return { ok: false, error: "sessionId is required for artifact_read" };
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
const loaded = loadArtifact(workspaceRoot, sessionId, artifactId);
|
|
16
|
+
const loaded = loadArtifact(workspaceRoot, sessionId, artifactId, { namespace: options.artifactNamespace || "ucode" });
|
|
17
17
|
if (!loaded.ok || !loaded.artifact) {
|
|
18
18
|
return { ok: false, error: loaded.error || "artifact not found", artifactId };
|
|
19
19
|
}
|