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
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
2
|
|
|
3
3
|
const LIGHT_PAPER = {
|
|
4
|
-
background: "#
|
|
5
|
-
edge: "#
|
|
6
|
-
tape: "rgba(
|
|
7
|
-
tapeEdge: "rgba(
|
|
8
|
-
ink: "#
|
|
9
|
-
inkMuted: "#
|
|
10
|
-
added: "#
|
|
11
|
-
removed: "#
|
|
12
|
-
crumpled: "#
|
|
4
|
+
background: "#faf6eb",
|
|
5
|
+
edge: "#dcd0b4",
|
|
6
|
+
tape: "rgba(224, 206, 148, 0.62)",
|
|
7
|
+
tapeEdge: "rgba(165, 145, 86, 0.16)",
|
|
8
|
+
ink: "#2c281e",
|
|
9
|
+
inkMuted: "#7d735d",
|
|
10
|
+
added: "#2f743e",
|
|
11
|
+
removed: "#b3463b",
|
|
12
|
+
crumpled: "#f1ead8",
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export type PaperPalette = typeof LIGHT_PAPER;
|
|
16
16
|
|
|
17
17
|
const DARK_PAPER: PaperPalette = {
|
|
18
|
-
background: "#
|
|
19
|
-
edge: "#
|
|
20
|
-
tape: "rgba(
|
|
21
|
-
tapeEdge: "rgba(
|
|
22
|
-
ink: "#
|
|
23
|
-
inkMuted: "#
|
|
24
|
-
added: "#
|
|
25
|
-
removed: "#
|
|
26
|
-
crumpled: "#
|
|
18
|
+
background: "#26231d",
|
|
19
|
+
edge: "#463f31",
|
|
20
|
+
tape: "rgba(182, 160, 104, 0.38)",
|
|
21
|
+
tapeEdge: "rgba(218, 195, 134, 0.16)",
|
|
22
|
+
ink: "#ece5d5",
|
|
23
|
+
inkMuted: "#a89e86",
|
|
24
|
+
added: "#8cc494",
|
|
25
|
+
removed: "#e29488",
|
|
26
|
+
crumpled: "#1e1b16",
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
/** Paseo theme colors are hex (#RGB, #RRGGBB or #RRGGBBAA). */
|
|
@@ -40,7 +40,7 @@ export const claudeUpdateCompleted = {
|
|
|
40
40
|
detail: {
|
|
41
41
|
type: "unknown",
|
|
42
42
|
input: { address: "a.md", edits: [{ oldText: "old", newText: "new" }] },
|
|
43
|
-
output: { output: "updated a.md (project pi-context)
|
|
43
|
+
output: { output: "updated a.md (project pi-context)" },
|
|
44
44
|
},
|
|
45
45
|
} as const;
|
|
46
46
|
|
|
@@ -35,10 +35,10 @@ test("write and moved update project the entire input and delivered diff", () =>
|
|
|
35
35
|
input: { address: "a.md", content: body }, output: { content: [{ type: "text", text: "created a.md" }] },
|
|
36
36
|
} });
|
|
37
37
|
assert.equal(notesOpSchema.parse(write!.items[0]!.data).preview, body);
|
|
38
|
-
const diff = "+
|
|
38
|
+
const diff = "+1 new\n".repeat(2000);
|
|
39
39
|
const update = transform({ name: "notes_update", detail: { type: "unknown",
|
|
40
40
|
input: { address: "a.md", rename_to: "b.md" },
|
|
41
|
-
output: { content: [{ type: "text", text:
|
|
41
|
+
output: { content: [{ type: "text", text: "moved a.md -> b.md" }], details: { diff } },
|
|
42
42
|
} });
|
|
43
43
|
assert.deepEqual(notesOpSchema.parse(update!.items[0]!.data), {
|
|
44
44
|
op: "update", address: "b.md", renamedFrom: "a.md", status: "completed", diff,
|
|
@@ -110,14 +110,14 @@ test("non-notes tools, unknown shapes and missing addresses stay untouched", ()
|
|
|
110
110
|
assert.equal(notesOpTransformer.transform({ item: { type: "user_message", text: "hi" } as never }), undefined);
|
|
111
111
|
});
|
|
112
112
|
|
|
113
|
-
test("Claude completed calls use the adapter's output text for read, write preview and update diff", () => {
|
|
113
|
+
test("Claude completed calls use the adapter's output text for read, write preview and input.edits for update diff", () => {
|
|
114
114
|
const read = notesOpSchema.parse(transform(claudeReadCompleted)!.items[0]!.data);
|
|
115
115
|
assert.deepEqual(read, { op: "read", address: "@self/foo.md", status: "completed", text: "body line one\nbody line two" });
|
|
116
116
|
assert.deepEqual(notesOpSchema.parse(transform(claudeWriteCompleted)!.items[0]!.data), {
|
|
117
117
|
op: "write", address: "a.md", status: "completed", preview: "the new body",
|
|
118
118
|
});
|
|
119
119
|
assert.deepEqual(notesOpSchema.parse(transform(claudeUpdateCompleted)!.items[0]!.data), {
|
|
120
|
-
op: "update", address: "a.md", status: "completed", diff: "-
|
|
120
|
+
op: "update", address: "a.md", status: "completed", diff: "- old\n+ new",
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
123
|
|
|
@@ -30,8 +30,8 @@ test("paper follows the host theme and preserves the light palette when switchin
|
|
|
30
30
|
const light = theme("#ffffff", "#18181b");
|
|
31
31
|
const dark = theme("#18181b", "#fafafa");
|
|
32
32
|
const paper = paperPalette(light);
|
|
33
|
-
assert.equal(paper.background, "#
|
|
34
|
-
assert.equal(paper.ink, "#
|
|
33
|
+
assert.equal(paper.background, "#faf6eb");
|
|
34
|
+
assert.equal(paper.ink, "#2c281e");
|
|
35
35
|
assert.ok(luminance(paperPalette(dark).background) < 0.05);
|
|
36
36
|
assert.notDeepEqual(paperPalette(dark), paper);
|
|
37
37
|
assert.deepEqual(paperPalette(light), paper);
|
|
@@ -41,7 +41,7 @@ test("host hex shorthand and alpha colors select the same dark paper", () => {
|
|
|
41
41
|
const paper = paperPalette(theme("#000000", "#ffffff"));
|
|
42
42
|
assert.deepEqual(paperPalette(theme("#000", "#fff")), paper);
|
|
43
43
|
assert.deepEqual(paperPalette(theme("#000000ff", "#ffffffff")), paper);
|
|
44
|
-
assert.equal(paperPalette(theme("#fff", "#000")).background, "#
|
|
44
|
+
assert.equal(paperPalette(theme("#fff", "#000")).background, "#faf6eb");
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
test("dark text, muted labels, additions and errors remain readable on normal and crumpled paper", () => {
|
package/plugins/pi/budget.ts
CHANGED
|
@@ -104,7 +104,7 @@ export function registerBudget(
|
|
|
104
104
|
// An aborted request does not undo the low-budget condition or repeat the toast.
|
|
105
105
|
if (!notifiedWindows.has(windowId)) {
|
|
106
106
|
notifiedWindows.add(windowId);
|
|
107
|
-
ctx.ui.notify("🥣 Brain almost full
|
|
107
|
+
ctx.ui.notify("🥣 Brain almost full", "warning");
|
|
108
108
|
}
|
|
109
109
|
return result({ customType: WARNING_TYPE, content: pendingWarning.content });
|
|
110
110
|
}
|
package/plugins/pi/marker.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import {
|
|
2
|
+
import { piSequenceCount } from "../../src/history/pi.js";
|
|
3
|
+
import { BOOT_TYPE, MARKER_TYPE } from "./entries.js";
|
|
3
4
|
import { nextHistorySeq } from "./history.js";
|
|
4
5
|
import { inspectResetTail } from "./reset/artifacts.js";
|
|
5
6
|
import { markerContent } from "./text.js";
|
|
6
7
|
import { currentReset } from "./window.js";
|
|
7
8
|
|
|
8
9
|
/** Spacing between durable seq breadcrumbs, in projected history seq. */
|
|
9
|
-
export const MARKER_INTERVAL =
|
|
10
|
+
export const MARKER_INTERVAL = 120;
|
|
10
11
|
|
|
11
|
-
/** Highest seq already
|
|
12
|
+
/** Highest seq already anchored by a window boot or marker; 0 before the first. */
|
|
12
13
|
function lastMarkerSeq(ctx: ExtensionContext): number {
|
|
13
14
|
let last = 0;
|
|
15
|
+
let nextSeq = 1;
|
|
14
16
|
for (const entry of ctx.sessionManager.getEntries()) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (
|
|
17
|
+
const count = piSequenceCount(entry);
|
|
18
|
+
if (count === 0) continue;
|
|
19
|
+
if (entry.type === "custom_message" && (entry.customType === MARKER_TYPE || entry.customType === BOOT_TYPE)) {
|
|
20
|
+
last = nextSeq;
|
|
21
|
+
}
|
|
22
|
+
nextSeq += count;
|
|
18
23
|
}
|
|
19
24
|
return last;
|
|
20
25
|
}
|
|
@@ -28,7 +28,11 @@ export function registerNotesTools(pi: ExtensionAPI) {
|
|
|
28
28
|
const identity = (ctx: ExtensionContext) => dreamingIdentity(notesIdentityFromPi(ctx), dreamOf(ctx));
|
|
29
29
|
const toolContext = (ctx: ExtensionContext) => notesToolContext(identity(ctx), ctx.cwd);
|
|
30
30
|
registerOperation(pi, notesWrite, (params, ctx) => notesWrite.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesWriteRenderers);
|
|
31
|
-
registerOperation(pi, notesUpdate, (params, ctx) =>
|
|
31
|
+
registerOperation(pi, notesUpdate, async (params, ctx) => {
|
|
32
|
+
let diff = "";
|
|
33
|
+
const outcome = await notesUpdate.execute(params, toolContext(ctx), (change) => { diff = renderDiff(change); });
|
|
34
|
+
return diff ? { ...outcome, details: { diff } } : outcome;
|
|
35
|
+
}, NOTES_NAMESPACE, notesUpdateRenderers);
|
|
32
36
|
registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesReadRenderers);
|
|
33
37
|
registerOperation(pi, notesList, (params, ctx) => notesList.execute(params, toolContext(ctx)), NOTES_NAMESPACE);
|
|
34
38
|
registerOperation(pi, notesSearch, (params, ctx) => notesSearch.execute(params, toolContext(ctx)), NOTES_NAMESPACE);
|
package/plugins/pi/render.ts
CHANGED
|
@@ -14,7 +14,7 @@ const EXPANDED_LINE_CAP = 80;
|
|
|
14
14
|
type WireError = { error: string; code: string };
|
|
15
15
|
|
|
16
16
|
/** structuredContent is wireResult(outcome): the data itself, or {error, code}. Old sessions may lack it. */
|
|
17
|
-
function wireOf<T>(result: AgentToolResult<
|
|
17
|
+
function wireOf<T>(result: AgentToolResult<unknown>): { data?: T; error?: WireError } {
|
|
18
18
|
const sc = result.structuredContent;
|
|
19
19
|
if (sc !== null && typeof sc === "object" && !Array.isArray(sc)) {
|
|
20
20
|
const obj = sc as Record<string, unknown>;
|
|
@@ -25,7 +25,7 @@ function wireOf<T>(result: AgentToolResult<undefined>): { data?: T; error?: Wire
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/** Results without a structured payload (resumed old sessions) fall back to the receipt's first line. */
|
|
28
|
-
function receiptFallback(result: AgentToolResult<
|
|
28
|
+
function receiptFallback(result: AgentToolResult<unknown>, theme: Theme): Component {
|
|
29
29
|
const text = result.content.find((c) => c.type === "text")?.text ?? "";
|
|
30
30
|
return new TruncatedText(theme.fg("dim", text.split("\n")[0] ?? ""), 0, 0);
|
|
31
31
|
}
|
|
@@ -77,6 +77,7 @@ export const notesWriteRenderers = {
|
|
|
77
77
|
};
|
|
78
78
|
|
|
79
79
|
export type NotesUpdateArgs = Static<typeof notesUpdateParameters>;
|
|
80
|
+
export type NotesUpdateDetails = { diff?: string };
|
|
80
81
|
export const notesUpdateRenderers = {
|
|
81
82
|
renderCall(args: NotesUpdateArgs, theme: Theme): Component {
|
|
82
83
|
let suffix = "";
|
|
@@ -85,10 +86,11 @@ export const notesUpdateRenderers = {
|
|
|
85
86
|
if (typeof args.rename_to === "string" && args.rename_to !== "") suffix += ` → ${args.rename_to}`;
|
|
86
87
|
return callLine(theme, "notes_update", args.address, suffix);
|
|
87
88
|
},
|
|
88
|
-
renderResult(result: AgentToolResult<undefined>, options: { expanded: boolean }, theme: Theme, context: CallContext<NotesUpdateArgs>): Component {
|
|
89
|
+
renderResult(result: AgentToolResult<NotesUpdateDetails | undefined>, options: { expanded: boolean }, theme: Theme, context: CallContext<NotesUpdateArgs>): Component {
|
|
89
90
|
const { data, error } = wireOf<NotesUpdateData>(result);
|
|
90
91
|
if (error) return errorComponent(theme, error, options.expanded);
|
|
91
92
|
if (!data) return receiptFallback(result, theme);
|
|
93
|
+
const diff = result.details?.diff ?? "";
|
|
92
94
|
let head: string;
|
|
93
95
|
if (context.args?.crumpled === true) {
|
|
94
96
|
head = `✂ crumpled ${theme.strikethrough(theme.fg("dim", data.address))}`;
|
|
@@ -100,14 +102,11 @@ export const notesUpdateRenderers = {
|
|
|
100
102
|
head = theme.fg("dim", "unchanged ") + addressText(theme, data.address);
|
|
101
103
|
} else {
|
|
102
104
|
head = `edited ${addressText(theme, data.address)}`;
|
|
103
|
-
const peek = firstAddedLine(
|
|
105
|
+
const peek = firstAddedLine(diff);
|
|
104
106
|
if (peek !== undefined && peek !== "") head += theme.fg("dim", " · ") + theme.fg("toolDiffAdded", `+ ${peek}`);
|
|
105
107
|
}
|
|
106
108
|
if (!options.expanded) return new TruncatedText(head, 0, 0);
|
|
107
|
-
|
|
108
|
-
if (data.diff !== "") parts.push("", renderDiff(data.diff));
|
|
109
|
-
if (data.change_kind !== "moved" && data.rename_from !== undefined) parts.push(theme.fg("dim", `renamed from ${data.rename_from}`));
|
|
110
|
-
return new Text(parts.join("\n"), 0, 0);
|
|
109
|
+
return new Text(diff !== "" ? `${head}\n\n${renderDiff(diff)}` : head, 0, 0);
|
|
111
110
|
},
|
|
112
111
|
};
|
|
113
112
|
|
package/plugins/pi/runtime.ts
CHANGED
|
@@ -77,9 +77,11 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
77
77
|
if (markerResetOrigin(marker) === "forced") ctx.ui.notify("🥣 Brain forcibly emptied: overflow", "warning");
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
+
pi.on("before_agent_start", (_event, ctx) => {
|
|
81
|
+
if (enabled) maybeSendMarker(pi, ctx);
|
|
82
|
+
});
|
|
80
83
|
pi.on("turn_start", (_event, ctx) => {
|
|
81
84
|
notifyCommittedResets(ctx);
|
|
82
|
-
if (enabled) maybeSendMarker(pi, ctx);
|
|
83
85
|
});
|
|
84
86
|
pi.on("agent_settled", (_event, ctx) => {
|
|
85
87
|
notifyCommittedResets(ctx);
|
|
@@ -127,8 +129,7 @@ export function registerContext(pi: ExtensionAPI, settingsManager?: SettingsMana
|
|
|
127
129
|
const windowId = reset?.data.windowId ?? rootWindowId(ctx.sessionManager.getSessionId());
|
|
128
130
|
try {
|
|
129
131
|
if (reset) {
|
|
130
|
-
|
|
131
|
-
return { messages: isCheckpointBackedReset(ctx, reset) ? event.messages : projectWindow(event.messages, windowId) };
|
|
132
|
+
return { messages: projectWindow(event.messages, windowId) };
|
|
132
133
|
}
|
|
133
134
|
return { messages: projectRootWindow(event.messages, windowId) };
|
|
134
135
|
} catch (error) {
|
|
@@ -13,33 +13,33 @@ export function output(value: unknown, details?: unknown, terminate = false) {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
/** Operation data is schema-derived JSON; only the unresolved generic needs a JsonValue assertion. */
|
|
16
|
-
function piOperationResult<TData>(render: Renderer<TData>, outcome: Outcome<TData
|
|
16
|
+
function piOperationResult<TData, TDetails = undefined>(render: Renderer<TData>, outcome: Outcome<TData>, details?: TDetails): AgentToolResult<TDetails> {
|
|
17
17
|
return {
|
|
18
18
|
content: [{ type: "text", text: render(outcome) }],
|
|
19
19
|
structuredContent: wireResult(outcome) as unknown as JsonValue,
|
|
20
20
|
isError: !outcome.ok,
|
|
21
|
-
details:
|
|
21
|
+
details: details as TDetails,
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export type ToolNamespace = { name: string; description: string };
|
|
26
26
|
export const NOTES_NAMESPACE: ToolNamespace = { name: "notes", description: "Notes you choose to keep across context windows. See the memory skill." };
|
|
27
27
|
export const DREAM_NAMESPACE: ToolNamespace = { name: "dream", description: "Consolidate one project's notes: begin, edit with notes_*, forget crumpled notes, end." };
|
|
28
|
-
export const HISTORY_NAMESPACE: ToolNamespace = { name: "history", description: "
|
|
28
|
+
export const HISTORY_NAMESPACE: ToolNamespace = { name: "history", description: "Session history (this or other local sessions): history_list to browse/search, history_read to read one event." };
|
|
29
29
|
|
|
30
30
|
/** Optional TUI renderers; without them the host draws its default call line and receipt text. */
|
|
31
|
-
export type OperationRenderers<TParams extends TSchema> = Pick<ToolDefinition<TParams,
|
|
31
|
+
export type OperationRenderers<TParams extends TSchema, TDetails = undefined> = Pick<ToolDefinition<TParams, TDetails>, "renderCall" | "renderResult">;
|
|
32
32
|
|
|
33
33
|
/** Register `operation` as a Pi tool; `run` supplies only the host context it needs. */
|
|
34
|
-
export function registerOperation<TParams extends TSchema, TData, TRest extends readonly unknown[]>(
|
|
34
|
+
export function registerOperation<TParams extends TSchema, TData, TRest extends readonly unknown[], TDetails = undefined>(
|
|
35
35
|
pi: ExtensionAPI,
|
|
36
36
|
operation: Operation<TParams, TData, TRest>,
|
|
37
|
-
run: (params: Static<TParams>, ctx: ExtensionToolContext) => Promise<Outcome<TData
|
|
37
|
+
run: (params: Static<TParams>, ctx: ExtensionToolContext) => Promise<Outcome<TData> & { details?: TDetails }>,
|
|
38
38
|
namespace?: ToolNamespace,
|
|
39
|
-
renderers?: OperationRenderers<TParams>,
|
|
39
|
+
renderers?: OperationRenderers<TParams, TDetails>,
|
|
40
40
|
exposure?: ToolExposure,
|
|
41
41
|
): void {
|
|
42
|
-
pi.registerTool(defineTool<TParams,
|
|
42
|
+
pi.registerTool(defineTool<TParams, TDetails>({
|
|
43
43
|
name: operation.name,
|
|
44
44
|
label: operation.label,
|
|
45
45
|
description: operation.description,
|
|
@@ -50,7 +50,8 @@ export function registerOperation<TParams extends TSchema, TData, TRest extends
|
|
|
50
50
|
...(exposure ? { exposure } : {}),
|
|
51
51
|
...renderers,
|
|
52
52
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
53
|
-
|
|
53
|
+
const result = await run(params, ctx);
|
|
54
|
+
return piOperationResult(operation.render, result, result.details);
|
|
54
55
|
},
|
|
55
56
|
}));
|
|
56
57
|
}
|
package/skills/memory/SKILL.md
CHANGED
|
@@ -44,9 +44,11 @@ For list/search, omit `glob` or use the collection alias `@default` for this ses
|
|
|
44
44
|
- **Something that happened**: `history_list` to browse or search this session's events; `history_read` the seq for the whole event.
|
|
45
45
|
- **An earlier window**: use its seq range from the boot window tree with `history_list`'s `before_seq` / `after_seq` bounds, or search for a remembered phrase.
|
|
46
46
|
- **Another session**: pass `session: "<id-or-prefix>"` or `"pi:<id>"`, `"claude:<id>"`, `"codex:<id>"`, `"dsh:<id>"`. An unqualified selector checks this harness first. If ambiguous, use a longer ID or a harness prefix; never pick a candidate blindly.
|
|
47
|
-
- **A phrase across sessions**: `history_list({ session: "*", query: "remembered phrase" })`, or restrict to a harness with `"pi:*"`. A wildcard
|
|
47
|
+
- **A phrase across sessions**: `history_list({ session: "*", query: "remembered phrase" })`, or restrict to a harness with `"pi:*"`. A wildcard cannot use `before_seq`/`after_seq` or `history_read`. Query results cover every role unless `roles` narrows them, are chronological, and have no paging cursors; narrow by time, role, query or session pattern instead. DSH sessions are discoverable only from DSH.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
- **Recent sessions, no remembered phrase**: `history_list({ session: "*" })` returns one representative event per session, preferring its first visible user prompt, up to `limit` (default 20). Sessions are chosen newest-modified first (`from: "oldest"` reverses that), then results are sorted chronologically. Empty queries also browse. Role/time filters apply before choosing representatives; with `roles`, the latest matching event represents each session. No paging cursors.
|
|
50
|
+
|
|
51
|
+
Seqs are stable **within a session**. When a hit carries `session`, copy it together with `seq` into `history_read` and save both in your note. The paging/expand/neighborhood recipes already preserve the resolved session. Omit `session` only when you mean your current host session. A single unreadable or unsupported local transcript refuses explicitly; wildcards skip individual sessions that cannot load. An empty result is not proof the remembered event never happened.
|
|
50
52
|
|
|
51
53
|
## Saving recovery state
|
|
52
54
|
|
package/src/history/claude.ts
CHANGED
|
@@ -251,11 +251,14 @@ export function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistoryS
|
|
|
251
251
|
return { ...projectHistory(windows, nextSeq - 1, branchSeqs), missingAncestors: [...missingAncestors], currentWindowOrdinal: "ordinal" in current ? current.ordinal : undefined };
|
|
252
252
|
}
|
|
253
253
|
|
|
254
|
-
/** Offline files have no live append binding
|
|
254
|
+
/** Offline files have no live append binding: prefer non-attachment leaves, then transcript order. */
|
|
255
255
|
export function offlineClaudeHead(text: string): string {
|
|
256
256
|
const latest = new Map<string, Row>();
|
|
257
257
|
for (const row of rowsOf(text)) {
|
|
258
|
-
if (MESSAGE_TYPES.has(row.type as string))
|
|
258
|
+
if (!MESSAGE_TYPES.has(row.type as string)) continue;
|
|
259
|
+
const uuid = requiredString(row.uuid, "uuid");
|
|
260
|
+
latest.delete(uuid);
|
|
261
|
+
latest.set(uuid, row);
|
|
259
262
|
}
|
|
260
263
|
const ancestors = new Set<string>();
|
|
261
264
|
for (const row of latest.values()) {
|
|
@@ -276,8 +279,10 @@ export function offlineClaudeHead(text: string): string {
|
|
|
276
279
|
}
|
|
277
280
|
}
|
|
278
281
|
const leaves = [...latest.keys()].filter((uuid) => !ancestors.has(uuid));
|
|
279
|
-
if (leaves.length
|
|
280
|
-
|
|
282
|
+
if (leaves.length === 0) throw new Error("Offline Claude transcript has 0 possible heads");
|
|
283
|
+
const nonAttachments = leaves.filter((uuid) => latest.get(uuid)!.type !== "attachment");
|
|
284
|
+
const candidates = nonAttachments.length ? nonAttachments : leaves;
|
|
285
|
+
return candidates.at(-1)!;
|
|
281
286
|
}
|
|
282
287
|
|
|
283
288
|
export async function readClaudeHistory(source: ClaudeHistorySource): Promise<ClaudeHistoryProjection> {
|
|
@@ -172,7 +172,8 @@ async function referencedPath(home: string, rolloutId: string): Promise<string>
|
|
|
172
172
|
if (matches.length !== 1) throw new Error(`Unavailable Codex lineage: rollout ${rolloutId} has ${matches.length ? "ambiguous native files" : "no local source file"}`);
|
|
173
173
|
return matches[0]!;
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
/** Bounded decoded bytes, also used by the local corpus's pre-projection miss check. */
|
|
176
|
+
export async function readCodexTranscriptBytes(path: string, remaining = MAX_BYTES): Promise<Buffer> {
|
|
176
177
|
const info = await stat(path);
|
|
177
178
|
if (!info.isFile() || info.size > remaining) throw new Error("Unavailable Codex transcript: read size limit exceeded or not a regular file");
|
|
178
179
|
const bytes = await readFile(path);
|
|
@@ -194,7 +195,7 @@ export async function readCodexTranscript(source: CodexTranscriptSource): Promis
|
|
|
194
195
|
while (true) {
|
|
195
196
|
if (segments.length >= MAX_SEGMENTS || seen.has(path)) throw new Error("Unavailable Codex lineage: cycle or ancestry depth limit exceeded");
|
|
196
197
|
seen.add(path);
|
|
197
|
-
const bytes = await
|
|
198
|
+
const bytes = await readCodexTranscriptBytes(path, remaining);
|
|
198
199
|
remaining -= bytes.length;
|
|
199
200
|
const segment = segmentFromBytes(bytes, cutoff);
|
|
200
201
|
if (segments.length === 0 && segment.meta.id !== source.threadId) throw new Error(`Codex transcript belongs to thread ${String(segment.meta.id)}, not requested threadId ${source.threadId} (session_id is root-scoped)`);
|
package/src/history/corpus.ts
CHANGED
|
@@ -8,7 +8,7 @@ export type HistorySession = {
|
|
|
8
8
|
harness: HistoryHarness;
|
|
9
9
|
id: string;
|
|
10
10
|
modifiedAt: number;
|
|
11
|
-
load(): Promise<HistorySessionData>;
|
|
11
|
+
load(queries?: readonly string[]): Promise<HistorySessionData | undefined>;
|
|
12
12
|
};
|
|
13
13
|
export type HistoryCorpus = {
|
|
14
14
|
currentHarness: HistoryHarness;
|
|
@@ -57,8 +57,14 @@ export async function resolveSession(corpus: HistoryCorpus | undefined, selector
|
|
|
57
57
|
return success(matches[0]!);
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export
|
|
61
|
-
|
|
60
|
+
export function loadHistorySession(session: HistorySession): Promise<Outcome<HistorySessionData>>;
|
|
61
|
+
export function loadHistorySession(session: HistorySession, queries: readonly string[] | undefined): Promise<Outcome<HistorySessionData | undefined>>;
|
|
62
|
+
export async function loadHistorySession(session: HistorySession, queries?: readonly string[]): Promise<Outcome<HistorySessionData | undefined>> {
|
|
63
|
+
try {
|
|
64
|
+
const data = await session.load(queries);
|
|
65
|
+
if (data === undefined && !queries?.length) throw new Error("Session returned no history");
|
|
66
|
+
return success(data);
|
|
67
|
+
}
|
|
62
68
|
catch (error) {
|
|
63
69
|
return failure("history_unavailable", `Cannot read session ${sessionIdentity(session)}: ${error instanceof Error ? error.message : String(error)}`);
|
|
64
70
|
}
|
package/src/history/history.ts
CHANGED
|
@@ -144,7 +144,7 @@ function toolEvent(item: DecodedHistoryItem, result?: DecodedHistoryItem): Histo
|
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
/** Pair results into call events; consumed result seqs
|
|
147
|
+
/** Pair results into call events; consumed result seqs redirect to their call event on read. */
|
|
148
148
|
export function projectHistory(rawWindows: DecodedHistoryWindow[], highestSeq: number, branchSeqs: Set<number>): HistoryProjection {
|
|
149
149
|
// Pair in durable address order, not window presentation order. Unnumbered
|
|
150
150
|
// segments need not have a provable chronological order relative to each other.
|
package/src/history/local.ts
CHANGED
|
@@ -5,11 +5,12 @@ 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 {
|
|
8
|
+
import { readCodexTranscriptBytes } from "./codex-transcript.js";
|
|
9
|
+
import { sessionIdentity, type HistoryCorpus, type HistorySession } from "./corpus.js";
|
|
9
10
|
|
|
10
11
|
export type LocalHistoryRoots = Partial<Record<"pi" | "claude" | "codex", string | null>>;
|
|
11
12
|
export type LocalHistoryOptions = {
|
|
12
|
-
current:
|
|
13
|
+
current: Pick<HistorySession, "harness" | "id" | "load">;
|
|
13
14
|
/** Undefined uses the harness default; null disables that harness's filesystem discovery. */
|
|
14
15
|
roots?: LocalHistoryRoots;
|
|
15
16
|
home?: string;
|
|
@@ -42,6 +43,35 @@ async function filesAt(root: string, depth: number): Promise<string[]> {
|
|
|
42
43
|
return paths;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
const PRESENTATION = `Codex unknown arguments not recorded output nested calls complete incomplete terminal ms image audio items null
|
|
47
|
+
copied subagent inference prefix omitted child-local history starts at native ordinal copied model context
|
|
48
|
+
does not prove original parent event addresses compaction boundary replacement_history is an inference checkpoint
|
|
49
|
+
not new conversation events opaque content omitted not recovered plaintext MCP completion without a recorded raw call
|
|
50
|
+
FunctionCallOutput display without raw output encrypted content unavailable world_state snapshot patch omitted from
|
|
51
|
+
the text projection not a newly spoken message native structured retained context not newly spoken dialogue`;
|
|
52
|
+
|
|
53
|
+
function escapeRegExp(value: string): string {
|
|
54
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Only prove misses, not hits. Only \\uXXXX can encode a word character; other JSON escapes are control/quote/slash. */
|
|
58
|
+
function mayMatch(text: string, queries: readonly string[], codex: boolean): boolean {
|
|
59
|
+
if (codex && text.includes('"history_base"')) return true;
|
|
60
|
+
const unescaped = text.includes("\\u")
|
|
61
|
+
? text.replace(/\\+u([0-9a-fA-F]{4})/g, (_, hex: string) => String.fromCharCode(Number.parseInt(hex, 16)))
|
|
62
|
+
: text;
|
|
63
|
+
return queries.some((query) => {
|
|
64
|
+
const tokens = query.match(/[\p{L}\p{N}_-]+/gu);
|
|
65
|
+
return tokens === null || tokens.every((token) => {
|
|
66
|
+
const parts = /^\d+ms$/iu.test(token) ? [token.slice(0, -2), "ms"] : [token];
|
|
67
|
+
return parts.every((part) => {
|
|
68
|
+
const literal = new RegExp(escapeRegExp(part), "iu");
|
|
69
|
+
return literal.test(unescaped) || (unescaped !== text && literal.test(text)) || literal.test(PRESENTATION);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
45
75
|
async function localSessions(harness: "pi" | "claude" | "codex", root: string): Promise<HistorySession[]> {
|
|
46
76
|
const paths = await filesAt(root, harness === "codex" ? 3 : 1);
|
|
47
77
|
const sessions: HistorySession[] = [];
|
|
@@ -56,9 +86,11 @@ async function localSessions(harness: "pi" | "claude" | "codex", root: string):
|
|
|
56
86
|
catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") continue; throw error; }
|
|
57
87
|
sessions.push({
|
|
58
88
|
harness, id, modifiedAt,
|
|
59
|
-
async load() {
|
|
89
|
+
async load(queries) {
|
|
90
|
+
if (harness === "codex" && !queries?.length) 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")) return undefined;
|
|
60
93
|
if (harness === "codex") return { projection: (await readCodexHistory({ threadId: id, transcriptPath: path })).projection };
|
|
61
|
-
const text = await readFile(path, "utf8");
|
|
62
94
|
if (harness === "pi") return { projection: piHistoryFromJsonl(text, id) };
|
|
63
95
|
const projection = claudeHistoryFromJsonl(text, { sessionId: id, headUuid: offlineClaudeHead(text) });
|
|
64
96
|
const missing = projection.missingAncestors;
|
package/src/history/query.ts
CHANGED
|
@@ -164,16 +164,27 @@ export function selectPage(projection: HistoryProjection, params: HistorySelecti
|
|
|
164
164
|
|
|
165
165
|
/** Validate before corpus discovery or I/O: per-session seqs cannot bound a multi-session search. */
|
|
166
166
|
export function corpusSelection(params: HistorySelection): Outcome<HistorySelection> {
|
|
167
|
-
const scoped = resolveSelection(params);
|
|
168
|
-
if (!scoped.ok) return scoped;
|
|
169
|
-
if (scoped.data.query === undefined) return failure("missing_query", "Wildcard session search requires a non-empty `query`.");
|
|
170
167
|
if (params.before_seq !== undefined || params.after_seq !== undefined) return failure("invalid_bounds", "`before_seq` and `after_seq` are per-session; omit them for wildcard session search.");
|
|
171
|
-
return
|
|
168
|
+
return resolveSelection(params);
|
|
172
169
|
}
|
|
173
170
|
|
|
174
|
-
/**
|
|
171
|
+
/** One topic per session, after role/time filtering; empty dialogue envelopes are not visible. */
|
|
172
|
+
export function sessionRepresentative(projection: HistoryProjection, scoped: HistorySelection): HistoryEvent | undefined {
|
|
173
|
+
const events = filteredItems(projection, scoped, false).filter((event) =>
|
|
174
|
+
(event.role !== "user" && event.role !== "assistant") || eventDocument(event) !== "");
|
|
175
|
+
if (scoped.roles) return events.at(-1);
|
|
176
|
+
return events.find((event) => event.role === "user")
|
|
177
|
+
?? events.filter((event) => event.role === "assistant").at(-1)
|
|
178
|
+
?? events.at(-1);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Merge hits or session representatives, never folds or per-session cursors. Timestamp ties use identity. */
|
|
175
182
|
export function selectCorpusPage(sessions: { session: string; projection: HistoryProjection }[], scoped: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number): Outcome<HistoryPage> {
|
|
176
|
-
const candidates = sessions.flatMap(({ session, projection }) =>
|
|
183
|
+
const candidates = sessions.flatMap(({ session, projection }): Candidate[] => {
|
|
184
|
+
if (scoped.query !== undefined) return prepareSelection(projection, { ...scoped, session }).candidates;
|
|
185
|
+
const event = sessionRepresentative(projection, scoped);
|
|
186
|
+
return event === undefined ? [] : [{ session, event }];
|
|
187
|
+
});
|
|
177
188
|
const time = (event: HistoryEvent) => event.createdAt === undefined || Number.isNaN(Date.parse(event.createdAt)) ? -Infinity : Date.parse(event.createdAt);
|
|
178
189
|
candidates.sort((a, b) => (time(a.event) - time(b.event) || a.session!.localeCompare(b.session!) || a.event.seq - b.event.seq));
|
|
179
190
|
return selectPrepared({ candidates, multi: true }, scoped, fits, maxChars);
|
package/src/tools/history.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Type, type Static } 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, type Operation } from "./result.js";
|
|
5
5
|
import { historyRoles, searchQuery } from "./schema.js";
|
|
6
|
-
import { HistoryPageSchema, corpusSelection, selectCorpusPage, selectPage, type HistoryPage } from "../history/query.js";
|
|
6
|
+
import { HistoryPageSchema, corpusSelection, selectCorpusPage, selectPage, sessionRepresentative, type HistoryPage } from "../history/query.js";
|
|
7
7
|
import { currentHistory, loadHistorySession, matchesSession, parseSessionSelector, resolveSession, sessionIdentity, type HistoryContext } from "../history/corpus.js";
|
|
8
8
|
import { allItems, eventDocument, nestedCallSummary, toolSummary, HistoryRoleSchema, NestedCallSummarySchema, ToolSummarySchema, type HistoryFoldedRow, type HistoryPageItem } from "../history/history.js";
|
|
9
9
|
|
|
@@ -77,7 +77,7 @@ const plainText: HistoryTextWrapper = (text) => text;
|
|
|
77
77
|
|
|
78
78
|
/* ------------------------------------------------------------------ history_list */
|
|
79
79
|
|
|
80
|
-
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
|
|
80
|
+
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." }));
|
|
81
81
|
|
|
82
82
|
export const historyListParameters = Type.Object({
|
|
83
83
|
session: sessionParameter,
|
|
@@ -95,7 +95,7 @@ export const historyListParameters = Type.Object({
|
|
|
95
95
|
export const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryContext, HistoryTextWrapper?]> = {
|
|
96
96
|
name: "history_list",
|
|
97
97
|
label: "History list items",
|
|
98
|
-
description: "Browse or search events, a page at a time. Omit session for this session; pass an ID/prefix for another, or *
|
|
98
|
+
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`.",
|
|
99
99
|
parameters: historyListParameters,
|
|
100
100
|
outputSchema: resultSchema(HistoryPageSchema),
|
|
101
101
|
async execute(params, context, wrapText = plainText) {
|
|
@@ -111,13 +111,17 @@ export const historyList: Operation<typeof historyListParameters, HistoryPage, [
|
|
|
111
111
|
if (!scoped.ok) return scoped;
|
|
112
112
|
if (corpus === undefined) return failure("unknown_session", "This host supplied no cross-session history corpus.");
|
|
113
113
|
const sessions = (await corpus.sessions(selector.data.harness)).filter((session) => matchesSession(session, selector.data));
|
|
114
|
+
const queries = Array.isArray(scoped.data.query) ? scoped.data.query : undefined;
|
|
115
|
+
if (!queries) sessions.sort((a, b) => (scoped.data.from === "oldest" ? a.modifiedAt - b.modifiedAt : b.modifiedAt - a.modifiedAt) || sessionIdentity(a).localeCompare(sessionIdentity(b)));
|
|
114
116
|
const loaded = [];
|
|
115
117
|
const notices: string[] = [];
|
|
116
118
|
for (const session of sessions) {
|
|
117
|
-
const result = await loadHistorySession(session);
|
|
118
|
-
if (!result.ok
|
|
119
|
+
const result = await loadHistorySession(session, queries);
|
|
120
|
+
if (!result.ok || !result.data) continue;
|
|
121
|
+
if (!queries && !sessionRepresentative(result.data.projection, scoped.data)) continue;
|
|
119
122
|
loaded.push({ session: sessionIdentity(session), projection: result.data.projection });
|
|
120
123
|
if (result.data.notice) notices.push(`session ${sessionIdentity(session)}: ${result.data.notice}`);
|
|
124
|
+
if (!queries && loaded.length >= Math.max(1, params.limit ?? 20)) break;
|
|
121
125
|
}
|
|
122
126
|
const notice = notices.length ? { notice: notices.join("") } : {};
|
|
123
127
|
const result = selectCorpusPage(loaded, scoped.data, (page) => fits({ ...page, ...notice }), maxChars);
|
|
@@ -159,21 +163,18 @@ export const historyRead: Operation<typeof historyReadParameters, HistoryReadDat
|
|
|
159
163
|
projection = loaded.data.projection;
|
|
160
164
|
identity = { session: sessionIdentity(target.data), ...(loaded.data.notice === undefined ? {} : { notice: loaded.data.notice }) };
|
|
161
165
|
}
|
|
162
|
-
const item = allItems(projection).find((event) => event.seq === params.seq);
|
|
163
166
|
// Address checks run in one order: past the end of the file, off this branch, then
|
|
164
|
-
//
|
|
165
|
-
if (
|
|
167
|
+
// resolved through any tool-result pairing to its call event.
|
|
168
|
+
if (params.seq > projection.highestSeq) {
|
|
166
169
|
return failure("unknown_seq", `There is no seq ${params.seq}; this session runs from seq 1 to ${projection.highestSeq}.`);
|
|
167
170
|
}
|
|
168
171
|
if (!projection.branchSeqs.has(params.seq)) {
|
|
169
172
|
if (identity.notice) 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.`);
|
|
170
173
|
return failure("not_on_branch", `Seq ${params.seq} is on another branch of this session; it can't be read from here.`);
|
|
171
174
|
}
|
|
175
|
+
const targetSeq = projection.pairedResults.get(params.seq) ?? params.seq;
|
|
176
|
+
const item = allItems(projection).find((event) => event.seq === targetSeq);
|
|
172
177
|
if (item === undefined) {
|
|
173
|
-
const callSeq = projection.pairedResults.get(params.seq);
|
|
174
|
-
if (callSeq !== undefined) {
|
|
175
|
-
return failure("not_an_event", `Seq ${params.seq} is a tool result, shown together with its call; read seq ${callSeq} instead.`);
|
|
176
|
-
}
|
|
177
178
|
return failure("unknown_seq", `Seq ${params.seq} holds nothing to read.`);
|
|
178
179
|
}
|
|
179
180
|
const document = eventDocument(item);
|