logdig 0.2.1 → 0.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logdig",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Turn saved Pi sessions into a work journal in your Obsidian daily notes.",
5
5
  "license": "MIT",
6
6
  "author": "Soleone",
package/src/journal.js CHANGED
@@ -212,6 +212,7 @@ export async function listJournaledSessions(cacheDirectory) {
212
212
  time: metadata.time,
213
213
  sourceFingerprint: metadata.sourceFingerprint,
214
214
  cacheFingerprint: metadata.cacheFingerprint,
215
+ project: metadata.project,
215
216
  blockId: metadata.blockId,
216
217
  blockStart: metadata.blockStart,
217
218
  continuationOf: metadata.continuationOf,
@@ -336,6 +337,18 @@ function updateContinuationReference(markdown, continuationOf) {
336
337
  return header + (continuationOf ? `\nContinues [[${continuationOf}|previous entry]].\n` : "") + body;
337
338
  }
338
339
 
340
+ function sourceFingerprintForProject(session, project) {
341
+ const events = [...(session.context || []), ...(session.events || [])];
342
+ if (events.some((event) => event.project !== session.project)) return undefined;
343
+ const relabel = (items) => items.map((event) => ({ ...event, project }));
344
+ return hashValue([
345
+ project,
346
+ session.timezone,
347
+ relabel(session.context || []),
348
+ relabel(session.events || []),
349
+ ]);
350
+ }
351
+
339
352
  export async function inspectSessionSummary(modelClient, cacheDirectory, session) {
340
353
  const sourceFingerprint = hashValue([session.project, session.timezone, session.context || [], session.events]);
341
354
  // Keep generation policy separate from evidence so model and thinking changes can
@@ -348,7 +361,20 @@ export async function inspectSessionSummary(modelClient, cacheDirectory, session
348
361
  const existing = cached && parseSessionNote(cached);
349
362
 
350
363
  const reused = existing?.cacheFingerprint === cacheFingerprint;
351
- return { sessionPath, sourceFingerprint, cacheFingerprint, reused, continuationOf: existing?.continuationOf, summary: reused ? existing.summary : undefined };
364
+ const previousSourceFingerprint = existing?.project && existing.project !== session.project
365
+ ? sourceFingerprintForProject(session, existing.project)
366
+ : undefined;
367
+ const relabeledReuse = !reused && previousSourceFingerprint === existing?.sourceFingerprint &&
368
+ existing?.cacheFingerprint === hashValue([SUMMARY_VERSION, JOURNAL_SYSTEM_PROMPT, CHUNK_LIMIT, previousSourceFingerprint, policy]);
369
+ const reusable = reused || relabeledReuse;
370
+ return {
371
+ sessionPath,
372
+ sourceFingerprint: reusable ? existing.sourceFingerprint : sourceFingerprint,
373
+ cacheFingerprint: reusable ? existing.cacheFingerprint : cacheFingerprint,
374
+ reused: reusable,
375
+ continuationOf: existing?.continuationOf,
376
+ summary: reusable ? existing.summary : undefined,
377
+ };
352
378
  }
353
379
 
354
380
  export async function saveSessionSummary(modelClient, cacheDirectory, session, { onGenerate } = {}) {
@@ -661,7 +687,10 @@ export async function inspectDailyEntry(dailyDirectory, heading, entry, journale
661
687
  const oldBlocks = locations.blocks.filter((block) => block.id !== id);
662
688
  const sameIdBlocks = locations.blocks.filter((block) => block.id === id);
663
689
  const missingSnapshot = entry.blockId && present && !snapshots.get(entry.sessionId)?.some((version) => version.id === id);
664
- const updated = Boolean(missingSnapshot) || oldBlocks.length > 0 || sameIdBlocks.length > 1 || (!present && sameIdBlocks.length > 0);
690
+ const projectChanged = locations.blocks.some((block) =>
691
+ block.snapshot?.project && entry.project && block.snapshot.project !== entry.project,
692
+ );
693
+ const updated = Boolean(missingSnapshot) || oldBlocks.length > 0 || sameIdBlocks.length > 1 || (!present && sameIdBlocks.length > 0) || projectChanged;
665
694
  return {
666
695
  dailyPath,
667
696
  existing,
@@ -673,14 +702,19 @@ export async function inspectDailyEntry(dailyDirectory, heading, entry, journale
673
702
  };
674
703
  }
675
704
 
705
+ function updateSnapshotProject(markdown, project) {
706
+ if (!project || frontmatter(markdown).project === project) return markdown;
707
+ return markdown.replace(/^project: .*$/m, `project: ${frontmatterValue(project)}`);
708
+ }
709
+
676
710
  async function updateEntrySnapshot(entryPath, entry, createIfMissing) {
677
711
  const snapshot = await readMarkdownIfPresent(entryPath);
678
712
  if (!snapshot) {
679
713
  if (createIfMissing) await writeAtomically(entryPath, await readFile(entry.sessionPath, "utf8"));
680
714
  return;
681
715
  }
682
- if (!entry.metrics) return;
683
- const enriched = enrichSessionNote(snapshot, entry.sourceFingerprint, entry.metrics);
716
+ const withProject = updateSnapshotProject(snapshot, entry.project);
717
+ const enriched = entry.metrics ? enrichSessionNote(withProject, entry.sourceFingerprint, entry.metrics) : withProject;
684
718
  if (enriched !== snapshot) await writeAtomically(entryPath, enriched);
685
719
  }
686
720
 
@@ -243,8 +243,11 @@ export async function writeSessions(modelClient, sessions, settings, range = {})
243
243
  dailyPath: dailyEntry.dailyPath,
244
244
  });
245
245
  // Dry-run predictions stay in plannedSnapshots, never in the real index.
246
- if (!range.dryRun && !versions.some((version) => version.id === entryId)) {
247
- versions.push({ ...entry, id: entryId, summary: cached.summary });
246
+ if (!range.dryRun) {
247
+ const versionIndex = versions.findIndex((version) => version.id === entryId);
248
+ const updatedVersion = { ...entry, id: entryId, summary: cached.summary };
249
+ if (versionIndex === -1) versions.push(updatedVersion);
250
+ else versions[versionIndex] = updatedVersion;
248
251
  }
249
252
  dates.add(block.date);
250
253
  dailyPaths.add(dailyEntry.dailyPath);