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
|
@@ -11,6 +11,7 @@ const {
|
|
|
11
11
|
const { redactSecrets } = require("../../runtime/privacy/redactor");
|
|
12
12
|
const { canonicalProjectRoot } = require("../../runtime/projects/projectId");
|
|
13
13
|
const { getUfooPaths } = require("../state/paths");
|
|
14
|
+
const { withFileLock } = require("../state/fileLock");
|
|
14
15
|
|
|
15
16
|
const SCHEMA_VERSION = "1.0";
|
|
16
17
|
const ID_PREFIX = "mem-";
|
|
@@ -20,11 +21,6 @@ const HISTORY_CACHE_TTL_MS = 60 * 60 * 1000;
|
|
|
20
21
|
const DEFAULT_PREFIX_MAX_TOKENS = 1500;
|
|
21
22
|
const prefixCache = new Map();
|
|
22
23
|
|
|
23
|
-
function sleepSync(ms) {
|
|
24
|
-
const buffer = new SharedArrayBuffer(4);
|
|
25
|
-
const array = new Int32Array(buffer);
|
|
26
|
-
Atomics.wait(array, 0, 0, ms);
|
|
27
|
-
}
|
|
28
24
|
|
|
29
25
|
function normalizeId(value = "") {
|
|
30
26
|
return String(value || "").trim();
|
|
@@ -168,23 +164,11 @@ class MemoryManager {
|
|
|
168
164
|
|
|
169
165
|
withLock(fn) {
|
|
170
166
|
ensureDir(this.memoryDir);
|
|
171
|
-
const started = Date.now();
|
|
172
|
-
while (true) {
|
|
173
|
-
try {
|
|
174
|
-
fs.mkdirSync(this.lockDir);
|
|
175
|
-
break;
|
|
176
|
-
} catch (err) {
|
|
177
|
-
if (err && err.code !== "EEXIST") throw err;
|
|
178
|
-
if (Date.now() - started > 5000) {
|
|
179
|
-
throw buildMemoryError("memory_lock_timeout", "timed out waiting for memory lock");
|
|
180
|
-
}
|
|
181
|
-
sleepSync(10);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
167
|
try {
|
|
185
|
-
return fn
|
|
186
|
-
}
|
|
187
|
-
|
|
168
|
+
return withFileLock(this.indexFile, fn, { lockfilePath: this.lockDir });
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error.code === "ELOCKED") throw buildMemoryError("memory_lock_timeout", "timed out waiting for memory lock");
|
|
171
|
+
throw error;
|
|
188
172
|
}
|
|
189
173
|
}
|
|
190
174
|
|
|
@@ -2,6 +2,8 @@ const fs = require("fs");
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const { getUfooPaths } = require("../state/paths");
|
|
4
4
|
const { redactSecrets } = require("../../runtime/privacy/redactor");
|
|
5
|
+
const { withFileLock } = require("../state/fileLock");
|
|
6
|
+
const { writeFileAtomic } = require("../bus/utils");
|
|
5
7
|
|
|
6
8
|
const REPORT_PHASES = {
|
|
7
9
|
START: "start",
|
|
@@ -38,7 +40,7 @@ function normalizeScope(value = "") {
|
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
function normalizeReportInput(input = {}, options = {}) {
|
|
41
|
-
const ts = options.ts || new Date().toISOString();
|
|
43
|
+
const ts = options.ts || input.ts || new Date().toISOString();
|
|
42
44
|
let phase = normalizePhase(input.phase || options.phase);
|
|
43
45
|
const entryId = String(
|
|
44
46
|
input.entry_id
|
|
@@ -53,7 +55,7 @@ function normalizeReportInput(input = {}, options = {}) {
|
|
|
53
55
|
|| input.task
|
|
54
56
|
|| options.task_id
|
|
55
57
|
|| options.taskId
|
|
56
|
-
|| `task-${
|
|
58
|
+
|| `task-${require("crypto").randomUUID()}`
|
|
57
59
|
).trim();
|
|
58
60
|
const agentId = String(
|
|
59
61
|
input.agent_id
|
|
@@ -101,7 +103,11 @@ function normalizeReportInput(input = {}, options = {}) {
|
|
|
101
103
|
function appendReport(projectRoot, entry) {
|
|
102
104
|
ensureReportDir(projectRoot);
|
|
103
105
|
const { reportsFile } = getReportPaths(projectRoot);
|
|
104
|
-
|
|
106
|
+
return withFileLock(reportsFile, () => {
|
|
107
|
+
if (entry.entry_id && parseJsonLines(reportsFile).some((row) => row.entry_id === entry.entry_id)) return false;
|
|
108
|
+
fs.appendFileSync(reportsFile, `${JSON.stringify(redactSecrets(entry))}\n`, "utf8");
|
|
109
|
+
return true;
|
|
110
|
+
});
|
|
105
111
|
}
|
|
106
112
|
|
|
107
113
|
function parseJsonLines(file) {
|
|
@@ -152,34 +158,40 @@ function loadReportState(projectRoot) {
|
|
|
152
158
|
function saveReportState(projectRoot, state) {
|
|
153
159
|
ensureReportDir(projectRoot);
|
|
154
160
|
const { stateFile } = getReportPaths(projectRoot);
|
|
155
|
-
|
|
161
|
+
writeFileAtomic(stateFile, JSON.stringify(redactSecrets(state), null, 2));
|
|
156
162
|
}
|
|
157
163
|
|
|
158
164
|
function updateReportState(projectRoot, entry) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
165
|
+
return withFileLock(getReportPaths(projectRoot).stateFile, () => {
|
|
166
|
+
const state = loadReportState(projectRoot);
|
|
167
|
+
const current = state.agents[entry.agent_id] && typeof state.agents[entry.agent_id] === "object"
|
|
168
|
+
? state.agents[entry.agent_id]
|
|
169
|
+
: {};
|
|
170
|
+
const lastByTask = current.last_by_task || {};
|
|
171
|
+
const previous = lastByTask[entry.task_id];
|
|
172
|
+
if (previous && (previous.entry_id === entry.entry_id || previous.ts > entry.ts)) return state;
|
|
173
|
+
const pending = current.pending && typeof current.pending === "object"
|
|
174
|
+
? { ...current.pending }
|
|
175
|
+
: {};
|
|
176
|
+
|
|
177
|
+
if (entry.phase === REPORT_PHASES.START || entry.phase === REPORT_PHASES.PROGRESS) {
|
|
178
|
+
pending[entry.task_id] = entry;
|
|
179
|
+
} else {
|
|
180
|
+
delete pending[entry.task_id];
|
|
181
|
+
}
|
|
172
182
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
state.agents[entry.agent_id] = {
|
|
184
|
+
...current,
|
|
185
|
+
last_by_task: { ...lastByTask, [entry.task_id]: entry },
|
|
186
|
+
pending,
|
|
187
|
+
pending_count: Object.keys(pending).length,
|
|
188
|
+
last: entry,
|
|
189
|
+
updated_at: entry.ts,
|
|
190
|
+
};
|
|
191
|
+
state.updated_at = entry.ts;
|
|
192
|
+
saveReportState(projectRoot, state);
|
|
193
|
+
return state;
|
|
194
|
+
});
|
|
183
195
|
}
|
|
184
196
|
|
|
185
197
|
function isSummaryHiddenEntry(entry) {
|
|
@@ -206,7 +218,11 @@ function getControllerInboxFile(projectRoot, controllerId = "ufoo-agent") {
|
|
|
206
218
|
function appendControllerInboxEntry(projectRoot, controllerId, entry) {
|
|
207
219
|
const file = getControllerInboxFile(projectRoot, controllerId);
|
|
208
220
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
209
|
-
|
|
221
|
+
return withFileLock(file, () => {
|
|
222
|
+
if (entry.entry_id && parseJsonLines(file).some((row) => row.entry_id === entry.entry_id)) return false;
|
|
223
|
+
fs.appendFileSync(file, `${JSON.stringify(redactSecrets(entry))}\n`, "utf8");
|
|
224
|
+
return true;
|
|
225
|
+
});
|
|
210
226
|
}
|
|
211
227
|
|
|
212
228
|
function listControllerInboxEntries(projectRoot, controllerId = "ufoo-agent", options = {}) {
|
|
@@ -224,75 +240,79 @@ function countControllerInboxEntries(projectRoot, controllerId = "ufoo-agent") {
|
|
|
224
240
|
|
|
225
241
|
function clearControllerInbox(projectRoot, controllerId = "ufoo-agent") {
|
|
226
242
|
const file = getControllerInboxFile(projectRoot, controllerId);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
243
|
+
return withFileLock(file, () => {
|
|
244
|
+
try {
|
|
245
|
+
if (fs.existsSync(file)) fs.rmSync(file, { force: true });
|
|
246
|
+
} catch {
|
|
247
|
+
// ignore clear errors
|
|
248
|
+
}
|
|
249
|
+
});
|
|
232
250
|
}
|
|
233
251
|
|
|
234
252
|
function consumeControllerInboxEntries(projectRoot, controllerId = "ufoo-agent", consumed = []) {
|
|
235
253
|
const file = getControllerInboxFile(projectRoot, controllerId);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const idSet = new Set();
|
|
244
|
-
const legacySerialized = new Set();
|
|
245
|
-
for (const item of list) {
|
|
246
|
-
if (!item) continue;
|
|
247
|
-
if (typeof item === "string") {
|
|
248
|
-
idSet.add(item);
|
|
249
|
-
continue;
|
|
254
|
+
return withFileLock(file, () => {
|
|
255
|
+
if (!fs.existsSync(file)) return { removed: 0, remaining: 0 };
|
|
256
|
+
const list = Array.isArray(consumed) ? consumed : [];
|
|
257
|
+
if (list.length === 0) {
|
|
258
|
+
const current = parseJsonLines(file);
|
|
259
|
+
return { removed: 0, remaining: current.length };
|
|
250
260
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
261
|
+
|
|
262
|
+
const idSet = new Set();
|
|
263
|
+
const legacySerialized = new Set();
|
|
264
|
+
for (const item of list) {
|
|
265
|
+
if (!item) continue;
|
|
266
|
+
if (typeof item === "string") {
|
|
267
|
+
idSet.add(item);
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
if (typeof item === "object") {
|
|
271
|
+
if (item.entry_id) {
|
|
272
|
+
idSet.add(String(item.entry_id));
|
|
273
|
+
} else {
|
|
274
|
+
legacySerialized.add(JSON.stringify(item));
|
|
275
|
+
}
|
|
256
276
|
}
|
|
257
277
|
}
|
|
258
|
-
}
|
|
259
278
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
const keptLines = [];
|
|
267
|
-
let removed = 0;
|
|
268
|
-
for (const line of lines) {
|
|
269
|
-
let parsed = null;
|
|
270
|
-
try {
|
|
271
|
-
parsed = JSON.parse(line);
|
|
272
|
-
} catch {
|
|
273
|
-
parsed = null;
|
|
279
|
+
const raw = fs.readFileSync(file, "utf8");
|
|
280
|
+
const lines = raw.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
281
|
+
if (lines.length === 0) {
|
|
282
|
+
return { removed: 0, remaining: 0 };
|
|
274
283
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
284
|
+
|
|
285
|
+
const keptLines = [];
|
|
286
|
+
let removed = 0;
|
|
287
|
+
for (const line of lines) {
|
|
288
|
+
let parsed = null;
|
|
289
|
+
try {
|
|
290
|
+
parsed = JSON.parse(line);
|
|
291
|
+
} catch {
|
|
292
|
+
parsed = null;
|
|
280
293
|
}
|
|
281
|
-
if (
|
|
282
|
-
|
|
283
|
-
|
|
294
|
+
if (parsed && typeof parsed === "object") {
|
|
295
|
+
const id = parsed.entry_id ? String(parsed.entry_id) : "";
|
|
296
|
+
if (id && idSet.has(id)) {
|
|
297
|
+
removed += 1;
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (!id && legacySerialized.has(JSON.stringify(parsed))) {
|
|
301
|
+
removed += 1;
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
284
304
|
}
|
|
305
|
+
keptLines.push(line);
|
|
285
306
|
}
|
|
286
|
-
keptLines.push(line);
|
|
287
|
-
}
|
|
288
307
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
308
|
+
if (keptLines.length === 0) {
|
|
309
|
+
fs.rmSync(file, { force: true });
|
|
310
|
+
return { removed, remaining: 0 };
|
|
311
|
+
}
|
|
293
312
|
|
|
294
|
-
|
|
295
|
-
|
|
313
|
+
writeFileAtomic(file, `${keptLines.join("\n")}\n`);
|
|
314
|
+
return { removed, remaining: keptLines.length };
|
|
315
|
+
});
|
|
296
316
|
}
|
|
297
317
|
|
|
298
318
|
function readReportSummary(projectRoot) {
|
|
@@ -2,6 +2,33 @@ const { getTimestamp, readJSON, writeJSON } = require("../bus/utils");
|
|
|
2
2
|
const { appendAgentRegistryDiagnostic, summarizeAgents } = require("./agentRegistryDiagnostics");
|
|
3
3
|
|
|
4
4
|
const AGENTS_SCHEMA_VERSION = 1;
|
|
5
|
+
const { withFileLock } = require("./fileLock");
|
|
6
|
+
const snapshots = new WeakMap();
|
|
7
|
+
const clone = (value) => JSON.parse(JSON.stringify(value));
|
|
8
|
+
|
|
9
|
+
function remember(data) {
|
|
10
|
+
snapshots.set(data, clone(data));
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Apply only fields changed since this caller's load. Unchanged fields and
|
|
15
|
+
// agents created by another process belong to the latest disk snapshot.
|
|
16
|
+
function applyChanges(current, baseline, next) {
|
|
17
|
+
const result = { ...current };
|
|
18
|
+
for (const key of new Set([...Object.keys(baseline), ...Object.keys(next)])) {
|
|
19
|
+
if (JSON.stringify(baseline[key]) === JSON.stringify(next[key])) continue;
|
|
20
|
+
if (!Object.prototype.hasOwnProperty.call(next, key)) {
|
|
21
|
+
delete result[key];
|
|
22
|
+
} else if (baseline[key] && next[key] && typeof baseline[key] === "object"
|
|
23
|
+
&& typeof next[key] === "object" && !Array.isArray(next[key])) {
|
|
24
|
+
// A stale writer must not resurrect a concurrently removed record.
|
|
25
|
+
if (result[key]) result[key] = applyChanges(result[key], baseline[key], next[key]);
|
|
26
|
+
} else {
|
|
27
|
+
result[key] = next[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
5
32
|
|
|
6
33
|
function toSafeString(value) {
|
|
7
34
|
return typeof value === "string" ? value : "";
|
|
@@ -94,7 +121,7 @@ function loadAgentsData(filePath) {
|
|
|
94
121
|
source: "ufoo.agentsStore.loadAgentsData",
|
|
95
122
|
reason: "missing_or_unreadable_registry",
|
|
96
123
|
});
|
|
97
|
-
return normalizeAgentsData({});
|
|
124
|
+
return remember(normalizeAgentsData({}));
|
|
98
125
|
}
|
|
99
126
|
const normalized = normalizeAgentsData(data);
|
|
100
127
|
const beforeSummary = summarizeAgents(data);
|
|
@@ -106,7 +133,7 @@ function loadAgentsData(filePath) {
|
|
|
106
133
|
after: afterSummary,
|
|
107
134
|
});
|
|
108
135
|
}
|
|
109
|
-
return normalized;
|
|
136
|
+
return remember(normalized);
|
|
110
137
|
}
|
|
111
138
|
|
|
112
139
|
function parseTimestampMs(value) {
|
|
@@ -137,18 +164,31 @@ function mergeExternalActivityFields(targetMeta, diskMeta) {
|
|
|
137
164
|
if (preferDisk) {
|
|
138
165
|
targetMeta.activity_state = diskState;
|
|
139
166
|
targetMeta.activity_since = diskSince;
|
|
167
|
+
if (diskMeta.activity_detail) targetMeta.activity_detail = diskMeta.activity_detail;
|
|
168
|
+
else delete targetMeta.activity_detail;
|
|
140
169
|
}
|
|
141
170
|
}
|
|
142
171
|
|
|
143
172
|
function saveAgentsData(filePath, data, options = {}) {
|
|
173
|
+
return withFileLock(filePath, () => saveAgentsDataUnlocked(filePath, data, options));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function saveAgentsDataUnlocked(filePath, data, options = {}) {
|
|
144
177
|
const source = typeof options.source === "string" && options.source
|
|
145
178
|
? options.source
|
|
146
179
|
: "ufoo.agentsStore.saveAgentsData";
|
|
147
|
-
|
|
180
|
+
let normalized = normalizeAgentsData(data);
|
|
148
181
|
|
|
149
182
|
// Merge externally-managed fields from disk to avoid daemon in-memory writes
|
|
150
183
|
// overwriting fresher runner/notifier state updates.
|
|
151
184
|
const disk = readJSON(filePath, null);
|
|
185
|
+
if (!disk && require("fs").existsSync(filePath)) throw new Error(`Refusing to overwrite unreadable agent registry: ${filePath}`);
|
|
186
|
+
const baseline = snapshots.get(data);
|
|
187
|
+
if (disk) {
|
|
188
|
+
normalized = normalizeAgentsData(baseline
|
|
189
|
+
? applyChanges(normalizeAgentsData(disk), baseline, normalized)
|
|
190
|
+
: { ...disk, ...normalized, agents: { ...disk.agents, ...normalized.agents } });
|
|
191
|
+
}
|
|
152
192
|
if (disk && disk.agents && normalized.agents) {
|
|
153
193
|
const droppedIds = Object.keys(disk.agents)
|
|
154
194
|
.filter((id) => !Object.prototype.hasOwnProperty.call(normalized.agents, id))
|
|
@@ -177,6 +217,19 @@ function saveAgentsData(filePath, data, options = {}) {
|
|
|
177
217
|
});
|
|
178
218
|
}
|
|
179
219
|
writeJSON(filePath, normalized);
|
|
220
|
+
Object.assign(data, normalized);
|
|
221
|
+
remember(data);
|
|
222
|
+
return normalized;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function updateAgentsData(filePath, mutate, options = {}) {
|
|
226
|
+
return withFileLock(filePath, () => {
|
|
227
|
+
const data = loadAgentsData(filePath);
|
|
228
|
+
const result = mutate(data);
|
|
229
|
+
if (result && typeof result.then === "function") throw new Error("Agent mutations must be synchronous");
|
|
230
|
+
if (result !== false) saveAgentsDataUnlocked(filePath, data, options);
|
|
231
|
+
return result;
|
|
232
|
+
});
|
|
180
233
|
}
|
|
181
234
|
|
|
182
235
|
module.exports = {
|
|
@@ -184,4 +237,5 @@ module.exports = {
|
|
|
184
237
|
loadAgentsData,
|
|
185
238
|
saveAgentsData,
|
|
186
239
|
normalizeAgentsData,
|
|
240
|
+
updateAgentsData,
|
|
187
241
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { createResourceLease } = require("../../agents/runtime/tasks/resourceLease");
|
|
6
|
+
|
|
7
|
+
function createWorkspaceAccess({ projectRoot, externalWriters = () => [] } = {}) {
|
|
8
|
+
const root = fs.realpathSync(projectRoot);
|
|
9
|
+
const key = (workspaceRoot) => fs.realpathSync(workspaceRoot || root);
|
|
10
|
+
const stores = new Map();
|
|
11
|
+
function storeFor(workspaceRoot) {
|
|
12
|
+
const workspace = key(workspaceRoot);
|
|
13
|
+
if (!stores.has(workspace)) stores.set(workspace, createResourceLease({ file: path.join(workspace, ".ufoo", "agent", "runtime", "workspace-leases.json") }));
|
|
14
|
+
return stores.get(workspace);
|
|
15
|
+
}
|
|
16
|
+
// All hosts accessing the same directory use its lease, including a native
|
|
17
|
+
// ucode opened directly in a linked worktree.
|
|
18
|
+
const leases = Object.freeze(Object.fromEntries(["acquire", "release", "run"].map((method) => [method,
|
|
19
|
+
(args, ...rest) => storeFor(args.key)[method]({ ...args, key: key(args.key) }, ...rest)])));
|
|
20
|
+
return Object.freeze({
|
|
21
|
+
leases,
|
|
22
|
+
async run(context, operation) {
|
|
23
|
+
if (!["write", "edit", "bash"].includes(context.tool)) return operation();
|
|
24
|
+
const workspace = key(context.workspaceRoot);
|
|
25
|
+
const writers = workspace === root ? externalWriters(context) : [];
|
|
26
|
+
if (writers.length) return { ok: false, code: "workspace_busy", error: "external workers own or may write this workspace", owners: writers };
|
|
27
|
+
return leases.run({ key: workspace, ownerId: context.taskRunId || context.sessionId || `process-${process.pid}`, signal: context.signal }, operation);
|
|
28
|
+
},
|
|
29
|
+
async runTask(context, operation) {
|
|
30
|
+
const workspace = key(context.workspaceRoot);
|
|
31
|
+
return leases.run({ key: workspace, ownerId: context.taskRunId, signal: context.signal, wait: true }, operation);
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { createWorkspaceAccess };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function isInternalAgentMeta(meta = {}) {
|
|
4
|
+
return Boolean(meta) && String(meta.launch_mode || meta.launchMode || "").trim().toLowerCase() === "internal";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function isInternalDashboardEvent(data = {}, getMeta = () => null) {
|
|
8
|
+
const agentId = data.event === "activity_state_changed"
|
|
9
|
+
? data.subscriber || data.publisher
|
|
10
|
+
: data.report?.agent_id || data.publisher;
|
|
11
|
+
if (agentId === "ufoo-agent" || String(agentId || "").endsWith(":ufoo-agent")) {
|
|
12
|
+
return !data.target || data.target === "ufoo-agent" || isInternalAgentMeta(getMeta(data.target));
|
|
13
|
+
}
|
|
14
|
+
return isInternalAgentMeta(getMeta(agentId));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { isInternalAgentMeta, isInternalDashboardEvent };
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const IPC_REQUEST_TYPES = {
|
|
4
4
|
STATUS: "status",
|
|
5
5
|
PROMPT: "prompt",
|
|
6
|
+
AGENT_RUNTIME: "agent_runtime",
|
|
6
7
|
CRON: "cron",
|
|
7
8
|
BUS_SEND: "bus_send",
|
|
8
9
|
BUS_WATCH: "bus_watch",
|
|
@@ -30,6 +31,8 @@ const IPC_REQUEST_TYPES = {
|
|
|
30
31
|
const IPC_RESPONSE_TYPES = {
|
|
31
32
|
STATUS: "status",
|
|
32
33
|
RESPONSE: "response",
|
|
34
|
+
RUNTIME_EVENT: "runtime_event",
|
|
35
|
+
RUNTIME_RESULT: "runtime_result",
|
|
33
36
|
BUS: "bus",
|
|
34
37
|
ERROR: "error",
|
|
35
38
|
BUS_SEND_OK: "bus_send_ok",
|
|
@@ -45,9 +45,13 @@ const COMMAND_NAMES = Object.freeze([
|
|
|
45
45
|
"ui.resync.request",
|
|
46
46
|
"app.exit",
|
|
47
47
|
"multi.exit",
|
|
48
|
+
"multi.open",
|
|
49
|
+
"multi.toggle",
|
|
48
50
|
"multi.focus",
|
|
49
51
|
"multi.viewport",
|
|
50
52
|
"multi.raw",
|
|
53
|
+
"multi.scroll",
|
|
54
|
+
"multi.expand",
|
|
51
55
|
]);
|
|
52
56
|
|
|
53
57
|
const EVENT_NAMES = Object.freeze([
|