notesoup 0.53.1 → 0.54.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/README.md +2 -2
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/claude/src/history.js +2 -3
- package/dist/plugins/claude/src/thresholds.js +4 -2
- package/dist/plugins/codex/src/hooks.js +1 -1
- package/dist/plugins/codex/src/identity.d.ts +1 -1
- package/dist/plugins/codex/src/identity.js +3 -3
- package/dist/plugins/codex/src/mcp.js +2 -1
- package/dist/plugins/codex/src/text.d.ts +1 -1
- package/dist/plugins/codex/src/text.js +2 -2
- package/dist/plugins/dsh/engine.js +2 -2
- package/dist/plugins/dsh/tools.js +8 -7
- package/dist/plugins/dsh/window.d.ts +1 -0
- package/dist/plugins/dsh/window.js +7 -3
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +4 -4
- package/dist/plugins/pi/marker.d.ts +9 -0
- package/dist/plugins/pi/marker.js +36 -0
- package/dist/plugins/pi/notes/tools.js +8 -6
- package/dist/plugins/pi/render.js +7 -4
- package/dist/plugins/pi/reset/artifacts.d.ts +2 -2
- package/dist/plugins/pi/reset/artifacts.js +2 -2
- package/dist/plugins/pi/runtime.js +11 -8
- package/dist/plugins/pi/text.d.ts +2 -0
- package/dist/plugins/pi/text.js +4 -0
- package/dist/plugins/pi/window.js +21 -7
- package/dist/src/boot/render.js +7 -7
- package/dist/src/boot/snapshot.d.ts +7 -7
- package/dist/src/boot/snapshot.js +17 -17
- package/dist/src/boot/text.d.ts +2 -2
- package/dist/src/boot/text.js +7 -5
- package/dist/src/dream/git.d.ts +2 -11
- package/dist/src/dream/git.js +6 -23
- package/dist/src/dream/lock.d.ts +2 -2
- package/dist/src/dream/lock.js +3 -3
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +3 -2
- package/dist/src/notes/address.d.ts +8 -8
- package/dist/src/notes/address.js +13 -13
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.js +2 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/paths.d.ts +6 -6
- package/dist/src/notes/paths.js +9 -9
- package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
- package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
- package/dist/src/notes/store.d.ts +4 -4
- package/dist/src/notes/store.js +55 -52
- package/dist/src/tools/dream.d.ts +21 -3
- package/dist/src/tools/dream.js +54 -16
- package/dist/src/tools/notes-context.d.ts +10 -0
- package/dist/src/tools/notes-context.js +27 -0
- package/dist/src/tools/notes.d.ts +69 -20
- package/dist/src/tools/notes.js +40 -31
- package/dist/test/agent-loop.test.js +8 -8
- package/dist/test/boot.integration.test.js +5 -5
- package/dist/test/claude-history.test.js +26 -0
- package/dist/test/claude-mod.test.js +257 -86
- package/dist/test/codex-plugin.test.js +18 -1
- package/dist/test/context-edit-budget.test.js +121 -0
- package/dist/test/dependencies.test.js +71 -4
- package/dist/test/dream-tools.test.js +153 -8
- package/dist/test/dsh.test.js +62 -15
- package/dist/test/helpers/dsh.d.ts +4 -1
- package/dist/test/helpers/dsh.js +20 -4
- package/dist/test/helpers/extension.d.ts +5 -0
- package/dist/test/helpers/extension.js +33 -2
- package/dist/test/host-neutral.test.js +17 -15
- package/dist/test/marker.test.js +78 -0
- package/dist/test/model-facing-text.test.js +12 -8
- package/dist/test/notes-cwd.test.d.ts +1 -0
- package/dist/test/notes-cwd.test.js +114 -0
- package/dist/test/notes-library.test.js +4 -4
- package/dist/test/notes-query-namespaces.test.d.ts +1 -0
- package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
- package/dist/test/notes.integration.test.js +72 -23
- package/dist/test/notes.test.js +50 -20
- package/dist/test/pi-render.test.js +33 -1
- package/dist/test/project-namespace.test.d.ts +1 -0
- package/dist/test/project-namespace.test.js +324 -0
- package/dist/test/reset-lifecycle.test.js +12 -0
- package/docs/architecture.md +13 -8
- package/docs/claude-code-mod.md +7 -7
- package/docs/codex.md +4 -4
- package/docs/dsh.md +8 -8
- package/docs/notes-library.md +9 -5
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +6 -2
- package/package.json +4 -6
- package/playbook.md +6 -6
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +681 -617
- package/plugins/claude/hooks/register.ts +61 -65
- package/plugins/claude/playbook.md +6 -6
- package/plugins/claude/skills/memory/SKILL.md +4 -4
- package/plugins/claude/src/helper.ts +3 -2
- package/plugins/claude/src/history.ts +2 -3
- package/plugins/claude/src/thresholds.ts +4 -2
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +877 -815
- package/plugins/codex/src/hooks.ts +1 -1
- package/plugins/codex/src/identity.ts +3 -3
- package/plugins/codex/src/mcp.ts +2 -1
- package/plugins/codex/src/text.ts +2 -2
- package/plugins/dsh/engine.ts +2 -2
- package/plugins/dsh/tools.ts +8 -7
- package/plugins/dsh/window.ts +8 -3
- package/plugins/paseo/OVERVIEW.md +4 -4
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/brain-empty-card.tsx +3 -4
- package/plugins/paseo/client/markdown.tsx +179 -0
- package/plugins/paseo/client/notes-op-card.tsx +35 -34
- package/plugins/paseo/client/notes-op-transformer.ts +17 -68
- package/plugins/paseo/client/paper-card.tsx +8 -19
- package/plugins/paseo/client/paper-palette.ts +40 -0
- package/plugins/paseo/client/sticky-card.tsx +6 -4
- package/plugins/paseo/package.json +3 -0
- package/plugins/paseo/paseo-plugin.json +2 -2
- package/plugins/paseo/shared/notes-op.ts +13 -9
- package/plugins/paseo/test/notes-op.test.ts +52 -73
- package/plugins/paseo/test/paper-palette.test.ts +54 -0
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +4 -4
- package/plugins/pi/marker.ts +39 -0
- package/plugins/pi/notes/tools.ts +8 -6
- package/plugins/pi/render.ts +6 -4
- package/plugins/pi/reset/artifacts.ts +2 -2
- package/plugins/pi/runtime.ts +9 -8
- package/plugins/pi/text.ts +5 -0
- package/plugins/pi/window.ts +22 -7
- package/skills/memory/SKILL.md +4 -4
- package/src/boot/render.ts +8 -8
- package/src/boot/snapshot.ts +20 -20
- package/src/boot/text.ts +7 -5
- package/src/dream/git.ts +7 -24
- package/src/dream/lock.ts +3 -3
- package/src/index.ts +4 -3
- package/src/notes/address.ts +13 -13
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +2 -2
- package/src/notes/index.ts +1 -1
- package/src/notes/paths.ts +9 -9
- package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
- package/src/notes/store.ts +61 -58
- package/src/tools/dream.ts +63 -16
- package/src/tools/notes-context.ts +29 -0
- package/src/tools/notes.ts +39 -29
- package/dist/test/project-home.test.js +0 -134
- /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
- /package/dist/test/{project-home.test.d.ts → marker.test.d.ts} +0 -0
|
@@ -8,7 +8,7 @@ const OUTPUT_LIMIT = 1024 * 1024
|
|
|
8
8
|
type Identity = { home: string; sessionId: string; cwd: string; agent: string; model: string }
|
|
9
9
|
type SchemaRow = { name: string; description: string; inputSchema: Record<string, unknown> }
|
|
10
10
|
type HistorySource = { sessionId: string; transcriptPath: string; headUuid?: string }
|
|
11
|
-
type Engine = Pick<EngineInterface, "process" | "session" | "ui" | "clock" | "prompt" | "env" | "settings">
|
|
11
|
+
type Engine = Pick<EngineInterface, "process" | "session" | "ui" | "clock" | "prompt" | "env" | "settings" | "command">
|
|
12
12
|
/** The measured context, as much of it as the engine reported. */
|
|
13
13
|
type ContextUsage = { tokens?: number; window?: number; percent?: number }
|
|
14
14
|
/** Shared reset prose, fetched once per session so Pi and Claude cannot drift apart. */
|
|
@@ -20,15 +20,14 @@ type ClaudeLimits = {
|
|
|
20
20
|
type ResetState = {
|
|
21
21
|
identity?: Identity; history?: HistorySource; historyWindowHead?: string; generation: number; window: number; disabled: boolean; turnRunning: boolean; resetting: boolean
|
|
22
22
|
manualPending: boolean; headless: boolean; usageFailureLogged: boolean; preparedBoot?: string; retainedBoot?: string
|
|
23
|
-
toolResetRequested?: boolean; lastWord?: string
|
|
23
|
+
toolResetRequested?: boolean; lastWord?: string; manualCompacting?: boolean
|
|
24
24
|
continuation?: string; continuationWindow?: number
|
|
25
25
|
compactDisabled: boolean; limitsFailureLogged: boolean; limitsAttempts: number; limitsWindow: number
|
|
26
26
|
limits?: ClaudeLimits; warnedWindow?: number; warningPending?: number; texts?: SharedTexts; settingsFailureLogged: boolean
|
|
27
27
|
}
|
|
28
|
-
const HEADLESS = "No brain when headless"
|
|
29
28
|
const COMPACT_DISABLED = "Brain can't be emptied with DISABLE_COMPACT"
|
|
30
29
|
const NOTESOUP_DISABLED = "Notesoup is off with NOTESOUP_DISABLED"
|
|
31
|
-
const THRESHOLDS_UNAVAILABLE = "Brain size unknown · no
|
|
30
|
+
const THRESHOLDS_UNAVAILABLE = "Brain size unknown · no budget warning"
|
|
32
31
|
const SETTINGS_UNAVAILABLE = "Notesoup settings unreadable · using the default flush margins"
|
|
33
32
|
/** Bounded retries: a transient helper failure must not disable thresholds for a whole window. */
|
|
34
33
|
const MAX_LIMITS_ATTEMPTS = 3
|
|
@@ -130,15 +129,15 @@ async function contextUsage($: Engine, state: ResetState): Promise<ContextUsage
|
|
|
130
129
|
} catch {
|
|
131
130
|
if (!state.usageFailureLogged) {
|
|
132
131
|
state.usageFailureLogged = true
|
|
133
|
-
log($, "Brain fullness unknown · no
|
|
132
|
+
log($, "Brain fullness unknown · no budget warning")
|
|
134
133
|
}
|
|
135
134
|
return undefined
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
async function breakdownContext($: Engine): Promise<Record<string, unknown> | undefined> {
|
|
139
138
|
try {
|
|
140
|
-
const
|
|
141
|
-
return typeof
|
|
139
|
+
const breakdown = (await $.session.usage({ breakdown: "summary" })).context.breakdown
|
|
140
|
+
return typeof breakdown === "object" && breakdown !== null ? breakdown as unknown as Record<string, unknown> : undefined
|
|
142
141
|
} catch { return undefined }
|
|
143
142
|
}
|
|
144
143
|
/** Everything the resolver may read: measured usage plus the raw settings and environment. */
|
|
@@ -248,19 +247,23 @@ async function run($: { process: { run: (argv: readonly string[], init?: { cwd?:
|
|
|
248
247
|
// reason (`timed out after …`), which a bare phrase would throw away.
|
|
249
248
|
catch (error) { return { ok: false as const, error: `helper execution failed: ${describeFailure(error)}` } }
|
|
250
249
|
}
|
|
250
|
+
function clearManualRequest(state: ResetState): void {
|
|
251
|
+
state.manualPending = false
|
|
252
|
+
state.toolResetRequested = state.lastWord = undefined
|
|
253
|
+
}
|
|
251
254
|
/** Session start does not fire on /clear, /resume or /branch. Forget the old window on end. */
|
|
252
255
|
function forgetSession(state: ResetState) {
|
|
253
256
|
state.generation++
|
|
254
257
|
state.identity = undefined
|
|
255
258
|
state.historyWindowHead = undefined
|
|
256
259
|
state.window = 0
|
|
257
|
-
state.turnRunning = state.resetting = state.
|
|
260
|
+
state.turnRunning = state.resetting = state.usageFailureLogged = false
|
|
261
|
+
clearManualRequest(state)
|
|
262
|
+
state.manualCompacting = false
|
|
258
263
|
state.preparedBoot = state.retainedBoot = undefined
|
|
259
264
|
state.texts = state.limits = undefined
|
|
260
265
|
state.continuation = undefined
|
|
261
266
|
state.continuationWindow = undefined
|
|
262
|
-
state.toolResetRequested = undefined
|
|
263
|
-
state.lastWord = undefined
|
|
264
267
|
state.limitsAttempts = state.limitsWindow = 0
|
|
265
268
|
state.settingsFailureLogged = state.limitsFailureLogged = false
|
|
266
269
|
state.warnedWindow = state.warningPending = undefined
|
|
@@ -345,8 +348,7 @@ export function register(on: On) {
|
|
|
345
348
|
keepMemory = envFlag(await $.env.get("NOTESOUP_KEEP_MEMORY").catch(() => undefined))
|
|
346
349
|
await refreshIdentity($, state)
|
|
347
350
|
state.headless = !e.isInteractive
|
|
348
|
-
|
|
349
|
-
// Compaction is the capability the reset is built on; without it, automatic resets stop here.
|
|
351
|
+
// Compaction is the capability explicit resets and budget warnings depend on.
|
|
350
352
|
state.compactDisabled = await compactDisabled($)
|
|
351
353
|
if (state.compactDisabled) log($, COMPACT_DISABLED)
|
|
352
354
|
registered.clear()
|
|
@@ -357,7 +359,7 @@ export function register(on: On) {
|
|
|
357
359
|
const wipe = await $.tool.register({
|
|
358
360
|
name: "empty_brain",
|
|
359
361
|
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.",
|
|
360
|
-
inputSchema: { type: "object", properties: { last_word: { type: "string", description: "A tiny sticky note, at most
|
|
362
|
+
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." } }, additionalProperties: false },
|
|
361
363
|
isDeferred: false,
|
|
362
364
|
} satisfies ToolSpec)
|
|
363
365
|
registered.add(wipe.tool)
|
|
@@ -395,33 +397,36 @@ export function register(on: On) {
|
|
|
395
397
|
on("turn.complete", async ($, e, next) => {
|
|
396
398
|
const result = await next(e)
|
|
397
399
|
if (e.agentId !== undefined) return result
|
|
400
|
+
state.turnRunning = false
|
|
398
401
|
if (state.disabled) return result
|
|
402
|
+
// A failed turn proves nothing about whether its notes were saved. Cancel
|
|
403
|
+
// the request instead of compacting now or springing it on a later turn.
|
|
404
|
+
if (e.reason !== "answer" && state.manualPending) cancelManualReset($, state, e.reason)
|
|
399
405
|
if (!await refreshIdentity($, state)) return result
|
|
400
|
-
state.
|
|
401
|
-
await maybeReset($, state, true)
|
|
402
|
-
return result
|
|
403
|
-
})
|
|
404
|
-
on("session.measure", async ($, e, next) => {
|
|
405
|
-
const result = await next(e)
|
|
406
|
-
if (!state.disabled && await refreshIdentity($, state)) await maybeReset($, state, false)
|
|
406
|
+
if (e.reason === "answer" && state.manualPending) await reset($, state)
|
|
407
407
|
return result
|
|
408
408
|
})
|
|
409
409
|
on("command.run", async ($, e, next) => {
|
|
410
410
|
if (state.disabled) return next(e)
|
|
411
|
+
// Only our queued native command admits manual compaction. A user's /compact
|
|
412
|
+
// still reaches the veto, even while a reset is pending.
|
|
413
|
+
if (e.command === "compact" && state.resetting && state.headless && e.origin.kind === "plugin" && e.origin.name === "notesoup") {
|
|
414
|
+
state.manualCompacting = true
|
|
415
|
+
try { return await next(e) } finally { state.manualCompacting = false }
|
|
416
|
+
}
|
|
411
417
|
if (e.command !== "empty" && e.command !== "fresh-window") return next(e)
|
|
412
418
|
if (!await refreshIdentity($, state)) return { text: "🥣 Different brain now · try /fresh-window again" }
|
|
413
|
-
if (state.headless) return { text: `🥣 ${HEADLESS}` }
|
|
414
419
|
if (state.compactDisabled) return { text: `🥣 ${COMPACT_DISABLED}` }
|
|
415
420
|
if (state.resetting || state.manualPending) return { text: "🥣 Brain already being emptied" }
|
|
416
421
|
if (state.turnRunning) {
|
|
417
422
|
state.manualPending = true
|
|
418
|
-
return { text: "🥣 Brain
|
|
423
|
+
return { text: "🥣 Dumping Brain" }
|
|
419
424
|
}
|
|
420
425
|
// command.run holds a turn even when idle. Start one hidden close-out
|
|
421
426
|
// turn after it returns; turn.complete is the verified self-hook path.
|
|
422
427
|
state.manualPending = true
|
|
423
428
|
manualSignal.wake?.()
|
|
424
|
-
return { text: "🥣 Brain
|
|
429
|
+
return { text: "🥣 Dumping Brain" }
|
|
425
430
|
})
|
|
426
431
|
on("session.compact", async ($, e, next) => {
|
|
427
432
|
// Disabled means fully transparent: native compaction runs exactly as if the mod were absent.
|
|
@@ -439,11 +444,11 @@ export function register(on: On) {
|
|
|
439
444
|
}
|
|
440
445
|
return result
|
|
441
446
|
}
|
|
442
|
-
// Native compaction never runs the summarizer while notesoup is on:
|
|
443
|
-
// precompute are vetoed
|
|
444
|
-
|
|
447
|
+
// Native compaction never runs the summarizer while notesoup is on: user
|
|
448
|
+
// manual and precompute are vetoed; auto becomes the notes-only reset.
|
|
449
|
+
const own = state.resetting && identity !== undefined && (e.trigger === "plugin" || (e.trigger === "manual" && state.manualCompacting === true))
|
|
450
|
+
if (e.trigger === "manual" && !own) return { skip: "No compacting brains here · use /fresh-window" }
|
|
445
451
|
if (e.trigger === "precompute") return { skip: "No precomputing brains here" }
|
|
446
|
-
const own = state.resetting && e.trigger === "plugin" && identity !== undefined
|
|
447
452
|
if (!own && e.trigger !== "auto") return passThrough()
|
|
448
453
|
if (identity === undefined) return passThrough()
|
|
449
454
|
const built = await resetMessages($, state, identity)
|
|
@@ -460,9 +465,7 @@ export function register(on: On) {
|
|
|
460
465
|
state.retainedBoot = built.boot
|
|
461
466
|
state.preparedBoot = undefined
|
|
462
467
|
state.window++
|
|
463
|
-
state
|
|
464
|
-
state.toolResetRequested = undefined
|
|
465
|
-
state.lastWord = undefined
|
|
468
|
+
clearManualRequest(state)
|
|
466
469
|
log($, "Brain emptied")
|
|
467
470
|
}
|
|
468
471
|
return { messages: built.messages }
|
|
@@ -506,12 +509,11 @@ async function callNotesTool($: Engine, state: ResetState, e: ToolCallInput): Pr
|
|
|
506
509
|
const name = tool.slice(PREFIX.length)
|
|
507
510
|
if (name === "empty_brain") {
|
|
508
511
|
if (agentId !== undefined) return errorResult("only the main agent can empty this brain")
|
|
509
|
-
if (state.headless) return errorResult(HEADLESS)
|
|
510
512
|
if (state.compactDisabled) return errorResult(COMPACT_DISABLED)
|
|
511
513
|
if (params.last_word !== undefined && typeof params.last_word !== "string") return errorResult("last_word must be a string")
|
|
512
514
|
const lastWord = typeof params.last_word === "string" ? params.last_word.trim() || undefined : undefined
|
|
513
515
|
const length = lastWord ? Array.from(lastWord).length : 0
|
|
514
|
-
if (length >
|
|
516
|
+
if (length > 500) return errorResult(`last_word is ${length} characters; the sticky note holds 500. Shorten it and call again.`)
|
|
515
517
|
if (!state.toolResetRequested) {
|
|
516
518
|
state.toolResetRequested = true
|
|
517
519
|
state.lastWord = lastWord
|
|
@@ -531,7 +533,7 @@ async function callNotesTool($: Engine, state: ResetState, e: ToolCallInput): Pr
|
|
|
531
533
|
|
|
532
534
|
/** Read the warning without consuming this window's delivery. */
|
|
533
535
|
async function warningText($: Engine, state: ResetState): Promise<string | undefined> {
|
|
534
|
-
if (state.disabled || state.
|
|
536
|
+
if (state.disabled || state.compactDisabled || !state.identity || state.warnedWindow === state.window || state.warningPending === state.window) return undefined
|
|
535
537
|
const generation = state.generation
|
|
536
538
|
const usage = await contextUsage($, state)
|
|
537
539
|
if (generation !== state.generation || usage === undefined) return undefined
|
|
@@ -545,7 +547,7 @@ async function warningText($: Engine, state: ResetState): Promise<string | undef
|
|
|
545
547
|
|
|
546
548
|
/** Reserve across next(), but consume only context the chain actually accepted. */
|
|
547
549
|
async function withWarning<T extends { context?: readonly string[]; drop?: string; deny?: string }>($: Engine, state: ResetState, deliver: (warning?: string) => T | Promise<T>): Promise<T> {
|
|
548
|
-
if (state.disabled || state.
|
|
550
|
+
if (state.disabled || state.compactDisabled || !await refreshIdentity($, state)) return deliver()
|
|
549
551
|
const generation = state.generation, window = state.window
|
|
550
552
|
const warning = await warningText($, state)
|
|
551
553
|
if (warning === undefined || generation !== state.generation || window !== state.window || state.warnedWindow === window || state.warningPending === window) return deliver()
|
|
@@ -600,7 +602,6 @@ async function finishManual($: Engine, state: ResetState, signal: { wake?: () =>
|
|
|
600
602
|
const texts = await loadTexts($, state)
|
|
601
603
|
if (generation !== state.generation) return
|
|
602
604
|
if (texts?.warning === undefined) {
|
|
603
|
-
state.manualPending = false
|
|
604
605
|
log($, "Brain still full: the close-out prompt didn't load")
|
|
605
606
|
return
|
|
606
607
|
}
|
|
@@ -608,56 +609,51 @@ async function finishManual($: Engine, state: ResetState, signal: { wake?: () =>
|
|
|
608
609
|
}
|
|
609
610
|
} catch {
|
|
610
611
|
if (generation === state.generation) {
|
|
611
|
-
state.manualPending = false
|
|
612
612
|
log($, "Brain still full: the close-out turn didn't start")
|
|
613
613
|
}
|
|
614
614
|
} finally { armManual($, state, signal) }
|
|
615
615
|
}
|
|
616
616
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
const usage = await contextUsage($, state)
|
|
622
|
-
if (generation !== state.generation || state.turnRunning) return
|
|
623
|
-
let due = complete && state.manualPending
|
|
624
|
-
if (!due && usage !== undefined) {
|
|
625
|
-
const limits = await limitsOf($, state, usage)
|
|
626
|
-
const measured = limits === undefined ? undefined : measuredValue(limits, usage)
|
|
627
|
-
// Missing measurements do not trigger a reset.
|
|
628
|
-
if (limits !== undefined && measured !== undefined && measured >= limits.reset) due = true
|
|
629
|
-
}
|
|
630
|
-
if (due && generation === state.generation) {
|
|
631
|
-
state.manualPending = false
|
|
632
|
-
await reset($, state)
|
|
633
|
-
}
|
|
617
|
+
/** A non-answer ends the request, never the context; the user can explicitly ask again. */
|
|
618
|
+
function cancelManualReset($: Engine, state: ResetState, reason: "aborted" | "refusal" | "error"): void {
|
|
619
|
+
clearManualRequest(state)
|
|
620
|
+
log($, `Brain emptying cancelled · turn ended ${reason}; ask /fresh-window again`)
|
|
634
621
|
}
|
|
622
|
+
|
|
623
|
+
// The sandbox permits $ forwarding only to file-top-level helpers.
|
|
635
624
|
async function reset($: Engine, state: ResetState): Promise<void> {
|
|
636
|
-
if (!state.identity || state.
|
|
625
|
+
if (!state.identity || state.compactDisabled || state.resetting) return
|
|
637
626
|
const generation = state.generation
|
|
638
627
|
state.resetting = true
|
|
639
628
|
state.preparedBoot = undefined
|
|
640
629
|
try {
|
|
641
|
-
|
|
630
|
+
let failure: string | undefined
|
|
631
|
+
if (state.headless) {
|
|
632
|
+
const receipt = await $.command.run({ command: "compact" })
|
|
633
|
+
if (generation !== state.generation) return
|
|
634
|
+
// A command receipt is not SessionCompacted. Our admitted hook must have
|
|
635
|
+
// prepared the boot; session.messages() here still reads the completed
|
|
636
|
+
// turn's snapshot, not the next request's newly compacted context.
|
|
637
|
+
if (state.preparedBoot === undefined) failure = receipt.text ?? "notes boot was not retained"
|
|
638
|
+
} else {
|
|
639
|
+
const result = await $.session.compact({ instructions: RESET_INSTRUCTIONS })
|
|
640
|
+
failure = result.skip
|
|
641
|
+
}
|
|
642
642
|
if (generation !== state.generation) return
|
|
643
|
-
if (
|
|
644
|
-
|
|
643
|
+
if (failure !== undefined || state.preparedBoot === undefined) {
|
|
644
|
+
state.manualPending = true
|
|
645
|
+
log($, `Brain not emptied · ${failure ?? "notes boot was not retained"}`)
|
|
645
646
|
return
|
|
646
647
|
}
|
|
647
648
|
state.retainedBoot = state.preparedBoot
|
|
648
649
|
state.window++
|
|
649
|
-
state
|
|
650
|
-
state.lastWord = undefined
|
|
650
|
+
clearManualRequest(state)
|
|
651
651
|
log($, "Brain emptied")
|
|
652
652
|
} catch (error) {
|
|
653
653
|
if (generation !== state.generation) return
|
|
654
654
|
const text = String(error)
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
log($, HEADLESS)
|
|
658
|
-
} else if (/a turn is (running|in flight)/.test(text)) {
|
|
659
|
-
state.manualPending = true
|
|
660
|
-
} else {
|
|
655
|
+
state.manualPending = true
|
|
656
|
+
if (!/a turn is (running|in flight)/.test(text)) {
|
|
661
657
|
log($, `Brain still full: ${text.replace(/[\r\n].*$/s, "")}`)
|
|
662
658
|
}
|
|
663
659
|
} finally {
|
|
@@ -6,7 +6,7 @@ I am reviewing my notes: keeping what is useful, connecting what belongs togethe
|
|
|
6
6
|
|
|
7
7
|
A dream covers one project: its `@project` notes and the session notes born in it. `@human`, `@self`, and `@model` are not part of a dream unless the human asks for them or the dream runs from inside the notes home itself. Do not broaden that scope while exploring; if a boundary is unclear, ask before crossing it. Unknown ownership is a coverage gap to report, not a reason to guess or repair ownership.
|
|
8
8
|
|
|
9
|
-
The
|
|
9
|
+
The notebooks serve different readers:
|
|
10
10
|
|
|
11
11
|
- Session notes (`<path>`, no `@`) are a trip's working record. Read them as sources; do not rewrite them. Only the wastebasket rule below may remove another session's notes.
|
|
12
12
|
- `@project` notes hold knowledge for whoever next works on that project.
|
|
@@ -16,7 +16,7 @@ The homes serve different readers:
|
|
|
16
16
|
|
|
17
17
|
## What a durable note holds
|
|
18
18
|
|
|
19
|
-
Durable notes hold decisions, constraints, and lessons that stay true after the current work ends. They are not diaries:
|
|
19
|
+
Durable notes hold decisions, constraints, and lessons that stay true after the current work ends. They are not diaries: raw logs, scorecards, and blow-by-blow recaps belong to history. When a piece of history actually matters — such as why an earlier approach failed — keep only a brief background summary, clearly separated from what is true now. A session finding is worth promoting only when it meets this bar.
|
|
20
20
|
|
|
21
21
|
## Review and consolidate
|
|
22
22
|
|
|
@@ -24,22 +24,22 @@ Durable notes hold decisions, constraints, and lessons that stay true after the
|
|
|
24
24
|
2. **Verify only what the proposed change depends on.** Before correcting, retiring, 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.
|
|
25
25
|
3. **Retire what is no longer true.** When evidence shows a durable note is stale, correct it in place; if nothing true remains, crumple it. Remove or fix its MAP line either way. A note's last access is a hint, not evidence: long-unread notes are candidates to check, not to crumple on sight. A read reports the access before itself, so reviewing a note does not make it look fresh.
|
|
26
26
|
4. **Merge only genuine duplicates.** Merge two notes only when they share a topic and kind (checkpoint, design, log). First carry every fact, condition, and exception unique to the absorbed note into the survivor, then crumple the absorbed note. Otherwise keep both and record any unresolved conflict.
|
|
27
|
-
5. **Relocate misfiled notes.** When a standing ruling or the note's own MAP already names its proper
|
|
27
|
+
5. **Relocate misfiled notes.** When a standing ruling or the note's own MAP already names its proper notebook, move it there, preserving its metadata, and update both notebooks' maps. 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
|
|
30
|
+
8. **Keep wake-up pages useful.** Each writable notebook's `CHEATSHEET.md` holds standing reminders, kept to five lines. Its `MAP.md` holds only the note index: durable notes' addresses and short gists. Both load every window when present; do not create empty pages. Preserve standing rules, add promoted notes to the map, and drop entries that no longer hold. Maps follow the same size budget.
|
|
31
31
|
|
|
32
32
|
## Deleting
|
|
33
33
|
|
|
34
34
|
Never physically delete a live note; crumple it first. Two cases allow deleting a crumpled note:
|
|
35
35
|
|
|
36
36
|
- **Your own session's notes** may be deleted once crumpled.
|
|
37
|
-
- **The wastebasket:** any note within the dream's reach that was crumpled more than 7 days ago may be deleted, whatever its
|
|
37
|
+
- **The wastebasket:** any note within the dream's reach that was crumpled more than 7 days ago may be deleted, whatever its notebook or session. Judge by its crumpled date; if none is readable, keep it and report it.
|
|
38
38
|
|
|
39
39
|
Where notes cannot be deleted, list the doomed addresses in the report instead of blanking them.
|
|
40
40
|
|
|
41
41
|
## Report
|
|
42
42
|
|
|
43
|
-
Give a concise report grouped by
|
|
43
|
+
Give a concise report grouped by notebook: what you inspected, changed, retired, promoted, deleted, and left unresolved. Mention coverage gaps and partial failures. If no notes changed, say so. Distinguish actual note changes from execution or audit artifacts; do not claim success for an incomplete run.
|
|
44
44
|
|
|
45
45
|
Put skill ideas and unresolved questions in the final message as proposals for the human, not new skill files.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: memory
|
|
3
|
-
description: How notesoup's `notes_*` and `history_*` tools fit together — note addresses and
|
|
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
4
|
---
|
|
5
5
|
|
|
6
6
|
# Memory
|
|
@@ -32,13 +32,13 @@ Any other `@` prefix is refused. A path is relative and `/`-separated, with no e
|
|
|
32
32
|
|
|
33
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
34
|
|
|
35
|
-
`CHEATSHEET.md` and `MAP.md` at the root of each `@`
|
|
35
|
+
`CHEATSHEET.md` and `MAP.md` at the root of each `@` notebook are separate pages you wake up with; absent pages are skipped. Keep standing reminders in `CHEATSHEET.md`, to five lines. `MAP.md` holds only the note index: each durable note's address and gist, for lookup. Update it whenever you add, move or crumple a durable note. Do not create empty pages.
|
|
36
36
|
|
|
37
|
-
|
|
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
38
|
|
|
39
39
|
## Finding things again
|
|
40
40
|
|
|
41
|
-
For list/search, omit `glob` or use the collection alias `@default` for this session and current shared
|
|
41
|
+
For list/search, omit `glob` or use the collection alias `@default` for this session and current shared notebooks. Use `**` for all notebooks or `@sessions/*/**` for all sessions. Results carry readable note addresses; `@default` itself is not a read/write address.
|
|
42
42
|
|
|
43
43
|
- **A note**: `notes_list` with a `glob` when you know roughly where it lives, `notes_search` when you know a phrase; then `notes_read` the address.
|
|
44
44
|
- **Something that happened**: `history_list` to browse or search this session's events; `history_read` the seq for the whole event.
|
|
@@ -13,6 +13,7 @@ import { claudeHistoryGapNotice, claudeHistoryUnconfirmedSeq, CLAUDE_HISTORY_UNK
|
|
|
13
13
|
import { resolveClaudeLimits } from "./thresholds.js";
|
|
14
14
|
import { projectKey, snapshotNotesIdentity, type NotesIdentity } from "../../../src/notes/index.js";
|
|
15
15
|
import type { Operation } from "../../../src/tools/result.js";
|
|
16
|
+
import { notesToolContext, type NotesToolContext } from "../../../src/tools/notes-context.js";
|
|
16
17
|
|
|
17
18
|
const MAX_REQUEST_BYTES = 512 * 1024;
|
|
18
19
|
const MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
@@ -55,7 +56,7 @@ function boundOperation<TParams extends TSchema, TData, TContext extends readonl
|
|
|
55
56
|
};
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
const OPERATIONS: Record<string, BoundOperation<[
|
|
59
|
+
const OPERATIONS: Record<string, BoundOperation<[NotesToolContext]>> = {
|
|
59
60
|
notes_write: boundOperation(notesWrite),
|
|
60
61
|
notes_update: boundOperation(notesUpdate),
|
|
61
62
|
notes_read: boundOperation(notesRead),
|
|
@@ -124,7 +125,7 @@ export async function dispatch(request: unknown): Promise<unknown> {
|
|
|
124
125
|
: await HISTORY_OPERATIONS[tool].call(params, projection, wrapText);
|
|
125
126
|
return { ...result, text: wrapText(result.text) };
|
|
126
127
|
}
|
|
127
|
-
return OPERATIONS[value.tool]!.call(value.params, id);
|
|
128
|
+
return OPERATIONS[value.tool]!.call(value.params, notesToolContext(id, (value.identity as ClaudeIdentityInput).cwd));
|
|
128
129
|
}
|
|
129
130
|
if (value.op === "history_state") {
|
|
130
131
|
const id = identity(value.identity as ClaudeIdentityInput);
|
|
@@ -56,9 +56,8 @@ function blocksOf(value: unknown): Row[] {
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
function decode(row: Row, seq: number): DecodedHistoryItem[] {
|
|
59
|
-
//
|
|
60
|
-
|
|
61
|
-
if (row.type === "system" && row.subtype === "turn_duration") return [];
|
|
59
|
+
// A system record without a body is graph metadata, not a message.
|
|
60
|
+
if (row.type === "system" && row.content == null) return [];
|
|
62
61
|
const common = { windowId: "", ...(typeof row.timestamp === "string" ? { createdAt: row.timestamp } : {}) };
|
|
63
62
|
let blocks: Row[], role: DecodedHistoryItem["role"];
|
|
64
63
|
if (row.type === "user" || row.type === "assistant") {
|
|
@@ -142,9 +142,11 @@ export function resolveClaudeLimits(facts: unknown): ClaudeLimits {
|
|
|
142
142
|
if (window !== undefined) {
|
|
143
143
|
const configured = configuredWindow(settings, env, breakdown.model);
|
|
144
144
|
const effective = Math.min(configured ?? window, window);
|
|
145
|
+
const available = effective - CLAUDE_OUTPUT_RESERVE_TOKENS;
|
|
146
|
+
const threshold = available - CLAUDE_AUTOCOMPACT_BUFFER_TOKENS;
|
|
145
147
|
const native = autoCompact
|
|
146
|
-
?
|
|
147
|
-
:
|
|
148
|
+
? pct === undefined ? threshold : Math.min(Math.floor(available * (pct / 100)), threshold)
|
|
149
|
+
: available;
|
|
148
150
|
return tokenLimits("window", autoCompact, native, resetMargin, warningRunway);
|
|
149
151
|
}
|
|
150
152
|
|
package/plugins/codex/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# notesoup for Codex
|
|
2
2
|
|
|
3
|
-
Native notes and history for Codex **0.160.1**. The plugin bundles one stdio MCP server with the five
|
|
3
|
+
Native notes and history for Codex **0.160.1**. The plugin bundles one stdio MCP server with the five notebooks and three history tools, and one hook helper that injects the notes boot into each native context window. `new_context` and `get_context_remaining` stay Codex's own tools; notesoup does not replace Codex's reset or budget.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|