u-foo 3.1.7 → 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 -2667
- 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,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,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const string = { type: "string", minLength: 1 };
|
|
4
|
+
const command = { type: "string", pattern: "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,100}$" };
|
|
5
|
+
const strings = { type: "array", items: string, maxItems: 100 };
|
|
6
|
+
const schema = (name, description, required, properties) => Object.freeze({ name, description, schema_version: "1.0",
|
|
7
|
+
allowed_tiers: ["controller"], input_schema: { type: "object", required, properties, additionalProperties: false },
|
|
8
|
+
output_schema: { type: "object" } });
|
|
9
|
+
const CONTROLLER_TOOL_SCHEMAS = Object.freeze({
|
|
10
|
+
delegate_task: schema("delegate_task", "Delegate to a concrete worker, or durably launch and bind one first. Reuse command_id on retries. Returns queue persistence, not completion.",
|
|
11
|
+
["command_id", "objective"], { command_id: command, objective: string, target: string, agent: { type: "string", enum: ["codex", "claude", "ucode", "grok", "kimi", "agy"] }, nickname: string, acceptance_criteria: strings }),
|
|
12
|
+
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 }),
|
|
13
|
+
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.",
|
|
14
|
+
["task_id", "outcome", "reason"], { task_id: string, outcome: { type: "string", enum: ["accepted", "rejected"] }, reason: string, evidence: strings }),
|
|
15
|
+
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.",
|
|
16
|
+
["operation"], { operation: { type: "string", enum: ["start", "inspect", "cancel", "list", "accept", "reject"] }, command_id: command, objective: string, task_run_id: string, reason: string, evidence: strings,
|
|
17
|
+
workspace: string, read_only: { type: "boolean" } }),
|
|
18
|
+
resume_agents: schema("resume_agents", "Inspect recoverable worker sessions or resume a selected worker through the project host.",
|
|
19
|
+
["operation"], { operation: { type: "string", enum: ["inspect", "resume"] }, target: string, command_id: command }),
|
|
20
|
+
manage_group: schema("manage_group", "Validate, start, stop or inspect project groups through the daemon group service. Use command_id for mutations.",
|
|
21
|
+
["operation"], { operation: { type: "string", enum: ["validate", "start", "stop", "status"] }, command_id: command, target: string, group_id: string }),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
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"
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
const
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const { canonicalProjectRoot } = require("../../runtime/projects/projectId");
|
|
3
|
+
const { listProjectRuntimes, projectPathExists } = require("../../runtime/projects/registry");
|
|
4
|
+
const { buildToolError } = require("./common");
|
|
2
5
|
|
|
3
6
|
function readProjectRegistryHandler(_ctx = {}, args = {}) {
|
|
4
7
|
const validate = args.validate !== false;
|
|
5
8
|
const cleanupTmp = args.cleanup_tmp !== false;
|
|
6
|
-
const
|
|
9
|
+
const limit = args.limit === undefined ? 100 : args.limit;
|
|
10
|
+
const offset = args.offset === undefined ? 0 : args.offset;
|
|
11
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 1000
|
|
12
|
+
|| !Number.isInteger(offset) || offset < 0) {
|
|
13
|
+
throw buildToolError("invalid_arguments", "registry limit must be 1..1000 and offset must be nonnegative integers");
|
|
14
|
+
}
|
|
15
|
+
const rows = listProjectRuntimes({
|
|
7
16
|
validate,
|
|
8
17
|
cleanupTmp,
|
|
9
18
|
runtimeDir: args.runtimeDir,
|
|
10
19
|
});
|
|
20
|
+
let root = "";
|
|
21
|
+
if (args.project_root) {
|
|
22
|
+
try { root = canonicalProjectRoot(args.project_root); }
|
|
23
|
+
catch { root = path.resolve(args.project_root); }
|
|
24
|
+
}
|
|
25
|
+
let omittedMissing = 0;
|
|
26
|
+
const filtered = rows.filter((row) => {
|
|
27
|
+
if (root && path.resolve(row.project_root) !== root) return false;
|
|
28
|
+
if (args.include_missing !== true && !projectPathExists(row.project_root)) {
|
|
29
|
+
omittedMissing += 1;
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
const projects = filtered.slice(offset, offset + limit);
|
|
11
35
|
|
|
12
36
|
return {
|
|
13
37
|
count: projects.length,
|
|
38
|
+
total: filtered.length,
|
|
39
|
+
next_offset: offset + projects.length < filtered.length ? offset + projects.length : null,
|
|
40
|
+
omitted_missing: omittedMissing,
|
|
14
41
|
projects,
|
|
15
42
|
};
|
|
16
43
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
5
|
+
const { isMetaActive } = require("../../coordination/bus/utils");
|
|
6
|
+
const { isInternalAgentMeta } = require("../../runtime/contracts/agentMode");
|
|
7
|
+
const { buildToolError } = require("./common");
|
|
8
|
+
|
|
9
|
+
/** Read-only routing preview. Selection never launches or dispatches work. */
|
|
10
|
+
function routeAgentHandler(ctx = {}, args = {}) {
|
|
11
|
+
if (typeof args.request !== "string" || !args.request.trim()) throw buildToolError("invalid_arguments", "route_agent requires request");
|
|
12
|
+
const file = getUfooPaths(ctx.projectRoot).agentsFile;
|
|
13
|
+
const bus = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, "utf8")) : { agents: {} };
|
|
14
|
+
const hint = String(args.context_hint || "").toLowerCase();
|
|
15
|
+
const text = `${args.request} ${hint}`.toLowerCase();
|
|
16
|
+
const tokens = new Set(text.match(/[a-z0-9_-]{3,}/g) || []);
|
|
17
|
+
const candidates = Object.entries(bus.agents || {}).filter(([id, meta]) => (
|
|
18
|
+
id !== "ufoo-agent" && meta.agent_type !== "ufoo-agent" && isMetaActive(meta)
|
|
19
|
+
&& (!ctx.internalAgentsOnly || isInternalAgentMeta(meta))
|
|
20
|
+
)).map(([id, meta]) => {
|
|
21
|
+
const nickname = String(meta.nickname || "");
|
|
22
|
+
const role = String(meta.role || meta.solo_role || meta.prompt_profile || "").toLowerCase();
|
|
23
|
+
const explicit = [id, nickname].some((name) => name && (hint === name.toLowerCase() || text.includes(`@${name.toLowerCase()}`)));
|
|
24
|
+
const matches = [...tokens].filter((token) => role.includes(token)).length;
|
|
25
|
+
const idle = ["idle", "waiting", ""].includes(meta.activity_state || "");
|
|
26
|
+
return { id, nickname, explicit, matches, idle, score: (explicit ? 100 : 0) + matches * 10 + (idle ? 1 : 0) };
|
|
27
|
+
}).sort((a, b) => b.score - a.score || a.id.localeCompare(b.id));
|
|
28
|
+
const selected = candidates[0];
|
|
29
|
+
if (!selected) return { target: "", nickname: "", reason: "No active worker in this project; choose direct execution or launch explicitly.", confidence: 0 };
|
|
30
|
+
return { target: selected.id, nickname: selected.nickname,
|
|
31
|
+
reason: selected.explicit ? "Explicit worker reference" : selected.matches ? "Matching role/profile" : selected.idle ? "Available project worker" : "Active project worker; currently busy",
|
|
32
|
+
confidence: selected.explicit ? 1 : selected.matches ? 0.8 : 0.4 };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = { routeAgentHandler };
|
package/src/tools/index.js
CHANGED
package/src/tools/registry.js
CHANGED
|
@@ -16,6 +16,7 @@ const closeAgent = require("./tier2/closeAgent");
|
|
|
16
16
|
const launchAgent = require("./tier2/launchAgent");
|
|
17
17
|
const manageCron = require("./tier2/manageCron");
|
|
18
18
|
const renameAgent = require("./tier2/renameAgent");
|
|
19
|
+
const runtimeCoordination = require("./tier2/runtimeCoordination");
|
|
19
20
|
const {
|
|
20
21
|
CALLER_TIERS,
|
|
21
22
|
assertCallerTierAllowed,
|
|
@@ -42,6 +43,7 @@ const SHARED_TOOL_REGISTRY = Object.freeze([
|
|
|
42
43
|
renameAgent,
|
|
43
44
|
closeAgent,
|
|
44
45
|
manageCron,
|
|
46
|
+
...runtimeCoordination,
|
|
45
47
|
]);
|
|
46
48
|
|
|
47
49
|
function getSharedToolRegistry() {
|
|
@@ -131,12 +131,16 @@ const READ_PROJECT_REGISTRY_SCHEMA = Object.freeze({
|
|
|
131
131
|
name: "read_project_registry",
|
|
132
132
|
tier: "tier0-read",
|
|
133
133
|
allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
134
|
-
description: "Read the cross-project runtime registry.",
|
|
134
|
+
description: "Read a page of the cross-project runtime registry. Deleted project paths are hidden by default; use next_offset to read more.",
|
|
135
135
|
input_schema: Object.freeze({
|
|
136
136
|
type: "object",
|
|
137
137
|
properties: Object.freeze({
|
|
138
138
|
validate: Object.freeze({ type: "boolean" }),
|
|
139
139
|
cleanup_tmp: Object.freeze({ type: "boolean" }),
|
|
140
|
+
include_missing: Object.freeze({ type: "boolean", default: false }),
|
|
141
|
+
limit: Object.freeze({ type: "integer", minimum: 1, maximum: 1000, default: 100 }),
|
|
142
|
+
offset: Object.freeze({ type: "integer", minimum: 0, default: 0 }),
|
|
143
|
+
project_root: Object.freeze({ type: "string", description: "Filter to this exact project root." }),
|
|
140
144
|
}),
|
|
141
145
|
additionalProperties: false,
|
|
142
146
|
}),
|
|
@@ -145,6 +149,9 @@ const READ_PROJECT_REGISTRY_SCHEMA = Object.freeze({
|
|
|
145
149
|
required: ["count", "projects"],
|
|
146
150
|
properties: Object.freeze({
|
|
147
151
|
count: Object.freeze({ type: "integer" }),
|
|
152
|
+
total: Object.freeze({ type: "integer" }),
|
|
153
|
+
next_offset: Object.freeze({ type: Object.freeze(["integer", "null"]) }),
|
|
154
|
+
omitted_missing: Object.freeze({ type: "integer" }),
|
|
148
155
|
projects: Object.freeze({
|
|
149
156
|
type: "array",
|
|
150
157
|
items: Object.freeze({ type: "object", additionalProperties: true }),
|
|
@@ -159,7 +166,7 @@ const ROUTE_AGENT_SCHEMA = Object.freeze({
|
|
|
159
166
|
name: "route_agent",
|
|
160
167
|
tier: "tier1-coordination",
|
|
161
168
|
allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
162
|
-
description: "
|
|
169
|
+
description: "Preview an active worker in the current project using explicit references, roles, and availability. Returns an empty target when none is available. Does not launch or dispatch; the main agent decides the next action.",
|
|
163
170
|
input_schema: Object.freeze({
|
|
164
171
|
type: "object",
|
|
165
172
|
required: ["request"],
|
|
@@ -187,7 +194,7 @@ const DISPATCH_MESSAGE_SCHEMA = Object.freeze({
|
|
|
187
194
|
name: "dispatch_message",
|
|
188
195
|
tier: "tier1-coordination",
|
|
189
196
|
allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
190
|
-
description: "
|
|
197
|
+
description: "Enqueue a message for a target agent, nickname, or broadcast queue. Success confirms queue persistence, not delivery or processing.",
|
|
191
198
|
input_schema: Object.freeze({
|
|
192
199
|
type: "object",
|
|
193
200
|
required: ["target", "message"],
|
|
@@ -209,6 +216,11 @@ const DISPATCH_MESSAGE_SCHEMA = Object.freeze({
|
|
|
209
216
|
ok: Object.freeze({ type: "boolean" }),
|
|
210
217
|
delivered: Object.freeze({ type: "integer" }),
|
|
211
218
|
queued: Object.freeze({ type: "integer" }),
|
|
219
|
+
delivery_status: Object.freeze({ type: "string", enum: Object.freeze(["queued"]) }),
|
|
220
|
+
target: Object.freeze({ type: "string" }),
|
|
221
|
+
source: Object.freeze({ type: "string" }),
|
|
222
|
+
mode: Object.freeze({ type: "string", enum: Object.freeze(["immediate", "queued"]) }),
|
|
223
|
+
seq: Object.freeze({ type: "integer" }),
|
|
212
224
|
targets: Object.freeze({
|
|
213
225
|
type: "array",
|
|
214
226
|
items: Object.freeze({ type: "string" }),
|
|
@@ -611,6 +623,7 @@ const PHASE0_TOOL_SCHEMAS = Object.freeze({
|
|
|
611
623
|
});
|
|
612
624
|
|
|
613
625
|
module.exports = {
|
|
626
|
+
...require("./controllerSchemas"),
|
|
614
627
|
SCHEMA_VERSION,
|
|
615
628
|
READ_BUS_SUMMARY_SCHEMA,
|
|
616
629
|
READ_PROMPT_HISTORY_SCHEMA,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { ROUTE_AGENT_SCHEMA } = require("../schemaFixtures");
|
|
2
2
|
const { CALLER_TIERS, TOOL_TIERS, createToolDefinition } = require("../types");
|
|
3
|
-
const {
|
|
3
|
+
const { routeAgentHandler } = require("../handlers/routeAgent");
|
|
4
4
|
|
|
5
5
|
module.exports = createToolDefinition({
|
|
6
6
|
name: ROUTE_AGENT_SCHEMA.name,
|
|
@@ -10,5 +10,5 @@ module.exports = createToolDefinition({
|
|
|
10
10
|
inputSchema: ROUTE_AGENT_SCHEMA.input_schema,
|
|
11
11
|
outputSchema: ROUTE_AGENT_SCHEMA.output_schema,
|
|
12
12
|
schemaVersion: ROUTE_AGENT_SCHEMA.schema_version,
|
|
13
|
-
handler:
|
|
13
|
+
handler: routeAgentHandler,
|
|
14
14
|
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { CONTROLLER_TOOL_SCHEMAS } = require("../controllerSchemas");
|
|
4
|
+
const { createToolDefinition, CALLER_TIERS, TOOL_TIERS } = require("../types");
|
|
5
|
+
const { assertControllerTier, buildToolError } = require("../handlers/common");
|
|
6
|
+
|
|
7
|
+
const ports = {
|
|
8
|
+
delegate_task: "agentManagement", read_task_reports: "agentManagement", accept_task: "agentManagement",
|
|
9
|
+
manage_tasks: "taskScheduler", resume_agents: "agentLifecycle", manage_group: "groups",
|
|
10
|
+
};
|
|
11
|
+
async function execute(name, ctx, args) {
|
|
12
|
+
assertControllerTier(ctx, name);
|
|
13
|
+
const port = ctx[ports[name]];
|
|
14
|
+
if (!port) throw buildToolError("tool_unavailable", `${name} requires a project host port`);
|
|
15
|
+
if (name === "delegate_task") return port.delegate(args, ctx);
|
|
16
|
+
if (name === "read_task_reports") {
|
|
17
|
+
const tasks = Object.values(port.snapshot().tasks);
|
|
18
|
+
return { ok: true, tasks: (args.task_id ? tasks.filter((task) => task.taskId === args.task_id) : tasks).slice(-100) };
|
|
19
|
+
}
|
|
20
|
+
if (name === "accept_task") return port.accept(args, ctx);
|
|
21
|
+
if (name === "manage_tasks") return port.execute(args, ctx);
|
|
22
|
+
const commandId = ctx.requestId ? `coord-${require("crypto").createHash("sha256").update(`${ctx.requestId}:${args.command_id}`).digest("hex").slice(0, 32)}` : args.command_id;
|
|
23
|
+
if (name === "resume_agents") {
|
|
24
|
+
if (args.operation === "inspect") return port.inspect(args.target || "");
|
|
25
|
+
return ctx.agentManagement.commands.execute({ commandId, kind: name, args }, () => port.resume(args.target || ""));
|
|
26
|
+
}
|
|
27
|
+
if (args.operation === "validate") return port.validateTemplateTarget(args.target || "");
|
|
28
|
+
if (args.operation === "status") return port.getStatus({ group_id: args.group_id || "" });
|
|
29
|
+
return ctx.agentManagement.commands.execute({ commandId, kind: name, args }, () => args.operation === "start"
|
|
30
|
+
? port.runGroup({ alias: args.target, ...(ctx.internalAgentsOnly ? { internal_only: true } : {}), instance: args.group_id || `group-${require("crypto").createHash("sha256").update(commandId).digest("hex").slice(0, 16)}` }) : port.stopGroup({ group_id: args.group_id }));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = Object.values(CONTROLLER_TOOL_SCHEMAS).map((schema) => createToolDefinition({
|
|
34
|
+
name: schema.name, description: schema.description, inputSchema: schema.input_schema, outputSchema: schema.output_schema,
|
|
35
|
+
schemaVersion: schema.schema_version, tier: TOOL_TIERS.TIER_2, allowedCallerTiers: [CALLER_TIERS.CONTROLLER],
|
|
36
|
+
requiredPorts: [ports[schema.name], ...(["resume_agents", "manage_group"].includes(schema.name) ? ["agentManagement"] : [])],
|
|
37
|
+
handler: (ctx, args) => execute(schema.name, ctx, args),
|
|
38
|
+
}));
|
package/src/tools/types.js
CHANGED
|
@@ -24,6 +24,7 @@ function createToolDefinition({
|
|
|
24
24
|
outputSchema,
|
|
25
25
|
handler,
|
|
26
26
|
schemaVersion,
|
|
27
|
+
requiredPorts = [],
|
|
27
28
|
}) {
|
|
28
29
|
const allowed = Object.freeze([...(allowedCallerTiers || [])]);
|
|
29
30
|
return Object.freeze({
|
|
@@ -36,6 +37,7 @@ function createToolDefinition({
|
|
|
36
37
|
input_schema: Object.freeze(inputSchema),
|
|
37
38
|
output_schema: outputSchema ? Object.freeze(outputSchema) : null,
|
|
38
39
|
handler,
|
|
40
|
+
requiredPorts: Object.freeze(requiredPorts.slice()),
|
|
39
41
|
});
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Shared presentation adapters: standalone ucode and embedded SDK/native agents.
|
|
4
|
+
const fmt = require("./format");
|
|
5
|
+
const { buildContextMeter } = require("../agents/runtime/context/contextWindow");
|
|
6
|
+
|
|
7
|
+
function toolStatus(name = "tool") {
|
|
8
|
+
const aliases = { Read: "read", Write: "write", Edit: "edit", Bash: "bash", TodoWrite: "plan_graph", plan: "plan_graph" };
|
|
9
|
+
const key = aliases[name] || String(name).toLowerCase();
|
|
10
|
+
return `${fmt.TOOL_LABELS[key] || `Calling ${name}`}…`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function statusForAgentPhase(event = {}) {
|
|
14
|
+
switch (event.type) {
|
|
15
|
+
case "request_start": case "requesting": return "Waiting for model…";
|
|
16
|
+
case "thinking": return "Thinking…";
|
|
17
|
+
case "text_delta": return "Generating response…";
|
|
18
|
+
case "tool_request": return toolStatus(event.name || "tool");
|
|
19
|
+
case "compacting": return "Compacting context…";
|
|
20
|
+
case "retry": return `Retrying request${event.attempt ? ` (${event.attempt}/${event.max_retries || "?"})` : ""}…`;
|
|
21
|
+
case "authenticating": return "Authenticating…";
|
|
22
|
+
case "cancelling": return "cancelling…";
|
|
23
|
+
case "applying_reply": return "applying reply…";
|
|
24
|
+
default: return "";
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function contextMeterForUsage(usage = {}, model = "", provider = "") {
|
|
29
|
+
if (usage.contextMeter?.label) return usage.contextMeter;
|
|
30
|
+
return buildContextMeter({ model, usage: {
|
|
31
|
+
input: usage.input_tokens ?? usage.prompt_tokens ?? usage.input ?? 0,
|
|
32
|
+
cacheRead: usage.cache_read_tokens ?? usage.cache_read_input_tokens ?? usage.cached_input_tokens ?? usage.cacheRead ?? 0,
|
|
33
|
+
cacheCreation: usage.cache_creation_tokens ?? usage.cache_creation_input_tokens ?? usage.cacheCreation ?? 0,
|
|
34
|
+
inputIncludesCache: provider === "claude-cli" || provider === "anthropic" ? false : true,
|
|
35
|
+
} });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function planLinesFromItems(items = []) {
|
|
39
|
+
return (Array.isArray(items) ? items : []).filter(Boolean).map((item) => {
|
|
40
|
+
const status = String(item.status || "");
|
|
41
|
+
const mark = item.completed || ["completed", "succeeded"].includes(status) ? "✓"
|
|
42
|
+
: ["in_progress", "running"].includes(status) ? "→"
|
|
43
|
+
: ["failed", "blocked"].includes(status) ? "✗" : "○";
|
|
44
|
+
return `${mark} ${item.text || item.content || item.title || item.step || ""}`;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function buildPlanSetPayload(executionState, options = {}) {
|
|
49
|
+
try {
|
|
50
|
+
const { buildPlanUiProjection } = require("../code/context/planProjection");
|
|
51
|
+
const projection = buildPlanUiProjection(executionState, {
|
|
52
|
+
cols: Number(options.cols) > 0 ? Number(options.cols) : 80,
|
|
53
|
+
activityMessage: String(options.activityMessage || ""),
|
|
54
|
+
});
|
|
55
|
+
if (!projection || !projection.visible) {
|
|
56
|
+
return {
|
|
57
|
+
summary: "",
|
|
58
|
+
lines: [],
|
|
59
|
+
hash: projection && projection.hash || "",
|
|
60
|
+
visible: false,
|
|
61
|
+
idle_hint: String((projection && projection.idleHint) || ""),
|
|
62
|
+
status_line: "",
|
|
63
|
+
band_mode: String((projection && projection.bandMode) || ""),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
let lines = Array.isArray(projection.bandLines) ? projection.bandLines.slice() : [];
|
|
67
|
+
const md = String(projection.roadmapMarkdown || "").trim();
|
|
68
|
+
if (md) {
|
|
69
|
+
try {
|
|
70
|
+
const rendered = fmt.renderLogLinesWithMarkdownAnsi(md, { inCodeBlock: false });
|
|
71
|
+
if (Array.isArray(rendered) && rendered.length > 0) {
|
|
72
|
+
lines = rendered.map((line) => String(line || ""));
|
|
73
|
+
}
|
|
74
|
+
} catch {
|
|
75
|
+
// keep bandLines
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const summary = String(
|
|
79
|
+
projection.statusLine
|
|
80
|
+
|| projection.activityStatusLine
|
|
81
|
+
|| lines[0]
|
|
82
|
+
|| ""
|
|
83
|
+
).trim();
|
|
84
|
+
return {
|
|
85
|
+
summary,
|
|
86
|
+
text: summary,
|
|
87
|
+
lines,
|
|
88
|
+
hash: projection.hash || "",
|
|
89
|
+
visible: true,
|
|
90
|
+
idle_hint: String(projection.idleHint || ""),
|
|
91
|
+
status_line: String(projection.statusLine || projection.activityStatusLine || ""),
|
|
92
|
+
activity_status_line: String(projection.activityStatusLine || ""),
|
|
93
|
+
band_mode: String(projection.bandMode || ""),
|
|
94
|
+
};
|
|
95
|
+
} catch {
|
|
96
|
+
return {
|
|
97
|
+
summary: "",
|
|
98
|
+
lines: [],
|
|
99
|
+
hash: "",
|
|
100
|
+
visible: false,
|
|
101
|
+
idle_hint: "",
|
|
102
|
+
status_line: "",
|
|
103
|
+
band_mode: "",
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
module.exports = { toolStatus, statusForAgentPhase, contextMeterForUsage, planLinesFromItems, buildPlanSetPayload };
|