@principal-ai/principal-view-core 0.28.6 → 0.28.7

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,389 @@
1
+ "use strict";
2
+ /**
3
+ * File-per-topic store under `~/.principal/topics/`.
4
+ *
5
+ * Layout (mirrors the trail store at `~/.principal/trails/`, so topics become
6
+ * locally greppable and an agent can read one directly):
7
+ *
8
+ * ~/.principal/topics/
9
+ * _index.json private, rebuildable manifest (entries[])
10
+ * <id>.json one pretty-printed DraftTopic per file
11
+ *
12
+ * Topics are the *least* repo-bound artifact (a bundle of trails spanning
13
+ * repos), so — unlike trails, which bucket by repo Purl — they are stored flat
14
+ * by id. No purl, no buckets, no `node:os`/Purl dependency beyond `homedir()`.
15
+ *
16
+ * The `_index.json` manifest is store-private and rebuildable: it is rebuilt by
17
+ * scanning the directory whenever it is missing or unparseable. It exists only
18
+ * to make `getTopics()` / `list()` cheap (no per-file read for listing).
19
+ *
20
+ * There is intentionally NO eviction cap. The trail store caps trails per repo
21
+ * (`PER_REPO_CAP`); topics are few, user-curated, and must never be silently
22
+ * dropped, so the cap is deliberately not carried over.
23
+ *
24
+ * Migration from the legacy single-blob `~/.alexandria/topics.json` is explicit
25
+ * (`migrateFromLegacyBlob`) — it is never run automatically on load; the desktop
26
+ * triggers it from a Settings action.
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.TopicStore = exports.LEGACY_TOPICS_BLOB = exports.TOPICS_DIR = exports.PRINCIPAL_DIR = void 0;
30
+ const node_os_1 = require("node:os");
31
+ const node_path_1 = require("node:path");
32
+ const promises_1 = require("node:fs/promises");
33
+ /** Root of the global, cross-repo principal narration store. */
34
+ exports.PRINCIPAL_DIR = (0, node_path_1.join)((0, node_os_1.homedir)(), '.principal');
35
+ /** File-per-topic directory. */
36
+ exports.TOPICS_DIR = (0, node_path_1.join)(exports.PRINCIPAL_DIR, 'topics');
37
+ /** Legacy single-blob path the migration reads from. */
38
+ exports.LEGACY_TOPICS_BLOB = (0, node_path_1.join)((0, node_os_1.homedir)(), '.alexandria', 'topics.json');
39
+ const INDEX_FILENAME = '_index.json';
40
+ const DESCRIPTION_PREVIEW_MAX = 200;
41
+ const emptyIndex = () => ({ version: 1, entries: [] });
42
+ const sanitizeSegment = (value) => value.replace(/[^A-Za-z0-9._-]/g, '_');
43
+ const nowIso = () => new Date().toISOString();
44
+ /** Locally-unique topic id, matching the legacy `topic-<ts>-<rand>` shape. */
45
+ const generateTopicId = () => `topic-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
46
+ const descriptionPreview = (description) => {
47
+ if (!description)
48
+ return '';
49
+ const trimmed = description.trim();
50
+ if (trimmed.length <= DESCRIPTION_PREVIEW_MAX)
51
+ return trimmed;
52
+ return `${trimmed.slice(0, DESCRIPTION_PREVIEW_MAX - 1)}…`;
53
+ };
54
+ const buildEntry = (topic, sizeBytes) => ({
55
+ id: topic.id,
56
+ title: topic.title || 'Untitled topic',
57
+ descriptionPreview: descriptionPreview(topic.description),
58
+ trailCount: topic.trailIds.length,
59
+ state: topic.status?.state,
60
+ createdAt: topic.createdAt,
61
+ updatedAt: topic.updatedAt,
62
+ createdBy: topic.createdBy,
63
+ hasAssets: (topic.assets?.length ?? 0) > 0,
64
+ sizeBytes,
65
+ fileName: `${sanitizeSegment(topic.id)}.json`,
66
+ });
67
+ class TopicStore {
68
+ /**
69
+ * @param baseDir file-per-topic directory (defaults to `TOPICS_DIR`)
70
+ * @param legacyBlobPath legacy blob the migration reads (defaults to
71
+ * `LEGACY_TOPICS_BLOB`); injectable for tests.
72
+ */
73
+ constructor(baseDir = exports.TOPICS_DIR, legacyBlobPath = exports.LEGACY_TOPICS_BLOB) {
74
+ this.index = null;
75
+ this.writeQueue = Promise.resolve();
76
+ this.baseDir = baseDir;
77
+ this.indexPath = (0, node_path_1.join)(baseDir, INDEX_FILENAME);
78
+ this.legacyBlobPath = legacyBlobPath;
79
+ }
80
+ // ===== Topic CRUD =====
81
+ async getTopics() {
82
+ const idx = await this.getIndex();
83
+ const topics = [];
84
+ for (const entry of idx.entries) {
85
+ const topic = await this.readTopic(entry.fileName);
86
+ if (topic)
87
+ topics.push(topic);
88
+ }
89
+ return topics;
90
+ }
91
+ async getTopic(id) {
92
+ const idx = await this.getIndex();
93
+ const entry = idx.entries.find((e) => e.id === id);
94
+ if (!entry)
95
+ return null;
96
+ return this.readTopic(entry.fileName);
97
+ }
98
+ /** Cheap listing straight off the manifest — no per-topic file read. */
99
+ async list() {
100
+ const idx = await this.getIndex();
101
+ return idx.entries
102
+ .slice()
103
+ .sort((a, b) => (a.updatedAt < b.updatedAt ? 1 : -1));
104
+ }
105
+ async createTopic(input) {
106
+ const idx = await this.getIndex();
107
+ const now = nowIso();
108
+ const id = input.id?.trim() || generateTopicId();
109
+ if (idx.entries.some((e) => e.id === id)) {
110
+ throw new Error(`Topic with id '${id}' already exists`);
111
+ }
112
+ const topic = {
113
+ ...input,
114
+ id,
115
+ title: input.title || 'Untitled topic',
116
+ trailIds: input.trailIds ?? [],
117
+ createdAt: input.createdAt ?? now,
118
+ updatedAt: input.updatedAt ?? now,
119
+ };
120
+ await this.writeTopic(topic, idx);
121
+ return topic;
122
+ }
123
+ async updateTopic(id, updates) {
124
+ const idx = await this.getIndex();
125
+ const existing = await this.requireTopic(idx, id);
126
+ const next = {
127
+ ...existing,
128
+ ...updates,
129
+ id: existing.id,
130
+ trailIds: existing.trailIds,
131
+ createdAt: existing.createdAt,
132
+ updatedAt: nowIso(),
133
+ };
134
+ await this.writeTopic(next, idx);
135
+ return next;
136
+ }
137
+ async deleteTopic(id) {
138
+ const idx = await this.getIndex();
139
+ const entryIdx = idx.entries.findIndex((e) => e.id === id);
140
+ if (entryIdx < 0)
141
+ return false;
142
+ const { fileName } = idx.entries[entryIdx];
143
+ idx.entries.splice(entryIdx, 1);
144
+ await this.unlinkRelative(fileName);
145
+ await this.persistIndex();
146
+ return true;
147
+ }
148
+ // ===== Trail membership =====
149
+ async addTrailToTopic(topicId, trailId) {
150
+ const idx = await this.getIndex();
151
+ const topic = await this.requireTopic(idx, topicId);
152
+ if (topic.trailIds.includes(trailId))
153
+ return topic;
154
+ const next = {
155
+ ...topic,
156
+ trailIds: [...topic.trailIds, trailId],
157
+ updatedAt: nowIso(),
158
+ };
159
+ await this.writeTopic(next, idx);
160
+ return next;
161
+ }
162
+ async removeTrailFromTopic(topicId, trailId) {
163
+ const idx = await this.getIndex();
164
+ const topic = await this.requireTopic(idx, topicId);
165
+ if (!topic.trailIds.includes(trailId))
166
+ return topic;
167
+ const next = {
168
+ ...topic,
169
+ trailIds: topic.trailIds.filter((t) => t !== trailId),
170
+ updatedAt: nowIso(),
171
+ };
172
+ await this.writeTopic(next, idx);
173
+ return next;
174
+ }
175
+ async reorderTopicTrails(topicId, trailIds) {
176
+ const idx = await this.getIndex();
177
+ const topic = await this.requireTopic(idx, topicId);
178
+ const current = new Set(topic.trailIds);
179
+ const next = new Set(trailIds);
180
+ if (current.size !== next.size || [...current].some((t) => !next.has(t))) {
181
+ throw new Error('reorderTopicTrails expects a permutation of the existing trail list');
182
+ }
183
+ const updated = {
184
+ ...topic,
185
+ trailIds: [...trailIds],
186
+ updatedAt: nowIso(),
187
+ };
188
+ await this.writeTopic(updated, idx);
189
+ return updated;
190
+ }
191
+ async getTopicsForTrail(trailId) {
192
+ const topics = await this.getTopics();
193
+ return topics.filter((t) => t.trailIds.includes(trailId));
194
+ }
195
+ // ===== Migration =====
196
+ /**
197
+ * One-shot migration from the legacy single-blob `~/.alexandria/topics.json`
198
+ * to file-per-topic. Reads the blob's `topics[]`, writes each as
199
+ * `<id>.json`, rebuilds the index, then renames the blob to `<blob>.bak` so
200
+ * a re-run is a no-op (mirrors the trail store's `migrateLegacyIfPresent`).
201
+ *
202
+ * Explicit by design — the desktop calls this from a Settings action, never
203
+ * on load. Idempotent: once the blob is `.bak`'d, subsequent calls report
204
+ * `noLegacyBlob`. An existing topic id is overwritten (the blob wins on a
205
+ * first migration), so re-importing after edits is the caller's decision.
206
+ */
207
+ async migrateFromLegacyBlob() {
208
+ let raw;
209
+ try {
210
+ raw = await (0, promises_1.readFile)(this.legacyBlobPath, 'utf8');
211
+ }
212
+ catch {
213
+ return { migrated: 0, skipped: 0, noLegacyBlob: true };
214
+ }
215
+ let blob;
216
+ try {
217
+ blob = JSON.parse(raw);
218
+ }
219
+ catch {
220
+ throw new Error(`Legacy topics blob at ${this.legacyBlobPath} is not valid JSON; not migrating.`);
221
+ }
222
+ const idx = await this.getIndex();
223
+ let migrated = 0;
224
+ let skipped = 0;
225
+ for (const legacy of blob.topics ?? []) {
226
+ if (!legacy?.id) {
227
+ skipped++;
228
+ continue;
229
+ }
230
+ const now = nowIso();
231
+ const topic = {
232
+ ...legacy,
233
+ title: legacy.title || 'Untitled topic',
234
+ trailIds: legacy.trailIds ?? [],
235
+ createdAt: legacy.createdAt ?? now,
236
+ updatedAt: legacy.updatedAt ?? now,
237
+ };
238
+ try {
239
+ await this.writeTopic(topic, idx);
240
+ migrated++;
241
+ }
242
+ catch {
243
+ skipped++;
244
+ }
245
+ }
246
+ const backupPath = `${this.legacyBlobPath}.bak`;
247
+ let backedUp;
248
+ if (!(await this.pathExists(backupPath))) {
249
+ try {
250
+ await (0, promises_1.rename)(this.legacyBlobPath, backupPath);
251
+ backedUp = backupPath;
252
+ }
253
+ catch {
254
+ // Non-fatal: topics are migrated; the blob just wasn't renamed.
255
+ }
256
+ }
257
+ return {
258
+ migrated,
259
+ skipped,
260
+ noLegacyBlob: false,
261
+ ...(backedUp ? { backupPath: backedUp } : {}),
262
+ };
263
+ }
264
+ // ===== Internals =====
265
+ async getIndex() {
266
+ if (!this.index) {
267
+ await (0, promises_1.mkdir)(this.baseDir, { recursive: true });
268
+ this.index = await this.loadIndex();
269
+ }
270
+ return this.index;
271
+ }
272
+ async requireTopic(idx, id) {
273
+ const entry = idx.entries.find((e) => e.id === id);
274
+ if (!entry)
275
+ throw new Error(`Topic with id '${id}' not found`);
276
+ const topic = await this.readTopic(entry.fileName);
277
+ if (!topic)
278
+ throw new Error(`Topic with id '${id}' not found`);
279
+ return topic;
280
+ }
281
+ /** Write a topic file and upsert its index entry. Does not generate ids. */
282
+ async writeTopic(topic, idx) {
283
+ const fileName = `${sanitizeSegment(topic.id)}.json`;
284
+ const file = (0, node_path_1.join)(this.baseDir, fileName);
285
+ await (0, promises_1.mkdir)((0, node_path_1.dirname)(file), { recursive: true });
286
+ const serialized = JSON.stringify(topic, null, 2);
287
+ await (0, promises_1.writeFile)(file, serialized, 'utf8');
288
+ const entry = buildEntry(topic, Buffer.byteLength(serialized, 'utf8'));
289
+ const at = idx.entries.findIndex((e) => e.id === topic.id);
290
+ if (at >= 0)
291
+ idx.entries[at] = entry;
292
+ else
293
+ idx.entries.push(entry);
294
+ await this.persistIndex();
295
+ }
296
+ async readTopic(fileName) {
297
+ try {
298
+ const raw = await (0, promises_1.readFile)((0, node_path_1.join)(this.baseDir, fileName), 'utf8');
299
+ return JSON.parse(raw);
300
+ }
301
+ catch (err) {
302
+ console.error('[TopicStore] Failed to read topic', fileName, err);
303
+ return null;
304
+ }
305
+ }
306
+ async unlinkRelative(fileName) {
307
+ try {
308
+ await (0, promises_1.unlink)((0, node_path_1.join)(this.baseDir, fileName));
309
+ }
310
+ catch (err) {
311
+ const code = err.code;
312
+ if (code !== 'ENOENT') {
313
+ console.error('[TopicStore] Failed to unlink', fileName, err);
314
+ }
315
+ }
316
+ }
317
+ async pathExists(path) {
318
+ try {
319
+ await (0, promises_1.access)(path);
320
+ return true;
321
+ }
322
+ catch {
323
+ return false;
324
+ }
325
+ }
326
+ async loadIndex() {
327
+ try {
328
+ const raw = await (0, promises_1.readFile)(this.indexPath, 'utf8');
329
+ const parsed = JSON.parse(raw);
330
+ if (parsed?.version === 1 && Array.isArray(parsed.entries)) {
331
+ return { version: 1, entries: parsed.entries };
332
+ }
333
+ }
334
+ catch (err) {
335
+ const code = err.code;
336
+ if (code !== 'ENOENT') {
337
+ console.warn('[TopicStore] _index.json unreadable, rebuilding', err);
338
+ }
339
+ }
340
+ // No auto-migration here: the legacy blob is imported only via the
341
+ // explicit migrateFromLegacyBlob() Settings action.
342
+ return this.rebuildIndex();
343
+ }
344
+ /** Rebuild the manifest by scanning every `<id>.json` in the directory. */
345
+ async rebuildIndex() {
346
+ const idx = emptyIndex();
347
+ let names;
348
+ try {
349
+ names = await (0, promises_1.readdir)(this.baseDir);
350
+ }
351
+ catch {
352
+ return idx;
353
+ }
354
+ for (const name of names) {
355
+ if (name === INDEX_FILENAME || !name.endsWith('.json'))
356
+ continue;
357
+ const topic = await this.readTopic(name);
358
+ if (!topic?.id)
359
+ continue;
360
+ const createdAt = topic.createdAt ?? nowIso();
361
+ const stamped = {
362
+ ...topic,
363
+ createdAt,
364
+ updatedAt: topic.updatedAt ?? createdAt,
365
+ title: topic.title || 'Untitled topic',
366
+ trailIds: topic.trailIds ?? [],
367
+ };
368
+ const raw = JSON.stringify(stamped, null, 2);
369
+ idx.entries.push(buildEntry(stamped, Buffer.byteLength(raw, 'utf8')));
370
+ }
371
+ this.index = idx;
372
+ await this.persistIndex();
373
+ return idx;
374
+ }
375
+ persistIndex() {
376
+ if (!this.index)
377
+ return Promise.resolve();
378
+ const snapshot = this.index;
379
+ this.writeQueue = this.writeQueue
380
+ .catch(() => undefined)
381
+ .then(async () => {
382
+ await (0, promises_1.mkdir)(this.baseDir, { recursive: true });
383
+ await (0, promises_1.writeFile)(this.indexPath, JSON.stringify(snapshot, null, 2), 'utf8');
384
+ });
385
+ return this.writeQueue;
386
+ }
387
+ }
388
+ exports.TopicStore = TopicStore;
389
+ //# sourceMappingURL=topicStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"topicStore.js","sourceRoot":"","sources":["../../src/storage/topicStore.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAEH,qCAAkC;AAClC,yCAA0C;AAC1C,+CAQ0B;AAG1B,gEAAgE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KAAK;YAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU;aAC9B,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC;aACtB,IAAI,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,IAAA,gBAAK,EAAC,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC/C,MAAM,IAAA,oBAAS,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QAC7E,CAAC,CAAC,CAAC;QACL,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AA/UD,gCA+UC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principal-ai/principal-view-core",
3
- "version": "0.28.6",
3
+ "version": "0.28.7",
4
4
  "description": "Core logic and types for graph-based principal view framework",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/src/index.ts CHANGED
@@ -532,6 +532,19 @@ export {
532
532
  export type { FileSystemAdapter } from '@principal-ai/repository-abstraction';
533
533
  export { InMemoryFileSystemAdapter } from '@principal-ai/repository-abstraction';
534
534
 
535
+ // Canonical topic storage contract (browser-safe types + Draft->Published
536
+ // projection). The file-per-topic store that reads/writes these is node-only;
537
+ // import it from '@principal-ai/principal-view-core/node'.
538
+ export { publishedFromDraft } from './storage/topic-types';
539
+ export type {
540
+ DraftTopic,
541
+ PublishedTopic,
542
+ PublishProjection,
543
+ TopicStatus,
544
+ TopicAsset,
545
+ TopicCreator,
546
+ } from './storage/topic-types';
547
+
535
548
  // NOTE: The following require Node.js dependencies and are NOT exported in the main bundle.
536
549
  // Use '@principal-ai/principal-view-core/node' for Node.js-specific functionality:
537
550
  //
package/src/node.ts CHANGED
@@ -13,6 +13,30 @@
13
13
  // Export all types (safe in all environments)
14
14
  export * from './types';
15
15
 
16
+ // File-per-topic store (~/.principal/topics) — node:fs only. The browser-safe
17
+ // topic types it reads/writes are also re-exported here for node consumers.
18
+ export {
19
+ TopicStore,
20
+ PRINCIPAL_DIR,
21
+ TOPICS_DIR,
22
+ LEGACY_TOPICS_BLOB,
23
+ } from './storage/topicStore';
24
+ export type {
25
+ TopicIndexEntry,
26
+ TopicCreate,
27
+ TopicUpdate,
28
+ MigrationResult,
29
+ } from './storage/topicStore';
30
+ export { publishedFromDraft } from './storage/topic-types';
31
+ export type {
32
+ DraftTopic,
33
+ PublishedTopic,
34
+ PublishProjection,
35
+ TopicStatus,
36
+ TopicAsset,
37
+ TopicCreator,
38
+ } from './storage/topic-types';
39
+
16
40
  // Export core classes (Node.js processing)
17
41
  export { EventProcessor } from './EventProcessor';
18
42
  export type { ProcessingResult } from './EventProcessor';