@deepstrike/wasm 0.2.38 → 0.2.40

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 (48) hide show
  1. package/README.md +14 -13
  2. package/dist/harness/index.d.ts +127 -61
  3. package/dist/harness/index.js +212 -83
  4. package/dist/index.d.ts +9 -6
  5. package/dist/index.js +4 -2
  6. package/dist/memory/extraction.d.ts +4 -0
  7. package/dist/memory/extraction.js +48 -0
  8. package/dist/memory/in-memory-store.d.ts +19 -9
  9. package/dist/memory/in-memory-store.js +68 -23
  10. package/dist/memory/index.d.ts +52 -24
  11. package/dist/memory/ranking.d.ts +33 -0
  12. package/dist/memory/ranking.js +77 -0
  13. package/dist/memory/retention.d.ts +17 -0
  14. package/dist/memory/retention.js +54 -0
  15. package/dist/providers/base.d.ts +5 -0
  16. package/dist/providers/base.js +32 -0
  17. package/dist/runtime/context-policy.d.ts +35 -0
  18. package/dist/runtime/context-policy.js +66 -0
  19. package/dist/runtime/eval.d.ts +2 -0
  20. package/dist/runtime/execution-plane.d.ts +2 -1
  21. package/dist/runtime/execution-plane.js +3 -3
  22. package/dist/runtime/facade.js +2 -1
  23. package/dist/runtime/index.d.ts +11 -4
  24. package/dist/runtime/index.js +5 -1
  25. package/dist/runtime/kernel-event-log.js +46 -13
  26. package/dist/runtime/kernel-rebuild.d.ts +8 -0
  27. package/dist/runtime/kernel-rebuild.js +65 -0
  28. package/dist/runtime/kernel-step.d.ts +139 -7
  29. package/dist/runtime/kernel-step.js +110 -10
  30. package/dist/runtime/kernel-transaction-log.d.ts +61 -0
  31. package/dist/runtime/kernel-transaction-log.js +140 -0
  32. package/dist/runtime/os-profile.d.ts +9 -10
  33. package/dist/runtime/os-profile.js +14 -10
  34. package/dist/runtime/os-snapshot.d.ts +19 -0
  35. package/dist/runtime/os-snapshot.js +16 -3
  36. package/dist/runtime/runner.d.ts +73 -41
  37. package/dist/runtime/runner.js +562 -290
  38. package/dist/runtime/session-log.d.ts +55 -10
  39. package/dist/runtime/session-log.js +60 -3
  40. package/dist/runtime/session-repair.d.ts +11 -7
  41. package/dist/runtime/session-repair.js +11 -8
  42. package/dist/runtime/sub-agent-orchestrator.js +1 -1
  43. package/dist/runtime/types/agent.d.ts +31 -0
  44. package/dist/runtime/types/agent.js +35 -0
  45. package/dist/signals/index.d.ts +21 -1
  46. package/dist/signals/index.js +1 -0
  47. package/dist/types.d.ts +7 -2
  48. package/package.json +2 -2
@@ -1,17 +1,18 @@
1
1
  import type { LLMProvider, Message, StreamEvent, PermissionRequestEvent, PermissionResponse, EntropySample, EntropyWatchOptions, DreamSummarizer } from "../types.js";
2
2
  import type { ToolSuspendEvent } from "./execution-plane.js";
3
- import type { DreamStore, DreamResult } from "../memory/index.js";
3
+ import type { DreamStore, MemoryQuery, MemoryRecord, MemoryScope } from "../memory/index.js";
4
4
  import type { KnowledgeSource } from "../knowledge/index.js";
5
5
  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 RecoveredNodeCompletion } from "./session-repair.js";
