@deepstrike/sdk 0.2.61 → 0.2.63

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.
@@ -0,0 +1,60 @@
1
+ const DIVERGENCE_STEP = /at step (\d+)/;
2
+ /**
3
+ * Inspect a durable journal without committing anything: replay it through the kernel and report
4
+ * whether it still restores. This turns a "silent brick" — an operation whose journal was appended
5
+ * but whose step can no longer be re-derived by this binary — into an actionable diagnosis: which
6
+ * record diverges, and what the head still holds if it does not.
7
+ *
8
+ * Nothing is mutated; the same journal can be diagnosed repeatedly and then restored normally.
9
+ */
10
+ export async function diagnoseKernelJournal(kernel, journal, operationId) {
11
+ const checkpoint = await journal.latestCheckpoint(operationId);
12
+ const records = await journal.recordsAfter(operationId, checkpoint?.covered_head);
13
+ try {
14
+ const cost = kernel.restore(checkpoint ? Buffer.from(checkpoint.checkpoint_bytes) : undefined, records.map(record => Buffer.from(record.record_bytes)));
15
+ return {
16
+ operationId,
17
+ recordCount: records.length,
18
+ restorable: true,
19
+ divergenceStep: null,
20
+ divergenceReason: null,
21
+ terminal: parseJson(kernel.terminalJson()),
22
+ pendingEffects: parsePendingEffects(kernel.pendingEffectsJson()),
23
+ };
24
+ }
25
+ catch (error) {
26
+ const message = error instanceof Error ? error.message : String(error);
27
+ const match = DIVERGENCE_STEP.exec(message);
28
+ return {
29
+ operationId,
30
+ recordCount: records.length,
31
+ restorable: false,
32
+ divergenceStep: match ? Number(match[1]) : null,
33
+ divergenceReason: message,
34
+ terminal: undefined,
35
+ pendingEffects: [],
36
+ };
37
+ }
38
+ }
39
+ function parseJson(value) {
40
+ if (!value)
41
+ return undefined;
42
+ try {
43
+ return JSON.parse(value);
44
+ }
45
+ catch {
46
+ return undefined;
47
+ }
48
+ }
49
+ function parsePendingEffects(raw) {
50
+ const parsed = parseJson(raw);
51
+ if (!Array.isArray(parsed))
52
+ return [];
53
+ return parsed.map(envelope => {
54
+ const effect = envelope?.effect;
55
+ return {
56
+ effect_id: String(envelope?.effect_id ?? ""),
57
+ kind: String(effect?.kind ?? ""),
58
+ };
59
+ });
60
+ }
@@ -1,7 +1,9 @@
1
1
  import type { EntropySample, Message, RenderedContext, TaskUpdate, ToolCall, ToolResult, ToolSchema } from "../types.js";
2
2
  import type { SkillMetadata } from "../skills/loader.js";
3
3
  import type { RollbackReason } from "./session-log.js";
4
+ export declare const CANONICAL_CONTENT_PARTS_PREFIX = "[[deepstrike-content-parts]]";
4
5
  export declare function encodeCanonicalContentParts(parts: unknown[]): string;
