@deepstrike/wasm 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.
Files changed (37) hide show
  1. package/README.md +2 -1
  2. package/dist/index.d.ts +4 -3
  3. package/dist/index.js +3 -2
  4. package/dist/runtime/canonical-kernel-step.d.ts +146 -0
  5. package/dist/runtime/canonical-kernel-step.js +1484 -0
  6. package/dist/runtime/execution-plane.d.ts +0 -3
  7. package/dist/runtime/execution-plane.js +0 -25
  8. package/dist/runtime/facade.js +3 -0
  9. package/dist/runtime/index.d.ts +7 -7
  10. package/dist/runtime/index.js +4 -3
  11. package/dist/runtime/kernel-event-log.d.ts +0 -1
  12. package/dist/runtime/kernel-event-log.js +7 -13
  13. package/dist/runtime/kernel-journal.d.ts +332 -0
  14. package/dist/runtime/kernel-journal.js +681 -0
  15. package/dist/runtime/kernel-step.d.ts +34 -89
  16. package/dist/runtime/kernel-step.js +67 -167
  17. package/dist/runtime/os-snapshot.d.ts +2 -2
  18. package/dist/runtime/os-snapshot.js +2 -6
  19. package/dist/runtime/payload-store.d.ts +30 -0
  20. package/dist/runtime/payload-store.js +66 -0
  21. package/dist/runtime/runner.d.ts +72 -79
  22. package/dist/runtime/runner.js +424 -637
  23. package/dist/runtime/session-log.d.ts +24 -27
  24. package/dist/runtime/session-log.js +11 -52
  25. package/dist/runtime/session-repair.d.ts +2 -36
  26. package/dist/runtime/session-repair.js +2 -47
  27. package/dist/runtime/sub-agent-orchestrator.d.ts +2 -2
  28. package/dist/runtime/sub-agent-orchestrator.js +36 -40
  29. package/dist/runtime/types/agent.d.ts +21 -16
  30. package/dist/runtime/types/agent.js +21 -41
  31. package/package.json +4 -3
  32. package/dist/runtime/kernel-rebuild.d.ts +0 -8
  33. package/dist/runtime/kernel-rebuild.js +0 -65
  34. package/dist/runtime/kernel-transaction-log.d.ts +0 -61
  35. package/dist/runtime/kernel-transaction-log.js +0 -140
  36. package/dist/runtime/large-result-spool.d.ts +0 -57
  37. package/dist/runtime/large-result-spool.js +0 -169
@@ -6,12 +6,12 @@ import type { SignalSource, RuntimeSignal } from "../signals/index.js";
6
6
  import type { SessionLog, SessionEvent } from "./session-log.js";
7
7
  import type { ExecutionPlane } from "./execution-plane.js";
8
8
  import { type GovernancePolicy } from "../governance.js";
9
- import { type RecoveredNodeOutcome } from "./session-repair.js";
10
- import type { AgentRunSpec, SubAgentResult, MilestonePolicy, MilestoneContract, MilestoneCheckResult, WorkflowSpec, WorkflowOutcome } from "./types/agent.js";
9
+ import type { KernelJournal } from "./kernel-journal.js";
10
+ import type { AgentRunSpec, MilestonePolicy, MilestoneContract, MilestoneCheckResult, WorkflowSpec, WorkflowOutcome } from "./types/agent.js";
11
11
  import { type SubAgentOrchestrator } from "./sub-agent-orchestrator.js";
12
12
  import { type ReducerRegistry } from "./reducers.js";
13
13
  import { type NativeOsProfile, type OsProfileId, type SignalPolicy } from "./os-profile.js";
14
- import { LargeResultSpool } from "./large-result-spool.js";
14
+ import { PayloadStore } from "./payload-store.js";
15
15
  import { type ContextPolicyOverridesV1 } from "./context-policy.js";
