u-foo 3.1.7 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +172 -13
- package/README.zh-CN.md +108 -13
- package/SKILLS/ufoo/SKILL.md +15 -3
- package/SKILLS/ufoo-bus/SKILL.md +21 -1
- package/bin/uclaude.js +4 -0
- package/bin/ucodex.js +4 -0
- package/bin/ufoo.js +3 -1
- package/dist/tui/darwin-arm64/ufoo-tui +0 -0
- package/dist/tui/darwin-x64/ufoo-tui +0 -0
- package/dist/tui/linux-arm64/ufoo-tui +0 -0
- package/dist/tui/linux-x64/ufoo-tui +0 -0
- package/package.json +10 -3
- package/scripts/postinstall-skills.js +53 -0
- package/scripts/postinstall.js +11 -16
- package/scripts/smoke-native-messages.js +214 -0
- package/src/agents/activity/activityStateWriter.js +37 -38
- package/src/agents/capabilities/agentManagement/index.js +4 -0
- package/src/agents/capabilities/agentManagement/service.js +113 -0
- package/src/agents/capabilities/agentRouting/index.js +4 -0
- package/src/agents/capabilities/coding/index.js +32 -0
- package/src/agents/capabilities/coordination/index.js +37 -0
- package/src/agents/capabilities/globalRouting/index.js +5 -0
- package/src/agents/capabilities/groups/index.js +3 -0
- package/src/agents/capabilities/index.js +25 -0
- package/src/agents/capabilities/planning/index.js +123 -0
- package/src/agents/capabilities/planning/main.js +28 -0
- package/src/agents/capabilities/projectDiscovery/index.js +3 -0
- package/src/agents/capabilities/scheduling/index.js +3 -0
- package/src/agents/capabilities/sharedMemory/index.js +4 -0
- package/src/agents/capabilities/skills/index.js +12 -0
- package/src/agents/capabilities/taskExecution/index.js +3 -0
- package/src/agents/capabilities/taskReports/index.js +6 -0
- package/src/agents/controller/controllerToolExecutor.js +6 -4
- package/src/agents/controller/loopRuntime.js +85 -221
- package/src/agents/controller/ufooAgent.js +1 -0
- package/src/agents/internal/internalRunner.js +103 -32
- package/src/agents/launch/launcher.js +88 -6
- package/src/agents/launch/nativeCapabilities.js +40 -0
- package/src/agents/launch/nativeMessages.js +362 -0
- package/src/agents/launch/notifier.js +13 -18
- package/src/agents/launch/readyDetector.js +26 -12
- package/src/agents/profiles/coding.js +6 -0
- package/src/agents/profiles/globalRouter.js +2 -0
- package/src/agents/profiles/main.js +5 -0
- package/src/agents/prompts/groupBootstrap.js +10 -0
- package/src/agents/prompts/mainAgent.js +39 -0
- package/src/agents/prompts/native/tasks.js +2 -2
- package/src/agents/prompts/native/ufoo.js +3 -0
- package/src/agents/providers/claudeEventTranslator.js +6 -1
- package/src/agents/providers/claudeThreadProvider.js +44 -2
- package/src/agents/providers/codexEventTranslator.js +47 -7
- package/src/agents/providers/codexThreadProvider.js +3 -2
- package/src/agents/providers/controllerJsonTransport.js +28 -0
- package/src/agents/providers/credentials/claude.js +10 -3
- package/src/agents/providers/nativeTransport.js +1135 -0
- package/src/agents/providers/runtimeConfig.js +186 -0
- package/src/agents/providers/thinkingLevels.js +132 -0
- package/src/agents/providers/transports/anthropicMessagesTransport.js +121 -0
- package/src/agents/providers/transports/index.js +10 -0
- package/src/agents/providers/transports/openaiChatTransport.js +117 -0
- package/src/agents/providers/transports/openaiResponsesTransport.js +120 -0
- package/src/agents/providers/transports/responsesProtocol.js +499 -0
- package/src/agents/providers/transports/systemBlocks.js +16 -0
- package/src/agents/providers/transports/transportContract.js +50 -0
- package/src/agents/providers/transports/visionBlocks.js +151 -0
- package/src/agents/providers/upstreamTransport.js +13 -4
- package/src/agents/runtime/composeCapabilities.js +89 -0
- package/src/agents/runtime/context/commandStore.js +43 -0
- package/src/agents/runtime/context/contextWindow.js +119 -0
- package/src/agents/runtime/context/fileLock.js +36 -0
- package/src/agents/runtime/context/runtimeStore.js +126 -0
- package/src/agents/runtime/context/sessionJournal.js +360 -0
- package/src/agents/runtime/context/sessionStore.js +57 -0
- package/src/agents/runtime/core/agentLoop.js +270 -0
- package/src/agents/runtime/core/stableJson.js +29 -0
- package/src/agents/runtime/core/toolLoopGuard.js +55 -0
- package/src/agents/runtime/createAgentRuntime.js +247 -0
- package/src/agents/runtime/index.js +14 -0
- package/src/agents/runtime/protocol/faultHarness.js +90 -0
- package/src/agents/runtime/protocol/materialize.js +107 -0
- package/src/agents/runtime/protocol/toolCallLedger.js +221 -0
- package/src/agents/runtime/tasks/resourceLease.js +66 -0
- package/src/agents/runtime/tasks/scheduler.js +73 -0
- package/src/agents/runtime/tools/registry.js +57 -0
- package/src/app/chat/ChatController.js +14 -3
- package/src/app/chat/agentDirectory.js +8 -2
- package/src/app/chat/commandExecutor.js +36 -46
- package/src/app/chat/commands.js +14 -7
- package/src/app/chat/daemonConnection.js +58 -5
- package/src/app/chat/daemonMessageRouter.js +61 -3
- package/src/app/chat/inputSubmitHandler.js +14 -2
- package/src/app/chat/launchRequestContext.js +42 -0
- package/src/app/chat/multiWindow/paneManager.js +85 -165
- package/src/app/chat/streamState.js +3 -3
- package/src/app/chat/transport.js +1 -1
- package/src/app/cli/busCoreCommands.js +9 -0
- package/src/app/cli/features/doctor.js +33 -0
- package/src/app/cli/features/skills.js +16 -4
- package/src/app/cli/reportCoreCommands.js +37 -0
- package/src/app/cli/run.js +40 -39
- package/src/code/agent.js +16 -4
- package/src/code/context/artifacts.js +12 -11
- package/src/code/context/assembler.js +2 -1
- package/src/code/context/promptLayers.js +1 -13
- package/src/code/context/stableJson.js +2 -27
- package/src/code/contextWindow.js +2 -117
- package/src/code/conversation/sessionJournal.js +3 -349
- package/src/code/internalThread.js +100 -0
- package/src/code/nativeRunner.js +36 -2667
- package/src/code/protocol/faultHarness.js +2 -88
- package/src/code/protocol/materialize.js +2 -105
- package/src/code/protocol/toolCallLedger.js +5 -215
- package/src/code/providers/anthropicMessagesTransport.js +2 -118
- package/src/code/providers/openaiChatTransport.js +2 -114
- package/src/code/providers/openaiResponsesTransport.js +2 -117
- package/src/code/providers/responsesProtocol.js +2 -497
- package/src/code/providers/transportContract.js +2 -48
- package/src/code/providers/visionBlocks.js +2 -149
- package/src/code/sessionStore.js +24 -96
- package/src/code/thinkingLevels.js +1 -130
- package/src/code/toolLoopGuard.js +3 -49
- package/src/code/tools/artifactRead.js +1 -1
- package/src/code/tools/executor.js +373 -0
- package/src/code/tools/specs.js +312 -0
- package/src/config.js +81 -67
- package/src/coordination/bus/deliveryQueue.js +16 -2
- package/src/coordination/bus/index.js +2 -6
- package/src/coordination/bus/inject.js +13 -5
- package/src/coordination/bus/nativeReceipts.js +100 -0
- package/src/coordination/bus/queue.js +1 -3
- package/src/coordination/bus/utils.js +7 -3
- package/src/coordination/history/agentSurface.js +142 -0
- package/src/coordination/history/controllerSummary.js +23 -0
- package/src/coordination/memory/index.js +5 -21
- package/src/coordination/report/store.js +103 -83
- package/src/coordination/state/agentsStore.js +57 -3
- package/src/coordination/state/fileLock.js +2 -0
- package/src/coordination/state/workspaceAccess.js +36 -0
- package/src/runtime/contracts/agentMode.js +17 -0
- package/src/runtime/contracts/eventContract.js +3 -0
- package/src/runtime/contracts/uiProtocol.js +4 -0
- package/src/runtime/daemon/agentHost.js +375 -0
- package/src/runtime/daemon/busBridge.js +396 -0
- package/src/runtime/daemon/claudeChannel.js +159 -0
- package/src/runtime/daemon/controlPlaneService.js +27 -17
- package/src/runtime/daemon/cronOps.js +25 -17
- package/src/runtime/daemon/deliveryScheduler.js +32 -5
- package/src/runtime/daemon/executionPaths.js +30 -0
- package/src/runtime/daemon/globalDaemon.js +28 -1
- package/src/runtime/daemon/groupOrchestrator.js +1 -0
- package/src/runtime/daemon/index.js +114 -344
- package/src/runtime/daemon/ipcServer.js +32 -10
- package/src/runtime/daemon/mcpConfigure.js +113 -20
- package/src/runtime/daemon/mcpHttpServer.js +27 -5
- package/src/runtime/daemon/mcpServer.js +7 -4
- package/src/runtime/daemon/mcpStdioProxy.js +127 -10
- package/src/runtime/daemon/ops.js +22 -17
- package/src/runtime/daemon/promptRequest.js +23 -4
- package/src/runtime/daemon/providerSessions.js +67 -33
- package/src/runtime/daemon/reportControlBus.js +59 -25
- package/src/runtime/daemon/status.js +4 -0
- package/src/runtime/privacy/redactor.js +2 -2
- package/src/runtime/projects/identity.js +2 -1
- package/src/runtime/projects/registry.js +98 -38
- package/src/tools/controllerSchemas.js +24 -0
- package/src/tools/handlers/dispatchMessage.js +5 -2
- package/src/tools/handlers/listAgents.js +3 -1
- package/src/tools/handlers/readBusSummary.js +3 -1
- package/src/tools/handlers/readProjectRegistry.js +29 -2
- package/src/tools/handlers/routeAgent.js +35 -0
- package/src/tools/index.js +1 -0
- package/src/tools/registry.js +2 -0
- package/src/tools/schemaFixtures.js +16 -3
- package/src/tools/tier1/routeAgent.js +2 -2
- package/src/tools/tier2/runtimeCoordination.js +38 -0
- package/src/tools/types.js +2 -0
- package/src/ui/agentPresentation.js +109 -0
- package/src/ui/agentSurface.js +270 -0
- package/src/ui/format/banner.js +8 -11
- package/src/ui/format/startupBanner.js +50 -0
- package/src/ui/multiPaneBusMirror.js +29 -3
- package/src/ui/rustChatHost.js +170 -438
- package/src/ui/rustMultiSession.js +225 -51
- package/src/ui/rustUcodeHost.js +20 -87
- package/src/ui/settingsBridge.js +7 -4
- package/src/app/chat/agentEnter.js +0 -70
- package/src/app/chat/multiWindow/index.js +0 -310
- package/src/app/chat/multiWindow/paneLayout.js +0 -84
- package/src/app/chat/multiWindow/renderer.js +0 -420
- package/src/app/chat/multiWindow/virtualTerminal.js +0 -327
- package/src/app/chat/multiWindow/vtFrame.js +0 -93
- package/src/ui/multiWindowHandoff.js +0 -232
- package/src/ui/ptyHandoff.js +0 -23
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const fs = require("fs");
|
|
2
2
|
const path = require("path");
|
|
3
|
+
const { randomUUID } = require("crypto");
|
|
3
4
|
const { getUfooPaths } = require("../../coordination/state/paths");
|
|
4
5
|
const {
|
|
5
6
|
parseIntervalMs,
|
|
@@ -231,17 +232,21 @@ function createDaemonCronController(options = {}) {
|
|
|
231
232
|
createdAt: task.createdAt,
|
|
232
233
|
lastRunAt: task.lastRunAt,
|
|
233
234
|
tickCount: task.tickCount,
|
|
235
|
+
scheduleId: task.scheduleId,
|
|
234
236
|
})),
|
|
235
237
|
};
|
|
236
238
|
|
|
239
|
+
const tmpFile = `${persistedFile}.${randomUUID()}.tmp`;
|
|
237
240
|
try {
|
|
238
241
|
fsModule.mkdirSync(pathModule.dirname(persistedFile), { recursive: true });
|
|
239
|
-
|
|
240
|
-
fsModule.writeFileSync(tmpFile, JSON.stringify(state, null, 2), "utf8");
|
|
242
|
+
fsModule.writeFileSync(tmpFile, JSON.stringify(state, null, 2), { encoding: "utf8", mode: 0o600 });
|
|
241
243
|
fsModule.renameSync(tmpFile, persistedFile);
|
|
242
244
|
} catch (err) {
|
|
243
245
|
const detail = err && err.message ? err.message : String(err || "persist failed");
|
|
244
246
|
log(`cron persist failed: ${detail}`);
|
|
247
|
+
throw err;
|
|
248
|
+
} finally {
|
|
249
|
+
try { fsModule.unlinkSync(tmpFile); } catch {}
|
|
245
250
|
}
|
|
246
251
|
}
|
|
247
252
|
|
|
@@ -263,13 +268,18 @@ function createDaemonCronController(options = {}) {
|
|
|
263
268
|
}
|
|
264
269
|
|
|
265
270
|
function runTask(task) {
|
|
271
|
+
if (!tasks.includes(task)) return;
|
|
272
|
+
const previous = { lastRunAt: task.lastRunAt, tickCount: task.tickCount };
|
|
266
273
|
task.lastRunAt = nowFn();
|
|
267
274
|
task.tickCount += 1;
|
|
275
|
+
// Reserve the occurrence before effects. A restart never sends this tick twice.
|
|
276
|
+
try { persistState(); } catch (error) { Object.assign(task, previous); throw error; }
|
|
268
277
|
|
|
269
278
|
for (const target of task.targets) {
|
|
270
279
|
try {
|
|
271
280
|
Promise.resolve(dispatch({
|
|
272
281
|
taskId: task.id,
|
|
282
|
+
occurrenceId: `${task.scheduleId}:${task.tickCount}`,
|
|
273
283
|
target,
|
|
274
284
|
message: task.prompt,
|
|
275
285
|
})).catch((err) => {
|
|
@@ -290,9 +300,9 @@ function createDaemonCronController(options = {}) {
|
|
|
290
300
|
if (idx < 0) return false;
|
|
291
301
|
|
|
292
302
|
const task = tasks[idx];
|
|
293
|
-
clearTaskTimer(task);
|
|
294
303
|
tasks.splice(idx, 1);
|
|
295
|
-
persistState();
|
|
304
|
+
try { persistState(); } catch (error) { tasks.splice(idx, 0, task); throw error; }
|
|
305
|
+
clearTaskTimer(task);
|
|
296
306
|
return true;
|
|
297
307
|
}
|
|
298
308
|
|
|
@@ -300,15 +310,13 @@ function createDaemonCronController(options = {}) {
|
|
|
300
310
|
if (task.onceAtMs > 0) {
|
|
301
311
|
const delay = Math.max(0, task.onceAtMs - nowFn());
|
|
302
312
|
task.timer = detachTimer(setTimeoutFn(() => {
|
|
303
|
-
runTask(task);
|
|
304
|
-
stopTask(task.id);
|
|
313
|
+
try { runTask(task); stopTask(task.id); } catch (error) { log(`cron occurrence not dispatched: ${error.message}`); }
|
|
305
314
|
}, delay));
|
|
306
315
|
return;
|
|
307
316
|
}
|
|
308
317
|
|
|
309
318
|
task.timer = detachTimer(setIntervalFn(() => {
|
|
310
|
-
runTask(task);
|
|
311
|
-
persistState();
|
|
319
|
+
try { runTask(task); } catch (error) { log(`cron occurrence not dispatched: ${error.message}`); }
|
|
312
320
|
}, task.intervalMs));
|
|
313
321
|
}
|
|
314
322
|
|
|
@@ -338,13 +346,14 @@ function createDaemonCronController(options = {}) {
|
|
|
338
346
|
createdAt: nowFn(),
|
|
339
347
|
lastRunAt: 0,
|
|
340
348
|
tickCount: 0,
|
|
349
|
+
scheduleId: randomUUID(),
|
|
341
350
|
timer: null,
|
|
342
351
|
};
|
|
343
352
|
|
|
344
|
-
attachTaskTimer(task);
|
|
345
|
-
runTask(task);
|
|
346
353
|
tasks.push(task);
|
|
347
|
-
persistState();
|
|
354
|
+
try { persistState(); } catch (error) { tasks.pop(); throw error; }
|
|
355
|
+
attachTaskTimer(task);
|
|
356
|
+
if (!useOnce) runTask(task);
|
|
348
357
|
|
|
349
358
|
return formatCronTask(task);
|
|
350
359
|
}
|
|
@@ -356,11 +365,9 @@ function createDaemonCronController(options = {}) {
|
|
|
356
365
|
function stopAll() {
|
|
357
366
|
if (tasks.length === 0) return 0;
|
|
358
367
|
const count = tasks.length;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
persistState();
|
|
368
|
+
const removed = tasks.splice(0);
|
|
369
|
+
try { persistState(); } catch (error) { tasks.push(...removed); throw error; }
|
|
370
|
+
removed.forEach(clearTaskTimer);
|
|
364
371
|
return count;
|
|
365
372
|
}
|
|
366
373
|
|
|
@@ -415,7 +422,7 @@ function createDaemonCronController(options = {}) {
|
|
|
415
422
|
}
|
|
416
423
|
|
|
417
424
|
if (Number.isFinite(onceAtMs) && onceAtMs > 0) {
|
|
418
|
-
if (
|
|
425
|
+
if (Number(item.tickCount) > 0) {
|
|
419
426
|
changed = true;
|
|
420
427
|
continue;
|
|
421
428
|
}
|
|
@@ -434,6 +441,7 @@ function createDaemonCronController(options = {}) {
|
|
|
434
441
|
createdAt: Number(item && item.createdAt) || now,
|
|
435
442
|
lastRunAt: Number(item && item.lastRunAt) || 0,
|
|
436
443
|
tickCount: Number(item && item.tickCount) || 0,
|
|
444
|
+
scheduleId: item.scheduleId || `legacy-${rawId}-${Number(item.createdAt) || now}`,
|
|
437
445
|
timer: null,
|
|
438
446
|
};
|
|
439
447
|
|
|
@@ -191,6 +191,18 @@ class DeliveryScheduler {
|
|
|
191
191
|
if (meta.mcp_bridge === true) {
|
|
192
192
|
return { ok: false, reason: "external_receive" };
|
|
193
193
|
}
|
|
194
|
+
// Startup confirmation is a transport gate, not a stale activity sample.
|
|
195
|
+
// Even immediate messages and queue-age overrides must wait for the host.
|
|
196
|
+
if (meta.launcher_ready === false) {
|
|
197
|
+
return { ok: false, reason: "launcher_not_ready" };
|
|
198
|
+
}
|
|
199
|
+
if (meta.native_delivery) {
|
|
200
|
+
// The provider queues work while busy. PTY activity snapshots must not
|
|
201
|
+
// gate a native receive, including messages waiting for the next turn.
|
|
202
|
+
return meta.native_delivery_ready === true
|
|
203
|
+
? { ok: true, reason: "native_receiver" }
|
|
204
|
+
: { ok: false, reason: "native_not_ready" };
|
|
205
|
+
}
|
|
194
206
|
const launchMode = String(meta.launch_mode || "").trim();
|
|
195
207
|
const adapter = this.adapterRouter.getAdapter({ launchMode, agentId: subscriber, meta });
|
|
196
208
|
if (!adapter.capabilities.supportsNotifierInjector) {
|
|
@@ -376,6 +388,15 @@ class DeliveryScheduler {
|
|
|
376
388
|
} else {
|
|
377
389
|
this.graceWarned.delete(subscriber);
|
|
378
390
|
}
|
|
391
|
+
if (selectedEvent && this.getAgentMeta(subscriber).meta?.native_delivery) {
|
|
392
|
+
const receipt = require("../../coordination/bus/nativeReceipts").readNativeReceipt(
|
|
393
|
+
this.projectRoot, subscriber, `${subscriber}:${this.pendingEventKey(selectedEvent)}`
|
|
394
|
+
);
|
|
395
|
+
if (receipt && ["unknown", "inflight"].includes(receipt.state)) {
|
|
396
|
+
this.noteDeferral(subscriber, "native_outcome_unknown");
|
|
397
|
+
return { ok: true, delivered: 0, deferred: true, reason: "native_outcome_unknown", receipt_id: receipt.id };
|
|
398
|
+
}
|
|
399
|
+
}
|
|
379
400
|
this.clearDeferral(subscriber);
|
|
380
401
|
|
|
381
402
|
const selectedKey = selectedEvent ? this.pendingEventKey(selectedEvent) : "";
|
|
@@ -416,7 +437,12 @@ class DeliveryScheduler {
|
|
|
416
437
|
const { agents } = this.getAgentMeta(subscriber);
|
|
417
438
|
const injectionText = this.buildInjectionText(envelope, subscriber, agents);
|
|
418
439
|
try {
|
|
419
|
-
|
|
440
|
+
if (agents[subscriber]?.native_delivery) {
|
|
441
|
+
await this.injector.inject(subscriber, injectionText, {
|
|
442
|
+
deliveryId: `${subscriber}:${this.pendingEventKey(evt)}`,
|
|
443
|
+
through_seq: Number(evt.seq) || undefined,
|
|
444
|
+
});
|
|
445
|
+
} else await this.injector.inject(subscriber, injectionText);
|
|
420
446
|
queue.completeClaim(claim);
|
|
421
447
|
this.clearPendingTracking(subscriber, evt);
|
|
422
448
|
// Close the idle gate immediately. PTY ActivityDetector will refresh
|
|
@@ -428,21 +454,22 @@ class DeliveryScheduler {
|
|
|
428
454
|
} catch {
|
|
429
455
|
// activity stamp must never undo a successful inject
|
|
430
456
|
}
|
|
431
|
-
await this.emitDelivery({
|
|
457
|
+
try { await this.emitDelivery({
|
|
432
458
|
subscriber,
|
|
433
459
|
event: envelope,
|
|
434
460
|
status: "ok",
|
|
435
|
-
});
|
|
461
|
+
}); } catch (error) { this.log(`delivery observer failed after confirmed inject: ${error.message}`); }
|
|
436
462
|
return { ok: true, delivered: 1, event: envelope };
|
|
437
463
|
} catch (err) {
|
|
438
464
|
queue.restoreClaim(claim);
|
|
439
465
|
if (gate.forceOverride) this.noteForceFailure(subscriber, gate.pending);
|
|
440
|
-
await this.emitDelivery({
|
|
466
|
+
try { await this.emitDelivery({
|
|
441
467
|
subscriber,
|
|
442
468
|
event: envelope,
|
|
443
469
|
status: "error",
|
|
444
470
|
error: err && err.message ? err.message : String(err || "inject failed"),
|
|
445
|
-
|
|
471
|
+
errorCode: err && err.code || "",
|
|
472
|
+
}); } catch (error) { this.log(`delivery observer failed: ${error.message}`); }
|
|
446
473
|
return {
|
|
447
474
|
ok: false,
|
|
448
475
|
delivered: 0,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { createRuntimeStore } = require("../../agents/runtime");
|
|
6
|
+
|
|
7
|
+
/** Persist one executor per conversation. Old controller transcripts stay on their path. */
|
|
8
|
+
function createExecutionPathSelector(projectRoot) {
|
|
9
|
+
const store = createRuntimeStore({ workspaceRoot: projectRoot, namespace: "controller-path", sessionId: "paths" });
|
|
10
|
+
return function select({ sessionId = "main-default", requestedMode, mode }) {
|
|
11
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,100}$/.test(sessionId)) throw new Error("invalid session identity");
|
|
12
|
+
let selected;
|
|
13
|
+
store.transaction((state) => {
|
|
14
|
+
const value = state.capabilityState["execution-path"]?.value || { sessions: {} };
|
|
15
|
+
selected = Object.hasOwn(value.sessions, sessionId) ? value.sessions[sessionId] : "";
|
|
16
|
+
if (selected) {
|
|
17
|
+
if (requestedMode && requestedMode !== selected) throw Object.assign(new Error(`session uses ${selected}; use /session new before changing its executor`), { code: "session_path_pinned" });
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const oldHistory = path.join(projectRoot, ".ufoo", "agent", "ufoo-agent.history.jsonl");
|
|
21
|
+
const newHistory = path.join(projectRoot, ".ufoo", "agent", "main", "runtimes", sessionId, "events.jsonl");
|
|
22
|
+
selected = sessionId === "main-default" && fs.existsSync(oldHistory) && !fs.existsSync(newHistory) ? "legacy" : mode;
|
|
23
|
+
value.sessions[sessionId] = selected;
|
|
24
|
+
return [{ type: "capability.state_committed", capabilityId: "execution-path", version: 1, value }];
|
|
25
|
+
});
|
|
26
|
+
return selected;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = { createExecutionPathSelector };
|
|
@@ -103,6 +103,8 @@ class GlobalDaemon {
|
|
|
103
103
|
runtimeFactory: (context) => this.createHostedRuntime(context),
|
|
104
104
|
});
|
|
105
105
|
this.activeGatewayRequests = new Map();
|
|
106
|
+
this.clientProjects = new WeakMap();
|
|
107
|
+
this.clientSubscriptions = new WeakMap();
|
|
106
108
|
this.projectRuntimeGateway = {
|
|
107
109
|
call: (projectRoot, operation, args, context) =>
|
|
108
110
|
this.callProjectOperation(projectRoot, operation, args, context),
|
|
@@ -166,9 +168,11 @@ class GlobalDaemon {
|
|
|
166
168
|
err.code = "PROJECT_RUNTIME_UNAVAILABLE";
|
|
167
169
|
throw err;
|
|
168
170
|
}
|
|
171
|
+
const socket = callContext.requestContext.socket;
|
|
172
|
+
if (this.clientProjects.get(socket) === context.projectRoot) this.bindClientSocket(socket, hostHandle);
|
|
169
173
|
return hostHandle.handleRequest(
|
|
170
174
|
callContext.requestContext.request,
|
|
171
|
-
|
|
175
|
+
socket
|
|
172
176
|
);
|
|
173
177
|
});
|
|
174
178
|
for (const operation of [
|
|
@@ -316,6 +320,11 @@ class GlobalDaemon {
|
|
|
316
320
|
|
|
317
321
|
async handleRequest(projectRoot, request, socket) {
|
|
318
322
|
const canonicalRoot = this.resolveProjectRoot(projectRoot);
|
|
323
|
+
if (socket && typeof socket.on === "function") {
|
|
324
|
+
const previousRoot = this.clientProjects.get(socket);
|
|
325
|
+
this.clientProjects.set(socket, canonicalRoot);
|
|
326
|
+
if (previousRoot !== canonicalRoot) this.bindClientSocket(socket, null);
|
|
327
|
+
}
|
|
319
328
|
const config = this.loadProjectConfig(canonicalRoot);
|
|
320
329
|
const provider = config.agentProvider || "codex-cli";
|
|
321
330
|
const model = config.agentModel || defaultAgentModelForProvider(provider);
|
|
@@ -332,6 +341,24 @@ class GlobalDaemon {
|
|
|
332
341
|
});
|
|
333
342
|
}
|
|
334
343
|
|
|
344
|
+
bindClientSocket(socket, host) {
|
|
345
|
+
if (!socket || typeof socket.on !== "function") return;
|
|
346
|
+
const next = host?.runtime?.resource("ipcServer") || null;
|
|
347
|
+
const previous = this.clientSubscriptions.get(socket)
|
|
348
|
+
|| this.controller?.runtime?.resource("ipcServer");
|
|
349
|
+
if (previous === next) return;
|
|
350
|
+
previous?.detachSocket?.(socket);
|
|
351
|
+
next?.attachSocket?.(socket);
|
|
352
|
+
if (next) this.clientSubscriptions.set(socket, next);
|
|
353
|
+
else this.clientSubscriptions.delete(socket);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
bindControllerClient(socket) {
|
|
357
|
+
if (!socket || typeof socket.on !== "function") return;
|
|
358
|
+
this.clientProjects.set(socket, this.controllerRoot);
|
|
359
|
+
this.bindClientSocket(socket, this.controller);
|
|
360
|
+
}
|
|
361
|
+
|
|
335
362
|
async callProjectOperation(projectRoot, operation, args = {}, context = {}) {
|
|
336
363
|
const canonicalRoot = this.resolveProjectRoot(projectRoot);
|
|
337
364
|
const config = this.loadProjectConfig(canonicalRoot);
|