@thehoneyjar/sigil-anchor 4.3.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.
@@ -0,0 +1,1230 @@
1
+ import { EventEmitter } from 'eventemitter3';
2
+ import { z } from 'zod';
3
+
4
+ /**
5
+ * Anchor Core Types
6
+ *
7
+ * Type definitions for the Anchor ground truth enforcement layer.
8
+ */
9
+
10
+ /** Network configuration for forking */
11
+ interface NetworkConfig {
12
+ /** Network name (e.g., 'mainnet', 'sepolia') */
13
+ name: string;
14
+ /** Chain ID */
15
+ chainId: number;
16
+ /** RPC URL to fork from */
17
+ rpcUrl: string;
18
+ }
19
+ /** Fork configuration */
20
+ interface ForkConfig {
21
+ /** Network to fork */
22
+ network: NetworkConfig;
23
+ /** Block number to fork at (optional, defaults to latest) */
24
+ blockNumber?: number;
25
+ /** Local RPC port (optional, auto-assigned if not specified) */
26
+ port?: number;
27
+ /** Session ID this fork belongs to */
28
+ sessionId?: string;
29
+ }
30
+ /** Active fork instance */
31
+ interface Fork {
32
+ /** Unique fork identifier */
33
+ id: string;
34
+ /** Network configuration */
35
+ network: NetworkConfig;
36
+ /** Block number fork was created at */
37
+ blockNumber: number;
38
+ /** Local RPC URL */
39
+ rpcUrl: string;
40
+ /** Local RPC port */
41
+ port: number;
42
+ /** Process ID */
43
+ pid: number;
44
+ /** Creation timestamp */
45
+ createdAt: Date;
46
+ /** Session ID this fork belongs to */
47
+ sessionId?: string;
48
+ }
49
+ /** Fork registry schema for persistence */
50
+ declare const ForkSchema: z.ZodObject<{
51
+ id: z.ZodString;
52
+ network: z.ZodObject<{
53
+ name: z.ZodString;
54
+ chainId: z.ZodNumber;
55
+ rpcUrl: z.ZodString;
56
+ }, "strip", z.ZodTypeAny, {
57
+ name: string;
58
+ chainId: number;
59
+ rpcUrl: string;
60
+ }, {
61
+ name: string;
62
+ chainId: number;
63
+ rpcUrl: string;
64
+ }>;
65
+ blockNumber: z.ZodNumber;
66
+ rpcUrl: z.ZodString;
67
+ port: z.ZodNumber;
68
+ pid: z.ZodNumber;
69
+ createdAt: z.ZodEffects<z.ZodString, Date, string>;
70
+ sessionId: z.ZodOptional<z.ZodString>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ id: string;
73
+ network: {
74
+ name: string;
75
+ chainId: number;
76
+ rpcUrl: string;
77
+ };
78
+ rpcUrl: string;
79
+ blockNumber: number;
80
+ port: number;
81
+ pid: number;
82
+ createdAt: Date;
83
+ sessionId?: string | undefined;
84
+ }, {
85
+ id: string;
86
+ network: {
87
+ name: string;
88
+ chainId: number;
89
+ rpcUrl: string;
90
+ };
91
+ rpcUrl: string;
92
+ blockNumber: number;
93
+ port: number;
94
+ pid: number;
95
+ createdAt: string;
96
+ sessionId?: string | undefined;
97
+ }>;
98
+ declare const ForkRegistrySchema: z.ZodObject<{
99
+ forks: z.ZodArray<z.ZodObject<{
100
+ id: z.ZodString;
101
+ network: z.ZodObject<{
102
+ name: z.ZodString;
103
+ chainId: z.ZodNumber;
104
+ rpcUrl: z.ZodString;
105
+ }, "strip", z.ZodTypeAny, {
106
+ name: string;
107
+ chainId: number;
108
+ rpcUrl: string;
109
+ }, {
110
+ name: string;
111
+ chainId: number;
112
+ rpcUrl: string;
113
+ }>;
114
+ blockNumber: z.ZodNumber;
115
+ rpcUrl: z.ZodString;
116
+ port: z.ZodNumber;
117
+ pid: z.ZodNumber;
118
+ createdAt: z.ZodEffects<z.ZodString, Date, string>;
119
+ sessionId: z.ZodOptional<z.ZodString>;
120
+ }, "strip", z.ZodTypeAny, {
121
+ id: string;
122
+ network: {
123
+ name: string;
124
+ chainId: number;
125
+ rpcUrl: string;
126
+ };
127
+ rpcUrl: string;
128
+ blockNumber: number;
129
+ port: number;
130
+ pid: number;
131
+ createdAt: Date;
132
+ sessionId?: string | undefined;
133
+ }, {
134
+ id: string;
135
+ network: {
136
+ name: string;
137
+ chainId: number;
138
+ rpcUrl: string;
139
+ };
140
+ rpcUrl: string;
141
+ blockNumber: number;
142
+ port: number;
143
+ pid: number;
144
+ createdAt: string;
145
+ sessionId?: string | undefined;
146
+ }>, "many">;
147
+ lastUpdated: z.ZodEffects<z.ZodString, Date, string>;
148
+ }, "strip", z.ZodTypeAny, {
149
+ forks: {
150
+ id: string;
151
+ network: {
152
+ name: string;
153
+ chainId: number;
154
+ rpcUrl: string;
155
+ };
156
+ rpcUrl: string;
157
+ blockNumber: number;
158
+ port: number;
159
+ pid: number;
160
+ createdAt: Date;
161
+ sessionId?: string | undefined;
162
+ }[];
163
+ lastUpdated: Date;
164
+ }, {
165
+ forks: {
166
+ id: string;
167
+ network: {
168
+ name: string;
169
+ chainId: number;
170
+ rpcUrl: string;
171
+ };
172
+ rpcUrl: string;
173
+ blockNumber: number;
174
+ port: number;
175
+ pid: number;
176
+ createdAt: string;
177
+ sessionId?: string | undefined;
178
+ }[];
179
+ lastUpdated: string;
180
+ }>;
181
+ type ForkRegistry = z.infer<typeof ForkRegistrySchema>;
182
+ /** Snapshot metadata */
183
+ interface SnapshotMetadata {
184
+ /** Snapshot ID (from Anvil) */
185
+ id: string;
186
+ /** Fork ID this snapshot belongs to */
187
+ forkId: string;
188
+ /** Session ID */
189
+ sessionId: string;
190
+ /** Task ID that created this snapshot */
191
+ taskId?: string;
192
+ /** Block number at snapshot time */
193
+ blockNumber: number;
194
+ /** Creation timestamp */
195
+ createdAt: Date;
196
+ /** Description */
197
+ description?: string;
198
+ }
199
+ /** Snapshot configuration */
200
+ interface SnapshotConfig {
201
+ /** Fork ID to snapshot */
202
+ forkId: string;
203
+ /** Session ID */
204
+ sessionId: string;
205
+ /** Task ID */
206
+ taskId?: string;
207
+ /** Description */
208
+ description?: string;
209
+ }
210
+ /** Checkpoint metadata */
211
+ interface CheckpointMetadata {
212
+ /** Checkpoint ID */
213
+ id: string;
214
+ /** Session ID */
215
+ sessionId: string;
216
+ /** Fork ID this checkpoint was created from */
217
+ forkId: string;
218
+ /** Snapshot range covered by this checkpoint */
219
+ snapshotRange: {
220
+ first: string;
221
+ last: string;
222
+ };
223
+ /** Block number at checkpoint time */
224
+ blockNumber: number;
225
+ /** Creation timestamp */
226
+ createdAt: Date;
227
+ /** Number of snapshots since last checkpoint */
228
+ snapshotCount: number;
229
+ }
230
+ /** Checkpoint configuration */
231
+ interface CheckpointConfig {
232
+ /** Session ID */
233
+ sessionId: string;
234
+ /** Fork ID */
235
+ forkId: string;
236
+ /** Snapshot interval before checkpointing */
237
+ interval?: number;
238
+ }
239
+ /** Task types in the Anchor pipeline */
240
+ type TaskType = 'fork' | 'ground' | 'warden' | 'generate' | 'validate' | 'write';
241
+ /** Task status */
242
+ type TaskStatus = 'pending' | 'running' | 'complete' | 'blocked' | 'failed';
243
+ /** Task in the state-pinned graph */
244
+ interface Task {
245
+ /** Unique task ID */
246
+ id: string;
247
+ /** Task type */
248
+ type: TaskType;
249
+ /** Current status */
250
+ status: TaskStatus;
251
+ /** Snapshot ID binding this task to EVM state */
252
+ snapshotId?: string;
253
+ /** Checkpoint ID for recovery */
254
+ checkpointId?: string;
255
+ /** IDs of tasks this depends on */
256
+ dependencies: string[];
257
+ /** Task input data */
258
+ input: unknown;
259
+ /** Task output data */
260
+ output?: unknown;
261
+ /** Error if failed */
262
+ error?: string;
263
+ /** Creation timestamp */
264
+ createdAt: Date;
265
+ /** Completion timestamp */
266
+ completedAt?: Date;
267
+ }
268
+ /** Task graph data for persistence */
269
+ interface TaskGraphData {
270
+ /** Session ID */
271
+ sessionId: string;
272
+ /** All tasks */
273
+ tasks: Task[];
274
+ /** Current head task ID */
275
+ headTaskId?: string;
276
+ /** Last updated timestamp */
277
+ lastUpdated: Date;
278
+ }
279
+ /** Zone hierarchy for physics validation */
280
+ type Zone = 'critical' | 'elevated' | 'standard' | 'local';
281
+ /** Zone hierarchy order (most restrictive first) */
282
+ declare const ZONE_HIERARCHY: Zone[];
283
+ /** Warden validation input */
284
+ interface WardenInput {
285
+ /** Component or action being validated */
286
+ component: string;
287
+ /** Cited zone in grounding statement */
288
+ citedZone: Zone | null;
289
+ /** Keywords detected in the component */
290
+ keywords: string[];
291
+ /** Grounding statement from agent */
292
+ groundingStatement: string;
293
+ /** Physics rules being applied */
294
+ appliedPhysics?: {
295
+ sync?: string;
296
+ timing?: string;
297
+ confirmation?: string;
298
+ };
299
+ }
300
+ /** Individual check result */
301
+ interface CheckResult {
302
+ /** Whether the check passed */
303
+ passed: boolean;
304
+ /** Reason for pass/fail */
305
+ reason: string;
306
+ }
307
+ /** Warden validation result */
308
+ interface WardenResult {
309
+ /** Overall validation status */
310
+ status: 'VALID' | 'DRIFT' | 'DECEPTIVE';
311
+ /** Individual check results */
312
+ checks: {
313
+ relevance: CheckResult;
314
+ hierarchy: CheckResult;
315
+ rules: CheckResult;
316
+ };
317
+ /** Required zone based on analysis */
318
+ requiredZone: Zone;
319
+ /** Zone cited by agent */
320
+ citedZone: Zone | null;
321
+ /** Correction message if needed */
322
+ correction?: string;
323
+ }
324
+ /** Anchor exit codes */
325
+ declare const ExitCode: {
326
+ readonly PASS: 0;
327
+ readonly DRIFT: 1;
328
+ readonly DECEPTIVE: 2;
329
+ readonly VIOLATION: 3;
330
+ readonly REVERT: 4;
331
+ readonly CORRUPT: 5;
332
+ readonly SCHEMA: 6;
333
+ };
334
+ type ExitCodeValue = (typeof ExitCode)[keyof typeof ExitCode];
335
+
336
+ /**
337
+ * ForkManager - Anvil fork lifecycle management
338
+ *
339
+ * Manages spawning, tracking, and killing Anvil fork processes.
340
+ * Persists fork registry to grimoires/anchor/forks.json.
341
+ */
342
+
343
+ /** ForkManager events */
344
+ interface ForkManagerEvents {
345
+ 'fork:created': (fork: Fork) => void;
346
+ 'fork:exit': (forkId: string, code: number | null) => void;
347
+ 'fork:error': (forkId: string, error: Error) => void;
348
+ }
349
+ /**
350
+ * ForkManager class for managing Anvil fork lifecycle
351
+ */
352
+ declare class ForkManager extends EventEmitter<ForkManagerEvents> {
353
+ private forks;
354
+ private processes;
355
+ private usedPorts;
356
+ private registryPath;
357
+ constructor(options?: {
358
+ registryPath?: string;
359
+ });
360
+ /**
361
+ * Initialize the ForkManager by loading persisted registry
362
+ */
363
+ init(): Promise<void>;
364
+ /**
365
+ * Spawn a new Anvil fork
366
+ *
367
+ * @param config - Fork configuration
368
+ * @returns Promise resolving to the created Fork
369
+ */
370
+ fork(config: ForkConfig): Promise<Fork>;
371
+ /**
372
+ * Wait for a fork to be ready
373
+ *
374
+ * @param forkId - Fork ID to wait for
375
+ * @param timeoutMs - Timeout in milliseconds
376
+ */
377
+ waitForReady(forkId: string, timeoutMs?: number): Promise<void>;
378
+ /**
379
+ * Kill a specific fork
380
+ *
381
+ * @param forkId - Fork ID to kill
382
+ */
383
+ kill(forkId: string): Promise<void>;
384
+ /**
385
+ * Kill all forks
386
+ */
387
+ killAll(): Promise<void>;
388
+ /**
389
+ * List all active forks
390
+ *
391
+ * @returns Array of active forks
392
+ */
393
+ list(): Fork[];
394
+ /**
395
+ * Get a fork by ID
396
+ *
397
+ * @param forkId - Fork ID
398
+ * @returns Fork if found, undefined otherwise
399
+ */
400
+ get(forkId: string): Fork | undefined;
401
+ /**
402
+ * Export environment variables for a fork
403
+ *
404
+ * @param forkId - Fork ID
405
+ * @returns Environment variables object
406
+ */
407
+ exportEnv(forkId: string): Record<string, string>;
408
+ /**
409
+ * Load fork registry from disk
410
+ */
411
+ private loadRegistry;
412
+ /**
413
+ * Save fork registry to disk
414
+ */
415
+ private saveRegistry;
416
+ /**
417
+ * Check if a fork is still healthy
418
+ */
419
+ private checkForkHealth;
420
+ /**
421
+ * Handle process exit
422
+ */
423
+ private handleProcessExit;
424
+ /**
425
+ * Find an available port
426
+ */
427
+ private findAvailablePort;
428
+ /**
429
+ * Generate a unique fork ID
430
+ */
431
+ private generateForkId;
432
+ }
433
+ /**
434
+ * Get the default ForkManager instance
435
+ */
436
+ declare function getForkManager(): ForkManager;
437
+ /**
438
+ * Reset the default ForkManager (for testing)
439
+ */
440
+ declare function resetForkManager(): void;
441
+
442
+ /**
443
+ * SnapshotManager - Anvil snapshot lifecycle management
444
+ *
445
+ * Manages creating, reverting, and tracking EVM snapshots.
446
+ * Persists snapshot metadata to grimoires/anchor/sessions/{sessionId}/snapshots/
447
+ */
448
+
449
+ /** Snapshot manager configuration */
450
+ interface SnapshotManagerConfig {
451
+ /** Base path for session data */
452
+ basePath?: string;
453
+ }
454
+ /**
455
+ * SnapshotManager class for managing Anvil snapshots
456
+ */
457
+ declare class SnapshotManager {
458
+ private snapshots;
459
+ private taskToSnapshot;
460
+ private basePath;
461
+ private sessionId;
462
+ constructor(config?: SnapshotManagerConfig);
463
+ /**
464
+ * Initialize the manager for a session
465
+ *
466
+ * @param sessionId - Session ID to manage snapshots for
467
+ */
468
+ init(sessionId: string): Promise<void>;
469
+ /**
470
+ * Create a new snapshot
471
+ *
472
+ * @param config - Snapshot configuration
473
+ * @param rpcUrl - RPC URL of the fork
474
+ * @returns Promise resolving to snapshot metadata
475
+ */
476
+ create(config: SnapshotConfig, rpcUrl: string): Promise<SnapshotMetadata>;
477
+ /**
478
+ * Revert to a snapshot
479
+ *
480
+ * @param rpcUrl - RPC URL of the fork
481
+ * @param snapshotId - Snapshot ID to revert to
482
+ * @returns Promise resolving to true if successful
483
+ */
484
+ revert(rpcUrl: string, snapshotId: string): Promise<boolean>;
485
+ /**
486
+ * Get snapshot metadata by ID
487
+ *
488
+ * @param snapshotId - Snapshot ID
489
+ * @returns Snapshot metadata if found
490
+ */
491
+ get(snapshotId: string): SnapshotMetadata | undefined;
492
+ /**
493
+ * List all snapshots sorted by creation time
494
+ *
495
+ * @returns Array of snapshot metadata
496
+ */
497
+ list(): SnapshotMetadata[];
498
+ /**
499
+ * Get snapshot for a specific task
500
+ *
501
+ * @param taskId - Task ID
502
+ * @returns Snapshot metadata if found
503
+ */
504
+ getForTask(taskId: string): SnapshotMetadata | undefined;
505
+ /**
506
+ * Get the count of snapshots
507
+ *
508
+ * @returns Number of snapshots
509
+ */
510
+ count(): number;
511
+ /**
512
+ * Cleanup old snapshots, keeping the most recent
513
+ *
514
+ * @param keepLast - Number of recent snapshots to keep
515
+ */
516
+ cleanup(keepLast: number): Promise<void>;
517
+ /**
518
+ * Get snapshot directory path for current session
519
+ */
520
+ private getSnapshotDir;
521
+ /**
522
+ * Get file path for a snapshot
523
+ */
524
+ private getSnapshotPath;
525
+ /**
526
+ * Load existing snapshots from disk
527
+ */
528
+ private loadSnapshots;
529
+ /**
530
+ * Save snapshot metadata to disk
531
+ */
532
+ private saveSnapshot;
533
+ /**
534
+ * Delete a snapshot from memory and disk
535
+ */
536
+ private deleteSnapshot;
537
+ }
538
+ /**
539
+ * Get the default SnapshotManager instance
540
+ */
541
+ declare function getSnapshotManager(): SnapshotManager;
542
+ /**
543
+ * Reset the default SnapshotManager (for testing)
544
+ */
545
+ declare function resetSnapshotManager(): void;
546
+
547
+ /**
548
+ * CheckpointManager - Hard restart strategy for Anvil memory management
549
+ *
550
+ * Creates periodic checkpoints via anvil_dumpState to prevent memory bloat.
551
+ * Restores checkpoints via anvil_loadState for crash recovery.
552
+ */
553
+
554
+ /** Checkpoint manager configuration */
555
+ interface CheckpointManagerConfig {
556
+ /** Base path for checkpoint data */
557
+ basePath?: string;
558
+ /** Snapshot interval before creating checkpoint */
559
+ snapshotInterval?: number;
560
+ /** Maximum checkpoints to retain */
561
+ maxCheckpoints?: number;
562
+ }
563
+ /**
564
+ * CheckpointManager class for hard restart strategy
565
+ */
566
+ declare class CheckpointManager {
567
+ private checkpoints;
568
+ private snapshotCount;
569
+ private firstSnapshotId;
570
+ private lastSnapshotId;
571
+ private basePath;
572
+ private snapshotInterval;
573
+ private maxCheckpoints;
574
+ private sessionId;
575
+ private forkId;
576
+ constructor(config?: CheckpointManagerConfig);
577
+ /**
578
+ * Initialize the manager for a session
579
+ *
580
+ * @param sessionId - Session ID
581
+ * @param forkId - Fork ID
582
+ */
583
+ init(sessionId: string, forkId: string): Promise<void>;
584
+ /**
585
+ * Called when a snapshot is created. May trigger checkpoint.
586
+ *
587
+ * @param snapshotId - ID of the created snapshot
588
+ * @param rpcUrl - RPC URL of the fork
589
+ * @returns True if checkpoint was created
590
+ */
591
+ onSnapshot(snapshotId: string, rpcUrl: string): Promise<boolean>;
592
+ /**
593
+ * Create a checkpoint by exporting state
594
+ *
595
+ * @param rpcUrl - RPC URL of the fork
596
+ * @returns Checkpoint metadata
597
+ */
598
+ create(rpcUrl: string): Promise<CheckpointMetadata>;
599
+ /**
600
+ * Restore from a checkpoint
601
+ *
602
+ * @param checkpointId - Checkpoint ID to restore
603
+ * @param forkManager - ForkManager instance
604
+ * @param network - Network configuration
605
+ * @returns New fork with restored state
606
+ */
607
+ restore(checkpointId: string, forkManager: ForkManager, network: NetworkConfig): Promise<Fork>;
608
+ /**
609
+ * Find the checkpoint containing a specific snapshot
610
+ *
611
+ * @param snapshotId - Snapshot ID to find
612
+ * @returns Checkpoint metadata if found
613
+ */
614
+ findCheckpointForSnapshot(snapshotId: string): CheckpointMetadata | undefined;
615
+ /**
616
+ * Get checkpoint by ID
617
+ *
618
+ * @param checkpointId - Checkpoint ID
619
+ * @returns Checkpoint metadata if found
620
+ */
621
+ get(checkpointId: string): CheckpointMetadata | undefined;
622
+ /**
623
+ * List all checkpoints sorted by time
624
+ *
625
+ * @returns Array of checkpoint metadata
626
+ */
627
+ list(): CheckpointMetadata[];
628
+ /**
629
+ * Get the latest checkpoint
630
+ *
631
+ * @returns Latest checkpoint metadata
632
+ */
633
+ latest(): CheckpointMetadata | undefined;
634
+ /**
635
+ * Cleanup old checkpoints, keeping only the most recent
636
+ */
637
+ cleanup(): Promise<void>;
638
+ /**
639
+ * Get session directory path
640
+ */
641
+ private getSessionDir;
642
+ /**
643
+ * Get checkpoint directory path
644
+ */
645
+ private getCheckpointDir;
646
+ /**
647
+ * Get state file path
648
+ */
649
+ private getStatePath;
650
+ /**
651
+ * Get metadata file path
652
+ */
653
+ private getMetaPath;
654
+ /**
655
+ * Load checkpoints from disk
656
+ */
657
+ private loadCheckpoints;
658
+ /**
659
+ * Save checkpoint to disk
660
+ */
661
+ private saveCheckpoint;
662
+ /**
663
+ * Delete a checkpoint from disk
664
+ */
665
+ private deleteCheckpoint;
666
+ /**
667
+ * Generate a unique checkpoint ID
668
+ */
669
+ private generateCheckpointId;
670
+ }
671
+ /**
672
+ * Get the default CheckpointManager instance
673
+ */
674
+ declare function getCheckpointManager(): CheckpointManager;
675
+ /**
676
+ * Reset the default CheckpointManager (for testing)
677
+ */
678
+ declare function resetCheckpointManager(): void;
679
+
680
+ /**
681
+ * TaskGraph - State-pinned DAG for task management
682
+ *
683
+ * Manages task dependencies, status tracking, and snapshot binding.
684
+ * Persists graph state to grimoires/anchor/sessions/{sessionId}/graph.json
685
+ */
686
+
687
+ /** Task graph configuration */
688
+ interface TaskGraphConfig {
689
+ /** Session ID */
690
+ sessionId: string;
691
+ /** Base path for session data */
692
+ basePath?: string;
693
+ /** Auto-save on changes */
694
+ autoSave?: boolean;
695
+ }
696
+ /**
697
+ * Generate a unique task ID
698
+ */
699
+ declare function generateTaskId(type: TaskType): string;
700
+ /**
701
+ * Reset the task counter (for testing)
702
+ */
703
+ declare function resetTaskCounter(): void;
704
+ /**
705
+ * TaskGraph class for managing state-pinned task DAG
706
+ */
707
+ declare class TaskGraph {
708
+ private tasks;
709
+ private dependents;
710
+ private sessionId;
711
+ private basePath;
712
+ private autoSave;
713
+ private headTaskId;
714
+ constructor(config: TaskGraphConfig);
715
+ /**
716
+ * Initialize the graph by loading persisted state
717
+ */
718
+ init(): Promise<void>;
719
+ /**
720
+ * Add a task to the graph
721
+ *
722
+ * @param task - Task to add
723
+ */
724
+ addTask(task: Task): Promise<void>;
725
+ /**
726
+ * Update task status
727
+ *
728
+ * @param taskId - Task ID
729
+ * @param status - New status
730
+ */
731
+ updateStatus(taskId: string, status: TaskStatus): Promise<void>;
732
+ /**
733
+ * Set the snapshot binding for a task
734
+ *
735
+ * @param taskId - Task ID
736
+ * @param snapshotId - Snapshot ID
737
+ */
738
+ setSnapshot(taskId: string, snapshotId: string): Promise<void>;
739
+ /**
740
+ * Set the checkpoint binding for a task
741
+ *
742
+ * @param taskId - Task ID
743
+ * @param checkpointId - Checkpoint ID
744
+ */
745
+ setCheckpoint(taskId: string, checkpointId: string): Promise<void>;
746
+ /**
747
+ * Set task output
748
+ *
749
+ * @param taskId - Task ID
750
+ * @param output - Task output
751
+ */
752
+ setOutput(taskId: string, output: unknown): Promise<void>;
753
+ /**
754
+ * Set task error
755
+ *
756
+ * @param taskId - Task ID
757
+ * @param error - Error message
758
+ */
759
+ setError(taskId: string, error: string): Promise<void>;
760
+ /**
761
+ * Get a task by ID
762
+ *
763
+ * @param taskId - Task ID
764
+ * @returns Task if found
765
+ */
766
+ getTask(taskId: string): Task | undefined;
767
+ /**
768
+ * Get all tasks
769
+ *
770
+ * @returns Array of all tasks
771
+ */
772
+ getAllTasks(): Task[];
773
+ /**
774
+ * Get tasks by status
775
+ *
776
+ * @param status - Status to filter by
777
+ * @returns Array of matching tasks
778
+ */
779
+ getTasksByStatus(status: TaskStatus): Task[];
780
+ /**
781
+ * Check if a task can run (all dependencies complete)
782
+ *
783
+ * @param taskId - Task ID
784
+ * @returns True if all dependencies are complete
785
+ */
786
+ canRun(taskId: string): boolean;
787
+ /**
788
+ * Get the next runnable task (pending with all deps complete)
789
+ *
790
+ * @returns Next runnable task or undefined
791
+ */
792
+ getNextRunnable(): Task | undefined;
793
+ /**
794
+ * Propagate blocked status to all dependents of a failed task
795
+ *
796
+ * @param taskId - ID of the failed task
797
+ */
798
+ propagateBlocked(taskId: string): Promise<void>;
799
+ /**
800
+ * Find the recovery point for a failed task
801
+ *
802
+ * @param taskId - ID of the task needing recovery
803
+ * @returns Last complete task with snapshot, or undefined
804
+ */
805
+ findRecoveryPoint(taskId: string): Task | undefined;
806
+ /**
807
+ * Check if there are any blocked tasks
808
+ *
809
+ * @returns True if any tasks are blocked
810
+ */
811
+ hasBlocked(): boolean;
812
+ /**
813
+ * Check if all tasks are complete
814
+ *
815
+ * @returns True if all tasks are complete
816
+ */
817
+ isComplete(): boolean;
818
+ /**
819
+ * Get the graph file path
820
+ */
821
+ private getGraphPath;
822
+ /**
823
+ * Export graph data as JSON-serializable object
824
+ *
825
+ * @returns Task graph data
826
+ */
827
+ toJSON(): TaskGraphData;
828
+ /**
829
+ * Save the graph to disk
830
+ */
831
+ save(): Promise<void>;
832
+ /**
833
+ * Load the graph from disk
834
+ */
835
+ load(): Promise<void>;
836
+ /**
837
+ * Validate that adding a task doesn't create a cycle
838
+ */
839
+ private validateNoCycle;
840
+ }
841
+
842
+ /**
843
+ * SessionManager - Session lifecycle management
844
+ *
845
+ * Manages session creation, persistence, and recovery.
846
+ * Coordinates ForkManager, SnapshotManager, CheckpointManager, and TaskGraph.
847
+ */
848
+
849
+ /** Session metadata */
850
+ interface SessionMetadata {
851
+ /** Session ID */
852
+ id: string;
853
+ /** Network configuration */
854
+ network: NetworkConfig;
855
+ /** Current fork ID */
856
+ forkId: string;
857
+ /** Creation timestamp */
858
+ createdAt: Date;
859
+ /** Last activity timestamp */
860
+ lastActivity: Date;
861
+ /** Session status */
862
+ status: 'active' | 'suspended' | 'complete' | 'failed';
863
+ /** Initial block number */
864
+ initialBlock: number;
865
+ }
866
+ /** Session manager configuration */
867
+ interface SessionManagerConfig {
868
+ /** Base path for session data */
869
+ basePath?: string;
870
+ }
871
+ /** Session state with all managers */
872
+ interface Session {
873
+ metadata: SessionMetadata;
874
+ fork: Fork;
875
+ forkManager: ForkManager;
876
+ snapshotManager: SnapshotManager;
877
+ checkpointManager: CheckpointManager;
878
+ taskGraph: TaskGraph;
879
+ }
880
+ /**
881
+ * SessionManager class for session lifecycle
882
+ */
883
+ declare class SessionManager {
884
+ private sessions;
885
+ private currentSession;
886
+ private basePath;
887
+ constructor(config?: SessionManagerConfig);
888
+ /**
889
+ * Initialize the manager by loading session index
890
+ */
891
+ init(): Promise<void>;
892
+ /**
893
+ * Create a new session
894
+ *
895
+ * @param network - Network to fork
896
+ * @param options - Session options
897
+ * @returns Created session
898
+ */
899
+ create(network: NetworkConfig, options?: {
900
+ blockNumber?: number;
901
+ }): Promise<Session>;
902
+ /**
903
+ * Resume an existing session
904
+ *
905
+ * @param sessionId - Session ID to resume
906
+ * @returns Resumed session
907
+ */
908
+ resume(sessionId: string): Promise<Session>;
909
+ /**
910
+ * Recover a session from checkpoint or snapshot
911
+ */
912
+ private recover;
913
+ /**
914
+ * Get current session
915
+ *
916
+ * @returns Current session or null
917
+ */
918
+ current(): Session | null;
919
+ /**
920
+ * List all sessions
921
+ *
922
+ * @param filter - Optional filter for status
923
+ * @returns Array of session metadata
924
+ */
925
+ list(filter?: {
926
+ status?: SessionMetadata['status'];
927
+ blocked?: boolean;
928
+ }): SessionMetadata[];
929
+ /**
930
+ * Get session by ID
931
+ *
932
+ * @param sessionId - Session ID
933
+ * @returns Session metadata if found
934
+ */
935
+ get(sessionId: string): SessionMetadata | undefined;
936
+ /**
937
+ * Update session status
938
+ *
939
+ * @param sessionId - Session ID
940
+ * @param status - New status
941
+ */
942
+ updateStatus(sessionId: string, status: SessionMetadata['status']): Promise<void>;
943
+ /**
944
+ * Get session directory path
945
+ */
946
+ private getSessionDir;
947
+ /**
948
+ * Get session metadata path
949
+ */
950
+ private getSessionPath;
951
+ /**
952
+ * Load session index
953
+ */
954
+ private loadSessionIndex;
955
+ /**
956
+ * Save session index
957
+ */
958
+ private saveSessionIndex;
959
+ /**
960
+ * Save session metadata
961
+ */
962
+ private saveSession;
963
+ /**
964
+ * Generate unique session ID
965
+ */
966
+ private generateSessionId;
967
+ }
968
+ /**
969
+ * Get the default SessionManager instance
970
+ */
971
+ declare function getSessionManager(): SessionManager;
972
+ /**
973
+ * Reset the default SessionManager (for testing)
974
+ */
975
+ declare function resetSessionManager(): void;
976
+
977
+ /**
978
+ * Warden Types
979
+ *
980
+ * Type definitions for the Warden ground truth enforcement system.
981
+ */
982
+
983
+ /** Sync strategy from physics table */
984
+ type SyncStrategy = 'pessimistic' | 'optimistic' | 'immediate';
985
+ /** Confirmation requirement */
986
+ type ConfirmationType = 'required' | 'toast_undo' | 'none';
987
+ /** Effect type from physics/lexicon */
988
+ type EffectType = 'financial' | 'destructive' | 'soft_delete' | 'standard' | 'navigation' | 'query' | 'local' | 'high_freq';
989
+ /** Physics rule for an effect type */
990
+ interface PhysicsRule {
991
+ /** Effect type */
992
+ effect: EffectType;
993
+ /** Sync strategy */
994
+ sync: SyncStrategy;
995
+ /** Timing in milliseconds */
996
+ timing: number;
997
+ /** Confirmation requirement */
998
+ confirmation: ConfirmationType;
999
+ /** Rationale for this physics */
1000
+ rationale: string;
1001
+ }
1002
+ /** Physics table mapping effect to rules */
1003
+ type PhysicsTable = Map<EffectType, PhysicsRule>;
1004
+ /** Vocabulary entry linking keywords to effects */
1005
+ interface VocabularyEntry {
1006
+ /** Keywords that trigger this effect */
1007
+ keywords: string[];
1008
+ /** Associated effect type */
1009
+ effect: EffectType;
1010
+ /** Category (primary, extended, web3, etc.) */
1011
+ category: string;
1012
+ }
1013
+ /** Full vocabulary mapping */
1014
+ interface Vocabulary {
1015
+ /** Effect keywords grouped by effect type */
1016
+ effects: Map<EffectType, VocabularyEntry>;
1017
+ /** Type overrides that force specific effects */
1018
+ typeOverrides: Map<string, EffectType>;
1019
+ /** Domain context defaults */
1020
+ domainDefaults: Map<string, EffectType>;
1021
+ }
1022
+ /** Grounding statement parsed from agent output */
1023
+ interface GroundingStatement {
1024
+ /** Component or action being described */
1025
+ component: string;
1026
+ /** Zone cited by agent (if any) */
1027
+ citedZone: Zone | null;
1028
+ /** Keywords detected in the statement */
1029
+ detectedKeywords: string[];
1030
+ /** Effect inferred from keywords */
1031
+ inferredEffect: EffectType | null;
1032
+ /** Physics rules claimed to be applied */
1033
+ claimedPhysics: {
1034
+ sync?: SyncStrategy;
1035
+ timing?: number;
1036
+ confirmation?: ConfirmationType;
1037
+ };
1038
+ /** Raw statement text */
1039
+ raw: string;
1040
+ }
1041
+ /** Validation check names */
1042
+ type CheckName = 'relevance' | 'hierarchy' | 'rules';
1043
+ /** Extended check result with details */
1044
+ interface ExtendedCheckResult extends CheckResult {
1045
+ /** Check name */
1046
+ name: CheckName;
1047
+ /** Expected value (if applicable) */
1048
+ expected?: string;
1049
+ /** Actual value (if applicable) */
1050
+ actual?: string;
1051
+ }
1052
+ /** Warden validation context */
1053
+ interface ValidationContext {
1054
+ /** Parsed grounding statement */
1055
+ statement: GroundingStatement;
1056
+ /** Physics table */
1057
+ physics: PhysicsTable;
1058
+ /** Vocabulary */
1059
+ vocabulary: Vocabulary;
1060
+ /** Required zone based on keywords */
1061
+ requiredZone: Zone;
1062
+ }
1063
+
1064
+ /**
1065
+ * PhysicsLoader - Load Sigil physics rules from markdown
1066
+ *
1067
+ * Parses .claude/rules/01-sigil-physics.md to extract the physics table.
1068
+ */
1069
+
1070
+ /**
1071
+ * Get default physics table (fallback when file not found)
1072
+ */
1073
+ declare function getDefaultPhysics(): PhysicsTable;
1074
+ /**
1075
+ * Load physics from file
1076
+ *
1077
+ * @param path - Path to physics markdown file (default: .claude/rules/01-sigil-physics.md)
1078
+ * @returns Parsed physics table
1079
+ */
1080
+ declare function loadPhysics(path?: string): Promise<PhysicsTable>;
1081
+ /**
1082
+ * Get physics rule for an effect type
1083
+ *
1084
+ * @param effect - Effect type to look up
1085
+ * @param physics - Physics table (will load if not provided)
1086
+ * @returns Physics rule or undefined
1087
+ */
1088
+ declare function getPhysicsRule(effect: EffectType, physics?: PhysicsTable): Promise<PhysicsRule | undefined>;
1089
+ /**
1090
+ * Clear physics cache (for testing)
1091
+ */
1092
+ declare function clearPhysicsCache(): void;
1093
+ /**
1094
+ * Check if physics are cached
1095
+ */
1096
+ declare function isPhysicsCached(): boolean;
1097
+
1098
+ /**
1099
+ * VocabularyLoader - Load Sigil vocabulary from markdown
1100
+ *
1101
+ * Parses .claude/rules/08-sigil-lexicon.md to extract keyword → effect mappings.
1102
+ */
1103
+
1104
+ /**
1105
+ * Get default vocabulary (fallback)
1106
+ */
1107
+ declare function getDefaultVocabulary(): Vocabulary;
1108
+ /**
1109
+ * Load vocabulary from file
1110
+ *
1111
+ * @param path - Path to vocabulary markdown file
1112
+ * @returns Parsed vocabulary
1113
+ */
1114
+ declare function loadVocabulary(path?: string): Promise<Vocabulary>;
1115
+ /**
1116
+ * Resolve effect from keywords
1117
+ *
1118
+ * @param keywords - Keywords to look up
1119
+ * @param vocabulary - Vocabulary (will load if not provided)
1120
+ * @returns Most specific effect type found, or null
1121
+ */
1122
+ declare function resolveEffectFromKeywords(keywords: string[], vocabulary?: Vocabulary): Promise<EffectType | null>;
1123
+ /**
1124
+ * Clear vocabulary cache (for testing)
1125
+ */
1126
+ declare function clearVocabularyCache(): void;
1127
+ /**
1128
+ * Check if vocabulary is cached
1129
+ */
1130
+ declare function isVocabularyCached(): boolean;
1131
+
1132
+ /**
1133
+ * GroundingGate - Validate agent grounding statements
1134
+ *
1135
+ * Parses agent output for grounding statements and validates them
1136
+ * against Sigil physics rules.
1137
+ */
1138
+
1139
+ /**
1140
+ * Parse grounding statement from text
1141
+ *
1142
+ * Looks for patterns like:
1143
+ * - "Zone: critical"
1144
+ * - "Effect: Financial"
1145
+ * - "Sync: pessimistic"
1146
+ * - "Timing: 800ms"
1147
+ * - Physics analysis boxes
1148
+ */
1149
+ declare function parseGroundingStatement(text: string): GroundingStatement;
1150
+ /**
1151
+ * Validate a grounding statement
1152
+ *
1153
+ * @param input - Raw text or parsed statement
1154
+ * @param options - Validation options
1155
+ * @returns Warden validation result
1156
+ */
1157
+ declare function validateGrounding(input: string | GroundingStatement, options?: {
1158
+ physicsPath?: string;
1159
+ vocabularyPath?: string;
1160
+ }): Promise<WardenResult>;
1161
+ /**
1162
+ * Quick validation check - returns true if valid
1163
+ */
1164
+ declare function isGroundingValid(input: string | GroundingStatement, options?: {
1165
+ physicsPath?: string;
1166
+ vocabularyPath?: string;
1167
+ }): Promise<boolean>;
1168
+ /**
1169
+ * Get exit code for validation result
1170
+ */
1171
+ declare function getExitCode(result: WardenResult): number;
1172
+
1173
+ /**
1174
+ * JSON-RPC helper for Anvil communication
1175
+ *
1176
+ * Provides type-safe RPC calls with timeout handling and error management.
1177
+ */
1178
+
1179
+ /** RPC error with code and message */
1180
+ declare class RpcError extends Error {
1181
+ readonly code: number;
1182
+ readonly data?: unknown;
1183
+ constructor(code: number, message: string, data?: unknown);
1184
+ }
1185
+ /** RPC timeout error */
1186
+ declare class RpcTimeoutError extends Error {
1187
+ readonly method: string;
1188
+ readonly timeoutMs: number;
1189
+ constructor(method: string, timeoutMs: number);
1190
+ }
1191
+ /**
1192
+ * Make a JSON-RPC call to an Anvil node
1193
+ *
1194
+ * @param url - RPC endpoint URL
1195
+ * @param method - RPC method name (e.g., 'eth_blockNumber', 'evm_snapshot')
1196
+ * @param params - Optional method parameters
1197
+ * @param timeoutMs - Timeout in milliseconds (default: 30000)
1198
+ * @returns Promise resolving to the result
1199
+ * @throws {RpcError} If the RPC returns an error
1200
+ * @throws {RpcTimeoutError} If the request times out
1201
+ */
1202
+ declare function rpcCall<T>(url: string, method: string, params?: unknown[], timeoutMs?: number): Promise<T>;
1203
+ /**
1204
+ * Check if an RPC endpoint is ready by calling eth_chainId
1205
+ *
1206
+ * @param url - RPC endpoint URL
1207
+ * @param timeoutMs - Timeout for the check
1208
+ * @returns Promise resolving to true if ready, false otherwise
1209
+ */
1210
+ declare function isRpcReady(url: string, timeoutMs?: number): Promise<boolean>;
1211
+ /**
1212
+ * Poll until RPC is ready
1213
+ *
1214
+ * @param url - RPC endpoint URL
1215
+ * @param maxAttempts - Maximum number of polling attempts
1216
+ * @param intervalMs - Interval between attempts in ms
1217
+ * @returns Promise resolving when ready
1218
+ * @throws Error if max attempts exceeded
1219
+ */
1220
+ declare function waitForRpc(url: string, maxAttempts?: number, intervalMs?: number): Promise<void>;
1221
+
1222
+ /**
1223
+ * Anchor v4.3.1 - Ground Truth Enforcement
1224
+ *
1225
+ * Sigil marks intent. Anchor grounds it, enforces it, and catches every lie.
1226
+ */
1227
+
1228
+ declare const VERSION = "4.3.1";
1229
+
1230
+ export { type CheckName, type CheckResult, type CheckpointConfig, CheckpointManager, type CheckpointMetadata, type ConfirmationType, type EffectType, ExitCode, type ExitCodeValue, type ExtendedCheckResult, type Fork, type ForkConfig, ForkManager, type ForkRegistry, ForkRegistrySchema, ForkSchema, type GroundingStatement, type NetworkConfig, type PhysicsRule, type PhysicsTable, RpcError, RpcTimeoutError, type Session, SessionManager, type SessionManagerConfig, type SessionMetadata, type SnapshotConfig, SnapshotManager, type SnapshotMetadata, type SyncStrategy, type Task, TaskGraph, type TaskGraphData, type TaskStatus, type TaskType, VERSION, type ValidationContext, type Vocabulary, type VocabularyEntry, type WardenInput, type WardenResult, ZONE_HIERARCHY, type Zone, clearPhysicsCache, clearVocabularyCache, generateTaskId, getCheckpointManager, getDefaultPhysics, getDefaultVocabulary, getExitCode, getForkManager, getPhysicsRule, getSessionManager, getSnapshotManager, isGroundingValid, isPhysicsCached, isRpcReady, isVocabularyCached, loadPhysics, loadVocabulary, parseGroundingStatement, resetCheckpointManager, resetForkManager, resetSessionManager, resetSnapshotManager, resetTaskCounter, resolveEffectFromKeywords, rpcCall, validateGrounding, waitForRpc };