@openclawbrain/cli 0.4.4 → 0.4.6

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,490 @@
1
+ import { type ArtifactManifestV1, type FeedbackEventV1, type InteractionEventV1, type NormalizedEventExportV1, type NormalizedEventV1, type PrincipalPriorityClassV1, type PrincipalRoleV1, type PackGraphPayloadV1, type PackVectorsPayloadV1, type RouterArtifactV1, type RouterPolicyUpdateV1, type RuntimeCompileStructuralSignalsV1, type RuntimeGraphPlasticityStateV1, type SparseFeedbackPolicyV1, type TeacherSupervisionArtifactV1 } from "@openclawbrain/contracts";
2
+ import { type EventExportCursorV1, type EventExportLaneV1, type NormalizedEventExportBridgeV1, type NormalizedEventExportSliceV1 } from "@openclawbrain/event-export";
3
+ import type { TextEmbedder } from "@openclawbrain/compiler";
4
+ import { type PackDescriptor, type GraphEvolutionLogV1, type LearningSpineServeRouteDecisionLogEntryV1 } from "@openclawbrain/pack-format";
5
+ import { type WorkspaceMetadataInput } from "@openclawbrain/workspace-metadata";
6
+ export interface CandidatePackEventExports {
7
+ interactionEvents: InteractionEventV1[];
8
+ feedbackEvents: FeedbackEventV1[];
9
+ }
10
+ export interface CandidatePackBuildInput {
11
+ packLabel: string;
12
+ workspace: WorkspaceMetadataInput;
13
+ eventRange: {
14
+ start: number;
15
+ end: number;
16
+ };
17
+ eventExports?: CandidatePackEventExports;
18
+ teacherSupervisionArtifacts?: readonly TeacherSupervisionArtifactV1[];
19
+ learnedRouting: boolean;
20
+ builtAt?: string;
21
+ offlineArtifacts?: string[];
22
+ structuralOps?: Partial<ArtifactManifestV1["graphDynamics"]["structuralOps"]>;
23
+ runtimeGraph?: PackGraphPayloadV1;
24
+ sparseFeedback?: Partial<SparseFeedbackPolicyV1>;
25
+ principalBacklog?: PrincipalBacklogSummaryV1;
26
+ /** PG algorithm version: "v1" (default flat softmax) or "v2" (paper-aligned graph-local). */
27
+ pgVersion?: "v1" | "v2";
28
+ /** Serve-time route decision logs for V2 trajectory reconstruction. */
29
+ serveTimeDecisions?: LearningSpineServeRouteDecisionLogEntryV1[];
30
+ /** Baseline state for V2 variance reduction. */
31
+ baselineState?: BaselineStateV1;
32
+ }
33
+ export interface CandidatePackFromNormalizedEventExportInput {
34
+ packLabel: string;
35
+ workspace: WorkspaceMetadataInput;
36
+ normalizedEventExport: NormalizedEventExportV1;
37
+ teacherSupervisionArtifacts?: readonly TeacherSupervisionArtifactV1[];
38
+ learnedRouting: boolean;
39
+ builtAt?: string;
40
+ offlineArtifacts?: string[];
41
+ structuralOps?: Partial<ArtifactManifestV1["graphDynamics"]["structuralOps"]>;
42
+ runtimeGraph?: PackGraphPayloadV1;
43
+ sparseFeedback?: Partial<SparseFeedbackPolicyV1>;
44
+ principalBacklog?: PrincipalBacklogSummaryV1;
45
+ pgVersion?: "v1" | "v2";
46
+ serveTimeDecisions?: LearningSpineServeRouteDecisionLogEntryV1[];
47
+ baselineState?: BaselineStateV1;
48
+ }
49
+ export interface BuildTeacherSupervisionArtifactsInput {
50
+ normalizedEventExport: NormalizedEventExportV1;
51
+ observedAt?: string;
52
+ staleAfterMs?: number;
53
+ sparseFeedback?: Partial<SparseFeedbackPolicyV1>;
54
+ }
55
+ interface CandidatePackBridgeInputBase {
56
+ packLabel: string;
57
+ workspace: WorkspaceMetadataInput;
58
+ teacherSupervisionArtifacts?: readonly TeacherSupervisionArtifactV1[];
59
+ learnedRouting: boolean;
60
+ builtAt?: string;
61
+ offlineArtifacts?: string[];
62
+ structuralOps?: Partial<ArtifactManifestV1["graphDynamics"]["structuralOps"]>;
63
+ runtimeGraph?: PackGraphPayloadV1;
64
+ sparseFeedback?: Partial<SparseFeedbackPolicyV1>;
65
+ principalBacklog?: PrincipalBacklogSummaryV1;
66
+ pgVersion?: "v1" | "v2";
67
+ serveTimeDecisions?: LearningSpineServeRouteDecisionLogEntryV1[];
68
+ baselineState?: BaselineStateV1;
69
+ }
70
+ export interface CandidatePackFromNormalizedEventExportSliceInput extends CandidatePackBridgeInputBase {
71
+ normalizedEventExportSlice: NormalizedEventExportSliceV1;
72
+ }
73
+ export interface CandidatePackBundleFromNormalizedEventExportBridgeInput extends CandidatePackBridgeInputBase {
74
+ normalizedEventExportBridge: NormalizedEventExportBridgeV1;
75
+ }
76
+ export interface CandidatePackPayloads {
77
+ graph: PackGraphPayloadV1;
78
+ vectors: PackVectorsPayloadV1;
79
+ router: RouterArtifactV1 | null;
80
+ }
81
+ export interface CandidatePackBuildResult {
82
+ manifest: ArtifactManifestV1;
83
+ payloads: CandidatePackPayloads;
84
+ routingBuild: {
85
+ learnedRoutingPath: "disabled" | "policy_gradient_v1" | "policy_gradient_v2";
86
+ pgVersionRequested: "v1" | "v2" | null;
87
+ pgVersionUsed: "v1" | "v2" | null;
88
+ decisionLogCount: number;
89
+ fallbackReason: string | null;
90
+ updatedBaseline: BaselineStateV1 | null;
91
+ };
92
+ summary: {
93
+ packId: string;
94
+ immutable: true;
95
+ routePolicy: ArtifactManifestV1["routePolicy"];
96
+ workspaceSnapshot: string;
97
+ eventRange: ArtifactManifestV1["provenance"]["eventRange"];
98
+ eventExportDigest: string | null;
99
+ learningSurface: ArtifactManifestV1["provenance"]["learningSurface"];
100
+ bootstrapping: ArtifactManifestV1["graphDynamics"]["bootstrapping"];
101
+ workspaceInit: PointerAwareWorkingSetSummaryV1;
102
+ runtimePlasticity: RuntimeGraphPlasticityStateV1;
103
+ graphEvolutionLog: GraphEvolutionLogV1;
104
+ learnedRouter: {
105
+ routerIdentity: string | null;
106
+ trainingMethod: RouterArtifactV1["training"]["method"] | null;
107
+ refreshStatus: RouterArtifactV1["training"]["status"] | null;
108
+ updateCount: number;
109
+ supervisionCount: number;
110
+ weightsChecksum: string | null;
111
+ visibleDelta: string[];
112
+ noOpReason: string | null;
113
+ };
114
+ };
115
+ }
116
+ export type PointerGraphHintV1 = "memory_index" | "markdown_link" | "bare_path";
117
+ export type PointerAwareWorkingSetLayerV1 = "anchor" | "working_set" | "passive_expansion";
118
+ export interface PointerGraphEdgeRecordV1 {
119
+ sourcePath: string;
120
+ targetPath: string;
121
+ depth: number;
122
+ hint: PointerGraphHintV1;
123
+ }
124
+ export interface PointerAwareWorkingSetFileRecordV1 {
125
+ path: string;
126
+ layer: PointerAwareWorkingSetLayerV1;
127
+ priority: number;
128
+ excerpt: string;
129
+ inboundCount: number;
130
+ outboundCount: number;
131
+ }
132
+ export interface PointerAwareWorkingSetInput {
133
+ rootDir: string;
134
+ observedAt?: string;
135
+ workingSetLimit?: number;
136
+ passiveExpansionLimit?: number;
137
+ }
138
+ export interface PointerAwareWorkingSetResultV1 {
139
+ rootDir: string;
140
+ observedAt: string;
141
+ memoryPath: string | null;
142
+ activeTasksPath: string | null;
143
+ todaysMemoryPath: string | null;
144
+ anchorPaths: string[];
145
+ bootInputs: string[];
146
+ workingSet: string[];
147
+ passiveExpansion: string[];
148
+ files: PointerAwareWorkingSetFileRecordV1[];
149
+ pointers: PointerGraphEdgeRecordV1[];
150
+ graphDigest: string | null;
151
+ }
152
+ export interface PointerAwareWorkingSetSummaryV1 {
153
+ pointerAware: boolean;
154
+ memoryPath: string | null;
155
+ bootInputs: string[];
156
+ workingSet: string[];
157
+ passiveExpansion: string[];
158
+ graphDigest: string | null;
159
+ }
160
+ export interface CandidatePackBundleEntry {
161
+ lane: EventExportLaneV1;
162
+ sliceId: string;
163
+ packLabel: string;
164
+ normalizedEventExport: NormalizedEventExportV1;
165
+ nextCursor: EventExportCursorV1;
166
+ watermark: NormalizedEventExportSliceV1["watermark"];
167
+ build: CandidatePackBuildResult;
168
+ }
169
+ export interface CandidatePackBundleBuildResult {
170
+ runtimeOwner: "openclaw";
171
+ bridgeDigest: string;
172
+ bundleDigest: string;
173
+ cursor: EventExportCursorV1;
174
+ dedupedInputCount: number;
175
+ duplicateIdentityCount: number;
176
+ entries: CandidatePackBundleEntry[];
177
+ }
178
+ export interface MaterializedCandidatePackBundleEntry extends CandidatePackBundleEntry {
179
+ rootDir: string;
180
+ descriptor: PackDescriptor;
181
+ }
182
+ export interface CandidatePackBundleMaterializationResult {
183
+ runtimeOwner: "openclaw";
184
+ bridgeDigest: string;
185
+ bundleDigest: string;
186
+ cursor: EventExportCursorV1;
187
+ dedupedInputCount: number;
188
+ duplicateIdentityCount: number;
189
+ entries: MaterializedCandidatePackBundleEntry[];
190
+ }
191
+ export declare const DEFAULT_ALWAYS_ON_LEARNING_LIVE_SLICES_PER_CYCLE = 1;
192
+ export declare const DEFAULT_ALWAYS_ON_LEARNING_BACKFILL_SLICES_PER_CYCLE = 1;
193
+ export declare const DEFAULT_TEACHER_SUPERVISION_STALE_AFTER_MS: number;
194
+ export declare const DEFAULT_POINTER_AWARE_WORKING_SET_LIMIT = 6;
195
+ export declare const DEFAULT_POINTER_AWARE_PASSIVE_EXPANSION_LIMIT = 12;
196
+ export declare const DEFAULT_ALWAYS_ON_STRUCTURAL_PLASTICITY_OPS: Required<ArtifactManifestV1["graphDynamics"]["structuralOps"]>;
197
+ export declare const ALWAYS_ON_STRUCTURAL_PLASTICITY_OP_CEILING: Required<ArtifactManifestV1["graphDynamics"]["structuralOps"]>;
198
+ export declare const ALWAYS_ON_STRUCTURAL_PLASTICITY_MIN_INTERACTIONS = 2;
199
+ export declare const ALWAYS_ON_STRUCTURAL_PLASTICITY_MIN_FEEDBACK = 1;
200
+ export declare const DEFAULT_SPARSE_FEEDBACK_POLICY: SparseFeedbackPolicyV1;
201
+ export interface SparseFeedbackRuntimeDiagnosticsV1 extends SparseFeedbackPolicyV1 {
202
+ eligibleFeedbackCount: number;
203
+ maskedFeedbackCount: number;
204
+ delayedFeedbackCount: number;
205
+ budgetedOutFeedbackCount: number;
206
+ amplifiedBackgroundLabelCount: number;
207
+ }
208
+ export type SparseFeedbackEventDispositionReasonV1 = "masked" | "delayed" | "budgeted_out";
209
+ export interface SparseFeedbackEventDispositionV1 {
210
+ eventId: string;
211
+ selected: boolean;
212
+ reason: SparseFeedbackEventDispositionReasonV1 | null;
213
+ }
214
+ export interface AlwaysOnLearningCadenceV1 {
215
+ liveSlicesPerCycle: number;
216
+ backfillSlicesPerCycle: number;
217
+ }
218
+ export interface AlwaysOnLearningPendingSlicesV1 {
219
+ live: NormalizedEventExportSliceV1[];
220
+ backfill: NormalizedEventExportSliceV1[];
221
+ }
222
+ export interface AlwaysOnLearningRuntimeStateV1 {
223
+ runtimeOwner: "openclaw";
224
+ hotPathLearning: false;
225
+ attachBlocksOnFullReplay: false;
226
+ cursor: EventExportCursorV1;
227
+ pending: AlwaysOnLearningPendingSlicesV1;
228
+ learnedEventExport: NormalizedEventExportV1 | null;
229
+ runtimeGraph: PackGraphPayloadV1 | null;
230
+ runtimePlasticity: RuntimeGraphPlasticityStateV1 | null;
231
+ learnedGraph: PackGraphPayloadV1 | null;
232
+ structuralController: AlwaysOnLearningStructuralControllerStateV1;
233
+ sparseFeedback: SparseFeedbackRuntimeDiagnosticsV1;
234
+ lastMaterializedAt: string | null;
235
+ materializationCount: number;
236
+ }
237
+ export type AlwaysOnLearningStructuralControlStrategyV1 = "fixed_v1" | "empirical_v1";
238
+ export type AlwaysOnLearningStructuralControlSourceV1 = "caller_override" | "fixed_default" | "no_compile_signal_evidence_fallback" | "compile_structural_signals_empirical_v1";
239
+ export interface AlwaysOnLearningCompileStructuralSignalsV1 extends Pick<RuntimeCompileStructuralSignalsV1, "matchedCandidateCount" | "selectedMatchedCount" | "overlapPrunedCount" | "traversalActivatedCount"> {
240
+ }
241
+ export interface AlwaysOnLearningStructuralControllerStateV1 {
242
+ requestedStrategy: AlwaysOnLearningStructuralControlStrategyV1;
243
+ effectiveStrategy: AlwaysOnLearningStructuralControlStrategyV1;
244
+ source: AlwaysOnLearningStructuralControlSourceV1;
245
+ compileSignals: AlwaysOnLearningCompileStructuralSignalsV1 | null;
246
+ structuralOps: Required<ArtifactManifestV1["graphDynamics"]["structuralOps"]>;
247
+ }
248
+ export type AlwaysOnLearningSchedulerBucketV1 = "principal_immediate" | "principal_backfill" | "live" | "backfill";
249
+ export interface PrincipalLearningCheckpointV1 {
250
+ teacherIdentity: string;
251
+ teacherRole: PrincipalRoleV1 | null;
252
+ priorityClass: PrincipalPriorityClassV1 | null;
253
+ learnedThroughSequence: number | null;
254
+ learnedThroughCreatedAt: string | null;
255
+ pendingEventCount: number;
256
+ pendingLiveEventCount: number;
257
+ pendingBackfillEventCount: number;
258
+ oldestPendingSequence: number | null;
259
+ oldestPendingCreatedAt: string | null;
260
+ newestPendingSequence: number | null;
261
+ newestPendingCreatedAt: string | null;
262
+ }
263
+ export interface PendingPrincipalEventV1 {
264
+ teacherIdentity: string;
265
+ teacherRole: PrincipalRoleV1 | null;
266
+ priorityClass: PrincipalPriorityClassV1 | null;
267
+ eventId: string;
268
+ kind: NormalizedEventV1["kind"];
269
+ sequence: number;
270
+ createdAt: string;
271
+ lane: EventExportLaneV1;
272
+ sourceStream: string;
273
+ }
274
+ export interface PrincipalBacklogSummaryV1 {
275
+ principalCount: number;
276
+ pendingEventCount: number;
277
+ checkpoints: PrincipalLearningCheckpointV1[];
278
+ oldestUnlearnedEvent: PendingPrincipalEventV1 | null;
279
+ newestPendingEvent: PendingPrincipalEventV1 | null;
280
+ }
281
+ export interface AlwaysOnLearningRuntimePlanV1 {
282
+ runtimeOwner: "openclaw";
283
+ hotPathLearning: false;
284
+ attachBlocksOnFullReplay: false;
285
+ bootstrapped: boolean;
286
+ mode: "cold_start" | "live_priority" | "background_catchup" | "caught_up";
287
+ nextPriorityLane: EventExportLaneV1 | "none";
288
+ nextPriorityBucket: AlwaysOnLearningSchedulerBucketV1 | "none";
289
+ pending: {
290
+ live: number;
291
+ backfill: number;
292
+ total: number;
293
+ freshLivePriority: boolean;
294
+ byBucket: Record<AlwaysOnLearningSchedulerBucketV1, number>;
295
+ };
296
+ principalBacklog: PrincipalBacklogSummaryV1;
297
+ learnedRange: NormalizedEventExportV1["range"] | null;
298
+ materialization: {
299
+ count: number;
300
+ lastMaterializedAt: string | null;
301
+ lastJobId: string | null;
302
+ lastReason: AlwaysOnLearningMaterializationJobV1["reason"] | null;
303
+ lastLane: AlwaysOnLearningMaterializationJobV1["lane"] | null;
304
+ lastPriority: AlwaysOnLearningMaterializationJobV1["priority"] | null;
305
+ lastSchedulerBucket: AlwaysOnLearningMaterializationJobV1["schedulerBucket"] | null;
306
+ };
307
+ }
308
+ export interface AdvanceAlwaysOnLearningRuntimeInput {
309
+ packLabel: string;
310
+ workspace: WorkspaceMetadataInput;
311
+ interactionEvents: readonly InteractionEventV1[];
312
+ feedbackEvents: readonly FeedbackEventV1[];
313
+ teacherSupervisionArtifacts?: readonly TeacherSupervisionArtifactV1[];
314
+ learnedRouting: boolean;
315
+ state?: AlwaysOnLearningRuntimeStateV1;
316
+ builtAt?: string;
317
+ offlineArtifacts?: string[];
318
+ structuralOps?: Partial<ArtifactManifestV1["graphDynamics"]["structuralOps"]>;
319
+ structuralControlStrategy?: AlwaysOnLearningStructuralControlStrategyV1;
320
+ compileStructuralSignals?: AlwaysOnLearningCompileStructuralSignalsV1 | null;
321
+ sparseFeedback?: Partial<SparseFeedbackPolicyV1>;
322
+ liveSliceSize?: number;
323
+ backfillSliceSize?: number;
324
+ cadence?: Partial<AlwaysOnLearningCadenceV1>;
325
+ pgVersion?: "v1" | "v2";
326
+ serveTimeDecisions?: LearningSpineServeRouteDecisionLogEntryV1[];
327
+ baselineState?: BaselineStateV1;
328
+ }
329
+ export interface AlwaysOnLearningMaterializationJobV1 {
330
+ jobId: string;
331
+ lane: EventExportLaneV1;
332
+ priority: "immediate" | "background";
333
+ schedulerBucket: AlwaysOnLearningSchedulerBucketV1;
334
+ reason: "attach_bootstrap" | "fresh_live_events" | "passive_history_catchup";
335
+ selectedSliceIds: string[];
336
+ selectedEventRange: NormalizedEventExportV1["range"];
337
+ normalizedEventExport: NormalizedEventExportV1;
338
+ candidateInput: CandidatePackFromNormalizedEventExportInput;
339
+ candidate: CandidatePackBuildResult;
340
+ }
341
+ export interface AdvanceAlwaysOnLearningRuntimeResultV1 {
342
+ runtimeOwner: "openclaw";
343
+ hotPathLearning: false;
344
+ attachBlocksOnFullReplay: false;
345
+ bridge: NormalizedEventExportBridgeV1;
346
+ selectedSlices: NormalizedEventExportSliceV1[];
347
+ deferred: {
348
+ live: number;
349
+ backfill: number;
350
+ };
351
+ materialization: AlwaysOnLearningMaterializationJobV1 | null;
352
+ state: AlwaysOnLearningRuntimeStateV1;
353
+ }
354
+ export interface DrainAlwaysOnLearningRuntimeInput extends AdvanceAlwaysOnLearningRuntimeInput {
355
+ maxCycles?: number;
356
+ }
357
+ export interface AlwaysOnLearningRuntimeCycleV1 extends AdvanceAlwaysOnLearningRuntimeResultV1 {
358
+ cycle: number;
359
+ }
360
+ export interface DrainAlwaysOnLearningRuntimeResultV1 {
361
+ runtimeOwner: "openclaw";
362
+ drained: boolean;
363
+ stopReason: "idle" | "max_cycles" | "no_progress";
364
+ cycles: AlwaysOnLearningRuntimeCycleV1[];
365
+ materializations: AlwaysOnLearningMaterializationJobV1[];
366
+ state: AlwaysOnLearningRuntimeStateV1;
367
+ }
368
+ export declare function buildTeacherSupervisionArtifactsFromNormalizedEventExport(input: BuildTeacherSupervisionArtifactsInput): TeacherSupervisionArtifactV1[];
369
+ export declare function createAlwaysOnLearningRuntimeState(): AlwaysOnLearningRuntimeStateV1;
370
+ export declare function describeAlwaysOnLearningRuntimeState(state: AlwaysOnLearningRuntimeStateV1, lastMaterialization?: AlwaysOnLearningMaterializationJobV1 | null): AlwaysOnLearningRuntimePlanV1;
371
+ export declare function advanceAlwaysOnLearningRuntime(input: AdvanceAlwaysOnLearningRuntimeInput): AdvanceAlwaysOnLearningRuntimeResultV1;
372
+ export declare function drainAlwaysOnLearningRuntime(input: DrainAlwaysOnLearningRuntimeInput): DrainAlwaysOnLearningRuntimeResultV1;
373
+ export declare function materializeAlwaysOnLearningCandidatePack(rootDir: string, job: AlwaysOnLearningMaterializationJobV1): PackDescriptor;
374
+ export declare function materializeAlwaysOnLearningCandidatePackWithEmbedder(rootDir: string, job: AlwaysOnLearningMaterializationJobV1, embedder: TextEmbedder): Promise<PackDescriptor>;
375
+ export declare function buildCandidatePackFromNormalizedEventExportSlice(input: CandidatePackFromNormalizedEventExportSliceInput): CandidatePackBuildResult;
376
+ export declare function buildCandidatePackBundleFromNormalizedEventExportBridge(input: CandidatePackBundleFromNormalizedEventExportBridgeInput): CandidatePackBundleBuildResult;
377
+ export declare function buildPointerAwareWorkingSet(input: PointerAwareWorkingSetInput): PointerAwareWorkingSetResultV1;
378
+ export declare function describeSparseFeedbackEventDispositions(feedbackEvents: readonly FeedbackEventV1[], observedAt: string, sparseFeedback: Partial<SparseFeedbackPolicyV1> | undefined): SparseFeedbackEventDispositionV1[];
379
+ export declare function reindexCandidatePackBuildResultWithEmbedder(result: CandidatePackBuildResult, embedder: TextEmbedder): Promise<CandidatePackBuildResult>;
380
+ /**
381
+ * Build an adjacency map from the graph's block edges.
382
+ *
383
+ * For each block, collects the targetBlockIds from its edges, filtering out:
384
+ * - Self-loops (edges pointing back to the same block)
385
+ * - Edges targeting blocks that don't exist in the graph
386
+ *
387
+ * Blocks with no (valid) outgoing edges get an empty neighbor array.
388
+ */
389
+ export declare function buildAdjacencyMap(graph: PackGraphPayloadV1): Map<string, string[]>;
390
+ export interface GraphLocalActionSet {
391
+ nodeBlockId: string;
392
+ neighborBlockIds: string[];
393
+ includesStop: boolean;
394
+ logits: Map<string, number>;
395
+ probabilities: Map<string, number>;
396
+ }
397
+ export declare function buildGraphLocalActionSet(nodeBlockId: string, neighborBlockIds: string[], graph: PackGraphPayloadV1, vectors: PackVectorsPayloadV1, queryContext: {
398
+ queryTokens: string[];
399
+ queryVector: Record<string, number>;
400
+ }, tau: number, stopBias?: number): GraphLocalActionSet;
401
+ export declare const STOP_ACTION_ID = "__STOP__";
402
+ export declare function createDefaultBaselineState(alpha?: number): BaselineStateV1;
403
+ /**
404
+ * EMA update: on first observation use the raw outcome; thereafter blend.
405
+ */
406
+ export declare function updateBaseline(current: BaselineStateV1, outcome: number): BaselineStateV1;
407
+ /**
408
+ * Corrected tail-sum policy gradient update for a single trajectory.
409
+ *
410
+ * From Gu (2016):
411
+ * ∂v(s_t)/∂W = E[ z_T · Σ_{l=t}^{T-1} ∇_W log π(a_l | s_l) ]
412
+ *
413
+ * At each node i, ∇_{w_i} log π(a|i) = (1/τ)(e_a − π_i),
414
+ * so Σ_j gradient_j = 0 (mass redistribution, not inflation).
415
+ */
416
+ export declare function computeTrajectoryPolicyGradient(trajectory: TrajectoryV1, adjacency: Map<string, string[]>, graph: PackGraphPayloadV1, vectors: PackVectorsPayloadV1, tau: number, pgScale: number): Map<string, {
417
+ delta: number;
418
+ evidenceCount: number;
419
+ rewardSum: number;
420
+ }>;
421
+ /**
422
+ * Aggregate policy gradient updates from multiple trajectories into
423
+ * RouterPolicyUpdateV1[] format.
424
+ */
425
+ export declare function aggregateTrajectoryUpdates(trajectories: TrajectoryV1[], adjacency: Map<string, string[]>, graph: PackGraphPayloadV1, vectors: PackVectorsPayloadV1, tau: number, pgScale: number): RouterPolicyUpdateV1[];
426
+ /**
427
+ * Baseline state for variance reduction (exponential moving average of returns).
428
+ */
429
+ export interface BaselineStateV1 {
430
+ movingAverage: number;
431
+ count: number;
432
+ alpha: number;
433
+ lastUpdatedAt: string;
434
+ }
435
+ /**
436
+ * A single step in a trajectory through the graph.
437
+ */
438
+ export interface TrajectoryStepV1 {
439
+ stepIndex: number;
440
+ nodeBlockId: string;
441
+ actionBlockId: string | null;
442
+ actionScore: number;
443
+ actionLogProbability: number;
444
+ candidateNeighborIds: string[];
445
+ candidateScores: Record<string, number>;
446
+ candidateProbabilities: Record<string, number>;
447
+ }
448
+ /**
449
+ * A full trajectory: a sequence of (state, action) pairs with an outcome.
450
+ */
451
+ export interface TrajectoryV1 {
452
+ trajectoryId: string;
453
+ sessionId: string | null;
454
+ turnId: string | null;
455
+ createdAt: string;
456
+ steps: TrajectoryStepV1[];
457
+ outcome: number;
458
+ baselineValue: number;
459
+ }
460
+ /**
461
+ * Join serve-time decisions with feedback events to assign outcome rewards.
462
+ * Returns decisionRecordId → outcome (z_T).
463
+ */
464
+ export declare function joinDecisionsWithFeedback(decisions: LearningSpineServeRouteDecisionLogEntryV1[], eventExport: NormalizedEventExportV1 | null, maxDelayMs?: number): Map<string, number>;
465
+ /**
466
+ * Reconstruct a trajectory from a serve-time decision log entry.
467
+ * Traces through the graph starting from the highest-scoring selected block.
468
+ */
469
+ export declare function reconstructTrajectoryFromServeDecision(decision: LearningSpineServeRouteDecisionLogEntryV1, graph: PackGraphPayloadV1, vectors: PackVectorsPayloadV1, adjacency: Map<string, string[]>, tau: number, outcome: number, baselineValue: number): TrajectoryV1;
470
+ export declare function buildCandidatePack(input: CandidatePackBuildInput): CandidatePackBuildResult;
471
+ export declare function buildCandidatePackFromNormalizedEventExport(input: CandidatePackFromNormalizedEventExportInput): CandidatePackBuildResult;
472
+ export declare function buildCandidatePackWithEmbedder(input: CandidatePackBuildInput, embedder: TextEmbedder): Promise<CandidatePackBuildResult>;
473
+ export declare function buildCandidatePackFromNormalizedEventExportWithEmbedder(input: CandidatePackFromNormalizedEventExportInput, embedder: TextEmbedder): Promise<CandidatePackBuildResult>;
474
+ export declare function materializeCandidatePack(rootDir: string, input: CandidatePackBuildInput): PackDescriptor;
475
+ export declare function materializeCandidatePackWithEmbedder(rootDir: string, input: CandidatePackBuildInput, embedder: TextEmbedder): Promise<PackDescriptor>;
476
+ export declare function materializeCandidatePackFromNormalizedEventExport(rootDir: string, input: CandidatePackFromNormalizedEventExportInput): PackDescriptor;
477
+ export declare function materializeCandidatePackFromNormalizedEventExportWithEmbedder(rootDir: string, input: CandidatePackFromNormalizedEventExportInput, embedder: TextEmbedder): Promise<PackDescriptor>;
478
+ export declare function materializeCandidatePackFromNormalizedEventExportSlice(rootDir: string, input: CandidatePackFromNormalizedEventExportSliceInput): PackDescriptor;
479
+ export declare function materializeCandidatePackBundleFromNormalizedEventExportBridge(rootDir: string, input: CandidatePackBundleFromNormalizedEventExportBridgeInput): CandidatePackBundleMaterializationResult;
480
+ /**
481
+ * Load baseline state from `<activationRoot>/baseline-state.json`.
482
+ * If the file is missing or unparseable, returns a fresh zero-initialised state.
483
+ */
484
+ export declare function loadOrInitBaseline(activationRoot: string): BaselineStateV1;
485
+ /**
486
+ * Persist baseline state to `<activationRoot>/baseline-state.json`.
487
+ * Creates the directory tree if it doesn't already exist.
488
+ */
489
+ export declare function persistBaseline(activationRoot: string, state: BaselineStateV1): void;
490
+ export {};