agent-recall-core 3.4.37 → 3.4.38

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.
Files changed (107) hide show
  1. package/README.md +111 -53
  2. package/dist/helpers/activity-feed.d.ts.map +1 -1
  3. package/dist/helpers/activity-feed.js +12 -7
  4. package/dist/helpers/activity-feed.js.map +1 -1
  5. package/dist/helpers/alignment-patterns.d.ts.map +1 -1
  6. package/dist/helpers/alignment-patterns.js +8 -13
  7. package/dist/helpers/alignment-patterns.js.map +1 -1
  8. package/dist/helpers/handoff.d.ts.map +1 -1
  9. package/dist/helpers/handoff.js +5 -8
  10. package/dist/helpers/handoff.js.map +1 -1
  11. package/dist/helpers/journal-files.d.ts +17 -0
  12. package/dist/helpers/journal-files.d.ts.map +1 -1
  13. package/dist/helpers/journal-files.js +61 -0
  14. package/dist/helpers/journal-files.js.map +1 -1
  15. package/dist/helpers/journal-filter.d.ts +22 -0
  16. package/dist/helpers/journal-filter.d.ts.map +1 -1
  17. package/dist/helpers/journal-filter.js +23 -0
  18. package/dist/helpers/journal-filter.js.map +1 -1
  19. package/dist/helpers/journal-name-parser.d.ts +13 -2
  20. package/dist/helpers/journal-name-parser.d.ts.map +1 -1
  21. package/dist/helpers/journal-name-parser.js +46 -2
  22. package/dist/helpers/journal-name-parser.js.map +1 -1
  23. package/dist/helpers/journal-sig-theme.d.ts +11 -0
  24. package/dist/helpers/journal-sig-theme.d.ts.map +1 -1
  25. package/dist/helpers/journal-sig-theme.js +18 -0
  26. package/dist/helpers/journal-sig-theme.js.map +1 -1
  27. package/dist/naming.d.ts +10 -3
  28. package/dist/naming.d.ts.map +1 -1
  29. package/dist/naming.js +19 -15
  30. package/dist/naming.js.map +1 -1
  31. package/dist/palace/pipeline.d.ts +6 -0
  32. package/dist/palace/pipeline.d.ts.map +1 -1
  33. package/dist/palace/pipeline.js +15 -2
  34. package/dist/palace/pipeline.js.map +1 -1
  35. package/dist/palace/rooms.d.ts +20 -0
  36. package/dist/palace/rooms.d.ts.map +1 -1
  37. package/dist/palace/rooms.js +90 -0
  38. package/dist/palace/rooms.js.map +1 -1
  39. package/dist/palace/skills.d.ts +13 -0
  40. package/dist/palace/skills.d.ts.map +1 -1
  41. package/dist/palace/skills.js +53 -6
  42. package/dist/palace/skills.js.map +1 -1
  43. package/dist/storage/ab-experiment.d.ts.map +1 -1
  44. package/dist/storage/ab-experiment.js +8 -12
  45. package/dist/storage/ab-experiment.js.map +1 -1
  46. package/dist/storage/corrections.d.ts +18 -0
  47. package/dist/storage/corrections.d.ts.map +1 -1
  48. package/dist/storage/corrections.js +211 -31
  49. package/dist/storage/corrections.js.map +1 -1
  50. package/dist/storage/cwd-allowlist.d.ts.map +1 -1
  51. package/dist/storage/cwd-allowlist.js +2 -4
  52. package/dist/storage/cwd-allowlist.js.map +1 -1
  53. package/dist/storage/memory-protocol.d.ts.map +1 -1
  54. package/dist/storage/memory-protocol.js +6 -10
  55. package/dist/storage/memory-protocol.js.map +1 -1
  56. package/dist/storage/paths.d.ts +120 -1
  57. package/dist/storage/paths.d.ts.map +1 -1
  58. package/dist/storage/paths.js +145 -31
  59. package/dist/storage/paths.js.map +1 -1
  60. package/dist/storage/project.d.ts.map +1 -1
  61. package/dist/storage/project.js +12 -4
  62. package/dist/storage/project.js.map +1 -1
  63. package/dist/storage/sanitize.d.ts +54 -0
  64. package/dist/storage/sanitize.d.ts.map +1 -0
  65. package/dist/storage/sanitize.js +97 -0
  66. package/dist/storage/sanitize.js.map +1 -0
  67. package/dist/storage/session.d.ts +12 -3
  68. package/dist/storage/session.d.ts.map +1 -1
  69. package/dist/storage/session.js +45 -8
  70. package/dist/storage/session.js.map +1 -1
  71. package/dist/tools-logic/bootstrap.d.ts.map +1 -1
  72. package/dist/tools-logic/bootstrap.js +2 -4
  73. package/dist/tools-logic/bootstrap.js.map +1 -1
  74. package/dist/tools-logic/check.d.ts.map +1 -1
  75. package/dist/tools-logic/check.js +5 -8
  76. package/dist/tools-logic/check.js.map +1 -1
  77. package/dist/tools-logic/export-corrections.js +2 -2
  78. package/dist/tools-logic/export-corrections.js.map +1 -1
  79. package/dist/tools-logic/journal-capture.d.ts.map +1 -1
  80. package/dist/tools-logic/journal-capture.js +53 -36
  81. package/dist/tools-logic/journal-capture.js.map +1 -1
  82. package/dist/tools-logic/journal-write.d.ts.map +1 -1
  83. package/dist/tools-logic/journal-write.js +51 -28
  84. package/dist/tools-logic/journal-write.js.map +1 -1
  85. package/dist/tools-logic/knowledge-read.d.ts.map +1 -1
  86. package/dist/tools-logic/knowledge-read.js +8 -6
  87. package/dist/tools-logic/knowledge-read.js.map +1 -1
  88. package/dist/tools-logic/knowledge-write.d.ts.map +1 -1
  89. package/dist/tools-logic/knowledge-write.js +5 -8
  90. package/dist/tools-logic/knowledge-write.js.map +1 -1
  91. package/dist/tools-logic/palace-write.d.ts.map +1 -1
  92. package/dist/tools-logic/palace-write.js +5 -1
  93. package/dist/tools-logic/palace-write.js.map +1 -1
  94. package/dist/tools-logic/project-board.js +2 -2
  95. package/dist/tools-logic/project-board.js.map +1 -1
  96. package/dist/tools-logic/session-end.d.ts.map +1 -1
  97. package/dist/tools-logic/session-end.js +9 -4
  98. package/dist/tools-logic/session-end.js.map +1 -1
  99. package/dist/tools-logic/session-start.d.ts.map +1 -1
  100. package/dist/tools-logic/session-start.js +5 -4
  101. package/dist/tools-logic/session-start.js.map +1 -1
  102. package/dist/types.d.ts +1 -1
  103. package/dist/types.js +1 -1
  104. package/dist/vector/local-vector-store.d.ts.map +1 -1
  105. package/dist/vector/local-vector-store.js +5 -4
  106. package/dist/vector/local-vector-store.js.map +1 -1
  107. package/package.json +1 -1
