notesoup 0.50.0 → 0.51.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 (172) hide show
  1. package/README.md +12 -0
  2. package/dist/{src/claude → plugins/claude/src}/helper.js +7 -7
  3. package/dist/{src/claude → plugins/claude/src}/history.d.ts +1 -1
  4. package/dist/{src/claude → plugins/claude/src}/history.js +1 -1
  5. package/dist/plugins/claude/src/text.d.ts +6 -0
  6. package/dist/plugins/claude/src/text.js +7 -0
  7. package/dist/{src/claude → plugins/claude/src}/thresholds.js +3 -3
  8. package/dist/{src → plugins}/dsh/budget.js +1 -1
  9. package/dist/{src → plugins}/dsh/engine.d.ts +1 -1
  10. package/dist/{src → plugins}/dsh/engine.js +1 -1
  11. package/dist/{src → plugins}/dsh/history.d.ts +1 -1
  12. package/dist/{src → plugins}/dsh/history.js +1 -1
  13. package/dist/{src → plugins}/dsh/index.js +1 -1
  14. package/dist/{src → plugins}/dsh/tools.js +3 -3
  15. package/dist/{src → plugins}/dsh/window.d.ts +1 -1
  16. package/dist/{src → plugins}/dsh/window.js +5 -5
  17. package/dist/{src → plugins}/pi/boot.d.ts +1 -1
  18. package/dist/{src → plugins}/pi/boot.js +5 -4
  19. package/dist/{src → plugins}/pi/budget.js +4 -4
  20. package/dist/{src → plugins}/pi/dream/cli.d.ts +1 -1
  21. package/dist/{src → plugins}/pi/dream/cli.js +6 -6
  22. package/dist/{src → plugins}/pi/dream/runner.d.ts +1 -1
  23. package/dist/{src → plugins}/pi/dream/runner.js +3 -3
  24. package/dist/{src → plugins}/pi/dream/settings.d.ts +1 -1
  25. package/dist/{src → plugins}/pi/dream/settings.js +2 -2
  26. package/dist/{src → plugins}/pi/history-tools.js +1 -1
  27. package/dist/{src → plugins}/pi/history.d.ts +1 -1
  28. package/dist/{src → plugins}/pi/history.js +1 -1
  29. package/dist/plugins/pi/index.d.ts +1 -0
  30. package/dist/plugins/pi/index.js +1 -0
  31. package/dist/{src → plugins}/pi/notes/adapter.d.ts +1 -1
  32. package/dist/{src → plugins}/pi/notes/adapter.js +1 -1
  33. package/dist/{src → plugins}/pi/notes/tools.js +1 -1
  34. package/dist/{src → plugins}/pi/reset/artifacts.d.ts +1 -1
  35. package/dist/{src → plugins}/pi/reset/artifacts.js +1 -1
  36. package/dist/{src → plugins}/pi/reset/lifecycle.d.ts +1 -1
  37. package/dist/{src → plugins}/pi/reset/lifecycle.js +1 -1
  38. package/dist/{src → plugins}/pi/runtime.js +2 -2
  39. package/dist/plugins/pi/text.d.ts +23 -0
  40. package/dist/plugins/pi/text.js +30 -0
  41. package/dist/{src → plugins}/pi/thresholds.d.ts +1 -1
  42. package/dist/{src → plugins}/pi/thresholds.js +4 -4
  43. package/dist/{src → plugins}/pi/tool-result.d.ts +1 -1
  44. package/dist/{src → plugins}/pi/tool-result.js +1 -1
  45. package/dist/{src → plugins}/pi/window.d.ts +1 -1
  46. package/dist/src/boot/text.d.ts +4 -13
  47. package/dist/src/boot/text.js +1 -11
  48. package/dist/src/budget/policy.d.ts +2 -3
  49. package/dist/src/budget/policy.js +1 -1
  50. package/dist/src/budget/text.d.ts +1 -12
  51. package/dist/src/budget/text.js +2 -24
  52. package/dist/src/dream/settings.d.ts +1 -2
  53. package/dist/src/dream/settings.js +4 -2
  54. package/dist/src/index.d.ts +29 -1
  55. package/dist/src/index.js +26 -1
  56. package/dist/src/notes/address.d.ts +5 -4
  57. package/dist/src/notes/address.js +13 -7
  58. package/dist/src/notes/identity.js +3 -7
  59. package/dist/src/notes/paths.d.ts +4 -2
  60. package/dist/src/notes/paths.js +11 -6
  61. package/dist/src/notes/store.d.ts +4 -1
  62. package/dist/src/notes/store.js +66 -34
  63. package/dist/src/settings.d.ts +7 -16
  64. package/dist/src/settings.js +7 -10
  65. package/dist/src/tools/notes.d.ts +5 -5
  66. package/dist/src/tools/notes.js +5 -4
  67. package/dist/test/agent-loop.test.js +5 -4
  68. package/dist/test/boot.integration.test.js +5 -5
  69. package/dist/test/budget-settings.integration.test.js +1 -1
  70. package/dist/test/claude-history.test.js +2 -2
  71. package/dist/test/claude-mod.test.js +12 -11
  72. package/dist/test/claude-validation.test.js +3 -3
  73. package/dist/test/dependencies.test.js +52 -44
  74. package/dist/test/doctor.test.js +1 -1
  75. package/dist/test/dream-skill.test.js +4 -4
  76. package/dist/test/dream.test.js +2 -2
  77. package/dist/test/dsh-cli.test.js +2 -2
  78. package/dist/test/dsh-compaction-parity.test.js +1 -1
  79. package/dist/test/dsh.test.js +4 -4
  80. package/dist/test/helpers/dependency-graph.js +9 -7
  81. package/dist/test/helpers/dsh.d.ts +1 -1
  82. package/dist/test/helpers/dsh.js +2 -2
  83. package/dist/test/helpers/extension.js +6 -5
  84. package/dist/test/helpers/notes.js +1 -1
  85. package/dist/test/model-facing-text.test.js +4 -2
  86. package/dist/test/notes-query-homes.test.d.ts +1 -0
  87. package/dist/test/notes-query-homes.test.js +161 -0
  88. package/dist/test/notes.integration.test.js +3 -2
  89. package/dist/test/notes.test.js +1 -1
  90. package/dist/test/reset-lifecycle.test.js +8 -7
  91. package/docs/architecture.md +21 -18
  92. package/docs/claude-code-mod.md +3 -3
  93. package/docs/dsh.md +1 -1
  94. package/docs/dsh.profile.patch.yml +1 -1
  95. package/docs/notes-library.md +17 -10
  96. package/docs/reset-lifecycle.md +1 -1
  97. package/docs/sdk-integration.md +2 -2
  98. package/package.json +17 -13
  99. package/{mods/notesoup → plugins/claude}/.claude-plugin/plugin.json +1 -1
  100. package/{mods/notesoup → plugins/claude}/dist/claude/helper.js +565 -540
  101. package/{mods/notesoup → plugins/claude}/skills/memory/SKILL.md +3 -0
  102. package/{src/claude → plugins/claude/src}/helper.ts +10 -9
  103. package/{src/claude → plugins/claude/src}/history.ts +1 -1
  104. package/plugins/claude/src/text.ts +10 -0
  105. package/{src/claude → plugins/claude/src}/thresholds.ts +3 -3
  106. package/{src → plugins}/dsh/budget.ts +1 -1
  107. package/{src → plugins}/dsh/engine.ts +1 -1
  108. package/{src → plugins}/dsh/history.ts +1 -1
  109. package/{src → plugins}/dsh/index.ts +1 -1
  110. package/{src → plugins}/dsh/tools.ts +3 -3
  111. package/{src → plugins}/dsh/window.ts +5 -5
  112. package/{src → plugins}/pi/boot.ts +5 -4
  113. package/{src → plugins}/pi/budget.ts +4 -4
  114. package/{src → plugins}/pi/dream/cli.ts +8 -8
  115. package/{src → plugins}/pi/dream/runner.ts +4 -4
  116. package/{src → plugins}/pi/dream/settings.ts +2 -2
  117. package/{src → plugins}/pi/history-tools.ts +1 -1
  118. package/{src → plugins}/pi/history.ts +1 -1
  119. package/plugins/pi/index.ts +1 -0
  120. package/{src → plugins}/pi/notes/adapter.ts +1 -1
  121. package/{src → plugins}/pi/notes/tools.ts +2 -2
  122. package/{src → plugins}/pi/reset/artifacts.ts +1 -1
  123. package/{src → plugins}/pi/reset/lifecycle.ts +2 -2
  124. package/{src → plugins}/pi/runtime.ts +2 -2
  125. package/plugins/pi/text.ts +35 -0
  126. package/{src → plugins}/pi/thresholds.ts +4 -4
  127. package/{src → plugins}/pi/tool-result.ts +1 -1
  128. package/{src → plugins}/pi/window.ts +1 -1
  129. package/skills/memory/SKILL.md +3 -0
  130. package/src/boot/text.ts +5 -15
  131. package/src/budget/policy.ts +3 -3
  132. package/src/budget/text.ts +2 -30
  133. package/src/dream/settings.ts +6 -3
  134. package/src/index.ts +52 -1
  135. package/src/notes/address.ts +12 -8
  136. package/src/notes/identity.ts +2 -8
  137. package/src/notes/paths.ts +12 -6
  138. package/src/notes/store.ts +62 -29
  139. package/src/settings.ts +8 -24
  140. package/src/tools/notes.ts +5 -4
  141. /package/dist/{src/claude → plugins/claude/src}/helper.d.ts +0 -0
  142. /package/dist/{src/claude → plugins/claude/src}/thresholds.d.ts +0 -0
  143. /package/dist/{src → plugins}/dsh/budget.d.ts +0 -0
  144. /package/dist/{src → plugins}/dsh/index.d.ts +0 -0
  145. /package/dist/{src → plugins}/dsh/tools.d.ts +0 -0
  146. /package/dist/{src → plugins}/pi/anchored.d.ts +0 -0
  147. /package/dist/{src → plugins}/pi/anchored.js +0 -0
  148. /package/dist/{src → plugins}/pi/budget.d.ts +0 -0
  149. /package/dist/{src → plugins}/pi/entries.d.ts +0 -0
  150. /package/dist/{src → plugins}/pi/entries.js +0 -0
  151. /package/dist/{src → plugins}/pi/estimate.d.ts +0 -0
  152. /package/dist/{src → plugins}/pi/estimate.js +0 -0
  153. /package/dist/{src → plugins}/pi/extension.d.ts +0 -0
  154. /package/dist/{src → plugins}/pi/extension.js +0 -0
  155. /package/dist/{src → plugins}/pi/history-tools.d.ts +0 -0
  156. /package/dist/{src → plugins}/pi/notes/tools.d.ts +0 -0
  157. /package/dist/{src → plugins}/pi/reset/committed.d.ts +0 -0
  158. /package/dist/{src → plugins}/pi/reset/committed.js +0 -0
  159. /package/dist/{src → plugins}/pi/runtime.d.ts +0 -0
  160. /package/dist/{src → plugins}/pi/session-reader.d.ts +0 -0
  161. /package/dist/{src → plugins}/pi/session-reader.js +0 -0
  162. /package/dist/{src → plugins}/pi/window.js +0 -0
  163. /package/{mods/notesoup → plugins/claude}/hooks/hooks.json +0 -0
  164. /package/{mods/notesoup → plugins/claude}/hooks/register.ts +0 -0
  165. /package/{mods/notesoup → plugins/claude}/playbook.md +0 -0
  166. /package/{mods/notesoup → plugins/claude}/skills/dream/SKILL.md +0 -0
  167. /package/{src → plugins}/pi/anchored.ts +0 -0
  168. /package/{src → plugins}/pi/entries.ts +0 -0
  169. /package/{src → plugins}/pi/estimate.ts +0 -0
  170. /package/{src → plugins}/pi/extension.ts +0 -0
  171. /package/{src → plugins}/pi/reset/committed.ts +0 -0
  172. /package/{src → plugins}/pi/session-reader.ts +0 -0
