u-foo 4.0.0 → 4.0.2
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 +90 -30
- package/README.zh-CN.md +76 -26
- package/SKILLS/ufoo/SKILL.md +25 -1
- package/SKILLS/ufoo-bus/SKILL.md +25 -2
- package/bin/ucode.js +4 -0
- package/bin/ufoo.js +3 -3
- 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 +6 -6
- package/src/agents/activity/activityDetector.js +1 -1
- package/src/agents/capabilities/agentManagement/service.js +40 -13
- package/src/agents/capabilities/coordination/index.js +1 -1
- package/src/agents/capabilities/taskReports/index.js +1 -1
- package/src/agents/controller/controllerToolExecutor.js +36 -20
- package/src/agents/controller/index.js +1 -6
- package/src/agents/internal/internalRunner.js +90 -56
- package/src/agents/launch/index.js +0 -1
- package/src/agents/launch/launcher.js +38 -29
- package/src/agents/launch/launcherReadiness.js +35 -0
- package/src/agents/launch/notifier.js +2 -2
- package/src/agents/launch/ptyWrapper.js +5 -2
- package/src/agents/launch/readyDetector.js +2 -2
- package/src/agents/profiles/main.js +1 -1
- package/src/agents/prompts/cooperation.js +14 -0
- package/src/agents/prompts/defaultBootstrap.js +1 -1
- package/src/agents/prompts/groupBootstrap.js +23 -7
- package/src/agents/prompts/mainAgent.js +11 -2
- package/src/agents/prompts/native/system.js +4 -1
- package/src/agents/prompts/native/ufoo.js +11 -3
- package/src/agents/prompts/promptProfiles.js +2 -0
- package/src/agents/prompts/reporting.js +16 -0
- package/src/agents/providers/claudeEventTranslator.js +3 -0
- package/src/agents/providers/claudeThreadProvider.js +3 -2
- package/src/agents/providers/clientIdentity.js +75 -0
- package/src/agents/providers/codexEventTranslator.js +23 -2
- package/src/agents/providers/codexThreadProvider.js +15 -6
- 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 +58 -40
- package/src/agents/providers/runtimeConfig.js +10 -8
- package/src/agents/providers/thinkingLevels.js +10 -36
- package/src/agents/providers/transports/responsesProtocol.js +11 -6
- package/src/agents/providers/upstreamRuntime.js +135 -0
- package/src/agents/runtime/context/checkpointStore.js +38 -0
- package/src/agents/runtime/context/compaction.js +151 -0
- package/src/agents/runtime/context/contextBudget.js +93 -0
- package/src/agents/runtime/context/replayHistory.js +28 -0
- package/src/agents/runtime/context/runtimeStore.js +2 -1
- package/src/agents/runtime/core/agentLoop.js +99 -18
- package/src/agents/runtime/core/executionBudget.js +36 -0
- package/src/agents/runtime/createAgentRuntime.js +16 -4
- package/src/agents/runtime/prompts/responseLanguage.js +12 -0
- package/src/agents/runtime/protocol/runObservation.js +24 -0
- package/src/agents/runtime/protocol/traceContext.js +9 -0
- package/src/app/chat/ChatController.js +26 -53
- package/src/app/chat/agentDirectory.js +1 -16
- package/src/app/chat/bootstrap.js +1 -2
- package/src/app/chat/commandExecutor.js +93 -285
- package/src/app/chat/commands.js +32 -45
- package/src/app/chat/daemonMessageRouter.js +0 -45
- package/src/app/chat/historyStore.js +12 -48
- package/src/app/chat/inputSubmitHandler.js +7 -33
- package/src/app/chat/internalAgentLogHistory.js +19 -60
- package/src/app/chat/multiWindow/paneManager.js +10 -3
- package/src/app/chat/streamState.js +0 -4
- package/src/app/cli/features/init.js +5 -5
- package/src/app/cli/metricsCommands.js +68 -0
- package/src/app/cli/run.js +42 -3
- package/src/app/cli/traceCommands.js +36 -0
- package/src/code/agent.js +18 -13
- package/src/code/busConsumer.js +1 -3
- package/src/code/commands.js +1 -1
- package/src/code/context/assembler.js +7 -8
- package/src/code/context/stateCommit.js +2 -1
- package/src/code/internalThread.js +10 -3
- 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 +55 -17
- package/src/code/providers/modelsCatalog.js +1 -317
- package/src/code/repl.js +4 -11
- package/src/code/sessionStore.js +3 -3
- package/src/code/taskDecomposer.js +18 -0
- package/src/code/toolBudget.js +1 -17
- package/src/config.js +22 -72
- package/src/coordination/bus/index.js +12 -3
- package/src/coordination/bus/inject.js +2 -2
- package/src/coordination/bus/message.js +15 -1
- package/src/coordination/bus/nickname.js +1 -1
- package/src/coordination/bus/subscriber.js +3 -2
- package/src/coordination/bus/utils.js +1 -1
- package/src/coordination/history/agentPerformance.js +279 -0
- package/src/coordination/history/agentTrace.js +249 -0
- package/src/coordination/state/workspaceAccess.js +1 -1
- 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 +11 -2
- package/src/runtime/contracts/uiProtocol.js +18 -19
- package/src/runtime/daemon/agentHost.js +57 -25
- package/src/runtime/daemon/agentRecoveryGroups.js +70 -0
- package/src/runtime/daemon/busBridge.js +1 -1
- package/src/runtime/daemon/controlPlaneService.js +1 -1
- package/src/runtime/daemon/groupOrchestrator.js +20 -5
- package/src/runtime/daemon/groupStatus.js +20 -0
- package/src/runtime/daemon/index.js +19 -44
- package/src/runtime/daemon/mcpHttpServer.js +39 -10
- package/src/runtime/daemon/mcpServer.js +1 -1
- package/src/runtime/daemon/nicknameScope.js +1 -1
- package/src/runtime/daemon/ops.js +46 -23
- package/src/runtime/daemon/projectRuntimeGateway.js +2 -0
- package/src/runtime/daemon/promptRequest.js +92 -589
- package/src/runtime/daemon/status.js +5 -6
- package/src/tools/controllerSchemas.js +6 -2
- package/src/tools/handlers/tier2.js +4 -2
- package/src/tools/registry.js +4 -0
- package/src/tools/schemaFixtures.js +26 -2
- package/src/tools/tier0/readAgentMetrics.js +14 -0
- package/src/tools/tier0/readAgentTrace.js +12 -0
- package/src/ui/agentSettingsController.js +107 -0
- package/src/ui/agentSurface.js +1 -1
- package/src/ui/dashboardBridge.js +1 -1
- package/src/ui/format/banner.js +1 -4
- 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/rustChatHost.js +191 -206
- package/src/ui/rustMultiSession.js +77 -36
- package/src/ui/rustUcodeHost.js +6 -1
- package/src/ui/settingsBridge.js +33 -16
- 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 -336
- package/src/agents/controller/ufooAgent.js +0 -830
- package/src/agents/launch/ptyRunner.js +0 -1135
- package/src/agents/providers/controllerJsonTransport.js +0 -28
- package/src/agents/providers/upstreamTransport.js +0 -698
- package/src/app/chat/agentBar.js +0 -135
- package/src/app/chat/agentSockets.js +0 -225
- package/src/app/chat/dashboardView.js +0 -405
- package/src/app/chat/rawKeyMap.js +0 -42
- package/src/app/chat/settingsController.js +0 -111
- package/src/coordination/history/controllerSummary.js +0 -23
- 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/executionPaths.js +0 -30
- package/src/runtime/daemon/promptLoop.js +0 -136
- package/src/runtime/privacy/shadowDiff.js +0 -174
|
@@ -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
|
|
|
@@ -191,7 +191,6 @@ function buildStatus(projectRoot, options = {}) {
|
|
|
191
191
|
controller: {
|
|
192
192
|
pending_total: controllerPendingTotal,
|
|
193
193
|
},
|
|
194
|
-
loop: readRecentLoopSummary(projectRoot),
|
|
195
194
|
cron: {
|
|
196
195
|
count: cronTasks.length,
|
|
197
196
|
tasks: cronTasks,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
const { INTERNAL_AGENT_TYPES } = require("../runtime/contracts/agentMode");
|
|
2
3
|
|
|
3
4
|
const string = { type: "string", minLength: 1 };
|
|
4
5
|
const command = { type: "string", pattern: "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,100}$" };
|
|
@@ -7,8 +8,11 @@ const schema = (name, description, required, properties) => Object.freeze({ name
|
|
|
7
8
|
allowed_tiers: ["controller"], input_schema: { type: "object", required, properties, additionalProperties: false },
|
|
8
9
|
output_schema: { type: "object" } });
|
|
9
10
|
const CONTROLLER_TOOL_SCHEMAS = Object.freeze({
|
|
10
|
-
delegate_task: schema("delegate_task", "
|
|
11
|
-
["command_id", "objective"], { command_id: command, objective: string,
|
|
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 }),
|
|
12
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 }),
|
|
13
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.",
|
|
14
18
|
["task_id", "outcome", "reason"], { task_id: string, outcome: { type: "string", enum: ["accepted", "rejected"] }, reason: string, evidence: strings }),
|
|
@@ -3,6 +3,7 @@ const {
|
|
|
3
3
|
assertControllerTier,
|
|
4
4
|
extractAuditFields,
|
|
5
5
|
} = require("./common");
|
|
6
|
+
const { normalizeInternalAgentType } = require("../../runtime/contracts/agentMode");
|
|
6
7
|
|
|
7
8
|
function normalizePositiveInt(value, fallback) {
|
|
8
9
|
const num = Number.parseInt(value, 10);
|
|
@@ -38,11 +39,12 @@ async function runSingleOp(ctx, op, toolName) {
|
|
|
38
39
|
async function launchAgentHandler(ctx = {}, args = {}) {
|
|
39
40
|
assertControllerTier(ctx, "launch_agent");
|
|
40
41
|
const audit = extractAuditFields(ctx);
|
|
41
|
-
const agent =
|
|
42
|
-
if (!agent) guardInvalidArgs(ctx, "launch_agent", "requires
|
|
42
|
+
const agent = normalizeInternalAgentType(args.agent);
|
|
43
|
+
if (!agent) guardInvalidArgs(ctx, "launch_agent", "requires internal codex, claude or ucode");
|
|
43
44
|
|
|
44
45
|
const op = {
|
|
45
46
|
action: "launch",
|
|
47
|
+
internal_only: true,
|
|
46
48
|
agent,
|
|
47
49
|
count: normalizePositiveInt(args.count, 1),
|
|
48
50
|
};
|
package/src/tools/registry.js
CHANGED
|
@@ -3,6 +3,8 @@ const readBusSummary = require("./tier0/readBusSummary");
|
|
|
3
3
|
const readOpenDecisions = require("./tier0/readOpenDecisions");
|
|
4
4
|
const readProjectRegistry = require("./tier0/readProjectRegistry");
|
|
5
5
|
const readPromptHistory = require("./tier0/readPromptHistory");
|
|
6
|
+
const readAgentTrace = require("./tier0/readAgentTrace");
|
|
7
|
+
const readAgentMetrics = require("./tier0/readAgentMetrics");
|
|
6
8
|
const ackBus = require("./tier1/ackBus");
|
|
7
9
|
const dispatchMessage = require("./tier1/dispatchMessage");
|
|
8
10
|
const editMemory = require("./tier1/editMemory");
|
|
@@ -25,6 +27,8 @@ const {
|
|
|
25
27
|
} = require("./types");
|
|
26
28
|
|
|
27
29
|
const SHARED_TOOL_REGISTRY = Object.freeze([
|
|
30
|
+
readAgentMetrics,
|
|
31
|
+
readAgentTrace,
|
|
28
32
|
readBusSummary,
|
|
29
33
|
readPromptHistory,
|
|
30
34
|
readOpenDecisions,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const { INTERNAL_AGENT_TYPES } = require("../runtime/contracts/agentMode");
|
|
1
2
|
const SCHEMA_VERSION = "1.0";
|
|
2
3
|
|
|
3
4
|
const CALLER_TIERS_READ_COORD = Object.freeze(["controller", "worker"]);
|
|
@@ -235,7 +236,7 @@ const ACK_BUS_SCHEMA = Object.freeze({
|
|
|
235
236
|
name: "ack_bus",
|
|
236
237
|
tier: "tier1-coordination",
|
|
237
238
|
allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
238
|
-
description: "Acknowledge pending bus messages for the caller-owned queue only.",
|
|
239
|
+
description: "Acknowledge pending bus messages for the caller-owned queue only. Internal runners confirm completed tasks automatically; calls for internal agents acknowledge zero messages and preserve queued work.",
|
|
239
240
|
input_schema: Object.freeze({
|
|
240
241
|
type: "object",
|
|
241
242
|
properties: Object.freeze({
|
|
@@ -474,7 +475,7 @@ const LAUNCH_AGENT_SCHEMA = Object.freeze({
|
|
|
474
475
|
properties: Object.freeze({
|
|
475
476
|
agent: Object.freeze({
|
|
476
477
|
type: "string",
|
|
477
|
-
enum:
|
|
478
|
+
enum: INTERNAL_AGENT_TYPES,
|
|
478
479
|
}),
|
|
479
480
|
count: Object.freeze({ type: "integer", minimum: 1 }),
|
|
480
481
|
nickname: Object.freeze({ type: "string" }),
|
|
@@ -601,7 +602,28 @@ const MANAGE_CRON_SCHEMA = Object.freeze({
|
|
|
601
602
|
}),
|
|
602
603
|
});
|
|
603
604
|
|
|
605
|
+
const READ_AGENT_TRACE_SCHEMA = Object.freeze({ name: "read_agent_trace", schema_version: SCHEMA_VERSION,
|
|
606
|
+
tier: "tier0-read", allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
607
|
+
description: "Read a task timeline across main/worker model and tool events, reports, queue state and context compaction, with an observed performance summary. Default shows the latest events with concise summaries; details includes redacted parameters/results. This is observation only, not acceptance or delivery acknowledgement.",
|
|
608
|
+
input_schema: { type: "object", properties: {
|
|
609
|
+
task_id: { type: "string", description: "Exact delegated task ID or parent taskRunId; includes related descendants." },
|
|
610
|
+
agent_id: { type: "string", description: "Worker subscriber ID or registered nickname." }, session_id: { type: "string" },
|
|
611
|
+
since: { type: "string", description: "ISO timestamp lower bound." }, limit: { type: "integer", minimum: 1, maximum: 2000 },
|
|
612
|
+
offset: { type: "integer", minimum: 0, description: "Explicit oldest-first pagination offset. Omit for the newest page." }, details: { type: "boolean" },
|
|
613
|
+
}, additionalProperties: false }, output_schema: { type: "object" } });
|
|
614
|
+
|
|
615
|
+
const READ_AGENT_METRICS_SCHEMA = Object.freeze({ name: "read_agent_metrics", schema_version: SCHEMA_VERSION,
|
|
616
|
+
tier: "tier0-read", allowed_tiers: CALLER_TIERS_READ_COORD,
|
|
617
|
+
description: "Read observed agent execution outcomes, latency, usage, tool errors/repetition, report size and delegation acceptance, grouped by provider/model/configuration. Time filters select run starts and retain full observed lifecycles. Missing evidence is unknown; execution completion is not acceptance or a quality score. No model calls or state mutations.",
|
|
618
|
+
input_schema: { type: "object", properties: {
|
|
619
|
+
task_id: { type: "string" }, agent_id: { type: "string" }, session_id: { type: "string" },
|
|
620
|
+
since: { type: "string", description: "ISO inclusive run-start lower bound." }, until: { type: "string", description: "ISO exclusive run-start upper bound." },
|
|
621
|
+
provider: { type: "string" }, model: { type: "string" }, limit: { type: "integer", minimum: 1, maximum: 100 },
|
|
622
|
+
}, additionalProperties: false }, output_schema: { type: "object" } });
|
|
623
|
+
|
|
604
624
|
const PHASE0_TOOL_SCHEMAS = Object.freeze({
|
|
625
|
+
read_agent_metrics: READ_AGENT_METRICS_SCHEMA,
|
|
626
|
+
read_agent_trace: READ_AGENT_TRACE_SCHEMA,
|
|
605
627
|
read_bus_summary: READ_BUS_SUMMARY_SCHEMA,
|
|
606
628
|
read_prompt_history: READ_PROMPT_HISTORY_SCHEMA,
|
|
607
629
|
read_open_decisions: READ_OPEN_DECISIONS_SCHEMA,
|
|
@@ -623,6 +645,8 @@ const PHASE0_TOOL_SCHEMAS = Object.freeze({
|
|
|
623
645
|
});
|
|
624
646
|
|
|
625
647
|
module.exports = {
|
|
648
|
+
READ_AGENT_METRICS_SCHEMA,
|
|
649
|
+
READ_AGENT_TRACE_SCHEMA,
|
|
626
650
|
...require("./controllerSchemas"),
|
|
627
651
|
SCHEMA_VERSION,
|
|
628
652
|
READ_BUS_SUMMARY_SCHEMA,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { createToolDefinition, CALLER_TIERS, TOOL_TIERS } = require("../types");
|
|
4
|
+
const { READ_AGENT_METRICS_SCHEMA } = require("../schemaFixtures");
|
|
5
|
+
const { readAgentPerformance } = require("../../coordination/history/agentTrace");
|
|
6
|
+
|
|
7
|
+
module.exports = createToolDefinition({ name: READ_AGENT_METRICS_SCHEMA.name, description: READ_AGENT_METRICS_SCHEMA.description,
|
|
8
|
+
inputSchema: READ_AGENT_METRICS_SCHEMA.input_schema, outputSchema: READ_AGENT_METRICS_SCHEMA.output_schema,
|
|
9
|
+
schemaVersion: READ_AGENT_METRICS_SCHEMA.schema_version, tier: TOOL_TIERS.TIER_0,
|
|
10
|
+
allowedCallerTiers: [CALLER_TIERS.CONTROLLER, CALLER_TIERS.WORKER],
|
|
11
|
+
handler: (ctx, args) => {
|
|
12
|
+
try { return readAgentPerformance(ctx.projectRoot, args); }
|
|
13
|
+
catch (error) { return { ok: false, code: "invalid_arguments", error: error.message }; }
|
|
14
|
+
} });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { createToolDefinition, CALLER_TIERS, TOOL_TIERS } = require("../types");
|
|
3
|
+
const { READ_AGENT_TRACE_SCHEMA } = require("../schemaFixtures");
|
|
4
|
+
const { readAgentTrace } = require("../../coordination/history/agentTrace");
|
|
5
|
+
module.exports = createToolDefinition({ name: READ_AGENT_TRACE_SCHEMA.name, description: READ_AGENT_TRACE_SCHEMA.description,
|
|
6
|
+
inputSchema: READ_AGENT_TRACE_SCHEMA.input_schema, outputSchema: READ_AGENT_TRACE_SCHEMA.output_schema,
|
|
7
|
+
schemaVersion: READ_AGENT_TRACE_SCHEMA.schema_version, tier: TOOL_TIERS.TIER_0,
|
|
8
|
+
allowedCallerTiers: [CALLER_TIERS.CONTROLLER, CALLER_TIERS.WORKER],
|
|
9
|
+
handler: (ctx, args) => {
|
|
10
|
+
if (args.since && !Number.isFinite(Date.parse(args.since))) return { ok: false, code: "invalid_arguments", error: "since must be an ISO timestamp" };
|
|
11
|
+
return readAgentTrace(ctx.projectRoot, args);
|
|
12
|
+
} });
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { loadConfig } = require("../config");
|
|
4
|
+
const { listAgentModels, confirmAgentModel } = require("../agents/providers/modelSettings");
|
|
5
|
+
const { suggestThinkingLevels, normalizeThinkingLevel } = require("../agents/providers/thinkingLevels");
|
|
6
|
+
|
|
7
|
+
const MODEL_COMMAND = "/settings agent model";
|
|
8
|
+
const THINKING_COMMAND = "/settings agent thinking";
|
|
9
|
+
|
|
10
|
+
function createAgentSettingsController({ getProjectRoot, applyPatch, publish, focusMain = () => {}, logMessage = () => {},
|
|
11
|
+
listModels = listAgentModels, confirmModel = confirmAgentModel } = {}) {
|
|
12
|
+
let draft = null;
|
|
13
|
+
function ask(stage) {
|
|
14
|
+
draft.stage = stage;
|
|
15
|
+
const config = loadConfig(draft.root);
|
|
16
|
+
const prompts = {
|
|
17
|
+
url: `Custom API URL${config.agentBaseUrl ? ` (Enter keeps ${config.agentBaseUrl})` : ""}`,
|
|
18
|
+
key: "Custom API key (hidden; Enter keeps the saved key, '-' clears it)",
|
|
19
|
+
model: "Model ID for the current provider",
|
|
20
|
+
};
|
|
21
|
+
publish("interaction.request", { id: `settings-${stage}`, kind: "settings", prompt: prompts[stage],
|
|
22
|
+
secret: stage === "key", lines: [prompts[stage], "Enter save · Esc cancel"] });
|
|
23
|
+
}
|
|
24
|
+
function open(section) {
|
|
25
|
+
focusMain();
|
|
26
|
+
if (section === "custom" || section === "manual") {
|
|
27
|
+
draft = { root: getProjectRoot(), values: {} };
|
|
28
|
+
ask(section === "custom" ? "url" : "model");
|
|
29
|
+
} else {
|
|
30
|
+
publish("prompt.set_text", { text: `${section === "thinking" ? THINKING_COMMAND : MODEL_COMMAND} `, preserve_draft: true });
|
|
31
|
+
}
|
|
32
|
+
return { ok: true };
|
|
33
|
+
}
|
|
34
|
+
async function applyModel(model, thinking = "") {
|
|
35
|
+
if (!model) return { ok: false, error: "Model ID is required" };
|
|
36
|
+
if (model === "<manual>") return open("manual");
|
|
37
|
+
if (thinking && !normalizeThinkingLevel(thinking)) return { ok: false, error: "Unknown thinking level" };
|
|
38
|
+
let confirmation;
|
|
39
|
+
try { confirmation = await confirmModel(getProjectRoot(), model); }
|
|
40
|
+
catch (error) { return { ok: false, error: error.message }; }
|
|
41
|
+
if (!confirmation.allowed) return { ok: false, error: confirmation.error };
|
|
42
|
+
const result = await applyPatch({ agent_model: model, ...(thinking ? { agent_thinking: thinking } : {}) });
|
|
43
|
+
if (result.ok) {
|
|
44
|
+
if (confirmation.warning) logMessage("system", "Model catalog unavailable; saved the supplied model ID.");
|
|
45
|
+
publish("prompt.restore", {});
|
|
46
|
+
}
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
async function respond(payload) {
|
|
50
|
+
if (!draft) return null;
|
|
51
|
+
if (draft.root !== getProjectRoot() || payload.cancelled) {
|
|
52
|
+
draft = null;
|
|
53
|
+
publish("interaction.clear", {});
|
|
54
|
+
return { ok: true, cancelled: true };
|
|
55
|
+
}
|
|
56
|
+
if (payload.id !== `settings-${draft.stage}`) return { ok: false, error: "Stale settings input" };
|
|
57
|
+
const text = String(payload.text || "").trim();
|
|
58
|
+
if (draft.stage === "url") {
|
|
59
|
+
const urlText = text || loadConfig(draft.root).agentBaseUrl;
|
|
60
|
+
try {
|
|
61
|
+
const url = new URL(urlText);
|
|
62
|
+
if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) throw new Error();
|
|
63
|
+
} catch {
|
|
64
|
+
logMessage("error", "Enter an http(s) API URL without embedded credentials.");
|
|
65
|
+
ask("url");
|
|
66
|
+
return { ok: false, error: "Invalid API URL" };
|
|
67
|
+
}
|
|
68
|
+
draft.values.agent_base_url = urlText;
|
|
69
|
+
ask("key");
|
|
70
|
+
return { ok: true };
|
|
71
|
+
}
|
|
72
|
+
if (draft.stage === "key") {
|
|
73
|
+
const patch = { ...draft.values, agent_provider: "custom" };
|
|
74
|
+
if (text) patch.agent_api_key = text === "-" ? "" : text;
|
|
75
|
+
const result = await applyPatch(patch);
|
|
76
|
+
if (!result.ok) { ask("key"); return result; }
|
|
77
|
+
draft = null;
|
|
78
|
+
publish("interaction.clear", {});
|
|
79
|
+
return open("model");
|
|
80
|
+
}
|
|
81
|
+
const result = await applyModel(text);
|
|
82
|
+
if (!result.ok) { logMessage("error", result.error); ask("model"); return result; }
|
|
83
|
+
draft = null;
|
|
84
|
+
publish("interaction.clear", {});
|
|
85
|
+
return open("thinking");
|
|
86
|
+
}
|
|
87
|
+
async function completions(text) {
|
|
88
|
+
const root = getProjectRoot();
|
|
89
|
+
const config = loadConfig(root);
|
|
90
|
+
const thinking = suggestThinkingLevels({ current: config.agentThinking });
|
|
91
|
+
const lists = { [THINKING_COMMAND]: thinking, [`${MODEL_COMMAND}/thinking`]: thinking };
|
|
92
|
+
if (text.trimStart().startsWith(`${MODEL_COMMAND} `)) {
|
|
93
|
+
const listed = await listModels(root).catch((error) => ({ ok: false, error: error.message }));
|
|
94
|
+
const ids = listed.ok ? listed.models.slice() : [];
|
|
95
|
+
if (config.agentModel && (!listed.ok || listed.allowUnlistedModels) && !ids.includes(config.agentModel)) {
|
|
96
|
+
ids.unshift(config.agentModel);
|
|
97
|
+
}
|
|
98
|
+
lists[MODEL_COMMAND] = ids.map((id) => ({ id, hasChildren: true, desc: id === config.agentModel ? "current · choose thinking" : "choose thinking" }));
|
|
99
|
+
lists[MODEL_COMMAND].push({ id: "<manual>", label: "Enter model ID", hasChildren: false,
|
|
100
|
+
desc: listed.ok ? "Configure a model by ID" : "Catalog unavailable · enter model ID" });
|
|
101
|
+
}
|
|
102
|
+
return lists;
|
|
103
|
+
}
|
|
104
|
+
return { open, respond, completions, applyModel };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
module.exports = { createAgentSettingsController, MODEL_COMMAND, THINKING_COMMAND };
|
package/src/ui/agentSurface.js
CHANGED
|
@@ -198,7 +198,7 @@ function createAgentSurface(options = {}) {
|
|
|
198
198
|
if (event.status !== "in_progress") status = "Waiting for model…";
|
|
199
199
|
return apply("tool.result", { id, summary: tool.summary, detail });
|
|
200
200
|
}
|
|
201
|
-
if (["task_completed", "task_failed", "task_cancelled"].includes(type)) {
|
|
201
|
+
if (["task_completed", "task_failed", "task_cancelled", "task_paused"].includes(type)) {
|
|
202
202
|
if (event.error) apply("transcript.append", { kind: "error", text: event.error });
|
|
203
203
|
if (event.usage) accept({ type: "usage", usage: event.usage });
|
|
204
204
|
apply("stream.done", { reason: type === "task_failed" ? "error" : "complete" });
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Shared dashboard snapshot helpers for Rust chat host.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
const { formatLoopSummary } = require("
|
|
7
|
+
const { formatLoopSummary } = require("./format/loopSummary");
|
|
8
8
|
|
|
9
9
|
function loadGlobalProjectRows(activeProjectRoot = "") {
|
|
10
10
|
const path = require("path");
|
package/src/ui/format/banner.js
CHANGED
|
@@ -14,15 +14,12 @@ function showBanner(options) {
|
|
|
14
14
|
// Compact logo (3 行)
|
|
15
15
|
const logo = UFOO_BANNER_LINES;
|
|
16
16
|
|
|
17
|
-
// Normalize agent type display name
|
|
18
|
-
const displayAgentType = agentType === "ufoo-code" ? "ucode" : agentType;
|
|
19
|
-
|
|
20
17
|
// 准备右侧信息行
|
|
21
18
|
const infoLines = [];
|
|
22
19
|
if (nickname) {
|
|
23
20
|
infoLines.push(`${chalk.dim("Nickname:")} ${chalk.cyan.bold(nickname)}`);
|
|
24
21
|
}
|
|
25
|
-
infoLines.push(`${chalk.dim("Agent:")} ${chalk.green.bold(
|
|
22
|
+
infoLines.push(`${chalk.dim("Agent:")} ${chalk.green.bold(agentType)}${chalk.dim(":")}${chalk.yellow(sessionId)}`);
|
|
26
23
|
if (daemonStatus) {
|
|
27
24
|
const statusColor = daemonStatus === "running" ? chalk.green : chalk.blue;
|
|
28
25
|
infoLines.push(`${chalk.dim("Daemon:")} ${statusColor(daemonStatus)}`);
|
package/src/ui/format/index.js
CHANGED
|
@@ -1115,8 +1115,11 @@ function buildCompletions({
|
|
|
1115
1115
|
|
|
1116
1116
|
if (trimmed.startsWith("/")) {
|
|
1117
1117
|
const tokenParts = trimmed.trimEnd().split(/\s+/).filter(Boolean);
|
|
1118
|
-
const
|
|
1119
|
-
|
|
1118
|
+
const dynamicHead = Object.keys(argumentLists || {}).filter((key) => key.includes(" ")
|
|
1119
|
+
&& !key.endsWith("/thinking") && tokenParts.slice(0, key.split(/\s+/).length).join(" ") === key)
|
|
1120
|
+
.sort((a, b) => b.length - a.length)[0];
|
|
1121
|
+
const head = dynamicHead || tokenParts[0] || "";
|
|
1122
|
+
const tail = tokenParts.slice(head.split(/\s+/).length);
|
|
1120
1123
|
const headKey = head.startsWith("/") ? head : `/${head}`;
|
|
1121
1124
|
const headNode = commandTree && typeof commandTree === "object" ? commandTree[headKey] : null;
|
|
1122
1125
|
const argListForHead = argumentLists && typeof argumentLists === "object"
|
|
@@ -1227,7 +1230,7 @@ function buildCompletions({
|
|
|
1227
1230
|
const secondaryList = argumentLists && typeof argumentLists === "object"
|
|
1228
1231
|
? argumentLists[`${headKey}/thinking`] || argumentLists[`${headKey}/think`]
|
|
1229
1232
|
: null;
|
|
1230
|
-
const supportsThinkingMenu =
|
|
1233
|
+
const supportsThinkingMenu = Array.isArray(secondaryList) && secondaryList.length > 0;
|
|
1231
1234
|
|
|
1232
1235
|
// Secondary menu: "/model <id> " or "/model <id> <partial>"
|
|
1233
1236
|
if (supportsThinkingMenu && (
|
|
@@ -1237,6 +1240,9 @@ function buildCompletions({
|
|
|
1237
1240
|
if (tail.length > 2) return [];
|
|
1238
1241
|
const modelId = String(tail[0] || "").trim();
|
|
1239
1242
|
if (!modelId) return [];
|
|
1243
|
+
const modelEntry = argListForHead.find((item) =>
|
|
1244
|
+
String((item && (item.alias || item.cmd || item.id || item.name)) || item || "") === modelId);
|
|
1245
|
+
if (modelEntry && modelEntry.hasChildren === false) return [];
|
|
1240
1246
|
const partial = tail.length >= 2 && !endsWithWhitespace
|
|
1241
1247
|
? String(tail[1] || "").toLowerCase()
|
|
1242
1248
|
: "";
|
|
@@ -1268,17 +1274,15 @@ function buildCompletions({
|
|
|
1268
1274
|
for (const item of argListForHead) {
|
|
1269
1275
|
const id = String((item && (item.alias || item.cmd || item.id || item.name)) || item || "");
|
|
1270
1276
|
if (!id) continue;
|
|
1271
|
-
|
|
1277
|
+
const label = String((item && item.label) || id);
|
|
1278
|
+
if (partial && !id.toLowerCase().startsWith(partial) && !label.toLowerCase().startsWith(partial)) continue;
|
|
1272
1279
|
const desc = String((item && (item.desc || item.summary || item.description || item.source)) || "");
|
|
1273
|
-
const hasChildren =
|
|
1274
|
-
(item && item.hasChildren)
|
|
1275
|
-
|| supportsThinkingMenu
|
|
1276
|
-
);
|
|
1280
|
+
const hasChildren = item && typeof item.hasChildren === "boolean" ? item.hasChildren : supportsThinkingMenu;
|
|
1277
1281
|
out.push({
|
|
1278
1282
|
kind: "argument",
|
|
1279
|
-
label: `${head} ${
|
|
1283
|
+
label: `${head} ${label}`,
|
|
1280
1284
|
// Trailing space keeps the popup open for the thinking submenu.
|
|
1281
|
-
replace:
|
|
1285
|
+
replace: `${head} ${id} `,
|
|
1282
1286
|
description: desc,
|
|
1283
1287
|
hasChildren,
|
|
1284
1288
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function formatToolDistribution(items = []) {
|
|
4
|
+
const tools = Array.isArray(items) ? items : [];
|
|
5
|
+
if (tools.length === 0) return "";
|
|
6
|
+
const visible = tools.slice(0, 2).map((item) => `${item.name}x${item.count}`);
|
|
7
|
+
if (tools.length > 2) {
|
|
8
|
+
visible.push(`+${tools.length - 2}`);
|
|
9
|
+
}
|
|
10
|
+
return visible.join(",");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function formatLoopSummary(loopSummary) {
|
|
14
|
+
if (!loopSummary || typeof loopSummary !== "object") return "";
|
|
15
|
+
const rounds = Number(loopSummary.rounds) || 0;
|
|
16
|
+
const toolCalls = Number(loopSummary.tool_calls) || 0;
|
|
17
|
+
const totalTokens = Number(loopSummary.total_tokens) || 0;
|
|
18
|
+
const inputTokens = Number(loopSummary.input_tokens) || 0;
|
|
19
|
+
const cacheReadTokens = Number(loopSummary.cache_read_tokens) || 0;
|
|
20
|
+
const cacheCreationTokens = Number(loopSummary.cache_creation_tokens) || 0;
|
|
21
|
+
const terminalReason = String(loopSummary.terminal_reason || "").trim();
|
|
22
|
+
const toolDistribution = formatToolDistribution(loopSummary.tools);
|
|
23
|
+
|
|
24
|
+
if (rounds <= 0 && toolCalls <= 0 && totalTokens <= 0 && !terminalReason && !toolDistribution) {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const parts = [
|
|
29
|
+
`r${rounds}`,
|
|
30
|
+
`tc${toolCalls}`,
|
|
31
|
+
`tok${totalTokens}`,
|
|
32
|
+
];
|
|
33
|
+
if (cacheReadTokens > 0 || cacheCreationTokens > 0) {
|
|
34
|
+
let cachePart = `cache${cacheReadTokens}/${cacheCreationTokens}`;
|
|
35
|
+
if (cacheReadTokens > 0) {
|
|
36
|
+
const hitRate = Math.round((cacheReadTokens / (cacheReadTokens + inputTokens)) * 100);
|
|
37
|
+
cachePart += `(${hitRate}%)`;
|
|
38
|
+
}
|
|
39
|
+
parts.push(cachePart);
|
|
40
|
+
}
|
|
41
|
+
if (toolDistribution) {
|
|
42
|
+
parts.push(toolDistribution);
|
|
43
|
+
}
|
|
44
|
+
if (terminalReason) {
|
|
45
|
+
parts.push(terminalReason);
|
|
46
|
+
}
|
|
47
|
+
return parts.join(" ");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = { formatLoopSummary };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared markdown renderer for TUI log output.
|
|
3
3
|
*
|
|
4
|
-
* Produces
|
|
4
|
+
* Produces markup tags for chat history or ANSI styles for terminal surfaces.
|
|
5
5
|
* Terminals cannot change font size, so headings/emphasis use color + weight
|
|
6
6
|
* instead of literal `#` / `**` markers. GFM pipe tables are aligned into a
|
|
7
7
|
* compact spreadsheet-like grid.
|
|
@@ -160,9 +160,8 @@ function createBlessedAdapters(escapeFn = (value) => String(value || "")) {
|
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
function createAnsiAdapters() {
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
// (e.g. piped test harnesses that still render Ink).
|
|
163
|
+
// Surface renderers consume ANSI styles even when the host's stdout is
|
|
164
|
+
// piped, so preserve heading and emphasis colors independently of detection.
|
|
166
165
|
const paint = typeof chalk.Instance === "function"
|
|
167
166
|
? new chalk.Instance({ level: Math.max(Number(chalk.level) || 0, 2) })
|
|
168
167
|
: chalk;
|