notesoup 0.51.2 → 0.51.4
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/dist/plugins/pi/reset/lifecycle.d.ts +29 -14
- package/dist/plugins/pi/reset/lifecycle.js +46 -49
- package/dist/test/reset-lifecycle.test.js +173 -79
- package/docs/architecture.md +1 -1
- package/docs/reset-lifecycle.md +6 -5
- 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 +109 -0
- package/plugins/paseo/client/notes-op-transformer.ts +115 -0
- package/plugins/paseo/client/sticky-card.tsx +19 -12
- package/plugins/paseo/index.client.tsx +10 -3
- package/plugins/paseo/package-lock.json +4018 -0
- 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
- package/plugins/pi/reset/lifecycle.ts +59 -61
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
|
|
7
|
+
const OP_LABEL: Record<NotesOp["op"], string> = { read: "READ NOTE", write: "WROTE NOTE", update: "UPDATED NOTE" };
|
|
8
|
+
const OP_LABEL_RUNNING: Record<NotesOp["op"], string> = { read: "READING NOTE", write: "WRITING NOTE", update: "UPDATING NOTE" };
|
|
9
|
+
const CHANGE_LABEL: Record<string, string> = { body: "edited", metadata: "metadata", moved: "renamed", none: "unchanged" };
|
|
10
|
+
|
|
11
|
+
/** Paper palette: pale note paper, readable regardless of the host theme. */
|
|
12
|
+
const PAPER = {
|
|
13
|
+
background: "#f7f2df",
|
|
14
|
+
border: "#d9cdaa",
|
|
15
|
+
tape: "#d8c98f",
|
|
16
|
+
ink: "#33301f",
|
|
17
|
+
inkMuted: "#867c63",
|
|
18
|
+
added: "#357a44",
|
|
19
|
+
removed: "#b0493e",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function DiffBody({ diff }: { diff: string }) {
|
|
23
|
+
return (
|
|
24
|
+
<View style={{ gap: 2 }}>
|
|
25
|
+
{diff.split("\n").map((line, index) => {
|
|
26
|
+
const color = line.startsWith("+") ? PAPER.added
|
|
27
|
+
: line.startsWith("-") ? PAPER.removed
|
|
28
|
+
: PAPER.inkMuted;
|
|
29
|
+
return <Text key={index} selectable style={{ color, fontSize: 12, fontFamily: "Menlo" }}>{line}</Text>;
|
|
30
|
+
})}
|
|
31
|
+
</View>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function NotesOpCard({ item, layout }: PluginTimelineItemProps<NotesOp>) {
|
|
36
|
+
const [expanded, setExpanded] = useState(false);
|
|
37
|
+
const data = item.data;
|
|
38
|
+
const title = data.status === "running" ? OP_LABEL_RUNNING[data.op] : OP_LABEL[data.op];
|
|
39
|
+
const state = data.error !== undefined ? "failed"
|
|
40
|
+
: data.op === "write" ? data.outcome
|
|
41
|
+
: data.op === "update" ? CHANGE_LABEL[data.changeKind ?? ""] ?? data.changeKind
|
|
42
|
+
: undefined;
|
|
43
|
+
const footnotes: string[] = [];
|
|
44
|
+
if (data.renamedFrom !== undefined) footnotes.push(`renamed from ${data.renamedFrom}`);
|
|
45
|
+
if (data.diff !== undefined && data.truncated) footnotes.push("diff shortened for display");
|
|
46
|
+
const showEllipsis = data.truncated && data.diff === undefined;
|
|
47
|
+
const hasBody = Boolean(data.text || data.preview || data.diff || footnotes.length);
|
|
48
|
+
return (
|
|
49
|
+
<View style={{ paddingTop: 6 }}>
|
|
50
|
+
<View style={{
|
|
51
|
+
alignSelf: "flex-start", width: 84, height: 14, marginLeft: 28, marginBottom: -9, zIndex: 1,
|
|
52
|
+
backgroundColor: PAPER.tape, opacity: 0.9, borderRadius: 2,
|
|
53
|
+
transform: [{ rotate: "-2deg" }],
|
|
54
|
+
}} />
|
|
55
|
+
<View style={{
|
|
56
|
+
padding: layout.compact ? 10 : 12,
|
|
57
|
+
gap: 5,
|
|
58
|
+
minWidth: 0,
|
|
59
|
+
borderRadius: 4,
|
|
60
|
+
borderWidth: 1,
|
|
61
|
+
borderColor: PAPER.border,
|
|
62
|
+
backgroundColor: PAPER.background,
|
|
63
|
+
}}>
|
|
64
|
+
<View style={{ gap: 3 }}>
|
|
65
|
+
<View style={{ flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: 8 }}>
|
|
66
|
+
<Text style={{ color: PAPER.inkMuted, fontSize: 11, letterSpacing: 0.5 }}>
|
|
67
|
+
{title}{data.status === "running" ? " …" : ""}
|
|
68
|
+
</Text>
|
|
69
|
+
{hasBody && !expanded && <Pressable
|
|
70
|
+
accessibilityRole="button"
|
|
71
|
+
accessibilityLabel={`${expanded ? "收起" : "展开"} ${data.address}`}
|
|
72
|
+
aria-expanded={expanded}
|
|
73
|
+
onPress={() => setExpanded(value => !value)}
|
|
74
|
+
hitSlop={6}
|
|
75
|
+
style={({ pressed }) => ({ padding: 5, opacity: pressed ? 0.6 : 1 })}
|
|
76
|
+
>
|
|
77
|
+
<Icon name={expanded ? "ChevronUp" : "ChevronDown"} size={18} color={PAPER.inkMuted} />
|
|
78
|
+
</Pressable>}
|
|
79
|
+
</View>
|
|
80
|
+
<Text style={{ color: PAPER.ink, fontSize: 13, flexShrink: 1 }}>
|
|
81
|
+
{data.address}
|
|
82
|
+
{state !== undefined && <Text style={{ color: PAPER.inkMuted, fontSize: 12, fontWeight: "400" }}>{" "}{state}</Text>}
|
|
83
|
+
</Text>
|
|
84
|
+
</View>
|
|
85
|
+
{data.error !== undefined && <Text selectable style={{ color: PAPER.removed, fontSize: 13, lineHeight: 19 }}>{data.error}</Text>}
|
|
86
|
+
{expanded && hasBody && <ScrollView
|
|
87
|
+
style={{ maxHeight: layout.compact ? 280 : 400 }}
|
|
88
|
+
contentContainerStyle={{ gap: 5 }}
|
|
89
|
+
nestedScrollEnabled
|
|
90
|
+
>
|
|
91
|
+
{data.text !== undefined && <Text selectable style={{ color: PAPER.ink, fontSize: 13, lineHeight: 19 }}>{data.text}{showEllipsis && " …"}</Text>}
|
|
92
|
+
{data.preview !== undefined && <Text selectable style={{ color: PAPER.inkMuted, fontSize: 13, lineHeight: 19 }}>{data.preview}{showEllipsis && " …"}</Text>}
|
|
93
|
+
{data.diff !== undefined && <DiffBody diff={data.diff} />}
|
|
94
|
+
{footnotes.length > 0 && <Text style={{ color: PAPER.inkMuted, fontSize: 11 }}>{footnotes.join(" · ")}</Text>}
|
|
95
|
+
</ScrollView>}
|
|
96
|
+
{hasBody && expanded && <Pressable
|
|
97
|
+
accessibilityRole="button"
|
|
98
|
+
accessibilityLabel={`收起 ${data.address}`}
|
|
99
|
+
aria-expanded={true}
|
|
100
|
+
onPress={() => setExpanded(false)}
|
|
101
|
+
hitSlop={6}
|
|
102
|
+
style={({ pressed }) => ({ alignSelf: "flex-end", paddingHorizontal: 5, paddingVertical: 1, opacity: pressed ? 0.6 : 1 })}
|
|
103
|
+
>
|
|
104
|
+
<Icon name="ChevronUp" size={18} color={PAPER.inkMuted} />
|
|
105
|
+
</Pressable>}
|
|
106
|
+
</View>
|
|
107
|
+
</View>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -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;
|
|
@@ -2,20 +2,27 @@ import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
|
|
|
2
2
|
import { Text, View } from "react-native";
|
|
3
3
|
import type { LastWord } from "../shared/last-word.ts";
|
|
4
4
|
|
|
5
|
-
export function StickyCard({ item,
|
|
5
|
+
export function StickyCard({ item, layout }: PluginTimelineItemProps<LastWord>) {
|
|
6
6
|
const text = item.data.text.replace(/^\*You peel a sticky note off your forehead\.\*\n/, "");
|
|
7
7
|
return (
|
|
8
|
-
<View style={{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
<View style={{ paddingTop: 6 }}>
|
|
9
|
+
<View style={{
|
|
10
|
+
alignSelf: "flex-start", width: 84, height: 14, marginLeft: 28, marginBottom: -9, zIndex: 1,
|
|
11
|
+
backgroundColor: "#d8c98f", opacity: 0.9, borderRadius: 2,
|
|
12
|
+
transform: [{ rotate: "-2deg" }],
|
|
13
|
+
}} />
|
|
14
|
+
<View style={{
|
|
15
|
+
padding: layout.compact ? 10 : 12,
|
|
16
|
+
gap: 5,
|
|
17
|
+
minWidth: 0,
|
|
18
|
+
borderRadius: 4,
|
|
19
|
+
borderWidth: 1,
|
|
20
|
+
borderColor: "#d9cdaa",
|
|
21
|
+
backgroundColor: "#f7f2df",
|
|
22
|
+
}}>
|
|
23
|
+
<Text style={{ color: "#867c63", fontSize: 11, letterSpacing: 0.5 }}>LAST WORD</Text>
|
|
24
|
+
<Text selectable style={{ color: "#33301f", fontSize: 13, lineHeight: 19, flexShrink: 1 }}>{text}</Text>
|
|
25
|
+
</View>
|
|
19
26
|
</View>
|
|
20
27
|
);
|
|
21
28
|
}
|
|
@@ -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
|
}
|