seekstone 0.24.0 → 0.24.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/dist/index.js CHANGED
@@ -589,11 +589,38 @@ function extractTasks(raw) {
589
589
  import { z } from "zod";
590
590
 
591
591
  // src/atomic-write.ts
592
- import { rename, writeFile } from "fs/promises";
592
+ import { rename, rm, writeFile } from "fs/promises";
593
593
  async function atomicWrite(absPath, content) {
594
594
  const tmpPath = `${absPath}.seekstone-tmp`;
595
595
  await writeFile(tmpPath, content, "utf8");
596
- await rename(tmpPath, absPath);
596
+ try {
597
+ await renameWithRetry(tmpPath, absPath);
598
+ } catch (err) {
599
+ await rm(tmpPath, { force: true }).catch(() => {
600
+ });
601
+ throw err;
602
+ }
603
+ }
604
+ var TRANSIENT_WINDOWS_CODES = /* @__PURE__ */ new Set(["EPERM", "EACCES", "EBUSY"]);
605
+ var RETRY_DELAYS_MS = [10, 20, 40, 80, 160, 320, 640];
606
+ async function renameWithRetry(from, to, {
607
+ platform = process.platform,
608
+ renameFn = rename,
609
+ sleep = (ms) => new Promise((r) => setTimeout(r, ms))
610
+ } = {}) {
611
+ for (let attempt = 0; ; attempt++) {
612
+ try {
613
+ await renameFn(from, to);
614
+ return;
615
+ } catch (err) {
616
+ const code = err.code ?? "";
617
+ const delay = RETRY_DELAYS_MS[attempt];
618
+ if (platform !== "win32" || !TRANSIENT_WINDOWS_CODES.has(code) || delay === void 0) {
619
+ throw err;
620
+ }
621
+ await sleep(delay);
622
+ }
623
+ }
597
624
  }
598
625
 
599
626
  // src/content-hash.ts
@@ -618,7 +645,7 @@ function assertHashMatch(raw, prevHash, path2) {
618
645
 
619
646
  // src/journal.ts
620
647
  import { timingSafeEqual } from "crypto";
621
- import { mkdir, open, readdir, readFile, rename as rename2, rm, stat } from "fs/promises";
648
+ import { mkdir, open, readdir, readFile, rename as rename2, rm as rm2, stat } from "fs/promises";
622
649
  import { join } from "path";
623
650
  var DEFAULT_MAX_BYTES = 50 * 1e6;
624
651
  var DEFAULT_MAX_ENTRIES = 1e3;
@@ -852,7 +879,7 @@ var Journal = class _Journal {
852
879
  const n = (refs.get(f.preHash) ?? 1) - 1;
853
880
  refs.set(f.preHash, n);
854
881
  if (n > 0 || !this.blobSizes.has(f.preHash)) continue;
855
- await rm(join(this.blobDir, f.preHash), { force: true });
882
+ await rm2(join(this.blobDir, f.preHash), { force: true });
856
883
  this.totalBytes -= this.blobSizes.get(f.preHash) ?? 0;
857
884
  this.blobSizes.delete(f.preHash);
858
885
  }
@@ -1734,7 +1761,7 @@ ${stringifyYaml(input.frontmatter, { lineWidth: 0 })}---
1734
1761
  }
1735
1762
 
1736
1763
  // src/tools/delete_note.ts
1737
- import { access as access2, mkdir as mkdir3, readFile as readFile4, rename as rename3, rm as rm2 } from "fs/promises";
1764
+ import { access as access2, mkdir as mkdir3, readFile as readFile4, rename as rename3, rm as rm3 } from "fs/promises";
1738
1765
  import { basename as basename2, extname as extname2, join as join2 } from "path";
1739
1766
  import { z as z5 } from "zod";
1740
1767
 
@@ -1808,7 +1835,7 @@ async function deleteNote(ctx2, rawInput) {
1808
1835
  await journalWrite(ctx2, "delete_note", input.path, raw, null);
1809
1836
  let trashedTo;
1810
1837
  if (input.permanent) {
1811
- await rm2(absPath);
1838
+ await rm3(absPath);
1812
1839
  } else {
1813
1840
  await mkdir3(join2(ctx2.vaultRoot, ".trash"), { recursive: true });
1814
1841
  trashedTo = await freeTrashPath(ctx2.vaultRoot, basename2(input.path));
@@ -3275,7 +3302,7 @@ function resolveNote(ctx2, input) {
3275
3302
  }
3276
3303
 
3277
3304
  // src/tools/undo_write.ts
3278
- import { mkdir as mkdir6, readFile as readFile13, rm as rm3 } from "fs/promises";
3305
+ import { mkdir as mkdir6, readFile as readFile13, rm as rm4 } from "fs/promises";
3279
3306
  import { dirname as dirname4 } from "path";
3280
3307
  import { z as z23 } from "zod";
3281
3308
  var UndoWriteInput = z23.object({
@@ -3358,7 +3385,7 @@ async function undoWrite(ctx2, rawInput) {
3358
3385
  const abs = resolveVaultPath(ctx2, f.path);
3359
3386
  const pre = preimages.get(f.path) ?? null;
3360
3387
  if (pre === null) {
3361
- await rm3(abs, { force: true });
3388
+ await rm4(abs, { force: true });
3362
3389
  removeNoteBacklinks(ctx2, f.path);
3363
3390
  if (ctx2.notes.has(f.path)) {
3364
3391
  ctx2.index.discard(f.path);
@@ -3990,6 +4017,25 @@ async function walkVault(vaultRoot2, opts = {}) {
3990
4017
  import MiniSearch from "minisearch";
3991
4018
  async function buildIndex(vaultRoot2, scope) {
3992
4019
  const t0 = Date.now();
4020
+ const entries = await walkVault(vaultRoot2, scope);
4021
+ const files = [];
4022
+ await Promise.all(
4023
+ entries.filter((e) => e.kind === "note").map(async (entry) => {
4024
+ try {
4025
+ const raw = await readFile15(entry.absPath, "utf8");
4026
+ files.push({
4027
+ relPath: entry.relPath,
4028
+ raw,
4029
+ sizeBytes: entry.sizeBytes,
4030
+ mtimeMs: entry.mtimeMs
4031
+ });
4032
+ } catch {
4033
+ }
4034
+ })
4035
+ );
4036
+ return { ...indexNotes(files), buildMs: Date.now() - t0 };
4037
+ }
4038
+ function indexNotes(files) {
3993
4039
  const index2 = new MiniSearch({
3994
4040
  idField: "id",
3995
4041
  fields: ["title", "body", "tags", "fmKeys"],
@@ -4000,40 +4046,37 @@ async function buildIndex(vaultRoot2, scope) {
4000
4046
  prefix: true
4001
4047
  }
4002
4048
  });
4003
- const entries = await walkVault(vaultRoot2, scope);
4004
- const noteEntries = entries.filter((e) => e.kind === "note");
4005
4049
  const docs = [];
4006
4050
  const notes2 = /* @__PURE__ */ new Map();
4007
- await Promise.all(
4008
- noteEntries.map(async (entry) => {
4009
- try {
4010
- const raw = await readFile15(entry.absPath, "utf8");
4011
- const fm = parseFrontmatter(raw);
4012
- const inlineTags = extractInlineTags(fm.body);
4013
- const fmTags = frontmatterTags(fm.data);
4014
- const allTags = [.../* @__PURE__ */ new Set([...inlineTags, ...fmTags])];
4015
- const title = typeof fm.data?.title === "string" && fm.data.title ? fm.data.title : basename3(entry.relPath, extname4(entry.relPath));
4016
- const doc = {
4017
- id: entry.relPath,
4018
- title,
4019
- body: fm.body,
4020
- tags: allTags.join(" "),
4021
- fmKeys: fm.keys.join(" "),
4022
- fm: fm.data,
4023
- raw,
4024
- tasks: extractTasks(raw),
4025
- sizeBytes: entry.sizeBytes,
4026
- mtimeMs: entry.mtimeMs
4027
- };
4028
- docs.push(doc);
4029
- notes2.set(entry.relPath, doc);
4030
- } catch {
4031
- }
4032
- })
4051
+ const sorted = [...files].sort(
4052
+ (a, b) => a.relPath < b.relPath ? -1 : a.relPath > b.relPath ? 1 : 0
4033
4053
  );
4054
+ for (const file of sorted) {
4055
+ try {
4056
+ const fm = parseFrontmatter(file.raw);
4057
+ const inlineTags = extractInlineTags(fm.body);
4058
+ const fmTags = frontmatterTags(fm.data);
4059
+ const allTags = [.../* @__PURE__ */ new Set([...inlineTags, ...fmTags])];
4060
+ const title = typeof fm.data?.title === "string" && fm.data.title ? fm.data.title : basename3(file.relPath, extname4(file.relPath));
4061
+ const doc = {
4062
+ id: file.relPath,
4063
+ title,
4064
+ body: fm.body,
4065
+ tags: allTags.join(" "),
4066
+ fmKeys: fm.keys.join(" "),
4067
+ fm: fm.data,
4068
+ raw: file.raw,
4069
+ tasks: extractTasks(file.raw),
4070
+ sizeBytes: file.sizeBytes,
4071
+ mtimeMs: file.mtimeMs
4072
+ };
4073
+ docs.push(doc);
4074
+ notes2.set(file.relPath, doc);
4075
+ } catch {
4076
+ }
4077
+ }
4034
4078
  index2.addAll(docs);
4035
- const backlinks2 = buildBacklinks(notes2);
4036
- return { index: index2, notes: notes2, backlinks: backlinks2, buildMs: Date.now() - t0 };
4079
+ return { index: index2, notes: notes2, backlinks: buildBacklinks(notes2) };
4037
4080
  }
4038
4081
  function buildBacklinks(notes2) {
4039
4082
  const result = /* @__PURE__ */ new Map();
@@ -6279,7 +6322,7 @@ function startWatcher(ctx2, log2, opts) {
6279
6322
  }
6280
6323
 
6281
6324
  // src/index.ts
6282
- var VERSION = true ? "0.24.0" : "0.0.0-dev";
6325
+ var VERSION = true ? "0.24.2" : "0.0.0-dev";
6283
6326
  var intent = parseCliIntent(process.argv.slice(2));
6284
6327
  if (intent === "version") {
6285
6328
  process.stdout.write(`${VERSION}