10
- import type { AgentRunSpec, SubAgentResult, MilestonePolicy, MilestoneContract, MilestoneCheckResult, WorkflowSpec } from "./types/agent.js";
9
+ import { type RecoveredNodeOutcome } from "./session-repair.js";
10
+ import type { AgentRunSpec, SubAgentResult, 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
- import { type NativeOsProfile, type OsProfileId } from "./os-profile.js";
13
+ import { type NativeOsProfile, type OsProfileId, type SignalPolicy } from "./os-profile.js";
14
14
  import { LargeResultSpool } from "./large-result-spool.js";
15
+ import { type ContextPolicyOverridesV1 } from "./context-policy.js";
15
16
  export interface MemoryWriteRateLimit {
16
17
  maxWrites: number;
17
18
  windowMs: number;
@@ -24,8 +25,19 @@ export interface ResourceQuota {
24
25
  /** Rolling-window memory-write rate limit: at most `maxWrites` per any `windowMs` span. */
25
26
  memoryWritesPerWindow?: MemoryWriteRateLimit;
26
27
  }
27
- export interface SchedulerBudget {
28
- maxWallMs?: number;
28
+ export interface SchedulerPolicy {
29
+ version: 1;
30
+ criticalPathWeight: number;
31
+ fanoutWeight: number;
32
+ ageWeight: number;
33
+ tokenCostWeight: number;
34
+ }
35
+ export declare function schedulerPolicyToKernel(policy: SchedulerPolicy): Record<string, number>;
36
+ /** Host-counted provider envelope and response reserves deducted from the model context window. */
37
+ export interface PromptBudget {
38
+ promptOverheadTokens: number;
39
+ outputReserveTokens: number;
40
+ safetyMarginTokens: number;
29
41
  }
30
42
  /**
31
43
  * Long-term memory policy (`set_memory_policy`) — opt-in, kernel-enforced. `validationEnabled:
@@ -41,6 +53,25 @@ export interface MemoryPolicy {
41
53
  maxContentBytes?: number;
42
54
  maxNameLength?: number;
43
55
  }
56
+ export interface KernelReliabilityOptions {
57
+ eventReplayCapacity?: number;
58
+ completedEffectReplayCapacity?: number;
59
+ providerRecoveryAttempts?: number;
60
+ outputRecoveryAttempts?: number;
61
+ hostEffectRetryAttempts?: number;
62
+ spoolThresholdBytes?: number;
63
+ spoolPreviewBytes?: number;
64
+ /** Max accepted ABI transactions retained for a portable KernelSnapshot rebuild. */
65
+ snapshotInputLimit?: number;
66
+ /** Max canonical JSON bytes accepted for one kernel input, 256..64MiB. */
67
+ maxInputBytes?: number;
68
+ /** Max canonical JSON bytes retained by the snapshot journal, 256..1GiB. */
69
+ snapshotJournalBytesLimit?: number;
70
+ }
71
+ export interface ArchiveStore {
72
+ write(sessionId: string, startSeq: number, messages: Message[]): Promise<string | undefined>;
73
+ read?(archiveRef: string): Promise<Message[]>;
74
+ }
44
75
  /** P0-C tool-gating telemetry: per-LLM-turn metrics, emitted via `RuntimeOptions.onTurnMetrics`.
45
76
  * Pure observation — no behavior change. `toolsExposed` vs `toolsCalled` quantifies over-exposure;
46
77
  * consecutive equal `activeSkill` values measure skill dwell `D`; the cache split gives the
@@ -79,11 +110,13 @@ export interface RuntimeOptions {
79
110
  * flows here for its child run. Undefined ⇒ the kernel default. */
80
111
  maxTotalTokens?: number;
81
112
  sessionLog: SessionLog;
113
+ compressionStore?: ArchiveStore;
82
114
  executionPlane: ExecutionPlane;
83
115
  maxTokens: number;
84
116
  maxTurns?: number;
85
117
  timeoutMs?: number;
86
118
  agentId?: string;
119
+ memoryScope?: MemoryScope;
87
120
  /** I4: optional run-start memory pre-fetch hook (mirrors Node SDK). Called once per run before
88
121
  * the first LLM turn; each returned query string becomes a dreamStore search; hits page into
89
122
  * the knowledge partition before turn 1. Requires dreamStore + agentId. */
@@ -91,22 +124,31 @@ export interface RuntimeOptions {
91
124
  goal: string;
92
125
  /** K4: `"initial"` = pre-turn-1 fetch; `"renewal"` = re-fired after a sprint renewal. */
93
126
  phase?: "initial" | "renewal";
94
- }) => Promise<string[] | undefined> | string[] | undefined;
127
+ }) => Promise<MemoryQuery[] | undefined> | MemoryQuery[] | undefined;
95
128
  systemPrompt?: string;
96
129
  initialMemory?: string[];
97
130
  /** Skill name → markdown body (WASM has no filesystem). */
98
131
  skillContentMap?: Map<string, string>;
99
132
  dreamStore?: DreamStore;
133
+ /** M4: advisory callback when a recalled record crosses the promotion threshold. */
134
+ onPromotionSuggested?: (info: {
135
+ recordId: string;
136
+ recallCount: number;
137
+ }) => void;
100
138
  knowledgeSource?: KnowledgeSource;
