@bendyline/docblocks 1.1.2 → 2.1.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.
Files changed (149) hide show
  1. package/README.md +76 -11
  2. package/dist/chunk-6IYMTYMQ.js +1692 -0
  3. package/dist/chunk-6IYMTYMQ.js.map +1 -0
  4. package/dist/chunk-AEHCVWU5.js +25 -0
  5. package/dist/chunk-AEHCVWU5.js.map +1 -0
  6. package/dist/chunk-B56KWCSE.js +802 -0
  7. package/dist/chunk-B56KWCSE.js.map +1 -0
  8. package/dist/{chunk-ME76RUMR.js → chunk-BNKV7MTO.js} +15 -1
  9. package/dist/chunk-BNKV7MTO.js.map +1 -0
  10. package/dist/chunk-BXMF5YQJ.js +149 -0
  11. package/dist/chunk-BXMF5YQJ.js.map +1 -0
  12. package/dist/chunk-COYQXQK3.js +1071 -0
  13. package/dist/chunk-COYQXQK3.js.map +1 -0
  14. package/dist/chunk-DN7A33LL.js +780 -0
  15. package/dist/chunk-DN7A33LL.js.map +1 -0
  16. package/dist/chunk-EZKJZUNJ.js +13 -0
  17. package/dist/chunk-EZKJZUNJ.js.map +1 -0
  18. package/dist/chunk-FA7UNOXK.js +20 -0
  19. package/dist/chunk-FA7UNOXK.js.map +1 -0
  20. package/dist/chunk-FNW556FN.js +75 -0
  21. package/dist/chunk-FNW556FN.js.map +1 -0
  22. package/dist/chunk-GM5YXU4L.js +29 -0
  23. package/dist/chunk-GM5YXU4L.js.map +1 -0
  24. package/dist/chunk-JS6XFWQK.js +225 -0
  25. package/dist/chunk-JS6XFWQK.js.map +1 -0
  26. package/dist/chunk-MNSZ7EZN.js +111 -0
  27. package/dist/chunk-MNSZ7EZN.js.map +1 -0
  28. package/dist/chunk-P3DVZQ6S.js +228 -0
  29. package/dist/chunk-P3DVZQ6S.js.map +1 -0
  30. package/dist/chunk-P4WATND4.js +52 -0
  31. package/dist/chunk-P4WATND4.js.map +1 -0
  32. package/dist/chunk-RVPGQBWR.js +169 -0
  33. package/dist/chunk-RVPGQBWR.js.map +1 -0
  34. package/dist/chunk-U722UUFN.js +9 -0
  35. package/dist/chunk-U722UUFN.js.map +1 -0
  36. package/dist/chunk-VTCSF7VS.js +553 -0
  37. package/dist/chunk-VTCSF7VS.js.map +1 -0
  38. package/dist/chunk-WJKYY5QR.js +1350 -0
  39. package/dist/chunk-WJKYY5QR.js.map +1 -0
  40. package/dist/chunk-XUML3MKV.js +945 -0
  41. package/dist/chunk-XUML3MKV.js.map +1 -0
  42. package/dist/document/index.d.ts +358 -0
  43. package/dist/document/index.js +25 -0
  44. package/dist/document/index.js.map +1 -0
  45. package/dist/filesystem/electron.d.ts +73 -0
  46. package/dist/filesystem/electron.js +17 -0
  47. package/dist/filesystem/electron.js.map +1 -0
  48. package/dist/filesystem/index.d.ts +228 -8
  49. package/dist/filesystem/index.js +133 -6
  50. package/dist/filesystem/index.js.map +1 -1
  51. package/dist/filesystem/indexeddb.d.ts +284 -0
  52. package/dist/filesystem/indexeddb.js +23 -0
  53. package/dist/filesystem/indexeddb.js.map +1 -0
  54. package/dist/filesystem/memory.d.ts +152 -0
  55. package/dist/filesystem/memory.js +13 -0
  56. package/dist/filesystem/memory.js.map +1 -0
  57. package/dist/filesystem/native.d.ts +136 -0
  58. package/dist/filesystem/native.js +28 -0
  59. package/dist/filesystem/native.js.map +1 -0
  60. package/dist/host/index.d.ts +32 -6
  61. package/dist/host/index.js +26 -27
  62. package/dist/host/index.js.map +1 -1
  63. package/dist/index.d.ts +14 -9
  64. package/dist/index.js +204 -8
  65. package/dist/index.js.map +1 -1
  66. package/dist/mcp/index.d.ts +33 -0
  67. package/dist/mcp/index.js +32 -0
  68. package/dist/mcp/index.js.map +1 -0
  69. package/dist/mcp/zod.d.ts +5765 -0
  70. package/dist/mcp/zod.js +724 -0
  71. package/dist/mcp/zod.js.map +1 -0
  72. package/dist/share/index.d.ts +43 -0
  73. package/dist/share/index.js +13 -0
  74. package/dist/share/index.js.map +1 -0
  75. package/dist/types-BEg5SQ1_.d.ts +301 -0
  76. package/dist/types-CX893hgH.d.ts +468 -0
  77. package/dist/types-CueK0tvU.d.ts +501 -0
  78. package/dist/vscode/index.d.ts +220 -0
  79. package/dist/vscode/index.js +383 -0
  80. package/dist/vscode/index.js.map +1 -0
  81. package/dist/workspace/index.d.ts +141 -3
  82. package/dist/workspace/index.js +28 -1
  83. package/dist/workspace/index.js.map +1 -1
  84. package/dist/workspace-path-CWVrcuPL.d.ts +21 -0
  85. package/package.json +50 -5
  86. package/dist/chunk-GUNM43XZ.js +0 -63
  87. package/dist/chunk-GUNM43XZ.js.map +0 -1
  88. package/dist/chunk-IM7LCQJ6.js +0 -850
  89. package/dist/chunk-IM7LCQJ6.js.map +0 -1
  90. package/dist/chunk-ME76RUMR.js.map +0 -1
  91. package/dist/filesystem/electron-provider.d.ts +0 -32
  92. package/dist/filesystem/electron-provider.d.ts.map +0 -1
  93. package/dist/filesystem/electron-provider.js +0 -64
  94. package/dist/filesystem/electron-provider.js.map +0 -1
  95. package/dist/filesystem/file-media-provider.d.ts +0 -23
  96. package/dist/filesystem/file-media-provider.d.ts.map +0 -1
  97. package/dist/filesystem/file-media-provider.js +0 -85
  98. package/dist/filesystem/file-media-provider.js.map +0 -1
  99. package/dist/filesystem/filesystem-content-container.d.ts +0 -24
  100. package/dist/filesystem/filesystem-content-container.d.ts.map +0 -1
  101. package/dist/filesystem/filesystem-content-container.js +0 -116
  102. package/dist/filesystem/filesystem-content-container.js.map +0 -1
  103. package/dist/filesystem/index.d.ts.map +0 -1
  104. package/dist/filesystem/indexeddb-content-container.d.ts +0 -20
  105. package/dist/filesystem/indexeddb-content-container.d.ts.map +0 -1
  106. package/dist/filesystem/indexeddb-content-container.js +0 -93
  107. package/dist/filesystem/indexeddb-content-container.js.map +0 -1
  108. package/dist/filesystem/indexeddb-provider.d.ts +0 -32
  109. package/dist/filesystem/indexeddb-provider.d.ts.map +0 -1
  110. package/dist/filesystem/indexeddb-provider.js +0 -295
  111. package/dist/filesystem/indexeddb-provider.js.map +0 -1
  112. package/dist/filesystem/native-provider.d.ts +0 -45
  113. package/dist/filesystem/native-provider.d.ts.map +0 -1
  114. package/dist/filesystem/native-provider.js +0 -336
  115. package/dist/filesystem/native-provider.js.map +0 -1
  116. package/dist/filesystem/types.d.ts +0 -50
  117. package/dist/filesystem/types.d.ts.map +0 -1
  118. package/dist/filesystem/types.js +0 -8
  119. package/dist/filesystem/types.js.map +0 -1
  120. package/dist/host/index.d.ts.map +0 -1
  121. package/dist/host/types.d.ts +0 -149
  122. package/dist/host/types.d.ts.map +0 -1
  123. package/dist/host/types.js +0 -10
  124. package/dist/host/types.js.map +0 -1
  125. package/dist/index-pgBHBQ9G.d.ts +0 -213
  126. package/dist/index.d.ts.map +0 -1
  127. package/dist/workspace/index.d.ts.map +0 -1
  128. package/dist/workspace/types.d.ts +0 -29
  129. package/dist/workspace/types.d.ts.map +0 -1
  130. package/dist/workspace/types.js +0 -6
  131. package/dist/workspace/types.js.map +0 -1
  132. package/dist/workspace/workspace-manager.d.ts +0 -35
  133. package/dist/workspace/workspace-manager.d.ts.map +0 -1
  134. package/dist/workspace/workspace-manager.js +0 -82
  135. package/dist/workspace/workspace-manager.js.map +0 -1
  136. package/src/filesystem/electron-provider.ts +0 -88
  137. package/src/filesystem/file-media-provider.ts +0 -103
  138. package/src/filesystem/filesystem-content-container.ts +0 -126
  139. package/src/filesystem/index.ts +0 -24
  140. package/src/filesystem/indexeddb-content-container.ts +0 -104
  141. package/src/filesystem/indexeddb-provider.ts +0 -345
  142. package/src/filesystem/native-provider.ts +0 -384
  143. package/src/filesystem/types.ts +0 -69
  144. package/src/host/index.ts +0 -47
  145. package/src/host/types.ts +0 -153
  146. package/src/index.ts +0 -9
  147. package/src/workspace/index.ts +0 -10
  148. package/src/workspace/types.ts +0 -29
  149. package/src/workspace/workspace-manager.ts +0 -90
