@staix/vault-mem 0.14.0 → 0.14.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/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.14.1] - 2026-11-23
6
+
7
+ - Fixed: setup accepts an override profile skill root linked to the host's real default skill root; other links remain refused.
8
+
5
9
  ## [0.14.0] - 2026-11-22
6
10
 
7
11
  - N-1: 0.13.1 and 0.14.0 share the note and spec index files, config format 6 and the enrichment sidecar format. CLI commands and MCP tool names, arguments and receipts are unchanged. Only the console provider differs: its Graph snapshot adds the first-page `enrichment` field and the `similar` and `semantic` arguments, which the 0.13.1 provider does not offer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staix/vault-mem",
3
- "version": "0.14.0",
3
+ "version": "0.14.1",
4
4
  "description": "Validated Obsidian-compatible knowledge vaults for agents and people",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,7 +35,7 @@
35
35
  "LICENSE"
36
36
  ],
37
37
  "scripts": {
38
- "check": "bun x tsc --noEmit && bun scripts/check-boundary.ts && bun scripts/readme-facts.ts && bun scripts/check-docs.mjs && bun test && bun pm pack --dry-run && bun scripts/package-smoke.ts",
38
+ "check": "bun x tsc --noEmit && bun scripts/check-boundary.ts && bun scripts/refusal-inventory.ts && bun scripts/readme-facts.ts && bun scripts/check-docs.mjs && bun test && bun pm pack --dry-run && bun scripts/package-smoke.ts",
39
39
  "smoke:package": "bun scripts/package-smoke.ts",
40
40
  "bench:release": "bun scripts/release-performance.ts",
41
41
  "parity:release": "bun scripts/release-parity.ts",
package/src/setup.ts CHANGED
@@ -4,7 +4,7 @@ import { dirname, isAbsolute, join, resolve } from "node:path";
4
4
  import { createHash, randomUUID } from "node:crypto";
5
5
  import { isDeepStrictEqual } from "node:util";
6
6
  import { shellWord } from "./text-output.ts";
7
- import { installSkills, skillRoot, type SkillInstallReport } from "./skills-install.ts";
7
+ import { installSkills, resolveHostSkillRoot, type SkillInstallReport } from "./skills-install.ts";
8
8
  import { fileURLToPath } from "node:url";
9
9
 
10
10
  /** Hosts whose MCP configuration `vmem setup` can register; `all` covers every user-level host (not agy). */
@@ -302,9 +302,11 @@ export function runSetup(target: string, mode: SetupMode, options: { home: strin
302
302
  }
303
303
  for (const name of targets) {
304
304
  try {
305
- const path = skillRoot(name, env);
306
- if (!path) { report.skills!.push({ target: name, reason: "skills are not installed for this host; use vmem skills export <dir>" }); continue; }
307
- report.skills!.push({ target: name, report: installSkills(path, mode, root?.path, root?.version, ["vmem", "setup", name, ...(root ? ["--root", root.path] : []), mode === "undo" ? "--undo" : "--apply"].map(shellWord).join(" ")) });
305
+ const resolved = resolveHostSkillRoot(name, env);
306
+ if (!resolved) { report.skills!.push({ target: name, reason: "skills are not installed for this host; use vmem skills export <dir>" }); continue; }
307
+ const skills = installSkills(resolved.root, mode, root?.path, root?.version, ["vmem", "setup", name, ...(root ? ["--root", root.path] : []), mode === "undo" ? "--undo" : "--apply"].map(shellWord).join(" "), resolved.recheck);
308
+ if (resolved.linkedFrom) for (const item of skills.actions) item.reason = `via linked root ${resolved.linkedFrom} to ${skills.root}${item.reason ? `; ${item.reason}` : ""}`;
309
+ report.skills!.push({ target: name, report: skills });
308
310
  } catch (error) { report.skills!.push({ target: name, refused: true, reason: error instanceof Error ? error.message : "skill setup failed; inspect the host configuration" }); }
309
311
  }
310
312
  report.console = consoleManifest(mode, env, root?.path);
@@ -1,5 +1,5 @@
1
1
  /** Install package-owned skills without replacing foreign or locally modified trees. */
2
- import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, opendirSync, readSync, realpathSync, rmSync, writeFileSync, type Stats } from "node:fs";
2
+ import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, opendirSync, readlinkSync, readSync, realpathSync, rmSync, writeFileSync, type Stats } from "node:fs";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { isAbsolute, join, relative, resolve, sep } from "node:path";
5
5
  import { homedir } from "node:os";
