A self-organizing Obsidian vault that gives AI coding agents persistent memory.
TypeScript ai-agentsclaude-codecodex-cligemini-cliknowledge-managementobsidianobsidian-vaultpersistent-memorysecond-braintemplate
fix: derive the auto-memory directory on Windows so tidy-fix migrates strays there (#294)
Brenno Ferrari962ee8ed83fa
diff --git a/.claude/scripts/tests/tidy-fix.test.ts b/.claude/scripts/tests/tidy-fix.test.tsindex 9d9e702..f074a92 100644--- a/.claude/scripts/tests/tidy-fix.test.ts+++ b/.claude/scripts/tests/tidy-fix.test.ts@@ -21,6 +21,7 @@ import { tmpdir } from "node:os";import { fileURLToPath } from "node:url";import { rmTemp } from "./_helpers.ts";+import { projectSlug } from "../tidy-fix.ts";const SCRIPT = resolve(dirname(fileURLToPath(import.meta.url)),@@ -34,6 +35,7 @@ function run(args: string[],root = ROOT,memDir = MEMDIR,+ extraEnv: NodeJS.ProcessEnv = {},): { stdout: string; code: number } {const r = spawnSync(process.execPath,@@ -44,6 +46,7 @@ function run(...process.env,CLAUDE_PROJECT_DIR: root,TIDY_FIX_MEMORY_DIR: memDir,+ ...extraEnv,},},);@@ -228,3 +231,50 @@ describe("tidy-fix — failures are reported as failed, never fixed", () => {}});});++/**+ * The memory folder used to be derived for POSIX paths only: every Windows+ * vault returned null, so the misplaced-memory migration never ran there,+ * and a POSIX path containing `.` or a space derived the wrong folder.+ * Expected names below are folders Claude Code actually created.+ */+describe("projectSlug — Claude Code's project folder naming", () => {+ test("Windows drive path: colon and separators become dashes", () => {+ assert.equal(projectSlug(String.raw`C:\Dev\obsidian-mind`), "C--Dev-obsidian-mind");+ assert.equal(projectSlug("C:/Dev/obsidian-mind"), "C--Dev-obsidian-mind");+ });+ test("dots and spaces become dashes; case and existing dashes are kept", () => {+ assert.equal(projectSlug(String.raw`C:\Dev\site.com-next`), "C--Dev-site-com-next");+ assert.equal(+ projectSlug(String.raw`D:\Games\Some Dedicated Server`),+ "D--Games-Some-Dedicated-Server",+ );+ assert.equal(projectSlug(String.raw`C:\Dev\MixedCaseApp`), "C--Dev-MixedCaseApp");+ });+ test("a drive root keeps its separator, as Claude Code names it", () => {+ assert.equal(projectSlug("C:\\"), "C--");+ assert.equal(projectSlug("/home/a/vault"), "-home-a-vault");+ });+});++describe("tidy-fix — memory folder derived without the override", () => {+ test("finds <config>/projects/<slug>/memory and migrates the stray", () => {+ const root = mkdtempSync(join(tmpdir(), "tidy-fix-slug-"));+ const config = mkdtempSync(join(tmpdir(), "tidy-fix-config-"));+ try {+ mkdirSync(join(root, "brain"), { recursive: true });+ const mem = join(config, "projects", projectSlug(root), "memory");+ mkdirSync(mem, { recursive: true });+ writeFileSync(join(mem, "MEMORY.md"), "old index\n");+ writeFileSync(join(mem, "found.md"), "# found\n");+ const { stdout, code } = run(["--apply"], root, "", { CLAUDE_CONFIG_DIR: config });+ assert.equal(code, 0, stdout);+ assert.ok(section(stdout, /^Fixed:$/).some((l) => l.startsWith("memory/found.md →")), stdout);+ assert.equal(readFileSync(join(root, "brain/found.md"), "utf-8"), "# found\n");+ assert.ok(!existsSync(join(mem, "found.md")));+ } finally {+ rmTemp(root);+ rmTemp(config);+ }+ });+});diff --git a/.claude/scripts/tidy-fix.ts b/.claude/scripts/tidy-fix.tsindex 74532a0..3ed6578 100644--- a/.claude/scripts/tidy-fix.ts+++ b/.claude/scripts/tidy-fix.ts@@ -35,8 +35,8 @@* node --experimental-strip-types .claude/scripts/tidy-fix.ts [--apply]** TIDY_FIX_MEMORY_DIR overrides the auto-memory dir (tests); otherwise it- * is derived from Claude Code's project-slug convention on POSIX paths and- * skipped (with a note) when it can't be derived or doesn't exist.+ * is derived from Claude Code's project-folder naming (see `projectSlug`)+ * on every platform, and skipped when that folder doesn't exist.*/import { spawnSync } from "node:child_process";@@ -45,6 +45,7 @@ import {mkdirSync,readdirSync,readFileSync,+ realpathSync,renameSync,rmSync,writeFileSync,@@ -93,14 +94,39 @@ function recordFix(else report.failed.push(line);}-/** Claude Code's project slug: POSIX path with separators dashed. */-function deriveMemoryDir(vaultRoot: string): string | null {+/**+ * Claude Code's project folder name: every character that is not a letter,+ * a digit or `-` becomes `-`, case kept, on every platform. Observed:+ * `C:\Dev\site.com-next` → `C--Dev-site-com-next`, a path with spaces →+ * dashes, `C:\` → `C--`, `/home/a/vault` → `-home-a-vault`. The same rule as+ * `.github/scripts/delivery-gate.ts:sessionDirs`.+ */+export function projectSlug(path: string): string {+ return path.replace(/[^A-Za-z0-9-]/g, "-");+}++/**+ * The auto-memory folder for this vault. Claude Code may slug the path as+ * given or as resolved (macOS's /var is /private/var), so both are tried and+ * the first that exists wins; neither existing means no memory here.+ */+function deriveMemoryDir(vaultRoot: string): string {const override = process.env["TIDY_FIX_MEMORY_DIR"];if (override) return override;- const posix = vaultRoot.replaceAll("\\", "/").replace(/\/+$/, "");- if (!posix.startsWith("/")) return null; // Windows slug convention unknown- const slug = posix.replaceAll("/", "-");- return join(homedir(), ".claude", "projects", slug, "memory");+ const projects = join(+ process.env["CLAUDE_CONFIG_DIR"] ?? join(homedir(), ".claude"),+ "projects",+ );+ let real = vaultRoot;+ try {+ real = realpathSync(vaultRoot);+ } catch {+ /* keep the path as given */+ }+ const dirs = [...new Set([vaultRoot, real].map(projectSlug))].map((slug) =>+ join(projects, slug, "memory"),+ );+ return dirs.find((d) => existsSync(d)) ?? (dirs[0] as string);}/** git mv with a plain-rename fallback (still zero-loss; noted in output). */@@ -206,12 +232,6 @@ function fixMisplacedMemory(report: Report,): void {const memDir = deriveMemoryDir(vaultRoot);- if (memDir === null) {- report.notes.push(- "memory dir not derivable on this platform — misplaced-memory scan skipped",- );- return;- }let entries: string[];try {entries = readdirSync(memDir).filter(