@nathanstephenson/flow 0.1.10-beta.2 → 0.1.10-beta.4
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 +27 -1
- package/build/backend-worker-chunks/{chunk-LO7O6NAM.mjs → chunk-JOI2POLP.mjs} +1 -1
- package/build/backend-worker-chunks/{chunk-UQDH2COY.mjs → chunk-K774KOGL.mjs} +2 -7
- package/build/backend-worker-chunks/chunk-LAEUXDNH.mjs +130 -0
- package/build/backend-worker-chunks/{chunk-MLOUI3ZM.mjs → chunk-NZZME2I3.mjs} +6 -1
- package/build/backend-worker-chunks/claude-GY27HBAY.mjs +35739 -0
- package/build/backend-worker-chunks/{pi-HJKTV2TH.mjs → pi-JV6MWPW7.mjs} +1901 -45
- package/build/backend-worker.mjs +52 -116
- package/dist/backend/claude/background-calls.js +7 -3
- package/dist/backend/claude/index.js +106 -16
- package/dist/backend/claude/subagents.js +41 -9
- package/dist/backend/fake/index.js +26 -5
- package/dist/backend/pi/cache-warming.js +8 -0
- package/dist/backend/pi/canonical-json.js +120 -0
- package/dist/backend/pi/compaction-model.js +3 -2
- package/dist/backend/pi/host-auth.js +258 -0
- package/dist/backend/pi/index.js +38 -12
- package/dist/backend/pi/model-auth.js +159 -0
- package/dist/backend/pi/model-catalog.js +120 -0
- package/dist/backend/pi/model-config.js +5 -0
- package/dist/backend/pi/model-selection.js +32 -0
- package/dist/backend/pi/subagents.js +7 -3
- package/dist/backend/pi/work.js +9 -1
- package/dist/backend/pi/workflow-subagent.js +4 -3
- package/dist/backend/worker/entry.js +32 -6
- package/dist/backend/worker/index.js +87 -7
- package/dist/backend/worker/rpc.js +13 -0
- package/dist/backend/worker/sandbox-mcp.js +18 -7
- package/dist/build-id +1 -1
- package/dist/cli/bootstrap.js +1 -1
- package/dist/client/reduce.js +11 -3
- package/dist/client/subagent-tree.js +49 -0
- package/dist/client/tool-summary.js +26 -15
- package/dist/daemon/git.js +10 -7
- package/dist/daemon/host.js +100 -22
- package/dist/daemon/models.js +2 -2
- package/dist/daemon/pi-model-cache.js +44 -0
- package/dist/daemon/runtime.js +63 -3
- package/dist/daemon/server.js +3 -0
- package/dist/daemon/store.js +2 -0
- package/dist/daemon/workflow-environment.js +191 -0
- package/dist/daemon/workflow-execution-launch.js +77 -0
- package/dist/daemon/workflow-execution-resources.js +76 -0
- package/dist/daemon/workflow-execution-values.js +128 -0
- package/dist/daemon/workflow-executions.js +272 -285
- package/dist/daemon/workflow-schedule-driver.js +247 -0
- package/dist/daemon/workflow-schedule-routes.js +137 -0
- package/dist/daemon/workflow-schedules.js +341 -0
- package/dist/isolation/filesystem.js +5 -1
- package/dist/isolation/sandbox.js +61 -18
- package/dist/isolation/shared-sandbox.js +3 -3
- package/dist/protocol/workflow-schedules.js +1 -0
- package/dist/tui/render.js +7 -1
- package/dist/workflows/calls.js +10 -7
- package/dist/workflows/errors.js +2 -0
- package/dist/workflows/executors.js +1 -1
- package/dist/workflows/invocations.js +8 -5
- package/dist/workflows/owner.js +45 -0
- package/dist/workflows/records.js +8 -2
- package/dist/workflows/schedule-errors.js +2 -0
- package/dist/workflows/schedule-store.js +385 -0
- package/dist/workflows/scheduler.js +29 -18
- package/dist/workflows/schedules.js +129 -0
- package/dist/workflows/store.js +110 -11
- package/package.json +8 -5
- package/web/dist/assets/index-BWKZK5HD.css +2 -0
- package/web/dist/assets/index-nIc09tKZ.js +40 -0
- package/web/dist/assets/{settings-mcp-sebWClE0.js → settings-mcp-bcNKV147.js} +1 -1
- package/web/dist/assets/settings-workflows-C_TKOhVa.js +23 -0
- package/web/dist/assets/workflows-DHG-CIo3.js +146 -0
- package/web/dist/assets/workflows-pane-9u_hJvgQ.js +1 -0
- package/web/dist/index.html +4 -3
- package/build/backend-worker-chunks/claude-COCNALN2.mjs +0 -30846
- package/web/dist/assets/index-CLdr6AA0.js +0 -40
- package/web/dist/assets/index-DHAcGIoF.css +0 -2
- package/web/dist/assets/settings-workflows-BvArjkes.js +0 -23
- package/web/dist/assets/workflow-editors-Tztq_Opa.js +0 -139
- package/web/dist/assets/workflows-CdDynCfW.js +0 -7
- package/web/dist/assets/workflows-pane-DaqHEeXu.js +0 -1
package/dist/daemon/host.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { waitForAbort } from "../backend/worker/rpc.js";
|
|
1
2
|
import { sessionListInput, sessionInspectInput, sessionCreateInput, sessionSendInput } from "../backend/session-tools.js";
|
|
2
3
|
import { sessionToolSummary, sessionToolPage } from "./session-tool-views.js";
|
|
3
4
|
import { credentialKey } from "./credential-redaction.js";
|
|
@@ -16,6 +17,8 @@ import { deriveStatus, railGroupRank } from "../client/status.js";
|
|
|
16
17
|
import { createWorktree, head, isClean, isRepository, removeMergedBranch, removeWorktree, repairWorktree, switchBranch as gitSwitchBranch, } from "./git.js";
|
|
17
18
|
import { SessionLog } from "./log.js";
|
|
18
19
|
import { probeModels } from "./models.js";
|
|
20
|
+
import { PiModelProbeCache } from "./pi-model-cache.js";
|
|
21
|
+
import { ScheduleValidationError } from "../workflows/schedule-errors.js";
|
|
19
22
|
import { probeSkills } from "./skills.js";
|
|
20
23
|
import { recordTiming } from "./timings.js";
|
|
21
24
|
import { SharedSandbox } from "../isolation/shared-sandbox.js";
|
|
@@ -42,6 +45,7 @@ export class SessionHost {
|
|
|
42
45
|
backends = new Map();
|
|
43
46
|
/** Model probes by backend name, held in flight rather than resolved — see `models`. */
|
|
44
47
|
modelProbes = new Map();
|
|
48
|
+
piModelProbeCache = new PiModelProbeCache();
|
|
45
49
|
/** One warm Skills session per Backend Adapter, for the last Scope asked — see `skillsFor` (ADR 0035). */
|
|
46
50
|
skillSessions = new Map();
|
|
47
51
|
/**
|
|
@@ -298,19 +302,29 @@ export class SessionHost {
|
|
|
298
302
|
* In flight rather than resolved is what is remembered, so two clients opening the page at once
|
|
299
303
|
* spawn one probe between them rather than one each.
|
|
300
304
|
*/
|
|
301
|
-
async models(scope, refresh = false) {
|
|
305
|
+
async models(scope, refresh = false, backendName) {
|
|
302
306
|
if (refresh)
|
|
303
307
|
this.modelProbes.clear();
|
|
304
|
-
const
|
|
308
|
+
const backends = backendName === undefined ? [...this.backends.values()] : [this.backendFor(backendName)];
|
|
309
|
+
const probes = backends.map((backend) => {
|
|
305
310
|
const held = this.modelProbes.get(backend.name);
|
|
306
311
|
if (held)
|
|
307
312
|
return held;
|
|
308
|
-
const probe = this.timed("models", backend, false, (timed) => probeModels(timed, scope, false, (held) => this.holdSkillSession(backend.name, held, false)));
|
|
313
|
+
const probe = this.timed("models", backend, false, (timed) => probeModels(backend.name === 'pi' ? this.piModelProbeCache.wrap(timed) : timed, scope, false, (held) => this.holdSkillSession(backend.name, held, false), refresh));
|
|
309
314
|
this.modelProbes.set(backend.name, probe);
|
|
310
315
|
return probe;
|
|
311
316
|
});
|
|
312
317
|
return await Promise.all(probes);
|
|
313
318
|
}
|
|
319
|
+
async workflowAgentModels(scope, backend) {
|
|
320
|
+
const [catalogue] = await this.models(scope, false, backend);
|
|
321
|
+
if (!catalogue || catalogue.problem)
|
|
322
|
+
throw new Error(catalogue?.problem ?? 'Workflow model capabilities are unavailable');
|
|
323
|
+
const probe = this.skillSessions.get(backend);
|
|
324
|
+
if (!probe || probe.dead || !probe.session.startWorkflowSubagent)
|
|
325
|
+
throw new Error('Workflow agent capabilities are unavailable. Retry after the Backend Session is ready.');
|
|
326
|
+
return catalogue.models;
|
|
327
|
+
}
|
|
314
328
|
/**
|
|
315
329
|
* Which Skills a Scope offers through one Backend Adapter, with no Agent Session in it.
|
|
316
330
|
*
|
|
@@ -566,6 +580,7 @@ export class SessionHost {
|
|
|
566
580
|
branch: branchFrom(entries),
|
|
567
581
|
branchGeneration: 0,
|
|
568
582
|
worktree: meta.worktree,
|
|
583
|
+
...(meta.scheduledOccurrenceId ? { scheduledOccurrenceId: meta.scheduledOccurrenceId } : {}),
|
|
569
584
|
pendingBranchNote: undefined,
|
|
570
585
|
capabilities: capabilitiesFrom(entries),
|
|
571
586
|
spend: spendFrom(entries),
|
|
@@ -594,7 +609,30 @@ export class SessionHost {
|
|
|
594
609
|
}
|
|
595
610
|
await this.reap();
|
|
596
611
|
}
|
|
612
|
+
scheduledAttachments = new Map();
|
|
613
|
+
/** Internal attachment lane: concurrent agent/input/recovery callbacks share creation and Revive.
|
|
614
|
+
* The caller has already journaled the intended identity before entering this operation. */
|
|
615
|
+
attachScheduled(options) {
|
|
616
|
+
if (this.workflowShutdown)
|
|
617
|
+
return Promise.reject(new CommandRefused('Session Host is stopping'));
|
|
618
|
+
const id = options.scheduled.id;
|
|
619
|
+
const pending = this.scheduledAttachments.get(id);
|
|
620
|
+
if (pending)
|
|
621
|
+
return pending;
|
|
622
|
+
const attachment = this.create(options).finally(() => { this.scheduledAttachments.delete(id); });
|
|
623
|
+
this.scheduledAttachments.set(id, attachment);
|
|
624
|
+
return attachment;
|
|
625
|
+
}
|
|
597
626
|
async create(options) {
|
|
627
|
+
if (options.scheduled) {
|
|
628
|
+
const existing = this.sessions.get(options.scheduled.id);
|
|
629
|
+
if (existing) {
|
|
630
|
+
if (existing.scheduledOccurrenceId !== options.scheduled.occurrenceId)
|
|
631
|
+
throw new Error('Scheduled association mismatch');
|
|
632
|
+
await this.openWorkflowSession(existing.id);
|
|
633
|
+
return existing.id;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
598
636
|
const connections = this.mcpConnections?.() ?? [];
|
|
599
637
|
if (options.mcpConnectionIds !== undefined && (!Array.isArray(options.mcpConnectionIds) || options.mcpConnectionIds.some((id) => typeof id !== "string")))
|
|
600
638
|
throw new Error("Invalid MCP selection");
|
|
@@ -606,17 +644,18 @@ export class SessionHost {
|
|
|
606
644
|
// Reject an unsupported policy before creating a worktree or any durable Agent Session state.
|
|
607
645
|
const permissionMode = options.permissionMode ?? this.permissionDefault(backend.name);
|
|
608
646
|
this.validatePermissionMode(backend.name, permissionMode);
|
|
609
|
-
const worktree = options.worktree ? await this.cutWorktree(options.scope, options.worktree) : undefined;
|
|
647
|
+
const worktree = options.scheduled?.worktree ?? (options.worktree ? await this.cutWorktree(options.scope, options.worktree) : undefined);
|
|
610
648
|
// The Scope from here down, and for this Agent Session's whole life. Resolved before any record
|
|
611
649
|
// exists so that a `worktree add` which failed leaves nothing persisted pointing at a directory
|
|
612
650
|
// that is not there.
|
|
613
651
|
const scope = scopeKey(worktree?.path ?? options.scope);
|
|
614
|
-
const id = randomUUID();
|
|
652
|
+
const id = options.scheduled?.id ?? randomUUID();
|
|
615
653
|
const now = new Date().toISOString();
|
|
616
654
|
const modelId = options.modelId ?? this.defaultModel?.(backend.name);
|
|
617
655
|
const effort = options.effort ?? this.defaultEffort?.(backend.name);
|
|
618
656
|
const record = {
|
|
619
657
|
id,
|
|
658
|
+
...(options.scheduled ? { scheduledOccurrenceId: options.scheduled.occurrenceId } : {}),
|
|
620
659
|
scope,
|
|
621
660
|
backendName: backend.name,
|
|
622
661
|
log: this.newLog(id),
|
|
@@ -684,7 +723,8 @@ export class SessionHost {
|
|
|
684
723
|
// Creation never returns an Agent Session without confirmed models. In particular, do not
|
|
685
724
|
// leave a persisted, empty Agent Session (or a newly cut worktree) after a failed probe.
|
|
686
725
|
await record.session?.dispose().catch(() => { });
|
|
687
|
-
|
|
726
|
+
if (!options.scheduled)
|
|
727
|
+
await this.releaseWorktree(record);
|
|
688
728
|
record.log.closeSubscribers();
|
|
689
729
|
this.sessions.delete(id);
|
|
690
730
|
this.store?.deleteSession(id);
|
|
@@ -712,7 +752,8 @@ export class SessionHost {
|
|
|
712
752
|
* how a spare gets dropped when somebody clears the Setting: nothing will ever *tell* us it
|
|
713
753
|
* changed (ADR 0009), so a read-through is the only moment it can be noticed.
|
|
714
754
|
*/
|
|
715
|
-
|
|
755
|
+
if (!options.scheduled)
|
|
756
|
+
this.warmSummaryModel(backend.name);
|
|
716
757
|
return id;
|
|
717
758
|
}
|
|
718
759
|
/**
|
|
@@ -893,7 +934,7 @@ export class SessionHost {
|
|
|
893
934
|
* value that can bypass the Steering Queue, and "after_turn" already means "queue if busy, else
|
|
894
935
|
* dispatch now" — so there is no sensible default to pick. It matches `Command` either way.
|
|
895
936
|
*/
|
|
896
|
-
async send(sessionId, text, when, attachments, beforeAccept, titleText) {
|
|
937
|
+
async send(sessionId, text, when, attachments, beforeAccept, titleText, fromSessionId) {
|
|
897
938
|
const record = this.record(sessionId);
|
|
898
939
|
this.refuseGitOperation(record.scope);
|
|
899
940
|
// ADR 0003: the first message revives a Dormant session, so resuming work is one action.
|
|
@@ -906,14 +947,15 @@ export class SessionHost {
|
|
|
906
947
|
// Checked before anything is written, so a refused send leaves no bytes behind.
|
|
907
948
|
this.refuseUnservableAttachments(record, attachments);
|
|
908
949
|
const ids = (attachments ?? []).map((attachment) => this.storeOrThrow().writeAttachment(record.id, attachment.mediaType, attachment.data));
|
|
950
|
+
const from = fromSessionId === undefined ? {} : { fromSessionId };
|
|
909
951
|
if (when === "after_turn" && record.turnInFlight) {
|
|
910
|
-
record.queue.push({ id: randomUUID(), text, attachments: ids });
|
|
952
|
+
record.queue.push({ id: randomUUID(), text, attachments: ids, ...from });
|
|
911
953
|
record.log.append(queueChanged(record.queue));
|
|
912
954
|
this.touch(record);
|
|
913
955
|
return;
|
|
914
956
|
}
|
|
915
957
|
// A title override applies only to the initial dispatch; a queued turn already has a title.
|
|
916
|
-
await this.dispatch(record, { text, attachments: ids }, titleText);
|
|
958
|
+
await this.dispatch(record, { text, attachments: ids, ...from }, titleText);
|
|
917
959
|
}
|
|
918
960
|
/**
|
|
919
961
|
* Whether this send's Attachments can be carried at all, refused before any are written down.
|
|
@@ -1920,6 +1962,8 @@ export class SessionHost {
|
|
|
1920
1962
|
for (const record of [...this.sessions.values()]) {
|
|
1921
1963
|
if (record.lifecycle !== "settled")
|
|
1922
1964
|
continue;
|
|
1965
|
+
if (this.workflowOwner?.canForget?.(record.id, record.scheduledOccurrenceId) === false)
|
|
1966
|
+
continue;
|
|
1923
1967
|
const settledAt = record.settledAt === undefined ? NaN : Date.parse(record.settledAt);
|
|
1924
1968
|
// An unreadable timestamp means we cannot know the age; leaving it is the safe failure.
|
|
1925
1969
|
if (Number.isNaN(settledAt) || now - settledAt < retention)
|
|
@@ -2075,7 +2119,7 @@ export class SessionHost {
|
|
|
2075
2119
|
this.workflowShutdown = true;
|
|
2076
2120
|
// Creation can still be awaiting backend startup after its caller disconnects. Drain those
|
|
2077
2121
|
// accepted operations before walking sessions, so late children cannot escape shutdown.
|
|
2078
|
-
await Promise.allSettled([...this.sessionToolOperations]);
|
|
2122
|
+
await Promise.allSettled([...this.sessionToolOperations, ...this.scheduledAttachments.values()]);
|
|
2079
2123
|
// First, so that a naming still in flight cannot warm a replacement on the way out — the
|
|
2080
2124
|
// one-shot CLI runner shuts down microseconds before `process.exit`, and a spare booted in
|
|
2081
2125
|
// that window is a child process nothing is left to dispose. Not awaited, and cannot be: see
|
|
@@ -2103,6 +2147,10 @@ export class SessionHost {
|
|
|
2103
2147
|
this.persist(record);
|
|
2104
2148
|
}
|
|
2105
2149
|
await this.shared?.close().catch((error) => console.error(`Shared sandbox removal failed: ${error.message}`));
|
|
2150
|
+
const stopped = await Promise.allSettled([...this.backends.values()].map(async (backend) => backend.shutdown?.()));
|
|
2151
|
+
const failures = stopped.filter(result => result.status === "rejected").map(result => result.reason);
|
|
2152
|
+
if (failures.length)
|
|
2153
|
+
throw new AggregateError(failures, "Backend Adapter shutdown failed");
|
|
2106
2154
|
}
|
|
2107
2155
|
async execute(command) {
|
|
2108
2156
|
switch (command.type) {
|
|
@@ -2233,27 +2281,48 @@ export class SessionHost {
|
|
|
2233
2281
|
throw new Error('Unknown Agent Session');
|
|
2234
2282
|
return structuredClone((this.mcpConnections?.() ?? []).filter(connection => record.mcpConnectionIds?.includes(connection.id)));
|
|
2235
2283
|
}
|
|
2284
|
+
scheduledConnections(ids) {
|
|
2285
|
+
const connections = this.mcpConnections?.() ?? [];
|
|
2286
|
+
if (ids.some(id => !connections.some(connection => connection.id === id)))
|
|
2287
|
+
throw new ScheduleValidationError('Selected MCP connection is unavailable');
|
|
2288
|
+
return structuredClone(connections.filter(connection => ids.includes(connection.id)));
|
|
2289
|
+
}
|
|
2290
|
+
scheduledMcp(scope, ids, mode) {
|
|
2291
|
+
const connections = this.scheduledConnections(ids);
|
|
2292
|
+
const oauth = this.mcpAuth ? (connection) => this.mcpAuth.provider(connection) : undefined;
|
|
2293
|
+
return import("../backend/mcp.js").then(({ McpSession }) => new McpSession(connections, scope, oauth, true, this.resolveSecret, undefined, this.filesystemStateRoot(), mode));
|
|
2294
|
+
}
|
|
2295
|
+
scheduledSandboxMcp(scope, ids) {
|
|
2296
|
+
return import("../backend/worker/sandbox-mcp.js").then(({ SandboxMcpSession }) => new SandboxMcpSession(this.scheduledConnections(ids), scope, this.mcpAuth ? connection => this.mcpAuth.provider(connection) : undefined, this.resolveSecret));
|
|
2297
|
+
}
|
|
2236
2298
|
/** Include an SDK-supplied owning root in every local execution's filesystem policy. */
|
|
2237
2299
|
filesystemStateRoot() { return this.store?.root; }
|
|
2238
2300
|
/** A host without configured Settings keeps the safe, restricted library default. */
|
|
2239
2301
|
filesystemIsolationMode() { return this.filesystemIsolation?.() ?? "bubblewrap"; }
|
|
2240
2302
|
sandboxSupport() { return this.sandbox?.(); }
|
|
2241
2303
|
/** The Shared Sandbox, when the Settings choose one VM for all sandbox sessions. */
|
|
2304
|
+
scheduledSandboxMounts(scope) {
|
|
2305
|
+
const mounts = [...this.backends.values()].flatMap(backend => backend.scheduledSandboxMounts?.(scope) ?? []);
|
|
2306
|
+
return { writable: mounts.flatMap(item => item.writable), readable: mounts.flatMap(item => item.readable) };
|
|
2307
|
+
}
|
|
2242
2308
|
sharedSandbox() { return this.sandboxSharing?.() === "shared" ? this.shared : undefined; }
|
|
2243
|
-
async openWorkflowMcp(id, connectionId, isolationMode = this.filesystemIsolationMode()) {
|
|
2309
|
+
async openWorkflowMcp(id, connectionId, isolationMode = this.filesystemIsolationMode(), signal) {
|
|
2310
|
+
signal?.throwIfAborted();
|
|
2244
2311
|
if (isolationMode === "sandbox") {
|
|
2245
|
-
await this.openWorkflowSession(id);
|
|
2312
|
+
await waitForAbort(this.openWorkflowSession(id), signal);
|
|
2313
|
+
signal?.throwIfAborted();
|
|
2246
2314
|
const { SandboxMcpSession } = await import("../backend/worker/sandbox-mcp.js");
|
|
2247
2315
|
const mcp = this.record(id).mcp;
|
|
2248
2316
|
if (!(mcp instanceof SandboxMcpSession))
|
|
2249
2317
|
throw new Error("Sandbox isolation is unavailable; unrestricted launch refused: the Agent Session has no sandbox");
|
|
2250
|
-
return mcp.directView(connectionId);
|
|
2318
|
+
return mcp.directView(connectionId, signal);
|
|
2251
2319
|
}
|
|
2252
2320
|
const connection = this.workflowMcpConnections(id).find(connection => connection.id === connectionId);
|
|
2253
2321
|
if (!connection)
|
|
2254
2322
|
throw new Error('MCP connection is removed or disabled for this Agent Session. Enable it in the Agent Session settings and reconfigure the step.');
|
|
2255
2323
|
const { McpSession } = await import("../backend/mcp.js");
|
|
2256
2324
|
const scope = this.workflowSession(id).scope;
|
|
2325
|
+
signal?.throwIfAborted();
|
|
2257
2326
|
return new McpSession([connection], scope, this.mcpAuth ? connection => this.mcpAuth.provider(connection) : undefined, true, this.resolveSecret, undefined, this.filesystemStateRoot(), isolationMode);
|
|
2258
2327
|
}
|
|
2259
2328
|
/** Metadata discovery owned by authoring, never by an Agent/Backend Session. */
|
|
@@ -2380,11 +2449,11 @@ export class SessionHost {
|
|
|
2380
2449
|
mcpConnectionIds: source.mcpConnectionIds ?? [],
|
|
2381
2450
|
permissionMode: source.permissionMode === 'auto' && name !== 'claude' ? 'ask' : source.permissionMode });
|
|
2382
2451
|
// Persist a receipt even if cancellation loses the RPC result; never blindly recreate.
|
|
2383
|
-
source.log.append({ type: 'notice', level: 'info', text: `Created Agent Session ${sessionId}
|
|
2384
|
-
this.record(sessionId).log.append({ type: 'notice', level: 'info', text: `Created by Agent Session ${source.id}
|
|
2452
|
+
source.log.append({ type: 'notice', level: 'info', text: `Created Agent Session ${sessionId}`, sessionId });
|
|
2453
|
+
this.record(sessionId).log.append({ type: 'notice', level: 'info', text: `Created by Agent Session ${source.id}`, sessionId: source.id });
|
|
2385
2454
|
try {
|
|
2386
2455
|
check(signal);
|
|
2387
|
-
await this.send(sessionId, attributed(text), 'after_turn', undefined, () => check(signal), text);
|
|
2456
|
+
await this.send(sessionId, attributed(text), 'after_turn', undefined, () => check(signal), text, source.id);
|
|
2388
2457
|
return { sessionId, delivery: 'accepted' };
|
|
2389
2458
|
}
|
|
2390
2459
|
catch (error) {
|
|
@@ -2396,7 +2465,7 @@ export class SessionHost {
|
|
|
2396
2465
|
const { sessionId, text } = sessionSendInput.parse(input);
|
|
2397
2466
|
if (sessionId === source.id)
|
|
2398
2467
|
throw new CommandRefused('Use the current conversation instead of messaging yourself');
|
|
2399
|
-
await this.send(sessionId, attributed(text), 'after_turn', undefined, () => check(signal), text);
|
|
2468
|
+
await this.send(sessionId, attributed(text), 'after_turn', undefined, () => check(signal), text, source.id);
|
|
2400
2469
|
return { sessionId, delivery: 'accepted' };
|
|
2401
2470
|
}),
|
|
2402
2471
|
};
|
|
@@ -2418,6 +2487,7 @@ export class SessionHost {
|
|
|
2418
2487
|
const compactionModelId = this.compactionModel?.(backend.name);
|
|
2419
2488
|
let attached;
|
|
2420
2489
|
const session = await backend.create({
|
|
2490
|
+
isolationMode,
|
|
2421
2491
|
mcp,
|
|
2422
2492
|
onFailure: () => {
|
|
2423
2493
|
if (!attached || record.session !== attached)
|
|
@@ -2656,7 +2726,7 @@ export class SessionHost {
|
|
|
2656
2726
|
}
|
|
2657
2727
|
record.initialEffortUnconfirmed = false;
|
|
2658
2728
|
}
|
|
2659
|
-
const { text, attachments } = message;
|
|
2729
|
+
const { text, attachments, fromSessionId } = message;
|
|
2660
2730
|
const note = record.pendingBranchNote;
|
|
2661
2731
|
record.pendingBranchNote = undefined;
|
|
2662
2732
|
/*
|
|
@@ -2679,6 +2749,7 @@ export class SessionHost {
|
|
|
2679
2749
|
id: messageId,
|
|
2680
2750
|
text: sent,
|
|
2681
2751
|
...(attachments.length > 0 ? { attachments } : {}),
|
|
2752
|
+
...(fromSessionId === undefined ? {} : { fromSessionId }),
|
|
2682
2753
|
});
|
|
2683
2754
|
// Titled from the original instructions, never attribution or `sent`. A switch made before the first
|
|
2684
2755
|
// message would otherwise name the Agent Session after the note, and permanently: the rename
|
|
@@ -2994,6 +3065,7 @@ export class SessionHost {
|
|
|
2994
3065
|
return;
|
|
2995
3066
|
const meta = {
|
|
2996
3067
|
id: record.id,
|
|
3068
|
+
...(record.scheduledOccurrenceId ? { scheduledOccurrenceId: record.scheduledOccurrenceId } : {}),
|
|
2997
3069
|
scope: record.scope,
|
|
2998
3070
|
backend: record.backendName,
|
|
2999
3071
|
title: record.title,
|
|
@@ -3228,12 +3300,18 @@ function openSubagents(entries) {
|
|
|
3228
3300
|
const event = entry.event;
|
|
3229
3301
|
if (event.type !== "subagent")
|
|
3230
3302
|
continue;
|
|
3231
|
-
if (event.state === "running" || event.state === "waiting")
|
|
3232
|
-
open.set(event.subagentId,
|
|
3303
|
+
if (event.state === "running" || event.state === "waiting") {
|
|
3304
|
+
open.set(event.subagentId, {
|
|
3305
|
+
name: event.name,
|
|
3306
|
+
...(event.model === undefined ? {} : { model: event.model }),
|
|
3307
|
+
...(event.effort === undefined ? {} : { effort: event.effort }),
|
|
3308
|
+
...(event.producer === undefined ? {} : { producer: event.producer }),
|
|
3309
|
+
});
|
|
3310
|
+
}
|
|
3233
3311
|
else
|
|
3234
3312
|
open.delete(event.subagentId);
|
|
3235
3313
|
}
|
|
3236
|
-
return [...open].map(([subagentId,
|
|
3314
|
+
return [...open].map(([subagentId, brief]) => ({ subagentId, ...brief }));
|
|
3237
3315
|
}
|
|
3238
3316
|
/** What the transcript last reported this Agent Session had spent, across every Backend Session. */
|
|
3239
3317
|
function spendFrom(entries) {
|
package/dist/daemon/models.js
CHANGED
|
@@ -29,7 +29,7 @@ const PROBE_TIMEOUT_MS = 45_000;
|
|
|
29
29
|
* Never throws: a backend that cannot answer reports a `problem`, and its section of the Settings
|
|
30
30
|
* offers a text field instead of a list. A refusal here must not make the whole page unreachable.
|
|
31
31
|
*/
|
|
32
|
-
export async function probeModels(backend, scope, workflowBuilder = false, keep) {
|
|
32
|
+
export async function probeModels(backend, scope, workflowBuilder = false, keep, refresh = false) {
|
|
33
33
|
let models = [];
|
|
34
34
|
let settle;
|
|
35
35
|
// Claude reports a provisional Capabilities at create and the real list moments later, over
|
|
@@ -47,7 +47,7 @@ export async function probeModels(backend, scope, workflowBuilder = false, keep)
|
|
|
47
47
|
let session;
|
|
48
48
|
try {
|
|
49
49
|
const refuseTool = async () => { throw new Error("Model discovery cannot use workflow builder tools"); };
|
|
50
|
-
session = await backend.create({ ...options, ...(workflowBuilder ? { workflowBuilder: {
|
|
50
|
+
session = await backend.create({ ...options, ...(refresh ? { refreshModels: true } : {}), ...(workflowBuilder ? { workflowBuilder: {
|
|
51
51
|
instructions: "List available models only.", read: refuseTool, list: refuseTool, write: refuseTool,
|
|
52
52
|
} } : {}) });
|
|
53
53
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { closeSync, fstatSync, mkdirSync, mkdtempSync, openSync, readSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { workflowBuilderFolder } from "../isolation/shared-sandbox.js";
|
|
4
|
+
export class PiModelProbeCache {
|
|
5
|
+
catalog;
|
|
6
|
+
generation = 0;
|
|
7
|
+
wrap(backend) {
|
|
8
|
+
return { name: backend.name, create: async (options) => {
|
|
9
|
+
const generation = ++this.generation;
|
|
10
|
+
const root = mkdtempSync(join(workflowBuilderFolder(), 'flow-model-probe-'));
|
|
11
|
+
const stateDir = join(root, 'backend');
|
|
12
|
+
const path = join(stateDir, 'models-store.json');
|
|
13
|
+
let session;
|
|
14
|
+
let fd;
|
|
15
|
+
try {
|
|
16
|
+
mkdirSync(stateDir, { mode: 0o700 });
|
|
17
|
+
fd = openSync(path, 'wx+', 0o600);
|
|
18
|
+
writeFileSync(fd, this.catalog ?? '{}');
|
|
19
|
+
session = await backend.create({ ...options, stateDir });
|
|
20
|
+
const stat = fstatSync(fd);
|
|
21
|
+
if (generation === this.generation && stat.nlink === 1 && stat.size <= 16 * 1024 * 1024) {
|
|
22
|
+
const bytes = Buffer.alloc(stat.size);
|
|
23
|
+
const size = readSync(fd, bytes, 0, bytes.length, 0);
|
|
24
|
+
this.catalog = bytes.subarray(0, size);
|
|
25
|
+
}
|
|
26
|
+
const dispose = session.dispose.bind(session);
|
|
27
|
+
session.dispose = async () => {
|
|
28
|
+
await dispose();
|
|
29
|
+
rmSync(root, { recursive: true, force: true });
|
|
30
|
+
};
|
|
31
|
+
return session;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
await session?.dispose();
|
|
35
|
+
rmSync(root, { recursive: true, force: true });
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (fd !== undefined)
|
|
40
|
+
closeSync(fd);
|
|
41
|
+
}
|
|
42
|
+
} };
|
|
43
|
+
}
|
|
44
|
+
}
|
package/dist/daemon/runtime.js
CHANGED
|
@@ -4,6 +4,9 @@ import { ConfigStore } from "./config-store.js";
|
|
|
4
4
|
import { SecretStore } from "./secret-store.js";
|
|
5
5
|
import { WorkflowStore } from "../workflows/store.js";
|
|
6
6
|
import { WorkflowExecutionService } from "./workflow-executions.js";
|
|
7
|
+
import { WorkflowScheduleStore } from "../workflows/schedule-store.js";
|
|
8
|
+
import { WorkflowScheduleService } from "./workflow-schedules.js";
|
|
9
|
+
import { scheduleDriver } from "./workflow-schedule-driver.js";
|
|
7
10
|
import { WorkflowBuilderService } from "./workflow-builder.js";
|
|
8
11
|
import { workflowCatalogue } from "./workflow-routes.js";
|
|
9
12
|
import { WorkflowMcpAuthoringService } from "./workflow-mcp-authoring.js";
|
|
@@ -52,6 +55,8 @@ export async function startRuntime(options) {
|
|
|
52
55
|
defaultEffort: config.defaultEffort, defaultPermissionMode: config.defaultPermissionMode, autoCompaction: config.autoCompaction, compactionModel: config.compactionModel, summaryModel: config.summaryModel,
|
|
53
56
|
});
|
|
54
57
|
const shells = new ShellRegistry();
|
|
58
|
+
let workflowSchedules;
|
|
59
|
+
let workflowExecutions;
|
|
55
60
|
let workflowBuilders;
|
|
56
61
|
let workflowMcpAuthoring;
|
|
57
62
|
let running;
|
|
@@ -61,6 +66,19 @@ export async function startRuntime(options) {
|
|
|
61
66
|
let stopping;
|
|
62
67
|
const stop = () => stopping ??= (async () => {
|
|
63
68
|
clearInterval(sweep);
|
|
69
|
+
const scheduledErrors = [];
|
|
70
|
+
try {
|
|
71
|
+
await workflowSchedules?.stopAdmission();
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
scheduledErrors.push(error);
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
await workflowExecutions?.stopScheduled();
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
scheduledErrors.push(error);
|
|
81
|
+
}
|
|
64
82
|
const interrupt = async () => { await Promise.all([host.shutdown(), workflowBuilders?.shutdown(), workflowMcpAuthoring?.shutdown(), shells.killAll(), reaping]); };
|
|
65
83
|
if (running)
|
|
66
84
|
await running.stopAdmission(interrupt);
|
|
@@ -78,13 +96,16 @@ export async function startRuntime(options) {
|
|
|
78
96
|
oidc?.dispose();
|
|
79
97
|
}
|
|
80
98
|
ownership.release();
|
|
99
|
+
if (scheduledErrors.length)
|
|
100
|
+
throw new AggregateError(scheduledErrors, 'Scheduled workflow cleanup failed');
|
|
81
101
|
})();
|
|
82
102
|
cleanup = stop;
|
|
83
103
|
registerBackends(host);
|
|
84
104
|
trimTimings(root);
|
|
85
105
|
void host.models(config.projectRoot() ?? process.cwd());
|
|
86
106
|
const workflows = new WorkflowStore(root);
|
|
87
|
-
|
|
107
|
+
store.onSessionDeleted = sessionId => workflows.deleteOwner({ kind: 'session', sessionId });
|
|
108
|
+
workflowExecutions = new WorkflowExecutionService(host, workflows, secrets, config, options.workflowRuntime());
|
|
88
109
|
workflowMcpAuthoring = new WorkflowMcpAuthoringService({ host, config, scope: process.cwd() });
|
|
89
110
|
workflowBuilders = new WorkflowBuilderService({
|
|
90
111
|
host, config, scope: process.cwd(), stateRoot: root,
|
|
@@ -99,9 +120,47 @@ export async function startRuntime(options) {
|
|
|
99
120
|
mcpCatalogue: (scope, projectId, scopeIdentity) => workflowMcpAuthoring.catalogue(projectId, { scope, scopeIdentity }),
|
|
100
121
|
mcpTool: (scope, projectId, scopeIdentity, connectionId, toolName) => workflowMcpAuthoring.tool(projectId, connectionId, toolName, { scope, scopeIdentity }),
|
|
101
122
|
});
|
|
123
|
+
try {
|
|
124
|
+
const schedules = new WorkflowScheduleStore(root);
|
|
125
|
+
workflowSchedules = new WorkflowScheduleService(schedules, scheduleDriver({ host, config, workflows, executions: workflowExecutions, schedules, transcripts: store }));
|
|
126
|
+
workflowExecutions.onScheduledResult = async (record) => { workflowSchedules.result(record); };
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
workflowExecutions.scheduledOwnershipAvailable = false;
|
|
130
|
+
console.error('Workflow Schedule initialization failed. Scheduling is disabled. Other Session Host services will continue.');
|
|
131
|
+
}
|
|
102
132
|
await host.load();
|
|
133
|
+
try {
|
|
134
|
+
await workflowSchedules?.start();
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
console.error('Workflow Schedule reconciliation failed. Other Session Host services will continue.');
|
|
138
|
+
}
|
|
103
139
|
workflowExecutions.reconcile();
|
|
104
|
-
|
|
140
|
+
reaping = reaping.then(async () => {
|
|
141
|
+
try {
|
|
142
|
+
await workflowSchedules?.prune();
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
console.error('Workflow Schedule retention failed. Cleanup will be retried.');
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
sweep = setInterval(() => {
|
|
149
|
+
reaping = reaping.then(async () => {
|
|
150
|
+
try {
|
|
151
|
+
await host.reap();
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
console.error('Agent Session Reaping failed. The next sweep will retry.');
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
await workflowSchedules?.prune();
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
console.error('Workflow Schedule retention failed. The next sweep will retry.');
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}, 60 * 60 * 1000);
|
|
105
164
|
sweep.unref();
|
|
106
165
|
host.onSessionClosed(sessionId => shells.killFor(sessionId));
|
|
107
166
|
const token = readOrCreateToken(root);
|
|
@@ -110,7 +169,7 @@ export async function startRuntime(options) {
|
|
|
110
169
|
instanceId: ownership.instanceId, pid: process.pid, version: options.version, url: '', token, mode: options.mode,
|
|
111
170
|
settings: { port: options.port ?? 0, address: options.address ?? '127.0.0.1', cwd: process.cwd(), oidc: oidcFingerprint() },
|
|
112
171
|
};
|
|
113
|
-
const hasActiveWork = () => host.hasActiveWork() || workflowBuilders.hasActiveWork() || workflowMcpAuthoring.hasActiveWork() || shells.hasLiveShells() || host.list().some(session => workflowExecutions.list(session.id).occupied);
|
|
172
|
+
const hasActiveWork = () => !!workflowSchedules?.hasActiveWork() || host.hasActiveWork() || workflowBuilders.hasActiveWork() || workflowMcpAuthoring.hasActiveWork() || shells.hasLiveShells() || host.list().some(session => workflowExecutions.list(session.id).occupied);
|
|
114
173
|
const updates = new WebUpdateController({
|
|
115
174
|
root,
|
|
116
175
|
installedVersion: options.version,
|
|
@@ -124,6 +183,7 @@ export async function startRuntime(options) {
|
|
|
124
183
|
control: { identity, stop, hasActiveWork },
|
|
125
184
|
updates,
|
|
126
185
|
host, token, shells, config, mcpAuth, store, workflows, secrets, workflowExecutions, workflowBuilders, workflowMcpAuthoring,
|
|
186
|
+
...(workflowSchedules === undefined ? {} : { workflowSchedules }),
|
|
127
187
|
assets: options.assets(), scope: process.cwd(),
|
|
128
188
|
...(oidc === undefined ? {} : { oidc }),
|
|
129
189
|
...(options.port === undefined ? {} : { port: options.port }),
|
package/dist/daemon/server.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createServer } from "node:http";
|
|
|
2
2
|
import { mediaTypeOf } from "../protocol/attachments.js";
|
|
3
3
|
import { ConfigError } from "./config.js";
|
|
4
4
|
import { workflowRoutes } from "./workflow-routes.js";
|
|
5
|
+
import { workflowScheduleRoutes } from "./workflow-schedule-routes.js";
|
|
5
6
|
import { workflowBuilderRoutes } from "./workflow-builder-routes.js";
|
|
6
7
|
import { workflowMcpAuthoringRoutes } from "./workflow-mcp-authoring-routes.js";
|
|
7
8
|
import { hostControlRoute } from "./host-control-routes.js";
|
|
@@ -291,6 +292,8 @@ ${ICON_LINKS}</head><body><script>window.location.replace(${JSON.stringify(locat
|
|
|
291
292
|
}
|
|
292
293
|
if (await workflowMcpAuthoringRoutes(request, response, url.pathname, options.workflowMcpAuthoring))
|
|
293
294
|
return;
|
|
295
|
+
if (await workflowScheduleRoutes(request, response, url, options.workflowSchedules, options.workflowExecutions))
|
|
296
|
+
return;
|
|
294
297
|
if (await workflowBuilderRoutes(request, response, url.pathname, options.workflowBuilders))
|
|
295
298
|
return;
|
|
296
299
|
if (await workflowExecutionRoutes(request, response, url.pathname, options.workflowExecutions, options.workflows))
|
package/dist/daemon/store.js
CHANGED
|
@@ -9,6 +9,7 @@ export function defaultStateRoot() {
|
|
|
9
9
|
}
|
|
10
10
|
export class TranscriptStore {
|
|
11
11
|
root;
|
|
12
|
+
onSessionDeleted;
|
|
12
13
|
constructor(root = defaultStateRoot()) {
|
|
13
14
|
this.root = root;
|
|
14
15
|
}
|
|
@@ -117,6 +118,7 @@ export class TranscriptStore {
|
|
|
117
118
|
*/
|
|
118
119
|
deleteSession(sessionId) {
|
|
119
120
|
rmSync(this.sessionDir(sessionId), { recursive: true, force: true });
|
|
121
|
+
this.onSessionDeleted?.(sessionId);
|
|
120
122
|
}
|
|
121
123
|
async listSessionIds() {
|
|
122
124
|
try {
|