@@ -114,10 +114,10 @@ function stage(root: string, files: Files, digestValue: string, packageVersion:
114
114
  } catch (error) { rmSync(dir, { recursive: true, force: true }); throw error; }
115
115
  }
116
116
  function existingRoot(path: string): string | undefined {
117
- try { const info = lstatSync(path); if (!info.isDirectory() || info.isSymbolicLink()) throw new Error("skill root is linked or not a directory; choose a real directory"); return realpathSync(path); }
117
+ try { const info = lstatSync(path); if (info.isSymbolicLink()) throw new Error(`skill root link points to ${readlinkSync(path)}; vmem installs only into a real directory or a link to the host's default skill root`); if (!info.isDirectory()) throw new Error("skill root is not a directory; choose a real directory"); return realpathSync(path); }
118
118
  catch (error) {
119
119
  if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
120
- if (error instanceof Error && error.message.startsWith("skill root is linked")) throw error;
120
+ if (error instanceof Error && error.message.startsWith("skill root ")) throw error;
121
121
  throw new Error("skill root cannot be inspected; check its path and permissions", { cause: error });
122
122
  }
123
123
  }
@@ -127,12 +127,13 @@ function removeVerified(path: string, sha: string): boolean {
127
127
  catch { return false; }
128
128
  }
129
129
  /** Plan or install one complete skill tree per name. `root` must be an absolute target directory. */
