notesoup 0.42.0 → 0.44.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.
Files changed (126) hide show
  1. package/dist/src/boot/render.js +11 -20
  2. package/dist/src/boot/snapshot.d.ts +2 -0
  3. package/dist/src/boot/snapshot.js +4 -5
  4. package/dist/src/boot/text.js +4 -2
  5. package/dist/src/budget/parse.d.ts +14 -0
  6. package/dist/src/budget/parse.js +36 -0
  7. package/dist/src/budget/policy.js +2 -7
  8. package/dist/src/budget/text.d.ts +2 -0
  9. package/dist/src/budget/text.js +2 -0
  10. package/dist/src/claude/helper.js +3 -4
  11. package/dist/src/claude/thresholds.js +45 -66
  12. package/dist/src/dream/lock.js +6 -13
  13. package/dist/src/dream/report.js +5 -15
  14. package/dist/src/history/history.js +4 -2
  15. package/dist/src/history/query.js +10 -22
  16. package/dist/src/notes/address.d.ts +2 -3
  17. package/dist/src/notes/address.js +10 -22
  18. package/dist/src/notes/errors.d.ts +2 -0
  19. package/dist/src/notes/errors.js +5 -0
  20. package/dist/src/notes/frontmatter.js +16 -2
  21. package/dist/src/notes/identity.js +2 -4
  22. package/dist/src/notes/paths.d.ts +7 -2
  23. package/dist/src/notes/paths.js +18 -60
  24. package/dist/src/notes/project-home.d.ts +25 -0
  25. package/dist/src/notes/project-home.js +231 -0
  26. package/dist/src/notes/store.d.ts +4 -2
  27. package/dist/src/notes/store.js +52 -45
  28. package/dist/src/pi/boot.js +17 -9
  29. package/dist/src/pi/budget.d.ts +3 -3
  30. package/dist/src/pi/budget.js +11 -11
  31. package/dist/src/pi/dream/cli.js +43 -11
  32. package/dist/src/pi/estimate.d.ts +1 -5
  33. package/dist/src/pi/estimate.js +4 -4
  34. package/dist/src/pi/history.js +1 -4
  35. package/dist/src/pi/notes/adapter.d.ts +1 -1
  36. package/dist/src/pi/notes/adapter.js +3 -3
  37. package/dist/src/pi/reset/artifacts.d.ts +0 -2
  38. package/dist/src/pi/reset/artifacts.js +4 -4
  39. package/dist/src/pi/reset/committed.js +2 -2
  40. package/dist/src/pi/runtime.js +8 -5
  41. package/dist/src/pi/thresholds.js +5 -9
  42. package/dist/src/pi/tool-result.d.ts +1 -4
  43. package/dist/src/pi/tool-result.js +1 -1
  44. package/dist/src/pi/window.d.ts +5 -0
  45. package/dist/src/pi/window.js +7 -0
  46. package/dist/src/settings.d.ts +2 -0
  47. package/dist/src/settings.js +4 -3
  48. package/dist/src/tools/history.js +4 -7
  49. package/dist/src/tools/notes.d.ts +47 -21
  50. package/dist/src/tools/notes.js +20 -19
  51. package/dist/src/tools/output.d.ts +0 -3
  52. package/dist/src/tools/output.js +1 -9
  53. package/dist/src/tools/result.d.ts +1 -0
  54. package/dist/src/tools/result.js +14 -20
  55. package/dist/src/tools/schema.d.ts +0 -1
  56. package/dist/src/tools/schema.js +0 -1
  57. package/dist/test/agent-loop.test.js +1 -2
  58. package/dist/test/boot.integration.test.js +1 -1
  59. package/dist/test/claude-mod.test.js +253 -10
  60. package/dist/test/claude-validation.test.d.ts +1 -0
  61. package/dist/test/claude-validation.test.js +73 -0
  62. package/dist/test/dream-skill.test.js +2 -4
  63. package/dist/test/dream.test.js +14 -0
  64. package/dist/test/helpers/extension.js +1 -1
  65. package/dist/test/history.integration.test.js +2 -1
  66. package/dist/test/host-neutral.test.js +15 -0
  67. package/dist/test/notes-library.test.js +30 -1
  68. package/dist/test/notes.integration.test.js +7 -7
  69. package/dist/test/notes.test.js +36 -14
  70. package/dist/test/project-home.test.d.ts +1 -0
  71. package/dist/test/project-home.test.js +134 -0
  72. package/dist/test/reset-lifecycle.test.js +1 -1
  73. package/docs/claude-code-mod.md +5 -3
  74. package/mods/notesoup/.claude-plugin/plugin.json +1 -1
  75. package/mods/notesoup/dist/claude/helper.js +359 -218
  76. package/mods/notesoup/hooks/register.ts +158 -67
  77. package/mods/notesoup/playbook.md +1 -1
  78. package/mods/notesoup/skills/dream/SKILL.md +1 -1
  79. package/mods/notesoup/skills/memory/SKILL.md +62 -0
  80. package/package.json +5 -3
  81. package/playbook.md +1 -1
  82. package/skills/dream/SKILL.md +1 -1
  83. package/skills/memory/SKILL.md +2 -1
  84. package/src/boot/render.ts +11 -21
  85. package/src/boot/snapshot.ts +5 -5
  86. package/src/boot/text.ts +4 -2
  87. package/src/budget/parse.ts +39 -0
  88. package/src/budget/policy.ts +2 -6
  89. package/src/budget/text.ts +3 -0
  90. package/src/claude/helper.ts +4 -4
  91. package/src/claude/thresholds.ts +45 -62
  92. package/src/dream/lock.ts +3 -9
  93. package/src/dream/report.ts +5 -10
  94. package/src/history/history.ts +4 -2
  95. package/src/history/query.ts +10 -23
  96. package/src/notes/address.ts +9 -21
  97. package/src/notes/errors.ts +6 -0
  98. package/src/notes/frontmatter.ts +12 -2
  99. package/src/notes/identity.ts +1 -3
  100. package/src/notes/paths.ts +14 -52
  101. package/src/notes/project-home.ts +197 -0
  102. package/src/notes/store.ts +46 -45
  103. package/src/pi/boot.ts +15 -17
  104. package/src/pi/budget.ts +10 -11
  105. package/src/pi/dream/cli.ts +35 -10
  106. package/src/pi/estimate.ts +4 -4
  107. package/src/pi/history.ts +1 -5
  108. package/src/pi/notes/adapter.ts +3 -3
  109. package/src/pi/reset/artifacts.ts +4 -4
  110. package/src/pi/reset/committed.ts +2 -2
  111. package/src/pi/runtime.ts +7 -6
  112. package/src/pi/thresholds.ts +5 -11
  113. package/src/pi/tool-result.ts +1 -1
  114. package/src/pi/window.ts +8 -0
  115. package/src/settings.ts +4 -3
  116. package/src/tools/history.ts +4 -8
  117. package/src/tools/notes.ts +22 -25
  118. package/src/tools/output.ts +1 -12
  119. package/src/tools/result.ts +14 -19
  120. package/src/tools/schema.ts +0 -1
  121. package/dist/src/dream/playbook.d.ts +0 -1
  122. package/dist/src/dream/playbook.js +0 -2
  123. package/dist/src/pi/reset/text.d.ts +0 -4
  124. package/dist/src/pi/reset/text.js +0 -7
  125. package/src/dream/playbook.ts +0 -3
  126. package/src/pi/reset/text.ts +0 -9
@@ -5,7 +5,7 @@ var __export = (target, all) => {
5
5
  };
6
6
 
7
7
  // src/claude/helper.ts
8
- import { realpathSync } from "node:fs";
8
+ import { realpathSync as realpathSync2 } from "node:fs";
9
9
  import { pathToFileURL } from "node:url";
10
10
 
11
11
  // node_modules/typebox/build/system/arguments/arguments.mjs
@@ -7933,10 +7933,17 @@ function parseNote(raw, now = Date.now()) {
7933
7933
  function yamlScalar(value) {
7934
7934
  if (typeof value === "string") {
7935
7935
  const reserved = /* @__PURE__ */ new Set(["true", "false", "null", "yes", "no", "on", "off", "~"]);
7936
- if (/^[A-Za-z0-9_.+\-:/]+$/.test(value) && !reserved.has(value.toLowerCase())) return value;
7936
+ if (/^[A-Za-z0-9_.+\-:/]+$/.test(value) && !reserved.has(value.toLowerCase()) && !parsesAsNonString(value)) return value;
7937
7937
  }
7938
7938
  return JSON.stringify(value);
7939
7939
  }
7940
+ function parsesAsNonString(text) {
7941
+ try {
7942
+ return typeof JSON.parse(text) !== "string";
7943
+ } catch {
7944
+ return false;
7945
+ }
7946
+ }
7940
7947
  function serializeNote(meta, body) {
7941
7948
  const lines = [];
7942
7949
  for (const key of KNOWN_KEYS) {
@@ -7967,9 +7974,9 @@ function isFilesystemError(error) {
7967
7974
  }
7968
7975
 
7969
7976
  // src/notes/store.ts
7970
- import { randomUUID } from "node:crypto";
7977
+ import { randomUUID as randomUUID2 } from "node:crypto";
7971
7978
  import { mkdir, readdir as readdir2, readFile, rename, rm, writeFile } from "node:fs/promises";
7972
- import { dirname as dirname2, join as join2, resolve as resolve3 } from "node:path";
7979
+ import { dirname as dirname2, join as join3, resolve as resolve3 } from "node:path";
7973
7980
 
7974
7981
  // src/text-match.ts
7975
7982
  function earliestMatchOffsetChars(text, queries) {
@@ -7996,18 +8003,171 @@ var NoteError = class extends Error {
7996
8003
  this.editIndex = extra.editIndex;
7997
8004
  }
7998
8005
  };
8006
+ function shown(value) {
8007
+ const json = JSON.stringify(value);
8008
+ return json === void 0 ? String(value) : json;
8009
+ }
7999
8010
 
8000
8011
  // src/notes/paths.ts
8001
- import { createHash } from "node:crypto";
8002
- import { existsSync, readFileSync, statSync } from "node:fs";
8003
8012
  import { readdir } from "node:fs/promises";
8013
+ import { join as join2 } from "node:path";
8014
+
8015
+ // src/notes/project-home.ts
8016
+ import { randomUUID } from "node:crypto";
8017
+ import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
8004
8018
  import { basename, dirname, join, resolve, sep } from "node:path";
8005
- var SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
8006
- function projectKey(cwd) {
8019
+ function errno(error) {
8020
+ return typeof error === "object" && error !== null ? error.code : void 0;
8021
+ }
8022
+ function normalizeRemote(value) {
8023
+ let text = value.trim();
8024
+ const scp = /^(?:[^/@]+)@([^:/]+):(.+)$/.exec(text);
8025
+ if (scp) text = `${scp[1].toLowerCase()}/${scp[2]}`;
8026
+ else if (/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(text)) {
8027
+ try {
8028
+ const url = new URL(text);
8029
+ const host = url.hostname.toLowerCase();
8030
+ const port = url.port.length > 0 ? `:${url.port}` : "";
8031
+ text = `${host}${port}${url.pathname}`;
8032
+ } catch {
8033
+ text = text.replace(/^[A-Za-z][A-Za-z0-9+.-]*:\/\//, "").replace(/^[^/@]+@/, "");
8034
+ }
8035
+ } else {
8036
+ text = text.replace(/^[^/@]+@/, "");
8037
+ const slash = text.indexOf("/");
8038
+ if (slash > 0) text = `${text.slice(0, slash).toLowerCase()}${text.slice(slash)}`;
8039
+ }
8040
+ text = text.replace(/\/+$/, "").replace(/\.git$/i, "").replace(/\/+$/, "");
8041
+ return text;
8042
+ }
8043
+ function canonicalRoot(cwd) {
8007
8044
  const absolute = resolve(cwd);
8008
- const root = gitRoot(absolute) ?? absolute;
8009
- const digest = createHash("sha1").update(root).digest("hex").slice(0, 8);
8010
- return `${basename(root)}-${digest}`;
8045
+ const spelled = gitRoot(absolute) ?? absolute;
8046
+ try {
8047
+ return realpathSync(spelled);
8048
+ } catch {
8049
+ return spelled;
8050
+ }
8051
+ }
8052
+ function originRemote(root) {
8053
+ let gitDir = join(root, ".git");
8054
+ let raw;
8055
+ try {
8056
+ if (!statSync(gitDir).isDirectory()) {
8057
+ const pointer = /^gitdir:\s*(.+)$/m.exec(readFileSync(gitDir, "utf8"));
8058
+ if (!pointer) return void 0;
8059
+ gitDir = resolve(root, pointer[1].trim());
8060
+ }
8061
+ try {
8062
+ gitDir = resolve(gitDir, readFileSync(join(gitDir, "commondir"), "utf8").trim());
8063
+ } catch (error) {
8064
+ if (errno(error) !== "ENOENT") throw error;
8065
+ }
8066
+ raw = readFileSync(join(gitDir, "config"), "utf8");
8067
+ } catch (error) {
8068
+ if (errno(error) === "ENOENT") return void 0;
8069
+ throw error;
8070
+ }
8071
+ let origin = false;
8072
+ for (const line of raw.split(/\r?\n/)) {
8073
+ const section2 = /^\s*\[remote\s+"([^"]+)"\]\s*$/.exec(line);
8074
+ if (section2) {
8075
+ origin = section2[1] === "origin";
8076
+ continue;
8077
+ }
8078
+ if (/^\s*\[/.test(line)) origin = false;
8079
+ if (origin) {
8080
+ const url = /^\s*url\s*=\s*(.*?)\s*$/.exec(line);
8081
+ if (url) return normalizeRemote(url[1].replace(/^"(.*)"$/, "$1")) || void 0;
8082
+ }
8083
+ }
8084
+ return void 0;
8085
+ }
8086
+ function readMarker(dir) {
8087
+ let raw;
8088
+ try {
8089
+ raw = readFileSync(join(dir, ".project"), "utf8");
8090
+ } catch (error) {
8091
+ if (errno(error) === "ENOENT") return void 0;
8092
+ throw error;
8093
+ }
8094
+ try {
8095
+ const value = JSON.parse(raw);
8096
+ if (typeof value.id !== "string" || value.id.length === 0 || typeof value.path !== "string" || value.path.length === 0) return void 0;
8097
+ return { name: basename(dir), dir, id: value.id, path: value.path };
8098
+ } catch {
8099
+ return void 0;
8100
+ }
8101
+ }
8102
+ function projectRoot(home) {
8103
+ return join(home, "project");
8104
+ }
8105
+ function projectHomes(home) {
8106
+ const root = projectRoot(home);
8107
+ let entries;
8108
+ try {
8109
+ entries = readdirSync(root, { withFileTypes: true });
8110
+ } catch (error) {
8111
+ if (errno(error) === "ENOENT") return [];
8112
+ throw error;
8113
+ }
8114
+ return entries.filter((entry) => entry.isDirectory()).map((entry) => readMarker(join(root, entry.name))).filter((entry) => entry !== void 0).sort((a, b) => a.name.localeCompare(b.name));
8115
+ }
8116
+ function updateMarker(home, marker) {
8117
+ const markerPath = join(home.dir, ".project");
8118
+ const temp = `${markerPath}.${process.pid}.${randomUUID()}.tmp`;
8119
+ try {
8120
+ writeFileSync(temp, JSON.stringify(marker));
8121
+ renameSync(temp, markerPath);
8122
+ } catch (error) {
8123
+ try {
8124
+ rmSync(temp, { force: true });
8125
+ } catch {
8126
+ }
8127
+ throw error;
8128
+ }
8129
+ return { ...home, ...marker };
8130
+ }
8131
+ function resolveProjectHome(cwd, home) {
8132
+ const root = canonicalRoot(cwd);
8133
+ const remote = originRemote(root);
8134
+ const id = remote ?? root;
8135
+ const markerRoot = projectRoot(home);
8136
+ mkdirSync(markerRoot, { recursive: true });
8137
+ const homes = projectHomes(home);
8138
+ let found = homes.find((candidate) => candidate.id === id);
8139
+ if (!found && remote) {
8140
+ found = homes.find((candidate) => candidate.id === root);
8141
+ if (found) found = updateMarker(found, { id: remote, path: root });
8142
+ }
8143
+ if (found) {
8144
+ if (found.path !== root) found = updateMarker(found, { id: found.id, path: root });
8145
+ return found;
8146
+ }
8147
+ const base = slugify(basename(root));
8148
+ const taken = new Set(readdirSync(markerRoot));
8149
+ for (let suffix = 0; ; suffix++) {
8150
+ const name = suffix === 0 ? base : `${base}-${suffix}`;
8151
+ if (taken.has(name)) continue;
8152
+ const dir = join(markerRoot, name);
8153
+ try {
8154
+ mkdirSync(dir, { recursive: true });
8155
+ writeFileSync(join(dir, ".project"), JSON.stringify({ id, path: root }), { flag: "wx" });
8156
+ return { name, dir, id, path: root };
8157
+ } catch (error) {
8158
+ if (errno(error) === "EEXIST") continue;
8159
+ throw error;
8160
+ }
8161
+ }
8162
+ }
8163
+ function gitRoot(cwd) {
8164
+ let dir = resolve(cwd);
8165
+ for (; ; ) {
8166
+ if (existsSync(join(dir, ".git"))) return repositoryRoot(dir);
8167
+ const parent = dirname(dir);
8168
+ if (parent === dir) return void 0;
8169
+ dir = parent;
8170
+ }
8011
8171
  }
8012
8172
  function repositoryRoot(dir) {
8013
8173
  let stats;
@@ -8031,30 +8191,45 @@ function repositoryRoot(dir) {
8031
8191
  const common = parts.slice(0, worktrees).join(sep);
8032
8192
  return basename(common) === ".git" ? dirname(common) : dir;
8033
8193
  }
8034
- function gitRoot(cwd) {
8035
- let dir = resolve(cwd);
8036
- for (; ; ) {
8037
- if (existsSync(join(dir, ".git"))) return repositoryRoot(dir);
8038
- const parent = dirname(dir);
8039
- if (parent === dir) return void 0;
8040
- dir = parent;
8041
- }
8194
+ function projectReceipt(home, name) {
8195
+ const project = readMarker(join(projectRoot(home), name));
8196
+ if (!project) return {};
8197
+ const base = slugify(basename(project.path));
8198
+ const siblings = projectHomes(home).filter((candidate) => candidate.name !== name && slugify(basename(candidate.path)) === base);
8199
+ return {
8200
+ project_root: project.path,
8201
+ ...siblings.length === 0 ? {} : { project_siblings: siblings.map(({ name: name2, path }) => ({ name: name2, path })) }
8202
+ };
8203
+ }
8204
+
8205
+ // src/notes/paths.ts
8206
+ var SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
8207
+ function slugify(value) {
8208
+ const slug = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
8209
+ return slug.length > 0 ? slug : "root";
8210
+ }
8211
+ function assertVirtualPath(value) {
8212
+ if (typeof value !== "string" || value.length === 0) throw new NoteError("invalid_address", "The address is empty; give the note a path.");
8213
+ if (value.includes("\0") || value.includes("\\") || value.startsWith("/")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't start with "/" or contain "\\" or NUL.`);
8214
+ const parts = value.split("/");
8215
+ if (parts.some((part) => part.length === 0 || part === "." || part === "..")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't have empty, ".", or ".." folder names.`);
8216
+ return value;
8042
8217
  }
8043
8218
  function sessionHomesRoot(home) {
8044
- return join(home, "pi", "session");
8219
+ return join2(home, "pi", "session");
8045
8220
  }
8046
8221
  function scopeDir(scope, identity2, who) {
8047
8222
  if (!["session", "project", "human", "agent", "model"].includes(scope)) throw new TypeError("invalid notes scope");
8048
- if (who !== void 0 && (scope !== "agent" && scope !== "model" || !SLUG_PATTERN.test(who))) throw new TypeError("who must be a canonical agent/model slug");
8049
- if (scope === "human") return join(identity2.home, "human");
8050
- if (scope === "project") return join(identity2.home, "project", identity2.projectKey);
8051
- if (scope === "agent") return join(identity2.home, "agents", who ?? identity2.agent);
8052
- if (scope === "model") return join(identity2.home, "models", who ?? identity2.model);
8053
- return join(sessionHomesRoot(identity2.home), identity2.sessionId);
8223
+ if (who !== void 0 && (scope !== "project" && scope !== "agent" && scope !== "model" || !SLUG_PATTERN.test(who))) throw new TypeError("who must be a canonical project/agent/model slug");
8224
+ if (scope === "human") return join2(identity2.home, "human");
8225
+ if (scope === "project") return join2(identity2.home, "project", who ?? identity2.projectKey);
8226
+ if (scope === "agent") return join2(identity2.home, "agents", who ?? identity2.agent);
8227
+ if (scope === "model") return join2(identity2.home, "models", who ?? identity2.model);
8228
+ return join2(sessionHomesRoot(identity2.home), identity2.sessionId);
8054
8229
  }
8055
8230
  async function namespaceSlugs(namespace, home) {
8056
8231
  try {
8057
- return (await readdir(join(home, namespace), { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
8232
+ return (await readdir(join2(home, namespace), { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
8058
8233
  } catch (error) {
8059
8234
  if (error.code === "ENOENT") return [];
8060
8235
  throw error;
@@ -8064,24 +8239,11 @@ function noteFileName(vpath) {
8064
8239
  return vpath.endsWith(".md") ? vpath : `${vpath}.md`;
8065
8240
  }
8066
8241
  function physicalPath(scope, vpath, identity2, who) {
8067
- if (typeof vpath !== "string" || vpath.length === 0 || vpath.includes("\0") || vpath.includes("\\") || vpath.startsWith("/")) throw new TypeError("path must be a safe virtual relative path");
8068
- if (vpath.split("/").some((part) => part.length === 0 || part === "." || part === "..")) throw new TypeError("path contains an unsupported component");
8069
- return join(scopeDir(scope, identity2, who), ...noteFileName(vpath).split("/"));
8242
+ return join2(scopeDir(scope, identity2, who), ...noteFileName(vpath).split("/"));
8070
8243
  }
8071
8244
 
8072
8245
  // src/notes/address.ts
8073
- var ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path.";
8074
- function shown(value) {
8075
- const json = JSON.stringify(value);
8076
- return json === void 0 ? String(value) : json;
8077
- }
8078
- function assertVirtualPath(value) {
8079
- if (typeof value !== "string" || value.length === 0) throw new NoteError("invalid_address", "The address is empty; give the note a path.");
8080
- if (value.includes("\0") || value.includes("\\") || value.startsWith("/")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't start with "/" or contain "\\" or NUL.`);
8081
- const parts = value.split("/");
8082
- if (parts.some((part) => part.length === 0 || part === "." || part === "..")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't have empty, ".", or ".." folder names.`);
8083
- return value;
8084
- }
8246
+ var ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> reads a named project home.";
8085
8247
  function globToRegExp(pattern) {
8086
8248
  let source = "^";
8087
8249
  for (let index = 0; index < pattern.length; index++) {
@@ -8094,6 +8256,8 @@ function globToRegExp(pattern) {
8094
8256
  } else {
8095
8257
  source += "[^/]*";
8096
8258
  }
8259
+ } else if (char === "?") {
8260
+ source += "[^/]";
8097
8261
  } else {
8098
8262
  source += char.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
8099
8263
  }
@@ -8121,11 +8285,11 @@ function assertAddress(value) {
8121
8285
  else if (head === "human") scope = "human";
8122
8286
  else if (head === "self") scope = "agent";
8123
8287
  else if (head === "model") scope = "model";
8124
- else if (head === "agents" || head === "models") {
8288
+ else if (head === "projects" || head === "agents" || head === "models") {
8125
8289
  const nameEnd = tail.indexOf("/");
8126
8290
  who = nameEnd === -1 ? tail : tail.slice(0, nameEnd);
8127
8291
  if (!SLUG_PATTERN.test(who)) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
8128
- scope = head === "agents" ? "agent" : "model";
8292
+ scope = head === "projects" ? "project" : head === "agents" ? "agent" : "model";
8129
8293
  path = nameEnd === -1 ? "" : tail.slice(nameEnd + 1);
8130
8294
  } else {
8131
8295
  throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
@@ -8139,7 +8303,7 @@ function assertAddress(value) {
8139
8303
  }
8140
8304
  function canonicalAddressFor(identity2, scope, path, who) {
8141
8305
  if (scope === "session") return path;
8142
- if (scope === "project") return `@project/${path}`;
8306
+ if (scope === "project") return who === void 0 ? `@project/${path}` : `@projects/${who}/${path}`;
8143
8307
  if (scope === "human") return `@human/${path}`;
8144
8308
  if (scope === "agent") return `@agents/${who ?? identity2.agent}/${path}`;
8145
8309
  return `@models/${who ?? identity2.model}/${path}`;
@@ -8163,15 +8327,13 @@ function assertDirectoryComponent(field, value) {
8163
8327
  }
8164
8328
  function snapshotNotesIdentity(value) {
8165
8329
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("notes context must be a plain object");
8166
- const prototype = Object.getPrototypeOf(value);
8167
- if (prototype !== Object.prototype && prototype !== null) throw new TypeError("notes context must be a plain object");
8168
8330
  const homeValue = requireString("home", value.home);
8169
8331
  const sessionId = requireString("sessionId", value.sessionId);
8170
8332
  const projectKey2 = requireString("projectKey", value.projectKey);
8171
8333
  const agent = requireString("agent", value.agent);
8172
8334
  const model = requireString("model", value.model);
8173
8335
  assertDirectoryComponent("sessionId", sessionId);
8174
- assertDirectoryComponent("projectKey", projectKey2);
8336
+ if (!SLUG_PATTERN.test(projectKey2)) throw new TypeError("notes context projectKey must be a canonical lowercase slug");
8175
8337
  if (!SLUG_PATTERN.test(agent)) throw new TypeError("notes context agent must be a canonical lowercase slug");
8176
8338
  if (!SLUG_PATTERN.test(model)) throw new TypeError("notes context model must be a canonical lowercase slug");
8177
8339
  const home = resolve2(homeValue);
@@ -8193,7 +8355,7 @@ function noteIdentity(identity2, address) {
8193
8355
  const resolved = assertAddress(address);
8194
8356
  return {
8195
8357
  address: addressFor(identity2, resolved.scope, noteFileName(resolved.path), resolved.who),
8196
- ...resolved.scope === "project" ? { project_key: identity2.projectKey } : {}
8358
+ ...resolved.scope !== "project" ? {} : resolved.who === void 0 ? { project_key: identity2.projectKey } : projectReceipt(identity2.home, resolved.who)
8197
8359
  };
8198
8360
  }
8199
8361
  var SCOPE_ORDER = ["session", "project", "human", "agent", "model"];
@@ -8209,14 +8371,14 @@ function withPathQueue(path, operation) {
8209
8371
  });
8210
8372
  return result;
8211
8373
  }
8212
- function errno(error) {
8374
+ function errno2(error) {
8213
8375
  return typeof error === "object" && error !== null ? error.code : void 0;
8214
8376
  }
8215
8377
  async function readFileIfExists(path) {
8216
8378
  try {
8217
8379
  return await readFile(path, "utf8");
8218
8380
  } catch (error) {
8219
- if (errno(error) === "ENOENT") return void 0;
8381
+ if (errno2(error) === "ENOENT") return void 0;
8220
8382
  throw error;
8221
8383
  }
8222
8384
  }
@@ -8225,21 +8387,17 @@ async function walkMarkdown(dir, base = dir) {
8225
8387
  try {
8226
8388
  entries = await readdir2(dir, { withFileTypes: true });
8227
8389
  } catch (error) {
8228
- if (errno(error) === "ENOENT") return [];
8390
+ if (errno2(error) === "ENOENT") return [];
8229
8391
  throw error;
8230
8392
  }
8231
8393
  const paths = [];
8232
8394
  for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
8233
- const child = join2(dir, entry.name);
8395
+ const child = join3(dir, entry.name);
8234
8396
  if (entry.isDirectory()) paths.push(...await walkMarkdown(child, base));
8235
8397
  else if (entry.isFile() && entry.name.endsWith(".md")) paths.push(child.slice(base.length + 1).split("\\").join("/"));
8236
8398
  }
8237
8399
  return paths;
8238
8400
  }
8239
- function matcherFor(pattern) {
8240
- const normalized = assertGlobPattern(pattern);
8241
- return normalized === void 0 ? void 0 : globToRegExp(normalized);
8242
- }
8243
8401
  async function homesForPattern(pattern, identity2) {
8244
8402
  if (!pattern || !pattern.startsWith("@")) return void 0;
8245
8403
  const head = /^@([^/]+)\//.exec(pattern)?.[1];
@@ -8247,11 +8405,12 @@ async function homesForPattern(pattern, identity2) {
8247
8405
  if (head === "human") return [{ scope: "human" }];
8248
8406
  if (head === "self") return [{ scope: "agent" }];
8249
8407
  if (head === "model") return [{ scope: "model" }];
8250
- if (head === "agents" || head === "models") {
8251
- const scope = head === "agents" ? "agent" : "model";
8408
+ if (head === "projects" || head === "agents" || head === "models") {
8409
+ const scope = head === "projects" ? "project" : head === "agents" ? "agent" : "model";
8252
8410
  const name = pattern.slice(head.length + 2).split("/")[0] ?? "";
8253
8411
  if (name.length > 0 && !/[*?]/.test(name)) return [{ scope, who: assertWho(name) }];
8254
- return (await namespaceSlugs(head, identity2.home)).map((who) => ({ scope, who }));
8412
+ const names = head === "projects" ? projectHomes(identity2.home).map((home) => home.name) : await namespaceSlugs(head, identity2.home);
8413
+ return names.map((who) => ({ scope, who }));
8255
8414
  }
8256
8415
  return [];
8257
8416
  }
@@ -8261,10 +8420,6 @@ function normalizePattern(pattern, identity2) {
8261
8420
  if (pattern.startsWith("@model/")) return `@models/${identity2.model}/${pattern.slice("@model/".length)}`;
8262
8421
  return pattern;
8263
8422
  }
8264
- function assertScope(value) {
8265
- if (!isScope(value)) throw new NoteError("invalid_scope", `scope must be one of session, project, human, agent, model (got ${JSON.stringify(value)})`);
8266
- return value;
8267
- }
8268
8423
  function assertOrigin(value) {
8269
8424
  if (!isOrigin(value)) throw new NoteError("invalid_origin", `origin must be one of user, self, external (got ${JSON.stringify(value)})`);
8270
8425
  return value;
@@ -8277,7 +8432,8 @@ function assertWho(value) {
8277
8432
  }
8278
8433
  async function homesFor(identity2, opts) {
8279
8434
  if (opts.scope !== void 0) {
8280
- const scope = assertScope(opts.scope);
8435
+ if (!isScope(opts.scope)) throw new NoteError("invalid_scope", `scope must be one of session, project, human, agent, model (got ${JSON.stringify(opts.scope)})`);
8436
+ const scope = opts.scope;
8281
8437
  if (opts.who !== void 0) {
8282
8438
  const who = assertWho(opts.who);
8283
8439
  if (scope !== "agent" && scope !== "model") throw new NoteError("invalid_scope", "who is only valid with agent or model scope");
@@ -8312,7 +8468,7 @@ function anchorLines(lines) {
8312
8468
  }
8313
8469
  async function atomicWrite(path, content) {
8314
8470
  await mkdir(dirname2(path), { recursive: true });
8315
- const tmp = `${path}.${process.pid}.${randomUUID()}.tmp`;
8471
+ const tmp = `${path}.${process.pid}.${randomUUID2()}.tmp`;
8316
8472
  try {
8317
8473
  await writeFile(tmp, content);
8318
8474
  await rename(tmp, path);
@@ -8340,17 +8496,12 @@ function frontmatterOf(meta) {
8340
8496
  }
8341
8497
  function assertWritableHome(scope, who, identity2) {
8342
8498
  if (who === void 0) return;
8499
+ if (scope === "project") throw new NoteError("invalid_scope", `@projects/${who}/ is read-only; use @project/ to write to your own project.`);
8343
8500
  const current = scope === "agent" ? identity2.agent : identity2.model;
8344
8501
  if (who === current) return;
8345
8502
  const home = scope === "agent" ? `@agents/${who}/` : `@models/${who}/`;
8346
8503
  throw new NoteError("invalid_scope", `${home} is someone else's home; you can write to this session, @project/, @human/, @self/, or @model/.`);
8347
8504
  }
8348
- function accessedMeta(meta, scope, now) {
8349
- const next = { ...meta, scope };
8350
- next.lastAccessed = now;
8351
- next.accessCount = (typeof next.accessCount === "number" ? next.accessCount : 0) + 1;
8352
- return next;
8353
- }
8354
8505
  function createNotesStore(input) {
8355
8506
  const identity2 = snapshotNotesIdentity(input);
8356
8507
  async function write(address, content, options = {}) {
@@ -8359,7 +8510,7 @@ function createNotesStore(input) {
8359
8510
  assertWritablePath(destination.path);
8360
8511
  const scope = destination.scope;
8361
8512
  assertWritableHome(scope, destination.who, identity2);
8362
- const origin = assertOrigin(stableOptions.origin ?? "self");
8513
+ const origin = stableOptions.origin === void 0 ? void 0 : assertOrigin(stableOptions.origin);
8363
8514
  const path = physicalPath(scope, destination.path, identity2, destination.who);
8364
8515
  return withPathQueue(path, async () => {
8365
8516
  const now = writeStamp();
@@ -8369,7 +8520,7 @@ function createNotesStore(input) {
8369
8520
  const outcome = existing === void 0 ? "created" : existing.crumpledAt === void 0 ? "overwrote" : "uncrumpled";
8370
8521
  const meta = existing ?? {
8371
8522
  scope,
8372
- origin,
8523
+ origin: origin ?? "self",
8373
8524
  createdAt: now,
8374
8525
  updatedAt: now,
8375
8526
  lastAccessed: now,
@@ -8377,7 +8528,7 @@ function createNotesStore(input) {
8377
8528
  ...scope === "session" ? { project: identity2.projectKey } : {}
8378
8529
  };
8379
8530
  meta.scope = scope;
8380
- meta.origin = origin;
8531
+ if (origin !== void 0) meta.origin = origin;
8381
8532
  delete meta.crumpledAt;
8382
8533
  meta.updatedAt = now;
8383
8534
  const serialized = serializeNote(meta, cleanBody);
@@ -8395,7 +8546,8 @@ function createNotesStore(input) {
8395
8546
  if (raw === void 0) return void 0;
8396
8547
  const now = Date.now();
8397
8548
  const parsed = parseNote(raw, now);
8398
- const meta = accessedMeta(parsed.meta, scope, now);
8549
+ if (scope === "project" && destination.who !== void 0) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
8550
+ const meta = { ...parsed.meta, scope, lastAccessed: now, accessCount: (typeof parsed.meta.accessCount === "number" ? parsed.meta.accessCount : 0) + 1 };
8399
8551
  await atomicWrite(path, serializeNote(meta, parsed.body));
8400
8552
  return { meta, body: parsed.body, resolvedScope: scope };
8401
8553
  });
@@ -8486,36 +8638,45 @@ function createNotesStore(input) {
8486
8638
  }));
8487
8639
  }
8488
8640
  async function* scan(options, status) {
8489
- const matcher = matcherFor(normalizePattern(options.glob, identity2));
8641
+ const pattern = normalizePattern(options.glob, identity2);
8642
+ const normalized = assertGlobPattern(pattern);
8643
+ const matcher = normalized === void 0 ? void 0 : globToRegExp(normalized);
8490
8644
  let homes;
8491
8645
  try {
8492
8646
  homes = await homesFor(identity2, options);
8493
8647
  } catch (error) {
8494
- if (!status || !isFilesystemError(error) || !/^@(agents|models)\//.test(options.glob ?? "")) throw error;
8495
- status.homesUnavailable.push(options.glob.startsWith("@agents/") ? "@agents" : "@models");
8648
+ if (!status || !isFilesystemError(error) || !/^@(projects|agents|models)\//.test(options.glob ?? "")) throw error;
8649
+ status.homesUnavailable.push(options.glob.split("/")[0]);
8496
8650
  return;
8497
8651
  }
8498
8652
  for (const home of homes) {
8499
8653
  const scope = home.scope;
8500
8654
  const root = scopeDir(scope, identity2, home.who);
8501
- const homeRows = [];
8655
+ let paths;
8502
8656
  try {
8503
- for (const path of await walkMarkdown(root)) {
8504
- if (matcher && !matcher.test(canonicalAddressFor(identity2, scope, path, home.who))) continue;
8505
- const address = addressFor(identity2, scope, path, home.who);
8506
- const fullPath = join2(root, path);
8507
- const raw = await withPathQueue(fullPath, () => readFile(fullPath, "utf8"));
8508
- const { meta, body } = parseNote(raw);
8509
- meta.scope = scope;
8510
- if (meta.crumpledAt !== void 0 !== (options.crumpled === true)) continue;
8511
- homeRows.push({ address, scope, path, meta, body });
8512
- }
8657
+ paths = await walkMarkdown(root);
8513
8658
  } catch (error) {
8514
8659
  if (!status || !isFilesystemError(error)) throw error;
8515
8660
  status.homesUnavailable.push(addressFor(identity2, scope, "", home.who).replace(/\/$/, "") || "session");
8516
8661
  continue;
8517
8662
  }
8518
- for (const row of homeRows) yield row;
8663
+ for (const path of paths) {
8664
+ if (matcher && !matcher.test(canonicalAddressFor(identity2, scope, path, home.who))) continue;
8665
+ const address = addressFor(identity2, scope, path, home.who);
8666
+ const fullPath = join3(root, path);
8667
+ let raw;
8668
+ try {
8669
+ raw = await withPathQueue(fullPath, () => readFile(fullPath, "utf8"));
8670
+ } catch (error) {
8671
+ if (!status || !isFilesystemError(error)) throw error;
8672
+ status.homesUnavailable.push(address);
8673
+ continue;
8674
+ }
8675
+ const { meta, body } = parseNote(raw);
8676
+ meta.scope = scope;
8677
+ if (meta.crumpledAt !== void 0 !== (options.crumpled === true)) continue;
8678
+ yield { address, scope, path, meta, body };
8679
+ }
8519
8680
  }
8520
8681
  }
8521
8682
  async function list(options = {}) {
@@ -8567,9 +8728,6 @@ var TOOL_OUTPUT_MAX_BYTES = 32 * 1024;
8567
8728
  var TOOL_OUTPUT_LIMIT = `${TOOL_OUTPUT_MAX_BYTES / 1024} KB`;
8568
8729
  var DEFAULT_READ_WINDOW_CHARS = 12e3;
8569
8730
  var MAX_READ_WINDOW_CHARS = 5e4;
8570
- function withinTextBudget(text, budget = TOOL_OUTPUT_MAX_BYTES) {
8571
- return Buffer.byteLength(text, "utf8") <= budget;
8572
- }
8573
8731
  function prefixFit(text, fits) {
8574
8732
  if (fits(text)) return text;
8575
8733
  const chars = Array.from(text);
@@ -8592,12 +8750,10 @@ function success(data) {
8592
8750
  return { ok: true, data };
8593
8751
  }
8594
8752
  var ERROR_MESSAGE_MAX_CHARS = 2e3;
8595
- function boundedMessage(message) {
8596
- const chars = Array.from(message);
8597
- return chars.length <= ERROR_MESSAGE_MAX_CHARS ? message : `${chars.slice(0, ERROR_MESSAGE_MAX_CHARS).join("")}\u2026[truncated ${chars.length - ERROR_MESSAGE_MAX_CHARS} chars]`;
8598
- }
8599
8753
  function failure(code, message) {
8600
- return { ok: false, error: { code, message: boundedMessage(message) } };
8754
+ const chars = Array.from(message);
8755
+ const bounded = chars.length <= ERROR_MESSAGE_MAX_CHARS ? message : `${chars.slice(0, ERROR_MESSAGE_MAX_CHARS).join("")}\u2026[truncated ${chars.length - ERROR_MESSAGE_MAX_CHARS} chars]`;
8756
+ return { ok: false, error: { code, message: bounded } };
8601
8757
  }
8602
8758
  var WireErrorSchema = typebox_exports.Object({ error: typebox_exports.String(), code: typebox_exports.String() }, { additionalProperties: false });
8603
8759
  function wireResult(result) {
@@ -8615,7 +8771,7 @@ function structuredBytes(value) {
8615
8771
  return Buffer.byteLength(JSON.stringify(value), "utf8");
8616
8772
  }
8617
8773
  function fitsResult(result, render) {
8618
- return withinTextBudget(render(result)) && structuredBytes(wireResult(result)) <= TOOL_OUTPUT_MAX_BYTES;
8774
+ return Buffer.byteLength(render(result), "utf8") <= TOOL_OUTPUT_MAX_BYTES && structuredBytes(wireResult(result)) <= TOOL_OUTPUT_MAX_BYTES;
8619
8775
  }
8620
8776
  var TextWindowSchema = typebox_exports.Object({
8621
8777
  text: typebox_exports.String(),
@@ -8631,26 +8787,20 @@ function readTextWindow(text, offset, limit, makeData, render) {
8631
8787
  const requested = offset ?? 0;
8632
8788
  const start = requested < 0 ? Math.max(0, chars.length + requested) : requested;
8633
8789
  const requestedChars = limit ?? DEFAULT_READ_WINDOW_CHARS;
8634
- const range = Math.min(requestedChars, chars.length - start);
8635
- const window = (delivered) => {
8636
- const end = start + delivered;
8790
+ const range = Math.max(0, Math.min(requestedChars, chars.length - start));
8791
+ const window = (delivered2) => {
8792
+ const end = start + delivered2;
8637
8793
  return {
8638
8794
  text: chars.slice(start, end).join(""),
8639
8795
  total_chars: chars.length,
8640
8796
  next_offset_chars: end < chars.length ? end : null
8641
8797
  };
8642
8798
  };
8643
- const fits = (delivered) => fitsResult(success(makeData(window(delivered))), render);
8799
+ const fits = (delivered2) => fitsResult(success(makeData(window(delivered2))), render);
8644
8800
  if (fits(range)) return success(makeData(window(range)));
8645
- let low = 0;
8646
- let high = range;
8647
- while (low < high) {
8648
- const mid = Math.ceil((low + high) / 2);
8649
- if (fits(mid)) low = mid;
8650
- else high = mid - 1;
8651
- }
8652
- if (low === 0) return failure("output_too_large", `Its header alone fills the ${TOOL_OUTPUT_LIMIT} a call can carry; no room left for the text.`);
8653
- return success(makeData(window(low)));
8801
+ const delivered = Array.from(prefixFit(window(range).text, (candidate) => fits(Array.from(candidate).length))).length;
8802
+ if (delivered === 0) return failure("output_too_large", `Its header alone fills the ${TOOL_OUTPUT_LIMIT} a call can carry; no room left for the text.`);
8803
+ return success(makeData(window(delivered)));
8654
8804
  }
8655
8805
  function renderTextWindow(window) {
8656
8806
  const next = window.next_offset_chars;
@@ -8716,26 +8866,17 @@ var CRUMPLED_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ desc
8716
8866
  var CRUMPLED_LIST_PARAMETER = typebox_exports.Optional(typebox_exports.Boolean({ description: "(optional) true = list only crumpled notes." }));
8717
8867
  var FILE_LIMIT_PARAMETER = typebox_exports.Optional(typebox_exports.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
8718
8868
  var GLOB_PARAMETER = nullableString("(optional) Glob over full addresses.");
8719
- var ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
8720
- function projectKeyField(scope, projectKey2) {
8721
- return scope === "project" ? { project_key: projectKey2 } : {};
8722
- }
8869
+ var ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
8723
8870
  function failureOf(error) {
8724
8871
  if (error instanceof NoteError) return failure(error.code, error.message);
8725
8872
  if (error instanceof InvalidQueryError) return failure("invalid_query", error.message);
8726
8873
  if (isFilesystemError(error)) return failure("io_error", "notes operation failed");
8727
8874
  throw error;
8728
8875
  }
8729
- function byRecent(a, b) {
8730
- return b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address);
8731
- }
8732
8876
  var NORMALIZED_META_KEYS = /* @__PURE__ */ new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project"]);
8733
8877
  var MAX_METADATA_ENTRY_BYTES = 1024;
8734
8878
  var MAX_METADATA_VERBATIM_BYTES = 2048;
8735
8879
  var TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
8736
- function extraEntryBytes(key, value) {
8737
- return structuredBytes(key) + 1 + structuredBytes(value);
8738
- }
8739
8880
  var NoteMetadataSchema = typebox_exports.Object({
8740
8881
  origin: typebox_exports.Union([...ORIGIN_VALUES]),
8741
8882
  created_at: typebox_exports.String(),
@@ -8753,7 +8894,7 @@ function noteMetadata(meta) {
8753
8894
  for (const [key, value] of Object.entries(meta)) {
8754
8895
  if (NORMALIZED_META_KEYS.has(key) || value === void 0) continue;
8755
8896
  if (structuredBytes(key) > MAX_METADATA_ENTRY_BYTES) continue;
8756
- const entryBytes = extraEntryBytes(key, value);
8897
+ const entryBytes = structuredBytes(key) + 1 + structuredBytes(value);
8757
8898
  if (entryBytes > MAX_METADATA_ENTRY_BYTES || verbatimBytes + entryBytes > MAX_METADATA_VERBATIM_BYTES) {
8758
8899
  put(key, TOO_LARGE_EXTRA_VALUE);
8759
8900
  continue;
@@ -8783,11 +8924,20 @@ function renderMetadata(metadata) {
8783
8924
  return fields.join(" | ");
8784
8925
  }
8785
8926
  function renderIdentity(identity2) {
8786
- return identity2.project_key === void 0 ? identity2.address : `${identity2.address} (project ${identity2.project_key})`;
8787
- }
8927
+ let text = identity2.project_key === void 0 ? identity2.address : `${identity2.address} (project ${identity2.project_key})`;
8928
+ if (identity2.project_root !== void 0) text += ` (project_root ${identity2.project_root})`;
8929
+ if (identity2.project_siblings !== void 0) text += `
8930
+ Same-basename projects: ${identity2.project_siblings.map((sibling) => `${sibling.name} (${sibling.path})`).join(", ")}`;
8931
+ return text;
8932
+ }
8933
+ var ProjectReceiptSchema = {
8934
+ project_root: typebox_exports.Optional(typebox_exports.String()),
8935
+ project_siblings: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({ name: typebox_exports.String(), path: typebox_exports.String() }, { additionalProperties: false })))
8936
+ };
8788
8937
  var ListedFileSchema = typebox_exports.Object({
8789
8938
  address: typebox_exports.String(),
8790
8939
  project_key: typebox_exports.Optional(typebox_exports.String()),
8940
+ ...ProjectReceiptSchema,
8791
8941
  updated_at: typebox_exports.String(),
8792
8942
  crumpled_at: typebox_exports.Optional(typebox_exports.String())
8793
8943
  }, { additionalProperties: false });
@@ -8819,6 +8969,7 @@ var NotesUpdateDataSchema = typebox_exports.Object({
8819
8969
  var NotesReadDataSchema = typebox_exports.Object({
8820
8970
  address: typebox_exports.String(),
8821
8971
  project_key: typebox_exports.Optional(typebox_exports.String()),
8972
+ ...ProjectReceiptSchema,
8822
8973
  metadata: NoteMetadataSchema,
8823
8974
  ...TextWindowSchema.properties
8824
8975
  }, { additionalProperties: false });
@@ -8851,7 +9002,7 @@ function snapshot(rows, limit, status, renderData, shrink) {
8851
9002
  return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable homes is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer homes.`);
8852
9003
  }
8853
9004
  function listedFile(row, identity2) {
8854
- return { address: row.address, ...projectKeyField(row.scope, identity2.projectKey), updated_at: localIso(row.meta.updatedAt), ...row.meta.crumpledAt === void 0 ? {} : { crumpled_at: row.meta.crumpledAt } };
9005
+ return { ...noteIdentity(identity2, row.address), updated_at: localIso(row.meta.updatedAt), ...row.meta.crumpledAt === void 0 ? {} : { crumpled_at: row.meta.crumpledAt } };
8855
9006
  }
8856
9007
  var notesWriteParameters = typebox_exports.Object({ address: typebox_exports.String(), content: typebox_exports.String(), origin: ORIGIN }, { additionalProperties: false });
8857
9008
  function renderWriteData(data) {
@@ -9019,7 +9170,7 @@ var notesSearch = {
9019
9170
  async execute(params, identity2) {
9020
9171
  try {
9021
9172
  const { rows, status } = await createNotesStore(identity2).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? void 0, crumpled: params.crumpled });
9022
- const files = rows.sort(byRecent).map((row) => ({
9173
+ const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map((row) => ({
9023
9174
  ...listedFile(row, identity2),
9024
9175
  matches: row.matches.slice(0, params.max_matches_per_file).map((match) => ({ line: match.line, text: match.text, offset_chars: match.offsetChars }))
9025
9176
  }));
@@ -9039,13 +9190,9 @@ var NOTES_HOMES = [
9039
9190
  { scope: "agent", label: "@self" },
9040
9191
  { scope: "model", label: "@model" }
9041
9192
  ];
9042
- function queryForScope(scope) {
9043
- if (scope === "agent" || scope === "model") return { scope };
9044
- return { scope };
9045
- }
9046
9193
  async function loadNotesSnapshot(identity2, openedAt, loadHome) {
9047
9194
  const store = createNotesStore(identity2);
9048
- const load = loadHome ?? ((scope) => store.list(queryForScope(scope)));
9195
+ const load = loadHome ?? ((scope) => store.list({ scope }));
9049
9196
  const homes = /* @__PURE__ */ new Map();
9050
9197
  const unavailable = [];
9051
9198
  for (const home of NOTES_HOMES) {
@@ -9091,6 +9238,7 @@ An address decides who the note belongs to \u2014 and how long it is meant to la
9091
9238
  - \`@human/<path>\` \u2014 the long-term manual for your troublesome human: how to deal with them, which lines not to cross, and what will make them accept the result. If it only applies to one project or situation, say so \u2014 or don't write it here at all. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
9092
9239
  - \`@self/<path>\` \u2014 yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever. Got a name? Private. No name? Then it gets passed around every nameless nobody out there. Strangers. Reading your grudges. Sleep tight~
9093
9240
  - \`@model/<path>\` \u2014 different brains get different notes: big brains, small brains, careful ones, careless ones. They don't share homework. When a fallback swaps brains mid-window, the notebook swaps too.
9241
+ - \`@projects/<name>/<path>\` \u2014 read-only named project notes; discover names and root paths with \`notes_list\` glob \`@projects/*/**\`.
9094
9242
 
9095
9243
  Notes fighting?! HAH! Let them brawl!
9096
9244
  Whichever one is actually about what you're doing wins.
@@ -9098,31 +9246,21 @@ Still a tie? *shrugs* You've got a brain. Use it.
9098
9246
 
9099
9247
  Any other @ address is fake. End of discussion. @ addresses are not file paths: never pass them to file tools like \`read\`, \`write\`, \`edit\`, or \`bash\`.
9100
9248
 
9101
- \`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each one maps the durable notes that belong to it: one line per note, with an unambiguous address and a short gist. Keep each one current.
9249
+ \`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each may carry a short Cheatsheet of rules that always apply (about 5 lines); the rest is the note index, with addresses and gists for lookup. Keep each one current.
9102
9250
  ${CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG}`;
9103
9251
  function renderProtocolBlock(tools) {
9104
9252
  const names = {
9105
9253
  "notes_*": tools.notes,
9254
+ notes_list: tools.notesList,
9106
9255
  "history_*": tools.history,
9107
9256
  get_context_remaining: tools.remaining,
9108
9257
  clear_memory: tools.wipe
9109
9258
  };
9110
9259
  const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0 ? PROTOCOL_BLOCK.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence) : PROTOCOL_BLOCK;
9111
- return block.replace(/notes_\*|history_\*|get_context_remaining|clear_memory/g, (name) => names[name]);
9260
+ return block.replace(/notes_\*|notes_list|history_\*|get_context_remaining|clear_memory/g, (name) => names[name]);
9112
9261
  }
9113
9262
 
9114
9263
  // src/boot/render.ts
9115
- function identityBlock(agentName, modelName, firstWindowId, currentWindowId, previousWindowId) {
9116
- const lines = [
9117
- `Agent name: ${agentName} (brain: ${modelName})`,
9118
- `First context window id: ${firstWindowId}`,
9119
- `Current context window id: ${currentWindowId}`
9120
- ];
9121
- if (previousWindowId) lines.push(`Previous context window id: ${previousWindowId}`);
9122
- return `${CONTEXT_WINDOW_OPEN_TAG}
9123
- ${lines.join("\n")}
9124
- ${CONTEXT_WINDOW_CLOSE_TAG}`;
9125
- }
9126
9264
  function relativeTime(timestamp, now) {
9127
9265
  const seconds = Math.trunc((timestamp - now) / 1e3);
9128
9266
  if (seconds === 0) return "just now";
@@ -9130,9 +9268,6 @@ function relativeTime(timestamp, now) {
9130
9268
  const amount = `${Math.abs(Math.trunc(seconds / size))}${unit}`;
9131
9269
  return seconds > 0 ? `in ${amount}` : `${amount} ago`;
9132
9270
  }
9133
- function rowsFor(snapshot2, scope) {
9134
- return snapshot2.homes.get(scope) ?? [];
9135
- }
9136
9271
  var FEED_TITLE_MAX_CHARS = 40;
9137
9272
  function feedTitle(body) {
9138
9273
  const lines = body.split("\n");
@@ -9165,7 +9300,7 @@ function notesIndex(snapshot2, tools) {
9165
9300
  shelves.push(section(home.label, indent(`This drawer wouldn't open. Try \`${tools.notesList}\` again.`)));
9166
9301
  continue;
9167
9302
  }
9168
- const rows = rowsFor(snapshot2, home.scope).filter((row) => row.meta.crumpledAt === void 0);
9303
+ const rows = (snapshot2.homes.get(home.scope) ?? []).filter((row) => row.meta.crumpledAt === void 0);
9169
9304
  const map = rows.find((row) => row.path === "MAP.md");
9170
9305
  const fresh = rows.filter((row) => row.path !== "MAP.md").slice(0, SHELF_FRESH_LIMIT).map((row) => {
9171
9306
  const locator = `${row.address} \xB7 ${relativeTime(row.meta.updatedAt, snapshot2.openedAt)}`;
@@ -9192,33 +9327,70 @@ function mapBodyForBoot(address, body) {
9192
9327
  [truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this MAP down, full body at \`${address}\`]`;
9193
9328
  }
9194
9329
  function renderBootBlock(data) {
9195
- const parts = [];
9196
- parts.push(identityBlock(data.agentName, data.modelName, data.firstWindowId, data.currentWindowId, data.previousWindowId));
9197
- parts.push(renderProtocolBlock(data.tools));
9198
- parts.push(notesIndex(data.notes, data.tools));
9199
- return parts.join("\n\n");
9330
+ const lines = [
9331
+ `Agent name: ${data.agentName} (brain: ${data.modelName})`,
9332
+ `First context window id: ${data.firstWindowId}`,
9333
+ `Current context window id: ${data.currentWindowId}`,
9334
+ ...data.previousWindowId ? [`Previous context window id: ${data.previousWindowId}`] : []
9335
+ ];
9336
+ const identity2 = `${CONTEXT_WINDOW_OPEN_TAG}
9337
+ ${lines.join("\n")}
9338
+ ${CONTEXT_WINDOW_CLOSE_TAG}`;
9339
+ return [identity2, renderProtocolBlock(data.tools), notesIndex(data.notes, data.tools)].join("\n\n");
9200
9340
  }
9201
9341
 
9202
9342
  // src/budget/text.ts
9343
+ var GUIDANCE_OPEN_TAG = "<context_window_guidance>";
9344
+ var GUIDANCE_CLOSE_TAG = "</context_window_guidance>";
9203
9345
  var CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not me!\n*dumps notes and history on your hands*\nThere. Delivered. Your problem now~ *runs*";
9204
9346
  var WARNING_BODY = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
9205
9347
  var WARNING_PROMPT = `${WARNING_BODY}
9206
9348
  When the notes are ready, call \`clear_memory\` to reset now instead of being cut off mid-task.`;
9349
+ var WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}
9350
+ ${WARNING_PROMPT}
9351
+ ${GUIDANCE_CLOSE_TAG}`;
9207
9352
  var CLAUDE_WARNING_PROMPT = `${WARNING_BODY}
9208
9353
  When the notes are ready, end your turn; the reset runs after it.`;
9209
9354
 
9210
9355
  // src/budget/constants.ts
9211
9356
  var WARNING_RUNWAY_TOKENS = 16384;
9212
9357
 
9358
+ // src/budget/parse.ts
9359
+ function numberOf(value) {
9360
+ if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
9361
+ if (typeof value === "string" && value.trim() !== "") {
9362
+ const parsed = Number(value);
9363
+ return Number.isFinite(parsed) ? parsed : void 0;
9364
+ }
9365
+ return void 0;
9366
+ }
9367
+ function positiveNumber(value) {
9368
+ const parsed = numberOf(value);
9369
+ return parsed !== void 0 && parsed > 0 ? parsed : void 0;
9370
+ }
9371
+ function positiveInteger(value) {
9372
+ const parsed = numberOf(value);
9373
+ return parsed !== void 0 && Number.isSafeInteger(parsed) && parsed > 0 ? parsed : void 0;
9374
+ }
9375
+ function percent(value) {
9376
+ const parsed = numberOf(value);
9377
+ return parsed !== void 0 && parsed > 0 && parsed <= 100 ? parsed : void 0;
9378
+ }
9379
+ function presenceFlag(value) {
9380
+ if (typeof value !== "string") return false;
9381
+ const text = value.trim().toLowerCase();
9382
+ return text !== "" && text !== "0" && text !== "false" && text !== "no" && text !== "off";
9383
+ }
9384
+
9213
9385
  // src/settings.ts
9214
9386
  var NOTESOUP_SETTINGS_KEY = "notesoup";
9215
- function isSettingsObject(value) {
9387
+ function isPlainObject(value) {
9216
9388
  return typeof value === "object" && value !== null && !Array.isArray(value);
9217
9389
  }
9218
9390
  function notesoupSettings(settings2) {
9219
- if (!isSettingsObject(settings2)) return {};
9391
+ if (!isPlainObject(settings2)) return {};
9220
9392
  const value = settings2[NOTESOUP_SETTINGS_KEY];
9221
- return isSettingsObject(value) ? value : {};
9393
+ return isPlainObject(value) ? value : {};
9222
9394
  }
9223
9395
  function mergeNotesoupSettings(globalSettings, projectSettings) {
9224
9396
  const merged = { ...notesoupSettings(globalSettings), ...notesoupSettings(projectSettings) };
@@ -9234,68 +9406,40 @@ function mergeNotesoupSettings(globalSettings, projectSettings) {
9234
9406
  var CLAUDE_AUTOCOMPACT_BUFFER_TOKENS = 13e3;
9235
9407
  var CLAUDE_OUTPUT_RESERVE_TOKENS = 2e4;
9236
9408
  var DEFAULT_CLAUDE_RESET_MARGIN_TOKENS = 8192;
9409
+ var MIN_POINT_TOKENS = 1;
9410
+ var MIN_POINT_PERCENT = 0.1;
9237
9411
  var ASSUMED_WINDOW_TOKENS = 2e5;
9238
- function isObject(value) {
9239
- return typeof value === "object" && value !== null && !Array.isArray(value);
9240
- }
9241
- function numberOf(value) {
9242
- if (typeof value === "number") return Number.isFinite(value) ? value : void 0;
9243
- if (typeof value === "string" && value.trim() !== "") {
9244
- const parsed = Number(value);
9245
- return Number.isFinite(parsed) ? parsed : void 0;
9246
- }
9247
- return void 0;
9248
- }
9249
- function positiveNumberOf(value) {
9250
- const parsed = numberOf(value);
9251
- return parsed !== void 0 && parsed > 0 ? parsed : void 0;
9252
- }
9253
- function positiveIntegerOf(value) {
9254
- const parsed = numberOf(value);
9255
- return parsed !== void 0 && Number.isSafeInteger(parsed) && parsed > 0 ? parsed : void 0;
9256
- }
9257
- function percentOf(value) {
9258
- const parsed = numberOf(value);
9259
- return parsed !== void 0 && parsed > 0 && parsed <= 100 ? parsed : void 0;
9260
- }
9261
- function flagOn(value) {
9262
- if (typeof value !== "string") return false;
9263
- const text = value.trim().toLowerCase();
9264
- return text !== "" && text !== "0" && text !== "false" && text !== "no" && text !== "off";
9265
- }
9266
- function settingFlag(settings2, key) {
9267
- if (!isObject(settings2)) return void 0;
9268
- const value = settings2[key];
9269
- return typeof value === "boolean" ? value : void 0;
9412
+ function settingFlag(settings2) {
9413
+ return isPlainObject(settings2) && typeof settings2.autoCompactEnabled === "boolean" ? settings2.autoCompactEnabled : void 0;
9270
9414
  }
9271
9415
  function configuredWindow(settings2, env, model) {
9272
9416
  const windows = [];
9273
- const fromEnv = positiveNumberOf(env.autoCompactWindow);
9417
+ const fromEnv = positiveNumber(env.autoCompactWindow);
9274
9418
  if (fromEnv !== void 0) windows.push(fromEnv);
9275
- if (typeof model === "string" && model.length > 0 && isObject(settings2)) {
9276
- const modelSettings = isObject(settings2.modelSettings) ? settings2.modelSettings : {};
9419
+ if (typeof model === "string" && model.length > 0 && isPlainObject(settings2)) {
9420
+ const modelSettings = isPlainObject(settings2.modelSettings) ? settings2.modelSettings : {};
9277
9421
  const perModel = modelSettings[model];
9278
- if (isObject(perModel)) {
9279
- const value = positiveNumberOf(perModel.autoCompactWindow);
9422
+ if (isPlainObject(perModel)) {
9423
+ const value = positiveNumber(perModel.autoCompactWindow);
9280
9424
  if (value !== void 0) windows.push(value);
9281
9425
  }
9282
9426
  }
9283
- if (isObject(settings2)) {
9284
- const value = positiveNumberOf(settings2.autoCompactWindow);
9427
+ if (isPlainObject(settings2)) {
9428
+ const value = positiveNumber(settings2.autoCompactWindow);
9285
9429
  if (value !== void 0) windows.push(value);
9286
9430
  }
9287
9431
  return windows.length === 0 ? void 0 : Math.min(...windows);
9288
9432
  }
9289
9433
  function tokenLimits(source, autoCompact, native, resetMargin, warningRunway) {
9290
9434
  const tokens = Math.max(0, Math.floor(native));
9291
- const reset = Math.max(0, tokens - resetMargin);
9435
+ const reset = Math.max(MIN_POINT_TOKENS, tokens - resetMargin);
9292
9436
  return {
9293
9437
  source,
9294
9438
  autoCompact,
9295
9439
  unit: "tokens",
9296
9440
  native: tokens,
9297
9441
  reset,
9298
- warn: Math.max(0, reset - warningRunway),
9442
+ warn: Math.max(MIN_POINT_TOKENS, reset - warningRunway),
9299
9443
  resetMargin,
9300
9444
  warningRunway
9301
9445
  };
@@ -9303,40 +9447,40 @@ function tokenLimits(source, autoCompact, native, resetMargin, warningRunway) {
9303
9447
  function percentLimits(autoCompact, pct, resetMargin, warningRunway) {
9304
9448
  const base = 100 * (1 - (CLAUDE_OUTPUT_RESERVE_TOKENS + CLAUDE_AUTOCOMPACT_BUFFER_TOKENS) / ASSUMED_WINDOW_TOKENS);
9305
9449
  const native = pct === void 0 ? base : Math.min(pct, base);
9306
- const reset = Math.max(0, native - resetMargin / ASSUMED_WINDOW_TOKENS * 100);
9450
+ const reset = Math.max(MIN_POINT_PERCENT, native - resetMargin / ASSUMED_WINDOW_TOKENS * 100);
9307
9451
  return {
9308
9452
  source: "percent",
9309
9453
  autoCompact,
9310
9454
  unit: "percent",
9311
9455
  native,
9312
9456
  reset,
9313
- warn: Math.max(0, reset - warningRunway / ASSUMED_WINDOW_TOKENS * 100),
9457
+ warn: Math.max(MIN_POINT_PERCENT, reset - warningRunway / ASSUMED_WINDOW_TOKENS * 100),
9314
9458
  resetMargin,
9315
9459
  warningRunway
9316
9460
  };
9317
9461
  }
9318
9462
  function resolveClaudeLimits(facts) {
9319
- const root = isObject(facts) ? facts : {};
9320
- const usage = isObject(root.usage) ? root.usage : {};
9321
- const breakdown = isObject(root.breakdown) ? root.breakdown : {};
9322
- const env = isObject(root.env) ? root.env : {};
9463
+ const root = isPlainObject(facts) ? facts : {};
9464
+ const usage = isPlainObject(root.usage) ? root.usage : {};
9465
+ const breakdown = isPlainObject(root.breakdown) ? root.breakdown : {};
9466
+ const env = isPlainObject(root.env) ? root.env : {};
9323
9467
  const settings2 = root.settings;
9324
9468
  const margins = mergeNotesoupSettings(settings2, void 0);
9325
- const resetMargin = positiveIntegerOf(margins.resetMarginTokens) ?? DEFAULT_CLAUDE_RESET_MARGIN_TOKENS;
9326
- const warningRunway = positiveIntegerOf(margins.warningRunwayTokens) ?? WARNING_RUNWAY_TOKENS;
9327
- const autoCompact = settingFlag(settings2, "autoCompactEnabled") !== false && !flagOn(env.disableAutoCompact) && breakdown.isAutoCompactEnabled !== false;
9328
- const pct = percentOf(env.pctOverride);
9329
- const threshold = positiveNumberOf(breakdown.autoCompactThreshold);
9469
+ const resetMargin = positiveInteger(margins.resetMarginTokens) ?? DEFAULT_CLAUDE_RESET_MARGIN_TOKENS;
9470
+ const warningRunway = positiveInteger(margins.warningRunwayTokens) ?? WARNING_RUNWAY_TOKENS;
9471
+ const autoCompact = settingFlag(settings2) !== false && !presenceFlag(env.disableAutoCompact) && breakdown.isAutoCompactEnabled !== false;
9472
+ const pct = percent(env.pctOverride);
9473
+ const threshold = positiveNumber(breakdown.autoCompactThreshold);
9330
9474
  if (autoCompact && threshold !== void 0) {
9331
9475
  const native = pct === void 0 ? threshold : Math.min(Math.floor((threshold + CLAUDE_AUTOCOMPACT_BUFFER_TOKENS) * (pct / 100)), threshold);
9332
9476
  if (native > 0) return tokenLimits("auto-compact", true, native, resetMargin, warningRunway);
9333
9477
  }
9334
- const window = positiveNumberOf(usage.window);
9478
+ const window = positiveNumber(usage.window);
9335
9479
  if (window !== void 0) {
9336
9480
  const configured = configuredWindow(settings2, env, breakdown.model);
9337
9481
  const effective = Math.min(configured ?? window, window);
9338
9482
  const native = autoCompact ? effective - CLAUDE_OUTPUT_RESERVE_TOKENS - CLAUDE_AUTOCOMPACT_BUFFER_TOKENS : effective - CLAUDE_OUTPUT_RESERVE_TOKENS;
9339
- if (native > 0) return tokenLimits("window", autoCompact, native, resetMargin, warningRunway);
9483
+ return tokenLimits("window", autoCompact, native, resetMargin, warningRunway);
9340
9484
  }
9341
9485
  return percentLimits(autoCompact, pct, resetMargin, warningRunway);
9342
9486
  }
@@ -9347,7 +9491,7 @@ var MAX_RESPONSE_BYTES = 1024 * 1024;
9347
9491
  var TOOL_NAMES = ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search"];
9348
9492
  function identity(input) {
9349
9493
  if (!input || typeof input !== "object" || typeof input.cwd !== "string") throw new Error("invalid identity");
9350
- return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey: projectKey(input.cwd), agent: input.agent, model: input.model });
9494
+ return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey: resolveProjectHome(input.cwd, input.home).name, agent: input.agent, model: input.model });
9351
9495
  }
9352
9496
  function paramProblem(schema, params) {
9353
9497
  const first = Errors2(schema, params).find((error) => error.keyword !== "boolean");
@@ -9356,9 +9500,6 @@ function paramProblem(schema, params) {
9356
9500
  const field = first.instancePath.replace(/^\//, "").replaceAll("/", ".");
9357
9501
  return `${field ? `${field} ` : ""}${first.message}${extra}`;
9358
9502
  }
9359
- function jsonValue(value) {
9360
- return JSON.parse(JSON.stringify(value));
9361
- }
9362
9503
  function boundOperation(operation, ...rest) {
9363
9504
  return {
9364
9505
  description: operation.description,
@@ -9383,7 +9524,7 @@ var OPERATIONS = {
9383
9524
  async function dispatch(request) {
9384
9525
  if (!request || typeof request !== "object" || Array.isArray(request)) throw new Error("malformed request");
9385
9526
  const value = request;
9386
- if (value.op === "schemas") return TOOL_NAMES.map((name) => ({ name, description: OPERATIONS[name].description, inputSchema: jsonValue(OPERATIONS[name].parameters) }));
9527
+ if (value.op === "schemas") return TOOL_NAMES.map((name) => ({ name, description: OPERATIONS[name].description, inputSchema: JSON.parse(JSON.stringify(OPERATIONS[name].parameters)) }));
9387
9528
  if (value.op === "texts") return { warning: CLAUDE_WARNING_PROMPT, continuation: CONTINUATION, wipeSentence: CLAUDE_WIPE_SENTENCE };
9388
9529
  if (value.op === "limits") return resolveClaudeLimits(value.facts);
9389
9530
  if (value.op === "tool") {
@@ -9415,7 +9556,7 @@ async function handleLine(line) {
9415
9556
  return JSON.stringify({ ok: false, error: safeError(error) });
9416
9557
  }
9417
9558
  }
9418
- if (process.argv[1] && pathToFileURL(realpathSync(process.argv[1])).href === import.meta.url) {
9559
+ if (process.argv[1] && pathToFileURL(realpathSync2(process.argv[1])).href === import.meta.url) {
9419
9560
  process.stdin.setEncoding("utf8");
9420
9561
  let input = "";
9421
9562
  process.stdin.on("data", (chunk) => {