6
+ export declare function decodeCanonicalContentParts(content: string): Array<Record<string, unknown>> | undefined;
5
7
  export interface PaceDecision {
6
8
  action: "continue" | "sleep" | "stop";
7
9
  delayMs?: number;
@@ -73,11 +75,7 @@ export type KernelRunnerAction = {
73
75
  } | {
74
76
  kind: "archive_page_out";
75
77
  effectId: string;
76
- turn?: number;
77
- action?: string;
78
- summary?: string;
79
78
  archived?: Message[];
80
- tier?: string;
81
79
  handleId?: string;
82
80
  payload?: {
83
81
  content: string;
@@ -200,7 +198,18 @@ export interface KernelObservation {
200
198
  rollbacks_in_window?: number;
201
199
  window_turns?: number;
202
200
  threshold?: number;
201
+ effects?: Array<{
202
+ effect_id: string;
203
+ kind: string;
204
+ }>;
203
205
  }
206
+ /** Presentation/policy facts for an archive action come from committed observations, never from
207
+ * the wire effect projection. */
208
+ export declare function archivePresentationFromObservations(observations: readonly KernelObservation[]): {
209
+ action?: string;
210
+ summary?: string;
211
+ tier?: "semantic" | "durable";
212
+ };
204
213
  export declare function toolSchemaToKernel(schema: ToolSchema): Record<string, unknown>;
205
214
  export declare function skillMetadataToKernel(skill: SkillMetadata): Record<string, unknown>;
206
215
  export declare function messageToKernelMessage(message: Message): Record<string, unknown>;
@@ -1,8 +1,8 @@
1
- const CANONICAL_CONTENT_PARTS_PREFIX = "[[deepstrike-content-parts]]";
1
+ export const CANONICAL_CONTENT_PARTS_PREFIX = "[[deepstrike-content-parts]]";
2
2
  export function encodeCanonicalContentParts(parts) {
3
3
  return `${CANONICAL_CONTENT_PARTS_PREFIX}${Buffer.from(JSON.stringify(parts)).toString("base64url")}`;
4
4
  }
5
- function decodeCanonicalContentParts(content) {
5
+ export function decodeCanonicalContentParts(content) {
6
6
  if (!content.startsWith(CANONICAL_CONTENT_PARTS_PREFIX))
7
7
  return undefined;
8
8
  try {
@@ -15,6 +15,26 @@ function decodeCanonicalContentParts(content) {
15
15
  return undefined;
16
16
  }
17
17
  }
18
+ /** Presentation/policy facts for an archive action come from committed observations, never from
19
+ * the wire effect projection. */
20
+ export function archivePresentationFromObservations(observations) {
21
+ const compressed = [...observations].reverse().find(observation => observation.kind === "compressed");
22
+ if (!compressed)
23
+ return {};
24
+ const action = compressionActionFromObservation(compressed.action);
25
+ if (!action)
26
+ return {};
27
+ return {
28
+ action,
29
+ ...(compressed.summary ? { summary: compressed.summary } : {}),
30
+ tier: action === "context_collapse" || action === "auto_compact" ? "semantic" : "durable",
31
+ };
32
+ }
33
+ function compressionActionFromObservation(action) {
34
+ return action === "snip_compact" || action === "micro_compact" || action === "context_collapse" || action === "auto_compact"
35
+ ? action
36
+ : undefined;
37
+ }
18
38
  function tryParseJson(s) {
19
39
  try {
20
40
  return JSON.parse(s);
@@ -9,9 +9,11 @@ import type { ExecutionPlane } from "./execution-plane.js";
9
9
  import type { RunGroup } from "./run-group.js";
10
10
  import { type MemoryPolicy, type ResourceQuota } from "../kernel.js";
11
11
  import type { AgentRunSpec, MilestoneCheckResult, MilestoneContract, MilestonePolicy, WorkflowSpec, WorkflowOutcome } from "../types/agent.js";
12
+ export declare function stableSemanticArchiveName(effectId: string): string;
12
13
  import { type SubAgentOrchestrator } from "./sub-agent-orchestrator.js";
13
14
  import { type ReducerRegistry } from "./reducers.js";
14
15
  import { type GovernancePolicy } from "../governance.js";
16
+ import { type UsageAccountingPolicy } from "./execution-evidence.js";
15
17
  import { type NativeOsProfile, type OsProfileId, type SignalPolicy } from "./os-profile.js";
16
18
  import { PayloadStore } from "./payload-store.js";
17
19
  import type { BackgroundTaskErrorHandler } from "./reliability.js";
@@ -175,6 +177,12 @@ export interface RuntimeOptions {
175
177
  signalPolicy?: SignalPolicy;
176
178
  /** Provider-envelope overhead plus output and safety reserves journaled before start. */
177
179
  promptBudget?: PromptBudget;
180
+ /**
181
+ * P4-S2: the measurement→settlement conversion policy. Absent ⇒ the default full-footprint
182
+ * policy — byte-identical numbers to what the runner has always fed `observed_*`; the policy
183
+ * only makes the conversion named, pinnable on `provider_attempt`, and replayable.
184
+ */
185
+ usageAccountingPolicy?: UsageAccountingPolicy;
178
186
  /** Stable replayable context behavior; SDK ratios are normalized to integer ppm on the ABI wire. */
179
187
  contextPolicy?: ContextPolicyOverrides;
180
188
  /** Deterministic DAG scheduling policy installed atomically through ConfigureRun. */
@@ -402,6 +410,16 @@ export declare class RuntimeRunner {
402
410
  private readonly composedSystemPrompt;
403
411
  /** H1.2: present only when `opts.nudges` is non-empty; else null and the append funnel is untouched. */
404
412
  private readonly nudgeEngine;
413
+ /** P4-S1: the run's resolved provider route, assembled once at construction (P4 §0.2 — the
414
+ * provider is fixed for the run today; every attempt references this same route object). */
415
+ private readonly providerRoute;
416
+ /** P4-S2: measurement→settlement policy; default = the exact implicit behavior (numbers unchanged). */
417
+ private readonly usageAccountingPolicy;
418
+ /** P4 §1.1: the active invocation's derived identity = its chain's FIRST effect_id. Tracked
419
+ * across kernel-driven provider retries (a provider_error commit arms `providerRetryPending`;
420
+ * the next call_provider adopts the pending invocation instead of opening a new one). */
421
+ private activeProviderInvocationId;
422
+ private providerRetryPending;
405
423
  constructor(opts: RuntimeOptions);
406
424
  /** Host configuration (for coordinator / sub-agent spawn). */
407
425
  get hostOptions(): RuntimeOptions;
@@ -411,6 +429,13 @@ export declare class RuntimeRunner {
411
429
  private commitKernelAction;
412
430
  private startKernelAgent;
413
431
  private payloadStore;
432
+ /**
433
+ * P4-S1 (G1): land one provider_attempt evidence record per effect execution. Pure host
434
+ * evidence (B7) — appended AFTER the transport fact exists (success/failure/abort), never
435
+ * consulted for kernel input. The accounting policy id pins only when a measurement exists,
436
+ * so (usage, policy_id) deterministically recomputes the settlement that crossed the wire.
437
+ */
438
+ private appendProviderAttempt;
414
439
  private persistMemoryToStore;
415
440
  private retrieveMemoryFromStore;
416
441
  /**