@deepstrike/wasm 0.2.1 → 0.2.5
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 +29 -2
- package/dist/governance.d.ts +32 -0
- package/dist/governance.js +18 -0
- package/dist/index.d.ts +2 -2
- package/dist/providers/anthropic.js +20 -3
- package/dist/providers/base.js +11 -1
- package/dist/runtime/execution-plane.d.ts +6 -3
- package/dist/runtime/execution-plane.js +54 -23
- package/dist/runtime/kernel-event-log.d.ts +26 -0
- package/dist/runtime/kernel-event-log.js +212 -0
- package/dist/runtime/kernel-step.d.ts +21 -1
- package/dist/runtime/kernel-step.js +9 -0
- package/dist/runtime/large-result-spool.d.ts +49 -0
- package/dist/runtime/large-result-spool.js +137 -0
- package/dist/runtime/os-profile.d.ts +7 -0
- package/dist/runtime/os-profile.js +6 -0
- package/dist/runtime/os-snapshot.d.ts +31 -0
- package/dist/runtime/os-snapshot.js +108 -0
- package/dist/runtime/runner.d.ts +20 -5
- package/dist/runtime/runner.js +305 -147
- package/dist/runtime/session-log.d.ts +110 -3
- package/dist/runtime/session-log.js +10 -2
- package/dist/runtime/sub-agent-orchestrator.d.ts +2 -2
- package/dist/runtime/sub-agent-orchestrator.js +14 -23
- package/dist/runtime/types/agent.d.ts +12 -3
- package/dist/runtime/types/agent.js +18 -0
- package/dist/types.d.ts +24 -0
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProviderReplay, ToolCall, ToolErrorKind } from "../types.js";
|
|
2
|
+
import type { KernelEventCategory, KernelPrimitive } from "./kernel-event-log.js";
|
|
2
3
|
export type RollbackReason = {
|
|
3
4
|
kind: "fatal_tool_error";
|
|
4
5
|
tool_name: string;
|
|
@@ -73,20 +74,51 @@ export type SessionEvent = {
|
|
|
73
74
|
} | {
|
|
74
75
|
kind: "compressed";
|
|
75
76
|
turn: number;
|
|
77
|
+
category?: KernelEventCategory;
|
|
78
|
+
primitive?: KernelPrimitive;
|
|
76
79
|
archived_seq_range: [number, number];
|
|
77
80
|
action?: "snip_compact" | "micro_compact" | "context_collapse" | "auto_compact";
|
|
78
81
|
summary?: string;
|
|
79
82
|
summary_tokens?: number;
|
|
80
83
|
archive_ref?: string;
|
|
81
84
|
preserved_refs?: string[];
|
|
85
|
+
} | {
|
|
86
|
+
kind: "page_out";
|
|
87
|
+
turn: number;
|
|
88
|
+
category?: KernelEventCategory;
|
|
89
|
+
primitive?: KernelPrimitive;
|
|
90
|
+
action?: "snip_compact" | "micro_compact" | "context_collapse" | "auto_compact";
|
|
91
|
+
summary?: string;
|
|
92
|
+
tier_hint?: string;
|
|
93
|
+
message_count?: number;
|
|
94
|
+
} | {
|
|
95
|
+
kind: "page_in";
|
|
96
|
+
turn: number;
|
|
97
|
+
category?: KernelEventCategory;
|
|
98
|
+
primitive?: KernelPrimitive;
|
|
99
|
+
entry_count: number;
|
|
100
|
+
} | {
|
|
101
|
+
kind: "large_result_spooled";
|
|
102
|
+
turn: number;
|
|
103
|
+
category?: KernelEventCategory;
|
|
104
|
+
primitive?: KernelPrimitive;
|
|
105
|
+
call_id: string;
|
|
106
|
+
tool: string;
|
|
107
|
+
original_size: number;
|
|
108
|
+
preview_size: number;
|
|
109
|
+
spool_ref?: string;
|
|
82
110
|
} | {
|
|
83
111
|
kind: "rollbacked";
|
|
84
112
|
turn: number;
|
|
113
|
+
category?: KernelEventCategory;
|
|
114
|
+
primitive?: KernelPrimitive;
|
|
85
115
|
checkpoint_history_len: number;
|
|
86
116
|
reason?: RollbackReason;
|
|
87
117
|
} | {
|
|
88
118
|
kind: "capability_changed";
|
|
89
119
|
turn: number;
|
|
120
|
+
category?: KernelEventCategory;
|
|
121
|
+
primitive?: KernelPrimitive;
|
|
90
122
|
added: string[];
|
|
91
123
|
removed: string[];
|
|
92
124
|
change_kind?: string;
|
|
@@ -94,43 +126,118 @@ export type SessionEvent = {
|
|
|
94
126
|
version?: string;
|
|
95
127
|
mounted_by?: string;
|
|
96
128
|
mount_reason?: string;
|
|
129
|
+
} | {
|
|
130
|
+
kind: "context_renewed";
|
|
131
|
+
turn: number;
|
|
132
|
+
category?: KernelEventCategory;
|
|
133
|
+
primitive?: KernelPrimitive;
|
|
134
|
+
sprint: number;
|
|
135
|
+
handoff_ref: string;
|
|
136
|
+
} | {
|
|
137
|
+
kind: "suspended";
|
|
138
|
+
turn: number;
|
|
139
|
+
category?: KernelEventCategory;
|
|
140
|
+
primitive?: KernelPrimitive;
|
|
141
|
+
reason: string;
|
|
142
|
+
pending_calls?: string[];
|
|
143
|
+
} | {
|
|
144
|
+
kind: "resumed";
|
|
145
|
+
turn: number;
|
|
146
|
+
category?: KernelEventCategory;
|
|
147
|
+
primitive?: KernelPrimitive;
|
|
148
|
+
approved?: string[];
|
|
149
|
+
denied?: string[];
|
|
150
|
+
} | {
|
|
151
|
+
kind: "tool_gated";
|
|
152
|
+
turn: number;
|
|
153
|
+
category?: KernelEventCategory;
|
|
154
|
+
primitive?: KernelPrimitive;
|
|
155
|
+
call_id: string;
|
|
156
|
+
tool: string;
|
|
157
|
+
reason: string;
|
|
158
|
+
} | {
|
|
159
|
+
kind: "signal_disposed";
|
|
160
|
+
turn: number;
|
|
161
|
+
category?: KernelEventCategory;
|
|
162
|
+
primitive?: KernelPrimitive;
|
|
163
|
+
signal_id: string;
|
|
164
|
+
disposition: string;
|
|
165
|
+
queue_depth: number;
|
|
166
|
+
} | {
|
|
167
|
+
kind: "budget_exceeded";
|
|
168
|
+
turn: number;
|
|
169
|
+
category?: KernelEventCategory;
|
|
170
|
+
primitive?: KernelPrimitive;
|
|
171
|
+
budget: string;
|
|
97
172
|
} | {
|
|
98
173
|
kind: "milestone_advanced";
|
|
99
174
|
turn: number;
|
|
175
|
+
category?: KernelEventCategory;
|
|
176
|
+
primitive?: KernelPrimitive;
|
|
100
177
|
phase_id: string;
|
|
101
178
|
capabilities_unlocked: string[];
|
|
102
179
|
} | {
|
|
103
180
|
kind: "milestone_blocked";
|
|
104
181
|
turn: number;
|
|
182
|
+
category?: KernelEventCategory;
|
|
183
|
+
primitive?: KernelPrimitive;
|
|
105
184
|
phase_id: string;
|
|
106
185
|
reason: string;
|
|
107
186
|
} | {
|
|
108
187
|
kind: "milestone_evidence";
|
|
109
188
|
turn: number;
|
|
189
|
+
category?: KernelEventCategory;
|
|
190
|
+
primitive?: KernelPrimitive;
|
|
110
191
|
phase_id: string;
|
|
111
192
|
evidence: string[];
|
|
112
193
|
} | {
|
|
113
194
|
kind: "checkpoint_taken";
|
|
114
195
|
turn: number;
|
|
196
|
+
category?: KernelEventCategory;
|
|
197
|
+
primitive?: KernelPrimitive;
|
|
115
198
|
history_len: number;
|
|
116
199
|
} | {
|
|
117
|
-
kind: "
|
|
200
|
+
kind: "agent_process_changed";
|
|
118
201
|
turn: number;
|
|
202
|
+
category?: KernelEventCategory;
|
|
203
|
+
primitive?: KernelPrimitive;
|
|
119
204
|
agent_id: string;
|
|
120
205
|
parent_session_id: string;
|
|
121
206
|
role: string;
|
|
122
207
|
isolation: string;
|
|
123
208
|
context_inheritance: string;
|
|
209
|
+
state?: string;
|
|
124
210
|
permitted_capability_ids: string[];
|
|
211
|
+
result_termination?: string;
|
|
212
|
+
} | {
|
|
213
|
+
kind: "memory_written";
|
|
214
|
+
turn: number;
|
|
215
|
+
category?: KernelEventCategory;
|
|
216
|
+
primitive?: KernelPrimitive;
|
|
217
|
+
memory_id: string;
|
|
218
|
+
memory_kind: string;
|
|
219
|
+
size_bytes: number;
|
|
220
|
+
} | {
|
|
221
|
+
kind: "memory_queried";
|
|
222
|
+
turn: number;
|
|
223
|
+
category?: KernelEventCategory;
|
|
224
|
+
primitive?: KernelPrimitive;
|
|
225
|
+
query_context: string;
|
|
226
|
+
requested_k: number;
|
|
227
|
+
requires_async_response: boolean;
|
|
125
228
|
} | {
|
|
126
229
|
kind: "run_terminal";
|
|
127
230
|
reason: string;
|
|
128
231
|
turns_used: number;
|
|
129
232
|
total_tokens: number;
|
|
233
|
+
} | {
|
|
234
|
+
kind: "summary_upgraded";
|
|
235
|
+
compressed_seq: number;
|
|
236
|
+
summary: string;
|
|
130
237
|
};
|
|
131
238
|
export interface SessionLog {
|
|
132
239
|
append(sessionId: string, event: SessionEvent): Promise<number>;
|
|
133
|
-
read(sessionId: string, fromSeq?: number): Promise<Array<{
|
|
240
|
+
read(sessionId: string, fromSeq?: number, primitiveFilter?: KernelPrimitive): Promise<Array<{
|
|
134
241
|
seq: number;
|
|
135
242
|
event: SessionEvent;
|
|
136
243
|
}>>;
|
|
@@ -139,7 +246,7 @@ export interface SessionLog {
|
|
|
139
246
|
export declare class InMemorySessionLog implements SessionLog {
|
|
140
247
|
private store;
|
|
141
248
|
append(sessionId: string, event: SessionEvent): Promise<number>;
|
|
142
|
-
read(sessionId: string, fromSeq?: number): Promise<Array<{
|
|
249
|
+
read(sessionId: string, fromSeq?: number, primitiveFilter?: KernelPrimitive): Promise<Array<{
|
|
143
250
|
seq: number;
|
|
144
251
|
event: SessionEvent;
|
|
145
252
|
}>>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { primitiveForKind } from "./kernel-event-log.js";
|
|
1
2
|
export class InMemorySessionLog {
|
|
2
3
|
store = new Map();
|
|
3
4
|
async append(sessionId, event) {
|
|
@@ -8,8 +9,15 @@ export class InMemorySessionLog {
|
|
|
8
9
|
entries.push({ seq, event });
|
|
9
10
|
return seq;
|
|
10
11
|
}
|
|
11
|
-
async read(sessionId, fromSeq = 0) {
|
|
12
|
-
|
|
12
|
+
async read(sessionId, fromSeq = 0, primitiveFilter) {
|
|
13
|
+
const entries = this.store.get(sessionId) ?? [];
|
|
14
|
+
return entries.filter(e => {
|
|
15
|
+
if (e.seq < fromSeq)
|
|
16
|
+
return false;
|
|
17
|
+
if (primitiveFilter && primitiveForKind(e.event.kind) !== primitiveFilter)
|
|
18
|
+
return false;
|
|
19
|
+
return true;
|
|
20
|
+
});
|
|
13
21
|
}
|
|
14
22
|
async latestSeq(sessionId) {
|
|
15
23
|
const entries = this.store.get(sessionId);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { AgentRunSpec,
|
|
1
|
+
import type { AgentRunSpec, AgentProcessChangedObservation, SubAgentResult } from "./types/agent.js";
|
|
2
2
|
import type { RuntimeOptions } from "./runner.js";
|
|
3
3
|
import type { SessionLog } from "./session-log.js";
|
|
4
4
|
export interface SubAgentRunContext {
|
|
5
5
|
parentOpts: RuntimeOptions;
|
|
6
6
|
parentSessionId: string;
|
|
7
7
|
spec: AgentRunSpec;
|
|
8
|
-
manifest:
|
|
8
|
+
manifest: AgentProcessChangedObservation;
|
|
9
9
|
sessionLog: SessionLog;
|
|
10
10
|
}
|
|
11
11
|
/** Host-side driver for kernel-isolated sub-agent runs. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { agentRunSpecToKernel } from "./types/agent.js";
|
|
1
|
+
import { agentRunSpecToKernel, findSpawnProcessObservation, spawnObservationToManifest } from "./types/agent.js";
|
|
2
2
|
import { FilteredExecutionPlane } from "./filtered-plane.js";
|
|
3
3
|
import { kernelApply } from "./kernel-step.js";
|
|
4
4
|
function terminationFromStatus(status) {
|
|
@@ -77,31 +77,22 @@ export async function spawnStandalone(parentOpts, parentSessionId, spec, orchest
|
|
|
77
77
|
spec: agentRunSpecToKernel(spec),
|
|
78
78
|
parent_session_id: parentSessionId,
|
|
79
79
|
});
|
|
80
|
-
const spawned = observations
|
|
81
|
-
if (!spawned
|
|
82
|
-
throw new Error("spawn_sub_agent did not emit
|
|
80
|
+
const spawned = findSpawnProcessObservation(observations);
|
|
81
|
+
if (!spawned) {
|
|
82
|
+
throw new Error("spawn_sub_agent did not emit agent_process_changed");
|
|
83
83
|
}
|
|
84
|
-
const
|
|
84
|
+
const manifest = spawnObservationToManifest(spawned, spec, parentSessionId);
|
|
85
85
|
await parentOpts.sessionLog.append(parentSessionId, {
|
|
86
|
-
kind: "
|
|
87
|
-
turn,
|
|
88
|
-
agent_id:
|
|
89
|
-
parent_session_id:
|
|
90
|
-
role:
|
|
91
|
-
isolation:
|
|
92
|
-
context_inheritance:
|
|
93
|
-
|
|
86
|
+
kind: "agent_process_changed",
|
|
87
|
+
turn: manifest.turn ?? 0,
|
|
88
|
+
agent_id: manifest.agent_id,
|
|
89
|
+
parent_session_id: manifest.parent_session_id,
|
|
90
|
+
role: manifest.role,
|
|
91
|
+
isolation: manifest.isolation,
|
|
92
|
+
context_inheritance: manifest.context_inheritance,
|
|
93
|
+
state: "running",
|
|
94
|
+
permitted_capability_ids: manifest.permitted_capability_ids ?? [],
|
|
94
95
|
});
|
|
95
|
-
const manifest = {
|
|
96
|
-
kind: "agent_spawned",
|
|
97
|
-
turn,
|
|
98
|
-
agent_id: spawned.agent_id,
|
|
99
|
-
parent_session_id: spawned.parent_session_id ?? parentSessionId,
|
|
100
|
-
role: spawned.role ?? spec.role,
|
|
101
|
-
isolation: spawned.isolation ?? spec.isolation ?? "shared",
|
|
102
|
-
context_inheritance: spawned.context_inheritance ?? "none",
|
|
103
|
-
permitted_capability_ids: spawned.permitted_capability_ids ?? [],
|
|
104
|
-
};
|
|
105
96
|
return orchestrator.run({
|
|
106
97
|
parentOpts,
|
|
107
98
|
parentSessionId,
|
|
@@ -24,16 +24,25 @@ export interface AgentRunSpec {
|
|
|
24
24
|
milestones?: MilestoneContract;
|
|
25
25
|
metadata?: Record<string, unknown>;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
/** Kernel process-table observation (Phase 3 canonical spawn signal). */
|
|
28
|
+
export interface AgentProcessChangedObservation {
|
|
29
|
+
kind: "agent_process_changed";
|
|
29
30
|
turn?: number;
|
|
30
31
|
agent_id: string;
|
|
31
32
|
parent_session_id: string;
|
|
32
33
|
role: string;
|
|
33
34
|
isolation: string;
|
|
34
35
|
context_inheritance: string;
|
|
35
|
-
|
|
36
|
+
state?: string;
|
|
37
|
+
permitted_capability_ids?: string[];
|
|
38
|
+
result_termination?: string;
|
|
36
39
|
}
|
|
40
|
+
/** Map kernel spawn observation → host manifest. */
|
|
41
|
+
export declare function spawnObservationToManifest(obs: AgentProcessChangedObservation | Record<string, unknown>, spec: AgentRunSpec, parentSessionId: string): AgentProcessChangedObservation;
|
|
42
|
+
export declare function findSpawnProcessObservation(observations: Array<{
|
|
43
|
+
kind: string;
|
|
44
|
+
agent_id?: string;
|
|
45
|
+
}>): AgentProcessChangedObservation | undefined;
|
|
37
46
|
export interface LoopResult {
|
|
38
47
|
termination: TerminationReason | string;
|
|
39
48
|
finalMessage?: Message;
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/** Map kernel spawn observation → host manifest. */
|
|
2
|
+
export function spawnObservationToManifest(obs, spec, parentSessionId) {
|
|
3
|
+
const o = obs;
|
|
4
|
+
return {
|
|
5
|
+
kind: "agent_process_changed",
|
|
6
|
+
turn: o.turn,
|
|
7
|
+
agent_id: String(o.agent_id ?? spec.identity.agentId),
|
|
8
|
+
parent_session_id: String(o.parent_session_id ?? parentSessionId),
|
|
9
|
+
role: String(o.role ?? spec.role),
|
|
10
|
+
isolation: String(o.isolation ?? spec.isolation ?? "shared"),
|
|
11
|
+
context_inheritance: String(o.context_inheritance ?? "none"),
|
|
12
|
+
permitted_capability_ids: o.permitted_capability_ids ?? [],
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function findSpawnProcessObservation(observations) {
|
|
16
|
+
const hit = observations.find(o => o.kind === "agent_process_changed" && typeof o.agent_id === "string");
|
|
17
|
+
return hit;
|
|
18
|
+
}
|
|
1
19
|
export function agentIdentitySub(agentId, sessionId, parentSessionId) {
|
|
2
20
|
return {
|
|
3
21
|
agentId,
|
package/dist/types.d.ts
CHANGED
|
@@ -26,6 +26,9 @@ export interface ToolSchema {
|
|
|
26
26
|
/** Structured provider context from the kernel (`call_llm` action). */
|
|
27
27
|
export interface RenderedContext {
|
|
28
28
|
systemText: string;
|
|
29
|
+
systemStable?: string;
|
|
30
|
+
systemKnowledge?: string;
|
|
31
|
+
systemVolatile?: string;
|
|
29
32
|
turns: Message[];
|
|
30
33
|
}
|
|
31
34
|
export interface StreamEvent {
|
|
@@ -38,6 +41,8 @@ export interface TextDelta extends StreamEvent {
|
|
|
38
41
|
export interface UsageEvent extends StreamEvent {
|
|
39
42
|
type: "usage";
|
|
40
43
|
totalTokens: number;
|
|
44
|
+
inputTokens?: number;
|
|
45
|
+
outputTokens?: number;
|
|
41
46
|
}
|
|
42
47
|
export interface ThinkingDelta extends StreamEvent {
|
|
43
48
|
type: "thinking_delta";
|
|
@@ -63,6 +68,7 @@ export interface DoneEvent extends StreamEvent {
|
|
|
63
68
|
iterations: number;
|
|
64
69
|
totalTokens: number;
|
|
65
70
|
status: string;
|
|
71
|
+
dreamResult?: import("./memory/index.js").DreamResult;
|
|
66
72
|
}
|
|
67
73
|
export interface ErrorEvent extends StreamEvent {
|
|
68
74
|
type: "error";
|
|
@@ -75,6 +81,19 @@ export interface PermissionRequestEvent extends StreamEvent {
|
|
|
75
81
|
arguments: string;
|
|
76
82
|
reason: string;
|
|
77
83
|
}
|
|
84
|
+
export interface PermissionResponse {
|
|
85
|
+
approved: boolean;
|
|
86
|
+
responder?: string;
|
|
87
|
+
reason?: string;
|
|
88
|
+
}
|
|
89
|
+
export interface PermissionResolvedEvent extends StreamEvent {
|
|
90
|
+
type: "permission_resolved";
|
|
91
|
+
callId: string;
|
|
92
|
+
toolName: string;
|
|
93
|
+
approved: boolean;
|
|
94
|
+
responder: string;
|
|
95
|
+
reason?: string;
|
|
96
|
+
}
|
|
78
97
|
export interface ToolDeniedEvent extends StreamEvent {
|
|
79
98
|
type: "tool_denied";
|
|
80
99
|
callId: string;
|
|
@@ -108,3 +127,8 @@ export interface LLMProvider {
|
|
|
108
127
|
complete(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>): Promise<Message>;
|
|
109
128
|
stream(context: RenderedContext, tools: ToolSchema[], extensions?: Record<string, unknown>, state?: ProviderRunState): AsyncIterable<StreamEvent>;
|
|
110
129
|
}
|
|
130
|
+
export interface DreamSummarizer {
|
|
131
|
+
summarize(archived: Message[], context: {
|
|
132
|
+
action?: string;
|
|
133
|
+
}): Promise<string>;
|
|
134
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepstrike/wasm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "DeepStrike WASM SDK — browser, Cloudflare Workers, Deno Deploy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"test": "node --experimental-vm-modules node_modules/.bin/jest"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@deepstrike/wasm-kernel": "0.2.
|
|
18
|
+
"@deepstrike/wasm-kernel": "0.2.5"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/jest": "^30.0.0",
|