@bitcobblers/wod-wiki-engine 0.61.2259 → 0.62.2260

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,685 @@
1
+ import { NoteBlock, BlockIndexRow, BlockEffort, BlockEquipment, Session, EventRecord, Note, PublicationVisibilitySummary, NotebookId, NoteUpstreamStatus, ResultOrigin, BlockRevision, Page, NotebookLink, ResolvedNoteOwnership, NoteProvenance, AnalyticsDataPoint, StoredOutputStatement, WorkoutResults, ICodeStatement } from '@bitcobblers/wod-wiki-core';
2
+ import { ReferenceIndex, IEffort, IScript } from '@bitcobblers/wod-wiki-lang';
3
+ import { IStorage } from '@bitcobblers/wod-wiki-storage';
4
+
5
+ /**
6
+ * FeedTree — universal path-addressed byte tree port and runtime-agnostic adapters.
7
+ *
8
+ * Unifies:
9
+ * - MemoryFeedTree: in-memory tests, server snapshot staging, dirty diffs
10
+ * - HttpFeedTree: read-only fetch over GitHub Pages, custom peer URLs, and `wod server /feed/`
11
+ * - DirectoryHandleFeedTree: browser File System Access folder export/import
12
+ */
13
+ type FeedPath = string;
14
+ type FeedTreeErrorCode = 'not-found' | 'unsupported' | 'read-only' | 'checksum' | 'layout' | 'permission';
15
+ declare class FeedTreeError extends Error {
16
+ readonly code: FeedTreeErrorCode;
17
+ constructor(code: FeedTreeErrorCode, message: string);
18
+ }
19
+ interface FeedFileStat {
20
+ bytes: number;
21
+ sha256?: string;
22
+ }
23
+ interface FeedTreeReader {
24
+ read(path: FeedPath): Promise<Uint8Array>;
25
+ readText?(path: FeedPath): Promise<string>;
26
+ stat(path: FeedPath): Promise<FeedFileStat | undefined>;
27
+ list?(prefix?: string): Promise<FeedPath[]>;
28
+ }
29
+ interface FeedTreeWriter {
30
+ write(path: FeedPath, bytes: Uint8Array): Promise<void>;
31
+ delete(path: FeedPath): Promise<void>;
32
+ }
33
+ interface FeedTree extends FeedTreeReader, FeedTreeWriter {
34
+ }
35
+ declare function encodeUtf8(text: string): Uint8Array;
36
+ declare function decodeUtf8(bytes: Uint8Array): string;
37
+ declare function normalizeFeedTreePath(rawPath: string): FeedPath;
38
+ declare function sha256HexAsync(input: Uint8Array | string): Promise<string>;
39
+ declare class MemoryFeedTree implements FeedTree {
40
+ private readonly store;
41
+ constructor(initial?: Readonly<Record<string, string | Uint8Array>>);
42
+ read(path: FeedPath): Promise<Uint8Array>;
43
+ readText(path: FeedPath): Promise<string>;
44
+ stat(path: FeedPath): Promise<FeedFileStat | undefined>;
45
+ write(path: FeedPath, bytes: Uint8Array): Promise<void>;
46
+ writeText(path: FeedPath, text: string): Promise<void>;
47
+ delete(path: FeedPath): Promise<void>;
48
+ list(prefix?: string): Promise<FeedPath[]>;
49
+ entries(): Array<[FeedPath, Uint8Array]>;
50
+ }
51
+ type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
52
+ declare class HttpFeedTree implements FeedTreeReader {
53
+ private readonly baseUrl;
54
+ private readonly fetchImpl;
55
+ constructor(baseUrl: string, fetchImpl?: FetchLike);
56
+ read(path: FeedPath): Promise<Uint8Array>;
57
+ readJson<T = unknown>(path: FeedPath): Promise<T>;
58
+ readText(path: FeedPath): Promise<string>;
59
+ stat(path: FeedPath): Promise<FeedFileStat | undefined>;
60
+ }
61
+ /** Structural subset of the Web File System Access API so non-DOM builds need no ambient DOM types. */
62
+ interface FileSystemWritableLike {
63
+ write(data: Uint8Array): Promise<void>;
64
+ close(): Promise<void>;
65
+ }
66
+ interface FileSystemFileHandleLike {
67
+ readonly kind: 'file';
68
+ readonly name: string;
69
+ getFile(): Promise<{
70
+ arrayBuffer(): Promise<ArrayBuffer>;
71
+ size: number;
72
+ }>;
73
+ createWritable(): Promise<FileSystemWritableLike>;
74
+ }
75
+ interface FileSystemDirectoryHandleLike {
76
+ readonly kind: 'directory';
77
+ readonly name: string;
78
+ getDirectoryHandle(name: string, options?: {
79
+ create?: boolean;
80
+ }): Promise<FileSystemDirectoryHandleLike>;
81
+ getFileHandle(name: string, options?: {
82
+ create?: boolean;
83
+ }): Promise<FileSystemFileHandleLike>;
84
+ removeEntry(name: string, options?: {
85
+ recursive?: boolean;
86
+ }): Promise<void>;
87
+ }
88
+ declare class DirectoryHandleFeedTree implements FeedTree {
89
+ private readonly root;
90
+ constructor(root: FileSystemDirectoryHandleLike);
91
+ private resolveDir;
92
+ read(path: FeedPath): Promise<Uint8Array>;
93
+ stat(path: FeedPath): Promise<FeedFileStat | undefined>;
94
+ write(path: FeedPath, bytes: Uint8Array): Promise<void>;
95
+ delete(path: FeedPath): Promise<void>;
96
+ }
97
+
98
+ declare const SEED_SCHEMA = 9;
99
+ declare const SEED_REGISTERED_WIDGETS: readonly string[];
100
+ declare const SEED_NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341";
101
+ /** Source and all current derived rows commit as one chunk. */
102
+ interface SeedRow {
103
+ path: string;
104
+ content: string;
105
+ blocks: Record<string, NoteBlock>;
106
+ blockIndex: BlockIndexRow[];
107
+ blockEfforts: BlockEffort[];
108
+ blockEquipment: BlockEquipment[];
109
+ telemetry?: {
110
+ sessions: Session[];
111
+ events: EventRecord[];
112
+ };
113
+ commit?: string;
114
+ uuid?: string;
115
+ version?: number;
116
+ }
117
+ type FeedOfflinePolicy = 'index-only' | 'offline-full';
118
+ interface SeedRecordRef {
119
+ uuid: string;
120
+ path: string;
121
+ recordPath?: string;
122
+ /** Optional relative path or http(s) URL to raw portable Markdown (.md). */
123
+ rawUrl?: string;
124
+ commit: string;
125
+ version: number;
126
+ sha256: string;
127
+ title?: string;
128
+ date?: number;
129
+ }
130
+ interface NotebookIndexSummary {
131
+ notebookId: string;
132
+ label: string;
133
+ category?: string;
134
+ description?: string;
135
+ indexPath: string;
136
+ version: number;
137
+ commit: string;
138
+ updatedAt?: string;
139
+ builtAt: string;
140
+ sha256: string;
141
+ bytes: number;
142
+ /** Optional lightweight index size in bytes when distinct from offline bundle bytes. */
143
+ indexBytes?: number;
144
+ /** Optional offline chunk bundle size in bytes. */
145
+ chunkBytes?: number;
146
+ count: number;
147
+ }
148
+ interface NotebookIndex extends NotebookIndexSummary {
149
+ records: SeedRecordRef[];
150
+ }
151
+ type ChunkKind = 'notes';
152
+ interface ManifestChunk {
153
+ id: string;
154
+ path: string;
155
+ sha256: string;
156
+ bytes: number;
157
+ count: number;
158
+ kind?: ChunkKind;
159
+ records?: SeedRecordRef[];
160
+ }
161
+ interface SeedManifest {
162
+ name?: string;
163
+ description?: string;
164
+ repositoryUrl?: string;
165
+ schema: number;
166
+ version: number;
167
+ versionLabel?: string;
168
+ commit?: string;
169
+ dirty?: boolean;
170
+ builtAt: string;
171
+ chunks: ManifestChunk[];
172
+ notebooks?: NotebookIndexSummary[];
173
+ /** Optional total index bytes across notebooks. */
174
+ indexBytes?: number;
175
+ /** Optional total offline chunk bytes across chunks. */
176
+ chunkBytes?: number;
177
+ }
178
+ type SeedPrecedenceTier = 'core' | 'community' | 'imported' | 'user';
179
+ declare function seedSourceTier(sourceIdOrMetaKey?: string | null, explicitTier?: SeedPrecedenceTier): SeedPrecedenceTier;
180
+ declare function seedPrecedenceRank(sourceIdOrMetaKey?: string | null, explicitTier?: SeedPrecedenceTier): number;
181
+ interface SeedMetaRecord {
182
+ key: string;
183
+ schema: number;
184
+ seedVersion: number;
185
+ builtAt: string;
186
+ importedAt: number;
187
+ chunks: Record<string, {
188
+ sha256: string;
189
+ version?: number;
190
+ builtAt?: string;
191
+ importedAt?: number;
192
+ noteIds?: string[];
193
+ }>;
194
+ claim?: {
195
+ owner: string;
196
+ at: number;
197
+ } | null;
198
+ tier?: SeedPrecedenceTier;
199
+ }
200
+ declare const SEED_BROADCAST_CHANNEL = "wodwiki.seed";
201
+ declare const FEED_INDEX_META_PREFIX = "feed:index:";
202
+ declare function feedIndexMetaKey(feedId: string, notebookId: string): string;
203
+ declare const EFFORTS_CHUNK_ID = "efforts";
204
+ declare const EQUIPMENT_CHUNK_ID = "equipment";
205
+ declare const CANVAS_CHUNK_ID = "canvas";
206
+ declare const DASHBOARDS_CHUNK_ID = "dashboards";
207
+ declare function seedMetaKey(sourceId: string): string;
208
+ /**
209
+ * The feed identifier a checkpoint key names — the key's source id. The
210
+ * checkpoint key keeps its seed spelling (`seed:<id>`, a persisted wire
211
+ * format) and the broadcast channel keeps its own, so a feed's checkpoint
212
+ * IS the checkpoint its id writes.
213
+ */
214
+ declare function feedIdOfMetaKey(metaKey: string): string;
215
+ declare function emptySeedMeta(key: string): SeedMetaRecord;
216
+ /** The notebook slug a notebook chunk id names — `notebook.<slug>`; the
217
+ * `_root` landing (a file directly under `markdown/notebooks/`) names no
218
+ * notebook. */
219
+ declare function notebookSlugForChunkId(chunkId: string): string | undefined;
220
+ declare function canvasRouteSlug(content: string): string | null;
221
+ declare function seedNoteSourceId(path: string, content: string, chunkId: string): string | undefined;
222
+
223
+ /**
224
+ * VaultIngestor & PublicationManager — transactional Note/Telemetry ingestion,
225
+ * zero-import remote preview, single-Note cloning, and Publication Visibility
226
+ * controls over IStorage.
227
+ */
228
+
229
+ declare function getNotePublicationSummary(storage: IStorage, noteId: string): Promise<PublicationVisibilitySummary>;
230
+ declare function setNotebookPublic(storage: IStorage, notebookIdOrSlug: string, isPublic: boolean): Promise<Note>;
231
+ declare function setSessionPublic(storage: IStorage, sessionId: string, isPublic: boolean): Promise<Session>;
232
+ interface CompileMarkdownSeedRowInput {
233
+ path: string;
234
+ markdown: string;
235
+ uuid?: string;
236
+ commit?: string;
237
+ version?: number;
238
+ title?: string;
239
+ date?: number;
240
+ sourceId?: string;
241
+ routeId?: string;
242
+ createdAt?: number;
243
+ referenceIndex?: ReferenceIndex;
244
+ }
245
+ /**
246
+ * Compile a raw portable `.md` document into a validated `SeedRow` lazily
247
+ * in-client (headless; zero DOM/React/Node fs dependencies).
248
+ */
249
+ declare function compileSeedRowFromMarkdown(input: CompileMarkdownSeedRowInput): Promise<SeedRow>;
250
+ declare function previewRemoteNotebook(reader: FeedTreeReader, indexPath: string): Promise<NotebookIndex>;
251
+ declare function previewRemoteRecord(reader: FeedTreeReader, recordOrPath: string | SeedRecordRef, options?: {
252
+ fetchImpl?: FetchLike;
253
+ }): Promise<SeedRow>;
254
+ declare function cloneRemoteRecord(storage: IStorage, reader: FeedTreeReader, input: {
255
+ feedId: string;
256
+ record: SeedRecordRef;
257
+ targetNotebookId: string;
258
+ sourceNotebookId?: string;
259
+ includePublicTelemetry?: boolean;
260
+ }): Promise<Note>;
261
+ type RetentionNote = Note & {
262
+ retention?: 'indexed' | 'cached' | 'schedule-pinned' | 'session-pinned';
263
+ upstreamStatus?: 'live' | 'unsubscribed' | 'removed';
264
+ };
265
+ /**
266
+ * Persist an on-demand fetched/compiled remote workout under its canonical
267
+ * UUID with `retention: 'cached'` and `upstreamStatus: 'live'`.
268
+ * Never overwrites user-authored notes or `session-pinned` local copies.
269
+ */
270
+ declare function materializeCachedRemoteRecord(storage: IStorage, input: {
271
+ feedId?: string;
272
+ notebookId?: string;
273
+ notebookSlug?: string;
274
+ record?: SeedRecordRef;
275
+ seedRow: SeedRow;
276
+ retention?: 'cached' | 'schedule-pinned' | 'session-pinned';
277
+ upstreamStatus?: 'live' | 'unsubscribed' | 'removed';
278
+ }): Promise<RetentionNote>;
279
+ interface PortableFileEntry {
280
+ path: string;
281
+ content?: string;
282
+ bytes?: Uint8Array;
283
+ }
284
+ interface PortabilityImportReport {
285
+ notesImported: number;
286
+ revisionsImported: number;
287
+ sessionsImported: number;
288
+ eventsImported: number;
289
+ errors: string[];
290
+ }
291
+ declare function exportPortableFilesFromStorage(storage: IStorage, options?: {
292
+ noteIds?: readonly string[];
293
+ telemetryFormat?: 'jsonl' | 'csv' | 'both';
294
+ }): Promise<PortableFileEntry[]>;
295
+ declare function ingestPortableFilesIntoStorage(storage: IStorage, files: readonly PortableFileEntry[], options?: {
296
+ defaultNotebookId?: string;
297
+ now?: number;
298
+ }): Promise<PortabilityImportReport>;
299
+
300
+ declare const FEED_SUBSCRIPTIONS_META_KEY = "feed:subscriptions";
301
+ declare const FEED_REGISTRY_META_KEY = "feed:registry";
302
+ interface FeedSubscriptionEntry {
303
+ subscribed: boolean;
304
+ notebookIds?: string[] | null;
305
+ offlinePolicy?: FeedOfflinePolicy;
306
+ autoSync?: boolean;
307
+ checkedAt?: number | null;
308
+ hidden?: boolean;
309
+ url?: string;
310
+ name?: string;
311
+ updatedAt: number;
312
+ }
313
+ interface FeedSubscriptionsMetaRecord {
314
+ key: typeof FEED_SUBSCRIPTIONS_META_KEY;
315
+ entries: Record<string, FeedSubscriptionEntry>;
316
+ migratedFromLocalStorage?: boolean;
317
+ }
318
+ interface RegisteredCustomFeedEntry {
319
+ id: string;
320
+ label: string;
321
+ url: string;
322
+ repositoryUrl?: string;
323
+ addedAt?: number;
324
+ }
325
+ interface FeedRegistryMetaRecord {
326
+ key: typeof FEED_REGISTRY_META_KEY;
327
+ customFeeds: RegisteredCustomFeedEntry[];
328
+ hiddenFeedIds: string[];
329
+ updatedAt: number;
330
+ migratedFromLocalStorage?: boolean;
331
+ }
332
+ interface RemoveSeedSourceResult {
333
+ deleted: number;
334
+ preservedPinned: number;
335
+ }
336
+ /**
337
+ * Remove one seed/feed source's imported notes, tags, index rows, bundled
338
+ * definitions (falling back to the next highest-precedence checkpoint),
339
+ * property overrides, and checkpoint record. User-authored notes and
340
+ * pinned feed notes (`retention` `'session-pinned'` or `'schedule-pinned'`,
341
+ * or attached `sessions` / `schedule_items` rows) are never deleted.
342
+ */
343
+ declare function removeSeedSourceContent(storage: IStorage, meta: SeedMetaRecord): Promise<RemoveSeedSourceResult>;
344
+ declare function removeFeedSourceContentById(storage: IStorage, sourceId: string): Promise<RemoveSeedSourceResult>;
345
+ /**
346
+ * Remove one notebook's cached notes and cached index from `storage` for a feed,
347
+ * preserving any `session-pinned` or `sessions`-attached notes and stamping them
348
+ * `upstreamStatus: 'unsubscribed'`.
349
+ */
350
+ declare function removeFeedNotebookContent(storage: IStorage, feedId: string, chunkId: string): Promise<RemoveSeedSourceResult>;
351
+ /**
352
+ * Reconcile locally cached notes for an index-only feed notebook when the
353
+ * upstream index changes: removes disappeared unpinned cached notes and stamps
354
+ * any `session-pinned` / `sessions`-attached copies with `upstreamStatus: 'removed'`.
355
+ */
356
+ declare function reconcileRemovedFeedRecords(storage: IStorage, feedId: string, notebookId: string, liveUuids: ReadonlySet<string>): Promise<RemoveSeedSourceResult>;
357
+ declare function readFeedRegistryHeadless(storage: IStorage): Promise<FeedRegistryMetaRecord>;
358
+ declare function writeFeedRegistryHeadless(storage: IStorage, next: Omit<FeedRegistryMetaRecord, 'key'>): Promise<FeedRegistryMetaRecord>;
359
+ declare function listFeedSubscriptionsHeadless(storage: IStorage): Promise<Record<string, FeedSubscriptionEntry>>;
360
+ declare function subscribeFeedSourceHeadless(storage: IStorage, sourceId: string, options?: {
361
+ notebookIds?: string[];
362
+ offlinePolicy?: FeedOfflinePolicy;
363
+ autoSync?: boolean;
364
+ url?: string;
365
+ name?: string;
366
+ }): Promise<{
367
+ sourceId: string;
368
+ subscribed: true;
369
+ notebookIds: string[] | null;
370
+ offlinePolicy: FeedOfflinePolicy;
371
+ }>;
372
+ declare function unsubscribeFeedSourceHeadless(storage: IStorage, sourceId: string): Promise<{
373
+ sourceId: string;
374
+ unsubscribed: true;
375
+ deletedNotes: number;
376
+ deleted: number;
377
+ preservedPinned: number;
378
+ }>;
379
+ declare function deleteFeedSourceHeadless(storage: IStorage, sourceId: string): Promise<{
380
+ sourceId: string;
381
+ deleted: true;
382
+ deletedNotes: number;
383
+ preservedPinned: number;
384
+ }>;
385
+
386
+ /**
387
+ * NotebookLifecycle — Atomic lifecycle operations for user-owned Notebooks
388
+ * shared across Playground `NotebookService` and MCP/CLI `wod_notebook_*` tools.
389
+ */
390
+
391
+ interface DeleteNotebookResult {
392
+ deleted: boolean;
393
+ notebookId: NotebookId;
394
+ slug: string;
395
+ }
396
+ /**
397
+ * Atomically delete a user-created Notebook landing note, its `notebook_links`,
398
+ * and any membership references on member Notes while keeping member Notes intact.
399
+ * Built-in/always-present notebooks are rejected before opening a transaction.
400
+ */
401
+ declare function deleteUserNotebook(storage: IStorage, notebookIdOrSlug: string): Promise<DeleteNotebookResult>;
402
+
403
+ /**
404
+ * SessionIntake — Deep module owning external-workout archival pinning,
405
+ * atomic Session pinning & Journal linking, explicit Fork-to-User-Notebook,
406
+ * and upstream Note provenance resolution.
407
+ *
408
+ * When a workout is run or logged on ANY non-owned Note (`feed`, `system`,
409
+ * `feed-archived`, or `remote:<feedId>:<uuid>`):
410
+ * 1. Ensures ONE immutable local archival copy exists under the canonical
411
+ * workout ID (`retention: 'session-pinned'`, `BlockRevision`s,
412
+ * `block_index`, and structured `NoteProvenance`), never spawning a new
413
+ * duplicate Journal Note on every run.
414
+ * 2. Pins the `Session` (`session.noteId = canonicalWorkoutNoteId`,
415
+ * `blockId`, `blockVersion`, `blockContentId`, `pageId` for the Journal
416
+ * calendar `Page`, `notebookIds: ['notebook/journal']`) directly to that
417
+ * single local copy so all repeated attempts aggregate on the workout's
418
+ * own page while appearing in Journal / Calendar / Sessions views via
419
+ * `session.pageId` and `notebook_links` (`targetKind: 'session'`).
420
+ * 3. Preserves the WW-052 invariant: `prepareJournalSessionRun` never
421
+ * persists a 0s phantom `Session` before the run commits.
422
+ *
423
+ * Explicit editing/ownership copies use `forkNoteToUserNotebook`, which
424
+ * creates a real editable `seedOrigin: 'user'` Note in a writable user
425
+ * Notebook with full `NoteProvenance`, `notebook_links`, and `block_revisions`.
426
+ */
427
+
428
+ interface ParsedRemoteNoteId {
429
+ isRemote: true;
430
+ feedId: string;
431
+ uuid: string;
432
+ }
433
+ declare function parseRemoteNoteId(noteId: string): ParsedRemoteNoteId | {
434
+ isRemote: false;
435
+ };
436
+ interface RemoteSeedRowLike {
437
+ path: string;
438
+ content: string;
439
+ blocks: Record<string, NoteBlock>;
440
+ blockIndex?: BlockIndexRow[];
441
+ blockEfforts?: BlockEffort[];
442
+ blockEquipment?: BlockEquipment[];
443
+ commit?: string;
444
+ uuid?: string;
445
+ version?: number;
446
+ }
447
+ interface ExternalWorkoutPayload {
448
+ id?: string;
449
+ title?: string;
450
+ rawContent: string;
451
+ blocks?: Record<string, NoteBlock>;
452
+ date?: number;
453
+ createdAt?: number;
454
+ tags?: string[];
455
+ type?: Note['type'];
456
+ sourceId?: string;
457
+ sourcePath?: string;
458
+ seedOrigin?: 'seed' | 'user';
459
+ seedVersion?: number;
460
+ seedChunkId?: string;
461
+ seedCommit?: string;
462
+ feedOrigin?: 'feed' | 'user';
463
+ feedSourceId?: string;
464
+ sourceNotebookId?: string;
465
+ upstreamStatus?: NoteUpstreamStatus;
466
+ seedRow?: RemoteSeedRowLike;
467
+ }
468
+ interface ResolvedRemoteWorkoutEnvelope {
469
+ note?: Note;
470
+ row?: RemoteSeedRowLike;
471
+ canonicalNoteId?: string;
472
+ remoteNoteId?: string;
473
+ feedId?: string;
474
+ notebookSlug?: string;
475
+ record?: {
476
+ uuid?: string;
477
+ path?: string;
478
+ commit?: string;
479
+ version?: number;
480
+ title?: string;
481
+ date?: number;
482
+ };
483
+ }
484
+ type RemoteWorkoutResolution = ExternalWorkoutPayload | Note | RemoteSeedRowLike | ResolvedRemoteWorkoutEnvelope;
485
+ interface EnsurePinnedExternalWorkoutInput {
486
+ noteId: string;
487
+ retention?: 'schedule-pinned' | 'session-pinned';
488
+ remotePayload?: RemoteWorkoutResolution;
489
+ resolveRemoteWorkout?: (noteId: string) => Promise<RemoteWorkoutResolution | undefined>;
490
+ now?: number;
491
+ }
492
+ interface PinnedExternalWorkoutResult {
493
+ note: Note;
494
+ created: boolean;
495
+ promotedFromLocal: boolean;
496
+ ownership: ResolvedNoteOwnership;
497
+ }
498
+ interface PrepareJournalSessionRunInput {
499
+ noteId: string;
500
+ blockId?: string;
501
+ blockContentId?: string;
502
+ sessionId?: string;
503
+ journalDate?: string;
504
+ scheduleItemId?: string;
505
+ startedAt?: number;
506
+ origin?: ResultOrigin;
507
+ remotePayload?: RemoteWorkoutResolution;
508
+ resolveRemoteWorkout?: (noteId: string) => Promise<RemoteWorkoutResolution | undefined>;
509
+ }
510
+ interface PreparedJournalSessionRun {
511
+ note: Note;
512
+ revision: BlockRevision;
513
+ session: Session;
514
+ /** Always false under single-archival-copy semantics (kept for backward shape compatibility). */
515
+ clonedFromReadOnly: boolean;
516
+ /** True when the Session is pinned to an external (feed/system/remote) canonical archival Note. */
517
+ pinnedExternalWorkout: boolean;
518
+ upstreamNoteId?: string;
519
+ }
520
+ interface LogSessionAgainstExternalWorkoutInput {
521
+ noteId: string;
522
+ blockId?: string;
523
+ blockContentId?: string;
524
+ sessionId?: string;
525
+ journalDate?: string;
526
+ scheduleItemId?: string;
527
+ startedAt?: number;
528
+ endedAt?: number;
529
+ durationMs?: number;
530
+ completed?: boolean;
531
+ roundsCompleted?: number;
532
+ totalRounds?: number;
533
+ repsCompleted?: number;
534
+ origin?: ResultOrigin;
535
+ public?: boolean;
536
+ events?: EventRecord[];
537
+ remotePayload?: RemoteWorkoutResolution;
538
+ resolveRemoteWorkout?: (noteId: string) => Promise<RemoteWorkoutResolution | undefined>;
539
+ }
540
+ interface LoggedExternalWorkoutSession {
541
+ note: Note;
542
+ revision: BlockRevision;
543
+ session: Session;
544
+ page: Page;
545
+ links: NotebookLink[];
546
+ events: EventRecord[];
547
+ pinnedResult: PinnedExternalWorkoutResult;
548
+ }
549
+ interface ForkNoteOptions {
550
+ title?: string;
551
+ journalDate?: string;
552
+ now?: number;
553
+ remotePayload?: RemoteWorkoutResolution;
554
+ resolveRemoteWorkout?: (noteId: string) => Promise<RemoteWorkoutResolution | undefined>;
555
+ }
556
+ interface ResolvedUpstreamProvenance {
557
+ exists: boolean;
558
+ sourceNoteId: string;
559
+ title?: string;
560
+ sourceVersion?: number;
561
+ currentUpstreamVersion?: number;
562
+ sourceCommit?: string;
563
+ feedSourceId?: string;
564
+ sourceNotebookId?: string;
565
+ sourcePath?: string;
566
+ upstreamStatus?: NoteUpstreamStatus;
567
+ }
568
+ /**
569
+ * Ensure ONE immutable local archival copy exists for an external (`feed`,
570
+ * `system`, or `remote:<feedId>:<uuid>`) workout in `notes` with
571
+ * `retention: 'session-pinned'`.
572
+ *
573
+ * - If already present locally (subscribed feed, system note, or cached remote
574
+ * workout), promotes it in place without creating a duplicate Note.
575
+ * - If only remote, resolves via `remotePayload` / `resolveRemoteWorkout` and
576
+ * materializes the single canonical archival copy under its canonical UUID.
577
+ * - If the Note is already user-owned (`kind === 'user'`), returns it unchanged.
578
+ */
579
+ declare function ensurePinnedExternalWorkout(storage: IStorage, input: EnsurePinnedExternalWorkoutInput): Promise<PinnedExternalWorkoutResult>;
580
+ /**
581
+ * Prepare a Session run against either a user-owned Note or an external
582
+ * (`feed` / `system` / `remote:*`) Note.
583
+ *
584
+ * - For external workouts: pins ONE immutable archival local copy under its
585
+ * canonical workout ID (`retention: 'session-pinned'`), prepares a `Session`
586
+ * referencing that canonical ID + today's Journal calendar `Page` (`pageId`) +
587
+ * `notebookIds: ['notebook/journal']`, and does NOT persist a 0s phantom
588
+ * `Session` row (WW-052).
589
+ * - For user-owned workouts: anchors in `notebook/journal` (and
590
+ * `notebook/playground` when applicable) and prepares the in-memory `Session`.
591
+ */
592
+ declare function prepareJournalSessionRun(storage: IStorage, input: PrepareJournalSessionRunInput): Promise<PreparedJournalSessionRun>;
593
+ /**
594
+ * Atomically ensure the single canonical external archival copy (`retention: 'session-pinned'`),
595
+ * commit a completed `Session` directly against `canonicalNote.id` + `pageId`,
596
+ * link `notebook/journal` (`targetKind: 'session'`), and persist optional `EventRecord`s.
597
+ */
598
+ declare function logSessionAgainstExternalWorkout(storage: IStorage, input: LogSessionAgainstExternalWorkoutInput): Promise<LoggedExternalWorkoutSession>;
599
+ /**
600
+ * Explicit "Fork to My Notes": creates a new editable `seedOrigin: 'user'` copy
601
+ * of any Note (local or resolved remote) in a writable user Notebook with full
602
+ * `NoteProvenance`, `notebook_links`, and `block_revisions`.
603
+ *
604
+ * Rejects system read-only notebooks (`isSystemReadOnlyNotebook(targetNotebookId)`)
605
+ * and feed-delivered target notebooks.
606
+ */
607
+ declare function forkNoteToUserNotebook(storage: IStorage, sourceNoteId: string, targetNotebookId: string, options?: ForkNoteOptions): Promise<Note>;
608
+ /**
609
+ * Resolve a Note's upstream provenance against current storage.
610
+ *
611
+ * - For user forks (`provenance.sourceNoteId !== note.id`): checks whether the
612
+ * upstream Note still exists and has not been unsubscribed/removed.
613
+ * - For single local archival copies (`retention: 'session-pinned'` where
614
+ * `provenance.sourceNoteId === note.id`): reports `exists: true` while
615
+ * `upstreamStatus` is `'live'` (or unset) and `exists: false` once
616
+ * `upstreamStatus` is `'unsubscribed'` or `'removed'`.
617
+ */
618
+ declare function resolveUpstreamProvenance(storage: IStorage, note: Pick<Note, 'provenance' | 'sourceId' | 'upstreamStatus' | 'retention' | 'seedOrigin' | 'feedOrigin' | 'seedVersion' | 'sourceRevision' | 'seedCommit' | 'feedSourceId' | 'sourcePath'> & {
619
+ id?: string;
620
+ }): Promise<ResolvedUpstreamProvenance | null>;
621
+ declare function buildNoteProvenance(sourceNote: Pick<Note, 'id' | 'seedVersion' | 'sourceRevision' | 'seedCommit' | 'feedSourceId' | 'sourcePath'>, sourceNotebookId: string | undefined, clonedAt: number): NoteProvenance;
622
+
623
+ /**
624
+ * Pure JSON Intermediate Representation (IR) Schemas & Envelope
625
+ *
626
+ * Implements wayfinder #955 and research asset `docs/research/json-ir-schemas-2026-08-17.md`.
627
+ * Freezes the existing result vocabulary (QueryResult, RowsQueryResult, FindQueryResult,
628
+ * StoredOutputStatement, AnalyticsDataPoint, WorkoutResult, StatementNode) in a
629
+ * versioned envelope safe for JSON round-trips.
630
+ */
631
+
632
+ type IrKind = 'fact-set' | 'result-set' | 'note-set' | 'corpus' | 'query-result' | 'find-result' | 'rows-result' | 'pipeline-result' | 'parse-tree' | 'execution-log';
633
+ /**
634
+ * Universal JSON envelope for all headless IR fixtures and output artifacts.
635
+ */
636
+ interface WodWikiIRFile<T> {
637
+ $schema: 'https://wod-wiki.dev/ir/v1.json';
638
+ kind: IrKind;
639
+ generatedAt: number;
640
+ source: string;
641
+ data: T;
642
+ }
643
+ declare function createIRFile<T>(kind: IrKind, data: T, optionsOrSource?: string | {
644
+ source?: string;
645
+ generatedAt?: number;
646
+ }, generatedAt?: number): WodWikiIRFile<T>;
647
+ declare function isIRFile<T = unknown>(obj: unknown): obj is WodWikiIRFile<T>;
648
+ interface MetricNode {
649
+ type: string;
650
+ image?: string;
651
+ value?: unknown;
652
+ origin?: string;
653
+ }
654
+ interface StatementNode {
655
+ id: number;
656
+ type: 'statement' | 'duration' | 'rounds' | 'rest' | 'segment' | 'root';
657
+ raw: string;
658
+ from: number;
659
+ to: number;
660
+ metrics: MetricNode[];
661
+ hints?: string[];
662
+ children?: StatementNode[];
663
+ }
664
+ declare function statementToNode(stmt: ICodeStatement, idMap: Map<number, ICodeStatement>): StatementNode;
665
+ /** Builds a StatementNode tree from a parsed WhiteboardScript. */
666
+ declare function buildStatementTree(script: IScript): StatementNode;
667
+ interface ExecutionLog {
668
+ results: WorkoutResults;
669
+ logs: StoredOutputStatement[];
670
+ statements?: StoredOutputStatement[];
671
+ blockKey?: string;
672
+ sourceScript?: string;
673
+ }
674
+ interface CorpusIRData {
675
+ notes?: Note[];
676
+ revisions?: BlockRevision[];
677
+ blocks?: BlockIndexRow[];
678
+ results?: Session[];
679
+ facts?: AnalyticsDataPoint[];
680
+ efforts?: IEffort[];
681
+ logs?: StoredOutputStatement[];
682
+ tags?: Record<string, string[]>;
683
+ }
684
+
685
+ export { type RemoteSeedRowLike as $, type FetchLike as A, type FileSystemDirectoryHandleLike as B, CANVAS_CHUNK_ID as C, type DeleteNotebookResult as D, EFFORTS_CHUNK_ID as E, type FeedTree as F, type FileSystemFileHandleLike as G, type FileSystemWritableLike as H, type ForkNoteOptions as I, HttpFeedTree as J, type IrKind as K, type LogSessionAgainstExternalWorkoutInput as L, type LoggedExternalWorkoutSession as M, type NotebookIndex as N, type ManifestChunk as O, type PortableFileEntry as P, MemoryFeedTree as Q, type ResolvedUpstreamProvenance as R, type StatementNode as S, type MetricNode as T, type NotebookIndexSummary as U, type ParsedRemoteNoteId as V, type PinnedExternalWorkoutResult as W, type PortabilityImportReport as X, type PrepareJournalSessionRunInput as Y, type PreparedJournalSessionRun as Z, type RegisteredCustomFeedEntry as _, type FeedSubscriptionEntry as a, type RemoveSeedSourceResult as a0, type ResolvedRemoteWorkoutEnvelope as a1, SEED_BROADCAST_CHANNEL as a2, SEED_NAMESPACE as a3, SEED_REGISTERED_WIDGETS as a4, SEED_SCHEMA as a5, type SeedRecordRef as a6, type WodWikiIRFile as a7, buildNoteProvenance as a8, buildStatementTree as a9, readFeedRegistryHeadless as aA, reconcileRemovedFeedRecords as aB, removeFeedNotebookContent as aC, removeFeedSourceContentById as aD, removeSeedSourceContent as aE, resolveUpstreamProvenance as aF, seedMetaKey as aG, seedNoteSourceId as aH, seedPrecedenceRank as aI, seedSourceTier as aJ, setNotebookPublic as aK, setSessionPublic as aL, sha256HexAsync as aM, statementToNode as aN, subscribeFeedSourceHeadless as aO, unsubscribeFeedSourceHeadless as aP, writeFeedRegistryHeadless as aQ, canvasRouteSlug as aa, cloneRemoteRecord as ab, compileSeedRowFromMarkdown as ac, createIRFile as ad, decodeUtf8 as ae, deleteFeedSourceHeadless as af, deleteUserNotebook as ag, emptySeedMeta as ah, encodeUtf8 as ai, ensurePinnedExternalWorkout as aj, exportPortableFilesFromStorage as ak, feedIdOfMetaKey as al, feedIndexMetaKey as am, forkNoteToUserNotebook as an, getNotePublicationSummary as ao, ingestPortableFilesIntoStorage as ap, isIRFile as aq, listFeedSubscriptionsHeadless as ar, logSessionAgainstExternalWorkout as as, materializeCachedRemoteRecord as at, normalizeFeedTreePath as au, notebookSlugForChunkId as av, parseRemoteNoteId as aw, prepareJournalSessionRun as ax, previewRemoteNotebook as ay, previewRemoteRecord as az, type FeedOfflinePolicy as b, type SeedRow as c, type SeedManifest as d, type SeedMetaRecord as e, type FeedTreeReader as f, type RemoteWorkoutResolution as g, type ChunkKind as h, type CompileMarkdownSeedRowInput as i, type CorpusIRData as j, DASHBOARDS_CHUNK_ID as k, DirectoryHandleFeedTree as l, EQUIPMENT_CHUNK_ID as m, type EnsurePinnedExternalWorkoutInput as n, type ExecutionLog as o, type ExternalWorkoutPayload as p, FEED_INDEX_META_PREFIX as q, FEED_REGISTRY_META_KEY as r, FEED_SUBSCRIPTIONS_META_KEY as s, type FeedFileStat as t, type FeedPath as u, type FeedRegistryMetaRecord as v, type FeedSubscriptionsMetaRecord as w, FeedTreeError as x, type FeedTreeErrorCode as y, type FeedTreeWriter as z };