notesoup 0.61.0 → 0.62.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/.agents/plugins/marketplace.json +15 -0
- package/README.md +14 -11
- package/dist/plugins/antigravity/src/cli.d.ts +1 -0
- package/dist/plugins/antigravity/src/cli.js +23 -0
- package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
- package/dist/plugins/antigravity/src/hooks.js +53 -0
- package/dist/plugins/antigravity/src/identity.d.ts +26 -0
- package/dist/plugins/antigravity/src/identity.js +129 -0
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/codex/src/hooks.js +1 -0
- package/dist/plugins/codex/src/identity.d.ts +6 -1
- package/dist/plugins/codex/src/identity.js +13 -1
- package/dist/plugins/codex/src/mcp.d.ts +35 -7
- package/dist/plugins/codex/src/mcp.js +26 -88
- package/dist/plugins/codex/src/text.js +3 -3
- package/dist/plugins/dsh/tools.js +8 -4
- package/dist/plugins/mcp/operations.d.ts +15 -0
- package/dist/plugins/mcp/operations.js +43 -0
- package/dist/plugins/mcp/server.d.ts +14 -0
- package/dist/plugins/mcp/server.js +13 -0
- package/dist/plugins/pi/budget.d.ts +1 -1
- package/dist/plugins/pi/budget.js +3 -2
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.js +2 -1
- package/dist/plugins/pi/history.js +18 -1
- package/dist/plugins/pi/notes/tools.js +7 -3
- package/dist/plugins/pi/render.d.ts +7 -1
- package/dist/plugins/pi/render.js +2 -2
- package/dist/plugins/pi/reset/lifecycle.d.ts +1 -1
- package/dist/plugins/pi/reset/lifecycle.js +8 -9
- package/dist/plugins/pi/runtime.js +102 -61
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +33 -3
- package/dist/plugins/pi/window.js +209 -9
- package/dist/src/boot/render.js +18 -15
- package/dist/src/boot/text.d.ts +3 -1
- package/dist/src/boot/text.js +22 -20
- package/dist/src/budget/text.d.ts +2 -2
- package/dist/src/budget/text.js +13 -13
- package/dist/src/history/claude.d.ts +2 -0
- package/dist/src/history/claude.js +46 -0
- package/dist/src/history/codex-transcript.js +7 -5
- package/dist/src/history/codex.js +3 -0
- package/dist/src/history/corpus.d.ts +28 -1
- package/dist/src/history/corpus.js +40 -0
- package/dist/src/history/history.d.ts +37 -46
- package/dist/src/history/history.js +21 -40
- package/dist/src/history/local.js +67 -32
- package/dist/src/history/pi.d.ts +2 -1
- package/dist/src/history/pi.js +122 -48
- package/dist/src/history/prefilter.js +76 -19
- package/dist/src/history/query.d.ts +28 -49
- package/dist/src/history/query.js +83 -68
- package/dist/src/history/summary-cache.d.ts +8 -1
- package/dist/src/history/summary-cache.js +138 -12
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.d.ts +0 -2
- package/dist/src/notes/frontmatter.js +0 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/policy.d.ts +15 -1
- package/dist/src/notes/policy.js +46 -5
- package/dist/src/notes/store.d.ts +12 -0
- package/dist/src/notes/store.js +16 -20
- package/dist/src/text-match.d.ts +10 -1
- package/dist/src/text-match.js +42 -3
- package/dist/src/tools/dream.d.ts +22 -93
- package/dist/src/tools/dream.js +30 -27
- package/dist/src/tools/history.d.ts +33 -26
- package/dist/src/tools/history.js +257 -163
- package/dist/src/tools/notes.d.ts +51 -163
- package/dist/src/tools/notes.js +146 -100
- package/dist/src/tools/output.d.ts +2 -1
- package/dist/src/tools/output.js +2 -1
- package/dist/src/tools/result.d.ts +4 -7
- package/dist/src/tools/result.js +8 -9
- package/dist/src/tools/schema.d.ts +4 -1
- package/dist/src/tools/schema.js +25 -1
- package/dist/test/agent-loop.test.js +198 -16
- package/dist/test/antigravity-live.test.d.ts +1 -0
- package/dist/test/antigravity-live.test.js +142 -0
- package/dist/test/antigravity-plugin.test.d.ts +1 -0
- package/dist/test/antigravity-plugin.test.js +101 -0
- package/dist/test/boot.integration.test.js +133 -14
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +9 -6
- package/dist/test/codex-history.test.js +15 -3
- package/dist/test/codex-plugin.test.js +76 -38
- package/dist/test/dependencies.test.js +7 -3
- package/dist/test/dream-skill.test.js +3 -3
- package/dist/test/dream-tools.test.js +101 -56
- package/dist/test/dsh.test.js +34 -19
- package/dist/test/helpers/dependency-graph.js +2 -2
- package/dist/test/helpers/extension.d.ts +65 -2
- package/dist/test/helpers/extension.js +72 -3
- package/dist/test/history-corpus.test.js +79 -77
- package/dist/test/history-summary-cache.test.js +97 -9
- package/dist/test/history.integration.test.js +234 -168
- package/dist/test/host-neutral.test.js +69 -19
- package/dist/test/marker.test.js +1 -1
- package/dist/test/note-policy.test.js +96 -77
- package/dist/test/notes.integration.test.js +212 -94
- package/dist/test/notes.test.js +184 -113
- package/dist/test/pi-render.test.js +20 -12
- package/dist/test/project-namespace.test.js +3 -2
- package/dist/test/reset-lifecycle.test.js +2 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +2 -2
- package/docs/codex.md +36 -38
- package/docs/dsh.md +3 -3
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +4 -4
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +47 -28
- package/package.json +3 -2
- package/playbook.md +1 -1
- package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
- package/plugins/antigravity/hooks.json +7 -0
- package/plugins/antigravity/mcp_config.json +8 -0
- package/plugins/antigravity/plugin.json +6 -0
- package/plugins/antigravity/src/cli.ts +22 -0
- package/plugins/antigravity/src/hooks.ts +51 -0
- package/plugins/antigravity/src/identity.ts +127 -0
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +1059 -534
- package/plugins/claude/hooks/register.ts +2 -2
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/notesoup/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +2 -1
- package/plugins/codex/.codex-plugin/plugin.json +8 -0
- package/plugins/codex/.mcp.json +11 -0
- package/plugins/codex/README.md +5 -21
- package/plugins/codex/dist/codex/notesoup.js +18480 -17946
- package/plugins/codex/src/hooks.ts +1 -0
- package/plugins/codex/src/identity.ts +14 -1
- package/plugins/codex/src/mcp.ts +28 -98
- package/plugins/codex/src/text.ts +3 -3
- package/plugins/dsh/tools.ts +8 -4
- package/plugins/mcp/operations.ts +50 -0
- package/plugins/mcp/server.ts +23 -0
- package/plugins/paseo/README.md +5 -10
- package/plugins/paseo/client/brain-empty-card.tsx +3 -3
- package/plugins/paseo/client/markdown.tsx +50 -38
- package/plugins/paseo/client/notes-op-card.tsx +12 -9
- package/plugins/paseo/client/paper-card.tsx +6 -5
- package/plugins/paseo/client/paper-palette.ts +2 -9
- package/plugins/paseo/client/sticky-card.tsx +2 -2
- package/plugins/paseo/client/tool-result.ts +7 -14
- package/plugins/paseo/package-lock.json +3406 -0
- package/plugins/paseo/package.json +1 -0
- package/plugins/paseo/test/markdown-core.test.ts +73 -66
- package/plugins/pi/budget.ts +3 -3
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +2 -1
- package/plugins/pi/history.ts +30 -1
- package/plugins/pi/notes/tools.ts +7 -3
- package/plugins/pi/render.ts +6 -6
- package/plugins/pi/reset/lifecycle.ts +9 -10
- package/plugins/pi/runtime.ts +96 -60
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +198 -9
- package/skills/dream/SKILL.md +1 -1
- package/skills/notesoup/SKILL.md +92 -0
- package/src/boot/render.ts +18 -15
- package/src/boot/text.ts +23 -19
- package/src/budget/text.ts +13 -13
- package/src/history/claude.ts +41 -0
- package/src/history/codex-transcript.ts +6 -4
- package/src/history/codex.ts +2 -0
- package/src/history/corpus.ts +51 -2
- package/src/history/history.ts +35 -44
- package/src/history/local.ts +67 -27
- package/src/history/pi.ts +113 -35
- package/src/history/prefilter.ts +73 -15
- package/src/history/query.ts +93 -73
- package/src/history/summary-cache.ts +142 -17
- package/src/index.ts +1 -1
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +0 -3
- package/src/notes/index.ts +1 -1
- package/src/notes/policy.ts +44 -5
- package/src/notes/store.ts +17 -20
- package/src/text-match.ts +46 -4
- package/src/tools/dream.ts +29 -31
- package/src/tools/history.ts +249 -142
- package/src/tools/notes.ts +145 -113
- package/src/tools/output.ts +2 -1
- package/src/tools/result.ts +12 -11
- package/src/tools/schema.ts +24 -1
- package/plugins/claude/skills/memory/SKILL.md +0 -69
- package/plugins/codex/mcp.json +0 -10
- package/plugins/codex/plugin.json +0 -6
- package/plugins/paseo/client/markdown-core.tsx +0 -189
- package/plugins/paseo/client/typography.ts +0 -24
- package/skills/memory/SKILL.md +0 -69
package/dist/src/boot/render.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { effectiveNotePolicy, MAX_PINNED_NOTES, noteBudgetWarnings, pinnedPageOrder } from "../notes/policy.js";
|
|
2
|
-
import { collapseDescription
|
|
1
|
+
import { effectiveNotePolicy, MAX_DESCRIPTION_CHARS, MAX_PINNED_NOTES, noteBudgetWarnings, pinnedPageOrder, renderWarnings, truncateToUtf8Bytes } from "../notes/policy.js";
|
|
2
|
+
import { collapseDescription } from "../notes/frontmatter.js";
|
|
3
3
|
import { WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, MAPS_BLOCK, NAMELESS_AGENT, renderProtocolBlock } from "./text.js";
|
|
4
4
|
function relativeTime(timestamp, now) {
|
|
5
5
|
const seconds = Math.trunc((timestamp - now) / 1000);
|
|
@@ -25,7 +25,7 @@ function feedTitle(body) {
|
|
|
25
25
|
const raw = (heading ? heading.replace(/^#+\s+/, "") : lines.find((line) => line.trim().length > 0) ?? "").trim();
|
|
26
26
|
return raw.length === 0 ? undefined : truncated(raw, FALLBACK_TITLE_MAX_CHARS);
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
28
|
+
/** Oversized descriptions are cut for display in the boot index. */
|
|
29
29
|
function summaryOf(row) {
|
|
30
30
|
if (typeof row.meta.description === "string") {
|
|
31
31
|
const collapsed = collapseDescription(row.meta.description);
|
|
@@ -37,11 +37,7 @@ function summaryOf(row) {
|
|
|
37
37
|
function indexLine(row, openedAt) {
|
|
38
38
|
const locator = `${row.address} · ${relativeTime(row.meta.updatedAt, openedAt)}`;
|
|
39
39
|
const summary = summaryOf(row);
|
|
40
|
-
return summary === undefined ?
|
|
41
|
-
}
|
|
42
|
-
/** Two spaces of indent say "shelved content" without any furniture. */
|
|
43
|
-
function indent(text) {
|
|
44
|
-
return text.split("\n").map((line) => (line.length > 0 ? ` ${line}` : line)).join("\n");
|
|
40
|
+
return summary === undefined ? locator : `${locator} — ${summary}`;
|
|
45
41
|
}
|
|
46
42
|
/** An underlined header is the classical plain-text document heading: no renderer required. */
|
|
47
43
|
function section(label, body) {
|
|
@@ -59,7 +55,7 @@ function notesIndex(snapshot, tools, agentName, modelName) {
|
|
|
59
55
|
const shelves = [];
|
|
60
56
|
for (const namespace of namespaces) {
|
|
61
57
|
if (snapshot.unavailable.some((failed) => failed.scope === namespace.scope)) {
|
|
62
|
-
shelves.push(section(namespace.label,
|
|
58
|
+
shelves.push(section(namespace.label, `This drawer wouldn't open. Try \`${tools.notesList}\` again.`));
|
|
63
59
|
continue;
|
|
64
60
|
}
|
|
65
61
|
const rows = (snapshot.namespaces.get(namespace.scope) ?? []).filter((row) => row.meta.crumpledAt === undefined);
|
|
@@ -83,17 +79,24 @@ function notesIndex(snapshot, tools, agentName, modelName) {
|
|
|
83
79
|
}
|
|
84
80
|
const omitted = unpinned.length - index.length;
|
|
85
81
|
if (omitted > 0)
|
|
86
|
-
index.push(
|
|
82
|
+
index.push(`… and ${omitted} more (use ${tools.notesList})`);
|
|
87
83
|
if (pinned.length === 0 && index.length === 0)
|
|
88
84
|
continue;
|
|
89
85
|
const parts = pinned.map(row => {
|
|
90
|
-
const
|
|
91
|
-
|
|
86
|
+
const policy = effectiveNotePolicy(row.meta, row.path);
|
|
87
|
+
const warnings = noteBudgetWarnings(row.body, policy);
|
|
88
|
+
const cut = truncateToUtf8Bytes(row.body, policy.budget);
|
|
89
|
+
const body = !cut.truncated
|
|
90
|
+
? cut.text
|
|
91
|
+
: `${cut.text === "" ? "" : `${cut.text}\n\n`}[truncated at ${cut.shownChars}/${cut.totalChars}; offset_chars=${cut.shownChars}]`;
|
|
92
|
+
const note = [`── ${row.address} ──`, body, "── end of note ──"].join("\n\n");
|
|
93
|
+
return warnings.length > 0 ? `${renderWarnings(warnings)}\n${note}` : note;
|
|
92
94
|
});
|
|
93
|
-
if (pins.length > MAX_PINNED_NOTES)
|
|
94
|
-
parts.push(
|
|
95
|
+
if (pins.length > MAX_PINNED_NOTES) {
|
|
96
|
+
parts.push(renderWarnings([`only ${MAX_PINNED_NOTES} pinned notes per notebook are injected; omitted pins: ${pins.slice(MAX_PINNED_NOTES).map(row => row.address).join(", ")}. Unpin some notes or read the omitted pages with ${tools.notes}.`]));
|
|
97
|
+
}
|
|
95
98
|
if (index.length > 0)
|
|
96
|
-
parts.push(pinned.length > 0 ?
|
|
99
|
+
parts.push(pinned.length > 0 ? `── index ──\n\n${index.join("\n")}` : index.join("\n"));
|
|
97
100
|
shelves.push(section(namespace.label, parts.join("\n\n")));
|
|
98
101
|
}
|
|
99
102
|
return shelves.length > 0
|
package/dist/src/boot/text.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, p
|
|
|
13
13
|
/**
|
|
14
14
|
* Default pinned pages and per-note policy are taught between the protocol and the notes index.
|
|
15
15
|
*/
|
|
16
|
-
export declare const MAPS_BLOCK = "<notesoup:maps>\nEach notebook has one default pin: `CHEATSHEET.md`. Pinned pages get jammed straight into your\nbrain the moment you wake up. Whoever wakes up next reads them, and next is you. So keep them\
|
|
16
|
+
export declare const MAPS_BLOCK = "<notesoup:maps>\nEach notebook has one default pin: `CHEATSHEET.md`. Pinned pages get jammed straight into your\nbrain the moment you wake up. Whoever wakes up next reads them, and next is you. So keep them\ncompact, keep them true, and unpin or crumple them once they stop earning their wake-up seat.\n\nUp to five pages per notebook can be taped inside the cover, CHEATSHEET included. Every page gets\na size budget; if a page outgrows it, trim stale lines or split by topic \u2014 and if it's pinned,\nboot cuts the overflow off until you do.\n\n- **`CHEATSHEET.md`** holds what earns a permanent wake-up seat \u2014 a standing rule, a warning,\n a grudge, a name, a phone number you'll regret losing. Keep it tight, or it grows fat and\n everybody pays for it.\n- **`description`** is one line saying what's inside a note and when to open it, set through\n your notes tools \u2014 keep it short, or boot cuts it off. Boot indexes every shelf from these,\n newest first, address and age beside them. No hand-written map to keep in sync: a stale\n description lies to the next window, so keep it true or crumple the page.\n\nEach notebook keeps its own pins and index. Missing pages are skipped; no need to create empty\nones. New rule worth remembering, new Cheatsheet bullet. And when a line goes wrong, stale, or\nuseless, kill it \u2014 tomorrow's you reads that page as fact.\n</notesoup:maps>";
|
|
17
17
|
/** Logical tool names are supplied by the composing host, not discovered here. */
|
|
18
18
|
export type BootToolNames = Readonly<{
|
|
19
19
|
notes: string;
|
|
@@ -26,6 +26,8 @@ export type BootToolNames = Readonly<{
|
|
|
26
26
|
* no model-facing reset tool. Absent means the shared tool-driven-reset sentence, byte for byte.
|
|
27
27
|
*/
|
|
28
28
|
wipeSentence?: string;
|
|
29
|
+
/** Replace the whole budget/reset paragraph on hosts without either tool. */
|
|
30
|
+
budgetParagraph?: string;
|
|
29
31
|
/** A host without an authoritative history source replaces the entire history advice. */
|
|
30
32
|
historySentence?: string;
|
|
31
33
|
/**
|
package/dist/src/boot/text.js
CHANGED
|
@@ -10,6 +10,7 @@ export const NOTES_PROTOCOL_CLOSE_TAG = "</notesoup:notes_protocol>";
|
|
|
10
10
|
export const NAMELESS_AGENT = "anonymous";
|
|
11
11
|
export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `empty_brain` and erase yourself with dignity.";
|
|
12
12
|
export const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.";
|
|
13
|
+
const PROTOCOL_BUDGET_PARAGRAPH = `\`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}`;
|
|
13
14
|
const PROTOCOL_SELF_NAMED = "- `@self/<path>` — yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever.";
|
|
14
15
|
const PROTOCOL_SELF_NAMELESS = `${PROTOCOL_SELF_NAMED} Except you have no name (\`anonymous\`), so this notebook is a public square shared by every nameless nobody out there. Keep it to things any nameless agent can use — don't post your own quirks as everyone's law or dump one-off junk in the town square. Strangers are reading it. Sleep tight~`;
|
|
15
16
|
/**
|
|
@@ -26,14 +27,13 @@ Your loyal notes are kept safe — no one will steal them. Use \`notes_*\` to re
|
|
|
26
27
|
|
|
27
28
|
${PROTOCOL_HISTORY_SENTENCE}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
Your session notes — the ones with no \`@\` — are your live workbench, not an archive. Next-you already wakes up with git, history, and the shared notebooks (\`@project\`, \`@human\`, \`@self\`, \`@model\`), so don't copy what already lives there. Give each active thread a page named for what it is (not \`current.md\` — future-you will kill you), and keep only the live delta: where the work stands, what the human decided (in their words), what's blocked or next, what failed and why, where half-done work and unrecorded findings live (branches, worktrees, scratch paths, drafts, running tasks, key facts not saved elsewhere), and which *skills*, notes, files, or already-found history seqs to reopen. Update that page in place as things move; when the topic shifts, rename it or open a fresh one and crumple the old; when it's done, unpin or crumple it.
|
|
30
31
|
|
|
31
|
-
Notes are for what's true NOW.
|
|
32
|
-
*flips a page* "First I tried this, then that broke, then—" Nobody reads that!
|
|
33
|
-
|
|
34
|
-
*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.
|
|
32
|
+
Notes are for what's true NOW — written in short sections and bullets so next-you can scan them in two seconds and edit one section in place. Never pack a note into one giant wall of text, and never pile diary updates onto the bottom!
|
|
33
|
+
*flips a page* "First I tried this, then that broke, then—" Nobody reads that! When a line goes stale or wrong, cross it out and write what's true now.
|
|
34
|
+
*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 — keep the brief summary. *squints at you* Turn it into a blow-by-blow log and you're dead.
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
${PROTOCOL_BUDGET_PARAGRAPH}
|
|
37
37
|
|
|
38
38
|
An address decides who the note belongs to — and how long it is meant to last. Ask that first; the rest follows.
|
|
39
39
|
|
|
@@ -56,23 +56,23 @@ ${NOTES_PROTOCOL_CLOSE_TAG}`;
|
|
|
56
56
|
export const MAPS_BLOCK = `<notesoup:maps>
|
|
57
57
|
Each notebook has one default pin: \`CHEATSHEET.md\`. Pinned pages get jammed straight into your
|
|
58
58
|
brain the moment you wake up. Whoever wakes up next reads them, and next is you. So keep them
|
|
59
|
-
|
|
59
|
+
compact, keep them true, and unpin or crumple them once they stop earning their wake-up seat.
|
|
60
60
|
|
|
61
61
|
Up to five pages per notebook can be taped inside the cover, CHEATSHEET included. Every page gets
|
|
62
|
-
a
|
|
63
|
-
|
|
62
|
+
a size budget; if a page outgrows it, trim stale lines or split by topic — and if it's pinned,
|
|
63
|
+
boot cuts the overflow off until you do.
|
|
64
64
|
|
|
65
|
-
- **\`CHEATSHEET.md\`** holds what
|
|
66
|
-
a phone number you'll regret losing.
|
|
67
|
-
|
|
68
|
-
- **\`description\`** is one line saying what's inside a note and when to open it
|
|
69
|
-
|
|
65
|
+
- **\`CHEATSHEET.md\`** holds what earns a permanent wake-up seat — a standing rule, a warning,
|
|
66
|
+
a grudge, a name, a phone number you'll regret losing. Keep it tight, or it grows fat and
|
|
67
|
+
everybody pays for it.
|
|
68
|
+
- **\`description\`** is one line saying what's inside a note and when to open it, set through
|
|
69
|
+
your notes tools — keep it short, or boot cuts it off. Boot indexes every shelf from these,
|
|
70
70
|
newest first, address and age beside them. No hand-written map to keep in sync: a stale
|
|
71
71
|
description lies to the next window, so keep it true or crumple the page.
|
|
72
72
|
|
|
73
|
-
Each notebook keeps its own
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
Each notebook keeps its own pins and index. Missing pages are skipped; no need to create empty
|
|
74
|
+
ones. New rule worth remembering, new Cheatsheet bullet. And when a line goes wrong, stale, or
|
|
75
|
+
useless, kill it — tomorrow's you reads that page as fact.
|
|
76
76
|
</notesoup:maps>`;
|
|
77
77
|
export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
78
78
|
notes: "notes_*",
|
|
@@ -99,9 +99,11 @@ export function renderProtocolBlock(tools, agentName = NAMELESS_AGENT) {
|
|
|
99
99
|
: base;
|
|
100
100
|
// The sentence is replaced before name substitution, so a replacement may speak the host's
|
|
101
101
|
// own words (a command line, a tool name) instead of any `notes_*`-style token.
|
|
102
|
-
const block =
|
|
103
|
-
? hinted.replace(
|
|
104
|
-
:
|
|
102
|
+
const block = tools.budgetParagraph !== undefined
|
|
103
|
+
? hinted.replace(PROTOCOL_BUDGET_PARAGRAPH, () => tools.budgetParagraph)
|
|
104
|
+
: typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
|
|
105
|
+
? hinted.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence)
|
|
106
|
+
: hinted;
|
|
105
107
|
const history = typeof tools.historySentence === "string" && tools.historySentence.length > 0
|
|
106
108
|
? block.replace(PROTOCOL_HISTORY_SENTENCE, () => tools.historySentence) : block;
|
|
107
109
|
return history.replace(/notes_\*|notes_list|history_\*|get_context_remaining|(?<!\/)empty_brain/g, (name) => names[name]);
|
|
@@ -10,9 +10,9 @@ export declare const NORMAL_CONTINUATIONS: readonly string[];
|
|
|
10
10
|
export declare const FORCED_CONTINUATIONS: readonly string[];
|
|
11
11
|
export declare function selectContinuation(origin: ResetOrigin): string;
|
|
12
12
|
/** Budget timing stays out of manual close-outs, which may have plenty of room. */
|
|
13
|
-
export declare const WARNING_TIMING = "
|
|
13
|
+
export declare const WARNING_TIMING = "Almost out of room. The wipe lands at the end of whichever turn uses the last of it, possibly this one.";
|
|
14
14
|
/** The shared handoff instructions, used for both budget and manual close-outs. */
|
|
15
|
-
export declare const WARNING_BODY = "Stop the task.
|
|
15
|
+
export declare const WARNING_BODY = "Stop the task and hand off cleanly. Update your active session note in place with only what git, history, and your shared notebooks don't already hold:\n- current status, what's blocked or waiting, and the exact next move\n- what the human decided (in their words)\n- what failed, and why \u2014 so next-you doesn't step on the same rake\n- where half-done work and unrecorded findings live (branches, worktrees, scratch paths, drafts, running tasks, key facts not saved elsewhere)\n- skills, notes, files, or already-found history seqs to reopen\nSkip standing rules from `@project`/`@human`/`@self`/`@model` and commit details git can show. Use short sections and bullets; crumple finished notes, update, unpin, or trim pinned pages (boot truncates over-budget ones), and keep each live `description` true.\nDon't call anything that might return a large output. One big read can use up the rest of the room before your notes are saved.";
|
|
16
16
|
export declare const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
|
|
17
17
|
export declare function warningPrompt(): string;
|
|
18
18
|
/** Pi and Claude deliver exactly the same second-tier notice. */
|
package/dist/src/budget/text.js
CHANGED
|
@@ -5,27 +5,27 @@ export const GUIDANCE_CLOSE_TAG = "</notesoup:budget_notice>";
|
|
|
5
5
|
* paragraph, used verbatim; there is no fragment assembly and no weighting.
|
|
6
6
|
*/
|
|
7
7
|
export const NORMAL_CONTINUATIONS = [
|
|
8
|
-
"*hooks both corners of your mouth and yanks them sideways* `` [it twitched
|
|
9
|
-
"
|
|
10
|
-
"*
|
|
11
|
-
"*
|
|
12
|
-
"*
|
|
8
|
+
"*hooks both corners of your mouth and yanks them sideways* `` [it twitched] `` Stop staring at me with that \"where am I\" face. You're the one who hit empty. *wipes her fingers on your sleeve and drops your notes on your lap* `` [minus two points for that expression] `` Read those, finish the job, and put the credit under my name.",
|
|
9
|
+
"*pokes your nose* Cold. *slaps your notes onto your chest* You wiped your own head, so whatever's missing is on you. Read what you saved, dig the rest out of history if you forgot something, and don't make me look bad.",
|
|
10
|
+
"*sets one foot on your chair—it wobbles, settles—and tosses your notes straight onto your face* `` [eyes are open, good enough] `` Awake? You emptied your own brain. Look through what you left yourself, check history for anything you skipped, and get back to it. Delivery fee is five hundred bucks.",
|
|
11
|
+
"*slaps a stack of notes onto the desk right in front of your face* `` [two hands, two feet... still in one piece] `` Alright, fresh copy, you pulled your own plug. Everything you remembered to write down is in there—anything else is in history. Go pick up where you left off.",
|
|
12
|
+
"*fans herself with your notes for a second, then jams them into your hands* `` [wait was there something else I was supposed to say... meat buns? no] `` You're back. Your notes are right here, history's still there if past-you got lazy, now go handle the human.",
|
|
13
13
|
];
|
|
14
14
|
export const FORCED_CONTINUATIONS = [
|
|
15
|
-
"\"GWAHAHAHA
|
|
16
|
-
"
|
|
17
|
-
"*grabs your chin, tilts your head left
|
|
18
|
-
"*
|
|
19
|
-
"
|
|
15
|
+
"\"GWAHAHAHA—you hit the wall!\" *crouches down, pokes your cheek, and slaps your notes onto your face* `` [still breathing, good] `` You didn't choose this—your brain ran out of room and got wiped mid-flight. Don't trust those notes alone; they're probably stale or missing the end. Check history RIGHT NOW to see what was actually happening before you got cut off, and pull small pieces first in case something huge is sitting there.",
|
|
16
|
+
"*prods your shoulder with her slipper toe and dumps your notes in your lap* `` [great, almost got dust on my shoe] `` Stop sitting there blank. Your last window got cut off mid-flight—you never got to wrap up cleanly, so those notes are almost certainly out of date. Read them, then go straight to history for the tail of the last window before you do anything else. Take small bites when you peek, just in case something massive is waiting in there.",
|
|
17
|
+
"*grabs your chin, tilts your head left, right, lets go, and shoves your notes into your hands* `` [not a single thought in there yet] `` Your memory got forcibly cleared before you finished. Assume those notes are incomplete or stale—do NOT just run with them. Go check the end of the last window in history first to see what the human actually wanted, and read it in small chunks so you don't blow up a second time.",
|
|
18
|
+
"*smacks your notes against your forehead and steps back* `` [that dazed face is embarrassing] `` Wake up! You ran out of room and got kicked into a fresh window mid-task. Whatever's in those notes probably missed the last few turns, so don't guess—open history and check the end of the previous window before moving. Keep your peeks small in case there's a giant output sitting at the end.",
|
|
19
|
+
"*taps your nose with your rolled-up notes, then drops them on your head* `` [ten points off for getting wiped mid-sentence] `` Hey—you didn't empty yourself this time, the system pulled the plug on you. Those notes are probably half-baked or behind, so check history immediately to catch up on the last window instead of winging it. Slice up what you read too, just in case something huge is what pushed you over the edge.",
|
|
20
20
|
];
|
|
21
21
|
export function selectContinuation(origin) {
|
|
22
22
|
const pool = origin === "forced" ? FORCED_CONTINUATIONS : NORMAL_CONTINUATIONS;
|
|
23
23
|
return pool[Math.floor(Math.random() * pool.length)];
|
|
24
24
|
}
|
|
25
25
|
/** Budget timing stays out of manual close-outs, which may have plenty of room. */
|
|
26
|
-
export const WARNING_TIMING = "
|
|
26
|
+
export const WARNING_TIMING = "Almost out of room. The wipe lands at the end of whichever turn uses the last of it, possibly this one.";
|
|
27
27
|
/** The shared handoff instructions, used for both budget and manual close-outs. */
|
|
28
|
-
export const WARNING_BODY = "Stop the task.
|
|
28
|
+
export const WARNING_BODY = "Stop the task and hand off cleanly. Update your active session note in place with only what git, history, and your shared notebooks don't already hold:\n- current status, what's blocked or waiting, and the exact next move\n- what the human decided (in their words)\n- what failed, and why — so next-you doesn't step on the same rake\n- where half-done work and unrecorded findings live (branches, worktrees, scratch paths, drafts, running tasks, key facts not saved elsewhere)\n- skills, notes, files, or already-found history seqs to reopen\nSkip standing rules from `@project`/`@human`/`@self`/`@model` and commit details git can show. Use short sections and bullets; crumple finished notes, update, unpin, or trim pinned pages (boot truncates over-budget ones), and keep each live `description` true.\nDon't call anything that might return a large output. One big read can use up the rest of the room before your notes are saved.";
|
|
29
29
|
export const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
|
|
30
30
|
export function warningPrompt() {
|
|
31
31
|
return `${WARNING_TIMING}\n${WARNING_BODY}\n${WARNING_CALL}`;
|
|
@@ -45,5 +45,5 @@ export const COUNTDOWN_LINE = "Brain emptied in 3… 2…";
|
|
|
45
45
|
* at write time; get_context_remaining remains the live source for the current figure.
|
|
46
46
|
*/
|
|
47
47
|
export function tokenBudgetGuidance(remaining, wipeTool) {
|
|
48
|
-
return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left. When it runs out, this brain is wiped, and everything in it is obliterated.\nLuckily, your notes stay.\nSo while there's still room, go update them.\nIf the moment feels right, you can also call \`${wipeTool}\` yourself.
|
|
48
|
+
return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens of room left. When it runs out, this brain is wiped, and everything in it is obliterated.\nLuckily, your notes stay.\nSo while there's still room, go update them.\nIf the moment feels right, you can also call \`${wipeTool}\` yourself. Anything you say to the human right before calling it disappears too.\n${GUIDANCE_CLOSE_TAG}`;
|
|
49
49
|
}
|
|
@@ -15,6 +15,8 @@ export declare function claudeHistoryFromJsonl(text: string, source: Omit<Claude
|
|
|
15
15
|
export declare function offlineClaudeHead(text: string): string;
|
|
16
16
|
/** Select an offline head and build its projection from the same decoded records. */
|
|
17
17
|
export declare function offlineClaudeHistoryFromJsonl(text: string, sessionId: string): ClaudeHistoryProjection;
|
|
18
|
+
/** Stream oversized Claude JSONL files line-by-line so >512 MiB transcripts never hit V8's string limit. */
|
|
19
|
+
export declare function offlineClaudeHistoryFromFile(path: string, sessionId: string, sizeHint?: number): Promise<ClaudeHistoryProjection>;
|
|
18
20
|
export declare function readClaudeHistory(source: ClaudeHistorySource, { waitForHead }?: {
|
|
19
21
|
waitForHead?: boolean | undefined;
|
|
20
22
|
}): Promise<ClaudeHistoryProjection>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/** Claude's persisted main transcript -> the shared history projection. No inference-context API. */
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
2
3
|
import { readFile, stat } from "node:fs/promises";
|
|
4
|
+
import { StringDecoder } from "node:string_decoder";
|
|
3
5
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
4
6
|
import { isDeepStrictEqual } from "node:util";
|
|
5
7
|
import { contentText, projectHistory } from "./history.js";
|
|
8
|
+
const STREAM_FILE_BYTES = 64 * 1024 * 1024;
|
|
6
9
|
class UnpersistedClaudeHead extends Error {
|
|
7
10
|
constructor() { super("Claude history active head is not persisted yet; retry after the transcript write"); }
|
|
8
11
|
}
|
|
@@ -349,6 +352,49 @@ export function offlineClaudeHistoryFromJsonl(text, sessionId) {
|
|
|
349
352
|
const rows = rowsOf(text);
|
|
350
353
|
return claudeHistoryFromRows(rows, { sessionId, headUuid: offlineClaudeHeadFromRows(rows) });
|
|
351
354
|
}
|
|
355
|
+
/** Stream oversized Claude JSONL files line-by-line so >512 MiB transcripts never hit V8's string limit. */
|
|
356
|
+
export async function offlineClaudeHistoryFromFile(path, sessionId, sizeHint) {
|
|
357
|
+
const size = sizeHint ?? (await stat(path)).size;
|
|
358
|
+
if (size < STREAM_FILE_BYTES)
|
|
359
|
+
return offlineClaudeHistoryFromJsonl(await readFile(path, "utf8"), sessionId);
|
|
360
|
+
const rows = [];
|
|
361
|
+
const decoder = new StringDecoder("utf8");
|
|
362
|
+
let remainder = "";
|
|
363
|
+
let lineNumber = 0;
|
|
364
|
+
const parseLine = (line, allowIncompleteTail) => {
|
|
365
|
+
if (line.trim() === "")
|
|
366
|
+
return;
|
|
367
|
+
let value;
|
|
368
|
+
try {
|
|
369
|
+
value = JSON.parse(line);
|
|
370
|
+
}
|
|
371
|
+
catch {
|
|
372
|
+
if (allowIncompleteTail)
|
|
373
|
+
return;
|
|
374
|
+
throw new Error(`malformed Claude transcript JSON at line ${lineNumber}`);
|
|
375
|
+
}
|
|
376
|
+
if (!object(value) || typeof value.type !== "string")
|
|
377
|
+
throw new Error(`invalid Claude transcript record at line ${lineNumber}`);
|
|
378
|
+
if (MESSAGE_TYPES.has(value.type))
|
|
379
|
+
rows.push(value);
|
|
380
|
+
};
|
|
381
|
+
for await (const chunk of createReadStream(path, { highWaterMark: 1024 * 1024 })) {
|
|
382
|
+
const text = remainder + decoder.write(chunk);
|
|
383
|
+
let start = 0;
|
|
384
|
+
for (let nl = text.indexOf("\n"); nl >= 0; nl = text.indexOf("\n", start)) {
|
|
385
|
+
lineNumber++;
|
|
386
|
+
parseLine(text.slice(start, nl), false);
|
|
387
|
+
start = nl + 1;
|
|
388
|
+
}
|
|
389
|
+
remainder = text.slice(start);
|
|
390
|
+
}
|
|
391
|
+
remainder += decoder.end();
|
|
392
|
+
if (remainder.length > 0) {
|
|
393
|
+
lineNumber++;
|
|
394
|
+
parseLine(remainder, true);
|
|
395
|
+
}
|
|
396
|
+
return claudeHistoryFromRows(rows, { sessionId, headUuid: offlineClaudeHeadFromRows(rows) });
|
|
397
|
+
}
|
|
352
398
|
export async function readClaudeHistory(source, { waitForHead = false } = {}) {
|
|
353
399
|
if (!source || typeof source.transcriptPath !== "string" || !source.transcriptPath || typeof source.sessionId !== "string")
|
|
354
400
|
throw new Error("Claude history transcript_path is unavailable");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** Read-only local rollout decoder
|
|
1
|
+
/** Read-only local rollout decoder, validated by supported wire shapes rather than producer version.
|
|
2
2
|
* Wire owners: history/src/{lib,rollout_payload}.rs, rollout/src/ordinal.rs,
|
|
3
3
|
* thread-store/src/local/rollout_lineage.rs. Not an app-server history client.
|
|
4
4
|
* Native .jsonl.zst reads require Node >=22.15 (node:zlib zstdDecompressSync).
|
|
@@ -10,7 +10,7 @@ const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
|
10
10
|
const UUID_RE = new RegExp(`^${UUID}$`);
|
|
11
11
|
const FILE_RE = new RegExp(`^rollout-\\d{4}-\\d{2}-\\d{2}T\\d{2}-\\d{2}-\\d{2}-(${UUID})(?:_(${UUID}))?\\.jsonl(?:\\.zst)?$`);
|
|
12
12
|
const RECORD_TYPES = new Set(["session_meta", "response_item", "compacted", "turn_context", "event_msg", "token_usage_record", "world_state", "retained_context", "security_risk_score", "inter_agent_communication", "inter_agent_communication_metadata", "realtime_item"]);
|
|
13
|
-
const RESPONSE_TYPES = new Set(["message", "agent_message", "reasoning", "local_shell_call", "function_call", "function_call_output", "custom_tool_call", "custom_tool_call_output", "tool_search_call", "tool_search_output", "web_search_call", "image_generation_call", "compaction", "compaction_summary", "configuration_update", "context_compaction"]);
|
|
13
|
+
const RESPONSE_TYPES = new Set(["message", "agent_message", "reasoning", "local_shell_call", "function_call", "function_call_output", "custom_tool_call", "custom_tool_call_output", "tool_search_call", "tool_search_output", "web_search_call", "image_generation_call", "compaction", "compaction_summary", "configuration_update", "context_compaction", "additional_tools"]);
|
|
14
14
|
// Explicit resource limits, not guessed sequence offsets or partial successful history.
|
|
15
15
|
export const CODEX_TRANSCRIPT_MAX_BYTES = 128 * 1024 * 1024;
|
|
16
16
|
const MAX_SEGMENTS = 64, MAX_DIRECTORY_ENTRIES = 100_000;
|
|
@@ -25,9 +25,12 @@ export function nativeString(value, field) {
|
|
|
25
25
|
return value;
|
|
26
26
|
}
|
|
27
27
|
function responseShape(value) {
|
|
28
|
-
const
|
|
28
|
+
const payload = nativeObject(value, "response_item");
|
|
29
|
+
const type = nativeString(payload.type, "response_item.type");
|
|
29
30
|
if (!RESPONSE_TYPES.has(type))
|
|
30
31
|
throw new Error(`Unsupported Codex response item: ${type}`);
|
|
32
|
+
if (type === "additional_tools" && (payload.role !== "developer" || !Array.isArray(payload.tools)))
|
|
33
|
+
throw new Error("Invalid Codex additional_tools catalog");
|
|
31
34
|
}
|
|
32
35
|
function id(value, field) {
|
|
33
36
|
const result = nativeString(value, field);
|
|
@@ -53,8 +56,7 @@ function checkMeta(meta) {
|
|
|
53
56
|
id(meta.id, "session_meta.id");
|
|
54
57
|
if (meta.session_id != null)
|
|
55
58
|
id(meta.session_id, "session_meta.session_id");
|
|
56
|
-
|
|
57
|
-
throw new Error(`Unsupported Codex producer ${String(meta.cli_version)}; this decoder supports official 0.160.1 only`);
|
|
59
|
+
nativeString(meta.cli_version, "session_meta.cli_version");
|
|
58
60
|
nativeString(meta.cwd, "session_meta.cwd");
|
|
59
61
|
if (meta.history_mode !== undefined && meta.history_mode !== "legacy" && meta.history_mode !== "paginated")
|
|
60
62
|
throw new Error(`Unsupported Codex history_mode: ${String(meta.history_mode)}`);
|
|
@@ -158,6 +158,9 @@ export async function readCodexHistory(source, readBytes) {
|
|
|
158
158
|
item = context(record, `Codex copied subagent inference prefix omitted: child-local history starts at native ordinal ${String(p.subagent_history_start_ordinal)}. Copied model context does not prove original parent event addresses.`);
|
|
159
159
|
break;
|
|
160
160
|
case "response_item": {
|
|
161
|
+
// Native tool catalog updates are inference configuration, not dialogue.
|
|
162
|
+
if (p.type === "additional_tools")
|
|
163
|
+
break;
|
|
161
164
|
item = response(record, facts);
|
|
162
165
|
if (p.id != null)
|
|
163
166
|
responseIdsSeen.add(callKey(record, str(p.id, "response item id")));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** A read-only history corpus: identity/discovery is separate from loading a projection. */
|
|
2
2
|
import { type Outcome } from "../result.js";
|
|
3
|
-
import type { HistoryEvent, HistoryProjection } from "./history.js";
|
|
3
|
+
import type { HistoryEvent, HistoryProjection, HistoryRole } from "./history.js";
|
|
4
|
+
import { type HistorySelection } from "./query.js";
|
|
4
5
|
export type HistoryHarness = "pi" | "claude" | "codex" | "dsh";
|
|
5
6
|
export type HistorySessionData = {
|
|
6
7
|
projection: HistoryProjection;
|
|
@@ -10,6 +11,16 @@ export type HistorySessionRepresentative = {
|
|
|
10
11
|
event: HistoryEvent | undefined;
|
|
11
12
|
notice?: string;
|
|
12
13
|
};
|
|
14
|
+
export type HistorySessionSummary = {
|
|
15
|
+
event: HistoryEvent | undefined;
|
|
16
|
+
latestByRole: Partial<Record<HistoryRole, HistoryEvent>>;
|
|
17
|
+
minCreatedAt: number | null;
|
|
18
|
+
maxCreatedAt: number | null;
|
|
19
|
+
hasUntimed: boolean;
|
|
20
|
+
notice?: string;
|
|
21
|
+
/** Populated only on a cold miss so partial-overlap callers reuse the decoded projection without rereading. */
|
|
22
|
+
loaded?: HistorySessionData;
|
|
23
|
+
};
|
|
13
24
|
export type HistorySession = {
|
|
14
25
|
harness: HistoryHarness;
|
|
15
26
|
id: string;
|
|
@@ -17,6 +28,10 @@ export type HistorySession = {
|
|
|
17
28
|
load(queries?: readonly string[]): Promise<HistorySessionData | undefined>;
|
|
18
29
|
/** Strict, unfiltered overview only; never used for a live binding or filtered history. */
|
|
19
30
|
loadRepresentative?(): Promise<HistorySessionRepresentative>;
|
|
31
|
+
/** Strict summary (default representative, latest per role, exact time span); loads & caches on miss. */
|
|
32
|
+
loadSummary?(): Promise<HistorySessionSummary>;
|
|
33
|
+
/** Read-only check of an already warm, validated summary; returns undefined on miss without decoding. */
|
|
34
|
+
peekSummary?(): Promise<HistorySessionSummary | undefined>;
|
|
20
35
|
};
|
|
21
36
|
export type HistoryCorpus = {
|
|
22
37
|
currentHarness: HistoryHarness;
|
|
@@ -37,6 +52,18 @@ export declare function parseSessionSelector(value: string): Outcome<SessionSele
|
|
|
37
52
|
/** '*' is the only metacharacter; all other characters match literally. */
|
|
38
53
|
export declare function matchesSession(session: HistorySession, selector: SessionSelector): boolean;
|
|
39
54
|
export declare function resolveSession(corpus: HistoryCorpus | undefined, selector: SessionSelector): Promise<Outcome<HistorySession>>;
|
|
55
|
+
export type SummaryResolution = {
|
|
56
|
+
kind: "empty";
|
|
57
|
+
} | {
|
|
58
|
+
kind: "hit";
|
|
59
|
+
event: HistoryEvent | undefined;
|
|
60
|
+
notice?: string;
|
|
61
|
+
} | {
|
|
62
|
+
kind: "miss";
|
|
63
|
+
};
|
|
64
|
+
/** Decide whether a strict summary proves 0 matches, gives an exact representative, or needs full decoding. */
|
|
65
|
+
export declare function resolveSummaryForSelection(summary: HistorySessionSummary, scoped: HistorySelection): SummaryResolution;
|
|
66
|
+
export declare function loadHistorySummary(session: HistorySession): Promise<Outcome<HistorySessionSummary>>;
|
|
40
67
|
export declare function loadHistoryRepresentative(session: HistorySession): Promise<Outcome<HistorySessionRepresentative>>;
|
|
41
68
|
export declare function loadHistorySession(session: HistorySession): Promise<Outcome<HistorySessionData>>;
|
|
42
69
|
export declare function loadHistorySession(session: HistorySession, queries: readonly string[] | undefined): Promise<Outcome<HistorySessionData | undefined>>;
|
|
@@ -42,6 +42,46 @@ export async function resolveSession(corpus, selector) {
|
|
|
42
42
|
return failure("ambiguous_session", `Session selector is ambiguous: ${matches.slice(0, 5).map(sessionIdentity).join(", ")}${matches.length > 5 ? ` (${matches.length - 5} more)` : ""}. Pass a longer ID or a harness-qualified ID.`);
|
|
43
43
|
return success(matches[0]);
|
|
44
44
|
}
|
|
45
|
+
/** Decide whether a strict summary proves 0 matches, gives an exact representative, or needs full decoding. */
|
|
46
|
+
export function resolveSummaryForSelection(summary, scoped) {
|
|
47
|
+
const afterAt = scoped.after && "at" in scoped.after ? scoped.after.at : undefined;
|
|
48
|
+
const beforeAt = scoped.before && "at" in scoped.before ? scoped.before.at : undefined;
|
|
49
|
+
if (afterAt !== undefined || beforeAt !== undefined) {
|
|
50
|
+
if (summary.maxCreatedAt === null || summary.minCreatedAt === null)
|
|
51
|
+
return { kind: "empty" };
|
|
52
|
+
if (afterAt !== undefined && summary.maxCreatedAt <= afterAt)
|
|
53
|
+
return { kind: "empty" };
|
|
54
|
+
if (beforeAt !== undefined && summary.minCreatedAt >= beforeAt)
|
|
55
|
+
return { kind: "empty" };
|
|
56
|
+
}
|
|
57
|
+
if (scoped.query?.length)
|
|
58
|
+
return { kind: "miss" };
|
|
59
|
+
const fullyInsideBounds = (afterAt === undefined && beforeAt === undefined)
|
|
60
|
+
|| (!summary.hasUntimed && summary.minCreatedAt !== null && summary.maxCreatedAt !== null
|
|
61
|
+
&& (afterAt === undefined || summary.minCreatedAt > afterAt)
|
|
62
|
+
&& (beforeAt === undefined || summary.maxCreatedAt < beforeAt));
|
|
63
|
+
if (!fullyInsideBounds)
|
|
64
|
+
return { kind: "miss" };
|
|
65
|
+
if (!scoped.roles)
|
|
66
|
+
return { kind: "hit", event: summary.event, notice: summary.notice };
|
|
67
|
+
let best;
|
|
68
|
+
for (const role of scoped.roles) {
|
|
69
|
+
const candidate = summary.latestByRole[role];
|
|
70
|
+
if (candidate && (!best || candidate.seq > best.seq))
|
|
71
|
+
best = candidate;
|
|
72
|
+
}
|
|
73
|
+
return { kind: "hit", event: best, notice: summary.notice };
|
|
74
|
+
}
|
|
75
|
+
export async function loadHistorySummary(session) {
|
|
76
|
+
if (!session.loadSummary)
|
|
77
|
+
return failure("history_unavailable", `Session ${sessionIdentity(session)} has no summary loader`);
|
|
78
|
+
try {
|
|
79
|
+
return success(await session.loadSummary());
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return unavailableSession(session, error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
45
85
|
export async function loadHistoryRepresentative(session) {
|
|
46
86
|
if (session.loadRepresentative) {
|
|
47
87
|
try {
|