16
16
  export interface MemoryWriteRateLimit {
17
17
  maxWrites: number;
@@ -44,11 +44,10 @@ export interface PromptBudget {
44
44
  /**
45
45
  * Long-term memory policy (`set_memory_policy`) — opt-in, kernel-enforced. `validationEnabled:
46
46
  * false` admits writes without validation, `maxContentBytes` / `maxNameLength` override the
47
- * validation limits, and `retrievalTopK` caps `query_memory` breadth. `memoryPath` /
48
- * `staleWarningDays` are carried for SDK recall I/O. Omitted fields keep the kernel defaults.
47
+ * validation limits, and `retrievalTopK` caps `query_memory` breadth. Host storage is configured
48
+ * on the `DreamStore` and never enters this contract. Omitted fields keep the kernel defaults.
49
49
  */
50
50
  export interface MemoryPolicy {
51
- memoryPath?: string;
52
51
  staleWarningDays?: number;
53
52
  retrievalTopK?: number;
54
53
  validationEnabled?: boolean;
@@ -56,19 +55,10 @@ export interface MemoryPolicy {
56
55
  maxNameLength?: number;
57
56
  }
58
57
  export interface KernelReliabilityOptions {
59
- eventReplayCapacity?: number;
60
- completedEffectReplayCapacity?: number;
61
58
  providerRecoveryAttempts?: number;
62
59
  outputRecoveryAttempts?: number;
63
- hostEffectRetryAttempts?: number;
64
- spoolThresholdBytes?: number;
65
- spoolPreviewBytes?: number;
66
- /** Max accepted ABI transactions retained for a portable KernelSnapshot rebuild. */
67
- snapshotInputLimit?: number;
68
60
  /** Max canonical JSON bytes accepted for one kernel input, 256..64MiB. */
69
61
  maxInputBytes?: number;
70
- /** Max canonical JSON bytes retained by the snapshot journal, 256..1GiB. */
71
- snapshotJournalBytesLimit?: number;
72
62
  }
73
63
  export interface ArchiveStore {
74
64
  write(sessionId: string, startSeq: number, messages: Message[]): Promise<string | undefined>;
@@ -105,6 +95,8 @@ export interface ToolResultHookDecision {
105
95
  }
106
96
  export interface RuntimeOptions {
107
97
  provider: LLMProvider;
98
+ /** Required for ABI-v3 operation recovery unless the SessionLog embeds one. */
99
+ kernelJournal?: KernelJournal;
108
100
  /** M1/G3 intelligence routing: resolve a per-node provider from a workflow node's `modelHint`.
109
101
  * Returns undefined ⇒ fall back to `provider`. Without this hook the hint is a no-op. */
110
102
  providerFor?: (modelHint: string) => LLMProvider | undefined;
@@ -195,10 +187,6 @@ export interface RuntimeOptions {
195
187
  onToolSuspend?: (event: ToolSuspendEvent) => Promise<unknown> | unknown;
196
188
  onPermissionRequest?: (event: PermissionRequestEvent) => Promise<PermissionResponse | boolean> | PermissionResponse | boolean;
197
189
  subAgentOrchestrator?: SubAgentOrchestrator;
198
- /** M5 v2.1: marks this runner as a workflow node (child of the workflow driver). A workflow node's
199
- * `start_workflow` FLATTENS to the parent kernel; a top-level run (unset) AUTO-PIVOTS — bootstraps +
200
- * drives the authored workflow in its own kernel, then resumes the reason loop with the outcome. */
201
- isWorkflowNode?: boolean;
202
190
  /** G2: custom reducers for `NodeKind::Reduce` workflow nodes, merged over the built-ins. */
203
191
  reducers?: ReducerRegistry;
204
192
  milestonePolicy?: MilestonePolicy;
@@ -209,11 +197,52 @@ export interface RuntimeOptions {
209
197
  requiredEvidence: string[];
210
198
  }) => Promise<MilestoneCheckResult> | MilestoneCheckResult;
211
199
  runSpec?: AgentRunSpec;
212
- /** P0-A tool gating: a static per-run tool profile — only these tool ids (plus the meta-tools)
213
- * are exposed to the model each turn. Lowers to the same `capability_filter` sub-agents use;
214
- * byte-stable across the run, so it never busts the prompt-cache prefix. Augments `runSpec`'s
215
- * filter when both set; synthesizes a minimal spec otherwise. Omitted/empty ⇒ no gating. */
200
+ /**
201
+ * The run's **exposure ceiling** — the outer bound on what this run may EVER advertise to the
202
+ * model. Not a static profile: it is an INTERSECTION applied on every turn (`exposed ⊆ ceiling`),
203
+ * so every narrowing mechanism operates *within* it and none can widen past it. Skills narrow
204
+ * inside the ceiling (`allowed_tools`), `baselineToolIds` selects which of the ceiling's tools are
205
+ * exposed before any skill activates, and `stableCoreToolIds` pins tools against skill narrowing.
206
+ *
207
+ * Exempt on the id axis: the kernel-owned meta-tools (`skill`, `memory`, `knowledge`,
208
+ * `update_plan`, `read_result`) stay exposed regardless of this list — a ceiling that hid `skill`
209
+ * would make progressive disclosure unreachable. The KIND axis
210
+ * (`runSpec.capabilityFilter.allowedKinds`) still applies to them.
211
+ *
212
+ * Byte-stable across the run, so it never busts the prompt-cache prefix. Lowers to the same
213
+ * `capability_filter` sub-agents use: augments `runSpec`'s filter when both are set, else
214
+ * synthesizes a minimal run spec. Omitted **or empty** ⇒ no ceiling (all registered tools) — the
215
+ * empty array is NOT a minimal surface here; use `baselineToolIds: []` for that.
216
+ *
217
+ * Enforcement: `toolDispatchGate` (default `"exposed"`) makes this a real boundary — a call to a
218
+ * tool outside the advertised set never executes.
219
+ */
216
220
  allowedToolIds?: string[];
221
+ /**
222
+ * The **pre-activation** exposure surface, selected from under the `allowedToolIds` ceiling.
223
+ * Makes the narrow→wide progressive-disclosure shape expressible: start the run advertising only
224
+ * these tools, and let a skill activation widen the surface by exactly its declared
225
+ * `allowed_tools` (still ∩ the ceiling). Per turn:
226
+ *
227
+ * `exposed = meta ∪ ((baseline ∪ stableCore ∪ ⋃ activeSkills.allowed_tools) ∩ ceiling)`
228
+ *
229
+ * An active skill that declares no `allowed_tools` contributes nothing — with a baseline set the
230
+ * surface stays narrow (strict; the legacy errs-open widening is deliberately not inherited).
231
+ *
232
+ * `undefined` ⇒ legacy behavior, byte-identical. `[]` is a legitimate, distinct value: the minimal
233
+ * surface (meta-tools + `stableCoreToolIds` only) — the `allowedToolIds` "empty means no gating"
234
+ * trap does NOT recur here. Entries outside the ceiling silently intersect away.
235
+ */
236
+ baselineToolIds?: string[];
237
+ /**
238
+ * Dispatch enforcement for the exposure surface. `"exposed"` (default) is fail-closed: a tool call
239
+ * the model was never advertised this turn never reaches the host — the kernel commits a
240
+ * model-visible `governance_denied` result instead, which feeds the repeat fuse like any other
241
+ * denial. Allowed siblings in the same batch still execute; `pace` and the meta-tool family always
242
+ * pass through. `"registered"` is the escape hatch restoring the pre-gate permissive behavior (any
243
+ * registered tool the model names executes, even if it was gated out of the tools schema).
244
+ */
245
+ toolDispatchGate?: "exposed" | "registered";
217
246
  /** P0-C: optional per-turn metrics sink for tool-gating telemetry (see `TurnMetrics`). Pure
218
247
  * observation; invoked once per LLM turn. Never throws into the run loop (errors are swallowed). */
219
248
  onTurnMetrics?: (metrics: TurnMetrics) => void;
@@ -224,7 +253,7 @@ export interface RuntimeOptions {
224
253
  dreamProvider?: LLMProvider;
225
254
  dreamSummarizer?: DreamSummarizer;
226
255
  dreamSystemPrompt?: string;
227
- resultSpool?: LargeResultSpool;
256
+ payloadStore?: PayloadStore;
228
257
  }
229
258
  export type OperationCancellationReason = "user" | "deadline" | "lease_lost" | "host_shutdown";
230
259
  export declare class RuntimeRunner {
@@ -236,6 +265,7 @@ export declare class RuntimeRunner {
236
265
  private pendingObservations;
237
266
  private activeKernel;
238
267
  private currentSessionId;
268
+ private fallbackPayloadStore;
239
269
  /** O2 (system-reminder channel): host-pushed notes awaiting the next turn-boundary drain. */
240
270
  private injectedSignals;
241
271
  /** Skill names whose content has already been pushed into the durable `knowledge` slot this
@@ -249,11 +279,14 @@ export declare class RuntimeRunner {
249
279
  private nextArchiveStart;
250
280
  private pendingPageOutArchives;
251
281
  private activePageOutArchive;
252
- /** M5 v2.1: sub-workflow specs a top-level agent authored via `start_workflow`, awaiting auto-drive
253
- * at the next safe point (after the tool turn resolves, kernel back in Reason). */
254
- private pendingAuthoredWorkflows;
282
+ /** Provider continuation emitted after a canonical nested workflow completes. */
255
283
  private workflowContinuation;
256
284
  constructor(opts: RuntimeOptions);
285
+ private resolveKernelJournal;
286
+ private createCanonicalRuntime;
287
+ private commitKernelApply;
288
+ private commitKernelMaybeAction;
289
+ private commitKernelAction;
257
290
  get hostOptions(): RuntimeOptions;
258
291
  interrupt(reason?: OperationCancellationReason): void;
259
292
  /** Push a contextual note into the run's signal stream (the system-reminder channel): it drains at
@@ -290,23 +323,16 @@ export declare class RuntimeRunner {
290
323
  pushKnowledge(message: Message, tokens?: number, opts?: {
291
324
  key?: string;
292
325
  pinned?: boolean;
293
- }): void;
326
+ }): Promise<void>;
327
+ private payloadStore;
294
328
  /** K1: mark a keyed knowledge entry for removal at the next compaction/renewal boundary.
295
329
  * Errs-open: an unknown key is a kernel-side no-op. */
296
- removeKnowledge(key: string): void;
330
+ removeKnowledge(key: string): Promise<void>;
297
331
  /** K3: host-driven skill deactivation — toolset re-widens at the next provider call, the
298
332
  * skill's knowledge pin drops at the next boundary. Errs-open: not-active is a no-op. */
299
- deactivateSkill(name: string): void;
333
+ deactivateSkill(name: string): Promise<void>;
300
334
  private resolveKernelSuspend;
301
- /**
302
- * O7: resolve a `read_result` meta-tool call to the full text of a previously-evicted tool
303
- * output. Resolution order: (a) the result spool committed by `large_result_spool_result`,
304
- * (b) a session-log scan for the original `tool_completed` event carrying that `call_id`.
305
- * Slices the resolved text by `[offset, offset + maxBytes)` (plain string slice — "bytes-ish").
306
- */
307
- private resolveReadResult;
308
335
  private execute;
309
- spawnSubAgent(spec: AgentRunSpec): Promise<SubAgentResult>;
310
336
  /**
311
337
  * G3: run one workflow node, enforcing its `output_schema` (if any) by instructing the agent,
312
338
  * validating its output (the supported JSON-Schema subset), and re-running once with the errors
@@ -327,44 +353,21 @@ export declare class RuntimeRunner {
327
353
  */
328
354
  /**
329
355
  * Lower the declarative governance / attention / scheduler-budget / resource-quota / memory policies
330
- * into a freshly-created kernel. Shared by `execute()` (full run) and `bootstrapWorkflowKernel()`
356
+ * into a freshly-created kernel. Shared by `execute()` (full run) and `initializeWorkflowKernel()`
331
357
  * (standalone workflow) so a DAG's node spawns are gated and quota'd exactly as a mid-run spawn.
332
- * Must run BEFORE `start_run`. No config ⇒ native-profile defaults.
358
+ * Must run before the canonical root start. No config ⇒ native-profile defaults.
333
359
  */
334
360
  private applyKernelPolicies;
335
361
  /**
336
- * Bootstrap a standalone kernel for a host-driven workflow with no active parent run — the path a
337
- * stateless handler (browser/edge worker) takes when it calls `runWorkflow(spec)` directly. Mirrors
338
- * `execute()`'s pre-run setup (policies via `applyKernelPolicies`, then `start_run`) and records a
339
- * best-effort `run_started` so the run is resumable. `runWorkflow` tears the kernel down afterward.
362
+ * Bootstrap a standalone kernel for a host-driven workflow with no active parent run. The caller
363
+ * durably records `run_started` with the same `runId` before this method can create journal state.
364
+ * `StartOperation { Workflow }` is the sole root transition; `runWorkflow` tears the kernel down.
340
365
  */
341
- private bootstrapWorkflowKernel;
366
+ private initializeWorkflowKernel;
342
367
  runWorkflow(spec: WorkflowSpec, opts?: {
343
- /** Typed recovered terminal outcomes, including control signals and output. */
344
- resumedOutcomes?: RecoveredNodeOutcome[];
345
- resumedSubmissions?: Record<string, unknown>[][];
346
- /** R3-1: original base index per submission batch (parallel to resumedSubmissions). */
347
- resumedSubmissionBases?: number[];
348
368
  /** Standalone session id when bootstrapping (no active parent run). Defaults to a fresh uuid. */
349
369
  sessionId?: string;
350
370
  }): Promise<WorkflowOutcome>;
351
- /**
352
- * M5/G1: bootstrap an **agent-authored** workflow ("the model writes its own harness"). Routes the
353
- * spec through the agent-reachable `Syscall::LoadWorkflow` (`submit_workflow`): with no workflow
354
- * active the kernel bootstraps the DAG, else it flattens onto the running one (bootstrap-or-flatten —
355
- * one kernel, one quota). The same shared driver runs the resulting batches.
356
- */
357
- bootstrapWorkflow(spec: WorkflowSpec, opts?: {
358
- submitterAgentId?: string;
359
- }): Promise<WorkflowOutcome>;
360
- /**
361
- * M5 v2.1: drive the sub-workflow(s) a top-level agent authored via `start_workflow`, at the safe
362
- * point (tool turn resolved → kernel in Reason). Each runs in THIS kernel (the kernel resumes the
363
- * reason loop on `workflow_completed`), then the outcome is injected as a user message and a fresh
364
- * `call_provider` is synthesized from the updated context (the workflow drive consumed its own
365
- * kernel actions — same re-render pattern as the reactive-compact retry path).
366
- */
367
- private driveAuthoredWorkflows;
368
371
  /**
369
372
  * #2-B-ii: while a workflow batch is in flight, poll the signal source; a Critical `InterruptNow`
370
373
  * routes through the kernel (root in `SubAgentAwait` → preempt → `AgentPreempted` + tears the
@@ -373,20 +376,10 @@ export declare class RuntimeRunner {
373
376
  */
374
377
  private monitorWorkflowPreemption;
375
378
  /**
376
- * Shared workflow driver for `runWorkflow` (host `load_workflow`) and `bootstrapWorkflow` (agent
377
- * `submit_workflow`): run each kernel-emitted batch in parallel, feed completions back (appending any
378
- * agent-submitted nodes first), and loop until the kernel reports the workflow complete.
379
+ * Shared canonical workflow driver: run each kernel-emitted batch in parallel, feed completions
380
+ * back, and loop until the kernel reports the workflow complete.
379
381
  */
380
382
  private driveWorkflow;
381
- /**
382
- * Resume a workflow from the parent session's completed nodes.
383
- * Reads the session log, extracts completed workflow node records (with their W-1 control
384
- * signals + outputs), and calls runWorkflow so the kernel skips those nodes, replays control
385
- * flow (classify prune / loop stop), and the driver re-seeds its outputs map.
386
- */
387
- resumeWorkflow(spec: WorkflowSpec, opts?: {
388
- sessionId?: string;
389
- }): Promise<WorkflowOutcome>;
390
383
  private appendObservations;
391
384
  /** I4 + K4: fetch long-term memory hits for the current goal and land them in `history` as an
392
385
  * ordinary user turn — single-use retrieval content that decays with the compression pyramid,