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
|
@@ -12,6 +12,69 @@ const PRESENTATION = `Codex unknown arguments not recorded output nested calls c
|
|
|
12
12
|
FunctionCallOutput display without raw output encrypted content unavailable world_state snapshot patch omitted from
|
|
13
13
|
the text projection not a newly spoken message native structured retained context not newly spoken dialogue`;
|
|
14
14
|
const HISTORY_BASE = '"history_base"';
|
|
15
|
+
const STREAM_HIGH_WATER_MARK = 256 * 1024;
|
|
16
|
+
function isHex(code) {
|
|
17
|
+
return (code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102);
|
|
18
|
+
}
|
|
19
|
+
/** Linear-time one-pass `\uXXXX` decoder: skips non-`\u` backslashes and bounds any trailing run to <= 6 chars. */
|
|
20
|
+
function decodeEscapes(source, final) {
|
|
21
|
+
const len = source.length;
|
|
22
|
+
let pending = "";
|
|
23
|
+
let limit = len;
|
|
24
|
+
if (!final && len > 0) {
|
|
25
|
+
let end = len;
|
|
26
|
+
let hexCount = 0;
|
|
27
|
+
while (end > 0 && hexCount < 3 && isHex(source.charCodeAt(end - 1))) {
|
|
28
|
+
end--;
|
|
29
|
+
hexCount++;
|
|
30
|
+
}
|
|
31
|
+
if (end >= 2 && source.charCodeAt(end - 1) === 117 && source.charCodeAt(end - 2) === 92) {
|
|
32
|
+
let slashStart = end - 2;
|
|
33
|
+
while (slashStart > 0 && source.charCodeAt(slashStart - 1) === 92)
|
|
34
|
+
slashStart--;
|
|
35
|
+
pending = `\\u${source.slice(end, len)}`;
|
|
36
|
+
limit = slashStart;
|
|
37
|
+
}
|
|
38
|
+
else if (source.charCodeAt(len - 1) === 92) {
|
|
39
|
+
let slashStart = len - 1;
|
|
40
|
+
while (slashStart > 0 && source.charCodeAt(slashStart - 1) === 92)
|
|
41
|
+
slashStart--;
|
|
42
|
+
pending = "\\";
|
|
43
|
+
limit = slashStart;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (limit < 6) {
|
|
47
|
+
return { decoded: limit === len ? source : source.slice(0, limit), pending };
|
|
48
|
+
}
|
|
49
|
+
let pos = source.indexOf("\\u");
|
|
50
|
+
if (pos < 0 || pos >= limit) {
|
|
51
|
+
return { decoded: limit === len ? source : source.slice(0, limit), pending };
|
|
52
|
+
}
|
|
53
|
+
let out = "";
|
|
54
|
+
let cursor = 0;
|
|
55
|
+
while (pos >= 0 && pos < limit) {
|
|
56
|
+
if (pos + 6 <= limit
|
|
57
|
+
&& isHex(source.charCodeAt(pos + 2))
|
|
58
|
+
&& isHex(source.charCodeAt(pos + 3))
|
|
59
|
+
&& isHex(source.charCodeAt(pos + 4))
|
|
60
|
+
&& isHex(source.charCodeAt(pos + 5))) {
|
|
61
|
+
let slashStart = pos;
|
|
62
|
+
while (slashStart > cursor && source.charCodeAt(slashStart - 1) === 92)
|
|
63
|
+
slashStart--;
|
|
64
|
+
if (slashStart > cursor)
|
|
65
|
+
out += source.slice(cursor, slashStart);
|
|
66
|
+
out += String.fromCharCode(Number.parseInt(source.slice(pos + 2, pos + 6), 16));
|
|
67
|
+
cursor = pos + 6;
|
|
68
|
+
pos = source.indexOf("\\u", cursor);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
pos = source.indexOf("\\u", pos + 2);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (cursor < limit)
|
|
75
|
+
out += source.slice(cursor, limit);
|
|
76
|
+
return { decoded: out, pending };
|
|
77
|
+
}
|
|
15
78
|
/** Compile literal Unicode case matching once, then keep only per-file token bits and a bounded tail. */
|
|
16
79
|
export function createHistoryPrefilter(queries) {
|
|
17
80
|
let overlap = HISTORY_BASE.length;
|
|
@@ -28,24 +91,18 @@ export function createHistoryPrefilter(queries) {
|
|
|
28
91
|
const decoder = new StringDecoder("utf8");
|
|
29
92
|
const seen = alternatives.map((tokens) => tokens.map(() => false));
|
|
30
93
|
let rawTail = "", normalizedTail = "", pending = "", possible = fallback;
|
|
31
|
-
// Unlike /\\+u(hex{4})/, this cannot backtrack quadratically over a long invalid run.
|
|
32
|
-
const escapes = /\\+(?:u([0-9a-fA-F]{0,4}))?/g;
|
|
33
94
|
const scan = (chunk, final = false) => {
|
|
34
|
-
const raw = rawTail + chunk
|
|
35
|
-
const needsNormalization = pending.length > 0 || chunk.includes("\\u") || chunk.endsWith("\\");
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return "";
|
|
46
|
-
}
|
|
47
|
-
return literal;
|
|
48
|
-
}) : chunk;
|
|
95
|
+
const raw = rawTail + chunk;
|
|
96
|
+
const needsNormalization = pending.length > 0 || chunk.includes("\\u") || (!final && chunk.endsWith("\\"));
|
|
97
|
+
let decoded = chunk;
|
|
98
|
+
if (needsNormalization) {
|
|
99
|
+
const result = decodeEscapes(pending + chunk, final);
|
|
100
|
+
decoded = result.decoded;
|
|
101
|
+
pending = result.pending;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
pending = "";
|
|
105
|
+
}
|
|
49
106
|
const normalized = decoded === chunk && normalizedTail === rawTail ? raw : normalizedTail + decoded;
|
|
50
107
|
if (codex && raw.includes(HISTORY_BASE))
|
|
51
108
|
possible = true;
|
|
@@ -75,7 +132,7 @@ export async function historyFileMayMatch(path, prefilter, codex = false, maxByt
|
|
|
75
132
|
// Plain Pi/Claude files will be read and validated by the strict decoder on a possible
|
|
76
133
|
// hit. Don't drain a potentially huge file just to read it from the beginning again.
|
|
77
134
|
if (!codex)
|
|
78
|
-
return prefilter(createReadStream(path), false, true);
|
|
135
|
+
return prefilter(createReadStream(path, { highWaterMark: STREAM_HIGH_WATER_MARK }), false, true);
|
|
79
136
|
const info = await stat(path);
|
|
80
137
|
if (!info.isFile() || info.size > maxBytes)
|
|
81
138
|
throw new Error("Unavailable Codex transcript: read size limit exceeded or not a regular file");
|
|
@@ -83,7 +140,7 @@ export async function historyFileMayMatch(path, prefilter, codex = false, maxByt
|
|
|
83
140
|
const compressed = path.endsWith(".jsonl.zst");
|
|
84
141
|
if (compressed && typeof zlib.createZstdDecompress !== "function")
|
|
85
142
|
throw new Error("Compressed Codex rollouts require Node >=22.15 (createZstdDecompress)");
|
|
86
|
-
const input = createReadStream(path);
|
|
143
|
+
const input = createReadStream(path, { highWaterMark: STREAM_HIGH_WATER_MARK });
|
|
87
144
|
const consume = async (chunks) => {
|
|
88
145
|
let size = 0;
|
|
89
146
|
async function* bounded() {
|
|
@@ -1,59 +1,36 @@
|
|
|
1
1
|
/** Stable-anchor paging, folding and literal matching. The operation supplies the full-response budget check. */
|
|
2
|
-
import { Type, type Static } from "typebox";
|
|
3
2
|
import { type Outcome } from "../result.js";
|
|
4
|
-
import { type HistoryEvent, type HistoryFilter, type HistoryProjection } from "./history.js";
|
|
5
|
-
|
|
6
|
-
export declare function markMultiPage(page: HistoryPage): HistoryPage;
|
|
7
|
-
export type HistorySelection = HistoryFilter & {
|
|
8
|
-
session?: string;
|
|
3
|
+
import { type HistoryEvent, type HistoryFilter, type HistoryFoldedRow, type HistoryPageItem, type HistoryProjection, type HistoryRole } from "./history.js";
|
|
4
|
+
type TimelineSelection = HistoryFilter & {
|
|
9
5
|
limit?: number;
|
|
6
|
+
};
|
|
7
|
+
export type HistorySelection = TimelineSelection & {
|
|
10
8
|
query?: string[];
|
|
11
9
|
context?: number;
|
|
12
10
|
};
|
|
13
|
-
export declare const HistoryPageSchema: Type.TObject<{
|
|
14
|
-
notice: Type.TOptional<Type.TString>;
|
|
15
|
-
items: Type.TArray<Type.TObject<{
|
|
16
|
-
content: Type.TString;
|
|
17
|
-
truncated: Type.TBoolean;
|
|
18
|
-
offset_chars: Type.TOptional<Type.TInteger>;
|
|
19
|
-
tool: Type.TOptional<Type.TString>;
|
|
20
|
-
tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
|
|
21
|
-
output_truncated: Type.TOptional<Type.TLiteral<true>>;
|
|
22
|
-
full_output_path: Type.TOptional<Type.TString>;
|
|
23
|
-
session: Type.TOptional<Type.TString>;
|
|
24
|
-
folded_before: Type.TOptional<Type.TObject<{
|
|
25
|
-
session: Type.TOptional<Type.TString>;
|
|
26
|
-
first_seq: Type.TInteger;
|
|
27
|
-
last_seq: Type.TInteger;
|
|
28
|
-
count: Type.TInteger;
|
|
29
|
-
tools: Type.TRecord<"^.*$", Type.TInteger>;
|
|
30
|
-
}>>;
|
|
31
|
-
context: Type.TOptional<Type.TLiteral<true>>;
|
|
32
|
-
seq: Type.TInteger;
|
|
33
|
-
role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
|
|
34
|
-
created_at: Type.TUnion<[Type.TString, Type.TNull]>;
|
|
35
|
-
}>>;
|
|
36
|
-
folded_after: Type.TOptional<Type.TObject<{
|
|
37
|
-
session: Type.TOptional<Type.TString>;
|
|
38
|
-
first_seq: Type.TInteger;
|
|
39
|
-
last_seq: Type.TInteger;
|
|
40
|
-
count: Type.TInteger;
|
|
41
|
-
tools: Type.TRecord<"^.*$", Type.TInteger>;
|
|
42
|
-
}>>;
|
|
43
|
-
has_older: Type.TBoolean;
|
|
44
|
-
has_newer: Type.TBoolean;
|
|
45
|
-
}>;
|
|
46
11
|
/** One whole page payload, before it becomes an outcome. */
|
|
47
|
-
export type HistoryPage =
|
|
12
|
+
export type HistoryPage = {
|
|
13
|
+
notice?: string;
|
|
14
|
+
items: HistoryPageItem[];
|
|
15
|
+
folded_after?: HistoryFoldedRow;
|
|
16
|
+
has_older: boolean;
|
|
17
|
+
has_newer: boolean;
|
|
18
|
+
};
|
|
48
19
|
/** A caller's budget rejected even the shortest page; tool limits and refusal copy belong to the caller. */
|
|
49
20
|
export type HistoryPageResult = Outcome<HistoryPage> | {
|
|
50
21
|
ok: false;
|
|
51
|
-
pageTooLarge:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
22
|
+
pageTooLarge: true;
|
|
23
|
+
};
|
|
24
|
+
export declare function selectPage(projection: HistoryProjection, params: TimelineSelection, fits: (page: HistoryPage) => boolean, maxChars: number): HistoryPageResult;
|
|
25
|
+
/** Strict single-pass overview summary: default representative, latest per role, and exact time span. */
|
|
26
|
+
export type ProjectionSummary = {
|
|
27
|
+
event: HistoryEvent | undefined;
|
|
28
|
+
latestByRole: Partial<Record<HistoryRole, HistoryEvent>>;
|
|
29
|
+
minCreatedAt: number | null;
|
|
30
|
+
maxCreatedAt: number | null;
|
|
31
|
+
hasUntimed: boolean;
|
|
55
32
|
};
|
|
56
|
-
export declare function
|
|
33
|
+
export declare function summarizeProjection(projection: HistoryProjection): ProjectionSummary;
|
|
57
34
|
/** One topic per session, after role/time filtering; empty dialogue envelopes are not visible. */
|
|
58
35
|
export declare function sessionRepresentative(projection: HistoryProjection, scoped: HistorySelection): HistoryEvent | undefined;
|
|
59
36
|
/** Keep only the requested end of the globally ordered selection while sessions are released. */
|
|
@@ -61,12 +38,14 @@ export declare class CorpusCollector {
|
|
|
61
38
|
private readonly scoped;
|
|
62
39
|
private readonly candidates;
|
|
63
40
|
private readonly limit;
|
|
41
|
+
private readonly compiledQuery;
|
|
64
42
|
private discarded;
|
|
65
43
|
constructor(scoped: HistorySelection);
|
|
66
44
|
private admit;
|
|
67
|
-
/** Admit
|
|
68
|
-
addRepresentative(session: string,
|
|
69
|
-
/**
|
|
70
|
-
|
|
45
|
+
/** Admit a session's overview representative (pre-selected or picked from a projection). */
|
|
46
|
+
addRepresentative(session: string, source: HistoryEvent | HistoryProjection | undefined): boolean;
|
|
47
|
+
/** Admit every query match from one session; an empty query matches nothing. */
|
|
48
|
+
addMatches(session: string, projection: HistoryProjection): void;
|
|
71
49
|
page(fits: (page: HistoryPage) => boolean, maxChars: number, unvisited?: boolean): HistoryPageResult;
|
|
72
50
|
}
|
|
51
|
+
export {};
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
/** Stable-anchor paging, folding and literal matching. The operation supplies the full-response budget check. */
|
|
2
|
-
import { Type } from "typebox";
|
|
3
2
|
import { success } from "../result.js";
|
|
4
|
-
import { earliestMatchOffsetChars, prefixFit } from "../text-match.js";
|
|
5
|
-
import { eventDocument, filteredItems, matchesFilter, visibleItem,
|
|
6
|
-
const multiPages = new WeakSet();
|
|
7
|
-
export function isMultiPage(page) { return multiPages.has(page); }
|
|
8
|
-
export function markMultiPage(page) {
|
|
9
|
-
multiPages.add(page);
|
|
10
|
-
return page;
|
|
11
|
-
}
|
|
12
|
-
export const HistoryPageSchema = Type.Object({
|
|
13
|
-
notice: Type.Optional(Type.String()),
|
|
14
|
-
items: Type.Array(HistoryPageItemSchema),
|
|
15
|
-
folded_after: Type.Optional(HistoryFoldedRowSchema),
|
|
16
|
-
has_older: Type.Boolean(),
|
|
17
|
-
has_newer: Type.Boolean(),
|
|
18
|
-
}, { additionalProperties: false });
|
|
3
|
+
import { compileSearchQueries, earliestMatchOffsetChars, prefixFit } from "../text-match.js";
|
|
4
|
+
import { eventDocument, eventTimestampMs, filteredItems, matchesFilter, visibleItem, MAX_FOLD_TOOL_NAMES, MAX_FOLD_TOOL_NAME_CHARS } from "./history.js";
|
|
19
5
|
/** Shorten preview text first; omit an oversized tool name rather than invent a partial name. */
|
|
20
6
|
function truncateHistoryItem(item, fits) {
|
|
21
7
|
if (fits(item))
|
|
@@ -34,7 +20,7 @@ function truncateHistoryItem(item, fits) {
|
|
|
34
20
|
return fits(withoutName) ? withoutName : shrinkContent(withoutName);
|
|
35
21
|
}
|
|
36
22
|
/** Summarize one already ordered gap; omitted tool names never change its exact count. */
|
|
37
|
-
function foldedRun(events
|
|
23
|
+
function foldedRun(events) {
|
|
38
24
|
if (events.length === 0)
|
|
39
25
|
return undefined;
|
|
40
26
|
const counts = new Map();
|
|
@@ -47,36 +33,34 @@ function foldedRun(events, session) {
|
|
|
47
33
|
const entries = [...counts].filter(([name]) => name.length <= MAX_FOLD_TOOL_NAME_CHARS).slice(0, MAX_FOLD_TOOL_NAMES);
|
|
48
34
|
// fromEntries preserves __proto__ as an ordinary key without mutating the prototype.
|
|
49
35
|
const tools = Object.fromEntries(entries);
|
|
50
|
-
return {
|
|
36
|
+
return { first_seq: events[0].seq, last_seq: events.at(-1).seq, count: events.length, tools };
|
|
51
37
|
}
|
|
52
38
|
// Tool/thinking-only envelopes are not dialogue, even with explicit roles.
|
|
53
39
|
const visible = (event) => (event.role !== "user" && event.role !== "assistant") || eventDocument(event) !== "";
|
|
54
|
-
function* queryHits(projection, params, session) {
|
|
55
|
-
const {
|
|
40
|
+
function* queryHits(projection, params, patterns, session) {
|
|
41
|
+
const { context } = params;
|
|
56
42
|
const events = filteredItems(projection, context ? {} : params).filter(visible);
|
|
57
43
|
for (const [index, event] of events.entries()) {
|
|
58
44
|
if (context && !matchesFilter(event, params))
|
|
59
45
|
continue;
|
|
60
|
-
const matchOffset = earliestMatchOffsetChars(eventDocument(event),
|
|
46
|
+
const matchOffset = earliestMatchOffsetChars(eventDocument(event), patterns);
|
|
61
47
|
if (matchOffset >= 0)
|
|
62
48
|
yield { event, session, matchOffset, neighbors: context ? { events, index } : undefined };
|
|
63
49
|
}
|
|
64
50
|
}
|
|
65
51
|
function prepareSelection(projection, params) {
|
|
66
|
-
const {
|
|
67
|
-
if (query)
|
|
68
|
-
return { candidates: [...queryHits(projection, params, session)] };
|
|
52
|
+
const { roles } = params;
|
|
69
53
|
const candidates = [];
|
|
70
54
|
let run = [];
|
|
71
55
|
for (const event of filteredItems(projection, params).filter(visible)) {
|
|
72
56
|
if (!roles && (event.role === "tool" || event.role === "context"))
|
|
73
57
|
run.push(event);
|
|
74
58
|
else {
|
|
75
|
-
candidates.push({ event,
|
|
59
|
+
candidates.push({ event, before: foldedRun(run) });
|
|
76
60
|
run = [];
|
|
77
61
|
}
|
|
78
62
|
}
|
|
79
|
-
return { candidates, tail: foldedRun(run
|
|
63
|
+
return { candidates, tail: foldedRun(run) };
|
|
80
64
|
}
|
|
81
65
|
/** Assemble only the admitted interval. Edge folds belong only to a page reaching that edge. */
|
|
82
66
|
function pageData(prepared, start, end, maxChars, preview) {
|
|
@@ -87,17 +71,48 @@ function pageData(prepared, start, end, maxChars, preview) {
|
|
|
87
71
|
const item = preview ?? (candidate.preview ??= { ...visibleItem(candidate.event, maxChars, candidate.matchOffset), ...(candidate.session === undefined ? {} : { session: candidate.session }) });
|
|
88
72
|
items.push(candidate.before && (index > start || start === 0) ? { ...item, folded_before: candidate.before } : item);
|
|
89
73
|
}
|
|
90
|
-
|
|
74
|
+
return {
|
|
91
75
|
items,
|
|
92
76
|
...(end === candidates.length && tail ? { folded_after: tail } : {}),
|
|
93
77
|
has_older: (start > 0 && start < end) || (!!prepared.discarded && !prepared.forward),
|
|
94
78
|
has_newer: (end < candidates.length && start < end) || (!!prepared.discarded && !!prepared.forward),
|
|
95
79
|
};
|
|
96
|
-
return prepared.multi ? markMultiPage(page) : page;
|
|
97
80
|
}
|
|
98
81
|
export function selectPage(projection, params, fits, maxChars) {
|
|
99
82
|
return selectPrepared(prepareSelection(projection, params), params, fits, maxChars);
|
|
100
83
|
}
|
|
84
|
+
export function summarizeProjection(projection) {
|
|
85
|
+
const events = filteredItems(projection, {}).filter(visible);
|
|
86
|
+
let firstUser;
|
|
87
|
+
let lastAssistant;
|
|
88
|
+
const latestByRole = {};
|
|
89
|
+
let minCreatedAt = Infinity;
|
|
90
|
+
let maxCreatedAt = -Infinity;
|
|
91
|
+
let hasUntimed = false;
|
|
92
|
+
for (const event of events) {
|
|
93
|
+
if (firstUser === undefined && event.role === "user")
|
|
94
|
+
firstUser = event;
|
|
95
|
+
if (event.role === "assistant")
|
|
96
|
+
lastAssistant = event;
|
|
97
|
+
latestByRole[event.role] = event;
|
|
98
|
+
const at = eventTimestampMs(event);
|
|
99
|
+
if (Number.isNaN(at))
|
|
100
|
+
hasUntimed = true;
|
|
101
|
+
else {
|
|
102
|
+
if (at < minCreatedAt)
|
|
103
|
+
minCreatedAt = at;
|
|
104
|
+
if (at > maxCreatedAt)
|
|
105
|
+
maxCreatedAt = at;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
event: firstUser ?? lastAssistant ?? events.at(-1),
|
|
110
|
+
latestByRole,
|
|
111
|
+
minCreatedAt: Number.isFinite(minCreatedAt) ? minCreatedAt : null,
|
|
112
|
+
maxCreatedAt: Number.isFinite(maxCreatedAt) ? maxCreatedAt : null,
|
|
113
|
+
hasUntimed,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
101
116
|
/** One topic per session, after role/time filtering; empty dialogue envelopes are not visible. */
|
|
102
117
|
export function sessionRepresentative(projection, scoped) {
|
|
103
118
|
const events = filteredItems(projection, scoped).filter(visible);
|
|
@@ -107,16 +122,13 @@ export function sessionRepresentative(projection, scoped) {
|
|
|
107
122
|
?? events.filter((event) => event.role === "assistant").at(-1)
|
|
108
123
|
?? events.at(-1);
|
|
109
124
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return Number.isNaN(at) ? -Infinity : at;
|
|
113
|
-
}
|
|
114
|
-
const compareCorpus = (a, b) => eventTime(a.event.createdAt) - eventTime(b.event.createdAt) || a.session.localeCompare(b.session) || a.event.seq - b.event.seq;
|
|
125
|
+
const earliestIfUntimed = (at) => Number.isNaN(at) ? -Infinity : at;
|
|
126
|
+
const compareCorpus = (a, b) => earliestIfUntimed(eventTimestampMs(a.event)) - earliestIfUntimed(eventTimestampMs(b.event)) || (a.session ?? "").localeCompare(b.session ?? "") || a.event.seq - b.event.seq;
|
|
115
127
|
/** Fill the remaining budget nearest first. Shared session/seq keys merge overlapping windows. */
|
|
116
128
|
function addContext(page, hits, radius, fits, maxChars) {
|
|
117
129
|
const key = (session, seq) => `${session ?? ""}\0${seq}`;
|
|
118
130
|
const seen = new Set(page.items.map(item => key(item.session, item.seq)));
|
|
119
|
-
const compare = (a, b) => (
|
|
131
|
+
const compare = (a, b) => earliestIfUntimed(Date.parse(a.created_at ?? "")) - earliestIfUntimed(Date.parse(b.created_at ?? "")) || (a.session ?? "").localeCompare(b.session ?? "") || a.seq - b.seq;
|
|
120
132
|
for (let distance = 1; distance <= radius; distance++) {
|
|
121
133
|
let found = false;
|
|
122
134
|
for (const { neighbors, session } of hits) {
|
|
@@ -149,10 +161,12 @@ export class CorpusCollector {
|
|
|
149
161
|
scoped;
|
|
150
162
|
candidates = [];
|
|
151
163
|
limit;
|
|
164
|
+
compiledQuery;
|
|
152
165
|
discarded = false;
|
|
153
166
|
constructor(scoped) {
|
|
154
167
|
this.scoped = scoped;
|
|
155
168
|
this.limit = Math.min(500, Math.max(1, scoped.limit ?? 20));
|
|
169
|
+
this.compiledQuery = scoped.query?.length ? compileSearchQueries(scoped.query) : [];
|
|
156
170
|
}
|
|
157
171
|
admit(candidate) {
|
|
158
172
|
// Upper bound preserves the stable ordering of equal candidates.
|
|
@@ -180,52 +194,53 @@ export class CorpusCollector {
|
|
|
180
194
|
}
|
|
181
195
|
this.candidates.splice(low, 0, candidate);
|
|
182
196
|
}
|
|
183
|
-
/** Admit
|
|
184
|
-
addRepresentative(session,
|
|
197
|
+
/** Admit a session's overview representative (pre-selected or picked from a projection). */
|
|
198
|
+
addRepresentative(session, source) {
|
|
199
|
+
const event = source && "windows" in source ? sessionRepresentative(source, this.scoped) : source;
|
|
185
200
|
if (!event)
|
|
186
201
|
return false;
|
|
187
|
-
this.admit({ session, event });
|
|
202
|
+
this.admit({ session: session || undefined, event });
|
|
188
203
|
return true;
|
|
189
204
|
}
|
|
190
|
-
/**
|
|
191
|
-
|
|
192
|
-
if (this.
|
|
193
|
-
return
|
|
194
|
-
for (const hit of queryHits(projection, this.scoped, session))
|
|
205
|
+
/** Admit every query match from one session; an empty query matches nothing. */
|
|
206
|
+
addMatches(session, projection) {
|
|
207
|
+
if (this.compiledQuery.length === 0)
|
|
208
|
+
return;
|
|
209
|
+
for (const hit of queryHits(projection, this.scoped, this.compiledQuery, session || undefined))
|
|
195
210
|
this.admit(hit);
|
|
196
|
-
return true;
|
|
197
211
|
}
|
|
198
212
|
page(fits, maxChars, unvisited = false) {
|
|
199
|
-
|
|
213
|
+
const result = selectPrepared({ candidates: this.candidates, discarded: this.discarded || unvisited, forward: !!this.scoped.after }, this.scoped, fits, maxChars);
|
|
214
|
+
if (result.ok && this.compiledQuery.length > 0 && this.scoped.context) {
|
|
215
|
+
const count = result.data.items.length;
|
|
216
|
+
const hits = this.scoped.after ? this.candidates.slice(0, count) : this.candidates.slice(this.candidates.length - count);
|
|
217
|
+
addContext(result.data, hits, this.scoped.context, fits, maxChars);
|
|
218
|
+
}
|
|
219
|
+
return result;
|
|
200
220
|
}
|
|
201
221
|
}
|
|
202
222
|
function selectPrepared(prepared, scoped, fits, maxChars) {
|
|
203
223
|
const { candidates } = prepared;
|
|
204
|
-
//
|
|
205
|
-
const newest = scoped.after === undefined;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
224
|
+
// Keep a contiguous interval from the requested end, always presented oldest first.
|
|
225
|
+
const newest = scoped.after === undefined && (scoped.before !== undefined || scoped.since === undefined);
|
|
226
|
+
const start = (count) => newest ? candidates.length - count : 0;
|
|
227
|
+
const pageFor = (count, preview) => pageData(prepared, start(count), start(count) + count, maxChars, preview);
|
|
228
|
+
let count = Math.min(Math.max(1, scoped.limit ?? 20), candidates.length);
|
|
229
|
+
if (count > 0 && !fits(pageFor(count))) {
|
|
230
|
+
let low = 0, high = count - 1;
|
|
231
|
+
while (low < high) {
|
|
232
|
+
const mid = Math.ceil((low + high) / 2);
|
|
233
|
+
if (fits(pageFor(mid)))
|
|
234
|
+
low = mid;
|
|
235
|
+
else
|
|
236
|
+
high = mid - 1;
|
|
216
237
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
candidate.preview = truncateHistoryItem(candidate.preview, (preview) => fits(pageData(prepared, start, end, maxChars, preview)));
|
|
238
|
+
count = Math.max(1, low);
|
|
239
|
+
if (low === 0) {
|
|
240
|
+
const candidate = candidates[start(1)];
|
|
241
|
+
candidate.preview = truncateHistoryItem(candidate.preview, preview => fits(pageFor(1, preview)));
|
|
222
242
|
}
|
|
223
|
-
break;
|
|
224
243
|
}
|
|
225
|
-
const page =
|
|
226
|
-
|
|
227
|
-
return { ok: false, pageTooLarge: { count: page.items.length, multi: prepared.multi === true } };
|
|
228
|
-
if (scoped.context)
|
|
229
|
-
addContext(page, candidates.slice(start, end), scoped.context, fits, maxChars);
|
|
230
|
-
return success(page);
|
|
244
|
+
const page = pageFor(count);
|
|
245
|
+
return fits(page) ? success(page) : { ok: false, pageTooLarge: true };
|
|
231
246
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import { type HistorySession, type HistorySessionData, type HistorySessionRepresentative } from "./corpus.js";
|
|
1
|
+
import { type HistorySession, type HistorySessionData, type HistorySessionRepresentative, type HistorySessionSummary } from "./corpus.js";
|
|
2
2
|
import { type CodexLineageSource } from "./codex-transcript.js";
|
|
3
|
+
export declare const HISTORY_SUMMARY_CACHE_TTL_MS: number;
|
|
3
4
|
/** Internal root selection; the host's home/env seams also keep filesystem tests hermetic. */
|
|
4
5
|
export declare function historySummaryCacheRoot(home?: string, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): string;
|
|
6
|
+
/** Remove expired (>3 days), obsolete-version (e.g. v1), and stale temporary cache files. */
|
|
7
|
+
export declare function pruneHistorySummaryCache(cacheRoot: string, now?: number): Promise<void>;
|
|
5
8
|
export type RepresentativeLoad = (track: (path: string) => Promise<void>) => Promise<{
|
|
6
9
|
data: HistorySessionData;
|
|
7
10
|
lineageSources?: CodexLineageSource[];
|
|
8
11
|
}>;
|
|
12
|
+
/** Read-only check of a warm, validated summary; never decodes on miss. */
|
|
13
|
+
export declare function peekCachedSessionSummary(session: Pick<HistorySession, "harness" | "id">, transcriptPath: string, cacheRoot: string): Promise<HistorySessionSummary | undefined>;
|
|
14
|
+
/** The loader always runs the strict decoder on misses; transcript errors deliberately escape. */
|
|
15
|
+
export declare function cachedSessionSummary(session: Pick<HistorySession, "harness" | "id">, transcriptPath: string, cacheRoot: string, load: RepresentativeLoad): Promise<HistorySessionSummary>;
|
|
9
16
|
/** The loader always runs the strict decoder on misses; transcript errors deliberately escape. */
|
|
10
17
|
export declare function cachedSessionRepresentative(session: Pick<HistorySession, "harness" | "id">, transcriptPath: string, cacheRoot: string, load: RepresentativeLoad): Promise<HistorySessionRepresentative>;
|