seekstone 0.22.4 → 0.24.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.
- package/README.md +2 -1
- package/dist/index.js +176 -47
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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. |
|
|
@@ -223,7 +224,7 @@ No network calls while running, no telemetry (the optional semantic-search model
|
|
|
223
224
|
|
|
224
225
|
## Requirements
|
|
225
226
|
|
|
226
|
-
- Node.js ≥ 22 (for CLI install options; the `.mcpb` bundle has no external requirements)
|
|
227
|
+
- Node.js ≥ 22.22 (for CLI install options; the `.mcpb` bundle has no external requirements)
|
|
227
228
|
- macOS, Linux, or Windows
|
|
228
229
|
|
|
229
230
|
---
|
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
|
}
|
|
@@ -730,9 +733,17 @@ var Journal = class _Journal {
|
|
|
730
733
|
};
|
|
731
734
|
}
|
|
732
735
|
/** Newest-first rows for `list_writes`. */
|
|
736
|
+
/**
|
|
737
|
+
* Newest-first metadata rows. `visible` hides entries that touched any path
|
|
738
|
+
* it rejects (the read scope, SHA-291 D3); hidden entries don't count
|
|
739
|
+
* toward `total` either.
|
|
740
|
+
*/
|
|
733
741
|
list(opts = {}) {
|
|
734
742
|
const limit = opts.limit ?? 20;
|
|
735
|
-
const
|
|
743
|
+
const { path: path2, visible } = opts;
|
|
744
|
+
const filtered = path2 === void 0 && visible === void 0 ? this.entries : this.entries.filter(
|
|
745
|
+
(e) => (path2 === void 0 || e.files.some((f) => f.path === path2)) && (visible === void 0 || e.files.every((f) => visible(f.path)))
|
|
746
|
+
);
|
|
736
747
|
const writes = [];
|
|
737
748
|
for (let i = filtered.length - 1; i >= 0 && writes.length < limit; i--) {
|
|
738
749
|
const e = filtered[i];
|
|
@@ -766,10 +777,11 @@ var Journal = class _Journal {
|
|
|
766
777
|
* undo/redo); an undo that was itself undone re-exposes its target. Redo is
|
|
767
778
|
* always explicit: `undo_write({ seq: <the undo's seq> })`.
|
|
768
779
|
*/
|
|
769
|
-
latestUndoable() {
|
|
780
|
+
latestUndoable(visible) {
|
|
770
781
|
const cancelled = /* @__PURE__ */ new Set();
|
|
771
782
|
for (let i = this.entries.length - 1; i >= 0; i--) {
|
|
772
783
|
const e = this.entries[i];
|
|
784
|
+
if (visible && !e.files.every((f) => visible(f.path))) continue;
|
|
773
785
|
if (cancelled.has(e.seq)) continue;
|
|
774
786
|
if (e.undoOf !== void 0) {
|
|
775
787
|
cancelled.add(e.undoOf);
|
|
@@ -880,42 +892,119 @@ async function journalWrite(ctx2, tool, path2, pre, post) {
|
|
|
880
892
|
|
|
881
893
|
// src/policy.ts
|
|
882
894
|
import picomatch from "picomatch";
|
|
895
|
+
function splitGlobs(raw) {
|
|
896
|
+
const out = [];
|
|
897
|
+
let depth = 0;
|
|
898
|
+
let cur = "";
|
|
899
|
+
for (const ch of raw ?? "") {
|
|
900
|
+
if (ch === "{") depth++;
|
|
901
|
+
else if (ch === "}" && depth > 0) depth--;
|
|
902
|
+
if (ch === "," && depth === 0) {
|
|
903
|
+
out.push(cur);
|
|
904
|
+
cur = "";
|
|
905
|
+
} else {
|
|
906
|
+
cur += ch;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
out.push(cur);
|
|
910
|
+
return out.map((g) => g.trim()).filter((g) => g.length > 0);
|
|
911
|
+
}
|
|
883
912
|
function parseWritePolicy(env) {
|
|
884
913
|
const ro = (env.SEEKSTONE_READ_ONLY ?? "").toLowerCase();
|
|
885
|
-
const
|
|
886
|
-
const
|
|
887
|
-
|
|
914
|
+
const policy2 = { readOnly: ro === "1" || ro === "true" };
|
|
915
|
+
const writeGlobs = splitGlobs(env.SEEKSTONE_WRITE_PATHS);
|
|
916
|
+
if (writeGlobs.length > 0) policy2.writeGlobs = writeGlobs;
|
|
917
|
+
const readGlobs = splitGlobs(env.SEEKSTONE_READ_PATHS);
|
|
918
|
+
if (readGlobs.length > 0) policy2.readGlobs = readGlobs;
|
|
919
|
+
return policy2;
|
|
888
920
|
}
|
|
889
921
|
function normalizeRel(relPath) {
|
|
890
922
|
let p = relPath.replaceAll("\\", "/");
|
|
891
923
|
while (p.startsWith("./")) p = p.slice(2);
|
|
892
924
|
return p;
|
|
893
925
|
}
|
|
926
|
+
function splitGlobSet(globs) {
|
|
927
|
+
const include = [];
|
|
928
|
+
const exclude = [];
|
|
929
|
+
for (const g of globs) {
|
|
930
|
+
if (g.startsWith("!")) {
|
|
931
|
+
const rest = g.slice(1).trim();
|
|
932
|
+
if (rest.length > 0) exclude.push(rest);
|
|
933
|
+
} else {
|
|
934
|
+
include.push(g);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
return { include: include.length > 0 ? include : ["**"], exclude };
|
|
938
|
+
}
|
|
939
|
+
var matchers = /* @__PURE__ */ new WeakMap();
|
|
940
|
+
function matcherFor(globs) {
|
|
941
|
+
let m = matchers.get(globs);
|
|
942
|
+
if (m === void 0) {
|
|
943
|
+
const { include, exclude } = splitGlobSet(globs);
|
|
944
|
+
const inc = picomatch(include, { dot: true });
|
|
945
|
+
const exc = exclude.length > 0 ? picomatch(exclude, { dot: true }) : void 0;
|
|
946
|
+
m = exc ? (p) => inc(p) && !exc(p) : inc;
|
|
947
|
+
matchers.set(globs, m);
|
|
948
|
+
}
|
|
949
|
+
return m;
|
|
950
|
+
}
|
|
951
|
+
function isReadable(policy2, relPath) {
|
|
952
|
+
if (!policy2.readGlobs) return true;
|
|
953
|
+
return matcherFor(policy2.readGlobs)(normalizeRel(relPath));
|
|
954
|
+
}
|
|
894
955
|
function isWritable(policy2, relPath) {
|
|
895
956
|
if (policy2.readOnly) return false;
|
|
957
|
+
if (!isReadable(policy2, relPath)) return false;
|
|
896
958
|
if (!policy2.writeGlobs) return true;
|
|
897
|
-
return
|
|
959
|
+
return matcherFor(policy2.writeGlobs)(normalizeRel(relPath));
|
|
898
960
|
}
|
|
899
961
|
function assertWritable(policy2, relPath) {
|
|
900
962
|
if (policy2.readOnly) {
|
|
901
963
|
throw new Error("Server is read-only (SEEKSTONE_READ_ONLY=1); write tools are disabled.");
|
|
902
964
|
}
|
|
965
|
+
if (!isReadable(policy2, relPath)) {
|
|
966
|
+
throw new Error(
|
|
967
|
+
`Write not permitted: "${relPath}" is outside SEEKSTONE_READ_PATHS (${policy2.readGlobs?.join(", ")}).`
|
|
968
|
+
);
|
|
969
|
+
}
|
|
903
970
|
if (!isWritable(policy2, relPath)) {
|
|
904
971
|
throw new Error(
|
|
905
972
|
`Write not permitted: "${relPath}" is outside SEEKSTONE_WRITE_PATHS (${policy2.writeGlobs?.join(", ")}).`
|
|
906
973
|
);
|
|
907
974
|
}
|
|
908
975
|
}
|
|
976
|
+
function readScopeWalk(policy2) {
|
|
977
|
+
return policy2.readGlobs ? splitGlobSet(policy2.readGlobs) : void 0;
|
|
978
|
+
}
|
|
909
979
|
|
|
910
980
|
// src/vault-path.ts
|
|
911
|
-
import { resolve, sep } from "path";
|
|
912
|
-
function
|
|
981
|
+
import { relative, resolve, sep } from "path";
|
|
982
|
+
function containVaultPath(vaultRoot2, inputPath) {
|
|
913
983
|
const abs = resolve(vaultRoot2, inputPath);
|
|
914
984
|
if (abs !== vaultRoot2 && !abs.startsWith(vaultRoot2 + sep)) {
|
|
915
985
|
throw new Error(`Path outside vault: ${inputPath}`);
|
|
916
986
|
}
|
|
917
987
|
return abs;
|
|
918
988
|
}
|
|
989
|
+
function resolveVaultPath(ctx2, inputPath) {
|
|
990
|
+
const abs = containVaultPath(ctx2.vaultRoot, inputPath);
|
|
991
|
+
if (ctx2.policy.readGlobs && !isReadable(ctx2.policy, vaultRelative(ctx2.vaultRoot, abs))) {
|
|
992
|
+
throw notFoundError(abs);
|
|
993
|
+
}
|
|
994
|
+
return abs;
|
|
995
|
+
}
|
|
996
|
+
function vaultRelative(vaultRoot2, abs) {
|
|
997
|
+
return relative(vaultRoot2, abs).split(sep).join("/");
|
|
998
|
+
}
|
|
999
|
+
function notFoundError(absPath) {
|
|
1000
|
+
const err = new Error(
|
|
1001
|
+
`ENOENT: no such file or directory, open '${absPath}'`
|
|
1002
|
+
);
|
|
1003
|
+
err.code = "ENOENT";
|
|
1004
|
+
err.syscall = "open";
|
|
1005
|
+
err.path = absPath;
|
|
1006
|
+
return err;
|
|
1007
|
+
}
|
|
919
1008
|
|
|
920
1009
|
// src/tools/append_note.ts
|
|
921
1010
|
var AppendNoteInput = z.object({
|
|
@@ -928,8 +1017,8 @@ var AppendNoteInput = z.object({
|
|
|
928
1017
|
)
|
|
929
1018
|
});
|
|
930
1019
|
async function appendNote(ctx2, input) {
|
|
931
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
932
1020
|
assertWritable(ctx2.policy, input.path);
|
|
1021
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
933
1022
|
const original = await readFile2(absPath, "utf8");
|
|
934
1023
|
if (input.prevHash !== void 0) assertHashMatch(original, input.prevHash, input.path);
|
|
935
1024
|
const fm = parseFrontmatter(original);
|
|
@@ -1595,8 +1684,8 @@ var CreateNoteInput = z4.object({
|
|
|
1595
1684
|
});
|
|
1596
1685
|
async function createNote(ctx2, rawInput) {
|
|
1597
1686
|
const input = CreateNoteInput.parse(rawInput);
|
|
1598
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
1599
1687
|
assertWritable(ctx2.policy, input.path);
|
|
1688
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
1600
1689
|
let existing = null;
|
|
1601
1690
|
if (!input.overwrite) {
|
|
1602
1691
|
try {
|
|
@@ -1712,8 +1801,8 @@ async function freeTrashPath(vaultRoot2, noteBase) {
|
|
|
1712
1801
|
}
|
|
1713
1802
|
async function deleteNote(ctx2, rawInput) {
|
|
1714
1803
|
const input = DeleteNoteInput.parse(rawInput);
|
|
1715
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
1716
1804
|
assertWritable(ctx2.policy, input.path);
|
|
1805
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
1717
1806
|
const raw = await readFile4(absPath, "utf8");
|
|
1718
1807
|
if (input.prevHash !== void 0) assertHashMatch(raw, input.prevHash, input.path);
|
|
1719
1808
|
await journalWrite(ctx2, "delete_note", input.path, raw, null);
|
|
@@ -1748,7 +1837,7 @@ var GetBacklinksInput = z6.object({
|
|
|
1748
1837
|
});
|
|
1749
1838
|
var EXCERPT_MAX = 200;
|
|
1750
1839
|
function getBacklinks(ctx2, input) {
|
|
1751
|
-
|
|
1840
|
+
containVaultPath(ctx2.vaultRoot, input.path);
|
|
1752
1841
|
const includeContext = input.includeContext ?? true;
|
|
1753
1842
|
const limit = input.limit ?? 50;
|
|
1754
1843
|
const refs = ctx2.backlinks.get(input.path) ?? [];
|
|
@@ -1778,7 +1867,7 @@ var GetLinksInput = z7.object({
|
|
|
1778
1867
|
path: z7.string().describe("Vault-relative path to the note.")
|
|
1779
1868
|
});
|
|
1780
1869
|
function getLinks(ctx2, input) {
|
|
1781
|
-
|
|
1870
|
+
containVaultPath(ctx2.vaultRoot, input.path);
|
|
1782
1871
|
const note = ctx2.notes.get(input.path);
|
|
1783
1872
|
if (note === void 0) throw new Error(`Note not found: ${input.path}`);
|
|
1784
1873
|
const rawLinks = extractLinksWithLines(note.raw);
|
|
@@ -1936,8 +2025,11 @@ var ListWritesInput = z11.object({
|
|
|
1936
2025
|
function listWrites(ctx2, rawInput) {
|
|
1937
2026
|
const input = ListWritesInput.parse(rawInput);
|
|
1938
2027
|
if (!ctx2.journal) return { writes: [], total: 0, disabled: true };
|
|
1939
|
-
const opts = {
|
|
2028
|
+
const opts = {
|
|
2029
|
+
limit: input.limit
|
|
2030
|
+
};
|
|
1940
2031
|
if (input.path !== void 0) opts.path = input.path;
|
|
2032
|
+
if (ctx2.policy.readGlobs) opts.visible = (p) => isReadable(ctx2.policy, p);
|
|
1941
2033
|
return ctx2.journal.list(opts);
|
|
1942
2034
|
}
|
|
1943
2035
|
|
|
@@ -2053,10 +2145,10 @@ var MoveNoteInput = z12.object({
|
|
|
2053
2145
|
});
|
|
2054
2146
|
async function moveNote(ctx2, rawInput) {
|
|
2055
2147
|
const input = MoveNoteInput.parse(rawInput);
|
|
2056
|
-
const absFrom = resolveVaultPath(ctx2.vaultRoot, input.from);
|
|
2057
|
-
const absTo = resolveVaultPath(ctx2.vaultRoot, input.to);
|
|
2058
2148
|
assertWritable(ctx2.policy, input.from);
|
|
2059
2149
|
assertWritable(ctx2.policy, input.to);
|
|
2150
|
+
const absFrom = resolveVaultPath(ctx2, input.from);
|
|
2151
|
+
const absTo = resolveVaultPath(ctx2, input.to);
|
|
2060
2152
|
let raw;
|
|
2061
2153
|
try {
|
|
2062
2154
|
raw = await readFile5(absFrom, "utf8");
|
|
@@ -2207,7 +2299,7 @@ var OutlineNoteInput = z13.object({
|
|
|
2207
2299
|
includeSizes: z13.boolean().default(false).describe("Include per-section character length in each heading entry. Default false.")
|
|
2208
2300
|
});
|
|
2209
2301
|
async function outlineNote(ctx2, input) {
|
|
2210
|
-
const absPath = resolveVaultPath(ctx2
|
|
2302
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2211
2303
|
const raw = await readFile6(absPath, "utf8");
|
|
2212
2304
|
return buildOutline(raw, {
|
|
2213
2305
|
includeBlocks: input.includeBlocks,
|
|
@@ -2229,8 +2321,8 @@ var PatchFrontmatterInput = z14.object({
|
|
|
2229
2321
|
)
|
|
2230
2322
|
});
|
|
2231
2323
|
async function patchFrontmatter(ctx2, input) {
|
|
2232
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
2233
2324
|
assertWritable(ctx2.policy, input.path);
|
|
2325
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2234
2326
|
const original = await readFile7(absPath, "utf8");
|
|
2235
2327
|
if (input.prevHash !== void 0) assertHashMatch(original, input.prevHash, input.path);
|
|
2236
2328
|
const fm = parseFrontmatter(original);
|
|
@@ -2322,8 +2414,8 @@ function lineStart(raw, offset) {
|
|
|
2322
2414
|
return prev === -1 ? 0 : prev + 1;
|
|
2323
2415
|
}
|
|
2324
2416
|
async function patchNote(ctx2, input) {
|
|
2325
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
2326
2417
|
assertWritable(ctx2.policy, input.path);
|
|
2418
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2327
2419
|
const raw = await readFile8(absPath, "utf8");
|
|
2328
2420
|
if (input.prevHash !== void 0) assertHashMatch(raw, input.prevHash, input.path);
|
|
2329
2421
|
const fm = parseFrontmatter(raw);
|
|
@@ -2524,12 +2616,14 @@ async function getPeriodicNote(ctx2, rawInput) {
|
|
|
2524
2616
|
const date = input.date ? new Date(input.date) : /* @__PURE__ */ new Date();
|
|
2525
2617
|
const cfg = await resolveConfig(ctx2.vaultRoot, input.period);
|
|
2526
2618
|
const path2 = resolveNotePath(cfg, date);
|
|
2527
|
-
const abs =
|
|
2619
|
+
const abs = containVaultPath(ctx2.vaultRoot, path2);
|
|
2528
2620
|
let existed = false;
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2621
|
+
if (isReadable(ctx2.policy, path2)) {
|
|
2622
|
+
try {
|
|
2623
|
+
await access3(abs);
|
|
2624
|
+
existed = true;
|
|
2625
|
+
} catch {
|
|
2626
|
+
}
|
|
2533
2627
|
}
|
|
2534
2628
|
if (existed) return { path: path2, existed: true, created: false };
|
|
2535
2629
|
if (!input.createIfMissing) return { path: path2, existed: false, created: false };
|
|
@@ -2538,7 +2632,7 @@ async function getPeriodicNote(ctx2, rawInput) {
|
|
|
2538
2632
|
if (cfg.template) {
|
|
2539
2633
|
try {
|
|
2540
2634
|
const templateAbs = resolveVaultPath(
|
|
2541
|
-
ctx2
|
|
2635
|
+
ctx2,
|
|
2542
2636
|
cfg.template.endsWith(".md") ? cfg.template : `${cfg.template}.md`
|
|
2543
2637
|
);
|
|
2544
2638
|
body = await readFile9(templateAbs, "utf8");
|
|
@@ -2565,8 +2659,8 @@ async function appendPeriodicNote(ctx2, rawInput) {
|
|
|
2565
2659
|
const date = input.date ? new Date(input.date) : /* @__PURE__ */ new Date();
|
|
2566
2660
|
const cfg = await resolveConfig(ctx2.vaultRoot, input.period);
|
|
2567
2661
|
const path2 = resolveNotePath(cfg, date);
|
|
2568
|
-
const abs = resolveVaultPath(ctx2.vaultRoot, path2);
|
|
2569
2662
|
assertWritable(ctx2.policy, path2);
|
|
2663
|
+
const abs = resolveVaultPath(ctx2, path2);
|
|
2570
2664
|
let original = "";
|
|
2571
2665
|
try {
|
|
2572
2666
|
original = await readFile9(abs, "utf8");
|
|
@@ -2765,7 +2859,7 @@ var ReadNoteInput = z18.object({
|
|
|
2765
2859
|
message: "At most one of section, block, or lines may be specified."
|
|
2766
2860
|
});
|
|
2767
2861
|
async function readNote(ctx2, input) {
|
|
2768
|
-
const absPath = resolveVaultPath(ctx2
|
|
2862
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2769
2863
|
const raw = await readFile10(absPath, "utf8");
|
|
2770
2864
|
const noteBytes = Buffer.byteLength(raw, "utf8");
|
|
2771
2865
|
const hash = contentHash(raw);
|
|
@@ -2949,8 +3043,8 @@ function rewriteHeadingLinks(raw, oldHeading, newHeading, matchesTarget) {
|
|
|
2949
3043
|
}
|
|
2950
3044
|
async function renameHeading(ctx2, rawInput) {
|
|
2951
3045
|
const input = RenameHeadingInput.parse(rawInput);
|
|
2952
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
2953
3046
|
assertWritable(ctx2.policy, input.path);
|
|
3047
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
2954
3048
|
let raw;
|
|
2955
3049
|
try {
|
|
2956
3050
|
raw = await readFile11(absPath, "utf8");
|
|
@@ -3070,8 +3164,8 @@ function buildRegex(find, opts) {
|
|
|
3070
3164
|
return new RegExp(pattern, flags);
|
|
3071
3165
|
}
|
|
3072
3166
|
async function replaceInNote(ctx2, input) {
|
|
3073
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
3074
3167
|
assertWritable(ctx2.policy, input.path);
|
|
3168
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
3075
3169
|
let re;
|
|
3076
3170
|
try {
|
|
3077
3171
|
re = buildRegex(input.find, {
|
|
@@ -3198,12 +3292,14 @@ async function undoWrite(ctx2, rawInput) {
|
|
|
3198
3292
|
if (!journal) {
|
|
3199
3293
|
throw new Error("Write journal is disabled (SEEKSTONE_HISTORY=0); nothing to undo.");
|
|
3200
3294
|
}
|
|
3295
|
+
const visible = ctx2.policy.readGlobs ? (p) => isReadable(ctx2.policy, p) : void 0;
|
|
3201
3296
|
let entry;
|
|
3202
3297
|
if (input.seq === void 0) {
|
|
3203
|
-
entry = journal.latestUndoable();
|
|
3298
|
+
entry = journal.latestUndoable(visible);
|
|
3204
3299
|
if (!entry) throw new Error("No undoable writes in the journal.");
|
|
3205
3300
|
} else {
|
|
3206
3301
|
entry = journal.get(input.seq);
|
|
3302
|
+
if (entry && visible && !entry.files.every((f) => visible(f.path))) entry = void 0;
|
|
3207
3303
|
if (!entry) throw new Error(`Journal entry ${input.seq} not found.`);
|
|
3208
3304
|
if (!journal.isUndoable(entry)) {
|
|
3209
3305
|
throw new Error(
|
|
@@ -3219,7 +3315,7 @@ async function undoWrite(ctx2, rawInput) {
|
|
|
3219
3315
|
const current = /* @__PURE__ */ new Map();
|
|
3220
3316
|
const conflicts = [];
|
|
3221
3317
|
for (const f of entry.files) {
|
|
3222
|
-
const abs = resolveVaultPath(ctx2
|
|
3318
|
+
const abs = resolveVaultPath(ctx2, f.path);
|
|
3223
3319
|
let cur = null;
|
|
3224
3320
|
try {
|
|
3225
3321
|
cur = await readFile13(abs, "utf8");
|
|
@@ -3259,7 +3355,7 @@ async function undoWrite(ctx2, rawInput) {
|
|
|
3259
3355
|
const undoEntry = await txn.commit();
|
|
3260
3356
|
const restored = [];
|
|
3261
3357
|
for (const f of entry.files) {
|
|
3262
|
-
const abs = resolveVaultPath(ctx2
|
|
3358
|
+
const abs = resolveVaultPath(ctx2, f.path);
|
|
3263
3359
|
const pre = preimages.get(f.path) ?? null;
|
|
3264
3360
|
if (pre === null) {
|
|
3265
3361
|
await rm3(abs, { force: true });
|
|
@@ -3321,8 +3417,8 @@ function lineStartOffset(raw, line) {
|
|
|
3321
3417
|
return offset;
|
|
3322
3418
|
}
|
|
3323
3419
|
async function updateTask(ctx2, input) {
|
|
3324
|
-
const absPath = resolveVaultPath(ctx2.vaultRoot, input.path);
|
|
3325
3420
|
assertWritable(ctx2.policy, input.path);
|
|
3421
|
+
const absPath = resolveVaultPath(ctx2, input.path);
|
|
3326
3422
|
const original = await readFile14(absPath, "utf8");
|
|
3327
3423
|
if (input.prevHash !== void 0) assertHashMatch(original, input.prevHash, input.path);
|
|
3328
3424
|
const lineCount = original.split("\n").length;
|
|
@@ -3833,7 +3929,7 @@ import { basename as basename3, extname as extname4 } from "path";
|
|
|
3833
3929
|
|
|
3834
3930
|
// ../core/src/walk.ts
|
|
3835
3931
|
import { stat as stat2 } from "fs/promises";
|
|
3836
|
-
import { extname as extname3, join as join6, relative, sep as sep2 } from "path";
|
|
3932
|
+
import { extname as extname3, join as join6, relative as relative2, sep as sep2 } from "path";
|
|
3837
3933
|
import fg from "fast-glob";
|
|
3838
3934
|
var IMAGE_EXTS = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".bmp", ".heic"]);
|
|
3839
3935
|
var VIDEO_EXTS = /* @__PURE__ */ new Set([".mp4", ".mov", ".webm", ".mkv", ".avi"]);
|
|
@@ -3858,15 +3954,15 @@ function classify(relPath) {
|
|
|
3858
3954
|
if (AUDIO_EXTS.has(ext)) return "audio";
|
|
3859
3955
|
return "other";
|
|
3860
3956
|
}
|
|
3861
|
-
async function walkVault(vaultRoot2) {
|
|
3862
|
-
const matches2 = await fg("**/*", {
|
|
3957
|
+
async function walkVault(vaultRoot2, opts = {}) {
|
|
3958
|
+
const matches2 = await fg(opts.include ?? "**/*", {
|
|
3863
3959
|
cwd: vaultRoot2,
|
|
3864
3960
|
absolute: true,
|
|
3865
3961
|
onlyFiles: true,
|
|
3866
3962
|
followSymbolicLinks: false,
|
|
3867
3963
|
dot: true,
|
|
3868
3964
|
// include dotfiles so the ignore globs are the only gate
|
|
3869
|
-
ignore: IGNORE_GLOBS,
|
|
3965
|
+
ignore: opts.exclude ? [...IGNORE_GLOBS, ...opts.exclude] : IGNORE_GLOBS,
|
|
3870
3966
|
stats: true,
|
|
3871
3967
|
suppressErrors: true
|
|
3872
3968
|
});
|
|
@@ -3875,7 +3971,7 @@ async function walkVault(vaultRoot2) {
|
|
|
3875
3971
|
const absPath = typeof m === "string" ? m : m.path;
|
|
3876
3972
|
const stats = typeof m === "string" ? await stat2(absPath) : m.stats;
|
|
3877
3973
|
if (!stats) continue;
|
|
3878
|
-
const relPath =
|
|
3974
|
+
const relPath = relative2(vaultRoot2, absPath).split(sep2).join("/");
|
|
3879
3975
|
const topDir = relPath.split("/")[0] ?? "";
|
|
3880
3976
|
entries.push({
|
|
3881
3977
|
absPath,
|
|
@@ -3892,7 +3988,7 @@ async function walkVault(vaultRoot2) {
|
|
|
3892
3988
|
|
|
3893
3989
|
// src/index/build.ts
|
|
3894
3990
|
import MiniSearch from "minisearch";
|
|
3895
|
-
async function buildIndex(vaultRoot2) {
|
|
3991
|
+
async function buildIndex(vaultRoot2, scope) {
|
|
3896
3992
|
const t0 = Date.now();
|
|
3897
3993
|
const index2 = new MiniSearch({
|
|
3898
3994
|
idField: "id",
|
|
@@ -3904,7 +4000,7 @@ async function buildIndex(vaultRoot2) {
|
|
|
3904
4000
|
prefix: true
|
|
3905
4001
|
}
|
|
3906
4002
|
});
|
|
3907
|
-
const entries = await walkVault(vaultRoot2);
|
|
4003
|
+
const entries = await walkVault(vaultRoot2, scope);
|
|
3908
4004
|
const noteEntries = entries.filter((e) => e.kind === "note");
|
|
3909
4005
|
const docs = [];
|
|
3910
4006
|
const notes2 = /* @__PURE__ */ new Map();
|
|
@@ -4310,6 +4406,34 @@ function installProcessGuards(log2) {
|
|
|
4310
4406
|
};
|
|
4311
4407
|
}
|
|
4312
4408
|
|
|
4409
|
+
// src/scope-warnings.ts
|
|
4410
|
+
var PERIODS = ["daily", "weekly", "monthly", "quarterly", "yearly"];
|
|
4411
|
+
var SAMPLE = 5;
|
|
4412
|
+
async function scopeWarnings(vaultRoot2, policy2) {
|
|
4413
|
+
if (!policy2.readGlobs) return [];
|
|
4414
|
+
const warnings = [];
|
|
4415
|
+
if (policy2.writeGlobs && !policy2.readOnly) {
|
|
4416
|
+
const entries = await walkVault(vaultRoot2, splitGlobSet(policy2.writeGlobs));
|
|
4417
|
+
const blocked = entries.map((e) => e.relPath).filter((p) => !isReadable(policy2, p));
|
|
4418
|
+
if (blocked.length > 0) {
|
|
4419
|
+
warnings.push(
|
|
4420
|
+
`${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(", ")}).`
|
|
4421
|
+
);
|
|
4422
|
+
}
|
|
4423
|
+
}
|
|
4424
|
+
for (const period of PERIODS) {
|
|
4425
|
+
const cfg = await resolveConfig(vaultRoot2, period);
|
|
4426
|
+
if (!cfg.template) continue;
|
|
4427
|
+
const template = cfg.template.endsWith(".md") ? cfg.template : `${cfg.template}.md`;
|
|
4428
|
+
if (!isReadable(policy2, template)) {
|
|
4429
|
+
warnings.push(
|
|
4430
|
+
`The ${period} note template "${template}" is outside SEEKSTONE_READ_PATHS; new ${period} notes are created without it.`
|
|
4431
|
+
);
|
|
4432
|
+
}
|
|
4433
|
+
}
|
|
4434
|
+
return warnings;
|
|
4435
|
+
}
|
|
4436
|
+
|
|
4313
4437
|
// src/semantic/bundled-model.ts
|
|
4314
4438
|
init_model_manifest();
|
|
4315
4439
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -6070,7 +6194,7 @@ function visibleTools(policy2) {
|
|
|
6070
6194
|
// src/watcher.ts
|
|
6071
6195
|
import { realpathSync } from "fs";
|
|
6072
6196
|
import { readFile as readFile20 } from "fs/promises";
|
|
6073
|
-
import { join as join12, relative as
|
|
6197
|
+
import { join as join12, relative as relative3, sep as sep3 } from "path";
|
|
6074
6198
|
import chokidar from "chokidar";
|
|
6075
6199
|
var DEFAULT_POLL_INTERVAL_MS = 1e4;
|
|
6076
6200
|
function resolvePollInterval(optValue, envValue, log2) {
|
|
@@ -6098,7 +6222,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6098
6222
|
vaultRoot2 = realpathSync(ctx2.vaultRoot);
|
|
6099
6223
|
} catch {
|
|
6100
6224
|
}
|
|
6101
|
-
const toRel = (abs) =>
|
|
6225
|
+
const toRel = (abs) => relative3(vaultRoot2, abs).split(sep3).join("/");
|
|
6102
6226
|
async function upsert(relPath, op) {
|
|
6103
6227
|
try {
|
|
6104
6228
|
const raw = await readFile20(join12(vaultRoot2, relPath), "utf8");
|
|
@@ -6122,7 +6246,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6122
6246
|
const onUpsert = (op) => (abs) => {
|
|
6123
6247
|
const relPath = toRel(abs);
|
|
6124
6248
|
opts?.onRawEvent?.(op, abs, relPath);
|
|
6125
|
-
if (relPath.endsWith(".md")) void upsert(relPath, op);
|
|
6249
|
+
if (relPath.endsWith(".md") && isReadable(ctx2.policy, relPath)) void upsert(relPath, op);
|
|
6126
6250
|
};
|
|
6127
6251
|
const watcher2 = chokidar.watch(vaultRoot2, {
|
|
6128
6252
|
// The startup index build already covers existing files.
|
|
@@ -6133,7 +6257,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6133
6257
|
// Skip dot-dirs (.obsidian, .git, .trash, …) regardless of where the vault
|
|
6134
6258
|
// lives — matched on the path relative to the vault root.
|
|
6135
6259
|
ignored: (p) => {
|
|
6136
|
-
const rel =
|
|
6260
|
+
const rel = relative3(vaultRoot2, p);
|
|
6137
6261
|
if (!rel || rel === ".") return false;
|
|
6138
6262
|
return rel.split(sep3).filter(Boolean).some((seg) => seg.startsWith(".") && seg !== "..");
|
|
6139
6263
|
}
|
|
@@ -6141,7 +6265,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6141
6265
|
watcher2.on("add", onUpsert("add")).on("change", onUpsert("change")).on("unlink", (abs) => {
|
|
6142
6266
|
const relPath = toRel(abs);
|
|
6143
6267
|
opts?.onRawEvent?.("unlink", abs, relPath);
|
|
6144
|
-
if (relPath.endsWith(".md")) remove(relPath);
|
|
6268
|
+
if (relPath.endsWith(".md") && isReadable(ctx2.policy, relPath)) remove(relPath);
|
|
6145
6269
|
});
|
|
6146
6270
|
const ready = new Promise((resolve4) => {
|
|
6147
6271
|
watcher2.once("ready", () => {
|
|
@@ -6155,7 +6279,7 @@ function startWatcher(ctx2, log2, opts) {
|
|
|
6155
6279
|
}
|
|
6156
6280
|
|
|
6157
6281
|
// src/index.ts
|
|
6158
|
-
var VERSION = true ? "0.
|
|
6282
|
+
var VERSION = true ? "0.24.0" : "0.0.0-dev";
|
|
6159
6283
|
var intent = parseCliIntent(process.argv.slice(2));
|
|
6160
6284
|
if (intent === "version") {
|
|
6161
6285
|
process.stdout.write(`${VERSION}
|
|
@@ -6206,8 +6330,9 @@ var vaultRoot = resolve3(rawVaultRoot);
|
|
|
6206
6330
|
var policy = parseWritePolicy(process.env);
|
|
6207
6331
|
if (policy.readOnly) log.info("read-only mode", { env: "SEEKSTONE_READ_ONLY" });
|
|
6208
6332
|
if (policy.writeGlobs) log.info("write paths scoped", { globs: policy.writeGlobs });
|
|
6333
|
+
if (policy.readGlobs) log.info("read paths scoped", { globs: policy.readGlobs });
|
|
6209
6334
|
log.info("building index", { vault: vaultRoot });
|
|
6210
|
-
var { index, notes, backlinks, buildMs } = await buildIndex(vaultRoot);
|
|
6335
|
+
var { index, notes, backlinks, buildMs } = await buildIndex(vaultRoot, readScopeWalk(policy));
|
|
6211
6336
|
log.info("index ready", { notes: notes.size, buildMs });
|
|
6212
6337
|
var ctx = { vaultRoot, index, notes, backlinks, policy };
|
|
6213
6338
|
var journalCfg = resolveJournalConfig(process.env);
|
|
@@ -6253,6 +6378,10 @@ if (semanticCfg) {
|
|
|
6253
6378
|
}
|
|
6254
6379
|
}
|
|
6255
6380
|
var watcher = startWatcher(ctx, log);
|
|
6381
|
+
void scopeWarnings(vaultRoot, policy).then((warnings) => {
|
|
6382
|
+
for (const w of warnings) log.warn(w);
|
|
6383
|
+
}).catch(() => {
|
|
6384
|
+
});
|
|
6256
6385
|
process.on("exit", () => void watcher.stop());
|
|
6257
6386
|
var instructions = resolveInstructions(process.env, vaultRoot, log);
|
|
6258
6387
|
var server = new Server(
|