u-foo 3.1.6 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -13
- package/README.zh-CN.md +108 -13
- package/SKILLS/ufoo/SKILL.md +15 -3
- package/SKILLS/ufoo-bus/SKILL.md +21 -1
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +3 -1
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/dist/tui/darwin-x64/ufoo-tui +0 -0
- package/dist/tui/linux-arm64/ufoo-tui +0 -0
- package/dist/tui/linux-x64/ufoo-tui +0 -0
- package/package.json +10 -3
- package/scripts/postinstall-skills.js +53 -0
- package/scripts/postinstall.js +11 -16
- package/scripts/smoke-native-messages.js +214 -0
- package/src/agents/activity/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +113 -0
- package/src/agents/capabilities/agentRouting/index.js +4 -0
- package/src/agents/capabilities/coding/index.js +32 -0
- package/src/agents/capabilities/coordination/index.js +37 -0
- package/src/agents/capabilities/globalRouting/index.js +5 -0
- package/src/agents/capabilities/groups/index.js +3 -0
- package/src/agents/capabilities/index.js +25 -0
- package/src/agents/capabilities/planning/index.js +123 -0
- package/src/agents/capabilities/planning/main.js +28 -0
- package/src/agents/capabilities/projectDiscovery/index.js +3 -0
- package/src/agents/capabilities/scheduling/index.js +3 -0
- package/src/agents/capabilities/sharedMemory/index.js +4 -0
- package/src/agents/capabilities/skills/index.js +12 -0
- package/src/agents/capabilities/taskExecution/index.js +3 -0
- package/src/agents/capabilities/taskReports/index.js +6 -0
- package/src/agents/controller/controllerToolExecutor.js +6 -4
- package/src/agents/controller/loopRuntime.js +85 -221
- package/src/agents/controller/ufooAgent.js +1 -0
- package/src/agents/internal/internalRunner.js +103 -32
- package/src/agents/launch/launcher.js +88 -6
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +13 -18
- package/src/agents/launch/readyDetector.js +26 -12
- package/src/agents/profiles/coding.js +6 -0
- package/src/agents/profiles/globalRouter.js +2 -0
- package/src/agents/profiles/main.js +5 -0
- package/src/agents/prompts/groupBootstrap.js +10 -0
- package/src/agents/prompts/mainAgent.js +39 -0
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +3 -0
- package/src/agents/providers/claudeEventTranslator.js +6 -1
- package/src/agents/providers/claudeThreadProvider.js +44 -2
- package/src/agents/providers/codexEventTranslator.js +47 -7
- package/src/agents/providers/codexThreadProvider.js +3 -2
- package/src/agents/providers/controllerJsonTransport.js +28 -0
- package/src/agents/providers/credentials/claude.js +10 -3
- package/src/agents/providers/nativeTransport.js +1135 -0
- package/src/agents/providers/runtimeConfig.js +186 -0
- package/src/agents/providers/thinkingLevels.js +132 -0
- package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
- package/src/agents/providers/transports/index.js +10 -0
- package/src/agents/providers/transports/openaiChatTransport.js +117 -0
- package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
- package/src/agents/providers/transports/responsesProtocol.js +499 -0
- package/src/agents/providers/transports/systemBlocks.js +16 -0
- package/src/agents/providers/transports/transportContract.js +50 -0
- package/src/agents/providers/transports/visionBlocks.js +151 -0
- package/src/agents/providers/upstreamTransport.js +13 -4
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/runtimeStore.js +126 -0
- package/src/agents/runtime/context/sessionJournal.js +360 -0
- package/src/agents/runtime/context/sessionStore.js +57 -0
- package/src/agents/runtime/core/agentLoop.js +270 -0
- package/src/agents/runtime/core/stableJson.js +29 -0
- package/src/agents/runtime/core/toolLoopGuard.js +55 -0
- package/src/agents/runtime/createAgentRuntime.js +247 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
- package/src/agents/runtime/tasks/resourceLease.js +66 -0
- package/src/agents/runtime/tasks/scheduler.js +73 -0
- package/src/agents/runtime/tools/registry.js +57 -0
- package/src/app/chat/ChatController.js +14 -3
- package/src/app/chat/agentDirectory.js +8 -2
- package/src/app/chat/commandExecutor.js +36 -46
- package/src/app/chat/commands.js +14 -7
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -3
- package/src/app/chat/inputSubmitHandler.js +14 -2
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +85 -165
- package/src/app/chat/streamState.js +3 -3
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/busCoreCommands.js +9 -0
- package/src/app/cli/features/doctor.js +33 -0
- package/src/app/cli/features/skills.js +16 -4
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +40 -39
- package/src/code/agent.js +16 -4
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +2 -1
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +100 -0
- package/src/code/nativeRunner.js +36 -2668
- package/src/code/protocol/faultHarness.js +2 -88
- package/src/code/protocol/materialize.js +2 -105
- package/src/code/protocol/toolCallLedger.js +5 -215
- package/src/code/providers/anthropicMessagesTransport.js +2 -118
- package/src/code/providers/openaiChatTransport.js +2 -114
- package/src/code/providers/openaiResponsesTransport.js +2 -117
- package/src/code/providers/responsesProtocol.js +2 -497
- package/src/code/providers/transportContract.js +2 -48
- package/src/code/providers/visionBlocks.js +2 -149
- package/src/code/sessionStore.js +24 -96
- package/src/code/thinkingLevels.js +1 -130
- package/src/code/toolLoopGuard.js +3 -49
- package/src/code/tools/artifactRead.js +1 -1
- package/src/code/tools/executor.js +373 -0
- package/src/code/tools/specs.js +312 -0
- package/src/config.js +81 -67
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +2 -6
- package/src/coordination/bus/inject.js +13 -5
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/utils.js +7 -3
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/controllerSummary.js +23 -0
- package/src/coordination/memory/index.js +5 -21
- package/src/coordination/report/store.js +103 -83
- package/src/coordination/state/agentsStore.js +57 -3
- package/src/coordination/state/fileLock.js +2 -0
- package/src/coordination/state/workspaceAccess.js +36 -0
- package/src/runtime/contracts/agentMode.js +17 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +4 -0
- package/src/runtime/daemon/agentHost.js +375 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +27 -17
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/executionPaths.js +30 -0
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +1 -0
- package/src/runtime/daemon/index.js +114 -344
- package/src/runtime/daemon/ipcServer.js +32 -10
- package/src/runtime/daemon/mcpConfigure.js +113 -20
- package/src/runtime/daemon/mcpHttpServer.js +27 -5
- package/src/runtime/daemon/mcpServer.js +7 -4
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/ops.js +22 -17
- package/src/runtime/daemon/promptRequest.js +23 -4
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +4 -0
- package/src/runtime/privacy/redactor.js +2 -2
- package/src/runtime/projects/identity.js +2 -1
- package/src/runtime/projects/registry.js +98 -38
- package/src/tools/controllerSchemas.js +24 -0
- package/src/tools/handlers/dispatchMessage.js +5 -2
- package/src/tools/handlers/listAgents.js +3 -1
- package/src/tools/handlers/readBusSummary.js +3 -1
- package/src/tools/handlers/readProjectRegistry.js +29 -2
- package/src/tools/handlers/routeAgent.js +35 -0
- package/src/tools/index.js +1 -0
- package/src/tools/registry.js +2 -0
- package/src/tools/schemaFixtures.js +16 -3
- package/src/tools/tier1/routeAgent.js +2 -2
- package/src/tools/tier2/runtimeCoordination.js +38 -0
- package/src/tools/types.js +2 -0
- package/src/ui/agentPresentation.js +109 -0
- package/src/ui/agentSurface.js +270 -0
- package/src/ui/format/banner.js +8 -11
- package/src/ui/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +170 -438
- package/src/ui/rustMultiSession.js +225 -51
- package/src/ui/rustUcodeHost.js +20 -87
- package/src/ui/settingsBridge.js +7 -4
- package/src/app/chat/agentEnter.js +0 -70
- package/src/app/chat/multiWindow/index.js +0 -310
- package/src/app/chat/multiWindow/paneLayout.js +0 -84
- package/src/app/chat/multiWindow/renderer.js +0 -420
- package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
- package/src/app/chat/multiWindow/vtFrame.js +0 -93
- package/src/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
|
+
const { randomUUID } = require("crypto");
|
|
3
|
+
const { createAgentSurfacePublisher } = require("../../coordination/history/agentSurface");
|
|
4
|
+
const { contextMeterForUsage } = require("../../ui/agentPresentation");
|
|
5
|
+
const { updateAgentsData } = require("../../coordination/state/agentsStore");
|
|
2
6
|
const path = require("path");
|
|
3
7
|
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
4
8
|
const { spawnSync } = require("child_process");
|
|
5
9
|
const EventBus = require("../../coordination/bus");
|
|
6
|
-
const { readJSON
|
|
10
|
+
const { readJSON } = require("../../coordination/bus/utils");
|
|
7
11
|
const { createActivityStatePublisher } = require("../activity/activityStatePublisher");
|
|
8
12
|
const { createActivityTracker } = require("../activity/activityTracker");
|
|
9
|
-
const { loadConfig, normalizeCodexInternalThreadMode } = require("../../config");
|
|
13
|
+
const { loadConfig, normalizeCodexInternalThreadMode, defaultAgentModelForProvider, sameModelProvider } = require("../../config");
|
|
10
14
|
const { createCodexThreadProvider } = require("../providers/codexThreadProvider");
|
|
11
15
|
const { createClaudeThreadProvider } = require("../providers/claudeThreadProvider");
|
|
12
16
|
const { resolveClaudeUpstreamCredentials } = require("../providers/credentials/claude");
|
|
@@ -176,6 +180,7 @@ function buildInternalPromptMessage(projectRoot, subscriber, evt = {}) {
|
|
|
176
180
|
|
|
177
181
|
function createBusSender(projectRoot, subscriber) {
|
|
178
182
|
const eventBus = new EventBus(projectRoot);
|
|
183
|
+
const surface = createAgentSurfacePublisher(projectRoot, subscriber);
|
|
179
184
|
let sendQueue = Promise.resolve();
|
|
180
185
|
|
|
181
186
|
function enqueue(target, message) {
|
|
@@ -190,19 +195,21 @@ function createBusSender(projectRoot, subscriber) {
|
|
|
190
195
|
async function flush() {
|
|
191
196
|
try {
|
|
192
197
|
await sendQueue;
|
|
198
|
+
await surface.flush();
|
|
193
199
|
} catch {
|
|
194
200
|
// ignore flush errors
|
|
195
201
|
}
|
|
196
202
|
}
|
|
197
203
|
|
|
198
|
-
return { enqueue, flush };
|
|
204
|
+
return { enqueue, flush, surface: surface.enqueue };
|
|
199
205
|
}
|
|
200
206
|
|
|
201
207
|
function isChatUiSource(source = "") {
|
|
202
208
|
const value = String(source || "").trim();
|
|
203
209
|
return value === "chat-direct"
|
|
204
210
|
|| value === "chat-agent-view"
|
|
205
|
-
|| value === "chat-internal-agent-view"
|
|
211
|
+
|| value === "chat-internal-agent-view"
|
|
212
|
+
|| value === "rust-multi-window";
|
|
206
213
|
}
|
|
207
214
|
|
|
208
215
|
function isUfooAgentDispatchSource(source = "") {
|
|
@@ -318,6 +325,9 @@ async function handleEvent(
|
|
|
318
325
|
.join("\n\n");
|
|
319
326
|
const publisher = evt.publisher || "unknown";
|
|
320
327
|
const streamToPublisher = shouldStreamReplyToPublisher(projectRoot, publisher, evt);
|
|
328
|
+
const emitSurface = typeof busSender.surface === "function"
|
|
329
|
+
? busSender.surface : () => {};
|
|
330
|
+
emitSurface({ type: "task_started", task_id: randomUUID(), message: evt.data.message, publisher });
|
|
321
331
|
|
|
322
332
|
const emitStreamDelta = (delta) => {
|
|
323
333
|
const text = String(delta || "");
|
|
@@ -330,17 +340,21 @@ async function handleEvent(
|
|
|
330
340
|
return handleThreadedEvent({
|
|
331
341
|
agentType,
|
|
332
342
|
provider,
|
|
343
|
+
model,
|
|
333
344
|
publisher,
|
|
334
345
|
prompt,
|
|
346
|
+
userMessage: evt.data.message,
|
|
335
347
|
busSender,
|
|
336
348
|
emitStreamDelta,
|
|
337
349
|
streamToPublisher,
|
|
338
350
|
threadRuntime,
|
|
339
351
|
tracker,
|
|
352
|
+
emitSurface,
|
|
340
353
|
});
|
|
341
354
|
}
|
|
342
355
|
|
|
343
356
|
const errorText = `[internal:${agentType}] error: no thread runtime available for provider ${provider}; cliRunner fallback has been removed`;
|
|
357
|
+
emitSurface({ type: "task_failed", error: errorText });
|
|
344
358
|
// eslint-disable-next-line no-console
|
|
345
359
|
console.error(errorText);
|
|
346
360
|
if (streamToPublisher) {
|
|
@@ -384,16 +398,17 @@ function toNonNegativeInt(value) {
|
|
|
384
398
|
function normalizeTurnUsage(usage = null) {
|
|
385
399
|
const item = usage && typeof usage === "object" ? usage : {};
|
|
386
400
|
return {
|
|
387
|
-
input_tokens: toNonNegativeInt(item.input_tokens
|
|
388
|
-
output_tokens: toNonNegativeInt(item.output_tokens
|
|
401
|
+
input_tokens: toNonNegativeInt(item.input_tokens ?? item.prompt_tokens ?? item.input),
|
|
402
|
+
output_tokens: toNonNegativeInt(item.output_tokens ?? item.completion_tokens ?? item.output),
|
|
389
403
|
cache_read_tokens: toNonNegativeInt(
|
|
390
404
|
item.cache_read_tokens
|
|
391
405
|
|| item.cache_read_input_tokens
|
|
392
406
|
|| item.cached_input_tokens
|
|
407
|
+
|| item.cacheRead
|
|
393
408
|
|| (item.input_tokens_details && item.input_tokens_details.cached_tokens)
|
|
394
409
|
),
|
|
395
410
|
cache_creation_tokens: toNonNegativeInt(
|
|
396
|
-
item.cache_creation_tokens || item.cache_creation_input_tokens
|
|
411
|
+
item.cache_creation_tokens || item.cache_creation_input_tokens || item.cacheCreation
|
|
397
412
|
),
|
|
398
413
|
};
|
|
399
414
|
}
|
|
@@ -401,23 +416,32 @@ function normalizeTurnUsage(usage = null) {
|
|
|
401
416
|
async function handleThreadedEvent({
|
|
402
417
|
agentType,
|
|
403
418
|
provider,
|
|
419
|
+
model = "",
|
|
404
420
|
publisher,
|
|
405
421
|
prompt,
|
|
422
|
+
userMessage = "",
|
|
406
423
|
busSender,
|
|
407
424
|
emitStreamDelta,
|
|
408
425
|
streamToPublisher = true,
|
|
409
426
|
threadRuntime,
|
|
410
427
|
tracker = null,
|
|
428
|
+
emitSurface = () => {},
|
|
411
429
|
}) {
|
|
412
430
|
try {
|
|
413
431
|
const plainReplyParts = [];
|
|
414
432
|
let turnUsage = null;
|
|
415
433
|
let stopReason = "";
|
|
434
|
+
let waitingForUser = false;
|
|
416
435
|
if (tracker && typeof tracker.notifyTurnStart === "function") {
|
|
417
436
|
tracker.notifyTurnStart();
|
|
418
437
|
}
|
|
419
|
-
for await (const event of threadRuntime.thread.runStreamed(prompt, {})) {
|
|
438
|
+
for await (const event of threadRuntime.thread.runStreamed(prompt, provider === "ucode" ? { userInput: userMessage } : {})) {
|
|
420
439
|
if (!event || typeof event !== "object") continue;
|
|
440
|
+
emitSurface(event);
|
|
441
|
+
if (["usage", "turn_completed"].includes(event.type) && event.usage && provider !== "ucode") {
|
|
442
|
+
emitSurface({ type: "context_usage", meter: contextMeterForUsage(event.usage, model || threadRuntime.thread.model, provider) });
|
|
443
|
+
}
|
|
444
|
+
if (event.type === "interaction" || (event.type === "status" && event.state === "waiting_input")) waitingForUser = true;
|
|
421
445
|
if (typeof threadRuntime.syncProviderSessionId === "function") {
|
|
422
446
|
threadRuntime.syncProviderSessionId();
|
|
423
447
|
}
|
|
@@ -435,6 +459,12 @@ async function handleThreadedEvent({
|
|
|
435
459
|
if (streamToPublisher && summary) {
|
|
436
460
|
emitStreamDelta(`\nTool: ${summary}\n`);
|
|
437
461
|
}
|
|
462
|
+
} else if (event.type === "tool_result" && streamToPublisher) {
|
|
463
|
+
const output = typeof event.output === "string" ? event.output
|
|
464
|
+
: Array.isArray(event.output) ? event.output.map((block) => block && block.text || "").join("\n")
|
|
465
|
+
: event.output && typeof event.output === "object" ? JSON.stringify(event.output) : "";
|
|
466
|
+
if (output) emitStreamDelta(output.slice(0, 4000) + (output.endsWith("\n") ? "" : "\n"));
|
|
467
|
+
if (Number.isFinite(event.exitCode) && event.exitCode !== 0) emitStreamDelta(`[exit ${event.exitCode}]\n`);
|
|
438
468
|
} else if (event.type === "usage" && event.usage) {
|
|
439
469
|
turnUsage = normalizeTurnUsage(event.usage);
|
|
440
470
|
} else if (event.type === "turn_completed") {
|
|
@@ -447,6 +477,8 @@ async function handleThreadedEvent({
|
|
|
447
477
|
if (typeof threadRuntime.syncProviderSessionId === "function") {
|
|
448
478
|
threadRuntime.syncProviderSessionId();
|
|
449
479
|
}
|
|
480
|
+
emitSurface({ type: "task_completed", usage: turnUsage });
|
|
481
|
+
if (waitingForUser && tracker?.requestUserInput) tracker.requestUserInput("reply");
|
|
450
482
|
|
|
451
483
|
if (streamToPublisher) {
|
|
452
484
|
const doneEnvelope = { stream: true, done: true, reason: "complete" };
|
|
@@ -465,13 +497,16 @@ async function handleThreadedEvent({
|
|
|
465
497
|
},
|
|
466
498
|
};
|
|
467
499
|
} catch (err) {
|
|
468
|
-
if (threadRuntime && typeof threadRuntime.rebuildThread === "function") {
|
|
469
|
-
await threadRuntime.rebuildThread();
|
|
470
|
-
}
|
|
471
500
|
if (tracker && typeof tracker.markIdle === "function") {
|
|
472
501
|
tracker.markIdle();
|
|
473
502
|
}
|
|
474
503
|
const errorText = `[internal:${agentType}] error: ${err && err.message ? err.message : "unknown error"}`;
|
|
504
|
+
emitSurface(err?.code === "cancelled" || err?.name === "AbortError"
|
|
505
|
+
? { type: "task_cancelled" } : { type: "task_failed", error: errorText });
|
|
506
|
+
if (threadRuntime && typeof threadRuntime.rebuildThread === "function") {
|
|
507
|
+
try { await threadRuntime.rebuildThread(); }
|
|
508
|
+
catch (recoveryError) { console.error(`[internal:${agentType}] recovery failed: ${recoveryError?.message || "unknown error"}`); }
|
|
509
|
+
}
|
|
475
510
|
// eslint-disable-next-line no-console
|
|
476
511
|
console.error(errorText);
|
|
477
512
|
if (streamToPublisher) {
|
|
@@ -612,29 +647,49 @@ function persistProviderSessionId(projectRoot, subscriber, providerSessionId) {
|
|
|
612
647
|
if (!projectRoot || !subscriber || !id) return false;
|
|
613
648
|
try {
|
|
614
649
|
const agentsFile = getUfooPaths(projectRoot).agentsFile;
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
}
|
|
626
|
-
return false;
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
writeJSON(agentsFile, parsed);
|
|
632
|
-
return true;
|
|
650
|
+
if (!fs.existsSync(agentsFile)) return false;
|
|
651
|
+
return updateAgentsData(agentsFile, (parsed) => {
|
|
652
|
+
if (!parsed.agents || typeof parsed.agents !== "object") return false;
|
|
653
|
+
if (!parsed.agents[subscriber] || typeof parsed.agents[subscriber] !== "object") {
|
|
654
|
+
appendAgentRegistryDiagnostic(agentsFile, "provider_session_subscriber_missing", {
|
|
655
|
+
source: "agent.internalRunner.persistProviderSessionId",
|
|
656
|
+
subscriber,
|
|
657
|
+
known_ids: Object.keys(parsed.agents || {}).sort(),
|
|
658
|
+
});
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
if (parsed.agents[subscriber].provider_session_id === id) return false;
|
|
662
|
+
parsed.agents[subscriber].provider_session_id = id;
|
|
663
|
+
parsed.agents[subscriber].provider_session_updated_at = new Date().toISOString();
|
|
664
|
+
return true;
|
|
665
|
+
});
|
|
633
666
|
} catch {
|
|
634
667
|
return false;
|
|
635
668
|
}
|
|
636
669
|
}
|
|
637
670
|
|
|
671
|
+
function resolveInternalModel({ projectRoot, provider, extraArgs = [], env = process.env }) {
|
|
672
|
+
for (let index = 0; index < extraArgs.length; index++) {
|
|
673
|
+
if (["-m", "--model"].includes(extraArgs[index]) && extraArgs[index + 1]) return String(extraArgs[index + 1]);
|
|
674
|
+
if (String(extraArgs[index]).startsWith("--model=")) return String(extraArgs[index]).slice(8);
|
|
675
|
+
}
|
|
676
|
+
if (env.UFOO_AGENT_MODEL) return String(env.UFOO_AGENT_MODEL);
|
|
677
|
+
// Native ucode resolves its own provider/model in the coding host.
|
|
678
|
+
if (provider === "ucode") return "";
|
|
679
|
+
const config = loadConfig(projectRoot);
|
|
680
|
+
return (sameModelProvider(config.agentProvider, provider) && config.agentModel)
|
|
681
|
+
|| defaultAgentModelForProvider(provider);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function resolveInternalCodexEffort(extraArgs = []) {
|
|
685
|
+
for (let index = 0; index < extraArgs.length; index++) {
|
|
686
|
+
if (!["-c", "--config"].includes(extraArgs[index])) continue;
|
|
687
|
+
const match = String(extraArgs[index + 1] || "").match(/^model_reasoning_effort\s*=\s*["']?(none|minimal|low|medium|high|xhigh|max)["']?$/);
|
|
688
|
+
if (match) return match[1];
|
|
689
|
+
}
|
|
690
|
+
return "medium";
|
|
691
|
+
}
|
|
692
|
+
|
|
638
693
|
function createThreadRuntime({ projectRoot, provider, model, extraArgs = [], subscriber = "", providerSessionId = "" }) {
|
|
639
694
|
const disabledRuntime = {
|
|
640
695
|
enabled: false,
|
|
@@ -656,6 +711,17 @@ function createThreadRuntime({ projectRoot, provider, model, extraArgs = [], sub
|
|
|
656
711
|
return changed;
|
|
657
712
|
}
|
|
658
713
|
|
|
714
|
+
if (provider === "ucode") {
|
|
715
|
+
const { createInternalCodingThread } = require("../../code/internalThread");
|
|
716
|
+
const thread = createInternalCodingThread({ workspaceRoot: projectRoot, model, sessionId: initialProviderSessionId });
|
|
717
|
+
return {
|
|
718
|
+
enabled: true, thread,
|
|
719
|
+
syncProviderSessionId: () => rememberProviderSessionId(thread),
|
|
720
|
+
rebuildThread: async () => {},
|
|
721
|
+
close: () => thread.close(),
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
|
|
659
725
|
if (provider === "codex-cli") {
|
|
660
726
|
if (getCodexThreadMode(projectRoot) !== "api") {
|
|
661
727
|
return disabledRuntime;
|
|
@@ -671,6 +737,7 @@ function createThreadRuntime({ projectRoot, provider, model, extraArgs = [], sub
|
|
|
671
737
|
cwd: projectRoot,
|
|
672
738
|
extraArgs,
|
|
673
739
|
tools: toolRuntime.tools,
|
|
740
|
+
threadOptions: { modelReasoningEffort: resolveInternalCodexEffort(extraArgs) },
|
|
674
741
|
});
|
|
675
742
|
let thread = initialProviderSessionId
|
|
676
743
|
? providerInstance.resumeThread(initialProviderSessionId)
|
|
@@ -694,6 +761,7 @@ function createThreadRuntime({ projectRoot, provider, model, extraArgs = [], sub
|
|
|
694
761
|
cwd: projectRoot,
|
|
695
762
|
extraArgs,
|
|
696
763
|
tools: toolRuntime.tools,
|
|
764
|
+
threadOptions: { modelReasoningEffort: resolveInternalCodexEffort(extraArgs) },
|
|
697
765
|
});
|
|
698
766
|
thread = savedProviderSessionId
|
|
699
767
|
? providerInstance.resumeThread(savedProviderSessionId)
|
|
@@ -771,8 +839,9 @@ async function runInternalRunner({ projectRoot, agentType = "codex", extraArgs =
|
|
|
771
839
|
const queueDir = path.join(getUfooPaths(projectRoot).busQueuesDir, safeSubscriber(subscriber));
|
|
772
840
|
const queueFile = path.join(queueDir, "pending.jsonl");
|
|
773
841
|
const normalizedAgentType = String(agentType || "").trim().toLowerCase();
|
|
774
|
-
const provider =
|
|
775
|
-
|
|
842
|
+
const provider = ["ufoo", "ucode", "ufoo-code"].includes(normalizedAgentType)
|
|
843
|
+
? "ucode" : normalizedAgentType === "codex" ? "codex-cli" : "claude-cli";
|
|
844
|
+
const model = resolveInternalModel({ projectRoot, provider, extraArgs });
|
|
776
845
|
const bootstrap = resolveInternalBootstrap({
|
|
777
846
|
projectRoot,
|
|
778
847
|
agentType: normalizedAgentType,
|
|
@@ -912,7 +981,7 @@ async function runInternalRunner({ projectRoot, agentType = "codex", extraArgs =
|
|
|
912
981
|
// 处理消息后更新心跳
|
|
913
982
|
updateHeartbeat();
|
|
914
983
|
lastHeartbeat = now;
|
|
915
|
-
if (handledAny) {
|
|
984
|
+
if (handledAny && activityTracker.getState().state !== "waiting_input") {
|
|
916
985
|
activityTracker.markIdle();
|
|
917
986
|
}
|
|
918
987
|
await busSender.flush();
|
|
@@ -934,6 +1003,8 @@ module.exports = {
|
|
|
934
1003
|
handleEvent,
|
|
935
1004
|
handleThreadedEvent,
|
|
936
1005
|
createThreadRuntime,
|
|
1006
|
+
resolveInternalModel,
|
|
1007
|
+
resolveInternalCodexEffort,
|
|
937
1008
|
getCodexThreadMode,
|
|
938
1009
|
getWorkerThreadToolMode,
|
|
939
1010
|
buildWorkerThreadToolRuntime,
|
|
@@ -14,6 +14,7 @@ const { createActivityStatePublisher } = require("../activity/activityStatePubli
|
|
|
14
14
|
const { reconcileDetectorOwnedActivity } = require("../activity/activityReconcile");
|
|
15
15
|
const { detectLaunchEnvironment } = require("./launchEnvironment");
|
|
16
16
|
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
17
|
+
const { updateAgentsData } = require("../../coordination/state/agentsStore");
|
|
17
18
|
const {
|
|
18
19
|
resolveDaemonEndpoint,
|
|
19
20
|
routeDaemonRequest,
|
|
@@ -30,6 +31,21 @@ const {
|
|
|
30
31
|
persistConversationId,
|
|
31
32
|
} = require("./agyConversation");
|
|
32
33
|
|
|
34
|
+
function setLauncherReady(projectRoot, subscriber, ready) {
|
|
35
|
+
try {
|
|
36
|
+
const file = getUfooPaths(projectRoot).agentsFile;
|
|
37
|
+
if (!fs.existsSync(file)) return false;
|
|
38
|
+
return updateAgentsData(file, (data) => {
|
|
39
|
+
const meta = data.agents && data.agents[subscriber];
|
|
40
|
+
if (!meta || meta.status === "inactive") return false;
|
|
41
|
+
meta.launcher_ready = ready;
|
|
42
|
+
return true;
|
|
43
|
+
});
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
33
49
|
function connectSocket(sockPath) {
|
|
34
50
|
return new Promise((resolve, reject) => {
|
|
35
51
|
const client = net.createConnection(sockPath, () => resolve(client));
|
|
@@ -385,6 +401,7 @@ class AgentLauncher {
|
|
|
385
401
|
subscriberId,
|
|
386
402
|
sessionId: parts[1],
|
|
387
403
|
nickname: meta.nickname || process.env.UFOO_NICKNAME || "",
|
|
404
|
+
agentHandle: process.env.UFOO_AGENT_HANDLE || "",
|
|
388
405
|
preRegistered: true,
|
|
389
406
|
};
|
|
390
407
|
} catch {
|
|
@@ -567,6 +584,7 @@ class AgentLauncher {
|
|
|
567
584
|
resolve({
|
|
568
585
|
subscriberId: payload.subscriberId,
|
|
569
586
|
nickname: payload.nickname || nickname || "",
|
|
587
|
+
agentHandle: payload.agentHandle || "",
|
|
570
588
|
sessionId: (payload.subscriberId || "").split(":")[1] || "",
|
|
571
589
|
preRegistered: false,
|
|
572
590
|
});
|
|
@@ -640,6 +658,7 @@ class AgentLauncher {
|
|
|
640
658
|
const monitorStartedAt = Date.now();
|
|
641
659
|
detector.onReady(() => {
|
|
642
660
|
stopReadyMonitor();
|
|
661
|
+
setLauncherReady(this.cwd, subscriberId, true);
|
|
643
662
|
notifier.markLauncherReady();
|
|
644
663
|
notifier.updateActivityState("ready");
|
|
645
664
|
});
|
|
@@ -672,12 +691,14 @@ class AgentLauncher {
|
|
|
672
691
|
|
|
673
692
|
child.on("error", (err) => {
|
|
674
693
|
stopReadyMonitor();
|
|
694
|
+
void options.nativeMessages?.close();
|
|
675
695
|
console.error(`[${this.command}] Failed to start:`, err.message);
|
|
676
696
|
process.exit(1);
|
|
677
697
|
});
|
|
678
698
|
|
|
679
699
|
child.on("exit", async (code, signal) => {
|
|
680
700
|
stopReadyMonitor();
|
|
701
|
+
await options.nativeMessages?.close();
|
|
681
702
|
// 清理 bus 状态
|
|
682
703
|
try {
|
|
683
704
|
const bus = new EventBus(this.cwd);
|
|
@@ -701,9 +722,21 @@ class AgentLauncher {
|
|
|
701
722
|
* 启动 agent
|
|
702
723
|
*/
|
|
703
724
|
async launch(args) {
|
|
725
|
+
let nativeMessages = null;
|
|
704
726
|
// 保存用户/group 显式传入的 nickname(在 session 复用覆盖前)
|
|
705
727
|
this._originalNickname = process.env.UFOO_NICKNAME || "";
|
|
706
728
|
try {
|
|
729
|
+
let useNativeMessages = require("./nativeMessages").resolveNativeMessageMode({ agentType: this.agentType, args });
|
|
730
|
+
let nativeCapabilities = null;
|
|
731
|
+
if (useNativeMessages) {
|
|
732
|
+
nativeCapabilities = require("./nativeCapabilities").probeNativeCapabilities({ agentType: this.agentType, command: this.command });
|
|
733
|
+
if (!nativeCapabilities.supported) {
|
|
734
|
+
const detail = `Native messages unavailable: ${nativeCapabilities.reason}; update ${this.command} or use --no-native-messages`;
|
|
735
|
+
if (process.env.UFOO_NATIVE_MESSAGES === "1") throw new Error(detail);
|
|
736
|
+
console.error(`[ufoo] ${detail}. Using legacy delivery for this launch.`);
|
|
737
|
+
useNativeMessages = false;
|
|
738
|
+
}
|
|
739
|
+
}
|
|
707
740
|
// 1. 确保初始化
|
|
708
741
|
await this.ensureInit();
|
|
709
742
|
|
|
@@ -719,11 +752,39 @@ class AgentLauncher {
|
|
|
719
752
|
const sessionId = result.sessionId || (subscriberId.split(":")[1] || "");
|
|
720
753
|
const finalNickname = result.nickname || nickname || "";
|
|
721
754
|
|
|
755
|
+
if (["codex", "claude-code"].includes(this.agentType)) {
|
|
756
|
+
setLauncherReady(this.cwd, subscriberId, false);
|
|
757
|
+
}
|
|
758
|
+
|
|
722
759
|
// 4. 更新环境变量(供子进程/后续使用)
|
|
723
760
|
if (subscriberId) process.env.UFOO_SUBSCRIBER_ID = subscriberId;
|
|
761
|
+
// Never inherit the launching Agent's capability for a new identity.
|
|
762
|
+
if (result.agentHandle) process.env.UFOO_AGENT_HANDLE = result.agentHandle;
|
|
763
|
+
else delete process.env.UFOO_AGENT_HANDLE;
|
|
724
764
|
if (finalNickname) process.env.UFOO_NICKNAME = finalNickname;
|
|
725
765
|
process.env.UFOO_AGENT_TYPE = this.agentType;
|
|
726
766
|
|
|
767
|
+
if (["codex", "claude-code"].includes(this.agentType)) {
|
|
768
|
+
// A resumed host may retain the previous launch's receiver metadata.
|
|
769
|
+
// Select the new transport before asynchronous receiver startup.
|
|
770
|
+
require("./nativeMessages").setNativeMetadata(this.cwd, subscriberId, {
|
|
771
|
+
native_delivery: useNativeMessages ? (this.agentType === "codex" ? "codex_queue" : "claude_channel") : null,
|
|
772
|
+
native_delivery_ready: false,
|
|
773
|
+
native_delivery_instance: null,
|
|
774
|
+
native_delivery_version: nativeCapabilities?.version || "",
|
|
775
|
+
native_delivery_diagnostic: nativeCapabilities?.reason || "",
|
|
776
|
+
});
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
if (useNativeMessages) {
|
|
780
|
+
nativeMessages = await require("./nativeMessages").prepareNativeMessages({
|
|
781
|
+
agentType: this.agentType, command: this.command, args,
|
|
782
|
+
projectRoot: this.cwd, subscriber: subscriberId,
|
|
783
|
+
});
|
|
784
|
+
args = nativeMessages.args;
|
|
785
|
+
Object.assign(process.env, nativeMessages.env || {});
|
|
786
|
+
}
|
|
787
|
+
|
|
727
788
|
// 5. 显示 banner(ucode 自带 TUI banner,这里避免重复)
|
|
728
789
|
if (shouldShowLaunchBanner(this.agentType)) {
|
|
729
790
|
showBanner({
|
|
@@ -874,19 +935,26 @@ class AgentLauncher {
|
|
|
874
935
|
}
|
|
875
936
|
|
|
876
937
|
if (startupBootstrapText && wrapper.pty) {
|
|
877
|
-
|
|
938
|
+
if (nativeMessages) {
|
|
939
|
+
try { await nativeMessages.send({ command: startupBootstrapText, deliveryId: `startup-bootstrap:${sessionId}` }); }
|
|
940
|
+
catch (err) { console.error(`[ufoo] Native startup bootstrap failed: ${err.message}`); }
|
|
941
|
+
} else await injectPtyCommand(wrapper, this.agentType, startupBootstrapText, "startup-bootstrap");
|
|
878
942
|
}
|
|
879
943
|
|
|
944
|
+
setLauncherReady(this.cwd, subscriberId, true);
|
|
880
945
|
await notifyDaemonAgentReady(daemonEndpoint, subscriberId, wrapper.pty ? wrapper.pty.pid : 0);
|
|
881
946
|
});
|
|
947
|
+
nativeMessages?.onReady?.(() => readyDetector.confirmNativeReady());
|
|
882
948
|
|
|
883
|
-
//
|
|
949
|
+
// Elapsed time cannot prove that a host can accept input. Preserve
|
|
950
|
+
// queued work and report a slow startup instead of injecting blindly.
|
|
884
951
|
const forceReadyTimer = setTimeout(() => {
|
|
885
|
-
readyDetector.
|
|
952
|
+
if (!readyDetector.ready) console.error(`[ufoo] Waiting for ${this.command} to become ready; queued work is retained.`);
|
|
886
953
|
}, 10000);
|
|
887
954
|
|
|
888
955
|
// 设置退出回调(复用清理逻辑)
|
|
889
956
|
wrapper.onExit = async ({ exitCode, signal }) => {
|
|
957
|
+
await nativeMessages?.close();
|
|
890
958
|
// 清理 timers
|
|
891
959
|
clearTimeout(forceReadyTimer);
|
|
892
960
|
clearInterval(activityReconcileTimer);
|
|
@@ -1000,9 +1068,20 @@ class AgentLauncher {
|
|
|
1000
1068
|
client.write(JSON.stringify({ ok: false, error: "inject disabled for ufoo-code (internal bus loop)" }) + "\n");
|
|
1001
1069
|
continue;
|
|
1002
1070
|
}
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1071
|
+
if (nativeMessages) {
|
|
1072
|
+
const reply = (result) => {
|
|
1073
|
+
if (!client.destroyed) client.write(JSON.stringify(result) + "\n");
|
|
1074
|
+
};
|
|
1075
|
+
void nativeMessages.send(req).then((receipt) => {
|
|
1076
|
+
reply({ ok: true, ...receipt });
|
|
1077
|
+
}).catch((err) => {
|
|
1078
|
+
reply({ ok: false, error: err.message, code: err.code });
|
|
1079
|
+
});
|
|
1080
|
+
} else {
|
|
1081
|
+
// 注入命令到PTY(带延迟确保输入完成)
|
|
1082
|
+
void injectPtyCommand(wrapper, this.agentType, req.command, "inject");
|
|
1083
|
+
client.write(JSON.stringify({ ok: true }) + "\n");
|
|
1084
|
+
}
|
|
1006
1085
|
} else if (req.type === PTY_SOCKET_MESSAGE_TYPES.RAW && req.data) {
|
|
1007
1086
|
// Raw PTY write (no Enter appended) - for TTY view passthrough
|
|
1008
1087
|
wrapper.write(req.data);
|
|
@@ -1094,14 +1173,17 @@ class AgentLauncher {
|
|
|
1094
1173
|
process.on("SIGTERM", () => handleTermSignal("SIGTERM"));
|
|
1095
1174
|
process.on("SIGINT", () => handleTermSignal("SIGINT"));
|
|
1096
1175
|
} catch (err) {
|
|
1176
|
+
if (nativeMessages) throw err;
|
|
1097
1177
|
console.error(`[PTY] Failed to start, falling back to spawn:`, err.message);
|
|
1098
1178
|
this._spawnDirect(args, subscriberId, { notifier });
|
|
1099
1179
|
}
|
|
1100
1180
|
} else {
|
|
1181
|
+
if (nativeMessages) throw new Error("Native messages require an interactive PTY launch; remove UFOO_DISABLE_PTY or use a terminal");
|
|
1101
1182
|
// 非PTY环境:tmux、internal、管道、显式禁用等
|
|
1102
1183
|
this._spawnDirect(args, subscriberId, { notifier });
|
|
1103
1184
|
}
|
|
1104
1185
|
} catch (err) {
|
|
1186
|
+
await nativeMessages?.close();
|
|
1105
1187
|
console.error(`[${this.command}] Error:`, err.message);
|
|
1106
1188
|
process.exit(1);
|
|
1107
1189
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const { spawnSync } = require("child_process");
|
|
2
|
+
|
|
3
|
+
// These are the oldest versions verified by our real-CLI smoke tests, not a
|
|
4
|
+
// claim about the vendor's first release of each experimental API.
|
|
5
|
+
const TESTED_BASELINES = { codex: "0.160.1", "claude-code": "2.1.204" };
|
|
6
|
+
const cache = new Map();
|
|
7
|
+
|
|
8
|
+
function atLeast(version, baseline) {
|
|
9
|
+
const left = version.split(".").map(Number);
|
|
10
|
+
const right = baseline.split(".").map(Number);
|
|
11
|
+
for (let i = 0; i < 3; i++) {
|
|
12
|
+
if (left[i] !== right[i]) return left[i] > right[i];
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function probeNativeCapabilities({ agentType, command, env = process.env, spawnSyncImpl = spawnSync } = {}) {
|
|
18
|
+
const baseline = TESTED_BASELINES[agentType];
|
|
19
|
+
if (!baseline) return { supported: false, reason: "unsupported_provider" };
|
|
20
|
+
const executable = command || (agentType === "codex" ? "codex" : "claude");
|
|
21
|
+
const key = `${agentType}:${executable}:${env.PATH}`;
|
|
22
|
+
const cached = cache.get(key);
|
|
23
|
+
if (spawnSyncImpl === spawnSync && cached && Date.now() - cached.at < 60000) return cached.result;
|
|
24
|
+
const output = spawnSyncImpl(executable, ["--version"], {
|
|
25
|
+
env, encoding: "utf8", timeout: 4000, maxBuffer: 128 * 1024, stdio: ["ignore", "pipe", "ignore"],
|
|
26
|
+
});
|
|
27
|
+
const version = String(output?.stdout || "").match(/\b(\d+\.\d+\.\d+)\b/)?.[1] || "";
|
|
28
|
+
let result = { supported: output?.status === 0 && Boolean(version) && atLeast(version, baseline), version, baseline };
|
|
29
|
+
if (!result.supported) result.reason = output?.error?.code === "ENOENT" ? "cli_missing" : `requires_tested_version_${baseline}`;
|
|
30
|
+
if (result.supported && agentType === "codex") {
|
|
31
|
+
const help = spawnSyncImpl(executable, ["--help"], { env, encoding: "utf8", timeout: 4000, maxBuffer: 128 * 1024, stdio: ["ignore", "pipe", "ignore"] });
|
|
32
|
+
if (help?.status !== 0 || !String(help.stdout).includes("--remote") || !String(help.stdout).includes("app-server")) {
|
|
33
|
+
result = { ...result, supported: false, reason: "missing_remote_app_server" };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (spawnSyncImpl === spawnSync) cache.set(key, { at: Date.now(), result });
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = { TESTED_BASELINES, probeNativeCapabilities };
|