@deepstrike/sdk 0.1.16 → 0.2.1
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/dist/collaboration/harness.d.ts +4 -1
- package/dist/collaboration/harness.js +20 -6
- package/dist/collaboration/modes/creator-verifier.d.ts +8 -2
- package/dist/collaboration/modes/creator-verifier.js +9 -3
- package/dist/collaboration/pool.d.ts +24 -3
- package/dist/collaboration/pool.js +65 -5
- package/dist/harness/harness.d.ts +5 -1
- package/dist/harness/harness.js +23 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +5 -0
- package/dist/kernel.d.ts +12 -43
- package/dist/kernel.js +1 -1
- package/dist/providers/anthropic.js +3 -1
- package/dist/runtime/archive.d.ts +15 -0
- package/dist/runtime/archive.js +35 -0
- package/dist/runtime/execution-plane.js +30 -6
- package/dist/runtime/filtered-plane.d.ts +14 -0
- package/dist/runtime/filtered-plane.js +45 -0
- package/dist/runtime/kernel-step.d.ts +88 -0
- package/dist/runtime/kernel-step.js +262 -0
- package/dist/runtime/process-sandbox-plane.d.ts +4 -4
- package/dist/runtime/process-sandbox-plane.js +5 -5
- package/dist/runtime/provider-replay.js +7 -2
- package/dist/runtime/replay-sanitize.d.ts +5 -0
- package/dist/runtime/replay-sanitize.js +25 -0
- package/dist/runtime/runner.d.ts +60 -4
- package/dist/runtime/runner.js +589 -86
- package/dist/runtime/session-log.d.ts +93 -1
- package/dist/runtime/session-repair.d.ts +37 -0
- package/dist/runtime/session-repair.js +77 -0
- package/dist/runtime/sub-agent-orchestrator.d.ts +19 -0
- package/dist/runtime/sub-agent-orchestrator.js +114 -0
- package/dist/skills/watcher.d.ts +19 -0
- package/dist/skills/watcher.js +38 -0
- package/dist/tools/index.d.ts +4 -1
- package/dist/tools/index.js +82 -11
- package/dist/types/agent.d.ts +68 -0
- package/dist/types/agent.js +78 -0
- package/dist/types.d.ts +27 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentPool } from "./pool.js";
|
|
1
|
+
import type { AgentPool, CoordinatorConfig } from "./pool.js";
|
|
2
2
|
import type { VerificationContract, ContractCheckResult } from "./contract.js";
|
|
3
3
|
import type { HandoffArtifact } from "./handoff.js";
|
|
4
4
|
export interface Violation {
|
|
@@ -17,6 +17,8 @@ export interface ContractOutcome {
|
|
|
17
17
|
export interface ContractHarnessOptions {
|
|
18
18
|
maxAttempts?: number;
|
|
19
19
|
onViolation?: (violations: Violation[]) => void;
|
|
20
|
+
/** When set with pool.configureCoordinator(), enables kernel spawn path. */
|
|
21
|
+
coordinator?: CoordinatorConfig;
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* ContractDrivenHarness — the core multi-agent execution primitive.
|
|
@@ -41,6 +43,7 @@ export declare class ContractDrivenHarness {
|
|
|
41
43
|
private maxAttempts;
|
|
42
44
|
private onViolation?;
|
|
43
45
|
constructor(pool: AgentPool, contract: VerificationContract, options?: ContractHarnessOptions);
|
|
46
|
+
stream(): AsyncIterable<ContractOutcome>;
|
|
44
47
|
run(): Promise<ContractOutcome>;
|
|
45
48
|
private _findViolations;
|
|
46
49
|
private _formatViolationsForFeedback;
|
|
@@ -28,6 +28,12 @@ export class ContractDrivenHarness {
|
|
|
28
28
|
this.contract = contract;
|
|
29
29
|
this.maxAttempts = options.maxAttempts ?? 3;
|
|
30
30
|
this.onViolation = options.onViolation;
|
|
31
|
+
if (options.coordinator) {
|
|
32
|
+
this.pool.configureCoordinator(options.coordinator.opts, options.coordinator.sessionId);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async *stream() {
|
|
36
|
+
yield await this.run();
|
|
31
37
|
}
|
|
32
38
|
async run() {
|
|
33
39
|
let artifact = "";
|
|
@@ -43,14 +49,22 @@ export class ContractDrivenHarness {
|
|
|
43
49
|
? `\n\n[Previous attempt failed. Violations to fix:\n${this._formatViolationsForFeedback(checkResults)}]`
|
|
44
50
|
: "";
|
|
45
51
|
const executorGoal = `${contractBlock}\n\n---\n\n${currentGoal}${violationNote}`;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
if (this.pool.usesSpawnPath()) {
|
|
53
|
+
const execResult = await this.pool.spawn("executor", executorGoal, {
|
|
54
|
+
verificationContractId: this.contract.id,
|
|
55
|
+
});
|
|
56
|
+
artifact = execResult.result.finalMessage?.content ?? "";
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
artifact = await collectText(this.pool.get("executor").run({
|
|
60
|
+
sessionId: crypto.randomUUID(),
|
|
61
|
+
goal: executorGoal,
|
|
62
|
+
criteria: contractToCriteriaStrings(this.contract),
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
51
65
|
// ── Phase 2: Verifier ──────────────────────────────────────────────────
|
|
52
66
|
// Verifier sees: artifact + contract only. No executor history.
|
|
53
|
-
const auditText = await this.pool.
|
|
67
|
+
const auditText = await this.pool.verify({ contract: this.contract, artifact });
|
|
54
68
|
// ── Phase 3: Parse audit → ContractCheckResult[] ──────────────────────
|
|
55
69
|
checkResults = this._parseAuditText(auditText);
|
|
56
70
|
const violations = this._findViolations(checkResults);
|
|
@@ -9,8 +9,8 @@ export interface CreatorVerifierMetrics {
|
|
|
9
9
|
/**
|
|
10
10
|
* CreatorVerifierMode — the simplest multi-agent collaboration pattern.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* By default uses the kernel spawn path via `pool.ensureCoordinator()`.
|
|
13
|
+
* Pass `useLegacyRunners: true` to fall back to independent runner sessions.
|
|
14
14
|
*
|
|
15
15
|
* Usage:
|
|
16
16
|
* ```ts
|
|
@@ -33,6 +33,10 @@ export declare class CreatorVerifierMode {
|
|
|
33
33
|
private _failed;
|
|
34
34
|
constructor(pool: AgentPool, options?: {
|
|
35
35
|
maxAttempts?: number;
|
|
36
|
+
/** Stable orchestration session for kernel lineage audit. */
|
|
37
|
+
coordinatorSessionId?: string;
|
|
38
|
+
/** Opt out of kernel spawn path and use legacy independent runner sessions. */
|
|
39
|
+
useLegacyRunners?: boolean;
|
|
36
40
|
});
|
|
37
41
|
run(contract: VerificationContract): Promise<ContractOutcome>;
|
|
38
42
|
/** Aggregate drift metrics across all runs through this mode instance. */
|
|
@@ -59,6 +63,8 @@ export declare class OrchestrationMode {
|
|
|
59
63
|
private inner;
|
|
60
64
|
constructor(pool: AgentPool, options?: {
|
|
61
65
|
maxAttempts?: number;
|
|
66
|
+
coordinatorSessionId?: string;
|
|
67
|
+
useLegacyRunners?: boolean;
|
|
62
68
|
});
|
|
63
69
|
run(goal: string): Promise<ContractOutcome & {
|
|
64
70
|
contract: VerificationContract;
|
|
@@ -2,8 +2,8 @@ import { ContractDrivenHarness } from "../harness.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* CreatorVerifierMode — the simplest multi-agent collaboration pattern.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* By default uses the kernel spawn path via `pool.ensureCoordinator()`.
|
|
6
|
+
* Pass `useLegacyRunners: true` to fall back to independent runner sessions.
|
|
7
7
|
*
|
|
8
8
|
* Usage:
|
|
9
9
|
* ```ts
|
|
@@ -30,6 +30,9 @@ export class CreatorVerifierMode {
|
|
|
30
30
|
}
|
|
31
31
|
async run(contract) {
|
|
32
32
|
this._total++;
|
|
33
|
+
if (!this.options.useLegacyRunners) {
|
|
34
|
+
this.pool.ensureCoordinator(this.options.coordinatorSessionId);
|
|
35
|
+
}
|
|
33
36
|
const harness = new ContractDrivenHarness(this.pool, contract, {
|
|
34
37
|
maxAttempts: this.options.maxAttempts ?? 3,
|
|
35
38
|
});
|
|
@@ -78,8 +81,11 @@ export class OrchestrationMode {
|
|
|
78
81
|
this.inner = new CreatorVerifierMode(pool, options);
|
|
79
82
|
}
|
|
80
83
|
async run(goal) {
|
|
84
|
+
if (!this.options.useLegacyRunners) {
|
|
85
|
+
this.pool.ensureCoordinator(this.options.coordinatorSessionId);
|
|
86
|
+
}
|
|
81
87
|
// Step 1: orchestrator produces a VerificationContract
|
|
82
|
-
const contractJson = await this.pool.
|
|
88
|
+
const contractJson = await this.pool.orchestrate(goal);
|
|
83
89
|
const contract = this._parseContract(contractJson, goal);
|
|
84
90
|
// Step 2: CreatorVerifierMode executes against the contract
|
|
85
91
|
const outcome = await this.inner.run(contract);
|
|
@@ -1,15 +1,36 @@
|
|
|
1
|
-
import type { RuntimeRunner } from "../runtime/runner.js";
|
|
1
|
+
import type { RuntimeOptions, RuntimeRunner } from "../runtime/runner.js";
|
|
2
2
|
import type { VerificationContract } from "./contract.js";
|
|
3
|
+
import type { AgentRunSpec, KernelAgentRole, SubAgentResult } from "../types/agent.js";
|
|
4
|
+
/** Legacy pool roles — mapped to kernel AgentRole when using spawn path. */
|
|
3
5
|
export type AgentRole = "orchestrator" | "executor" | "verifier";
|
|
6
|
+
export declare const KERNEL_ROLE_MAP: Record<AgentRole, KernelAgentRole>;
|
|
4
7
|
export interface IsolatedVerifierContext {
|
|
5
8
|
contract: VerificationContract;
|
|
6
9
|
artifact: string;
|
|
7
10
|
}
|
|
11
|
+
export interface CoordinatorConfig {
|
|
12
|
+
opts: RuntimeOptions;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
}
|
|
8
15
|
export declare class AgentPool {
|
|
9
16
|
private runners;
|
|
17
|
+
private coordinator?;
|
|
10
18
|
add(role: AgentRole, runner: RuntimeRunner): this;
|
|
19
|
+
/** Enable kernel spawn path with lineage recorded under `sessionId`. */
|
|
20
|
+
configureCoordinator(opts: RuntimeOptions, sessionId: string): this;
|
|
21
|
+
/**
|
|
22
|
+
* Infer coordinator from a registered runner (executor → orchestrator → verifier).
|
|
23
|
+
* Idempotent when coordinator is already configured.
|
|
24
|
+
*/
|
|
25
|
+
ensureCoordinator(sessionId?: string): this;
|
|
26
|
+
usesSpawnPath(): boolean;
|
|
11
27
|
has(role: AgentRole): boolean;
|
|
12
28
|
get(role: AgentRole): RuntimeRunner;
|
|
13
|
-
|
|
14
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Spawn a kernel-isolated sub-agent. Requires `configureCoordinator()`.
|
|
31
|
+
* Maps legacy pool roles to kernel roles (executor → implement, etc.).
|
|
32
|
+
*/
|
|
33
|
+
spawn(role: AgentRole | KernelAgentRole, goal: string, extra?: Partial<Omit<AgentRunSpec, "identity" | "role" | "goal">>): Promise<SubAgentResult>;
|
|
34
|
+
verify(ctx: IsolatedVerifierContext): Promise<string>;
|
|
35
|
+
orchestrate(goal: string): Promise<string>;
|
|
15
36
|
}
|
|
@@ -1,11 +1,41 @@
|
|
|
1
1
|
import { collectText } from "../runtime/runner.js";
|
|
2
|
+
import { spawnStandalone } from "../runtime/sub-agent-orchestrator.js";
|
|
2
3
|
import { formatContractForSystemPrompt } from "./contract.js";
|
|
4
|
+
import { agentIdentitySub } from "../types/agent.js";
|
|
5
|
+
export const KERNEL_ROLE_MAP = {
|
|
6
|
+
orchestrator: "plan",
|
|
7
|
+
executor: "implement",
|
|
8
|
+
verifier: "verify",
|
|
9
|
+
};
|
|
3
10
|
export class AgentPool {
|
|
4
11
|
runners = new Map();
|
|
12
|
+
coordinator;
|
|
5
13
|
add(role, runner) {
|
|
6
14
|
this.runners.set(role, runner);
|
|
7
15
|
return this;
|
|
8
16
|
}
|
|
17
|
+
/** Enable kernel spawn path with lineage recorded under `sessionId`. */
|
|
18
|
+
configureCoordinator(opts, sessionId) {
|
|
19
|
+
this.coordinator = { opts, sessionId };
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Infer coordinator from a registered runner (executor → orchestrator → verifier).
|
|
24
|
+
* Idempotent when coordinator is already configured.
|
|
25
|
+
*/
|
|
26
|
+
ensureCoordinator(sessionId) {
|
|
27
|
+
if (this.coordinator)
|
|
28
|
+
return this;
|
|
29
|
+
const source = this.has("executor")
|
|
30
|
+
? "executor"
|
|
31
|
+
: this.has("orchestrator")
|
|
32
|
+
? "orchestrator"
|
|
33
|
+
: "verifier";
|
|
34
|
+
return this.configureCoordinator(this.get(source).hostOptions, sessionId ?? crypto.randomUUID());
|
|
35
|
+
}
|
|
36
|
+
usesSpawnPath() {
|
|
37
|
+
return this.coordinator !== undefined;
|
|
38
|
+
}
|
|
9
39
|
has(role) {
|
|
10
40
|
return this.runners.has(role);
|
|
11
41
|
}
|
|
@@ -15,8 +45,24 @@ export class AgentPool {
|
|
|
15
45
|
throw new Error(`AgentPool: no runner registered for role "${role}"`);
|
|
16
46
|
return runner;
|
|
17
47
|
}
|
|
18
|
-
|
|
19
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Spawn a kernel-isolated sub-agent. Requires `configureCoordinator()`.
|
|
50
|
+
* Maps legacy pool roles to kernel roles (executor → implement, etc.).
|
|
51
|
+
*/
|
|
52
|
+
async spawn(role, goal, extra) {
|
|
53
|
+
if (!this.coordinator) {
|
|
54
|
+
throw new Error("AgentPool.configureCoordinator() required for kernel spawn path");
|
|
55
|
+
}
|
|
56
|
+
const kernelRole = role in KERNEL_ROLE_MAP ? KERNEL_ROLE_MAP[role] : role;
|
|
57
|
+
const spec = {
|
|
58
|
+
identity: agentIdentitySub(`${kernelRole}-${crypto.randomUUID()}`, crypto.randomUUID(), this.coordinator.sessionId),
|
|
59
|
+
role: kernelRole,
|
|
60
|
+
goal,
|
|
61
|
+
...extra,
|
|
62
|
+
};
|
|
63
|
+
return spawnStandalone(this.coordinator.opts, this.coordinator.sessionId, spec);
|
|
64
|
+
}
|
|
65
|
+
async verify(ctx) {
|
|
20
66
|
const contractBlock = formatContractForSystemPrompt(ctx.contract);
|
|
21
67
|
const auditGoal = [
|
|
22
68
|
contractBlock, "",
|
|
@@ -29,10 +75,17 @@ export class AgentPool {
|
|
|
29
75
|
"List any anti-patterns you detected.",
|
|
30
76
|
"Conclude with an overall PASS or FAIL verdict.",
|
|
31
77
|
].join("\n");
|
|
78
|
+
if (this.coordinator) {
|
|
79
|
+
const result = await this.spawn("verify", auditGoal, {
|
|
80
|
+
verificationContractId: ctx.contract.id,
|
|
81
|
+
isolation: "read_only",
|
|
82
|
+
});
|
|
83
|
+
return result.result.finalMessage?.content ?? "";
|
|
84
|
+
}
|
|
85
|
+
const runner = this.get("verifier");
|
|
32
86
|
return collectText(runner.run({ sessionId: crypto.randomUUID(), goal: auditGoal }));
|
|
33
87
|
}
|
|
34
|
-
async
|
|
35
|
-
const runner = this.get("orchestrator");
|
|
88
|
+
async orchestrate(goal) {
|
|
36
89
|
const orchestratorGoal = [
|
|
37
90
|
`You are a planning orchestrator. Decompose the following goal into a VerificationContract.`,
|
|
38
91
|
``,
|
|
@@ -49,6 +102,13 @@ export class AgentPool {
|
|
|
49
102
|
``,
|
|
50
103
|
`Output ONLY the JSON object, no prose.`,
|
|
51
104
|
].join("\n");
|
|
52
|
-
|
|
105
|
+
if (this.coordinator) {
|
|
106
|
+
const result = await this.spawn("plan", orchestratorGoal);
|
|
107
|
+
return result.result.finalMessage?.content ?? "";
|
|
108
|
+
}
|
|
109
|
+
return collectText(this.get("orchestrator").run({
|
|
110
|
+
sessionId: crypto.randomUUID(),
|
|
111
|
+
goal: orchestratorGoal,
|
|
112
|
+
}));
|
|
53
113
|
}
|
|
54
114
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RuntimeRunner } from "../runtime/runner.js";
|
|
2
2
|
import { collectText } from "../runtime/runner.js";
|
|
3
|
+
import type { StreamEvent } from "../types.js";
|
|
3
4
|
export interface Criterion {
|
|
4
5
|
text: string;
|
|
5
6
|
required: boolean;
|
|
@@ -75,6 +76,7 @@ export declare class SinglePassHarness {
|
|
|
75
76
|
private runner;
|
|
76
77
|
constructor(runner: RuntimeRunner);
|
|
77
78
|
run(request: HarnessRequest): Promise<HarnessOutcome>;
|
|
79
|
+
stream(request: HarnessRequest): AsyncIterable<StreamEvent>;
|
|
78
80
|
}
|
|
79
81
|
export declare class EvalLoopHarness {
|
|
80
82
|
private runner;
|
|
@@ -82,6 +84,7 @@ export declare class EvalLoopHarness {
|
|
|
82
84
|
private maxAttempts;
|
|
83
85
|
constructor(runner: RuntimeRunner, gate: QualityGate, maxAttempts?: number);
|
|
84
86
|
run(request: HarnessRequest): Promise<HarnessOutcome>;
|
|
87
|
+
stream(request: HarnessRequest): AsyncIterable<StreamEvent>;
|
|
85
88
|
}
|
|
86
89
|
export interface HarnessLoopOptions {
|
|
87
90
|
maxAttempts?: number;
|
|
@@ -93,6 +96,7 @@ export declare class HarnessLoop {
|
|
|
93
96
|
private maxAttempts;
|
|
94
97
|
private skillDir?;
|
|
95
98
|
constructor(runner: RuntimeRunner, evalProvider: import("../types.js").LLMProvider, options?: HarnessLoopOptions);
|
|
96
|
-
|
|
99
|
+
run(request: HarnessRequest): Promise<HarnessOutcome>;
|
|
100
|
+
stream(request: HarnessRequest): AsyncIterable<HarnessEvent>;
|
|
97
101
|
}
|
|
98
102
|
export { collectText };
|
package/dist/harness/harness.js
CHANGED
|
@@ -22,6 +22,9 @@ export class SinglePassHarness {
|
|
|
22
22
|
async run(request) {
|
|
23
23
|
return { ...await runOnce(this.runner, request), passed: true };
|
|
24
24
|
}
|
|
25
|
+
async *stream(request) {
|
|
26
|
+
yield* this.runner.run({ sessionId: crypto.randomUUID(), goal: request.goal, criteria: request.criteria?.map(c => c.text), extensions: request.extensions });
|
|
27
|
+
}
|
|
25
28
|
}
|
|
26
29
|
export class EvalLoopHarness {
|
|
27
30
|
runner;
|
|
@@ -41,6 +44,9 @@ export class EvalLoopHarness {
|
|
|
41
44
|
}
|
|
42
45
|
return outcome;
|
|
43
46
|
}
|
|
47
|
+
async *stream(request) {
|
|
48
|
+
yield* this.runner.run({ sessionId: crypto.randomUUID(), goal: request.goal, criteria: request.criteria?.map(c => c.text), extensions: request.extensions });
|
|
49
|
+
}
|
|
44
50
|
}
|
|
45
51
|
export class HarnessLoop {
|
|
46
52
|
runner;
|
|
@@ -53,7 +59,23 @@ export class HarnessLoop {
|
|
|
53
59
|
this.maxAttempts = options.maxAttempts ?? 3;
|
|
54
60
|
this.skillDir = options.skillDir;
|
|
55
61
|
}
|
|
56
|
-
async
|
|
62
|
+
async run(request) {
|
|
63
|
+
let last;
|
|
64
|
+
for await (const evt of this.stream(request))
|
|
65
|
+
last = evt;
|
|
66
|
+
const done = last?.type === "done" ? last : undefined;
|
|
67
|
+
return {
|
|
68
|
+
result: "",
|
|
69
|
+
passed: done?.verdict.passed ?? false,
|
|
70
|
+
iterations: done?.iterations ?? 0,
|
|
71
|
+
totalTokens: done?.totalTokens ?? 0,
|
|
72
|
+
status: done?.status ?? "error",
|
|
73
|
+
overallScore: done?.verdict.overallScore,
|
|
74
|
+
feedback: done?.verdict.feedback,
|
|
75
|
+
details: done?.verdict.details,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async *stream(request) {
|
|
57
79
|
const kernel = getKernel();
|
|
58
80
|
const pipeline = new kernel.EvalPipeline({ extractSkillOnPass: true });
|
|
59
81
|
const criteria = request.criteria ?? [];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
export { RuntimeRunner, collectText } from "./runtime/runner.js";
|
|
2
2
|
export type { RuntimeOptions } from "./runtime/runner.js";
|
|
3
|
+
export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
|
|
4
|
+
export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
|
|
5
|
+
export type { SubAgentRunContext } from "./runtime/sub-agent-orchestrator.js";
|
|
3
6
|
export { LocalExecutionPlane } from "./runtime/execution-plane.js";
|
|
4
7
|
export type { ExecutionPlane, RunContext } from "./runtime/execution-plane.js";
|
|
5
8
|
export { InMemorySessionLog, FileSessionLog } from "./runtime/session-log.js";
|
|
6
9
|
export type { SessionLog, SessionEvent } from "./runtime/session-log.js";
|
|
10
|
+
export { NullArchiveStore, FileArchiveStore } from "./runtime/archive.js";
|
|
11
|
+
export type { ArchiveStore } from "./runtime/archive.js";
|
|
7
12
|
export { EnvCredentialVault, InMemoryCredentialVault, ChainedCredentialVault } from "./runtime/credential-vault.js";
|
|
8
13
|
export type { CredentialVault } from "./runtime/credential-vault.js";
|
|
9
14
|
export { ProcessSandboxPlane } from "./runtime/process-sandbox-plane.js";
|
|
@@ -45,10 +50,13 @@ export type { GovernanceVerdict } from "./governance.js";
|
|
|
45
50
|
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
46
51
|
export type { HarnessRequest, HarnessOutcome, HarnessLoopOptions, QualityGate } from "./harness/harness.js";
|
|
47
52
|
export type { Message, ToolCall, ToolResult, ToolSchema, ContentPart, TextPart, ImagePart, AudioPart, StreamEvent, TextDelta, ThinkingDelta, ToolCallEvent, ToolChunk, ToolDeltaEvent, ToolSuspendEvent, ToolResultEvent, DoneEvent, ErrorEvent, PermissionRequestEvent, LLMProvider, RetryConfig, TokenUsage, ProviderToolSpec, ProviderRunState, ProviderReplay, RenderedContext, } from "./types.js";
|
|
53
|
+
export type { AgentCapabilityFilter, AgentIdentity, AgentIsolation, AgentRunSpec, AgentSpawnedObservation, ContextInheritance, KernelAgentRole, LoopResult, MilestoneCheckResult, MilestoneContract, MilestonePhase, MilestonePolicy, SubAgentResult, TerminationReason, } from "./types/agent.js";
|
|
54
|
+
export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, } from "./types/agent.js";
|
|
48
55
|
export type { AcceptanceCriterion, VerificationContract, ContractCheckResult, } from "./collaboration/contract.js";
|
|
49
56
|
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
50
57
|
export { AgentPool } from "./collaboration/pool.js";
|
|
51
|
-
export type { AgentRole, IsolatedVerifierContext } from "./collaboration/pool.js";
|
|
58
|
+
export type { AgentRole, IsolatedVerifierContext, CoordinatorConfig } from "./collaboration/pool.js";
|
|
59
|
+
export { KERNEL_ROLE_MAP } from "./collaboration/pool.js";
|
|
52
60
|
export { ContractDrivenHarness } from "./collaboration/harness.js";
|
|
53
61
|
export type { ContractOutcome, ContractHarnessOptions, Violation } from "./collaboration/harness.js";
|
|
54
62
|
export { HandoffBus } from "./collaboration/handoff.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
// ── Runtime (Layer 1.5) ────────────────────────────────────────────────────
|
|
2
2
|
export { RuntimeRunner, collectText } from "./runtime/runner.js";
|
|
3
|
+
export { FilteredExecutionPlane } from "./runtime/filtered-plane.js";
|
|
4
|
+
export { SubAgentOrchestrator, defaultSubAgentOrchestrator, spawnStandalone } from "./runtime/sub-agent-orchestrator.js";
|
|
3
5
|
export { LocalExecutionPlane } from "./runtime/execution-plane.js";
|
|
4
6
|
export { InMemorySessionLog, FileSessionLog } from "./runtime/session-log.js";
|
|
7
|
+
export { NullArchiveStore, FileArchiveStore } from "./runtime/archive.js";
|
|
5
8
|
export { EnvCredentialVault, InMemoryCredentialVault, ChainedCredentialVault } from "./runtime/credential-vault.js";
|
|
6
9
|
export { ProcessSandboxPlane } from "./runtime/process-sandbox-plane.js";
|
|
7
10
|
export { McpProxyPlane } from "./runtime/mcp-proxy-plane.js";
|
|
@@ -32,8 +35,10 @@ export { PermissionManager, PermissionMode } from "./safety/permissions.js";
|
|
|
32
35
|
export { Governance } from "./governance.js";
|
|
33
36
|
// ── Harness ────────────────────────────────────────────────────────────────
|
|
34
37
|
export { SinglePassHarness, EvalLoopHarness, HarnessLoop } from "./harness/harness.js";
|
|
38
|
+
export { agentIdentitySub, agentRunSpecToKernel, milestoneCheckFail, milestoneCheckPass, milestoneCheckResultToKernel, subAgentResultToKernel, } from "./types/agent.js";
|
|
35
39
|
export { ContractBuilder, formatContractForSystemPrompt, contractToCriteriaStrings, } from "./collaboration/contract.js";
|
|
36
40
|
export { AgentPool } from "./collaboration/pool.js";
|
|
41
|
+
export { KERNEL_ROLE_MAP } from "./collaboration/pool.js";
|
|
37
42
|
export { ContractDrivenHarness } from "./collaboration/harness.js";
|
|
38
43
|
export { HandoffBus } from "./collaboration/handoff.js";
|
|
39
44
|
export { CreatorVerifierMode, OrchestrationMode } from "./collaboration/modes/creator-verifier.js";
|
package/dist/kernel.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { Message, RenderedContext
|
|
2
|
-
import type { SkillMetadata } from "./skills/loader.js";
|
|
1
|
+
import type { Message, RenderedContext } from "./types.js";
|
|
3
2
|
export interface GovernanceVerdict {
|
|
4
3
|
kind: "allow" | "deny" | "rate_limited" | "ask_user";
|
|
5
4
|
reason?: string;
|
|
@@ -26,45 +25,6 @@ export interface RuntimeSignal {
|
|
|
26
25
|
dedupeKey?: string;
|
|
27
26
|
timestampMs: number;
|
|
28
27
|
}
|
|
29
|
-
export interface LoopAction {
|
|
30
|
-
kind: "call_llm" | "execute_tools" | "done";
|
|
31
|
-
context?: RenderedContext;
|
|
32
|
-
tools?: ToolSchema[];
|
|
33
|
-
calls?: ToolCall[];
|
|
34
|
-
result?: {
|
|
35
|
-
termination: string;
|
|
36
|
-
turnsUsed: number;
|
|
37
|
-
totalTokensUsed: bigint;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
interface LoopObservation {
|
|
41
|
-
kind: "compressed";
|
|
42
|
-
action?: string;
|
|
43
|
-
rhoAfter?: number;
|
|
44
|
-
}
|
|
45
|
-
interface LoopStateMachineInstance {
|
|
46
|
-
setAvailableSkills(skills: SkillMetadata[]): void;
|
|
47
|
-
setMemoryEnabled(enabled: boolean): void;
|
|
48
|
-
setKnowledgeEnabled(enabled: boolean): void;
|
|
49
|
-
addSystemMessage(content: string, tokens: number): void;
|
|
50
|
-
addMemoryMessage(content: string, tokens: number): void;
|
|
51
|
-
addHistoryMessage(message: Message, tokens: number): void;
|
|
52
|
-
setTools(tools: ToolSchema[]): void;
|
|
53
|
-
start(task: {
|
|
54
|
-
goal: string;
|
|
55
|
-
criteria: string[];
|
|
56
|
-
}): LoopAction;
|
|
57
|
-
resumeAfterPreload(): LoopAction;
|
|
58
|
-
feedLlmResponse(message: Message): LoopAction;
|
|
59
|
-
feedToolResults(results: ToolResult[]): LoopAction;
|
|
60
|
-
feedTimeout(): LoopAction;
|
|
61
|
-
isTerminal(): boolean;
|
|
62
|
-
preloadHistory(messages: Message[]): void;
|
|
63
|
-
drainNewMessages(): Message[];
|
|
64
|
-
readonly turn: number;
|
|
65
|
-
pressure(): number;
|
|
66
|
-
takeObservations(): LoopObservation[];
|
|
67
|
-
}
|
|
68
28
|
interface SignalRouterInstance {
|
|
69
29
|
ingest(signal: RuntimeSignal, isRunning: boolean): string;
|
|
70
30
|
next(): RuntimeSignal | null;
|
|
@@ -135,14 +95,23 @@ interface IdlePipelineInstance {
|
|
|
135
95
|
}>, nowMs: number): IdlePipelineAction;
|
|
136
96
|
feedSynthesisResult(content: string): IdlePipelineAction;
|
|
137
97
|
}
|
|
98
|
+
export interface KernelRuntimeInstance {
|
|
99
|
+
step(inputJson: string): string;
|
|
100
|
+
isTerminal(): boolean;
|
|
101
|
+
turn(): number;
|
|
102
|
+
recoveryContentBytes(): number;
|
|
103
|
+
render(): RenderedContext;
|
|
104
|
+
drainNewMessages(): Message[];
|
|
105
|
+
preservedRefs(): string[];
|
|
106
|
+
}
|
|
138
107
|
interface KernelModule {
|
|
139
108
|
Governance: new (defaultAction?: "allow" | "deny" | "ask_user") => GovernanceInstance;
|
|
140
|
-
|
|
109
|
+
KernelRuntime: new (policy: {
|
|
141
110
|
maxTokens: number;
|
|
142
111
|
maxTurns?: number;
|
|
143
112
|
maxTotalTokens?: bigint;
|
|
144
113
|
timeoutMs?: bigint;
|
|
145
|
-
}) =>
|
|
114
|
+
}) => KernelRuntimeInstance;
|
|
146
115
|
SignalRouter: new (maxQueueSize: number) => SignalRouterInstance;
|
|
147
116
|
EvalPipeline: new (options?: {
|
|
148
117
|
extractSkillOnPass?: boolean;
|
package/dist/kernel.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
const cjsRequire = createRequire(import.meta.url);
|
|
6
6
|
let cachedKernel;
|
|
7
7
|
function resolveCoreModule() {
|
|
8
|
-
const localCore = join(dirname(fileURLToPath(import.meta.url)), "
|
|
8
|
+
const localCore = join(dirname(fileURLToPath(import.meta.url)), "../../crates/deepstrike-node");
|
|
9
9
|
if (existsSync(join(localCore, "index.js")))
|
|
10
10
|
return localCore;
|
|
11
11
|
return "@deepstrike/core";
|
|
@@ -22,7 +22,9 @@ export class AnthropicProvider {
|
|
|
22
22
|
constructor(apiKey, model = "claude-sonnet-4-6", retry = { maxRetries: 3, baseDelay: 1000 }, options = {}) {
|
|
23
23
|
this.model = model;
|
|
24
24
|
this.client = withServerRuntimeGuard(() => new Anthropic({
|
|
25
|
-
...(options.authMode === "bearer"
|
|
25
|
+
...(options.authMode === "bearer"
|
|
26
|
+
? { authToken: apiKey, apiKey: null }
|
|
27
|
+
: { apiKey, authToken: null }),
|
|
26
28
|
...(options.baseURL ? { baseURL: options.baseURL } : {}),
|
|
27
29
|
}));
|
|
28
30
|
this.circuit = new CircuitBreaker();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Message } from "../types.js";
|
|
2
|
+
export interface ArchiveStore {
|
|
3
|
+
write(sessionId: string, seq: number, messages: Message[]): Promise<string>;
|
|
4
|
+
read(archiveRef: string): Promise<Message[]>;
|
|
5
|
+
}
|
|
6
|
+
export declare class NullArchiveStore implements ArchiveStore {
|
|
7
|
+
write(_sessionId: string, _seq: number, _messages: Message[]): Promise<string>;
|
|
8
|
+
read(_archiveRef: string): Promise<Message[]>;
|
|
9
|
+
}
|
|
10
|
+
export declare class FileArchiveStore implements ArchiveStore {
|
|
11
|
+
private readonly root;
|
|
12
|
+
constructor(root: string);
|
|
13
|
+
write(sessionId: string, seq: number, messages: Message[]): Promise<string>;
|
|
14
|
+
read(archiveRef: string): Promise<Message[]>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { mkdir, writeFile, readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
export class NullArchiveStore {
|
|
4
|
+
async write(_sessionId, _seq, _messages) {
|
|
5
|
+
return "";
|
|
6
|
+
}
|
|
7
|
+
async read(_archiveRef) {
|
|
8
|
+
throw new Error("NullArchiveStore does not store archives");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class FileArchiveStore {
|
|
12
|
+
root;
|
|
13
|
+
constructor(root) {
|
|
14
|
+
this.root = root;
|
|
15
|
+
}
|
|
16
|
+
async write(sessionId, seq, messages) {
|
|
17
|
+
const dir = join(this.root, sessionId);
|
|
18
|
+
await mkdir(dir, { recursive: true });
|
|
19
|
+
const filePath = join(dir, `${seq}.jsonl`);
|
|
20
|
+
const lines = messages.map(msg => JSON.stringify(msg)).join("\n") + "\n";
|
|
21
|
+
await writeFile(filePath, lines, "utf8");
|
|
22
|
+
return filePath;
|
|
23
|
+
}
|
|
24
|
+
async read(archiveRef) {
|
|
25
|
+
const content = await readFile(archiveRef, "utf8");
|
|
26
|
+
const lines = content.split("\n");
|
|
27
|
+
const messages = [];
|
|
28
|
+
for (const line of lines) {
|
|
29
|
+
if (!line.trim())
|
|
30
|
+
continue;
|
|
31
|
+
messages.push(JSON.parse(line));
|
|
32
|
+
}
|
|
33
|
+
return messages;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -23,7 +23,7 @@ export class LocalExecutionPlane {
|
|
|
23
23
|
ctx.governance.setTime?.(BigInt(Date.now()));
|
|
24
24
|
const v = ctx.governance.evaluate(c.name, c.arguments);
|
|
25
25
|
if (v.kind === "deny") {
|
|
26
|
-
yield { type: "
|
|
26
|
+
yield { type: "tool_denied", callId: c.id, toolName: c.name, reason: v.reason ?? "" };
|
|
27
27
|
yield { type: "tool_result", callId: c.id, name: c.name, content: `permission denied: ${v.reason ?? ""}`, isError: true };
|
|
28
28
|
continue;
|
|
29
29
|
}
|
|
@@ -81,7 +81,15 @@ export class LocalExecutionPlane {
|
|
|
81
81
|
const task = active[index];
|
|
82
82
|
if (result.done) {
|
|
83
83
|
const r = result.value;
|
|
84
|
-
yield {
|
|
84
|
+
yield {
|
|
85
|
+
type: "tool_result",
|
|
86
|
+
callId: r.callId,
|
|
87
|
+
name: task.call.name,
|
|
88
|
+
content: r.output,
|
|
89
|
+
isError: r.isError,
|
|
90
|
+
isFatal: r.isFatal,
|
|
91
|
+
errorKind: r.errorKind,
|
|
92
|
+
};
|
|
85
93
|
active.splice(index, 1);
|
|
86
94
|
continue;
|
|
87
95
|
}
|
|
@@ -96,9 +104,19 @@ export class LocalExecutionPlane {
|
|
|
96
104
|
return { callId: call.id, output: `unknown tool: ${call.name}`, isError: true };
|
|
97
105
|
try {
|
|
98
106
|
const args = JSON.parse(call.arguments || "{}");
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
107
|
+
const originalArgsStr = JSON.stringify(args);
|
|
108
|
+
const validation = validateToolArguments(registered.schema.parameters, args);
|
|
109
|
+
if (validation.error)
|
|
110
|
+
return { callId: call.id, output: `invalid arguments: ${validation.error}`, isError: true };
|
|
111
|
+
if (validation.repaired) {
|
|
112
|
+
yield {
|
|
113
|
+
type: "tool_argument_repaired",
|
|
114
|
+
callId: call.id,
|
|
115
|
+
name: call.name,
|
|
116
|
+
originalArguments: originalArgsStr,
|
|
117
|
+
repairedArguments: JSON.stringify(args),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
102
120
|
const output = await registered.execute(args);
|
|
103
121
|
if (isAsyncIterable(output)) {
|
|
104
122
|
let combined = "";
|
|
@@ -132,7 +150,13 @@ export class LocalExecutionPlane {
|
|
|
132
150
|
return { callId: call.id, output, isError: false };
|
|
133
151
|
}
|
|
134
152
|
catch (err) {
|
|
135
|
-
return {
|
|
153
|
+
return {
|
|
154
|
+
callId: call.id,
|
|
155
|
+
output: String(err),
|
|
156
|
+
isError: true,
|
|
157
|
+
isFatal: Boolean(err?.isFatal),
|
|
158
|
+
errorKind: err?.errorKind,
|
|
159
|
+
};
|
|
136
160
|
}
|
|
137
161
|
}
|
|
138
162
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ToolCall, ToolSchema, StreamEvent } from "../types.js";
|
|
2
|
+
import type { RegisteredTool } from "../tools/index.js";
|
|
3
|
+
import type { ExecutionPlane, RunContext } from "./execution-plane.js";
|
|
4
|
+
/** Wraps an execution plane, allowing only manifest-permitted tool IDs (+ meta-tools). */
|
|
5
|
+
export declare class FilteredExecutionPlane implements ExecutionPlane {
|
|
6
|
+
private readonly inner;
|
|
7
|
+
private readonly permittedIds;
|
|
8
|
+
private readonly metaTools;
|
|
9
|
+
constructor(inner: ExecutionPlane, permittedIds: Set<string>, metaTools?: Set<string>);
|
|
10
|
+
register(...tools: RegisteredTool[]): this;
|
|
11
|
+
unregister(name: string): this;
|
|
12
|
+
schemas(): ToolSchema[];
|
|
13
|
+
executeAll(calls: ToolCall[], ctx: RunContext): AsyncIterable<StreamEvent>;
|
|
14
|
+
}
|