@sema-agent/core 7.11.2 → 7.12.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/CHANGELOG.md +42 -13
- package/dist/core/auto-mode-arming.d.ts +10 -14
- package/dist/core/auto-mode-arming.js +3 -9
- package/dist/core/auto-mode-defaults.d.ts +0 -2
- package/dist/core/auto-mode-defaults.js +0 -1
- package/dist/core/auto-mode-rebuild.d.ts +6 -13
- package/dist/core/auto-mode-rebuild.js +0 -2
- package/dist/core/auto-mode.d.ts +30 -89
- package/dist/core/auto-mode.js +12 -59
- package/dist/core/checkpoint-store.d.ts +1 -3
- package/dist/core/gate-fold.js +1 -9
- package/dist/core/gate-lanes.js +15 -9
- package/dist/core/hooks.d.ts +6 -0
- package/dist/core/runner/contracts.d.ts +41 -9
- package/dist/core/runner/denial-limit-arms.d.ts +10 -13
- package/dist/core/runner/denial-limit-arms.js +9 -7
- package/dist/core/runner/gate-exit.js +9 -1
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +1 -1
- package/dist/core/runner/prepare-caps-and-workflow.js +0 -5
- package/dist/core/runner/prepare-suspend-saga.d.ts +0 -2
- package/dist/core/runner/prepare-suspend-saga.js +2 -10
- package/dist/core/runner/prepare-task.js +1 -1
- package/dist/core/runner/prepare-wiring-manifest.d.ts +1 -1
- package/dist/core/runner/prepare-wiring-manifest.js +1 -8
- package/dist/core/runner/run-attachment-seats.d.ts +4 -2
- package/dist/core/runner/run-attachment-seats.js +2 -2
- package/dist/core/runner/run-identity-wiring.d.ts +14 -33
- package/dist/core/runner/run-identity-wiring.js +4 -3
- package/dist/core/runner/run-leg.d.ts +106 -0
- package/dist/core/runner/run-leg.js +462 -0
- package/dist/core/runner/run-notification-lane.d.ts +55 -0
- package/dist/core/runner/run-notification-lane.js +128 -0
- package/dist/core/runner/run-reasoning-seat.d.ts +5 -5
- package/dist/core/runner/run-reasoning-seat.js +7 -7
- package/dist/core/runner/run-settle-and-teardown.d.ts +109 -0
- package/dist/core/runner/run-settle-and-teardown.js +324 -0
- package/dist/core/runner/run-terminal-adoption.d.ts +99 -0
- package/dist/core/runner/run-terminal-adoption.js +120 -0
- package/dist/core/runner/runtask.d.ts +14 -3
- package/dist/core/runner/runtask.js +55 -1010
- package/dist/core/runner-deps.d.ts +4 -14
- package/dist/core/store-contracts/workflow-journal-store-contract.d.ts +7 -0
- package/dist/core/store-contracts/workflow-journal-store-contract.js +85 -0
- package/dist/core/tool-policy.d.ts +37 -93
- package/dist/core/tool-policy.js +1 -11
- package/dist/core/trace.d.ts +6 -7
- package/dist/core/wiring-manifest.d.ts +5 -22
- package/dist/core/wiring-manifest.js +3 -11
- package/dist/core/workflow-journal-store.d.ts +35 -4
- package/dist/core/workflow-journal-store.js +19 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/orchestration/workflow.js +2 -0
- package/dist/stores/file/workflow-journal-store.d.ts +7 -10
- package/dist/stores/file/workflow-journal-store.js +2 -4
- package/package.json +1 -1
- package/test/export-surface.snapshot.json +10 -10
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type PeerInboundChainRef } from "../../agents/peer-admission.js";
|
|
2
|
+
import type { PushQueue } from "../push-queue.js";
|
|
3
|
+
import type { SessionStore } from "../session.js";
|
|
4
|
+
import { type PendingSessionNotifications, type SystemInjectionPriority, type TaskNotificationPayload } from "../task-notification.js";
|
|
5
|
+
import type { RunnerDeps, TaskEvent, TaskSpec } from "../types.js";
|
|
6
|
+
import type { SessionReadFileStates } from "./prepare-hands-readface.js";
|
|
7
|
+
import type { NotificationLaneBindings, Prepared, PrepareResume, ResumeRun, RunInternals, RunnerDepsSeat, RunnerSelfSeat, TaskIdRef } from "./contracts.js";
|
|
8
|
+
export interface RunNotificationLaneInput<R> {
|
|
9
|
+
/** borrowed-readonly — the task spec: prepare's input, and the principal the peer scope is minted from. */
|
|
10
|
+
spec: TaskSpec;
|
|
11
|
+
/** borrowed-mutable — the run's event queue: the routed `task_notification` frames are pushed here. */
|
|
12
|
+
queue: PushQueue<TaskEvent>;
|
|
13
|
+
/** borrowed-readonly — the resume plan when this leg resumes a checkpoint (prepare's resume seed is derived from it). */
|
|
14
|
+
resume: ResumeRun | undefined;
|
|
15
|
+
/** borrowed-readonly — the trusted run-scoped channel: the detach hub, the uplink, the root / parent anchors, the peer refs, the upstream notification observer. */
|
|
16
|
+
internals: RunInternals | undefined;
|
|
17
|
+
/** borrowed-mutable — the stream layer's backstop carrier, handed to prepare so a prepare THROW still names its run. */
|
|
18
|
+
taskIdRef: TaskIdRef | undefined;
|
|
19
|
+
/** borrowed-readonly — the Runner's deployment deps, read LIVE (`onError` in the park closure — after the run, on a swapped
|
|
20
|
+
* catalog it is still the CURRENT sink; `models` and prepare's `deps` at the natural-snapshot pin); the one home of why it
|
|
21
|
+
* is a seat and not a captured object is {@link RunnerDepsSeat}. */
|
|
22
|
+
runner: RunnerDepsSeat;
|
|
23
|
+
/** borrowed-readonly — the TRUSTED Runner self-reference prepare mounts the `run_workflow` tool over (never a TaskSpec field). */
|
|
24
|
+
self: RunnerSelfSeat;
|
|
25
|
+
/** borrowed-readonly — the session store prepare acquires / creates the leg's session through. */
|
|
26
|
+
sessions: SessionStore;
|
|
27
|
+
/** borrowed-mutable — the Runner's own per-session read-state seat, ALWAYS this Runner's (a caller-supplied one is overridden). */
|
|
28
|
+
sessionReadStates: SessionReadFileStates;
|
|
29
|
+
/** borrowed-mutable — the Runner's per-session parked-notification store: the torn-down lane and the escalation pend here. */
|
|
30
|
+
pendingSessionNotifications: PendingSessionNotifications;
|
|
31
|
+
/** borrowed-readonly — the orchestrator's entry (a lane may not name the orchestrator; the driver hands it in). */
|
|
32
|
+
prepareTask: (spec: TaskSpec, deps: RunnerDeps, sessions: SessionStore, resume: PrepareResume | undefined, internals: RunInternals, runnerSelf: RunnerSelfSeat, taskIdRef: TaskIdRef | undefined) => Promise<Prepared>;
|
|
33
|
+
/** borrowed-readonly — the lanes after this one, entered in this lane's last continuation with what it prepared and bound. */
|
|
34
|
+
next: (lane: RunNotificationLaneResult) => Promise<R>;
|
|
35
|
+
}
|
|
36
|
+
/** What the lane prepared and bound — the seats every lane after it reads. */
|
|
37
|
+
export interface RunNotificationLaneResult {
|
|
38
|
+
/** The leg's prepared seat. */
|
|
39
|
+
prepared: Prepared;
|
|
40
|
+
/** The ONE injection entry every notification producer rides (the identity lane binds the notify() bridge to it). */
|
|
41
|
+
injectTaskNotification: (notification: TaskNotificationPayload, opts?: {
|
|
42
|
+
priority?: SystemInjectionPriority;
|
|
43
|
+
}) => Promise<"queued" | "parked" | "dropped_duplicate">;
|
|
44
|
+
/** The turn-open dedup set (the cross-layer double-park dedup): the identity lane registers a redelivered frame's key here. */
|
|
45
|
+
deliveredAtTurnOpen: Set<string>;
|
|
46
|
+
/** design/176: the peer inbound chain ref this run carries (the spawn chain's, or a fresh one). */
|
|
47
|
+
peerInboundChainRef: PeerInboundChainRef;
|
|
48
|
+
/** The model catalog pinned BEFORE prepare (the natural-snapshot closure for swapDeps): the budget seats resolve against it. */
|
|
49
|
+
modelCatalog: RunnerDeps["models"];
|
|
50
|
+
/** The lane's bindings as one seat over its own variables — see {@link NotificationLaneBindings}. */
|
|
51
|
+
notificationLane: NotificationLaneBindings;
|
|
52
|
+
/** The queue subscription's release; the leg lane's finally calls it right after flipping `live`. */
|
|
53
|
+
unsubscribeTaskNotifications: () => void;
|
|
54
|
+
}
|
|
55
|
+
export declare function runNotificationLane<R>(input: RunNotificationLaneInput<R>): Promise<R>;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createPeerInboundChainRef, createPeerSelfRef } from "../../agents/peer-admission.js";
|
|
2
|
+
import { boundInputHashOf } from "../canonical-json.js";
|
|
3
|
+
import { isDelegatedAgentTerminal, isTerminalTaskNotification, renderTaskNotificationXml, SystemInjectionQueue, taskNotificationDedupKey } from "../task-notification.js";
|
|
4
|
+
import { ToolDetachHub } from "../tool-detach.js";
|
|
5
|
+
import { pendingContentAskCallId } from "./decide-continuation.js";
|
|
6
|
+
export async function runNotificationLane(input) {
|
|
7
|
+
const { spec, queue, resume, internals, taskIdRef, runner, self, sessions, sessionReadStates, pendingSessionNotifications, prepareTask, next } = input;
|
|
8
|
+
const prepareResume = resume
|
|
9
|
+
? {
|
|
10
|
+
leafId: resume.cp.leafId,
|
|
11
|
+
suspendedBatch: new Set(resume.cp.pendingAction.kind === "tool_approval" ? resume.cp.pendingAction.batchToolCallIds : []),
|
|
12
|
+
seed: resume.cp.state,
|
|
13
|
+
priorSuspendCount: resume.cp.suspendCount,
|
|
14
|
+
priorLedger: resume.cp.resourceLedger,
|
|
15
|
+
priorHumanReview: resume.cp.humanReview,
|
|
16
|
+
workspaceHandle: resume.cp.state.workspaceHandle,
|
|
17
|
+
executesApprovedAction: resume.cp.pendingAction.kind === "tool_approval" &&
|
|
18
|
+
resume.outcome.gate !== "wake" &&
|
|
19
|
+
resume.outcome.decision === "allow",
|
|
20
|
+
...(resume.outcome.gate !== "wake" && resume.outcome.decision === "allow" && pendingContentAskCallId(resume.cp) !== undefined
|
|
21
|
+
? {
|
|
22
|
+
redeemedContentAskCallId: pendingContentAskCallId(resume.cp),
|
|
23
|
+
redeemedContentAskQuestionsHash: boundInputHashOf(resume.cp.pendingAction.args?.questions),
|
|
24
|
+
}
|
|
25
|
+
: {}),
|
|
26
|
+
}
|
|
27
|
+
: undefined;
|
|
28
|
+
const taskNotificationQueue = new SystemInjectionQueue();
|
|
29
|
+
const detachHub = internals?.detachHub ?? new ToolDetachHub();
|
|
30
|
+
let notificationHarness;
|
|
31
|
+
let notificationIdent = () => ({});
|
|
32
|
+
let notificationLaneLive = true;
|
|
33
|
+
let notificationSessionId;
|
|
34
|
+
let descendantAnchorDisclosed = false;
|
|
35
|
+
const parkTaskNotification = (payload, priority) => {
|
|
36
|
+
if (notificationSessionId !== undefined)
|
|
37
|
+
pendingSessionNotifications.pend(notificationSessionId, payload, priority);
|
|
38
|
+
if (!isDelegatedAgentTerminal(payload))
|
|
39
|
+
return;
|
|
40
|
+
const uplink = internals?.parentNotify;
|
|
41
|
+
if (uplink !== undefined) {
|
|
42
|
+
try {
|
|
43
|
+
uplink(payload, { priority });
|
|
44
|
+
}
|
|
45
|
+
catch (e) {
|
|
46
|
+
runner.deps.onError?.(e, { phase: "degraded", sessionId: notificationSessionId ?? "", classification: "descendant-terminal-uplink" });
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const rootAnchor = internals?.rootSessionId;
|
|
51
|
+
if (rootAnchor !== undefined && rootAnchor !== notificationSessionId) {
|
|
52
|
+
pendingSessionNotifications.pend(rootAnchor, payload, priority);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (internals?.parentSessionId !== undefined && !descendantAnchorDisclosed) {
|
|
56
|
+
descendantAnchorDisclosed = true;
|
|
57
|
+
runner.deps.onError?.(new Error(`background-agent terminal ${payload.task_id} parked on this run's own session — the delegation tree's root session is not reachable from this run (no uplink, no root anchor)`), { phase: "degraded", sessionId: notificationSessionId ?? "", classification: "descendant-terminal-unrouted" });
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const unsubscribeTaskNotifications = taskNotificationQueue.subscribe((item) => {
|
|
61
|
+
queue.push({ type: "task_notification", notification: item.payload, priority: item.priority, ...notificationIdent() });
|
|
62
|
+
if (notificationHarness && prepared.batchHaltRef.current === undefined) {
|
|
63
|
+
const xml = renderTaskNotificationXml(item.payload);
|
|
64
|
+
const noteOptions = {
|
|
65
|
+
provenance: "engine-note",
|
|
66
|
+
enginePayload: item.payload,
|
|
67
|
+
...(item.payload.task_type !== "external" && isTerminalTaskNotification(item.payload) ? { capPreferred: true } : {}),
|
|
68
|
+
};
|
|
69
|
+
const deliver = item.priority === "later"
|
|
70
|
+
? notificationHarness.followUp(xml, noteOptions)
|
|
71
|
+
: notificationHarness.steer(xml, { ...noteOptions, ...(item.priority === "now" ? { immediate: true } : {}) });
|
|
72
|
+
void deliver.then(() => item.onDisposition?.("queued"), () => {
|
|
73
|
+
parkTaskNotification(item.payload, item.priority);
|
|
74
|
+
item.onDisposition?.("parked");
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
parkTaskNotification(item.payload, item.priority);
|
|
79
|
+
item.onDisposition?.("parked");
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const upstreamTaskNotification = internals?.onTaskNotification;
|
|
83
|
+
const deliveredAtTurnOpen = new Set();
|
|
84
|
+
const injectTaskNotification = (notification, opts) => {
|
|
85
|
+
if (deliveredAtTurnOpen.has(taskNotificationDedupKey(notification)))
|
|
86
|
+
return Promise.resolve("dropped_duplicate");
|
|
87
|
+
if (!notificationLaneLive) {
|
|
88
|
+
parkTaskNotification(notification, opts?.priority ?? "later");
|
|
89
|
+
return Promise.resolve("parked");
|
|
90
|
+
}
|
|
91
|
+
return new Promise((resolve) => {
|
|
92
|
+
const accepted = taskNotificationQueue.enqueue({
|
|
93
|
+
kind: "task_notification",
|
|
94
|
+
priority: opts?.priority ?? "later",
|
|
95
|
+
dedupKey: taskNotificationDedupKey(notification),
|
|
96
|
+
payload: notification,
|
|
97
|
+
onDisposition: resolve,
|
|
98
|
+
});
|
|
99
|
+
if (!accepted)
|
|
100
|
+
resolve("queued");
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
const peerSelfRef = internals?.peerSelfRef ?? createPeerSelfRef(internals?.registryScope ?? spec.principal ?? "default");
|
|
104
|
+
const peerInboundChainRef = internals?.peerInboundChainRef ?? createPeerInboundChainRef();
|
|
105
|
+
const modelCatalog = runner.deps.models;
|
|
106
|
+
const prepared = await prepareTask(spec, runner.deps, sessions, prepareResume, {
|
|
107
|
+
...(internals ?? {}),
|
|
108
|
+
peerSelfRef,
|
|
109
|
+
peerInboundChainRef,
|
|
110
|
+
detachHub,
|
|
111
|
+
sessionReadStates,
|
|
112
|
+
onTaskNotification: (notification, opts) => {
|
|
113
|
+
try {
|
|
114
|
+
upstreamTaskNotification?.(notification, opts);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
}
|
|
118
|
+
injectTaskNotification(notification, opts);
|
|
119
|
+
},
|
|
120
|
+
}, self, taskIdRef);
|
|
121
|
+
const notificationLane = {
|
|
122
|
+
get harness() { return notificationHarness; }, set harness(h) { notificationHarness = h; },
|
|
123
|
+
get sessionId() { return notificationSessionId; }, set sessionId(s) { notificationSessionId = s; },
|
|
124
|
+
get ident() { return notificationIdent; }, set ident(f) { notificationIdent = f; },
|
|
125
|
+
get live() { return notificationLaneLive; }, set live(v) { notificationLaneLive = v; },
|
|
126
|
+
};
|
|
127
|
+
return await next({ prepared, injectTaskNotification, deliveredAtTurnOpen, peerInboundChainRef, modelCatalog, notificationLane, unsubscribeTaskNotifications });
|
|
128
|
+
}
|
|
@@ -14,14 +14,14 @@ export interface RunReasoningSeatInput {
|
|
|
14
14
|
rs: RunState;
|
|
15
15
|
/** borrowed-mutable — the stream layer's backstop carrier: `effectiveReasoning` is published here at every mint. */
|
|
16
16
|
taskIdRef: TaskIdRef | undefined;
|
|
17
|
-
/** borrowed-mutable — the driver's resolution cell (the `let` the result assembly reads): the leg-entry mint and
|
|
18
|
-
* the first-committed-request correction are written here, and the dedupe reads it back. */
|
|
19
|
-
reasoningResolution: {
|
|
20
|
-
current: ResolvedReasoning | undefined;
|
|
21
|
-
};
|
|
22
17
|
}
|
|
23
18
|
export interface RunReasoningSeatResult {
|
|
24
19
|
/** The CONSUMPTION half of {@link ReasoningWireFacts} — installed as the third brain ALS sink. */
|
|
25
20
|
observeReasoningWireFacts: (facts: ReasoningWireFacts) => void;
|
|
21
|
+
/** #327 — the leg's resolution as a READ FACE over this lane's own `let` (the leg-entry mint, then at most one
|
|
22
|
+
* first-committed-request correction): the settle lane's result assembly reads it for `effectiveReasoning`. */
|
|
23
|
+
reasoningResolution: {
|
|
24
|
+
readonly current: ResolvedReasoning | undefined;
|
|
25
|
+
};
|
|
26
26
|
}
|
|
27
27
|
export declare function runReasoningSeat(input: RunReasoningSeatInput): RunReasoningSeatResult;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { resolveReasoning } from "../../brain/reasoning.js";
|
|
2
2
|
import { emitTrace } from "../trace.js";
|
|
3
3
|
export function runReasoningSeat(input) {
|
|
4
|
-
const { prepared, rs, taskIdRef
|
|
5
|
-
reasoningResolution
|
|
4
|
+
const { prepared, rs, taskIdRef } = input;
|
|
5
|
+
let reasoningResolution = prepared.thinking && prepared.thinking !== "off" ? resolveReasoning(prepared.thinking, prepared.model) : undefined;
|
|
6
6
|
const publishReasoningResolution = (r) => {
|
|
7
|
-
reasoningResolution
|
|
7
|
+
reasoningResolution = r;
|
|
8
8
|
if (taskIdRef)
|
|
9
9
|
taskIdRef.effectiveReasoning = r;
|
|
10
10
|
emitTrace(rs.telemetry.tracer, () => ({
|
|
@@ -22,8 +22,8 @@ export function runReasoningSeat(input) {
|
|
|
22
22
|
ts: Date.now(),
|
|
23
23
|
}));
|
|
24
24
|
};
|
|
25
|
-
if (reasoningResolution
|
|
26
|
-
publishReasoningResolution(reasoningResolution
|
|
25
|
+
if (reasoningResolution !== undefined)
|
|
26
|
+
publishReasoningResolution(reasoningResolution);
|
|
27
27
|
let reasoningFactsConsumed = false;
|
|
28
28
|
const observeReasoningWireFacts = (facts) => {
|
|
29
29
|
if (reasoningFactsConsumed)
|
|
@@ -32,7 +32,7 @@ export function runReasoningSeat(input) {
|
|
|
32
32
|
if (prepared.thinking === undefined || prepared.thinking === "off")
|
|
33
33
|
return;
|
|
34
34
|
const next = resolveReasoning(prepared.thinking, prepared.model, facts);
|
|
35
|
-
const current = reasoningResolution
|
|
35
|
+
const current = reasoningResolution;
|
|
36
36
|
if (current !== undefined &&
|
|
37
37
|
current.effective === next.effective &&
|
|
38
38
|
current.graded === next.graded &&
|
|
@@ -44,5 +44,5 @@ export function runReasoningSeat(input) {
|
|
|
44
44
|
}
|
|
45
45
|
publishReasoningResolution(next);
|
|
46
46
|
};
|
|
47
|
-
return { observeReasoningWireFacts };
|
|
47
|
+
return { observeReasoningWireFacts, reasoningResolution: { get current() { return reasoningResolution; } } };
|
|
48
48
|
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* design/393 S6 — the run body's SETTLE AND TEARDOWN (R15), verbatim from `Runner.runLocked`: the end-of-task
|
|
3
|
+
* compaction's frames and detector reset, the nested-stats fold, the prefix-cache observability and its loud
|
|
4
|
+
* mismatch / low-hit disclosures, the cross-slice cumulative spend fold, the human-review and mechanism counters,
|
|
5
|
+
* the result assembly (`assembleResult` — the one place the leg's facts become a TaskResult), the resume leg's
|
|
6
|
+
* unstarted-action reopen compensation, the read-state seal and the settle-time workspace-state write, the
|
|
7
|
+
* StopFailure observer, the delegation-lifecycle terminal, the reap-stash for a committed pause, the resumed-terminal
|
|
8
|
+
* unpin, the memory harvest, the `task.end` trace, `setResult`, the sub-agent's terminal tick, the mooted manual
|
|
9
|
+
* compaction, the forwarded-frame drain and the queue's `done` + close, the file-history boundary settle and the
|
|
10
|
+
* prompt-suggestion kickoff — then, in its finally, the four teardown legs in the order they were: the shell-lane
|
|
11
|
+
* children settle, the background-shell sweep, the registry clears / the background-agent abort / the retained
|
|
12
|
+
* child sessions, and the owned env's teardown.
|
|
13
|
+
*
|
|
14
|
+
* Async (eleven first-level awaits, all of them the same awaits at the same positions). The `queue.push("done")` and
|
|
15
|
+
* the teardown legs' order are contract (the forwarded-frame drain lands before `done`; the env is torn down after
|
|
16
|
+
* every reader of it); nothing here reorders them. Products: the result is PUBLISHED through `setResult` and the
|
|
17
|
+
* effects are installed on the borrowed seats — nothing comes back to the driver (the same empty Result the seat
|
|
18
|
+
* lanes whose products are all installations carry).
|
|
19
|
+
*/
|
|
20
|
+
import type { AssistantMessage } from "../../internal/llm.js";
|
|
21
|
+
import type { ResolvedReasoning } from "../../brain/reasoning.js";
|
|
22
|
+
import type { PushQueue } from "../push-queue.js";
|
|
23
|
+
import type { SessionStore } from "../session.js";
|
|
24
|
+
import type { CompactOutcome, DelegationLifecycleEvent, TaskEvent, TaskResult, TaskSpec } from "../types.js";
|
|
25
|
+
import { type Stats } from "./assemble-result.js";
|
|
26
|
+
import type { EndOfTaskCompaction, ManualCompactRef, Prepared, ResumeRun, RunInternals, RunnerDepsSeat, RunState, SuspendReap, TaskIdRef } from "./contracts.js";
|
|
27
|
+
export interface RunSettleAndTeardownInput {
|
|
28
|
+
/** borrowed-readonly — the task spec: the hooks slot, the suggestion opt-in, the retain / forward flags, the task id and principal. */
|
|
29
|
+
spec: TaskSpec;
|
|
30
|
+
/** borrowed-mutable — the run's event queue: the compaction / human-input / task_progress / done frames, then CLOSED here. */
|
|
31
|
+
queue: PushQueue<TaskEvent>;
|
|
32
|
+
/** borrowed-mutable — the leg's prepared seat: the settle-time seal and workspace write, the refs the result assembly reads, the env the teardown reaps. */
|
|
33
|
+
prepared: Prepared;
|
|
34
|
+
/** borrowed-readonly — the resume plan when this leg resumed a checkpoint (the reopen compensation and the unpin read it). */
|
|
35
|
+
resume: ResumeRun | undefined;
|
|
36
|
+
/** borrowed-readonly — the trusted run-scoped channel: the delegation task type, cycle seq, parent task id and the display-sink forward. */
|
|
37
|
+
internals: RunInternals | undefined;
|
|
38
|
+
/** borrowed-readonly — the run's mutable state, read for the telemetry / degrade / limits / counters the result and the frames report. */
|
|
39
|
+
rs: RunState;
|
|
40
|
+
/** borrowed-mutable — this leg's usage counters: the nested / cumulative folds, the cache-hit rate, the mechanism counters are written here. */
|
|
41
|
+
stats: Stats;
|
|
42
|
+
/** borrowed-readonly — the run's event-identity mint. */
|
|
43
|
+
ident: () => {
|
|
44
|
+
eventId: string;
|
|
45
|
+
parentToolCallId?: string;
|
|
46
|
+
sourceTaskId?: string;
|
|
47
|
+
};
|
|
48
|
+
/** borrowed-readonly — the spawning tool call's id when this task runs AS A SUB-AGENT (gates the terminal tick). */
|
|
49
|
+
parentToolCallId: string | undefined;
|
|
50
|
+
/** borrowed-readonly — the sub-agent display name for the terminal tick. */
|
|
51
|
+
subagentName: string | undefined;
|
|
52
|
+
/** borrowed-readonly — the loop-liveness latch: `userHalted` signs the result's halt seat. */
|
|
53
|
+
loopLatch: {
|
|
54
|
+
readonly userHalted: boolean;
|
|
55
|
+
};
|
|
56
|
+
/** borrowed-readonly — the hard walltime timer: `fired` and `latenessMs` ride the result and the `task.end` frame. */
|
|
57
|
+
timeout: {
|
|
58
|
+
readonly fired: boolean;
|
|
59
|
+
readonly latenessMs?: number;
|
|
60
|
+
};
|
|
61
|
+
/** borrowed-readonly — the run's own committed tail (the read-state seal). */
|
|
62
|
+
ownCommittedTailRef: {
|
|
63
|
+
readonly current: string | undefined;
|
|
64
|
+
};
|
|
65
|
+
/** borrowed-readonly — the delegation-lifecycle emission closure (the terminal station is here). */
|
|
66
|
+
emitDelegationLifecycle: (event: DelegationLifecycleEvent) => void;
|
|
67
|
+
/** borrowed-mutable — the stream layer's backstop carrier: the owed delegation terminal is cleared here. */
|
|
68
|
+
taskIdRef: TaskIdRef | undefined;
|
|
69
|
+
/** borrowed-mutable — the manual /compact seat: the parked waiters are mooted and the channel closed before `done`. */
|
|
70
|
+
manualCompactRef: ManualCompactRef;
|
|
71
|
+
/** borrowed-readonly — the boundary lane's drain of the manual-compact waiters (with the outcome every waiter receives). */
|
|
72
|
+
drainManualCompact: (outcome: CompactOutcome) => void;
|
|
73
|
+
/** borrowed-readonly — the leg lane's final assistant message (undefined on every no-prompt arm). */
|
|
74
|
+
final: AssistantMessage | undefined;
|
|
75
|
+
/** borrowed-readonly — the adopted terminal cause (the leg's throw, or what the terminal-adoption lane lifted over it). */
|
|
76
|
+
threw: unknown;
|
|
77
|
+
/** borrowed-readonly — the live-abort flag captured before the leg's release-abort. */
|
|
78
|
+
abortedLive: boolean;
|
|
79
|
+
/** borrowed-readonly — design/174: the answered-but-never-collected deliveries the leg's finally settled. */
|
|
80
|
+
strandedHumanAnswers: ReadonlyArray<{
|
|
81
|
+
deliveryId: string;
|
|
82
|
+
toolCallId: string;
|
|
83
|
+
}>;
|
|
84
|
+
/** borrowed-readonly — the reasoning seat's resolution, as the read face on its Result (the result's `effectiveReasoning`). */
|
|
85
|
+
reasoningResolution: {
|
|
86
|
+
readonly current: ResolvedReasoning | undefined;
|
|
87
|
+
};
|
|
88
|
+
/** borrowed-readonly — the end-of-task compaction's outcome (the terminal-adoption lane's `finish` call). */
|
|
89
|
+
comp: EndOfTaskCompaction;
|
|
90
|
+
/** borrowed-readonly — the stream's result setter: the assembled TaskResult is published through it exactly once. */
|
|
91
|
+
setResult: (r: TaskResult) => void;
|
|
92
|
+
/** borrowed-readonly — the stream's suggestions seat: the fire-and-forget suggestion pass's promise is handed to it. */
|
|
93
|
+
onSuggestions: (p: Promise<string[]>) => void;
|
|
94
|
+
/** borrowed-readonly — the stream's reap-stash for a committed pause (what `destroy()` reaps when the run SUSPENDED). */
|
|
95
|
+
onSuspend: (reap: SuspendReap) => void;
|
|
96
|
+
/** borrowed-readonly — the Runner's deployment deps, read LIVE (`onError`, `hooks`, `checkpointStore`, `executionEnv`, `onNotice`);
|
|
97
|
+
* the one home of why it is a seat and not a captured object is {@link RunnerDepsSeat}. */
|
|
98
|
+
runner: RunnerDepsSeat;
|
|
99
|
+
/** borrowed-readonly — the session store: the resumed-terminal leg unpins the checkpoint's session through it. */
|
|
100
|
+
sessions: SessionStore;
|
|
101
|
+
/** borrowed-readonly — the Runner's post-completion prompt-suggestion pass (its private method, as a delegate). */
|
|
102
|
+
suggestNextPrompts: (spec: TaskSpec, prepared: Prepared, result: TaskResult) => Promise<string[]>;
|
|
103
|
+
/** borrowed-readonly — the Runner's owned-env teardown (its private method, as a delegate; its gate mirrors the reap-stash's). */
|
|
104
|
+
teardownOwnedEnv: (prepared: Prepared) => Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
/** Nothing comes back: the result is published through `setResult`, the queue is closed, the teardown legs ran. */
|
|
107
|
+
export interface RunSettleAndTeardownResult {
|
|
108
|
+
}
|
|
109
|
+
export declare function runSettleAndTeardown(input: RunSettleAndTeardownInput): Promise<RunSettleAndTeardownResult>;
|