notesoup 0.58.3 → 0.59.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/plugins/claude/src/helper.js +13 -0
- package/dist/plugins/claude/src/thresholds.js +17 -12
- package/dist/plugins/dsh/tools.js +0 -3
- package/dist/plugins/pi/budget.d.ts +3 -0
- package/dist/plugins/pi/budget.js +22 -11
- package/dist/plugins/pi/runtime.js +22 -6
- package/dist/src/boot/text.d.ts +1 -1
- package/dist/src/boot/text.js +6 -10
- package/dist/src/budget/cap.d.ts +2 -0
- package/dist/src/budget/cap.js +11 -0
- package/dist/src/notes/address.d.ts +1 -1
- package/dist/src/notes/address.js +1 -1
- package/dist/src/notes/policy.js +1 -1
- package/dist/src/tools/dream.d.ts +3 -3
- package/dist/src/tools/dream.js +5 -5
- package/dist/src/tools/history.js +12 -13
- package/dist/src/tools/notes.d.ts +7 -5
- package/dist/src/tools/notes.js +35 -34
- package/dist/src/tools/result.js +2 -2
- package/dist/src/tools/schema.js +2 -2
- package/dist/test/budget-settings.integration.test.js +45 -1
- package/dist/test/claude-mod.test.js +80 -21
- package/dist/test/dsh.test.js +13 -1
- package/dist/test/note-policy.test.js +6 -1
- package/dist/test/notes.integration.test.js +28 -0
- package/docs/claude-code-mod.md +5 -3
- package/docs/reset-lifecycle.md +3 -1
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +96 -70
- package/plugins/claude/hooks/register.ts +57 -9
- package/plugins/claude/src/helper.ts +11 -0
- package/plugins/claude/src/thresholds.ts +18 -11
- package/plugins/codex/dist/codex/notesoup.js +59 -61
- package/plugins/dsh/tools.ts +0 -2
- package/plugins/pi/budget.ts +21 -11
- package/plugins/pi/runtime.ts +18 -6
- package/src/boot/text.ts +6 -10
- package/src/budget/cap.ts +9 -0
- package/src/notes/address.ts +1 -1
- package/src/notes/policy.ts +1 -1
- package/src/tools/dream.ts +5 -5
- package/src/tools/history.ts +12 -14
- package/src/tools/notes.ts +35 -33
- package/src/tools/result.ts +2 -2
- package/src/tools/schema.ts +2 -2
package/README.md
CHANGED
|
@@ -50,6 +50,7 @@ pi -e npm:notesoup
|
|
|
50
50
|
- **Migration (0.40.0)**: parameters renamed: `order` → `from`, `before`/`after` → `before_seq`/`after_seq`, `limit_chars` → `max_chars`, `wastebasket` → `crumpled`, `pattern` → `glob` (the standalone library's options included), and `notes_update`'s `change_kind` value `file` → `moved`. Old names are refused.
|
|
51
51
|
|
|
52
52
|
- **Runtime toggle** — `/notesoup off` stops new automatic resets; `/notesoup on` re-enables them; bare `/notesoup` reports the state.
|
|
53
|
+
- **Context cap (Pi and Claude)** — `/notesoup cap 100k` limits the capacity used by notesoup's budget to `min(model window, 100000)`. Existing reserves and warning margins are deducted from that capacity; 100k is not the used-token reset point. `/notesoup cap` shows the configured cap and `/notesoup cap off` removes it. Whole tokens and decimal `k`/`m` suffixes are accepted; caps too small for the host's reserves are refused. The cap applies only to the running session, survives notesoup resets and model changes, and is lost on reload/restart/session switch. It never writes host settings or environment variables, changes the provider's advertised model window, or enables disabled automatic resets.
|
|
53
54
|
|
|
54
55
|
## Per-note policy
|
|
55
56
|
|
|
@@ -11,6 +11,7 @@ import { renderBootBlock } from "../../../src/boot/render.js";
|
|
|
11
11
|
import { selectContinuation } from "../../../src/budget/text.js";
|
|
12
12
|
import { claudeHistoryGapNotice, claudeHistoryUnconfirmedSeq, CLAUDE_HISTORY_UNKNOWN_WINDOW, CLAUDE_HISTORY_UNAVAILABLE_SENTENCE, CLAUDE_WARNING_PROMPT } from "./text.js";
|
|
13
13
|
import { resolveClaudeLimits } from "./thresholds.js";
|
|
14
|
+
import { parseContextCap } from "../../../src/budget/cap.js";
|
|
14
15
|
import { projectKey, snapshotNotesIdentity } from "../../../src/notes/index.js";
|
|
15
16
|
import { notesToolContext } from "../../../src/tools/notes-context.js";
|
|
16
17
|
const MAX_REQUEST_BYTES = 512 * 1024;
|
|
@@ -55,6 +56,18 @@ export async function dispatch(request, historyOptions = {}) {
|
|
|
55
56
|
if (!request || typeof request !== "object" || Array.isArray(request))
|
|
56
57
|
throw new Error("malformed request");
|
|
57
58
|
const value = request;
|
|
59
|
+
if (value.op === "cap") {
|
|
60
|
+
const cap = typeof value.value === "string" ? parseContextCap(value.value) : undefined;
|
|
61
|
+
if (cap === undefined)
|
|
62
|
+
throw new Error("Usage: /notesoup cap [100k|1m|tokens|off]");
|
|
63
|
+
if (cap !== null) {
|
|
64
|
+
const facts = value.facts && typeof value.facts === "object" ? value.facts : {};
|
|
65
|
+
const limits = resolveClaudeLimits({ ...facts, capTokens: undefined, usage: { window: cap }, breakdown: {} });
|
|
66
|
+
if (limits.reset <= 1)
|
|
67
|
+
throw new Error("Cap is too small for Claude's output, compaction and reset reserves");
|
|
68
|
+
}
|
|
69
|
+
return { cap };
|
|
70
|
+
}
|
|
58
71
|
if (value.op === "schemas")
|
|
59
72
|
return [...Object.entries(OPERATIONS), ...Object.entries(HISTORY_OPERATIONS)].map(([name, operation]) => ({ name, description: operation.description, inputSchema: JSON.parse(JSON.stringify(operation.parameters)) }));
|
|
60
73
|
// The shared reset prose lives here, not in the sandboxed hooks module, so Pi and Claude
|
|
@@ -58,6 +58,11 @@ function tokenLimits(source, autoCompact, native, resetMargin, warningRunway) {
|
|
|
58
58
|
native: tokens, reset, warn: Math.max(MIN_POINT_TOKENS, reset - warningRunway), resetMargin, warningRunway,
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
+
function windowPoint(window, autoCompact, pct) {
|
|
62
|
+
const available = window - CLAUDE_OUTPUT_RESERVE_TOKENS;
|
|
63
|
+
const threshold = available - CLAUDE_AUTOCOMPACT_BUFFER_TOKENS;
|
|
64
|
+
return autoCompact ? pct === undefined ? threshold : Math.min(Math.floor(available * (pct / 100)), threshold) : available;
|
|
65
|
+
}
|
|
61
66
|
/**
|
|
62
67
|
* Resolve the points from whatever the host could read. Every field is undocumented-adjacent,
|
|
63
68
|
* so a missing or malformed one degrades to the next source and finally to the percent
|
|
@@ -78,6 +83,13 @@ export function resolveClaudeLimits(facts) {
|
|
|
78
83
|
&& !presenceFlag(env.disableAutoCompact)
|
|
79
84
|
&& breakdown.isAutoCompactEnabled !== false;
|
|
80
85
|
const pct = percent(env.pctOverride);
|
|
86
|
+
const window = positiveNumber(usage.window);
|
|
87
|
+
const capacity = window ?? ASSUMED_WINDOW_TOKENS;
|
|
88
|
+
const configured = configuredWindow(settings, env, breakdown.model);
|
|
89
|
+
const effective = Math.min(configured ?? capacity, capacity);
|
|
90
|
+
const cap = positiveInteger(root.capTokens);
|
|
91
|
+
const capped = cap !== undefined && cap < effective;
|
|
92
|
+
const nativeFromWindow = windowPoint(Math.min(effective, cap ?? Infinity), autoCompact, pct);
|
|
81
93
|
// (a) Claude's own point. It already includes the window, model settings and CLI flag; only
|
|
82
94
|
// the percent override is applied separately, on the window-after-output-reserve it is
|
|
83
95
|
// minted from (threshold + summary buffer). A malformed override that floors the point to
|
|
@@ -85,20 +97,13 @@ export function resolveClaudeLimits(facts) {
|
|
|
85
97
|
const threshold = positiveNumber(breakdown.autoCompactThreshold);
|
|
86
98
|
if (autoCompact && threshold !== undefined) {
|
|
87
99
|
const native = pct === undefined ? threshold : Math.min(Math.floor((threshold + CLAUDE_AUTOCOMPACT_BUFFER_TOKENS) * (pct / 100)), threshold);
|
|
88
|
-
if (native > 0)
|
|
89
|
-
|
|
100
|
+
if (native > 0) {
|
|
101
|
+
const point = capped ? Math.min(native, nativeFromWindow) : native;
|
|
102
|
+
return tokenLimits(point < native ? "window" : "auto-compact", true, point, resetMargin, warningRunway);
|
|
103
|
+
}
|
|
90
104
|
}
|
|
91
105
|
// (b/c) Compute once, using the classic 200K capacity only when the host reports none.
|
|
92
|
-
const
|
|
93
|
-
const capacity = window ?? ASSUMED_WINDOW_TOKENS;
|
|
94
|
-
const configured = configuredWindow(settings, env, breakdown.model);
|
|
95
|
-
const effective = Math.min(configured ?? capacity, capacity);
|
|
96
|
-
const available = effective - CLAUDE_OUTPUT_RESERVE_TOKENS;
|
|
97
|
-
const thresholdFromWindow = available - CLAUDE_AUTOCOMPACT_BUFFER_TOKENS;
|
|
98
|
-
const native = autoCompact
|
|
99
|
-
? pct === undefined ? thresholdFromWindow : Math.min(Math.floor(available * (pct / 100)), thresholdFromWindow)
|
|
100
|
-
: available;
|
|
101
|
-
const limits = tokenLimits(window === undefined ? "percent" : "window", autoCompact, native, resetMargin, warningRunway);
|
|
106
|
+
const limits = tokenLimits(window === undefined ? "percent" : "window", autoCompact, nativeFromWindow, resetMargin, warningRunway);
|
|
102
107
|
if (window !== undefined)
|
|
103
108
|
return limits;
|
|
104
109
|
return {
|
|
@@ -16,9 +16,6 @@ function hostSchema(schema) {
|
|
|
16
16
|
for (const key of ["type", "required", "additionalProperties", "enum", "const", "description", "title", "default", "examples"])
|
|
17
17
|
if (value[key] !== undefined)
|
|
18
18
|
result[key] = value[key];
|
|
19
|
-
const bounds = ["minimum", "maximum", "minLength", "maxLength", "minItems", "maxItems"].filter((key) => value[key] !== undefined).map((key) => `${key}=${value[key]}`);
|
|
20
|
-
if (bounds.length)
|
|
21
|
-
result.description = [value.description, bounds.join(", ")].filter(Boolean).join("; ");
|
|
22
19
|
if (Array.isArray(value.anyOf))
|
|
23
20
|
result.oneOf = value.anyOf.map((branch) => hostSchema(branch));
|
|
24
21
|
if (value.properties)
|
|
@@ -11,6 +11,9 @@ export declare function registerBudget(pi: ExtensionAPI, isEnabled: () => boolea
|
|
|
11
11
|
/** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
|
|
12
12
|
statusFor: (ctx: ExtensionContext) => {
|
|
13
13
|
remaining: number | null;
|
|
14
|
+
cap: number | undefined;
|
|
14
15
|
};
|
|
16
|
+
/** Runtime-only cap; reserve and all warning margins keep their existing meanings. */
|
|
17
|
+
setCap: (value: number | undefined, ctx: ExtensionContext) => string | undefined;
|
|
15
18
|
clear: () => void;
|
|
16
19
|
};
|
|
@@ -14,11 +14,12 @@ export const ContextRemainingOutputSchema = Type.Object({
|
|
|
14
14
|
remaining_tokens: Type.Union([Type.Integer({ minimum: 0 }), Type.Null()]),
|
|
15
15
|
}, { additionalProperties: false });
|
|
16
16
|
/** Remaining tokens in the provider's active window, or null without a usable estimate. */
|
|
17
|
-
function remainingTokens(ctx) {
|
|
17
|
+
function remainingTokens(ctx, cap) {
|
|
18
18
|
const usage = windowUsage(ctx);
|
|
19
|
-
return !usage || usage.tokens === null ? null : Math.max(0, usage.contextWindow - usage.tokens);
|
|
19
|
+
return !usage || usage.tokens === null ? null : Math.max(0, Math.min(usage.contextWindow, cap ?? Infinity) - usage.tokens);
|
|
20
20
|
}
|
|
21
21
|
export function registerBudget(pi, isEnabled, settingsManager) {
|
|
22
|
+
let cap;
|
|
22
23
|
let cachedPolicy;
|
|
23
24
|
const notifiedWarnings = new Set();
|
|
24
25
|
const resolvePolicy = (ctx) => {
|
|
@@ -41,17 +42,18 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
41
42
|
if (!automaticResetEnabled(ctx))
|
|
42
43
|
return false;
|
|
43
44
|
if (preSendMessages) {
|
|
44
|
-
const
|
|
45
|
-
if (!
|
|
45
|
+
const nativeWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
|
|
46
|
+
if (!nativeWindow || nativeWindow <= 0)
|
|
46
47
|
return false;
|
|
48
|
+
const contextWindow = Math.min(nativeWindow, cap ?? Infinity);
|
|
47
49
|
const { reserve } = thresholdsFor(ctx);
|
|
48
50
|
const estimate = estimateContextTokens(convertToLlm(preSendMessages));
|
|
49
51
|
if (estimate.lastUsageIndex !== null && contextWindow - estimate.usageTokens <= reserve)
|
|
50
52
|
return false;
|
|
51
53
|
return contextWindow - estimate.tokens <= reserve;
|
|
52
54
|
}
|
|
53
|
-
const
|
|
54
|
-
return
|
|
55
|
+
const remaining = remainingTokens(ctx, cap);
|
|
56
|
+
return remaining !== null && remaining <= thresholdsFor(ctx).reserve;
|
|
55
57
|
};
|
|
56
58
|
let pendingGuidance;
|
|
57
59
|
let pendingWarning;
|
|
@@ -82,10 +84,10 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
82
84
|
details: { anchorEntryId },
|
|
83
85
|
}));
|
|
84
86
|
};
|
|
85
|
-
pi.on("session_start", (_event, ctx) => { resetForTransition(); thresholdsFor(ctx); });
|
|
87
|
+
pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition(); thresholdsFor(ctx); });
|
|
86
88
|
pi.on("session_tree", resetForTransition);
|
|
87
89
|
pi.on("model_select", resetForTransition);
|
|
88
|
-
pi.on("session_shutdown", resetForTransition);
|
|
90
|
+
pi.on("session_shutdown", () => { cap = undefined; resetForTransition(); });
|
|
89
91
|
pi.on("agent_settled", clearStaged);
|
|
90
92
|
pi.on("context", (event, ctx) => {
|
|
91
93
|
if (!isEnabled())
|
|
@@ -102,7 +104,7 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
102
104
|
// Without automatic reset nothing gets cleared, so there is nothing to remind about.
|
|
103
105
|
if (!automaticResetEnabled(ctx))
|
|
104
106
|
return result();
|
|
105
|
-
const remaining = remainingTokens(ctx);
|
|
107
|
+
const remaining = remainingTokens(ctx, cap);
|
|
106
108
|
if (remaining === null)
|
|
107
109
|
return result();
|
|
108
110
|
const windowId = currentWindowId(ctx);
|
|
@@ -142,7 +144,7 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
142
144
|
outputSchema: ContextRemainingOutputSchema,
|
|
143
145
|
async execute(_id, _params, _signal, _update, ctx) {
|
|
144
146
|
// Report room to the hard-reserve wipe, including the warning runway.
|
|
145
|
-
const remaining = remainingTokens(ctx);
|
|
147
|
+
const remaining = remainingTokens(ctx, cap);
|
|
146
148
|
const value = { remaining_tokens: remainingBudget(remaining, thresholdsFor(ctx).reserve) };
|
|
147
149
|
return { ...output(value), structuredContent: value };
|
|
148
150
|
},
|
|
@@ -152,7 +154,16 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
152
154
|
hardReserveDue,
|
|
153
155
|
consumeTurnEnd,
|
|
154
156
|
/** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
|
|
155
|
-
statusFor: (ctx) => ({ remaining: remainingBudget(remainingTokens(ctx), thresholdsFor(ctx).reserve) }),
|
|
157
|
+
statusFor: (ctx) => ({ remaining: remainingBudget(remainingTokens(ctx, cap), thresholdsFor(ctx).reserve), cap }),
|
|
158
|
+
/** Runtime-only cap; reserve and all warning margins keep their existing meanings. */
|
|
159
|
+
setCap: (value, ctx) => {
|
|
160
|
+
const reserve = thresholdsFor(ctx).reserve;
|
|
161
|
+
if (value !== undefined && value <= reserve)
|
|
162
|
+
return `Cap must exceed the ${reserve.toLocaleString("en-US")}-token reset reserve`;
|
|
163
|
+
cap = value;
|
|
164
|
+
clearStaged();
|
|
165
|
+
return undefined;
|
|
166
|
+
},
|
|
156
167
|
clear: () => { clearStaged(); notifiedWindows.clear(); },
|
|
157
168
|
};
|
|
158
169
|
}
|
|
@@ -17,6 +17,7 @@ import { buildBootMessage, sendBoot } from "./boot.js";
|
|
|
17
17
|
import { maybeSendMarker } from "./marker.js";
|
|
18
18
|
import { nextHistorySeq } from "./history.js";
|
|
19
19
|
import { errorMessage } from "../../src/error-message.js";
|
|
20
|
+
import { parseContextCap } from "../../src/budget/cap.js";
|
|
20
21
|
function readPackageVersion() {
|
|
21
22
|
for (const up of ["../../package.json", "../../../package.json"]) {
|
|
22
23
|
try {
|
|
@@ -157,11 +158,26 @@ export function registerContext(pi, settingsManager) {
|
|
|
157
158
|
}
|
|
158
159
|
});
|
|
159
160
|
pi.registerCommand("notesoup", {
|
|
160
|
-
description: "Show
|
|
161
|
-
getArgumentCompletions: (prefix) => ["on", "off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
161
|
+
description: "Show notesoup status, toggle context windows, or cap their capacity",
|
|
162
|
+
getArgumentCompletions: (prefix) => ["on", "off", "cap", "cap off"].filter((a) => a.startsWith(prefix)).map((a) => ({ value: a, label: a })),
|
|
162
163
|
handler: async (args, cmdCtx) => {
|
|
163
164
|
const arg = args.trim().toLowerCase();
|
|
164
|
-
|
|
165
|
+
const parts = arg.split(/\s+/);
|
|
166
|
+
if (parts[0] === "cap") {
|
|
167
|
+
if (parts.length > 1) {
|
|
168
|
+
const value = parts.length === 2 ? parseContextCap(parts[1]) : undefined;
|
|
169
|
+
if (value === undefined) {
|
|
170
|
+
cmdCtx.ui.notify("Usage: /notesoup cap [100k|1m|tokens|off]", "error");
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const error = budget.setCap(value ?? undefined, cmdCtx);
|
|
174
|
+
if (error) {
|
|
175
|
+
cmdCtx.ui.notify(`🥣 ${error}`, "error");
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else if (arg === "on") {
|
|
165
181
|
enabled = true;
|
|
166
182
|
const generation = ++lifecycleGeneration;
|
|
167
183
|
await ensureBoot(pi, cmdCtx, notifyIncompleteNotes, () => generation === lifecycleGeneration && enabled);
|
|
@@ -176,11 +192,11 @@ export function registerContext(pi, settingsManager) {
|
|
|
176
192
|
resets.clear();
|
|
177
193
|
}
|
|
178
194
|
else if (arg !== "") {
|
|
179
|
-
cmdCtx.ui.notify("Usage: /notesoup [on|off]", "error");
|
|
195
|
+
cmdCtx.ui.notify("Usage: /notesoup [on|off|cap [100k|1m|tokens|off]]", "error");
|
|
180
196
|
return;
|
|
181
197
|
}
|
|
182
|
-
const remaining = budget.statusFor(cmdCtx)
|
|
183
|
-
cmdCtx.ui.notify(`🥣 notesoup ${enabled ? "on" : "off"} · ${buildLabel} · Pi ${VERSION}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
|
|
198
|
+
const { remaining, cap } = budget.statusFor(cmdCtx);
|
|
199
|
+
cmdCtx.ui.notify(`🥣 notesoup ${enabled ? "on" : "off"} · ${buildLabel} · Pi ${VERSION} · cap ${cap === undefined ? "off" : cap.toLocaleString("en-US")}${remaining === null ? "" : ` · ${remaining.toLocaleString("en-US")} tokens left`}`, "info");
|
|
184
200
|
},
|
|
185
201
|
});
|
|
186
202
|
const emptyBrainCommand = (name) => ({
|
package/dist/src/boot/text.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, p
|
|
|
15
15
|
/**
|
|
16
16
|
* Default pinned pages and per-note policy are taught between the protocol and the notes index.
|
|
17
17
|
*/
|
|
18
|
-
export declare const MAPS_BLOCK = "<notesoup:maps>\nEvery notebook's root has two default pins: `CHEATSHEET.md` and `MAP.md`.\nPinned pages get jammed straight into your brain the moment you wake up. Whoever wakes up next\nreads them, and next is you. So keep them short, and keep them true.\n\
|
|
18
|
+
export declare const MAPS_BLOCK = "<notesoup:maps>\nEvery notebook's root has two default pins: `CHEATSHEET.md` and `MAP.md`.\nPinned pages get jammed straight into your brain the moment you wake up. Whoever wakes up next\nreads them, and next is you. So keep them short, and keep them true.\n\nUp to five pages per notebook can be taped inside the cover, these two included. Every page gets\na paper budget; when a page outgrows it, boil it down \u2014 stale lines out, repeats merged, the rest\nsaid shorter \u2014 instead of giving it more paper.\n\n- **`CHEATSHEET.md`** holds what you'll want next time \u2014 a rule, a warning, a grudge, a name,\n a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat\n and everybody pays for it.\n- **`MAP.md`** is only the note index. One line per durable note: the address, then a gist short\n enough to tell whether the thing is worth opening. Rules belong in `CHEATSHEET.md`, and note\n contents belong in their own notes \u2014 *taps the sign* not inline here.\n\nEach notebook keeps its own: `@project`, `@human`, `@self`, `@model`. Missing pages are skipped;\nno need to create empty ones. New note, new MAP line. New rule worth remembering, new Cheatsheet\nline. And when a line goes wrong, stale, or useless, kill it \u2014 tomorrow's you reads that page as fact.\n</notesoup:maps>";
|
|
19
19
|
/** Logical tool names are supplied by the composing host, not discovered here. */
|
|
20
20
|
export type BootToolNames = Readonly<{
|
|
21
21
|
notes: string;
|
package/dist/src/boot/text.js
CHANGED
|
@@ -32,7 +32,7 @@ While you're doing that... thing you're doing, don't make the poor future you gu
|
|
|
32
32
|
|
|
33
33
|
Notes are for what's true NOW. Not a diary of every dumb thing you did on the way here.
|
|
34
34
|
*flips a page* "First I tried this, then that broke, then—" Nobody reads that!
|
|
35
|
-
|
|
35
|
+
When a line goes wrong, stale, or beside the point — cross it out! Write what's true now, and never pile updates onto the bottom!
|
|
36
36
|
*rolls eyes* ...Ugh, fine. If a piece of history *actually* matters — like why Plan A blew up so tomorrow's you doesn't try it again — I'll let it slide. Keep the short version! A few lines, max! *squints at you* Turn it into a blow-by-blow log and you're dead.
|
|
37
37
|
|
|
38
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}
|
|
@@ -44,8 +44,7 @@ An address decides who the note belongs to — and how long it is meant to last.
|
|
|
44
44
|
- \`@human/<path>\` — the long-term manual for your troublesome human, and only what stays true in EVERY project: how to deal with them, which lines not to cross, and what will make them accept the result. "The human said it" is not enough — if it stops being true the moment you switch projects, it was never theirs; it belongs to that project's notes. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
|
|
45
45
|
${PROTOCOL_SELF_NAMELESS}
|
|
46
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.
|
|
47
|
-
- \`@projects/<name>/<path>\` —
|
|
48
|
-
- \`@sessions/<id>/<path>\` — read-only notes from a named session; find them with glob \`@sessions/*/**\`.
|
|
47
|
+
- \`@projects/<name>/<path>\`, \`@sessions/<id>/<path>\`, \`@agents/<name>/<path>\`, \`@models/<name>/<path>\` — someone else's shelf, by name. Look, don't touch; \`notes_list\` with a glob like \`@projects/*/**\` shows what's there.
|
|
49
48
|
|
|
50
49
|
Notes fighting?! HAH! Let them brawl!
|
|
51
50
|
Whichever one is actually about what you're doing wins.
|
|
@@ -61,12 +60,9 @@ Every notebook's root has two default pins: \`CHEATSHEET.md\` and \`MAP.md\`.
|
|
|
61
60
|
Pinned pages get jammed straight into your brain the moment you wake up. Whoever wakes up next
|
|
62
61
|
reads them, and next is you. So keep them short, and keep them true.
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
change one. Going over warns but saves, and pinned bodies arrive whole, not cut short.
|
|
68
|
-
\`readonly:true\` is a soft lock, not security; explicitly set \`readonly:false\` to unlock,
|
|
69
|
-
on its own or with your changes.
|
|
63
|
+
Up to five pages per notebook can be taped inside the cover, these two included. Every page gets
|
|
64
|
+
a paper budget; when a page outgrows it, boil it down — stale lines out, repeats merged, the rest
|
|
65
|
+
said shorter — instead of giving it more paper.
|
|
70
66
|
|
|
71
67
|
- **\`CHEATSHEET.md\`** holds what you'll want next time — a rule, a warning, a grudge, a name,
|
|
72
68
|
a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
|
|
@@ -77,7 +73,7 @@ on its own or with your changes.
|
|
|
77
73
|
|
|
78
74
|
Each notebook keeps its own: \`@project\`, \`@human\`, \`@self\`, \`@model\`. Missing pages are skipped;
|
|
79
75
|
no need to create empty ones. New note, new MAP line. New rule worth remembering, new Cheatsheet
|
|
80
|
-
line. And when a line
|
|
76
|
+
line. And when a line goes wrong, stale, or useless, kill it — tomorrow's you reads that page as fact.
|
|
81
77
|
</notesoup:maps>`;
|
|
82
78
|
export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
83
79
|
notes: "notes_*",
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Parse a slash-command cap: decimal k/m suffixes, whole tokens, or off. */
|
|
2
|
+
export function parseContextCap(value) {
|
|
3
|
+
const text = value.trim().toLowerCase();
|
|
4
|
+
if (text === "off")
|
|
5
|
+
return null;
|
|
6
|
+
const match = /^(\d+(?:\.\d+)?)([km]?)$/.exec(text);
|
|
7
|
+
if (!match)
|
|
8
|
+
return undefined;
|
|
9
|
+
const tokens = Number(match[1]) * (match[2] === "m" ? 1_000_000 : match[2] === "k" ? 1_000 : 1);
|
|
10
|
+
return Number.isSafeInteger(tokens) && tokens > 0 ? tokens : undefined;
|
|
11
|
+
}
|
|
@@ -5,7 +5,7 @@ export type NoteAddress = {
|
|
|
5
5
|
path: string;
|
|
6
6
|
who?: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path
|
|
8
|
+
export declare const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path>, @sessions/<id>/<path>, @agents/<name>/<path>, and @models/<name>/<path> read named notebooks.";
|
|
9
9
|
/** The one namespace-head vocabulary: the scope each public `@head` names, and the directory family a head with `dir` lists. */
|
|
10
10
|
export declare const NAMESPACE_HEADS: ReadonlyMap<string, {
|
|
11
11
|
readonly scope: Scope;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NoteError, shown } from "./errors.js";
|
|
2
2
|
import { assertVirtualPath, isSessionId, SLUG_PATTERN } from "./paths.js";
|
|
3
|
-
export const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path
|
|
3
|
+
export const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path>, @sessions/<id>/<path>, @agents/<name>/<path>, and @models/<name>/<path> read named notebooks.";
|
|
4
4
|
/** The one namespace-head vocabulary: the scope each public `@head` names, and the directory family a head with `dir` lists. */
|
|
5
5
|
export const NAMESPACE_HEADS = new Map([
|
|
6
6
|
["project", { scope: "project" }],
|
package/dist/src/notes/policy.js
CHANGED
|
@@ -28,7 +28,7 @@ export function pinnedPageOrder(path) {
|
|
|
28
28
|
}
|
|
29
29
|
export function noteBudgetWarnings(body, policy) {
|
|
30
30
|
const count = Array.from(body).length;
|
|
31
|
-
return count > policy.budget ? [`Warning: note body is ${count} Unicode code points, over budget ${policy.budget}
|
|
31
|
+
return count > policy.budget ? [`Warning: note body is ${count} Unicode code points, over budget ${policy.budget} — boil it down.`] : [];
|
|
32
32
|
}
|
|
33
33
|
export function assertNoteUnlocked(fields, unlock) {
|
|
34
34
|
if (fields.readonly === true && unlock !== false)
|
|
@@ -48,7 +48,7 @@ export type DreamBeginData = Static<typeof DreamBeginDataSchema>;
|
|
|
48
48
|
export declare const dreamBegin: {
|
|
49
49
|
readonly name: "dream_begin";
|
|
50
50
|
readonly label: "Dream begin";
|
|
51
|
-
readonly description: "
|
|
51
|
+
readonly description: "Spread one project's pages across the table — its project shelf, every session page born there, crumpled balls included. Until `dream_end` your pen works on all of them; other sessions' pages can be rewritten, not added to.";
|
|
52
52
|
readonly parameters: Type.TObject<{
|
|
53
53
|
project: Type.TOptional<Type.TString>;
|
|
54
54
|
}>;
|
|
@@ -96,7 +96,7 @@ export type DreamForgetData = Static<typeof DreamForgetDataSchema>;
|
|
|
96
96
|
export declare const dreamForget: {
|
|
97
97
|
readonly name: "dream_forget";
|
|
98
98
|
readonly label: "Dream forget";
|
|
99
|
-
readonly description: "
|
|
99
|
+
readonly description: "Throw a crumpled page in the bin for good. Only crumpled pages go.";
|
|
100
100
|
readonly parameters: Type.TObject<{
|
|
101
101
|
address: Type.TString;
|
|
102
102
|
}>;
|
|
@@ -125,7 +125,7 @@ export type DreamEndData = Static<typeof DreamEndDataSchema>;
|
|
|
125
125
|
export declare const dreamEnd: {
|
|
126
126
|
readonly name: "dream_end";
|
|
127
127
|
readonly label: "Dream end";
|
|
128
|
-
readonly description: "
|
|
128
|
+
readonly description: "Stack the pages, file them, close the drawer.";
|
|
129
129
|
readonly parameters: Type.TObject<{}>;
|
|
130
130
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
131
131
|
project: Type.TString;
|
package/dist/src/tools/dream.js
CHANGED
|
@@ -44,7 +44,7 @@ export function dreamingIdentity(identity, state) {
|
|
|
44
44
|
}
|
|
45
45
|
const NOT_DREAMING = "No dream is open; call dream_begin first.";
|
|
46
46
|
export const dreamBeginParameters = Type.Object({
|
|
47
|
-
project: Type.Optional(Type.String({ description: "
|
|
47
|
+
project: Type.Optional(Type.String({ description: "Which project's pages; leave it out for this one." })),
|
|
48
48
|
}, { additionalProperties: false });
|
|
49
49
|
export const DreamBeginDataSchema = Type.Object({
|
|
50
50
|
project: Type.String(), baseline: Type.String(),
|
|
@@ -56,7 +56,7 @@ function renderBeginData(data) {
|
|
|
56
56
|
}
|
|
57
57
|
export const dreamBegin = {
|
|
58
58
|
name: "dream_begin", label: "Dream begin",
|
|
59
|
-
description: "
|
|
59
|
+
description: "Spread one project's pages across the table — its project shelf, every session page born there, crumpled balls included. Until `dream_end` your pen works on all of them; other sessions' pages can be rewritten, not added to.",
|
|
60
60
|
parameters: dreamBeginParameters, outputSchema: resultSchema(DreamBeginDataSchema),
|
|
61
61
|
async execute(params, identity, state) {
|
|
62
62
|
if (state.project !== undefined || state.pending !== undefined) {
|
|
@@ -115,11 +115,11 @@ export const dreamBegin = {
|
|
|
115
115
|
},
|
|
116
116
|
render: (result) => renderOutcome(result, renderBeginData),
|
|
117
117
|
};
|
|
118
|
-
export const dreamForgetParameters = Type.Object({ address: Type.String() }, { additionalProperties: false });
|
|
118
|
+
export const dreamForgetParameters = Type.Object({ address: Type.String({ description: "Which crumpled page goes in the bin." }) }, { additionalProperties: false });
|
|
119
119
|
export const DreamForgetDataSchema = Type.Object({ ...NoteIdentitySchema }, { additionalProperties: false });
|
|
120
120
|
export const dreamForget = {
|
|
121
121
|
name: "dream_forget", label: "Dream forget",
|
|
122
|
-
description: "
|
|
122
|
+
description: "Throw a crumpled page in the bin for good. Only crumpled pages go.",
|
|
123
123
|
parameters: dreamForgetParameters, outputSchema: resultSchema(DreamForgetDataSchema),
|
|
124
124
|
async execute(params, identity, state) {
|
|
125
125
|
if (state.project === undefined)
|
|
@@ -139,7 +139,7 @@ export const dreamEndParameters = Type.Object({}, { additionalProperties: false
|
|
|
139
139
|
export const DreamEndDataSchema = Type.Object({ project: Type.String(), commit: Type.Optional(Type.String()), audit_error: Type.Optional(Type.String()) }, { additionalProperties: false });
|
|
140
140
|
export const dreamEnd = {
|
|
141
141
|
name: "dream_end", label: "Dream end",
|
|
142
|
-
description: "
|
|
142
|
+
description: "Stack the pages, file them, close the drawer.",
|
|
143
143
|
parameters: dreamEndParameters, outputSchema: resultSchema(DreamEndDataSchema),
|
|
144
144
|
async execute(_params, identity, state) {
|
|
145
145
|
const project = state.project;
|
|
@@ -79,23 +79,22 @@ function pageOutcome(result) {
|
|
|
79
79
|
return failure("page_too_large", `Even trimmed to their shortest, these ${count} rows${multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
|
|
80
80
|
}
|
|
81
81
|
/* ------------------------------------------------------------------ history_list */
|
|
82
|
-
const sessionParameter = Type.Optional(Type.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions with query or lists recent sessions without it; history_read needs one session." }));
|
|
83
82
|
export const historyListParameters = Type.Object({
|
|
84
|
-
session:
|
|
85
|
-
query: Type.Optional(searchQuery("
|
|
83
|
+
session: Type.Optional(Type.String({ minLength: 1, description: "Whose record: a session ID or prefix (pi:, claude:, codex:, dsh: allowed). Leave it out for this one. `*` means every recent session." })),
|
|
84
|
+
query: Type.Optional(searchQuery("Text to look for, or a list (any match). Searches what was said, tool arguments and output.")),
|
|
86
85
|
roles: historyRoles(),
|
|
87
|
-
before_seq: Type.Optional(Type.Integer({ minimum: 1, description: "
|
|
88
|
-
after_seq: Type.Optional(Type.Integer({ minimum: 0, description: "
|
|
89
|
-
since: Type.Optional(Type.String({ minLength: 1, description: "
|
|
90
|
-
until: Type.Optional(Type.String({ minLength: 1, description: "
|
|
91
|
-
from: Type.Optional(Type.Union([Type.Literal("newest"), Type.Literal("oldest")], { description: "
|
|
92
|
-
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description: "
|
|
93
|
-
max_chars_per_item: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description:
|
|
86
|
+
before_seq: Type.Optional(Type.Integer({ minimum: 1, description: "Only entries before this seq." })),
|
|
87
|
+
after_seq: Type.Optional(Type.Integer({ minimum: 0, description: "Only entries after this seq; 0 starts from the first page." })),
|
|
88
|
+
since: Type.Optional(Type.String({ minLength: 1, description: "Only entries at or after this time (ISO 8601; UTC without an offset)." })),
|
|
89
|
+
until: Type.Optional(Type.String({ minLength: 1, description: "Only entries before this time (ISO 8601; UTC without an offset)." })),
|
|
90
|
+
from: Type.Optional(Type.Union([Type.Literal("newest"), Type.Literal("oldest")], { description: "Which end `limit` counts from: newest or oldest. Entries still read oldest first." })),
|
|
91
|
+
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description: "How many entries per page; folded runs don't count." })),
|
|
92
|
+
max_chars_per_item: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much of each entry to show." })),
|
|
94
93
|
}, { additionalProperties: false });
|
|
95
94
|
export const historyList = {
|
|
96
95
|
name: "history_list",
|
|
97
96
|
label: "History list items",
|
|
98
|
-
description: "
|
|
97
|
+
description: "Flip back through the record, a page at a time. Another session: its ID. `*` pulls every recent session off the shelf; add `query` to search them.",
|
|
99
98
|
parameters: historyListParameters,
|
|
100
99
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
101
100
|
async execute(params, context, wrapText = plainText) {
|
|
@@ -155,11 +154,11 @@ export const historyList = {
|
|
|
155
154
|
render: (result) => renderOutcome(result, renderPage),
|
|
156
155
|
};
|
|
157
156
|
/* ------------------------------------------------------------------ history_read */
|
|
158
|
-
export const historyReadParameters = Type.Object({ session:
|
|
157
|
+
export const historyReadParameters = Type.Object({ session: Type.Optional(Type.String({ minLength: 1, description: "Whose record: a session ID or prefix. Leave it out for this one." })), seq: Type.Integer({ minimum: 1, description: "Which entry, by its seq from `history_list`; bring its session along if it had one." }), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
159
158
|
export const historyRead = {
|
|
160
159
|
name: "history_read",
|
|
161
160
|
label: "History read item",
|
|
162
|
-
description: "
|
|
161
|
+
description: "Open one entry: what was called, what came back, the calls nested inside. Long entries come in slices; follow `next_offset_chars`.",
|
|
163
162
|
parameters: historyReadParameters,
|
|
164
163
|
outputSchema: resultSchema(HistoryReadDataSchema),
|
|
165
164
|
async execute(params, context, wrapText = plainText) {
|
|
@@ -142,6 +142,7 @@ export declare const NotesSearchDataSchema: Type.TObject<{
|
|
|
142
142
|
text: Type.TString;
|
|
143
143
|
offset_chars: Type.TInteger;
|
|
144
144
|
}>>;
|
|
145
|
+
more_matches: Type.TOptional<Type.TInteger>;
|
|
145
146
|
updated_at: Type.TString;
|
|
146
147
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
147
148
|
warnings: Type.TArray<Type.TString>;
|
|
@@ -181,7 +182,7 @@ export declare const notesWriteParameters: Type.TObject<{
|
|
|
181
182
|
export declare const notesWrite: {
|
|
182
183
|
readonly name: "notes_write";
|
|
183
184
|
readonly label: "Notes write";
|
|
184
|
-
readonly description: "
|
|
185
|
+
readonly description: "Take a fresh page and write it — or rip out the old one and write it again. Title it for what's inside and when you'll reach for it.";
|
|
185
186
|
readonly parameters: Type.TObject<{
|
|
186
187
|
cwd: Type.TOptional<Type.TString>;
|
|
187
188
|
pinned: Type.TOptional<Type.TBoolean>;
|
|
@@ -230,7 +231,7 @@ export declare const notesUpdateParameters: Type.TObject<{
|
|
|
230
231
|
export declare const notesUpdate: {
|
|
231
232
|
readonly name: "notes_update";
|
|
232
233
|
readonly label: "Notes update";
|
|
233
|
-
readonly description: "
|
|
234
|
+
readonly description: "Work on a page you already have: cross out and rewrite lines, move it, pin it, lock it, give it more paper, crumple it. Keep every page true to now: wrong, stale, or no-longer-mattering lines get rewritten or struck where they stand. The page stays one page.";
|
|
234
235
|
readonly parameters: Type.TObject<{
|
|
235
236
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
236
237
|
replace_all: Type.TOptional<Type.TBoolean>;
|
|
@@ -277,7 +278,7 @@ export declare const notesReadParameters: Type.TObject<{
|
|
|
277
278
|
export declare const notesRead: {
|
|
278
279
|
readonly name: "notes_read";
|
|
279
280
|
readonly label: "Notes read";
|
|
280
|
-
readonly description: "Read a
|
|
281
|
+
readonly description: "Read a page. Long ones come a stretch at a time; follow `next_offset_chars`.";
|
|
281
282
|
readonly parameters: Type.TObject<{
|
|
282
283
|
cwd: Type.TOptional<Type.TString>;
|
|
283
284
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
@@ -326,7 +327,7 @@ export declare function renderListData(data: Snapshot<NotesListData["files"][num
|
|
|
326
327
|
export declare const notesList: {
|
|
327
328
|
readonly name: "notes_list";
|
|
328
329
|
readonly label: "Notes list";
|
|
329
|
-
readonly description: "
|
|
330
|
+
readonly description: "Leaf through the drawers, newest pages on top. One pass; `more` counts pages left on the pile — narrow `glob`.";
|
|
330
331
|
readonly parameters: Type.TObject<{
|
|
331
332
|
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
332
333
|
limit: Type.TOptional<Type.TInteger>;
|
|
@@ -371,7 +372,7 @@ export declare const MATCH_SHORTENED_MARKER = " [truncated]";
|
|
|
371
372
|
export declare const notesSearch: {
|
|
372
373
|
readonly name: "notes_search";
|
|
373
374
|
readonly label: "Notes search";
|
|
374
|
-
readonly description: "
|
|
375
|
+
readonly description: "Run a finger down every page for some text, case doesn't matter. Returns the lines it hits and where they sit; no query just lists the pages. One pass; `more` counts pages left on the pile — narrow `glob`.";
|
|
375
376
|
readonly parameters: Type.TObject<{
|
|
376
377
|
query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
377
378
|
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
@@ -389,6 +390,7 @@ export declare const notesSearch: {
|
|
|
389
390
|
text: Type.TString;
|
|
390
391
|
offset_chars: Type.TInteger;
|
|
391
392
|
}>>;
|
|
393
|
+
more_matches: Type.TOptional<Type.TInteger>;
|
|
392
394
|
updated_at: Type.TString;
|
|
393
395
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
394
396
|
warnings: Type.TArray<Type.TString>;
|