101
139
  signalSource?: SignalSource;
102
140
  extensions?: Record<string, unknown>;
103
141
  /** Named or concrete OS profile. Defaults to the native microkernel profile. */
104
142
  osProfile?: OsProfileId | NativeOsProfile;
105
143
  governancePolicy?: GovernancePolicy;
106
- attentionPolicy?: {
107
- maxQueueSize?: number;
108
- };
109
- schedulerBudget?: SchedulerBudget;
144
+ signalPolicy?: SignalPolicy;
145
+ promptBudget?: PromptBudget;
146
+ /** Stable replayable context behavior; ratios are normalized to integer ppm. */
147
+ contextPolicy?: ContextPolicyOverridesV1;
148
+ schedulerPolicy?: SchedulerPolicy;
149
+ kernelReliability?: KernelReliabilityOptions;
150
+ /** Attempts allowed for a workflow node to satisfy its output schema, 1..16. Default: 2. */
151
+ workflowSchemaValidationAttempts?: number;
110
152
  resourceQuota?: ResourceQuota;
111
153
  /** O6: the in-kernel repeat fuse — identical tool call (same name AND args) `denyAfter` turns in a
112
154
  * row ⇒ deny + directive note; `terminateAfter` ⇒ run ends `no_progress`. Defaults 5/8; `false`
@@ -182,9 +224,11 @@ export interface RuntimeOptions {
182
224
  dreamSystemPrompt?: string;
183
225
  resultSpool?: LargeResultSpool;
184
226
  }
227
+ export type OperationCancellationReason = "user" | "deadline" | "lease_lost" | "host_shutdown";
185
228
  export declare class RuntimeRunner {
186
229
  private readonly opts;
187
230
  private interrupted;
231
+ private cancellationReason;
188
232
  /** #2-B-ii: aborts the in-flight provider stream on interrupt/preempt. Recreated per `execute`. */
189
233
  private abortController;
190
234
  private pendingObservations;
