notesoup 0.61.0 → 0.63.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 (210) hide show
  1. package/.agents/plugins/marketplace.json +15 -0
  2. package/README.md +14 -11
  3. package/dist/plugins/antigravity/src/cli.d.ts +1 -0
  4. package/dist/plugins/antigravity/src/cli.js +23 -0
  5. package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
  6. package/dist/plugins/antigravity/src/hooks.js +53 -0
  7. package/dist/plugins/antigravity/src/identity.d.ts +26 -0
  8. package/dist/plugins/antigravity/src/identity.js +129 -0
  9. package/dist/plugins/claude/src/helper.js +24 -5
  10. package/dist/plugins/claude/src/text.d.ts +7 -0
  11. package/dist/plugins/claude/src/text.js +12 -1
  12. package/dist/plugins/codex/src/hooks.js +1 -0
  13. package/dist/plugins/codex/src/identity.d.ts +6 -1
  14. package/dist/plugins/codex/src/identity.js +13 -1
  15. package/dist/plugins/codex/src/mcp.d.ts +35 -7
  16. package/dist/plugins/codex/src/mcp.js +26 -88
  17. package/dist/plugins/codex/src/text.js +3 -3
  18. package/dist/plugins/dsh/tools.js +8 -4
  19. package/dist/plugins/mcp/operations.d.ts +15 -0
  20. package/dist/plugins/mcp/operations.js +43 -0
  21. package/dist/plugins/mcp/server.d.ts +14 -0
  22. package/dist/plugins/mcp/server.js +13 -0
  23. package/dist/plugins/pi/budget.d.ts +4 -1
  24. package/dist/plugins/pi/budget.js +35 -8
  25. package/dist/plugins/pi/entries.d.ts +2 -0
  26. package/dist/plugins/pi/entries.js +2 -0
  27. package/dist/plugins/pi/history-tools.js +2 -1
  28. package/dist/plugins/pi/history.js +18 -1
  29. package/dist/plugins/pi/notes/tools.js +7 -3
  30. package/dist/plugins/pi/render.d.ts +7 -1
  31. package/dist/plugins/pi/render.js +2 -2
  32. package/dist/plugins/pi/reset/artifacts.d.ts +1 -1
  33. package/dist/plugins/pi/reset/artifacts.js +4 -4
  34. package/dist/plugins/pi/reset/lifecycle.d.ts +9 -2
  35. package/dist/plugins/pi/reset/lifecycle.js +109 -31
  36. package/dist/plugins/pi/runtime.js +104 -63
  37. package/dist/plugins/pi/tool-result.js +7 -7
  38. package/dist/plugins/pi/window.d.ts +25 -3
  39. package/dist/plugins/pi/window.js +219 -9
  40. package/dist/src/boot/render.js +18 -15
  41. package/dist/src/boot/text.d.ts +3 -1
  42. package/dist/src/boot/text.js +22 -20
  43. package/dist/src/budget/text.d.ts +7 -3
  44. package/dist/src/budget/text.js +24 -15
  45. package/dist/src/history/claude.d.ts +2 -0
  46. package/dist/src/history/claude.js +46 -0
  47. package/dist/src/history/codex-transcript.js +7 -5
  48. package/dist/src/history/codex.js +3 -0
  49. package/dist/src/history/corpus.d.ts +28 -1
  50. package/dist/src/history/corpus.js +40 -0
  51. package/dist/src/history/history.d.ts +37 -46
  52. package/dist/src/history/history.js +21 -40
  53. package/dist/src/history/local.js +67 -32
  54. package/dist/src/history/pi.d.ts +2 -1
  55. package/dist/src/history/pi.js +122 -48
  56. package/dist/src/history/prefilter.js +76 -19
  57. package/dist/src/history/query.d.ts +28 -49
  58. package/dist/src/history/query.js +83 -68
  59. package/dist/src/history/summary-cache.d.ts +8 -1
  60. package/dist/src/history/summary-cache.js +138 -12
  61. package/dist/src/index.d.ts +2 -2
  62. package/dist/src/index.js +1 -1
  63. package/dist/src/notes/errors.d.ts +1 -1
  64. package/dist/src/notes/frontmatter.d.ts +0 -2
  65. package/dist/src/notes/frontmatter.js +0 -2
  66. package/dist/src/notes/index.d.ts +1 -1
  67. package/dist/src/notes/index.js +1 -1
  68. package/dist/src/notes/policy.d.ts +15 -1
  69. package/dist/src/notes/policy.js +46 -5
  70. package/dist/src/notes/store.d.ts +12 -0
  71. package/dist/src/notes/store.js +16 -20
  72. package/dist/src/text-match.d.ts +10 -1
  73. package/dist/src/text-match.js +42 -3
  74. package/dist/src/tools/dream.d.ts +22 -93
  75. package/dist/src/tools/dream.js +30 -27
  76. package/dist/src/tools/history.d.ts +33 -26
  77. package/dist/src/tools/history.js +257 -163
  78. package/dist/src/tools/notes.d.ts +51 -163
  79. package/dist/src/tools/notes.js +146 -100
  80. package/dist/src/tools/output.d.ts +2 -1
  81. package/dist/src/tools/output.js +2 -1
  82. package/dist/src/tools/result.d.ts +4 -7
  83. package/dist/src/tools/result.js +8 -9
  84. package/dist/src/tools/schema.d.ts +4 -1
  85. package/dist/src/tools/schema.js +25 -1
  86. package/dist/test/agent-loop.test.js +394 -56
  87. package/dist/test/antigravity-live.test.d.ts +1 -0
  88. package/dist/test/antigravity-live.test.js +142 -0
  89. package/dist/test/antigravity-plugin.test.d.ts +1 -0
  90. package/dist/test/antigravity-plugin.test.js +101 -0
  91. package/dist/test/boot.integration.test.js +156 -15
  92. package/dist/test/budget-settings.integration.test.js +4 -4
  93. package/dist/test/claude-history.test.js +14 -13
  94. package/dist/test/claude-mod.test.js +199 -16
  95. package/dist/test/claude-validation.test.js +69 -2
  96. package/dist/test/codex-history.test.js +15 -3
  97. package/dist/test/codex-plugin.test.js +76 -38
  98. package/dist/test/dependencies.test.js +7 -3
  99. package/dist/test/dream-skill.test.js +3 -3
  100. package/dist/test/dream-tools.test.js +101 -56
  101. package/dist/test/dsh.test.js +34 -19
  102. package/dist/test/helpers/dependency-graph.js +2 -2
  103. package/dist/test/helpers/extension.d.ts +68 -3
  104. package/dist/test/helpers/extension.js +74 -5
  105. package/dist/test/history-corpus.test.js +79 -77
  106. package/dist/test/history-summary-cache.test.js +97 -9
  107. package/dist/test/history.integration.test.js +234 -168
  108. package/dist/test/host-neutral.test.js +69 -19
  109. package/dist/test/marker.test.js +1 -1
  110. package/dist/test/model-facing-text.test.js +13 -3
  111. package/dist/test/note-policy.test.js +96 -77
  112. package/dist/test/notes.integration.test.js +212 -94
  113. package/dist/test/notes.test.js +184 -113
  114. package/dist/test/pi-render.test.js +20 -12
  115. package/dist/test/project-namespace.test.js +3 -2
  116. package/dist/test/reset-lifecycle.test.js +12 -2
  117. package/docs/antigravity.md +44 -0
  118. package/docs/architecture.md +6 -4
  119. package/docs/claude-code-mod.md +7 -7
  120. package/docs/codex.md +36 -38
  121. package/docs/dsh.md +3 -3
  122. package/docs/history-sessions.md +28 -50
  123. package/docs/notes-library.md +4 -4
  124. package/docs/reset-lifecycle.md +1 -1
  125. package/docs/skills.md +3 -3
  126. package/docs/tool-results.md +47 -28
  127. package/package.json +3 -2
  128. package/playbook.md +1 -1
  129. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  130. package/plugins/antigravity/hooks.json +7 -0
  131. package/plugins/antigravity/mcp_config.json +8 -0
  132. package/plugins/antigravity/plugin.json +6 -0
  133. package/plugins/antigravity/src/cli.ts +22 -0
  134. package/plugins/antigravity/src/hooks.ts +51 -0
  135. package/plugins/antigravity/src/identity.ts +127 -0
  136. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  137. package/plugins/claude/dist/claude/helper.js +1108 -539
  138. package/plugins/claude/hooks/register.ts +202 -62
  139. package/plugins/claude/playbook.md +1 -1
  140. package/plugins/claude/skills/dream/SKILL.md +1 -1
  141. package/plugins/claude/skills/notesoup-guide/SKILL.md +92 -0
  142. package/plugins/claude/src/helper.ts +24 -5
  143. package/plugins/claude/src/text.ts +14 -1
  144. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  145. package/plugins/codex/.mcp.json +11 -0
  146. package/plugins/codex/README.md +5 -21
  147. package/plugins/codex/dist/codex/notesoup.js +18480 -17946
  148. package/plugins/codex/src/hooks.ts +1 -0
  149. package/plugins/codex/src/identity.ts +14 -1
  150. package/plugins/codex/src/mcp.ts +28 -98
  151. package/plugins/codex/src/text.ts +3 -3
  152. package/plugins/dsh/tools.ts +8 -4
  153. package/plugins/mcp/operations.ts +50 -0
  154. package/plugins/mcp/server.ts +23 -0
  155. package/plugins/paseo/README.md +5 -10
  156. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  157. package/plugins/paseo/client/markdown.tsx +50 -38
  158. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  159. package/plugins/paseo/client/paper-card.tsx +6 -5
  160. package/plugins/paseo/client/paper-palette.ts +2 -9
  161. package/plugins/paseo/client/sticky-card.tsx +2 -2
  162. package/plugins/paseo/client/tool-result.ts +7 -14
  163. package/plugins/paseo/package-lock.json +3406 -0
  164. package/plugins/paseo/package.json +1 -0
  165. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  166. package/plugins/pi/budget.ts +31 -8
  167. package/plugins/pi/entries.ts +2 -0
  168. package/plugins/pi/history-tools.ts +2 -1
  169. package/plugins/pi/history.ts +30 -1
  170. package/plugins/pi/notes/tools.ts +7 -3
  171. package/plugins/pi/render.ts +6 -6
  172. package/plugins/pi/reset/artifacts.ts +4 -3
  173. package/plugins/pi/reset/lifecycle.ts +125 -32
  174. package/plugins/pi/runtime.ts +98 -62
  175. package/plugins/pi/tool-result.ts +8 -8
  176. package/plugins/pi/window.ts +210 -10
  177. package/skills/dream/SKILL.md +1 -1
  178. package/skills/notesoup-guide/SKILL.md +92 -0
  179. package/src/boot/render.ts +18 -15
  180. package/src/boot/text.ts +23 -19
  181. package/src/budget/text.ts +27 -15
  182. package/src/history/claude.ts +41 -0
  183. package/src/history/codex-transcript.ts +6 -4
  184. package/src/history/codex.ts +2 -0
  185. package/src/history/corpus.ts +51 -2
  186. package/src/history/history.ts +35 -44
  187. package/src/history/local.ts +67 -27
  188. package/src/history/pi.ts +113 -35
  189. package/src/history/prefilter.ts +73 -15
  190. package/src/history/query.ts +93 -73
  191. package/src/history/summary-cache.ts +142 -17
  192. package/src/index.ts +2 -2
  193. package/src/notes/errors.ts +1 -1
  194. package/src/notes/frontmatter.ts +0 -3
  195. package/src/notes/index.ts +1 -1
  196. package/src/notes/policy.ts +44 -5
  197. package/src/notes/store.ts +17 -20
  198. package/src/text-match.ts +46 -4
  199. package/src/tools/dream.ts +29 -31
  200. package/src/tools/history.ts +249 -142
  201. package/src/tools/notes.ts +145 -113
  202. package/src/tools/output.ts +2 -1
  203. package/src/tools/result.ts +12 -11
  204. package/src/tools/schema.ts +24 -1
  205. package/plugins/claude/skills/memory/SKILL.md +0 -69
  206. package/plugins/codex/mcp.json +0 -10
  207. package/plugins/codex/plugin.json +0 -6
  208. package/plugins/paseo/client/markdown-core.tsx +0 -189
  209. package/plugins/paseo/client/typography.ts +0 -24
  210. package/skills/memory/SKILL.md +0 -69