@@ -1,384 +0,0 @@
1
- /**
2
- * NativeFileSystemProvider — wraps the File System Access API
3
- * (window.showDirectoryPicker / FileSystemDirectoryHandle).
4
- *
5
- * Progressive enhancement: only available in browsers that support
6
- * the API (Chrome, Edge). Feature-detect with `isNativeFileSystemSupported()`.
7
- */
8
-
9
- import type { FileSystemProvider, FileSystemEntry, FileMeta } from './types.js';
10
-
11
- // ── Feature detection ──────────────────────────────────────────────
12
-
13
- export function isNativeFileSystemSupported(): boolean {
14
- return typeof globalThis !== 'undefined' && 'showDirectoryPicker' in globalThis;
15
- }
16
-
17
- // ── Handle persistence (IndexedDB, structured clone) ───────────────
18
-
19
- const HANDLE_DB_NAME = 'docblocks-handles';
20
- const HANDLE_STORE_NAME = 'directory-handles';
21
-
22
- function openHandleDB(): Promise<IDBDatabase> {
23
- return new Promise((resolve, reject) => {
24
- const req = indexedDB.open(HANDLE_DB_NAME, 1);
25
- req.onupgradeneeded = () => {
26
- req.result.createObjectStore(HANDLE_STORE_NAME);
27
- };
28
- req.onsuccess = () => resolve(req.result);
29
- req.onerror = () => reject(req.error);
30
- });
31
- }
32
-
33
- /** Persist a FileSystemDirectoryHandle so it survives page reloads. */
34
- export async function storeDirectoryHandle(
35
- workspaceId: string,
36
- handle: FileSystemDirectoryHandle,
37
- ): Promise<void> {
38
- const db = await openHandleDB();
39
- return new Promise((resolve, reject) => {
40
- const tx = db.transaction(HANDLE_STORE_NAME, 'readwrite');
41
- tx.objectStore(HANDLE_STORE_NAME).put(handle, workspaceId);
42
- tx.oncomplete = () => {
43
- db.close();
44
- resolve();
45
- };
46
- tx.onerror = () => {
47
- db.close();
48
- reject(tx.error);
49
- };
50
- });
51
- }
52
-
53
- /** Retrieve a previously stored handle. Returns null if not found. */
54
- export async function loadDirectoryHandle(
55
- workspaceId: string,
56
- ): Promise<FileSystemDirectoryHandle | null> {
57
- const db = await openHandleDB();
58
- return new Promise((resolve, reject) => {
59
- const tx = db.transaction(HANDLE_STORE_NAME, 'readonly');
60
- const req = tx.objectStore(HANDLE_STORE_NAME).get(workspaceId);
61
- req.onsuccess = () => {
62
- db.close();
63
- resolve(req.result ?? null);
64
- };
65
- req.onerror = () => {
66
- db.close();
67
- reject(req.error);
68
- };
69
- });
70
- }
71
-
72
- /** Remove a stored handle (e.g. when deleting a workspace). */
73
- export async function removeDirectoryHandle(workspaceId: string): Promise<void> {
74
- const db = await openHandleDB();
75
- return new Promise((resolve, reject) => {
76
- const tx = db.transaction(HANDLE_STORE_NAME, 'readwrite');
77
- tx.objectStore(HANDLE_STORE_NAME).delete(workspaceId);
78
- tx.oncomplete = () => {
79
- db.close();
80
- resolve();
81
- };
82
- tx.onerror = () => {
83
- db.close();
84
- reject(tx.error);
85
- };
86
- });
87
- }
88
-
89
- // ── Helpers ────────────────────────────────────────────────────────
90
-
91
- function normalisePath(p: string): string {
92
- return p.replace(/\\/g, '/').replace(/\/+/g, '/').replace(/^\//, '').replace(/\/$/, '');
93
- }
94
-
95
- /**
96
- * Walk a chain of path segments to reach a FileSystemDirectoryHandle.
97
- * Returns null if any segment is missing.
98
- */
99
- async function resolveDir(
100
- root: FileSystemDirectoryHandle,
101
- dirPath: string,
102
- ): Promise<FileSystemDirectoryHandle | null> {
103
- if (!dirPath) return root;
104
- const parts = dirPath.split('/');
105
- let current = root;
106
- for (const part of parts) {
107
- try {
108
- current = await current.getDirectoryHandle(part);
109
- } catch {
110
- return null;
111
- }
112
- }
113
- return current;
114
- }
115
-
116
- /**
117
- * Walk path segments, creating directories as needed.
118
- */
119
- async function resolveDirCreate(
120
- root: FileSystemDirectoryHandle,
121
- dirPath: string,
122
- ): Promise<FileSystemDirectoryHandle> {
123
- if (!dirPath) return root;
124
- const parts = dirPath.split('/');
125
- let current = root;
126
- for (const part of parts) {
127
- current = await current.getDirectoryHandle(part, { create: true });
128
- }
129
- return current;
130
- }
131
-
132
- function parentDir(p: string): string {
133
- const idx = p.lastIndexOf('/');
134
- return idx === -1 ? '' : p.slice(0, idx);
135
- }
136
-
137
- function baseName(p: string): string {
138
- const idx = p.lastIndexOf('/');
139
- return idx === -1 ? p : p.slice(idx + 1);
140
- }
141
-
142
- function toWritableBinary(data: ArrayBuffer | Uint8Array): ArrayBuffer {
143
- if (data instanceof ArrayBuffer) return data;
144
- const copy = new Uint8Array(data.byteLength);
145
- copy.set(data);
146
- return copy.buffer;
147
- }
148
-
149
- // ── Implementation ─────────────────────────────────────────────────
150
-
151
- export class NativeFileSystemProvider implements FileSystemProvider {
152
- readonly id: string;
153
- readonly label: string;
154
-
155
- private root: FileSystemDirectoryHandle;
156
-
157
- constructor(id: string, root: FileSystemDirectoryHandle) {
158
- this.id = id;
159
- this.label = root.name;
160
- this.root = root;
161
- }
162
-
163
- private async copyDirectory(oldDirPath: string, newDirPath: string): Promise<boolean> {
164
- const source = await resolveDir(this.root, oldDirPath);
165
- if (!source) return false;
166
- await resolveDirCreate(this.root, newDirPath);
167
-
168
- for await (const [name, handle] of source as unknown as AsyncIterable<
169
- [string, FileSystemHandle]
170
- >) {
171
- const oldChild = oldDirPath ? `${oldDirPath}/${name}` : name;
172
- const newChild = newDirPath ? `${newDirPath}/${name}` : name;
173
- if (handle.kind === 'directory') {
174
- await this.copyDirectory(oldChild, newChild);
175
- } else {
176
- const fileHandle = await source.getFileHandle(name);
177
- const file = await fileHandle.getFile();
178
- await this.writeBinary(newChild, await file.arrayBuffer());
179
- }
180
- }
181
-
182
- return true;
183
- }
184
-
185
- async readFile(path: string): Promise<string | null> {
186
- const p = normalisePath(path);
187
- const dir = await resolveDir(this.root, parentDir(p));
188
- if (!dir) return null;
189
- try {
190
- const fileHandle = await dir.getFileHandle(baseName(p));
191
- const file = await fileHandle.getFile();
192
- return file.text();
193
- } catch {
194
- return null;
195
- }
196
- }
197
-
198
- async writeFile(path: string, content: string): Promise<void> {
199
- const p = normalisePath(path);
200
- const dir = await resolveDirCreate(this.root, parentDir(p));
201
- const fileHandle = await dir.getFileHandle(baseName(p), { create: true });
202
- const writable = await fileHandle.createWritable();
203
- await writable.write(content);
204
- await writable.close();
205
- }
206
-
207
- async delete(path: string): Promise<void> {
208
- const p = normalisePath(path);
209
- const parent = parentDir(p);
210
- const name = baseName(p);
211
- const dir = await resolveDir(this.root, parent);
212
- if (!dir) return;
213
- await dir.removeEntry(name, { recursive: true });
214
- }
215
-
216
- async rename(oldPath: string, newPath: string): Promise<void> {
217
- const op = normalisePath(oldPath);
218
- const np = normalisePath(newPath);
219
- if (op === np) return;
220
- if (!op || !np) {
221
- throw new Error('Cannot rename the filesystem root');
222
- }
223
- if (np.startsWith(op + '/')) {
224
- throw new Error('Cannot move a directory into itself');
225
- }
226
-
227
- // The File System Access API doesn't have a native rename.
228
- // Copy → delete.
229
- const oldParent = await resolveDir(this.root, parentDir(op));
230
- if (!oldParent) return;
231
-
232
- try {
233
- const fileHandle = await oldParent.getFileHandle(baseName(op));
234
- const file = await fileHandle.getFile();
235
- await this.writeBinary(np, await file.arrayBuffer());
236
- await this.delete(op);
237
- return;
238
- } catch {
239
- // Not a file; try directory below.
240
- }
241
-
242
- const copied = await this.copyDirectory(op, np);
243
- if (copied) {
244
- await this.delete(op);
245
- }
246
- }
247
-
248
- async readDirectory(path: string): Promise<FileSystemEntry[]> {
249
- const p = normalisePath(path);
250
- const dir = await resolveDir(this.root, p);
251
- if (!dir) return [];
252
-
253
- const entries: FileSystemEntry[] = [];
254
- for await (const [name, handle] of dir as unknown as AsyncIterable<
255
- [string, FileSystemHandle]
256
- >) {
257
- const entryPath = p ? `${p}/${name}` : name;
258
- if (handle.kind === 'directory') {
259
- entries.push({ kind: 'directory', name, path: entryPath });
260
- } else {
261
- entries.push({ kind: 'file', name, path: entryPath });
262
- }
263
- }
264
-
265
- // Sort: directories first, then alphabetical
266
- entries.sort((a, b) => {
267
- if (a.kind !== b.kind) return a.kind === 'directory' ? -1 : 1;
268
- return a.name.localeCompare(b.name);
269
- });
270
-
271
- return entries;
272
- }
273
-
274
- async exists(path: string): Promise<boolean> {
275
- const p = normalisePath(path);
276
- const parent = parentDir(p);
277
- const name = baseName(p);
278
- const dir = await resolveDir(this.root, parent);
279
- if (!dir) return false;
280
-
281
- try {
282
- await dir.getFileHandle(name);
283
- return true;
284
- } catch {
285
- try {
286
- await dir.getDirectoryHandle(name);
287
- return true;
288
- } catch {
289
- return false;
290
- }
291
- }
292
- }
293
-
294
- async createDirectory(path: string): Promise<void> {
295
- const p = normalisePath(path);
296
- await resolveDirCreate(this.root, p);
297
- }
298
-
299
- async stat(path: string): Promise<FileMeta | null> {
300
- const p = normalisePath(path);
301
- const dir = await resolveDir(this.root, parentDir(p));
302
- if (!dir) return null;
303
-
304
- try {
305
- const fileHandle = await dir.getFileHandle(baseName(p));
306
- const file = await fileHandle.getFile();
307
- return {
308
- name: file.name,
309
- path: p,
310
- size: file.size,
311
- lastModified: new Date(file.lastModified).toISOString(),
312
- };
313
- } catch {
314
- return null;
315
- }
316
- }
317
-
318
- async readBinary(path: string): Promise<ArrayBuffer | null> {
319
- const p = normalisePath(path);
320
- const dir = await resolveDir(this.root, parentDir(p));
321
- if (!dir) return null;
322
- try {
323
- const fileHandle = await dir.getFileHandle(baseName(p));
324
- const file = await fileHandle.getFile();
325
- return file.arrayBuffer();
326
- } catch {
327
- return null;
328
- }
329
- }
330
-
331
- async writeBinary(path: string, data: ArrayBuffer | Uint8Array): Promise<void> {
332
- const p = normalisePath(path);
333
- const dir = await resolveDirCreate(this.root, parentDir(p));
334
- const fileHandle = await dir.getFileHandle(baseName(p), { create: true });
335
- const writable = await fileHandle.createWritable();
336
- await writable.write(toWritableBinary(data));
337
- await writable.close();
338
- }
339
- }
340
-
341
- /**
342
- * Prompt the user to pick a local folder and return a NativeFileSystemProvider.
343
- * The directory handle is persisted in IndexedDB so it can be restored later.
344
- * Throws if the user cancels or the API is unsupported.
345
- */
346
- export async function openNativeFolder(): Promise<NativeFileSystemProvider> {
347
- if (!isNativeFileSystemSupported()) {
348
- throw new Error('File System Access API is not supported in this browser');
349
- }
350
-
351
- const handle = await (
352
- globalThis as unknown as { showDirectoryPicker: () => Promise<FileSystemDirectoryHandle> }
353
- ).showDirectoryPicker();
354
- const id = `native-${handle.name}-${Date.now()}`;
355
- await storeDirectoryHandle(id, handle);
356
- return new NativeFileSystemProvider(id, handle);
357
- }
358
-
359
- /**
360
- * Restore a previously opened native folder from a persisted handle.
361
- * Re-requests read/write permission (browser will show a prompt).
362
- * Returns null if the handle is not found or permission is denied.
363
- */
364
- export async function restoreNativeFolder(
365
- workspaceId: string,
366
- ): Promise<NativeFileSystemProvider | null> {
367
- const handle = await loadDirectoryHandle(workspaceId);
368
- if (!handle) return null;
369
-
370
- // Verify/request permission
371
- const opts = { mode: 'readwrite' as const };
372
- const h = handle as FileSystemDirectoryHandle & {
373
- queryPermission(desc: { mode: string }): Promise<string>;
374
- requestPermission(desc: { mode: string }): Promise<string>;
375
- };
376
- if ((await h.queryPermission(opts)) === 'granted') {
377
- return new NativeFileSystemProvider(workspaceId, handle);
378
- }
379
- if ((await h.requestPermission(opts)) === 'granted') {
380
- return new NativeFileSystemProvider(workspaceId, handle);
381
- }
382
-
383
- return null;
384
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * FileSystemProvider — abstract interface for a virtual filesystem.
3
- *
4
- * Implementations back onto IndexedDB (for browser-local storage) or
5
- * the File System Access API (for native folder access).
6
- */
7
-
8
- // ── Entry types ────────────────────────────────────────────────────
9
-
10
- export interface FileEntry {
11
- kind: 'file';
12
- name: string;
13
- path: string;
14
- }
15
-
16
- export interface FolderEntry {
17
- kind: 'directory';
18
- name: string;
19
- path: string;
20
- }
21
-
22
- export type FileSystemEntry = FileEntry | FolderEntry;
23
-
24
- export interface FileMeta {
25
- name: string;
26
- path: string;
27
- size: number;
28
- lastModified: string;
29
- }
30
-
31
- // ── Provider interface ─────────────────────────────────────────────
32
-
33
- export interface FileSystemProvider {
34
- /** Unique identifier for this provider instance. */
35
- readonly id: string;
36
-
37
- /** Human-readable label (e.g., folder name or "Browser Storage"). */
38
- readonly label: string;
39
-
40
- /** Read the text content of a file. Returns null if the file doesn't exist. */
41
- readFile(path: string): Promise<string | null>;
42
-
43
- /** Write text content to a file, creating it (and parent dirs) if needed. */
44
- writeFile(path: string, content: string): Promise<void>;
45
-
46
- /** Delete a file or empty directory. */
47
- delete(path: string): Promise<void>;
48
-
49
- /** Rename or move an entry. */
50
- rename(oldPath: string, newPath: string): Promise<void>;
51
-
52
- /** List immediate children of a directory. */
53
- readDirectory(path: string): Promise<FileSystemEntry[]>;
54
-
55
- /** Check whether a path exists. */
56
- exists(path: string): Promise<boolean>;
57
-
58
- /** Create a directory (and parents if needed). */
59
- createDirectory(path: string): Promise<void>;
60
-
61
- /** Get metadata for a file. Returns null if not found. */
62
- stat(path: string): Promise<FileMeta | null>;
63
-
64
- /** Read raw binary content. Returns null if not found. */
65
- readBinary(path: string): Promise<ArrayBuffer | null>;
66
-
67
- /** Write raw binary content. */
68
- writeBinary(path: string, data: ArrayBuffer | Uint8Array): Promise<void>;
69
- }
package/src/host/index.ts DELETED
@@ -1,47 +0,0 @@
1
- /**
2
- * Host bridge — shared types + runtime access for the Electron desktop
3
- * host. The renderer calls `getDocBlocksHost()` to reach the preload
4
- * contextBridge; `isElectronHost()` gates desktop-only UI branches.
5
- */
6
-
7
- export type {
8
- DocBlocksHostAPI,
9
- DocBlocksHostFsAPI,
10
- DocBlocksHostWorkspacesAPI,
11
- DocBlocksHostShellAPI,
12
- DocBlocksHostFfmpegAPI,
13
- DocBlocksHostUpdaterAPI,
14
- ElectronWorkspaceInfo,
15
- HostEnvironment,
16
- MenuCommand,
17
- OpenRequest,
18
- UpdaterStatus,
19
- } from './types.js';
20
-
21
- import type { DocBlocksHostAPI } from './types.js';
22
-
23
- /** True when running inside the Electron desktop shell. */
24
- export function isElectronHost(): boolean {
25
- if (typeof globalThis === 'undefined') return false;
26
- const host = (globalThis as { docBlocksHost?: unknown }).docBlocksHost;
27
- return (
28
- typeof host === 'object' &&
29
- host !== null &&
30
- typeof (host as { fs?: unknown }).fs === 'object' &&
31
- (host as { fs?: unknown }).fs !== null
32
- );
33
- }
34
-
35
- /** Return the host API, or throw if not running under Electron. */
36
- export function getDocBlocksHost(): DocBlocksHostAPI {
37
- const host = (globalThis as { docBlocksHost?: DocBlocksHostAPI }).docBlocksHost;
38
- if (!host) {
39
- throw new Error('docBlocksHost is not available — not running under Electron?');
40
- }
41
- return host;
42
- }
43
-
44
- /** Return the host API, or null if not running under Electron. */
45
- export function maybeGetDocBlocksHost(): DocBlocksHostAPI | null {
46
- return (globalThis as { docBlocksHost?: DocBlocksHostAPI }).docBlocksHost ?? null;
47
- }
package/src/host/types.ts DELETED
@@ -1,153 +0,0 @@
1
- /**
2
- * DocBlocksHostAPI — the contract exposed by the Electron desktop shell
3
- * to its renderer process via contextBridge.
4
- *
5
- * This file is the single source of truth for the host ↔ renderer
6
- * bridge. The Electron preload script exposes an implementation matching
7
- * this shape; the React renderer calls it through `window.docBlocksHost`.
8
- */
9
-
10
- import type { FileSystemEntry, FileMeta } from '../filesystem/types.js';
11
-
12
- /** Filesystem operations scoped to a registered absolute root path. */
13
- export interface DocBlocksHostFsAPI {
14
- readFile(rootPath: string, path: string): Promise<string | null>;
15
- writeFile(rootPath: string, path: string, content: string): Promise<void>;
16
- delete(rootPath: string, path: string): Promise<void>;
17
- rename(rootPath: string, oldPath: string, newPath: string): Promise<void>;
18
- readDirectory(rootPath: string, path: string): Promise<FileSystemEntry[]>;
19
- exists(rootPath: string, path: string): Promise<boolean>;
20
- createDirectory(rootPath: string, path: string): Promise<void>;
21
- stat(rootPath: string, path: string): Promise<FileMeta | null>;
22
- readBinary(rootPath: string, path: string): Promise<ArrayBuffer | null>;
23
- writeBinary(rootPath: string, path: string, data: ArrayBuffer | Uint8Array): Promise<void>;
24
- /**
25
- * Subscribe to change notifications for a watched root. Returns an
26
- * unsubscribe function. The main process uses chokidar under the hood.
27
- */
28
- watch(rootPath: string, onChange: (path: string) => void): () => void;
29
- }
30
-
31
- /** Descriptor returned for an Electron-managed workspace (backed by a folder). */
32
- export interface ElectronWorkspaceInfo {
33
- id: string;
34
- name: string;
35
- rootPath: string;
36
- }
37
-
38
- /** Workspace-management operations exposed to the renderer. */
39
- export interface DocBlocksHostWorkspacesAPI {
40
- /**
41
- * Return the default workspace (creating ~/Documents/DocBlocks on first
42
- * call, or the user's configured default).
43
- */
44
- getDefault(): Promise<ElectronWorkspaceInfo>;
45
- /**
46
- * Open the native folder picker. Returns null if the user cancels.
47
- * The selected folder is registered in the main process whitelist.
48
- */
49
- pickFolder(): Promise<ElectronWorkspaceInfo | null>;
50
- /**
51
- * Re-register a previously known workspace so its rootPath is trusted
52
- * for subsequent fs calls. Called on app startup for persisted
53
- * electron-native workspaces before any fs operation.
54
- */
55
- register(info: ElectronWorkspaceInfo): Promise<void>;
56
- /** Remove a workspace from the trusted whitelist. */
57
- unregister(id: string): Promise<void>;
58
- }
59
-
60
- /** Shell operations — reveal in Finder/Explorer, open external URLs. */
61
- export interface DocBlocksHostShellAPI {
62
- /** Reveal a file (by absolute path) in the OS file manager. */
63
- revealInFolder(absolutePath: string): Promise<void>;
64
- /** Open a URL in the default browser. */
65
- openExternal(url: string): Promise<void>;
66
- }
67
-
68
- /** System ffmpeg detection and invocation. */
69
- export interface DocBlocksHostFfmpegAPI {
70
- /** True if `ffmpeg` is available on PATH (or bundled). */
71
- available(): Promise<boolean>;
72
- /** Version string from `ffmpeg -version`, or null if unavailable. */
73
- version(): Promise<string | null>;
74
- /**
75
- * Render a markdown file at the given absolute path to MP4 using the
76
- * existing squisq-video CLI pipeline. Returns the absolute path to the
77
- * produced MP4 file, or throws on failure.
78
- */
79
- renderVideo(
80
- markdownAbsolutePath: string,
81
- options: { fps?: number; quality?: 'draft' | 'normal' | 'high' },
82
- ): Promise<string>;
83
- }
84
-
85
- /** Auto-updater control. */
86
- export interface DocBlocksHostUpdaterAPI {
87
- /** Kick off a check; resolves to true if an update is available. */
88
- checkForUpdates(): Promise<boolean>;
89
- /** Current app version string. */
90
- getVersion(): Promise<string>;
91
- /**
92
- * Quit the app and apply a downloaded update. Should only be called
93
- * after an `UpdaterStatus` of kind `'downloaded'` has been observed.
94
- */
95
- quitAndInstall(): Promise<void>;
96
- /**
97
- * Subscribe to updater status events. Returns an unsubscribe function.
98
- */
99
- onStatus(listener: (status: UpdaterStatus) => void): () => void;
100
- }
101
-
102
- export type UpdaterStatus =
103
- | { kind: 'checking' }
104
- | { kind: 'available'; version: string; releaseNotes?: string; releaseUrl?: string }
105
- | { kind: 'not-available' }
106
- | { kind: 'downloading'; percent: number }
107
- | { kind: 'downloaded'; version: string; releaseNotes?: string; releaseUrl?: string }
108
- | { kind: 'error'; message: string };
109
-
110
- /** Menu-command events pushed from the main process to the renderer. */
111
- export type MenuCommand =
112
- | 'file:new'
113
- | 'file:openFolder'
114
- | 'file:revealWorkspace'
115
- | 'file:settings'
116
- | 'help:about'
117
- | 'help:checkForUpdates'
118
- | 'help:viewOnGitHub';
119
-
120
- /** Deep-link event resolved by the host into a trusted workspace file. */
121
- export interface OpenRequest {
122
- kind: 'workspace-file';
123
- workspaceId: string;
124
- /** Slash-prefixed path relative to the workspace root. */
125
- path: string;
126
- }
127
-
128
- /** Environment metadata provided by the host. */
129
- export interface HostEnvironment {
130
- platform: 'darwin' | 'win32' | 'linux';
131
- appVersion: string;
132
- isDev: boolean;
133
- }
134
-
135
- /** The full DocBlocks desktop host API. */
136
- export interface DocBlocksHostAPI {
137
- env: HostEnvironment;
138
- fs: DocBlocksHostFsAPI;
139
- workspaces: DocBlocksHostWorkspacesAPI;
140
- shell: DocBlocksHostShellAPI;
141
- ffmpeg: DocBlocksHostFfmpegAPI;
142
- updater: DocBlocksHostUpdaterAPI;
143
- /**
144
- * Subscribe to menu commands dispatched by the native menu.
145
- * Returns an unsubscribe function.
146
- */
147
- onMenuCommand(listener: (cmd: MenuCommand) => void): () => void;
148
- /**
149
- * Subscribe to open-file / open-url requests from the OS.
150
- * Returns an unsubscribe function.
151
- */
152
- onOpenRequest(listener: (request: OpenRequest) => void): () => void;
153
- }
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * @bendyline/docblocks — Core package
3
- *
4
- * Re-exports filesystem, workspace, and host modules for convenience.
5
- */
6
-
7
- export * from './filesystem/index.js';
8
- export * from './workspace/index.js';
9
- export * from './host/index.js';
@@ -1,10 +0,0 @@
1
- export type { WorkspaceDescriptor } from './types.js';
2
-
3
- export {
4
- listWorkspaces,
5
- getWorkspace,
6
- saveWorkspace,
7
- removeWorkspace,
8
- touchWorkspace,
9
- ensureDefaultWorkspace,
10
- } from './workspace-manager.js';