@kjerneverk/riotplan-format 1.0.0-dev.0

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,973 @@
1
+ /**
2
+ * @kjerneverk/riotplan-format
3
+ *
4
+ * SQLite-based storage format for RiotPlan with dual format support.
5
+ *
6
+ * This package provides a storage abstraction layer that supports both
7
+ * directory-based and SQLite .plan formats for RiotPlan plans.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+
12
+ /**
13
+ * Options for batch migration
14
+ */
15
+ export declare interface BatchMigrationOptions extends MigrationOptions {
16
+ /** Glob pattern for source plans */
17
+ pattern?: string;
18
+ /** Maximum concurrent migrations */
19
+ concurrency?: number;
20
+ /** Continue on individual failures */
21
+ continueOnError?: boolean;
22
+ /** Target format for all migrations */
23
+ targetFormat?: StorageFormat;
24
+ }
25
+
26
+ /**
27
+ * Result of batch migration
28
+ */
29
+ export declare interface BatchMigrationResult {
30
+ /** Total number of plans found */
31
+ totalPlans: number;
32
+ /** Number of successful migrations */
33
+ successful: number;
34
+ /** Number of failed migrations */
35
+ failed: number;
36
+ /** Number of skipped migrations */
37
+ skipped: number;
38
+ /** Individual migration results */
39
+ results: MigrationResult[];
40
+ /** Total duration in milliseconds */
41
+ duration: number;
42
+ }
43
+
44
+ /**
45
+ * Checkpoint for saving plan state
46
+ */
47
+ export declare interface Checkpoint {
48
+ /** Checkpoint name */
49
+ name: string;
50
+ /** Checkpoint message/description */
51
+ message: string;
52
+ /** Creation timestamp (ISO 8601) */
53
+ createdAt: string;
54
+ /** Snapshot of plan state at checkpoint time */
55
+ snapshot: CheckpointSnapshot;
56
+ }
57
+
58
+ /**
59
+ * Snapshot of plan state for checkpoints
60
+ */
61
+ export declare interface CheckpointSnapshot {
62
+ /** Plan metadata at checkpoint time */
63
+ metadata: PlanMetadata;
64
+ /** Step statuses at checkpoint time */
65
+ steps: Pick<PlanStep, 'number' | 'status' | 'startedAt' | 'completedAt'>[];
66
+ /** Files included in checkpoint */
67
+ files: Pick<PlanFile, 'type' | 'filename' | 'content'>[];
68
+ }
69
+
70
+ /**
71
+ * Create a directory storage provider
72
+ *
73
+ * @param planPath - Path to the plan directory
74
+ * @returns A directory storage provider instance
75
+ *
76
+ * @remarks
77
+ * This creates a base provider that throws "not implemented" errors.
78
+ * Use the implementation from the main riotplan package for actual functionality.
79
+ */
80
+ export declare function createDirectoryProvider(planPath: string): DirectoryStorageProvider;
81
+
82
+ /**
83
+ * Create a plan migrator
84
+ */
85
+ export declare function createMigrator(): PlanMigrator;
86
+
87
+ /**
88
+ * Create a storage provider for the given path using default configuration
89
+ *
90
+ * This is a convenience function for simple use cases.
91
+ *
92
+ * @param planPath - Path to the plan
93
+ * @param options - Optional creation options
94
+ * @returns A storage provider instance
95
+ */
96
+ export declare function createProvider(planPath: string, options?: CreateProviderOptions & {
97
+ config?: Partial<FormatConfig>;
98
+ }): StorageProvider;
99
+
100
+ /**
101
+ * Options for creating a storage provider
102
+ */
103
+ export declare interface CreateProviderOptions {
104
+ /** Force a specific format instead of auto-detecting */
105
+ format?: StorageFormat;
106
+ /** Create the plan if it doesn't exist */
107
+ create?: boolean;
108
+ }
109
+
110
+ /**
111
+ * Create a new SQLite storage provider
112
+ */
113
+ export declare function createSqliteProvider(planPath: string): SqliteStorageProvider;
114
+
115
+ /**
116
+ * Create a storage provider factory with the given configuration
117
+ *
118
+ * @param config - Optional format configuration
119
+ * @returns A storage provider factory
120
+ */
121
+ export declare function createStorageFactory(config?: Partial<FormatConfig>): DefaultStorageProviderFactory;
122
+
123
+ /**
124
+ * Create a migration validator
125
+ */
126
+ export declare function createValidator(): MigrationValidator;
127
+
128
+ /**
129
+ * Default directory configuration
130
+ */
131
+ export declare const DEFAULT_DIRECTORY_CONFIG: Required<DirectoryConfig>;
132
+
133
+ /**
134
+ * Default format configuration
135
+ */
136
+ export declare const DEFAULT_FORMAT_CONFIG: ResolvedFormatConfig;
137
+
138
+ /**
139
+ * Default SQLite configuration
140
+ */
141
+ export declare const DEFAULT_SQLITE_CONFIG: Required<SqliteConfig>;
142
+
143
+ /**
144
+ * Default storage provider factory implementation
145
+ *
146
+ * Creates appropriate storage providers based on path characteristics
147
+ * and configuration preferences.
148
+ */
149
+ export declare class DefaultStorageProviderFactory implements StorageProviderFactory {
150
+ private config;
151
+ constructor(config?: Partial<FormatConfig>);
152
+ /**
153
+ * Create a storage provider for the given path
154
+ *
155
+ * @param planPath - Path to the plan
156
+ * @param options - Optional creation options
157
+ * @returns A storage provider instance
158
+ */
159
+ createProvider(planPath: string, options?: CreateProviderOptions): StorageProvider;
160
+ /**
161
+ * Check if this factory supports the given path
162
+ *
163
+ * @param planPath - Path to check
164
+ * @returns True if a provider can be created for this path
165
+ */
166
+ supportsPath(planPath: string): boolean;
167
+ /**
168
+ * Determine the format to use for a path
169
+ *
170
+ * @param planPath - The plan path
171
+ * @param forcedFormat - Optional format override
172
+ * @returns The format to use
173
+ */
174
+ private determineFormat;
175
+ /**
176
+ * Get the default format from configuration
177
+ */
178
+ get defaultFormat(): StorageFormat;
179
+ /**
180
+ * Get the SQLite configuration
181
+ */
182
+ get sqliteConfig(): Required<SqliteConfig>;
183
+ /**
184
+ * Get the directory configuration
185
+ */
186
+ get directoryConfig(): Required<DirectoryConfig>;
187
+ }
188
+
189
+ /**
190
+ * Detect the format of a plan at the given path
191
+ *
192
+ * @param planPath - Path to check
193
+ * @returns The detected format or 'unknown' if not a valid plan
194
+ */
195
+ export declare function detectPlanFormat(planPath: string): StorageFormat | 'unknown';
196
+
197
+ /**
198
+ * Configuration options for directory storage
199
+ */
200
+ export declare interface DirectoryConfig {
201
+ /** Create plan subdirectory by default (default: true) */
202
+ usePlanSubdir?: boolean;
203
+ /** Default directory permissions (default: '0755') */
204
+ permissions?: string;
205
+ }
206
+
207
+ /**
208
+ * Directory-based storage provider
209
+ *
210
+ * This provider stores plans as a directory structure with markdown files.
211
+ * The directory structure follows the RiotPlan convention:
212
+ *
213
+ * ```
214
+ * my-plan/
215
+ * ├── SUMMARY.md
216
+ * ├── STATUS.md
217
+ * ├── IDEA.md (optional)
218
+ * ├── SHAPING.md (optional)
219
+ * ├── EXECUTION_PLAN.md (optional)
220
+ * ├── plan/
221
+ * │ ├── 01-step-one.md
222
+ * │ ├── 02-step-two.md
223
+ * │ └── ...
224
+ * ├── evidence/
225
+ * │ └── *.md
226
+ * ├── feedback/
227
+ * │ └── *.md
228
+ * ├── reflections/
229
+ * │ └── *.md
230
+ * └── .history/
231
+ * ├── timeline.json
232
+ * └── checkpoints/
233
+ * └── *.json
234
+ * ```
235
+ *
236
+ * @remarks
237
+ * This is a base implementation that throws "not implemented" errors.
238
+ * The main riotplan package should extend this class and implement
239
+ * the methods using its existing file loading logic.
240
+ */
241
+ export declare class DirectoryStorageProvider implements StorageProvider {
242
+ readonly format: StorageFormat;
243
+ readonly path: string;
244
+ constructor(planPath: string);
245
+ exists(): Promise<boolean>;
246
+ initialize(_metadata: PlanMetadata): Promise<StorageResult<void>>;
247
+ close(): Promise<void>;
248
+ getMetadata(): Promise<StorageResult<PlanMetadata>>;
249
+ updateMetadata(_updates: Partial<PlanMetadata>): Promise<StorageResult<void>>;
250
+ getSteps(): Promise<StorageResult<PlanStep[]>>;
251
+ getStep(_number: number): Promise<StorageResult<PlanStep | null>>;
252
+ addStep(_step: PlanStep): Promise<StorageResult<void>>;
253
+ updateStep(_number: number, _updates: Partial<PlanStep>): Promise<StorageResult<void>>;
254
+ deleteStep(_number: number): Promise<StorageResult<void>>;
255
+ getFiles(): Promise<StorageResult<PlanFile[]>>;
256
+ getFile(_type: string, _filename: string): Promise<StorageResult<PlanFile | null>>;
257
+ saveFile(_file: PlanFile): Promise<StorageResult<void>>;
258
+ deleteFile(_type: string, _filename: string): Promise<StorageResult<void>>;
259
+ getTimelineEvents(): Promise<StorageResult<TimelineEvent[]>>;
260
+ addTimelineEvent(_event: TimelineEvent): Promise<StorageResult<void>>;
261
+ getEvidence(): Promise<StorageResult<EvidenceRecord[]>>;
262
+ addEvidence(_evidence: EvidenceRecord): Promise<StorageResult<void>>;
263
+ getFeedback(): Promise<StorageResult<FeedbackRecord[]>>;
264
+ addFeedback(_feedback: FeedbackRecord): Promise<StorageResult<void>>;
265
+ getCheckpoints(): Promise<StorageResult<Checkpoint[]>>;
266
+ getCheckpoint(_name: string): Promise<StorageResult<Checkpoint | null>>;
267
+ createCheckpoint(_checkpoint: Checkpoint): Promise<StorageResult<void>>;
268
+ restoreCheckpoint(_name: string): Promise<StorageResult<void>>;
269
+ search(_query: string): Promise<StorageResult<SearchResult[]>>;
270
+ createSnapshot(): Promise<CheckpointSnapshot>;
271
+ }
272
+
273
+ /**
274
+ * Ensure a path has the correct extension for the format
275
+ *
276
+ * @param planPath - The plan path
277
+ * @param format - The storage format
278
+ * @param config - Optional format configuration
279
+ * @returns The path with the correct extension
280
+ */
281
+ export declare function ensureFormatExtension(planPath: string, format: StorageFormat, config?: FormatConfig): string;
282
+
283
+ /**
284
+ * Evidence record stored in the database
285
+ */
286
+ export declare interface EvidenceRecord {
287
+ /** Evidence ID */
288
+ id: string;
289
+ /** Evidence description */
290
+ description: string;
291
+ /** Source of the evidence */
292
+ source?: string;
293
+ /** Source URL if applicable */
294
+ sourceUrl?: string;
295
+ /** How the evidence was gathered */
296
+ gatheringMethod?: 'manual' | 'model-assisted';
297
+ /** Evidence content (for inline evidence) */
298
+ content?: string;
299
+ /** Path to evidence file (for file-based evidence) */
300
+ filePath?: string;
301
+ /** Relevance score (0-1) from model if model-assisted */
302
+ relevanceScore?: number;
303
+ /** Original question or search query that prompted gathering this evidence */
304
+ originalQuery?: string;
305
+ /** Model-generated summary of the evidence */
306
+ summary?: string;
307
+ /** Creation timestamp (ISO 8601) */
308
+ createdAt: string;
309
+ }
310
+
311
+ /**
312
+ * Feedback record stored in the database
313
+ */
314
+ export declare interface FeedbackRecord {
315
+ /** Feedback ID */
316
+ id: string;
317
+ /** Feedback title */
318
+ title?: string;
319
+ /** Platform where feedback was given */
320
+ platform?: string;
321
+ /** Feedback content */
322
+ content: string;
323
+ /** Participants in the feedback session */
324
+ participants?: string[];
325
+ /** Creation timestamp (ISO 8601) */
326
+ createdAt: string;
327
+ }
328
+
329
+ /**
330
+ * Format-related configuration for RiotPlan
331
+ */
332
+ export declare interface FormatConfig {
333
+ /** Default plan storage format (default: 'directory') */
334
+ defaultFormat?: StorageFormat;
335
+ /** SQLite-specific options */
336
+ sqlite?: SqliteConfig;
337
+ /** Directory-specific options */
338
+ directory?: DirectoryConfig;
339
+ }
340
+
341
+ /**
342
+ * Generate a target path based on source path and target format
343
+ */
344
+ export declare function generateTargetPath(sourcePath: string, sourceFormat: StorageFormat, targetFormat: StorageFormat): string;
345
+
346
+ /**
347
+ * Get the appropriate file extension for a format
348
+ *
349
+ * @param format - The storage format
350
+ * @param config - Optional format configuration
351
+ * @returns The file extension (empty string for directory format)
352
+ */
353
+ export declare function getFormatExtension(format: StorageFormat, config?: FormatConfig): string;
354
+
355
+ /**
356
+ * Get plan name from path
357
+ *
358
+ * @param planPath - The plan path
359
+ * @param format - The storage format
360
+ * @param config - Optional format configuration
361
+ * @returns The plan name extracted from the path
362
+ */
363
+ export declare function getPlanNameFromPath(planPath: string, format: StorageFormat, config?: FormatConfig): string;
364
+
365
+ /**
366
+ * Check if a file has a valid SQLite header
367
+ *
368
+ * @param filePath - Path to the file
369
+ * @returns True if the file starts with SQLite magic bytes
370
+ */
371
+ export declare function hasSqliteHeader(filePath: string): boolean;
372
+
373
+ /**
374
+ * Infer the format from a path based on extension and existence
375
+ *
376
+ * @param planPath - The plan path
377
+ * @param config - Optional format configuration
378
+ * @returns The inferred format
379
+ */
380
+ export declare function inferFormatFromPath(planPath: string, config?: FormatConfig): StorageFormat;
381
+
382
+ /**
383
+ * Infer target format from source format (opposite format)
384
+ */
385
+ export declare function inferTargetFormat(sourceFormat: StorageFormat): StorageFormat;
386
+
387
+ /**
388
+ * Check if a path looks like it should be a directory plan
389
+ *
390
+ * @param planPath - Path to check
391
+ * @returns True if the path exists and is a directory, or doesn't have a file extension
392
+ */
393
+ export declare function isDirectoryPath(planPath: string): boolean;
394
+
395
+ /**
396
+ * Check if a path looks like it should be a SQLite plan file
397
+ *
398
+ * @param planPath - Path to check
399
+ * @param config - Optional format configuration
400
+ * @returns True if the path has a SQLite plan extension
401
+ */
402
+ export declare function isSqlitePath(planPath: string, config?: FormatConfig): boolean;
403
+
404
+ /**
405
+ * Options for markdown rendering
406
+ */
407
+ export declare interface MarkdownRenderOptions {
408
+ /** Include timeline events in output */
409
+ includeTimeline?: boolean;
410
+ /** Include evidence records */
411
+ includeEvidence?: boolean;
412
+ /** Include feedback records */
413
+ includeFeedback?: boolean;
414
+ /** Include source format metadata */
415
+ includeSourceInfo?: boolean;
416
+ }
417
+
418
+ /**
419
+ * Merge user config with defaults
420
+ */
421
+ export declare function mergeFormatConfig(userConfig?: Partial<FormatConfig>): ResolvedFormatConfig;
422
+
423
+ /**
424
+ * Options for migration operations
425
+ */
426
+ export declare interface MigrationOptions {
427
+ /** Overwrite destination if it exists */
428
+ force?: boolean;
429
+ /** Preserve source after migration */
430
+ keepSource?: boolean;
431
+ /** Validate data integrity after migration */
432
+ validate?: boolean;
433
+ /** Progress callback */
434
+ onProgress?: (progress: MigrationProgress) => void;
435
+ }
436
+
437
+ /**
438
+ * Progress information during migration
439
+ */
440
+ export declare interface MigrationProgress {
441
+ /** Current phase */
442
+ phase: 'reading' | 'converting' | 'writing' | 'validating';
443
+ /** Progress percentage (0-100) */
444
+ percentage: number;
445
+ /** Current item being processed */
446
+ currentItem?: string;
447
+ /** Total items to process */
448
+ totalItems?: number;
449
+ /** Items processed so far */
450
+ processedItems?: number;
451
+ }
452
+
453
+ /**
454
+ * Result of a migration operation
455
+ */
456
+ export declare interface MigrationResult {
457
+ /** Whether the migration succeeded */
458
+ success: boolean;
459
+ /** Source format */
460
+ sourceFormat: StorageFormat;
461
+ /** Target format */
462
+ targetFormat: StorageFormat;
463
+ /** Source path */
464
+ sourcePath: string;
465
+ /** Target path */
466
+ targetPath: string;
467
+ /** Error message if failed */
468
+ error?: string;
469
+ /** Warning messages */
470
+ warnings: string[];
471
+ /** Migration statistics */
472
+ stats: MigrationStats;
473
+ /** Duration in milliseconds */
474
+ duration: number;
475
+ }
476
+
477
+ /**
478
+ * Statistics from a migration operation
479
+ */
480
+ export declare interface MigrationStats {
481
+ /** Number of steps converted */
482
+ stepsConverted: number;
483
+ /** Number of files converted */
484
+ filesConverted: number;
485
+ /** Number of timeline events converted */
486
+ timelineEventsConverted: number;
487
+ /** Number of evidence records converted */
488
+ evidenceConverted: number;
489
+ /** Number of feedback records converted */
490
+ feedbackConverted: number;
491
+ /** Number of checkpoints converted */
492
+ checkpointsConverted: number;
493
+ }
494
+
495
+ /**
496
+ * Validates migration fidelity between source and target
497
+ */
498
+ export declare class MigrationValidator {
499
+ /**
500
+ * Validate that target contains all data from source
501
+ */
502
+ validate(source: StorageProvider, target: StorageProvider): Promise<ValidationResult>;
503
+ private validateMetadata;
504
+ private validateSteps;
505
+ private validateFiles;
506
+ private validateTimeline;
507
+ private validateEvidence;
508
+ private validateFeedback;
509
+ }
510
+
511
+ /**
512
+ * File extension for SQLite plan files
513
+ */
514
+ export declare const PLAN_FILE_EXTENSION = ".plan";
515
+
516
+ /**
517
+ * Plan file stored in the database
518
+ */
519
+ export declare interface PlanFile {
520
+ /** File type identifier */
521
+ type: PlanFileType;
522
+ /** Original filename */
523
+ filename: string;
524
+ /** File content (markdown/text) */
525
+ content: string;
526
+ /** Creation timestamp (ISO 8601) */
527
+ createdAt: string;
528
+ /** Last update timestamp (ISO 8601) */
529
+ updatedAt: string;
530
+ }
531
+
532
+ /**
533
+ * Known plan file types
534
+ */
535
+ export declare type PlanFileType = 'idea' | 'shaping' | 'summary' | 'execution_plan' | 'status' | 'provenance' | 'lifecycle' | 'evidence' | 'feedback' | 'prompt' | 'reflection' | 'other';
536
+
537
+ /**
538
+ * Plan metadata stored in the database
539
+ */
540
+ export declare interface PlanMetadata {
541
+ /** Unique plan identifier (code) */
542
+ id: string;
543
+ /** Human-readable plan name */
544
+ name: string;
545
+ /** Plan description */
546
+ description?: string;
547
+ /** Creation timestamp (ISO 8601) */
548
+ createdAt: string;
549
+ /** Last update timestamp (ISO 8601) */
550
+ updatedAt: string;
551
+ /** Current lifecycle stage */
552
+ stage: PlanStage;
553
+ /** Schema version for migrations */
554
+ schemaVersion: number;
555
+ }
556
+
557
+ /**
558
+ * Migrates plans between directory and SQLite formats
559
+ */
560
+ export declare class PlanMigrator {
561
+ private validator;
562
+ constructor();
563
+ /**
564
+ * Migrate a plan from source to target format
565
+ *
566
+ * @param sourcePath - Path to source plan
567
+ * @param targetPath - Path for target plan
568
+ * @param sourceProvider - Provider for reading source
569
+ * @param targetProvider - Provider for writing target
570
+ * @param options - Migration options
571
+ */
572
+ migrate(sourcePath: string, targetPath: string, sourceProvider: StorageProvider, targetProvider: StorageProvider, options?: MigrationOptions): Promise<MigrationResult>;
573
+ private migrateSteps;
574
+ private migrateFiles;
575
+ private migrateTimeline;
576
+ private migrateEvidence;
577
+ private migrateFeedback;
578
+ private migrateCheckpoints;
579
+ private deleteSource;
580
+ private reportProgress;
581
+ }
582
+
583
+ /**
584
+ * Plan lifecycle stages
585
+ */
586
+ export declare type PlanStage = 'idea' | 'shaping' | 'built' | 'executing' | 'completed' | 'cancelled';
587
+
588
+ /**
589
+ * Plan step stored in the database
590
+ */
591
+ export declare interface PlanStep {
592
+ /** Step number (1-based) */
593
+ number: number;
594
+ /** Step code/identifier */
595
+ code: string;
596
+ /** Step title */
597
+ title: string;
598
+ /** Step description/objective */
599
+ description?: string;
600
+ /** Step status */
601
+ status: StepStatus;
602
+ /** When the step was started (ISO 8601) */
603
+ startedAt?: string;
604
+ /** When the step was completed (ISO 8601) */
605
+ completedAt?: string;
606
+ /** Full markdown content of the step file */
607
+ content: string;
608
+ }
609
+
610
+ /**
611
+ * Rendered plan as markdown files
612
+ */
613
+ export declare interface RenderedPlan {
614
+ /** Main files (SUMMARY.md, STATUS.md, etc.) */
615
+ files: Map<string, string>;
616
+ /** Step files (plan/01-step.md, etc.) */
617
+ steps: Map<string, string>;
618
+ /** Evidence files (evidence/*.md) */
619
+ evidence: Map<string, string>;
620
+ /** Feedback files (feedback/*.md) */
621
+ feedback: Map<string, string>;
622
+ }
623
+
624
+ /**
625
+ * Render a plan to markdown format
626
+ */
627
+ export declare function renderPlanToMarkdown(provider: StorageProvider, options?: MarkdownRenderOptions): Promise<RenderedPlan>;
628
+
629
+ /**
630
+ * Resolved format configuration with all fields required
631
+ */
632
+ export declare interface ResolvedFormatConfig {
633
+ defaultFormat: StorageFormat;
634
+ sqlite: Required<SqliteConfig>;
635
+ directory: Required<DirectoryConfig>;
636
+ }
637
+
638
+ /**
639
+ * Current SQLite schema version
640
+ */
641
+ export declare const SCHEMA_VERSION = 1;
642
+
643
+ /**
644
+ * Search result from content search
645
+ */
646
+ export declare interface SearchResult {
647
+ /** Type of content found */
648
+ type: 'step' | 'file' | 'evidence' | 'feedback' | 'timeline';
649
+ /** Identifier (step number, filename, etc.) */
650
+ id: string;
651
+ /** Matching content snippet */
652
+ snippet: string;
653
+ /** Relevance score (0-1) */
654
+ score: number;
655
+ }
656
+
657
+ /**
658
+ * Configuration options for SQLite storage
659
+ */
660
+ export declare interface SqliteConfig {
661
+ /** Enable WAL mode for better concurrency (default: true) */
662
+ walMode?: boolean;
663
+ /** SQLite pragma settings */
664
+ pragmas?: Record<string, string | number | boolean>;
665
+ /** File extension for SQLite plan files (default: '.plan') */
666
+ extension?: string;
667
+ }
668
+
669
+ /**
670
+ * SQLite-based storage provider for .plan files
671
+ */
672
+ export declare class SqliteStorageProvider implements StorageProvider {
673
+ readonly format: "sqlite";
674
+ readonly path: string;
675
+ private db;
676
+ private planId;
677
+ constructor(planPath: string);
678
+ /**
679
+ * Initialize the database with schema
680
+ */
681
+ private initializeSchema;
682
+ /**
683
+ * Get the plan ID, loading it if necessary
684
+ */
685
+ private getPlanId;
686
+ exists(): Promise<boolean>;
687
+ initialize(metadata: PlanMetadata): Promise<StorageResult<void>>;
688
+ close(): Promise<void>;
689
+ getMetadata(): Promise<StorageResult<PlanMetadata>>;
690
+ updateMetadata(metadata: Partial<PlanMetadata>): Promise<StorageResult<void>>;
691
+ getSteps(): Promise<StorageResult<PlanStep[]>>;
692
+ getStep(number: number): Promise<StorageResult<PlanStep | null>>;
693
+ addStep(step: PlanStep): Promise<StorageResult<void>>;
694
+ updateStep(number: number, updates: Partial<PlanStep>): Promise<StorageResult<void>>;
695
+ deleteStep(number: number): Promise<StorageResult<void>>;
696
+ getFiles(): Promise<StorageResult<PlanFile[]>>;
697
+ getFile(type: string, filename: string): Promise<StorageResult<PlanFile | null>>;
698
+ saveFile(file: PlanFile): Promise<StorageResult<void>>;
699
+ deleteFile(type: string, filename: string): Promise<StorageResult<void>>;
700
+ getTimelineEvents(options?: {
701
+ since?: string;
702
+ type?: string;
703
+ limit?: number;
704
+ }): Promise<StorageResult<TimelineEvent[]>>;
705
+ addTimelineEvent(event: TimelineEvent): Promise<StorageResult<void>>;
706
+ getEvidence(): Promise<StorageResult<EvidenceRecord[]>>;
707
+ addEvidence(evidence: EvidenceRecord): Promise<StorageResult<void>>;
708
+ getFeedback(): Promise<StorageResult<FeedbackRecord[]>>;
709
+ addFeedback(feedback: FeedbackRecord): Promise<StorageResult<void>>;
710
+ getCheckpoints(): Promise<StorageResult<Checkpoint[]>>;
711
+ getCheckpoint(name: string): Promise<StorageResult<Checkpoint | null>>;
712
+ createCheckpoint(checkpoint: Checkpoint): Promise<StorageResult<void>>;
713
+ restoreCheckpoint(name: string): Promise<StorageResult<void>>;
714
+ search(query: string): Promise<StorageResult<SearchResult[]>>;
715
+ private extractSnippet;
716
+ private calculateScore;
717
+ /**
718
+ * Create a snapshot of the current plan state for checkpoints
719
+ */
720
+ createSnapshot(): Promise<CheckpointSnapshot>;
721
+ }
722
+
723
+ /**
724
+ * Step status values
725
+ */
726
+ export declare type StepStatus = 'pending' | 'in_progress' | 'completed' | 'skipped';
727
+
728
+ /**
729
+ * Storage format types for RiotPlan
730
+ *
731
+ * This module defines the core types for the dual-format storage architecture
732
+ * that supports both directory-based and SQLite .plan formats.
733
+ */
734
+ /**
735
+ * Supported storage formats
736
+ */
737
+ export declare type StorageFormat = 'directory' | 'sqlite';
738
+
739
+ /**
740
+ * Options for storage operations
741
+ */
742
+ export declare interface StorageOptions {
743
+ /** Storage format to use */
744
+ format?: StorageFormat;
745
+ /** Create if not exists */
746
+ create?: boolean;
747
+ /** Schema version to use (for migrations) */
748
+ schemaVersion?: number;
749
+ }
750
+
751
+ /**
752
+ * Abstract storage provider interface
753
+ *
754
+ * Both DirectoryStorageProvider and SqliteStorageProvider implement this interface,
755
+ * allowing the plan operations to work with either format transparently.
756
+ */
757
+ export declare interface StorageProvider {
758
+ /**
759
+ * Get the storage format this provider uses
760
+ */
761
+ readonly format: StorageFormat;
762
+ /**
763
+ * Get the path to the plan (directory path or .plan file path)
764
+ */
765
+ readonly path: string;
766
+ /**
767
+ * Check if the plan exists
768
+ */
769
+ exists(): Promise<boolean>;
770
+ /**
771
+ * Initialize a new plan
772
+ */
773
+ initialize(metadata: PlanMetadata): Promise<StorageResult<void>>;
774
+ /**
775
+ * Close the storage (cleanup resources)
776
+ */
777
+ close(): Promise<void>;
778
+ /**
779
+ * Get plan metadata
780
+ */
781
+ getMetadata(): Promise<StorageResult<PlanMetadata>>;
782
+ /**
783
+ * Update plan metadata
784
+ */
785
+ updateMetadata(metadata: Partial<PlanMetadata>): Promise<StorageResult<void>>;
786
+ /**
787
+ * Get all steps
788
+ */
789
+ getSteps(): Promise<StorageResult<PlanStep[]>>;
790
+ /**
791
+ * Get a specific step by number
792
+ */
793
+ getStep(number: number): Promise<StorageResult<PlanStep | null>>;
794
+ /**
795
+ * Add a new step
796
+ */
797
+ addStep(step: PlanStep): Promise<StorageResult<void>>;
798
+ /**
799
+ * Update an existing step
800
+ */
801
+ updateStep(number: number, updates: Partial<PlanStep>): Promise<StorageResult<void>>;
802
+ /**
803
+ * Delete a step
804
+ */
805
+ deleteStep(number: number): Promise<StorageResult<void>>;
806
+ /**
807
+ * Get all files
808
+ */
809
+ getFiles(): Promise<StorageResult<PlanFile[]>>;
810
+ /**
811
+ * Get a specific file by type and filename
812
+ */
813
+ getFile(type: string, filename: string): Promise<StorageResult<PlanFile | null>>;
814
+ /**
815
+ * Save a file
816
+ */
817
+ saveFile(file: PlanFile): Promise<StorageResult<void>>;
818
+ /**
819
+ * Delete a file
820
+ */
821
+ deleteFile(type: string, filename: string): Promise<StorageResult<void>>;
822
+ /**
823
+ * Get timeline events
824
+ */
825
+ getTimelineEvents(options?: {
826
+ since?: string;
827
+ type?: string;
828
+ limit?: number;
829
+ }): Promise<StorageResult<TimelineEvent[]>>;
830
+ /**
831
+ * Add a timeline event
832
+ */
833
+ addTimelineEvent(event: TimelineEvent): Promise<StorageResult<void>>;
834
+ /**
835
+ * Get all evidence records
836
+ */
837
+ getEvidence(): Promise<StorageResult<EvidenceRecord[]>>;
838
+ /**
839
+ * Add an evidence record
840
+ */
841
+ addEvidence(evidence: EvidenceRecord): Promise<StorageResult<void>>;
842
+ /**
843
+ * Get all feedback records
844
+ */
845
+ getFeedback(): Promise<StorageResult<FeedbackRecord[]>>;
846
+ /**
847
+ * Add a feedback record
848
+ */
849
+ addFeedback(feedback: FeedbackRecord): Promise<StorageResult<void>>;
850
+ /**
851
+ * Get all checkpoints
852
+ */
853
+ getCheckpoints(): Promise<StorageResult<Checkpoint[]>>;
854
+ /**
855
+ * Get a specific checkpoint by name
856
+ */
857
+ getCheckpoint(name: string): Promise<StorageResult<Checkpoint | null>>;
858
+ /**
859
+ * Create a checkpoint
860
+ */
861
+ createCheckpoint(checkpoint: Checkpoint): Promise<StorageResult<void>>;
862
+ /**
863
+ * Restore from a checkpoint
864
+ */
865
+ restoreCheckpoint(name: string): Promise<StorageResult<void>>;
866
+ /**
867
+ * Search across all plan content
868
+ */
869
+ search(query: string): Promise<StorageResult<SearchResult[]>>;
870
+ }
871
+
872
+ /**
873
+ * Interface for storage provider factories
874
+ */
875
+ export declare interface StorageProviderFactory {
876
+ /**
877
+ * Create a storage provider for the given path
878
+ */
879
+ createProvider(path: string, options?: unknown): StorageProvider;
880
+ /**
881
+ * Check if this factory supports the given path
882
+ */
883
+ supportsPath(path: string): boolean;
884
+ }
885
+
886
+ /**
887
+ * Factory function type for creating storage providers
888
+ */
889
+ export declare type StorageProviderFactoryFn = (path: string) => Promise<StorageProvider>;
890
+
891
+ /**
892
+ * Result of a storage operation
893
+ */
894
+ export declare interface StorageResult<T> {
895
+ /** Whether the operation succeeded */
896
+ success: boolean;
897
+ /** Result data if successful */
898
+ data?: T;
899
+ /** Error message if failed */
900
+ error?: string;
901
+ }
902
+
903
+ /**
904
+ * Timeline event stored in the database
905
+ */
906
+ export declare interface TimelineEvent {
907
+ /** Event ID */
908
+ id: string;
909
+ /** Event timestamp (ISO 8601) */
910
+ timestamp: string;
911
+ /** Event type */
912
+ type: TimelineEventType;
913
+ /** Event data (JSON) */
914
+ data: Record<string, unknown>;
915
+ }
916
+
917
+ /**
918
+ * Timeline event types
919
+ */
920
+ export declare type TimelineEventType = 'plan_created' | 'stage_transition' | 'step_started' | 'step_completed' | 'note_added' | 'constraint_added' | 'question_added' | 'evidence_added' | 'approach_added' | 'approach_selected' | 'feedback_added' | 'checkpoint_created' | 'narrative_added' | 'reflection_added';
921
+
922
+ /**
923
+ * Validate that a plan path is valid for the given format
924
+ *
925
+ * @param planPath - The plan path
926
+ * @param format - The expected format
927
+ * @param config - Optional format configuration
928
+ * @returns An error message if invalid, or null if valid
929
+ */
930
+ export declare function validatePlanPath(planPath: string, format: StorageFormat, config?: FormatConfig): string | null;
931
+
932
+ /**
933
+ * Validation error during migration
934
+ */
935
+ export declare interface ValidationError {
936
+ /** Type of validation error */
937
+ type: 'missing_step' | 'content_mismatch' | 'metadata_difference' | 'missing_file' | 'missing_event';
938
+ /** Path or identifier of the problematic item */
939
+ path: string;
940
+ /** Expected value */
941
+ expected: unknown;
942
+ /** Actual value */
943
+ actual: unknown;
944
+ /** Human-readable error message */
945
+ message: string;
946
+ }
947
+
948
+ /**
949
+ * Result of migration validation
950
+ */
951
+ export declare interface ValidationResult {
952
+ /** Whether validation passed */
953
+ valid: boolean;
954
+ /** Validation errors */
955
+ errors: ValidationError[];
956
+ /** Warning messages */
957
+ warnings: string[];
958
+ /** Validation statistics */
959
+ stats: {
960
+ stepsCompared: number;
961
+ filesCompared: number;
962
+ timelineEventsCompared: number;
963
+ evidenceCompared: number;
964
+ feedbackCompared: number;
965
+ };
966
+ }
967
+
968
+ /**
969
+ * Package version
970
+ */
971
+ export declare const VERSION = "1.0.0-dev.0";
972
+
973
+ export { }