u-foo 4.0.10 → 4.1.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/OPTIONAL_SKILLS/ufoo-bus-poll/SKILL.md +27 -0
- package/README.md +279 -789
- package/README.zh-CN.md +290 -439
- package/SKILLS/ufoo/SKILL.md +7 -0
- package/bin/ufoo.js +36 -3
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/docs/OBSERVABILITY.md +4 -2
- package/docs/README.md +1 -0
- package/package.json +6 -2
- package/scripts/pack-desktop.js +174 -0
- package/src/agents/capabilities/coding/index.js +26 -3
- package/src/agents/capabilities/index.js +2 -1
- package/src/agents/capabilities/mac/index.js +145 -0
- package/src/agents/capabilities/planning/index.js +1 -1
- package/src/agents/capabilities/turnRecall/index.js +5 -16
- package/src/agents/profiles/coding.js +1 -1
- package/src/agents/profiles/main.js +1 -1
- package/src/agents/providers/nativeTransport.js +105 -116
- package/src/agents/providers/runtimeConfig.js +15 -4
- package/src/agents/providers/transports/anthropicCache.js +78 -0
- package/src/agents/providers/transports/antigravityTransport.js +3 -2
- package/src/agents/providers/transports/openaiResponsesTransport.js +7 -12
- package/src/agents/providers/transports/requestCacheObservation.js +61 -0
- package/src/agents/providers/transports/responsesProtocol.js +54 -46
- package/src/agents/providers/upstreamRuntime.js +2 -2
- package/src/agents/runtime/context/contextWindow.js +10 -0
- package/src/agents/runtime/context/slidingWindowManager.js +97 -41
- package/src/agents/runtime/context/topicSelector.js +4 -2
- package/src/agents/runtime/context/turnAnalyzer.js +17 -29
- package/src/agents/runtime/core/agentLoop.js +23 -7
- package/src/agents/runtime/createAgentRuntime.js +1 -1
- package/src/agents/runtime/protocol/auxiliaryModelRequest.js +28 -0
- package/src/app/chat/ChatController.js +1 -0
- package/src/app/chat/commandExecutor.js +25 -0
- package/src/app/chat/commands.js +2 -0
- package/src/app/chat/daemonMessageRouter.js +30 -3
- package/src/app/cli/appCommands.js +107 -0
- package/src/app/cli/features/skills.js +2 -0
- package/src/app/cli/macCommands.js +321 -0
- package/src/app/cli/metricsCommands.js +6 -1
- package/src/app/cli/run.js +26 -0
- package/src/app/cli/setupCommands.js +1 -0
- package/src/code/agent.js +1 -0
- package/src/code/context/assembler.js +8 -6
- package/src/code/context/promptLayers.js +3 -1
- package/src/code/context/stateCommit.js +2 -2
- package/src/code/context/transcript.js +11 -5
- package/src/code/nativeRunner.js +25 -5
- package/src/code/skills/loader.js +10 -2
- package/src/code/skills/render.js +8 -1
- package/src/config.js +42 -0
- package/src/coordination/bus/activate.js +44 -19
- package/src/coordination/history/agentPerformance.js +88 -11
- package/src/coordination/history/agentTrace.js +2 -0
- package/src/coordination/history/modelInputCost.js +52 -0
- package/src/runtime/contracts/uiProtocol.js +26 -0
- package/src/runtime/daemon/agentHost.js +35 -12
- package/src/runtime/daemon/mcpStdioProxy.js +3 -2
- package/src/runtime/mac/helperClient.js +279 -0
- package/src/runtime/mac/helperCompiler.js +235 -0
- package/src/runtime/mac/macSession.js +866 -0
- package/src/runtime/mac/native/ufoo_mac_helper.swift +2493 -0
- package/src/runtime/mac/paths.js +63 -0
- package/src/ui/agentSettingsController.js +12 -5
- package/src/ui/cliHandoff.js +484 -0
- package/src/ui/desktopArchive.js +41 -0
- package/src/ui/desktopUiHost.js +1601 -0
- package/src/ui/desktopUiHostCli.js +66 -0
- package/src/ui/format/index.js +17 -0
- package/src/ui/rustChatHost.js +45 -6
- package/src/ui/workspaceInspector.js +621 -0
|
@@ -65,38 +65,25 @@ const CONTINUATION_CUES = [
|
|
|
65
65
|
/^(continue|proceed|go ahead|yes|ok|okay|sure|fix that|fix it|try again|also|and then|now)\b/i,
|
|
66
66
|
];
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
if (typeof text !== "string") return "";
|
|
70
|
-
return text.replace(/<turn_context(?:\s+[^>]*)?>[\s\S]*?<\/turn_context>\s*/gi, "").trim();
|
|
71
|
-
}
|
|
68
|
+
const TURN_CONTEXT_SOURCE = Symbol.for("ufoo.turnContextSource");
|
|
72
69
|
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return content
|
|
77
|
-
.map((part) => {
|
|
78
|
-
if (!part || typeof part !== "object") return part;
|
|
79
|
-
if (part.type === "text" && typeof part.text === "string") {
|
|
80
|
-
const cleaned = stripTurnContextWrapper(part.text);
|
|
81
|
-
if (!cleaned) return null;
|
|
82
|
-
return cleaned === part.text ? part : { ...part, text: cleaned };
|
|
83
|
-
}
|
|
84
|
-
return part;
|
|
85
|
-
})
|
|
86
|
-
.filter(Boolean);
|
|
70
|
+
function stripTurnContextFromMessage(message) {
|
|
71
|
+
const source = message?.[TURN_CONTEXT_SOURCE];
|
|
72
|
+
return source ? { ...message, content: source.originalContent } : message;
|
|
87
73
|
}
|
|
88
74
|
|
|
89
75
|
function extractTextFromMessage(message, { includeThinking = false } = {}) {
|
|
90
76
|
if (!message || typeof message !== "object") return "";
|
|
77
|
+
message = stripTurnContextFromMessage(message);
|
|
91
78
|
if (typeof message.content === "string") {
|
|
92
|
-
return message.
|
|
79
|
+
return message.content.trim();
|
|
93
80
|
}
|
|
94
81
|
if (!Array.isArray(message.content)) return "";
|
|
95
82
|
const chunks = [];
|
|
96
83
|
for (const part of message.content) {
|
|
97
84
|
if (!part || typeof part !== "object") continue;
|
|
98
85
|
if (part.type === "text" && typeof part.text === "string") {
|
|
99
|
-
const text =
|
|
86
|
+
const text = part.text;
|
|
100
87
|
if (text.trim()) chunks.push(text.trim());
|
|
101
88
|
} else if (includeThinking && part.type === "thinking" && typeof part.thinking === "string") {
|
|
102
89
|
if (part.thinking.trim()) chunks.push(part.thinking.trim());
|
|
@@ -325,8 +312,8 @@ function classifyTurnKind({ requestKind = "user", prompt = "", turnMessages = []
|
|
|
325
312
|
return "resumed_interaction";
|
|
326
313
|
}
|
|
327
314
|
const firstUser = (turnMessages || []).find((m) => m && m.role === "user");
|
|
328
|
-
const instruction = firstUser ?
|
|
329
|
-
if (!instruction && !
|
|
315
|
+
const instruction = firstUser ? userInstruction(stripTurnContextFromMessage(firstUser)) : "";
|
|
316
|
+
if (!instruction && !String(prompt || "") && (turnMessages || []).length > 0) {
|
|
330
317
|
const hasToolResults = (turnMessages || []).some((m) => m && (m.role === "tool" || (Array.isArray(m.content) && m.content.some((p) => p && p.type === "tool_result"))));
|
|
331
318
|
if (hasToolResults) return "tool_continuation";
|
|
332
319
|
}
|
|
@@ -365,7 +352,7 @@ function buildDeterministicTurnRecord({
|
|
|
365
352
|
for (const msg of messages) {
|
|
366
353
|
if (!msg || typeof msg !== "object") continue;
|
|
367
354
|
if (msg.role === "user") {
|
|
368
|
-
const instruction =
|
|
355
|
+
const instruction = userInstruction(stripTurnContextFromMessage(msg)) || extractTextFromMessage(msg);
|
|
369
356
|
if (instruction) userTexts.push(instruction);
|
|
370
357
|
} else if (msg.role === "assistant") {
|
|
371
358
|
const text = extractTextFromMessage(msg);
|
|
@@ -397,7 +384,7 @@ function buildDeterministicTurnRecord({
|
|
|
397
384
|
}
|
|
398
385
|
}
|
|
399
386
|
|
|
400
|
-
const cleanedPrompt =
|
|
387
|
+
const cleanedPrompt = String(prompt || "");
|
|
401
388
|
const rawUserText = userTexts[0] || cleanedPrompt || (turnKind === "system_wake" ? `[${requestKind}]` : "");
|
|
402
389
|
const finalAssistantText = assistantTexts[assistantTexts.length - 1] || "";
|
|
403
390
|
|
|
@@ -653,7 +640,7 @@ function createAsyncTurnEnricher({
|
|
|
653
640
|
const queue = [];
|
|
654
641
|
|
|
655
642
|
async function processOne(item) {
|
|
656
|
-
const { turn, expectedHash } = item;
|
|
643
|
+
const { turn, expectedHash, requestContext } = item;
|
|
657
644
|
if (closed || typeof runAuxModel !== "function") return;
|
|
658
645
|
activeController = new AbortController();
|
|
659
646
|
let timedOut = false;
|
|
@@ -666,6 +653,7 @@ function createAsyncTurnEnricher({
|
|
|
666
653
|
try {
|
|
667
654
|
const raw = await runAuxModel({
|
|
668
655
|
purpose: "turn_enrich",
|
|
656
|
+
requestContext,
|
|
669
657
|
turn,
|
|
670
658
|
existingTopics: store.listTopics().slice(0, 12),
|
|
671
659
|
signal: activeController.signal,
|
|
@@ -713,11 +701,11 @@ function createAsyncTurnEnricher({
|
|
|
713
701
|
})();
|
|
714
702
|
}
|
|
715
703
|
|
|
716
|
-
function enqueue(turnRecord) {
|
|
704
|
+
function enqueue(turnRecord, requestContext) {
|
|
717
705
|
if (closed || !enabled || typeof runAuxModel !== "function") return false;
|
|
718
706
|
if (!turnRecord || !turnRecord.turnId) return false;
|
|
719
707
|
const existingIdx = queue.findIndex((item) => item.turn.turnId === turnRecord.turnId);
|
|
720
|
-
const entry = { turn: turnRecord, expectedHash: turnRecord.contentHash || "" };
|
|
708
|
+
const entry = { turn: turnRecord, expectedHash: turnRecord.contentHash || "", requestContext };
|
|
721
709
|
if (existingIdx >= 0) {
|
|
722
710
|
queue[existingIdx] = entry;
|
|
723
711
|
} else {
|
|
@@ -756,8 +744,8 @@ function createAsyncTurnEnricher({
|
|
|
756
744
|
}
|
|
757
745
|
|
|
758
746
|
module.exports = {
|
|
759
|
-
|
|
760
|
-
|
|
747
|
+
TURN_CONTEXT_SOURCE,
|
|
748
|
+
stripTurnContextFromMessage,
|
|
761
749
|
classifyTurnKind,
|
|
762
750
|
buildDeterministicTurnRecord,
|
|
763
751
|
backfillMissingTurns,
|
|
@@ -33,7 +33,7 @@ function createExecutionGuards({ signal = null, timeoutMs = 43200000 } = {}) {
|
|
|
33
33
|
/** Shared model/tool loop. All business policies and tools are injected. */
|
|
34
34
|
async function runAgentLoop({
|
|
35
35
|
transport, tools, policies = [], workspaceRoot = process.cwd(),
|
|
36
|
-
prompt = "", systemPrompt = "", systemBlocks = null, historyMessages = [],
|
|
36
|
+
prompt = "", systemPrompt = "", systemBlocks = null, turnSupplement = "", historyMessages = [],
|
|
37
37
|
model = "", baseUrl = "", apiKey = "", provider = "", accountId = "", requestHeaders = {}, requestProfile = "",
|
|
38
38
|
thinkingLevel = "", requestKind = "unknown",
|
|
39
39
|
timeoutMs = 43200000, onStreamDelta = null, onThinkingDelta = null,
|
|
@@ -94,6 +94,7 @@ async function runAgentLoop({
|
|
|
94
94
|
let isolatedPrefix = 0;
|
|
95
95
|
let turnId = "";
|
|
96
96
|
let lastContextEstimate = 0;
|
|
97
|
+
let lastContextWindow;
|
|
97
98
|
let forceCompaction = false;
|
|
98
99
|
let contextRetry = false;
|
|
99
100
|
const context = () => ({ executionState, messages, loopGuard, usage, toolCallsExecuted, toolErrors, turnId });
|
|
@@ -132,7 +133,7 @@ async function runAgentLoop({
|
|
|
132
133
|
};
|
|
133
134
|
const finish = (extra = {}) => ({
|
|
134
135
|
text: aggregated, finalText: "", streamed, toolCallsExecuted, messages,
|
|
135
|
-
turnItems: currentTurnItems(), usage, executionState,
|
|
136
|
+
turnItems: currentTurnItems(), usage, executionState, contextWindow: lastContextWindow,
|
|
136
137
|
protocolLedger: lastLedger || ledgerApi.snapshotLedger(activeLedger), historyOffset, ...extra,
|
|
137
138
|
});
|
|
138
139
|
let committedMessages = messages.length;
|
|
@@ -198,6 +199,9 @@ async function runAgentLoop({
|
|
|
198
199
|
const requestTools = errorStop ? [] : tools.toOpenAiTools();
|
|
199
200
|
|
|
200
201
|
let maxOutputTokens;
|
|
202
|
+
let contextWindow;
|
|
203
|
+
let compressionReason = null;
|
|
204
|
+
let strategyVersion = 1;
|
|
201
205
|
if (contextManager) {
|
|
202
206
|
let sysPrefix = 0;
|
|
203
207
|
while (sysPrefix < providerMessages.length && String(providerMessages[sysPrefix]?.role || "").toLowerCase() === "system") sysPrefix += 1;
|
|
@@ -206,7 +210,7 @@ async function runAgentLoop({
|
|
|
206
210
|
: Math.min(providerMessages.length, sysPrefix + historyOffset);
|
|
207
211
|
const logicalTurnId = taskRunId || (sessionId ? `${sessionId}:${historyOffset}` : `offset_${historyOffset}`);
|
|
208
212
|
let prepared;
|
|
209
|
-
try { prepared = await contextManager.prepare({ messages: providerMessages, model: requestModel, systemPrompt, systemBlocks,
|
|
213
|
+
try { prepared = await contextManager.prepare({ messages: providerMessages, model: requestModel, systemPrompt, systemBlocks, turnSupplement,
|
|
210
214
|
tools: requestTools, transport, signal, onPhase, onEvent: event,
|
|
211
215
|
lastUsage: usage.lastContextTokens, lastEstimate: lastContextEstimate,
|
|
212
216
|
force: forceCompaction, historyOffset: prepareHistoryOffset, requestKind, turnId: logicalTurnId, resume,
|
|
@@ -221,6 +225,9 @@ async function runAgentLoop({
|
|
|
221
225
|
isolatedPrefix = providerMessages.length;
|
|
222
226
|
lastContextEstimate = prepared.estimatedTokens;
|
|
223
227
|
maxOutputTokens = prepared.maxOutputTokens;
|
|
228
|
+
contextWindow = prepared.meta?.contextWindow;
|
|
229
|
+
compressionReason = prepared.meta?.compressionReason || null;
|
|
230
|
+
strategyVersion = prepared.meta?.strategyVersion || 1;
|
|
224
231
|
forceCompaction = false;
|
|
225
232
|
}
|
|
226
233
|
// Only newly generated messages are mirrored into the full transcript.
|
|
@@ -229,11 +236,15 @@ async function runAgentLoop({
|
|
|
229
236
|
try { activeGuards.ensureActive(); }
|
|
230
237
|
catch (error) { return finish({ error: error.message, stopReason: error.code || "runtime_error" }); }
|
|
231
238
|
const modelStarted = Date.now();
|
|
232
|
-
|
|
239
|
+
const transportName = transport.name || transport.id || "";
|
|
240
|
+
const modelRequest = { modelRequestId: randomUUID(), purpose: "foreground", provider, model: requestModel,
|
|
241
|
+
transport: transportName, channel: requestProfile || transportName, compressionReason, strategyVersion };
|
|
242
|
+
await event("model.started", { ...modelRequest, estimatedInputTokens: lastContextEstimate });
|
|
233
243
|
const streamEvents = [];
|
|
234
244
|
let streamEventError = null;
|
|
235
245
|
let turnResult;
|
|
236
246
|
let turnError = null;
|
|
247
|
+
let cacheRequest;
|
|
237
248
|
const outputBeforeTurn = aggregated.length;
|
|
238
249
|
let stepStreamedText = false;
|
|
239
250
|
try { turnResult = await transport.runTurn({
|
|
@@ -241,6 +252,8 @@ async function runAgentLoop({
|
|
|
241
252
|
systemPrompt, systemBlocks, messages: providerMessages, tools: requestTools,
|
|
242
253
|
...(maxOutputTokens ? { maxOutputTokens } : {}),
|
|
243
254
|
sessionId, signal, timeoutMs,
|
|
255
|
+
requestScope: workspaceRoot, requestPurpose: "foreground", strategyVersion,
|
|
256
|
+
onRequest(value) { cacheRequest = value; },
|
|
244
257
|
onPhase(phase) {
|
|
245
258
|
streamEvents.push(event("model.phase", { phase }).catch(error => { streamEventError ||= error; }));
|
|
246
259
|
onPhase?.(phase);
|
|
@@ -268,7 +281,8 @@ async function runAgentLoop({
|
|
|
268
281
|
if (streamEventError) throw streamEventError;
|
|
269
282
|
}
|
|
270
283
|
if (turnError) {
|
|
271
|
-
await event("model.failed", {
|
|
284
|
+
await event("model.failed", { ...modelRequest, cacheRequest, channel: cacheRequest?.channel || modelRequest.channel,
|
|
285
|
+
error: turnError.message, code: turnError.code || "provider_error", durationMs: Date.now() - modelStarted });
|
|
272
286
|
if (errorStop) return finish({ ...errorStop, summaryError: turnError.message });
|
|
273
287
|
if (!contextManager || !isContextOverflow(turnError)) throw turnError;
|
|
274
288
|
if (contextRetry || aggregated.length !== outputBeforeTurn) return finish({ error: turnError.message, stopReason: "context_budget_exceeded" });
|
|
@@ -278,15 +292,17 @@ async function runAgentLoop({
|
|
|
278
292
|
continue;
|
|
279
293
|
}
|
|
280
294
|
contextRetry = false;
|
|
295
|
+
await event("model.completed", { ...modelRequest, cacheRequest, channel: cacheRequest?.channel || modelRequest.channel,
|
|
296
|
+
model: turnResult?.actualModel || requestModel, usage: turnResult?.usage, providerRequestId: turnResult?.responseId, durationMs: Date.now() - modelStarted });
|
|
281
297
|
activeGuards.ensureActive();
|
|
282
298
|
retireImages(providerMessages);
|
|
283
299
|
if (providerMessages !== messages) retireImages(messages);
|
|
284
300
|
usage.turns += 1;
|
|
285
301
|
for (const key of ["input", "output", "cacheRead", "cacheCreation"]) usage[key] += count(turnResult && turnResult.usage && turnResult.usage[key]);
|
|
286
302
|
usage.lastContextTokens = contextTokensFromUsage(turnResult && turnResult.usage);
|
|
287
|
-
|
|
303
|
+
lastContextWindow = contextWindow;
|
|
288
304
|
if (typeof onContextUsage === "function") {
|
|
289
|
-
try { onContextUsage(buildContextMeter({ usedTokens: usage.lastContextTokens, model: requestModel })); } catch { /* observer only */ }
|
|
305
|
+
try { onContextUsage(buildContextMeter({ usedTokens: usage.lastContextTokens, limitTokens: contextWindow, model: requestModel })); } catch { /* observer only */ }
|
|
290
306
|
}
|
|
291
307
|
if (errorStop) {
|
|
292
308
|
// Exactly one text-only closing attempt: never execute tool/legacy commands,
|
|
@@ -68,7 +68,7 @@ function createAgentRuntime({ profile, transport, capabilities, host = {}, defau
|
|
|
68
68
|
if (state.owner && pidAlive(state.owner.pid)) throw Object.assign(new Error("runtime session already owned"), { code: "runtime_busy" });
|
|
69
69
|
const selectedCapabilities = composition.capabilities.map((capability) => capability.id);
|
|
70
70
|
const matchesAdditively = Array.isArray(state.capabilities)
|
|
71
|
-
&& stableStringify(state.capabilities) === stableStringify(selectedCapabilities.filter((id) => !["turn-recall", "browser"].includes(id) || state.capabilities.includes(id)));
|
|
71
|
+
&& stableStringify(state.capabilities) === stableStringify(selectedCapabilities.filter((id) => !["turn-recall", "browser", "mac-app"].includes(id) || state.capabilities.includes(id)));
|
|
72
72
|
if (state.capabilities && stableStringify(state.capabilities) !== stableStringify(selectedCapabilities) && !matchesAdditively
|
|
73
73
|
&& Object.values(state.tasks).some((task) => ["queued", "running", "waiting_user"].includes(task.status))) throw new Error("cannot change capabilities with unfinished state; use a new session or explicit migration");
|
|
74
74
|
interruptedTasks = Object.values(state.tasks).filter((task) => task.status === "running");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { randomUUID } = require("crypto");
|
|
4
|
+
|
|
5
|
+
async function runAuxiliaryModelRequest(transport, { purpose, onEvent, ...request }) {
|
|
6
|
+
const startedAt = Date.now();
|
|
7
|
+
const metadata = {
|
|
8
|
+
modelRequestId: randomUUID(), purpose, provider: request.provider, model: request.model,
|
|
9
|
+
transport: transport.name || transport.id || "", channel: request.requestProfile || transport.name || transport.id || "",
|
|
10
|
+
};
|
|
11
|
+
const observe = async (type, properties = {}) => {
|
|
12
|
+
try { await onEvent?.({ ...metadata, ...properties, type }); } catch { /* observer only */ }
|
|
13
|
+
};
|
|
14
|
+
await observe("model.started");
|
|
15
|
+
let cacheRequest;
|
|
16
|
+
try {
|
|
17
|
+
const result = await transport.runTurn({ ...request, requestPurpose: purpose, onRequest: value => { cacheRequest = value; } });
|
|
18
|
+
await observe("model.completed", { durationMs: Date.now() - startedAt, usage: result?.usage, cacheRequest,
|
|
19
|
+
channel: cacheRequest?.channel || metadata.channel, model: result?.actualModel || request.model, providerRequestId: result?.responseId });
|
|
20
|
+
return result;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
await observe("model.failed", { durationMs: Date.now() - startedAt, cacheRequest,
|
|
23
|
+
channel: cacheRequest?.channel || metadata.channel, code: error.code || "provider_error" });
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = { runAuxiliaryModelRequest };
|
|
@@ -207,6 +207,7 @@ function createChatController({
|
|
|
207
207
|
? ports.applyChatSettings
|
|
208
208
|
: null,
|
|
209
209
|
openResumeMenu: typeof ports.openResumeMenu === "function" ? ports.openResumeMenu : null,
|
|
210
|
+
openDesktopApp: typeof ports.openDesktopApp === "function" ? ports.openDesktopApp : null,
|
|
210
211
|
});
|
|
211
212
|
return commandExecutor;
|
|
212
213
|
}
|
|
@@ -1749,6 +1749,28 @@ function createCommandExecutor(options = {}) {
|
|
|
1749
1749
|
logMessage("error", "{white-fg}✗{/white-fg} Window layouts are not available");
|
|
1750
1750
|
}
|
|
1751
1751
|
return true;
|
|
1752
|
+
case "app": {
|
|
1753
|
+
if (typeof options.openDesktopApp === "function") {
|
|
1754
|
+
const res = await options.openDesktopApp(args);
|
|
1755
|
+
if (res && res.ok) {
|
|
1756
|
+
logMessage("system", `{white-fg}✓{/white-fg} Handed off to Ufoo Desktop (${escapeBlessed(res.url || "")})`);
|
|
1757
|
+
} else {
|
|
1758
|
+
logMessage("error", `{white-fg}✗{/white-fg} ${escapeBlessed((res && res.error) || "Failed to open Ufoo Desktop")}`);
|
|
1759
|
+
}
|
|
1760
|
+
} else {
|
|
1761
|
+
const { openInDesktopApp } = require("../../ui/cliHandoff");
|
|
1762
|
+
const activeRoot = typeof options.getActiveProjectRoot === "function"
|
|
1763
|
+
? options.getActiveProjectRoot()
|
|
1764
|
+
: projectRoot;
|
|
1765
|
+
const res = await openInDesktopApp({
|
|
1766
|
+
projectRoot: activeRoot || projectRoot,
|
|
1767
|
+
target: args[0] || "main",
|
|
1768
|
+
});
|
|
1769
|
+
if (res.ok) logMessage("system", `{white-fg}✓{/white-fg} Handed off to Ufoo Desktop (${escapeBlessed(res.url)})`);
|
|
1770
|
+
else logMessage("error", `{white-fg}✗{/white-fg} ${escapeBlessed(res.error)}`);
|
|
1771
|
+
}
|
|
1772
|
+
return true;
|
|
1773
|
+
}
|
|
1752
1774
|
case "mcp":
|
|
1753
1775
|
await handleMcpCommand(args);
|
|
1754
1776
|
return true;
|
|
@@ -1803,6 +1825,9 @@ function createCommandExecutor(options = {}) {
|
|
|
1803
1825
|
case "settings":
|
|
1804
1826
|
await handleSettingsCommand(args);
|
|
1805
1827
|
return true;
|
|
1828
|
+
case "model":
|
|
1829
|
+
await handleAgentSettingsCommand(["model", ...args]);
|
|
1830
|
+
return true;
|
|
1806
1831
|
case "ufoo":
|
|
1807
1832
|
await handleUfooCommand(args);
|
|
1808
1833
|
return true;
|
package/src/app/chat/commands.js
CHANGED
|
@@ -50,6 +50,7 @@ const COMMAND_TREE = {
|
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
52
|
"/clear": { desc: "Clear chat log on screen" },
|
|
53
|
+
"/model": { desc: "Select a model for the current ufoo provider", hasArguments: true },
|
|
53
54
|
"/group": {
|
|
54
55
|
desc: "Agent group orchestration",
|
|
55
56
|
children: {
|
|
@@ -157,6 +158,7 @@ const COMMAND_TREE = {
|
|
|
157
158
|
"/status": { desc: "Status display" },
|
|
158
159
|
"/task": { desc: "Main agent tasks", children: { list: { desc: "List durable tasks" }, inspect: { desc: "Inspect a child task" }, cancel: { desc: "Cancel a task by run ID" } } },
|
|
159
160
|
"/answer": { desc: "Answer a runtime interaction: /answer <interaction-id> <reply>" },
|
|
161
|
+
"/app": { desc: "Hand off current project or focused worker to Ufoo Desktop App" },
|
|
160
162
|
"/session": { desc: "Main conversation", children: { show: { desc: "Show conversation ID" }, new: { desc: "Start a conversation with current settings" } } },
|
|
161
163
|
"/ufoo": { desc: "ufoo protocol" },
|
|
162
164
|
};
|
|
@@ -25,14 +25,22 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
25
25
|
setTransientAgentState = () => {},
|
|
26
26
|
clearTransientAgentState = () => {},
|
|
27
27
|
refreshDashboard = () => {},
|
|
28
|
+
isOwnRequestId = () => false,
|
|
29
|
+
onInteractionRequest = null,
|
|
30
|
+
onInteractionClear = null,
|
|
31
|
+
onRuntimeEvent = null,
|
|
28
32
|
} = options;
|
|
29
33
|
const runtimeSequences = new Map();
|
|
30
34
|
const runtimeStreams = new Map();
|
|
31
35
|
const runtimeFinished = new Set();
|
|
32
36
|
const runtimeInteractions = new Set();
|
|
33
|
-
|
|
37
|
+
const renderedPeerRequests = new Set();
|
|
38
|
+
function showInteraction(interaction, context = {}) {
|
|
34
39
|
if (!interaction || runtimeInteractions.has(interaction.id)) return;
|
|
35
40
|
runtimeInteractions.add(interaction.id);
|
|
41
|
+
if (typeof onInteractionRequest === "function") {
|
|
42
|
+
onInteractionRequest({ ...interaction, ...context });
|
|
43
|
+
}
|
|
36
44
|
logMessage("system", escapeBlessed(`${interaction.prompt}\n${(interaction.options || []).map((option) => `[${option.key}] ${option.label}`).join(" ")}\n/answer ${interaction.id} <reply>`));
|
|
37
45
|
}
|
|
38
46
|
function handleRuntimeEvent(event) {
|
|
@@ -40,9 +48,28 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
40
48
|
const sessionKey = `${event.projectId || ""}:${event.sessionId}`;
|
|
41
49
|
if (event.sequence <= (runtimeSequences.get(sessionKey) || 0)) return true;
|
|
42
50
|
runtimeSequences.set(sessionKey, event.sequence);
|
|
51
|
+
if (typeof onRuntimeEvent === "function") {
|
|
52
|
+
try { onRuntimeEvent(event); } catch { /* ignore observer errors */ }
|
|
53
|
+
}
|
|
43
54
|
const key = `${sessionKey}:${event.taskRunId}`;
|
|
44
55
|
const label = event.agentId === "ufoo-agent" ? "ufoo" : `task ${event.taskRunId}`;
|
|
45
|
-
if (event.type === "
|
|
56
|
+
if (event.type === "request.accepted" && event.agentId === "ufoo-agent") {
|
|
57
|
+
const req = event.request && typeof event.request === "object" ? event.request : {};
|
|
58
|
+
const reqId = String(req.requestId || "").trim();
|
|
59
|
+
const isUserTurn = !req.runtimeEvent && !req.report && !req.parentTaskRunId;
|
|
60
|
+
const promptText = String(req.text || "").trim();
|
|
61
|
+
if (isUserTurn && promptText && (!reqId || (!isOwnRequestId(reqId) && !renderedPeerRequests.has(reqId)))) {
|
|
62
|
+
if (reqId) {
|
|
63
|
+
renderedPeerRequests.add(reqId);
|
|
64
|
+
if (renderedPeerRequests.size > 500) renderedPeerRequests.delete(renderedPeerRequests.values().next().value);
|
|
65
|
+
}
|
|
66
|
+
logMessage("user", escapeBlessed(promptText));
|
|
67
|
+
}
|
|
68
|
+
} else if (event.type === "interaction.answered") {
|
|
69
|
+
if (typeof onInteractionClear === "function") {
|
|
70
|
+
onInteractionClear({ id: event.interactionId || "", sessionId: event.sessionId, taskRunId: event.taskRunId });
|
|
71
|
+
}
|
|
72
|
+
} else if (event.type === "message.delta") {
|
|
46
73
|
const state = beginStream(key, speakerPrefix(label, "white"), " ", { runtime: true, sessionId: event.sessionId, taskRunId: event.taskRunId });
|
|
47
74
|
appendStreamDelta(state, event.text || "");
|
|
48
75
|
runtimeStreams.set(key, true);
|
|
@@ -56,7 +83,7 @@ function createDaemonMessageRouter(options = {}) {
|
|
|
56
83
|
if (text) logMessage("reply", `${speakerPrefix(label, "white")}${escapeBlessed(text)}`);
|
|
57
84
|
}
|
|
58
85
|
if (["task.failed", "task.interrupted"].includes(event.type)) logMessage("error", escapeBlessed(`${label}: ${event.error || event.type}`));
|
|
59
|
-
if (event.type === "task.paused") showInteraction(event.result?.executionState?.pendingUserInteraction);
|
|
86
|
+
if (event.type === "task.paused") showInteraction(event.result?.executionState?.pendingUserInteraction, { sessionId: event.sessionId, taskRunId: event.taskRunId });
|
|
60
87
|
runtimeFinished.add(event.taskRunId);
|
|
61
88
|
if (runtimeFinished.size > 500) runtimeFinished.delete(runtimeFinished.values().next().value);
|
|
62
89
|
requestStatus();
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { openInDesktopApp, installCliShims } = require("../../ui/cliHandoff");
|
|
6
|
+
const { canonicalProjectRoot } = require("../../runtime/projects/projectId");
|
|
7
|
+
|
|
8
|
+
function printAppHelp() {
|
|
9
|
+
console.log("Usage: ufoo app [project-path] [options]");
|
|
10
|
+
console.log("");
|
|
11
|
+
console.log("Open or hand off the current workspace to Ufoo Desktop App (macOS).");
|
|
12
|
+
console.log("");
|
|
13
|
+
console.log("Options:");
|
|
14
|
+
console.log(" --agent <id> Focus a specific Worker Agent in single-agent view");
|
|
15
|
+
console.log(" --window <mode> Open project root in main, side, or multi window mode");
|
|
16
|
+
console.log(" --doc <path> Open a workspace document in the Right Inspector");
|
|
17
|
+
console.log(" --install-cli Install ufoo/ucode/uclaude/ucodex shims to ~/.ufoo/bin");
|
|
18
|
+
console.log(" --zshrc Append ~/.ufoo/bin to ~/.zshrc when used with --install-cli");
|
|
19
|
+
console.log(" --json Print structured JSON result");
|
|
20
|
+
console.log(" -h, --help Show help");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function parseAppCliArgs(argv = []) {
|
|
24
|
+
const out = {
|
|
25
|
+
projectRoot: "",
|
|
26
|
+
target: "main",
|
|
27
|
+
windowMode: "",
|
|
28
|
+
docPath: "",
|
|
29
|
+
installCli: false,
|
|
30
|
+
updateZshrc: false,
|
|
31
|
+
json: false,
|
|
32
|
+
help: false,
|
|
33
|
+
};
|
|
34
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
35
|
+
const arg = String(argv[i] || "");
|
|
36
|
+
if (arg === "-h" || arg === "--help") out.help = true;
|
|
37
|
+
else if (arg === "--install-cli") out.installCli = true;
|
|
38
|
+
else if (arg === "--zshrc") out.updateZshrc = true;
|
|
39
|
+
else if (arg === "--json") out.json = true;
|
|
40
|
+
else if (arg === "--agent" && argv[i + 1]) {
|
|
41
|
+
out.target = String(argv[++i]).trim();
|
|
42
|
+
} else if (arg === "--window" && argv[i + 1]) {
|
|
43
|
+
out.windowMode = String(argv[++i]).trim().toLowerCase();
|
|
44
|
+
} else if (arg === "--doc" && argv[i + 1]) {
|
|
45
|
+
out.docPath = String(argv[++i]).trim();
|
|
46
|
+
} else if (!arg.startsWith("-") && !out.projectRoot) {
|
|
47
|
+
out.projectRoot = arg;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function runAppCommand(argv = []) {
|
|
54
|
+
const parsed = parseAppCliArgs(argv);
|
|
55
|
+
if (parsed.help) {
|
|
56
|
+
printAppHelp();
|
|
57
|
+
return { ok: true, help: true };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (parsed.installCli) {
|
|
61
|
+
const res = installCliShims({ updateZshrc: parsed.updateZshrc });
|
|
62
|
+
if (parsed.json) {
|
|
63
|
+
console.log(JSON.stringify(res, null, 2));
|
|
64
|
+
} else {
|
|
65
|
+
console.log(`Installed ${res.installed.length} CLI shims into ${res.targetDir}`);
|
|
66
|
+
if (!res.inPath) {
|
|
67
|
+
console.log(`Add to PATH: export PATH="${res.targetDir}:$PATH"`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return res;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const rawRoot = parsed.projectRoot || process.cwd();
|
|
74
|
+
let projectRoot = path.resolve(rawRoot);
|
|
75
|
+
try {
|
|
76
|
+
projectRoot = canonicalProjectRoot(rawRoot);
|
|
77
|
+
} catch {
|
|
78
|
+
// keep resolved path
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const result = await openInDesktopApp({
|
|
82
|
+
projectRoot,
|
|
83
|
+
target: parsed.target || "main",
|
|
84
|
+
windowMode: parsed.windowMode || "",
|
|
85
|
+
docPath: parsed.docPath || "",
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (parsed.json) {
|
|
89
|
+
console.log(JSON.stringify(result, null, 2));
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (result.ok) {
|
|
94
|
+
console.log(`Handed off to Ufoo Desktop (${result.url})`);
|
|
95
|
+
} else {
|
|
96
|
+
console.error(`Could not open Ufoo Desktop: ${result.error}`);
|
|
97
|
+
console.error(`Deep link: ${result.url}`);
|
|
98
|
+
process.exitCode = 1;
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = {
|
|
104
|
+
runAppCommand,
|
|
105
|
+
parseAppCliArgs,
|
|
106
|
+
printAppHelp,
|
|
107
|
+
};
|
|
@@ -90,6 +90,8 @@ class SkillsManager {
|
|
|
90
90
|
target = path.join(codexHome, "skills");
|
|
91
91
|
} else if (options.agents) {
|
|
92
92
|
target = path.join(process.env.HOME, ".agents", "skills");
|
|
93
|
+
} else if (options.agy) {
|
|
94
|
+
target = path.join(process.env.HOME, ".gemini", "config", "skills");
|
|
93
95
|
} else {
|
|
94
96
|
target = path.join(process.env.HOME, ".claude", "skills");
|
|
95
97
|
}
|