130
- export function installSkills(root: string, mode: SetupMode, packageRoot = PACKAGE_ROOT, packageVersion = version, retryCommand = ["vmem", "skills", "export", root].map(shellWord).join(" ")): SkillInstallReport {
130
+ export function installSkills(root: string, mode: SetupMode, packageRoot = PACKAGE_ROOT, packageVersion = version, retryCommand = ["vmem", "skills", "export", root].map(shellWord).join(" "), rootGuard?: () => void): SkillInstallReport {
131
131
  if (!isAbsolute(root)) throw new Error("skills: target must be absolute; provide an absolute skill root");
132
132
  if (mode !== "undo" && (typeof packageVersion !== "string" || !packageVersion.trim() || Buffer.byteLength(packageVersion) > 128 || /[\p{Cc}\p{Zl}\p{Zp}]/u.test(packageVersion))) throw new Error("skills: package version is invalid; reinstall a valid vmem package");
133
133
  const requested = resolve(root), actions: SkillAction[] = [];
134
+ rootGuard?.();
134
135
  let actual = existingRoot(requested);
135
- if (!actual && mode !== "dry-run" && mode !== "undo") { mkdirSync(requested, { recursive: true, mode: 0o700 }); actual = existingRoot(requested); }
136
+ if (!actual && mode !== "dry-run" && mode !== "undo") { rootGuard?.(); mkdirSync(requested, { recursive: true, mode: 0o700 }); actual = existingRoot(requested); }
136
137
  if (!actual && mode === "apply") throw new Error("skills: target directory could not be created; inspect the target and retry");
137
138
  for (const name of SKILL_NAMES) {
138
139
  const target = join(actual ?? requested, name), action: SkillAction = { name, path: target, change: "absent" }; actions.push(action);
@@ -149,6 +150,7 @@ export function installSkills(root: string, mode: SetupMode, packageRoot = PACKA
149
150
  }
150
151
  if (mode === "undo") {
151
152
  if (!before) continue;
153
+ rootGuard?.();
152
154
  action.change = "remove";
153
155
  const moved = join(actual!, `.vmem-skill-${randomUUID()}`);
154
156
  renameAtomic(target, moved, false);
@@ -166,9 +168,11 @@ export function installSkills(root: string, mode: SetupMode, packageRoot = PACKA
166
168
  if (before && own?.sha256 === sha && own.version === packageVersion) { action.change = "unchanged"; continue; }
167
169
  action.change = before ? "replace" : "install";
168
170
  if (mode === "dry-run") continue;
171
+ rootGuard?.();
169
172
  const temp = stage(actual!, files, sha, packageVersion), staged = lstatSync(temp);
170
173
  let preserve = false, published = false;
171
174
  try {
175
+ rootGuard?.();
172
176
  if (!before) { renameAtomic(temp, target, false); published = true; }
173
177
  else {
174
178
  if (!identical(before, lstatSync(target))) throw new Error("skill changed before replacement; inspect it and retry");
@@ -203,6 +207,40 @@ export function skillRoot(target: SetupTarget, env: NodeJS.ProcessEnv): string |
203
207
  return join(value ? resolve(value) : join(home, spec[1]), "skills");
204
208
  }
205
209
 
210
+ /** Only an override profile may link its skill root to that host's real default root. */
211
+ export function resolveHostSkillRoot(target: SetupTarget, env: NodeJS.ProcessEnv): { root: string; linkedFrom?: string; recheck?: () => void } | undefined {
212
+ const requested = skillRoot(target, env);
213
+ if (!requested) return undefined;
214
+ let info: Stats;
215
+ try { info = lstatSync(requested); } catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") return { root: requested }; throw error; }
216
+ if (!info.isSymbolicLink()) return { root: requested };
217
+ const targetText = readlinkSync(requested);
218
+ const refused = () => new Error(`skill root link points to ${targetText}; vmem installs only into a real directory or a link to the host's default skill root`);
219
+ const vars: Partial<Record<SetupTarget, string>> = { claude: "CLAUDE_CONFIG_DIR", codex: "CODEX_HOME", kimi: "KIMI_CODE_HOME", qwen: "QWEN_HOME" };
220
+ const variable = vars[target];
221
+ if (!variable || !env[variable]?.trim()) throw refused();
222
+ const defaults = { ...env }; delete defaults[variable];
223
+ const defaultRoot = skillRoot(target, defaults)!;
224
+ let defaultInfo: Stats, actual: string;
225
+ try {
226
+ defaultInfo = lstatSync(defaultRoot);
227
+ if (!defaultInfo.isDirectory() || defaultInfo.isSymbolicLink()) throw refused();
228
+ actual = realpathSync(defaultRoot);
229
+ if (realpathSync(requested) !== actual) throw refused();
230
+ } catch { throw refused(); }
231
+ const recheck = () => {
232
+ try {
233
+ const link = lstatSync(requested), current = lstatSync(defaultRoot);
234
+ if (!link.isSymbolicLink() || link.dev !== info.dev || link.ino !== info.ino || readlinkSync(requested) !== targetText || !identical(defaultInfo, current) || realpathSync(defaultRoot) !== actual || realpathSync(requested) !== actual) throw new Error();
235
+ } catch {
236
+ let target = targetText;
237
+ try { target = readlinkSync(requested); } catch { /* Keep the last observed target when the link disappeared. */ }
238
+ throw new Error(`skill root link changed (target ${target}); inspect ${requested} before retrying`);
239
+ }
240
+ };
241
+ return { root: actual, linkedFrom: requested, recheck };
242
+ }
243
+
206
244
  /** Export into a dedicated directory. Unknown entries mean it is not a vmem export root. */
207
245
  export function exportSkills(destination: string): SkillInstallReport {
208
246
  if (typeof destination !== "string" || !destination.trim() || /[\p{Cc}\p{Zl}\p{Zp}]/u.test(destination)) throw new Error("skills export: destination is missing or invalid; choose a directory path");