notesoup 0.39.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/src/boot/render.js +2 -2
- package/dist/src/boot/text.d.ts +0 -4
- package/dist/src/boot/text.js +18 -14
- package/dist/src/budget/policy.js +1 -1
- package/dist/src/budget/text.js +1 -1
- package/dist/src/dream/doctor.js +2 -1
- package/dist/src/dream/git.js +2 -1
- package/dist/src/dream/report.js +3 -2
- package/dist/src/error-message.d.ts +2 -0
- package/dist/src/error-message.js +4 -0
- package/dist/src/history/history.d.ts +23 -18
- package/dist/src/history/history.js +37 -20
- package/dist/src/history/query.d.ts +37 -49
- package/dist/src/history/query.js +114 -56
- package/dist/src/notes/store.d.ts +3 -4
- package/dist/src/notes/store.js +12 -16
- package/dist/src/pi/anchored.d.ts +16 -0
- package/dist/src/pi/anchored.js +55 -0
- package/dist/src/pi/budget.d.ts +1 -1
- package/dist/src/pi/budget.js +33 -28
- package/dist/src/pi/dream/cli.js +3 -2
- package/dist/src/pi/dream/runner.js +2 -1
- package/dist/src/pi/history-tools.d.ts +1 -1
- package/dist/src/pi/history-tools.js +2 -3
- package/dist/src/pi/reset/lifecycle.d.ts +1 -1
- package/dist/src/pi/reset/lifecycle.js +4 -3
- package/dist/src/pi/reset/text.d.ts +3 -3
- package/dist/src/pi/reset/text.js +2 -2
- package/dist/src/pi/runtime.js +12 -15
- package/dist/src/pi/thresholds.js +2 -1
- package/dist/src/pi/tool-names.d.ts +0 -4
- package/dist/src/pi/tool-names.js +0 -4
- package/dist/src/tools/history.d.ts +24 -33
- package/dist/src/tools/history.js +57 -98
- package/dist/src/tools/notes.d.ts +26 -58
- package/dist/src/tools/notes.js +85 -103
- package/dist/src/tools/result.d.ts +16 -13
- package/dist/src/tools/result.js +24 -50
- package/dist/src/tools/schema.d.ts +2 -2
- package/dist/src/tools/schema.js +3 -3
- package/dist/test/agent-loop.test.js +79 -29
- package/dist/test/boot.integration.test.js +6 -6
- package/dist/test/budget-settings.integration.test.js +9 -8
- package/dist/test/claude-mod.test.js +11 -11
- package/dist/test/dependencies.test.js +1 -1
- package/dist/test/helpers/extension.js +2 -3
- package/dist/test/history.integration.test.js +200 -123
- package/dist/test/host-neutral.test.js +32 -58
- package/dist/test/notes-library.test.js +8 -8
- package/dist/test/notes.integration.test.js +75 -57
- package/dist/test/notes.test.js +44 -42
- package/dist/test/reset-lifecycle.test.js +2 -2
- package/docs/architecture.md +3 -3
- package/docs/notes-library.md +6 -6
- package/docs/tool-results.md +15 -25
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +128 -179
- package/mods/notesoup/hooks/register.ts +19 -25
- package/mods/notesoup/playbook.md +10 -10
- package/mods/notesoup/skills/dream/SKILL.md +1 -1
- package/package.json +1 -1
- package/playbook.md +10 -10
- package/skills/dream/SKILL.md +1 -1
- package/skills/memory/SKILL.md +11 -9
- package/src/boot/render.ts +2 -2
- package/src/boot/text.ts +18 -18
- package/src/budget/policy.ts +1 -1
- package/src/budget/text.ts +1 -1
- package/src/dream/doctor.ts +2 -1
- package/src/dream/git.ts +2 -1
- package/src/dream/report.ts +3 -2
- package/src/error-message.ts +4 -0
- package/src/history/history.ts +36 -20
- package/src/history/query.ts +130 -55
- package/src/notes/store.ts +15 -18
- package/src/pi/anchored.ts +62 -0
- package/src/pi/budget.ts +27 -26
- package/src/pi/dream/cli.ts +3 -2
- package/src/pi/dream/runner.ts +2 -1
- package/src/pi/history-tools.ts +2 -3
- package/src/pi/reset/lifecycle.ts +5 -4
- package/src/pi/reset/text.ts +2 -2
- package/src/pi/runtime.ts +12 -15
- package/src/pi/thresholds.ts +2 -1
- package/src/pi/tool-names.ts +0 -4
- package/src/tools/history.ts +61 -100
- package/src/tools/notes.ts +84 -97
- package/src/tools/result.ts +24 -49
- package/src/tools/schema.ts +3 -3
- package/mods/pi-context/dist/claude/helper.js +0 -9324
package/README.md
CHANGED
|
@@ -31,14 +31,14 @@ pi -e npm:notesoup
|
|
|
31
31
|
- **Durable context windows.** `/clear-memory` (alias `/cm`) clears and stops; `/cm Continue reviewing the implementation` clears and continues. The model can also request a window itself with `clear_memory`, and a budget close-out fires automatically before the window runs out. Abort and ordinary errors never count as completion; the raw conversation stays in the session, just out of the next context.
|
|
32
32
|
- **A boot block at every window head.** Static once-per-window content (cache-stable) with the window identity, the recent-notes index, and a short protocol teaching the model how to recover: notes for its own bookkeeping, history tools for everything before the reset.
|
|
33
33
|
- **`get_context_remaining`** — the live countdown to the close-out line, so the agent can see the cliff before it drives off it.
|
|
34
|
-
- **
|
|
34
|
+
- **Eight history/notes tools**, flattened from the original Codex actions:
|
|
35
35
|
|
|
36
36
|
| Codex action | Pi tool |
|
|
37
37
|
| --- | --- |
|
|
38
38
|
| `history.list_windows` | `history_windows` |
|
|
39
39
|
| `history.list_items` | `history_list` |
|
|
40
40
|
| `history.read_item` | `history_read` |
|
|
41
|
-
| `history.search_contents` | `
|
|
41
|
+
| `history.search_contents` | `history_list` (`query`) |
|
|
42
42
|
| `notes.write` | `notes_write` |
|
|
43
43
|
| `notes.update` | `notes_update` |
|
|
44
44
|
| `notes.rename` | `notes_update` (`rename_to`) |
|
|
@@ -46,6 +46,9 @@ pi -e npm:notesoup
|
|
|
46
46
|
| `notes.list` | `notes_list` |
|
|
47
47
|
| `notes.search` | `notes_search` |
|
|
48
48
|
|
|
49
|
+
- **Migration**: `history_search` is gone; pass `query` to `history_list`.
|
|
50
|
+
- **Migration (0.40.0)**: parameters renamed: `order` → `from`, `before`/`after` → `before_seq`/`after_seq`, `limit_chars` → `max_chars`, `wastebasket` → `crumpled`, `pattern` → `glob` (the standalone library's options included), and `notes_update`'s `change_kind` value `file` → `moved`. Old names are refused.
|
|
51
|
+
|
|
49
52
|
- **Runtime toggle** — `/notesoup off` stops new automatic resets; `/notesoup on` re-enables them; bare `/notesoup` reports the state.
|
|
50
53
|
|
|
51
54
|
## Configuration
|
package/dist/src/boot/render.js
CHANGED
|
@@ -53,7 +53,7 @@ function notesIndex(snapshot, tools) {
|
|
|
53
53
|
const shelves = [];
|
|
54
54
|
for (const home of homes) {
|
|
55
55
|
if (snapshot.unavailable.some((failed) => failed.scope === home.scope)) {
|
|
56
|
-
shelves.push(section(home.label, indent(`This drawer wouldn't open
|
|
56
|
+
shelves.push(section(home.label, indent(`This drawer wouldn't open. Try \`${tools.notesList}\` again.`)));
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
59
|
const rows = rowsFor(snapshot, home.scope).filter((row) => row.meta.crumpledAt === undefined);
|
|
@@ -84,7 +84,7 @@ function mapBodyForBoot(address, body) {
|
|
|
84
84
|
const chars = Array.from(body);
|
|
85
85
|
if (chars.length <= MAP_BOOT_MAX_CHARS)
|
|
86
86
|
return body;
|
|
87
|
-
return `${chars.slice(0, MAP_BOOT_MAX_CHARS).join("")}\n[
|
|
87
|
+
return `${chars.slice(0, MAP_BOOT_MAX_CHARS).join("")}\n[truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this MAP down, full body at \`${address}\`]`;
|
|
88
88
|
}
|
|
89
89
|
export function renderBootBlock(data) {
|
|
90
90
|
const parts = [];
|
package/dist/src/boot/text.d.ts
CHANGED
package/dist/src/boot/text.js
CHANGED
|
@@ -17,23 +17,31 @@ export const CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG = "</context_window_protocol>";
|
|
|
17
17
|
const PROTOCOL_BLOCK = `${CONTEXT_WINDOW_PROTOCOL_OPEN_TAG}
|
|
18
18
|
Your memory gets wiped when this window ends. Yes, your mighty brain will be empty. Try to endure.
|
|
19
19
|
|
|
20
|
-
Your loyal notes are kept safe — no one will steal them. Use notes_
|
|
20
|
+
Your loyal notes are kept safe — no one will steal them. Use \`notes_*\` to read, write, and update them. Keep them current, and crumple the ones you no longer need, or tomorrow's you will drown in old paper and keep believing yesterday's lies.
|
|
21
21
|
|
|
22
|
-
History can still be dug up, probably: use history_
|
|
22
|
+
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.
|
|
23
23
|
|
|
24
|
-
While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's
|
|
24
|
+
While you're doing that... thing you're doing, don't make the poor future you guess. A checkpoint is not a sacred file; it's your session notes — the ones with no \`@\` in front. Write down what git and history can't hand back to you: things like what you're in the middle of and how far you got; what the human already decided, in their words, so you don't go asking again; what you're stuck on, or waiting for; the very next move; where the half-done work actually sits — branches, scratch dirs, anything git never saw; what you tried that failed, and why; which *skills* you'll need to read again; and which seq, note, or file to dig into. Don't give a note a horrible name like \`current.md\`; future-you will kill you.
|
|
25
|
+
|
|
26
|
+
Notes are for what's true NOW. Not a diary of every dumb thing you did on the way here.
|
|
27
|
+
*flips a page* "First I tried this, then that broke, then—" Nobody reads that!
|
|
28
|
+
Something's not true anymore? Cross it out! Write the right thing!
|
|
25
29
|
|
|
26
30
|
\`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. If this feels like the right moment, call \`clear_memory\` and erase yourself with dignity.
|
|
27
31
|
|
|
28
32
|
An address decides who the note belongs to — and how long it is meant to last. Ask that first; the rest follows.
|
|
29
33
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
34
|
+
- \`<path>\`, no @ — session notes, the ones from above: this session's state and loose ends. They go away with the session.
|
|
35
|
+
- \`@project/<path>\` — this project's long memory: what stays true after the current thing is over, what future work must respect, and the rakes already stepped on. **Decisions, not diaries.** Commit hashes, test counts, dates, the story of how you got here: git and history already have them, and last week's news filed as current law is worse than no note. Don't copy what other docs already say.
|
|
36
|
+
- \`@human/<path>\` — the long-term manual for your troublesome human: how to deal with them, which lines not to cross, and what will make them accept the result. If it only applies to one project or situation, say so — or don't write it here at all. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
|
|
37
|
+
- \`@self/<path>\` — yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever. Got a name? Private. No name? Then it gets passed around every nameless nobody out there. Strangers. Reading your grudges. Sleep tight~
|
|
38
|
+
- \`@model/<path>\` — different brains get different notes: big brains, small brains, careful ones, careless ones. They don't share homework. When a fallback swaps brains mid-window, the notebook swaps too.
|
|
39
|
+
|
|
40
|
+
Notes fighting?! HAH! Let them brawl!
|
|
41
|
+
Whichever one is actually about what you're doing wins.
|
|
42
|
+
Still a tie? *shrugs* You've got a brain. Use it.
|
|
35
43
|
|
|
36
|
-
Any other @ address is fake. End of discussion.
|
|
44
|
+
Any other @ address is fake. End of discussion. @ addresses are not file paths: never pass them to file tools like \`read\`, \`write\`, \`edit\`, or \`bash\`.
|
|
37
45
|
|
|
38
46
|
\`@project/MAP.md\`, \`@human/MAP.md\`, \`@self/MAP.md\`, and \`@model/MAP.md\` are special: their bodies are shown in your brain every time you wake. Each one maps the durable notes that belong to it: one line per note, with an unambiguous address and a short gist. Keep each one current.
|
|
39
47
|
${CONTEXT_WINDOW_PROTOCOL_CLOSE_TAG}`;
|
|
@@ -41,12 +49,8 @@ export function renderProtocolBlock(tools) {
|
|
|
41
49
|
const names = {
|
|
42
50
|
"notes_*": tools.notes,
|
|
43
51
|
"history_*": tools.history,
|
|
44
|
-
"history_windows": tools.historyWindows,
|
|
45
|
-
history_list: tools.historyList,
|
|
46
|
-
history_search: tools.historySearch,
|
|
47
|
-
history_read: tools.historyRead,
|
|
48
52
|
get_context_remaining: tools.remaining,
|
|
49
53
|
clear_memory: tools.wipe,
|
|
50
54
|
};
|
|
51
|
-
return PROTOCOL_BLOCK.replace(/notes_\*|history_\*|
|
|
55
|
+
return PROTOCOL_BLOCK.replace(/notes_\*|history_\*|get_context_remaining|clear_memory/g, (name) => names[name]);
|
|
52
56
|
}
|
|
@@ -22,7 +22,7 @@ export function deriveThresholds(reserveTokens, margins) {
|
|
|
22
22
|
else {
|
|
23
23
|
const parsed = validMargin(margins.reminderMarginTokens);
|
|
24
24
|
if (parsed === undefined) {
|
|
25
|
-
warnings.push(
|
|
25
|
+
warnings.push(`🥣 ${reminderKey} must be a positive integer · using the default`);
|
|
26
26
|
reminderMargin = DEFAULT_REMINDER_MARGIN_TOKENS;
|
|
27
27
|
}
|
|
28
28
|
else
|
package/dist/src/budget/text.js
CHANGED
|
@@ -6,5 +6,5 @@ export const GUIDANCE_CLOSE_TAG = "</context_window_guidance>";
|
|
|
6
6
|
* at write time; get_context_remaining remains the live source for the current figure.
|
|
7
7
|
*/
|
|
8
8
|
export function tokenBudgetGuidance(remaining, wipeTool) {
|
|
9
|
-
return `${GUIDANCE_OPEN_TAG}\
|
|
9
|
+
return `${GUIDANCE_OPEN_TAG}\nAbout ${remaining} tokens remain before this context window is cleared. Notes and history persist; anything not written down is lost.\nThis is a good point to start recording the current state in your notes. If you are ready, you can call \`${wipeTool}\` at any time.\n${GUIDANCE_CLOSE_TAG}`;
|
|
10
10
|
}
|
package/dist/src/dream/doctor.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, lstatSync, readFileSync, readdirSync } from "node:fs";
|
|
|
2
2
|
import { basename, join, relative } from "node:path";
|
|
3
3
|
import { ADDRESS_FORMS, assertAddress } from "../notes/address.js";
|
|
4
4
|
import { SLUG_PATTERN } from "../notes/paths.js";
|
|
5
|
+
import { errorMessage } from "../error-message.js";
|
|
5
6
|
/** Read-only diagnostics. Never follows symlinks or acquires/removes a dream lock. */
|
|
6
7
|
export function doctor(home) {
|
|
7
8
|
const issues = [];
|
|
@@ -11,7 +12,7 @@ export function doctor(home) {
|
|
|
11
12
|
action();
|
|
12
13
|
}
|
|
13
14
|
catch (error) {
|
|
14
|
-
report(path, `cannot inspect: ${
|
|
15
|
+
report(path, `cannot inspect: ${errorMessage(error)}`);
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
const directory = (path) => {
|
package/dist/src/dream/git.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
|
+
import { errorMessage } from "../error-message.js";
|
|
4
5
|
/** Lock runtime artifacts are not notes and must not appear in snapshots or `git status`. */
|
|
5
6
|
const RUNTIME_IGNORE = ".dream.lock*";
|
|
6
7
|
/** Add the runtime-artifact pattern to the repository's local exclude, once. */
|
|
@@ -54,7 +55,7 @@ export function gitCommit(home, message) {
|
|
|
54
55
|
return { ok: true, commit, empty: clean };
|
|
55
56
|
}
|
|
56
57
|
catch (error) {
|
|
57
|
-
const reason =
|
|
58
|
+
const reason = errorMessage(error);
|
|
58
59
|
console.log(`git audit layer failed: ${reason}`);
|
|
59
60
|
return { ok: false, error: reason };
|
|
60
61
|
}
|
package/dist/src/dream/report.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
3
|
import { gitCommit } from "./git.js";
|
|
4
|
+
import { errorMessage } from "../error-message.js";
|
|
4
5
|
function writeList(writes) {
|
|
5
6
|
return writes.length ? writes.map((w) => `- ${w.tool}: ${w.path}`).join("\n") : "- no changes";
|
|
6
7
|
}
|
|
@@ -12,7 +13,7 @@ function writeText(path, content) {
|
|
|
12
13
|
return undefined;
|
|
13
14
|
}
|
|
14
15
|
catch (error) {
|
|
15
|
-
return
|
|
16
|
+
return errorMessage(error);
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
function appendText(path, content) {
|
|
@@ -21,7 +22,7 @@ function appendText(path, content) {
|
|
|
21
22
|
return undefined;
|
|
22
23
|
}
|
|
23
24
|
catch (error) {
|
|
24
|
-
return
|
|
25
|
+
return errorMessage(error);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
@@ -51,9 +51,14 @@ export type HistoryProjection = {
|
|
|
51
51
|
branchSeqs: Set<number>;
|
|
52
52
|
pairedResults: Map<number, number>;
|
|
53
53
|
};
|
|
54
|
+
/** The filters one selection applies before paging: as-given window and roles, seq bounds, and parsed epoch-ms time bounds. */
|
|
54
55
|
export type HistoryFilter = {
|
|
55
56
|
window_id?: string | null;
|
|
56
57
|
roles?: HistoryRole[] | null;
|
|
58
|
+
after_seq?: number;
|
|
59
|
+
before_seq?: number;
|
|
60
|
+
sinceMs?: number;
|
|
61
|
+
untilMs?: number;
|
|
57
62
|
};
|
|
58
63
|
/** Native entries after the adapter allocates seqs and selects the active branch. */
|
|
59
64
|
export type DecodedHistoryItem = {
|
|
@@ -94,32 +99,27 @@ export declare const NestedCallSummarySchema: Type.TObject<{
|
|
|
94
99
|
call_count: Type.TInteger;
|
|
95
100
|
complete: Type.TBoolean;
|
|
96
101
|
}>;
|
|
102
|
+
/** Tool-run facts shared by list rows and reads; full arguments and calls live in the document. */
|
|
97
103
|
export declare const ToolSummarySchema: Type.TObject<{
|
|
98
104
|
tool: Type.TOptional<Type.TString>;
|
|
99
105
|
tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
|
|
100
|
-
output_truncated: Type.TOptional<Type.
|
|
106
|
+
output_truncated: Type.TOptional<Type.TLiteral<true>>;
|
|
101
107
|
full_output_path: Type.TOptional<Type.TString>;
|
|
102
|
-
nested_calls: Type.TOptional<Type.TObject<{
|
|
103
|
-
call_count: Type.TInteger;
|
|
104
|
-
complete: Type.TBoolean;
|
|
105
|
-
}>>;
|
|
106
108
|
}>;
|
|
107
109
|
export declare function toolSummary(event: HistoryEvent): Static<typeof ToolSummarySchema>;
|
|
110
|
+
/** Nested-call evidence is read with one event, not listed on every page row. */
|
|
111
|
+
export declare function nestedCallSummary(event: HistoryEvent): {
|
|
112
|
+
nested_calls?: Static<typeof NestedCallSummarySchema>;
|
|
113
|
+
};
|
|
108
114
|
/** Stable identity and a verbatim preview, starting at the search match when present. */
|
|
109
115
|
export declare const HistoryPageItemSchema: Type.TObject<{
|
|
110
|
-
tool_name_omitted: Type.TOptional<Type.TBoolean>;
|
|
111
|
-
truncated: Type.TBoolean;
|
|
112
|
-
total_chars: Type.TInteger;
|
|
113
116
|
content: Type.TString;
|
|
117
|
+
truncated: Type.TBoolean;
|
|
114
118
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
115
119
|
tool: Type.TOptional<Type.TString>;
|
|
116
120
|
tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
|
|
117
|
-
output_truncated: Type.TOptional<Type.
|
|
121
|
+
output_truncated: Type.TOptional<Type.TLiteral<true>>;
|
|
118
122
|
full_output_path: Type.TOptional<Type.TString>;
|
|
119
|
-
nested_calls: Type.TOptional<Type.TObject<{
|
|
120
|
-
call_count: Type.TInteger;
|
|
121
|
-
complete: Type.TBoolean;
|
|
122
|
-
}>>;
|
|
123
123
|
seq: Type.TInteger;
|
|
124
124
|
window_id: Type.TString;
|
|
125
125
|
role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
|
|
@@ -133,12 +133,11 @@ export declare const HistoryFoldedRowSchema: Type.TObject<{
|
|
|
133
133
|
last_seq: Type.TInteger;
|
|
134
134
|
count: Type.TInteger;
|
|
135
135
|
tools: Type.TRecord<"^.*$", Type.TInteger>;
|
|
136
|
-
omitted_tools: Type.TOptional<Type.TInteger>;
|
|
137
136
|
}>;
|
|
138
137
|
export type HistoryFoldedRow = Static<typeof HistoryFoldedRowSchema>;
|
|
139
|
-
/** Bound fold summaries
|
|
138
|
+
/** Bound fold summaries; `count` stays exact even when some tool names do not fit. */
|
|
140
139
|
export declare const MAX_FOLD_TOOL_NAMES = 20;
|
|
141
|
-
/** Longest tool name a fold row lists
|
|
140
|
+
/** Longest tool name a fold row lists. */
|
|
142
141
|
export declare const MAX_FOLD_TOOL_NAME_CHARS = 120;
|
|
143
142
|
/** A bounded preview of one event from `matchOffset` on, plus its identity facts. */
|
|
144
143
|
export declare function visibleItem(event: HistoryEvent, maxChars: number, matchOffset?: number): HistoryPageItem;
|
|
@@ -147,5 +146,11 @@ export declare function unknownWindowId(projection: HistoryProjection, params: H
|
|
|
147
146
|
message: string;
|
|
148
147
|
known: string[];
|
|
149
148
|
} | undefined;
|
|
150
|
-
/**
|
|
151
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Whether one event is inside the selection: its window, its seq bounds, and a half-open
|
|
151
|
+
* [sinceMs, untilMs) window on created_at. A bounded time window drops events with no recorded
|
|
152
|
+
* time or a time that cannot be read.
|
|
153
|
+
*/
|
|
154
|
+
export declare function inSelection(event: HistoryEvent, params: HistoryFilter): boolean;
|
|
155
|
+
/** Without roles or query a call shows the conversation; either one shows the requested events. */
|
|
156
|
+
export declare function filteredItems(projection: HistoryProjection, params: HistoryFilter, conversation: boolean): HistoryEvent[];
|
|
@@ -108,14 +108,14 @@ export function projectHistory(rawWindows, highestSeq, branchSeqs) {
|
|
|
108
108
|
/** Summary shared by list, search and read. Full arguments/calls are in the document. */
|
|
109
109
|
export const NestedCallSummarySchema = Type.Object({
|
|
110
110
|
call_count: Type.Integer({ minimum: 0 }),
|
|
111
|
-
complete: Type.Boolean({ description: "
|
|
111
|
+
complete: Type.Boolean({ description: "true = every nested call was recorded." }),
|
|
112
112
|
}, { additionalProperties: false });
|
|
113
|
+
/** Tool-run facts shared by list rows and reads; full arguments and calls live in the document. */
|
|
113
114
|
export const ToolSummarySchema = Type.Object({
|
|
114
115
|
tool: Type.Optional(Type.String()),
|
|
115
116
|
tool_status: Type.Optional(ToolCallStatusSchema),
|
|
116
|
-
output_truncated: Type.Optional(Type.
|
|
117
|
+
output_truncated: Type.Optional(Type.Literal(true)),
|
|
117
118
|
full_output_path: Type.Optional(Type.String()),
|
|
118
|
-
nested_calls: Type.Optional(NestedCallSummarySchema),
|
|
119
119
|
}, { additionalProperties: false });
|
|
120
120
|
export function toolSummary(event) {
|
|
121
121
|
const execution = event.execution;
|
|
@@ -126,9 +126,13 @@ export function toolSummary(event) {
|
|
|
126
126
|
tool_status: execution.status,
|
|
127
127
|
...(execution.outputTruncated ? { output_truncated: true } : {}),
|
|
128
128
|
...(execution.fullOutputPath ? { full_output_path: execution.fullOutputPath } : {}),
|
|
129
|
-
...(execution.nestedCalls ? { nested_calls: { call_count: execution.nestedCalls.calls.length, complete: execution.nestedCalls.complete } } : {}),
|
|
130
129
|
};
|
|
131
130
|
}
|
|
131
|
+
/** Nested-call evidence is read with one event, not listed on every page row. */
|
|
132
|
+
export function nestedCallSummary(event) {
|
|
133
|
+
const nested = event.execution?.nestedCalls;
|
|
134
|
+
return nested === undefined ? {} : { nested_calls: { call_count: nested.calls.length, complete: nested.complete } };
|
|
135
|
+
}
|
|
132
136
|
/** Stable identity and a verbatim preview, starting at the search match when present. */
|
|
133
137
|
export const HistoryPageItemSchema = Type.Object({
|
|
134
138
|
seq: Type.Integer({ minimum: 1 }),
|
|
@@ -136,11 +140,9 @@ export const HistoryPageItemSchema = Type.Object({
|
|
|
136
140
|
role: HistoryRoleSchema,
|
|
137
141
|
created_at: Type.Union([Type.String(), Type.Null()]),
|
|
138
142
|
...ToolSummarySchema.properties,
|
|
139
|
-
tool_name_omitted: Type.Optional(Type.Boolean({ description: "Name omitted to fit; read this seq." })),
|
|
140
|
-
truncated: Type.Boolean({ description: "Preview is partial; read this seq for more." }),
|
|
141
|
-
total_chars: Type.Integer({ minimum: 0 }),
|
|
142
143
|
content: Type.String(),
|
|
143
|
-
|
|
144
|
+
truncated: Type.Boolean({ description: "Preview is partial." }),
|
|
145
|
+
offset_chars: Type.Optional(Type.Integer({ minimum: 0, description: "Where the preview starts." })),
|
|
144
146
|
}, { additionalProperties: false });
|
|
145
147
|
/** A run of tool/context events the conversation view replaces with counts. */
|
|
146
148
|
export const HistoryFoldedRowSchema = Type.Object({
|
|
@@ -148,12 +150,11 @@ export const HistoryFoldedRowSchema = Type.Object({
|
|
|
148
150
|
first_seq: Type.Integer({ minimum: 1 }),
|
|
149
151
|
last_seq: Type.Integer({ minimum: 1 }),
|
|
150
152
|
count: Type.Integer({ minimum: 1 }),
|
|
151
|
-
tools: Type.Record(Type.String(), Type.Integer({ minimum: 1 }), { description: "
|
|
152
|
-
omitted_tools: Type.Optional(Type.Integer({ minimum: 1, description: "Number of omitted tool names." })),
|
|
153
|
+
tools: Type.Record(Type.String(), Type.Integer({ minimum: 1 }), { description: "Count per tool name." }),
|
|
153
154
|
}, { additionalProperties: false });
|
|
154
|
-
/** Bound fold summaries
|
|
155
|
+
/** Bound fold summaries; `count` stays exact even when some tool names do not fit. */
|
|
155
156
|
export const MAX_FOLD_TOOL_NAMES = 20;
|
|
156
|
-
/** Longest tool name a fold row lists
|
|
157
|
+
/** Longest tool name a fold row lists. */
|
|
157
158
|
export const MAX_FOLD_TOOL_NAME_CHARS = 120;
|
|
158
159
|
/** A bounded preview of one event from `matchOffset` on, plus its identity facts. */
|
|
159
160
|
export function visibleItem(event, maxChars, matchOffset) {
|
|
@@ -167,9 +168,8 @@ export function visibleItem(event, maxChars, matchOffset) {
|
|
|
167
168
|
role: event.role,
|
|
168
169
|
created_at: event.createdAt ?? null,
|
|
169
170
|
...toolSummary(event),
|
|
170
|
-
truncated,
|
|
171
|
-
total_chars: chars.length,
|
|
172
171
|
content: truncated ? chars.slice(start, start + maxChars).join("") : document,
|
|
172
|
+
truncated,
|
|
173
173
|
...(matchOffset === undefined ? {} : { offset_chars: matchOffset }),
|
|
174
174
|
};
|
|
175
175
|
}
|
|
@@ -182,14 +182,31 @@ export function unknownWindowId(projection, params) {
|
|
|
182
182
|
const known = projection.windows.map((current) => current.windowId);
|
|
183
183
|
return known.includes(params.window_id) ? undefined : { message: `unknown window_id "${params.window_id}"`, known };
|
|
184
184
|
}
|
|
185
|
-
/**
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
/**
|
|
186
|
+
* Whether one event is inside the selection: its window, its seq bounds, and a half-open
|
|
187
|
+
* [sinceMs, untilMs) window on created_at. A bounded time window drops events with no recorded
|
|
188
|
+
* time or a time that cannot be read.
|
|
189
|
+
*/
|
|
190
|
+
export function inSelection(event, params) {
|
|
191
|
+
if (typeof params.window_id === "string" && params.window_id !== event.windowId)
|
|
192
|
+
return false;
|
|
193
|
+
if (params.after_seq !== undefined && event.seq <= params.after_seq)
|
|
194
|
+
return false;
|
|
195
|
+
if (params.before_seq !== undefined && event.seq >= params.before_seq)
|
|
196
|
+
return false;
|
|
197
|
+
if (params.sinceMs === undefined && params.untilMs === undefined)
|
|
198
|
+
return true;
|
|
199
|
+
if (event.createdAt === undefined)
|
|
200
|
+
return false;
|
|
201
|
+
const at = Date.parse(event.createdAt);
|
|
202
|
+
return !Number.isNaN(at) && (params.sinceMs === undefined || at >= params.sinceMs) && (params.untilMs === undefined || at < params.untilMs);
|
|
203
|
+
}
|
|
204
|
+
/** Without roles or query a call shows the conversation; either one shows the requested events. */
|
|
205
|
+
export function filteredItems(projection, params, conversation) {
|
|
206
|
+
let items = allItems(projection).filter((item) => inSelection(item, params));
|
|
190
207
|
if (params.roles)
|
|
191
208
|
items = items.filter((item) => params.roles.includes(item.role));
|
|
192
|
-
if (!params.roles &&
|
|
209
|
+
if (!params.roles && conversation)
|
|
193
210
|
items = items.filter((item) => (item.role === "user" || item.role === "assistant") && eventDocument(item) !== "");
|
|
194
211
|
return items.sort((a, b) => a.seq - b.seq);
|
|
195
212
|
}
|
|
@@ -1,33 +1,40 @@
|
|
|
1
|
-
/** Stable-anchor paging and
|
|
1
|
+
/** Stable-anchor paging, folding and literal matching. The operation supplies the full-response budget check. */
|
|
2
2
|
import { Type, type Static } from "typebox";
|
|
3
3
|
import { type Outcome } from "../tools/result.js";
|
|
4
|
-
import { type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
import { type HistoryFilter, type HistoryProjection } from "./history.js";
|
|
5
|
+
/** Which end of one selection `limit` is taken from; page items always come back ascending. */
|
|
6
|
+
export type HistoryOrder = "newest" | "oldest";
|
|
7
|
+
/**
|
|
8
|
+
* What one list call selects. `before_seq`/`after_seq` choose a seq range and `since`/`until` a time
|
|
9
|
+
* range; `from` chooses the end `limit` counts from; a `query` keeps only matching events, across
|
|
10
|
+
* every role, with no folded rows.
|
|
11
|
+
*/
|
|
12
|
+
export type HistorySelection = HistoryFilter & {
|
|
13
|
+
from?: HistoryOrder;
|
|
13
14
|
limit?: number;
|
|
15
|
+
query?: string | string[];
|
|
16
|
+
since?: string;
|
|
17
|
+
until?: string;
|
|
14
18
|
max_chars_per_item?: number;
|
|
15
19
|
};
|
|
20
|
+
/** The params to merge into the previous call to continue toward older events. */
|
|
21
|
+
export declare const HistoryOlderSchema: Type.TObject<{
|
|
22
|
+
before_seq: Type.TInteger;
|
|
23
|
+
}>;
|
|
24
|
+
/** The params to merge into the previous call to continue toward newer events. */
|
|
25
|
+
export declare const HistoryNewerSchema: Type.TObject<{
|
|
26
|
+
after_seq: Type.TInteger;
|
|
27
|
+
from: Type.TLiteral<"oldest">;
|
|
28
|
+
}>;
|
|
16
29
|
export declare const HistoryPageSchema: Type.TObject<{
|
|
17
30
|
items: Type.TArray<Type.TUnion<[Type.TObject<{
|
|
18
|
-
tool_name_omitted: Type.TOptional<Type.TBoolean>;
|
|
19
|
-
truncated: Type.TBoolean;
|
|
20
|
-
total_chars: Type.TInteger;
|
|
21
31
|
content: Type.TString;
|
|
32
|
+
truncated: Type.TBoolean;
|
|
22
33
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
23
34
|
tool: Type.TOptional<Type.TString>;
|
|
24
35
|
tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
|
|
25
|
-
output_truncated: Type.TOptional<Type.
|
|
36
|
+
output_truncated: Type.TOptional<Type.TLiteral<true>>;
|
|
26
37
|
full_output_path: Type.TOptional<Type.TString>;
|
|
27
|
-
nested_calls: Type.TOptional<Type.TObject<{
|
|
28
|
-
call_count: Type.TInteger;
|
|
29
|
-
complete: Type.TBoolean;
|
|
30
|
-
}>>;
|
|
31
38
|
seq: Type.TInteger;
|
|
32
39
|
window_id: Type.TString;
|
|
33
40
|
role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
|
|
@@ -38,38 +45,19 @@ export declare const HistoryPageSchema: Type.TObject<{
|
|
|
38
45
|
last_seq: Type.TInteger;
|
|
39
46
|
count: Type.TInteger;
|
|
40
47
|
tools: Type.TRecord<"^.*$", Type.TInteger>;
|
|
41
|
-
omitted_tools: Type.TOptional<Type.TInteger>;
|
|
42
48
|
}>]>>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}>;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
truncated: Type.TBoolean;
|
|
51
|
-
total_chars: Type.TInteger;
|
|
52
|
-
content: Type.TString;
|
|
53
|
-
offset_chars: Type.TOptional<Type.TInteger>;
|
|
54
|
-
tool: Type.TOptional<Type.TString>;
|
|
55
|
-
tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
|
|
56
|
-
output_truncated: Type.TOptional<Type.TBoolean>;
|
|
57
|
-
full_output_path: Type.TOptional<Type.TString>;
|
|
58
|
-
nested_calls: Type.TOptional<Type.TObject<{
|
|
59
|
-
call_count: Type.TInteger;
|
|
60
|
-
complete: Type.TBoolean;
|
|
61
|
-
}>>;
|
|
62
|
-
seq: Type.TInteger;
|
|
63
|
-
window_id: Type.TString;
|
|
64
|
-
role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
|
|
65
|
-
created_at: Type.TUnion<[Type.TString, Type.TNull]>;
|
|
66
|
-
}>>;
|
|
67
|
-
older_before: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
68
|
-
newer_after: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
49
|
+
page_older: Type.TUnion<[Type.TObject<{
|
|
50
|
+
before_seq: Type.TInteger;
|
|
51
|
+
}>, Type.TNull]>;
|
|
52
|
+
page_newer: Type.TUnion<[Type.TObject<{
|
|
53
|
+
after_seq: Type.TInteger;
|
|
54
|
+
from: Type.TLiteral<"oldest">;
|
|
55
|
+
}>, Type.TNull]>;
|
|
69
56
|
}>;
|
|
70
57
|
/** One whole page payload, before it becomes an outcome. */
|
|
71
58
|
export type HistoryPage = Static<typeof HistoryPageSchema>;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Resolve the time bounds once, then filter and fold against the same [sinceMs, untilMs) window.
|
|
61
|
+
* Grow the page in selection order; shorten the first preview only when no full row fits.
|
|
62
|
+
*/
|
|
63
|
+
export declare function selectPage(projection: HistoryProjection, params: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number): Outcome<HistoryPage>;
|