@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.
package/README.md ADDED
@@ -0,0 +1,221 @@
1
+ # @kjerneverk/riotplan-format
2
+
3
+ SQLite-based storage format for RiotPlan with dual format support.
4
+
5
+ This package provides a storage abstraction layer that supports both directory-based and SQLite `.plan` formats for RiotPlan plans.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @kjerneverk/riotplan-format
11
+ ```
12
+
13
+ ## Features
14
+
15
+ - **Dual Format Support**: Store plans as directories (traditional) or SQLite files (portable)
16
+ - **Storage Abstraction**: Unified `StorageProvider` interface for both formats
17
+ - **Format Detection**: Automatic detection of plan format from path
18
+ - **Migration Utilities**: Convert plans between formats with validation
19
+ - **Markdown Rendering**: Export plans to markdown format
20
+ - **Type-Safe**: Full TypeScript support with comprehensive types
21
+
22
+ ## Usage
23
+
24
+ ### Creating a SQLite Plan
25
+
26
+ ```typescript
27
+ import { SqliteStorageProvider } from '@kjerneverk/riotplan-format';
28
+
29
+ const provider = new SqliteStorageProvider('./my-plan.plan');
30
+
31
+ await provider.initialize({
32
+ id: 'my-plan',
33
+ name: 'My Plan',
34
+ description: 'A sample plan',
35
+ stage: 'idea',
36
+ createdAt: new Date().toISOString(),
37
+ updatedAt: new Date().toISOString(),
38
+ schemaVersion: 1,
39
+ });
40
+
41
+ // Add a step
42
+ await provider.addStep({
43
+ number: 1,
44
+ code: 'step-1',
45
+ title: 'First Step',
46
+ status: 'pending',
47
+ content: '# First Step\n\nDescription here.',
48
+ });
49
+
50
+ // Close when done
51
+ await provider.close();
52
+ ```
53
+
54
+ ### Using the Storage Factory
55
+
56
+ ```typescript
57
+ import { createStorageFactory, createProvider } from '@kjerneverk/riotplan-format';
58
+
59
+ // Create a factory with custom config
60
+ const factory = createStorageFactory({
61
+ defaultFormat: 'sqlite',
62
+ sqlite: {
63
+ extension: '.plan',
64
+ walMode: true,
65
+ },
66
+ });
67
+
68
+ // Create a provider based on path
69
+ const provider = factory.createProvider('./my-plan.plan');
70
+
71
+ // Or use the convenience function
72
+ const provider2 = createProvider('./another.plan', { format: 'sqlite' });
73
+ ```
74
+
75
+ ### Format Detection
76
+
77
+ ```typescript
78
+ import { detectPlanFormat, inferFormatFromPath } from '@kjerneverk/riotplan-format';
79
+
80
+ // Detect format of existing plan
81
+ const format = detectPlanFormat('./my-plan'); // 'directory' | 'sqlite' | 'unknown'
82
+
83
+ // Infer format from path
84
+ const inferred = inferFormatFromPath('./my-plan.plan'); // 'sqlite'
85
+ ```
86
+
87
+ ### Migration Between Formats
88
+
89
+ ```typescript
90
+ import { PlanMigrator, MigrationValidator } from '@kjerneverk/riotplan-format';
91
+
92
+ const migrator = new PlanMigrator();
93
+
94
+ // Migrate from source to target
95
+ const result = await migrator.migrate(
96
+ sourcePath,
97
+ targetPath,
98
+ sourceProvider,
99
+ targetProvider,
100
+ {
101
+ keepSource: true,
102
+ validate: true,
103
+ onProgress: (progress) => {
104
+ console.log(`${progress.phase}: ${progress.percentage}%`);
105
+ },
106
+ }
107
+ );
108
+
109
+ if (result.success) {
110
+ console.log(`Migrated ${result.stats.stepsConverted} steps`);
111
+ }
112
+
113
+ // Validate migration
114
+ const validator = new MigrationValidator();
115
+ const validation = await validator.validate(sourceProvider, targetProvider);
116
+ ```
117
+
118
+ ### Rendering to Markdown
119
+
120
+ ```typescript
121
+ import { renderPlanToMarkdown } from '@kjerneverk/riotplan-format';
122
+
123
+ const rendered = await renderPlanToMarkdown(provider, {
124
+ includeEvidence: true,
125
+ includeFeedback: true,
126
+ includeSourceInfo: true,
127
+ });
128
+
129
+ // rendered.files: Map<string, string> - SUMMARY.md, STATUS.md, etc.
130
+ // rendered.steps: Map<string, string> - 01-step.md, 02-step.md, etc.
131
+ // rendered.evidence: Map<string, string> - evidence files
132
+ // rendered.feedback: Map<string, string> - feedback files
133
+ ```
134
+
135
+ ## API Reference
136
+
137
+ ### Types
138
+
139
+ - `PlanMetadata` - Plan metadata (id, name, stage, timestamps)
140
+ - `PlanStep` - Step definition (number, title, status, content)
141
+ - `PlanFile` - File content (type, filename, content)
142
+ - `TimelineEvent` - Timeline event (type, timestamp, data)
143
+ - `EvidenceRecord` - Evidence record (description, source, content)
144
+ - `FeedbackRecord` - Feedback record (title, content, participants)
145
+ - `Checkpoint` - Checkpoint for state snapshots
146
+ - `StorageFormat` - `'directory' | 'sqlite'`
147
+
148
+ ### Storage Providers
149
+
150
+ - `StorageProvider` - Interface for storage operations
151
+ - `SqliteStorageProvider` - SQLite implementation
152
+ - `DirectoryStorageProvider` - Directory implementation (skeleton)
153
+
154
+ ### Configuration
155
+
156
+ - `FormatConfig` - Format selection configuration
157
+ - `SqliteConfig` - SQLite-specific options
158
+ - `DirectoryConfig` - Directory-specific options
159
+ - `mergeFormatConfig()` - Merge user config with defaults
160
+
161
+ ### Utilities
162
+
163
+ - `detectPlanFormat()` - Detect format of existing plan
164
+ - `inferFormatFromPath()` - Infer format from path
165
+ - `validatePlanPath()` - Validate path for format
166
+ - `ensureFormatExtension()` - Add correct extension
167
+
168
+ ### Migration
169
+
170
+ - `PlanMigrator` - Migrate plans between formats
171
+ - `MigrationValidator` - Validate migration fidelity
172
+ - `generateTargetPath()` - Generate target path for migration
173
+ - `inferTargetFormat()` - Infer opposite format
174
+
175
+ ### Rendering
176
+
177
+ - `renderPlanToMarkdown()` - Render plan to markdown files
178
+
179
+ ## Directory Format Structure
180
+
181
+ ```
182
+ my-plan/
183
+ ├── SUMMARY.md # Plan overview
184
+ ├── STATUS.md # Current status and progress
185
+ ├── IDEA.md # Original idea (optional)
186
+ ├── SHAPING.md # Shaping notes (optional)
187
+ ├── EXECUTION_PLAN.md # Execution strategy (optional)
188
+ ├── plan/
189
+ │ ├── 01-step-one.md
190
+ │ ├── 02-step-two.md
191
+ │ └── ...
192
+ ├── evidence/
193
+ │ └── *.md
194
+ ├── feedback/
195
+ │ └── *.md
196
+ ├── reflections/
197
+ │ └── *.md
198
+ └── .history/
199
+ ├── timeline.json
200
+ └── checkpoints/
201
+ └── *.json
202
+ ```
203
+
204
+ ## SQLite Schema
205
+
206
+ The SQLite format uses a normalized schema with tables for:
207
+
208
+ - `plans` - Plan metadata
209
+ - `plan_steps` - Step definitions
210
+ - `plan_files` - File contents
211
+ - `timeline_events` - Timeline events
212
+ - `evidence_records` - Evidence records
213
+ - `feedback_records` - Feedback records
214
+ - `checkpoints` - State snapshots
215
+ - `step_reflections` - Step reflections
216
+
217
+ Schema version tracking enables future migrations.
218
+
219
+ ## License
220
+
221
+ MIT