@@ -7,12 +7,131 @@
7
7
  */
8
8
  /**
9
9
  * Sanitize a project name for safe use in path.join().
10
- * Strips ALL non-alphanumeric chars (including dots) to prevent ".." traversal.
10
+ *
11
+ * naming-v2 spec §2 (bug #1 — case-fold divergence): now lowercases + NFC +
12
+ * byte-caps via the shared sanitizer, instead of the old char-slice that
13
+ * preserved case. Strips ALL non-alphanumeric chars (including dots) to
14
+ * prevent ".." traversal, same as before.
15
+ *
16
+ * This function is PURE (no filesystem access) — it does not know whether a
17
+ * differently-cased directory for this project already exists on disk. Path
18
+ * builders below call `resolveProjectDirName()` to apply the v2
19
+ * EXISTING-DIR-REUSE rule on top of this before touching the filesystem.
11
20
  *
12
21
  * Exported so other modules (bootstrap, etc.) share the same hardened slug
13
22
  * grammar instead of rolling their own. Future-proofing against drift.
14
23
  */
15
24
  export declare function sanitizeProject(project: string): string;
25
+ /**
26
+ * v2 EXISTING-DIR REUSE RULE (naming-v2 spec §2, bug #1).
27
+ *
28
+ * `sanitizeProject` now lowercases, which would otherwise SPLIT an existing
29
+ * project directory the moment a caller passes a differently-cased name:
30
+ * "projects/AgentRecall" and "projects/agentrecall" are ONE inode on
31
+ * default (case-insensitive) APFS but become two silently-diverging
32
+ * directories on any case-sensitive filesystem (Linux prod, ext4 Docker, CI).
33
+ *
34
+ * Before resolving a project's directory, check whether a dir already
35
+ * exists under `projects/` that matches the sanitized slug
36
+ * case-INSENSITIVELY — if so, reuse that dir's EXACT on-disk casing for both
37
+ * reads and writes. Only a genuinely brand-new project (no existing dir
38
+ * under any casing) gets the new lowercased slug. This is a NEW-WRITES-ONLY
39
+ * concern in spirit (no existing file is ever renamed) — it just prevents
40
+ * new writes for an old project from starting a second, diverging directory.
41
+ *
42
+ * F1 fix (independent review, 2026-07-20): when MORE THAN ONE case-variant
43
+ * directory already exists for the same sanitized slug (e.g. both
44
+ * "AgentRecall" AND "agentrecall" already diverged on disk before this file
45
+ * shipped, or on a case-sensitive filesystem where two callers raced), the
46
+ * old `entries.find()` returned whichever entry `readdirSync()` happened to
47
+ * list first — filesystem/OS-dependent, NON-DETERMINISTIC across machines
48
+ * and even across repeated calls on some platforms. Resolution order is now:
49
+ * 1. An EXACT (byte-for-byte) match for the sanitized name wins outright —
50
+ * no ambiguity to resolve.
51
+ * 2. Exactly one case-insensitive match — use it (the common case).
52
+ * 3. Multiple case-variant matches — pick the LEXICOGRAPHICALLY FIRST
53
+ * (deterministic across machines and process restarts) and emit a
54
+ * one-line warning to stderr (never stdout — this runs under MCP
55
+ * stdio, and writing to stdout would corrupt the JSON-RPC stream)
56
+ * naming every variant found plus the one picked. Best-effort: a
57
+ * failed warning write must never throw.
58
+ *
59
+ * Best-effort: any fs error (missing root, permissions) falls through to the
60
+ * plain sanitized slug — a directory resolver must never throw.
61
+ */
62
+ export interface CaseVariantResolution {
63
+ /** The entry to actually use. */
64
+ picked: string;
65
+ /** Every case-insensitive match found (sorted when `ambiguous`). */
66
+ variants: string[];
67
+ /** true when MORE THAN ONE case-variant matched and a pick had to be made. */
68
+ ambiguous: boolean;
69
+ }
70
+ /**
71
+ * Pure resolution logic (F1 fix, independent review 2026-07-20), extracted
72
+ * from `resolveProjectDirName` so the exact/ambiguous/lexicographic-pick
73
+ * decision is unit-testable against a plain string array — real directories
74
+ * differing only by case cannot be fabricated for a test on the default
75
+ * case-insensitive-but-case-preserving filesystem this suite runs on (macOS
76
+ * APFS: a second `mkdirSync` for a case-variant of an existing dir silently
77
+ * collides with the first). `entries` is whatever `fs.readdirSync()` returned
78
+ * for `projects/`. Returns `null` when nothing matches (caller falls back to
79
+ * the plain sanitized slug — a brand-new project).
80
+ */
81
+ export declare function pickProjectDirEntry(sanitized: string, entries: string[]): CaseVariantResolution | null;
82
+ export declare function resolveProjectDirName(root: string, project: string): string;
83
+ /**
84
+ * Pure grouping logic for `listCaseVariantForks` — extracted for the same
85
+ * fs-free testability reason as `pickProjectDirEntry` above.
86
+ */
87
+ export declare function groupCaseVariantForks(entries: string[]): Array<{
88
+ project: string;
89
+ variants: string[];
90
+ }>;
91
+ /**
92
+ * Read-only diagnostic (F1 follow-up, independent review 2026-07-20): scan
93
+ * `root/projects` for every sanitized-slug bucket that has MORE THAN ONE
94
+ * on-disk case-variant directory. Exported for a future store-doctor
95
+ * command to surface/merge these forks — NOT wired to any write path today.
96
+ * Never throws; returns [] on any fs error or when there is no fork.
97
+ */
98
+ export declare function listCaseVariantForks(root: string): Array<{
99
+ project: string;
100
+ variants: string[];
101
+ }>;
102
+ /**
103
+ * Canonical directory name for all per-project storage under the
104
+ * AgentRecall root. Exported (F2 fix, independent review 2026-07-20) so no
105
+ * OTHER module ever needs to inline the literal "projects" — every call site
106
+ * that did was a call-site divergence risk: routing a project-specific
107
+ * sub-path through a hand-rolled `path.join(root, "projects", <slug>, ...)`
108
+ * silently skips the resolveProjectDirName EXISTING-DIR reuse rule above,
109
+ * reintroducing the exact case-fold-split bug this file exists to prevent.
110
+ * `projectsRootDir()` / `projectSubPath()` below are the two sanctioned ways
111
+ * to reference this segment from anywhere else in the package.
112
+ */
113
+ export declare const PROJECTS_DIRNAME = "projects";
114
+ /**
115
+ * The root directory containing every project's storage (read-only
116
+ * enumeration use only — e.g. `fs.readdirSync(projectsRootDir())` to list
117
+ * all known project slugs). Callers that already HOLD a specific on-disk
118
+ * slug (from such a readdir) should join directly against this — there is
119
+ * no case-fold-divergence risk when the slug came FROM disk. Callers that
120
+ * have a caller-SUPPLIED project name and want ITS directory must use
121
+ * `projectSubPath()` instead, so the EXISTING-DIR reuse rule applies.
122
+ */
123
+ export declare function projectsRootDir(): string;
124
+ /**
125
+ * Resolve an absolute path under a project's directory, applying the v2
126
+ * EXISTING-DIR reuse rule (resolveProjectDirName) and the path-escape guard
127
+ * (assertInsideRoot) exactly once. This is the ONE sanctioned way for any
128
+ * module outside this file to build a project-specific path — every
129
+ * `journalDir`/`palaceDir`/etc. helper below is defined in terms of it.
130
+ *
131
+ * `projectSubPath(project)` (no extra segments) returns the project's own
132
+ * root directory (`projects/<safe>`).
133
+ */
134
+ export declare function projectSubPath(project: string, ...segments: string[]): string;
16
135
  /**
17
136
  * Resolve the journal directory for a project.
18
137
  * For writes, always use the new location.
@@ -1 +1 @@
1
- {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/storage/paths.ts"],"names":[],"mappings":"AAAA;;;;;;GA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G;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
@@ -8,9 +8,19 @@
8
8
  import * as fs from "node:fs";
9
9
  import * as path from "node:path";
10
10
  import { getRoot, getLegacyRoot } from "../types.js";
11
+ import { sanitizeName } from "./sanitize.js";
11
12
  /**
12
13
  * Sanitize a project name for safe use in path.join().
13
- * Strips ALL non-alphanumeric chars (including dots) to prevent ".." traversal.
14
+ *
15
+ * naming-v2 spec §2 (bug #1 — case-fold divergence): now lowercases + NFC +
16
+ * byte-caps via the shared sanitizer, instead of the old char-slice that
17
+ * preserved case. Strips ALL non-alphanumeric chars (including dots) to
18
+ * prevent ".." traversal, same as before.
19
+ *
20
+ * This function is PURE (no filesystem access) — it does not know whether a
21
+ * differently-cased directory for this project already exists on disk. Path
22
+ * builders below call `resolveProjectDirName()` to apply the v2
23
+ * EXISTING-DIR-REUSE rule on top of this before touching the filesystem.
14
24
  *
15
25
  * Exported so other modules (bootstrap, etc.) share the same hardened slug
16
26
  * grammar instead of rolling their own. Future-proofing against drift.
@@ -18,11 +28,94 @@ import { getRoot, getLegacyRoot } from "../types.js";
18
28
  export function sanitizeProject(project) {
19
29
  if (!project)
20
30
  return "unnamed";
21
- const safe = project
22
- .replace(/[^a-zA-Z0-9_\-]/g, "-")
23
- .replace(/^-+|-+$/g, "")
24
- .slice(0, 100);
25
- return safe || "unnamed";
31
+ return sanitizeName(project, 100);
32
+ }
33
+ /**
34
+ * Pure resolution logic (F1 fix, independent review 2026-07-20), extracted
35
+ * from `resolveProjectDirName` so the exact/ambiguous/lexicographic-pick
36
+ * decision is unit-testable against a plain string array — real directories
37
+ * differing only by case cannot be fabricated for a test on the default
38
+ * case-insensitive-but-case-preserving filesystem this suite runs on (macOS
39
+ * APFS: a second `mkdirSync` for a case-variant of an existing dir silently
40
+ * collides with the first). `entries` is whatever `fs.readdirSync()` returned
41
+ * for `projects/`. Returns `null` when nothing matches (caller falls back to
42
+ * the plain sanitized slug — a brand-new project).
43
+ */
44
+ export function pickProjectDirEntry(sanitized, entries) {
45
+ const matches = entries.filter((e) => e.toLowerCase() === sanitized.toLowerCase());
46
+ if (matches.length === 0)
47
+ return null;
48
+ const exact = matches.find((e) => e === sanitized);
49
+ if (exact)
50
+ return { picked: exact, variants: matches, ambiguous: false };
51
+ if (matches.length === 1)
52
+ return { picked: matches[0], variants: matches, ambiguous: false };
53
+ // Multiple case-variant directories for the same slug — deterministic
54
+ // lexicographic pick.
55
+ const sorted = [...matches].sort();
56
+ return { picked: sorted[0], variants: sorted, ambiguous: true };
57
+ }
58
+ export function resolveProjectDirName(root, project) {
59
+ const sanitized = sanitizeProject(project);
60
+ try {
61
+ const projectsRoot = path.join(root, "projects");
62
+ const entries = fs.readdirSync(projectsRoot);
63
+ const resolution = pickProjectDirEntry(sanitized, entries);
64
+ if (!resolution)
65
+ return sanitized;
66
+ if (resolution.ambiguous) {
67
+ try {
68
+ process.stderr.write(`[agent-recall] WARNING: ${resolution.variants.length} case-variant project directories found for ` +
69
+ `"${sanitized}" (${resolution.variants.join(", ")}) — using "${resolution.picked}" deterministically. ` +
70
+ `Consider merging these directories.\n`);
71
+ }
72
+ catch {
73
+ // a failed diagnostic write must never break resolution
74
+ }
75
+ }
76
+ return resolution.picked;
77
+ }
78
+ catch {
79
+ return sanitized;
80
+ }
81
+ }
82
+ /**
83
+ * Pure grouping logic for `listCaseVariantForks` — extracted for the same
84
+ * fs-free testability reason as `pickProjectDirEntry` above.
85
+ */
86
+ export function groupCaseVariantForks(entries) {
87
+ const buckets = new Map();
88
+ for (const entry of entries) {
89
+ const key = entry.toLowerCase();
90
+ const arr = buckets.get(key);
91
+ if (arr)
92
+ arr.push(entry);
93
+ else
94
+ buckets.set(key, [entry]);
95
+ }
96
+ const forks = [];
97
+ for (const [project, variants] of buckets) {
98
+ if (variants.length > 1)
99
+ forks.push({ project, variants: [...variants].sort() });
100
+ }
101
+ return forks.sort((a, b) => a.project.localeCompare(b.project));
102
+ }
103
+ /**
104
+ * Read-only diagnostic (F1 follow-up, independent review 2026-07-20): scan
105
+ * `root/projects` for every sanitized-slug bucket that has MORE THAN ONE
106
+ * on-disk case-variant directory. Exported for a future store-doctor
107
+ * command to surface/merge these forks — NOT wired to any write path today.
108
+ * Never throws; returns [] on any fs error or when there is no fork.
109
+ */
110
+ export function listCaseVariantForks(root) {
111
+ try {
112
+ const projectsRoot = path.join(root, "projects");
113
+ const entries = fs.readdirSync(projectsRoot);
114
+ return groupCaseVariantForks(entries);
115
+ }
116
+ catch {
117
+ return [];
118
+ }
26
119
  }
