@deepstrike/sdk 0.2.3 → 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.
Files changed (35) hide show
  1. package/README.md +287 -70
  2. package/dist/collaboration/modes/creator-verifier.d.ts +0 -3
  3. package/dist/collaboration/modes/creator-verifier.js +2 -6
  4. package/dist/governance.d.ts +36 -0
  5. package/dist/governance.js +22 -0
  6. package/dist/index.d.ts +11 -5
  7. package/dist/index.js +5 -1
  8. package/dist/memory/agent.d.ts +111 -0
  9. package/dist/memory/agent.js +151 -0
  10. package/dist/memory/protocols.d.ts +56 -0
  11. package/dist/providers/deepseek.js +13 -1
  12. package/dist/runtime/execution-plane.d.ts +6 -9
  13. package/dist/runtime/execution-plane.js +53 -25
  14. package/dist/runtime/kernel-event-log.d.ts +26 -0
  15. package/dist/runtime/kernel-event-log.js +220 -0
  16. package/dist/runtime/kernel-primitives-dashboard.d.ts +44 -0
  17. package/dist/runtime/kernel-primitives-dashboard.js +135 -0
  18. package/dist/runtime/kernel-step.d.ts +25 -1
  19. package/dist/runtime/kernel-step.js +12 -3
  20. package/dist/runtime/large-result-spool.d.ts +84 -0
  21. package/dist/runtime/large-result-spool.js +167 -0
  22. package/dist/runtime/os-profile.d.ts +18 -0
  23. package/dist/runtime/os-profile.js +47 -0
  24. package/dist/runtime/os-snapshot.d.ts +35 -0
  25. package/dist/runtime/os-snapshot.js +128 -0
  26. package/dist/runtime/runner.d.ts +62 -9
  27. package/dist/runtime/runner.js +425 -135
  28. package/dist/runtime/session-log.d.ts +118 -4
  29. package/dist/runtime/session-log.js +15 -4
  30. package/dist/runtime/sub-agent-orchestrator.d.ts +2 -2
  31. package/dist/runtime/sub-agent-orchestrator.js +14 -23
  32. package/dist/types/agent.d.ts +12 -3
  33. package/dist/types/agent.js +18 -0
  34. package/dist/types.d.ts +22 -0
  35. 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,34 +126,116 @@ 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: "agent_spawned";
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;
228
+ } | {
229
+ kind: "memory_validation_failed";
230
+ turn: number;
231
+ category?: KernelEventCategory;
232
+ primitive?: KernelPrimitive;
233
+ memory_id: string;
234
+ error: string;
235
+ } | {
236
+ kind: "memory_retrieval_result";
237
+ selected_memory_ids: string[];
238
+ selection_rationale: string;
125
239
  } | {
126
240
  kind: "run_terminal";
127
241
  reason: string;
@@ -134,7 +248,7 @@ export type SessionEvent = {
134
248
  };
135
249
  export interface SessionLog {
136
250
  append(sessionId: string, event: SessionEvent): Promise<number>;
137
- read(sessionId: string, fromSeq?: number): Promise<Array<{
251
+ read(sessionId: string, fromSeq?: number, primitiveFilter?: KernelPrimitive): Promise<Array<{
138
252
  seq: number;
139
253
  event: SessionEvent;
140
254
  }>>;
@@ -143,7 +257,7 @@ export interface SessionLog {
143
257
  export declare class InMemorySessionLog implements SessionLog {
144
258
  private store;
145
259
  append(sessionId: string, event: SessionEvent): Promise<number>;
146
- read(sessionId: string, fromSeq?: number): Promise<Array<{
260
+ read(sessionId: string, fromSeq?: number, primitiveFilter?: KernelPrimitive): Promise<Array<{
147
261
  seq: number;
148
262
  event: SessionEvent;
149
263
  }>>;
@@ -156,7 +270,7 @@ export declare class FileSessionLog implements SessionLog {
156
270
  private path;
157
271
  private nextSeq;
158
272
  append(sessionId: string, event: SessionEvent): Promise<number>;
159
- read(sessionId: string, fromSeq?: number): Promise<Array<{
273
+ read(sessionId: string, fromSeq?: number, primitiveFilter?: KernelPrimitive): Promise<Array<{
160
274
  seq: number;
161
275
  event: SessionEvent;
162
276
  }>>;
@@ -2,6 +2,7 @@ import { createWriteStream, createReadStream } from "node:fs";
2
2
  import { mkdir } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { createInterface } from "node:readline";
5
+ import { primitiveForKind } from "./kernel-event-log.js";
5
6
  export class InMemorySessionLog {
6
7
  store = new Map();
7
8
  async append(sessionId, event) {
@@ -12,8 +13,15 @@ export class InMemorySessionLog {
12
13
  entries.push({ seq, event });
13
14
  return seq;
14
15
  }
15
- async read(sessionId, fromSeq = 0) {
16
- return (this.store.get(sessionId) ?? []).filter(e => e.seq >= fromSeq);
16
+ async read(sessionId, fromSeq = 0, primitiveFilter) {
17
+ const entries = this.store.get(sessionId) ?? [];
18
+ return entries.filter(e => {
19
+ if (e.seq < fromSeq)
20
+ return false;
21
+ if (primitiveFilter && primitiveForKind(e.event.kind) !== primitiveFilter)
22
+ return false;
23
+ return true;
24
+ });
17
25
  }
18
26
  async latestSeq(sessionId) {
19
27
  const entries = this.store.get(sessionId);
@@ -56,7 +64,7 @@ export class FileSessionLog {
56
64
  });
57
65
  return seq;
58
66
  }
59
- async read(sessionId, fromSeq = 0) {
67
+ async read(sessionId, fromSeq = 0, primitiveFilter) {
60
68
  const results = [];
61
69
  try {
62
70
  const rl = createInterface({
@@ -67,8 +75,11 @@ export class FileSessionLog {
67
75
  if (!line.trim())
68
76
  continue;
69
77
  const entry = JSON.parse(line);
70
- if (entry.seq >= fromSeq)
78
+ if (entry.seq >= fromSeq) {
79
+ if (primitiveFilter && primitiveForKind(entry.event.kind) !== primitiveFilter)
80
+ continue;
71
81
  results.push(entry);
82
+ }
72
83
  }
73
84
  }
74
85
  catch (err) {
@@ -1,12 +1,12 @@
1
1
  import type { StreamEvent } from "../types.js";
2
- import type { AgentRunSpec, AgentSpawnedObservation, SubAgentResult } from "../types/agent.js";
2
+ import type { AgentRunSpec, AgentProcessChangedObservation, SubAgentResult } from "../types/agent.js";
3
3
  import type { RuntimeOptions } from "./runner.js";
4
4
  import type { SessionLog } from "./session-log.js";
5
5
  export interface SubAgentRunContext {
6
6
  parentOpts: RuntimeOptions;
7
7
  parentSessionId: string;
8
8
  spec: AgentRunSpec;
9
- manifest: AgentSpawnedObservation;
9
+ manifest: AgentProcessChangedObservation;
10
10
  sessionLog: SessionLog;
11
11
  harness?: {
12
12
  evalProvider: import("../types.js").LLMProvider;
@@ -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) {
@@ -109,31 +109,22 @@ export async function spawnStandalone(parentOpts, parentSessionId, spec, orchest
109
109
  spec: agentRunSpecToKernel(spec),
110
110
  parent_session_id: parentSessionId,
111
111
  });
112
- const spawned = observations.find(o => o.kind === "agent_spawned");
113
- if (!spawned || typeof spawned.agent_id !== "string") {
114
- throw new Error("spawn_sub_agent did not emit agent_spawned");
112
+ const spawned = findSpawnProcessObservation(observations);
113
+ if (!spawned) {
114
+ throw new Error("spawn_sub_agent did not emit agent_process_changed");
115
115
  }
116
- const turn = spawned.turn ?? 0;
116
+ const manifest = spawnObservationToManifest(spawned, spec, parentSessionId);
117
117
  await parentOpts.sessionLog.append(parentSessionId, {
118
- kind: "agent_spawned",
119
- turn,
120
- agent_id: spawned.agent_id,
121
- parent_session_id: spawned.parent_session_id ?? parentSessionId,
122
- role: spawned.role ?? spec.role,
123
- isolation: spawned.isolation ?? spec.isolation ?? "shared",
124
- context_inheritance: spawned.context_inheritance ?? "none",
125
- permitted_capability_ids: spawned.permitted_capability_ids ?? [],
118
+ kind: "agent_process_changed",
119
+ turn: manifest.turn ?? 0,
120
+ agent_id: manifest.agent_id,
121
+ parent_session_id: manifest.parent_session_id,
122
+ role: manifest.role,
123
+ isolation: manifest.isolation,
124
+ context_inheritance: manifest.context_inheritance,
125
+ state: "running",
126
+ permitted_capability_ids: manifest.permitted_capability_ids ?? [],
126
127
  });
127
- const manifest = {
128
- kind: "agent_spawned",
129
- turn,
130
- agent_id: spawned.agent_id,
131
- parent_session_id: spawned.parent_session_id ?? parentSessionId,
132
- role: spawned.role ?? spec.role,
133
- isolation: spawned.isolation ?? spec.isolation ?? "shared",
134
- context_inheritance: spawned.context_inheritance ?? "none",
135
- permitted_capability_ids: spawned.permitted_capability_ids ?? [],
136
- };
137
128
  return orchestrator.run({
138
129
  parentOpts,
139
130
  parentSessionId,
@@ -24,16 +24,25 @@ export interface AgentRunSpec {
24
24
  milestones?: MilestoneContract;
25
25
  metadata?: Record<string, unknown>;
26
26
  }
27
- export interface AgentSpawnedObservation {
28
- kind: "agent_spawned";
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
- permitted_capability_ids: string[];
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
@@ -141,6 +141,19 @@ export interface PermissionRequestEvent extends StreamEvent {
141
141
  arguments: string;
142
142
  reason: string;
143
143
  }
144
+ export interface PermissionResponse {
145
+ approved: boolean;
146
+ responder?: string;
147
+ reason?: string;
148
+ }
149
+ export interface PermissionResolvedEvent extends StreamEvent {
150
+ type: "permission_resolved";
151
+ callId: string;
152
+ toolName: string;
153
+ approved: boolean;
154
+ responder: string;
155
+ reason?: string;
156
+ }
144
157
  export interface ToolDeniedEvent extends StreamEvent {
145
158
  type: "tool_denied";
146
159
  callId: string;
@@ -221,6 +234,15 @@ export interface LLMProvider {
221
234
  export interface AsyncSummarizer {
222
235
  summarize(archived: Message[], action: string): Promise<string>;
223
236
  }
237
+ /**
238
+ * Long-term memory summarizer for semantic `page_out` events (Layer 5 contract).
239
+ * The kernel emits `page_out { tier_hint: "semantic" }`; the SDK persists an LLM summary to DreamStore.
240
+ */
241
+ export interface DreamSummarizer {
242
+ summarize(archived: Message[], context: {
243
+ action?: string;
244
+ }): Promise<string>;
245
+ }
224
246
  export interface TaskUpdate {
225
247
  plan?: string[];
226
248
  currentStep?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepstrike/sdk",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "DeepStrike Node.js SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@anthropic-ai/sdk": "^0.99.0",
23
- "@deepstrike/core": "0.2.3",
23
+ "@deepstrike/core": "0.2.5",
24
24
  "@google/generative-ai": "^0.24.1",
25
25
  "openai": "^5.23.2"
26
26
  },