notesoup 0.54.2 → 0.55.1
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/dist/plugins/pi/budget.js +1 -1
- package/dist/plugins/pi/marker.d.ts +1 -1
- package/dist/plugins/pi/marker.js +11 -7
- package/dist/plugins/pi/notes/tools.js +5 -1
- package/dist/plugins/pi/render.d.ts +4 -1
- package/dist/plugins/pi/render.js +3 -7
- package/dist/plugins/pi/runtime.js +5 -5
- package/dist/plugins/pi/tool-result.d.ts +4 -2
- package/dist/plugins/pi/tool-result.js +5 -4
- package/dist/src/history/claude.d.ts +1 -1
- package/dist/src/history/claude.js +11 -6
- package/dist/src/history/codex-transcript.d.ts +2 -0
- package/dist/src/history/codex-transcript.js +3 -2
- package/dist/src/history/corpus.d.ts +2 -1
- package/dist/src/history/corpus.js +5 -2
- package/dist/src/history/history.d.ts +1 -1
- package/dist/src/history/history.js +1 -1
- package/dist/src/history/local.d.ts +2 -6
- package/dist/src/history/local.js +34 -2
- package/dist/src/history/query.d.ts +4 -2
- package/dist/src/history/query.js +17 -8
- package/dist/src/tools/history.js +17 -13
- package/dist/src/tools/notes.d.ts +2 -7
- package/dist/src/tools/notes.js +5 -26
- package/dist/test/boot.integration.test.js +24 -0
- package/dist/test/budget-settings.integration.test.js +2 -2
- package/dist/test/claude-history.test.js +4 -6
- package/dist/test/codex-history.test.js +3 -2
- package/dist/test/dependencies.test.js +3 -4
- package/dist/test/dream-tools.test.js +3 -3
- package/dist/test/history-corpus.test.js +238 -14
- package/dist/test/history.integration.test.js +9 -9
- package/dist/test/host-neutral.test.js +7 -9
- package/dist/test/marker.test.js +34 -27
- package/dist/test/notes.integration.test.js +8 -10
- package/dist/test/notes.test.js +9 -7
- package/dist/test/pi-render.test.js +7 -7
- package/dist/test/project-namespace.test.js +4 -4
- package/docs/claude-code-mod.md +1 -1
- package/docs/history-sessions.md +9 -7
- package/docs/skills.md +1 -1
- package/docs/tool-results.md +3 -3
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +68 -47
- package/plugins/claude/skills/memory/SKILL.md +4 -2
- package/plugins/codex/dist/codex/notesoup.js +68 -47
- package/plugins/paseo/OVERVIEW.md +2 -2
- package/plugins/paseo/client/brain-empty-card.tsx +1 -1
- package/plugins/paseo/client/notes-op-card.tsx +1 -1
- package/plugins/paseo/client/notes-op-transformer.ts +16 -1
- package/plugins/paseo/client/paper-palette.ts +18 -18
- package/plugins/paseo/test/fixtures/claude-tool-calls.ts +1 -1
- package/plugins/paseo/test/notes-op.test.ts +4 -4
- package/plugins/paseo/test/paper-palette.test.ts +3 -3
- package/plugins/pi/budget.ts +1 -1
- package/plugins/pi/marker.ts +11 -6
- package/plugins/pi/notes/tools.ts +5 -1
- package/plugins/pi/render.ts +7 -8
- package/plugins/pi/runtime.ts +4 -3
- package/plugins/pi/tool-result.ts +10 -9
- package/skills/memory/SKILL.md +4 -2
- package/src/history/claude.ts +9 -4
- package/src/history/codex-transcript.ts +3 -2
- package/src/history/corpus.ts +9 -3
- package/src/history/history.ts +1 -1
- package/src/history/local.ts +36 -4
- package/src/history/query.ts +17 -6
- package/src/tools/history.ts +13 -12
- package/src/tools/notes.ts +5 -27
|
@@ -105,7 +105,7 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
105
105
|
// An aborted request does not undo the low-budget condition or repeat the toast.
|
|
106
106
|
if (!notifiedWindows.has(windowId)) {
|
|
107
107
|
notifiedWindows.add(windowId);
|
|
108
|
-
ctx.ui.notify("🥣 Brain almost full
|
|
108
|
+
ctx.ui.notify("🥣 Brain almost full", "warning");
|
|
109
109
|
}
|
|
110
110
|
return result({ customType: WARNING_TYPE, content: pendingWarning.content });
|
|
111
111
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
/** Spacing between durable seq breadcrumbs, in projected history seq. */
|
|
3
|
-
export declare const MARKER_INTERVAL =
|
|
3
|
+
export declare const MARKER_INTERVAL = 120;
|
|
4
4
|
/**
|
|
5
5
|
* Stamp the current seq every MARKER_INTERVAL seqs. The marker names the seq it occupies, so a
|
|
6
6
|
* model paging history_list meets a breadcrumb that tells it where it is. Skipped while a reset
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { piSequenceCount } from "../../src/history/pi.js";
|
|
2
|
+
import { BOOT_TYPE, MARKER_TYPE } from "./entries.js";
|
|
2
3
|
import { nextHistorySeq } from "./history.js";
|
|
3
4
|
import { inspectResetTail } from "./reset/artifacts.js";
|
|
4
5
|
import { markerContent } from "./text.js";
|
|
5
6
|
import { currentReset } from "./window.js";
|
|
6
7
|
/** Spacing between durable seq breadcrumbs, in projected history seq. */
|
|
7
|
-
export const MARKER_INTERVAL =
|
|
8
|
-
/** Highest seq already
|
|
8
|
+
export const MARKER_INTERVAL = 120;
|
|
9
|
+
/** Highest seq already anchored by a window boot or marker; 0 before the first. */
|
|
9
10
|
function lastMarkerSeq(ctx) {
|
|
10
11
|
let last = 0;
|
|
12
|
+
let nextSeq = 1;
|
|
11
13
|
for (const entry of ctx.sessionManager.getEntries()) {
|
|
12
|
-
|
|
14
|
+
const count = piSequenceCount(entry);
|
|
15
|
+
if (count === 0)
|
|
13
16
|
continue;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
if (entry.type === "custom_message" && (entry.customType === MARKER_TYPE || entry.customType === BOOT_TYPE)) {
|
|
18
|
+
last = nextSeq;
|
|
19
|
+
}
|
|
20
|
+
nextSeq += count;
|
|
17
21
|
}
|
|
18
22
|
return last;
|
|
19
23
|
}
|
|
@@ -27,7 +27,11 @@ export function registerNotesTools(pi) {
|
|
|
27
27
|
const identity = (ctx) => dreamingIdentity(notesIdentityFromPi(ctx), dreamOf(ctx));
|
|
28
28
|
const toolContext = (ctx) => notesToolContext(identity(ctx), ctx.cwd);
|
|
29
29
|
registerOperation(pi, notesWrite, (params, ctx) => notesWrite.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesWriteRenderers);
|
|
30
|
-
registerOperation(pi, notesUpdate, (params, ctx) =>
|
|
30
|
+
registerOperation(pi, notesUpdate, async (params, ctx) => {
|
|
31
|
+
let diff = "";
|
|
32
|
+
const outcome = await notesUpdate.execute(params, toolContext(ctx), (change) => { diff = renderDiff(change); });
|
|
33
|
+
return diff ? { ...outcome, details: { diff } } : outcome;
|
|
34
|
+
}, NOTES_NAMESPACE, notesUpdateRenderers);
|
|
31
35
|
registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesReadRenderers);
|
|
32
36
|
registerOperation(pi, notesList, (params, ctx) => notesList.execute(params, toolContext(ctx)), NOTES_NAMESPACE);
|
|
33
37
|
registerOperation(pi, notesSearch, (params, ctx) => notesSearch.execute(params, toolContext(ctx)), NOTES_NAMESPACE);
|
|
@@ -15,9 +15,12 @@ export declare const notesWriteRenderers: {
|
|
|
15
15
|
}, theme: Theme, context: CallContext<NotesWriteArgs>): Component;
|
|
16
16
|
};
|
|
17
17
|
export type NotesUpdateArgs = Static<typeof notesUpdateParameters>;
|
|
18
|
+
export type NotesUpdateDetails = {
|
|
19
|
+
diff?: string;
|
|
20
|
+
};
|
|
18
21
|
export declare const notesUpdateRenderers: {
|
|
19
22
|
renderCall(args: NotesUpdateArgs, theme: Theme): Component;
|
|
20
|
-
renderResult(result: AgentToolResult<undefined>, options: {
|
|
23
|
+
renderResult(result: AgentToolResult<NotesUpdateDetails | undefined>, options: {
|
|
21
24
|
expanded: boolean;
|
|
22
25
|
}, theme: Theme, context: CallContext<NotesUpdateArgs>): Component;
|
|
23
26
|
};
|
|
@@ -83,6 +83,7 @@ export const notesUpdateRenderers = {
|
|
|
83
83
|
return errorComponent(theme, error, options.expanded);
|
|
84
84
|
if (!data)
|
|
85
85
|
return receiptFallback(result, theme);
|
|
86
|
+
const diff = result.details?.diff ?? "";
|
|
86
87
|
let head;
|
|
87
88
|
if (context.args?.crumpled === true) {
|
|
88
89
|
head = `✂ crumpled ${theme.strikethrough(theme.fg("dim", data.address))}`;
|
|
@@ -98,18 +99,13 @@ export const notesUpdateRenderers = {
|
|
|
98
99
|
}
|
|
99
100
|
else {
|
|
100
101
|
head = `edited ${addressText(theme, data.address)}`;
|
|
101
|
-
const peek = firstAddedLine(
|
|
102
|
+
const peek = firstAddedLine(diff);
|
|
102
103
|
if (peek !== undefined && peek !== "")
|
|
103
104
|
head += theme.fg("dim", " · ") + theme.fg("toolDiffAdded", `+ ${peek}`);
|
|
104
105
|
}
|
|
105
106
|
if (!options.expanded)
|
|
106
107
|
return new TruncatedText(head, 0, 0);
|
|
107
|
-
|
|
108
|
-
if (data.diff !== "")
|
|
109
|
-
parts.push("", renderDiff(data.diff));
|
|
110
|
-
if (data.change_kind !== "moved" && data.rename_from !== undefined)
|
|
111
|
-
parts.push(theme.fg("dim", `renamed from ${data.rename_from}`));
|
|
112
|
-
return new Text(parts.join("\n"), 0, 0);
|
|
108
|
+
return new Text(diff !== "" ? `${head}\n\n${renderDiff(diff)}` : head, 0, 0);
|
|
113
109
|
},
|
|
114
110
|
};
|
|
115
111
|
export const notesReadRenderers = {
|
|
@@ -78,11 +78,13 @@ export function registerContext(pi, settingsManager) {
|
|
|
78
78
|
ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
-
pi.on("
|
|
82
|
-
notifyCommittedResets(ctx);
|
|
81
|
+
pi.on("before_agent_start", (_event, ctx) => {
|
|
83
82
|
if (enabled)
|
|
84
83
|
maybeSendMarker(pi, ctx);
|
|
85
84
|
});
|
|
85
|
+
pi.on("turn_start", (_event, ctx) => {
|
|
86
|
+
notifyCommittedResets(ctx);
|
|
87
|
+
});
|
|
86
88
|
pi.on("agent_settled", (_event, ctx) => {
|
|
87
89
|
notifyCommittedResets(ctx);
|
|
88
90
|
pendingResetNotices.clear();
|
|
@@ -131,9 +133,7 @@ export function registerContext(pi, settingsManager) {
|
|
|
131
133
|
const windowId = reset?.data.windowId ?? rootWindowId(ctx.sessionManager.getSessionId());
|
|
132
134
|
try {
|
|
133
135
|
if (reset) {
|
|
134
|
-
|
|
135
|
-
throw new Error(`Missing boot for context window ${windowId}`);
|
|
136
|
-
return { messages: isCheckpointBackedReset(ctx, reset) ? event.messages : projectWindow(event.messages, windowId) };
|
|
136
|
+
return { messages: projectWindow(event.messages, windowId) };
|
|
137
137
|
}
|
|
138
138
|
return { messages: projectRootWindow(event.messages, windowId) };
|
|
139
139
|
}
|
|
@@ -20,6 +20,8 @@ export declare const NOTES_NAMESPACE: ToolNamespace;
|
|
|
20
20
|
export declare const DREAM_NAMESPACE: ToolNamespace;
|
|
21
21
|
export declare const HISTORY_NAMESPACE: ToolNamespace;
|
|
22
22
|
/** Optional TUI renderers; without them the host draws its default call line and receipt text. */
|
|
23
|
-
export type OperationRenderers<TParams extends TSchema> = Pick<ToolDefinition<TParams,
|
|
23
|
+
export type OperationRenderers<TParams extends TSchema, TDetails = undefined> = Pick<ToolDefinition<TParams, TDetails>, "renderCall" | "renderResult">;
|
|
24
24
|
/** Register `operation` as a Pi tool; `run` supplies only the host context it needs. */
|
|
25
|
-
export declare function registerOperation<TParams extends TSchema, TData, TRest extends readonly unknown[]>(pi: ExtensionAPI, operation: Operation<TParams, TData, TRest>, run: (params: Static<TParams>, ctx: ExtensionToolContext) => Promise<Outcome<TData
|
|
25
|
+
export declare function registerOperation<TParams extends TSchema, TData, TRest extends readonly unknown[], TDetails = undefined>(pi: ExtensionAPI, operation: Operation<TParams, TData, TRest>, run: (params: Static<TParams>, ctx: ExtensionToolContext) => Promise<Outcome<TData> & {
|
|
26
|
+
details?: TDetails;
|
|
27
|
+
}>, namespace?: ToolNamespace, renderers?: OperationRenderers<TParams, TDetails>, exposure?: ToolExposure): void;
|
|
@@ -8,17 +8,17 @@ export function output(value, details, terminate = false) {
|
|
|
8
8
|
return { content: [{ type: "text", text: JSON.stringify(value) }], details, terminate, ...(refused ? { isError: true } : {}) };
|
|
9
9
|
}
|
|
10
10
|
/** Operation data is schema-derived JSON; only the unresolved generic needs a JsonValue assertion. */
|
|
11
|
-
function piOperationResult(render, outcome) {
|
|
11
|
+
function piOperationResult(render, outcome, details) {
|
|
12
12
|
return {
|
|
13
13
|
content: [{ type: "text", text: render(outcome) }],
|
|
14
14
|
structuredContent: wireResult(outcome),
|
|
15
15
|
isError: !outcome.ok,
|
|
16
|
-
details:
|
|
16
|
+
details: details,
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
export const NOTES_NAMESPACE = { name: "notes", description: "Notes you choose to keep across context windows. See the memory skill." };
|
|
20
20
|
export const DREAM_NAMESPACE = { name: "dream", description: "Consolidate one project's notes: begin, edit with notes_*, forget crumpled notes, end." };
|
|
21
|
-
export const HISTORY_NAMESPACE = { name: "history", description: "
|
|
21
|
+
export const HISTORY_NAMESPACE = { name: "history", description: "Session history (this or other local sessions): history_list to browse/search, history_read to read one event." };
|
|
22
22
|
/** Register `operation` as a Pi tool; `run` supplies only the host context it needs. */
|
|
23
23
|
export function registerOperation(pi, operation, run, namespace, renderers, exposure) {
|
|
24
24
|
pi.registerTool(defineTool({
|
|
@@ -32,7 +32,8 @@ export function registerOperation(pi, operation, run, namespace, renderers, expo
|
|
|
32
32
|
...(exposure ? { exposure } : {}),
|
|
33
33
|
...renderers,
|
|
34
34
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
35
|
-
|
|
35
|
+
const result = await run(params, ctx);
|
|
36
|
+
return piOperationResult(operation.render, result, result.details);
|
|
36
37
|
},
|
|
37
38
|
}));
|
|
38
39
|
}
|
|
@@ -11,6 +11,6 @@ export type ClaudeHistoryProjection = HistoryProjection & {
|
|
|
11
11
|
};
|
|
12
12
|
/** All addresses are allocated on the full first-occurrence log, before branch selection. */
|
|
13
13
|
export declare function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistorySource, "transcriptPath">): ClaudeHistoryProjection;
|
|
14
|
-
/** Offline files have no live append binding
|
|
14
|
+
/** Offline files have no live append binding: prefer non-attachment leaves, then transcript order. */
|
|
15
15
|
export declare function offlineClaudeHead(text: string): string;
|
|
16
16
|
export declare function readClaudeHistory(source: ClaudeHistorySource): Promise<ClaudeHistoryProjection>;
|
|
@@ -291,12 +291,15 @@ export function claudeHistoryFromJsonl(text, source) {
|
|
|
291
291
|
: b.ordinal === undefined ? -1 : a.ordinal - b.ordinal);
|
|
292
292
|
return { ...projectHistory(windows, nextSeq - 1, branchSeqs), missingAncestors: [...missingAncestors], currentWindowOrdinal: "ordinal" in current ? current.ordinal : undefined };
|
|
293
293
|
}
|
|
294
|
-
/** Offline files have no live append binding
|
|
294
|
+
/** Offline files have no live append binding: prefer non-attachment leaves, then transcript order. */
|
|
295
295
|
export function offlineClaudeHead(text) {
|
|
296
296
|
const latest = new Map();
|
|
297
297
|
for (const row of rowsOf(text)) {
|
|
298
|
-
if (MESSAGE_TYPES.has(row.type))
|
|
299
|
-
|
|
298
|
+
if (!MESSAGE_TYPES.has(row.type))
|
|
299
|
+
continue;
|
|
300
|
+
const uuid = requiredString(row.uuid, "uuid");
|
|
301
|
+
latest.delete(uuid);
|
|
302
|
+
latest.set(uuid, row);
|
|
300
303
|
}
|
|
301
304
|
const ancestors = new Set();
|
|
302
305
|
for (const row of latest.values()) {
|
|
@@ -325,9 +328,11 @@ export function offlineClaudeHead(text) {
|
|
|
325
328
|
}
|
|
326
329
|
}
|
|
327
330
|
const leaves = [...latest.keys()].filter((uuid) => !ancestors.has(uuid));
|
|
328
|
-
if (leaves.length
|
|
329
|
-
throw new Error(
|
|
330
|
-
|
|
331
|
+
if (leaves.length === 0)
|
|
332
|
+
throw new Error("Offline Claude transcript has 0 possible heads");
|
|
333
|
+
const nonAttachments = leaves.filter((uuid) => latest.get(uuid).type !== "attachment");
|
|
334
|
+
const candidates = nonAttachments.length ? nonAttachments : leaves;
|
|
335
|
+
return candidates.at(-1);
|
|
331
336
|
}
|
|
332
337
|
export async function readClaudeHistory(source) {
|
|
333
338
|
if (!source || typeof source.transcriptPath !== "string" || !source.transcriptPath || typeof source.sessionId !== "string")
|
|
@@ -29,6 +29,8 @@ export type CodexRecord = {
|
|
|
29
29
|
};
|
|
30
30
|
export declare function nativeObject(value: unknown, field: string): NativeObject;
|
|
31
31
|
export declare function nativeString(value: unknown, field: string): string;
|
|
32
|
+
/** Bounded decoded bytes, also used by the local corpus's pre-projection miss check. */
|
|
33
|
+
export declare function readCodexTranscriptBytes(path: string, remaining?: number): Promise<Buffer>;
|
|
32
34
|
/** Internal shared read: both boot facts and history use exactly this lineage and window owner. */
|
|
33
35
|
export declare function readCodexTranscript(source: CodexTranscriptSource): Promise<{
|
|
34
36
|
state: CodexTranscriptState;
|
|
@@ -189,7 +189,8 @@ async function referencedPath(home, rolloutId) {
|
|
|
189
189
|
throw new Error(`Unavailable Codex lineage: rollout ${rolloutId} has ${matches.length ? "ambiguous native files" : "no local source file"}`);
|
|
190
190
|
return matches[0];
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
/** Bounded decoded bytes, also used by the local corpus's pre-projection miss check. */
|
|
193
|
+
export async function readCodexTranscriptBytes(path, remaining = MAX_BYTES) {
|
|
193
194
|
const info = await stat(path);
|
|
194
195
|
if (!info.isFile() || info.size > remaining)
|
|
195
196
|
throw new Error("Unavailable Codex transcript: read size limit exceeded or not a regular file");
|
|
@@ -215,7 +216,7 @@ export async function readCodexTranscript(source) {
|
|
|
215
216
|
if (segments.length >= MAX_SEGMENTS || seen.has(path))
|
|
216
217
|
throw new Error("Unavailable Codex lineage: cycle or ancestry depth limit exceeded");
|
|
217
218
|
seen.add(path);
|
|
218
|
-
const bytes = await
|
|
219
|
+
const bytes = await readCodexTranscriptBytes(path, remaining);
|
|
219
220
|
remaining -= bytes.length;
|
|
220
221
|
const segment = segmentFromBytes(bytes, cutoff);
|
|
221
222
|
if (segments.length === 0 && segment.meta.id !== source.threadId)
|
|
@@ -10,7 +10,7 @@ export type HistorySession = {
|
|
|
10
10
|
harness: HistoryHarness;
|
|
11
11
|
id: string;
|
|
12
12
|
modifiedAt: number;
|
|
13
|
-
load(): Promise<HistorySessionData>;
|
|
13
|
+
load(queries?: readonly string[]): Promise<HistorySessionData | undefined>;
|
|
14
14
|
};
|
|
15
15
|
export type HistoryCorpus = {
|
|
16
16
|
currentHarness: HistoryHarness;
|
|
@@ -32,4 +32,5 @@ export declare function parseSessionSelector(value: string): Outcome<SessionSele
|
|
|
32
32
|
export declare function matchesSession(session: HistorySession, selector: SessionSelector): boolean;
|
|
33
33
|
export declare function resolveSession(corpus: HistoryCorpus | undefined, selector: SessionSelector): Promise<Outcome<HistorySession>>;
|
|
34
34
|
export declare function loadHistorySession(session: HistorySession): Promise<Outcome<HistorySessionData>>;
|
|
35
|
+
export declare function loadHistorySession(session: HistorySession, queries: readonly string[] | undefined): Promise<Outcome<HistorySessionData | undefined>>;
|
|
35
36
|
export declare function currentHistory(context: HistoryContext): HistoryProjection | Promise<HistoryProjection>;
|
|
@@ -41,9 +41,12 @@ export async function resolveSession(corpus, selector) {
|
|
|
41
41
|
return failure("ambiguous_session", `Session selector is ambiguous: ${matches.slice(0, 5).map(sessionIdentity).join(", ")}${matches.length > 5 ? ` (${matches.length - 5} more)` : ""}. Pass a longer ID or a harness-qualified ID.`);
|
|
42
42
|
return success(matches[0]);
|
|
43
43
|
}
|
|
44
|
-
export async function loadHistorySession(session) {
|
|
44
|
+
export async function loadHistorySession(session, queries) {
|
|
45
45
|
try {
|
|
46
|
-
|
|
46
|
+
const data = await session.load(queries);
|
|
47
|
+
if (data === undefined && !queries?.length)
|
|
48
|
+
throw new Error("Session returned no history");
|
|
49
|
+
return success(data);
|
|
47
50
|
}
|
|
48
51
|
catch (error) {
|
|
49
52
|
return failure("history_unavailable", `Cannot read session ${sessionIdentity(session)}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -91,7 +91,7 @@ export declare function contentText(content: unknown): string;
|
|
|
91
91
|
export declare function historyDocument(event: HistoryEvent): string;
|
|
92
92
|
/** Memoized `historyDocument`: search, preview, and read must agree on the same characters. */
|
|
93
93
|
export declare function eventDocument(event: HistoryEvent): string;
|
|
94
|
-
/** Pair results into call events; consumed result seqs
|
|
94
|
+
/** Pair results into call events; consumed result seqs redirect to their call event on read. */
|
|
95
95
|
export declare function projectHistory(rawWindows: DecodedHistoryWindow[], highestSeq: number, branchSeqs: Set<number>): HistoryProjection;
|
|
96
96
|
/** Summary shared by list, search and read. Full arguments/calls are in the document. */
|
|
97
97
|
export declare const NestedCallSummarySchema: Type.TObject<{
|
|
@@ -73,7 +73,7 @@ function toolEvent(item, result) {
|
|
|
73
73
|
},
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
/** Pair results into call events; consumed result seqs
|
|
76
|
+
/** Pair results into call events; consumed result seqs redirect to their call event on read. */
|
|
77
77
|
export function projectHistory(rawWindows, highestSeq, branchSeqs) {
|
|
78
78
|
// Pair in durable address order, not window presentation order. Unnumbered
|
|
79
79
|
// segments need not have a provable chronological order relative to each other.
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { type HistoryCorpus, type
|
|
1
|
+
import { type HistoryCorpus, type HistorySession } from "./corpus.js";
|
|
2
2
|
export type LocalHistoryRoots = Partial<Record<"pi" | "claude" | "codex", string | null>>;
|
|
3
3
|
export type LocalHistoryOptions = {
|
|
4
|
-
current:
|
|
5
|
-
harness: HistoryHarness;
|
|
6
|
-
id: string;
|
|
7
|
-
load(): Promise<HistorySessionData>;
|
|
8
|
-
};
|
|
4
|
+
current: Pick<HistorySession, "harness" | "id" | "load">;
|
|
9
5
|
/** Undefined uses the harness default; null disables that harness's filesystem discovery. */
|
|
10
6
|
roots?: LocalHistoryRoots;
|
|
11
7
|
home?: string;
|
|
@@ -5,6 +5,7 @@ import { join } from "node:path";
|
|
|
5
5
|
import { piHistoryFromJsonl } from "./pi.js";
|
|
6
6
|
import { claudeHistoryFromJsonl, offlineClaudeHead } from "./claude.js";
|
|
7
7
|
import { readCodexHistory } from "./codex.js";
|
|
8
|
+
import { readCodexTranscriptBytes } from "./codex-transcript.js";
|
|
8
9
|
import { sessionIdentity } from "./corpus.js";
|
|
9
10
|
function rootsFor(options) {
|
|
10
11
|
const env = options.env ?? process.env;
|
|
@@ -36,6 +37,33 @@ async function filesAt(root, depth) {
|
|
|
36
37
|
}
|
|
37
38
|
return paths;
|
|
38
39
|
}
|
|
40
|
+
const PRESENTATION = `Codex unknown arguments not recorded output nested calls complete incomplete terminal ms image audio items null
|
|
41
|
+
copied subagent inference prefix omitted child-local history starts at native ordinal copied model context
|
|
42
|
+
does not prove original parent event addresses compaction boundary replacement_history is an inference checkpoint
|
|
43
|
+
not new conversation events opaque content omitted not recovered plaintext MCP completion without a recorded raw call
|
|
44
|
+
FunctionCallOutput display without raw output encrypted content unavailable world_state snapshot patch omitted from
|
|
45
|
+
the text projection not a newly spoken message native structured retained context not newly spoken dialogue`;
|
|
46
|
+
function escapeRegExp(value) {
|
|
47
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
48
|
+
}
|
|
49
|
+
/** Only prove misses, not hits. Only \\uXXXX can encode a word character; other JSON escapes are control/quote/slash. */
|
|
50
|
+
function mayMatch(text, queries, codex) {
|
|
51
|
+
if (codex && text.includes('"history_base"'))
|
|
52
|
+
return true;
|
|
53
|
+
const unescaped = text.includes("\\u")
|
|
54
|
+
? text.replace(/\\+u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCharCode(Number.parseInt(hex, 16)))
|
|
55
|
+
: text;
|
|
56
|
+
return queries.some((query) => {
|
|
57
|
+
const tokens = query.match(/[\p{L}\p{N}_-]+/gu);
|
|
58
|
+
return tokens === null || tokens.every((token) => {
|
|
59
|
+
const parts = /^\d+ms$/iu.test(token) ? [token.slice(0, -2), "ms"] : [token];
|
|
60
|
+
return parts.every((part) => {
|
|
61
|
+
const literal = new RegExp(escapeRegExp(part), "iu");
|
|
62
|
+
return literal.test(unescaped) || (unescaped !== text && literal.test(text)) || literal.test(PRESENTATION);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
39
67
|
async function localSessions(harness, root) {
|
|
40
68
|
const paths = await filesAt(root, harness === "codex" ? 3 : 1);
|
|
41
69
|
const sessions = [];
|
|
@@ -57,10 +85,14 @@ async function localSessions(harness, root) {
|
|
|
57
85
|
}
|
|
58
86
|
sessions.push({
|
|
59
87
|
harness, id, modifiedAt,
|
|
60
|
-
async load() {
|
|
88
|
+
async load(queries) {
|
|
89
|
+
if (harness === "codex" && !queries?.length)
|
|
90
|
+
return { projection: (await readCodexHistory({ threadId: id, transcriptPath: path })).projection };
|
|
91
|
+
const text = harness === "codex" ? (await readCodexTranscriptBytes(path)).toString("utf8") : await readFile(path, "utf8");
|
|
92
|
+
if (queries?.length && !mayMatch(text, queries, harness === "codex"))
|
|
93
|
+
return undefined;
|
|
61
94
|
if (harness === "codex")
|
|
62
95
|
return { projection: (await readCodexHistory({ threadId: id, transcriptPath: path })).projection };
|
|
63
|
-
const text = await readFile(path, "utf8");
|
|
64
96
|
if (harness === "pi")
|
|
65
97
|
return { projection: piHistoryFromJsonl(text, id) };
|
|
66
98
|
const projection = claudeHistoryFromJsonl(text, { sessionId: id, headUuid: offlineClaudeHead(text) });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Stable-anchor paging, folding and literal matching. The operation supplies the full-response budget check. */
|
|
2
2
|
import { Type, type Static } from "typebox";
|
|
3
3
|
import { type Outcome } from "../tools/result.js";
|
|
4
|
-
import { type HistoryFilter, type HistoryProjection } from "./history.js";
|
|
4
|
+
import { type HistoryEvent, type HistoryFilter, type HistoryProjection } from "./history.js";
|
|
5
5
|
/** Which end of one selection `limit` is taken from; page items always come back ascending. */
|
|
6
6
|
export type HistoryOrder = "newest" | "oldest";
|
|
7
7
|
/**
|
|
@@ -66,7 +66,9 @@ export type HistoryPage = Static<typeof HistoryPageSchema>;
|
|
|
66
66
|
export declare function selectPage(projection: HistoryProjection, params: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number): Outcome<HistoryPage>;
|
|
67
67
|
/** Validate before corpus discovery or I/O: per-session seqs cannot bound a multi-session search. */
|
|
68
68
|
export declare function corpusSelection(params: HistorySelection): Outcome<HistorySelection>;
|
|
69
|
-
/**
|
|
69
|
+
/** One topic per session, after role/time filtering; empty dialogue envelopes are not visible. */
|
|
70
|
+
export declare function sessionRepresentative(projection: HistoryProjection, scoped: HistorySelection): HistoryEvent | undefined;
|
|
71
|
+
/** Merge hits or session representatives, never folds or per-session cursors. Timestamp ties use identity. */
|
|
70
72
|
export declare function selectCorpusPage(sessions: {
|
|
71
73
|
session: string;
|
|
72
74
|
projection: HistoryProjection;
|
|
@@ -144,18 +144,27 @@ export function selectPage(projection, params, fits, maxChars) {
|
|
|
144
144
|
}
|
|
145
145
|
/** Validate before corpus discovery or I/O: per-session seqs cannot bound a multi-session search. */
|
|
146
146
|
export function corpusSelection(params) {
|
|
147
|
-
const scoped = resolveSelection(params);
|
|
148
|
-
if (!scoped.ok)
|
|
149
|
-
return scoped;
|
|
150
|
-
if (scoped.data.query === undefined)
|
|
151
|
-
return failure("missing_query", "Wildcard session search requires a non-empty `query`.");
|
|
152
147
|
if (params.before_seq !== undefined || params.after_seq !== undefined)
|
|
153
148
|
return failure("invalid_bounds", "`before_seq` and `after_seq` are per-session; omit them for wildcard session search.");
|
|
154
|
-
return
|
|
149
|
+
return resolveSelection(params);
|
|
155
150
|
}
|
|
156
|
-
/**
|
|
151
|
+
/** One topic per session, after role/time filtering; empty dialogue envelopes are not visible. */
|
|
152
|
+
export function sessionRepresentative(projection, scoped) {
|
|
153
|
+
const events = filteredItems(projection, scoped, false).filter((event) => (event.role !== "user" && event.role !== "assistant") || eventDocument(event) !== "");
|
|
154
|
+
if (scoped.roles)
|
|
155
|
+
return events.at(-1);
|
|
156
|
+
return events.find((event) => event.role === "user")
|
|
157
|
+
?? events.filter((event) => event.role === "assistant").at(-1)
|
|
158
|
+
?? events.at(-1);
|
|
159
|
+
}
|
|
160
|
+
/** Merge hits or session representatives, never folds or per-session cursors. Timestamp ties use identity. */
|
|
157
161
|
export function selectCorpusPage(sessions, scoped, fits, maxChars) {
|
|
158
|
-
const candidates = sessions.flatMap(({ session, projection }) =>
|
|
162
|
+
const candidates = sessions.flatMap(({ session, projection }) => {
|
|
163
|
+
if (scoped.query !== undefined)
|
|
164
|
+
return prepareSelection(projection, { ...scoped, session }).candidates;
|
|
165
|
+
const event = sessionRepresentative(projection, scoped);
|
|
166
|
+
return event === undefined ? [] : [{ session, event }];
|
|
167
|
+
});
|
|
159
168
|
const time = (event) => event.createdAt === undefined || Number.isNaN(Date.parse(event.createdAt)) ? -Infinity : Date.parse(event.createdAt);
|
|
160
169
|
candidates.sort((a, b) => (time(a.event) - time(b.event) || a.session.localeCompare(b.session) || a.event.seq - b.event.seq));
|
|
161
170
|
return selectPrepared({ candidates, multi: true }, scoped, fits, maxChars);
|
|
@@ -3,7 +3,7 @@ import { Type } from "typebox";
|
|
|
3
3
|
import { HISTORY_PREVIEW_CHARS, MAX_READ_WINDOW_CHARS } from "./output.js";
|
|
4
4
|
import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, success, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
5
5
|
import { historyRoles, searchQuery } from "./schema.js";
|
|
6
|
-
import { HistoryPageSchema, corpusSelection, selectCorpusPage, selectPage } from "../history/query.js";
|
|
6
|
+
import { HistoryPageSchema, corpusSelection, selectCorpusPage, selectPage, sessionRepresentative } from "../history/query.js";
|
|
7
7
|
import { currentHistory, loadHistorySession, matchesSession, parseSessionSelector, resolveSession, sessionIdentity } from "../history/corpus.js";
|
|
8
8
|
import { allItems, eventDocument, nestedCallSummary, toolSummary, HistoryRoleSchema, NestedCallSummarySchema, ToolSummarySchema } from "../history/history.js";
|
|
9
9
|
/** One read: identity, tool summary and a flat document slice. */
|
|
@@ -65,7 +65,7 @@ function renderRead(data) {
|
|
|
65
65
|
}
|
|
66
66
|
const plainText = (text) => text;
|
|
67
67
|
/* ------------------------------------------------------------------ history_list */
|
|
68
|
-
const sessionParameter = Type.Optional(Type.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions
|
|
68
|
+
const sessionParameter = Type.Optional(Type.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions with query or lists recent sessions without it; history_read needs one session." }));
|
|
69
69
|
export const historyListParameters = Type.Object({
|
|
70
70
|
session: sessionParameter,
|
|
71
71
|
query: Type.Optional(searchQuery("(optional) Text, or a list of texts (any match). Empty text/list means no search filter; empty entries are ignored. Searches every role, tool arguments and output included; returns only hits.")),
|
|
@@ -81,7 +81,7 @@ export const historyListParameters = Type.Object({
|
|
|
81
81
|
export const historyList = {
|
|
82
82
|
name: "history_list",
|
|
83
83
|
label: "History list items",
|
|
84
|
-
description: "Browse or search events, a page at a time. Omit session for this session; pass an ID/prefix for another, or *
|
|
84
|
+
description: "Browse or search events, a page at a time. Omit session for this session; pass an ID/prefix for another, or * to browse recent sessions across local harnesses (add query to search). Read one in full with `history_read`.",
|
|
85
85
|
parameters: historyListParameters,
|
|
86
86
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
87
87
|
async execute(params, context, wrapText = plainText) {
|
|
@@ -101,15 +101,22 @@ export const historyList = {
|
|
|
101
101
|
if (corpus === undefined)
|
|
102
102
|
return failure("unknown_session", "This host supplied no cross-session history corpus.");
|
|
103
103
|
const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
|
|
104
|
+
const queries = Array.isArray(scoped.data.query) ? scoped.data.query : undefined;
|
|
105
|
+
if (!queries)
|
|
106
|
+
sessions.sort((a, b) => (scoped.data.from === "oldest" ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
|
|
104
107
|
const loaded = [];
|
|
105
108
|
const notices = [];
|
|
106
109
|
for (const session of sessions) {
|
|
107
|
-
const result = await loadHistorySession(session);
|
|
108
|
-
if (!result.ok)
|
|
109
|
-
|
|
110
|
+
const result = await loadHistorySession(session, queries);
|
|
111
|
+
if (!result.ok || !result.data)
|
|
112
|
+
continue;
|
|
113
|
+
if (!queries && !sessionRepresentative(result.data.projection, scoped.data))
|
|
114
|
+
continue;
|
|
110
115
|
loaded.push({ session: sessionIdentity(session), projection: result.data.projection });
|
|
111
116
|
if (result.data.notice)
|
|
112
117
|
notices.push(`session ${sessionIdentity(session)}: ${result.data.notice}`);
|
|
118
|
+
if (!queries && loaded.length >= Math.max(1, params.limit ?? 20))
|
|
119
|
+
break;
|
|
113
120
|
}
|
|
114
121
|
const notice = notices.length ? { notice: notices.join("") } : {};
|
|
115
122
|
const result = selectCorpusPage(loaded, scoped.data, (page) => fits({ ...page, ...notice }), maxChars);
|
|
@@ -155,10 +162,9 @@ export const historyRead = {
|
|
|
155
162
|
projection = loaded.data.projection;
|
|
156
163
|
identity = { session: sessionIdentity(target.data), ...(loaded.data.notice === undefined ? {} : { notice: loaded.data.notice }) };
|
|
157
164
|
}
|
|
158
|
-
const item = allItems(projection).find((event) => event.seq === params.seq);
|
|
159
165
|
// Address checks run in one order: past the end of the file, off this branch, then
|
|
160
|
-
//
|
|
161
|
-
if (
|
|
166
|
+
// resolved through any tool-result pairing to its call event.
|
|
167
|
+
if (params.seq > projection.highestSeq) {
|
|
162
168
|
return failure("unknown_seq", `There is no seq ${params.seq}; this session runs from seq 1 to ${projection.highestSeq}.`);
|
|
163
169
|
}
|
|
164
170
|
if (!projection.branchSeqs.has(params.seq)) {
|
|
@@ -166,11 +172,9 @@ export const historyRead = {
|
|
|
166
172
|
return failure("unconfirmed_seq", `Seq ${params.seq} is outside the confirmed selected history; it may be on another branch or beyond an unresolved ancestry gap.`);
|
|
167
173
|
return failure("not_on_branch", `Seq ${params.seq} is on another branch of this session; it can't be read from here.`);
|
|
168
174
|
}
|
|
175
|
+
const targetSeq = projection.pairedResults.get(params.seq) ?? params.seq;
|
|
176
|
+
const item = allItems(projection).find((event) => event.seq === targetSeq);
|
|
169
177
|
if (item === undefined) {
|
|
170
|
-
const callSeq = projection.pairedResults.get(params.seq);
|
|
171
|
-
if (callSeq !== undefined) {
|
|
172
|
-
return failure("not_an_event", `Seq ${params.seq} is a tool result, shown together with its call; read seq ${callSeq} instead.`);
|
|
173
|
-
}
|
|
174
178
|
return failure("unknown_seq", `Seq ${params.seq} holds nothing to read.`);
|
|
175
179
|
}
|
|
176
180
|
const document = eventDocument(item);
|
|
@@ -49,7 +49,6 @@ export declare const NotesWriteDataSchema: Type.TObject<{
|
|
|
49
49
|
export type NotesWriteData = Static<typeof NotesWriteDataSchema>;
|
|
50
50
|
export declare const NotesUpdateDataSchema: Type.TObject<{
|
|
51
51
|
change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
|
|
52
|
-
diff: Type.TString;
|
|
53
52
|
rename_from: Type.TOptional<Type.TString>;
|
|
54
53
|
project_root: Type.TOptional<Type.TString>;
|
|
55
54
|
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
@@ -174,9 +173,6 @@ export declare const notesUpdateParameters: Type.TObject<{
|
|
|
174
173
|
rename_to: Type.TOptional<Type.TString>;
|
|
175
174
|
cwd: Type.TOptional<Type.TString>;
|
|
176
175
|
}>;
|
|
177
|
-
declare function renderUpdate(result: Outcome<NotesUpdateData>): string;
|
|
178
|
-
/** A shortened diff still says so in the receipt's own text, on both surfaces. */
|
|
179
|
-
export declare const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
|
|
180
176
|
export declare const notesUpdate: {
|
|
181
177
|
readonly name: "notes_update";
|
|
182
178
|
readonly label: "Notes update";
|
|
@@ -195,7 +191,6 @@ export declare const notesUpdate: {
|
|
|
195
191
|
}>;
|
|
196
192
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
197
193
|
change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
|
|
198
|
-
diff: Type.TString;
|
|
199
194
|
rename_from: Type.TOptional<Type.TString>;
|
|
200
195
|
project_root: Type.TOptional<Type.TString>;
|
|
201
196
|
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
@@ -209,8 +204,8 @@ export declare const notesUpdate: {
|
|
|
209
204
|
code: Type.TString;
|
|
210
205
|
}>]>;
|
|
211
206
|
readonly executionMode: "sequential";
|
|
212
|
-
readonly execute: (params: Static<typeof notesUpdateParameters>, context: NotesToolContext,
|
|
213
|
-
readonly render:
|
|
207
|
+
readonly execute: (params: Static<typeof notesUpdateParameters>, context: NotesToolContext, onChange?: (change: NoteChange) => void) => Promise<Outcome<NotesUpdateData>>;
|
|
208
|
+
readonly render: (result: Outcome<NotesUpdateData>) => string;
|
|
214
209
|
};
|
|
215
210
|
export declare const notesReadParameters: Type.TObject<{
|
|
216
211
|
cwd: Type.TOptional<Type.TString>;
|