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