notesoup 0.50.0 → 0.51.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/README.md +12 -1
  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/package.json +13 -13
  98. package/{mods/notesoup → plugins/claude}/.claude-plugin/plugin.json +1 -1
  99. package/{mods/notesoup → plugins/claude}/dist/claude/helper.js +80 -55
  100. package/{mods/notesoup → plugins/claude}/skills/memory/SKILL.md +3 -0
  101. package/{src/claude → plugins/claude/src}/helper.ts +10 -9
  102. package/{src/claude → plugins/claude/src}/history.ts +1 -1
  103. package/plugins/claude/src/text.ts +10 -0
  104. package/{src/claude → plugins/claude/src}/thresholds.ts +3 -3
  105. package/{src → plugins}/dsh/budget.ts +1 -1
  106. package/{src → plugins}/dsh/engine.ts +1 -1
  107. package/{src → plugins}/dsh/history.ts +1 -1
  108. package/{src → plugins}/dsh/index.ts +1 -1
  109. package/{src → plugins}/dsh/tools.ts +3 -3
  110. package/{src → plugins}/dsh/window.ts +5 -5
  111. package/{src → plugins}/pi/boot.ts +5 -4
  112. package/{src → plugins}/pi/budget.ts +4 -4
  113. package/{src → plugins}/pi/dream/cli.ts +8 -8
  114. package/{src → plugins}/pi/dream/runner.ts +4 -4
  115. package/{src → plugins}/pi/dream/settings.ts +2 -2
  116. package/{src → plugins}/pi/history-tools.ts +1 -1
  117. package/{src → plugins}/pi/history.ts +1 -1
  118. package/plugins/pi/index.ts +1 -0
  119. package/{src → plugins}/pi/notes/adapter.ts +1 -1
  120. package/{src → plugins}/pi/notes/tools.ts +2 -2
  121. package/{src → plugins}/pi/reset/artifacts.ts +1 -1
  122. package/{src → plugins}/pi/reset/lifecycle.ts +2 -2
  123. package/{src → plugins}/pi/runtime.ts +2 -2
  124. package/plugins/pi/text.ts +35 -0
  125. package/{src → plugins}/pi/thresholds.ts +4 -4
  126. package/{src → plugins}/pi/tool-result.ts +1 -1
  127. package/{src → plugins}/pi/window.ts +1 -1
  128. package/skills/memory/SKILL.md +3 -0
  129. package/src/boot/text.ts +5 -15
  130. package/src/budget/policy.ts +3 -3
  131. package/src/budget/text.ts +2 -30
  132. package/src/dream/settings.ts +6 -3
  133. package/src/index.ts +52 -1
  134. package/src/notes/address.ts +12 -8
  135. package/src/notes/identity.ts +2 -8
  136. package/src/notes/paths.ts +12 -6
  137. package/src/notes/store.ts +62 -29
  138. package/src/settings.ts +8 -24
  139. package/src/tools/notes.ts +5 -4
  140. package/docs/sdk-integration.md +0 -39
  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