package/src/index.ts CHANGED
@@ -1 +1,52 @@
1
- export { default, createNotesoup } from "./pi/extension.js";
1
+ /**
2
+ * Host-neutral core entry.
3
+ *
4
+ * Everything under `src/` is independent of any host SDK: notes, boot, history, budget and the
5
+ * shared operations know nothing about Pi, Claude Code or dsh. Each plugin under `plugins/`
6
+ * composes these domains into that host's registration and owns that host's text, lifecycle and
7
+ * SDK types. Nothing here imports a plugin.
8
+ *
9
+ * This is the deliberate embedding surface for a host adapter — a curated list, not a re-export
10
+ * of every internal module. The notes family is also published as `notesoup/notes`; the Pi
11
+ * extension is `notesoup/pi` and the dsh plugins are `notesoup/dsh` and `notesoup/dsh/engine`.
12
+ */
13
+
14
+ // Notes: the standalone filesystem library, addressed by an explicit identity.
15
+ export { createNotesStore, noteIdentity, projectKey, slugify, NoteError } from "./notes/index.js";
16
+ export type {
17
+ NoteEditResult,
18
+ NoteMatch,
19
+ NoteMeta,
20
+ NoteReadResult,
21
+ NoteRenameResult,
22
+ NoteRow,
23
+ NoteSearchRow,
24
+ NotesIdentity,
25
+ NotesQuery,
26
+ NotesStore,
27
+ NoteWriteResult,
28
+ Origin,
29
+ Scope,
30
+ } from "./notes/index.js";
31
+
32
+ // Boot: five homes captured once, rendered from explicit logical tool names.
33
+ export { loadNotesSnapshot, unavailableNotesSnapshot } from "./boot/snapshot.js";
34
+ export type { NotesHome, NotesSnapshot } from "./boot/snapshot.js";
35
+ export { renderBootBlock } from "./boot/render.js";
36
+ export type { BootRenderData, BootWindowTree } from "./boot/render.js";
37
+ export { DEFAULT_BOOT_TOOL_NAMES, renderProtocolBlock } from "./boot/text.js";
38
+ export type { BootToolNames } from "./boot/text.js";
39
+
40
+ // Operations: the schemas and typed outcomes a host registers as its own tools, over a
41
+ // host-supplied notes identity or decoded history projection.
42
+ export { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "./tools/notes.js";
43
+ export { historyList, historyRead, historyWindows } from "./tools/history.js";
44
+ export { projectHistory } from "./history/history.js";
45
+ export type { HistoryProjection } from "./history/history.js";
46
+ export type { Operation, OperationError, Outcome, Renderer, TextWindow } from "./tools/result.js";
47
+
48
+ // Budget: pure thresholds and the approved reset prose.
49
+ export { deriveThresholds, remainingBudget } from "./budget/policy.js";
50
+ export type { ResolvedThresholds } from "./budget/policy.js";
51
+ export { selectContinuation, tokenBudgetGuidance, warningPrompt, WARNING_BODY } from "./budget/text.js";
52
+ export type { ResetOrigin } from "./budget/text.js";
@@ -1,17 +1,18 @@
1
1
  import { NoteError, shown } from "./errors.js";
2
2
  import type { NotesIdentity } from "./identity.js";
3
- import { assertVirtualPath, SLUG_PATTERN, type Scope } from "./paths.js";
3
+ import { assertVirtualPath, isSessionId, SLUG_PATTERN, type Scope } from "./paths.js";
4
4
 
5
5
  export type NoteAddress = { scope: Scope; path: string; who?: string };
6
6
 
7
- export const 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.";
7
+ export const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> and @sessions/<id>/<path> read named homes.";
8
8
 
9
9
  /** The one home-head vocabulary: the scope each public `@head` names, and the home directory family a head with `home` lists. */
10
- export const HOME_HEADS: ReadonlyMap<string, { readonly scope: Scope; readonly home?: "project" | "agents" | "models" }> = new Map([
10
+ export const HOME_HEADS: ReadonlyMap<string, { readonly scope: Scope; readonly home?: "sessions" | "project" | "agents" | "models" }> = new Map([
11
11
  ["project", { scope: "project" }],
12
12
  ["human", { scope: "human" }],
13
13
  ["self", { scope: "agent" }],
14
14
  ["model", { scope: "model" }],
15
+ ["sessions", { scope: "session", home: "sessions" }],
15
16
  ["projects", { scope: "project", home: "project" }],
16
17
  ["agents", { scope: "agent", home: "agents" }],
17
18
  ["models", { scope: "model", home: "models" }],
@@ -55,7 +56,7 @@ export function assertGlobPattern(value: unknown): string | undefined {
55
56
 
56
57
  /**
57
58
  * Decode one public note address into its physical home and virtual path. @self and @model
58
- * are relative; explicit projects/agents/models addresses always name one canonical slug.
59
+ * are relative; projects/agents/models name a canonical slug, sessions a directory component.
59
60
  */
60
61
  export function assertAddress(value: unknown): NoteAddress {
61
62
  if (typeof value !== "string") throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
@@ -70,7 +71,7 @@ export function assertAddress(value: unknown): NoteAddress {
70
71
  if (head.home === undefined) path = tail.join("/");
71
72
  else {
72
73
  who = tail[0] ?? "";
73
- if (!SLUG_PATTERN.test(who)) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
74
+ if (!(scope === "session" ? isSessionId(who) : SLUG_PATTERN.test(who))) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
74
75
  path = tail.slice(1).join("/");
75
76
  }
76
77
  if (path === "" && scope !== "agent" && scope !== "model") throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
@@ -82,8 +83,8 @@ export function assertAddress(value: unknown): NoteAddress {
82
83
 
83
84
  /** Render a virtual path in its one unambiguous address form, used to match patterns. */
84
85
  export function canonicalAddressFor(identity: NotesIdentity, scope: Scope, path: string, who?: string): string {
85
- if (scope === "session") return path;
86
- if (scope === "project") return who === undefined ? `@project/${path}` : `@projects/${who}/${path}`;
86
+ if (scope === "session") return `@sessions/${who ?? identity.sessionId}/${path}`;
87
+ if (scope === "project") return `@projects/${who ?? identity.projectKey}/${path}`;
87
88
  if (scope === "human") return `@human/${path}`;
88
89
  if (scope === "agent") return `@agents/${who ?? identity.agent}/${path}`;
89
90
  return `@models/${who ?? identity.model}/${path}`;
@@ -91,9 +92,12 @@ export function canonicalAddressFor(identity: NotesIdentity, scope: Scope, path:
91
92
 
92
93
  /**
93
94
  * Render the address a caller sees. The current agent and model homes read as @self/ and
94
- * @model/ so ordinary sessions are not taught explicit ids; only other homes (dream) name one.
95
+ * @model/. Current session and project homes retain bare paths and @project/; explicitly
96
+ * named session/project homes keep their read-only addresses, even for the current identity.
95
97
  */
96
98
  export function addressFor(identity: NotesIdentity, scope: Scope, path: string, who?: string): string {
99
+ if (scope === "session" && who === undefined) return path;
100
+ if (scope === "project" && who === undefined) return `@project/${path}`;
97
101
  if (scope === "agent" && (who === undefined || who === identity.agent)) return `@self/${path}`;
98
102
  if (scope === "model" && (who === undefined || who === identity.model)) return `@model/${path}`;
99
103
  return canonicalAddressFor(identity, scope, path, who);
@@ -1,5 +1,5 @@
1
1
  import { resolve } from "node:path";
2
- import { SLUG_PATTERN } from "./paths.js";
2
+ import { isSessionId, SLUG_PATTERN } from "./paths.js";
3
3
 
4
4
  /** Explicit, host-neutral identity for one notes store. */
5
5
  export type NotesIdentity = Readonly<{
@@ -15,12 +15,6 @@ function requireString(field: string, value: unknown): string {
15
15
  return value;
16
16
  }
17
17
 
18
- function assertDirectoryComponent(field: string, value: string): void {
19
- if (value === "." || value === ".." || /[\\/\0:]/.test(value)) {
20
- throw new TypeError(`notes context ${field} must be a safe single directory component`);
21
- }
22
- }
23
-
24
18
  /** Validate and snapshot caller identity; no global or environment defaults are consulted. */
25
19
  export function snapshotNotesIdentity(value: NotesIdentity): NotesIdentity {
26
20
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("notes context must be a plain object");
@@ -29,7 +23,7 @@ export function snapshotNotesIdentity(value: NotesIdentity): NotesIdentity {
29
23
  const projectKey = requireString("projectKey", value.projectKey);
30
24
  const agent = requireString("agent", value.agent);
31
25
  const model = requireString("model", value.model);
32
- assertDirectoryComponent("sessionId", sessionId);
26
+ if (!isSessionId(sessionId)) throw new TypeError("notes context sessionId must be a safe single directory component");
33
27
  if (!SLUG_PATTERN.test(projectKey)) throw new TypeError("notes context projectKey must be a canonical lowercase slug");
34
28
  if (!SLUG_PATTERN.test(agent)) throw new TypeError("notes context agent must be a canonical lowercase slug");
35
29
  if (!SLUG_PATTERN.test(model)) throw new TypeError("notes context model must be a canonical lowercase slug");
@@ -8,6 +8,11 @@ export type Scope = "session" | "project" | "human" | "agent" | "model";
8
8
  /** The one legal home-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
9
9
  export const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
10
10
 
11
+ /** Session identities use the same single-directory-component grammar as NotesIdentity, not slugs. */
12
+ export function isSessionId(value: string): boolean {
13
+ return value.length > 0 && value !== "." && value !== ".." && !/[\\/\0:]/.test(value);
14
+ }
15
+
11
16
  /** Slugify a caller-declared identity; identity is never inferred from note content. */
12
17
  export function slugify(value: string): string {
13
18
  const slug = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
@@ -35,19 +40,20 @@ export function sessionHomesRoot(home: string): string {
35
40
  /** Absolute directory holding one scope's notes. The identity's home is already resolved. */
36
41
  export function scopeDir(scope: Scope, identity: NotesIdentity, who?: string): string {
37
42
  if (!["session", "project", "human", "agent", "model"].includes(scope)) throw new TypeError("invalid notes scope");
38
- if (who !== undefined && (scope !== "project" && scope !== "agent" && scope !== "model" || !SLUG_PATTERN.test(who))) throw new TypeError("who must be a canonical project/agent/model slug");
43
+ if (who !== undefined && (scope === "session" ? !isSessionId(who) : scope === "human" || !SLUG_PATTERN.test(who))) throw new TypeError("who must be a session directory component or canonical project/agent/model slug");
39
44
  if (scope === "human") return join(identity.home, "human");
40
45
  if (scope === "project") return join(identity.home, "project", who ?? identity.projectKey);
41
46
  if (scope === "agent") return join(identity.home, "agents", who ?? identity.agent);
42
47
  if (scope === "model") return join(identity.home, "models", who ?? identity.model);
43
- return join(sessionHomesRoot(identity.home), identity.sessionId);
48
+ return join(sessionHomesRoot(identity.home), who ?? identity.sessionId);
44
49
  }
45
50
 
46
- /** Every existing home directory of the agents/ or models/ namespace, as names. */
47
- export async function namespaceSlugs(namespace: "agents" | "models", home: string): Promise<string[]> {
51
+ /** Every addressable home directory in a namespace; sessions keep their original identity spelling. */
52
+ export async function namespaceSlugs(namespace: "sessions" | "project" | "agents" | "models", home: string): Promise<string[]> {
53
+ const root = namespace === "sessions" ? sessionHomesRoot(home) : join(home, namespace);
48
54
  try {
49
- return (await readdir(join(home, namespace), { withFileTypes: true }))
50
- .filter((entry) => entry.isDirectory())
55
+ return (await readdir(root, { withFileTypes: true }))
56
+ .filter((entry) => entry.isDirectory() && (namespace === "sessions" ? isSessionId(entry.name) : SLUG_PATTERN.test(entry.name)))
51
57
  .map((entry) => entry.name)
52
58
  .sort();
53
59
  } catch (error) {
@@ -9,8 +9,8 @@ import { snapshotNotesIdentity, type NotesIdentity } from "./identity.js";
9
9
  import { NoteError } from "./errors.js";
10
10
  import { MAX_NOTE_BYTES, MAX_NOTE_PATH_BYTES } from "./constants.js";
11
11
  import { isOrigin, localIso, parseNote, serializeNote, stripLeadingFrontmatter, type NoteMeta, type Origin } from "./frontmatter.js";
12
- import { namespaceSlugs, noteFileName, physicalPath, scopeDir, SLUG_PATTERN, type Scope } from "./paths.js";
13
- import { projectHomes, projectReceipt, type ProjectReceipt } from "./project-home.js";
12
+ import { namespaceSlugs, noteFileName, physicalPath, scopeDir, isSessionId, SLUG_PATTERN, type Scope } from "./paths.js";
13
+ import { projectReceipt, type ProjectReceipt } from "./project-home.js";
14
14
 
15
15
  export type { NoteMeta, Origin, Scope };
16
16
 
@@ -28,7 +28,10 @@ export type NoteSearchRow = { address: string; scope: Scope; path: string; meta:
28
28
  export type EditOperation = { oldText: string; newText: string };
29
29
  export type WriteOptions = { origin?: Origin };
30
30
  export type EditOptions = { origin?: Origin; crumpled?: boolean; replaceAll?: boolean; renameTo?: string };
31
- export type NotesQuery = { glob?: string; crumpled?: boolean };
31
+ /** Omitted/null/empty glob or bare @default selects current homes; explicit globs match full addresses.
32
+ * Only the current session also matches its bare-path alias (e.g. *.md or deep/**).
33
+ */
34
+ export type NotesQuery = { glob?: string | null; crumpled?: boolean };
32
35
  /** A read exposes metadata and the pure body; the serialized frontmatter is never part of the body. */
33
36
  export type NoteReadResult = { meta: NoteMeta; body: string; resolvedScope: Scope };
34
37
  export type NoteWriteResult = { meta: NoteMeta; outcome: "created" | "overwrote" | "uncrumpled" };
@@ -115,21 +118,55 @@ async function walkMarkdown(dir: string, base = dir): Promise<string[]> {
115
118
  /** Which homes one call iterates; reserved heads narrow traversal before any file is read. */
116
119
  type HomeRef = { scope: Scope; who?: string };
117
120
 
118
- async function homesForPattern(pattern: string | undefined, identity: NotesIdentity): Promise<HomeRef[] | undefined> {
119
- if (!pattern || !pattern.startsWith("@")) return undefined;
120
- const [rawHead, ...tail] = pattern.split("/");
121
- const head = tail.length === 0 ? undefined : HOME_HEADS.get(rawHead!.slice(1)); // a bare "@projects" names no homes
122
- if (head === undefined) return [];
123
- if (head.home === undefined) return [{ scope: head.scope }];
124
- const name = tail[0];
125
- if (name !== undefined && name.length > 0 && !/[*?]/.test(name)) return [{ scope: head.scope, who: assertWho(name) }];
126
- const names = head.home === "project" ? projectHomes(identity.home).map(home => home.name) : await namespaceSlugs(head.home, identity.home);
127
- return names.map((who) => ({ scope: head.scope, who }));
121
+ async function homesForPattern(pattern: string | undefined, identity: NotesIdentity, status?: NoteQueryStatus): Promise<HomeRef[]> {
122
+ if (pattern === undefined) return SCOPE_ORDER.map((scope) => ({ scope }));
123
+
124
+ const families = [
125
+ { scope: "session", home: "sessions", current: identity.sessionId },
126
+ { scope: "project", home: "project", current: identity.projectKey },
127
+ { scope: "agent", home: "agents", current: identity.agent },
128
+ { scope: "model", home: "models", current: identity.model },
129
+ ] as const;
130
+ async function enumerate(family: typeof families[number], relative: boolean): Promise<HomeRef[]> {
131
+ let names: string[];
132
+ try {
133
+ names = await namespaceSlugs(family.home, identity.home);
134
+ } catch (error) {
135
+ if (!status || !isFilesystemError(error)) throw error;
136
+ status.homesUnavailable.push(`@${family.home === "project" ? "projects" : family.home}`);
137
+ return [];
138
+ }
139
+ // Include the current home even when missing or a non-directory, and only once.
140
+ return [...new Set([family.current, ...names])].map((who) => ({
141
+ scope: family.scope,
142
+ who: relative && who === family.current ? undefined : who,
143
+ }));
144
+ }
145
+
146
+ if (pattern.startsWith("@")) {
147
+ const [rawHead, ...tail] = pattern.slice(1).split("/");
148
+ if (!/[*?]/.test(rawHead!)) {
149
+ const head = HOME_HEADS.get(rawHead!);
150
+ if (head === undefined || tail.length === 0) return [];
151
+ if (head.home === undefined) return [{ scope: head.scope }];
152
+ const name = tail[0];
153
+ if (name && !/[*?]/.test(name)) return [{ scope: head.scope, who: assertWho(name, head.scope) }];
154
+ return enumerate(families.find((family) => family.home === head.home)!, false);
155
+ }
156
+ }
157
+ // Unreserved patterns see the full universe, not just the current identities.
158
+ const homes: HomeRef[] = [];
159
+ for (const scope of SCOPE_ORDER) {
160
+ if (scope === "human") homes.push({ scope });
161
+ else homes.push(...await enumerate(families.find((family) => family.scope === scope)!, true));
162
+ }
163
+ return homes;
128
164
  }
129
165
 
130
166
  /** Relative pattern heads resolve to canonical names, so they match canonical addresses. */
131
167
  function normalizePattern(pattern: string | undefined, identity: NotesIdentity): string | undefined {
132
168
  if (!pattern) return pattern;
169
+ if (pattern.startsWith("@project/")) return `@projects/${identity.projectKey}/${pattern.slice("@project/".length)}`;
133
170
  if (pattern.startsWith("@self/")) return `@agents/${identity.agent}/${pattern.slice("@self/".length)}`;
134
171
  if (pattern.startsWith("@model/")) return `@models/${identity.model}/${pattern.slice("@model/".length)}`;
135
172
  return pattern;
@@ -140,9 +177,9 @@ function assertOrigin(value: unknown): Origin {
140
177
  return value;
141
178
  }
142
179
 
143
- function assertWho(value: unknown): string {
144
- if (typeof value !== "string" || !SLUG_PATTERN.test(value)) {
145
- throw new NoteError("invalid_scope", "who must be a canonical lowercase slug");
180
+ function assertWho(value: unknown, scope: Scope): string {
181
+ if (typeof value !== "string" || !(scope === "session" ? isSessionId(value) : SLUG_PATTERN.test(value))) {
182
+ throw new NoteError("invalid_scope", scope === "session" ? "session id must be a safe single directory component" : "who must be a canonical lowercase slug");
146
183
  }
147
184
  return value;
148
185
  }
@@ -216,9 +253,10 @@ function frontmatterOf(meta: NoteMeta): string {
216
253
  return serializeNote(meta, "").slice(0, -2);
217
254
  }
218
255
 
219
- /** Explicit project homes are always read-only; agent/model homes allow their owner. */
256
+ /** Explicit session/project homes are always read-only; agent/model homes allow their owner. */
220
257
  function assertWritableHome(scope: Scope, who: string | undefined, identity: NotesIdentity): void {
221
258
  if (who === undefined) return;
259
+ if (scope === "session") throw new NoteError("invalid_scope", `@sessions/${who}/ is read-only; use a bare path to write to this session.`);
222
260
  if (scope === "project") throw new NoteError("invalid_scope", `@projects/${who}/ is read-only; use @project/ to write to your own project.`);
223
261
  const current = scope === "agent" ? identity.agent : identity.model;
224
262
  if (who === current) return;
@@ -275,7 +313,7 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
275
313
  if (raw === undefined) return undefined;
276
314
  const now = Date.now();
277
315
  const parsed = parseNote(raw, now);
278
- if (scope === "project" && destination.who !== undefined) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
316
+ if ((scope === "project" || scope === "session") && destination.who !== undefined) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
279
317
  // A read records its own access, exactly as a write records an edit.
280
318
  const meta: NoteMeta = { ...parsed.meta, scope, lastAccessed: now, accessCount: (typeof parsed.meta.accessCount === "number" ? parsed.meta.accessCount : 0) + 1 };
281
319
  await atomicWrite(path, serializeNote(meta, parsed.body));
@@ -367,17 +405,11 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
367
405
  }
368
406
 
369
407
  async function* scan(options: NotesQuery, status?: NoteQueryStatus): AsyncGenerator<Omit<NoteRow, "sizeBytes">> {
370
- const pattern = normalizePattern(options.glob, identity);
371
- const normalized = assertGlobPattern(pattern);
408
+ const glob = assertGlobPattern(options.glob);
409
+ const pattern = glob === "@default" ? undefined : glob;
410
+ const normalized = normalizePattern(pattern, identity);
372
411
  const matcher = normalized === undefined ? undefined : globToRegExp(normalized);
373
- let homes: HomeRef[];
374
- try {
375
- homes = await homesForPattern(normalized, identity) ?? SCOPE_ORDER.map((scope) => ({ scope }));
376
- } catch (error) {
377
- if (!status || !isFilesystemError(error) || !/^@(projects|agents|models)\//.test(options.glob ?? "")) throw error;
378
- status.homesUnavailable.push(options.glob!.split("/")[0]!);
379
- return;
380
- }
412
+ const homes = await homesForPattern(pattern, identity, status);
381
413
  for (const home of homes) {
382
414
  const scope = home.scope;
383
415
  const root = scopeDir(scope, identity, home.who);
@@ -390,7 +422,8 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
390
422
  continue;
391
423
  }
392
424
  for (const path of paths) {
393
- if (matcher && !matcher.test(canonicalAddressFor(identity, scope, path, home.who))) continue;
425
+ if (matcher && !matcher.test(canonicalAddressFor(identity, scope, path, home.who))
426
+ && !(scope === "session" && home.who === undefined && !pattern!.startsWith("@") && matcher.test(path))) continue;
394
427
  const address = addressFor(identity, scope, path, home.who);
395
428
  const fullPath = join(root, path);
396
429
  let raw: string;
package/src/settings.ts CHANGED
@@ -1,19 +1,5 @@
1
+ /** The one settings key every host reads its own fields from. */
1
2
  export const NOTESOUP_SETTINGS_KEY = "notesoup";
2
- /** Nested under "notesoup": the default dreamer model pattern, overridden by CLI --dreamer. */
3
- export const NOTESOUP_DREAMER_KEY = "dreamer";
4
-
5
- /**
6
- * The one notesoup settings shape both hosts read. `reminderMarginTokens` is Pi's early
7
- * reminder margin; `resetMarginTokens` and `warningRunwayTokens` are the Claude mod's
8
- * margins against Claude's own auto-compact point (see src/claude/thresholds.ts). A host
9
- * ignores the keys it does not use; every value is validated where it is consumed.
10
- */
11
- export type NotesoupSettings = {
12
- reminderMarginTokens?: unknown;
13
- resetMarginTokens?: unknown;
14
- warningRunwayTokens?: unknown;
15
- dreamer?: unknown;
16
- };
17
3
 
18
4
  /** A plain settings object; arrays and null are not one. */
19
5
  export function isPlainObject(value: unknown): value is Record<string, unknown> {
@@ -27,13 +13,11 @@ function notesoupSettings(settings: unknown): Record<string, unknown> {
27
13
  return isPlainObject(value) ? value : {};
28
14
  }
29
15
 
30
- /** Merge the global and project "notesoup" objects per key; project wins, mirroring Pi's deep merge. */
31
- export function mergeNotesoupSettings(globalSettings: unknown, projectSettings: unknown): NotesoupSettings {
32
- const merged = { ...notesoupSettings(globalSettings), ...notesoupSettings(projectSettings) };
33
- return {
34
- reminderMarginTokens: merged.reminderMarginTokens,
35
- resetMarginTokens: merged.resetMarginTokens,
36
- warningRunwayTokens: merged.warningRunwayTokens,
37
- dreamer: merged.dreamer,
38
- };
16
+ /**
17
+ * Merge the global and project "notesoup" objects per key; project wins, mirroring Pi's deep
18
+ * merge. The record is exactly what the scopes contain: this core module owns the key and the
19
+ * merge, while each host names, reads and validates the fields it consumes.
20
+ */
21
+ export function mergeNotesoupSettings(globalSettings: unknown, projectSettings: unknown): Record<string, unknown> {
22
+ return { ...notesoupSettings(globalSettings), ...notesoupSettings(projectSettings) };
39
23
  }
@@ -14,8 +14,9 @@ const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
14
14
  const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
15
15
  const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
16
16
  const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
17
- const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses.");
18
- const 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.";
17
+ const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current homes.");
18
+ const QUERY_HOMES_DESCRIPTION = "Omit `glob` or use `@default` for this session and current shared homes; `**` searches all homes, `@sessions/*/**` searches all sessions.";
19
+ const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
19
20
 
20
21
  /**
21
22
  * Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
@@ -311,7 +312,7 @@ function renderListData(data: NotesListData): string {
311
312
 
312
313
  export const notesList = {
313
314
  name: "notes_list", label: "Notes list",
314
- description: `List notes in this session and the four @ homes, newest first. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
315
+ description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${QUERY_HOMES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
315
316
  parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
316
317
  async execute(params: Static<typeof notesListParameters>, identity: NotesIdentity): Promise<Outcome<NotesListData>> {
317
318
  try {
@@ -358,7 +359,7 @@ function fitSearchFile(file: SearchFile, fits: (candidate: SearchFile) => boolea
358
359
 
359
360
  export const notesSearch = {
360
361
  name: "notes_search", label: "Notes search",
361
- description: `Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
362
+ description: `Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${QUERY_HOMES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
362
363
  parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
363
364
  async execute(params: Static<typeof notesSearchParameters>, identity: NotesIdentity): Promise<Outcome<NotesSearchData>> {
364
365
  try {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes