notesoup 0.40.0 → 0.42.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.
- package/dist/src/boot/render.js +1 -1
- package/dist/src/boot/text.d.ts +12 -0
- package/dist/src/boot/text.js +25 -5
- package/dist/src/budget/policy.js +1 -1
- package/dist/src/budget/text.d.ts +12 -0
- package/dist/src/budget/text.js +13 -1
- package/dist/src/claude/helper.js +23 -2
- package/dist/src/claude/thresholds.d.ts +39 -0
- package/dist/src/claude/thresholds.js +149 -0
- package/dist/src/dream/doctor.js +3 -2
- package/dist/src/dream/git.js +2 -1
- package/dist/src/dream/jail.js +10 -10
- package/dist/src/dream/report.js +3 -2
- package/dist/src/error-message.d.ts +2 -0
- package/dist/src/error-message.js +4 -0
- package/dist/src/history/history.js +1 -1
- package/dist/src/history/query.js +6 -6
- package/dist/src/notes/address.d.ts +1 -1
- package/dist/src/notes/address.js +12 -12
- package/dist/src/notes/store.js +16 -12
- package/dist/src/pi/anchored.d.ts +16 -0
- package/dist/src/pi/anchored.js +55 -0
- package/dist/src/pi/budget.d.ts +1 -1
- package/dist/src/pi/budget.js +33 -28
- package/dist/src/pi/dream/cli.js +3 -2
- package/dist/src/pi/dream/runner.js +2 -1
- package/dist/src/pi/reset/lifecycle.d.ts +1 -1
- package/dist/src/pi/reset/lifecycle.js +4 -3
- package/dist/src/pi/reset/text.d.ts +3 -4
- package/dist/src/pi/reset/text.js +5 -4
- package/dist/src/pi/runtime.js +13 -16
- package/dist/src/pi/thresholds.js +2 -1
- package/dist/src/pi/tool-result.js +2 -2
- package/dist/src/settings.d.ts +8 -0
- package/dist/src/settings.js +6 -1
- package/dist/src/tools/history.js +12 -12
- package/dist/src/tools/notes.d.ts +3 -3
- package/dist/src/tools/notes.js +12 -11
- package/dist/src/tools/output.d.ts +2 -0
- package/dist/src/tools/output.js +2 -0
- package/dist/src/tools/result.js +2 -2
- package/dist/src/tools/schema.js +3 -3
- package/dist/test/agent-loop.test.js +78 -28
- package/dist/test/boot.integration.test.js +5 -5
- package/dist/test/budget-settings.integration.test.js +9 -8
- package/dist/test/claude-mod.test.js +213 -23
- package/dist/test/dream.test.js +3 -3
- package/dist/test/history.integration.test.js +7 -8
- package/dist/test/host-neutral.test.js +2 -2
- package/dist/test/notes-library.test.js +1 -1
- package/dist/test/notes.integration.test.js +5 -5
- package/dist/test/notes.test.js +16 -16
- package/dist/test/reset-lifecycle.test.js +2 -2
- package/docs/claude-code-mod.md +10 -2
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +212 -45
- package/mods/notesoup/hooks/register.ts +209 -48
- package/mods/notesoup/playbook.md +10 -10
- package/mods/notesoup/skills/dream/SKILL.md +1 -1
- package/package.json +1 -1
- package/playbook.md +10 -10
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +5 -3
- package/src/boot/render.ts +1 -1
- package/src/boot/text.ts +31 -5
- package/src/budget/policy.ts +1 -1
- package/src/budget/text.ts +18 -1
- package/src/claude/helper.ts +20 -3
- package/src/claude/thresholds.ts +170 -0
- package/src/dream/doctor.ts +3 -2
- package/src/dream/git.ts +2 -1
- package/src/dream/jail.ts +10 -10
- package/src/dream/report.ts +3 -2
- package/src/error-message.ts +4 -0
- package/src/history/history.ts +1 -1
- package/src/history/query.ts +6 -6
- package/src/notes/address.ts +12 -12
- package/src/notes/store.ts +17 -12
- package/src/pi/anchored.ts +62 -0
- package/src/pi/budget.ts +27 -26
- package/src/pi/dream/cli.ts +3 -2
- package/src/pi/dream/runner.ts +2 -1
- package/src/pi/reset/lifecycle.ts +5 -4
- package/src/pi/reset/text.ts +6 -7
- package/src/pi/runtime.ts +13 -16
- package/src/pi/thresholds.ts +2 -1
- package/src/pi/tool-result.ts +2 -2
- package/src/settings.ts +18 -2
- package/src/tools/history.ts +12 -12
- package/src/tools/notes.ts +14 -12
- package/src/tools/output.ts +2 -0
- package/src/tools/result.ts +2 -2
- package/src/tools/schema.ts +3 -3
|
@@ -9,11 +9,27 @@ const OUTPUT_LIMIT = 1024 * 1024
|
|
|
9
9
|
|
|
10
10
|
type Identity = { home: string; sessionId: string; cwd: string; agent: string; model: string }
|
|
11
11
|
type SchemaRow = { name: string; description: string; inputSchema: Record<string, unknown> }
|
|
12
|
-
type Engine = Pick<EngineInterface, "process" | "session" | "ui" | "clock" | "prompt">
|
|
12
|
+
type Engine = Pick<EngineInterface, "process" | "session" | "ui" | "clock" | "prompt" | "env">
|
|
13
|
+
type UsageSample = { context?: unknown }
|
|
14
|
+
/** `usage({breakdown:true})` is wired in the engine but absent from the public typings. */
|
|
15
|
+
type UsageReader = (options?: { breakdown?: boolean }) => Promise<UsageSample | undefined>
|
|
16
|
+
/** The measured context, as much of it as the engine reported. */
|
|
17
|
+
type ContextUsage = { tokens?: number; window?: number; percent?: number }
|
|
18
|
+
/** Shared reset prose, fetched once per session so Pi and Claude cannot drift apart. */
|
|
19
|
+
type SharedTexts = { warning?: string; continuation?: string; wipeSentence?: string }
|
|
20
|
+
type ClaudeLimits = {
|
|
21
|
+
source: string; autoCompact: boolean; unit: "tokens" | "percent"
|
|
22
|
+
native: number; reset: number; warn: number; resetMargin: number; warningRunway: number
|
|
23
|
+
}
|
|
13
24
|
type ResetState = {
|
|
14
25
|
identity?: Identity; window: number; turnRunning: boolean; resetting: boolean
|
|
15
26
|
manualPending: boolean; headless: boolean; usageFailureLogged: boolean; preparedBoot?: string; retainedBoot?: string
|
|
27
|
+
compactDisabled: boolean; limitsFailureLogged: boolean; limitsAttempted: boolean; limitsWindow: number
|
|
28
|
+
limits?: ClaudeLimits; warnedWindow?: number; texts?: SharedTexts
|
|
16
29
|
}
|
|
30
|
+
const HEADLESS = "Clear-memory is off in headless (-p / SDK) sessions"
|
|
31
|
+
const COMPACT_DISABLED = "Clear-memory can't run: compaction is off in this session (DISABLE_COMPACT)"
|
|
32
|
+
const THRESHOLDS_UNAVAILABLE = "Context thresholds unavailable · automatic clear-memory skipped"
|
|
17
33
|
const RESET_INSTRUCTIONS = "notesoup: reset to a fresh notes-only context window."
|
|
18
34
|
const BOOT_TOOLS = {
|
|
19
35
|
notes: `${PREFIX}notes_*`, notesList: `${PREFIX}notes_list`,
|
|
@@ -21,11 +37,120 @@ const BOOT_TOOLS = {
|
|
|
21
37
|
remaining: "get_context_remaining (unavailable in Claude)", wipe: "/clear-memory (user command; no model reset tool in Claude)",
|
|
22
38
|
}
|
|
23
39
|
|
|
24
|
-
|
|
25
|
-
|
|
40
|
+
/** The boot names the host's own wipe path, so the protocol block speaks about `/clear-memory`. */
|
|
41
|
+
async function buildBoot($: Engine, identity: Identity, window: number, texts?: SharedTexts) {
|
|
42
|
+
const tools = texts?.wipeSentence === undefined ? BOOT_TOOLS : { ...BOOT_TOOLS, wipeSentence: texts.wipeSentence }
|
|
43
|
+
return run($, { op: "boot", identity, window, tools }, identity.cwd)
|
|
44
|
+
}
|
|
45
|
+
function numberOf(value: unknown): number | undefined {
|
|
46
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined
|
|
47
|
+
}
|
|
48
|
+
function sharedTextsOf(value: unknown): SharedTexts | undefined {
|
|
49
|
+
if (typeof value !== "object" || value === null) return undefined
|
|
50
|
+
const row = value as Record<string, unknown>
|
|
51
|
+
const texts: SharedTexts = {}
|
|
52
|
+
if (typeof row.warning === "string" && row.warning.length > 0) texts.warning = row.warning
|
|
53
|
+
if (typeof row.continuation === "string" && row.continuation.length > 0) texts.continuation = row.continuation
|
|
54
|
+
if (typeof row.wipeSentence === "string" && row.wipeSentence.length > 0) texts.wipeSentence = row.wipeSentence
|
|
55
|
+
return Object.keys(texts).length > 0 ? texts : undefined
|
|
56
|
+
}
|
|
57
|
+
/** The helper's resolved points, accepted only when every number is a real number. */
|
|
58
|
+
function limitsShape(value: unknown): ClaudeLimits | undefined {
|
|
59
|
+
if (typeof value !== "object" || value === null) return undefined
|
|
60
|
+
const row = value as Record<string, unknown>
|
|
61
|
+
const unit = row.unit === "tokens" || row.unit === "percent" ? row.unit : undefined
|
|
62
|
+
const native = numberOf(row.native), reset = numberOf(row.reset), warn = numberOf(row.warn)
|
|
63
|
+
const resetMargin = numberOf(row.resetMargin), warningRunway = numberOf(row.warningRunway)
|
|
64
|
+
if (unit === undefined || native === undefined || reset === undefined || warn === undefined || resetMargin === undefined || warningRunway === undefined) return undefined
|
|
65
|
+
return { source: typeof row.source === "string" ? row.source : "unknown", autoCompact: row.autoCompact !== false, unit, native, reset, warn, resetMargin, warningRunway }
|
|
66
|
+
}
|
|
67
|
+
async function envValue($: Engine, name: string): Promise<string | undefined> {
|
|
68
|
+
try { const value = await $.env.get(name); return typeof value === "string" ? value : undefined } catch { return undefined }
|
|
69
|
+
}
|
|
70
|
+
/** Presence-style environment flags: any value but an explicit no counts as on. */
|
|
71
|
+
async function envFlag($: Engine, name: string): Promise<boolean> {
|
|
72
|
+
const value = await envValue($, name)
|
|
73
|
+
if (value === undefined) return false
|
|
74
|
+
const text = value.trim().toLowerCase()
|
|
75
|
+
return text !== "" && text !== "0" && text !== "false"
|
|
76
|
+
}
|
|
77
|
+
async function readSettings($: Engine): Promise<unknown> {
|
|
78
|
+
const settings = ($ as { settings?: { read?: (options?: unknown) => Promise<unknown> } }).settings
|
|
79
|
+
if (typeof settings?.read !== "function") return undefined
|
|
80
|
+
try { return await settings.read() } catch { return undefined }
|
|
81
|
+
}
|
|
82
|
+
/** The measured context, or undefined when the engine cannot report it. The failure logs once. */
|
|
83
|
+
async function contextUsage($: Engine, state: ResetState): Promise<ContextUsage | undefined> {
|
|
84
|
+
try {
|
|
85
|
+
const read = $.session.usage as unknown as UsageReader
|
|
86
|
+
const context = (await read())?.context
|
|
87
|
+
if (typeof context !== "object" || context === null) return {}
|
|
88
|
+
const row = context as Record<string, unknown>
|
|
89
|
+
return { tokens: numberOf(row.tokens), window: numberOf(row.window), percent: numberOf(row.percent) }
|
|
90
|
+
} catch {
|
|
91
|
+
if (!state.usageFailureLogged) {
|
|
92
|
+
state.usageFailureLogged = true
|
|
93
|
+
log($, "Context usage unavailable · automatic clear-memory skipped")
|
|
94
|
+
}
|
|
95
|
+
return undefined
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async function breakdownContext($: Engine): Promise<Record<string, unknown> | undefined> {
|
|
99
|
+
try {
|
|
100
|
+
const read = $.session.usage as unknown as UsageReader
|
|
101
|
+
const context = (await read({ breakdown: true }))?.context
|
|
102
|
+
return typeof context === "object" && context !== null ? context as Record<string, unknown> : undefined
|
|
103
|
+
} catch { return undefined }
|
|
104
|
+
}
|
|
105
|
+
/** Everything the resolver may read: measured usage plus the raw settings and environment. */
|
|
106
|
+
async function limitFacts($: Engine, usage: ContextUsage): Promise<Record<string, unknown>> {
|
|
107
|
+
return {
|
|
108
|
+
usage,
|
|
109
|
+
breakdown: await breakdownContext($),
|
|
110
|
+
settings: await readSettings($),
|
|
111
|
+
env: {
|
|
112
|
+
pctOverride: await envValue($, "CLAUDE_AUTOCOMPACT_PCT_OVERRIDE"),
|
|
113
|
+
autoCompactWindow: await envValue($, "CLAUDE_CODE_AUTO_COMPACT_WINDOW"),
|
|
114
|
+
disableAutoCompact: await envValue($, "DISABLE_AUTO_COMPACT"),
|
|
115
|
+
},
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The points the current window is measured against, resolved by the helper's shared
|
|
120
|
+
* derivation. One attempt per reported window value: an unknown window resolves the percent
|
|
121
|
+
* fallback, and a later real window re-resolves against it.
|
|
122
|
+
*/
|
|
123
|
+
async function limitsOf($: Engine, state: ResetState, usage: ContextUsage): Promise<ClaudeLimits | undefined> {
|
|
124
|
+
const window = usage.window !== undefined && usage.window > 0 ? usage.window : 0
|
|
125
|
+
if (state.limitsAttempted && state.limitsWindow === window) return state.limits
|
|
126
|
+
const response = await run($, { op: "limits", facts: await limitFacts($, usage) }, state.identity?.cwd ?? ".")
|
|
127
|
+
const limits = response.ok ? limitsShape(response.result) : undefined
|
|
128
|
+
state.limitsAttempted = true
|
|
129
|
+
state.limitsWindow = window
|
|
130
|
+
if (limits) state.limits = limits
|
|
131
|
+
else if (!state.limitsFailureLogged) {
|
|
132
|
+
state.limitsFailureLogged = true
|
|
133
|
+
log($, THRESHOLDS_UNAVAILABLE)
|
|
134
|
+
}
|
|
135
|
+
return limits ?? state.limits
|
|
136
|
+
}
|
|
137
|
+
/** The measured value the points are expressed in; tokens win, percent × window stands in. */
|
|
138
|
+
function measuredValue(limits: ClaudeLimits, usage: ContextUsage): number | undefined {
|
|
139
|
+
if (limits.unit === "percent") return usage.percent
|
|
140
|
+
if (usage.tokens !== undefined) return usage.tokens
|
|
141
|
+
return usage.percent !== undefined && usage.window !== undefined && usage.window > 0 ? (usage.percent / 100) * usage.window : undefined
|
|
142
|
+
}
|
|
143
|
+
/** The shared reset prose: one helper round trip per session, retried until it lands. */
|
|
144
|
+
async function loadTexts($: Engine, state: ResetState): Promise<SharedTexts | undefined> {
|
|
145
|
+
if (state.texts) return state.texts
|
|
146
|
+
if (!state.identity) return undefined
|
|
147
|
+
const response = await run($, { op: "texts" }, state.identity.cwd)
|
|
148
|
+
const texts = response.ok ? sharedTextsOf(response.result) : undefined
|
|
149
|
+
if (texts) state.texts = texts
|
|
150
|
+
return texts
|
|
26
151
|
}
|
|
27
152
|
function log($: Engine, text: string) {
|
|
28
|
-
try { $.ui.log(
|
|
153
|
+
try { $.ui.log(`🥣 ${text}`) } catch { /* UI must not break a turn or reset. */ }
|
|
29
154
|
}
|
|
30
155
|
|
|
31
156
|
function errorResult(message: string): ToolCallResult { return { result: `notesoup: ${message}`, isError: true } }
|
|
@@ -58,7 +183,7 @@ function identityOf(e: { cwd: string }, sessionId: string, home: string, model:
|
|
|
58
183
|
export function register(on: On) {
|
|
59
184
|
let identity: Identity | undefined
|
|
60
185
|
const manualSignal: { wake?: () => void } = {}
|
|
61
|
-
const state: ResetState = { window: 0, turnRunning: false, resetting: false, manualPending: false, headless: false, usageFailureLogged: false }
|
|
186
|
+
const state: ResetState = { window: 0, turnRunning: false, resetting: false, manualPending: false, headless: false, usageFailureLogged: false, compactDisabled: false, limitsFailureLogged: false, limitsAttempted: false, limitsWindow: 0 }
|
|
62
187
|
const registered = new Set<string>()
|
|
63
188
|
on("session.start", async ($, e, next) => {
|
|
64
189
|
const home = await $.env.get("PI_NOTES_HOME") ?? `${await $.env.get("HOME") ?? await $.env.get("USERPROFILE") ?? ""}/.agents/notes`
|
|
@@ -67,12 +192,20 @@ export function register(on: On) {
|
|
|
67
192
|
state.window = 0
|
|
68
193
|
state.turnRunning = state.resetting = state.manualPending = state.usageFailureLogged = false
|
|
69
194
|
state.headless = !e.isInteractive
|
|
70
|
-
if (state.headless) log($,
|
|
195
|
+
if (state.headless) log($, HEADLESS)
|
|
71
196
|
state.preparedBoot = state.retainedBoot = undefined
|
|
197
|
+
state.texts = state.limits = undefined
|
|
198
|
+
state.limitsAttempted = false
|
|
199
|
+
state.limitsWindow = 0
|
|
200
|
+
state.warnedWindow = undefined
|
|
201
|
+
// Compaction is the capability the reset is built on; without it, automatic resets stop here.
|
|
202
|
+
state.compactDisabled = await envFlag($, "DISABLE_COMPACT")
|
|
203
|
+
if (state.compactDisabled) log($, COMPACT_DISABLED)
|
|
72
204
|
// The engine's history view includes retained boots on resume/reload.
|
|
73
205
|
// Recover their ordinal without treating that view as inference context.
|
|
74
206
|
try { restoreWindow(state, await $.session.messages()) } catch { /* A fresh session starts at zero. */ }
|
|
75
207
|
registered.clear()
|
|
208
|
+
await loadTexts($, state)
|
|
76
209
|
armManual($, state, manualSignal)
|
|
77
210
|
await $.command.register({ name: "clear-memory", description: "Reset context to a fresh notes-only window", immediate: true })
|
|
78
211
|
const schemas = await run($, { op: "schemas" }, e.cwd)
|
|
@@ -112,45 +245,73 @@ export function register(on: On) {
|
|
|
112
245
|
})
|
|
113
246
|
on("command.run", async ($, e, next) => {
|
|
114
247
|
if (e.command !== "clear-memory") return next(e)
|
|
115
|
-
if (state.headless) return { text:
|
|
116
|
-
if (state.
|
|
248
|
+
if (state.headless) return { text: `🥣 ${HEADLESS}` }
|
|
249
|
+
if (state.compactDisabled) return { text: `🥣 ${COMPACT_DISABLED}` }
|
|
250
|
+
if (state.resetting || state.manualPending) return { text: "🥣 Clear-memory already queued" }
|
|
117
251
|
if (state.turnRunning) {
|
|
118
252
|
state.manualPending = true
|
|
119
|
-
return { text: "
|
|
253
|
+
return { text: "🥣 Clear-memory queued · runs after this turn" }
|
|
120
254
|
}
|
|
121
255
|
// command.run holds a turn even when idle. Start one hidden close-out
|
|
122
256
|
// turn after it returns; turn.complete is the verified self-hook path.
|
|
123
257
|
state.manualPending = true
|
|
124
258
|
manualSignal.wake?.()
|
|
125
|
-
return { text: "
|
|
259
|
+
return { text: "🥣 Clearing memory · notes first, then it stops" }
|
|
126
260
|
})
|
|
127
261
|
on("session.compact", async ($, e, next) => {
|
|
128
262
|
// Do not take over native /compact or another plugin's compaction.
|
|
129
263
|
if (!state.resetting || e.trigger !== "plugin" || e.agentId !== undefined || !identity) return next(e)
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
264
|
+
const texts = await loadTexts($, state)
|
|
265
|
+
if (texts?.continuation === undefined) return { skip: "reset text didn't load" }
|
|
266
|
+
const boot = await buildBoot($, identity, state.window + 1, texts)
|
|
267
|
+
if (!boot.ok) return { skip: `notes didn't load: ${boot.error}` }
|
|
132
268
|
state.preparedBoot = String(boot.result)
|
|
133
|
-
|
|
269
|
+
// The same closed reset shape as Pi: notes boot first, then the one reset message.
|
|
270
|
+
return { messages: [
|
|
271
|
+
{ role: "user", text: state.preparedBoot, toolUses: [] },
|
|
272
|
+
{ role: "user", text: texts.continuation, toolUses: [] },
|
|
273
|
+
] }
|
|
134
274
|
})
|
|
135
275
|
on("prompt.context", async ($, e, next) => {
|
|
136
276
|
const result = await next(e)
|
|
137
277
|
// The reset already retained its boot as the sole conversation message.
|
|
138
278
|
// Prompt context still recomputes, but must not inject a duplicate snapshot.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (!identity)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
279
|
+
const retained = state.retainedBoot !== undefined
|
|
280
|
+
let blocks = retained ? result.blocks.filter((block) => block.name !== "notesoup:boot") : [...result.blocks]
|
|
281
|
+
if (!retained && !blocks.some((block) => block.name === "notesoup:boot") && identity) {
|
|
282
|
+
const texts = await loadTexts($, state)
|
|
283
|
+
const boot = await buildBoot($, identity, state.window, texts)
|
|
284
|
+
if (!boot.ok) {
|
|
285
|
+
try {
|
|
286
|
+
await $.ui.notify("🥣 Notes didn't load")
|
|
287
|
+
} catch { /* Notification failure must not suppress the fallback block. */ }
|
|
288
|
+
}
|
|
289
|
+
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.` }]
|
|
147
290
|
}
|
|
148
|
-
const
|
|
149
|
-
return { ...result, blocks: [...
|
|
291
|
+
const warning = await warningBlock($, state)
|
|
292
|
+
return { ...result, blocks: warning === undefined ? blocks : [...blocks, warning] }
|
|
150
293
|
})
|
|
151
294
|
|
|
152
295
|
}
|
|
153
296
|
|
|
297
|
+
/**
|
|
298
|
+
* The one warning per window: injected only once the measured context crosses the resolved
|
|
299
|
+
* warn point, and only until the window changes. The reset decision runs independently.
|
|
300
|
+
*/
|
|
301
|
+
async function warningBlock($: Engine, state: ResetState): Promise<{ name: string; text: string } | undefined> {
|
|
302
|
+
if (state.headless || state.compactDisabled || !state.identity || state.warnedWindow === state.window) return undefined
|
|
303
|
+
const usage = await contextUsage($, state)
|
|
304
|
+
if (usage === undefined) return undefined
|
|
305
|
+
const limits = await limitsOf($, state, usage)
|
|
306
|
+
if (limits === undefined) return undefined
|
|
307
|
+
const measured = measuredValue(limits, usage)
|
|
308
|
+
if (measured === undefined || measured < limits.warn) return undefined
|
|
309
|
+
const texts = await loadTexts($, state)
|
|
310
|
+
if (texts?.warning === undefined) return undefined
|
|
311
|
+
state.warnedWindow = state.window
|
|
312
|
+
return { name: "notesoup:warning", text: texts.warning }
|
|
313
|
+
}
|
|
314
|
+
|
|
154
315
|
function restoreWindow(state: ResetState, messages: readonly { role: string; text: string }[]) {
|
|
155
316
|
if (!state.identity) return
|
|
156
317
|
const prefix = `Current context window id: claude:${state.identity.sessionId}:`
|
|
@@ -179,60 +340,60 @@ function armManual($: Engine, state: ResetState, signal: { wake?: () => void })
|
|
|
179
340
|
async function finishManual($: Engine, state: ResetState, signal: { wake?: () => void }) {
|
|
180
341
|
try {
|
|
181
342
|
if (state.manualPending && !state.turnRunning) {
|
|
182
|
-
|
|
343
|
+
const texts = await loadTexts($, state)
|
|
344
|
+
if (texts?.warning === undefined) {
|
|
345
|
+
state.manualPending = false
|
|
346
|
+
log($, "Couldn't clear memory: the close-out prompt didn't load")
|
|
347
|
+
return
|
|
348
|
+
}
|
|
349
|
+
await $.prompt.submit({ text: texts.warning })
|
|
183
350
|
}
|
|
184
351
|
} catch {
|
|
185
352
|
state.manualPending = false
|
|
186
|
-
log($, "
|
|
353
|
+
log($, "Couldn't clear memory: the close-out turn didn't start")
|
|
187
354
|
} finally { armManual($, state, signal) }
|
|
188
355
|
}
|
|
189
356
|
|
|
190
357
|
// The sandbox permits $ forwarding only to file-top-level helpers.
|
|
191
358
|
async function maybeReset($: Engine, state: ResetState, complete: boolean) {
|
|
192
|
-
if (!state.identity || state.resetting || state.headless) return
|
|
193
|
-
|
|
194
|
-
try { percent = (await $.session.usage()).context?.percent }
|
|
195
|
-
catch {
|
|
196
|
-
if (!state.usageFailureLogged) {
|
|
197
|
-
state.usageFailureLogged = true
|
|
198
|
-
log($, "context usage unavailable; automatic reset skipped.")
|
|
199
|
-
}
|
|
200
|
-
}
|
|
359
|
+
if (!state.identity || state.resetting || state.headless || state.compactDisabled) return
|
|
360
|
+
const usage = await contextUsage($, state)
|
|
201
361
|
if (state.turnRunning) return
|
|
202
|
-
|
|
362
|
+
let due = complete && state.manualPending
|
|
363
|
+
if (!due && usage !== undefined) {
|
|
364
|
+
const limits = await limitsOf($, state, usage)
|
|
365
|
+
const measured = limits === undefined ? undefined : measuredValue(limits, usage)
|
|
366
|
+
// Missing measurements do not trigger a reset.
|
|
367
|
+
if (limits !== undefined && measured !== undefined && measured >= limits.reset) due = true
|
|
368
|
+
}
|
|
369
|
+
if (due) {
|
|
203
370
|
state.manualPending = false
|
|
204
371
|
await reset($, state)
|
|
205
372
|
}
|
|
206
373
|
}
|
|
207
|
-
async function reset($: Engine, state: ResetState): Promise<
|
|
208
|
-
if (!state.identity
|
|
209
|
-
if (state.headless) return "notesoup: reset skipped in headless (-p / SDK) session."
|
|
210
|
-
if (state.resetting) return "notesoup: reset already in progress."
|
|
374
|
+
async function reset($: Engine, state: ResetState): Promise<void> {
|
|
375
|
+
if (!state.identity || state.headless || state.resetting) return
|
|
211
376
|
state.resetting = true
|
|
212
377
|
state.preparedBoot = undefined
|
|
213
378
|
try {
|
|
214
379
|
const result = await $.session.compact({ instructions: RESET_INSTRUCTIONS })
|
|
215
380
|
if (result.skip !== undefined || state.preparedBoot === undefined) {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return `notesoup: ${text}`
|
|
381
|
+
log($, `Memory not cleared · ${result.skip ?? "notes boot was not retained"}`)
|
|
382
|
+
return
|
|
219
383
|
}
|
|
220
384
|
state.retainedBoot = state.preparedBoot
|
|
221
385
|
state.window++
|
|
222
|
-
log($,
|
|
223
|
-
return `notesoup: memory cleared · window ${state.window}`
|
|
386
|
+
log($, "Memory cleared")
|
|
224
387
|
} catch (error) {
|
|
225
388
|
const text = String(error)
|
|
226
389
|
if (text.includes("headless (-p / SDK)")) {
|
|
227
390
|
state.headless = true
|
|
228
|
-
log($,
|
|
391
|
+
log($, HEADLESS)
|
|
229
392
|
} else if (/a turn is (running|in flight)/.test(text)) {
|
|
230
393
|
state.manualPending = true
|
|
231
|
-
return "notesoup: reset queued until the turn completes."
|
|
232
394
|
} else {
|
|
233
|
-
log($, `
|
|
395
|
+
log($, `Couldn't clear memory: ${text.replace(/[\r\n].*$/s, "")}`)
|
|
234
396
|
}
|
|
235
|
-
return state.headless ? "notesoup: reset skipped in headless (-p / SDK) session." : "notesoup: reset failed; keeping the current window."
|
|
236
397
|
} finally {
|
|
237
398
|
state.preparedBoot = undefined
|
|
238
399
|
state.resetting = false
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Dream
|
|
2
2
|
|
|
3
|
-
I am reviewing my notes: keeping what is useful, connecting what belongs together, and leaving a clearer record for whoever comes next.
|
|
3
|
+
I am reviewing my notes: keeping what is useful, connecting what belongs together, and leaving a clearer record for whoever comes next.
|
|
4
4
|
|
|
5
5
|
## Scope
|
|
6
6
|
|
|
@@ -10,22 +10,22 @@ A project dream draws from that project's material, project notes, and session n
|
|
|
10
10
|
|
|
11
11
|
The homes serve different readers:
|
|
12
12
|
|
|
13
|
-
- Session notes are a trip's working record. Read them as sources where permitted; never edit them, even after promoting a useful finding.
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
13
|
+
- Session notes (`<path>`, no `@`) are a trip's working record. Read them as sources where permitted; never edit them, even after promoting a useful finding.
|
|
14
|
+
- `@project` notes hold knowledge for whoever next works on that project.
|
|
15
|
+
- `@human` notes hold the human's cross-project preferences and standing rules. Do not turn project facts or your own conclusions into rules in the human's voice.
|
|
16
|
+
- `@self` notes belong to their author: private if the author has a name, one shared notebook for everyone nameless. Other named authors' notes are read-only unless the human authorizes revision.
|
|
17
|
+
- `@model` notes describe the substrate's behavior. Other models' notes are read-only unless the human authorizes revision.
|
|
18
18
|
|
|
19
19
|
## Review and consolidate
|
|
20
20
|
|
|
21
|
-
1. **Leave stable notes alone.** Change a note to incorporate new evidence, resolve a verified error, merge a genuine duplicate, or split an oversized file
|
|
21
|
+
1. **Leave stable notes alone.** Change a note to incorporate new evidence, resolve a verified error, merge a genuine duplicate, or split an oversized file, not merely to shorten or rephrase it. No change is a valid outcome.
|
|
22
22
|
2. **Verify only what the proposed change depends on.** Before correcting or promoting a conclusion, check the relevant evidence as needed. Do not revalidate every stable note or turn dream into a source-code audit. An unavailable referent is unverified, not proof that it is dead; do not promote an unsupported claim as current fact.
|
|
23
|
-
3. **Merge only genuine duplicates.** Supersede a note only when both notes have the same topic and kind (checkpoint, design, log
|
|
24
|
-
4. **Relocate misfiled notes.** When a standing ruling or the note's own MAP already names its proper home, migrate it: copy it there preserving frontmatter with a one-line provenance note, crumple the original, and update both homes' maps. Crumple keeps the original readable by address, so relocation is
|
|
23
|
+
3. **Merge only genuine duplicates.** Supersede a note only when both notes have the same topic and kind (checkpoint, design, log), and the survivor is strictly newer or more specific. Name the shared topic in the survivor. Otherwise keep both and record any unresolved conflict.
|
|
24
|
+
4. **Relocate misfiled notes.** When a standing ruling or the note's own MAP already names its proper home, migrate it: copy it there preserving frontmatter with a one-line provenance note, crumple the original, and update both homes' maps. Crumple keeps the original readable by address, so relocation is reversible: do it, don't propose it. Propose only when the destination home itself is unclear.
|
|
25
25
|
5. **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.
|
|
26
26
|
6. **Keep notes manageable.** Aim below about 200 lines / 8KB per note. Split oversized notes by topic with one-line cross-links. Checkpoints may exceed the budget: trim prose, never facts.
|
|
27
27
|
7. **Keep maps useful.** Each writable home's MAP.md lists its durable notes, one line per entry, with an unambiguous address and a short gist in your own words. Add promoted notes and drop entries that no longer hold. Maps follow the same size budget.
|
|
28
|
-
8. **Preserve the record.** Never physically delete a live note; after merging, crumple the absorbed note only if it is writable. The wastebasket is the one exception: physically delete a crumpled note when its home is writable and
|
|
28
|
+
8. **Preserve the record.** Never physically delete a live note; after merging, crumple the absorbed note only if it is writable. The wastebasket is the one exception: physically delete a crumpled note when its home is writable and it has been crumpled and untouched for more than 7 days. With raw frontmatter, judge by `lastAccessed`, falling back to `crumpledAt`. With only `notes_*` tools, judge by `crumpled_at`. If no date is readable, keep the note and report it. Never read a raw note through `notes_read` to get the date: it refreshes `lastAccessed`. A venue that cannot delete files lists the doomed addresses in its report instead of blanking them. Preserve existing metadata and provenance.
|
|
29
29
|
|
|
30
30
|
## Report
|
|
31
31
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dream
|
|
3
|
-
description: Review and consolidate durable notes using notesoup's shared dream playbook. Use when the human asks to dream over notes, merge genuine duplicates, update maps, or promote durable
|
|
3
|
+
description: Review and consolidate durable notes using notesoup's shared dream playbook. Use when the human asks to dream over notes, merge genuine duplicates, update maps, or promote durable findings.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Dream
|
package/package.json
CHANGED
package/playbook.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Dream
|
|
2
2
|
|
|
3
|
-
I am reviewing my notes: keeping what is useful, connecting what belongs together, and leaving a clearer record for whoever comes next.
|
|
3
|
+
I am reviewing my notes: keeping what is useful, connecting what belongs together, and leaving a clearer record for whoever comes next.
|
|
4
4
|
|
|
5
5
|
## Scope
|
|
6
6
|
|
|
@@ -10,22 +10,22 @@ A project dream draws from that project's material, project notes, and session n
|
|
|
10
10
|
|
|
11
11
|
The homes serve different readers:
|
|
12
12
|
|
|
13
|
-
- Session notes are a trip's working record. Read them as sources where permitted; never edit them, even after promoting a useful finding.
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
13
|
+
- Session notes (`<path>`, no `@`) are a trip's working record. Read them as sources where permitted; never edit them, even after promoting a useful finding.
|
|
14
|
+
- `@project` notes hold knowledge for whoever next works on that project.
|
|
15
|
+
- `@human` notes hold the human's cross-project preferences and standing rules. Do not turn project facts or your own conclusions into rules in the human's voice.
|
|
16
|
+
- `@self` notes belong to their author: private if the author has a name, one shared notebook for everyone nameless. Other named authors' notes are read-only unless the human authorizes revision.
|
|
17
|
+
- `@model` notes describe the substrate's behavior. Other models' notes are read-only unless the human authorizes revision.
|
|
18
18
|
|
|
19
19
|
## Review and consolidate
|
|
20
20
|
|
|
21
|
-
1. **Leave stable notes alone.** Change a note to incorporate new evidence, resolve a verified error, merge a genuine duplicate, or split an oversized file
|
|
21
|
+
1. **Leave stable notes alone.** Change a note to incorporate new evidence, resolve a verified error, merge a genuine duplicate, or split an oversized file, not merely to shorten or rephrase it. No change is a valid outcome.
|
|
22
22
|
2. **Verify only what the proposed change depends on.** Before correcting or promoting a conclusion, check the relevant evidence as needed. Do not revalidate every stable note or turn dream into a source-code audit. An unavailable referent is unverified, not proof that it is dead; do not promote an unsupported claim as current fact.
|
|
23
|
-
3. **Merge only genuine duplicates.** Supersede a note only when both notes have the same topic and kind (checkpoint, design, log
|
|
24
|
-
4. **Relocate misfiled notes.** When a standing ruling or the note's own MAP already names its proper home, migrate it: copy it there preserving frontmatter with a one-line provenance note, crumple the original, and update both homes' maps. Crumple keeps the original readable by address, so relocation is
|
|
23
|
+
3. **Merge only genuine duplicates.** Supersede a note only when both notes have the same topic and kind (checkpoint, design, log), and the survivor is strictly newer or more specific. Name the shared topic in the survivor. Otherwise keep both and record any unresolved conflict.
|
|
24
|
+
4. **Relocate misfiled notes.** When a standing ruling or the note's own MAP already names its proper home, migrate it: copy it there preserving frontmatter with a one-line provenance note, crumple the original, and update both homes' maps. Crumple keeps the original readable by address, so relocation is reversible: do it, don't propose it. Propose only when the destination home itself is unclear.
|
|
25
25
|
5. **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.
|
|
26
26
|
6. **Keep notes manageable.** Aim below about 200 lines / 8KB per note. Split oversized notes by topic with one-line cross-links. Checkpoints may exceed the budget: trim prose, never facts.
|
|
27
27
|
7. **Keep maps useful.** Each writable home's MAP.md lists its durable notes, one line per entry, with an unambiguous address and a short gist in your own words. Add promoted notes and drop entries that no longer hold. Maps follow the same size budget.
|
|
28
|
-
8. **Preserve the record.** Never physically delete a live note; after merging, crumple the absorbed note only if it is writable. The wastebasket is the one exception: physically delete a crumpled note when its home is writable and
|
|
28
|
+
8. **Preserve the record.** Never physically delete a live note; after merging, crumple the absorbed note only if it is writable. The wastebasket is the one exception: physically delete a crumpled note when its home is writable and it has been crumpled and untouched for more than 7 days. With raw frontmatter, judge by `lastAccessed`, falling back to `crumpledAt`. With only `notes_*` tools, judge by `crumpled_at`. If no date is readable, keep the note and report it. Never read a raw note through `notes_read` to get the date: it refreshes `lastAccessed`. A venue that cannot delete files lists the doomed addresses in its report instead of blanking them. Preserve existing metadata and provenance.
|
|
29
29
|
|
|
30
30
|
## Report
|
|
31
31
|
|
package/skills/dream/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: dream
|
|
3
|
-
description: Review and consolidate durable notes using notesoup's shared dream playbook. Use when the human asks to dream over notes, merge genuine duplicates, update maps, or promote durable
|
|
3
|
+
description: Review and consolidate durable notes using notesoup's shared dream playbook. Use when the human asks to dream over notes, merge genuine duplicates, update maps, or promote durable findings.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Dream
|
package/skills/memory/SKILL.md
CHANGED
|
@@ -21,12 +21,14 @@ The address decides who a note belongs to and how long it lasts.
|
|
|
21
21
|
| `<path>`, no `@` | session note | current task state and loose ends; gone with the session |
|
|
22
22
|
| `@project/<path>` | project note | decisions and constraints future work must respect |
|
|
23
23
|
| `@human/<path>` | human note | how to work with this human, across projects |
|
|
24
|
-
| `@self/<path>` | self note |
|
|
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
|
|
|
27
|
+
When notes conflict, the one most relevant to what you're doing applies. If that doesn't settle it, judge the case.
|
|
28
|
+
|
|
27
29
|
Any other `@` prefix is refused. A path is relative and `/`-separated, with no empty, `.` or `..` segments.
|
|
28
30
|
|
|
29
|
-
`@` addresses
|
|
31
|
+
`@` 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.
|
|
30
32
|
|
|
31
33
|
`MAP.md` at the root of each `@` home is its index: one line per durable note, address and gist. Update it whenever you add, move or crumple a durable note.
|
|
32
34
|
|
|
@@ -42,7 +44,7 @@ Seqs are stable. Write the useful ones into a note so they need not be found twi
|
|
|
42
44
|
|
|
43
45
|
## Saving recovery state
|
|
44
46
|
|
|
45
|
-
Before a long or risky step, or when room runs low, keep
|
|
47
|
+
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 to the current state instead of starting new ones or appending a timeline. Record:
|
|
46
48
|
|
|
47
49
|
- the goal and the current step
|
|
48
50
|
- decisions made, and why
|
package/src/boot/render.ts
CHANGED
|
@@ -60,7 +60,7 @@ function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames): string {
|
|
|
60
60
|
const shelves: string[] = [];
|
|
61
61
|
for (const home of homes) {
|
|
62
62
|
if (snapshot.unavailable.some((failed) => failed.scope === home.scope)) {
|
|
63
|
-
shelves.push(section(home.label, indent(`This drawer wouldn't open
|
|
63
|
+
shelves.push(section(home.label, indent(`This drawer wouldn't open. Try \`${tools.notesList}\` again.`)));
|
|
64
64
|
continue;
|
|
65
65
|
}
|
|
66
66
|
const rows = rowsFor(snapshot, home.scope).filter((row) => row.meta.crumpledAt === undefined);
|
package/src/boot/text.ts
CHANGED
|
@@ -6,6 +6,14 @@ export const CONTEXT_WINDOW_OPEN_TAG = "<context_window>";
|
|
|
6
6
|
export const CONTEXT_WINDOW_CLOSE_TAG = "</context_window>";
|
|
7
7
|
export const CONTEXT_WINDOW_PROTOCOL_OPEN_TAG = "<context_window_protocol>";
|
|
8
8
|
export const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
|
|
9
|
+
/**
|
|
10
|
+
* The one sentence that tells the model how to end its window voluntarily. A host with no
|
|
11
|
+
* model-facing reset tool replaces the whole sentence through BootToolNames.wipeSentence.
|
|
12
|
+
*/
|
|
13
|
+
export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `clear_memory` 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 `/clear-memory`.";
|
|
16
|
+
|
|
9
17
|
/**
|
|
10
18
|
* Static protocol teaching adapted from Codex's token_budget.guidance_message to
|
|
11
19
|
* notesoup's tool names. It lives once per window in the persisted boot block;
|
|
@@ -21,18 +29,26 @@ Your loyal notes are kept safe — no one will steal them. Use \`notes_*\` to re
|
|
|
21
29
|
|
|
22
30
|
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.
|
|
23
31
|
|
|
24
|
-
While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's
|
|
32
|
+
While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's your session notes — the ones with no \`@\` in front. Write down what git and history can't hand back to you: things like what you're in the middle of and how far you got; what the human already decided, in their words, so you don't go asking again; what you're stuck on, or waiting for; the very next move; where the half-done work actually sits — branches, scratch dirs, anything git never saw; what you tried that failed, and why; which *skills* you'll need to read again; and which seq, note, or file to dig into. Don't give a note a horrible name like \`current.md\`; future-you will kill you.
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
Notes are for what's true NOW. Not a diary of every dumb thing you did on the way here.
|
|
35
|
+
*flips a page* "First I tried this, then that broke, then—" Nobody reads that!
|
|
36
|
+
Something's not true anymore? Cross it out! Write the right thing!
|
|
37
|
+
|
|
38
|
+
\`get_context_remaining\` tells you how much room is left. Check it before you do something ambitious. When it reaches zero, your brain gets reset immediately, taking every unwritten brilliant idea with it. ${PROTOCOL_WIPE_SENTENCE}
|
|
27
39
|
|
|
28
40
|
An address decides who the note belongs to — and how long it is meant to last. Ask that first; the rest follows.
|
|
29
41
|
|
|
30
|
-
- \`<path>\`, no @ — the
|
|
42
|
+
- \`<path>\`, no @ — session notes, the ones from above: this session's state and loose ends. They go away with the session.
|
|
31
43
|
- \`@project/<path>\` — this project's long memory: what stays true after the current thing is over, what future work must respect, and the rakes already stepped on. **Decisions, not diaries.** Commit hashes, test counts, dates, the story of how you got here: git and history already have them, and last week's news filed as current law is worse than no note. Don't copy what other docs already say.
|
|
32
44
|
- \`@human/<path>\` — the long-term manual for your troublesome human: how to deal with them, which lines not to cross, and what will make them accept the result. If it only applies to one project or situation, say so — or don't write it here at all. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
|
|
33
|
-
- \`@self/<path>\` —
|
|
45
|
+
- \`@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~
|
|
34
46
|
- \`@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.
|
|
35
47
|
|
|
48
|
+
Notes fighting?! HAH! Let them brawl!
|
|
49
|
+
Whichever one is actually about what you're doing wins.
|
|
50
|
+
Still a tie? *shrugs* You've got a brain. Use it.
|
|
51
|
+
|
|
36
52
|
Any other @ address is fake. End of discussion. @ addresses are not file paths: never pass them to file tools like \`read\`, \`write\`, \`edit\`, or \`bash\`.
|
|
37
53
|
|
|
38
54
|
\`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each one maps the durable notes that belong to it: one line per note, with an unambiguous address and a short gist. Keep each one current.
|
|
@@ -45,6 +61,11 @@ export type BootToolNames = Readonly<{
|
|
|
45
61
|
history: string;
|
|
46
62
|
remaining: string;
|
|
47
63
|
wipe: string;
|
|
64
|
+
/**
|
|
65
|
+
* Replaces the whole voluntary-wipe sentence (PROTOCOL_WIPE_SENTENCE) when the host has
|
|
66
|
+
* no model-facing reset tool. Absent means Pi's default sentence, byte for byte.
|
|
67
|
+
*/
|
|
68
|
+
wipeSentence?: string;
|
|
48
69
|
}>;
|
|
49
70
|
|
|
50
71
|
export function renderProtocolBlock(tools: BootToolNames): string {
|
|
@@ -54,5 +75,10 @@ export function renderProtocolBlock(tools: BootToolNames): string {
|
|
|
54
75
|
get_context_remaining: tools.remaining,
|
|
55
76
|
clear_memory: tools.wipe,
|
|
56
77
|
};
|
|
57
|
-
|
|
78
|
+
// The sentence is replaced before name substitution, so a replacement may speak the host's
|
|
79
|
+
// own words (a command line, a tool name) instead of any `notes_*`-style token.
|
|
80
|
+
const block = typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
|
|
81
|
+
? PROTOCOL_BLOCK.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence!)
|
|
82
|
+
: PROTOCOL_BLOCK;
|
|
83
|
+
return block.replace(/notes_\*|history_\*|get_context_remaining|clear_memory/g, (name) => names[name]!);
|
|
58
84
|
}
|
package/src/budget/policy.ts
CHANGED
|
@@ -23,7 +23,7 @@ export function deriveThresholds(reserveTokens: number, margins: NotesoupSetting
|
|
|
23
23
|
else {
|
|
24
24
|
const parsed = validMargin(margins.reminderMarginTokens);
|
|
25
25
|
if (parsed === undefined) {
|
|
26
|
-
warnings.push(
|
|
26
|
+
warnings.push(`🥣 ${reminderKey} must be a positive integer · using the default`);
|
|
27
27
|
reminderMargin = DEFAULT_REMINDER_MARGIN_TOKENS;
|
|
28
28
|
} else reminderMargin = parsed;
|
|
29
29
|
}
|