@@ -1,7 +1,7 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import type { ExtensionAPI, ExtensionContext, SessionBoundaryDraft, SessionEntry } from "@earendil-works/pi-coding-agent";
3
3
  import { BOOT_TYPE, CONTINUATION_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../entries.js";
4
- import { selectContinuation, type ResetOrigin } from "../../budget/text.js";
4
+ import { selectContinuation, type ResetOrigin } from "../../../src/budget/text.js";
5
5
  import { isForeignResetTailEntry, isWindowBootEntry, isWindowMarker, markerResetOrigin, type WindowMarker } from "../window.js";
6
6
  import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "../boot.js";
7
7
 
@@ -4,8 +4,8 @@ import type { AgentBeforeSettleEvent, ExtensionAPI, ExtensionContext, SessionBou
4
4
  import { currentReset, currentWindowId } from "../window.js";
5
5
  import { nextHistorySeq } from "../history.js";
6
6
  import { resetBoundaryCommitted } from "./committed.js";
7
- import type { ResetOrigin } from "../../budget/text.js";
8
- import { errorMessage } from "../../error-message.js";
7
+ import type { ResetOrigin } from "../../../src/budget/text.js";
8
+ import { errorMessage } from "../../../src/error-message.js";
9
9
 
10
10
  type BudgetOwner = {
11
11
  automaticResetEnabled: (ctx: ExtensionContext) => boolean;
@@ -8,10 +8,10 @@ import { currentReset, currentWindowId, isCheckpointBackedReset, isWindowBoot, i
8
8
  import { registerResetLifecycle } from "./reset/lifecycle.js";
9
9
  import { buildResetDrafts, LAST_WORD_PREFIX, MAX_LAST_WORD_CHARS, repairResetTail, sanitizeLastWord } from "./reset/artifacts.js";
10
10
  import { BOOT_TYPE, MANUAL_WIPE_TYPE, RESET_LAST_WORD_TYPE } from "./entries.js";
11
- import { warningContent } from "../budget/text.js";
11
+ import { warningContent } from "./text.js";
12
12
  import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
13
13
  import { nextHistorySeq } from "./history.js";
14
- import { errorMessage } from "../error-message.js";
14
+ import { errorMessage } from "../../src/error-message.js";
15
15
 
16
16
  function readPackageVersion(): string {
17
17
  for (const up of ["../../package.json", "../../../package.json"]) {
@@ -0,0 +1,35 @@
1
+ import { COUNTDOWN_LINE, GUIDANCE_CLOSE_TAG, GUIDANCE_OPEN_TAG, WARNING_BODY, WARNING_CALL } from "../../src/budget/text.js";
2
+
3
+ /**
4
+ * Pi-only closing hints. Pi's TUI drops the human's visible transcript when a window resets, and
5
+ * the model, not the human, owns when that reset happens. A host whose reset leaves the human's
6
+ * view intact must not carry these — the claim would be false there. The bare `empty_brain` token
7
+ * is interpolated by renderProtocolBlock; the prose itself stays plain English.
8
+ */
9
+ export const PI_PRE_RESET_HINTS = `Resetting clears the human's chat view too. Don't put a long explanation right before a reset and assume they'll still be able to read it. Save the handoff in notes; give the explanation after the reset.
10
+ Unless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.`;
11
+
12
+ /** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
13
+ export const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
14
+
15
+ /**
16
+ * With a prompt attached the close-out is an order rather than a nudge: the human already
17
+ * said when to reset, and a task line for the next window just preceded it. Only Pi has a
18
+ * reset command that takes a prompt, so this lives with the Pi text.
19
+ */
20
+ export const WARNING_CALL_PROMPTED = "Organize the notes first, then call `empty_brain` right away — do not wait to be cut off.";
21
+
22
+ /**
23
+ * The human typed `/empty <prompt>`: the raw command line leads the close-out so the
24
+ * closing model sees what the next window was asked to do, verbatim. The tag names it as the
25
+ * next window's prompt, so no prose has to explain that.
26
+ */
27
+ export function promptBlock(commandLine: string): string {
28
+ return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
29
+ }
30
+
31
+ /** The hidden checkpoint text for Pi's manual/budget-triggered requests (dsh reads warningPrompt() directly). */
32
+ export function warningContent(commandLine?: string): string {
33
+ const closeOut = commandLine ? `${promptBlock(commandLine)}\n${WARNING_CALL_PROMPTED}` : WARNING_CALL;
34
+ return `${GUIDANCE_OPEN_TAG}\n${WARNING_BODY}\n${closeOut}\n${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
35
+ }
@@ -1,8 +1,8 @@
1
- import { deriveThresholds, type ResolvedThresholds } from "../budget/policy.js";
1
+ import { deriveThresholds, type ResolvedThresholds } from "../../src/budget/policy.js";
2
2
  import { SettingsManager, type ExtensionContext } from "@earendil-works/pi-coding-agent";
3
- import { DEFAULT_RESERVE_TOKENS } from "../budget/constants.js";
4
- import { mergeNotesoupSettings } from "../settings.js";
5
- import { errorMessage } from "../error-message.js";
3
+ import { DEFAULT_RESERVE_TOKENS } from "../../src/budget/constants.js";
4
+ import { mergeNotesoupSettings } from "../../src/settings.js";
5
+ import { errorMessage } from "../../src/error-message.js";
6
6
 
7
7
  /**
8
8
  * Read the active compaction reserve, enablement, and notesoup margin settings. This
@@ -3,7 +3,7 @@ import { defineTool, type ExtensionAPI, type ExtensionToolContext } from "@earen
3
3
  import type { AgentToolResult } from "@earendil-works/pi-agent-core";
4
4
  import type { JsonValue } from "@earendil-works/pi-ai";
5
5
  import type { Static, TSchema } from "typebox";
6
- import { wireResult, type Operation, type Outcome, type Renderer } from "../tools/result.js";
6
+ import { wireResult, type Operation, type Outcome, type Renderer } from "../../src/tools/result.js";
7
7
 
8
8
  /** Pi's JSON envelope for reset and budget tools; details carry only log/UI metadata. */
9
9
  export function output(value: unknown, details?: unknown, terminate = false) {
@@ -3,7 +3,7 @@ import { getCurrentSystemMessage } from "@earendil-works/pi-ai";
3
3
  import { estimateContextTokens } from "./estimate.js";
4
4
  import { convertToLlm, type CustomEntry, type ExtensionContext, type SessionEntry } from "@earendil-works/pi-coding-agent";
5
5
  import { BOOT_TYPE, RESET_MARKER_TYPE } from "./entries.js";
6
- import type { ResetOrigin } from "../budget/text.js";
6
+ import type { ResetOrigin } from "../../src/budget/text.js";
7
7
  import type { SessionReader } from "./session-reader.js";
8
8
 
9
9
  export type WindowMarkerData = { readonly windowId: string; readonly origin?: ResetOrigin };
@@ -24,6 +24,7 @@ The address decides who a note belongs to and how long it lasts.
24
24
  | `@self/<path>` | self note | your reminders; yours alone if you have a name, shared by everyone nameless |
25
25
  | `@model/<path>` | model note | what applies to this model only |
26
26
  | `@projects/<name>/<path>` | named project, read-only | discover names and root paths with `notes_list` glob `@projects/*/**` |
27
+ | `@sessions/<id>/<path>` | named session, read-only | recover earlier task state; discover with glob `@sessions/*/**` |
27
28
 
28
29
  When notes conflict, the one most relevant to what you're doing applies. If that doesn't settle it, judge the case.
29
30
 
@@ -37,6 +38,8 @@ Write only what git and history cannot give back. Crumple notes that are no long
37
38
 
38
39
  ## Finding things again
39
40
 
41
+ For list/search, omit `glob` or use the collection alias `@default` for this session and current shared homes. Use `**` for all homes or `@sessions/*/**` for all sessions. Results carry readable note addresses; `@default` itself is not a read/write address.
42
+
40
43
  - **A note**: `notes_list` with a `glob` when you know roughly where it lives, `notes_search` when you know a phrase; then `notes_read` the address.
41
44
  - **Something that happened**: `history_list` to browse or search this session's events; `history_read` the seq for the whole event.
42
45
  - **An earlier window**: `history_windows` gives window ids; pass one as `window_id` to `history_list`.
package/src/boot/text.ts CHANGED
@@ -11,10 +11,7 @@ export const NOTES_PROTOCOL_CLOSE_TAG = "</notesoup:notes_protocol>";
11
11
  * model-facing reset tool replaces the whole sentence through BootToolNames.wipeSentence.
12
12
  */
13
13
  export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `empty_brain` and erase yourself with dignity.";
14
- /** Claude has no model-facing reset tool: the model ends its turn and the human runs the command. */
15
- export const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
16
14
  export const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.";
17
- export const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in this Claude session: no main transcript_path was supplied. Keep essential state in notes; don't pretend those notes are the missing transcript.";
18
15
 
19
16
  /**
20
17
  * Static protocol teaching adapted from Codex's token_budget.guidance_message to
@@ -47,6 +44,7 @@ An address decides who the note belongs to — and how long it is meant to last.
47
44
  - \`@self/<path>\` — 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~
48
45
  - \`@model/<path>\` — 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.
49
46
  - \`@projects/<name>/<path>\` — read-only named project notes; discover names and root paths with \`notes_list\` glob \`@projects/*/**\`.
47
+ - \`@sessions/<id>/<path>\` — read-only notes from a named session; find them with glob \`@sessions/*/**\`.
50
48
 
51
49
  Notes fighting?! HAH! Let them brawl!
52
50
  Whichever one is actually about what you're doing wins.
@@ -88,15 +86,6 @@ remembering, new Cheatsheet line. And when a line stops being true, kill it —
88
86
  reads that page as fact.
89
87
  </notesoup:maps>`;
90
88
 
91
- /**
92
- * Pi-only closing hints. Pi's TUI drops the human's visible transcript when a window resets, and
93
- * the model, not the human, owns when that reset happens. A host whose reset leaves the human's
94
- * view intact must not carry these — the claim would be false there. The bare `empty_brain` token
95
- * is interpolated by renderProtocolBlock; the prose itself stays plain English.
96
- */
97
- export const PI_PRE_RESET_HINTS = `Resetting clears the human's chat view too. Don't put a long explanation right before a reset and assume they'll still be able to read it. Save the handoff in notes; give the explanation after the reset.
98
- Unless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.`;
99
-
100
89
  /** Logical tool names are supplied by the composing host, not discovered here. */
101
90
  export type BootToolNames = Readonly<{
102
91
  notes: string;
@@ -106,14 +95,15 @@ export type BootToolNames = Readonly<{
106
95
  wipe: string;
107
96
  /**
108
97
  * Replaces the whole voluntary-wipe sentence (PROTOCOL_WIPE_SENTENCE) when the host has
109
- * no model-facing reset tool. Absent means Pi's default sentence, byte for byte.
98
+ * no model-facing reset tool. Absent means the shared tool-driven-reset sentence, byte for byte.
110
99
  */
111
100
  wipeSentence?: string;
112
101
  /** A host without an authoritative history source replaces the entire history advice. */
113
102
  historySentence?: string;
114
103
  /**
115
- * Extra protocol prose appended before the closing tag. Pi passes PI_PRE_RESET_HINTS; hosts
116
- * whose reset leaves the human's view intact leave it absent.
104
+ * Extra protocol prose appended before the closing tag. A host whose reset also drops the
105
+ * human's visible transcript supplies its own hints here; a host whose reset leaves that
106
+ * view intact leaves it absent, because the claim would be false there.
117
107
  */
118
108
  preResetHints?: string;
119
109
  }>;
@@ -1,17 +1,17 @@
1
1
  import { DEFAULT_REMINDER_MARGIN_TOKENS, WARNING_RUNWAY_TOKENS } from "./constants.js";
2
2
  import { positiveInteger } from "./parse.js";
3
- import { NOTESOUP_SETTINGS_KEY, type NotesoupSettings } from "../settings.js";
3
+ import { NOTESOUP_SETTINGS_KEY } from "../settings.js";
4
4
 
5
5
  export type ResolvedThresholds = { reminder: number; reserve: number; warning: number };
6
6
 
7
7
  /**
8
- * Pure derivation of the thresholds from Pi's reserve: the reminder fires at reserve
8
+ * Pure derivation of the thresholds from the host's reserve: the reminder fires at reserve
9
9
  * plus the notesoup margin, the warning steer at reserve plus WARNING_RUNWAY_TOKENS.
10
10
  * An invalid margin degrades to the default and reports one warning. Automatic
11
11
  * threshold/overflow handling is represented by reset lifecycle boundary drafts;
12
12
  * no compaction summary is generated.
13
13
  */
14
- export function deriveThresholds(reserveTokens: number, margins: NotesoupSettings): { thresholds: ResolvedThresholds; warnings: string[] } {
14
+ export function deriveThresholds(reserveTokens: number, margins: Record<string, unknown>): { thresholds: ResolvedThresholds; warnings: string[] } {
15
15
  const warnings: string[] = [];
16
16
  const reminderKey = `${NOTESOUP_SETTINGS_KEY}.reminderMarginTokens`;
17
17
  let reminderMargin: number;
@@ -1,5 +1,3 @@
1
- import { PI_PRE_RESET_HINTS } from "../boot/text.js";
2
-
3
1
  export const GUIDANCE_OPEN_TAG = "<notesoup:budget_notice>";
4
2
  export const GUIDANCE_CLOSE_TAG = "</notesoup:budget_notice>";
5
3
 
@@ -39,23 +37,8 @@ export const WARNING_BODY =
39
37
 
40
38
  export const WARNING_CALL = "When the notes are ready, call `empty_brain` to reset now instead of being cut off mid-task.";
41
39
 
42
- /**
43
- * With a prompt attached the close-out is an order rather than a nudge: the human already
44
- * said when to reset, and a task line for the next window just preceded it.
45
- */
46
- export const WARNING_CALL_PROMPTED = "Organize the notes first, then call `empty_brain` right away — do not wait to be cut off.";
47
-
48
- /**
49
- * The human typed `/empty <prompt>`: the raw command line leads the close-out so the
50
- * closing model sees what the next window was asked to do, verbatim. The tag names it as the
51
- * next window's prompt, so no prose has to explain that.
52
- */
53
- function promptBlock(commandLine: string): string {
54
- return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
55
- }
56
-
57
- export function warningPrompt(commandLine?: string): string {
58
- return `${WARNING_BODY}\n${commandLine ? `${promptBlock(commandLine)}\n${WARNING_CALL_PROMPTED}` : WARNING_CALL}`;
40
+ export function warningPrompt(): string {
41
+ return `${WARNING_BODY}\n${WARNING_CALL}`;
59
42
  }
60
43
 
61
44
  /**
@@ -64,17 +47,6 @@ export function warningPrompt(commandLine?: string): string {
64
47
  */
65
48
  export const COUNTDOWN_LINE = "Brain emptied in 3… 2…";
66
49
 
67
- /** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
68
- export const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
69
-
70
- /** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads warningPrompt() directly). */
71
- export function warningContent(commandLine?: string): string {
72
- return `${GUIDANCE_OPEN_TAG}\n${warningPrompt(commandLine)}\n${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
73
- }
74
-
75
- /** Claude's variant: the mod resets after the turn, so the model only has to stop. */
76
- export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.\n${COUNTDOWN_LINE}`;
77
-
78
50
  /**
79
51
  * Codex-equivalent low-budget reminder. The measured remaining count is frozen into
80
52
  * the text at the crossing that fires it, so each persisted copy is a snapshot true
@@ -1,4 +1,7 @@
1
- import { NOTESOUP_DREAMER_KEY, NOTESOUP_SETTINGS_KEY, type NotesoupSettings } from "../settings.js";
1
+ import { NOTESOUP_SETTINGS_KEY } from "../settings.js";
2
+
3
+ /** Nested under the "notesoup" settings key; the dream CLI is the only reader. */
4
+ const NOTESOUP_DREAMER_KEY = "dreamer";
2
5
 
3
6
  export type DreamerSetting = { pattern?: string; warnings: string[] };
4
7
 
@@ -6,8 +9,8 @@ export type DreamerSetting = { pattern?: string; warnings: string[] };
6
9
  * `notesoup.dreamer` is a non-empty model pattern. Anything else present is ignored
7
10
  * with one warning; absent means no configured pattern, so the automatic model applies.
8
11
  */
9
- export function deriveDreamer(settings: NotesoupSettings): DreamerSetting {
10
- const raw = settings.dreamer;
12
+ export function deriveDreamer(settings: Record<string, unknown>): DreamerSetting {
13
+ const raw = settings[NOTESOUP_DREAMER_KEY];
11
14
  if (raw === undefined) return { warnings: [] };
12
15
  if (typeof raw !== "string" || raw.trim().length === 0) {
13
16
  return { warnings: [`notesoup: ${NOTESOUP_SETTINGS_KEY}.${NOTESOUP_DREAMER_KEY} must be a non-empty string; ignoring it.`] };
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 loaded through the Pi manifest; dsh uses `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;