notesoup 0.59.1 → 0.60.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -17
- package/dist/plugins/claude/src/helper.js +3 -4
- package/dist/plugins/codex/src/mcp.js +1 -2
- package/dist/plugins/dsh/tools.js +1 -2
- package/dist/plugins/pi/notes/tools.d.ts +1 -1
- package/dist/plugins/pi/notes/tools.js +2 -3
- package/dist/src/history/claude.d.ts +3 -1
- package/dist/src/history/claude.js +40 -4
- package/dist/src/history/history.d.ts +10 -11
- package/dist/src/history/history.js +8 -19
- package/dist/src/history/prefilter.d.ts +1 -1
- package/dist/src/history/prefilter.js +14 -9
- package/dist/src/history/query.d.ts +3 -14
- package/dist/src/history/query.js +73 -85
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/address.js +3 -3
- package/dist/src/notes/store.d.ts +2 -4
- package/dist/src/notes/store.js +1 -2
- package/dist/src/tools/history.d.ts +4 -6
- package/dist/src/tools/history.js +69 -29
- package/dist/src/tools/notes.d.ts +18 -78
- package/dist/src/tools/notes.js +39 -50
- package/dist/src/tools/schema.d.ts +0 -1
- package/dist/src/tools/schema.js +0 -1
- package/dist/test/claude-history.test.js +27 -6
- package/dist/test/claude-mod.test.js +19 -8
- package/dist/test/codex-history.test.js +1 -1
- package/dist/test/codex-plugin.test.js +1 -2
- package/dist/test/dependencies.test.js +2 -2
- package/dist/test/dsh.test.js +2 -2
- package/dist/test/history-corpus.test.js +21 -36
- package/dist/test/history-prefilter.test.js +5 -0
- package/dist/test/history-summary-cache.test.js +3 -3
- package/dist/test/history.integration.test.js +53 -106
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/note-policy.test.js +5 -5
- package/dist/test/notes-cwd.test.js +5 -5
- package/dist/test/notes-query-namespaces.test.js +2 -6
- package/dist/test/notes.integration.test.js +30 -35
- package/dist/test/notes.test.js +12 -14
- package/dist/test/project-namespace.test.js +3 -3
- package/docs/architecture.md +3 -3
- package/docs/claude-code-mod.md +5 -3
- package/docs/codex.md +1 -1
- package/docs/dsh.md +2 -2
- package/docs/history-sessions.md +9 -10
- package/docs/notes-library.md +3 -3
- package/docs/tool-results.md +12 -6
- package/package.json +1 -1
- package/plugins/claude/dist/claude/helper.js +214 -173
- package/plugins/claude/hooks/register.ts +8 -6
- package/plugins/claude/skills/memory/SKILL.md +6 -6
- package/plugins/claude/src/helper.ts +3 -4
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +176 -160
- package/plugins/codex/src/mcp.ts +1 -2
- package/plugins/dsh/tools.ts +1 -2
- package/plugins/paseo/README.md +16 -0
- package/plugins/paseo/client/brain-empty-card.tsx +5 -3
- package/plugins/paseo/client/markdown-core.tsx +189 -0
- package/plugins/paseo/client/markdown.tsx +38 -135
- package/plugins/paseo/client/notes-op-card.tsx +15 -12
- package/plugins/paseo/client/paper-card.tsx +1 -3
- package/plugins/paseo/client/sticky-card.tsx +2 -1
- package/plugins/paseo/client/typography.ts +24 -0
- package/plugins/paseo/test/markdown-core.test.ts +75 -0
- package/plugins/pi/notes/tools.ts +2 -3
- package/skills/memory/SKILL.md +6 -6
- package/src/history/claude.ts +31 -4
- package/src/history/history.ts +11 -16
- package/src/history/prefilter.ts +13 -9
- package/src/history/query.ts +67 -99
- package/src/index.ts +1 -1
- package/src/notes/address.ts +2 -2
- package/src/notes/store.ts +3 -6
- package/src/tools/history.ts +60 -29
- package/src/tools/notes.ts +39 -54
- package/src/tools/schema.ts +0 -1
package/plugins/dsh/tools.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { HarnessError } from "@deepseek-ai/dsh-llm";
|
|
|
4
4
|
import { defineTool, type JsonSchemaNode, type ObjectJsonSchema, type ToolRunContext } from "@deepseek-ai/dsh-tools";
|
|
5
5
|
import type { Static, TSchema } from "typebox";
|
|
6
6
|
import { Check, Errors } from "typebox/value";
|
|
7
|
-
import { notesList, notesRead,
|
|
7
|
+
import { notesList, notesRead, notesUpdate, notesWrite } from "../../src/tools/notes.js";
|
|
8
8
|
import { historyList, historyRead } from "../../src/tools/history.js";
|
|
9
9
|
import { success } from "../../src/result.js";
|
|
10
10
|
import type { Operation } from "../../src/tools/result.js";
|
|
@@ -75,7 +75,6 @@ export function registerTools(ctx: Context, engine: NotesoupCompactionEngine): v
|
|
|
75
75
|
register(ctx, notesUpdate, (agent) => [toolContext(agent)] as const);
|
|
76
76
|
register(ctx, notesRead, (agent) => [toolContext(agent)] as const);
|
|
77
77
|
register(ctx, notesList, (agent) => [toolContext(agent)] as const);
|
|
78
|
-
register(ctx, notesSearch, (agent) => [toolContext(agent)] as const);
|
|
79
78
|
register(ctx, historyList, (agent) => [historyContext(ctx, agent.session.id)] as const);
|
|
80
79
|
register(ctx, historyRead, (agent) => [historyContext(ctx, agent.session.id)] as const);
|
|
81
80
|
ctx.tools.register(defineTool({
|
package/plugins/paseo/README.md
CHANGED
|
@@ -10,3 +10,19 @@ npm test
|
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
Install this directory with `paseo plugin install /absolute/path/to/plugins/paseo`. Source changes require `paseo plugin reload notesoup`; no daemon restart is needed.
|
|
13
|
+
|
|
14
|
+
## Markdown maintenance
|
|
15
|
+
|
|
16
|
+
`client/markdown-core.tsx` and `test/markdown-core.test.ts` are manually mirrored,
|
|
17
|
+
byte-for-byte, between the Square and pi-context (notesoup) repositories at
|
|
18
|
+
`plugins/paseo/`. No shared package or cross-repository runtime import is needed.
|
|
19
|
+
When changing rendering behavior, copy both files to the other plugin and run
|
|
20
|
+
`npm test && npm run typecheck` in both plugin directories. Compare the files
|
|
21
|
+
with `diff -u` before delivery. Each `client/markdown.tsx` owns its palette and
|
|
22
|
+
wrapper; do not copy those adapters.
|
|
23
|
+
|
|
24
|
+
The core handles inline nesting, block structure, selectable text, safe `http(s)`/`mailto`
|
|
25
|
+
link presses, and horizontal code/table scrolling. Images render as alt text or `[image]`;
|
|
26
|
+
this is not the full Paseo assistant renderer. Tests inspect React elements with RN host
|
|
27
|
+
primitives, not native layout. Verify wrapping, selection and scrolling on iOS
|
|
28
|
+
before claiming visual or gesture correctness.
|
|
@@ -3,6 +3,7 @@ import { Modal } from "@getpaseo/plugin/client/react-native";
|
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { Pressable, Text, View } from "react-native";
|
|
5
5
|
import type { BrainEmpty } from "../shared/brain-empty.ts";
|
|
6
|
+
import { typography } from "./typography.ts";
|
|
6
7
|
|
|
7
8
|
function label(data: BrainEmpty): string {
|
|
8
9
|
if (data.status === "running") return "✂ emptying brain …";
|
|
@@ -27,6 +28,7 @@ function CutLine({ color }: { color: string }) {
|
|
|
27
28
|
export function BrainEmptyDivider({ item, theme }: PluginTimelineItemProps<BrainEmpty>) {
|
|
28
29
|
const [lastWordOpen, setLastWordOpen] = useState(false);
|
|
29
30
|
const data = item.data;
|
|
31
|
+
const type = typography(theme);
|
|
30
32
|
const refused = data.error !== undefined || data.status === "failed";
|
|
31
33
|
const color = refused ? theme.colors.statusDanger : theme.colors.foregroundMuted;
|
|
32
34
|
const hasLastWord = data.outcome === "rollover_requested" && data.lastWord !== undefined;
|
|
@@ -41,17 +43,17 @@ export function BrainEmptyDivider({ item, theme }: PluginTimelineItemProps<Brain
|
|
|
41
43
|
>
|
|
42
44
|
<View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
|
|
43
45
|
<CutLine color={color} />
|
|
44
|
-
<Text style={{
|
|
46
|
+
<Text style={{ ...type.sm, color, letterSpacing: 0.3 }}>{label(data)}</Text>
|
|
45
47
|
<CutLine color={color} />
|
|
46
48
|
</View>
|
|
47
49
|
{data.error !== undefined && (
|
|
48
|
-
<Text selectable style={{ color: theme.colors.statusDanger,
|
|
50
|
+
<Text selectable style={{ ...type.sm, color: theme.colors.statusDanger, textAlign: "center" }}>{data.error}</Text>
|
|
49
51
|
)}
|
|
50
52
|
</Pressable>
|
|
51
53
|
{hasLastWord && (
|
|
52
54
|
<Modal title="Last word" open={lastWordOpen} onOpenChange={setLastWordOpen}>
|
|
53
55
|
<Modal.Content style={{ backgroundColor: theme.colors.surface2 }}>
|
|
54
|
-
<Text selectable style={{ color: theme.colors.foreground
|
|
56
|
+
<Text selectable style={{ ...type.body, color: theme.colors.foreground }}>{data.lastWord}</Text>
|
|
55
57
|
</Modal.Content>
|
|
56
58
|
</Modal>
|
|
57
59
|
)}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Manually mirrored between square and pi-context (notesoup):
|
|
2
|
+
// plugins/paseo/client/markdown-core.tsx. Keep both copies byte-identical.
|
|
3
|
+
// Mechanics only: palettes, attribution and preview controls belong to the adapters.
|
|
4
|
+
import type { ReactNode } from "react";
|
|
5
|
+
import { Linking, ScrollView, Text, View, type TextStyle, type ViewStyle } from "react-native";
|
|
6
|
+
import { Lexer, type Token, type Tokens } from "marked";
|
|
7
|
+
|
|
8
|
+
export interface MarkdownStyles {
|
|
9
|
+
text: TextStyle;
|
|
10
|
+
strong: TextStyle;
|
|
11
|
+
em: TextStyle;
|
|
12
|
+
del: TextStyle;
|
|
13
|
+
link: TextStyle;
|
|
14
|
+
// Keep nested Text backgrounds square; rounded inline backgrounds are unreliable on iOS.
|
|
15
|
+
inlineCode: TextStyle;
|
|
16
|
+
heading: TextStyle;
|
|
17
|
+
quoteText: TextStyle;
|
|
18
|
+
codeText: TextStyle;
|
|
19
|
+
bullet: TextStyle;
|
|
20
|
+
tableCell: TextStyle;
|
|
21
|
+
codeBlock: ViewStyle;
|
|
22
|
+
codeContent: ViewStyle;
|
|
23
|
+
quote: ViewStyle;
|
|
24
|
+
separator: ViewStyle;
|
|
25
|
+
list: ViewStyle;
|
|
26
|
+
listRow: ViewStyle;
|
|
27
|
+
listItem: ViewStyle;
|
|
28
|
+
table: ViewStyle;
|
|
29
|
+
tableHead: ViewStyle;
|
|
30
|
+
tableRow: ViewStyle;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Children of a token, if it has any: `Token` is a union, so the optional field needs one cast. */
|
|
34
|
+
const children = (node: Token | { tokens?: Token[] }): Token[] => (node as { tokens?: Token[] }).tokens ?? [];
|
|
35
|
+
|
|
36
|
+
const ENTITIES: Record<string, string> = {
|
|
37
|
+
lt: "<", gt: ">", quot: '"', apos: "'", amp: "&", nbsp: "\u00a0", mdash: "—", ndash: "–",
|
|
38
|
+
};
|
|
39
|
+
const HTML_BR = /^<br\s*\/?>$/i;
|
|
40
|
+
const SAFE_LINK = /^(?:https?:|mailto:)/i;
|
|
41
|
+
|
|
42
|
+
function unescape(text: string): string {
|
|
43
|
+
return text.replace(/&(?:#(\d+)|#x([0-9a-fA-F]+)|([a-zA-Z0-9]+));/g, (raw, dec?: string, hex?: string, named?: string) => {
|
|
44
|
+
if (dec !== undefined || hex !== undefined) {
|
|
45
|
+
const code = Number.parseInt((dec ?? hex)!, dec !== undefined ? 10 : 16);
|
|
46
|
+
return code > 0 && code <= 0x10ffff && (code < 0xd800 || code > 0xdfff) ? String.fromCodePoint(code) : raw;
|
|
47
|
+
}
|
|
48
|
+
return ENTITIES[named!] ?? raw;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function linkPress(href: string, openLinks: boolean): (() => void) | undefined {
|
|
53
|
+
const url = unescape(href);
|
|
54
|
+
return openLinks && SAFE_LINK.test(url) ? () => { void Promise.resolve(Linking.openURL(url)).catch(() => {}); } : undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function inlinePlain(tokens: Token[]): string {
|
|
58
|
+
return tokens.map(token => {
|
|
59
|
+
switch (token.type) {
|
|
60
|
+
case "checkbox": return "";
|
|
61
|
+
case "br": return "\n";
|
|
62
|
+
case "html": return HTML_BR.test(token.raw.trim()) ? "\n" : token.raw;
|
|
63
|
+
case "codespan": return token.text;
|
|
64
|
+
case "image": return inlinePlain(children(token)) || token.text || "[image]";
|
|
65
|
+
default: {
|
|
66
|
+
const inline = token as Tokens.Generic;
|
|
67
|
+
return inline.tokens !== undefined ? inlinePlain(inline.tokens) : unescape(inline.text ?? inline.raw);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}).join("");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function cellWidth(cell: Tokens.TableCell | undefined): number {
|
|
74
|
+
if (!cell) return 56;
|
|
75
|
+
const widest = Math.max(...inlinePlain(children(cell)).split("\n").map(line =>
|
|
76
|
+
[...line].reduce((sum, ch) => sum + (ch.codePointAt(0)! > 0x2e7f ? 14 : 7.5), 16)));
|
|
77
|
+
return Math.min(240, Math.max(56, widest));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Inline runs nest inside their block's Text, so they carry only what differs from it. */
|
|
81
|
+
export function renderInlines(tokens: Token[], styles: MarkdownStyles, prefix: string, openLinks = false): ReactNode[] {
|
|
82
|
+
return tokens.map((token, index) => {
|
|
83
|
+
const key = `${prefix}-${index}`;
|
|
84
|
+
const nested = (style?: TextStyle, onPress?: () => void): ReactNode => (
|
|
85
|
+
<Text key={key} style={style} onPress={onPress}>{renderInlines(children(token), styles, key, openLinks)}</Text>
|
|
86
|
+
);
|
|
87
|
+
switch (token.type) {
|
|
88
|
+
case "checkbox": return null;
|
|
89
|
+
case "strong": return nested(styles.strong);
|
|
90
|
+
case "em": return nested(styles.em);
|
|
91
|
+
case "del": return nested(styles.del);
|
|
92
|
+
case "link": return nested(styles.link, linkPress((token as Tokens.Link).href, openLinks));
|
|
93
|
+
case "codespan": return <Text key={key} style={styles.inlineCode}>{token.text}</Text>;
|
|
94
|
+
case "br": return "\n";
|
|
95
|
+
case "html": return HTML_BR.test(token.raw.trim()) ? "\n" : token.raw;
|
|
96
|
+
case "image": {
|
|
97
|
+
const image = token as Tokens.Image;
|
|
98
|
+
const label = inlinePlain(children(image)) || image.text || "[image]";
|
|
99
|
+
return <Text key={key} style={styles.link} onPress={linkPress(image.href, openLinks)}>{label}</Text>;
|
|
100
|
+
}
|
|
101
|
+
default: {
|
|
102
|
+
const inline = token as Tokens.Generic;
|
|
103
|
+
if (inline.tokens !== undefined) return nested();
|
|
104
|
+
return unescape(inline.text ?? inline.raw);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function renderBlocks(tokens: Token[], styles: MarkdownStyles, prefix: string, textStyle?: TextStyle, openLinks = true): ReactNode[] {
|
|
111
|
+
const visible = tokens.filter(token =>
|
|
112
|
+
token.type !== "space" && token.type !== "checkbox" && token.type !== "def"
|
|
113
|
+
&& !(token.type === "html" && HTML_BR.test(token.raw.trim())));
|
|
114
|
+
return visible.map((token, index) => {
|
|
115
|
+
const key = `${prefix}-${index}`;
|
|
116
|
+
switch (token.type) {
|
|
117
|
+
case "html":
|
|
118
|
+
return <Text key={key} selectable style={[styles.text, textStyle]}>{token.raw}</Text>;
|
|
119
|
+
case "hr":
|
|
120
|
+
return <View key={key} style={styles.separator} />;
|
|
121
|
+
case "code":
|
|
122
|
+
return (
|
|
123
|
+
<ScrollView key={key} horizontal style={styles.codeBlock} contentContainerStyle={styles.codeContent}>
|
|
124
|
+
<Text selectable style={styles.codeText}>{token.text}</Text>
|
|
125
|
+
</ScrollView>
|
|
126
|
+
);
|
|
127
|
+
case "heading": {
|
|
128
|
+
// Headings sit closer to the section they introduce than to whatever preceded them.
|
|
129
|
+
const rhythm = { marginTop: index > 0 ? 4 : 0, marginBottom: index < visible.length - 1 ? -2 : 0 };
|
|
130
|
+
return (
|
|
131
|
+
<Text key={key} selectable style={[styles.text, textStyle, styles.heading, rhythm]}>
|
|
132
|
+
{renderInlines(children(token), styles, key, openLinks)}
|
|
133
|
+
</Text>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
case "blockquote":
|
|
137
|
+
return <View key={key} style={styles.quote}>{renderBlocks(children(token), styles, key, styles.quoteText, openLinks)}</View>;
|
|
138
|
+
case "list": {
|
|
139
|
+
const list = token as Tokens.List;
|
|
140
|
+
const start = typeof list.start === "number" ? list.start : 1;
|
|
141
|
+
return (
|
|
142
|
+
<View key={key} style={styles.list}>
|
|
143
|
+
{list.items.map((item, itemIndex) => (
|
|
144
|
+
<View key={`${key}-${itemIndex}`} style={styles.listRow}>
|
|
145
|
+
<Text style={styles.bullet}>
|
|
146
|
+
{item.task ? (item.checked === true ? "☑" : "☐") : list.ordered ? `${start + itemIndex}.` : "•"}
|
|
147
|
+
</Text>
|
|
148
|
+
<View style={styles.listItem}>{renderBlocks(children(item), styles, `${key}-${itemIndex}`, textStyle, openLinks)}</View>
|
|
149
|
+
</View>
|
|
150
|
+
))}
|
|
151
|
+
</View>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
case "table": {
|
|
155
|
+
const table = token as Tokens.Table;
|
|
156
|
+
const rows = [table.header, ...table.rows];
|
|
157
|
+
// Columns size to their widest cell (within reason) and the table scrolls sideways
|
|
158
|
+
// on narrow screens instead of crushing every cell to a sliver.
|
|
159
|
+
const widths = table.header.map((_, column) => Math.max(...rows.map(cells => cellWidth(cells[column]))));
|
|
160
|
+
return (
|
|
161
|
+
<ScrollView key={key} horizontal>
|
|
162
|
+
<View style={styles.table}>
|
|
163
|
+
{rows.map((cells, rowIndex) => (
|
|
164
|
+
<View key={`${key}-${rowIndex}`} style={rowIndex === 0 ? [styles.tableRow, styles.tableHead, { borderTopWidth: 0 }] : styles.tableRow}>
|
|
165
|
+
{cells.map((cell, cellIndex) => (
|
|
166
|
+
<Text
|
|
167
|
+
key={`${key}-${rowIndex}-${cellIndex}`}
|
|
168
|
+
selectable
|
|
169
|
+
style={[styles.text, textStyle, styles.tableCell, { width: widths[cellIndex], textAlign: table.align[cellIndex] ?? "left" },
|
|
170
|
+
rowIndex === 0 ? styles.strong : undefined]}
|
|
171
|
+
>{renderInlines(children(cell), styles, `${key}-${rowIndex}-${cellIndex}`, openLinks)}</Text>
|
|
172
|
+
))}
|
|
173
|
+
</View>
|
|
174
|
+
))}
|
|
175
|
+
</View>
|
|
176
|
+
</ScrollView>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
default: {
|
|
180
|
+
const block = token as Tokens.Generic;
|
|
181
|
+
return (
|
|
182
|
+
<Text key={key} selectable style={[styles.text, textStyle]}>
|
|
183
|
+
{renderInlines(block.tokens ?? Lexer.lexInline(block.text ?? block.raw), styles, key, openLinks)}
|
|
184
|
+
</Text>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
@@ -1,160 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { Lexer, lexer } from "marked";
|
|
3
|
+
import { renderBlocks, renderInlines, type MarkdownStyles } from "./markdown-core.tsx";
|
|
3
4
|
import { StyleSheet, Text, View, type TextStyle, type ViewStyle } from "react-native";
|
|
4
|
-
import { MONO } from "./paper-card.tsx";
|
|
5
5
|
import type { PaperPalette } from "./paper-palette.ts";
|
|
6
|
+
import type { Typography } from "./typography.ts";
|
|
6
7
|
|
|
7
|
-
type Styles = {
|
|
8
|
-
block: ViewStyle;
|
|
9
|
-
text: TextStyle; muted: TextStyle; strong: TextStyle; em: TextStyle; del: TextStyle;
|
|
10
|
-
codespan: TextStyle; link: TextStyle; heading: TextStyle; quoteText: TextStyle;
|
|
11
|
-
code: TextStyle; marker: TextStyle; tableCell: TextStyle;
|
|
12
|
-
quote: ViewStyle; hr: ViewStyle; list: ViewStyle; listItem: ViewStyle;
|
|
13
|
-
table: ViewStyle; tableRow: ViewStyle;
|
|
14
|
-
};
|
|
8
|
+
type Styles = MarkdownStyles & { block: ViewStyle; muted: TextStyle };
|
|
15
9
|
|
|
16
|
-
function markdownStyles(paper: PaperPalette): Styles {
|
|
10
|
+
function markdownStyles(paper: PaperPalette, type: Typography): Styles {
|
|
11
|
+
const hairline = { borderWidth: StyleSheet.hairlineWidth, borderColor: paper.edge };
|
|
17
12
|
return {
|
|
18
13
|
block: { gap: 8 },
|
|
19
|
-
text: { color: paper.ink
|
|
20
|
-
muted: { color: paper.inkMuted
|
|
14
|
+
text: { ...type.body, color: paper.ink },
|
|
15
|
+
muted: { ...type.body, color: paper.inkMuted },
|
|
21
16
|
strong: { fontWeight: "600" },
|
|
22
|
-
em: {
|
|
17
|
+
em: { fontStyle: "italic" },
|
|
23
18
|
del: { color: paper.inkMuted, textDecorationLine: "line-through" },
|
|
24
|
-
|
|
19
|
+
// No borderRadius here: nested rounded Text backgrounds paint a wrapped slab on iOS Fabric.
|
|
20
|
+
// A faint ink wash keeps flush glyph edges gentle and stays visible on crumpled paper too.
|
|
21
|
+
inlineCode: { ...type.inlineCode, backgroundColor: `${paper.ink}10` },
|
|
25
22
|
link: { color: paper.added, textDecorationLine: "underline" },
|
|
26
|
-
heading: { fontWeight: "600" },
|
|
27
|
-
quote: { borderLeftWidth: 2, borderLeftColor: paper.edge, paddingLeft: 10, gap: 4
|
|
28
|
-
quoteText: { color: paper.inkMuted
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
listItem: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
heading: { ...type.base, fontWeight: "600", color: paper.ink, letterSpacing: -0.1 },
|
|
24
|
+
quote: { borderLeftWidth: 2, borderLeftColor: paper.edge, paddingLeft: 10, gap: 4 },
|
|
25
|
+
quoteText: { color: paper.inkMuted },
|
|
26
|
+
codeBlock: { ...hairline, backgroundColor: paper.crumpled, borderRadius: 4 },
|
|
27
|
+
codeContent: { paddingVertical: 6, paddingHorizontal: 8 },
|
|
28
|
+
codeText: { ...type.code, color: paper.ink },
|
|
29
|
+
separator: { height: StyleSheet.hairlineWidth, backgroundColor: paper.edge, marginVertical: 2 },
|
|
30
|
+
list: { gap: 4 },
|
|
31
|
+
listRow: { flexDirection: "row" },
|
|
32
|
+
listItem: { flex: 1, gap: 4 },
|
|
33
|
+
bullet: { ...type.body, color: paper.inkMuted, minWidth: 18, paddingRight: 6,
|
|
34
|
+
textAlign: "right", fontVariant: ["tabular-nums"] },
|
|
35
|
+
table: { ...hairline, borderRadius: 4, overflow: "hidden" },
|
|
36
|
+
tableHead: { backgroundColor: paper.crumpled },
|
|
37
|
+
tableRow: { flexDirection: "row", borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: paper.edge },
|
|
38
|
+
tableCell: { paddingVertical: 4, paddingHorizontal: 8 },
|
|
40
39
|
};
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
function renderInlines(tokens: Token[] | undefined, styles: Styles, keyPrefix: string): ReactNode[] {
|
|
45
|
-
if (!tokens) return [];
|
|
46
|
-
return tokens.map((token, index) => {
|
|
47
|
-
const key = `${keyPrefix}.${index}`;
|
|
48
|
-
switch (token.type) {
|
|
49
|
-
case "strong":
|
|
50
|
-
return <Text key={key} style={styles.strong}>{renderInlines(token.tokens, styles, key)}</Text>;
|
|
51
|
-
case "em":
|
|
52
|
-
return <Text key={key} style={styles.em}>{renderInlines(token.tokens, styles, key)}</Text>;
|
|
53
|
-
case "del":
|
|
54
|
-
return <Text key={key} style={styles.del}>{renderInlines(token.tokens, styles, key)}</Text>;
|
|
55
|
-
case "codespan":
|
|
56
|
-
return <Text key={key} style={styles.codespan}>{token.text}</Text>;
|
|
57
|
-
case "link":
|
|
58
|
-
return <Text key={key} style={styles.link}>{renderInlines(token.tokens, styles, key)}</Text>;
|
|
59
|
-
case "br":
|
|
60
|
-
return "\n";
|
|
61
|
-
case "image":
|
|
62
|
-
return <Text key={key} style={styles.link}>{token.text}</Text>;
|
|
63
|
-
default: {
|
|
64
|
-
const nested = (token as Tokens.Generic).tokens;
|
|
65
|
-
if (nested?.length) return <Text key={key}>{renderInlines(nested, styles, key)}</Text>;
|
|
66
|
-
const { text } = token as Tokens.Text;
|
|
67
|
-
return text ?? token.raw;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function renderListItem(item: Tokens.ListItem, marker: string, key: string, styles: Styles, textStyle: TextStyle): ReactNode {
|
|
74
|
-
return (
|
|
75
|
-
<View key={key} style={styles.listItem}>
|
|
76
|
-
<Text style={[styles.marker, textStyle]}>{item.task ? (item.checked ? "☑" : "☐") : marker}</Text>
|
|
77
|
-
<View style={{ flex: 1, gap: 4 }}>{renderBlocks(item.tokens, styles, key, textStyle)}</View>
|
|
78
|
-
</View>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function renderBlocks(tokens: Token[] | undefined, styles: Styles, keyPrefix: string, textStyle: TextStyle): ReactNode[] {
|
|
83
|
-
if (!tokens) return [];
|
|
84
|
-
return tokens.map((token, index) => {
|
|
85
|
-
const key = `${keyPrefix}.${index}`;
|
|
86
|
-
switch (token.type) {
|
|
87
|
-
case "space":
|
|
88
|
-
case "checkbox":
|
|
89
|
-
case "def":
|
|
90
|
-
return null;
|
|
91
|
-
case "hr":
|
|
92
|
-
return <View key={key} style={styles.hr} />;
|
|
93
|
-
case "code":
|
|
94
|
-
return <Text key={key} selectable style={styles.code}>{token.text}</Text>;
|
|
95
|
-
case "heading":
|
|
96
|
-
return <Text key={key} selectable style={[textStyle, styles.heading,
|
|
97
|
-
{ marginTop: index === 0 ? 2 : token.depth === 1 ? 2 : 6 }]}>{renderInlines(token.tokens, styles, key)}</Text>;
|
|
98
|
-
case "blockquote":
|
|
99
|
-
return <View key={key} style={styles.quote}>{renderBlocks(token.tokens, styles, key, styles.quoteText)}</View>;
|
|
100
|
-
case "list": {
|
|
101
|
-
const list = token as Tokens.List;
|
|
102
|
-
const start = typeof list.start === "number" ? list.start : 1;
|
|
103
|
-
return (
|
|
104
|
-
<View key={key} style={styles.list}>
|
|
105
|
-
{list.items.map((item, itemIndex) =>
|
|
106
|
-
renderListItem(item, list.ordered ? `${start + itemIndex}.` : "•", `${key}.${itemIndex}`, styles, textStyle))}
|
|
107
|
-
</View>
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
case "table": {
|
|
111
|
-
const table = token as Tokens.Table;
|
|
112
|
-
return (
|
|
113
|
-
<View key={key} style={styles.table}>
|
|
114
|
-
{[table.header, ...table.rows].map((row, rowIndex) => (
|
|
115
|
-
<View key={`${key}.${rowIndex}`} style={styles.tableRow}>
|
|
116
|
-
{row.map((cell, cellIndex) => (
|
|
117
|
-
<Text
|
|
118
|
-
key={`${key}.${rowIndex}.${cellIndex}`}
|
|
119
|
-
selectable
|
|
120
|
-
style={[textStyle, styles.tableCell, { textAlign: cell.align ?? "left" }, cell.header && styles.strong]}
|
|
121
|
-
>
|
|
122
|
-
{renderInlines(cell.tokens, styles, `${key}.${rowIndex}.${cellIndex}`)}
|
|
123
|
-
</Text>
|
|
124
|
-
))}
|
|
125
|
-
</View>
|
|
126
|
-
))}
|
|
127
|
-
</View>
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
default: {
|
|
131
|
-
const generic = token as Tokens.Generic;
|
|
132
|
-
return (
|
|
133
|
-
<Text key={key} selectable style={textStyle}>
|
|
134
|
-
{generic.tokens?.length ? renderInlines(generic.tokens, styles, key) : generic.text ?? generic.raw}
|
|
135
|
-
</Text>
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function NoteInline({ text, paper, color, numberOfLines }: {
|
|
42
|
+
export function NoteInline({ text, paper, type, color, numberOfLines }: {
|
|
143
43
|
text: string;
|
|
144
44
|
paper: PaperPalette;
|
|
45
|
+
type: Typography;
|
|
145
46
|
color?: string;
|
|
146
47
|
numberOfLines?: number;
|
|
147
48
|
}) {
|
|
148
|
-
const styles = markdownStyles(paper);
|
|
49
|
+
const styles = useMemo(() => markdownStyles(paper, type), [paper, type]);
|
|
50
|
+
const tokens = useMemo(() => Lexer.lexInline(text), [text]);
|
|
149
51
|
return (
|
|
150
52
|
<Text numberOfLines={numberOfLines} style={{ ...styles.text, color: color ?? paper.ink }}>
|
|
151
|
-
{renderInlines(
|
|
53
|
+
{renderInlines(tokens, styles, "inline")}
|
|
152
54
|
</Text>
|
|
153
55
|
);
|
|
154
56
|
}
|
|
155
57
|
|
|
156
|
-
export function NoteMarkdown({ text, paper, muted = false }: { text: string; paper: PaperPalette; muted?: boolean }) {
|
|
157
|
-
const styles = markdownStyles(paper);
|
|
58
|
+
export function NoteMarkdown({ text, paper, type, muted = false }: { text: string; paper: PaperPalette; type: Typography; muted?: boolean }) {
|
|
59
|
+
const styles = useMemo(() => markdownStyles(paper, type), [paper, type]);
|
|
60
|
+
const tokens = useMemo(() => lexer(text), [text]);
|
|
158
61
|
const textStyle = muted ? styles.muted : styles.text;
|
|
159
|
-
return <View style={styles.block}>{renderBlocks(
|
|
62
|
+
return <View style={styles.block}>{renderBlocks(tokens, styles, "block", textStyle)}</View>;
|
|
160
63
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
|
|
2
2
|
import { Icon } from "@getpaseo/plugin/client/react-native";
|
|
3
|
-
import { useState } from "react";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
4
|
import { Pressable, ScrollView, Text, View } from "react-native";
|
|
5
5
|
import { COLLAPSED_PREVIEW_MAX_CHARS, outputPreview, type NotesOp } from "../shared/notes-op.ts";
|
|
6
6
|
import { NoteInline, NoteMarkdown } from "./markdown.tsx";
|
|
7
|
-
import {
|
|
7
|
+
import { PaperCard } from "./paper-card.tsx";
|
|
8
8
|
import { paperPalette, type PaperPalette } from "./paper-palette.ts";
|
|
9
|
+
import { typography, type Typography } from "./typography.ts";
|
|
9
10
|
|
|
10
11
|
const OP_LABEL: Record<NotesOp["op"], string> = { read: "read", write: "wrote", update: "edited" };
|
|
11
12
|
const OP_LABEL_RUNNING: Record<NotesOp["op"], string> = { read: "reading", write: "writing", update: "editing" };
|
|
@@ -15,7 +16,7 @@ function addedLine(diff: string): string | undefined {
|
|
|
15
16
|
return /^\+.*/m.exec(diff)?.[0].replace(/^\+(?:\s*\d+\s+\+|\s*\d+)?\s?/, "");
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
function DiffBody({ diff, paper }: { diff: string; paper: PaperPalette }) {
|
|
19
|
+
function DiffBody({ diff, paper, style }: { diff: string; paper: PaperPalette; style: Typography["code"] }) {
|
|
19
20
|
const runs: { color: string; lines: string[] }[] = [];
|
|
20
21
|
for (const line of diff.split("\n")) {
|
|
21
22
|
const color = line.startsWith("+") ? paper.added : line.startsWith("-") ? paper.removed : paper.inkMuted;
|
|
@@ -24,7 +25,7 @@ function DiffBody({ diff, paper }: { diff: string; paper: PaperPalette }) {
|
|
|
24
25
|
else runs.push({ color, lines: [line] });
|
|
25
26
|
}
|
|
26
27
|
return (
|
|
27
|
-
<Text selectable style={
|
|
28
|
+
<Text selectable style={style}>
|
|
28
29
|
{runs.map((run, index) => <Text key={index} style={{ color: run.color }}>{index > 0 ? "\n" : ""}{run.lines.join("\n")}</Text>)}
|
|
29
30
|
</Text>
|
|
30
31
|
);
|
|
@@ -33,6 +34,7 @@ function DiffBody({ diff, paper }: { diff: string; paper: PaperPalette }) {
|
|
|
33
34
|
export function NotesOpCard({ item, layout, theme }: PluginTimelineItemProps<NotesOp>) {
|
|
34
35
|
const [expanded, setExpanded] = useState(false);
|
|
35
36
|
const paper = paperPalette(theme);
|
|
37
|
+
const type = useMemo(() => typography(theme), [theme]);
|
|
36
38
|
const data = item.data;
|
|
37
39
|
const title = data.status === "running" ? OP_LABEL_RUNNING[data.op] : OP_LABEL[data.op];
|
|
38
40
|
const hasBody = Boolean(data.text || data.preview || data.diff);
|
|
@@ -51,30 +53,31 @@ export function NotesOpCard({ item, layout, theme }: PluginTimelineItemProps<Not
|
|
|
51
53
|
style={({ pressed }) => ({ gap: 4, opacity: pressed && hasBody ? 0.7 : 1 })}
|
|
52
54
|
>
|
|
53
55
|
<View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
|
|
54
|
-
<Text style={{ color: paper.inkMuted
|
|
56
|
+
<Text style={{ ...type.sm, color: paper.inkMuted }}>
|
|
55
57
|
{data.crumpled ? "crumpled" : title}{data.status === "running" ? " …" : ""}
|
|
56
58
|
</Text>
|
|
57
|
-
<Text numberOfLines={1} style={{ color: data.crumpled ? paper.inkMuted : paper.ink,
|
|
59
|
+
<Text numberOfLines={1} style={{ ...type.base, color: data.crumpled ? paper.inkMuted : paper.ink, flex: 1, textDecorationLine: data.crumpled ? "line-through" : "none" }}>
|
|
58
60
|
{data.address}
|
|
59
61
|
</Text>
|
|
60
|
-
{hasBody && <Icon name={expanded ? "ChevronUp" : "ChevronDown"} size={
|
|
62
|
+
{hasBody && <Icon name={expanded ? "ChevronUp" : "ChevronDown"} size={12} color={paper.inkMuted} />}
|
|
61
63
|
</View>
|
|
62
64
|
{peek !== undefined && (
|
|
63
65
|
<NoteInline
|
|
64
66
|
text={`${data.diff !== undefined ? "+ " : ""}${outputPreview(peek, COLLAPSED_PREVIEW_MAX_CHARS).replace(/\s+/g, " ")}`}
|
|
65
67
|
paper={paper}
|
|
68
|
+
type={type}
|
|
66
69
|
color={data.diff !== undefined ? paper.added : paper.ink}
|
|
67
70
|
numberOfLines={2}
|
|
68
71
|
/>
|
|
69
72
|
)}
|
|
70
|
-
{data.error !== undefined && <Text selectable style={{ color: paper.removed
|
|
73
|
+
{data.error !== undefined && <Text selectable style={{ ...type.sm, color: paper.removed }}>{data.error}</Text>}
|
|
71
74
|
</Pressable>
|
|
72
75
|
{expanded && hasBody && (
|
|
73
76
|
<ScrollView style={{ maxHeight: layout.compact ? 280 : 400, marginTop: 2, borderTopWidth: 1, borderTopColor: paper.edge }} contentContainerStyle={{ gap: 5, paddingTop: 8 }} nestedScrollEnabled>
|
|
74
|
-
{data.text !== undefined && <NoteMarkdown text={outputPreview(data.text)} paper={paper} />}
|
|
75
|
-
{data.preview !== undefined && <NoteMarkdown text={outputPreview(data.preview)} paper={paper} />}
|
|
76
|
-
{data.diff !== undefined && <DiffBody diff={outputPreview(data.diff)} paper={paper} />}
|
|
77
|
-
{data.renamedFrom !== undefined && <Text style={{ color: paper.inkMuted
|
|
77
|
+
{data.text !== undefined && <NoteMarkdown text={outputPreview(data.text)} paper={paper} type={type} />}
|
|
78
|
+
{data.preview !== undefined && <NoteMarkdown text={outputPreview(data.preview)} paper={paper} type={type} />}
|
|
79
|
+
{data.diff !== undefined && <DiffBody diff={outputPreview(data.diff)} paper={paper} style={type.code} />}
|
|
80
|
+
{data.renamedFrom !== undefined && <Text style={{ ...type.sm, color: paper.inkMuted }}>renamed from {data.renamedFrom}</Text>}
|
|
78
81
|
</ScrollView>
|
|
79
82
|
)}
|
|
80
83
|
</PaperCard>
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
3
|
import type { PaperPalette } from "./paper-palette.ts";
|
|
4
4
|
|
|
5
|
-
export const MONO = Platform.select({ ios: "Menlo", android: "monospace", default: "ui-monospace, Menlo, monospace" });
|
|
6
|
-
|
|
7
5
|
function Tape({ paper }: { paper: PaperPalette }) {
|
|
8
6
|
return (
|
|
9
7
|
<View style={{
|
|
@@ -3,13 +3,14 @@ import { Text } from "react-native";
|
|
|
3
3
|
import type { LastWord } from "../shared/last-word.ts";
|
|
4
4
|
import { PaperCard } from "./paper-card.tsx";
|
|
5
5
|
import { paperPalette } from "./paper-palette.ts";
|
|
6
|
+
import { typography } from "./typography.ts";
|
|
6
7
|
|
|
7
8
|
export function StickyCard({ item, layout, theme }: PluginTimelineItemProps<LastWord>) {
|
|
8
9
|
const paper = paperPalette(theme);
|
|
9
10
|
const text = item.data.text.replace(/^\*You peel a sticky note off your forehead\.\*\n/, "");
|
|
10
11
|
return (
|
|
11
12
|
<PaperCard paper={paper} compact={layout.compact}>
|
|
12
|
-
<Text selectable style={{ color: paper.ink,
|
|
13
|
+
<Text selectable style={{ ...typography(theme).body, color: paper.ink, flexShrink: 1 }}>{text}</Text>
|
|
13
14
|
</PaperCard>
|
|
14
15
|
);
|
|
15
16
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PluginTheme } from "@getpaseo/plugin";
|
|
2
|
+
import { Platform } from "react-native";
|
|
3
|
+
|
|
4
|
+
type ThemeTypography = {
|
|
5
|
+
fontSize?: Partial<Record<"sm" | "base" | "code", number>>;
|
|
6
|
+
fontFamily?: Partial<Record<"ui" | "mono", string>>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const MONO = Platform.select({ ios: "Menlo", android: "monospace", default: "ui-monospace, Menlo, monospace" });
|
|
10
|
+
const lineHeight = (size: number, ratio: number) => Math.round(size * ratio * 2) / 2;
|
|
11
|
+
|
|
12
|
+
export function typography(theme: PluginTheme) {
|
|
13
|
+
// The host can supply these roles before the SDK exposes them (#6600).
|
|
14
|
+
const { fontSize, fontFamily } = (theme as PluginTheme & { typography?: ThemeTypography }).typography ?? {};
|
|
15
|
+
const text = (size: number) => ({ fontSize: size, lineHeight: lineHeight(size, 1.5), fontFamily: fontFamily?.ui });
|
|
16
|
+
const size = fontSize?.code ?? 13;
|
|
17
|
+
const inlineCode = { fontSize: size, fontFamily: fontFamily?.mono ?? MONO };
|
|
18
|
+
return {
|
|
19
|
+
sm: text(fontSize?.sm ?? 11.5), base: text(fontSize?.base ?? 13), body: text(size),
|
|
20
|
+
inlineCode, code: { ...inlineCode, lineHeight: lineHeight(size, 1.4) },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Typography = ReturnType<typeof typography>;
|