@deepstrike/sdk 0.2.51 → 0.2.60

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 (148) hide show
  1. package/README.md +28 -28
  2. package/dist/agent-ir.d.ts +103 -0
  3. package/dist/agent-ir.js +134 -0
  4. package/dist/agent.d.ts +67 -0
  5. package/dist/agent.js +36 -0
  6. package/dist/collaboration/harness.js +1 -1
  7. package/dist/collaboration/modes/creator-verifier.d.ts +2 -7
  8. package/dist/collaboration/modes/creator-verifier.js +4 -6
  9. package/dist/collaboration/pool.d.ts +8 -20
  10. package/dist/collaboration/pool.js +27 -97
  11. package/dist/compat/anthropic/mcp.d.ts +15 -0
  12. package/dist/compat/anthropic/mcp.js +10 -0
  13. package/dist/compat/openai/agent.d.ts +34 -0
  14. package/dist/compat/openai/agent.js +24 -0
  15. package/dist/governance.d.ts +1 -17
  16. package/dist/governance.js +1 -34
  17. package/dist/guardrail.d.ts +6 -0
  18. package/dist/guardrail.js +1 -0
  19. package/dist/handoff-target.d.ts +12 -0
  20. package/dist/handoff-target.js +1 -0
  21. package/dist/harness/manifest.js +0 -4
  22. package/dist/index.d.ts +19 -7
  23. package/dist/index.js +8 -5
  24. package/dist/kernel.d.ts +2 -20
  25. package/dist/knowledge/public.d.ts +29 -0
  26. package/dist/knowledge/public.js +1 -0
  27. package/dist/mcp-server.d.ts +28 -0
  28. package/dist/mcp-server.js +1 -0
  29. package/dist/memory/agent.d.ts +2 -2
  30. package/dist/memory/agent.js +2 -2
  31. package/dist/memory/durable.d.ts +16 -0
  32. package/dist/memory/durable.js +46 -0
  33. package/dist/memory/in-memory-store.d.ts +9 -7
  34. package/dist/memory/in-memory-store.js +8 -2
  35. package/dist/memory/protocols.d.ts +22 -4
  36. package/dist/memory/public.d.ts +4 -3
  37. package/dist/memory/public.js +3 -2
  38. package/dist/providers/anthropic-adapter.d.ts +47 -0
  39. package/dist/providers/anthropic-adapter.js +444 -0
  40. package/dist/providers/anthropic-compatible.d.ts +2 -3
  41. package/dist/providers/anthropic-compatible.js +8 -5
  42. package/dist/providers/anthropic.d.ts +19 -23
  43. package/dist/providers/anthropic.js +169 -395
  44. package/dist/providers/base.js +43 -3
  45. package/dist/providers/capability-router.d.ts +29 -0
  46. package/dist/providers/capability-router.js +43 -0
  47. package/dist/providers/catalog.d.ts +16 -4
  48. package/dist/providers/catalog.js +112 -21
  49. package/dist/providers/content-normalization.d.ts +57 -0
  50. package/dist/providers/content-normalization.js +238 -0
  51. package/dist/providers/content-policy.d.ts +16 -0
  52. package/dist/providers/content-policy.js +39 -0
  53. package/dist/providers/credentials.d.ts +83 -0
  54. package/dist/providers/credentials.js +190 -0
  55. package/dist/providers/endpoints.d.ts +137 -0
  56. package/dist/providers/endpoints.js +128 -0
  57. package/dist/providers/factories.js +9 -3
  58. package/dist/providers/gemini-adapter.d.ts +33 -0
  59. package/dist/providers/gemini-adapter.js +272 -0
  60. package/dist/providers/gemini.d.ts +16 -3
  61. package/dist/providers/gemini.js +97 -195
  62. package/dist/providers/model-catalog.d.ts +37 -0
  63. package/dist/providers/model-catalog.js +62 -0
  64. package/dist/providers/model-registry.d.ts +98 -0
  65. package/dist/providers/model-registry.js +315 -0
  66. package/dist/providers/ollama-adapter.d.ts +65 -0
  67. package/dist/providers/ollama-adapter.js +188 -0
  68. package/dist/providers/ollama.d.ts +9 -4
  69. package/dist/providers/ollama.js +96 -109
  70. package/dist/providers/openai-chat-dialects.d.ts +154 -0
  71. package/dist/providers/openai-chat-dialects.js +179 -0
  72. package/dist/providers/openai-chat.d.ts +46 -18
  73. package/dist/providers/openai-chat.js +418 -51
  74. package/dist/providers/openai-responses-adapter.d.ts +42 -0
  75. package/dist/providers/openai-responses-adapter.js +341 -0
  76. package/dist/providers/openai-responses.d.ts +14 -33
  77. package/dist/providers/openai-responses.js +131 -264
  78. package/dist/providers/openai.d.ts +29 -76
  79. package/dist/providers/openai.js +195 -292
  80. package/dist/providers/protocol-adapter.d.ts +34 -0
  81. package/dist/providers/protocol-adapter.js +9 -0
  82. package/dist/providers/protocol-capabilities.d.ts +34 -0
  83. package/dist/providers/protocol-capabilities.js +44 -0
  84. package/dist/providers/provider-error.d.ts +31 -0
  85. package/dist/providers/provider-error.js +149 -0
  86. package/dist/providers/public.d.ts +26 -3
  87. package/dist/providers/public.js +13 -1
  88. package/dist/providers/registry.d.ts +7 -6
  89. package/dist/providers/registry.js +47 -20
  90. package/dist/providers/request-plan.d.ts +86 -0
  91. package/dist/providers/request-plan.js +175 -0
  92. package/dist/providers/usage-normalizer.d.ts +48 -0
  93. package/dist/providers/usage-normalizer.js +96 -0
  94. package/dist/providers/vendor-profiles.d.ts +2 -15
  95. package/dist/providers/vendor-profiles.js +14 -60
  96. package/dist/runtime/canonical-kernel-step.d.ts +10 -2
  97. package/dist/runtime/canonical-kernel-step.js +106 -32
  98. package/dist/runtime/context-policy.d.ts +10 -12
  99. package/dist/runtime/context-policy.js +6 -8
  100. package/dist/runtime/durable-content.d.ts +50 -0
  101. package/dist/runtime/durable-content.js +159 -0
  102. package/dist/runtime/execution-plane.d.ts +2 -2
  103. package/dist/runtime/execution-plane.js +2 -2
  104. package/dist/runtime/kernel-event-log.js +0 -1
  105. package/dist/runtime/kernel-step.d.ts +0 -1
  106. package/dist/runtime/kernel-step.js +4 -2
  107. package/dist/runtime/mcp-proxy-plane.d.ts +25 -1
  108. package/dist/runtime/mcp-proxy-plane.js +44 -6
  109. package/dist/runtime/output-schema.d.ts +1 -2
  110. package/dist/runtime/provider-replay.d.ts +1 -1
  111. package/dist/runtime/provider-replay.js +12 -27
  112. package/dist/runtime/reactive-session.d.ts +1 -1
  113. package/dist/runtime/reactive-session.js +2 -3
  114. package/dist/runtime/run-group.d.ts +1 -1
  115. package/dist/runtime/runner.d.ts +26 -40
  116. package/dist/runtime/runner.js +145 -63
  117. package/dist/runtime/session-log.d.ts +8 -1
  118. package/dist/runtime/session-log.js +42 -2
  119. package/dist/runtime/session-repair.d.ts +1 -1
  120. package/dist/runtime/session-repair.js +1 -1
  121. package/dist/runtime/sub-agent-orchestrator.d.ts +1 -1
  122. package/dist/runtime/sub-agent-orchestrator.js +8 -11
  123. package/dist/runtime/workflow-control-flow.d.ts +0 -4
  124. package/dist/runtime/workflow-control-flow.js +0 -16
  125. package/dist/session.d.ts +11 -0
  126. package/dist/session.js +1 -0
  127. package/dist/skill.d.ts +17 -0
  128. package/dist/skill.js +16 -0
  129. package/dist/skills/loader.d.ts +3 -0
  130. package/dist/tools/errors.d.ts +1 -3
  131. package/dist/tools/errors.js +1 -3
  132. package/dist/tools/index.d.ts +3 -0
  133. package/dist/types/agent.d.ts +21 -9
  134. package/dist/types/agent.js +30 -4
  135. package/dist/types.d.ts +128 -13
  136. package/package.json +3 -3
  137. package/dist/providers/deepseek.d.ts +0 -46
  138. package/dist/providers/deepseek.js +0 -97
  139. package/dist/providers/glm.d.ts +0 -25
  140. package/dist/providers/glm.js +0 -48
  141. package/dist/providers/kimi.d.ts +0 -23
  142. package/dist/providers/kimi.js +0 -30
  143. package/dist/providers/minimax.d.ts +0 -49
  144. package/dist/providers/minimax.js +0 -98
  145. package/dist/providers/profiles.d.ts +0 -1992
  146. package/dist/providers/profiles.js +0 -796
  147. package/dist/providers/qwen.d.ts +0 -38
  148. package/dist/providers/qwen.js +0 -97
