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
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const os = require("os");
|
|
3
3
|
const path = require("path");
|
|
4
|
-
const { loadAgentsData,
|
|
4
|
+
const { loadAgentsData, updateAgentsData } = require("../../coordination/state/agentsStore");
|
|
5
5
|
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
6
6
|
|
|
7
7
|
function persistProviderSession(projectRoot, subscriberId, payload) {
|
|
8
8
|
const filePath = getUfooPaths(projectRoot).agentsFile;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
return updateAgentsData(filePath, (data) => {
|
|
10
|
+
const meta = data.agents[subscriberId] || {};
|
|
11
|
+
if (meta.status === "inactive") return false;
|
|
12
|
+
if (Object.entries(data.agents).some(([id, other]) => id !== subscriberId
|
|
13
|
+
&& other.status === "active" && other.provider_session_id === payload.sessionId)) return false;
|
|
14
|
+
data.agents[subscriberId] = {
|
|
15
|
+
...meta,
|
|
16
|
+
provider_session_id: payload.sessionId || "",
|
|
17
|
+
provider_session_source: payload.source || "",
|
|
18
|
+
provider_session_updated_at: new Date().toISOString(),
|
|
19
|
+
};
|
|
20
|
+
return true;
|
|
21
|
+
});
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
function loadProviderSessionCache(projectRoot) {
|
|
@@ -56,9 +60,46 @@ function resolveClaudeSessionFromFile(pid) {
|
|
|
56
60
|
* Codex writes ~/.codex/sessions/YYYY/MM/DD/rollout-<ts>-<id>.jsonl
|
|
57
61
|
* First line contains { type: "session_meta", payload: { id, cwd, ... } }
|
|
58
62
|
*/
|
|
59
|
-
function
|
|
63
|
+
function readFirstJsonLine(filePath) {
|
|
64
|
+
const fd = fs.openSync(filePath, "r");
|
|
65
|
+
const chunks = [];
|
|
66
|
+
let total = 0;
|
|
67
|
+
try {
|
|
68
|
+
// Modern session_meta includes base instructions and can exceed 4 KB.
|
|
69
|
+
// Bound memory while reading the complete first JSON record.
|
|
70
|
+
while (total < 2 * 1024 * 1024) {
|
|
71
|
+
const buffer = Buffer.alloc(64 * 1024);
|
|
72
|
+
const size = fs.readSync(fd, buffer, 0, buffer.length, null);
|
|
73
|
+
if (!size) return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
74
|
+
const newline = buffer.subarray(0, size).indexOf(10);
|
|
75
|
+
chunks.push(buffer.subarray(0, newline === -1 ? size : newline));
|
|
76
|
+
total += size;
|
|
77
|
+
if (newline !== -1) return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
} finally { fs.closeSync(fd); }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function resolveCodexSessionFromFile(cwd, options = {}) {
|
|
60
84
|
if (!cwd) return null;
|
|
61
85
|
try {
|
|
86
|
+
let expectedSession = String(options.sessionId || "");
|
|
87
|
+
let startedAt = options.startedAt || "";
|
|
88
|
+
let claimedSessions = new Set();
|
|
89
|
+
if (options.projectRoot && options.subscriberId) {
|
|
90
|
+
const data = loadAgentsData(getUfooPaths(options.projectRoot).agentsFile);
|
|
91
|
+
const own = data.agents[options.subscriberId];
|
|
92
|
+
if (!own || own.status !== "active") return null;
|
|
93
|
+
expectedSession = expectedSession || own.provider_session_id || "";
|
|
94
|
+
startedAt = startedAt || own.joined_at || "";
|
|
95
|
+
const peers = Object.entries(data.agents).filter(([id, meta]) => id !== options.subscriberId
|
|
96
|
+
&& meta.status === "active" && meta.agent_type === "codex");
|
|
97
|
+
// Cwd is not a process identity. Parallel launches must bind through an
|
|
98
|
+
// exact provider session id instead of racing for the newest rollout.
|
|
99
|
+
if (!expectedSession && peers.length) return null;
|
|
100
|
+
claimedSessions = new Set(peers.map(([, meta]) => meta.provider_session_id).filter(Boolean));
|
|
101
|
+
}
|
|
102
|
+
const startedAtMs = Date.parse(startedAt);
|
|
62
103
|
const now = new Date();
|
|
63
104
|
// Check today and yesterday (session may have started before midnight)
|
|
64
105
|
const dates = [now];
|
|
@@ -66,14 +107,14 @@ function resolveCodexSessionFromFile(cwd) {
|
|
|
66
107
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
67
108
|
dates.push(yesterday);
|
|
68
109
|
|
|
69
|
-
|
|
70
|
-
let bestMtime = 0;
|
|
110
|
+
const matches = new Map();
|
|
71
111
|
|
|
72
112
|
for (const d of dates) {
|
|
73
113
|
const yyyy = String(d.getFullYear());
|
|
74
114
|
const mm = String(d.getMonth() + 1).padStart(2, "0");
|
|
75
115
|
const dd = String(d.getDate()).padStart(2, "0");
|
|
76
|
-
const
|
|
116
|
+
const codexHome = options.codexHome || process.env.CODEX_HOME || path.join(os.homedir(), ".codex");
|
|
117
|
+
const dir = path.join(codexHome, "sessions", yyyy, mm, dd);
|
|
77
118
|
if (!fs.existsSync(dir)) continue;
|
|
78
119
|
|
|
79
120
|
const files = fs.readdirSync(dir)
|
|
@@ -83,31 +124,24 @@ function resolveCodexSessionFromFile(cwd) {
|
|
|
83
124
|
const filePath = path.join(dir, file);
|
|
84
125
|
try {
|
|
85
126
|
const stat = fs.statSync(filePath);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// Read first line for session_meta
|
|
89
|
-
const fd = fs.openSync(filePath, "r");
|
|
90
|
-
const buf = Buffer.alloc(4096);
|
|
91
|
-
const bytesRead = fs.readSync(fd, buf, 0, 4096, 0);
|
|
92
|
-
fs.closeSync(fd);
|
|
93
|
-
const firstLine = buf.toString("utf8", 0, bytesRead).split("\n")[0];
|
|
94
|
-
if (!firstLine) continue;
|
|
95
|
-
|
|
96
|
-
const record = JSON.parse(firstLine);
|
|
127
|
+
const record = readFirstJsonLine(filePath);
|
|
128
|
+
if (!record) continue;
|
|
97
129
|
const payload = record.payload || record;
|
|
98
130
|
const sessionCwd = payload.cwd || "";
|
|
99
131
|
const sessionId = payload.id || "";
|
|
100
132
|
|
|
101
|
-
if (sessionId
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
133
|
+
if (!sessionId || sessionCwd !== cwd || claimedSessions.has(sessionId)) continue;
|
|
134
|
+
if (expectedSession && sessionId !== expectedSession) continue;
|
|
135
|
+
const createdAt = Date.parse(payload.timestamp || record.timestamp || "");
|
|
136
|
+
if (!expectedSession && Number.isFinite(startedAtMs)
|
|
137
|
+
&& (Number.isFinite(createdAt) ? createdAt : stat.birthtimeMs) < startedAtMs) continue;
|
|
138
|
+
matches.set(sessionId, { sessionId, source: filePath });
|
|
105
139
|
} catch {
|
|
106
140
|
continue;
|
|
107
141
|
}
|
|
108
142
|
}
|
|
109
143
|
}
|
|
110
|
-
return
|
|
144
|
+
return matches.size === 1 ? matches.values().next().value : null;
|
|
111
145
|
} catch {
|
|
112
146
|
return null;
|
|
113
147
|
}
|
|
@@ -158,7 +192,7 @@ function resolveSessionFromFile(agentType, opts = {}) {
|
|
|
158
192
|
return resolveClaudeSessionFromFile(opts.pid);
|
|
159
193
|
}
|
|
160
194
|
if (agentType === "codex") {
|
|
161
|
-
return resolveCodexSessionFromFile(opts.cwd);
|
|
195
|
+
return resolveCodexSessionFromFile(opts.cwd, opts);
|
|
162
196
|
}
|
|
163
197
|
if (agentType === "kimi") {
|
|
164
198
|
return resolveKimiSessionFromIndex(opts.cwd);
|
|
@@ -222,13 +256,13 @@ function scheduleProviderSessionResolve({
|
|
|
222
256
|
}
|
|
223
257
|
|
|
224
258
|
// 1. Try direct file read (fast, non-invasive)
|
|
225
|
-
const fileOpts = { pid: agentPid, cwd: agentCwd || projectRoot };
|
|
259
|
+
const fileOpts = { pid: agentPid, cwd: agentCwd || projectRoot, projectRoot, subscriberId };
|
|
226
260
|
const fileResolved = await resolveSessionFromFileWithRetries(
|
|
227
261
|
agentType, fileOpts, fileAttempts, fileIntervalMs,
|
|
228
262
|
);
|
|
229
263
|
if (cancelled) return;
|
|
230
264
|
if (fileResolved && fileResolved.sessionId) {
|
|
231
|
-
persistProviderSession(projectRoot, subscriberId, fileResolved);
|
|
265
|
+
if (!persistProviderSession(projectRoot, subscriberId, fileResolved)) return;
|
|
232
266
|
if (typeof onResolved === "function") {
|
|
233
267
|
onResolved(subscriberId, fileResolved);
|
|
234
268
|
}
|
|
@@ -15,6 +15,9 @@ const {
|
|
|
15
15
|
const REPORT_CONTROL_TARGET = "ufoo-agent";
|
|
16
16
|
const REPORT_CONTROL_EVENT = "agent_report";
|
|
17
17
|
const REPORT_CONTROL_TYPE = "control/report";
|
|
18
|
+
const { withFileLock } = require("../../coordination/state/fileLock");
|
|
19
|
+
const { normalizeReportInput, normalizePhase, loadReportState } = require("../../coordination/report/store");
|
|
20
|
+
const draining = new Set();
|
|
18
21
|
|
|
19
22
|
function getReportControlQueueDir(projectRoot) {
|
|
20
23
|
const paths = getUfooPaths(projectRoot);
|
|
@@ -60,35 +63,66 @@ function buildReportControlEvent(report = {}, options = {}) {
|
|
|
60
63
|
|
|
61
64
|
async function enqueueAgentReport(projectRoot, report, options = {}) {
|
|
62
65
|
ensureReportControlQueue(projectRoot);
|
|
66
|
+
return withFileLock(getReportControlQueueFile(projectRoot), () => {
|
|
67
|
+
const queue = new DeliveryQueue(getReportControlQueueFile(projectRoot));
|
|
68
|
+
const publisher = options.publisher || resolveReportPublisher(report);
|
|
69
|
+
const pending = { ...(loadReportState(projectRoot).agents[publisher]?.pending || {}) };
|
|
70
|
+
const controls = [...queue.processingFiles().flatMap((file) => {
|
|
71
|
+
return require("../../coordination/bus/utils").readJSONL(file);
|
|
72
|
+
}), ...queue.readPendingRaw()];
|
|
73
|
+
for (const control of controls) {
|
|
74
|
+
const entry = control.data?.report;
|
|
75
|
+
if (!entry || entry.agent_id !== publisher) continue;
|
|
76
|
+
if (["start", "progress"].includes(entry.phase)) pending[entry.task_id] = entry;
|
|
77
|
+
else delete pending[entry.task_id];
|
|
78
|
+
}
|
|
79
|
+
let taskId = String(report.task_id || report.taskId || report.task || "").trim();
|
|
80
|
+
if (!taskId && normalizePhase(report.phase) !== "start") {
|
|
81
|
+
const tasks = Object.keys(pending);
|
|
82
|
+
if (tasks.length > 1) throw new Error("Multiple active tasks; specify --task / task_id for this report");
|
|
83
|
+
taskId = tasks[0];
|
|
84
|
+
}
|
|
85
|
+
const entry = normalizeReportInput({ ...report, agent_id: publisher, task_id: taskId });
|
|
86
|
+
const event = normalizeQueueEnvelope(buildReportControlEvent(entry, options), {
|
|
87
|
+
queueType: QUEUE_TYPES.REPORT,
|
|
88
|
+
delivery: { mode: "daemon_consume", gate: "none", max_inflight: 1 },
|
|
89
|
+
ack: { policy: "on_consume" },
|
|
90
|
+
});
|
|
91
|
+
queue.append(event);
|
|
63
92
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
93
|
+
return {
|
|
94
|
+
queued: true,
|
|
95
|
+
request_id: event.data.request_id,
|
|
96
|
+
target: REPORT_CONTROL_TARGET,
|
|
97
|
+
targets: [REPORT_CONTROL_TARGET],
|
|
98
|
+
report: entry,
|
|
99
|
+
};
|
|
68
100
|
});
|
|
69
|
-
new DeliveryQueue(getReportControlQueueFile(projectRoot)).append(event);
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
queued: true,
|
|
73
|
-
request_id: event.data.request_id,
|
|
74
|
-
target: REPORT_CONTROL_TARGET,
|
|
75
|
-
targets: [REPORT_CONTROL_TARGET],
|
|
76
|
-
report,
|
|
77
|
-
};
|
|
78
101
|
}
|
|
79
102
|
|
|
80
|
-
function
|
|
103
|
+
async function drainReportControlEvents(projectRoot, handle) {
|
|
81
104
|
const queueFile = getReportControlQueueFile(projectRoot);
|
|
105
|
+
if (draining.has(queueFile)) return 0;
|
|
106
|
+
draining.add(queueFile);
|
|
82
107
|
const queue = new DeliveryQueue(queueFile);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
108
|
+
let consumed = 0;
|
|
109
|
+
try {
|
|
110
|
+
while (true) {
|
|
111
|
+
const claim = withFileLock(queueFile, () => {
|
|
112
|
+
queue.recover();
|
|
113
|
+
if (queue.processingFiles().length) return null;
|
|
114
|
+
return queue.claimNext();
|
|
115
|
+
});
|
|
116
|
+
if (!claim) break;
|
|
117
|
+
try {
|
|
118
|
+
const handled = await handle(claim.event);
|
|
119
|
+
if (handled === false) { queue.restoreClaim(claim); break; }
|
|
120
|
+
queue.completeClaim(claim);
|
|
121
|
+
consumed += 1;
|
|
122
|
+
} catch (error) { queue.restoreClaim(claim); throw error; }
|
|
123
|
+
}
|
|
124
|
+
return consumed;
|
|
125
|
+
} finally { draining.delete(queueFile); }
|
|
92
126
|
}
|
|
93
127
|
|
|
94
128
|
function isAgentReportControlEvent(evt) {
|
|
@@ -104,7 +138,7 @@ function extractAgentReportControl(evt) {
|
|
|
104
138
|
if (!isAgentReportControlEvent(evt)) return null;
|
|
105
139
|
const data = evt.data && typeof evt.data === "object" ? evt.data : {};
|
|
106
140
|
return {
|
|
107
|
-
report: data.report,
|
|
141
|
+
report: normalizeReportInput(data.report, { entry_id: data.request_id, ts: data.report.ts || data.queued_at || evt.timestamp || evt.ts }),
|
|
108
142
|
request_id: data.request_id || "",
|
|
109
143
|
queued_at: data.queued_at || evt.timestamp || evt.ts || "",
|
|
110
144
|
};
|
|
@@ -121,7 +155,7 @@ module.exports = {
|
|
|
121
155
|
buildReportControlData,
|
|
122
156
|
buildReportControlEvent,
|
|
123
157
|
enqueueAgentReport,
|
|
124
|
-
|
|
158
|
+
drainReportControlEvents,
|
|
125
159
|
isAgentReportControlEvent,
|
|
126
160
|
extractAgentReportControl,
|
|
127
161
|
};
|
|
@@ -4,7 +4,7 @@ const { getUfooPaths } = require("../../coordination/state/paths");
|
|
|
4
4
|
const { isMetaActive } = require("../../coordination/bus/utils");
|
|
5
5
|
const { resolveDisplayNickname, resolveScopedNickname } = require("./nicknameScope");
|
|
6
6
|
const { readReportSummary, countControllerInboxEntries } = require("../../coordination/report/store");
|
|
7
|
-
const {
|
|
7
|
+
const { reconcileGroupStatus } = require("./groupStatus");
|
|
8
8
|
|
|
9
9
|
function readBus(projectRoot) {
|
|
10
10
|
const busPath = getUfooPaths(projectRoot).agentsFile;
|
|
@@ -83,7 +83,7 @@ function normalizeCronTasks(raw = []) {
|
|
|
83
83
|
}));
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
function readGroups(projectRoot) {
|
|
86
|
+
function readGroups(projectRoot, agents = {}) {
|
|
87
87
|
const groupsDir = getUfooPaths(projectRoot).groupsDir;
|
|
88
88
|
if (!groupsDir || !fs.existsSync(groupsDir)) {
|
|
89
89
|
return { count: 0, active: 0, failed: 0, stopped: 0, items: [] };
|
|
@@ -97,7 +97,7 @@ function readGroups(projectRoot) {
|
|
|
97
97
|
for (const file of files) {
|
|
98
98
|
const filePath = path.join(groupsDir, file);
|
|
99
99
|
try {
|
|
100
|
-
const raw = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
100
|
+
const raw = reconcileGroupStatus(JSON.parse(fs.readFileSync(filePath, "utf8")), agents);
|
|
101
101
|
const members = Array.isArray(raw.members) ? raw.members : [];
|
|
102
102
|
const membersActive = members.filter((item) => item && (item.status === "active" || item.status === "reused")).length;
|
|
103
103
|
items.push({
|
|
@@ -117,7 +117,7 @@ function readGroups(projectRoot) {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
items.sort((a, b) => String(b.updated_at || "").localeCompare(String(a.updated_at || "")));
|
|
120
|
-
const active = items.filter((item) => item.status === "active").length;
|
|
120
|
+
const active = items.filter((item) => item.status === "active" || item.status === "partial").length;
|
|
121
121
|
const failed = items.filter((item) => item.status === "failed").length;
|
|
122
122
|
const stopped = items.filter((item) => item.status === "stopped").length;
|
|
123
123
|
return {
|
|
@@ -135,7 +135,7 @@ function buildStatus(projectRoot, options = {}) {
|
|
|
135
135
|
const unread = readUnread(projectRoot);
|
|
136
136
|
const reports = readReportSummary(projectRoot);
|
|
137
137
|
const controllerPendingTotal = countControllerInboxEntries(projectRoot, "ufoo-agent");
|
|
138
|
-
const groups = readGroups(projectRoot);
|
|
138
|
+
const groups = readGroups(projectRoot, bus?.agents || {});
|
|
139
139
|
const subscribers = bus ? Object.keys(bus.agents || {}) : [];
|
|
140
140
|
const cronTasks = normalizeCronTasks(options.cronTasks || []);
|
|
141
141
|
|
|
@@ -168,6 +168,10 @@ function buildStatus(projectRoot, options = {}) {
|
|
|
168
168
|
activity_state,
|
|
169
169
|
activity_since,
|
|
170
170
|
activity_detail,
|
|
171
|
+
native_delivery: meta?.native_delivery || "",
|
|
172
|
+
native_delivery_ready: meta?.native_delivery_ready === true,
|
|
173
|
+
native_delivery_version: meta?.native_delivery_version || "",
|
|
174
|
+
native_delivery_diagnostic: meta?.native_delivery_diagnostic || "",
|
|
171
175
|
host_inject_sock: meta?.host_inject_sock || "",
|
|
172
176
|
host_daemon_sock: meta?.host_daemon_sock || "",
|
|
173
177
|
host_name: meta?.host_name || "",
|
|
@@ -187,7 +191,6 @@ function buildStatus(projectRoot, options = {}) {
|
|
|
187
191
|
controller: {
|
|
188
192
|
pending_total: controllerPendingTotal,
|
|
189
193
|
},
|
|
190
|
-
loop: readRecentLoopSummary(projectRoot),
|
|
191
194
|
cron: {
|
|
192
195
|
count: cronTasks.length,
|
|
193
196
|
tasks: cronTasks,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const REDACTED = "[REDACTED]";
|
|
4
|
-
const SENSITIVE_KEY_PATTERN = /(^|_|-)(authorization|accesstoken|access_token|refreshtoken|refresh_token|apikey|api_key|tokenhash|token_hash)$/i;
|
|
4
|
+
const SENSITIVE_KEY_PATTERN = /(^|_|-)(authorization|accesstoken|access_token|refreshtoken|refresh_token|apikey|api_key|tokenhash|token_hash|agenthandle|agent_handle)$/i;
|
|
5
5
|
const BEARER_PATTERN = /\bBearer\s+[A-Za-z0-9._~+/=-]+\b/gi;
|
|
6
|
-
const INLINE_SECRET_ASSIGNMENT_PATTERN = /\b(api[_-]?key|access[_-]?token|refresh[_-]?token|token)\s*[:=]\s*["']?([A-Za-z0-9._~+/=-]{8,})["']?/gi;
|
|
6
|
+
const INLINE_SECRET_ASSIGNMENT_PATTERN = /\b(api[_-]?key|access[_-]?token|refresh[_-]?token|(?:UFOO_)?agent[_-]?handle|token)\s*[:=]\s*["']?([A-Za-z0-9._~+/=-]{8,})["']?/gi;
|
|
7
7
|
|
|
8
8
|
function isPlainObject(value) {
|
|
9
9
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
@@ -13,7 +13,8 @@ function normalizeProjectRoot(projectRoot) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function resolveGlobalControllerProjectRoot() {
|
|
16
|
-
|
|
16
|
+
const root = trimTrailingSlashes(path.resolve(os.homedir()));
|
|
17
|
+
try { return canonicalProjectRoot(root); } catch { return root; }
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
function resolveGlobalControllerUfooDir() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
+
const { withFileLock } = require("../../coordination/state/fileLock");
|
|
2
3
|
const os = require("os");
|
|
3
4
|
const path = require("path");
|
|
4
5
|
const { canonicalProjectRoot, buildProjectId, trimTrailingSlashes } = require("./projectId");
|
|
@@ -33,6 +34,7 @@ function canonicalizeForRecord(projectRoot) {
|
|
|
33
34
|
|
|
34
35
|
function resolveRuntimeDir(options = {}) {
|
|
35
36
|
if (options.runtimeDir) return options.runtimeDir;
|
|
37
|
+
if (process.env.UFOO_PROJECT_RUNTIME_DIR) return path.resolve(process.env.UFOO_PROJECT_RUNTIME_DIR);
|
|
36
38
|
return path.join(os.homedir(), ".ufoo", "projects", "runtime");
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -117,6 +119,16 @@ function isSocketAlive(socketPath) {
|
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
|
|
122
|
+
function projectPathExists(projectRoot) {
|
|
123
|
+
try {
|
|
124
|
+
fs.statSync(projectRoot);
|
|
125
|
+
return true;
|
|
126
|
+
} catch (err) {
|
|
127
|
+
// Permission and transient IO failures are not proof of deletion.
|
|
128
|
+
return !["ENOENT", "ENOTDIR"].includes(err.code);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
120
132
|
function normalizeStatus(value, fallback = "running") {
|
|
121
133
|
const raw = String(value || "").trim().toLowerCase();
|
|
122
134
|
if (
|
|
@@ -165,52 +177,58 @@ function upsertProjectRuntime(entry = {}, options = {}) {
|
|
|
165
177
|
const projectRoot = entry.projectRoot || entry.project_root;
|
|
166
178
|
if (!projectRoot) throw new Error("projectRoot is required");
|
|
167
179
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
180
|
+
return withFileLock(runtimeFilePathByProjectRoot(projectRoot, options), () => {
|
|
181
|
+
const existing = readProjectRuntimeByRoot(projectRoot, options) || {};
|
|
182
|
+
const normalized = normalizeRuntimeEntry({
|
|
183
|
+
...existing,
|
|
184
|
+
...entry,
|
|
185
|
+
project_root: projectRoot,
|
|
186
|
+
project_name: entry.projectName || entry.project_name || existing.project_name,
|
|
187
|
+
daemon_pid: parseDaemonPid(entry.daemonPid ?? entry.daemon_pid, existing.daemon_pid),
|
|
188
|
+
socket_path: entry.socketPath || entry.socket_path || existing.socket_path,
|
|
189
|
+
status: normalizeStatus(entry.status, existing.status || "running"),
|
|
190
|
+
last_seen: normalizeIsoTimestamp(entry.lastSeen || entry.last_seen || new Date().toISOString()),
|
|
191
|
+
last_switch_at: entry.lastSwitchAt || entry.last_switch_at || existing.last_switch_at,
|
|
192
|
+
}, projectRoot);
|
|
193
|
+
|
|
194
|
+
const filePath = runtimeFilePathByProjectId(normalized.project_id, options);
|
|
195
|
+
writeJsonAtomic(filePath, normalized);
|
|
196
|
+
return normalized;
|
|
197
|
+
});
|
|
184
198
|
}
|
|
185
199
|
|
|
186
200
|
function markProjectStopped(projectRoot, options = {}) {
|
|
187
201
|
if (!projectRoot) return null;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
202
|
+
return withFileLock(runtimeFilePathByProjectRoot(projectRoot, options), () => {
|
|
203
|
+
const existing = readProjectRuntimeByRoot(projectRoot, options);
|
|
204
|
+
const paths = getUfooPaths(canonicalizeForRecord(projectRoot));
|
|
205
|
+
return upsertProjectRuntime({
|
|
206
|
+
projectRoot,
|
|
207
|
+
projectName: existing ? existing.project_name : path.basename(projectRoot),
|
|
208
|
+
daemonPid: existing ? existing.daemon_pid : null,
|
|
209
|
+
socketPath: existing ? existing.socket_path : paths.ufooSock,
|
|
210
|
+
status: "stopped",
|
|
211
|
+
lastSeen: new Date().toISOString(),
|
|
212
|
+
lastSwitchAt: existing ? existing.last_switch_at : undefined,
|
|
213
|
+
}, options);
|
|
214
|
+
});
|
|
199
215
|
}
|
|
200
216
|
|
|
201
217
|
function markProjectDormant(projectRoot, options = {}) {
|
|
202
218
|
if (!projectRoot) return null;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
219
|
+
return withFileLock(runtimeFilePathByProjectRoot(projectRoot, options), () => {
|
|
220
|
+
const existing = readProjectRuntimeByRoot(projectRoot, options);
|
|
221
|
+
const paths = getUfooPaths(canonicalizeForRecord(projectRoot));
|
|
222
|
+
return upsertProjectRuntime({
|
|
223
|
+
projectRoot,
|
|
224
|
+
projectName: existing ? existing.project_name : path.basename(projectRoot),
|
|
225
|
+
daemonPid: existing ? existing.daemon_pid : process.pid,
|
|
226
|
+
socketPath: existing ? existing.socket_path : paths.ufooSock,
|
|
227
|
+
status: "dormant",
|
|
228
|
+
lastSeen: new Date().toISOString(),
|
|
229
|
+
lastSwitchAt: existing ? existing.last_switch_at : undefined,
|
|
230
|
+
}, options);
|
|
231
|
+
});
|
|
214
232
|
}
|
|
215
233
|
|
|
216
234
|
function validateProjectRuntime(entry = {}, options = {}) {
|
|
@@ -239,6 +257,7 @@ function validateProjectRuntime(entry = {}, options = {}) {
|
|
|
239
257
|
...entry,
|
|
240
258
|
status,
|
|
241
259
|
validation: {
|
|
260
|
+
project_exists: projectPathExists(entry.project_root),
|
|
242
261
|
pid_alive: pidAlive,
|
|
243
262
|
socket_alive: socketAlive,
|
|
244
263
|
stale_ttl_ms: staleTtlMs,
|
|
@@ -248,6 +267,45 @@ function validateProjectRuntime(entry = {}, options = {}) {
|
|
|
248
267
|
};
|
|
249
268
|
}
|
|
250
269
|
|
|
270
|
+
// Archive only abandoned registrations whose workspace is gone. Keep dormant
|
|
271
|
+
// projects, live daemons, and recent records. Reads never perform this mutation.
|
|
272
|
+
function archiveMissingProjectRuntimes(options = {}) {
|
|
273
|
+
const runtimeDir = resolveRuntimeDir(options);
|
|
274
|
+
const archiveDir = options.archiveDir || path.join(path.dirname(runtimeDir), "archive", String(Date.now()));
|
|
275
|
+
const nowMs = Number.isFinite(options.nowMs) ? options.nowMs : Date.now();
|
|
276
|
+
const archived = [];
|
|
277
|
+
if (!fs.existsSync(runtimeDir)) return { count: 0, archive_dir: archiveDir, projects: archived };
|
|
278
|
+
for (const file of fs.readdirSync(runtimeDir).filter((name) => name.endsWith(".json")).sort()) {
|
|
279
|
+
const source = path.join(runtimeDir, file);
|
|
280
|
+
try {
|
|
281
|
+
const row = withFileLock(source, () => {
|
|
282
|
+
if (!fs.lstatSync(source).isFile()) return null;
|
|
283
|
+
const raw = fs.readFileSync(source, "utf8");
|
|
284
|
+
const parsed = JSON.parse(raw);
|
|
285
|
+
if (!parsed.project_root || !parsed.last_seen || !Number.isFinite(Date.parse(parsed.last_seen))) return null;
|
|
286
|
+
const row = validateProjectRuntime(normalizeRuntimeEntry(parsed), { ...options, nowMs });
|
|
287
|
+
if (row.validation.project_exists || row.validation.pid_alive || row.validation.socket_alive
|
|
288
|
+
|| row.validation.age_ms <= DEFAULT_STALE_TTL_MS) return null;
|
|
289
|
+
if (options.dryRun !== false) {
|
|
290
|
+
return row;
|
|
291
|
+
}
|
|
292
|
+
// An upsert may have refreshed the record since it was examined.
|
|
293
|
+
if (fs.readFileSync(source, "utf8") !== raw || projectPathExists(row.project_root)) return null;
|
|
294
|
+
ensureDir(archiveDir);
|
|
295
|
+
const destination = path.join(archiveDir, file);
|
|
296
|
+
if (fs.existsSync(destination)) throw new Error(`Archive already exists: ${destination}`);
|
|
297
|
+
fs.renameSync(source, destination);
|
|
298
|
+
return row;
|
|
299
|
+
});
|
|
300
|
+
if (row) archived.push(row);
|
|
301
|
+
} catch (err) {
|
|
302
|
+
if (err.code === "ENOENT" || err instanceof SyntaxError) continue;
|
|
303
|
+
throw err;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return { count: archived.length, archive_dir: archiveDir, projects: archived };
|
|
307
|
+
}
|
|
308
|
+
|
|
251
309
|
function listProjectRuntimes(options = {}) {
|
|
252
310
|
const runtimeDir = resolveRuntimeDir(options);
|
|
253
311
|
if (!fs.existsSync(runtimeDir)) return [];
|
|
@@ -298,4 +356,6 @@ module.exports = {
|
|
|
298
356
|
listProjectRuntimes,
|
|
299
357
|
getCurrentProjectRuntime,
|
|
300
358
|
validateProjectRuntime,
|
|
359
|
+
projectPathExists,
|
|
360
|
+
archiveMissingProjectRuntimes,
|
|
301
361
|
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { INTERNAL_AGENT_TYPES } = require("../runtime/contracts/agentMode");
|
|
3
|
+
|
|
4
|
+
const string = { type: "string", minLength: 1 };
|
|
5
|
+
const command = { type: "string", pattern: "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,100}$" };
|
|
6
|
+
const strings = { type: "array", items: string, maxItems: 100 };
|
|
7
|
+
const schema = (name, description, required, properties) => Object.freeze({ name, description, schema_version: "1.0",
|
|
8
|
+
allowed_tiers: ["controller"], input_schema: { type: "object", required, properties, additionalProperties: false },
|
|
9
|
+
output_schema: { type: "object" } });
|
|
10
|
+
const CONTROLLER_TOOL_SCHEMAS = Object.freeze({
|
|
11
|
+
delegate_task: schema("delegate_task", "Assign work with a stable command_id. To create a worker, pass agent and optional nickname; OMIT target. To reuse an active worker, pass its concrete subscriber ID or unique registered nickname in target. Never put an unregistered new nickname or a placeholder in target. Returns queue persistence, not completion.",
|
|
12
|
+
["command_id", "objective"], { command_id: command, objective: string,
|
|
13
|
+
target: { ...string, description: "Optional EXISTING active worker subscriber ID or unique registered nickname. Omit when creating a worker." },
|
|
14
|
+
agent: { type: "string", enum: INTERNAL_AGENT_TYPES, description: "Internal worker type to create when target is omitted; independent of the main model provider." },
|
|
15
|
+
nickname: { ...string, description: "Optional name for a NEW worker; it is not an existing target." }, acceptance_criteria: strings }),
|
|
16
|
+
read_task_reports: schema("read_task_reports", "Read delegated task ownership, delivery and report status. A terminal report still requires validation and acceptance.", [], { task_id: string }),
|
|
17
|
+
accept_task: schema("accept_task", "Accept or reject an unreviewed terminal worker report. Acceptance requires validation evidence and a reason; ordinary replies do not complete tasks.",
|
|
18
|
+
["task_id", "outcome", "reason"], { task_id: string, outcome: { type: "string", enum: ["accepted", "rejected"] }, reason: string, evidence: strings }),
|
|
19
|
+
manage_tasks: schema("manage_tasks", "Start independent coding task contexts without blocking the main conversation; inspect or cancel their durable runs. Reuse command_id on start retries.",
|
|
20
|
+
["operation"], { operation: { type: "string", enum: ["start", "inspect", "cancel", "list", "accept", "reject"] }, command_id: command, objective: string, task_run_id: string, reason: string, evidence: strings,
|
|
21
|
+
workspace: string, read_only: { type: "boolean" } }),
|
|
22
|
+
resume_agents: schema("resume_agents", "Inspect recoverable worker sessions or resume a selected worker through the project host.",
|
|
23
|
+
["operation"], { operation: { type: "string", enum: ["inspect", "resume"] }, target: string, command_id: command }),
|
|
24
|
+
manage_group: schema("manage_group", "Validate, start, stop or inspect project groups through the daemon group service. Use command_id for mutations.",
|
|
25
|
+
["operation"], { operation: { type: "string", enum: ["validate", "start", "stop", "status"] }, command_id: command, target: string, group_id: string }),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
module.exports = { CONTROLLER_TOOL_SCHEMAS };
|
|
@@ -69,8 +69,11 @@ async function dispatchMessageHandler(ctx = {}, args = {}) {
|
|
|
69
69
|
target,
|
|
70
70
|
source: subscriber,
|
|
71
71
|
mode,
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
// send/broadcast persist queue entries. The delivery scheduler or the
|
|
73
|
+
// recipient's MCP reader consumes them later, even in immediate mode.
|
|
74
|
+
delivered: 0,
|
|
75
|
+
queued: result.targets.length,
|
|
76
|
+
delivery_status: "queued",
|
|
74
77
|
targets: result.targets,
|
|
75
78
|
seq: result.seq,
|
|
76
79
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const { buildStatus } = require("../../runtime/daemon/status");
|
|
2
|
+
const { isInternalAgentMeta } = require("../../runtime/contracts/agentMode");
|
|
2
3
|
|
|
3
4
|
function listAgentsHandler(ctx = {}) {
|
|
4
5
|
const status = buildStatus(ctx.projectRoot);
|
|
5
|
-
const agents = Array.isArray(status.active_meta) ? status.active_meta : []
|
|
6
|
+
const agents = (Array.isArray(status.active_meta) ? status.active_meta : [])
|
|
7
|
+
.filter((agent) => !ctx.internalAgentsOnly || isInternalAgentMeta(agent));
|
|
6
8
|
return {
|
|
7
9
|
count: agents.length,
|
|
8
10
|
agents,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const { buildStatus } = require("../../runtime/daemon/status");
|
|
2
|
+
const { isInternalAgentMeta } = require("../../runtime/contracts/agentMode");
|
|
2
3
|
|
|
3
4
|
function readBusSummaryHandler(ctx = {}) {
|
|
4
5
|
const status = buildStatus(ctx.projectRoot);
|
|
5
|
-
const activeAgents = Array.isArray(status.active_meta) ? status.active_meta : []
|
|
6
|
+
const activeAgents = (Array.isArray(status.active_meta) ? status.active_meta : [])
|
|
7
|
+
.filter((agent) => !ctx.internalAgentsOnly || isInternalAgentMeta(agent));
|
|
6
8
|
const busyCount = activeAgents.filter((item) => {
|
|
7
9
|
const state = String((item && item.activity_state) || "").trim().toLowerCase();
|
|
8
10
|
return state === "working"
|