u-foo 3.1.6 → 4.0.0
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 +172 -13
- package/README.zh-CN.md +108 -13
- package/SKILLS/ufoo/SKILL.md +15 -3
- package/SKILLS/ufoo-bus/SKILL.md +21 -1
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +3 -1
- 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 +10 -3
- 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/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +113 -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 +6 -4
- package/src/agents/controller/loopRuntime.js +85 -221
- package/src/agents/controller/ufooAgent.js +1 -0
- package/src/agents/internal/internalRunner.js +103 -32
- package/src/agents/launch/launcher.js +88 -6
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +13 -18
- package/src/agents/launch/readyDetector.js +26 -12
- 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/groupBootstrap.js +10 -0
- package/src/agents/prompts/mainAgent.js +39 -0
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +3 -0
- package/src/agents/providers/claudeEventTranslator.js +6 -1
- package/src/agents/providers/claudeThreadProvider.js +44 -2
- package/src/agents/providers/codexEventTranslator.js +47 -7
- package/src/agents/providers/codexThreadProvider.js +3 -2
- package/src/agents/providers/controllerJsonTransport.js +28 -0
- package/src/agents/providers/credentials/claude.js +10 -3
- package/src/agents/providers/nativeTransport.js +1135 -0
- package/src/agents/providers/runtimeConfig.js +186 -0
- package/src/agents/providers/thinkingLevels.js +132 -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 +499 -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/upstreamTransport.js +13 -4
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/runtimeStore.js +126 -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 +270 -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 +247 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -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 +14 -3
- package/src/app/chat/agentDirectory.js +8 -2
- package/src/app/chat/commandExecutor.js +36 -46
- package/src/app/chat/commands.js +14 -7
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -3
- package/src/app/chat/inputSubmitHandler.js +14 -2
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +85 -165
- package/src/app/chat/streamState.js +3 -3
- 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/skills.js +16 -4
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +40 -39
- package/src/code/agent.js +16 -4
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +2 -1
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +100 -0
- package/src/code/nativeRunner.js +36 -2668
- 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/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/sessionStore.js +24 -96
- package/src/code/thinkingLevels.js +1 -130
- 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 +81 -67
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +2 -6
- package/src/coordination/bus/inject.js +13 -5
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/utils.js +7 -3
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/controllerSummary.js +23 -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/runtime/contracts/agentMode.js +17 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +4 -0
- package/src/runtime/daemon/agentHost.js +375 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +27 -17
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/executionPaths.js +30 -0
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +1 -0
- package/src/runtime/daemon/index.js +114 -344
- 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 +7 -4
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/ops.js +22 -17
- package/src/runtime/daemon/promptRequest.js +23 -4
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +4 -0
- 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 +24 -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/index.js +1 -0
- package/src/tools/registry.js +2 -0
- package/src/tools/schemaFixtures.js +16 -3
- 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/agentSurface.js +270 -0
- package/src/ui/format/banner.js +8 -11
- package/src/ui/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +170 -438
- package/src/ui/rustMultiSession.js +225 -51
- package/src/ui/rustUcodeHost.js +20 -87
- package/src/ui/settingsBridge.js +7 -4
- package/src/app/chat/agentEnter.js +0 -70
- 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/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -1,151 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
function extractVisionPayload(toolResult = null) {
|
|
8
|
-
if (!toolResult || typeof toolResult !== "object") return null;
|
|
9
|
-
const base64 = String(toolResult.base64 || "").trim();
|
|
10
|
-
const mediaType = String(toolResult.mediaType || "").trim().toLowerCase();
|
|
11
|
-
if (!base64 || !mediaType.startsWith("image/")) return null;
|
|
12
|
-
if (toolResult.ok === false) return null;
|
|
13
|
-
return {
|
|
14
|
-
path: String(toolResult.path || "").trim(),
|
|
15
|
-
mediaType,
|
|
16
|
-
bytes: Number.isFinite(toolResult.bytes) ? toolResult.bytes : null,
|
|
17
|
-
base64,
|
|
18
|
-
artifactId: String(toolResult.artifactId || "").trim(),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function isVisionToolResult(toolResult = null) {
|
|
23
|
-
return Boolean(extractVisionPayload(toolResult));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function stripVisionBase64(value) {
|
|
27
|
-
if (Array.isArray(value)) {
|
|
28
|
-
return value.map((item) => stripVisionBase64(item));
|
|
29
|
-
}
|
|
30
|
-
if (!value || typeof value !== "object") return value;
|
|
31
|
-
const out = {};
|
|
32
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
33
|
-
if (key === "base64") continue;
|
|
34
|
-
out[key] = stripVisionBase64(entry);
|
|
35
|
-
}
|
|
36
|
-
return out;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function visionSummaryText(vision = null, toolResult = null) {
|
|
40
|
-
const pathText = (vision && vision.path) || (toolResult && toolResult.path) || "image";
|
|
41
|
-
const mediaType = (vision && vision.mediaType) || (toolResult && toolResult.mediaType) || "image/*";
|
|
42
|
-
const bytes = (vision && vision.bytes) != null
|
|
43
|
-
? vision.bytes
|
|
44
|
-
: (toolResult && toolResult.bytes);
|
|
45
|
-
const parts = [
|
|
46
|
-
`Image loaded for vision: ${pathText}`,
|
|
47
|
-
`mediaType=${mediaType}`,
|
|
48
|
-
];
|
|
49
|
-
if (Number.isFinite(bytes)) parts.push(`bytes=${bytes}`);
|
|
50
|
-
if (vision && vision.artifactId) parts.push(`artifactId=${vision.artifactId}`);
|
|
51
|
-
parts.push("Visual content is attached for this model call only; call read_image again later if needed.");
|
|
52
|
-
return parts.join(" | ");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function toAnthropicImageBlock(vision = null) {
|
|
56
|
-
if (!vision) return null;
|
|
57
|
-
return {
|
|
58
|
-
type: "image",
|
|
59
|
-
source: {
|
|
60
|
-
type: "base64",
|
|
61
|
-
media_type: vision.mediaType,
|
|
62
|
-
data: vision.base64,
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function toOpenAiImagePart(vision = null) {
|
|
68
|
-
if (!vision) return null;
|
|
69
|
-
return {
|
|
70
|
-
type: "image_url",
|
|
71
|
-
image_url: {
|
|
72
|
-
url: `data:${vision.mediaType};base64,${vision.base64}`,
|
|
73
|
-
},
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function degradeVisionContent(content) {
|
|
78
|
-
if (typeof content === "string") return content;
|
|
79
|
-
if (!Array.isArray(content)) return content;
|
|
80
|
-
const texts = [];
|
|
81
|
-
for (const block of content) {
|
|
82
|
-
if (!block || typeof block !== "object") continue;
|
|
83
|
-
const type = String(block.type || "").trim().toLowerCase();
|
|
84
|
-
if (type === "text" && block.text) {
|
|
85
|
-
texts.push(String(block.text));
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
if (type === "image" || type === "image_url") {
|
|
89
|
-
const pathHint = block.path
|
|
90
|
-
|| (block.source && block.source.path)
|
|
91
|
-
|| "";
|
|
92
|
-
texts.push(pathHint ? `[image: ${pathHint}]` : "[image]");
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
if (type === "tool_result" && Array.isArray(block.content)) {
|
|
96
|
-
texts.push(degradeVisionContent(block.content));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return texts.filter(Boolean).join("\n") || "[multimodal content]";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Retire only visual blocks after a successful model call. In particular,
|
|
103
|
-
// preserve Anthropic tool_result envelopes and their tool_use_id linkage.
|
|
104
|
-
function retireVisionContent(content) {
|
|
105
|
-
if (!Array.isArray(content)) return content;
|
|
106
|
-
let changed = false;
|
|
107
|
-
const retired = content.map((block) => {
|
|
108
|
-
if (!block || typeof block !== "object") return block;
|
|
109
|
-
const type = String(block.type || "").toLowerCase();
|
|
110
|
-
if (type === "image" || type === "image_url" || type === "input_image") {
|
|
111
|
-
changed = true;
|
|
112
|
-
const pathHint = block.path || (block.source && block.source.path) || "";
|
|
113
|
-
return {
|
|
114
|
-
type: "text",
|
|
115
|
-
text: pathHint
|
|
116
|
-
? `[image already viewed: ${pathHint}; use read_image to view again]`
|
|
117
|
-
: "[image already viewed; use read_image with the recorded path to view again]",
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
if (Array.isArray(block.content)) {
|
|
121
|
-
const nested = retireVisionContent(block.content);
|
|
122
|
-
if (nested !== block.content) {
|
|
123
|
-
changed = true;
|
|
124
|
-
return { ...block, content: nested };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return block;
|
|
128
|
-
});
|
|
129
|
-
return changed ? retired : content;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function retireMessageImages(messages = []) {
|
|
133
|
-
for (let i = 0; i < messages.length; i += 1) {
|
|
134
|
-
const message = messages[i];
|
|
135
|
-
if (message && Array.isArray(message.content)) {
|
|
136
|
-
const content = retireVisionContent(message.content);
|
|
137
|
-
if (content !== message.content) messages[i] = { ...message, content };
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
module.exports = {
|
|
143
|
-
extractVisionPayload,
|
|
144
|
-
isVisionToolResult,
|
|
145
|
-
stripVisionBase64,
|
|
146
|
-
visionSummaryText,
|
|
147
|
-
toAnthropicImageBlock,
|
|
148
|
-
toOpenAiImagePart,
|
|
149
|
-
degradeVisionContent,
|
|
150
|
-
retireMessageImages,
|
|
151
|
-
};
|
|
3
|
+
// Existing public entry; implementation belongs to the shared agent layer.
|
|
4
|
+
module.exports = require("../../agents/providers/transports/visionBlocks");
|
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();
|
|
@@ -212,50 +226,14 @@ function listSessionSummaries(workspaceRoot = process.cwd(), { limit = 40 } = {}
|
|
|
212
226
|
return rows.slice(0, cap);
|
|
213
227
|
}
|
|
214
228
|
|
|
215
|
-
|
|
216
|
-
const normalizedId = normalizeSessionId(sessionId);
|
|
217
|
-
if (!normalizedId) return "";
|
|
218
|
-
return path.join(getSessionsDir(workspaceRoot), `${normalizedId}.json`);
|
|
219
|
-
}
|
|
229
|
+
const getSessionFilePath = sessionStore.getFilePath;
|
|
220
230
|
|
|
221
231
|
function saveSessionSnapshot(workspaceRoot = process.cwd(), snapshot = {}) {
|
|
222
232
|
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
|
-
}
|
|
233
|
+
const saved = sessionStore.save(normalizedRoot, snapshot);
|
|
234
|
+
if (!saved.ok) return saved;
|
|
235
|
+
const payload = saved.snapshot;
|
|
236
|
+
const filePath = saved.filePath;
|
|
259
237
|
|
|
260
238
|
// Artifact GC is throttled (default 2m) so long sessions do not accumulate
|
|
261
239
|
// unbounded tool result files between explicit maintenance runs.
|
|
@@ -278,57 +256,7 @@ function saveSessionSnapshot(workspaceRoot = process.cwd(), snapshot = {}) {
|
|
|
278
256
|
};
|
|
279
257
|
}
|
|
280
258
|
|
|
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
|
-
}
|
|
259
|
+
const loadSessionSnapshot = sessionStore.load;
|
|
332
260
|
|
|
333
261
|
function deleteSessionData(workspaceRoot = process.cwd(), sessionId = "") {
|
|
334
262
|
const normalizedId = normalizeSessionId(sessionId);
|
|
@@ -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");
|
|
@@ -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
|
}
|