@deepstrike/wasm 0.2.77 → 0.2.79
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/agent.d.ts +6 -2
- package/dist/agent.js +59 -19
- package/dist/index.d.ts +7 -9
- package/dist/index.js +3 -5
- package/dist/memory/attestation.d.ts +38 -0
- package/dist/memory/attestation.js +43 -0
- package/dist/memory/authority.d.ts +2 -0
- package/dist/memory/authority.js +3 -1
- package/dist/memory/candidate-sink.d.ts +66 -0
- package/dist/memory/candidate-sink.js +82 -0
- package/dist/memory/durable.d.ts +4 -2
- package/dist/memory/durable.js +2 -0
- package/dist/memory/index.d.ts +9 -1
- package/dist/memory/index.js +5 -0
- package/dist/memory/lifecycle.d.ts +82 -0
- package/dist/memory/lifecycle.js +46 -0
- package/dist/memory/recall-projection.d.ts +5 -0
- package/dist/memory/recall-projection.js +18 -0
- package/dist/memory/runtime-policy.d.ts +15 -0
- package/dist/memory/runtime-policy.js +26 -0
- package/dist/memory/writer.d.ts +22 -0
- package/dist/memory/writer.js +41 -0
- package/dist/providers/anthropic-compaction.d.ts +84 -0
- package/dist/providers/anthropic-compaction.js +222 -0
- package/dist/providers/anthropic.d.ts +41 -1
- package/dist/providers/anthropic.js +187 -18
- package/dist/providers/base.js +11 -1
- package/dist/runtime/canonical-kernel-step.d.ts +1 -2
- package/dist/runtime/canonical-kernel-step.js +74 -8
- package/dist/runtime/execution-plane.js +1 -1
- package/dist/runtime/index.d.ts +0 -2
- package/dist/runtime/index.js +0 -1
- package/dist/runtime/kernel-event-log.d.ts +8 -0
- package/dist/runtime/kernel-event-log.js +63 -1
- package/dist/runtime/kernel-step.d.ts +15 -2
- package/dist/runtime/os-snapshot.js +1 -0
- package/dist/runtime/runner.d.ts +44 -26
- package/dist/runtime/runner.js +206 -240
- package/dist/runtime/session-event-registry.generated.d.ts +212 -0
- package/dist/runtime/session-event-registry.generated.js +112 -0
- package/dist/runtime/session-log.d.ts +83 -16
- package/dist/runtime/session-log.js +10 -58
- package/dist/runtime/session-repair.d.ts +0 -3
- package/dist/runtime/session-repair.js +0 -3
- package/dist/runtime/sub-agent-orchestrator.d.ts +5 -1
- package/dist/runtime/sub-agent-orchestrator.js +4 -0
- package/dist/runtime/types/agent.d.ts +18 -52
- package/dist/runtime/types/agent.js +8 -45
- package/dist/types.d.ts +10 -5
- package/package.json +3 -3
- package/dist/memory/extraction.d.ts +0 -4
- package/dist/memory/extraction.js +0 -48
- package/dist/runtime/context.d.ts +0 -28
- package/dist/runtime/context.js +0 -16
- package/dist/runtime/evolution.d.ts +0 -189
- package/dist/runtime/evolution.js +0 -25
- package/dist/runtime/reducers.d.ts +0 -15
- package/dist/runtime/reducers.js +0 -57
- package/dist/runtime/verifiable-report.d.ts +0 -59
- package/dist/runtime/verifiable-report.js +0 -64
- package/dist/runtime/workflow-control-flow.d.ts +0 -21
- package/dist/runtime/workflow-control-flow.js +0 -83
|
@@ -84,18 +84,8 @@ export interface LoopResult {
|
|
|
84
84
|
finalMessage?: ModelMessage;
|
|
85
85
|
turnsUsed: number;
|
|
86
86
|
totalTokensUsed: number;
|
|
87
|
-
/** loop-control loop stop signal: a loop iteration sets `false` to end the loop before `max_iters`.
|
|
88
|
-
* `undefined` (every non-loop result) ⇒ no opinion → run to the cap. Sent only when set. */
|
|
89
|
-
loopContinue?: boolean;
|
|
90
|
-
/** A#2 classify routing: a classifier node reports the chosen branch label here; the kernel runs
|
|
91
|
-
* that branch and prunes the rest. Sent only when set. */
|
|
92
|
-
classifyBranch?: string;
|
|
93
|
-
/** A#2 tournament verdict: a judge reports the winning entrant's agent id here. Sent only when set. */
|
|
94
|
-
tournamentWinner?: string;
|
|
95
87
|
/** ③ loop-agent pacing: the kernel-adjudicated after-round decision, surfaced by the orchestrator
|
|
96
|
-
* from the child's done event.
|
|
97
|
-
* vocabulary (stop → loopContinue=false).
|
|
98
|
-
* SDK-internal — stripped by `subAgentResultToKernel`. */
|
|
88
|
+
* from the child's done event. SDK-internal — stripped by `subAgentResultToKernel`. */
|
|
99
89
|
paceDecision?: import("../kernel-step.js").PaceDecision;
|
|
100
90
|
}
|
|
101
91
|
export interface SubAgentResult {
|
|
@@ -170,27 +160,6 @@ export interface WorkflowNodeSpec {
|
|
|
170
160
|
trust?: NodeTrust;
|
|
171
161
|
/** G3: JSON Schema the node's output must conform to (validated + retried SDK-side). */
|
|
172
162
|
outputSchema?: Record<string, unknown>;
|
|
173
|
-
/** G2: make this a deterministic reduce node — runs no LLM; the runner routes it to the registered
|
|
174
|
-
* reducer of this name over its `dependsOn` nodes' outputs. */
|
|
175
|
-
reducer?: string;
|
|
176
|
-
/** loop-control: make this a *loop* node — re-run its agent up to `maxIters` times. An iteration may end
|
|
177
|
-
* the loop early by reporting `loopContinue: false` (the runner solicits this from the agent). */
|
|
178
|
-
loop?: {
|
|
179
|
-
maxIters: number;
|
|
180
|
-
};
|
|
181
|
-
/** A#2: make this a *classify* node — its agent picks exactly one branch `label`; that branch's
|
|
182
|
-
* nodes run and the others are pruned. Each branch node must list this node's index in `dependsOn`. */
|
|
183
|
-
classify?: {
|
|
184
|
-
branches: Array<{
|
|
185
|
-
label: string;
|
|
186
|
-
nodes: number[];
|
|
187
|
-
}>;
|
|
188
|
-
};
|
|
189
|
-
/** A#2: make this a *tournament controller* — generate each `entrants` candidate in parallel, then
|
|
190
|
-
* pairwise-judge them to one winner (this node's `task.goal` is the judging criterion). ≥2 entrants. */
|
|
191
|
-
tournament?: {
|
|
192
|
-
entrants: WorkflowTaskSpec[];
|
|
193
|
-
};
|
|
194
163
|
/** M4/G5: cap this node's child run at `tokenBudget` cumulative tokens (the per-node "use N tokens"). */
|
|
195
164
|
tokenBudget?: number;
|
|
196
165
|
/** O3: cap this node's child run at `maxTurns` provider turns (falls back to the parent's). */
|
|
@@ -239,6 +208,13 @@ export interface WorkflowOutcome {
|
|
|
239
208
|
rejection?: ControlRequestRejection;
|
|
240
209
|
}
|
|
241
210
|
export declare function workflowNodeOutcomeFromKernel(raw: KernelWorkflowNodeOutcome): WorkflowNodeOutcome;
|
|
211
|
+
/** Plan task 1.1 · one parent knowledge item a child run starts with (kernel-chosen by scope). */
|
|
212
|
+
export interface InheritedKnowledge {
|
|
213
|
+
content: string;
|
|
214
|
+
key?: string;
|
|
215
|
+
tokens?: number;
|
|
216
|
+
pinned?: boolean;
|
|
217
|
+
}
|
|
242
218
|
/** Per-node spawn descriptor carried in the `workflow_batch_spawned` observation. */
|
|
243
219
|
export interface WorkflowSpawnInfo {
|
|
244
220
|
agent_id: string;
|
|
@@ -253,23 +229,13 @@ export interface WorkflowSpawnInfo {
|
|
|
253
229
|
trust?: string;
|
|
254
230
|
/** G3: JSON Schema the node's output must conform to (carried verbatim from the spec). */
|
|
255
231
|
output_schema?: Record<string, unknown>;
|
|
256
|
-
/**
|
|
257
|
-
|
|
258
|
-
/** The dependency agent ids for EVERY dependent node (W-N2: a DAG edge carries data). A reduce
|
|
259
|
-
* node's registered function consumes them; every other node gets its deps' outputs in context. */
|
|
232
|
+
/** The dependency agent ids for EVERY dependent node (W-N2: a DAG edge carries data): the node
|
|
233
|
+
* gets its deps' outputs in context. */
|
|
260
234
|
input_agent_ids?: string[];
|
|
261
|
-
/**
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
right: string;
|
|
266
|
-
};
|
|
267
|
-
/** loop-control: present only for a *loop* iteration spawn — the loop's `max_iters`. Marks the spawn as a
|
|
268
|
-
* loop iteration so the runner solicits + reports a `loopContinue` stop signal. */
|
|
269
|
-
loop_max_iters?: number;
|
|
270
|
-
/** A#2: present only for a *classify* spawn — the branch labels the classifier must choose among.
|
|
271
|
-
* Non-empty marks the spawn as a classifier so the runner instructs the agent + reports `classifyBranch`. */
|
|
272
|
-
classify_labels?: string[];
|
|
235
|
+
/** The kernel-composed dependency section that follows the node's goal. */
|
|
236
|
+
dependency_brief?: string;
|
|
237
|
+
/** Plan task 1.1 · the parent knowledge the kernel lets this node inherit (by item scope). */
|
|
238
|
+
inherited_knowledge?: InheritedKnowledge[];
|
|
273
239
|
/** M4/G5: the node's per-node cumulative token cap, if set — the runner caps the child run here. */
|
|
274
240
|
token_budget?: number;
|
|
275
241
|
/** O3: per-node turn cap → the child run's `maxTurns`. */
|
|
@@ -317,8 +283,8 @@ export declare function generateAndFilter(generators: WorkflowTaskSpec[], filter
|
|
|
317
283
|
*/
|
|
318
284
|
export declare function verifyRules(rules: WorkflowTaskSpec[], skeptic?: WorkflowTaskSpec): WorkflowSpec;
|
|
319
285
|
/**
|
|
320
|
-
* Generate → evaluate
|
|
321
|
-
*
|
|
322
|
-
*
|
|
286
|
+
* Generate → evaluate template (parity with node/python `genEval`): a worker node (worktree
|
|
287
|
+
* isolation, full context) feeding a fresh-context verifier whose output is pinned to the kernel's
|
|
288
|
+
* verdict schema. Retry-with-feedback is `AttemptLoop`. Async because the wasm kernel loads lazily.
|
|
323
289
|
*/
|
|
324
|
-
export declare function genEval(worker: WorkflowTaskSpec, evaluate: WorkflowTaskSpec,
|
|
290
|
+
export declare function genEval(worker: WorkflowTaskSpec, evaluate: WorkflowTaskSpec, extractSkillOnPass?: boolean): Promise<WorkflowSpec>;
|
|
@@ -96,11 +96,6 @@ export function subAgentResultToKernel(result) {
|
|
|
96
96
|
: null,
|
|
97
97
|
turns_used: result.result.turnsUsed,
|
|
98
98
|
total_tokens_used: result.result.totalTokensUsed,
|
|
99
|
-
// A#2: control-flow signals — additive, omitted on the wire when unset so a plain spawn's
|
|
100
|
-
// result is byte-identical to before. The kernel reads each only for the matching node kind.
|
|
101
|
-
...(result.result.loopContinue !== undefined ? { loop_continue: result.result.loopContinue } : {}),
|
|
102
|
-
...(result.result.classifyBranch !== undefined ? { classify_branch: result.result.classifyBranch } : {}),
|
|
103
|
-
...(result.result.tournamentWinner !== undefined ? { tournament_winner: result.result.tournamentWinner } : {}),
|
|
104
99
|
},
|
|
105
100
|
};
|
|
106
101
|
}
|
|
@@ -179,28 +174,9 @@ function workflowTaskToKernel(t) {
|
|
|
179
174
|
...(task.lane ? { lane: task.lane } : {}),
|
|
180
175
|
};
|
|
181
176
|
}
|
|
182
|
-
/** Lower a node's control-flow kind to the kernel's serde-tagged `NodeKind` JSON, or `undefined` for
|
|
183
|
-
* a plain spawn. `reducer` / `loop` / `classify` / `tournament` are mutually exclusive. */
|
|
184
|
-
function nodeKindToKernel(n) {
|
|
185
|
-
const declared = [n.reducer != null, n.loop != null, n.classify != null, n.tournament != null].filter(Boolean).length;
|
|
186
|
-
if (declared > 1) {
|
|
187
|
-
throw new Error("a workflow node may declare at most one of: reducer, loop, classify, tournament");
|
|
188
|
-
}
|
|
189
|
-
if (n.reducer != null)
|
|
190
|
-
return { type: "reduce", reducer: n.reducer };
|
|
191
|
-
if (n.loop != null)
|
|
192
|
-
return { type: "loop", max_iters: n.loop.maxIters };
|
|
193
|
-
if (n.classify != null) {
|
|
194
|
-
return { type: "classify", branches: n.classify.branches.map(b => ({ label: b.label, nodes: b.nodes })) };
|
|
195
|
-
}
|
|
196
|
-
if (n.tournament != null)
|
|
197
|
-
return { type: "tournament", entrants: n.tournament.entrants.map(workflowTaskToKernel) };
|
|
198
|
-
return undefined;
|
|
199
|
-
}
|
|
200
177
|
/** Map one host `WorkflowNodeSpec` to its snake_case canonical JSON. Shared by the workflow root and
|
|
201
178
|
* `submit_workflow_nodes` (R3-1) so the two encodings never drift. */
|
|
202
179
|
export function workflowNodeSpecToKernel(n) {
|
|
203
|
-
const kind = nodeKindToKernel(n);
|
|
204
180
|
const schedulingFactors = schedulingFactorsToKernel(n.schedulingFactors);
|
|
205
181
|
return {
|
|
206
182
|
...(n.nodeId ? { node_id: n.nodeId } : {}),
|
|
@@ -211,8 +187,6 @@ export function workflowNodeSpecToKernel(n) {
|
|
|
211
187
|
...(n.modelHint ? { model_hint: n.modelHint } : {}),
|
|
212
188
|
...(n.trust && n.trust !== "trusted" ? { trust: n.trust } : {}),
|
|
213
189
|
...(n.outputSchema ? { output_schema: n.outputSchema } : {}),
|
|
214
|
-
// A#2/G2: loop / classify / tournament / reduce lower to a serde-tagged `NodeKind`; spawn omits it.
|
|
215
|
-
...(kind ? { kind } : {}),
|
|
216
190
|
// M4/G5: per-node token cap (additive; omitted when unset).
|
|
217
191
|
...(n.tokenBudget != null ? { token_budget: n.tokenBudget } : {}),
|
|
218
192
|
// O3: per-node turn / wall-clock caps (additive; omitted when unset).
|
|
@@ -304,15 +278,10 @@ export const startWorkflowTool = {
|
|
|
304
278
|
};
|
|
305
279
|
/** Build a sub-agent run spec for a kernel-generated workflow node. */
|
|
306
280
|
export function workflowNodeToSpec(node, parentSessionId) {
|
|
307
|
-
// W-N6 transcript-as-carry: a loop node's iterations share ONE stable session id (the `-i{k}`
|
|
308
|
-
// suffix names the spawn, not the session), so iteration k replays the transcript of 0..k-1 —
|
|
309
|
-
// "do the next increment" actually sees the previous increments. The agent_id keeps the
|
|
310
|
-
// per-iteration suffix (kernel completion routing).
|
|
311
|
-
const sessionNodeId = node.loop_max_iters != null ? node.agent_id.replace(/-i\d+$/, "") : node.agent_id;
|
|
312
281
|
return {
|
|
313
282
|
identity: {
|
|
314
283
|
agentId: node.agent_id,
|
|
315
|
-
sessionId: `${parentSessionId}-${
|
|
284
|
+
sessionId: `${parentSessionId}-${node.agent_id}`,
|
|
316
285
|
isSubAgent: true,
|
|
317
286
|
parentSessionId,
|
|
318
287
|
},
|
|
@@ -326,11 +295,6 @@ export function workflowNodeToSpec(node, parentSessionId) {
|
|
|
326
295
|
// O3: carry the node's turn / wall-clock caps (the orchestrator already honors these).
|
|
327
296
|
...(node.max_turns != null ? { maxTurns: node.max_turns } : {}),
|
|
328
297
|
...(node.max_wall_ms != null ? { maxWallMs: node.max_wall_ms } : {}),
|
|
329
|
-
// DW-3 one continuation vocabulary: a loop ITERATION runs with the pacing trap armed, so the
|
|
330
|
-
// agent signals continue/stop through the kernel-adjudicated `pace` meta-tool instead of a
|
|
331
|
-
// text-sniffed JSON blob. One iteration = one round; the DAG (not max_rounds) caps iterations,
|
|
332
|
-
// and default stop means "ended without pacing" = done — the CC silence-is-completion contract.
|
|
333
|
-
...(node.loop_max_iters != null ? { loopRound: { defaultAction: "stop" } } : {}),
|
|
334
298
|
};
|
|
335
299
|
}
|
|
336
300
|
/** Build the host manifest for a kernel-generated workflow node. */
|
|
@@ -362,7 +326,7 @@ export function fanoutSynthesize(workers, synthesize) {
|
|
|
362
326
|
task: asTask(synthesize),
|
|
363
327
|
role: "plan",
|
|
364
328
|
isolation: "shared",
|
|
365
|
-
contextInheritance: "
|
|
329
|
+
contextInheritance: "system_only",
|
|
366
330
|
dependsOn: workers.map((_, i) => i),
|
|
367
331
|
});
|
|
368
332
|
return { nodes };
|
|
@@ -373,7 +337,7 @@ export function generateAndFilter(generators, filter) {
|
|
|
373
337
|
task: asTask(t),
|
|
374
338
|
role: "implement",
|
|
375
339
|
isolation: "worktree",
|
|
376
|
-
contextInheritance: "
|
|
340
|
+
contextInheritance: "system_only",
|
|
377
341
|
}));
|
|
378
342
|
nodes.push({
|
|
379
343
|
task: asTask(filter),
|
|
@@ -407,11 +371,11 @@ export function verifyRules(rules, skeptic) {
|
|
|
407
371
|
return { nodes };
|
|
408
372
|
}
|
|
409
373
|
/**
|
|
410
|
-
* Generate → evaluate
|
|
411
|
-
*
|
|
412
|
-
*
|
|
374
|
+
* Generate → evaluate template (parity with node/python `genEval`): a worker node (worktree
|
|
375
|
+
* isolation, full context) feeding a fresh-context verifier whose output is pinned to the kernel's
|
|
376
|
+
* verdict schema. Retry-with-feedback is `AttemptLoop`. Async because the wasm kernel loads lazily.
|
|
413
377
|
*/
|
|
414
|
-
export async function genEval(worker, evaluate,
|
|
378
|
+
export async function genEval(worker, evaluate, extractSkillOnPass = true) {
|
|
415
379
|
const kernel = await getKernel();
|
|
416
380
|
const schema = JSON.parse(kernel.verdictOutputSchema(extractSkillOnPass));
|
|
417
381
|
return {
|
|
@@ -420,8 +384,7 @@ export async function genEval(worker, evaluate, maxIters = 3, extractSkillOnPass
|
|
|
420
384
|
task: asTask(worker),
|
|
421
385
|
role: "implement",
|
|
422
386
|
isolation: "worktree",
|
|
423
|
-
contextInheritance: "
|
|
424
|
-
loop: { maxIters: Math.max(1, maxIters) },
|
|
387
|
+
contextInheritance: "system_only",
|
|
425
388
|
},
|
|
426
389
|
{
|
|
427
390
|
task: asTask(evaluate),
|
package/dist/types.d.ts
CHANGED
|
@@ -243,6 +243,16 @@ export interface ProviderDescriptor {
|
|
|
243
243
|
supported: boolean;
|
|
244
244
|
requiresStrictPairing: boolean;
|
|
245
245
|
};
|
|
246
|
+
/** Context tiers this provider performs natively as configured. The runner hands each one to
|
|
247
|
+
* the provider and the kernel skips its own; renewal is never delegated. */
|
|
248
|
+
nativeContext?: NativeContextTiers;
|
|
249
|
+
}
|
|
250
|
+
/** Context-management tiers a provider can perform server-side. */
|
|
251
|
+
export interface NativeContextTiers {
|
|
252
|
+
/** Old tool results are cleared before the model sees them. */
|
|
253
|
+
toolResultClearing?: boolean;
|
|
254
|
+
/** Earlier history is summarized server-side. */
|
|
255
|
+
compaction?: boolean;
|
|
246
256
|
}
|
|
247
257
|
export type MeasurementSource = {
|
|
248
258
|
kind: "native";
|
|
@@ -321,8 +331,3 @@ export interface LLMProvider {
|
|
|
321
331
|
* providers that ignore it still stop processing immediately. */
|
|
322
332
|
signal?: AbortSignal): AsyncIterable<StreamEvent>;
|
|
323
333
|
}
|
|
324
|
-
export interface MemorySummarizer {
|
|
325
|
-
summarize(archived: ModelMessage[], context: {
|
|
326
|
-
action?: string;
|
|
327
|
-
}): Promise<string>;
|
|
328
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepstrike/wasm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.79",
|
|
4
4
|
"description": "DeepStrike WASM SDK — browser, Cloudflare Workers, Deno Deploy",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"build:wasm": "wasm-pack build ../crates/deepstrike-wasm --target bundler --out-dir ../../wasm/pkg",
|
|
15
15
|
"build": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\" && tsc",
|
|
16
16
|
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
|
17
|
-
"test:canonical-binding": "wasm-pack build ../crates/deepstrike-wasm --target nodejs --dev --out-dir ../../wasm/pkg-node && node tests/canonical-binding.node.cjs && node tests/golden-fixtures-sweep.node.cjs && npm run build && node tests/boundary-p0-regressions.node.mjs && node tests/boundary-p1-regressions.node.mjs && node tests/boundary-p2-regressions.node.mjs"
|
|
17
|
+
"test:canonical-binding": "wasm-pack build ../crates/deepstrike-wasm --target nodejs --dev --out-dir ../../wasm/pkg-node && node tests/canonical-binding.node.cjs && node tests/golden-fixtures-sweep.node.cjs && npm run build && node tests/boundary-p0-regressions.node.mjs && node tests/boundary-p1-regressions.node.mjs && node tests/boundary-p2-regressions.node.mjs && node tests/memory-candidate-binding.node.mjs && node tests/memory-recall-renewal.node.mjs"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@deepstrike/wasm-kernel": "0.2.
|
|
20
|
+
"@deepstrike/wasm-kernel": "0.2.79"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/jest": "^30.0.0",
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { LLMProvider } from "../types.js";
|
|
2
|
-
import type { MemoryRecord, MemoryScope, SessionData } from "./index.js";
|
|
3
|
-
export declare function extractSessionMemories(provider: LLMProvider, session: SessionData, scope: MemoryScope, systemPrompt?: string): Promise<MemoryRecord[]>;
|
|
4
|
-
export declare function parseExtractedMemories(output: string, session: SessionData, scope: MemoryScope): MemoryRecord[];
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const KINDS = new Set(["user", "feedback", "project", "reference"]);
|
|
2
|
-
export async function extractSessionMemories(provider, session, scope, systemPrompt) {
|
|
3
|
-
const transcript = session.messages.map(message => `[${message.role.toUpperCase()}] ${message.content}`).join("\n").slice(0, 8_000);
|
|
4
|
-
const context = {
|
|
5
|
-
systemText: [systemPrompt, "Extract durable, reusable facts from this completed session. Return only JSON; do not include transient progress or guesses."].filter(Boolean).join("\n\n"),
|
|
6
|
-
turns: [{ role: "user", content: `${transcript}\n\nReturn {"memories":[{"name":"stable-kebab-key","kind":"user|feedback|project|reference","content":"fact","description":"why durable","confidence":0.0,"links":[],"pinned":false,"ttl_days":null,"evidence_refs":[]}]} with at most 10 items. Return {"memories":[]} when nothing is durable.`, toolCalls: [] }],
|
|
7
|
-
};
|
|
8
|
-
let output = "";
|
|
9
|
-
const state = provider.createRunState?.();
|
|
10
|
-
for await (const event of provider.stream(context, [], undefined, state)) {
|
|
11
|
-
if (event.type === "text_delta" && "delta" in event)
|
|
12
|
-
output += event.delta;
|
|
13
|
-
}
|
|
14
|
-
return parseExtractedMemories(output, session, scope);
|
|
15
|
-
}
|
|
16
|
-
export function parseExtractedMemories(output, session, scope) {
|
|
17
|
-
let value;
|
|
18
|
-
try {
|
|
19
|
-
value = JSON.parse(output.trim().replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/, ""));
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
if (!value || typeof value !== "object" || !Array.isArray(value.memories))
|
|
25
|
-
return [];
|
|
26
|
-
const records = [];
|
|
27
|
-
for (const raw of value.memories.slice(0, 10)) {
|
|
28
|
-
if (!raw || typeof raw !== "object")
|
|
29
|
-
continue;
|
|
30
|
-
const draft = raw;
|
|
31
|
-
const name = typeof draft.name === "string" ? draft.name.trim() : "";
|
|
32
|
-
const kind = typeof draft.kind === "string" && KINDS.has(draft.kind) ? draft.kind : undefined;
|
|
33
|
-
const content = typeof draft.content === "string" ? draft.content.trim() : "";
|
|
34
|
-
if (!name || !kind || !content)
|
|
35
|
-
continue;
|
|
36
|
-
records.push({
|
|
37
|
-
record_id: `${scope.tenant_id}:${scope.namespace}:${kind}:${name}`, scope, name, kind, content,
|
|
38
|
-
description: typeof draft.description === "string" ? draft.description.trim() : "",
|
|
39
|
-
provenance: { session_id: session.sessionId, author: "extraction", trust: "untrusted", evidence_refs: Array.isArray(draft.evidence_refs) ? draft.evidence_refs.filter((ref) => typeof ref === "string") : [] },
|
|
40
|
-
created_at: session.updatedAtMs, updated_at: session.updatedAtMs, recall_count: 0,
|
|
41
|
-
confidence: typeof draft.confidence === "number" ? Math.max(0, Math.min(1, draft.confidence)) : 0.5,
|
|
42
|
-
links: Array.isArray(draft.links) ? draft.links.filter((link) => typeof link === "string") : [],
|
|
43
|
-
pinned: draft.pinned === true,
|
|
44
|
-
...(typeof draft.ttl_days === "number" && Number.isInteger(draft.ttl_days) && draft.ttl_days > 0 ? { ttl_days: draft.ttl_days } : {}),
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return records;
|
|
48
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { RecordedPromptMeasurement, ResolvedProviderRoute } from "../providers/request-plan.js";
|
|
2
|
-
import type { ContextExecutionInput, ContextPlan, ContextState, EvaluationContextBinding } from "./evolution.js";
|
|
3
|
-
/** Host evidence completing the kernel's immutable context candidate. */
|
|
4
|
-
export interface ContextProviderPreparationRequest {
|
|
5
|
-
readonly effect: Record<string, unknown>;
|
|
6
|
-
readonly request_fingerprint: string;
|
|
7
|
-
readonly provider_route: ResolvedProviderRoute;
|
|
8
|
-
readonly prompt_measurement: RecordedPromptMeasurement;
|
|
9
|
-
}
|
|
10
|
-
export interface ContextPrepared {
|
|
11
|
-
readonly state: ContextState;
|
|
12
|
-
readonly provider_route: ResolvedProviderRoute;
|
|
13
|
-
readonly prompt_measurement: RecordedPromptMeasurement;
|
|
14
|
-
readonly execution_input: ContextExecutionInput;
|
|
15
|
-
readonly plan: ContextPlan;
|
|
16
|
-
readonly binding: EvaluationContextBinding;
|
|
17
|
-
}
|
|
18
|
-
export type ContextPrepareJson = (request: string) => string;
|
|
19
|
-
export type ContextVerifyJson = (request: string) => string;
|
|
20
|
-
/** All validation and content addressing are delegated to the Rust authority. */
|
|
21
|
-
export declare function createContextPreparationAdapter(prepareJson: ContextPrepareJson, verifyJson: ContextVerifyJson): {
|
|
22
|
-
verify(effect: Record<string, unknown>, preparation: ContextPrepared): boolean;
|
|
23
|
-
prepare(request: ContextProviderPreparationRequest): ContextPrepared;
|
|
24
|
-
};
|
|
25
|
-
export declare function createNativeContextPreparationAdapter(): Promise<{
|
|
26
|
-
verify(effect: Record<string, unknown>, preparation: ContextPrepared): boolean;
|
|
27
|
-
prepare(request: ContextProviderPreparationRequest): ContextPrepared;
|
|
28
|
-
}>;
|
package/dist/runtime/context.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { getKernel } from "./kernel.js";
|
|
2
|
-
/** All validation and content addressing are delegated to the Rust authority. */
|
|
3
|
-
export function createContextPreparationAdapter(prepareJson, verifyJson) {
|
|
4
|
-
return {
|
|
5
|
-
verify(effect, preparation) {
|
|
6
|
-
return JSON.parse(verifyJson(JSON.stringify({ effect, preparation })));
|
|
7
|
-
},
|
|
8
|
-
prepare(request) {
|
|
9
|
-
return JSON.parse(prepareJson(JSON.stringify(request)));
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export async function createNativeContextPreparationAdapter() {
|
|
14
|
-
const kernel = await getKernel();
|
|
15
|
-
return createContextPreparationAdapter(kernel.contextPrepareJson, kernel.contextVerifyJson);
|
|
16
|
-
}
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
export type ArtifactKind = "runtime" | "skill" | "prompt" | "policy" | "toolset" | "bundle";
|
|
2
|
-
export interface ArtifactRef {
|
|
3
|
-
readonly kind: ArtifactKind;
|
|
4
|
-
readonly digest: string;
|
|
5
|
-
}
|
|
6
|
-
export interface ArtifactManifest {
|
|
7
|
-
readonly kind: ArtifactKind;
|
|
8
|
-
readonly payload_digest: string;
|
|
9
|
-
readonly parents: readonly string[];
|
|
10
|
-
readonly toolchain_digest: string;
|
|
11
|
-
readonly scope: string;
|
|
12
|
-
}
|
|
13
|
-
export interface ArtifactVersion {
|
|
14
|
-
readonly digest: string;
|
|
15
|
-
readonly manifest: ArtifactManifest;
|
|
16
|
-
}
|
|
17
|
-
export interface ArtifactSet {
|
|
18
|
-
readonly digest: string;
|
|
19
|
-
readonly artifacts: readonly ArtifactRef[];
|
|
20
|
-
}
|
|
21
|
-
export interface EvolutionProposal {
|
|
22
|
-
readonly digest: string;
|
|
23
|
-
readonly base_artifact_set: string;
|
|
24
|
-
readonly candidate_artifact_set: string;
|
|
25
|
-
readonly objective: string;
|
|
26
|
-
readonly change_manifest: string;
|
|
27
|
-
readonly proposer: string;
|
|
28
|
-
readonly constraints: readonly string[];
|
|
29
|
-
}
|
|
30
|
-
export interface EvaluationContextBinding {
|
|
31
|
-
readonly digest: string;
|
|
32
|
-
readonly operation_id: string;
|
|
33
|
-
readonly execution_input: string;
|
|
34
|
-
readonly context_state: string;
|
|
35
|
-
readonly context_policy: string;
|
|
36
|
-
readonly context_plan: string;
|
|
37
|
-
readonly rendered_snapshot: string;
|
|
38
|
-
readonly prompt_measurement: string;
|
|
39
|
-
readonly provider_route: string;
|
|
40
|
-
readonly cache_prefix?: string;
|
|
41
|
-
}
|
|
42
|
-
export type ContextEntrySource = "system" | "knowledge" | "history" | "state" | "signal";
|
|
43
|
-
export type ContextPlanAction = "include" | "excerpt" | "collapse" | "page_out" | "omit";
|
|
44
|
-
export interface ContextEntryRef {
|
|
45
|
-
readonly entry_id: string;
|
|
46
|
-
readonly content_digest: string;
|
|
47
|
-
readonly source: ContextEntrySource;
|
|
48
|
-
readonly ordinal: number;
|
|
49
|
-
}
|
|
50
|
-
export interface ContextState {
|
|
51
|
-
readonly schema: "context/v1";
|
|
52
|
-
readonly generation: number;
|
|
53
|
-
readonly system: readonly ContextEntryRef[];
|
|
54
|
-
readonly knowledge: readonly ContextEntryRef[];
|
|
55
|
-
readonly history: readonly ContextEntryRef[];
|
|
56
|
-
readonly state: readonly ContextEntryRef[];
|
|
57
|
-
readonly task_state: string;
|
|
58
|
-
readonly signals: readonly string[];
|
|
59
|
-
readonly digest: string;
|
|
60
|
-
}
|
|
61
|
-
export interface ContextSelection {
|
|
62
|
-
readonly entry_id: string;
|
|
63
|
-
readonly action: ContextPlanAction;
|
|
64
|
-
readonly reason: string;
|
|
65
|
-
}
|
|
66
|
-
export interface ContextPlan {
|
|
67
|
-
readonly schema: "context/v1";
|
|
68
|
-
readonly plan_id: string;
|
|
69
|
-
readonly operation_id: string;
|
|
70
|
-
readonly step_id: string;
|
|
71
|
-
readonly state_digest: string;
|
|
72
|
-
readonly state_generation: number;
|
|
73
|
-
readonly runtime_inputs: string;
|
|
74
|
-
readonly policy_digest: string;
|
|
75
|
-
readonly provider_profile_digest: string;
|
|
76
|
-
readonly measurement_fingerprints: readonly string[];
|
|
77
|
-
readonly selections: readonly ContextSelection[];
|
|
78
|
-
readonly input_budget_tokens: number;
|
|
79
|
-
readonly projected_tokens: number;
|
|
80
|
-
readonly pressure_ppm: number;
|
|
81
|
-
readonly cache_prefix: {
|
|
82
|
-
readonly digest: string;
|
|
83
|
-
readonly entries: number;
|
|
84
|
-
} | null;
|
|
85
|
-
}
|
|
86
|
-
export interface ContextExecutionInput {
|
|
87
|
-
readonly schema: "context/v1";
|
|
88
|
-
readonly input_digest: string;
|
|
89
|
-
readonly operation_id: string;
|
|
90
|
-
readonly step_id: string;
|
|
91
|
-
readonly input_sequence: number;
|
|
92
|
-
readonly state_digest: string;
|
|
93
|
-
readonly policy_digest: string;
|
|
94
|
-
readonly plan_digest: string;
|
|
95
|
-
readonly rendered_snapshot: string;
|
|
96
|
-
readonly prompt_measurement: string;
|
|
97
|
-
readonly provider_route: string;
|
|
98
|
-
readonly cache_prefix: {
|
|
99
|
-
readonly digest: string;
|
|
100
|
-
readonly entries: number;
|
|
101
|
-
} | null;
|
|
102
|
-
}
|
|
103
|
-
export interface ContextPreparationRequest {
|
|
104
|
-
readonly operation_id: string;
|
|
105
|
-
readonly step_id: string;
|
|
106
|
-
readonly input_sequence: number;
|
|
107
|
-
readonly policy_digest: string;
|
|
108
|
-
readonly prompt_measurement: string;
|
|
109
|
-
readonly provider_route: string;
|
|
110
|
-
}
|
|
111
|
-
export interface EvaluationRun {
|
|
112
|
-
readonly digest: string;
|
|
113
|
-
readonly proposal: string;
|
|
114
|
-
readonly baseline_artifact_set: string;
|
|
115
|
-
readonly candidate_artifact_set: string;
|
|
116
|
-
readonly evaluator: string;
|
|
117
|
-
readonly dataset: string;
|
|
118
|
-
readonly operation_ids: readonly string[];
|
|
119
|
-
readonly contexts: readonly EvaluationContextBinding[];
|
|
120
|
-
readonly evidence_refs: readonly string[];
|
|
121
|
-
}
|
|
122
|
-
export interface EvaluationMetric {
|
|
123
|
-
readonly name: string;
|
|
124
|
-
readonly baseline: string;
|
|
125
|
-
readonly candidate: string;
|
|
126
|
-
readonly improved: boolean;
|
|
127
|
-
}
|
|
128
|
-
export interface EvaluationGate {
|
|
129
|
-
readonly name: string;
|
|
130
|
-
readonly required: boolean;
|
|
131
|
-
readonly passed: boolean;
|
|
132
|
-
}
|
|
133
|
-
export interface EvaluationFact {
|
|
134
|
-
readonly digest: string;
|
|
135
|
-
readonly evaluation: string;
|
|
136
|
-
readonly metrics: readonly EvaluationMetric[];
|
|
137
|
-
readonly gates: readonly EvaluationGate[];
|
|
138
|
-
readonly replay_passed: boolean;
|
|
139
|
-
}
|
|
140
|
-
export type PromotionOutcome = "promote" | "reject" | "hold";
|
|
141
|
-
export interface PromotionDecision {
|
|
142
|
-
readonly digest: string;
|
|
143
|
-
readonly proposal: string;
|
|
144
|
-
readonly evaluation_facts: readonly string[];
|
|
145
|
-
readonly policy: string;
|
|
146
|
-
readonly outcome: PromotionOutcome;
|
|
147
|
-
readonly selected_artifact_set: string;
|
|
148
|
-
}
|
|
149
|
-
export interface ActivationBinding {
|
|
150
|
-
readonly digest: string;
|
|
151
|
-
readonly operation_id: string;
|
|
152
|
-
readonly artifact_set: string;
|
|
153
|
-
readonly promotion_decision: string;
|
|
154
|
-
}
|
|
155
|
-
export interface EvolutionBundle {
|
|
156
|
-
readonly artifacts: readonly ArtifactVersion[];
|
|
157
|
-
readonly artifact_sets: readonly ArtifactSet[];
|
|
158
|
-
readonly proposals: readonly EvolutionProposal[];
|
|
159
|
-
readonly evaluations: readonly EvaluationRun[];
|
|
160
|
-
readonly facts: readonly EvaluationFact[];
|
|
161
|
-
readonly decisions: readonly PromotionDecision[];
|
|
162
|
-
readonly activations: readonly ActivationBinding[];
|
|
163
|
-
}
|
|
164
|
-
export type EvolutionVerdict = "pass" | "fail" | "unavailable";
|
|
165
|
-
export interface EvolutionReport {
|
|
166
|
-
readonly schema: "evolution-report/v1";
|
|
167
|
-
readonly verdict: EvolutionVerdict;
|
|
168
|
-
readonly violations: readonly {
|
|
169
|
-
readonly code: string;
|
|
170
|
-
readonly detail: string;
|
|
171
|
-
}[];
|
|
172
|
-
}
|
|
173
|
-
export type EvolutionValidateJson = (request: string) => string;
|
|
174
|
-
export interface EvolutionStore {
|
|
175
|
-
loadBundle(): Promise<EvolutionBundle> | EvolutionBundle;
|
|
176
|
-
}
|
|
177
|
-
export declare function createEvolutionRuntimeAdapter(validateJson: EvolutionValidateJson): {
|
|
178
|
-
validate: (bundle: EvolutionBundle) => EvolutionReport;
|
|
179
|
-
};
|
|
180
|
-
export declare function createNativeEvolutionRuntimeAdapter(): Promise<{
|
|
181
|
-
validate: (bundle: EvolutionBundle) => EvolutionReport;
|
|
182
|
-
}>;
|
|
183
|
-
export declare class EvolutionRuntime {
|
|
184
|
-
private readonly adapter;
|
|
185
|
-
constructor(adapter: ReturnType<typeof createEvolutionRuntimeAdapter>);
|
|
186
|
-
validate(bundle: EvolutionBundle): EvolutionReport;
|
|
187
|
-
validateStore(store: EvolutionStore): Promise<EvolutionReport>;
|
|
188
|
-
activate(bundle: EvolutionBundle, operationId: string): ActivationBinding;
|
|
189
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { getKernel } from "./kernel.js";
|
|
2
|
-
export function createEvolutionRuntimeAdapter(validateJson) {
|
|
3
|
-
return { validate: (bundle) => JSON.parse(validateJson(JSON.stringify(bundle))) };
|
|
4
|
-
}
|
|
5
|
-
export async function createNativeEvolutionRuntimeAdapter() {
|
|
6
|
-
const kernel = await getKernel();
|
|
7
|
-
return createEvolutionRuntimeAdapter(kernel.evolutionValidateJson);
|
|
8
|
-
}
|
|
9
|
-
export class EvolutionRuntime {
|
|
10
|
-
adapter;
|
|
11
|
-
constructor(adapter) {
|
|
12
|
-
this.adapter = adapter;
|
|
13
|
-
}
|
|
14
|
-
validate(bundle) { return this.adapter.validate(bundle); }
|
|
15
|
-
async validateStore(store) { return this.validate(await store.loadBundle()); }
|
|
16
|
-
activate(bundle, operationId) {
|
|
17
|
-
const report = this.validate(bundle);
|
|
18
|
-
if (report.verdict !== "pass")
|
|
19
|
-
throw new Error(`evolution bundle is not activatable: ${report.violations.map(v => v.code).join(", ")}`);
|
|
20
|
-
const activation = bundle.activations.find(value => value.operation_id === operationId);
|
|
21
|
-
if (!activation)
|
|
22
|
-
throw new Error(`no verified activation binding for operation ${operationId}`);
|
|
23
|
-
return activation;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** One dependency's contribution to a reduce: the producing node's agent id and its output text. */
|
|
2
|
-
export interface ReducerInput {
|
|
3
|
-
agentId: string;
|
|
4
|
-
output: string;
|
|
5
|
-
}
|
|
6
|
-
/** A pure function over a reduce node's dependency outputs → the reduce node's output string. */
|
|
7
|
-
export type Reducer = (inputs: ReducerInput[]) => string;
|
|
8
|
-
export type ReducerRegistry = Record<string, Reducer>;
|
|
9
|
-
/**
|
|
10
|
-
* Built-in reducers, available to every workflow without registration. A user-supplied registry is
|
|
11
|
-
* merged over these (so a custom reducer can shadow a built-in of the same name).
|
|
12
|
-
*/
|
|
13
|
-
export declare const builtinReducers: ReducerRegistry;
|
|
14
|
-
/** Resolve a reducer by name from the built-ins overlaid with a user registry. */
|
|
15
|
-
export declare function resolveReducer(name: string, user?: ReducerRegistry): Reducer | undefined;
|