notesoup 0.61.0 → 0.63.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 +24 -5
- package/dist/plugins/claude/src/text.d.ts +7 -0
- package/dist/plugins/claude/src/text.js +12 -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 +4 -1
- package/dist/plugins/pi/budget.js +35 -8
- package/dist/plugins/pi/entries.d.ts +2 -0
- package/dist/plugins/pi/entries.js +2 -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/artifacts.d.ts +1 -1
- package/dist/plugins/pi/reset/artifacts.js +4 -4
- package/dist/plugins/pi/reset/lifecycle.d.ts +9 -2
- package/dist/plugins/pi/reset/lifecycle.js +109 -31
- package/dist/plugins/pi/runtime.js +104 -63
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +25 -3
- package/dist/plugins/pi/window.js +219 -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 +7 -3
- package/dist/src/budget/text.js +24 -15
- 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 +2 -2
- 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 +394 -56
- 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 +156 -15
- package/dist/test/budget-settings.integration.test.js +4 -4
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +199 -16
- package/dist/test/claude-validation.test.js +69 -2
- 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 +68 -3
- package/dist/test/helpers/extension.js +74 -5
- 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/model-facing-text.test.js +13 -3
- 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 +12 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +7 -7
- 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/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 +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 +1108 -539
- package/plugins/claude/hooks/register.ts +202 -62
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/notesoup-guide/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +24 -5
- package/plugins/claude/src/text.ts +14 -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 +31 -8
- package/plugins/pi/entries.ts +2 -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/artifacts.ts +4 -3
- package/plugins/pi/reset/lifecycle.ts +125 -32
- package/plugins/pi/runtime.ts +98 -62
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +210 -10
- package/skills/dream/SKILL.md +1 -1
- package/skills/notesoup-guide/SKILL.md +92 -0
- package/src/boot/render.ts +18 -15
- package/src/boot/text.ts +23 -19
- package/src/budget/text.ts +27 -15
- 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 +2 -2
- 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
|
@@ -1,32 +1,45 @@
|
|
|
1
|
-
/** Host-neutral history operations:
|
|
1
|
+
/** Host-neutral history operations: bounded plain-text output. */
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import { HISTORY_PREVIEW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
3
|
+
import { HISTORY_PREVIEW_CHARS, HISTORY_READ_WINDOW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
4
4
|
import { failure, success } from "../result.js";
|
|
5
|
-
import {
|
|
6
|
-
import { historyRoles, searchQuery } from "./schema.js";
|
|
5
|
+
import { fitsText, readTextWindow, renderOutcome, renderTextWindow, TextWindowRequestSchema } from "./result.js";
|
|
6
|
+
import { historyRoles, parseIsoTimestamp, searchQuery } from "./schema.js";
|
|
7
|
+
import { localIso } from "../notes/frontmatter.js";
|
|
7
8
|
import { InvalidQueryError, searchQueries } from "../text-match.js";
|
|
8
|
-
import {
|
|
9
|
-
import { currentHistory, loadHistoryRepresentative, loadHistorySession, matchesSession, parseSessionSelector, resolveSession, sessionIdentity } from "../history/corpus.js";
|
|
10
|
-
import { allItems, eventDocument, nestedCallSummary, toolSummary
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
import { CorpusCollector, selectPage } from "../history/query.js";
|
|
10
|
+
import { currentHistory, loadHistoryRepresentative, loadHistorySession, loadHistorySummary, matchesSession, parseSessionSelector, resolveSession, resolveSummaryForSelection, sessionIdentity } from "../history/corpus.js";
|
|
11
|
+
import { allItems, eventDocument, nestedCallSummary, toolSummary } from "../history/history.js";
|
|
12
|
+
const WILDCARD_CONCURRENCY = 12;
|
|
13
|
+
async function loadOverviewSession(session, scoped) {
|
|
14
|
+
if (session.loadSummary) {
|
|
15
|
+
const summary = await loadHistorySummary(session);
|
|
16
|
+
if (!summary.ok)
|
|
17
|
+
return undefined;
|
|
18
|
+
const resolved = resolveSummaryForSelection(summary.data, scoped);
|
|
19
|
+
if (resolved.kind === "empty")
|
|
20
|
+
return undefined;
|
|
21
|
+
if (resolved.kind === "hit")
|
|
22
|
+
return { event: resolved.event, notice: resolved.notice };
|
|
23
|
+
if (summary.data.loaded)
|
|
24
|
+
return summary.data.loaded;
|
|
25
|
+
}
|
|
26
|
+
else if (!scoped.roles && !scoped.after && !scoped.before && session.loadRepresentative) {
|
|
27
|
+
const rep = await loadHistoryRepresentative(session);
|
|
28
|
+
return rep.ok ? rep.data : undefined;
|
|
29
|
+
}
|
|
30
|
+
const loaded = await loadHistorySession(session);
|
|
31
|
+
return loaded.ok ? loaded.data : undefined;
|
|
32
|
+
}
|
|
22
33
|
/* ------------------------------------------------------------------ rendering */
|
|
23
34
|
function header(item) {
|
|
24
|
-
|
|
35
|
+
const atMs = item.created_at ? Date.parse(item.created_at) : NaN;
|
|
36
|
+
const at = Number.isFinite(atMs) ? localIso(atMs) : undefined;
|
|
37
|
+
return [item.session === undefined ? undefined : `session ${item.session}`, `seq ${item.seq}`, item.role, ...(at === undefined ? [] : [at])].filter(Boolean).join(" | ");
|
|
25
38
|
}
|
|
26
39
|
function toolHeader(item) {
|
|
27
40
|
if (item.role !== "tool")
|
|
28
41
|
return undefined;
|
|
29
|
-
const parts = [`tool ${item.tool}
|
|
42
|
+
const parts = [...(item.tool ? [`tool ${item.tool}`] : []), `status ${item.tool_status}`];
|
|
30
43
|
if (item.output_truncated)
|
|
31
44
|
parts.push(`output truncated${item.full_output_path ? `, full text at ${item.full_output_path}` : ""}`);
|
|
32
45
|
if (item.nested_calls) {
|
|
@@ -36,91 +49,185 @@ function toolHeader(item) {
|
|
|
36
49
|
}
|
|
37
50
|
function renderPageItem(item) {
|
|
38
51
|
const tool = toolHeader(item);
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
lines.push(item.content);
|
|
52
|
+
const offset = (item.offset_chars ?? 0) > 0 ? ` | offset_chars ${item.offset_chars}` : "";
|
|
53
|
+
// The session banner already names the session above its rows; per-row identity stays local.
|
|
54
|
+
const lines = [header({ seq: item.seq, role: item.role, created_at: item.created_at }) + offset + (item.context ? " | search context" : ""), ...(tool ? [tool] : [])];
|
|
55
|
+
lines.push(item.truncated ? (item.content ? `${item.content} [truncated]` : "[truncated]") : item.content);
|
|
43
56
|
return lines.join("\n");
|
|
44
57
|
}
|
|
45
|
-
function renderFoldedRow(row) {
|
|
58
|
+
function renderFoldedRow(row, session) {
|
|
46
59
|
const tools = Object.entries(row.tools).map(([name, count]) => `${name} ${count}`).join(", ");
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
return `${row.session === undefined ? "" : `session ${row.session} | `}seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}${expand}`;
|
|
60
|
+
const expand = JSON.stringify({ session, after: row.first_seq - 1, before: row.last_seq + 1, roles: ["tool", "context"] });
|
|
61
|
+
return `seqs ${row.first_seq}-${row.last_seq} | folded ${row.count} events${tools ? ` | ${tools}` : ""}\n\t→ expand: ${expand}`;
|
|
50
62
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const body = [...page.items.flatMap((item) => [...(item.folded_before ? [renderFoldedRow(item.folded_before)] : []), renderPageItem(item)]), ...(page.folded_after ? [renderFoldedRow(page.folded_after)] : [])].join("\n\n");
|
|
56
|
-
if (isMultiPage(page)) {
|
|
57
|
-
const directions = [page.has_older && "older", page.has_newer && "newer"].filter(Boolean).join("|");
|
|
58
|
-
return (page.notice ?? "") + body + (directions ? `\n\n→ more ${directions} results: narrow with time bounds (after/before), query, roles or the session pattern` : "");
|
|
59
|
-
}
|
|
60
|
-
const hits = page.items.filter(item => !item.context);
|
|
61
|
-
const first = hits[0];
|
|
62
|
-
const last = hits.at(-1);
|
|
63
|
+
const sessionBanner = (session) => session === undefined ? "" : `=== session ${session} ===\n`;
|
|
64
|
+
const EMPTY_PAGE = "No events match these filters.";
|
|
65
|
+
function renderTimelinePage(page) {
|
|
66
|
+
const { session } = page.paging;
|
|
67
|
+
const body = [...page.items.flatMap((item) => [...(item.folded_before ? [renderFoldedRow(item.folded_before, session)] : []), renderPageItem(item)]), ...(page.folded_after ? [renderFoldedRow(page.folded_after, session)] : [])].join("\n\n");
|
|
63
68
|
const cursors = [
|
|
64
|
-
page.has_older ? `→ older: ${JSON.stringify({
|
|
65
|
-
page.has_newer ? `→ newer: ${JSON.stringify({
|
|
66
|
-
].filter(
|
|
67
|
-
return (page.notice ?? "") + (cursors.length
|
|
69
|
+
page.has_older ? `→ older: ${JSON.stringify({ ...page.paging, before: page.items[0].seq })}` : "",
|
|
70
|
+
page.has_newer ? `→ newer: ${JSON.stringify({ ...page.paging, after: page.items.at(-1).seq })}` : "",
|
|
71
|
+
].filter(Boolean);
|
|
72
|
+
return (page.notice ?? "") + sessionBanner(session) + (body || EMPTY_PAGE) + (cursors.length ? `\n\n${cursors.join(" | ")}` : "");
|
|
73
|
+
}
|
|
74
|
+
function renderCollectionPage(page, narrow) {
|
|
75
|
+
const sessions = new Map(page.items.filter(item => !item.context).map(item => [item.session, []]));
|
|
76
|
+
for (const item of page.items)
|
|
77
|
+
sessions.get(item.session).push(item);
|
|
78
|
+
const body = [...sessions].map(([session, items]) => sessionBanner(session) + items.sort((a, b) => a.seq - b.seq).map(renderPageItem).join("\n\n")).join("\n\n");
|
|
79
|
+
const directions = [page.has_older && "older", page.has_newer && "newer"].filter(Boolean).join("|");
|
|
80
|
+
return (page.notice ?? "") + (body || sessionBanner(page.session) + EMPTY_PAGE) + (directions ? `\n\n→ more ${directions} results: ${narrow}` : "");
|
|
68
81
|
}
|
|
82
|
+
const renderOverviewPage = (page) => renderCollectionPage(page, "narrow with since/until, roles or the session pattern");
|
|
83
|
+
const renderSearchPage = (page) => renderCollectionPage(page, "narrow with since/until, query, roles or the session pattern");
|
|
69
84
|
function renderRead(data) {
|
|
70
85
|
const tool = toolHeader(data);
|
|
71
|
-
const neighborhood =
|
|
86
|
+
const neighborhood = `→ history_list: ${JSON.stringify({ session: data.session, after: Math.max(0, data.seq - 10), before: data.seq + 10 })}`;
|
|
72
87
|
return (data.notice ?? "") + [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
|
|
73
88
|
}
|
|
74
89
|
const plainText = (text) => text;
|
|
75
90
|
/** Translate query budget facts into this tool's bounded refusal; successful pages are unchanged. */
|
|
76
|
-
function pageOutcome(result) {
|
|
91
|
+
function pageOutcome(result, narrow) {
|
|
77
92
|
if (!("pageTooLarge" in result))
|
|
78
93
|
return result;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
94
|
+
return failure("page_too_large", `These events exceed the ${TOOL_OUTPUT_LIMIT} limit; ${narrow}, or use history_read for one event.`);
|
|
95
|
+
}
|
|
96
|
+
async function loadNamedSession(context, selector) {
|
|
97
|
+
if (!("corpus" in context))
|
|
98
|
+
return failure("unknown_session", "Other sessions are unavailable here.");
|
|
99
|
+
const target = await resolveSession(context.corpus, selector);
|
|
100
|
+
if (!target.ok)
|
|
101
|
+
return target;
|
|
102
|
+
const loaded = await loadHistorySession(target.data);
|
|
103
|
+
return loaded.ok ? success({ ...loaded.data, session: sessionIdentity(target.data) }) : loaded;
|
|
104
|
+
}
|
|
105
|
+
async function loadTimeline(context, session, tool) {
|
|
106
|
+
if (session === undefined)
|
|
107
|
+
return success({ projection: await currentHistory(context) });
|
|
108
|
+
const selector = parseSessionSelector(session);
|
|
109
|
+
if (!selector.ok)
|
|
110
|
+
return selector;
|
|
111
|
+
if (selector.data.wildcard)
|
|
112
|
+
return failure("invalid_session", `${tool} needs one session ID or prefix. Use history_list or history_search for wildcards.`);
|
|
113
|
+
return loadNamedSession(context, selector.data);
|
|
82
114
|
}
|
|
83
115
|
/* ------------------------------------------------------------------ history_list */
|
|
84
|
-
const
|
|
116
|
+
const sessionParameter = (description) => Type.Optional(Type.String({ minLength: 1, description }));
|
|
117
|
+
const limitParameter = (description) => Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description }));
|
|
118
|
+
const previewParameter = Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "Maximum characters per preview." }));
|
|
119
|
+
const seqBound = (description) => Type.Optional(Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description }));
|
|
120
|
+
const timeBound = (description) => Type.Optional(Type.String({ description: `${description} ISO 8601 (local time if no offset).` }));
|
|
121
|
+
function parseTimeBounds(params) {
|
|
122
|
+
const since = params.since === undefined ? undefined : parseIsoTimestamp(params.since);
|
|
123
|
+
const until = params.until === undefined ? undefined : parseIsoTimestamp(params.until);
|
|
124
|
+
if (params.since !== undefined && since === undefined)
|
|
125
|
+
return failure("invalid_bounds", `since must be an ISO 8601 time; got ${JSON.stringify(params.since)}.`);
|
|
126
|
+
if (params.until !== undefined && until === undefined)
|
|
127
|
+
return failure("invalid_bounds", `until must be an ISO 8601 time; got ${JSON.stringify(params.until)}.`);
|
|
128
|
+
return success({ since, until });
|
|
129
|
+
}
|
|
85
130
|
export const historyListParameters = Type.Object({
|
|
86
|
-
session:
|
|
131
|
+
session: sessionParameter("Session ID, prefix, or wildcard (e.g. `*`, `pi:*`) for one event per session. Omit for current session."),
|
|
132
|
+
roles: historyRoles(true),
|
|
133
|
+
after: seqBound("Exclusive seq; page forward (0 starts at the beginning)."),
|
|
134
|
+
before: seqBound("Exclusive seq; without `after`, takes newest events."),
|
|
135
|
+
since: timeBound("Exclusive start time; oldest first."),
|
|
136
|
+
until: timeBound("Exclusive end time; without `since`, newest first."),
|
|
137
|
+
limit: limitParameter("Events or sessions per page."),
|
|
138
|
+
max_chars_per_item: previewParameter,
|
|
139
|
+
}, { additionalProperties: false });
|
|
140
|
+
export const historyList = {
|
|
141
|
+
name: "history_list",
|
|
142
|
+
label: "Browse history",
|
|
143
|
+
description: "Browse one session's timeline (oldest to newest), or pass a wildcard `session` to overview matching sessions.",
|
|
144
|
+
parameters: historyListParameters,
|
|
145
|
+
async execute(params, context, wrapText = plainText) {
|
|
146
|
+
const { after, before, roles, limit, max_chars_per_item } = params;
|
|
147
|
+
const bounds = parseTimeBounds(params);
|
|
148
|
+
if (!bounds.ok)
|
|
149
|
+
return bounds;
|
|
150
|
+
const { since, until } = bounds.data;
|
|
151
|
+
const selector = params.session === undefined ? undefined : parseSessionSelector(params.session);
|
|
152
|
+
if (selector && !selector.ok)
|
|
153
|
+
return selector;
|
|
154
|
+
if (selector?.ok && selector.data.wildcard) {
|
|
155
|
+
if (after !== undefined || before !== undefined) {
|
|
156
|
+
return failure("invalid_bounds", "after and before are seq numbers for a single session; use since and until with wildcard sessions.");
|
|
157
|
+
}
|
|
158
|
+
const wild = selector.data;
|
|
159
|
+
if (!("corpus" in context))
|
|
160
|
+
return failure("unknown_session", "Other sessions are unavailable here.");
|
|
161
|
+
const scoped = {
|
|
162
|
+
after: since === undefined ? undefined : { at: since },
|
|
163
|
+
before: until === undefined ? undefined : { at: until },
|
|
164
|
+
roles,
|
|
165
|
+
limit,
|
|
166
|
+
};
|
|
167
|
+
const sessions = (await context.corpus.sessions(wild.harness)).filter((s) => matchesSession(s, wild));
|
|
168
|
+
sessions.sort((a, b) => (since !== undefined ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
|
|
169
|
+
const targetCount = Math.min(500, Math.max(1, limit ?? 20));
|
|
170
|
+
const collector = new CorpusCollector(scoped);
|
|
171
|
+
const notices = [];
|
|
172
|
+
let qualifying = 0, offset = 0;
|
|
173
|
+
while (offset < sessions.length && qualifying < targetCount) {
|
|
174
|
+
const batchSize = Math.min(WILDCARD_CONCURRENCY, targetCount - qualifying, sessions.length - offset);
|
|
175
|
+
const batch = sessions.slice(offset, offset + batchSize);
|
|
176
|
+
const loadedBatch = await Promise.all(batch.map((s) => loadOverviewSession(s, scoped)));
|
|
177
|
+
for (let i = 0; i < batch.length; i++) {
|
|
178
|
+
const s = batch[i];
|
|
179
|
+
const item = loadedBatch[i];
|
|
180
|
+
if (!item)
|
|
181
|
+
continue;
|
|
182
|
+
const added = collector.addRepresentative(sessionIdentity(s), item.projection ?? item.event);
|
|
183
|
+
if (!added)
|
|
184
|
+
continue;
|
|
185
|
+
qualifying++;
|
|
186
|
+
if (item.notice)
|
|
187
|
+
notices.push(`session ${sessionIdentity(s)}: ${item.notice}`);
|
|
188
|
+
}
|
|
189
|
+
offset += batch.length;
|
|
190
|
+
}
|
|
191
|
+
const unvisited = offset < sessions.length;
|
|
192
|
+
const decorateOverview = (page) => ({ ...page, ...(notices.length ? { notice: notices.join("") } : {}) });
|
|
193
|
+
const overview = pageOutcome(collector.page((page) => fitsText(wrapText(renderOverviewPage(decorateOverview(page)))), max_chars_per_item ?? HISTORY_PREVIEW_CHARS, unvisited), "narrow with since/until, roles or the session pattern");
|
|
194
|
+
return overview.ok ? success(decorateOverview(overview.data)) : overview;
|
|
195
|
+
}
|
|
196
|
+
const loaded = await loadTimeline(context, params.session, "history_list");
|
|
197
|
+
if (!loaded.ok)
|
|
198
|
+
return loaded;
|
|
199
|
+
const { projection, session, notice } = loaded.data;
|
|
200
|
+
const paging = { session, roles, since: params.since, until: params.until, limit, max_chars_per_item };
|
|
201
|
+
const decorate = (page) => ({ ...page, paging, ...(notice === undefined ? {} : { notice }) });
|
|
202
|
+
const result = pageOutcome(selectPage(projection, {
|
|
203
|
+
roles, limit,
|
|
204
|
+
after: after === undefined ? undefined : { seq: after },
|
|
205
|
+
before: before === undefined ? undefined : { seq: before },
|
|
206
|
+
since, until,
|
|
207
|
+
}, page => fitsText(wrapText(renderTimelinePage(decorate(page)))), max_chars_per_item ?? HISTORY_PREVIEW_CHARS), "narrow with after/before, since/until or specify roles");
|
|
208
|
+
return result.ok ? success(decorate(result.data)) : result;
|
|
209
|
+
},
|
|
210
|
+
render: (result) => renderOutcome(result, (page) => "paging" in page ? renderTimelinePage(page) : renderOverviewPage(page)),
|
|
211
|
+
};
|
|
212
|
+
/* ------------------------------------------------------------------ history_search */
|
|
213
|
+
export const historySearchParameters = Type.Object({
|
|
214
|
+
session: sessionParameter("Session ID, prefix, or wildcard (e.g. `*`, `pi:*`). Omit for current session."),
|
|
215
|
+
query: searchQuery("Case-insensitive literal text, or a list (any match)."),
|
|
216
|
+
since: timeBound("Exclusive start time; oldest matches first."),
|
|
217
|
+
until: timeBound("Exclusive end time; without `since`, newest matches first."),
|
|
87
218
|
roles: historyRoles(),
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
context: Type.Optional(Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description: "Neighboring events on each side of a hit in its own session; requires a query." })),
|
|
92
|
-
limit: Type.Optional(Type.Integer({ minimum: 1, maximum: 500, description: "How many events or hits per page; folds and search context don't count." })),
|
|
93
|
-
max_chars_per_item: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much of each entry to show." })),
|
|
219
|
+
context: Type.Optional(Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER, description: "Neighboring events shown on each side of a hit." })),
|
|
220
|
+
limit: limitParameter("Hits per page."),
|
|
221
|
+
max_chars_per_item: previewParameter,
|
|
94
222
|
}, { additionalProperties: false });
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
return
|
|
99
|
-
|
|
100
|
-
const seq = Number(value);
|
|
101
|
-
if (Number.isSafeInteger(seq) && seq >= 0)
|
|
102
|
-
return success({ seq });
|
|
103
|
-
}
|
|
104
|
-
else if (typeof value === "string") {
|
|
105
|
-
const match = ISO_8601.exec(value);
|
|
106
|
-
const at = match ? Date.parse(match[1] ? value : `${value}Z`) : NaN;
|
|
107
|
-
if (!Number.isNaN(at) && new Date(value.slice(0, 10)).toISOString().startsWith(value.slice(0, 10)))
|
|
108
|
-
return success({ at });
|
|
109
|
-
}
|
|
110
|
-
return failure("invalid_bounds", `\`${name}\` must be a non-negative integer seq or an ISO 8601 time; got ${JSON.stringify(value)}.`);
|
|
111
|
-
}
|
|
112
|
-
function parseSelection(params) {
|
|
113
|
-
const after = parseBound("after", params.after);
|
|
114
|
-
if (!after.ok)
|
|
115
|
-
return after;
|
|
116
|
-
const before = parseBound("before", params.before);
|
|
117
|
-
if (!before.ok)
|
|
118
|
-
return before;
|
|
223
|
+
function searchSelection(params) {
|
|
224
|
+
const bounds = parseTimeBounds(params);
|
|
225
|
+
if (!bounds.ok)
|
|
226
|
+
return bounds;
|
|
227
|
+
const { since, until } = bounds.data;
|
|
119
228
|
try {
|
|
120
229
|
const query = searchQueries(params.query);
|
|
121
|
-
|
|
122
|
-
return failure("invalid_params", "`context` requires a non-empty `query`.");
|
|
123
|
-
return success({ after: after.data, before: before.data, query: query.length ? query : undefined, roles: params.roles, context: params.context, limit: params.limit });
|
|
230
|
+
return success({ after: since === undefined ? undefined : { at: since }, before: until === undefined ? undefined : { at: until }, query, roles: params.roles, context: params.context, limit: params.limit });
|
|
124
231
|
}
|
|
125
232
|
catch (error) {
|
|
126
233
|
if (error instanceof InvalidQueryError)
|
|
@@ -128,99 +235,86 @@ function parseSelection(params) {
|
|
|
128
235
|
throw error;
|
|
129
236
|
}
|
|
130
237
|
}
|
|
131
|
-
export const
|
|
132
|
-
name: "
|
|
133
|
-
label: "
|
|
134
|
-
description: "
|
|
135
|
-
parameters:
|
|
136
|
-
outputSchema: resultSchema(HistoryPageSchema),
|
|
238
|
+
export const historySearch = {
|
|
239
|
+
name: "history_search",
|
|
240
|
+
label: "Search history",
|
|
241
|
+
description: "Search passages by literal text in one or more sessions, including tool arguments and output.",
|
|
242
|
+
parameters: historySearchParameters,
|
|
137
243
|
async execute(params, context, wrapText = plainText) {
|
|
138
|
-
const selection =
|
|
244
|
+
const selection = searchSelection(params);
|
|
139
245
|
if (!selection.ok)
|
|
140
246
|
return selection;
|
|
141
247
|
const scoped = selection.data;
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
const
|
|
248
|
+
const { after, before, query } = scoped;
|
|
249
|
+
const collector = new CorpusCollector(scoped);
|
|
250
|
+
const notices = [];
|
|
251
|
+
let session;
|
|
145
252
|
if (params.session === undefined)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
253
|
+
collector.addMatches("", await currentHistory(context));
|
|
254
|
+
else {
|
|
255
|
+
const selector = parseSessionSelector(params.session);
|
|
256
|
+
if (!selector.ok)
|
|
257
|
+
return selector;
|
|
258
|
+
const corpus = "corpus" in context ? context.corpus : undefined;
|
|
259
|
+
if (!selector.data.wildcard) {
|
|
260
|
+
const loaded = await loadNamedSession(context, selector.data);
|
|
261
|
+
if (!loaded.ok)
|
|
262
|
+
return loaded;
|
|
263
|
+
session = loaded.data.session;
|
|
264
|
+
collector.addMatches(session, loaded.data.projection);
|
|
265
|
+
if (loaded.data.notice)
|
|
266
|
+
notices.push(loaded.data.notice);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
if (!corpus)
|
|
270
|
+
return failure("unknown_session", "Other sessions are unavailable here.");
|
|
271
|
+
if (query && query.length > 0) {
|
|
272
|
+
const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
|
|
273
|
+
const hasTimeBounds = after !== undefined || before !== undefined;
|
|
274
|
+
const noticesByIndex = new Array(sessions.length);
|
|
275
|
+
let next = 0;
|
|
276
|
+
const workers = Math.min(WILDCARD_CONCURRENCY, sessions.length);
|
|
277
|
+
await Promise.all(Array.from({ length: workers }, async () => {
|
|
278
|
+
while (next < sessions.length) {
|
|
279
|
+
const index = next++;
|
|
280
|
+
const session = sessions[index];
|
|
281
|
+
if (hasTimeBounds && session.peekSummary) {
|
|
282
|
+
const summary = await session.peekSummary();
|
|
283
|
+
if (summary && resolveSummaryForSelection(summary, scoped).kind === "empty")
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
const result = await loadHistorySession(session, query);
|
|
287
|
+
if (!result.ok || !result.data)
|
|
288
|
+
continue;
|
|
289
|
+
collector.addMatches(sessionIdentity(session), result.data.projection);
|
|
290
|
+
if (result.data.notice)
|
|
291
|
+
noticesByIndex[index] = `session ${sessionIdentity(session)}: ${result.data.notice}`;
|
|
292
|
+
}
|
|
293
|
+
}));
|
|
294
|
+
for (const entry of noticesByIndex)
|
|
295
|
+
if (entry)
|
|
296
|
+
notices.push(entry);
|
|
178
297
|
}
|
|
179
298
|
}
|
|
180
|
-
const notice = notices.length ? { notice: notices.join("") } : {};
|
|
181
|
-
const result = pageOutcome(collector.page((page) => fits(markMultiPage({ ...page, ...notice })), maxChars, unvisited));
|
|
182
|
-
return result.ok ? success(markMultiPage({ ...result.data, ...notice })) : result;
|
|
183
299
|
}
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const loaded = await loadHistorySession(target.data);
|
|
188
|
-
if (!loaded.ok)
|
|
189
|
-
return loaded;
|
|
190
|
-
const notice = loaded.data.notice === undefined ? {} : { notice: loaded.data.notice };
|
|
191
|
-
const result = pageOutcome(selectPage(loaded.data.projection, { ...scoped, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars));
|
|
192
|
-
return result.ok ? success({ ...result.data, ...notice }) : result;
|
|
300
|
+
const decorate = (page) => ({ ...page, ...(session === undefined ? {} : { session }), ...(notices.length ? { notice: notices.join("") } : {}) });
|
|
301
|
+
const result = pageOutcome(collector.page(page => fitsText(wrapText(renderSearchPage(decorate(page)))), params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS), "narrow with since/until, query, roles or the session pattern");
|
|
302
|
+
return result.ok ? success(decorate(result.data)) : result;
|
|
193
303
|
},
|
|
194
|
-
render: (result) => renderOutcome(result,
|
|
304
|
+
render: (result) => renderOutcome(result, renderSearchPage),
|
|
195
305
|
};
|
|
196
306
|
/* ------------------------------------------------------------------ history_read */
|
|
197
|
-
export const historyReadParameters = Type.Object({ session:
|
|
307
|
+
export const historyReadParameters = Type.Object({ session: sessionParameter("Session ID or prefix. Omit for current session."), seq: Type.Integer({ minimum: 1, description: "Event seq to read." }), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
198
308
|
export const historyRead = {
|
|
199
309
|
name: "history_read",
|
|
200
|
-
label: "
|
|
201
|
-
description: "
|
|
310
|
+
label: "Read history event",
|
|
311
|
+
description: "Read one history event, including tool arguments, output, and nested calls.",
|
|
202
312
|
parameters: historyReadParameters,
|
|
203
|
-
outputSchema: resultSchema(HistoryReadDataSchema),
|
|
204
313
|
async execute(params, context, wrapText = plainText) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
else {
|
|
210
|
-
const selector = parseSessionSelector(params.session);
|
|
211
|
-
if (!selector.ok)
|
|
212
|
-
return selector;
|
|
213
|
-
if (selector.data.wildcard)
|
|
214
|
-
return failure("invalid_session", "`history_read` reads one session; pass a specific `session` ID, not a wildcard.");
|
|
215
|
-
const target = await resolveSession("corpus" in context ? context.corpus : undefined, selector.data);
|
|
216
|
-
if (!target.ok)
|
|
217
|
-
return target;
|
|
218
|
-
const loaded = await loadHistorySession(target.data);
|
|
219
|
-
if (!loaded.ok)
|
|
220
|
-
return loaded;
|
|
221
|
-
projection = loaded.data.projection;
|
|
222
|
-
identity = { session: sessionIdentity(target.data), ...(loaded.data.notice === undefined ? {} : { notice: loaded.data.notice }) };
|
|
223
|
-
}
|
|
314
|
+
const loaded = await loadTimeline(context, params.session, "history_read");
|
|
315
|
+
if (!loaded.ok)
|
|
316
|
+
return loaded;
|
|
317
|
+
const { projection, ...identity } = loaded.data;
|
|
224
318
|
// Address checks run in one order: past the end of the file, off this branch, then
|
|
225
319
|
// resolved through any tool-result pairing to its call event.
|
|
226
320
|
if (params.seq > projection.highestSeq) {
|
|
@@ -241,7 +335,7 @@ export const historyRead = {
|
|
|
241
335
|
if (typeof params.offset_chars === "number" && params.offset_chars > totalChars) {
|
|
242
336
|
return failure("invalid_offset", `This event ends at char ${totalChars}; offset_chars ${params.offset_chars} is past the last word.`);
|
|
243
337
|
}
|
|
244
|
-
return readTextWindow(document, params.offset_chars, params.max_chars, (window) => ({
|
|
338
|
+
return readTextWindow(document, params.offset_chars, params.max_chars ?? HISTORY_READ_WINDOW_CHARS, (window) => ({
|
|
245
339
|
...identity,
|
|
246
340
|
seq: item.seq,
|
|
247
341
|
role: item.role,
|