@@ -13,13 +13,19 @@ type HistorySource = { sessionId: string; transcriptPath: string; headUuid?: str
13
13
  type Engine = Pick<EngineInterface, "process" | "session" | "ui" | "prompt" | "env" | "settings" | "command">
14
14
  /** The measured context, as much of it as the engine reported. */
15
15
  type ContextUsage = { tokens?: number; window?: number; percent?: number }
16
- /** Shared reset prose, fetched once per session so Pi and Claude cannot drift apart. */
17
- type SharedTexts = { warning?: string; historyUnavailableSentence?: string }
16
+ /** Shared reset prose and version, fetched once per session so Pi and Claude cannot drift apart. */
17
+ type SharedTexts = { version?: string; warning?: string; commandBare?: string; commandPrompted?: string; historyUnavailableSentence?: string }
18
+ type ToolsHealth = { started: boolean; notes: number; history: number; wipe: boolean; remaining: boolean; degraded?: string }
18
19
  type ClaudeLimits = {
19
20
  source: string; autoCompact: boolean; unit: "tokens" | "percent"
20
21
  native: number; reset: number; warn: number; resetMargin: number; warningRunway: number
21
22
  }
22
- type ResetRequest = { tool?: { lastWord?: string }; resume: boolean }
23
+ type ResetRequest = {
24
+ tool?: { lastWord?: string }
25
+ command?: { name: string; args?: string; warned: boolean }
26
+ resume: boolean
27
+ betweenTurns: boolean
28
+ }
23
29
  /** Request: until consumed/cancelled. Cutoff: one turn, even after auto consumes the request.
24
30
  * Commit lives separately in ResetState: one native command attempt, proved by kept rows. */
25
31
  class ResetFlow {
@@ -29,21 +35,27 @@ class ResetFlow {
29
35
  pendingInputTurnId?: string
30
36
  running = false
31
37
 
32
- requestReset(tool?: { lastWord?: string; terminate: boolean }): boolean {
38
+ requestReset(tool?: { lastWord?: string; terminate: boolean }, command?: { name: string; args?: string }): boolean {
33
39
  const first = tool ? this.request?.tool === undefined : this.request === undefined
34
- const request = this.request ??= { resume: true }
40
+ const request = this.request ??= { resume: true, betweenTurns: false }
35
41
  if (tool) {
36
42
  if (first) {
37
43
  request.tool = { lastWord: tool.lastWord }
38
44
  request.resume &&= !tool.terminate
45
+ request.betweenTurns = false
39
46
  }
40
47
  this.cutoffTurnId = this.turnId
41
- } else request.resume = false
48
+ } else {
49
+ request.resume = false
50
+ request.betweenTurns = false
51
+ if (command && !request.command) request.command = { name: command.name, args: command.args, warned: false }
52
+ }
42
53
  return first
43
54
  }
44
- requestAutomatic() {
45
- this.request ??= { resume: true }
46
- this.cutoffTurnId = this.turnId
55
+ /** Automatic budget reset: mid-turn cutoff resumes unfinished work; post-answer settlement waits for the human. */
56
+ requestAutomatic(resume: boolean) {
57
+ if (!this.request) this.request = { resume, betweenTurns: !resume }
58
+ if (resume) this.cutoffTurnId = this.turnId
47
59
  }
48
60
  input(turnId?: string) {
49
61
  if (turnId !== undefined) this.pendingInputTurnId = turnId
@@ -89,7 +101,7 @@ class ResetFlow {
89
101
  type ResetState = {
90
102
  identity?: Identity; history?: HistorySource; historyWindowHead?: string; generation: number; window: number; disabled: boolean; flow: ResetFlow
91
103
  headless: boolean; usageFailureLogged: boolean; commit?: { instructions: string; boot?: string; boundary: boolean; resolve: (kept: boolean) => void }; retainedBoot?: string
92
- continuation?: { window: number; text: string }
104
+ continuation?: { window: number; origin: "normal" | "forced"; betweenTurns: boolean; text: string }
93
105
  compactDisabled: boolean; limitsFailureLogged: boolean; limitsAttempts: number; limitsKey?: string
94
106
  capTokens?: number; limits?: ClaudeLimits; warnedWindow?: number; warningPending?: number; texts?: SharedTexts; settingsFailureLogged: boolean
95
107
  }
@@ -105,22 +117,23 @@ const RESET_INSTRUCTIONS = "notesoup: reset to a fresh notes-only context window
105
117
  const BOOT_TOOLS = {
106
118
  notes: `${PREFIX}notes_*`, notesList: `${PREFIX}notes_list`,
107
119
  history: "history_* (unavailable: no main transcript_path)",
108
- remaining: "get_context_remaining (unavailable in Claude)", wipe: `${PREFIX}empty_brain`,
120
+ remaining: `${PREFIX}get_context_remaining`, wipe: `${PREFIX}empty_brain`,
109
121
  }
110
122
 
111
- /** Bind the shared protocol to the registered Claude tools. */
112
- async function buildBoot($: Engine, identity: Identity, window: number, texts?: SharedTexts, history?: HistorySource) {
113
- const available = history?.sessionId === identity.sessionId
114
- const tools = { ...BOOT_TOOLS, ...(available ? { history: `${PREFIX}history_*` } : { historySentence: texts?.historyUnavailableSentence }) }
123
+ /** Bind the shared protocol to the tools actually registered in this Claude session. */
124
+ async function buildBoot($: Engine, identity: Identity, window: number, texts?: SharedTexts, history?: HistorySource, health?: ToolsHealth) {
125
+ const historyAvailable = history?.sessionId === identity.sessionId && (!health?.started || health.history > 0)
126
+ const remaining = health?.started && !health.remaining ? "get_context_remaining (unavailable)" : BOOT_TOOLS.remaining
127
+ const tools = { ...BOOT_TOOLS, remaining, ...(historyAvailable ? { history: `${PREFIX}history_*` } : { historySentence: texts?.historyUnavailableSentence }) }
115
128
  return run($, { op: "boot", identity, window, tools })
116
129
  }
117
130
  /** The notes-only reset shape, shared by our own reset and Claude's native auto compaction. */
118
131
  type ResetMessages = { boot: string; messages: Array<{ role: "user"; text: string; toolUses: [] }> }
119
- async function resetMessages($: Engine, state: ResetState, identity: Identity): Promise<ResetMessages | { skip: string }> {
132
+ async function resetMessages($: Engine, state: ResetState, identity: Identity, health?: ToolsHealth): Promise<ResetMessages | { skip: string }> {
120
133
  const generation = state.generation
121
134
  const texts = await loadTexts($, state)
122
135
  if (texts === undefined) return { skip: "reset text didn't load" }
123
- const boot = await buildBoot($, identity, state.window + 1, texts, state.history)
136
+ const boot = await buildBoot($, identity, state.window + 1, texts, state.history, health)
124
137
  if (generation !== state.generation) return { skip: "session changed while building the notes boot" }
125
138
  if (!boot.ok) return { skip: `notes didn't load: ${boot.error}` }
126
139
  const continuation = await continuationFor($, state)
@@ -141,10 +154,17 @@ function sharedTextsOf(value: unknown): SharedTexts | undefined {
141
154
  if (typeof value !== "object" || value === null) return undefined
142
155
  const row = value as Record<string, unknown>
143
156
  const texts: SharedTexts = {}
157
+ if (typeof row.version === "string" && row.version.length > 0) texts.version = row.version
144
158
  if (typeof row.warning === "string" && row.warning.length > 0) texts.warning = row.warning
159
+ if (typeof row.commandBare === "string" && row.commandBare.length > 0) texts.commandBare = row.commandBare
160
+ if (typeof row.commandPrompted === "string" && row.commandPrompted.length > 0) texts.commandPrompted = row.commandPrompted
145
161
  if (typeof row.historyUnavailableSentence === "string" && row.historyUnavailableSentence.length > 0) texts.historyUnavailableSentence = row.historyUnavailableSentence
146
162
  return Object.keys(texts).length > 0 ? texts : undefined
147
163
  }
164
+ function commandCloseoutText(texts: SharedTexts | undefined, command?: { name: string; args?: string }): string | undefined {
165
+ if (command?.args) return texts?.commandPrompted ? `${texts.commandPrompted}\n/${command.name} ${command.args}` : undefined
166
+ return texts?.commandBare ?? texts?.warning
167
+ }
148
168
  /** The helper's resolved points, accepted only when every number is a real number. */
149
169
  function limitsShape(value: unknown): ClaudeLimits | undefined {
150
170
  if (typeof value !== "object" || value === null) return undefined
@@ -244,9 +264,18 @@ function measuredValue(limits: ClaudeLimits, usage: ContextUsage): number | unde
244
264
  if (usage.tokens !== undefined) return usage.tokens
245
265
  return usage.percent !== undefined && usage.window !== undefined && usage.window > 0 ? (usage.percent / 100) * usage.window : undefined
246
266
  }
267
+ /** Remaining tokens before the hard-reset line (reaches zero at reset); null when unknown. */
268
+ function remainingTokensFor(limits: ClaudeLimits | undefined, usage: ContextUsage | undefined): number | null {
269
+ if (!limits || !usage) return null
270
+ const measured = measuredValue(limits, usage)
271
+ if (measured === undefined) return null
272
+ if (limits.unit === "tokens") return Math.max(0, Math.floor(limits.reset - measured))
273
+ if (usage.window !== undefined && usage.window > 0) return Math.max(0, Math.floor(((limits.reset - measured) / 100) * usage.window))
274
+ return null
275
+ }
247
276
  /** The warning and hard clear share one policy; only a safe main-loop boundary acts on it. */
248
- async function hardResetDue($: Engine, state: ResetState): Promise<boolean> {
249
- if (state.disabled || state.compactDisabled || !state.identity || state.commit) return false
277
+ async function hardResetDue($: Engine, state: ResetState, health: ToolsHealth): Promise<boolean> {
278
+ if (state.disabled || state.compactDisabled || health.degraded || !state.identity || state.commit) return false
250
279
  const generation = state.generation, window = state.window, cap = state.capTokens
251
280
  const usage = await contextUsage($, state)
252
281
  if (generation !== state.generation || usage === undefined) return false
@@ -256,8 +285,8 @@ async function hardResetDue($: Engine, state: ResetState): Promise<boolean> {
256
285
  return measured !== undefined && measured >= limits.reset
257
286
  }
258
287
 
259
- /** Runtime-only capacity; never writes Claude's settings or its process environment. */
260
- async function capCommand($: Engine, state: ResetState, args: string): Promise<{ text: string }> {
288
+ /** Runtime-only capacity and health readout; never writes Claude's settings or process environment. */
289
+ async function capCommand($: Engine, state: ResetState, health: ToolsHealth, args: string): Promise<{ text: string }> {
261
290
  if (!await refreshIdentity($, state)) return { text: "🥣 Different brain now · try /notesoup again" }
262
291
  const parts = args.trim().toLowerCase().split(/\s+/)
263
292
  if (parts[0] !== "" && (parts[0] !== "cap" || parts.length > 2)) return { text: "Usage: /notesoup cap [100k|1m|tokens|off]" }
@@ -272,7 +301,24 @@ async function capCommand($: Engine, state: ResetState, args: string): Promise<{
272
301
  if (cap !== null && (typeof cap !== "number" || !Number.isSafeInteger(cap) || cap <= 0)) return { text: "🥣 Invalid cap from helper" }
273
302
  state.capTokens = cap ?? undefined
274
303
  }
275
- return { text: `🥣 notesoup · cap ${state.capTokens === undefined ? "off" : state.capTokens.toLocaleString("en-US")} · current session only` }
304
+ const texts = await loadTexts($, state)
305
+ const label = texts?.version ? `notesoup v${texts.version}` : "notesoup"
306
+ const capText = `cap ${state.capTokens === undefined ? "off" : state.capTokens.toLocaleString("en-US")}`
307
+ const fields = [label, capText]
308
+ if (health.degraded) {
309
+ fields.push(`degraded (${health.degraded})`)
310
+ } else {
311
+ const usage = await contextUsage($, state)
312
+ const limits = usage ? await limitsOf($, state, usage) : undefined
313
+ const remaining = remainingTokensFor(limits, usage)
314
+ if (remaining !== null) fields.push(`${remaining.toLocaleString("en-US")} tokens left`)
315
+ if (health.started) {
316
+ const total = (health.wipe ? 1 : 0) + (health.remaining ? 1 : 0) + health.notes + health.history
317
+ fields.push(`tools ${total}/9`)
318
+ }
319
+ fields.push(state.history?.sessionId === state.identity?.sessionId ? "history ready" : "history unavailable")
320
+ }
321
+ return { text: `🥣 ${fields.join(" · ")} · current session only` }
276
322
  }
277
323
 
278
324
  /** The shared reset prose: one helper round trip per session, retried until it lands. */
@@ -288,19 +334,25 @@ async function loadTexts($: Engine, state: ResetState): Promise<SharedTexts | un
288
334
  }
289
335
  /** One draw per reset artifact, reused on retry; only a real tool request is voluntary. */
290
336
  async function continuationFor($: Engine, state: ResetState): Promise<string | undefined> {
291
- if (state.continuation?.window === state.window) return state.continuation.text
337
+ const origin: "normal" | "forced" = state.flow.request?.tool ? "normal" : "forced"
338
+ const betweenTurns = origin === "forced" && state.flow.request?.betweenTurns === true
339
+ const cached = state.continuation
340
+ if (cached && cached.window === state.window && cached.origin === origin && cached.betweenTurns === betweenTurns) return cached.text
292
341
  const generation = state.generation
293
- const response = await run($, { op: "continuation", origin: state.flow.request?.tool ? "normal" : "forced" })
342
+ const response = await run($, { op: "continuation", origin, ...(betweenTurns ? { betweenTurns: true } : {}) })
294
343
  if (generation !== state.generation) return undefined
295
344
  const result = response.ok ? response.result : undefined
296
345
  const text = typeof result === "object" && result !== null ? (result as { text?: unknown }).text : undefined
297
346
  if (typeof text !== "string" || text.length === 0) return undefined
298
- state.continuation = { window: state.window, text }
347
+ state.continuation = { window: state.window, origin, betweenTurns, text }
299
348
  return text
300
349
  }
301
350
  function log($: Engine, text: string) {
302
351
  try { $.ui.log(`🥣 ${text}`) } catch { /* UI must not break a turn or reset. */ }
303
352
  }
353
+ async function toast($: Engine, text: string) {
354
+ try { await $.ui.toast(text) } catch { /* Notification failure must not break a turn or startup. */ }
355
+ }
304
356
  /** A rejected call's reason, one line, bounded: the caller reads it, not a stack. */
305
357
  function describeFailure(error: unknown): string {
306
358
  const text = error instanceof Error ? `${error.name}: ${error.message}` : String(error)
@@ -401,6 +453,7 @@ export function register(on: On) {
401
453
  const resetSignal: ResetSignal = {}
402
454
  const state: ResetState = { generation: 0, window: 0, disabled: false, flow: new ResetFlow(), headless: false, usageFailureLogged: false, compactDisabled: false, limitsFailureLogged: false, limitsAttempts: 0, settingsFailureLogged: false }
403
455
  const registered = new Set<string>()
456
+ const health: ToolsHealth = { started: false, notes: 0, history: 0, wipe: false, remaining: false }
404
457
  let keepMemory = false
405
458
  // Classic SessionStart precedes typed session.start and startup appends. Keep this binding
406
459
  // across forgetSession; re-key it only against the actual session id, never a guessed path.
@@ -437,9 +490,13 @@ export function register(on: On) {
437
490
  })
438
491
  on("session.start", async ($, e, next) => {
439
492
  forgetSession(state)
493
+ registered.clear()
494
+ health.started = false
495
+ health.notes = health.history = 0
496
+ health.wipe = health.remaining = false
497
+ health.degraded = undefined
440
498
  state.disabled = envFlag(await $.env.get("NOTESOUP_DISABLED").catch(() => undefined))
441
499
  if (state.disabled) {
442
- registered.clear()
443
500
  log($, NOTESOUP_DISABLED)
444
501
  return next(e)
445
502
  }
@@ -449,24 +506,74 @@ export function register(on: On) {
449
506
  // Compaction is the capability explicit resets and budget warnings depend on.
450
507
  state.compactDisabled = envFlag(await $.env.get("DISABLE_COMPACT").catch(() => undefined))
451
508
  if (state.compactDisabled) log($, COMPACT_DISABLED)
452
- registered.clear()
453
509
  await loadTexts($, state)
454
- armReset($, state, resetSignal)
455
- await $.command.register({ name: "notesoup", description: "Show or cap the notesoup context capacity: cap [100k|1m|tokens|off]", immediate: true })
456
- await $.command.register({ name: "empty", description: "Reset context to a fresh notes-only window", immediate: true })
457
- await $.command.register({ name: "fresh-window", description: "Reset context to a fresh notes-only window", immediate: true })
458
- const wipe = await $.tool.register({
459
- name: "empty_brain",
460
- description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
461
- inputSchema: { type: "object", properties: { last_word: { type: "string", description: "A tiny sticky note, at most 300 characters. After the wipe it is slapped on your forehead; longer notes are refused." }, terminate: { type: "boolean", description: "Stop after the wipe. Default: false.", default: false } }, additionalProperties: false },
462
- isDeferred: false,
463
- } satisfies ToolSpec)
464
- registered.add(wipe.tool)
510
+ health.started = true
511
+ // Register tools before slash commands and isolate every failure: a broken command must
512
+ // never take down tools, and missing core tools must disarm automatic resets instead of wiping blind.
513
+ const toolErrors: string[] = []
514
+ try {
515
+ const wipe = await $.tool.register({
516
+ name: "empty_brain",
517
+ description: "Clear your in-context memory and start a fresh context window. Your session, notes, and history survive. Pass `last_word` to stick a tiny note on your forehead for after the wipe.",
518
+ inputSchema: { type: "object", properties: { last_word: { type: "string", description: "A tiny sticky note (at most 300 characters), slapped on your forehead after the wipe." }, terminate: { type: "boolean", description: "Stop after the wipe.", default: false } }, additionalProperties: false },
519
+ isDeferred: false,
520
+ } satisfies ToolSpec)
521
+ registered.add(wipe.tool)
522
+ health.wipe = true
523
+ } catch (error) {
524
+ toolErrors.push(`empty_brain: ${describeFailure(error)}`)
525
+ }
526
+ try {
527
+ const remaining = await $.tool.register({
528
+ name: "get_context_remaining",
529
+ description: "Check how much room your brain has left before it gets forcibly emptied. Returns null when unknown.",
530
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
531
+ isDeferred: false,
532
+ } satisfies ToolSpec)
533
+ registered.add(remaining.tool)
534
+ health.remaining = true
535
+ } catch (error) {
536
+ log($, `Tool get_context_remaining failed to register · ${describeFailure(error)}`)
537
+ }
465
538
  const schemas = await run($, { op: "schemas" })
466
- if (!schemas.ok || !Array.isArray(schemas.result)) return next(e)
467
- for (const row of schemas.result as SchemaRow[]) {
468
- const full = await $.tool.register({ name: row.name, description: row.description, inputSchema: row.inputSchema, isDeferred: false } satisfies ToolSpec)
469
- registered.add(full.tool)
539
+ if (!schemas.ok || !Array.isArray(schemas.result)) {
540
+ toolErrors.push(schemas.ok ? "helper returned invalid tool schemas" : schemas.error)
541
+ } else {
542
+ for (const row of schemas.result as SchemaRow[]) {
543
+ try {
544
+ const full = await $.tool.register({ name: row.name, description: row.description, inputSchema: row.inputSchema, isDeferred: false } satisfies ToolSpec)
545
+ registered.add(full.tool)
546
+ if (row.name.startsWith("notes_")) health.notes++
547
+ else if (row.name.startsWith("history_")) health.history++
548
+ } catch (error) {
549
+ toolErrors.push(`${row.name}: ${describeFailure(error)}`)
550
+ }
551
+ }
552
+ }
553
+ try {
554
+ await $.command.register({ name: "notesoup", description: "Show notesoup status or cap capacity: cap [100k|1m|tokens|off]", immediate: true })
555
+ } catch (error) {
556
+ log($, `Command /notesoup failed to register · ${describeFailure(error)}`)
557
+ await toast($, "🥣 Notesoup /notesoup command failed to load")
558
+ }
559
+ try {
560
+ await $.command.register({ name: "empty", description: "Reset context to a fresh notes-only window", argumentHint: "[context for notes]", immediate: true })
561
+ } catch (error) {
562
+ log($, `Command /empty failed to register · ${describeFailure(error)}`)
563
+ await toast($, "🥣 Notesoup /empty command failed to load")
564
+ }
565
+ try {
566
+ await $.command.register({ name: "fresh-window", description: "Reset context to a fresh notes-only window", argumentHint: "[context for notes]", immediate: true })
567
+ } catch (error) {
568
+ log($, `Command /fresh-window failed to register · ${describeFailure(error)}`)
569
+ await toast($, "🥣 Notesoup /fresh-window command failed to load")
570
+ }
571
+ if (health.notes < 4 || !health.wipe) {
572
+ health.degraded = toolErrors[0] ?? "core notesoup tools did not register"
573
+ log($, `Notesoup tools unavailable (${health.degraded}) · automatic brain reset disabled`)
574
+ await toast($, "🥣 Notesoup tools failed to load · auto-reset off")
575
+ } else {
576
+ armReset($, state, resetSignal)
470
577
  }
471
578
  return next(e)
472
579
  })
@@ -479,12 +586,21 @@ export function register(on: On) {
479
586
  if (state.disabled) return next(e)
480
587
  const generation = state.generation
481
588
  const result = registered.has(e.tool) ? await callNotesTool($, state, e) : await next(e)
482
- if (e.agentId !== undefined || result.deny !== undefined || generation !== state.generation) return result
483
- return withWarning($, state, (warning) => warning === undefined ? result : { ...result, context: [...(result.context ?? []), warning] })
589
+ if (e.agentId !== undefined || result.deny !== undefined || generation !== state.generation || health.degraded) return result
590
+ const pendingCommand = state.flow.request?.command && !state.flow.request.command.warned && !state.flow.request.tool ? state.flow.request.command : undefined
591
+ if (pendingCommand) {
592
+ const texts = await loadTexts($, state)
593
+ const notice = commandCloseoutText(texts, pendingCommand)
594
+ if (generation === state.generation && notice !== undefined && state.flow.request?.command === pendingCommand && !pendingCommand.warned) {
595
+ pendingCommand.warned = true
596
+ return { ...result, context: [...(result.context ?? []), notice] }
597
+ }
598
+ }
599
+ return withWarning($, state, health, (warning) => warning === undefined ? result : { ...result, context: [...(result.context ?? []), warning] })
484
600
  })
485
601
  on("prompt.submit", async ($, e, next) => {
486
602
  const generation = state.generation
487
- const result = await withWarning($, state, (warning) =>
603
+ const result = await withWarning($, state, health, (warning) =>
488
604
  next(warning === undefined ? e : { ...e, context: [...(e.context ?? []), warning] }))
489
605
  // Our own submissions skip this hook; accepted input owns the continuation.
490
606
  if (generation === state.generation && result.drop === undefined) state.flow.input(e.turnId)
@@ -503,7 +619,7 @@ export function register(on: On) {
503
619
  if (state.disabled || e.agentId !== undefined) return yield* next(e)
504
620
  // Like the warning, the hard point consumes the same resolved limits. This boundary
505
621
  // follows the whole previous tool batch; no sibling tool or in-flight request is aborted.
506
- if (await hardResetDue($, state)) state.flow.requestAutomatic()
622
+ if (await hardResetDue($, state, health)) state.flow.requestAutomatic(true)
507
623
  if (!state.flow.cutoff(e.turnId)) return yield* next(e)
508
624
  // This boundary follows the entire tool batch. A synthetic streamed stop
509
625
  // ends the main turn without aborting siblings or making an old-window request.
@@ -515,22 +631,34 @@ export function register(on: On) {
515
631
  const result = await next(e)
516
632
  if (e.agentId !== undefined || generation !== state.generation) return result
517
633
  const cancelled = state.flow.complete(e.reason)
518
- if (state.disabled) return result
634
+ if (state.disabled || health.degraded) return result
519
635
  // A failed turn proves nothing about whether its notes were saved.
520
636
  if (cancelled) log($, `Brain emptying cancelled · turn ended ${e.reason}; ask /fresh-window again`)
521
637
  if (!await refreshIdentity($, state)) return result
522
638
  if (e.reason === "answer") {
523
- if (!state.flow.request && await hardResetDue($, state)) state.flow.requestAutomatic()
524
- if (state.flow.request) resetSignal.wake?.({ kind: "reset", generation: state.generation })
639
+ // A clean end_turn with no prior mid-turn cutoff already delivered its answer:
640
+ // rotate quietly to a fresh window without waking the model for a ghost turn.
641
+ if (!state.flow.request && await hardResetDue($, state, health)) state.flow.requestAutomatic(false)
642
+ const req = state.flow.request
643
+ if (req) {
644
+ // If /empty [args] arrived mid-turn while the model was already finishing without
645
+ // further tool calls, give it one close-out turn while room remains so notes and
646
+ // any trailing context args are not silently dropped.
647
+ const unwarnedCommand = req.command !== undefined && !req.command.warned && req.tool === undefined
648
+ const needsCloseout = unwarnedCommand && !await hardResetDue($, state, health)
649
+ resetSignal.wake?.({ kind: needsCloseout ? "closeout" : "reset", generation: state.generation })
650
+ }
525
651
  }
526
652
  return result
527
653
  })
528
654
  on("command.run", { command: ["notesoup", "empty", "fresh-window"] }, async ($, e, next) => {
529
655
  if (state.disabled) return next(e)
530
- if (e.command === "notesoup") return capCommand($, state, e.args)
656
+ if (e.command === "notesoup") return capCommand($, state, health, e.args)
657
+ if (health.degraded) return { text: `🥣 Notesoup tools unavailable (${health.degraded}) · cannot empty brain` }
531
658
  if (!await refreshIdentity($, state)) return { text: "🥣 Different brain now · try /fresh-window again" }
532
659
  if (state.compactDisabled) return { text: `🥣 ${COMPACT_DISABLED}` }
533
- const first = state.flow.requestReset()
660
+ const trimmed = e.args?.trim() || undefined
661
+ const first = state.flow.requestReset(undefined, { name: e.command, args: trimmed })
534
662
  if (state.commit || !first) return { text: "🥣 Brain already being emptied" }
535
663
  // command.run holds a turn even when idle; close out from the non-held waiter.
536
664
  if (!state.flow.running) resetSignal.wake?.({ kind: "closeout", generation: state.generation })
@@ -552,6 +680,7 @@ export function register(on: On) {
552
680
  }
553
681
  return result
554
682
  }
683
+ if (health.degraded) return passThrough()
555
684
  // Native compaction never runs the summarizer while notesoup is on: user
556
685
  // manual and precompute are vetoed; auto becomes the notes-only reset.
557
686
  const own = state.commit !== undefined && identity !== undefined && e.trigger === "manual" && e.instructions === state.commit.instructions
@@ -559,7 +688,7 @@ export function register(on: On) {
559
688
  if (e.trigger === "precompute") return { skip: "No precomputing brains here" }
560
689
  if (!own && e.trigger !== "auto") return passThrough()
561
690
  if (identity === undefined) return passThrough()
562
- const built = await resetMessages($, state, identity)
691
+ const built = await resetMessages($, state, identity, health)
563
692
  if ("skip" in built) {
564
693
  if (own) return { skip: built.skip }
565
694
  // An over-long prompt must still compact: fall back to the engine's summary.
@@ -571,13 +700,17 @@ export function register(on: On) {
571
700
  return { messages: built.messages }
572
701
  })
573
702
  // notesoup replaces Claude's summarization and auto-memory guidance; memory can be kept on request.
574
- on("prompt.section", { name: "context_management" }, ($, e, next) => state.disabled ? next(e) : { text: null })
703
+ on("prompt.section", { name: "context_management" }, ($, e, next) => state.disabled || health.degraded ? next(e) : { text: null })
575
704
  on("prompt.section", { name: "memory" }, ($, e, next) => state.disabled || keepMemory ? next(e) : { text: null })
576
705
  on("prompt.context", async ($, e, next) => {
577
706
  if (state.disabled) return next(e)
578
707
  const result = await next(e)
579
708
  const identity = await refreshIdentity($, state)
580
709
  const generation = state.generation
710
+ if (health.degraded) {
711
+ const blocks = result.blocks.filter((block) => block.name !== "notesoup:boot")
712
+ return { ...result, blocks: [...blocks, { name: "notesoup:boot", text: `# notesoup\nNotesoup tools failed to load in this session (${health.degraded}). Automatic brain reset is disabled and native compaction remains active; tell the human if you need notes or history.` }] }
713
+ }
581
714
  // The reset already retained its boot as the sole conversation message.
582
715
  // Prompt context still recomputes, but must not inject a duplicate snapshot.
583
716
  const retained = state.retainedBoot !== undefined
@@ -588,12 +721,10 @@ export function register(on: On) {
588
721
  })
589
722
  if (!retained && !blocks.some((block) => block.name === "notesoup:boot") && identity) {
590
723
  const texts = await loadTexts($, state)
591
- const boot = await buildBoot($, identity, state.window, texts, state.history)
724
+ const boot = await buildBoot($, identity, state.window, texts, state.history, health)
592
725
  if (generation !== state.generation) return result
593
726
  if (!boot.ok) {
594
- try {
595
- await $.ui.toast("🥣 Notes went missing")
596
- } catch { /* Notification failure must not suppress the fallback block. */ }
727
+ await toast($, "🥣 Notes went missing")
597
728
  }
598
729
  blocks = [...blocks, { name: "notesoup:boot", text: boot.ok ? String(boot.result) : `# notesoup\nYour notes didn't load this time (${boot.error}). Try \`${PREFIX}notes_list\`; if it fails too, tell the human.` }]
599
730
  }
@@ -620,7 +751,13 @@ async function callNotesTool($: Engine, state: ResetState, e: ToolCallInput): Pr
620
751
  if (state.flow.requestReset({ lastWord, terminate: terminate === true })) state.continuation = undefined
621
752
  return { result: `Brain reset requested. This tool batch will finish, then the turn stops before its next model request unless it has new user input to handle. Your notes and sticky note survive the reset.${state.flow.request!.resume ? " You will continue in a fresh window after the reset." : " No automatic continuation will be submitted."}` }
622
753
  }
623
- const history = name === "history_list" || name === "history_read"
754
+ if (name === "get_context_remaining") {
755
+ if (agentId !== undefined) return errorResult("context remaining is unavailable for subagents; main-session usage is not their context")
756
+ const usage = await contextUsage($, state)
757
+ const limits = usage ? await limitsOf($, state, usage) : undefined
758
+ return { result: JSON.stringify({ remaining_tokens: remainingTokensFor(limits, usage) }) }
759
+ }
760
+ const history = name === "history_list" || name === "history_search" || name === "history_read"
624
761
  if (history && agentId !== undefined) return errorResult("history is unavailable for subagents; main-session history is not their transcript")
625
762
  const result = await run($, { op: "tool", tool: name, params, identity, history: state.history }, history ? HISTORY_TIMEOUT_MS : TIMEOUT_MS)
626
763
  if (!result.ok) return errorResult(result.error)
@@ -644,8 +781,8 @@ async function warningText($: Engine, state: ResetState): Promise<string | undef
644
781
  }
645
782
 
646
783
  /** Reserve across next(), but consume only context the chain actually accepted. */
647
- async function withWarning<T extends { context?: readonly string[]; drop?: string; deny?: string }>($: Engine, state: ResetState, deliver: (warning?: string) => T | Promise<T>): Promise<T> {
648
- if (state.disabled || state.compactDisabled || !await refreshIdentity($, state)) return deliver()
784
+ async function withWarning<T extends { context?: readonly string[]; drop?: string; deny?: string }>($: Engine, state: ResetState, health: ToolsHealth, deliver: (warning?: string) => T | Promise<T>): Promise<T> {
785
+ if (state.disabled || state.compactDisabled || health.degraded || !await refreshIdentity($, state)) return deliver()
649
786
  const generation = state.generation, window = state.window
650
787
  const warning = await warningText($, state)
651
788
  if (warning === undefined || generation !== state.generation || window !== state.window || state.warnedWindow === window || state.warningPending === window) return deliver()
@@ -708,12 +845,15 @@ async function runResetWork($: Engine, state: ResetState, work: ResetWork) {
708
845
  } else {
709
846
  const texts = await loadTexts($, state)
710
847
  if (generation !== state.generation) return
711
- if (texts?.warning === undefined) {
848
+ const command = state.flow.request?.command
849
+ const closeout = commandCloseoutText(texts, command)
850
+ if (closeout === undefined) {
712
851
  state.flow.cancel()
713
852
  log($, "Brain still full: the close-out prompt didn't load")
714
853
  return
715
854
  }
716
- text = texts.warning
855
+ if (command) command.warned = true
856
+ text = closeout
717
857
  }
718
858
  const result = await $.prompt.submit({ text })
719
859
  if (result.drop !== undefined) throw result.drop
@@ -27,7 +27,7 @@ Durable notes hold decisions, constraints, and lessons that stay true after the
27
27
  5. **Relocate misfiled notes.** When a standing ruling or the note's own `description` already names its proper notebook, move it there, preserving its metadata, and keep its `description` true. Do it, don't propose it. Propose only when the destination notebook itself is unclear.
28
28
  6. **Preserve meaning and provenance.** Keep facts, conditions, exceptions, uncertainty, authorship, and sources. When promoting a finding, cite its source. Do not relabel agent-authored material as human-authored. If its destination or authority is unclear, propose the promotion instead.
29
29
  7. **Keep notes manageable.** Aim below about 200 lines / 8KB per note. Split oversized notes by topic with one-line cross-links.
30
- 8. **Keep wake-up pages useful.** Each writable notebook's `CHEATSHEET.md` holds standing reminders, kept to five lines; it is the one default-pinned page and loads every window when live unless explicitly unpinned. Every durable note gets a one-line `description` (max 160 characters) saying what it holds and when to open it — boot lists each notebook's unpinned notes newest first from these, so a missing, stale, or vague description hides the page. A hand-written `MAP.md` is an ordinary note now; once its lines live in `description`s, crumple it. Do not create empty pages. Each notebook allows five live pins. Ordinary pages default to a 4096-code-point advisory budget (2048 for root `CHEATSHEET.md`), adjustable per note; overflow warns without truncating a pinned body. Preserve standing rules and keep descriptions true as notes are promoted or retired.
30
+ 8. **Keep wake-up pages useful.** Each writable notebook's `CHEATSHEET.md` holds compact standing reminders; it is the one default-pinned page and loads every window when live unless explicitly unpinned. Every durable note gets a short one-line `description` saying what it holds and when to open it — boot lists each notebook's unpinned notes newest first from these, so a missing, stale, or vague description hides the page. A hand-written `MAP.md` is an ordinary note now; once its lines live in `description`s, crumple it. Do not create empty pages. Pin slots per notebook are capped, and each page carries a UTF-8 byte budget (4 KB for `CHEATSHEET.md`, 8 KB for ordinary notes; overridable in frontmatter); overflow warns, and boot truncates over-budget pinned bodies. Preserve standing rules and keep descriptions true as notes are promoted or retired.
31
31
 
32
32
  ## Deleting
33
33
 
@@ -5,7 +5,7 @@ description: Review and consolidate durable notes using notesoup's shared dream
5
5
 
6
6
  # Dream
7
7
 
8
- Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. Standing reminders belong in a separate `CHEATSHEET.md` (five lines), the one default-pinned page; it loads every window when live unless explicitly unpinned. Every durable note carries a one-line `description` (max 160 characters) saying what it holds and when to open it — boot renders each notebook's index from these, so a missing or stale description is an index defect. Ordinary notes default to a 4096-code-point advisory budget (2048 for root `CHEATSHEET.md`), adjustable per note; pinned bodies load whole with overflow warnings. Respect soft readonly locks; explicitly unlock with `readonly:false` before changing a locked note.
8
+ Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. Standing reminders belong in a separate compact `CHEATSHEET.md`, the one default-pinned page; it loads every window when live unless explicitly unpinned. Every durable note carries a short one-line `description` saying what it holds and when to open it — boot renders each notebook's index from these, so a missing or stale description is an index defect. Pages carry UTF-8 byte budgets (4 KB for `CHEATSHEET.md`, 8 KB for ordinary notes, overridable in frontmatter); overflow warns, and boot truncates over-budget pinned bodies. Respect soft readonly locks; explicitly unlock with `readonly:false` before changing a locked note.
9
9
 
10
10
  Dream in this agent's current session. Do not start another agent or model unless the human asks.
11
11
 
@@ -0,0 +1,92 @@
1
+ ---
2
+ name: notesoup-guide
3
+ description: How notesoup's `notes_*` and `history_*` tools fit together — note addresses and notebooks, finding things again, and saving recovery state. Use when the context-window protocol is missing or unclear, or when unsure where a note belongs or how to find something again.
4
+ ---
5
+
6
+ # Notesoup Guide
7
+
8
+ Two stores outlive the context window. Anything in neither is lost when the window ends or is wiped.
9
+
10
+ - **Notes** (`notes_*`) — what you choose to keep. Plain markdown, written on purpose.
11
+ - **History** (`history_*`) — recorded messages, tool calls and summaries. Current session by default; other local sessions/harnesses through `session`. Read-only.
12
+
13
+ Each tool's own description covers its parameters and paging. This guide covers what the descriptions cannot: where notes belong, and how the tools work together.
14
+
15
+ ## Addresses
16
+
17
+ The address decides who a note belongs to and how long it lasts.
18
+
19
+ | Address | Note | Keep there |
20
+ | --- | --- | --- |
21
+ | `<path>`, no `@` | session note | current task state and loose ends; gone with the session |
22
+ | `@project/<path>` | project note | decisions and constraints future work must respect |
23
+ | `@human/<path>` | human note | how to work with this human, across projects |
24
+ | `@self/<path>` | self note | your reminders; yours alone if you have a name, shared by everyone nameless |
25
+ | `@model/<path>` | model note | what applies to this model only |
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/*/**` |
28
+
29
+ When notes conflict, the one most relevant to what you're doing applies. If that doesn't settle it, judge the case.
30
+
31
+ Any other `@` prefix is refused. A path is relative and `/`-separated, with no empty, `.` or `..` segments.
32
+
33
+ `@` addresses are not file paths: never pass them to file tools like `read`, `write`, `edit`, or `bash`. That creates a stray directory instead of a note.
34
+
35
+ `CHEATSHEET.md` at each notebook's root is the default-pinned page you wake up with; absent or crumpled pages are skipped. Set `pinned`, `readonly`, and `description` through `notes_write`/`notes_update` or frontmatter. Explicit `pinned:false` unpins even a default page; each page carries a UTF-8 byte budget (4 KB for root `CHEATSHEET.md`, 8 KB for ordinary notes; overridable in frontmatter). Overflow on body budget or an oversized description warns but still saves; boot truncates over-budget pinned bodies and oversized descriptions. `readonly:true` is a soft lock, not security; explicitly set `readonly:false` to unlock, alone or alongside your changes. Keep `CHEATSHEET.md` compact with short bullets. Give each durable note a short one-line `description`: boot lists every notebook's unpinned pages newest first as address, age, and description, so it is the only index. Do not create empty pages.
36
+
37
+ Keep notes focused on what is true now; if a piece of past context still matters (such as why an approach was ruled out), keep only a brief summary rather than a blow-by-blow log. Crumple notes that are no longer true; a stale note is worse than none.
38
+
39
+ ## Finding things again
40
+
41
+ ### Notes
42
+
43
+ In `notes_list`, omit `glob` for this session and the current shared notebooks. Use `**` for all notebooks or `@sessions/*/**` for all sessions.
44
+
45
+ - **A note**: add `glob` to narrow where `notes_list` looks, and `query` if you remember a phrase. Then use `notes_read` with the address and, for a match, its `offset_chars`.
46
+ - **Older notes**: when `notes_list` ends with `→ older: {…}`, call it again with that object to see older matches. Continue until the line is gone.
47
+ ### Shared search and read conventions
48
+
49
+ Queries look for literal text, ignoring case. A list of phrases matches any one of them.
50
+
51
+ Both list tools report omissions and partial previews. A truncated result is not the whole
52
+ record.
53
+
54
+ Read offsets count characters relative to the body or event document, not the
55
+ presentation header.
56
+
57
+ Continue an incomplete read at the offset named in its trailing notice. A concurrent edit can
58
+ change a note's offsets.
59
+
60
+ All shared tools return text. On supported hosts, `notes_read` also returns the note body
61
+ `text` without presentation markers, plus `next_offset_chars`, metadata and warnings.
62
+
63
+ When carrying a reference into another window, save its full address or event identity, not just
64
+ a quotation; you can retrieve the text again.
65
+
66
+ ### History
67
+
68
+ - **Browse a known timeline**: `history_list({ before: 190 })` uses exclusive integer seq bounds (see the boot window tree for earlier windows), with optional ISO 8601 `since` / `until`. With `after` (or `since` alone) you page forward; otherwise take the newest events. Follow the older/newer and expand recipes.
69
+ - **List sessions**: pass a wildcard such as `session: "*"` or `"pi:*"` to `history_list` for one representative event per session (default 20 sessions), optionally narrowed with `roles` and `since` / `until`.
70
+ - **Find a passage**: `history_search({ query: "remembered phrase", context: 1 })` searches all roles in the current session, one named session, or a wildcard such as `session: "*"`, with optional neighboring events, `roles`, and ISO 8601 `since` / `until`. `query` is required (an empty query returns no matches).
71
+ - **Target one session**: all three tools accept an ID or prefix, optionally qualified with `pi:`, `claude:`, `codex:` or `dsh:`. Omit `session` for this session. If ambiguous, pass a longer or qualified ID. DSH sessions are available only from DSH.
72
+ - **Open a passage**: `history_read({ seq: 42 })` reads one event. If a session heading is shown above the event, include the full session ID; if a preview offset is shown, pass it as `offset_chars`. Follow the continuation to read more.
73
+
74
+ Save the seq and full session ID together when carrying a cross-session reference into another window. An empty search is not proof an event never happened: wildcard searches skip sessions that cannot be read.
75
+
76
+ ## Saving recovery state
77
+
78
+ Before a long or risky step, or when room runs low, keep session notes named for what they hold (not `current.md`) and rewrite them in place with short sections and bullets instead of starting new ones or appending a timeline. Skip standing rules already in `@project`/`@human`/`@self`/`@model` and commit details git can show; record only the live delta:
79
+
80
+ - current status, blockers, and the next action
81
+ - what the human decided (in their words)
82
+ - what failed, and why
83
+ - where half-done work and unrecorded findings live (branches, worktrees, scratch paths, drafts, running tasks, key facts not saved elsewhere)
84
+ - skills, notes, files, or already-found history seqs to reopen
85
+
86
+ `get_context_remaining` reports the room left. `empty_brain` starts a fresh window, so save the note first.
87
+
88
+ ## When a tool is missing or refuses
89
+
90
+ A refusal displays `error: <code>: <message>`; read the message before retrying. `notes_read` also supplies `{ error, code }` where structured results are available.
91
+
92
+ If a `notes_*` or `history_*` tool is absent or fails at the host level, do not imitate it: no filesystem tools on `@` addresses, and no reading or editing note storage or session files directly. Use the tools that remain, tell the human which one is missing, and keep essential state in the reply.