27
120
  /**
28
121
  * Check that `resolved` is strictly inside `root` (rejects prefix matches like
@@ -35,16 +128,53 @@ function assertInsideRoot(resolved, root, project) {
35
128
  }
36
129
  }
37
130
  /**
38
- * Resolve the journal directory for a project.
39
- * For writes, always use the new location.
131
+ * Canonical directory name for all per-project storage under the
132
+ * AgentRecall root. Exported (F2 fix, independent review 2026-07-20) so no
133
+ * OTHER module ever needs to inline the literal "projects" — every call site
134
+ * that did was a call-site divergence risk: routing a project-specific
135
+ * sub-path through a hand-rolled `path.join(root, "projects", <slug>, ...)`
136
+ * silently skips the resolveProjectDirName EXISTING-DIR reuse rule above,
137
+ * reintroducing the exact case-fold-split bug this file exists to prevent.
138
+ * `projectsRootDir()` / `projectSubPath()` below are the two sanctioned ways
139
+ * to reference this segment from anywhere else in the package.
40
140
  */
41
- export function journalDir(project) {
42
- const safe = sanitizeProject(project);
141
+ export const PROJECTS_DIRNAME = "projects";
142
+ /**
143
+ * The root directory containing every project's storage (read-only
144
+ * enumeration use only — e.g. `fs.readdirSync(projectsRootDir())` to list
145
+ * all known project slugs). Callers that already HOLD a specific on-disk
146
+ * slug (from such a readdir) should join directly against this — there is
147
+ * no case-fold-divergence risk when the slug came FROM disk. Callers that
148
+ * have a caller-SUPPLIED project name and want ITS directory must use
149
+ * `projectSubPath()` instead, so the EXISTING-DIR reuse rule applies.
150
+ */
151
+ export function projectsRootDir() {
152
+ return path.join(getRoot(), PROJECTS_DIRNAME);
153
+ }
154
+ /**
155
+ * Resolve an absolute path under a project's directory, applying the v2
156
+ * EXISTING-DIR reuse rule (resolveProjectDirName) and the path-escape guard
157
+ * (assertInsideRoot) exactly once. This is the ONE sanctioned way for any
158
+ * module outside this file to build a project-specific path — every
159
+ * `journalDir`/`palaceDir`/etc. helper below is defined in terms of it.
160
+ *
161
+ * `projectSubPath(project)` (no extra segments) returns the project's own
162
+ * root directory (`projects/<safe>`).
163
+ */
164
+ export function projectSubPath(project, ...segments) {
43
165
  const root = getRoot();
44
- const resolved = path.join(root, "projects", safe, "journal");
166
+ const safe = resolveProjectDirName(root, project);
167
+ const resolved = path.join(root, PROJECTS_DIRNAME, safe, ...segments);
45
168
  assertInsideRoot(resolved, root, project);
46
169
  return resolved;
47
170
  }
171
+ /**
172
+ * Resolve the journal directory for a project.
173
+ * For writes, always use the new location.
174
+ */
175
+ export function journalDir(project) {
176
+ return projectSubPath(project, "journal");
177
+ }
48
178
  /**
49
179
  * Find all journal directories for a project (new + legacy fallback).
50
180
  *
@@ -99,11 +229,7 @@ export function journalDirs(project, includeArchive = false) {
99
229
  * Resolve the palace directory for a project.
100
230
  */
101
231
  export function palaceDir(project) {
102
- const safe = sanitizeProject(project);
103
- const root = getRoot();
104
- const resolved = path.join(root, "projects", safe, "palace");
105
- assertInsideRoot(resolved, root, project);
106
- return resolved;
232
+ return projectSubPath(project, "palace");
107
233
  }
108
234
  /**
109
235
  * Resolve a room directory within a project's palace.
@@ -132,11 +258,7 @@ export function sanitizeSlug(input) {
132
258
  * Resolve the digest directory for a project.
133
259
  */
134
260
  export function digestDir(project) {
135
- const safe = sanitizeProject(project);
136
- const root = getRoot();
137
- const resolved = path.join(root, "projects", safe, "digest");
138
- assertInsideRoot(resolved, root, project);
139
- return resolved;
261
+ return projectSubPath(project, "digest");
140
262
  }
141
263
  /**
142
264
  * Resolve the lossless raw-archive directory for a project (Wave 2).
@@ -146,11 +268,7 @@ export function digestDir(project) {
146
268
  * the lossy compression tier (awareness / palace skills).
147
269
  */
148
270
  export function archiveRawDir(project) {
149
- const safe = sanitizeProject(project);
150
- const root = getRoot();
151
- const resolved = path.join(root, "projects", safe, "journal", "archive", "raw");
152
- assertInsideRoot(resolved, root, project);
153
- return resolved;
271
+ return projectSubPath(project, "journal", "archive", "raw");
154
272
  }
155
273
  /**
156
274
  * Resolve the personal-tier directory for a project (Wave 5).
@@ -162,11 +280,7 @@ export function archiveRawDir(project) {
162
280
  * scanned by autoBackfill (which only walks journal + palace/rooms).
163
281
  */
164
282
  export function personalDir(project) {
165
- const safe = sanitizeProject(project);
166
- const root = getRoot();
167
- const resolved = path.join(root, "projects", safe, "personal");
168
- assertInsideRoot(resolved, root, project);
169
- return resolved;
283
+ return projectSubPath(project, "personal");
170
284
  }
171
285
  /**
172
286
  * Resolve the global (cross-project) digest directory.
@@ -1 +1 @@
1
- {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/storage/paths.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAErD;;;;;;GAMG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,MAAM,IAAI,GAAG,OAAO;SACjB,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC;SAChC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,KAAK,CAAC,CAAC,EAAE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C;SAChC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;SACvB,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACjB,OAAO,IAAI,IAAI,SAAS,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,OAAe;IAC3C,OAAO,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,OAAe;IACzC,OAAO,cAAc,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,eAAe,CAAC,CAAC;AAC/C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/storage/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAwB/C;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAyBxD;AAED;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CA+ErD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAsCjF;AAaD;;GAEG;AACH,wBAAgB,eAAe,IAAI,WAAW,EAAE,CAuD/C"}
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/storage/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAwB/C;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAyBxD;AAED;;;;GAIG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CA+ErD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CA6CjF;AAaD;;GAEG;AACH,wBAAgB,eAAe,IAAI,WAAW,EAAE,CAuD/C"}
@@ -5,7 +5,8 @@ import * as fs from "node:fs";
5
5
  import * as path from "node:path";
6
6
  import { execFile } from "node:child_process";
7
7
  import { promisify } from "node:util";
8
- import { getRoot, getLegacyRoot } from "../types.js";
8
+ import { getLegacyRoot } from "../types.js";
9
+ import { projectsRootDir } from "./paths.js";
9
10
  const execFileAsync = promisify(execFile);
10
11
  /**
11
12
  * Common directory names that are not valid project slugs.
@@ -167,7 +168,13 @@ export async function resolveProject(project) {
167
168
  const detected = await detectProject();
168
169
  // Gate: block auto-detected slugs from creating new dirs if invalid
169
170
  if (!isValidProjectSlug(detected)) {
170
- const projectDir = path.join(getRoot(), "projects", detected);
171
+ // Deliberately NOT routed through projectSubPath()/resolveProjectDirName:
172
+ // this is a raw existence probe for an ALREADY-INVALID slug (blocks new-dir
173
+ // creation unless legacy data already exists at this exact name) — running
174
+ // it through the sanitizing resolver would change what "exists" means for
175
+ // exactly the malformed inputs this gate exists to catch. Only the literal
176
+ // "projects" segment is routed through paths.ts (F2 fix, 2026-07-20).
177
+ const projectDir = path.join(projectsRootDir(), detected);
171
178
  if (!fs.existsSync(projectDir)) {
172
179
  throw new Error(`Auto-detected project slug "${detected}" is invalid (UUID, system dir, or deny-listed). ` +
173
180
  `Set AGENT_RECALL_PROJECT env var or pass project explicitly.`);
@@ -178,7 +185,8 @@ export async function resolveProject(project) {
178
185
  }
179
186
  // Explicit slug: validate before allowing new directory creation
180
187
  if (!isValidProjectSlug(project)) {
181
- const projectDir = path.join(getRoot(), "projects", project);
188
+ // See comment above — deliberately raw, not routed through resolveProjectDirName.
189
+ const projectDir = path.join(projectsRootDir(), project);
182
190
  if (!fs.existsSync(projectDir)) {
183
191
  throw new Error(`Invalid project slug "${project}". Slugs must contain at least one letter ` +
184
192
  `and cannot be UUIDs, end with .md, start with _, or be a reserved word ` +
@@ -215,7 +223,7 @@ function isJournalFile(f) {
215
223
  export function listAllProjects() {
216
224
  const projects = new Map();
217
225
  // New location
218
- const projectsDir = path.join(getRoot(), "projects");
226
+ const projectsDir = projectsRootDir();
219
227
  if (fs.existsSync(projectsDir)) {
220
228
  const dirs = fs.readdirSync(projectsDir);
221
229
  for (const slug of dirs) {
@@ -1 +1 @@
1
- {"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/storage/project.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGrD,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C;;;GAGG;AACH,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC;IAC5B,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS;IAC1D,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS;CACxD,CAAC,CAAC;AAEH,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC;IAC7B,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,SAA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+ *
4
+ * ONE function used by naming.ts, session.ts, corrections.ts, and paths.ts
5
+ * (project-level slugs) — call-site divergence was the source of two live
6
+ * bugs (docs/proposals/2026-07-20-naming-v2-spec.md §2).
7
+ * NOT yet adopted by room/topic-level slugs (`sanitizeSlug` in paths.ts,
8
+ * palace/rooms.ts): those remain case-PRESERVING, so room-level case-fold
9
+ * divergence on case-sensitive filesystems is still possible — tracked as a
10
+ * v2.1 item in the spec (§7); lowercasing them retroactively would re-case
11
+ * existing topic files (e.g. README.md) with no existing-dir-reuse safety
12
+ * net. Bugs closed in v2.0:
13
+ *
14
+ * 1. Case-fold divergence: `sanitizeProject`/`sanitizeSlug` never lowercased,
15
+ * so "projects/agentrecall" and "projects/AgentRecall" are one inode on
16
+ * default (case-insensitive) APFS but silently diverge into two dirs on
17
+ * any case-sensitive filesystem (Linux prod, ext4 Docker, CI).
18
+ * 2. Byte-vs-char budget: every `.slice(N)` capped UTF-16 code units, so a
19
+ * CJK/emoji slug could pass the char cap yet exceed the 255-byte
20
+ * filesystem component limit.
21
+ *
22
+ * Grammar: lowercase → Unicode NFC → collapse any run of non-`[a-z0-9-]`
23
+ * characters (INCLUDING existing runs of "-" itself) to a single "-" → trim
24
+ * leading/trailing "-" → byte-cap (never split a multi-byte codepoint) →
25
+ * fallback "unnamed" for an empty result.
26
+ *
27
+ * INVARIANT: the output never contains "--". This is what lets v2 filename
28
+ * parsers use "--" as an unambiguous field delimiter — no well-formed slug
29
+ * component can be mistaken for a field boundary.
30
+ */
31
+ /**
32
+ * Byte-safe truncation of arbitrary text (NOT necessarily already
33
+ * ASCII-sanitized — this is also exported standalone for callers that need
34
+ * to byte-cap raw, possibly multi-byte content without running it through
35
+ * the ASCII-collapsing `sanitizeName` pipeline).
36
+ *
37
+ * Walks the string one Unicode codepoint at a time (so a surrogate pair is
38
+ * never split mid-character) accumulating UTF-8 byte length, and stops
39
+ * BEFORE the codepoint that would exceed `maxBytes`. When the resulting hard
40
+ * cut lands within 8 bytes of a "-" character, prefers cutting at that "-"
41
+ * instead (word-boundary preference) — but only when doing so doesn't throw
42
+ * away the entire result. Pure string op; never throws.
43
+ */
44
+ export declare function byteCap(input: string, maxBytes: number): string;
45
+ /**
46
+ * Sanitize free text into a v2-grammar-safe name component.
47
+ *
48
+ * lowercase → NFC → collapse any run of characters outside `[a-z0-9-]`
49
+ * (including runs of the separator "-" itself, e.g. a literal "--" in the
50
+ * input) into a single "-" → trim leading/trailing "-" → byte-cap →
51
+ * fallback "unnamed" when the result is empty.
52
+ */
53
+ export declare function sanitizeName(input: string, maxBytes?: number): string;
54
+ //# sourceMappingURL=sanitize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/storage/sanitize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAgC/D;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAM,GAAG,MAAM,CAUlE"}
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Naming System v2 — shared sanitizer (Wave 1).
3
+ *
4
+ * ONE function used by naming.ts, session.ts, corrections.ts, and paths.ts
5
+ * (project-level slugs) — call-site divergence was the source of two live
6
+ * bugs (docs/proposals/2026-07-20-naming-v2-spec.md §2).
7
+ * NOT yet adopted by room/topic-level slugs (`sanitizeSlug` in paths.ts,
8
+ * palace/rooms.ts): those remain case-PRESERVING, so room-level case-fold
9
+ * divergence on case-sensitive filesystems is still possible — tracked as a
10
+ * v2.1 item in the spec (§7); lowercasing them retroactively would re-case
11
+ * existing topic files (e.g. README.md) with no existing-dir-reuse safety
12
+ * net. Bugs closed in v2.0:
13
+ *
14
+ * 1. Case-fold divergence: `sanitizeProject`/`sanitizeSlug` never lowercased,
15
+ * so "projects/agentrecall" and "projects/AgentRecall" are one inode on
16
+ * default (case-insensitive) APFS but silently diverge into two dirs on
17
+ * any case-sensitive filesystem (Linux prod, ext4 Docker, CI).
18
+ * 2. Byte-vs-char budget: every `.slice(N)` capped UTF-16 code units, so a
19
+ * CJK/emoji slug could pass the char cap yet exceed the 255-byte
20
+ * filesystem component limit.
21
+ *
22
+ * Grammar: lowercase → Unicode NFC → collapse any run of non-`[a-z0-9-]`
23
+ * characters (INCLUDING existing runs of "-" itself) to a single "-" → trim
24
+ * leading/trailing "-" → byte-cap (never split a multi-byte codepoint) →
25
+ * fallback "unnamed" for an empty result.
26
+ *
27
+ * INVARIANT: the output never contains "--". This is what lets v2 filename
28
+ * parsers use "--" as an unambiguous field delimiter — no well-formed slug
29
+ * component can be mistaken for a field boundary.
30
+ */
31
+ /**
32
+ * Byte-safe truncation of arbitrary text (NOT necessarily already
33
+ * ASCII-sanitized — this is also exported standalone for callers that need
34
+ * to byte-cap raw, possibly multi-byte content without running it through
35
+ * the ASCII-collapsing `sanitizeName` pipeline).
36
+ *
37
+ * Walks the string one Unicode codepoint at a time (so a surrogate pair is
38
+ * never split mid-character) accumulating UTF-8 byte length, and stops
39
+ * BEFORE the codepoint that would exceed `maxBytes`. When the resulting hard
40
+ * cut lands within 8 bytes of a "-" character, prefers cutting at that "-"
41
+ * instead (word-boundary preference) — but only when doing so doesn't throw
42
+ * away the entire result. Pure string op; never throws.
43
+ */
44
+ export function byteCap(input, maxBytes) {
45
+ if (maxBytes <= 0)
46
+ return "";
47
+ if (Buffer.byteLength(input, "utf-8") <= maxBytes)
48
+ return input;
49
+ let bytes = 0;
50
+ let cutIndex = input.length;
51
+ for (let i = 0; i < input.length;) {
52
+ const codePoint = input.codePointAt(i);
53
+ if (codePoint === undefined)
54
+ break;
55
+ const char = String.fromCodePoint(codePoint);
56
+ const charBytes = Buffer.byteLength(char, "utf-8");
57
+ if (bytes + charBytes > maxBytes) {
58
+ cutIndex = i;
59
+ break;
60
+ }
61
+ bytes += charBytes;
62
+ i += char.length; // advance by 1 or 2 UTF-16 code units (surrogate pair)
63
+ }
64
+ const hardCut = input.slice(0, cutIndex);
65
+ // Word-boundary preference: if a "-" exists within the last 8 bytes of the
66
+ // hard cut, prefer cutting there so a slug doesn't end mid-word.
67
+ const windowStart = Math.max(0, hardCut.length - 8);
68
+ const window = hardCut.slice(windowStart);
69
+ const lastDash = window.lastIndexOf("-");
70
+ if (lastDash !== -1) {
71
+ const candidate = hardCut.slice(0, windowStart + lastDash);
72
+ if (candidate.length > 0)
73
+ return candidate;
74
+ }
75
+ return hardCut;
76
+ }
77
+ /**
78
+ * Sanitize free text into a v2-grammar-safe name component.
79
+ *
80
+ * lowercase → NFC → collapse any run of characters outside `[a-z0-9-]`
81
+ * (including runs of the separator "-" itself, e.g. a literal "--" in the
82
+ * input) into a single "-" → trim leading/trailing "-" → byte-cap →
83
+ * fallback "unnamed" when the result is empty.
84
+ */
85
+ export function sanitizeName(input, maxBytes = 100) {
86
+ if (!input)
87
+ return "unnamed";
88
+ const collapsed = input
89
+ .toLowerCase()
90
+ .normalize("NFC")
91
+ .replace(/[^a-z0-9-]+/g, "-") // strip disallowed chars to "-"
92
+ .replace(/-{2,}/g, "-") // collapse any resulting (or pre-existing) "--" runs
93
+ .replace(/^-+|-+$/g, ""); // trim leading/trailing "-"
94
+ const capped = byteCap(collapsed, maxBytes).replace(/^-+|-+$/g, "");
95
+ return capped || "unnamed";
96
+ }
97
+ //# sourceMappingURL=sanitize.js.map