notesoup 0.53.1 → 0.53.2
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/plugins/claude/src/history.js +2 -3
- package/dist/plugins/claude/src/thresholds.js +4 -2
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/marker.d.ts +9 -0
- package/dist/plugins/pi/marker.js +36 -0
- 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 +9 -6
- package/dist/plugins/pi/text.d.ts +2 -0
- package/dist/plugins/pi/text.js +4 -0
- package/dist/test/agent-loop.test.js +8 -8
- package/dist/test/boot.integration.test.js +4 -4
- package/dist/test/claude-history.test.js +26 -0
- package/dist/test/claude-mod.test.js +178 -53
- package/dist/test/marker.test.d.ts +1 -0
- package/dist/test/marker.test.js +78 -0
- package/dist/test/reset-lifecycle.test.js +12 -0
- package/docs/architecture.md +1 -1
- package/docs/claude-code-mod.md +7 -7
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +4 -2
- package/plugins/claude/hooks/register.ts +44 -56
- package/plugins/claude/src/history.ts +2 -3
- package/plugins/claude/src/thresholds.ts +4 -2
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/marker.ts +39 -0
- package/plugins/pi/reset/artifacts.ts +2 -2
- package/plugins/pi/runtime.ts +7 -6
- package/plugins/pi/text.ts +5 -0
package/package.json
CHANGED
|
@@ -9715,7 +9715,7 @@ function blocksOf(value) {
|
|
|
9715
9715
|
});
|
|
9716
9716
|
}
|
|
9717
9717
|
function decode(row, seq) {
|
|
9718
|
-
if (row.type === "system" && row.
|
|
9718
|
+
if (row.type === "system" && row.content == null) return [];
|
|
9719
9719
|
const common = { windowId: "", ...typeof row.timestamp === "string" ? { createdAt: row.timestamp } : {} };
|
|
9720
9720
|
let blocks, role;
|
|
9721
9721
|
if (row.type === "user" || row.type === "assistant") {
|
|
@@ -10249,7 +10249,9 @@ function resolveClaudeLimits(facts) {
|
|
|
10249
10249
|
if (window !== void 0) {
|
|
10250
10250
|
const configured = configuredWindow(settings2, env, breakdown.model);
|
|
10251
10251
|
const effective = Math.min(configured ?? window, window);
|
|
10252
|
-
const
|
|
10252
|
+
const available = effective - CLAUDE_OUTPUT_RESERVE_TOKENS;
|
|
10253
|
+
const threshold2 = available - CLAUDE_AUTOCOMPACT_BUFFER_TOKENS;
|
|
10254
|
+
const native = autoCompact ? pct === void 0 ? threshold2 : Math.min(Math.floor(available * (pct / 100)), threshold2) : available;
|
|
10253
10255
|
return tokenLimits("window", autoCompact, native, resetMargin, warningRunway);
|
|
10254
10256
|
}
|
|
10255
10257
|
return percentLimits(autoCompact, pct, resetMargin, warningRunway);
|
|
@@ -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. */
|
|
@@ -255,6 +254,7 @@ function forgetSession(state: ResetState) {
|
|
|
255
254
|
state.historyWindowHead = undefined
|
|
256
255
|
state.window = 0
|
|
257
256
|
state.turnRunning = state.resetting = state.manualPending = state.usageFailureLogged = false
|
|
257
|
+
state.manualCompacting = false
|
|
258
258
|
state.preparedBoot = state.retainedBoot = undefined
|
|
259
259
|
state.texts = state.limits = undefined
|
|
260
260
|
state.continuation = undefined
|
|
@@ -345,8 +345,7 @@ export function register(on: On) {
|
|
|
345
345
|
keepMemory = envFlag(await $.env.get("NOTESOUP_KEEP_MEMORY").catch(() => undefined))
|
|
346
346
|
await refreshIdentity($, state)
|
|
347
347
|
state.headless = !e.isInteractive
|
|
348
|
-
|
|
349
|
-
// Compaction is the capability the reset is built on; without it, automatic resets stop here.
|
|
348
|
+
// Compaction is the capability explicit resets and budget warnings depend on.
|
|
350
349
|
state.compactDisabled = await compactDisabled($)
|
|
351
350
|
if (state.compactDisabled) log($, COMPACT_DISABLED)
|
|
352
351
|
registered.clear()
|
|
@@ -357,7 +356,7 @@ export function register(on: On) {
|
|
|
357
356
|
const wipe = await $.tool.register({
|
|
358
357
|
name: "empty_brain",
|
|
359
358
|
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
|
|
359
|
+
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
360
|
isDeferred: false,
|
|
362
361
|
} satisfies ToolSpec)
|
|
363
362
|
registered.add(wipe.tool)
|
|
@@ -398,30 +397,30 @@ export function register(on: On) {
|
|
|
398
397
|
if (state.disabled) return result
|
|
399
398
|
if (!await refreshIdentity($, state)) return result
|
|
400
399
|
state.turnRunning = false
|
|
401
|
-
await
|
|
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)
|
|
400
|
+
if (state.manualPending) await reset($, state)
|
|
407
401
|
return result
|
|
408
402
|
})
|
|
409
403
|
on("command.run", async ($, e, next) => {
|
|
410
404
|
if (state.disabled) return next(e)
|
|
405
|
+
// Only our queued native command admits manual compaction. A user's /compact
|
|
406
|
+
// still reaches the veto, even while a reset is pending.
|
|
407
|
+
if (e.command === "compact" && state.resetting && state.headless && e.origin.kind === "plugin" && e.origin.name === "notesoup") {
|
|
408
|
+
state.manualCompacting = true
|
|
409
|
+
try { return await next(e) } finally { state.manualCompacting = false }
|
|
410
|
+
}
|
|
411
411
|
if (e.command !== "empty" && e.command !== "fresh-window") return next(e)
|
|
412
412
|
if (!await refreshIdentity($, state)) return { text: "🥣 Different brain now · try /fresh-window again" }
|
|
413
|
-
if (state.headless) return { text: `🥣 ${HEADLESS}` }
|
|
414
413
|
if (state.compactDisabled) return { text: `🥣 ${COMPACT_DISABLED}` }
|
|
415
414
|
if (state.resetting || state.manualPending) return { text: "🥣 Brain already being emptied" }
|
|
416
415
|
if (state.turnRunning) {
|
|
417
416
|
state.manualPending = true
|
|
418
|
-
return { text: "🥣 Brain
|
|
417
|
+
return { text: "🥣 Dumping Brain" }
|
|
419
418
|
}
|
|
420
419
|
// command.run holds a turn even when idle. Start one hidden close-out
|
|
421
420
|
// turn after it returns; turn.complete is the verified self-hook path.
|
|
422
421
|
state.manualPending = true
|
|
423
422
|
manualSignal.wake?.()
|
|
424
|
-
return { text: "🥣 Brain
|
|
423
|
+
return { text: "🥣 Dumping Brain" }
|
|
425
424
|
})
|
|
426
425
|
on("session.compact", async ($, e, next) => {
|
|
427
426
|
// Disabled means fully transparent: native compaction runs exactly as if the mod were absent.
|
|
@@ -439,11 +438,11 @@ export function register(on: On) {
|
|
|
439
438
|
}
|
|
440
439
|
return result
|
|
441
440
|
}
|
|
442
|
-
// Native compaction never runs the summarizer while notesoup is on:
|
|
443
|
-
// precompute are vetoed
|
|
444
|
-
|
|
441
|
+
// Native compaction never runs the summarizer while notesoup is on: user
|
|
442
|
+
// manual and precompute are vetoed; auto becomes the notes-only reset.
|
|
443
|
+
const own = state.resetting && identity !== undefined && (e.trigger === "plugin" || (e.trigger === "manual" && state.manualCompacting === true))
|
|
444
|
+
if (e.trigger === "manual" && !own) return { skip: "No compacting brains here · use /fresh-window" }
|
|
445
445
|
if (e.trigger === "precompute") return { skip: "No precomputing brains here" }
|
|
446
|
-
const own = state.resetting && e.trigger === "plugin" && identity !== undefined
|
|
447
446
|
if (!own && e.trigger !== "auto") return passThrough()
|
|
448
447
|
if (identity === undefined) return passThrough()
|
|
449
448
|
const built = await resetMessages($, state, identity)
|
|
@@ -506,12 +505,11 @@ async function callNotesTool($: Engine, state: ResetState, e: ToolCallInput): Pr
|
|
|
506
505
|
const name = tool.slice(PREFIX.length)
|
|
507
506
|
if (name === "empty_brain") {
|
|
508
507
|
if (agentId !== undefined) return errorResult("only the main agent can empty this brain")
|
|
509
|
-
if (state.headless) return errorResult(HEADLESS)
|
|
510
508
|
if (state.compactDisabled) return errorResult(COMPACT_DISABLED)
|
|
511
509
|
if (params.last_word !== undefined && typeof params.last_word !== "string") return errorResult("last_word must be a string")
|
|
512
510
|
const lastWord = typeof params.last_word === "string" ? params.last_word.trim() || undefined : undefined
|
|
513
511
|
const length = lastWord ? Array.from(lastWord).length : 0
|
|
514
|
-
if (length >
|
|
512
|
+
if (length > 500) return errorResult(`last_word is ${length} characters; the sticky note holds 500. Shorten it and call again.`)
|
|
515
513
|
if (!state.toolResetRequested) {
|
|
516
514
|
state.toolResetRequested = true
|
|
517
515
|
state.lastWord = lastWord
|
|
@@ -531,7 +529,7 @@ async function callNotesTool($: Engine, state: ResetState, e: ToolCallInput): Pr
|
|
|
531
529
|
|
|
532
530
|
/** Read the warning without consuming this window's delivery. */
|
|
533
531
|
async function warningText($: Engine, state: ResetState): Promise<string | undefined> {
|
|
534
|
-
if (state.disabled || state.
|
|
532
|
+
if (state.disabled || state.compactDisabled || !state.identity || state.warnedWindow === state.window || state.warningPending === state.window) return undefined
|
|
535
533
|
const generation = state.generation
|
|
536
534
|
const usage = await contextUsage($, state)
|
|
537
535
|
if (generation !== state.generation || usage === undefined) return undefined
|
|
@@ -545,7 +543,7 @@ async function warningText($: Engine, state: ResetState): Promise<string | undef
|
|
|
545
543
|
|
|
546
544
|
/** Reserve across next(), but consume only context the chain actually accepted. */
|
|
547
545
|
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.
|
|
546
|
+
if (state.disabled || state.compactDisabled || !await refreshIdentity($, state)) return deliver()
|
|
549
547
|
const generation = state.generation, window = state.window
|
|
550
548
|
const warning = await warningText($, state)
|
|
551
549
|
if (warning === undefined || generation !== state.generation || window !== state.window || state.warnedWindow === window || state.warningPending === window) return deliver()
|
|
@@ -600,7 +598,6 @@ async function finishManual($: Engine, state: ResetState, signal: { wake?: () =>
|
|
|
600
598
|
const texts = await loadTexts($, state)
|
|
601
599
|
if (generation !== state.generation) return
|
|
602
600
|
if (texts?.warning === undefined) {
|
|
603
|
-
state.manualPending = false
|
|
604
601
|
log($, "Brain still full: the close-out prompt didn't load")
|
|
605
602
|
return
|
|
606
603
|
}
|
|
@@ -608,56 +605,47 @@ async function finishManual($: Engine, state: ResetState, signal: { wake?: () =>
|
|
|
608
605
|
}
|
|
609
606
|
} catch {
|
|
610
607
|
if (generation === state.generation) {
|
|
611
|
-
state.manualPending = false
|
|
612
608
|
log($, "Brain still full: the close-out turn didn't start")
|
|
613
609
|
}
|
|
614
610
|
} finally { armManual($, state, signal) }
|
|
615
611
|
}
|
|
616
612
|
|
|
617
613
|
// The sandbox permits $ forwarding only to file-top-level helpers.
|
|
618
|
-
async function maybeReset($: Engine, state: ResetState, complete: boolean) {
|
|
619
|
-
if (!state.identity || state.resetting || state.headless || state.compactDisabled) return
|
|
620
|
-
const generation = state.generation
|
|
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
|
-
}
|
|
634
|
-
}
|
|
635
614
|
async function reset($: Engine, state: ResetState): Promise<void> {
|
|
636
|
-
if (!state.identity || state.
|
|
615
|
+
if (!state.identity || state.compactDisabled || state.resetting) return
|
|
637
616
|
const generation = state.generation
|
|
638
617
|
state.resetting = true
|
|
639
618
|
state.preparedBoot = undefined
|
|
640
619
|
try {
|
|
641
|
-
|
|
620
|
+
let failure: string | undefined
|
|
621
|
+
if (state.headless) {
|
|
622
|
+
const receipt = await $.command.run({ command: "compact" })
|
|
623
|
+
if (generation !== state.generation) return
|
|
624
|
+
// A command receipt is not SessionCompacted. Our admitted hook must have
|
|
625
|
+
// prepared the boot; session.messages() here still reads the completed
|
|
626
|
+
// turn's snapshot, not the next request's newly compacted context.
|
|
627
|
+
if (state.preparedBoot === undefined) failure = receipt.text ?? "notes boot was not retained"
|
|
628
|
+
} else {
|
|
629
|
+
const result = await $.session.compact({ instructions: RESET_INSTRUCTIONS })
|
|
630
|
+
failure = result.skip
|
|
631
|
+
}
|
|
642
632
|
if (generation !== state.generation) return
|
|
643
|
-
if (
|
|
644
|
-
|
|
633
|
+
if (failure !== undefined || state.preparedBoot === undefined) {
|
|
634
|
+
state.manualPending = true
|
|
635
|
+
log($, `Brain not emptied · ${failure ?? "notes boot was not retained"}`)
|
|
645
636
|
return
|
|
646
637
|
}
|
|
647
638
|
state.retainedBoot = state.preparedBoot
|
|
648
639
|
state.window++
|
|
640
|
+
state.manualPending = false
|
|
649
641
|
state.toolResetRequested = undefined
|
|
650
642
|
state.lastWord = undefined
|
|
651
643
|
log($, "Brain emptied")
|
|
652
644
|
} catch (error) {
|
|
653
645
|
if (generation !== state.generation) return
|
|
654
646
|
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 {
|
|
647
|
+
state.manualPending = true
|
|
648
|
+
if (!/a turn is (running|in flight)/.test(text)) {
|
|
661
649
|
log($, `Brain still full: ${text.replace(/[\r\n].*$/s, "")}`)
|
|
662
650
|
}
|
|
663
651
|
} finally {
|
|
@@ -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/pi/entries.ts
CHANGED
|
@@ -7,3 +7,4 @@ export const CONTINUATION_TYPE = "notesoup/continuation";
|
|
|
7
7
|
export const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
|
|
8
8
|
export const CARRIED_INPUT_TYPE = "notesoup/carried-input";
|
|
9
9
|
export const NEXT_WINDOW_PROMPT_TYPE = "notesoup/next-window-prompt";
|
|
10
|
+
export const MARKER_TYPE = "notesoup/marker";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { MARKER_TYPE } from "./entries.js";
|
|
3
|
+
import { nextHistorySeq } from "./history.js";
|
|
4
|
+
import { inspectResetTail } from "./reset/artifacts.js";
|
|
5
|
+
import { markerContent } from "./text.js";
|
|
6
|
+
import { currentReset } from "./window.js";
|
|
7
|
+
|
|
8
|
+
/** Spacing between durable seq breadcrumbs, in projected history seq. */
|
|
9
|
+
export const MARKER_INTERVAL = 50;
|
|
10
|
+
|
|
11
|
+
/** Highest seq already stamped by a marker; 0 before the first. */
|
|
12
|
+
function lastMarkerSeq(ctx: ExtensionContext): number {
|
|
13
|
+
let last = 0;
|
|
14
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
15
|
+
if (entry.type !== "custom_message" || entry.customType !== MARKER_TYPE) continue;
|
|
16
|
+
const seq = (entry.details as { seq?: unknown } | undefined)?.seq;
|
|
17
|
+
if (typeof seq === "number" && seq > last) last = seq;
|
|
18
|
+
}
|
|
19
|
+
return last;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Stamp the current seq every MARKER_INTERVAL seqs. The marker names the seq it occupies, so a
|
|
24
|
+
* model paging history_list meets a breadcrumb that tells it where it is. Skipped while a reset
|
|
25
|
+
* tail still awaits boot or continuation: a foreign message there would close the repair shape.
|
|
26
|
+
*/
|
|
27
|
+
export function maybeSendMarker(pi: ExtensionAPI, ctx: ExtensionContext): void {
|
|
28
|
+
const reset = currentReset(ctx);
|
|
29
|
+
if (reset) {
|
|
30
|
+
const tail = inspectResetTail(ctx, reset.id, reset.data.windowId);
|
|
31
|
+
if (tail && (!tail.boot || !tail.continuation)) return;
|
|
32
|
+
}
|
|
33
|
+
const seq = nextHistorySeq(ctx);
|
|
34
|
+
if (seq - lastMarkerSeq(ctx) < MARKER_INTERVAL) return;
|
|
35
|
+
pi.sendMessage(
|
|
36
|
+
{ customType: MARKER_TYPE, content: markerContent(seq), display: false, details: { seq } },
|
|
37
|
+
{ triggerTurn: false },
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -19,10 +19,10 @@ export function isCarriedInputEntry(entry: SessionEntry): boolean {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/** Advertised size: the description quotes this softer limit so sloppy character counts still fit. */
|
|
22
|
-
export const LAST_WORD_ADVERTISED_CHARS =
|
|
22
|
+
export const LAST_WORD_ADVERTISED_CHARS = 300;
|
|
23
23
|
|
|
24
24
|
/** A sticky note, not a letter: over this, empty_brain refuses instead of truncating. */
|
|
25
|
-
export const MAX_LAST_WORD_CHARS =
|
|
25
|
+
export const MAX_LAST_WORD_CHARS = 500;
|
|
26
26
|
|
|
27
27
|
/** How the next window finds the note. */
|
|
28
28
|
export const LAST_WORD_PREFIX = "*You peel a sticky note off your forehead.*\n";
|
package/plugins/pi/runtime.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { buildResetDrafts, LAST_WORD_ADVERTISED_CHARS, MAX_LAST_WORD_CHARS, repa
|
|
|
11
11
|
import { BOOT_TYPE, MANUAL_WIPE_TYPE } from "./entries.js";
|
|
12
12
|
import { commandWarningContent } from "./text.js";
|
|
13
13
|
import { buildBootMessage, sendBoot, type IncompleteNotesNotifier } from "./boot.js";
|
|
14
|
+
import { maybeSendMarker } from "./marker.js";
|
|
14
15
|
import { nextHistorySeq } from "./history.js";
|
|
15
16
|
import { errorMessage } from "../../src/error-message.js";
|
|
16
17
|
|
|
@@ -73,13 +74,13 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
73
74
|
const marker = branch.find((entry): entry is WindowMarker => isWindowMarker(entry) && entry.data.windowId === windowId);
|
|
74
75
|
if (!marker || !isCheckpointBackedReset(ctx, marker) || !resetBoundaryCommitted(ctx, marker.id, windowId)) continue;
|
|
75
76
|
pendingResetNotices.delete(windowId);
|
|
76
|
-
|
|
77
|
-
// committed notice stays a one-line marker instead of repeating it.
|
|
78
|
-
const forced = markerResetOrigin(marker) === "forced";
|
|
79
|
-
ctx.ui.notify(forced ? "🥣 Brain forcibly emptied: overflow" : "🥣 Fresh brain", forced ? "warning" : "info");
|
|
77
|
+
if (markerResetOrigin(marker) === "forced") ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
|
|
80
78
|
}
|
|
81
79
|
};
|
|
82
|
-
pi.on("turn_start", (_event, ctx) =>
|
|
80
|
+
pi.on("turn_start", (_event, ctx) => {
|
|
81
|
+
notifyCommittedResets(ctx);
|
|
82
|
+
if (enabled) maybeSendMarker(pi, ctx);
|
|
83
|
+
});
|
|
83
84
|
pi.on("agent_settled", (_event, ctx) => {
|
|
84
85
|
notifyCommittedResets(ctx);
|
|
85
86
|
pendingResetNotices.clear();
|
|
@@ -189,7 +190,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
189
190
|
cmdCtx.ui.notify("🥣 Brain already being emptied", "info");
|
|
190
191
|
return;
|
|
191
192
|
}
|
|
192
|
-
cmdCtx.ui.notify("🥣 Brain
|
|
193
|
+
cmdCtx.ui.notify("🥣 Dumping Brain", "info");
|
|
193
194
|
try {
|
|
194
195
|
pi.sendMessage({ customType: MANUAL_WIPE_TYPE, content: commandWarningContent(prompt !== undefined ? `/empty ${prompt}` : undefined), display: false }, { triggerTurn: true, deliverAs: "steer" });
|
|
195
196
|
} catch (error) {
|
package/plugins/pi/text.ts
CHANGED
|
@@ -11,6 +11,11 @@ Unless the human explicitly directs otherwise, decide for yourself when to call
|
|
|
11
11
|
|
|
12
12
|
export { warningNotice as warningContent } from "../../src/budget/text.js";
|
|
13
13
|
|
|
14
|
+
/** Odometer breadcrumb: the marker names its own seq, so history paging reads the landscape directly. */
|
|
15
|
+
export function markerContent(seq: number): string {
|
|
16
|
+
return `<notesoup:marker seq="${seq}" />`;
|
|
17
|
+
}
|
|
18
|
+
|
|
14
19
|
/** The closing model sees deferred input as a bare next-window prompt block. */
|
|
15
20
|
export function promptBlock(commandLine: string): string {
|
|
16
21
|
return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
|