package/README.md CHANGED
@@ -6,9 +6,7 @@
6
6
 
7
7
  # DeepStrike Node.js SDK
8
8
 
9
- Runtime framework built on a Rust kernel. The kernel owns loop control, context compression, governance, signal routing, and memory paging the SDK owns all I/O (LLM calls, tool execution, disk, long-term memory).
10
-
11
- Node.js is the reference SDK for the **Agent OS native profile**: declarative governance and in-kernel signal routing are enabled by default on every run.
9
+ Build Node.js Agents with providers, typed tools, memory, Skills, delegation, workflows, and durable sessions. The SDK keeps the Agent's long-running work explicit through stream events, SessionLog evidence, tool policies, and host-provided integrations.
12
10
 
13
11
  ## Install
14
12
 
@@ -82,7 +80,7 @@ const reply = await collectText(runner.run({ sessionId: "chat-1", goal: "What is
82
80
 
83
81
  Use `InMemorySessionLog` for process-local sessions or `FileSessionLog` when replay should survive restarts. `wake(sessionId)` resumes from the event log without inserting a duplicate `run_started` event.
84
82
 
85
- ### Package layout (v0.2.50)
83
+ ### Package layout
86
84
 
87
85
  The root export is the **intent layer** — what you reach for to run an agent, run a workflow, author a tool, or pick a provider (~30 symbols). Advanced machinery lives behind subpaths, so the common surface stays small and tree-shakeable:
88
86
 
@@ -92,7 +90,7 @@ The root export is the **intent layer** — what you reach for to run an agent,
92
90
  | `@deepstrike/sdk/providers` | backend factories (`deepseek`, `kimi`, `qwen`, `glm`, `minimax`, `gemini`, `ollama`), profiles, `CircuitBreaker` |
93
91
  | `@deepstrike/sdk/workflow` | `SubAgentOrchestrator`, `spawnStandalone`, reducers, contracts, handoff/modes, agent + spec types |
94
92
  | `@deepstrike/sdk/planes` | `WorktreeExecutionPlane`, `ProcessSandboxPlane`, `McpProxyPlane`, `RemoteVpcPlane`, archive/credential stores |
95
- | `@deepstrike/sdk/memory` | `DreamStore`, `WorkingMemory`, `InMemoryDreamStore`, `rankMemories`, `extractSessionMemories`, `KnowledgeSource` |
93
+ | `@deepstrike/sdk/memory` | `MemoryStore`, `WorkingMemory`, `InMemoryMemoryStore`, `rankMemories`, `extractSessionMemories`, `KnowledgeSource` |
96
94
  | `@deepstrike/sdk/harness` | `AttemptLoop`, body/judge/carry policies, `judge` |
97
95
  | `@deepstrike/sdk/os` | profiles, `KernelPrimitivesDashboard`, `primitiveForKind` / `KernelPrimitive`, signals, `PermissionManager`, replay-testing utilities |
98
96
 
@@ -161,7 +159,7 @@ for await (const event of runner.run({ sessionId: "readme-1", goal: "Summarize R
161
159
  ```text
162
160
  ┌─────────────────────────────────────────────────────────┐
163
161
  │ RuntimeRunner (Layer 1.5) │
164
- │ LLMProvider · ExecutionPlane · SessionLog · DreamStore
162
+ │ LLMProvider · ExecutionPlane · SessionLog · MemoryStore
165
163
  └───────────────────────────┬─────────────────────────────┘
166
164
  │ durable prepare / append / commit
167
165
  ┌───────────────────────────▼─────────────────────────────┐
@@ -179,7 +177,7 @@ The runner drives one durable operation loop:
179
177
 
180
178
  Kernel session events carry an optional `category` tag (`syscall` · `sched` · `mm` · `proc` · `ipc`) for diagnostics and OS snapshot rebuilds.
181
179
 
182
- ### What Agent OS gives you
180
+ ### What this enables
183
181
 
184
182
  The mechanisms above are not internal refactors — they change what you can build without custom runner code:
185
183
 
@@ -187,13 +185,13 @@ The mechanisms above are not internal refactors — they change what you can bui
187
185
  Tool calls, spawns, compression, and signals pass through one kernel gate with an explicit lifecycle (Ready / Running / Blocked / Suspended). You implement I/O; the kernel decides *when* and *whether*. Node, Python, and Rust share the same decision path, so `wake(sessionId)` and cross-language tooling see consistent behavior.
188
186
 
189
187
  **Longer, sturdier sessions (external payloads + semantic page-out)**
190
- The host atomically persists oversized tool results before submitting an `External` result. Core journals only the opaque locator, digest, size, and preview; `read_result` becomes a correlated `LoadPayload` effect. When pressure triggers semantic eviction, the SDK summarizes archived content into `DreamStore`.
188
+ The host atomically persists oversized tool results before submitting an `External` result. Core journals only the opaque locator, digest, size, and preview; `read_result` becomes a correlated `LoadPayload` effect. When pressure triggers semantic eviction, the SDK summarizes archived content into `MemoryStore`.
191
189
 
192
190
  **Safety and governance by default (OS native profile)**
193
191
  Every run loads declarative `governancePolicy` (deny / ask_user / rate-limit / param rules) and in-kernel signal routing (`signalPolicy`, default queue 64). Dangerous tools, external interrupts, and approval flows are policy — not ad-hoc `if` checks in your handlers.
194
192
 
195
193
  **Long-term memory as syscalls (Phase-7)**
196
- `writeMemory` and `queryMemory` run outside the main tool loop: kernel validation happens before `DreamStore.upsert`, while queries call `DreamStore.search` and journal `memory_retrieval_result`. Failed writes emit `memory_validation_failed` for audit; good memory is durable without polluting history.
194
+ `writeMemory` and `queryMemory` run outside the main tool loop: kernel validation happens before `MemoryStore.put`, while queries call `MemoryStore.search` and journal `memory_retrieval_result`. Failed writes emit `memory_validation_failed` for audit; good memory is durable without polluting history.
197
195
 
198
196
  **Multi-agent and multi-signal orchestration**
199
197
  Sub-agents register in the kernel process table (`agent_process_changed`); parent runs suspend explicitly until `sub_agent_completed`. Signals get disposition (Interrupt / Queue / Observe / Dropped) in-kernel, so gateways, cron, and heartbeats compose with the main loop instead of racing it.
@@ -206,7 +204,7 @@ Page-out, signals, processes, budgets, and memory events land in `SessionLog` wi
206
204
  | Policy before tools run | `governancePolicy` (default: allow-all native profile) |
207
205
  | External interrupts | `signalSource` + in-kernel `signalPolicy` |
208
206
  | Huge tool output | Canonical external payload; optional custom `payloadStore` |
209
- | Durable recall across runs | `DreamStore` + semantic `page_out` via `dreamSummarizer` |
207
+ | Durable recall across runs | `MemoryStore` + semantic `page_out` via `memorySummarizer` |
210
208
  | Programmatic memory I/O | `runner.writeMemory()` / `runner.queryMemory()` |
211
209
  | Debug / compliance | `SessionLog` events + OS snapshot helpers |
212
210
 
@@ -214,7 +212,7 @@ Page-out, signals, processes, budgets, and memory events land in `SessionLog` wi
214
212
 
215
213
  ## Dynamic workflows
216
214
 
217
- Instead of planning **and** executing a hard task in one long context window, hand the kernel a declarative DAG and let it spawn a fresh-context sub-agent per node. The kernel owns the control flow (gate · budget · suspend-on-join · resume); your SDK runs the agents. See the [top-level overview](../README.md#the-six-harness-patterns-as-first-class-kernel-nodes) for the full pattern catalog.
215
+ For a task that needs more than one Agent, describe a DAG and let the runtime run fresh-context specialists under the same budgets, policies, and session evidence as the parent. See the [workflow guide](../docs/en/guides/workflow.md) for the complete pattern catalog.
218
216
 
219
217
  ```ts
220
218
  // One fresh-context verifier per rule (no inherited author context → can't rubber-stamp),
@@ -253,7 +251,7 @@ Dependencies use `dependsOn: number[]`, where each number is a node index, and `
253
251
  how upstream terminal states gate the node (`all_success` by default, plus `accept_partial`,
254
252
  `all_terminal`, and `optional`).
255
253
 
256
- ### Workflow capabilities (v0.2.50)
254
+ ### Workflow capabilities
257
255
 
258
256
  - **Runtime fan-out** — register `submitWorkflowNodesTool` on the parent execution plane and a trusted node can append nodes to the live DAG mid-run (true loop-until-done; one verifier per discovered claim). The tool schema is exported from `@deepstrike/sdk/workflow`, not the package root. Submission events remain audit projections; checkpoint state owns recovery. Governance rejection fails the submitting node instead of acknowledging work that was never appended.
259
257
  - **Quarantine, no escape** — set `trust: "quarantined"` on a node that reads untrusted content; it's denied write-capable isolation in-kernel, and any nodes it submits are coerced to quarantined too (no privilege escalation).
@@ -403,7 +401,7 @@ const runner = new RuntimeRunner({
403
401
  maxNameLength: 100, // override write_memory name-length limit
404
402
  },
405
403
 
406
- // Agent OS native profile (defaults shown)
404
+ // Default governance and signal policy
407
405
  governancePolicy: DEFAULT_NATIVE_GOVERNANCE_POLICY,
408
406
  signalPolicy: DEFAULT_NATIVE_SIGNAL_POLICY, // SignalRouter queue size 64
409
407
  promptBudget: {
@@ -417,15 +415,15 @@ const runner = new RuntimeRunner({
417
415
  skillDir: "./skills",
418
416
  knowledgeSource: myKS,
419
417
  signalSource: gw,
420
- dreamStore: myStore,
418
+ memoryStore: myStore,
421
419
  agentId: "my-agent",
422
420
  initialMemory: ["..."],
423
421
 
424
422
  // Memory paging & compression (SDK-side I/O)
425
423
  compressionStore: archiveStore, // persist compressed transcript slices
426
424
  asyncSummarizer: mySummarizer, // upgrade rule-based compression summaries
427
- dreamProvider: dreamLlm, // LLM for idle dream() synthesis
428
- dreamSummarizer: myDreamSummarizer, // LLM for semantic page_out → DreamStore
425
+ memoryProvider: memoryLlm, // LLM for durable-memory extraction
426
+ memorySummarizer: myMemorySummarizer, // LLM for semantic page_out → MemoryStore
429
427
 
430
428
  // Sub-agents
431
429
  runSpec: { role: "orchestrator", isolation: "process" },
@@ -445,16 +443,16 @@ const runner = new RuntimeRunner({
445
443
  | Option | Purpose |
446
444
  |--------|---------|
447
445
  | `governancePolicy` | Declarative deny / ask_user / rate-limit / param rules installed before canonical root start |
448
- | `signalPolicy` | Versioned in-kernel signal queue/TTL policy (default queue 64) |
446
+ | `signalPolicy` | In-kernel signal queue/TTL policy (default queue 64) |
449
447
  | `promptBudget` | Provider-envelope overhead, output reserve, and safety margin deducted from the context window |
450
448
  | `resourceQuota` | M2 declarative limits — `maxConcurrentSubagents` / `maxTotalSubagents` / `maxSpawnDepth` / `maxWorkflowNodes` / `memoryWritesPerWindow` — enforced at the kernel syscall trap (`set_resource_quota`); over-quota spawns roll back, over-rate writes surface as `memory_validation_failed` |
451
- | `memoryPolicy` | Canonical long-term memory policy: `validationEnabled: false` admits writes without validation, `maxContentBytes` / `maxNameLength` override validation limits, `retrievalTopK` caps `query_memory` breadth, and `staleWarningDays` controls stale recall policy. Storage belongs to the configured `dreamStore`. |
449
+ | `memoryPolicy` | Canonical long-term memory policy: `validationEnabled: false` admits writes without validation, `maxContentBytes` / `maxNameLength` override validation limits, `retrievalTopK` caps `query_memory` breadth, and `staleWarningDays` controls stale recall policy. Storage belongs to the configured `memoryStore`. |
452
450
  | `onPermissionRequest` | Resolves `tool_gated` + `suspended` → kernel `resume` with approved/denied call IDs |
453
451
  | `compressionStore` | Writes archived messages on `compressed` observations |
454
452
  | `payloadStore` | Resolves canonical opaque payload locators (default: `.payloads/`) |
455
453
  | `asyncSummarizer` | Background LLM summary after compression; stored as `summary_upgraded` |
456
- | `dreamSummarizer` | Summarizes `page_out { tier_hint: "semantic" }` into `DreamStore` during a run |
457
- | `dreamProvider` | Separate LLM for `dream()` idle consolidation (falls back to `provider`) |
454
+ | `memorySummarizer` | Summarizes `page_out { tier_hint: "semantic" }` into `MemoryStore` during a run |
455
+ | `memoryProvider` | Separate LLM for durable-memory extraction (falls back to `provider`) |
458
456
 
459
457
  Rebuild an OS diagnostics snapshot from session events:
460
458
 
@@ -574,13 +572,15 @@ mem.get("step") // 1
574
572
  mem.clear()
575
573
  ```
576
574
 
577
- ### DreamStore (long-term memory)
575
+ ### MemoryStore (long-term memory)
578
576
 
579
577
  ```typescript
580
- import type { DreamStore } from "@deepstrike/sdk/memory"
578
+ import type { MemoryStore } from "@deepstrike/sdk/memory"
581
579
 
582
- class MyStore implements DreamStore {
583
- async upsert(agentId, record) { ... } // the only durable memory mutation
580
+ class MyStore implements MemoryStore {
581
+ async put(agentId, record) { ... } // the durable write path
582
+ async get(agentId, recordId) { ... } // Promise<MemoryRecord | null>
583
+ async delete(agentId, recordId) { ... } // idempotent deletion
584
584
  async search(agentId, query) { ... } // Promise<MemoryRecall[]>
585
585
  async saveSession(session) { ... } // completed transcript for extraction
586
586
  }
@@ -591,7 +591,7 @@ const runner = new RuntimeRunner({
591
591
  executionPlane: plane,
592
592
  sessionLog: new FileSessionLog(".deepstrike/sessions"),
593
593
  maxTokens: 4096,
594
- dreamStore: new MyStore(),
594
+ memoryStore: new MyStore(),
595
595
  agentId: "my-agent",
596
596
  memoryScope, // scopes run-start recall, queries, extraction, and semantic page-out
597
597
  })
@@ -601,10 +601,10 @@ Four memory paths:
601
601
 
602
602
  | Path | When | What happens |
603
603
  |------|------|--------------|
604
- | In-session `memory(query)` | LLM calls meta-tool | `DreamStore.search()` → history tool result |
604
+ | In-session `memory(query)` | LLM calls meta-tool | `MemoryStore.search()` → history tool result |
605
605
  | `initialMemory` | Run start | Injected into Slot 2 (`systemKnowledge`) |
606
- | `writeMemory(record)` | Host writes a durable record | Kernel validation / quota / dedup → `DreamStore.upsert()` |
607
- | Semantic `page_out` | Kernel evicts with `tier_hint: "semantic"` | SDK summarizes via `dreamSummarizer` / `dreamProvider` → gated `writeMemory()` |
606
+ | `writeMemory(record)` | Host writes a durable record | Kernel validation / quota / dedup → `MemoryStore.put()` |
607
+ | Semantic `page_out` | Kernel evicts with `tier_hint: "semantic"` | SDK summarizes via `memorySummarizer` / `memoryProvider` → gated `writeMemory()` |
608
608
 
609
609
  ### Phase-7 memory syscalls (`writeMemory` / `queryMemory`)
610
610
 
@@ -0,0 +1,103 @@
1
+ import { Agent, type AgentOptions, type ModelRef } from "./agent.js";
2
+ import type { Guardrail } from "./guardrail.js";
3
+ import type { Handoff } from "./handoff-target.js";
4
+ import type { Knowledge } from "./knowledge/public.js";
5
+ import type { MCPServer } from "./mcp-server.js";
6
+ import type { JsonSchema } from "./runtime/output-schema.js";
7
+ import type { Skill } from "./skill.js";
8
+ import type { RegisteredTool } from "./tools/index.js";
9
+ import type { AgentCapabilityFilter } from "./types/agent.js";
10
+ export interface AgentToolDefinition {
11
+ name: string;
12
+ description?: string;
13
+ parameters?: Record<string, unknown>;
14
+ providerOptions?: Record<string, unknown>;
15
+ }
16
+ /** A JSON-friendly Agent definition accepted by `normalizeAgent`. It is deliberately declarative:
17
+ * executable tools still enter the SDK through `AgentOptions.tools`. */
18
+ export interface AgentDefinition extends Omit<AgentOptions, "tools"> {
19
+ tools?: Array<RegisteredTool | AgentToolDefinition>;
20
+ }
21
+ export interface AgentToolIR {
22
+ name: string;
23
+ description: string;
24
+ parameters: Record<string, unknown>;
25
+ providerOptions?: Record<string, unknown>;
26
+ }
27
+ export interface AgentMemoryIR {
28
+ kind: "durable" | "working";
29
+ namespace?: string;
30
+ }
31
+ export type AgentCapabilityIR = {
32
+ kind: "tool";
33
+ id: string;
34
+ description: string;
35
+ } | {
36
+ kind: "mcp_server";
37
+ id: string;
38
+ description: string;
39
+ } | {
40
+ kind: "skill";
41
+ id: string;
42
+ description: string;
43
+ };
44
+ /** The host-facing lowering destinations. These are declarations, not grants: a runner still
45
+ * attenuates them through its existing `AgentRunSpec.capabilityFilter` and mounted manifest. */
46
+ export interface AgentLoweringInputs {
47
+ run: {
48
+ name: string;
49
+ model?: ModelRef;
50
+ };
51
+ context: {
52
+ description?: string;
53
+ instructions?: string;
54
+ outputSchema?: JsonSchema;
55
+ knowledge: Knowledge[];
56
+ };
57
+ capabilities: {
58
+ tools: AgentToolIR[];
59
+ mcpServers: MCPServer[];
60
+ skills: Skill[];
61
+ effective: AgentCapabilityIR[];
62
+ };
63
+ memory?: AgentMemoryIR;
64
+ delegation: {
65
+ handoffs: Handoff[];
66
+ };
67
+ governance: {
68
+ guardrails: Guardrail[];
69
+ };
70
+ }
71
+ /** spc_015-09: the canonical, provider-neutral Agent IR between public SDK surfaces and host
72
+ * runtime inputs. It contains neither an execution plan nor a Kernel wire DTO. */
73
+ export interface AgentSpec {
74
+ name: string;
75
+ description?: string;
76
+ instructions?: string;
77
+ model?: ModelRef;
78
+ tools: AgentToolIR[];
79
+ outputSchema?: JsonSchema;
80
+ mcpServers?: MCPServer[];
81
+ skills?: Skill[];
82
+ memory?: AgentMemoryIR;
83
+ knowledge?: Knowledge[];
84
+ handoffs?: Handoff[];
85
+ guardrails?: Guardrail[];
86
+ metadata?: Record<string, unknown>;
87
+ /** Declared capabilities. This descriptive view grants nothing by itself. */
88
+ capabilities: AgentCapabilityIR[];
89
+ /** Host ceiling copied from the public Agent, when supplied. Empty axes remain non-narrowing. */
90
+ capabilityFilter?: AgentCapabilityFilter;
91
+ /** The declarations that survive the supplied local ceiling. Host mounts may narrow further. */
92
+ effectiveCapabilities: AgentCapabilityIR[];
93
+ /** Namespace-isolated provider extensions. Unknown namespaces are preserved verbatim. */
94
+ extensions: Record<string, unknown>;
95
+ inputs: AgentLoweringInputs;
96
+ }
97
+ /** Normalizes native Agents and JSON-safe descriptor objects into the one public surface used by
98
+ * lowering. It does not interpret provider namespaces or create executable capabilities. */
99
+ export declare function normalizeAgent(agent: Agent | AgentDefinition): Agent;
100
+ /** Pure: no provider branching, no scheduling, authorization, persistence, or Kernel wire calls.
101
+ * Providers consume only their own namespace from `extensions`; the host decides whether declared
102
+ * capabilities survive its existing attenuation filter. */
103
+ export declare function lowerAgent(agent: Agent): AgentSpec;
@@ -0,0 +1,134 @@
1
+ import { Agent } from "./agent.js";
2
+ import { WorkingMemory } from "./memory/public.js";
3
+ function clone(value) {
4
+ if (value === undefined || value === null || typeof value !== "object")
5
+ return value;
6
+ if (Array.isArray(value))
7
+ return value.map(clone);
8
+ const copy = {};
9
+ for (const [key, nested] of Object.entries(value))
10
+ copy[key] = clone(nested);
11
+ return copy;
12
+ }
13
+ function toolDefinitionToRegisteredTool(tool) {
14
+ const parameters = clone(tool.parameters ?? { type: "object", properties: {} });
15
+ if (parameters.type !== "object") {
16
+ throw new Error(`tool "${tool.name}": parameters must be a JSON Schema with root type "object"`);
17
+ }
18
+ return {
19
+ schema: {
20
+ name: tool.name,
21
+ description: tool.description ?? "",
22
+ parameters: JSON.stringify(parameters),
23
+ },
24
+ providerOptions: clone(tool.providerOptions),
25
+ async execute() {
26
+ throw new Error(`tool "${tool.name}" has no execution binding — declarative Agent definitions only carry shape`);
27
+ },
28
+ };
29
+ }
30
+ function isRegisteredTool(tool) {
31
+ return "schema" in tool && "execute" in tool;
32
+ }
33
+ /** Normalizes native Agents and JSON-safe descriptor objects into the one public surface used by
34
+ * lowering. It does not interpret provider namespaces or create executable capabilities. */
35
+ export function normalizeAgent(agent) {
36
+ if (agent instanceof Agent)
37
+ return agent;
38
+ const tools = agent.tools?.map(tool => isRegisteredTool(tool) ? tool : toolDefinitionToRegisteredTool(tool));
39
+ const { tools: _rawTools, ...options } = agent;
40
+ return new Agent({ ...options, ...(tools ? { tools } : {}) });
41
+ }
42
+ function lowerTool(tool) {
43
+ let parameters;
44
+ try {
45
+ parameters = JSON.parse(tool.schema.parameters);
46
+ }
47
+ catch {
48
+ throw new Error(`tool "${tool.schema.name}" has invalid JSON Schema parameters`);
49
+ }
50
+ if (!parameters || typeof parameters !== "object" || Array.isArray(parameters)) {
51
+ throw new Error(`tool "${tool.schema.name}" parameters must decode to an object`);
52
+ }
53
+ return {
54
+ name: tool.schema.name,
55
+ description: tool.schema.description,
56
+ parameters: clone(parameters),
57
+ ...(tool.providerOptions ? { providerOptions: clone(tool.providerOptions) } : {}),
58
+ };
59
+ }
60
+ function lowerMemory(memory) {
61
+ if (!memory)
62
+ return undefined;
63
+ if (memory instanceof WorkingMemory)
64
+ return { kind: "working" };
65
+ const reference = memory;
66
+ return {
67
+ kind: "durable",
68
+ ...(reference.namespace ? { namespace: reference.namespace } : {}),
69
+ };
70
+ }
71
+ function capabilityAllowed(capability, filter) {
72
+ if (!filter)
73
+ return true;
74
+ const kind = capability.kind === "mcp_server" ? "mcp_server" : capability.kind;
75
+ const kindAllowed = !filter.allowedKinds?.length || filter.allowedKinds.includes(kind);
76
+ const idAllowed = !filter.allowedIds?.length || filter.allowedIds.includes(capability.id);
77
+ return kindAllowed && idAllowed;
78
+ }
79
+ /** Pure: no provider branching, no scheduling, authorization, persistence, or Kernel wire calls.
80
+ * Providers consume only their own namespace from `extensions`; the host decides whether declared
81
+ * capabilities survive its existing attenuation filter. */
82
+ export function lowerAgent(agent) {
83
+ const tools = (agent.tools ?? []).map(lowerTool);
84
+ const mcpServers = clone(agent.mcpServers ?? []);
85
+ const skills = clone(agent.skills ?? []);
86
+ const knowledge = clone(agent.knowledge ?? []);
87
+ const handoffs = clone(agent.handoffs ?? []);
88
+ const guardrails = clone(agent.guardrails ?? []);
89
+ const memory = lowerMemory(agent.memory);
90
+ const extensions = clone(agent.providerOptions ?? {});
91
+ const capabilities = [
92
+ ...tools.map(tool => ({ kind: "tool", id: tool.name, description: tool.description })),
93
+ ...mcpServers.map(server => ({
94
+ kind: "mcp_server",
95
+ id: server.name ?? server.transport.kind,
96
+ description: server.name ?? `${server.transport.kind} MCP server`,
97
+ })),
98
+ ...skills.map(skill => ({ kind: "skill", id: skill.name, description: skill.description ?? "" })),
99
+ ];
100
+ const capabilityFilter = agent.capabilityFilter ? clone(agent.capabilityFilter) : undefined;
101
+ const effectiveCapabilities = capabilities.filter(capability => capabilityAllowed(capability, capabilityFilter));
102
+ return {
103
+ name: agent.name,
104
+ ...(agent.description ? { description: agent.description } : {}),
105
+ ...(agent.instructions ? { instructions: agent.instructions } : {}),
106
+ ...(agent.model ? { model: clone(agent.model) } : {}),
107
+ tools,
108
+ ...(agent.outputSchema ? { outputSchema: clone(agent.outputSchema) } : {}),
109
+ ...(mcpServers.length ? { mcpServers } : {}),
110
+ ...(skills.length ? { skills } : {}),
111
+ ...(memory ? { memory } : {}),
112
+ ...(knowledge.length ? { knowledge } : {}),
113
+ ...(handoffs.length ? { handoffs } : {}),
114
+ ...(guardrails.length ? { guardrails } : {}),
115
+ ...(agent.metadata ? { metadata: clone(agent.metadata) } : {}),
116
+ capabilities,
117
+ ...(capabilityFilter ? { capabilityFilter } : {}),
118
+ effectiveCapabilities,
119
+ extensions,
120
+ inputs: {
121
+ run: { name: agent.name, ...(agent.model ? { model: clone(agent.model) } : {}) },
122
+ context: {
123
+ ...(agent.description ? { description: agent.description } : {}),
124
+ ...(agent.instructions ? { instructions: agent.instructions } : {}),
125
+ ...(agent.outputSchema ? { outputSchema: clone(agent.outputSchema) } : {}),
126
+ knowledge,
127
+ },
128
+ capabilities: { tools, mcpServers, skills, effective: effectiveCapabilities },
129
+ ...(memory ? { memory } : {}),
130
+ delegation: { handoffs },
131
+ governance: { guardrails },
132
+ },
133
+ };
134
+ }
@@ -0,0 +1,67 @@
1
+ import type { RegisteredTool } from "./tools/index.js";
2
+ import type { Memory, WorkingMemory } from "./memory/public.js";
3
+ import type { MCPServer } from "./mcp-server.js";
4
+ import type { JsonSchema } from "./runtime/output-schema.js";
5
+ import type { Guardrail } from "./guardrail.js";
6
+ import type { Skill } from "./skill.js";
7
+ import type { Knowledge } from "./knowledge/public.js";
8
+ import type { Handoff } from "./handoff-target.js";
9
+ import type { AgentCapabilityFilter } from "./types/agent.js";
10
+ /** A serializable durable-memory binding for agents that are described before a host store exists. */
11
+ export interface MemoryReference {
12
+ kind?: "durable";
13
+ namespace?: string;
14
+ }
15
+ export type AgentMemory = Memory | WorkingMemory | MemoryReference;
16
+ /** spc_001 §2.1: dual-mode model reference — either an explicit vendor model name, or a
17
+ * capability-based requirement the Host routes to a concrete model. Routing logic for the
18
+ * `ModelRequirement` branch is Provider Adapter work, out of scope here (spc_001-06). */
19
+ export type ModelRef = string | ModelRequirement;
20
+ export interface ModelRequirement {
21
+ capability?: {
22
+ reasoning?: boolean;
23
+ vision?: boolean;
24
+ toolUse?: boolean;
25
+ };
26
+ contextWindow?: number;
27
+ latencyClass?: string;
28
+ costClass?: string;
29
+ }
30
+ export interface AgentOptions {
31
+ name: string;
32
+ description?: string;
33
+ instructions?: string;
34
+ model?: ModelRef;
35
+ /** Optional host capability ceiling. It narrows declarations during Agent IR lowering; it never grants authority. */
36
+ capabilityFilter?: AgentCapabilityFilter;
37
+ tools?: RegisteredTool[];
38
+ mcpServers?: MCPServer[];
39
+ skills?: Skill[];
40
+ memory?: AgentMemory;
41
+ knowledge?: Knowledge[];
42
+ handoffs?: Handoff[];
43
+ providerOptions?: Record<string, unknown>;
44
+ outputSchema?: JsonSchema;
45
+ metadata?: Record<string, unknown>;
46
+ guardrails?: Guardrail[];
47
+ }
48
+ /** spc_001 §2.1: public Agent contract — a thin field-storage wrapper today, with lowering to the
49
+ * Kernel's `AgentRunSpec`/Canonical Agent IR added incrementally by later cards (spc_001-03+). */
50
+ export declare class Agent {
51
+ readonly name: string;
52
+ readonly description?: string;
53
+ readonly instructions?: string;
54
+ readonly model?: ModelRef;
55
+ readonly capabilityFilter?: AgentCapabilityFilter;
56
+ readonly tools?: RegisteredTool[];
57
+ readonly mcpServers?: MCPServer[];
58
+ readonly skills?: Skill[];
59
+ readonly memory?: AgentMemory;
60
+ readonly knowledge?: Knowledge[];
61
+ readonly handoffs?: Handoff[];
62
+ readonly providerOptions?: Record<string, unknown>;
63
+ readonly outputSchema?: JsonSchema;
64
+ readonly metadata?: Record<string, unknown>;
65
+ readonly guardrails?: Guardrail[];
66
+ constructor(options: AgentOptions);
67
+ }
package/dist/agent.js ADDED
@@ -0,0 +1,36 @@
1
+ /** spc_001 §2.1: public Agent contract — a thin field-storage wrapper today, with lowering to the
2
+ * Kernel's `AgentRunSpec`/Canonical Agent IR added incrementally by later cards (spc_001-03+). */
3
+ export class Agent {
4
+ name;
5
+ description;
6
+ instructions;
7
+ model;
8
+ capabilityFilter;
9
+ tools;
10
+ mcpServers;
11
+ skills;
12
+ memory;
13
+ knowledge;
14
+ handoffs;
15
+ providerOptions;
16
+ outputSchema;
17
+ metadata;
18
+ guardrails;
19
+ constructor(options) {
20
+ this.name = options.name;
21
+ this.description = options.description;
22
+ this.instructions = options.instructions;
23
+ this.model = options.model;
24
+ this.capabilityFilter = options.capabilityFilter;
25
+ this.tools = options.tools;
26
+ this.mcpServers = options.mcpServers;
27
+ this.skills = options.skills;
28
+ this.memory = options.memory;
29
+ this.knowledge = options.knowledge;
30
+ this.handoffs = options.handoffs;
31
+ this.providerOptions = options.providerOptions;
32
+ this.outputSchema = options.outputSchema;
33
+ this.metadata = options.metadata;
34
+ this.guardrails = options.guardrails;
35
+ }
36
+ }
@@ -10,7 +10,7 @@ export class CreatorVerifierBody {
10
10
  }
11
11
  async *run(context) {
12
12
  const contractBlock = formatContractForSystemPrompt(this.contract);
13
- const result = await this.pool.execute("executor", {
13
+ const result = await this.pool.execute("implement", {
14
14
  sessionId: context.sessionId,
15
15
  goal: `${contractBlock}\n\n---\n\n${context.goal}`,
16
16
  ...(context.contextInput ? { contextInput: context.contextInput } : {}),
@@ -9,14 +9,12 @@ export interface CreatorVerifierMetrics {
9
9
  /**
10
10
  * CreatorVerifierMode — the simplest multi-agent collaboration pattern.
11
11
  *
12
- * By default uses the kernel spawn path via `pool.ensureCoordinator()`.
13
- * Pass `useLegacyRunners: true` to fall back to independent runner sessions.
12
+ * Uses the kernel spawn path through an explicitly configured coordinator.
14
13
  *
15
14
  * Usage:
16
15
  * ```ts
17
16
  * const pool = new AgentPool()
18
- * .add("executor", executorRunner)
19
- * .add("verifier", verifierRunner)
17
+ * .configureCoordinator(runtimeOptions, sessionId)
20
18
  *
21
19
  * const mode = new CreatorVerifierMode(pool)
22
20
  * const result = await mode.run(contract)
@@ -33,8 +31,6 @@ export declare class CreatorVerifierMode {
33
31
  private _failed;
34
32
  constructor(pool: AgentPool, options?: {
35
33
  maxAttempts?: number;
36
- /** Stable orchestration session for kernel lineage audit. */
37
- coordinatorSessionId?: string;
38
34
  });
39
35
  run(contract: VerificationContract): Promise<ContractOutcome>;
40
36
  /** Aggregate drift metrics across all runs through this mode instance. */
@@ -61,7 +57,6 @@ export declare class OrchestrationMode {
61
57
  private inner;
62
58
  constructor(pool: AgentPool, options?: {
63
59
  maxAttempts?: number;
64
- coordinatorSessionId?: string;
65
60
  });
66
61
  run(goal: string): Promise<ContractOutcome & {
67
62
  contract: VerificationContract;
@@ -4,14 +4,12 @@ import { AttemptLoop } from "../../harness/harness.js";
4
4
  /**
5
5
  * CreatorVerifierMode — the simplest multi-agent collaboration pattern.
6
6
  *
7
- * By default uses the kernel spawn path via `pool.ensureCoordinator()`.
8
- * Pass `useLegacyRunners: true` to fall back to independent runner sessions.
7
+ * Uses the kernel spawn path through an explicitly configured coordinator.
9
8
  *
10
9
  * Usage:
11
10
  * ```ts
12
11
  * const pool = new AgentPool()
13
- * .add("executor", executorRunner)
14
- * .add("verifier", verifierRunner)
12
+ * .configureCoordinator(runtimeOptions, sessionId)
15
13
  *
16
14
  * const mode = new CreatorVerifierMode(pool)
17
15
  * const result = await mode.run(contract)
@@ -32,7 +30,7 @@ export class CreatorVerifierMode {
32
30
  }
33
31
  async run(contract) {
34
32
  this._total++;
35
- this.pool.ensureCoordinator(this.options.coordinatorSessionId);
33
+ this.pool.ensureCoordinator();
36
34
  const loop = new AttemptLoop({
37
35
  body: new CreatorVerifierBody(this.pool, contract),
38
36
  judge: new StructuredContractJudge(this.pool, contract),
@@ -115,7 +113,7 @@ export class OrchestrationMode {
115
113
  this.inner = new CreatorVerifierMode(pool, options);
116
114
  }
117
115
  async run(goal) {
118
- this.pool.ensureCoordinator(this.options.coordinatorSessionId);
116
+ this.pool.ensureCoordinator();
119
117
  // Step 1: orchestrator produces a VerificationContract
120
118
  const contractJson = await this.pool.orchestrate(goal);
121
119
  const contract = this._parseContract(contractJson, goal);
@@ -1,9 +1,7 @@
1
- import type { RuntimeOptions, RuntimeRunner } from "../runtime/runner.js";
1
+ import type { RuntimeOptions } from "../runtime/runner.js";
2
2
  import type { VerificationContract } from "./contract.js";
3
3
  import type { AgentRunSpec, KernelAgentRole, SubAgentResult } from "../types/agent.js";
4
- /** Legacy pool roles — mapped to kernel AgentRole when using spawn path. */
5
- export type AgentRole = "orchestrator" | "executor" | "verifier";
6
- export declare const KERNEL_ROLE_MAP: Record<AgentRole, KernelAgentRole>;
4
+ export type AgentRole = KernelAgentRole;
7
5
  export interface IsolatedVerifierContext {
8
6
  contract: VerificationContract;
9
7
  artifact: string;
@@ -19,26 +17,16 @@ export interface RoleExecutionInput {
19
17
  verificationContractId?: string;
20
18
  }
21
19
  export declare class AgentPool {
22
- private runners;
23
20
  private coordinator?;
24
- add(role: AgentRole, runner: RuntimeRunner): this;
25
21
  /** Enable kernel spawn path with lineage recorded under `sessionId`. */
26
22
  configureCoordinator(opts: RuntimeOptions, sessionId: string): this;
27
- /**
28
- * Infer coordinator from a registered runner (executor → orchestrator → verifier).
29
- * Idempotent when coordinator is already configured.
30
- */
31
- ensureCoordinator(sessionId?: string): this;
23
+ /** Assert that this pool has one canonical kernel coordinator. */
24
+ ensureCoordinator(): this;
32
25
  usesSpawnPath(): boolean;
33
- has(role: AgentRole): boolean;
34
- get(role: AgentRole): RuntimeRunner;
35
- /**
36
- * Spawn a kernel-isolated sub-agent. Requires `configureCoordinator()`.
37
- * Maps legacy pool roles to kernel roles (executor → implement, etc.).
38
- */
39
- spawn(role: AgentRole | KernelAgentRole, goal: string, extra?: Partial<Omit<AgentRunSpec, "identity" | "role" | "goal">>): Promise<SubAgentResult>;
40
- /** Execute a role in a caller-owned session so AttemptLoop can retain transcript across attempts. */
41
- execute(role: AgentRole, input: RoleExecutionInput): Promise<SubAgentResult>;
26
+ /** Spawn a kernel-isolated sub-agent. Requires `configureCoordinator()`. */
27
+ spawn(role: KernelAgentRole, goal: string, extra?: Partial<Omit<AgentRunSpec, "identity" | "role" | "goal">>): Promise<SubAgentResult>;
28
+ /** Execute a role in a caller-owned session while preserving kernel lineage. */
29
+ execute(role: KernelAgentRole, input: RoleExecutionInput): Promise<SubAgentResult>;
42
30
  verify(ctx: IsolatedVerifierContext): Promise<string>;
43
31
  orchestrate(goal: string): Promise<string>;
44
32
  }