seekstone 0.23.0 → 0.24.1
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/README.md +1 -0
- package/dist/index.js +211 -55
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -156,6 +156,7 @@ Every write tool (`append_note`, `patch_note`, `patch_frontmatter`, `replace_in_
|
|
|
156
156
|
| `SEEKSTONE_WATCH_POLL_INTERVAL` | no | Stat-poll interval in ms (default `10000`). Only used with `SEEKSTONE_WATCH_POLL=1`. Lower = faster pickup of external edits, higher CPU. |
|
|
157
157
|
| `SEEKSTONE_LOG_MAX_SIZE` | no | Log-rotation threshold for `SEEKSTONE_LOG_FILE` (e.g. `10mb`; default 5 MB). |
|
|
158
158
|
| `SEEKSTONE_READ_ONLY` | no | Set to `1` to run read-only: the 11 write tools are unregistered entirely (and rejected if called anyway), so the session provably cannot modify your vault. |
|
|
159
|
+
| `SEEKSTONE_READ_PATHS` | no | Comma-separated vault-relative globs (e.g. `Projects/**,Reference/**`, or `!Journal/**` for everything except `Journal/`). Files outside them are invisible to the agent: never indexed, never in any tool output, and a direct read gets the same not-found error as a missing file. Writes are also limited to this scope. |
|
|
159
160
|
| `SEEKSTONE_WRITE_PATHS` | no | Comma-separated vault-relative globs (e.g. `journal/**,inbox/*.md`). Writes are permitted only under matching paths; the rest of the vault stays read-only. |
|
|
160
161
|
| `SEEKSTONE_HISTORY` | no | Set to `0` to disable the write journal (default on). With it on, every write tool stores the pre-image of each file it touches under `<vault>/.seekstone/history/` so `undo_write` can restore it byte-for-byte. |
|
|
161
162
|
| `SEEKSTONE_HISTORY_MAX_SIZE` | no | Cap on stored pre-images (e.g. `100mb`; default 50 MB). Oldest entries are evicted first and then show `undoable: false` in `list_writes` — never silently. |
|
package/dist/index.js
CHANGED
|
@@ -378,6 +378,9 @@ function classifyError(message) {
|
|
|
378
378
|
if (message.startsWith("Server is read-only")) {
|
|
379
379
|
return { outcome: "policy_denied", policy: "read_only", error: "read_only" };
|
|
380
380
|
}
|
|
381
|
+
if (message.startsWith("Write not permitted") && message.includes("SEEKSTONE_READ_PATHS")) {
|
|
382
|
+
return { outcome: "policy_denied", policy: "read_paths", error: "read_paths" };
|
|
383
|
+
}
|
|
381
384
|
if (message.startsWith("Write not permitted")) {
|
|
382
385
|
return { outcome: "policy_denied", policy: "write_paths", error: "write_paths" };
|
|
383
386
|
}
|
|
@@ -586,11 +589,38 @@ function extractTasks(raw) {
|
|
|
586
589
|
import { z } from "zod";
|
|
587
590
|
|
|
588
591
|
// src/atomic-write.ts
|
|
589
|
-
import { rename, writeFile } from "fs/promises";
|
|
592
|
+
import { rename, rm, writeFile } from "fs/promises";
|
|
590
593
|
async function atomicWrite(absPath, content) {
|
|
591
594
|
const tmpPath = `${absPath}.seekstone-tmp`;
|
|
592
595
|
await writeFile(tmpPath, content, "utf8");
|
|
593
|
-
|
|
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
|
+
}
|
|
594
624
|
}
|
|
595
625
|
|
|
596
626
|
// src/content-hash.ts
|
|
@@ -615,7 +645,7 @@ function assertHashMatch(raw, prevHash, path2) {
|
|
|
615
645
|
|
|
616
646
|
// src/journal.ts
|
|
617
647
|
import { timingSafeEqual } from "crypto";
|
|
618
|
-
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";
|
|
619
649
|
import { join } from "path";
|
|
620
650
|
var DEFAULT_MAX_BYTES = 50 * 1e6;
|
|
621
651
|
var DEFAULT_MAX_ENTRIES = 1e3;
|
|
@@ -730,9 +760,17 @@ var Journal = class _Journal {
|
|
|
730
760
|
};
|
|
731
761
|
}
|
|
732
762
|
/** Newest-first rows for `list_writes`. */
|
|
763
|
+
/**
|
|
764
|
+
* Newest-first metadata rows. `visible` hides entries that touched any path
|
|
765
|
+
* it rejects (the read scope, SHA-291 D3); hidden entries don't count
|
|
766
|
+
* toward `total` either.
|
|
767
|
+
*/
|
|
733
768
|
list(opts = {}) {
|
|
734
769
|
const limit = opts.limit ?? 20;
|
|
735
|
-
const
|
|
770
|
+
const { path: path2, visible } = opts;
|
|
771
|
+
const filtered = path2 === void 0 && visible === void 0 ? this.entries : this.entries.filter(
|
|
772
|
+
(e) => (path2 === void 0 || e.files.some((f) => f.path === path2)) && (visible === void 0 || e.files.every((f) => visible(f.path)))
|
|
773
|
+
);
|
|
736
774
|
const writes = [];
|
|
737
775
|
for (let i = filtered.length - 1; i >= 0 && writes.length < limit; i--) {
|
|
738
776
|
const e = filtered[i];
|
|
@@ -766,10 +804,11 @@ var Journal = class _Journal {
|
|
|
766
804
|
* undo/redo); an undo that was itself undone re-exposes its target. Redo is
|
|
767
805
|
* always explicit: `undo_write({ seq: <the undo's seq> })`.
|
|
768
806
|
*/
|
|
769
|
-
latestUndoable() {
|
|
807
|
+
latestUndoable(visible) {
|
|
770
808
|
const cancelled = /* @__PURE__ */ new Set();
|
|
771
809
|
for (let i = this.entries.length - 1; i >= 0; i--) {
|
|
772
810
|
const e = this.entries[i];
|
|
811
|
+
if (visible && !e.files.every((f) => visible(f.path))) continue;
|
|
773
812
|
if (cancelled.has(e.seq)) continue;
|
|
774
813
|
if (e.undoOf !== void 0) {
|
|
775
814
|
cancelled.add(e.undoOf);
|
|
@@ -840,7 +879,7 @@ var Journal = class _Journal {
|
|
|
840
879
|
const n = (refs.get(f.preHash) ?? 1) - 1;
|
|
841
880
|
refs.set(f.preHash, n);
|
|
842
881
|
if (n > 0 || !this.blobSizes.has(f.preHash)) continue;
|
|
843
|
-
await
|
|
882
|
+
await rm2(join(this.blobDir, f.preHash), { force: true });
|
|
844
883
|
this.totalBytes -= this.blobSizes.get(f.preHash) ?? 0;
|
|
845
884
|
this.blobSizes.delete(f.preHash);
|
|
846
885
|
}
|
|
@@ -880,42 +919,119 @@ async function journalWrite(ctx2, tool, path2, pre, post) {
|
|
|
880
919
|
|
|
881
920
|
// src/policy.ts
|
|
882
921
|
import picomatch from "picomatch";
|
|
922
|
+
function splitGlobs(raw) {
|
|
923
|
+
const out = [];
|
|
924
|
+
let depth = 0;
|
|
925
|
+
let cur = "";
|
|
926
|
+
for (const ch of raw ?? "") {
|
|
927
|
+
if (ch === "{") depth++;
|
|
928
|
+
else if (ch === "}" && depth > 0) depth--;
|
|
929
|
+
if (ch === "," && depth === 0) {
|
|
930
|
+
out.push(cur);
|
|
931
|
+
cur = "";
|
|
932
|
+
} else {
|
|
933
|
+
cur += ch;
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
out.push(cur);
|
|
937
|
+
return out.map((g) => g.trim()).filter((g) => g.length > 0);
|
|
938
|
+
}
|
|
883
939
|
function parseWritePolicy(env) {
|
|
884
940
|
const ro = (env.SEEKSTONE_READ_ONLY ?? "").toLowerCase();
|
|
885
|
-
const
|
|
886
|
-
const
|
|
887
|
-
|
|
941
|
+
const policy2 = { readOnly: ro === "1" || ro === "true" };
|
|
942
|
+
const writeGlobs = splitGlobs(env.SEEKSTONE_WRITE_PATHS);
|
|
943
|
+
if (writeGlobs.length > 0) policy2.writeGlobs = writeGlobs;
|
|
944
|
+
const readGlobs = splitGlobs(env.SEEKSTONE_READ_PATHS);
|
|
945
|
+
if (readGlobs.length > 0) policy2.readGlobs = readGlobs;
|
|
946
|
+
return policy2;
|
|
888
947
|
}
|
|
889
948
|
function normalizeRel(relPath) {
|
|
890
949
|
let p = relPath.replaceAll("\\", "/");
|
|
891
950
|
while (p.startsWith("./")) p = p.slice(2);
|
|
892
951
|
return p;
|
|
893
952
|
}
|
|
953
|
+
function splitGlobSet(globs) {
|
|
954
|
+
const include = [];
|
|
955
|
+
const exclude = [];
|
|
956
|
+
for (const g of globs) {
|
|
957
|
+
if (g.startsWith("!")) {
|
|
958
|
+
const rest = g.slice(1).trim();
|
|
959
|
+
if (rest.length > 0) exclude.push(rest);
|
|
960
|
+
} else {
|
|
961
|
+
include.push(g);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
return { include: include.length > 0 ? include : ["**"], exclude };
|
|
965
|
+
}
|
|
966
|
+
var matchers = /* @__PURE__ */ new WeakMap();
|
|
967
|
+
function matcherFor(globs) {
|
|
968
|
+
let m = matchers.get(globs);
|
|
969
|
+
if (m === void 0) {
|
|
970
|
+
const { include, exclude } = splitGlobSet(globs);
|
|
971
|
+
const inc = picomatch(include, { dot: true });
|
|
972
|
+
const exc = exclude.length > 0 ? picomatch(exclude, { dot: true }) : void 0;
|
|
973
|
+
m = exc ? (p) => inc(p) && !exc(p) : inc;
|
|
974
|
+
matchers.set(globs, m);
|
|
975
|
+
}
|
|
976
|
+
return m;
|
|
977
|
+
}
|
|
978
|
+
function isReadable(policy2, relPath) {
|
|
979
|
+
if (!policy2.readGlobs) return true;
|
|
980
|
+
return matcherFor(policy2.readGlobs)(normalizeRel(relPath));
|
|
981
|
+
}
|
|
894
982
|
function isWritable(policy2, relPath) {
|
|
895
983
|
if (policy2.readOnly) return false;
|
|
984
|
+
if (!isReadable(policy2, relPath)) return false;
|
|
896
985
|
if (!policy2.writeGlobs) return true;
|
|
897
|
-
return
|
|
986
|
+
return matcherFor(policy2.writeGlobs)(normalizeRel(relPath));
|
|
898
987
|
}
|
|
899
988
|
function assertWritable(policy2, relPath) {
|
|
900
989
|
if (policy2.readOnly) {
|
|
901
990
|
throw new Error("Server is read-only (SEEKSTONE_READ_ONLY=1); write tools are disabled.");
|
|
902
991
|
}
|
|
992
|
+
if (!isReadable(policy2, relPath)) {
|
|
993
|
+
throw new Error(
|
|
994
|
+
`Write not permitted: "${relPath}" is outside SEEKSTONE_READ_PATHS (${policy2.readGlobs?.join(", ")}).`
|
|
995
|
+
);
|
|
996
|
+
}
|
|
903
997
|
if (!isWritable(policy2, relPath)) {
|
|
904
998
|
throw new Error(
|
|
905
999
|
`Write not permitted: "${relPath}" is outside SEEKSTONE_WRITE_PATHS (${policy2.writeGlobs?.join(", ")}).`
|
|
906
1000
|
);
|
|
907
1001
|
}
|
|
908
1002
|
}
|
|
1003
|
+
function readScopeWalk(policy2) {
|
|
1004
|
+
return policy2.readGlobs ? splitGlobSet(policy2.readGlobs) : void 0;
|
|
1005
|
+
}
|
|
909
1006
|
|
|
910
1007
|
// src/vault-path.ts
|
|
911
|
-
import { resolve, sep } from "path";
|
|
912
|
-
function
|
|
1008
|
+
import { relative, resolve, sep } from "path";
|
|
1009
|
+
function containVaultPath(vaultRoot2, inputPath) {
|
|
913
1010
|
const abs = resolve(vaultRoot2, inputPath);
|
|
914
1011
|
if (abs !== vaultRoot2 && !abs.startsWith(vaultRoot2 + sep)) {
|
|
915
1012
|
throw new Error(`Path outside vault: ${inputPath}`);
|
|
916
1013
|
}
|
|
917
1014
|
return abs;
|
|
918
1015
|
}
|
|
1016
|
+
function resolveVaultPath(ctx2, inputPath) {
|
|
1017
|
+
const abs = containVaultPath(ctx2.vaultRoot, inputPath);
|
|
1018
|
+
if (ctx2.policy.readGlobs && !isReadable(ctx2.policy, vaultRelative(ctx2.vaultRoot, abs))) {
|
|
1019
|
+
throw notFoundError(abs);
|
|
1020
|
+
}
|
|
1021
|
+
return abs;
|
|
1022
|
+
}
|
|
1023
|
+
function vaultRelative(vaultRoot2, abs) {
|
|
1024
|
+
return relative(vaultRoot2, abs).split(sep).join("/");
|
|
1025
|
+
}
|
|
1026
|
+
function notFoundError(absPath) {
|
|
1027
|
+
const err = new Error(
|
|
1028
|
+
`ENOENT: no such file or directory, open '${absPath}'`
|
|
1029
|
+
);
|
|
1030
|
+
err.code = "ENOENT";
|
|
1031
|
+
err.syscall = "open";
|
|
1032
|
+
err.path = absPath;
|
|
1033
|
+
return err;
|
|
1034
|
+
}
|
|
919
1035
|
|
|
920
1036
|
// src/tools/append_note.ts
|
|
921
1037
|
var AppendNoteInput = z.object({
|
|
@@ -928,8 +1044,8 @@ var AppendNoteInput = z.object({
|
|
|
928
1044
|
)
|
|
929
1045
|
});
|
|
930
1046
|
async function appendNote(ctx2, input) {
|
|
931
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
932
1047
|
assertWritable(ctx2.policy, input.path);
|
|
1048
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
933
1049
|
const original = await readFile2(absPath, "utf8");
|
|
934
1050
|
if (input.prevHash !== void 0) assertHashMatch(original, input.prevHash, input.path);
|
|
935
1051
|
const fm = parseFrontmatter(original);
|
|
@@ -1595,8 +1711,8 @@ var CreateNoteInput = z4.object({
|
|
|
1595
1711
|
});
|
|
1596
1712
|
async function createNote(ctx2, rawInput) {
|
|
1597
1713
|
const input = CreateNoteInput.parse(rawInput);
|
|
1598
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
1599
1714
|
assertWritable(ctx2.policy, input.path);
|
|
1715
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
1600
1716
|
let existing = null;
|
|
1601
1717
|
if (!input.overwrite) {
|
|
1602
1718
|
try {
|
|
@@ -1645,7 +1761,7 @@ ${stringifyYaml(input.frontmatter, { lineWidth: 0 })}---
|
|
|
1645
1761
|
}
|
|
1646
1762
|
|
|
1647
1763
|
// src/tools/delete_note.ts
|
|
1648
|
-
import { access as access2, mkdir as mkdir3, readFile as readFile4, rename as rename3, rm as
|
|
1764
|
+
import { access as access2, mkdir as mkdir3, readFile as readFile4, rename as rename3, rm as rm3 } from "fs/promises";
|
|
1649
1765
|
import { basename as basename2, extname as extname2, join as join2 } from "path";
|
|
1650
1766
|
import { z as z5 } from "zod";
|
|
1651
1767
|
|
|
@@ -1712,14 +1828,14 @@ async function freeTrashPath(vaultRoot2, noteBase) {
|
|
|
1712
1828
|
}
|
|
1713
1829
|
async function deleteNote(ctx2, rawInput) {
|
|
1714
1830
|
const input = DeleteNoteInput.parse(rawInput);
|
|
1715
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
1716
1831
|
assertWritable(ctx2.policy, input.path);
|
|
1832
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
1717
1833
|
const raw = await readFile4(absPath, "utf8");
|
|
1718
1834
|
if (input.prevHash !== void 0) assertHashMatch(raw, input.prevHash, input.path);
|
|
1719
1835
|
await journalWrite(ctx2, "delete_note", input.path, raw, null);
|
|
1720
1836
|
let trashedTo;
|
|
1721
1837
|
if (input.permanent) {
|
|
1722
|
-
await
|
|
1838
|
+
await rm3(absPath);
|
|
1723
1839
|
} else {
|
|
1724
1840
|
await mkdir3(join2(ctx2.vaultRoot, ".trash"), { recursive: true });
|
|
1725
1841
|
trashedTo = await freeTrashPath(ctx2.vaultRoot, basename2(input.path));
|
|
@@ -1748,7 +1864,7 @@ var GetBacklinksInput = z6.object({
|
|
|
1748
1864
|
});
|
|
1749
1865
|
var EXCERPT_MAX = 200;
|
|
1750
1866
|
function getBacklinks(ctx2, input) {
|
|
1751
|
-
|
|
1867
|
+
containVaultPath(ctx2.vaultRoot, input.path);
|
|
1752
1868
|
const includeContext = input.includeContext ?? true;
|
|
1753
1869
|
const limit = input.limit ?? 50;
|
|
1754
1870
|
const refs = ctx2.backlinks.get(input.path) ?? [];
|
|
@@ -1778,7 +1894,7 @@ var GetLinksInput = z7.object({
|
|
|
1778
1894
|
path: z7.string().describe("Vault-relative path to the note.")
|
|
1779
1895
|
});
|
|
1780
1896
|
function getLinks(ctx2, input) {
|
|
1781
|
-
|
|
1897
|
+
containVaultPath(ctx2.vaultRoot, input.path);
|
|
1782
1898
|
const note = ctx2.notes.get(input.path);
|
|
1783
1899
|
if (note === void 0) throw new Error(`Note not found: ${input.path}`);
|
|
1784
1900
|
const rawLinks = extractLinksWithLines(note.raw);
|
|
@@ -1936,8 +2052,11 @@ var ListWritesInput = z11.object({
|
|
|
1936
2052
|
function listWrites(ctx2, rawInput) {
|
|
1937
2053
|
const input = ListWritesInput.parse(rawInput);
|
|
1938
2054
|
if (!ctx2.journal) return { writes: [], total: 0, disabled: true };
|
|
1939
|
-
const opts = {
|
|
2055
|
+
const opts = {
|
|
2056
|
+
limit: input.limit
|
|
2057
|
+
};
|
|
1940
2058
|
if (input.path !== void 0) opts.path = input.path;
|
|
2059
|
+
if (ctx2.policy.readGlobs) opts.visible = (p) => isReadable(ctx2.policy, p);
|
|
1941
2060
|
return ctx2.journal.list(opts);
|
|
1942
2061
|
}
|
|
1943
2062
|
|
|
@@ -2053,10 +2172,10 @@ var MoveNoteInput = z12.object({
|
|
|
2053
2172
|
});
|
|
2054
2173
|
async function moveNote(ctx2, rawInput) {
|
|
2055
2174
|
const input = MoveNoteInput.parse(rawInput);
|
|
2056
|
-
const absFrom = resolveVaultPath(ctx2.vaultRoot, input.from);
|
|
2057
|
-
const absTo = resolveVaultPath(ctx2.vaultRoot, input.to);
|
|
2058
2175
|
assertWritable(ctx2.policy, input.from);
|
|
2059
2176
|
assertWritable(ctx2.policy, input.to);
|
|
2177
|
+
const absFrom = resolveVaultPath(ctx2, input.from);
|
|
2178
|
+
const absTo = resolveVaultPath(ctx2, input.to);
|
|
2060
2179
|
let raw;
|
|
2061
2180
|
try {
|
|
2062
2181
|
raw = await readFile5(absFrom, "utf8");
|
|
@@ -2207,7 +2326,7 @@ var OutlineNoteInput = z13.object({
|
|
|
2207
2326
|
includeSizes: z13.boolean().default(false).describe("Include per-section character length in each heading entry. Default false.")
|
|
2208
2327
|
});
|
|
2209
2328
|
async function outlineNote(ctx2, input) {
|
|
2210
|
-
const absPath = resolveVaultPath(ctx2
|
|
2329
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2211
2330
|
const raw = await readFile6(absPath, "utf8");
|
|
2212
2331
|
return buildOutline(raw, {
|
|
2213
2332
|
includeBlocks: input.includeBlocks,
|
|
@@ -2229,8 +2348,8 @@ var PatchFrontmatterInput = z14.object({
|
|
|
2229
2348
|
)
|
|
2230
2349
|
});
|
|
2231
2350
|
async function patchFrontmatter(ctx2, input) {
|
|
2232
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
2233
2351
|
assertWritable(ctx2.policy, input.path);
|
|
2352
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2234
2353
|
const original = await readFile7(absPath, "utf8");
|
|
2235
2354
|
if (input.prevHash !== void 0) assertHashMatch(original, input.prevHash, input.path);
|
|
2236
2355
|
const fm = parseFrontmatter(original);
|
|
@@ -2322,8 +2441,8 @@ function lineStart(raw, offset) {
|
|
|
2322
2441
|
return prev === -1 ? 0 : prev + 1;
|
|
2323
2442
|
}
|
|
2324
2443
|
async function patchNote(ctx2, input) {
|
|
2325
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
2326
2444
|
assertWritable(ctx2.policy, input.path);
|
|
2445
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2327
2446
|
const raw = await readFile8(absPath, "utf8");
|
|
2328
2447
|
if (input.prevHash !== void 0) assertHashMatch(raw, input.prevHash, input.path);
|
|
2329
2448
|
const fm = parseFrontmatter(raw);
|
|
@@ -2524,12 +2643,14 @@ async function getPeriodicNote(ctx2, rawInput) {
|
|
|
2524
2643
|
const date = input.date ? new Date(input.date) : /* @__PURE__ */ new Date();
|
|
2525
2644
|
const cfg = await resolveConfig(ctx2.vaultRoot, input.period);
|
|
2526
2645
|
const path2 = resolveNotePath(cfg, date);
|
|
2527
|
-
const abs =
|
|
2646
|
+
const abs = containVaultPath(ctx2.vaultRoot, path2);
|
|
2528
2647
|
let existed = false;
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2648
|
+
if (isReadable(ctx2.policy, path2)) {
|
|
2649
|
+
try {
|
|
2650
|
+
await access3(abs);
|
|
2651
|
+
existed = true;
|
|
2652
|
+
} catch {
|
|
2653
|
+
}
|
|
2533
2654
|
}
|
|
2534
2655
|
if (existed) return { path: path2, existed: true, created: false };
|
|
2535
2656
|
if (!input.createIfMissing) return { path: path2, existed: false, created: false };
|
|
@@ -2538,7 +2659,7 @@ async function getPeriodicNote(ctx2, rawInput) {
|
|
|
2538
2659
|
if (cfg.template) {
|
|
2539
2660
|
try {
|
|
2540
2661
|
const templateAbs = resolveVaultPath(
|
|
2541
|
-
ctx2
|
|
2662
|
+
ctx2,
|
|
2542
2663
|
cfg.template.endsWith(".md") ? cfg.template : `${cfg.template}.md`
|
|
2543
2664
|
);
|
|
2544
2665
|
body = await readFile9(templateAbs, "utf8");
|
|
@@ -2565,8 +2686,8 @@ async function appendPeriodicNote(ctx2, rawInput) {
|
|
|
2565
2686
|
const date = input.date ? new Date(input.date) : /* @__PURE__ */ new Date();
|
|
2566
2687
|
const cfg = await resolveConfig(ctx2.vaultRoot, input.period);
|
|
2567
2688
|
const path2 = resolveNotePath(cfg, date);
|
|
2568
|
-
const abs = resolveVaultPath(ctx2.vaultRoot, path2);
|
|
2569
2689
|
assertWritable(ctx2.policy, path2);
|
|
2690
|
+
const abs = resolveVaultPath(ctx2, path2);
|
|
2570
2691
|
let original = "";
|
|
2571
2692
|
try {
|
|
2572
2693
|
original = await readFile9(abs, "utf8");
|
|
@@ -2765,7 +2886,7 @@ var ReadNoteInput = z18.object({
|
|
|
2765
2886
|
message: "At most one of section, block, or lines may be specified."
|
|
2766
2887
|
});
|
|
2767
2888
|
async function readNote(ctx2, input) {
|
|
2768
|
-
const absPath = resolveVaultPath(ctx2
|
|
2889
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2769
2890
|
const raw = await readFile10(absPath, "utf8");
|
|
2770
2891
|
const noteBytes = Buffer.byteLength(raw, "utf8");
|
|
2771
2892
|
const hash = contentHash(raw);
|
|
@@ -2949,8 +3070,8 @@ function rewriteHeadingLinks(raw, oldHeading, newHeading, matchesTarget) {
|
|
|
2949
3070
|
}
|
|
2950
3071
|
async function renameHeading(ctx2, rawInput) {
|
|
2951
3072
|
const input = RenameHeadingInput.parse(rawInput);
|
|
2952
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
2953
3073
|
assertWritable(ctx2.policy, input.path);
|
|
3074
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2954
3075
|
let raw;
|
|
2955
3076
|
try {
|
|
2956
3077
|
raw = await readFile11(absPath, "utf8");
|
|
@@ -3070,8 +3191,8 @@ function buildRegex(find, opts) {
|
|
|
3070
3191
|
return new RegExp(pattern, flags);
|
|
3071
3192
|
}
|
|
3072
3193
|
async function replaceInNote(ctx2, input) {
|
|
3073
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
3074
3194
|
assertWritable(ctx2.policy, input.path);
|
|
3195
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
3075
3196
|
let re;
|
|
3076
3197
|
try {
|
|
3077
3198
|
re = buildRegex(input.find, {
|
|
@@ -3181,7 +3302,7 @@ function resolveNote(ctx2, input) {
|
|
|
3181
3302
|
}
|
|
3182
3303
|
|
|
3183
3304
|
// src/tools/undo_write.ts
|
|
3184
|
-
import { mkdir as mkdir6, readFile as readFile13, rm as
|
|
3305
|
+
import { mkdir as mkdir6, readFile as readFile13, rm as rm4 } from "fs/promises";
|
|
3185
3306
|
import { dirname as dirname4 } from "path";
|
|
3186
3307
|
import { z as z23 } from "zod";
|
|
3187
3308
|
var UndoWriteInput = z23.object({
|
|
@@ -3198,12 +3319,14 @@ async function undoWrite(ctx2, rawInput) {
|
|
|
3198
3319
|
if (!journal) {
|
|
3199
3320
|
throw new Error("Write journal is disabled (SEEKSTONE_HISTORY=0); nothing to undo.");
|
|
3200
3321
|
}
|
|
3322
|
+
const visible = ctx2.policy.readGlobs ? (p) => isReadable(ctx2.policy, p) : void 0;
|
|
3201
3323
|
let entry;
|
|
3202
3324
|
if (input.seq === void 0) {
|
|
3203
|
-
entry = journal.latestUndoable();
|
|
3325
|
+
entry = journal.latestUndoable(visible);
|
|
3204
3326
|
if (!entry) throw new Error("No undoable writes in the journal.");
|
|
3205
3327
|
} else {
|
|
3206
3328
|
entry = journal.get(input.seq);
|
|
3329
|
+
if (entry && visible && !entry.files.every((f) => visible(f.path))) entry = void 0;
|
|
3207
3330
|
if (!entry) throw new Error(`Journal entry ${input.seq} not found.`);
|
|
3208
3331
|
if (!journal.isUndoable(entry)) {
|
|
3209
3332
|
throw new Error(
|
|
@@ -3219,7 +3342,7 @@ async function undoWrite(ctx2, rawInput) {
|
|
|
3219
3342
|
const current = /* @__PURE__ */ new Map();
|
|
3220
3343
|
const conflicts = [];
|
|
3221
3344
|
for (const f of entry.files) {
|
|
3222
|
-
const abs = resolveVaultPath(ctx2
|
|
3345
|
+
const abs = resolveVaultPath(ctx2, f.path);
|
|
3223
3346
|
let cur = null;
|
|
3224
3347
|
try {
|
|
3225
3348
|
cur = await readFile13(abs, "utf8");
|
|
@@ -3259,10 +3382,10 @@ async function undoWrite(ctx2, rawInput) {
|
|
|
3259
3382
|
const undoEntry = await txn.commit();
|
|
3260
3383
|
const restored = [];
|
|
3261
3384
|
for (const f of entry.files) {
|
|
3262
|
-
const abs = resolveVaultPath(ctx2
|
|
3385
|
+
const abs = resolveVaultPath(ctx2, f.path);
|
|
3263
3386
|
const pre = preimages.get(f.path) ?? null;
|
|
3264
3387
|
if (pre === null) {
|
|
3265
|
-
await
|
|
3388
|
+
await rm4(abs, { force: true });
|
|
3266
3389
|
removeNoteBacklinks(ctx2, f.path);
|
|
3267
3390
|
if (ctx2.notes.has(f.path)) {
|
|
3268
3391
|
ctx2.index.discard(f.path);
|
|
@@ -3321,8 +3444,8 @@ function lineStartOffset(raw, line) {
|
|
|
3321
3444
|
return offset;
|
|
3322
3445
|
}
|
|
3323
3446
|
async function updateTask(ctx2, input) {
|
|
3324
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
3325
3447
|
assertWritable(ctx2.policy, input.path);
|
|
3448
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
3326
3449
|
const original = await readFile14(absPath, "utf8");
|
|
3327
3450
|
if (input.prevHash !== void 0) assertHashMatch(original, input.prevHash, input.path);
|
|
3328
3451
|
const lineCount = original.split("\n").length;
|
|
@@ -3833,7 +3956,7 @@ import { basename as basename3, extname as extname4 } from "path";
|
|
|
3833
3956
|
|
|
3834
3957
|
// ../core/src/walk.ts
|
|
3835
3958
|
import { stat as stat2 } from "fs/promises";
|
|
3836
|
-
import { extname as extname3, join as join6, relative, sep as sep2 } from "path";
|
|
3959
|
+
import { extname as extname3, join as join6, relative as relative2, sep as sep2 } from "path";
|
|
3837
3960
|
import fg from "fast-glob";
|
|
3838
3961
|
var IMAGE_EXTS = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".bmp", ".heic"]);
|
|
3839
3962
|
var VIDEO_EXTS = /* @__PURE__ */ new Set([".mp4", ".mov", ".webm", ".mkv", ".avi"]);
|
|
@@ -3858,15 +3981,15 @@ function classify(relPath) {
|
|
|
3858
3981
|
if (AUDIO_EXTS.has(ext)) return "audio";
|
|
3859
3982
|
return "other";
|
|
3860
3983
|
}
|
|
3861
|
-
async function walkVault(vaultRoot2) {
|
|
3862
|
-
const matches2 = await fg("**/*", {
|
|
3984
|
+
async function walkVault(vaultRoot2, opts = {}) {
|
|
3985
|
+
const matches2 = await fg(opts.include ?? "**/*", {
|
|
3863
3986
|
cwd: vaultRoot2,
|
|
3864
3987
|
absolute: true,
|
|
3865
3988
|
onlyFiles: true,
|
|
3866
3989
|
followSymbolicLinks: false,
|
|
3867
3990
|
dot: true,
|
|
3868
3991
|
// include dotfiles so the ignore globs are the only gate
|
|
3869
|
-
ignore: IGNORE_GLOBS,
|
|
3992
|
+
ignore: opts.exclude ? [...IGNORE_GLOBS, ...opts.exclude] : IGNORE_GLOBS,
|
|
3870
3993
|
stats: true,
|
|
3871
3994
|
suppressErrors: true
|
|
3872
3995
|
});
|
|
@@ -3875,7 +3998,7 @@ async function walkVault(vaultRoot2) {
|
|
|
3875
3998
|
const absPath = typeof m === "string" ? m : m.path;
|
|
3876
3999
|
const stats = typeof m === "string" ? await stat2(absPath) : m.stats;
|
|
3877
4000
|
if (!stats) continue;
|
|
3878
|
-
const relPath =
|
|
4001
|
+
const relPath = relative2(vaultRoot2, absPath).split(sep2).join("/");
|
|
3879
4002
|
const topDir = relPath.split("/")[0] ?? "";
|
|
3880
4003
|
entries.push({
|
|
3881
4004
|
absPath,
|
|
@@ -3892,7 +4015,7 @@ async function walkVault(vaultRoot2) {
|
|
|
3892
4015
|
|
|
3893
4016
|
// src/index/build.ts
|
|
3894
4017
|
import MiniSearch from "minisearch";
|
|
3895
|
-
async function buildIndex(vaultRoot2) {
|
|
4018
|
+
async function buildIndex(vaultRoot2, scope) {
|
|
3896
4019
|
const t0 = Date.now();
|
|
3897
4020
|
const index2 = new MiniSearch({
|
|
3898
4021
|
idField: "id",
|
|
@@ -3904,7 +4027,7 @@ async function buildIndex(vaultRoot2) {
|
|
|
3904
4027
|
prefix: true
|
|
3905
4028
|
}
|
|
3906
4029
|
});
|
|
3907
|
-
const entries = await walkVault(vaultRoot2);
|
|
4030
|
+
const entries = await walkVault(vaultRoot2, scope);
|
|
3908
4031
|
const noteEntries = entries.filter((e) => e.kind === "note");
|
|
3909
4032
|
const docs = [];
|
|
3910
4033
|
const notes2 = /* @__PURE__ */ new Map();
|
|
@@ -4310,6 +4433,34 @@ function installProcessGuards(log2) {
|
|
|
4310
4433
|
};
|
|
4311
4434
|
}
|
|
4312
4435
|
|
|
4436
|
+
// src/scope-warnings.ts
|
|
4437
|
+
var PERIODS = ["daily", "weekly", "monthly", "quarterly", "yearly"];
|
|
4438
|
+
var SAMPLE = 5;
|
|
4439
|
+
async function scopeWarnings(vaultRoot2, policy2) {
|
|
4440
|
+
if (!policy2.readGlobs) return [];
|
|
4441
|
+
const warnings = [];
|
|
4442
|
+
if (policy2.writeGlobs && !policy2.readOnly) {
|
|
4443
|
+
const entries = await walkVault(vaultRoot2, splitGlobSet(policy2.writeGlobs));
|
|
4444
|
+
const blocked = entries.map((e) => e.relPath).filter((p) => !isReadable(policy2, p));
|
|
4445
|
+
if (blocked.length > 0) {
|
|
4446
|
+
warnings.push(
|
|
4447
|
+
`${blocked.length} file(s) match SEEKSTONE_WRITE_PATHS but are outside SEEKSTONE_READ_PATHS, so they are not writable (e.g. ${blocked.slice(0, SAMPLE).join(", ")}).`
|
|
4448
|
+
);
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
for (const period of PERIODS) {
|
|
4452
|
+
const cfg = await resolveConfig(vaultRoot2, period);
|
|
4453
|
+
if (!cfg.template) continue;
|
|
4454
|
+
const template = cfg.template.endsWith(".md") ? cfg.template : `${cfg.template}.md`;
|
|
4455
|
+
if (!isReadable(policy2, template)) {
|
|
4456
|
+
warnings.push(
|
|
4457
|
+
`The ${period} note template "${template}" is outside SEEKSTONE_READ_PATHS; new ${period} notes are created without it.`
|
|
4458
|
+
);
|
|
4459
|
+
}
|
|
4460
|
+
}
|
|
4461
|
+
return warnings;
|
|
4462
|
+
}
|
|
4463
|
+
|
|
4313
4464
|
// src/semantic/bundled-model.ts
|
|
4314
4465
|
init_model_manifest();
|
|
4315
4466
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -6070,7 +6221,7 @@ function visibleTools(policy2) {
|
|
|
6070
6221
|
// src/watcher.ts
|
|
6071
6222
|
import { realpathSync } from "fs";
|
|
6072
6223
|
import { readFile as readFile20 } from "fs/promises";
|
|
6073
|
-
import { join as join12, relative as
|
|
6224
|
+
import { join as join12, relative as relative3, sep as sep3 } from "path";
|
|
6074
6225
|
import chokidar from "chokidar";
|
|
6075
6226
|
var DEFAULT_POLL_INTERVAL_MS = 1e4;
|
|
6076
6227
|
function resolvePollInterval(optValue, envValue, log2) {
|
|
@@ -6098,7 +6249,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6098
6249
|
vaultRoot2 = realpathSync(ctx2.vaultRoot);
|
|
6099
6250
|
} catch {
|
|
6100
6251
|
}
|
|
6101
|
-
const toRel = (abs) =>
|
|
6252
|
+
const toRel = (abs) => relative3(vaultRoot2, abs).split(sep3).join("/");
|
|
6102
6253
|
async function upsert(relPath, op) {
|
|
6103
6254
|
try {
|
|
6104
6255
|
const raw = await readFile20(join12(vaultRoot2, relPath), "utf8");
|
|
@@ -6122,7 +6273,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6122
6273
|
const onUpsert = (op) => (abs) => {
|
|
6123
6274
|
const relPath = toRel(abs);
|
|
6124
6275
|
opts?.onRawEvent?.(op, abs, relPath);
|
|
6125
|
-
if (relPath.endsWith(".md")) void upsert(relPath, op);
|
|
6276
|
+
if (relPath.endsWith(".md") && isReadable(ctx2.policy, relPath)) void upsert(relPath, op);
|
|
6126
6277
|
};
|
|
6127
6278
|
const watcher2 = chokidar.watch(vaultRoot2, {
|
|
6128
6279
|
// The startup index build already covers existing files.
|
|
@@ -6133,7 +6284,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6133
6284
|
// Skip dot-dirs (.obsidian, .git, .trash, …) regardless of where the vault
|
|
6134
6285
|
// lives — matched on the path relative to the vault root.
|
|
6135
6286
|
ignored: (p) => {
|
|
6136
|
-
const rel =
|
|
6287
|
+
const rel = relative3(vaultRoot2, p);
|
|
6137
6288
|
if (!rel || rel === ".") return false;
|
|
6138
6289
|
return rel.split(sep3).filter(Boolean).some((seg) => seg.startsWith(".") && seg !== "..");
|
|
6139
6290
|
}
|
|
@@ -6141,7 +6292,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6141
6292
|
watcher2.on("add", onUpsert("add")).on("change", onUpsert("change")).on("unlink", (abs) => {
|
|
6142
6293
|
const relPath = toRel(abs);
|
|
6143
6294
|
opts?.onRawEvent?.("unlink", abs, relPath);
|
|
6144
|
-
if (relPath.endsWith(".md")) remove(relPath);
|
|
6295
|
+
if (relPath.endsWith(".md") && isReadable(ctx2.policy, relPath)) remove(relPath);
|
|
6145
6296
|
});
|
|
6146
6297
|
const ready = new Promise((resolve4) => {
|
|
6147
6298
|
watcher2.once("ready", () => {
|
|
@@ -6155,7 +6306,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6155
6306
|
}
|
|
6156
6307
|
|
|
6157
6308
|
// src/index.ts
|
|
6158
|
-
var VERSION = true ? "0.
|
|
6309
|
+
var VERSION = true ? "0.24.1" : "0.0.0-dev";
|
|
6159
6310
|
var intent = parseCliIntent(process.argv.slice(2));
|
|
6160
6311
|
if (intent === "version") {
|
|
6161
6312
|
process.stdout.write(`${VERSION}
|
|
@@ -6206,8 +6357,9 @@ var vaultRoot = resolve3(rawVaultRoot);
|
|
|
6206
6357
|
var policy = parseWritePolicy(process.env);
|
|
6207
6358
|
if (policy.readOnly) log.info("read-only mode", { env: "SEEKSTONE_READ_ONLY" });
|
|
6208
6359
|
if (policy.writeGlobs) log.info("write paths scoped", { globs: policy.writeGlobs });
|
|
6360
|
+
if (policy.readGlobs) log.info("read paths scoped", { globs: policy.readGlobs });
|
|
6209
6361
|
log.info("building index", { vault: vaultRoot });
|
|
6210
|
-
var { index, notes, backlinks, buildMs } = await buildIndex(vaultRoot);
|
|
6362
|
+
var { index, notes, backlinks, buildMs } = await buildIndex(vaultRoot, readScopeWalk(policy));
|
|
6211
6363
|
log.info("index ready", { notes: notes.size, buildMs });
|
|
6212
6364
|
var ctx = { vaultRoot, index, notes, backlinks, policy };
|
|
6213
6365
|
var journalCfg = resolveJournalConfig(process.env);
|
|
@@ -6253,6 +6405,10 @@ if (semanticCfg) {
|
|
|
6253
6405
|
}
|
|
6254
6406
|
}
|
|
6255
6407
|
var watcher = startWatcher(ctx, log);
|
|
6408
|
+
void scopeWarnings(vaultRoot, policy).then((warnings) => {
|
|
6409
|
+
for (const w of warnings) log.warn(w);
|
|
6410
|
+
}).catch(() => {
|
|
6411
|
+
});
|
|
6256
6412
|
process.on("exit", () => void watcher.stop());
|
|
6257
6413
|
var instructions = resolveInstructions(process.env, vaultRoot, log);
|
|
6258
6414
|
var server = new Server(
|