notesoup 0.51.3 → 0.51.5
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/notes/tools.js +1 -1
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/paseo/OVERVIEW.md +6 -2
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/notes-op-card.tsx +84 -0
- package/plugins/paseo/client/notes-op-transformer.ts +115 -0
- package/plugins/paseo/client/paper-card.tsx +36 -0
- package/plugins/paseo/client/sticky-card.tsx +7 -14
- package/plugins/paseo/index.client.tsx +10 -3
- package/plugins/paseo/shared/notes-op.ts +29 -0
- package/plugins/paseo/test/notes-op.test.ts +129 -0
- package/plugins/pi/notes/tools.ts +1 -1
|
@@ -3,7 +3,7 @@ import { notesWrite, notesUpdate, notesRead, notesList, notesSearch } from "../.
|
|
|
3
3
|
import { notesIdentityFromPi } from "./adapter.js";
|
|
4
4
|
import { NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
|
|
5
5
|
function renderDiff(change) {
|
|
6
|
-
return change.kind === "none" ? "" : generateDiffString(change.before, change.after).diff;
|
|
6
|
+
return change.kind === "none" ? "" : generateDiffString(change.before, change.after, 1).diff;
|
|
7
7
|
}
|
|
8
8
|
/** Register the five shared note operations; each one supplies Pi's session identity and nothing else. */
|
|
9
9
|
export function registerNotesTools(pi) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# Notesoup last word
|
|
2
2
|
|
|
3
|
-
Displays notesoup last-word messages already present in Paseo’s timeline as expanded, selectable cards.
|
|
3
|
+
Displays notesoup last-word messages already present in Paseo’s timeline as expanded, selectable paper cards. Last-word and notes cards share a pale-paper palette, tape accent, small corners, and compact spacing; last-word text stays visible without folding. Requires Paseo 0.11.2 on the client and daemon.
|
|
4
4
|
|
|
5
|
-
This client-only plugin transforms
|
|
5
|
+
This client-only plugin transforms existing timeline rows in place: last-word custom messages become sticky cards, and notes_read/notes_write/notes_update tool calls become paper cards with the address, state, and a content or diff preview. It does not read session files or append messages. Other timeline items are unchanged.
|
|
6
|
+
|
|
7
|
+
Notes cards start collapsed, with an expand arrow at the top right and a collapse arrow below the expanded body. Long content scrolls inside a bounded panel. Display limits are 4000 characters for reads and writes, and 8000 for diffs; expanding does not fetch more content.
|
|
8
|
+
|
|
9
|
+
Notes cards prefer the structured tool payload on live events. Replayed history carries only the rendered result text, so the transformer parses that fallback; replayed writes show no content preview.
|
|
6
10
|
|
|
7
11
|
Paseo 0.11.2 drops Pi boundary `entry_appended` events from its live timeline. This plugin cannot display messages that Paseo has not received; that adapter gap needs an upstream fix. Messages available through history can be rendered.
|
package/plugins/paseo/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Notesoup Paseo plugin
|
|
2
2
|
|
|
3
|
-
Client-only last-word
|
|
3
|
+
Client-only renderers: last-word sticky cards and paper cards for notes_read/notes_write/notes_update tool calls. See [OVERVIEW.md](OVERVIEW.md) for behavior and the upstream live-event limitation.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
cd plugins/paseo
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
|
|
2
|
+
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Pressable, ScrollView, Text, View } from "react-native";
|
|
5
|
+
import type { NotesOp } from "../shared/notes-op.ts";
|
|
6
|
+
import { PAPER, PaperCard } from "./paper-card.tsx";
|
|
7
|
+
|
|
8
|
+
const OP_LABEL: Record<NotesOp["op"], string> = { read: "READ NOTE", write: "WROTE NOTE", update: "UPDATED NOTE" };
|
|
9
|
+
const OP_LABEL_RUNNING: Record<NotesOp["op"], string> = { read: "READING NOTE", write: "WRITING NOTE", update: "UPDATING NOTE" };
|
|
10
|
+
const CHANGE_LABEL: Record<string, string> = { body: "edited", metadata: "metadata", moved: "renamed", none: "unchanged" };
|
|
11
|
+
|
|
12
|
+
function DiffBody({ diff }: { diff: string }) {
|
|
13
|
+
return (
|
|
14
|
+
<View style={{ gap: 2 }}>
|
|
15
|
+
{diff.split("\n").map((line, index) => {
|
|
16
|
+
const color = line.startsWith("+") ? PAPER.added
|
|
17
|
+
: line.startsWith("-") ? PAPER.removed
|
|
18
|
+
: PAPER.inkMuted;
|
|
19
|
+
return <Text key={index} selectable style={{ color, fontSize: 12, fontFamily: "Menlo" }}>{line}</Text>;
|
|
20
|
+
})}
|
|
21
|
+
</View>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function NotesOpCard({ item, layout }: PluginTimelineItemProps<NotesOp>) {
|
|
26
|
+
const [expanded, setExpanded] = useState(false);
|
|
27
|
+
const data = item.data;
|
|
28
|
+
const title = data.status === "running" ? OP_LABEL_RUNNING[data.op] : OP_LABEL[data.op];
|
|
29
|
+
const state = data.error !== undefined ? "failed"
|
|
30
|
+
: data.op === "write" ? data.outcome
|
|
31
|
+
: data.op === "update" ? CHANGE_LABEL[data.changeKind ?? ""] ?? data.changeKind
|
|
32
|
+
: undefined;
|
|
33
|
+
const footnotes: string[] = [];
|
|
34
|
+
if (data.renamedFrom !== undefined) footnotes.push(`renamed from ${data.renamedFrom}`);
|
|
35
|
+
if (data.diff !== undefined && data.truncated) footnotes.push("diff shortened for display");
|
|
36
|
+
const showEllipsis = data.truncated && data.diff === undefined;
|
|
37
|
+
const hasBody = Boolean(data.text || data.preview || data.diff || footnotes.length);
|
|
38
|
+
return (
|
|
39
|
+
<PaperCard compact={layout.compact}>
|
|
40
|
+
<View style={{ gap: 3 }}>
|
|
41
|
+
<View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: 8 }}>
|
|
42
|
+
<Text style={{ color: PAPER.inkMuted, fontSize: 11, letterSpacing: 0.5 }}>
|
|
43
|
+
{title}{data.status === "running" ? " …" : ""}
|
|
44
|
+
</Text>
|
|
45
|
+
{hasBody && !expanded && <Pressable
|
|
46
|
+
accessibilityRole="button"
|
|
47
|
+
accessibilityLabel={`${expanded ? "收起" : "展开"} ${data.address}`}
|
|
48
|
+
aria-expanded={expanded}
|
|
49
|
+
onPress={() => setExpanded(value => !value)}
|
|
50
|
+
hitSlop={6}
|
|
51
|
+
style={({ pressed }) => ({ padding: 5, opacity: pressed ? 0.6 : 1 })}
|
|
52
|
+
>
|
|
53
|
+
<Icon name={expanded ? "ChevronUp" : "ChevronDown"} size={18} color={PAPER.inkMuted} />
|
|
54
|
+
</Pressable>}
|
|
55
|
+
</View>
|
|
56
|
+
<Text style={{ color: PAPER.ink, fontSize: 13, flexShrink: 1 }}>
|
|
57
|
+
{data.address}
|
|
58
|
+
{state !== undefined && <Text style={{ color: PAPER.inkMuted, fontSize: 12, fontWeight: "400" }}>{" "}{state}</Text>}
|
|
59
|
+
</Text>
|
|
60
|
+
</View>
|
|
61
|
+
{data.error !== undefined && <Text selectable style={{ color: PAPER.removed, fontSize: 13, lineHeight: 19 }}>{data.error}</Text>}
|
|
62
|
+
{expanded && hasBody && <ScrollView
|
|
63
|
+
style={{ maxHeight: layout.compact ? 280 : 400 }}
|
|
64
|
+
contentContainerStyle={{ gap: 5 }}
|
|
65
|
+
nestedScrollEnabled
|
|
66
|
+
>
|
|
67
|
+
{data.text !== undefined && <Text selectable style={{ color: PAPER.ink, fontSize: 13, lineHeight: 19 }}>{data.text}{showEllipsis && " …"}</Text>}
|
|
68
|
+
{data.preview !== undefined && <Text selectable style={{ color: PAPER.inkMuted, fontSize: 13, lineHeight: 19 }}>{data.preview}{showEllipsis && " …"}</Text>}
|
|
69
|
+
{data.diff !== undefined && <DiffBody diff={data.diff} />}
|
|
70
|
+
{footnotes.length > 0 && <Text style={{ color: PAPER.inkMuted, fontSize: 11 }}>{footnotes.join(" · ")}</Text>}
|
|
71
|
+
</ScrollView>}
|
|
72
|
+
{hasBody && expanded && <Pressable
|
|
73
|
+
accessibilityRole="button"
|
|
74
|
+
accessibilityLabel={`收起 ${data.address}`}
|
|
75
|
+
aria-expanded={true}
|
|
76
|
+
onPress={() => setExpanded(false)}
|
|
77
|
+
hitSlop={6}
|
|
78
|
+
style={({ pressed }) => ({ alignSelf: "flex-end", paddingHorizontal: 5, paddingVertical: 1, opacity: pressed ? 0.6 : 1 })}
|
|
79
|
+
>
|
|
80
|
+
<Icon name="ChevronUp" size={18} color={PAPER.inkMuted} />
|
|
81
|
+
</Pressable>}
|
|
82
|
+
</PaperCard>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
|
+
import {
|
|
3
|
+
DIFF_MAX_CHARS,
|
|
4
|
+
NOTES_OP_KIND,
|
|
5
|
+
NOTES_OP_TOOLS,
|
|
6
|
+
PREVIEW_MAX_CHARS,
|
|
7
|
+
READ_TEXT_MAX_CHARS,
|
|
8
|
+
type NotesOp,
|
|
9
|
+
type NotesOpTool,
|
|
10
|
+
} from "../shared/notes-op.ts";
|
|
11
|
+
|
|
12
|
+
type Transformer = Extract<Parameters<PluginClientContext["addTimelineTransformer"]>[0], { query: { itemType: "tool_call" } }>;
|
|
13
|
+
type Source = Parameters<Transformer["transform"]>[0];
|
|
14
|
+
type ToolCallItem = Extract<Source["item"], { type: "tool_call" }>;
|
|
15
|
+
|
|
16
|
+
const OP_BY_TOOL: Record<NotesOpTool, NotesOp["op"]> = {
|
|
17
|
+
notes_read: "read",
|
|
18
|
+
notes_write: "write",
|
|
19
|
+
notes_update: "update",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
23
|
+
return typeof value === "object" && value !== null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function clip(text: string, maxChars: number): { text: string; truncated: boolean } {
|
|
27
|
+
const chars = Array.from(text);
|
|
28
|
+
return chars.length <= maxChars
|
|
29
|
+
? { text, truncated: false }
|
|
30
|
+
: { text: chars.slice(0, maxChars).join(""), truncated: true };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Prefer the structured payload; fall back to the rendered text blocks. */
|
|
34
|
+
function resultText(output: unknown): string | undefined {
|
|
35
|
+
if (!isRecord(output) || !Array.isArray(output.content)) return undefined;
|
|
36
|
+
const parts = output.content.filter(isRecord).filter((block) => block.type === "text" && typeof block.text === "string");
|
|
37
|
+
return parts.length > 0 ? parts.map((block) => block.text as string).join("\n") : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function baseData(item: ToolCallItem, op: NotesOp["op"], input: unknown): NotesOp | undefined {
|
|
41
|
+
const address = isRecord(input) && typeof input.address === "string" ? input.address : undefined;
|
|
42
|
+
if (!address) return undefined;
|
|
43
|
+
const status = item.status === "running" ? "running" : item.status === "failed" ? "failed" : "completed";
|
|
44
|
+
return { op, address, status };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function notesOpData(item: ToolCallItem): NotesOp | undefined {
|
|
48
|
+
const op = OP_BY_TOOL[item.name as NotesOpTool];
|
|
49
|
+
if (!op || item.detail.type !== "unknown") return undefined;
|
|
50
|
+
const { input, output } = item.detail;
|
|
51
|
+
const data = baseData(item, op, input);
|
|
52
|
+
if (!data) return undefined;
|
|
53
|
+
if (data.status === "running") return data;
|
|
54
|
+
|
|
55
|
+
const wire = isRecord(output) && isRecord(output.structuredContent) ? output.structuredContent : undefined;
|
|
56
|
+
if (wire && typeof wire.error === "string") return { ...data, error: wire.error };
|
|
57
|
+
if (data.status === "failed" && !wire) return { ...data, error: resultText(output) ?? "failed" };
|
|
58
|
+
if (!wire) {
|
|
59
|
+
// History replay reconstructs results without the structured payload; parse the rendered text.
|
|
60
|
+
const text = resultText(output);
|
|
61
|
+
if (text === undefined) return data;
|
|
62
|
+
if (op === "read") {
|
|
63
|
+
const clipped = clip(text.split("\n").slice(2).join("\n").replace(/^\n/, ""), READ_TEXT_MAX_CHARS);
|
|
64
|
+
return { ...data, text: clipped.text, ...(clipped.truncated ? { truncated: true } : {}) };
|
|
65
|
+
}
|
|
66
|
+
if (op === "write") {
|
|
67
|
+
const outcome = text.split(" ")[0];
|
|
68
|
+
return { ...data, ...(["created", "overwrote", "uncrumpled"].includes(outcome) ? { outcome } : {}) };
|
|
69
|
+
}
|
|
70
|
+
const head = text.split("\n")[0] ?? "";
|
|
71
|
+
const changeKind = head.startsWith("moved ") ? "moved" : head.startsWith("updated ") ? "body" : head.startsWith("unchanged ") ? "none" : undefined;
|
|
72
|
+
const diffStart = text.indexOf("\ndiff:\n");
|
|
73
|
+
const clippedDiff = diffStart >= 0 ? clip(text.slice(diffStart + 7), DIFF_MAX_CHARS) : undefined;
|
|
74
|
+
return {
|
|
75
|
+
...data,
|
|
76
|
+
...(changeKind ? { changeKind } : {}),
|
|
77
|
+
...(clippedDiff && clippedDiff.text.length > 0 ? { diff: clippedDiff.text, ...(clippedDiff.truncated ? { truncated: true } : {}) } : {}),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (op === "read" && typeof wire.text === "string") {
|
|
82
|
+
const clipped = clip(wire.text, READ_TEXT_MAX_CHARS);
|
|
83
|
+
return {
|
|
84
|
+
...data,
|
|
85
|
+
text: clipped.text,
|
|
86
|
+
truncated: clipped.truncated || wire.next_offset_chars !== null,
|
|
87
|
+
...(typeof wire.total_chars === "number" ? { totalChars: wire.total_chars } : {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (op === "write") {
|
|
91
|
+
const preview = isRecord(input) && typeof input.content === "string" ? clip(input.content, PREVIEW_MAX_CHARS) : undefined;
|
|
92
|
+
return {
|
|
93
|
+
...data,
|
|
94
|
+
...(typeof wire.outcome === "string" ? { outcome: wire.outcome } : {}),
|
|
95
|
+
...(preview ? { preview: preview.text, ...(preview.truncated ? { truncated: true } : {}) } : {}),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const clippedDiff = typeof wire.diff === "string" && wire.diff.length > 0 ? clip(wire.diff, DIFF_MAX_CHARS) : undefined;
|
|
99
|
+
return {
|
|
100
|
+
...data,
|
|
101
|
+
...(typeof wire.change_kind === "string" ? { changeKind: wire.change_kind } : {}),
|
|
102
|
+
...(typeof wire.rename_from === "string" ? { renamedFrom: wire.rename_from } : {}),
|
|
103
|
+
...(clippedDiff ? { diff: clippedDiff.text, ...(clippedDiff.truncated ? { truncated: true } : {}) } : {}),
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export const notesOpTransformer = {
|
|
108
|
+
id: "notes-op-source",
|
|
109
|
+
query: { itemType: "tool_call" },
|
|
110
|
+
transform: ({ item }: Pick<Source, "item">) => {
|
|
111
|
+
if (item.type !== "tool_call" || !NOTES_OP_TOOLS.includes(item.name as NotesOpTool)) return undefined;
|
|
112
|
+
const data = notesOpData(item);
|
|
113
|
+
return data === undefined ? undefined : { items: [{ type: "plugin" as const, kind: NOTES_OP_KIND, version: 1, data }] };
|
|
114
|
+
},
|
|
115
|
+
} satisfies Transformer;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { View } from "react-native";
|
|
3
|
+
|
|
4
|
+
/** Shared paper palette, independent of the host theme. */
|
|
5
|
+
export const PAPER = {
|
|
6
|
+
background: "#f7f2df",
|
|
7
|
+
border: "#d9cdaa",
|
|
8
|
+
tape: "#d8c98f",
|
|
9
|
+
ink: "#33301f",
|
|
10
|
+
inkMuted: "#867c63",
|
|
11
|
+
added: "#357a44",
|
|
12
|
+
removed: "#b0493e",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export function PaperCard({ compact, children }: { compact: boolean; children: ReactNode }) {
|
|
16
|
+
return (
|
|
17
|
+
<View style={{ paddingTop: 6 }}>
|
|
18
|
+
<View style={{
|
|
19
|
+
alignSelf: "flex-start", width: 84, height: 14, marginLeft: 28, marginBottom: -9, zIndex: 1,
|
|
20
|
+
backgroundColor: PAPER.tape, opacity: 0.9, borderRadius: 2,
|
|
21
|
+
transform: [{ rotate: "-2deg" }],
|
|
22
|
+
}} />
|
|
23
|
+
<View style={{
|
|
24
|
+
padding: compact ? 10 : 12,
|
|
25
|
+
gap: 5,
|
|
26
|
+
minWidth: 0,
|
|
27
|
+
borderRadius: 4,
|
|
28
|
+
borderWidth: 1,
|
|
29
|
+
borderColor: PAPER.border,
|
|
30
|
+
backgroundColor: PAPER.background,
|
|
31
|
+
}}>
|
|
32
|
+
{children}
|
|
33
|
+
</View>
|
|
34
|
+
</View>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
|
|
2
|
-
import { Text
|
|
2
|
+
import { Text } from "react-native";
|
|
3
3
|
import type { LastWord } from "../shared/last-word.ts";
|
|
4
|
+
import { PAPER, PaperCard } from "./paper-card.tsx";
|
|
4
5
|
|
|
5
|
-
export function StickyCard({ item,
|
|
6
|
+
export function StickyCard({ item, layout }: PluginTimelineItemProps<LastWord>) {
|
|
6
7
|
const text = item.data.text.replace(/^\*You peel a sticky note off your forehead\.\*\n/, "");
|
|
7
8
|
return (
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
borderRadius: 12,
|
|
13
|
-
borderWidth: 1,
|
|
14
|
-
borderColor: theme.colors.border,
|
|
15
|
-
backgroundColor: theme.colors.surface1,
|
|
16
|
-
}}>
|
|
17
|
-
<Text style={{ color: theme.colors.foregroundMuted, fontWeight: "600" }}>Last word</Text>
|
|
18
|
-
<Text selectable style={{ color: theme.colors.foreground, flexShrink: 1 }}>{text}</Text>
|
|
19
|
-
</View>
|
|
9
|
+
<PaperCard compact={layout.compact}>
|
|
10
|
+
<Text style={{ color: PAPER.inkMuted, fontSize: 11, letterSpacing: 0.5 }}>LAST WORD</Text>
|
|
11
|
+
<Text selectable style={{ color: PAPER.ink, fontSize: 13, lineHeight: 19, flexShrink: 1 }}>{text}</Text>
|
|
12
|
+
</PaperCard>
|
|
20
13
|
);
|
|
21
14
|
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
2
|
import { sourceRowTransformer } from "./client/source-row.ts";
|
|
3
|
+
import { notesOpTransformer } from "./client/notes-op-transformer.ts";
|
|
3
4
|
import { StickyCard } from "./client/sticky-card.tsx";
|
|
5
|
+
import { NotesOpCard } from "./client/notes-op-card.tsx";
|
|
4
6
|
import { CARD_KIND, lastWordSchema } from "./shared/last-word.ts";
|
|
7
|
+
import { NOTES_OP_KIND, notesOpSchema } from "./shared/notes-op.ts";
|
|
5
8
|
|
|
6
9
|
export default function contribute(client: PluginClientContext) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
const removals = [
|
|
11
|
+
client.addTimelineRenderer({ kind: CARD_KIND, version: 1, schema: lastWordSchema, Component: StickyCard }),
|
|
12
|
+
client.addTimelineRenderer({ kind: NOTES_OP_KIND, version: 1, schema: notesOpSchema, Component: NotesOpCard }),
|
|
13
|
+
client.addTimelineTransformer(sourceRowTransformer),
|
|
14
|
+
client.addTimelineTransformer(notesOpTransformer),
|
|
15
|
+
];
|
|
16
|
+
return () => { for (const remove of removals) remove(); };
|
|
10
17
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const NOTES_OP_KIND = "notes-op";
|
|
4
|
+
export const NOTES_OP_TOOLS = ["notes_read", "notes_write", "notes_update"] as const;
|
|
5
|
+
export type NotesOpTool = (typeof NOTES_OP_TOOLS)[number];
|
|
6
|
+
|
|
7
|
+
/** Card data stays small: the plugin timeline refuses payloads over 64 KB. */
|
|
8
|
+
export const READ_TEXT_MAX_CHARS = 4000;
|
|
9
|
+
export const DIFF_MAX_CHARS = 8000;
|
|
10
|
+
export const PREVIEW_MAX_CHARS = 4000;
|
|
11
|
+
|
|
12
|
+
export const notesOpSchema = z.object({
|
|
13
|
+
op: z.enum(["read", "write", "update"]),
|
|
14
|
+
address: z.string(),
|
|
15
|
+
status: z.enum(["running", "completed", "failed"]),
|
|
16
|
+
error: z.string().optional(),
|
|
17
|
+
// read
|
|
18
|
+
text: z.string().optional(),
|
|
19
|
+
totalChars: z.number().optional(),
|
|
20
|
+
// write
|
|
21
|
+
outcome: z.string().optional(),
|
|
22
|
+
preview: z.string().optional(),
|
|
23
|
+
// update
|
|
24
|
+
changeKind: z.string().optional(),
|
|
25
|
+
diff: z.string().optional(),
|
|
26
|
+
renamedFrom: z.string().optional(),
|
|
27
|
+
truncated: z.boolean().optional(),
|
|
28
|
+
});
|
|
29
|
+
export type NotesOp = z.infer<typeof notesOpSchema>;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { notesOpTransformer } from "../client/notes-op-transformer.ts";
|
|
4
|
+
import { DIFF_MAX_CHARS, PREVIEW_MAX_CHARS, READ_TEXT_MAX_CHARS, notesOpSchema } from "../shared/notes-op.ts";
|
|
5
|
+
|
|
6
|
+
function toolCall(overrides: Record<string, unknown>) {
|
|
7
|
+
return {
|
|
8
|
+
type: "tool_call" as const,
|
|
9
|
+
callId: "call-1",
|
|
10
|
+
name: "notes_read",
|
|
11
|
+
status: "completed" as const,
|
|
12
|
+
error: null,
|
|
13
|
+
detail: { type: "unknown" as const, input: { address: "@self/foo.md" }, output: {} },
|
|
14
|
+
...overrides,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const transform = (overrides: Record<string, unknown>) => notesOpTransformer.transform({ item: toolCall(overrides) as never });
|
|
19
|
+
|
|
20
|
+
test("notes_read renders the structured window, marks continuation as truncated", () => {
|
|
21
|
+
const result = transform({
|
|
22
|
+
detail: {
|
|
23
|
+
type: "unknown",
|
|
24
|
+
input: { address: "@self/foo.md" },
|
|
25
|
+
output: { structuredContent: { address: "@self/foo.md", text: "hello note", total_chars: 9999, next_offset_chars: 4000 } },
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const data = notesOpSchema.parse(result!.items[0]!.data);
|
|
29
|
+
assert.deepEqual(data, { op: "read", address: "@self/foo.md", status: "completed", text: "hello note", totalChars: 9999, truncated: true });
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("notes_write carries outcome and a clipped content preview", () => {
|
|
33
|
+
const result = transform({
|
|
34
|
+
name: "notes_write",
|
|
35
|
+
detail: {
|
|
36
|
+
type: "unknown",
|
|
37
|
+
input: { address: "session.md", content: "x".repeat(PREVIEW_MAX_CHARS + 10) },
|
|
38
|
+
output: { structuredContent: { address: "session.md", outcome: "created" } },
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const data = notesOpSchema.parse(result!.items[0]!.data);
|
|
42
|
+
assert.equal(data.op, "write");
|
|
43
|
+
assert.equal(data.outcome, "created");
|
|
44
|
+
assert.equal(data.preview!.length, PREVIEW_MAX_CHARS);
|
|
45
|
+
assert.equal(data.truncated, true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("notes_update carries change kind, rename, and clipped diff", () => {
|
|
49
|
+
const result = transform({
|
|
50
|
+
name: "notes_update",
|
|
51
|
+
detail: {
|
|
52
|
+
type: "unknown",
|
|
53
|
+
input: { address: "@project/a.md" },
|
|
54
|
+
output: { structuredContent: { address: "@project/b.md", change_kind: "moved", rename_from: "@project/a.md", diff: "y".repeat(DIFF_MAX_CHARS + 10) } },
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
const data = notesOpSchema.parse(result!.items[0]!.data);
|
|
58
|
+
assert.equal(data.changeKind, "moved");
|
|
59
|
+
assert.equal(data.renamedFrom, "@project/a.md");
|
|
60
|
+
assert.equal(data.diff!.length, DIFF_MAX_CHARS);
|
|
61
|
+
assert.equal(data.truncated, true);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("wire errors and failed calls surface the refusal text", () => {
|
|
65
|
+
const refused = transform({
|
|
66
|
+
detail: { type: "unknown", input: { address: "@self/foo.md" }, output: { structuredContent: { error: "No note at @self/foo.md.", code: "not_found" } } },
|
|
67
|
+
});
|
|
68
|
+
assert.equal(notesOpSchema.parse(refused!.items[0]!.data).error, "No note at @self/foo.md.");
|
|
69
|
+
|
|
70
|
+
const failed = transform({
|
|
71
|
+
status: "failed",
|
|
72
|
+
error: { message: "boom" },
|
|
73
|
+
detail: { type: "unknown", input: { address: "@self/foo.md" }, output: { content: [{ type: "text", text: "io failed" }] } },
|
|
74
|
+
});
|
|
75
|
+
assert.equal(notesOpSchema.parse(failed!.items[0]!.data).error, "io failed");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("running calls render from input alone; long reads clip to the card budget", () => {
|
|
79
|
+
const running = transform({ status: "running", detail: { type: "unknown", input: { address: "@human/map.md" }, output: null } });
|
|
80
|
+
assert.deepEqual(notesOpSchema.parse(running!.items[0]!.data), { op: "read", address: "@human/map.md", status: "running" });
|
|
81
|
+
|
|
82
|
+
const long = transform({
|
|
83
|
+
detail: { type: "unknown", input: { address: "big.md" }, output: { structuredContent: { address: "big.md", text: "z".repeat(READ_TEXT_MAX_CHARS + 500), total_chars: 50000, next_offset_chars: null } } },
|
|
84
|
+
});
|
|
85
|
+
const data = notesOpSchema.parse(long!.items[0]!.data);
|
|
86
|
+
assert.equal(data.text!.length, READ_TEXT_MAX_CHARS);
|
|
87
|
+
assert.equal(data.truncated, true);
|
|
88
|
+
assert.ok(JSON.stringify(result_items(long)).length < 64 * 1024, "plugin payload stays under the timeline limit");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("history replay has no structured payload: the rendered text is parsed instead", () => {
|
|
92
|
+
const read = transform({
|
|
93
|
+
detail: { type: "unknown", input: { address: "@self/foo.md" }, output: { content: [{ type: "text", text: "@self/foo.md\norigin self | created 2026-10-15 | updated 2026-10-15\n\nbody line one\nbody line two" }] } },
|
|
94
|
+
});
|
|
95
|
+
assert.equal(notesOpSchema.parse(read!.items[0]!.data).text, "body line one\nbody line two");
|
|
96
|
+
|
|
97
|
+
const write = transform({
|
|
98
|
+
name: "notes_write",
|
|
99
|
+
detail: { type: "unknown", input: { address: "a.md", content: "ignored" }, output: { content: [{ type: "text", text: "overwrote a.md (project pi-context)" }] } },
|
|
100
|
+
});
|
|
101
|
+
const writeData = notesOpSchema.parse(write!.items[0]!.data);
|
|
102
|
+
assert.equal(writeData.outcome, "overwrote");
|
|
103
|
+
assert.equal(writeData.preview, undefined, "replay has no input preview authority beyond the address");
|
|
104
|
+
|
|
105
|
+
const update = transform({
|
|
106
|
+
name: "notes_update",
|
|
107
|
+
detail: { type: "unknown", input: { address: "a.md" }, output: { content: [{ type: "text", text: "updated a.md\ndiff:\n- 1 - old\n+ 1 + new" }] } },
|
|
108
|
+
});
|
|
109
|
+
const updateData = notesOpSchema.parse(update!.items[0]!.data);
|
|
110
|
+
assert.equal(updateData.changeKind, "body");
|
|
111
|
+
assert.equal(updateData.diff, "- 1 - old\n+ 1 + new");
|
|
112
|
+
|
|
113
|
+
const moved = transform({
|
|
114
|
+
name: "notes_update",
|
|
115
|
+
detail: { type: "unknown", input: { address: "a.md" }, output: { content: [{ type: "text", text: "moved a.md -> b.md" }] } },
|
|
116
|
+
});
|
|
117
|
+
assert.equal(notesOpSchema.parse(moved!.items[0]!.data).changeKind, "moved");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("non-notes tools, unknown shapes and missing addresses stay untouched", () => {
|
|
121
|
+
assert.equal(notesOpTransformer.transform({ item: toolCall({ name: "bash" }) as never }), undefined);
|
|
122
|
+
assert.equal(notesOpTransformer.transform({ item: toolCall({ detail: { type: "plain_text", text: "hi" } }) as never }), undefined);
|
|
123
|
+
assert.equal(notesOpTransformer.transform({ item: toolCall({ detail: { type: "unknown", input: {}, output: {} } }) as never }), undefined);
|
|
124
|
+
assert.equal(notesOpTransformer.transform({ item: { type: "user_message", text: "hi" } as never }), undefined);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
function result_items(result: { items: Array<{ data: unknown }> } | undefined) {
|
|
128
|
+
return result!.items.map((item) => item.data);
|
|
129
|
+
}
|
|
@@ -5,7 +5,7 @@ import { NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
|
|
|
5
5
|
import type { NoteChange } from "../../../src/notes/index.js";
|
|
6
6
|
|
|
7
7
|
function renderDiff(change: NoteChange): string {
|
|
8
|
-
return change.kind === "none" ? "" : generateDiffString(change.before, change.after).diff;
|
|
8
|
+
return change.kind === "none" ? "" : generateDiffString(change.before, change.after, 1).diff;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/** Register the five shared note operations; each one supplies Pi's session identity and nothing else. */
|