@@ -201,16 +245,18 @@ export declare class RuntimeRunner {
201
245
  /** K4: the active run's goal, kept for the renewal-boundary memory re-query. */
202
246
  private currentGoal;
203
247
  private nextArchiveStart;
248
+ private pendingPageOutArchives;
249
+ private activePageOutArchive;
204
250
  /** M5 v2.1: sub-workflow specs a top-level agent authored via `start_workflow`, awaiting auto-drive
205
251
  * at the next safe point (after the tool turn resolves, kernel back in Reason). */
206
252
  private pendingAuthoredWorkflows;
207
- private pendingSpoolOutputs;
253
+ private workflowContinuation;
208
254
  constructor(opts: RuntimeOptions);
209
255
  get hostOptions(): RuntimeOptions;
210
- interrupt(): void;
256
+ interrupt(reason?: OperationCancellationReason): void;
211
257
  /** Push a contextual note into the run's signal stream (the system-reminder channel): it drains at
212
- * the next turn boundary, routes through the kernel attention policy, and once acted on — renders
213
- * as a `[SIGNAL] <text>` line in the volatile state turn plus a durable directive. `urgency` maps to
258
+ * the next turn boundary, routes through the kernel attention policy, and renders once as a
259
+ * `[SIGNAL] <text>` line in the volatile state turn. `urgency` maps to
214
260
  * the kernel disposition ladder: `"normal"` queues (default), `"high"` soft-interrupts, `"critical"`
215
261
  * preempts. */
216
262
  injectNote(text: string, urgency?: RuntimeSignal["urgency"]): void;
@@ -220,17 +266,21 @@ export declare class RuntimeRunner {
220
266
  /** Injected-note drain shared with the main loop's per-turn poll: injected notes first (FIFO), then
221
267
  * the configured `signalSource` — one code path so the two inbound channels never drift. */
222
268
  private nextInboundSignal;
269
+ private consumeInboundSignal;
223
270
  run(req: {
224
271
  sessionId: string;
225
272
  goal: string;
226
273
  criteria?: string[];
227
274
  extensions?: Record<string, unknown>;
275
+ attachments?: import("../types.js").ContentPart[];
228
276
  inheritEvents?: Array<{
229
277
  seq: number;
230
278
  event: SessionEvent;
231
279
  }>;
232
280
  }): AsyncIterable<StreamEvent>;
233
281
  wake(sessionId: string, extensions?: Record<string, unknown>): AsyncIterable<StreamEvent>;
282
+ writeMemory(memory: MemoryRecord, sessionId?: string): Promise<void>;
283
+ private appendMemorySyscallObservations;
234
284
  /** Push content into Slot 2 (system_knowledge) via add_knowledge_message.
235
285
  * K1: `opts.key` gives the entry identity — a same-key push upserts (applied at the next
236
286
  * compaction/renewal boundary) instead of appending a duplicate. `opts.pinned` exempts the
@@ -248,13 +298,11 @@ export declare class RuntimeRunner {
248
298
  private resolveKernelSuspend;
249
299
  /**
250
300
  * O7: resolve a `read_result` meta-tool call to the full text of a previously-evicted tool
251
- * output. Resolution order: (a) this turn's in-memory `pendingSpoolOutputs` map, (b) the result
252
- * spool (persisted once the kernel observation `large_result_spooled` was processed), (c) a
253
- * session-log scan for the original `tool_completed` event carrying that `call_id`. Slices the
254
- * resolved text by `[offset, offset + maxBytes)` (plain string slice — "bytes-ish").
301
+ * output. Resolution order: (a) the result spool committed by `large_result_spool_result`,
302
+ * (b) a session-log scan for the original `tool_completed` event carrying that `call_id`.
303
+ * Slices the resolved text by `[offset, offset + maxBytes)` (plain string slice "bytes-ish").
255
304
  */
256
305
  private resolveReadResult;
257
- dream(agentId: string, nowMs?: number): Promise<DreamResult>;
258
306
  private execute;
259
307
  spawnSubAgent(spec: AgentRunSpec): Promise<SubAgentResult>;
260
308
  /**
@@ -290,23 +338,14 @@ export declare class RuntimeRunner {
290
338
  */
291
339
  private bootstrapWorkflowKernel;
292
340
  runWorkflow(spec: WorkflowSpec, opts?: {
293
- resumedCompleted?: string[];
294
- /** W-1: recovered completions WITH control signals (classify branch / loop stop) — lowered to
295
- * the kernel's `resumed_results` so control flow replays faithfully. Supersedes
296
- * `resumedCompleted` for ids present in both. */
297
- resumedResults?: RecoveredNodeCompletion[];
341
+ /** Typed recovered terminal outcomes, including control signals and output. */
342
+ resumedOutcomes?: RecoveredNodeOutcome[];
298
343
  resumedSubmissions?: Record<string, unknown>[][];
299
344
  /** R3-1: original base index per submission batch (parallel to resumedSubmissions). */
300
345
  resumedSubmissionBases?: number[];
301
- /** W-1: recovered node outputs (agent id → output text) to pre-seed the driver's outputs map. */
302
- resumedOutputs?: Map<string, string>;
303
346
  /** Standalone session id when bootstrapping (no active parent run). Defaults to a fresh uuid. */
304
347
  sessionId?: string;
305
- }): Promise<{
306
- completed: string[];
307
- failed: string[];
308
- outputs: Record<string, string>;
309
- }>;
348
+ }): Promise<WorkflowOutcome>;
310
349
  /**
311
350
  * M5/G1: bootstrap an **agent-authored** workflow ("the model writes its own harness"). Routes the
312
351
  * spec through the agent-reachable `Syscall::LoadWorkflow` (`submit_workflow`): with no workflow
@@ -315,11 +354,7 @@ export declare class RuntimeRunner {
315
354
  */
316
355
  bootstrapWorkflow(spec: WorkflowSpec, opts?: {
317
356
  submitterAgentId?: string;
318
- }): Promise<{
319
- completed: string[];
320
- failed: string[];
321
- outputs: Record<string, string>;
322
- }>;
357
+ }): Promise<WorkflowOutcome>;
323
358
  /**
324
359
  * M5 v2.1: drive the sub-workflow(s) a top-level agent authored via `start_workflow`, at the safe
325
360
  * point (tool turn resolved → kernel in Reason). Each runs in THIS kernel (the kernel resumes the
@@ -349,10 +384,7 @@ export declare class RuntimeRunner {
349
384
  */
350
385
  resumeWorkflow(spec: WorkflowSpec, opts?: {
351
386
  sessionId?: string;
352
- }): Promise<{
353
- completed: string[];
354
- failed: string[];
355
- }>;
387
+ }): Promise<WorkflowOutcome>;
356
388
  private appendObservations;
357
389
  /** I4 + K4: fetch long-term memory hits for the current goal and land them in `history` as an
358
390
  * ordinary user turn — single-use retrieval content that decays with the compression pyramid,