@deepstrike/sdk 0.2.49 → 0.2.51
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 +83 -60
- package/dist/harness/manifest.d.ts +1 -1
- package/dist/harness/manifest.js +43 -29
- package/dist/index.d.ts +5 -7
- package/dist/index.js +3 -3
- package/dist/kernel.d.ts +61 -31
- package/dist/runtime/canonical-kernel-step.d.ts +143 -0
- package/dist/runtime/canonical-kernel-step.js +1444 -0
- package/dist/runtime/execution-plane.d.ts +0 -3
- package/dist/runtime/execution-plane.js +0 -24
- package/dist/runtime/facade.js +3 -0
- package/dist/runtime/kernel-event-log.js +7 -13
- package/dist/runtime/kernel-journal.d.ts +264 -0
- package/dist/runtime/kernel-journal.js +741 -0
- package/dist/runtime/kernel-primitives-dashboard.d.ts +0 -2
- package/dist/runtime/kernel-primitives-dashboard.js +1 -8
- package/dist/runtime/kernel-step.d.ts +29 -109
- package/dist/runtime/kernel-step.js +47 -317
- package/dist/runtime/os-snapshot.d.ts +2 -2
- package/dist/runtime/os-snapshot.js +2 -6
- package/dist/runtime/payload-store.d.ts +16 -0
- package/dist/runtime/payload-store.js +80 -0
- package/dist/runtime/runner.d.ts +80 -119
- package/dist/runtime/runner.js +706 -779
- package/dist/runtime/session-log.d.ts +34 -32
- package/dist/runtime/session-log.js +21 -131
- package/dist/runtime/session-repair.d.ts +2 -36
- package/dist/runtime/session-repair.js +2 -47
- package/dist/runtime/sub-agent-orchestrator.d.ts +1 -1
- package/dist/runtime/sub-agent-orchestrator.js +42 -40
- package/dist/types/agent.d.ts +31 -19
- package/dist/types/agent.js +31 -42
- package/dist/workflow/public.d.ts +1 -1
- package/dist/workflow/public.js +1 -1
- package/package.json +2 -2
- package/dist/runtime/kernel-rebuild.d.ts +0 -13
- package/dist/runtime/kernel-rebuild.js +0 -75
- package/dist/runtime/kernel-transaction-log.d.ts +0 -61
- package/dist/runtime/kernel-transaction-log.js +0 -149
- package/dist/runtime/large-result-spool.d.ts +0 -93
- package/dist/runtime/large-result-spool.js +0 -214
|
@@ -2,7 +2,6 @@ const KERNEL_KINDS = new Set([
|
|
|
2
2
|
"compressed",
|
|
3
3
|
"page_out",
|
|
4
4
|
"page_in",
|
|
5
|
-
"large_result_spooled",
|
|
6
5
|
"capability_changed",
|
|
7
6
|
"context_renewed",
|
|
8
7
|
"suspended",
|
|
@@ -30,7 +29,6 @@ export function rebuildOsSnapshotFromSessionEvents(events) {
|
|
|
30
29
|
signals: [],
|
|
31
30
|
pageOutCount: 0,
|
|
32
31
|
pageInCount: 0,
|
|
33
|
-
spoolCount: 0,
|
|
34
32
|
toolGatedCount: 0,
|
|
35
33
|
memoryWrittenCount: 0,
|
|
36
34
|
memoryQueriedCount: 0,
|
|
@@ -64,7 +62,8 @@ export function rebuildOsSnapshotFromSessionEvents(events) {
|
|
|
64
62
|
const record = {
|
|
65
63
|
turn: event.turn,
|
|
66
64
|
agent_id: event.agent_id,
|
|
67
|
-
|
|
65
|
+
...(event.parent_task_id ? { parent_task_id: event.parent_task_id } : {}),
|
|
66
|
+
...(event.parent_session_id ? { parent_session_id: event.parent_session_id } : {}),
|
|
68
67
|
state: event.state ?? "running",
|
|
69
68
|
};
|
|
70
69
|
const idx = index.get(event.agent_id);
|
|
@@ -119,9 +118,6 @@ export function rebuildOsSnapshotFromSessionEvents(events) {
|
|
|
119
118
|
case "page_in":
|
|
120
119
|
snap.pageInCount += 1;
|
|
121
120
|
break;
|
|
122
|
-
case "large_result_spooled":
|
|
123
|
-
snap.spoolCount += 1;
|
|
124
|
-
break;
|
|
125
121
|
case "memory_written":
|
|
126
122
|
snap.memoryWrittenCount += 1;
|
|
127
123
|
break;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface PayloadStoreConfig {
|
|
2
|
+
storageDir?: string;
|
|
3
|
+
maxAgeMs?: number;
|
|
4
|
+
}
|
|
5
|
+
/** File-backed storage for canonical opaque payload locators. */
|
|
6
|
+
export declare class PayloadStore {
|
|
7
|
+
private readonly storageDir;
|
|
8
|
+
private readonly maxAgeMs?;
|
|
9
|
+
private readonly activeWrites;
|
|
10
|
+
constructor(config?: PayloadStoreConfig);
|
|
11
|
+
private payloadPath;
|
|
12
|
+
persistPayload(sessionId: string, payloadRef: string, content: string): Promise<void>;
|
|
13
|
+
loadPayload(sessionId: string, payloadRef: string): Promise<string | undefined>;
|
|
14
|
+
cleanup(maxAgeMs?: number): Promise<number>;
|
|
15
|
+
private atomicWrite;
|
|
16
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import * as crypto from "node:crypto";
|
|
2
|
+
import * as fs from "node:fs/promises";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
/** File-backed storage for canonical opaque payload locators. */
|
|
5
|
+
export class PayloadStore {
|
|
6
|
+
storageDir;
|
|
7
|
+
maxAgeMs;
|
|
8
|
+
activeWrites = new Map();
|
|
9
|
+
constructor(config = {}) {
|
|
10
|
+
this.storageDir = config.storageDir ?? ".payloads";
|
|
11
|
+
this.maxAgeMs = config.maxAgeMs;
|
|
12
|
+
}
|
|
13
|
+
payloadPath(sessionId, payloadRef) {
|
|
14
|
+
const key = crypto
|
|
15
|
+
.createHash("sha256")
|
|
16
|
+
.update(`${sessionId}\u0000${payloadRef}`)
|
|
17
|
+
.digest("hex");
|
|
18
|
+
return path.join(this.storageDir, `${key}.payload`);
|
|
19
|
+
}
|
|
20
|
+
async persistPayload(sessionId, payloadRef, content) {
|
|
21
|
+
const target = this.payloadPath(sessionId, payloadRef);
|
|
22
|
+
let write = this.activeWrites.get(target);
|
|
23
|
+
if (!write) {
|
|
24
|
+
write = this.atomicWrite(target, content).finally(() => {
|
|
25
|
+
this.activeWrites.delete(target);
|
|
26
|
+
});
|
|
27
|
+
this.activeWrites.set(target, write);
|
|
28
|
+
}
|
|
29
|
+
await write;
|
|
30
|
+
}
|
|
31
|
+
async loadPayload(sessionId, payloadRef) {
|
|
32
|
+
try {
|
|
33
|
+
return await fs.readFile(this.payloadPath(sessionId, payloadRef), "utf8");
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.code === "ENOENT")
|
|
37
|
+
return undefined;
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async cleanup(maxAgeMs = this.maxAgeMs ?? 7 * 24 * 60 * 60 * 1000) {
|
|
42
|
+
let files;
|
|
43
|
+
try {
|
|
44
|
+
files = await fs.readdir(this.storageDir);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error.code === "ENOENT")
|
|
48
|
+
return 0;
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
const now = Date.now();
|
|
52
|
+
let removed = 0;
|
|
53
|
+
for (const file of files) {
|
|
54
|
+
const target = path.join(this.storageDir, file);
|
|
55
|
+
const stat = await fs.stat(target);
|
|
56
|
+
if (now - stat.mtimeMs > maxAgeMs) {
|
|
57
|
+
await fs.unlink(target);
|
|
58
|
+
removed += 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return removed;
|
|
62
|
+
}
|
|
63
|
+
async atomicWrite(target, content) {
|
|
64
|
+
await fs.mkdir(this.storageDir, { recursive: true });
|
|
65
|
+
const temporary = `${target}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
66
|
+
let handle;
|
|
67
|
+
try {
|
|
68
|
+
handle = await fs.open(temporary, "wx");
|
|
69
|
+
await handle.writeFile(content, "utf8");
|
|
70
|
+
await handle.sync();
|
|
71
|
+
await handle.close();
|
|
72
|
+
handle = undefined;
|
|
73
|
+
await fs.rename(temporary, target);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await handle?.close().catch(() => undefined);
|
|
77
|
+
await fs.unlink(temporary).catch(() => undefined);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
package/dist/runtime/runner.d.ts
CHANGED
|
@@ -3,17 +3,17 @@ import type { DreamStore, MemoryRecord, MemoryRecall, MemoryScope, MemoryQuery }
|
|
|
3
3
|
import type { KnowledgeSource } from "../knowledge/source.js";
|
|
4
4
|
import type { RuntimeSignalUrgency, SignalSource } from "../signals/types.js";
|
|
5
5
|
import type { SessionLog, SessionEvent } from "./session-log.js";
|
|
6
|
+
import type { KernelJournal } from "./kernel-journal.js";
|
|
6
7
|
import type { ArchiveStore } from "./archive.js";
|
|
7
8
|
import type { ExecutionPlane } from "./execution-plane.js";
|
|
8
9
|
import type { RunGroup } from "./run-group.js";
|
|
9
10
|
import { type MemoryPolicy, type ResourceQuota } from "../kernel.js";
|
|
10
|
-
import { type RecoveredNodeOutcome } from "./session-repair.js";
|
|
11
11
|
import type { AgentRunSpec, MilestoneCheckResult, MilestoneContract, MilestonePolicy, WorkflowSpec, WorkflowOutcome } from "../types/agent.js";
|
|
12
12
|
import { type SubAgentOrchestrator } from "./sub-agent-orchestrator.js";
|
|
13
13
|
import { type ReducerRegistry } from "./reducers.js";
|
|
14
14
|
import { type GovernancePolicy } from "../governance.js";
|
|
15
15
|
import { type NativeOsProfile, type OsProfileId, type SignalPolicy } from "./os-profile.js";
|
|
16
|
-
import {
|
|
16
|
+
import { PayloadStore } from "./payload-store.js";
|
|
17
17
|
import type { BackgroundTaskErrorHandler } from "./reliability.js";
|
|
18
18
|
import { type ContextPolicyOverridesV1 } from "./context-policy.js";
|
|
19
19
|
import { type InstructionProfile } from "../harness/manifest.js";
|
|
@@ -80,26 +80,12 @@ export interface ToolResultHookDecision {
|
|
|
80
80
|
}
|
|
81
81
|
/** Bounded kernel reliability policy. Omitted fields retain kernel defaults. */
|
|
82
82
|
export interface KernelReliabilityOptions {
|
|
83
|
-
/** Deduplicated input-event replay window, 1..65536. */
|
|
84
|
-
eventReplayCapacity?: number;
|
|
85
|
-
/** Completed effect-result replay window, 1..65536. */
|
|
86
|
-
completedEffectReplayCapacity?: number;
|
|
87
83
|
/** Provider overflow recovery retries, 0..16. */
|
|
88
84
|
providerRecoveryAttempts?: number;
|
|
89
85
|
/** Truncated-output recovery retries, 0..16. */
|
|
90
86
|
outputRecoveryAttempts?: number;
|
|
91
|
-
/** Host durability-effect retries, 0..16. */
|
|
92
|
-
hostEffectRetryAttempts?: number;
|
|
93
|
-
/** Tool-result spool threshold in bytes; must be positive. */
|
|
94
|
-
spoolThresholdBytes?: number;
|
|
95
|
-
/** Inline spool preview bytes; positive and no larger than the threshold. */
|
|
96
|
-
spoolPreviewBytes?: number;
|
|
97
|
-
/** Max accepted ABI transactions retained for a portable KernelSnapshot rebuild. */
|
|
98
|
-
snapshotInputLimit?: number;
|
|
99
87
|
/** Max canonical JSON bytes accepted for one kernel input, 256..64MiB. */
|
|
100
88
|
maxInputBytes?: number;
|
|
101
|
-
/** Max canonical JSON bytes retained by the snapshot journal, 256..1GiB. */
|
|
102
|
-
snapshotJournalBytesLimit?: number;
|
|
103
89
|
}
|
|
104
90
|
export type OperationCancellationReason = "user" | "deadline" | "lease_lost" | "host_shutdown";
|
|
105
91
|
export interface RuntimeOptions {
|
|
@@ -118,6 +104,8 @@ export interface RuntimeOptions {
|
|
|
118
104
|
* Undefined ⇒ worktree nodes fall back to the inherited plane (no isolation). */
|
|
119
105
|
worktreeManager?: import("./worktree-plane.js").WorktreeManager;
|
|
120
106
|
sessionLog: SessionLog;
|
|
107
|
+
/** ABI v3 transaction capability. Default session logs expose one; custom logs pass it explicitly. */
|
|
108
|
+
kernelJournal?: KernelJournal;
|
|
121
109
|
executionPlane: ExecutionPlane;
|
|
122
110
|
/** Receives failures from run-owned best-effort tasks after their semantic owner has committed. */
|
|
123
111
|
onBackgroundTaskError?: BackgroundTaskErrorHandler;
|
|
@@ -194,7 +182,7 @@ export interface RuntimeOptions {
|
|
|
194
182
|
* and memory-write syscalls are admitted unconditionally (pre-M2 behavior).
|
|
195
183
|
*/
|
|
196
184
|
resourceQuota?: ResourceQuota;
|
|
197
|
-
/**
|
|
185
|
+
/** Canonical provider/output recovery and input-bound policy. */
|
|
198
186
|
kernelReliability?: KernelReliabilityOptions;
|
|
199
187
|
/** Attempts allowed for a workflow node to satisfy its output schema, 1..16. Default: 2. */
|
|
200
188
|
workflowSchemaValidationAttempts?: number;
|
|
@@ -273,6 +261,8 @@ export interface RuntimeOptions {
|
|
|
273
261
|
* concurrency stays vehicle-scoped (spec §2.5).
|
|
274
262
|
*/
|
|
275
263
|
runGroup?: RunGroup;
|
|
264
|
+
/** Host-only retries for settling the run-group ledger; never enters the canonical ABI. */
|
|
265
|
+
groupBudgetSettlementRetries?: number;
|
|
276
266
|
/**
|
|
277
267
|
* Set by the SubAgentOrchestrator for host-derived child runs: the child still joins the
|
|
278
268
|
* `runGroup` (lineage) and settles its actual terminal usage into the group ledger, but reserves
|
|
@@ -281,18 +271,14 @@ export interface RuntimeOptions {
|
|
|
281
271
|
*/
|
|
282
272
|
nestedGroupVehicle?: boolean;
|
|
283
273
|
/**
|
|
284
|
-
* Optional long-term memory policy
|
|
285
|
-
*
|
|
286
|
-
* defaults. Enabling memory still requires `dreamStore` + `agentId`.
|
|
274
|
+
* Optional canonical long-term memory policy. Enabling memory still requires `dreamStore` +
|
|
275
|
+
* `agentId`; storage location is configured on that host store, not in the kernel contract.
|
|
287
276
|
*/
|
|
288
277
|
memoryPolicy?: MemoryPolicy;
|
|
289
278
|
tokenizer?: string;
|
|
290
279
|
enablePlanTool?: boolean;
|
|
291
|
-
/**
|
|
292
|
-
|
|
293
|
-
* Defaults to `.spool/` under the process cwd.
|
|
294
|
-
*/
|
|
295
|
-
resultSpool?: LargeResultSpool;
|
|
280
|
+
/** Storage for canonical opaque external payload locators. */
|
|
281
|
+
payloadStore?: PayloadStore;
|
|
296
282
|
compressionStore?: ArchiveStore;
|
|
297
283
|
onToolSuspend?: (event: ToolSuspendEvent) => Promise<unknown> | unknown;
|
|
298
284
|
onPermissionRequest?: (event: PermissionRequestEvent) => Promise<PermissionResponse | boolean> | PermissionResponse | boolean;
|
|
@@ -304,15 +290,59 @@ export interface RuntimeOptions {
|
|
|
304
290
|
criteria: string[];
|
|
305
291
|
requiredEvidence: string[];
|
|
306
292
|
}) => Promise<MilestoneCheckResult> | MilestoneCheckResult;
|
|
307
|
-
/** Passed to
|
|
293
|
+
/** Passed to the canonical agent root for role/isolation metadata. */
|
|
308
294
|
runSpec?: AgentRunSpec;
|
|
309
|
-
/**
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
295
|
+
/**
|
|
296
|
+
* The run's **exposure ceiling** — the outer bound on what this run may EVER advertise to the
|
|
297
|
+
* model. Not a static profile: it is an INTERSECTION applied on every turn (`exposed ⊆ ceiling`),
|
|
298
|
+
* so every narrowing mechanism operates *within* it and none can widen past it. Skills narrow
|
|
299
|
+
* inside the ceiling (`allowed_tools`), `baselineToolIds` selects which of the ceiling's tools are
|
|
300
|
+
* exposed before any skill activates, `stableCoreToolIds` pins tools against skill narrowing, and
|
|
301
|
+
* the self-harness manifest surface folds by intersection for exactly this reason.
|
|
302
|
+
*
|
|
303
|
+
* Exempt on the id axis: the kernel-owned meta-tools (`skill`, `memory`, `knowledge`,
|
|
304
|
+
* `update_plan`, `read_result`) stay exposed regardless of this list — a ceiling that hid `skill`
|
|
305
|
+
* would make progressive disclosure unreachable. The KIND axis
|
|
306
|
+
* (`runSpec.capabilityFilter.allowedKinds`) still applies to them.
|
|
307
|
+
*
|
|
308
|
+
* Byte-stable across the run, so it never busts the prompt-cache prefix. Lowers to the same
|
|
309
|
+
* `capability_filter` sub-agents use: augments `runSpec`'s filter when both are set, else
|
|
310
|
+
* synthesizes a minimal run spec. Omitted **or empty** ⇒ no ceiling (all registered tools) — the
|
|
311
|
+
* empty array is NOT a minimal surface here; use `baselineToolIds: []` for that.
|
|
312
|
+
*
|
|
313
|
+
* Enforcement: `toolDispatchGate` (default `"exposed"`) makes this a real boundary — a call to a
|
|
314
|
+
* tool outside the advertised set never executes.
|
|
315
|
+
*/
|
|
315
316
|
allowedToolIds?: string[];
|
|
317
|
+
/**
|
|
318
|
+
* The **pre-activation** exposure surface, selected from under the `allowedToolIds` ceiling.
|
|
319
|
+
* Makes the narrow→wide progressive-disclosure shape expressible: start the run advertising only
|
|
320
|
+
* these tools, and let a skill activation widen the surface by exactly its declared
|
|
321
|
+
* `allowed_tools` (still ∩ the ceiling). Per turn:
|
|
322
|
+
*
|
|
323
|
+
* `exposed = meta ∪ ((baseline ∪ stableCore ∪ ⋃ activeSkills.allowed_tools) ∩ ceiling)`
|
|
324
|
+
*
|
|
325
|
+
* An active skill that declares no `allowed_tools` contributes nothing — with a baseline set the
|
|
326
|
+
* surface stays narrow (strict; the legacy errs-open widening is deliberately not inherited).
|
|
327
|
+
*
|
|
328
|
+
* `undefined` ⇒ legacy behavior, byte-identical (ceiling + errs-open skill narrowing). `[]` is a
|
|
329
|
+
* legitimate, distinct value: the minimal surface (meta-tools + `stableCoreToolIds` only) — the
|
|
330
|
+
* `allowedToolIds` "empty means no gating" trap does NOT recur here. Entries outside the ceiling
|
|
331
|
+
* silently intersect away (no root-start error), the same fold every id-list surface uses.
|
|
332
|
+
*/
|
|
333
|
+
baselineToolIds?: string[];
|
|
334
|
+
/**
|
|
335
|
+
* Dispatch enforcement for the exposure surface. `"exposed"` (default) is fail-closed: a tool call
|
|
336
|
+
* the model was never advertised this turn never reaches the host — the kernel commits a
|
|
337
|
+
* model-visible `governance_denied` result instead ("Tool 'X' is not part of this run's toolset"),
|
|
338
|
+
* which feeds the repeat fuse like any other denial. Allowed siblings in the same batch still
|
|
339
|
+
* execute; `pace` and the meta-tool family always pass through.
|
|
340
|
+
*
|
|
341
|
+
* `"registered"` is the escape hatch restoring the pre-gate permissive behavior (any registered
|
|
342
|
+
* tool the model names executes, even if it was gated out of the tools schema). Set it only when a
|
|
343
|
+
* host deliberately relies on blind calls to unadvertised tools.
|
|
344
|
+
*/
|
|
345
|
+
toolDispatchGate?: "exposed" | "registered";
|
|
316
346
|
/** P0-C: optional per-turn metrics sink for tool-gating telemetry (see `TurnMetrics`). Pure
|
|
317
347
|
* observation; invoked once per LLM turn. Never throws into the run loop (errors are swallowed). */
|
|
318
348
|
onTurnMetrics?: (metrics: TurnMetrics) => void;
|
|
@@ -324,13 +354,6 @@ export interface RuntimeOptions {
|
|
|
324
354
|
milestoneContract?: MilestoneContract;
|
|
325
355
|
/** Custom sub-agent host driver; defaults to SubAgentOrchestrator. */
|
|
326
356
|
subAgentOrchestrator?: SubAgentOrchestrator;
|
|
327
|
-
/** M5 v2.1: marks this runner as executing AS a workflow node (a child spawned by the workflow
|
|
328
|
-
* driver). A workflow node's `start_workflow` FLATTENS to the parent kernel (emits
|
|
329
|
-
* `workflow_nodes_submitted` for `runWorkflow` to append). A top-level run (this flag unset)
|
|
330
|
-
* instead AUTO-PIVOTS: it bootstraps + drives the authored workflow in its own kernel and resumes
|
|
331
|
-
* the reason loop with the outcome. The orchestrator sets this on workflow-node children so a
|
|
332
|
-
* nested `start_workflow` flattens rather than recursing. */
|
|
333
|
-
isWorkflowNode?: boolean;
|
|
334
357
|
/**
|
|
335
358
|
* When set, sub-agents run through AttemptLoop with a RuntimeAttemptBody and LLM judge.
|
|
336
359
|
* The eval provider evaluates the sub-agent's output against the criteria
|
|
@@ -372,6 +395,7 @@ export declare class RuntimeRunner {
|
|
|
372
395
|
private activeGroupBudgetScope;
|
|
373
396
|
private pendingObservations;
|
|
374
397
|
private currentSessionId;
|
|
398
|
+
private fallbackPayloadStore;
|
|
375
399
|
/** O2 (system-reminder channel): host-pushed notes awaiting the next turn-boundary drain. */
|
|
376
400
|
private injectedSignals;
|
|
377
401
|
/** Skill names whose content has already been pushed into the durable `knowledge` slot this
|
|
@@ -383,9 +407,6 @@ export declare class RuntimeRunner {
|
|
|
383
407
|
private activePageOutArchive;
|
|
384
408
|
/** K4: the active run's goal, kept for the renewal-boundary memory re-query. */
|
|
385
409
|
private currentGoal;
|
|
386
|
-
/** M5 v2.1: sub-workflow specs a top-level agent authored via `start_workflow`, awaiting auto-drive
|
|
387
|
-
* at the next safe point (after the tool turn resolves, kernel back in Reason — not suspended). */
|
|
388
|
-
private pendingAuthoredWorkflows;
|
|
389
410
|
private workflowContinuation;
|
|
390
411
|
private dashboard;
|
|
391
412
|
/** Most recent kernel entropy sample of the active/last run (see `latestEntropy`). */
|
|
@@ -402,25 +423,16 @@ export declare class RuntimeRunner {
|
|
|
402
423
|
private commitKernelApply;
|
|
403
424
|
private commitKernelMaybeAction;
|
|
404
425
|
private commitKernelAction;
|
|
426
|
+
private startKernelAgent;
|
|
427
|
+
private payloadStore;
|
|
405
428
|
private persistMemoryToStore;
|
|
406
429
|
private retrieveMemoryFromStore;
|
|
407
430
|
/**
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
* `promotion_suggested`) from the routed hits — the store stays a pure query.
|
|
412
|
-
*
|
|
413
|
-
* `seenRecordIds` is one dedupe horizon: a record hit by several queries of the same
|
|
414
|
-
* prefetch is routed (recalled, injected) once. The kernel derives counts statelessly from
|
|
415
|
-
* each hit's payload, so host-side pre-filtering is the only place duplicates can be stopped.
|
|
416
|
-
*
|
|
417
|
-
* The recall lifecycle is consumed immediately rather than via the per-turn drain: the store
|
|
418
|
-
* must be up to date before any same-turn re-query, and a renewal prefetch fires inside the
|
|
419
|
-
* drain loop where queued observations would not be consumed until the next boundary.
|
|
420
|
-
* Non-memory observations are forwarded to `leftovers` (the run's pending queue) when given,
|
|
421
|
-
* and discarded for detached syscall runtimes (their kernel is throwaway).
|
|
431
|
+
* Route a host-originated renewal prefetch into canonical knowledge commands. This is not an
|
|
432
|
+
* agent syscall: the host selects records from its store, then the kernel owns the only mutation
|
|
433
|
+
* of live semantic context. `seenRecordIds` is the prefetch's dedupe horizon.
|
|
422
434
|
*/
|
|
423
|
-
private
|
|
435
|
+
private prefetchMemoryIntoKnowledge;
|
|
424
436
|
writeMemory(memory: MemoryRecord, opts?: {
|
|
425
437
|
sessionId?: string;
|
|
426
438
|
agentId?: string;
|
|
@@ -429,29 +441,28 @@ export declare class RuntimeRunner {
|
|
|
429
441
|
sessionId?: string;
|
|
430
442
|
agentId?: string;
|
|
431
443
|
}): Promise<MemoryRecall[]>;
|
|
444
|
+
private applyHostMemoryRecallLifecycle;
|
|
432
445
|
private logMemoryRetrievalResult;
|
|
433
|
-
private
|
|
446
|
+
private createCanonicalRuntime;
|
|
447
|
+
private resolveKernelJournal;
|
|
434
448
|
private groupBudgetRequest;
|
|
435
449
|
private settleGroupBudget;
|
|
436
450
|
/**
|
|
437
451
|
* Lower the declarative governance / attention / scheduler-budget / resource-quota policies into a
|
|
438
|
-
* freshly-created kernel. Shared by `execute()` (full agent run) and `
|
|
452
|
+
* freshly-created kernel. Shared by `execute()` (full agent run) and `initializeWorkflowKernel()`
|
|
439
453
|
* (standalone host-driven workflow) so a workflow's DAG-node spawns are gated, queued, and quota'd
|
|
440
|
-
* exactly as a mid-run spawn would be. Must run
|
|
454
|
+
* exactly as a mid-run spawn would be. Must run before the canonical root start so the gate enforces
|
|
441
455
|
* every policy from the first spawn. No config ⇒ the native-profile defaults (铁律: defaults only).
|
|
442
456
|
*/
|
|
443
457
|
private applyKernelPolicies;
|
|
444
458
|
/**
|
|
445
|
-
* Mirror one
|
|
446
|
-
* Shared by the main run drain, the prefetch path, and the host memory syscalls so every
|
|
447
|
-
* query route has identical recall + promotion semantics (T5).
|
|
459
|
+
* Mirror one agent-syscall memory-lifecycle observation into the durable store / host callbacks.
|
|
448
460
|
*
|
|
449
461
|
* M3: `memory_recalled` carries the kernel-derived count — the runner never computes
|
|
450
462
|
* `recall_count + 1` itself. M4: `promotion_suggested` is advisory and already
|
|
451
463
|
* edge-triggered by the kernel; the runner surfaces it and never auto-pins.
|
|
452
464
|
*/
|
|
453
465
|
private mirrorMemoryLifecycle;
|
|
454
|
-
private consumeMemoryLifecycleObservations;
|
|
455
466
|
/** Mount a tool capability on the currently-running kernel runtime. No-op if not running. */
|
|
456
467
|
mountTool(schema: ToolSchema): Promise<void>;
|
|
457
468
|
/** Mount a skill capability on the currently-running kernel runtime. No-op if not running. */
|
|
@@ -476,11 +487,6 @@ export declare class RuntimeRunner {
|
|
|
476
487
|
* drops at the next compaction/renewal boundary. A later `skill(name)` call re-activates and
|
|
477
488
|
* re-pins fresh content. Errs-open: not-active is a kernel-side no-op. */
|
|
478
489
|
deactivateSkill(name: string): Promise<void>;
|
|
479
|
-
/**
|
|
480
|
-
* Spawn an isolated sub-agent via the kernel, run it on the host, and feed the result back.
|
|
481
|
-
* Requires an active parent run (`run()` / `wake()` in progress or paused at milestone).
|
|
482
|
-
*/
|
|
483
|
-
spawnSubAgent(spec: AgentRunSpec): AsyncIterable<StreamEvent>;
|
|
484
490
|
/**
|
|
485
491
|
* G3: run one workflow node, enforcing its `output_schema` (if any). Without a schema this is a
|
|
486
492
|
* plain `orchestrator.run`. With one, the node's agent is instructed to emit conforming JSON, its
|
|
@@ -504,44 +510,17 @@ export declare class RuntimeRunner {
|
|
|
504
510
|
* Returns one typed terminal outcome for every node in the DAG.
|
|
505
511
|
*/
|
|
506
512
|
runWorkflow(spec: WorkflowSpec, opts?: {
|
|
507
|
-
/** Typed recovered terminal outcomes, including control signals and output. */
|
|
508
|
-
resumedOutcomes?: RecoveredNodeOutcome[];
|
|
509
|
-
resumedSubmissions?: Record<string, unknown>[][];
|
|
510
|
-
/** R3-1: original base index per submission batch (parallel to resumedSubmissions). */
|
|
511
|
-
resumedSubmissionBases?: number[];
|
|
512
513
|
/** Standalone session id when bootstrapping (no active parent run). Defaults to a fresh uuid. */
|
|
513
514
|
sessionId?: string;
|
|
514
515
|
}): Promise<WorkflowOutcome>;
|
|
515
516
|
/**
|
|
516
517
|
* Bootstrap a standalone kernel for a host-driven workflow with NO active parent run — the path a
|
|
517
518
|
* stateless request handler takes when it calls `runWorkflow(spec)` directly. Mirrors `execute()`'s
|
|
518
|
-
* pre-run kernel setup (governance / attention / quota via `applyKernelPolicies`, then
|
|
519
|
+
* pre-run kernel setup (governance / attention / quota via `applyKernelPolicies`, then root start)
|
|
519
520
|
* after `runWorkflow` has durably recorded `run_started`. Sets `activeKernel` / `currentSessionId`;
|
|
520
521
|
* `runWorkflow` is responsible for tearing them down.
|
|
521
522
|
*/
|
|
522
|
-
private
|
|
523
|
-
/**
|
|
524
|
-
* M5/G1: bootstrap an **agent-authored** workflow ("the model writes its own harness"). Unlike
|
|
525
|
-
* `runWorkflow` (the host fires the privileged `load_workflow`), this routes the spec through the
|
|
526
|
-
* agent-reachable `Syscall::LoadWorkflow` (the `submit_workflow` event): with no workflow active the
|
|
527
|
-
* kernel **bootstraps** the DAG; if one is already active it **flattens** the spec's nodes onto it
|
|
528
|
-
* (bootstrap-or-flatten — one kernel, one quota, never a workflow stack). Gated by the same
|
|
529
|
-
* `max_workflow_nodes` backstop as runtime submission, so an authored harness can't overgrow the run.
|
|
530
|
-
* The resulting batches are driven by the same shared driver as `runWorkflow`.
|
|
531
|
-
*/
|
|
532
|
-
bootstrapWorkflow(spec: WorkflowSpec, opts?: {
|
|
533
|
-
submitterAgentId?: string;
|
|
534
|
-
}): Promise<WorkflowOutcome>;
|
|
535
|
-
/**
|
|
536
|
-
* M5 v2.1: drive the sub-workflow(s) a top-level agent authored via `start_workflow`. Called at the
|
|
537
|
-
* verified-safe point (right after the tool turn resolved to `call_provider` — kernel in Reason, not
|
|
538
|
-
* suspended). For each authored spec: `bootstrapWorkflow` runs it in THIS kernel (the kernel resumes
|
|
539
|
-
* the agent reason loop on `workflow_completed` — `finish_workflow` sets phase=Reason), then the
|
|
540
|
-
* outcome is injected as a user message so the agent's next turn sees the result. Returns a fresh
|
|
541
|
-
* `call_provider` synthesized from the updated context (the workflow drive consumed its own kernel
|
|
542
|
-
* actions, so we re-render — the same pattern as the reactive-compact retry path).
|
|
543
|
-
*/
|
|
544
|
-
private driveAuthoredWorkflows;
|
|
523
|
+
private initializeWorkflowKernel;
|
|
545
524
|
/**
|
|
546
525
|
* #2-B-ii: while a workflow batch is in flight, poll the signal source. A Critical `InterruptNow`
|
|
547
526
|
* routes through the kernel (which, with the root suspended in `SubAgentAwait`, preempts — marks the
|
|
@@ -552,21 +531,10 @@ export declare class RuntimeRunner {
|
|
|
552
531
|
*/
|
|
553
532
|
private monitorWorkflowPreemption;
|
|
554
533
|
/**
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* batch in parallel, feed completions back (appending any agent-submitted nodes first), and loop
|
|
558
|
-
* until the kernel reports the workflow complete. Returns typed terminal node outcomes.
|
|
534
|
+
* Drive a canonical root or provider-authored workflow from kernel effects only: run each
|
|
535
|
+
* emitted batch, resolve its launch/completion/preemption effects, and stop at the kernel terminal.
|
|
559
536
|
*/
|
|
560
537
|
private driveWorkflow;
|
|
561
|
-
/**
|
|
562
|
-
* Resume a workflow from the parent session's completed nodes.
|
|
563
|
-
* Reads the session log, extracts completed workflow node records (with their W-1 control
|
|
564
|
-
* signals + outputs), and calls runWorkflow so the kernel skips those nodes, replays control
|
|
565
|
-
* flow (classify prune / loop stop), and the driver re-seeds its outputs map.
|
|
566
|
-
*/
|
|
567
|
-
resumeWorkflow(spec: WorkflowSpec, opts?: {
|
|
568
|
-
sessionId?: string;
|
|
569
|
-
}): Promise<WorkflowOutcome>;
|
|
570
538
|
interrupt(reason?: OperationCancellationReason): void;
|
|
571
539
|
/** Push a contextual note into the run's signal stream (the system-reminder channel): it drains at
|
|
572
540
|
* the next turn boundary, routes through the kernel attention policy, and renders once as a
|
|
@@ -599,14 +567,6 @@ export declare class RuntimeRunner {
|
|
|
599
567
|
wake(sessionId: string, extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
|
|
600
568
|
/** Execute a kernel-owned approval effect and return the correlated decision lists. */
|
|
601
569
|
private resolveApprovalRequests;
|
|
602
|
-
/**
|
|
603
|
-
* O7: resolve a `read_result` meta-tool call to the full text of a previously-evicted tool
|
|
604
|
-
* output. Resolution order: (a) the on-disk result spool committed by the explicit
|
|
605
|
-
* `spool_large_result` host effect, then (b) a session-log scan for the original
|
|
606
|
-
* `tool_completed` event carrying that `call_id`. Slices the
|
|
607
|
-
* resolved text by `[offset, offset + maxBytes)` (plain string slice — "bytes-ish").
|
|
608
|
-
*/
|
|
609
|
-
private resolveReadResult;
|
|
610
570
|
private execute;
|
|
611
571
|
/** I4 + K4: fetch long-term memory hits for the current goal and land them in `history` as an
|
|
612
572
|
* ordinary user turn — single-use retrieval content that decays with the compression pyramid,
|
|
@@ -614,6 +574,7 @@ export declare class RuntimeRunner {
|
|
|
614
574
|
* after each sprint renewal (`phase: "renewal"`): renewal drops the old history INCLUDING the
|
|
615
575
|
* earlier memory hits, so the new sprint gets a fresh recall pass. Errs-open throughout. */
|
|
616
576
|
private prefetchMemoryIntoHistory;
|
|
577
|
+
private prefetchMemoryIntoInitialContext;
|
|
617
578
|
private appendObservations;
|
|
618
579
|
private archiveSemanticPageOut;
|
|
619
580
|
private upgradeCompressedSummary;
|