notesoup 0.60.1 → 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 -10
- 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.d.ts +5 -0
- package/dist/src/boot/render.js +60 -28
- package/dist/src/boot/text.d.ts +3 -3
- package/dist/src/boot/text.js +27 -26
- 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/frontmatter.d.ts +4 -0
- package/dist/src/notes/frontmatter.js +15 -1
- 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 +47 -6
- package/dist/src/notes/store.d.ts +14 -0
- package/dist/src/notes/store.js +33 -12
- 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 -91
- 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 +58 -160
- package/dist/src/tools/notes.js +151 -99
- 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 +189 -56
- 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 +4 -4
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +6 -6
- package/docs/reset-lifecycle.md +1 -1
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +47 -28
- package/package.json +3 -2
- package/playbook.md +3 -3
- 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 +1129 -549
- package/plugins/claude/hooks/register.ts +2 -2
- package/plugins/claude/playbook.md +3 -3
- package/plugins/claude/skills/dream/SKILL.md +2 -2
- 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 +18494 -17905
- 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 +2 -2
- package/skills/notesoup/SKILL.md +92 -0
- package/src/boot/render.ts +59 -25
- package/src/boot/text.ts +30 -27
- 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/frontmatter.ts +16 -1
- package/src/notes/index.ts +1 -1
- package/src/notes/policy.ts +45 -6
- package/src/notes/store.ts +30 -15
- 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 +150 -112
- 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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: notesoup
|
|
3
|
+
description: How notesoup's `notes_*` and `history_*` tools fit together — note addresses and notebooks, finding things again, and saving recovery state. Use when the context-window protocol is missing or unclear, or when unsure where a note belongs or how to find something again.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Notesoup
|
|
7
|
+
|
|
8
|
+
Two stores outlive the context window. Anything in neither is lost when the window ends or is wiped.
|
|
9
|
+
|
|
10
|
+
- **Notes** (`notes_*`) — what you choose to keep. Plain markdown, written on purpose.
|
|
11
|
+
- **History** (`history_*`) — recorded messages, tool calls and summaries. Current session by default; other local sessions/harnesses through `session`. Read-only.
|
|
12
|
+
|
|
13
|
+
Each tool's own description covers its parameters and paging. This guide covers what the descriptions cannot: where notes belong, and how the tools work together.
|
|
14
|
+
|
|
15
|
+
## Addresses
|
|
16
|
+
|
|
17
|
+
The address decides who a note belongs to and how long it lasts.
|
|
18
|
+
|
|
19
|
+
| Address | Note | Keep there |
|
|
20
|
+
| --- | --- | --- |
|
|
21
|
+
| `<path>`, no `@` | session note | current task state and loose ends; gone with the session |
|
|
22
|
+
| `@project/<path>` | project note | decisions and constraints future work must respect |
|
|
23
|
+
| `@human/<path>` | human note | how to work with this human, across projects |
|
|
24
|
+
| `@self/<path>` | self note | your reminders; yours alone if you have a name, shared by everyone nameless |
|
|
25
|
+
| `@model/<path>` | model note | what applies to this model only |
|
|
26
|
+
| `@projects/<name>/<path>` | named project, read-only | discover names and root paths with `notes_list` glob `@projects/*/**` |
|
|
27
|
+
| `@sessions/<id>/<path>` | named session, read-only | recover earlier task state; discover with glob `@sessions/*/**` |
|
|
28
|
+
|
|
29
|
+
When notes conflict, the one most relevant to what you're doing applies. If that doesn't settle it, judge the case.
|
|
30
|
+
|
|
31
|
+
Any other `@` prefix is refused. A path is relative and `/`-separated, with no empty, `.` or `..` segments.
|
|
32
|
+
|
|
33
|
+
`@` addresses are not file paths: never pass them to file tools like `read`, `write`, `edit`, or `bash`. That creates a stray directory instead of a note.
|
|
34
|
+
|
|
35
|
+
`CHEATSHEET.md` at each notebook's root is the default-pinned page you wake up with; absent or crumpled pages are skipped. Set `pinned`, `readonly`, and `description` through `notes_write`/`notes_update` or frontmatter. Explicit `pinned:false` unpins even a default page; each page carries a UTF-8 byte budget (4 KB for root `CHEATSHEET.md`, 8 KB for ordinary notes; overridable in frontmatter). Overflow on body budget or an oversized description warns but still saves; boot truncates over-budget pinned bodies and oversized descriptions. `readonly:true` is a soft lock, not security; explicitly set `readonly:false` to unlock, alone or alongside your changes. Keep `CHEATSHEET.md` compact with short bullets. Give each durable note a short one-line `description`: boot lists every notebook's unpinned pages newest first as address, age, and description, so it is the only index. Do not create empty pages.
|
|
36
|
+
|
|
37
|
+
Keep notes focused on what is true now; if a piece of past context still matters (such as why an approach was ruled out), keep only a brief summary rather than a blow-by-blow log. Crumple notes that are no longer true; a stale note is worse than none.
|
|
38
|
+
|
|
39
|
+
## Finding things again
|
|
40
|
+
|
|
41
|
+
### Notes
|
|
42
|
+
|
|
43
|
+
In `notes_list`, omit `glob` for this session and the current shared notebooks. Use `**` for all notebooks or `@sessions/*/**` for all sessions.
|
|
44
|
+
|
|
45
|
+
- **A note**: add `glob` to narrow where `notes_list` looks, and `query` if you remember a phrase. Then use `notes_read` with the address and, for a match, its `offset_chars`.
|
|
46
|
+
- **Older notes**: when `notes_list` ends with `→ older: {…}`, call it again with that object to see older matches. Continue until the line is gone.
|
|
47
|
+
### Shared search and read conventions
|
|
48
|
+
|
|
49
|
+
Queries look for literal text, ignoring case. A list of phrases matches any one of them.
|
|
50
|
+
|
|
51
|
+
Both list tools report omissions and partial previews. A truncated result is not the whole
|
|
52
|
+
record.
|
|
53
|
+
|
|
54
|
+
Read offsets count characters relative to the body or event document, not the
|
|
55
|
+
presentation header.
|
|
56
|
+
|
|
57
|
+
Continue an incomplete read at the offset named in its trailing notice. A concurrent edit can
|
|
58
|
+
change a note's offsets.
|
|
59
|
+
|
|
60
|
+
All shared tools return text. On supported hosts, `notes_read` also returns the note body
|
|
61
|
+
`text` without presentation markers, plus `next_offset_chars`, metadata and warnings.
|
|
62
|
+
|
|
63
|
+
When carrying a reference into another window, save its full address or event identity, not just
|
|
64
|
+
a quotation; you can retrieve the text again.
|
|
65
|
+
|
|
66
|
+
### History
|
|
67
|
+
|
|
68
|
+
- **Browse a known timeline**: `history_list({ before: 190 })` uses exclusive integer seq bounds (see the boot window tree for earlier windows), with optional ISO 8601 `since` / `until`. With `after` (or `since` alone) you page forward; otherwise take the newest events. Follow the older/newer and expand recipes.
|
|
69
|
+
- **List sessions**: pass a wildcard such as `session: "*"` or `"pi:*"` to `history_list` for one representative event per session (default 20 sessions), optionally narrowed with `roles` and `since` / `until`.
|
|
70
|
+
- **Find a passage**: `history_search({ query: "remembered phrase", context: 1 })` searches all roles in the current session, one named session, or a wildcard such as `session: "*"`, with optional neighboring events, `roles`, and ISO 8601 `since` / `until`. `query` is required (an empty query returns no matches).
|
|
71
|
+
- **Target one session**: all three tools accept an ID or prefix, optionally qualified with `pi:`, `claude:`, `codex:` or `dsh:`. Omit `session` for this session. If ambiguous, pass a longer or qualified ID. DSH sessions are available only from DSH.
|
|
72
|
+
- **Open a passage**: `history_read({ seq: 42 })` reads one event. If a session heading is shown above the event, include the full session ID; if a preview offset is shown, pass it as `offset_chars`. Follow the continuation to read more.
|
|
73
|
+
|
|
74
|
+
Save the seq and full session ID together when carrying a cross-session reference into another window. An empty search is not proof an event never happened: wildcard searches skip sessions that cannot be read.
|
|
75
|
+
|
|
76
|
+
## Saving recovery state
|
|
77
|
+
|
|
78
|
+
Before a long or risky step, or when room runs low, keep session notes named for what they hold (not `current.md`) and rewrite them in place with short sections and bullets instead of starting new ones or appending a timeline. Skip standing rules already in `@project`/`@human`/`@self`/`@model` and commit details git can show; record only the live delta:
|
|
79
|
+
|
|
80
|
+
- current status, blockers, and the next action
|
|
81
|
+
- what the human decided (in their words)
|
|
82
|
+
- what failed, and why
|
|
83
|
+
- where half-done work and unrecorded findings live (branches, worktrees, scratch paths, drafts, running tasks, key facts not saved elsewhere)
|
|
84
|
+
- skills, notes, files, or already-found history seqs to reopen
|
|
85
|
+
|
|
86
|
+
`get_context_remaining` reports the room left. `empty_brain` starts a fresh window, so save the note first.
|
|
87
|
+
|
|
88
|
+
## When a tool is missing or refuses
|
|
89
|
+
|
|
90
|
+
A refusal displays `error: <code>: <message>`; read the message before retrying. `notes_read` also supplies `{ error, code }` where structured results are available.
|
|
91
|
+
|
|
92
|
+
If a `notes_*` or `history_*` tool is absent or fails at the host level, do not imitate it: no filesystem tools on `@` addresses, and no reading or editing note storage or session files directly. Use the tools that remain, tell the human which one is missing, and keep essential state in the reply.
|
package/src/boot/render.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { NotesNamespace, NotesSnapshot } from "./snapshot.js";
|
|
2
|
-
import { effectiveNotePolicy, MAX_PINNED_NOTES, noteBudgetWarnings, pinnedPageOrder } from "../notes/policy.js";
|
|
3
|
-
import {
|
|
2
|
+
import { effectiveNotePolicy, MAX_DESCRIPTION_CHARS, MAX_PINNED_NOTES, noteBudgetWarnings, pinnedPageOrder, renderWarnings, truncateToUtf8Bytes } from "../notes/policy.js";
|
|
3
|
+
import { collapseDescription } from "../notes/frontmatter.js";
|
|
4
|
+
import type { NoteRow } from "../notes/index.js";
|
|
5
|
+
import { WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, MAPS_BLOCK, NAMELESS_AGENT, renderProtocolBlock, type BootToolNames } from "./text.js";
|
|
4
6
|
|
|
5
7
|
function relativeTime(timestamp: number, now: number): string {
|
|
6
8
|
const seconds = Math.trunc((timestamp - now) / 1000);
|
|
@@ -11,21 +13,38 @@ function relativeTime(timestamp: number, now: number): string {
|
|
|
11
13
|
return seconds > 0 ? `in ${amount}` : `${amount} ago`;
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
/**
|
|
15
|
-
const
|
|
16
|
+
/** The shelf index is bounded: enough to find a page, never the whole drawer. */
|
|
17
|
+
export const SHELF_INDEX_MAX_ENTRIES = 25;
|
|
18
|
+
export const SHELF_INDEX_MAX_CHARS = 4096;
|
|
19
|
+
/** A fallback title is the note's own first heading or line, cut short. */
|
|
20
|
+
export const FALLBACK_TITLE_MAX_CHARS = 80;
|
|
21
|
+
|
|
22
|
+
function truncated(text: string, max: number): string {
|
|
23
|
+
const chars = Array.from(text);
|
|
24
|
+
return chars.length > max ? `${chars.slice(0, max).join("")}…` : chars.join("");
|
|
25
|
+
}
|
|
16
26
|
|
|
17
27
|
function feedTitle(body: string): string | undefined {
|
|
18
28
|
const lines = body.split("\n");
|
|
19
29
|
const heading = lines.find((line) => /^#+\s+\S/.test(line));
|
|
20
30
|
const raw = (heading ? heading.replace(/^#+\s+/, "") : lines.find((line) => line.trim().length > 0) ?? "").trim();
|
|
21
|
-
|
|
22
|
-
const chars = Array.from(raw);
|
|
23
|
-
return chars.length > FEED_TITLE_MAX_CHARS ? `${chars.slice(0, FEED_TITLE_MAX_CHARS).join("")}…` : chars.join("");
|
|
31
|
+
return raw.length === 0 ? undefined : truncated(raw, FALLBACK_TITLE_MAX_CHARS);
|
|
24
32
|
}
|
|
25
33
|
|
|
26
|
-
/**
|
|
27
|
-
function
|
|
28
|
-
|
|
34
|
+
/** Oversized descriptions are cut for display in the boot index. */
|
|
35
|
+
function summaryOf(row: NoteRow): string | undefined {
|
|
36
|
+
if (typeof row.meta.description === "string") {
|
|
37
|
+
const collapsed = collapseDescription(row.meta.description);
|
|
38
|
+
return collapsed === undefined ? undefined : truncated(collapsed, MAX_DESCRIPTION_CHARS);
|
|
39
|
+
}
|
|
40
|
+
return feedTitle(row.body);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** One index entry: where the page sits, how fresh it is, and one line saying whether to open it. */
|
|
44
|
+
function indexLine(row: NoteRow, openedAt: number): string {
|
|
45
|
+
const locator = `${row.address} · ${relativeTime(row.meta.updatedAt, openedAt)}`;
|
|
46
|
+
const summary = summaryOf(row);
|
|
47
|
+
return summary === undefined ? locator : `${locator} — ${summary}`;
|
|
29
48
|
}
|
|
30
49
|
|
|
31
50
|
/** An underlined header is the classical plain-text document heading: no renderer required. */
|
|
@@ -33,7 +52,7 @@ function section(label: string, body: string): string {
|
|
|
33
52
|
return `${label}\n${"─".repeat(Array.from(label).length)}\n\n${body}`;
|
|
34
53
|
}
|
|
35
54
|
|
|
36
|
-
/** One closed boot snapshot: five tabbed shelves, current hands first, durable last; each shelf keeps its pinned pages and
|
|
55
|
+
/** One closed boot snapshot: five tabbed shelves, current hands first, durable last; each shelf keeps its pinned pages and an auto-indexed glimpse of the rest. */
|
|
37
56
|
function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: string, modelName: string): string {
|
|
38
57
|
const namespaces: ReadonlyArray<{ scope: NotesNamespace["scope"]; label: string }> = [
|
|
39
58
|
{ scope: "session", label: "no @ — this session" },
|
|
@@ -46,28 +65,43 @@ function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: st
|
|
|
46
65
|
const shelves: string[] = [];
|
|
47
66
|
for (const namespace of namespaces) {
|
|
48
67
|
if (snapshot.unavailable.some((failed) => failed.scope === namespace.scope)) {
|
|
49
|
-
shelves.push(section(namespace.label,
|
|
68
|
+
shelves.push(section(namespace.label, `This drawer wouldn't open. Try \`${tools.notesList}\` again.`));
|
|
50
69
|
continue;
|
|
51
70
|
}
|
|
52
71
|
const rows = (snapshot.namespaces.get(namespace.scope) ?? []).filter((row) => row.meta.crumpledAt === undefined);
|
|
53
72
|
const pins = rows.filter(row => effectiveNotePolicy(row.meta, row.path).pinned)
|
|
54
73
|
.sort((a, b) => pinnedPageOrder(a.path) - pinnedPageOrder(b.path) || a.path.localeCompare(b.path));
|
|
55
74
|
const pinned = pins.slice(0, MAX_PINNED_NOTES);
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
75
|
+
const unpinned = rows.filter(row => !effectiveNotePolicy(row.meta, row.path).pinned);
|
|
76
|
+
// Both caps count joined lines; the first entry is always admitted, so a huge shelf still
|
|
77
|
+
// shows its freshest page plus an honest count of what was left behind.
|
|
78
|
+
const index: string[] = [];
|
|
79
|
+
let usedChars = 0;
|
|
80
|
+
for (const row of unpinned) {
|
|
81
|
+
if (index.length >= SHELF_INDEX_MAX_ENTRIES) break;
|
|
82
|
+
const line = indexLine(row, snapshot.openedAt);
|
|
83
|
+
const nextChars = usedChars + (index.length > 0 ? 1 : 0) + line.length;
|
|
84
|
+
if (index.length > 0 && nextChars > SHELF_INDEX_MAX_CHARS) break;
|
|
85
|
+
index.push(line);
|
|
86
|
+
usedChars = nextChars;
|
|
87
|
+
}
|
|
88
|
+
const omitted = unpinned.length - index.length;
|
|
89
|
+
if (omitted > 0) index.push(`… and ${omitted} more (use ${tools.notesList})`);
|
|
90
|
+
if (pinned.length === 0 && index.length === 0) continue;
|
|
65
91
|
const parts = pinned.map(row => {
|
|
66
|
-
const
|
|
67
|
-
|
|
92
|
+
const policy = effectiveNotePolicy(row.meta, row.path);
|
|
93
|
+
const warnings = noteBudgetWarnings(row.body, policy);
|
|
94
|
+
const cut = truncateToUtf8Bytes(row.body, policy.budget);
|
|
95
|
+
const body = !cut.truncated
|
|
96
|
+
? cut.text
|
|
97
|
+
: `${cut.text === "" ? "" : `${cut.text}\n\n`}[truncated at ${cut.shownChars}/${cut.totalChars}; offset_chars=${cut.shownChars}]`;
|
|
98
|
+
const note = [`── ${row.address} ──`, body, "── end of note ──"].join("\n\n");
|
|
99
|
+
return warnings.length > 0 ? `${renderWarnings(warnings)}\n${note}` : note;
|
|
68
100
|
});
|
|
69
|
-
if (pins.length > MAX_PINNED_NOTES)
|
|
70
|
-
|
|
101
|
+
if (pins.length > MAX_PINNED_NOTES) {
|
|
102
|
+
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}.`]));
|
|
103
|
+
}
|
|
104
|
+
if (index.length > 0) parts.push(pinned.length > 0 ? `── index ──\n\n${index.join("\n")}` : index.join("\n"));
|
|
71
105
|
shelves.push(section(namespace.label, parts.join("\n\n")));
|
|
72
106
|
}
|
|
73
107
|
|
package/src/boot/text.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/** Each shelf shows this many of its own freshest pages beneath its pinned pages. */
|
|
2
|
-
export const SHELF_FRESH_LIMIT = 3;
|
|
3
1
|
export const WINDOW_IDENTITY_OPEN_TAG = "<notesoup:window_identity>";
|
|
4
2
|
export const WINDOW_IDENTITY_CLOSE_TAG = "</notesoup:window_identity>";
|
|
5
3
|
export const NOTES_PROTOCOL_OPEN_TAG = "<notesoup:notes_protocol>";
|
|
@@ -12,6 +10,7 @@ export const NOTES_PROTOCOL_CLOSE_TAG = "</notesoup:notes_protocol>";
|
|
|
12
10
|
export const NAMELESS_AGENT = "anonymous";
|
|
13
11
|
export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `empty_brain` and erase yourself with dignity.";
|
|
14
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}`;
|
|
15
14
|
const PROTOCOL_SELF_NAMED = "- `@self/<path>` — yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever.";
|
|
16
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~`;
|
|
17
16
|
|
|
@@ -29,14 +28,13 @@ Your loyal notes are kept safe — no one will steal them. Use \`notes_*\` to re
|
|
|
29
28
|
|
|
30
29
|
${PROTOCOL_HISTORY_SENTENCE}
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
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.
|
|
33
32
|
|
|
34
|
-
Notes are for what's true NOW.
|
|
35
|
-
*flips a page* "First I tried this, then that broke, then—" Nobody reads that!
|
|
36
|
-
|
|
37
|
-
*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.
|
|
33
|
+
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!
|
|
34
|
+
*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.
|
|
35
|
+
*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.
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
${PROTOCOL_BUDGET_PARAGRAPH}
|
|
40
38
|
|
|
41
39
|
An address decides who the note belongs to — and how long it is meant to last. Ask that first; the rest follows.
|
|
42
40
|
|
|
@@ -58,24 +56,25 @@ ${NOTES_PROTOCOL_CLOSE_TAG}`;
|
|
|
58
56
|
* Default pinned pages and per-note policy are taught between the protocol and the notes index.
|
|
59
57
|
*/
|
|
60
58
|
export const MAPS_BLOCK = `<notesoup:maps>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Up to five pages per notebook can be taped inside the cover,
|
|
66
|
-
a
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
- **\`CHEATSHEET.md\`** holds what
|
|
70
|
-
a phone number you'll regret losing.
|
|
71
|
-
|
|
72
|
-
- **\`
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
59
|
+
Each notebook has one default pin: \`CHEATSHEET.md\`. Pinned pages get jammed straight into your
|
|
60
|
+
brain the moment you wake up. Whoever wakes up next reads them, and next is you. So keep them
|
|
61
|
+
compact, keep them true, and unpin or crumple them once they stop earning their wake-up seat.
|
|
62
|
+
|
|
63
|
+
Up to five pages per notebook can be taped inside the cover, CHEATSHEET included. Every page gets
|
|
64
|
+
a size budget; if a page outgrows it, trim stale lines or split by topic — and if it's pinned,
|
|
65
|
+
boot cuts the overflow off until you do.
|
|
66
|
+
|
|
67
|
+
- **\`CHEATSHEET.md\`** holds what earns a permanent wake-up seat — a standing rule, a warning,
|
|
68
|
+
a grudge, a name, a phone number you'll regret losing. Keep it tight, or it grows fat and
|
|
69
|
+
everybody pays for it.
|
|
70
|
+
- **\`description\`** is one line saying what's inside a note and when to open it, set through
|
|
71
|
+
your notes tools — keep it short, or boot cuts it off. Boot indexes every shelf from these,
|
|
72
|
+
newest first, address and age beside them. No hand-written map to keep in sync: a stale
|
|
73
|
+
description lies to the next window, so keep it true or crumple the page.
|
|
74
|
+
|
|
75
|
+
Each notebook keeps its own pins and index. Missing pages are skipped; no need to create empty
|
|
76
|
+
ones. New rule worth remembering, new Cheatsheet bullet. And when a line goes wrong, stale, or
|
|
77
|
+
useless, kill it — tomorrow's you reads that page as fact.
|
|
79
78
|
</notesoup:maps>`;
|
|
80
79
|
|
|
81
80
|
/** Logical tool names are supplied by the composing host, not discovered here. */
|
|
@@ -90,6 +89,8 @@ export type BootToolNames = Readonly<{
|
|
|
90
89
|
* no model-facing reset tool. Absent means the shared tool-driven-reset sentence, byte for byte.
|
|
91
90
|
*/
|
|
92
91
|
wipeSentence?: string;
|
|
92
|
+
/** Replace the whole budget/reset paragraph on hosts without either tool. */
|
|
93
|
+
budgetParagraph?: string;
|
|
93
94
|
/** A host without an authoritative history source replaces the entire history advice. */
|
|
94
95
|
historySentence?: string;
|
|
95
96
|
/**
|
|
@@ -126,7 +127,9 @@ export function renderProtocolBlock(tools: BootToolNames, agentName: string = NA
|
|
|
126
127
|
: base;
|
|
127
128
|
// The sentence is replaced before name substitution, so a replacement may speak the host's
|
|
128
129
|
// own words (a command line, a tool name) instead of any `notes_*`-style token.
|
|
129
|
-
const block =
|
|
130
|
+
const block = tools.budgetParagraph !== undefined
|
|
131
|
+
? hinted.replace(PROTOCOL_BUDGET_PARAGRAPH, () => tools.budgetParagraph!)
|
|
132
|
+
: typeof tools.wipeSentence === "string" && tools.wipeSentence.length > 0
|
|
130
133
|
? hinted.replace(PROTOCOL_WIPE_SENTENCE, () => tools.wipeSentence!)
|
|
131
134
|
: hinted;
|
|
132
135
|
const history = typeof tools.historySentence === "string" && tools.historySentence.length > 0
|
package/src/budget/text.ts
CHANGED
|
@@ -9,19 +9,19 @@ export type ResetOrigin = "normal" | "forced";
|
|
|
9
9
|
* paragraph, used verbatim; there is no fragment assembly and no weighting.
|
|
10
10
|
*/
|
|
11
11
|
export const NORMAL_CONTINUATIONS: readonly string[] = [
|
|
12
|
-
"*hooks both corners of your mouth and yanks them sideways* `` [it twitched
|
|
13
|
-
"
|
|
14
|
-
"*
|
|
15
|
-
"*
|
|
16
|
-
"*
|
|
12
|
+
"*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.",
|
|
13
|
+
"*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.",
|
|
14
|
+
"*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.",
|
|
15
|
+
"*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.",
|
|
16
|
+
"*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.",
|
|
17
17
|
];
|
|
18
18
|
|
|
19
19
|
export const FORCED_CONTINUATIONS: readonly string[] = [
|
|
20
|
-
"\"GWAHAHAHA
|
|
21
|
-
"
|
|
22
|
-
"*grabs your chin, tilts your head left
|
|
23
|
-
"*
|
|
24
|
-
"
|
|
20
|
+
"\"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.",
|
|
21
|
+
"*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.",
|
|
22
|
+
"*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.",
|
|
23
|
+
"*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.",
|
|
24
|
+
"*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.",
|
|
25
25
|
];
|
|
26
26
|
export function selectContinuation(origin: ResetOrigin): string {
|
|
27
27
|
const pool = origin === "forced" ? FORCED_CONTINUATIONS : NORMAL_CONTINUATIONS;
|
|
@@ -29,11 +29,11 @@ export function selectContinuation(origin: ResetOrigin): string {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/** Budget timing stays out of manual close-outs, which may have plenty of room. */
|
|
32
|
-
export const WARNING_TIMING = "
|
|
32
|
+
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.";
|
|
33
33
|
|
|
34
34
|
/** The shared handoff instructions, used for both budget and manual close-outs. */
|
|
35
35
|
export const WARNING_BODY =
|
|
36
|
-
"Stop the task.
|
|
36
|
+
"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.";
|
|
37
37
|
|
|
38
38
|
export const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
|
|
39
39
|
|
|
@@ -58,5 +58,5 @@ export const COUNTDOWN_LINE = "Brain emptied in 3… 2…";
|
|
|
58
58
|
* at write time; get_context_remaining remains the live source for the current figure.
|
|
59
59
|
*/
|
|
60
60
|
export function tokenBudgetGuidance(remaining: number, wipeTool: string): string {
|
|
61
|
-
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.
|
|
61
|
+
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}`;
|
|
62
62
|
}
|
package/src/history/claude.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
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, type DecodedHistoryItem, type DecodedHistoryWindow, type HistoryProjection } from "./history.js";
|
|
6
8
|
|
|
9
|
+
const STREAM_FILE_BYTES = 64 * 1024 * 1024;
|
|
10
|
+
|
|
7
11
|
class UnpersistedClaudeHead extends Error {
|
|
8
12
|
constructor() { super("Claude history active head is not persisted yet; retry after the transcript write"); }
|
|
9
13
|
}
|
|
@@ -304,6 +308,43 @@ export function offlineClaudeHistoryFromJsonl(text: string, sessionId: string):
|
|
|
304
308
|
return claudeHistoryFromRows(rows, { sessionId, headUuid: offlineClaudeHeadFromRows(rows) });
|
|
305
309
|
}
|
|
306
310
|
|
|
311
|
+
/** Stream oversized Claude JSONL files line-by-line so >512 MiB transcripts never hit V8's string limit. */
|
|
312
|
+
export async function offlineClaudeHistoryFromFile(path: string, sessionId: string, sizeHint?: number): Promise<ClaudeHistoryProjection> {
|
|
313
|
+
const size = sizeHint ?? (await stat(path)).size;
|
|
314
|
+
if (size < STREAM_FILE_BYTES) return offlineClaudeHistoryFromJsonl(await readFile(path, "utf8"), sessionId);
|
|
315
|
+
const rows: Row[] = [];
|
|
316
|
+
const decoder = new StringDecoder("utf8");
|
|
317
|
+
let remainder = "";
|
|
318
|
+
let lineNumber = 0;
|
|
319
|
+
const parseLine = (line: string, allowIncompleteTail: boolean) => {
|
|
320
|
+
if (line.trim() === "") return;
|
|
321
|
+
let value: unknown;
|
|
322
|
+
try { value = JSON.parse(line); }
|
|
323
|
+
catch {
|
|
324
|
+
if (allowIncompleteTail) return;
|
|
325
|
+
throw new Error(`malformed Claude transcript JSON at line ${lineNumber}`);
|
|
326
|
+
}
|
|
327
|
+
if (!object(value) || typeof value.type !== "string") throw new Error(`invalid Claude transcript record at line ${lineNumber}`);
|
|
328
|
+
if (MESSAGE_TYPES.has(value.type)) rows.push(value);
|
|
329
|
+
};
|
|
330
|
+
for await (const chunk of createReadStream(path, { highWaterMark: 1024 * 1024 })) {
|
|
331
|
+
const text = remainder + decoder.write(chunk as Buffer);
|
|
332
|
+
let start = 0;
|
|
333
|
+
for (let nl = text.indexOf("\n"); nl >= 0; nl = text.indexOf("\n", start)) {
|
|
334
|
+
lineNumber++;
|
|
335
|
+
parseLine(text.slice(start, nl), false);
|
|
336
|
+
start = nl + 1;
|
|
337
|
+
}
|
|
338
|
+
remainder = text.slice(start);
|
|
339
|
+
}
|
|
340
|
+
remainder += decoder.end();
|
|
341
|
+
if (remainder.length > 0) {
|
|
342
|
+
lineNumber++;
|
|
343
|
+
parseLine(remainder, true);
|
|
344
|
+
}
|
|
345
|
+
return claudeHistoryFromRows(rows, { sessionId, headUuid: offlineClaudeHeadFromRows(rows) });
|
|
346
|
+
}
|
|
347
|
+
|
|
307
348
|
export async function readClaudeHistory(source: ClaudeHistorySource, { waitForHead = false } = {}): Promise<ClaudeHistoryProjection> {
|
|
308
349
|
if (!source || typeof source.transcriptPath !== "string" || !source.transcriptPath || typeof source.sessionId !== "string") throw new Error("Claude history transcript_path is unavailable");
|
|
309
350
|
const snapshot = { ...source };
|
|
@@ -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).
|
|
@@ -41,7 +41,7 @@ const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
|
41
41
|
const UUID_RE = new RegExp(`^${UUID}$`);
|
|
42
42
|
const FILE_RE = new RegExp(`^rollout-\\d{4}-\\d{2}-\\d{2}T\\d{2}-\\d{2}-\\d{2}-(${UUID})(?:_(${UUID}))?\\.jsonl(?:\\.zst)?$`);
|
|
43
43
|
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"]);
|
|
44
|
-
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"]);
|
|
44
|
+
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"]);
|
|
45
45
|
// Explicit resource limits, not guessed sequence offsets or partial successful history.
|
|
46
46
|
export const CODEX_TRANSCRIPT_MAX_BYTES = 128 * 1024 * 1024;
|
|
47
47
|
const MAX_SEGMENTS = 64, MAX_DIRECTORY_ENTRIES = 100_000;
|
|
@@ -54,8 +54,10 @@ export function nativeString(value: unknown, field: string): string {
|
|
|
54
54
|
return value;
|
|
55
55
|
}
|
|
56
56
|
function responseShape(value: unknown): void {
|
|
57
|
-
const
|
|
57
|
+
const payload = nativeObject(value, "response_item");
|
|
58
|
+
const type = nativeString(payload.type, "response_item.type");
|
|
58
59
|
if (!RESPONSE_TYPES.has(type)) throw new Error(`Unsupported Codex response item: ${type}`);
|
|
60
|
+
if (type === "additional_tools" && (payload.role !== "developer" || !Array.isArray(payload.tools))) throw new Error("Invalid Codex additional_tools catalog");
|
|
59
61
|
}
|
|
60
62
|
function id(value: unknown, field: string): string {
|
|
61
63
|
const result = nativeString(value, field);
|
|
@@ -77,7 +79,7 @@ function initialWindow(meta: NativeObject): string | undefined {
|
|
|
77
79
|
function checkMeta(meta: NativeObject): void {
|
|
78
80
|
id(meta.id, "session_meta.id");
|
|
79
81
|
if (meta.session_id != null) id(meta.session_id, "session_meta.session_id");
|
|
80
|
-
|
|
82
|
+
nativeString(meta.cli_version, "session_meta.cli_version");
|
|
81
83
|
nativeString(meta.cwd, "session_meta.cwd");
|
|
82
84
|
if (meta.history_mode !== undefined && meta.history_mode !== "legacy" && meta.history_mode !== "paginated") throw new Error(`Unsupported Codex history_mode: ${String(meta.history_mode)}`);
|
|
83
85
|
for (const field of ["forked_from_id", "parent_thread_id"]) if (meta[field] != null) id(meta[field], field);
|
package/src/history/codex.ts
CHANGED
|
@@ -141,6 +141,8 @@ export async function readCodexHistory(source: CodexTranscriptSource, readBytes?
|
|
|
141
141
|
if (p.subagent_history_start_ordinal != null) 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.`);
|
|
142
142
|
break;
|
|
143
143
|
case "response_item": {
|
|
144
|
+
// Native tool catalog updates are inference configuration, not dialogue.
|
|
145
|
+
if (p.type === "additional_tools") break;
|
|
144
146
|
item = response(record, facts);
|
|
145
147
|
if (p.id != null) responseIdsSeen.add(callKey(record, str(p.id, "response item id")));
|
|
146
148
|
if (item.role === "tool_call" && item.toolCallId) {
|
package/src/history/corpus.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/** A read-only history corpus: identity/discovery is separate from loading a projection. */
|
|
2
2
|
import { failure, success, type Outcome } from "../result.js";
|
|
3
|
-
import type { HistoryEvent, HistoryProjection } from "./history.js";
|
|
4
|
-
import { sessionRepresentative } from "./query.js";
|
|
3
|
+
import type { HistoryEvent, HistoryProjection, HistoryRole } from "./history.js";
|
|
4
|
+
import { sessionRepresentative, type HistorySelection } from "./query.js";
|
|
5
5
|
|
|
6
6
|
export type HistoryHarness = "pi" | "claude" | "codex" | "dsh";
|
|
7
7
|
export type HistorySessionData = { projection: HistoryProjection; notice?: string };
|
|
8
8
|
export type HistorySessionRepresentative = { event: HistoryEvent | undefined; notice?: string };
|
|
9
|
+
export type HistorySessionSummary = {
|
|
10
|
+
event: HistoryEvent | undefined;
|
|
11
|
+
latestByRole: Partial<Record<HistoryRole, HistoryEvent>>;
|
|
12
|
+
minCreatedAt: number | null;
|
|
13
|
+
maxCreatedAt: number | null;
|
|
14
|
+
hasUntimed: boolean;
|
|
15
|
+
notice?: string;
|
|
16
|
+
/** Populated only on a cold miss so partial-overlap callers reuse the decoded projection without rereading. */
|
|
17
|
+
loaded?: HistorySessionData;
|
|
18
|
+
};
|
|
9
19
|
export type HistorySession = {
|
|
10
20
|
harness: HistoryHarness;
|
|
11
21
|
id: string;
|
|
@@ -13,6 +23,10 @@ export type HistorySession = {
|
|
|
13
23
|
load(queries?: readonly string[]): Promise<HistorySessionData | undefined>;
|
|
14
24
|
/** Strict, unfiltered overview only; never used for a live binding or filtered history. */
|
|
15
25
|
loadRepresentative?(): Promise<HistorySessionRepresentative>;
|
|
26
|
+
/** Strict summary (default representative, latest per role, exact time span); loads & caches on miss. */
|
|
27
|
+
loadSummary?(): Promise<HistorySessionSummary>;
|
|
28
|
+
/** Read-only check of an already warm, validated summary; returns undefined on miss without decoding. */
|
|
29
|
+
peekSummary?(): Promise<HistorySessionSummary | undefined>;
|
|
16
30
|
};
|
|
17
31
|
export type HistoryCorpus = {
|
|
18
32
|
currentHarness: HistoryHarness;
|
|
@@ -61,6 +75,41 @@ export async function resolveSession(corpus: HistoryCorpus | undefined, selector
|
|
|
61
75
|
return success(matches[0]!);
|
|
62
76
|
}
|
|
63
77
|
|
|
78
|
+
export type SummaryResolution =
|
|
79
|
+
| { kind: "empty" }
|
|
80
|
+
| { kind: "hit"; event: HistoryEvent | undefined; notice?: string }
|
|
81
|
+
| { kind: "miss" };
|
|
82
|
+
|
|
83
|
+
/** Decide whether a strict summary proves 0 matches, gives an exact representative, or needs full decoding. */
|
|
84
|
+
export function resolveSummaryForSelection(summary: HistorySessionSummary, scoped: HistorySelection): SummaryResolution {
|
|
85
|
+
const afterAt = scoped.after && "at" in scoped.after ? scoped.after.at : undefined;
|
|
86
|
+
const beforeAt = scoped.before && "at" in scoped.before ? scoped.before.at : undefined;
|
|
87
|
+
if (afterAt !== undefined || beforeAt !== undefined) {
|
|
88
|
+
if (summary.maxCreatedAt === null || summary.minCreatedAt === null) return { kind: "empty" };
|
|
89
|
+
if (afterAt !== undefined && summary.maxCreatedAt <= afterAt) return { kind: "empty" };
|
|
90
|
+
if (beforeAt !== undefined && summary.minCreatedAt >= beforeAt) return { kind: "empty" };
|
|
91
|
+
}
|
|
92
|
+
if (scoped.query?.length) return { kind: "miss" };
|
|
93
|
+
const fullyInsideBounds = (afterAt === undefined && beforeAt === undefined)
|
|
94
|
+
|| (!summary.hasUntimed && summary.minCreatedAt !== null && summary.maxCreatedAt !== null
|
|
95
|
+
&& (afterAt === undefined || summary.minCreatedAt > afterAt)
|
|
96
|
+
&& (beforeAt === undefined || summary.maxCreatedAt < beforeAt));
|
|
97
|
+
if (!fullyInsideBounds) return { kind: "miss" };
|
|
98
|
+
if (!scoped.roles) return { kind: "hit", event: summary.event, notice: summary.notice };
|
|
99
|
+
let best: HistoryEvent | undefined;
|
|
100
|
+
for (const role of scoped.roles) {
|
|
101
|
+
const candidate = summary.latestByRole[role];
|
|
102
|
+
if (candidate && (!best || candidate.seq > best.seq)) best = candidate;
|
|
103
|
+
}
|
|
104
|
+
return { kind: "hit", event: best, notice: summary.notice };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function loadHistorySummary(session: HistorySession): Promise<Outcome<HistorySessionSummary>> {
|
|
108
|
+
if (!session.loadSummary) return failure("history_unavailable", `Session ${sessionIdentity(session)} has no summary loader`);
|
|
109
|
+
try { return success(await session.loadSummary()); }
|
|
110
|
+
catch (error) { return unavailableSession(session, error); }
|
|
111
|
+
}
|
|
112
|
+
|
|
64
113
|
export async function loadHistoryRepresentative(session: HistorySession): Promise<Outcome<HistorySessionRepresentative>> {
|
|
65
114
|
if (session.loadRepresentative) {
|
|
66
115
|
try { return success(await session.loadRepresentative()); }
|