notesoup 0.53.1 → 0.54.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.
Files changed (153) hide show
  1. package/README.md +2 -2
  2. package/dist/plugins/claude/src/helper.js +2 -1
  3. package/dist/plugins/claude/src/history.js +2 -3
  4. package/dist/plugins/claude/src/thresholds.js +4 -2
  5. package/dist/plugins/codex/src/hooks.js +1 -1
  6. package/dist/plugins/codex/src/identity.d.ts +1 -1
  7. package/dist/plugins/codex/src/identity.js +3 -3
  8. package/dist/plugins/codex/src/mcp.js +2 -1
  9. package/dist/plugins/codex/src/text.d.ts +1 -1
  10. package/dist/plugins/codex/src/text.js +2 -2
  11. package/dist/plugins/dsh/engine.js +2 -2
  12. package/dist/plugins/dsh/tools.js +8 -7
  13. package/dist/plugins/dsh/window.d.ts +1 -0
  14. package/dist/plugins/dsh/window.js +7 -3
  15. package/dist/plugins/pi/entries.d.ts +1 -0
  16. package/dist/plugins/pi/entries.js +1 -0
  17. package/dist/plugins/pi/history-tools.d.ts +1 -1
  18. package/dist/plugins/pi/history-tools.js +4 -4
  19. package/dist/plugins/pi/marker.d.ts +9 -0
  20. package/dist/plugins/pi/marker.js +36 -0
  21. package/dist/plugins/pi/notes/tools.js +8 -6
  22. package/dist/plugins/pi/render.js +7 -4
  23. package/dist/plugins/pi/reset/artifacts.d.ts +2 -2
  24. package/dist/plugins/pi/reset/artifacts.js +2 -2
  25. package/dist/plugins/pi/runtime.js +11 -8
  26. package/dist/plugins/pi/text.d.ts +2 -0
  27. package/dist/plugins/pi/text.js +4 -0
  28. package/dist/plugins/pi/window.js +21 -7
  29. package/dist/src/boot/render.js +7 -7
  30. package/dist/src/boot/snapshot.d.ts +7 -7
  31. package/dist/src/boot/snapshot.js +17 -17
  32. package/dist/src/boot/text.d.ts +2 -2
  33. package/dist/src/boot/text.js +7 -5
  34. package/dist/src/dream/git.d.ts +2 -11
  35. package/dist/src/dream/git.js +6 -23
  36. package/dist/src/dream/lock.d.ts +2 -2
  37. package/dist/src/dream/lock.js +3 -3
  38. package/dist/src/index.d.ts +2 -1
  39. package/dist/src/index.js +3 -2
  40. package/dist/src/notes/address.d.ts +8 -8
  41. package/dist/src/notes/address.js +13 -13
  42. package/dist/src/notes/errors.d.ts +1 -1
  43. package/dist/src/notes/frontmatter.js +2 -2
  44. package/dist/src/notes/index.d.ts +1 -1
  45. package/dist/src/notes/index.js +1 -1
  46. package/dist/src/notes/paths.d.ts +6 -6
  47. package/dist/src/notes/paths.js +9 -9
  48. package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
  49. package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
  50. package/dist/src/notes/store.d.ts +4 -4
  51. package/dist/src/notes/store.js +55 -52
  52. package/dist/src/tools/dream.d.ts +21 -3
  53. package/dist/src/tools/dream.js +54 -16
  54. package/dist/src/tools/notes-context.d.ts +10 -0
  55. package/dist/src/tools/notes-context.js +27 -0
  56. package/dist/src/tools/notes.d.ts +69 -20
  57. package/dist/src/tools/notes.js +40 -31
  58. package/dist/test/agent-loop.test.js +8 -8
  59. package/dist/test/boot.integration.test.js +5 -5
  60. package/dist/test/claude-history.test.js +26 -0
  61. package/dist/test/claude-mod.test.js +257 -86
  62. package/dist/test/codex-plugin.test.js +18 -1
  63. package/dist/test/context-edit-budget.test.js +121 -0
  64. package/dist/test/dependencies.test.js +71 -4
  65. package/dist/test/dream-tools.test.js +153 -8
  66. package/dist/test/dsh.test.js +62 -15
  67. package/dist/test/helpers/dsh.d.ts +4 -1
  68. package/dist/test/helpers/dsh.js +20 -4
  69. package/dist/test/helpers/extension.d.ts +5 -0
  70. package/dist/test/helpers/extension.js +33 -2
  71. package/dist/test/host-neutral.test.js +17 -15
  72. package/dist/test/marker.test.js +78 -0
  73. package/dist/test/model-facing-text.test.js +12 -8
  74. package/dist/test/notes-cwd.test.d.ts +1 -0
  75. package/dist/test/notes-cwd.test.js +114 -0
  76. package/dist/test/notes-library.test.js +4 -4
  77. package/dist/test/notes-query-namespaces.test.d.ts +1 -0
  78. package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
  79. package/dist/test/notes.integration.test.js +72 -23
  80. package/dist/test/notes.test.js +50 -20
  81. package/dist/test/pi-render.test.js +33 -1
  82. package/dist/test/project-namespace.test.d.ts +1 -0
  83. package/dist/test/project-namespace.test.js +324 -0
  84. package/dist/test/reset-lifecycle.test.js +12 -0
  85. package/docs/architecture.md +13 -8
  86. package/docs/claude-code-mod.md +7 -7
  87. package/docs/codex.md +4 -4
  88. package/docs/dsh.md +8 -8
  89. package/docs/notes-library.md +9 -5
  90. package/docs/skills.md +3 -3
  91. package/docs/tool-results.md +6 -2
  92. package/package.json +4 -6
  93. package/playbook.md +6 -6
  94. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  95. package/plugins/claude/dist/claude/helper.js +681 -617
  96. package/plugins/claude/hooks/register.ts +61 -65
  97. package/plugins/claude/playbook.md +6 -6
  98. package/plugins/claude/skills/memory/SKILL.md +4 -4
  99. package/plugins/claude/src/helper.ts +3 -2
  100. package/plugins/claude/src/history.ts +2 -3
  101. package/plugins/claude/src/thresholds.ts +4 -2
  102. package/plugins/codex/README.md +1 -1
  103. package/plugins/codex/dist/codex/notesoup.js +877 -815
  104. package/plugins/codex/src/hooks.ts +1 -1
  105. package/plugins/codex/src/identity.ts +3 -3
  106. package/plugins/codex/src/mcp.ts +2 -1
  107. package/plugins/codex/src/text.ts +2 -2
  108. package/plugins/dsh/engine.ts +2 -2
  109. package/plugins/dsh/tools.ts +8 -7
  110. package/plugins/dsh/window.ts +8 -3
  111. package/plugins/paseo/OVERVIEW.md +4 -4
  112. package/plugins/paseo/README.md +1 -1
  113. package/plugins/paseo/client/brain-empty-card.tsx +3 -4
  114. package/plugins/paseo/client/markdown.tsx +179 -0
  115. package/plugins/paseo/client/notes-op-card.tsx +35 -34
  116. package/plugins/paseo/client/notes-op-transformer.ts +17 -68
  117. package/plugins/paseo/client/paper-card.tsx +8 -19
  118. package/plugins/paseo/client/paper-palette.ts +40 -0
  119. package/plugins/paseo/client/sticky-card.tsx +6 -4
  120. package/plugins/paseo/package.json +3 -0
  121. package/plugins/paseo/paseo-plugin.json +2 -2
  122. package/plugins/paseo/shared/notes-op.ts +13 -9
  123. package/plugins/paseo/test/notes-op.test.ts +52 -73
  124. package/plugins/paseo/test/paper-palette.test.ts +54 -0
  125. package/plugins/pi/entries.ts +1 -0
  126. package/plugins/pi/history-tools.ts +4 -4
  127. package/plugins/pi/marker.ts +39 -0
  128. package/plugins/pi/notes/tools.ts +8 -6
  129. package/plugins/pi/render.ts +6 -4
  130. package/plugins/pi/reset/artifacts.ts +2 -2
  131. package/plugins/pi/runtime.ts +9 -8
  132. package/plugins/pi/text.ts +5 -0
  133. package/plugins/pi/window.ts +22 -7
  134. package/skills/memory/SKILL.md +4 -4
  135. package/src/boot/render.ts +8 -8
  136. package/src/boot/snapshot.ts +20 -20
  137. package/src/boot/text.ts +7 -5
  138. package/src/dream/git.ts +7 -24
  139. package/src/dream/lock.ts +3 -3
  140. package/src/index.ts +4 -3
  141. package/src/notes/address.ts +13 -13
  142. package/src/notes/errors.ts +1 -1
  143. package/src/notes/frontmatter.ts +2 -2
  144. package/src/notes/index.ts +1 -1
  145. package/src/notes/paths.ts +9 -9
  146. package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
  147. package/src/notes/store.ts +61 -58
  148. package/src/tools/dream.ts +63 -16
  149. package/src/tools/notes-context.ts +29 -0
  150. package/src/tools/notes.ts +39 -29
  151. package/dist/test/project-home.test.js +0 -134
  152. /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
  153. /package/dist/test/{project-home.test.d.ts → marker.test.d.ts} +0 -0
@@ -35,7 +35,7 @@ export function bootWithinCap(boot: string): string | undefined {
35
35
  const bytes = Buffer.byteLength(boot, "utf8");
36
36
  return bytes <= MAX_BOOT_BYTES
37
37
  ? undefined
38
- : `notesoup: this window's boot is ${bytes} bytes, over the ${MAX_BOOT_BYTES}-byte cap. No truncated or spilled boot was injected; slim the home MAPs and restart/resume the thread.`;
38
+ : `notesoup: this window's boot is ${bytes} bytes, over the ${MAX_BOOT_BYTES}-byte cap. No truncated or spilled boot was injected; slim the notebook MAPs and restart/resume the thread.`;
39
39
  }
40
40
 
41
41
  export async function readHookInput(stream: NodeJS.ReadableStream): Promise<string> {
@@ -42,7 +42,7 @@ export function safeThreadId(value: unknown, field = "threadId"): string {
42
42
  export function pluginDataRoot(env: NodeJS.ProcessEnv = process.env): string {
43
43
  const value = env.PLUGIN_DATA;
44
44
  if (typeof value !== "string" || value.trim() === "" || !isAbsolute(value)) {
45
- throw new CodexIdentityError("missing_plugin_data", "PLUGIN_DATA is unavailable. Install notesoup as a Codex plugin (or set PLUGIN_DATA for a standalone test) so hook bindings have one mutable home.");
45
+ throw new CodexIdentityError("missing_plugin_data", "PLUGIN_DATA is unavailable. Install notesoup as a Codex plugin (or set PLUGIN_DATA for a standalone test) so hook bindings have one mutable data directory.");
46
46
  }
47
47
  return resolve(value);
48
48
  }
@@ -52,7 +52,7 @@ export function notesHome(env: NodeJS.ProcessEnv = process.env): string {
52
52
  return value !== undefined && value.trim() !== "" ? resolve(value) : join(homedir(), ".agents", "notes");
53
53
  }
54
54
 
55
- /** Native ids arrive provider-prefixed; @model is the last segment, slugged like every other home. */
55
+ /** Native ids arrive provider-prefixed; @model is the last segment, slugged like every other notebook. */
56
56
  export function modelSlug(value: unknown): string | undefined {
57
57
  if (typeof value !== "string") return undefined;
58
58
  const id = value.trim();
@@ -138,7 +138,7 @@ export function turnModel(meta: Record<string, unknown>): string {
138
138
  }
139
139
  const model = typeof value === "object" && value !== null ? (value as Record<string, unknown>).model : undefined;
140
140
  const slug = modelSlug(model);
141
- if (slug === undefined) throw new CodexIdentityError("missing_model", "Codex did not supply this turn's model in MCP metadata, so notesoup cannot choose an @model home. Update Codex, or call notes from a model turn.");
141
+ if (slug === undefined) throw new CodexIdentityError("missing_model", "Codex did not supply this turn's model in MCP metadata, so notesoup cannot choose an @model notebook. Update Codex, or call notes from a model turn.");
142
142
  return slug;
143
143
  }
144
144
 
@@ -10,6 +10,7 @@ import { wireResult, type Operation, type Outcome } from "../../../src/tools/res
10
10
  import { CodexIdentityError, notesIdentityFor, pluginDataRoot, readBinding, rootSessionIdOf, safeThreadId, turnModel, type ThreadBinding } from "./identity.js";
11
11
  import { readCodexHistory } from "./history.js";
12
12
  import { readStartState } from "./state.js";
13
+ import { notesToolContext } from "../../../src/tools/notes-context.js";
13
14
 
14
15
  type Bound = {
15
16
  readonly operation: Operation<TSchema, unknown, readonly unknown[]>;
@@ -130,7 +131,7 @@ export async function callTool(name: string, args: unknown, meta: Record<string,
130
131
  const { binding, rootSessionId, model } = await identityFor(meta, env);
131
132
  const native = await readNative(binding, rootSessionId, bound.history, meta, env);
132
133
  if (!bound.history) {
133
- const outcome = await bound.operation.execute(params, notesIdentityFor(binding, model)) as Outcome<unknown>;
134
+ const outcome = await bound.operation.execute(params, notesToolContext(notesIdentityFor(binding, model), binding.cwd)) as Outcome<unknown>;
134
135
  return successFor(bound, outcome);
135
136
  }
136
137
  const projection = (native as Awaited<ReturnType<typeof readCodexHistory>>).projection;
@@ -25,7 +25,7 @@ export function missingNativeFacts(reason: string): string {
25
25
  return `notesoup: no boot injected because Codex's native window facts could not be read (${reason}). ${CODEX_SETUP_HINT} notesoup supports Codex 0.160.1 transcripts.`;
26
26
  }
27
27
 
28
- /** A boot can still identify itself when the note store itself refused; it must not pretend homes are empty. */
28
+ /** A boot can still identify itself when the note store itself refused; it must not pretend notebooks are empty. */
29
29
  export function notesFailureBoot(reason: string): string {
30
- return `notesoup: your notes did not load this time (${reason}). Try the notes_list tool; if it fails too, tell the human. Do not assume a home is empty from this failure.`;
30
+ return `notesoup: your notes did not load this time (${reason}). Try the notes_list tool; if it fails too, tell the human. Do not assume a notebook is empty from this failure.`;
31
31
  }
@@ -129,8 +129,8 @@ export class NotesoupCompactionEngine extends CompactionEngine {
129
129
  try {
130
130
  const next = await this.windows.mint(agent, previous.window + 1, opened.time);
131
131
  signal?.throwIfAborted();
132
- if (session.surface.contentGeneration !== generation || session.surface.nodes.length !== shadowedSeqs.length + 1) throw new ManualCompactionError("changed", "notesoup: the surface changed while opening the next notebook; retry after current work finishes.");
133
- // Mint BEFORE writing the checkpoint. A rejected append restores the previous notebook.
132
+ if (session.surface.contentGeneration !== generation || session.surface.nodes.length !== shadowedSeqs.length + 1) throw new ManualCompactionError("changed", "notesoup: the surface changed while opening the next page; retry after current work finishes.");
133
+ // Mint BEFORE writing the checkpoint. A rejected append restores the previous page.
134
134
  // One draw per reset artifact: the checkpoint text and the steered copy share it.
135
135
  const continuation = selectContinuation(origin);
136
136
  state.snapshot = next;
@@ -8,7 +8,8 @@ import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../.
8
8
  import { historyList, historyRead, historyWindows } from "../../src/tools/history.js";
9
9
  import { success, type Operation } from "../../src/tools/result.js";
10
10
  import { historyProjection } from "./history.js";
11
- import { notesIdentity } from "./window.js";
11
+ import { notesCwd, notesIdentity } from "./window.js";
12
+ import { notesToolContext } from "../../src/tools/notes-context.js";
12
13
  import { measureBudget } from "./budget.js";
13
14
  import { preflight, type NotesoupCompactionEngine } from "./engine.js";
14
15
 
@@ -70,12 +71,12 @@ export function registerTools(ctx: Context, engine: NotesoupCompactionEngine): v
70
71
  }
71
72
  if (!exec.parent && nestedResets.get(exec.agent)?.delete(exec.rootCallId) && !result.isError) state.pendingReset = true;
72
73
  });
73
- const identity = (agent: Agent) => notesIdentity(agent, engine.config);
74
- register(ctx, notesWrite, (agent) => [identity(agent)] as const);
75
- register(ctx, notesUpdate, (agent) => [identity(agent)] as const);
76
- register(ctx, notesRead, (agent) => [identity(agent)] as const);
77
- register(ctx, notesList, (agent) => [identity(agent)] as const);
78
- register(ctx, notesSearch, (agent) => [identity(agent)] as const);
74
+ const toolContext = (agent: Agent) => notesToolContext(notesIdentity(agent, engine.config), notesCwd(agent));
75
+ register(ctx, notesWrite, (agent) => [toolContext(agent)] as const);
76
+ register(ctx, notesUpdate, (agent) => [toolContext(agent)] as const);
77
+ register(ctx, notesRead, (agent) => [toolContext(agent)] as const);
78
+ register(ctx, notesList, (agent) => [toolContext(agent)] as const);
79
+ register(ctx, notesSearch, (agent) => [toolContext(agent)] as const);
79
80
  register(ctx, historyList, async (agent) => [await historyProjection(ctx, agent.session.id)] as const);
80
81
  register(ctx, historyRead, async (agent) => [await historyProjection(ctx, agent.session.id)] as const);
81
82
  register(ctx, historyWindows, async (agent) => [await historyProjection(ctx, agent.session.id), agent.session.id] as const);
@@ -86,13 +86,17 @@ export function recoverSnapshot(events: readonly SessionEvent[]): WindowSnapshot
86
86
  return latest;
87
87
  }
88
88
 
89
+ export function notesCwd(agent: Pick<Agent, "session" | "options">): string {
90
+ return agent.session.header.cwd ?? process.cwd();
91
+ }
92
+
89
93
  /** Identity is extracted here, never in the filesystem domain. */
90
94
  export function notesIdentity(agent: Pick<Agent, "session" | "options">, config: NotesConfig): NotesIdentity {
91
95
  const home = config.notesHome ?? join(homedir(), ".agents", "notes");
92
96
  return snapshotNotesIdentity({
93
97
  home,
94
98
  sessionId: agent.session.id,
95
- projectKey: projectKey(agent.session.header.cwd ?? process.cwd(), home),
99
+ projectKey: projectKey(notesCwd(agent), home),
96
100
  agent: slugify(config.agentName ?? "dsh"),
97
101
  model: slugify(agent.session.requestHeader()?.config.model ?? agent.options.model ?? "unknown"),
98
102
  });
@@ -111,9 +115,10 @@ export class Windows {
111
115
  const existing = this.states.get(agent.session);
112
116
  if (existing) return existing;
113
117
  const restored = recoverSnapshot(agent.session.snapshotEvents());
114
- const snapshot = restored ?? await this.mint(agent, 0, agent.session.header.createdAt);
118
+ const sameSession = restored !== undefined && restored.windowId === windowId(agent.session.id, restored.window);
119
+ const snapshot = sameSession ? restored : await this.mint(agent, restored?.window ?? 0, agent.session.header.createdAt);
115
120
  signal?.throwIfAborted();
116
- if (!restored) appendPluginRecord(agent.session, WINDOW_RECORD, snapshot);
121
+ if (!sameSession) appendPluginRecord(agent.session, WINDOW_RECORD, snapshot);
117
122
  const state = { snapshot, pendingReset: false, warned: false, reminded: false };
118
123
  restoreWarnings(state, agent.session.snapshotEvents());
119
124
  this.states.set(agent.session, state);
@@ -1,12 +1,12 @@
1
- # Notesoup last word
1
+ # Notesoup
2
2
 
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; a crumple call turns its card grey and strikes the address. Requires Paseo 0.11.2 on the client and daemon.
3
+ Displays notesoup last-word messages already present in Paseo’s timeline as expanded, selectable paper cards. Last-word and notes cards share a paper palette that follows Paseo’s theme: pale paper in light themes and warm charcoal paper in dark themes, with matching ink, tape and diff colors. Both keep small corners and compact spacing; a crumple call dulls its paper and strikes the address. Requires Paseo 0.11.2 or newer on the client and daemon.
4
4
 
5
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 accepts the bare Pi tool names and Claude's exact `mcp__notesoup__` prefix; same-named tools from other MCP servers are unchanged. It does not read session files or append messages. Other timeline items are unchanged.
6
6
 
7
- Notes cards start collapsed; update cards also show the sentence just added. The whole header row expands and collapses the 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.
7
+ Notes cards start collapsed; update cards also show the sentence just added. The whole header row expands and collapses the body. Long content scrolls inside a bounded panel. Read text and diffs come from the existing tool-result text; writes come from the call's content argument. Live and history use the same projection without a persisted copy. Each displayed body/diff is capped at 32,000 UTF-16 units, retaining the beginning and end with a visible omission line; collapsed previews are capped at 1,000 units before layout. Expanding does not fetch more content; original tool results and notes are unchanged. Diff lines of the same color share a text run rather than one component per line.
8
8
 
9
- Notes cards prefer Pi's structured tool payload on live events. Pi replayed history carries only rendered text blocks; Claude carries rendered text under the adapter's `output` field. Both use the same text fallback parser, and write previews come from the call arguments. Failed calls also read the adapter's error content (string or text blocks) or transport message when no result is available.
9
+ Notes cards use the same rendered-text parser for Pi live events and replayed history; Claude supplies that text under the adapter's `output` field. Write previews come from the call arguments. The UI does not depend on Pi's live-only `structuredContent`. Failed calls also read the adapter's error content (string or text blocks) or transport message when no result is available.
10
10
 
11
11
  `empty_brain` (including `mcp__notesoup__empty_brain`) becomes a divider for running, completed and failed calls. Pi's JSON rollover outcomes are preserved. Claude's plain acknowledgement only completes the tool call; it does not invent a Pi outcome or assert that the deferred reset has committed.
12
12
 
@@ -9,4 +9,4 @@ npm run typecheck
9
9
  npm test
10
10
  ```
11
11
 
12
- Install this directory with `paseo plugin install /absolute/path/to/plugins/paseo`. Source changes require `paseo plugin reload notesoup-last-word`; no daemon restart is needed.
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.
@@ -1,7 +1,6 @@
1
1
  import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
2
2
  import { Text, View } from "react-native";
3
3
  import type { BrainEmpty } from "../shared/brain-empty.ts";
4
- import { PAPER } from "./paper-card.tsx";
5
4
 
6
5
  function label(data: BrainEmpty): string {
7
6
  if (data.status === "running") return "✂ emptying brain …";
@@ -23,10 +22,10 @@ function CutLine({ color }: { color: string }) {
23
22
  );
24
23
  }
25
24
 
26
- export function BrainEmptyDivider({ item }: PluginTimelineItemProps<BrainEmpty>) {
25
+ export function BrainEmptyDivider({ item, theme }: PluginTimelineItemProps<BrainEmpty>) {
27
26
  const data = item.data;
28
27
  const refused = data.error !== undefined || data.status === "failed";
29
- const color = refused ? PAPER.removed : PAPER.inkMuted;
28
+ const color = refused ? theme.colors.statusDanger : theme.colors.foregroundMuted;
30
29
  return (
31
30
  <View style={{ paddingVertical: 6, gap: 3 }}>
32
31
  <View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
@@ -35,7 +34,7 @@ export function BrainEmptyDivider({ item }: PluginTimelineItemProps<BrainEmpty>)
35
34
  <CutLine color={color} />
36
35
  </View>
37
36
  {data.error !== undefined && (
38
- <Text selectable style={{ color: PAPER.removed, fontSize: 12, textAlign: "center" }}>{data.error}</Text>
37
+ <Text selectable style={{ color: theme.colors.statusDanger, fontSize: 12, textAlign: "center" }}>{data.error}</Text>
39
38
  )}
40
39
  </View>
41
40
  );
@@ -0,0 +1,179 @@
1
+ import { Lexer, lexer, type Token, type Tokens } from "marked";
2
+ import type { ReactNode } from "react";
3
+ import { StyleSheet, Text, View, type TextStyle, type ViewStyle } from "react-native";
4
+ import { MONO } from "./paper-card.tsx";
5
+ import type { PaperPalette } from "./paper-palette.ts";
6
+
7
+ type Styles = {
8
+ block: ViewStyle;
9
+ text: TextStyle;
10
+ muted: TextStyle;
11
+ strong: TextStyle;
12
+ em: TextStyle;
13
+ del: TextStyle;
14
+ codespan: TextStyle;
15
+ link: TextStyle;
16
+ heading: (depth: number) => TextStyle;
17
+ quote: ViewStyle;
18
+ quoteText: TextStyle;
19
+ code: TextStyle;
20
+ hr: ViewStyle;
21
+ list: ViewStyle;
22
+ listItem: ViewStyle;
23
+ marker: TextStyle;
24
+ table: ViewStyle;
25
+ tableRow: ViewStyle;
26
+ tableCell: TextStyle;
27
+ };
28
+
29
+ function markdownStyles(paper: PaperPalette): Styles {
30
+ return {
31
+ block: { gap: 6 },
32
+ text: { color: paper.ink, fontSize: 13, lineHeight: 19 },
33
+ muted: { color: paper.inkMuted, fontSize: 13, lineHeight: 19 },
34
+ strong: { fontWeight: "700" },
35
+ em: { color: paper.inkMuted, fontStyle: "italic" },
36
+ del: { color: paper.inkMuted, textDecorationLine: "line-through" },
37
+ codespan: { fontFamily: MONO, backgroundColor: paper.crumpled },
38
+ link: { color: paper.added, textDecorationLine: "underline" },
39
+ heading: depth => ({ fontWeight: "700", fontSize: Math.max(13, 18 - depth), lineHeight: Math.max(19, 25 - depth) }),
40
+ quote: { borderLeftWidth: 2, borderLeftColor: paper.edge, paddingLeft: 8, gap: 4 },
41
+ quoteText: { color: paper.inkMuted },
42
+ code: {
43
+ fontFamily: MONO, fontSize: 12, lineHeight: 17, color: paper.ink,
44
+ backgroundColor: paper.crumpled, borderWidth: StyleSheet.hairlineWidth, borderColor: paper.edge,
45
+ borderRadius: 3, paddingVertical: 6, paddingHorizontal: 8,
46
+ },
47
+ hr: { height: 1, backgroundColor: paper.edge },
48
+ list: { gap: 4 },
49
+ listItem: { flexDirection: "row", gap: 6 },
50
+ marker: { color: paper.inkMuted, minWidth: 14 },
51
+ table: { borderWidth: StyleSheet.hairlineWidth, borderColor: paper.edge, borderRadius: 3, overflow: "hidden" },
52
+ tableRow: { flexDirection: "row" },
53
+ tableCell: { flex: 1, paddingVertical: 3, paddingHorizontal: 6, fontSize: 12.5, lineHeight: 18 },
54
+ };
55
+ }
56
+
57
+ /** Inline tokens keep their nesting: strong/em/del/link hold the tokens they wrap. */
58
+ function renderInlines(tokens: Token[] | undefined, styles: Styles, keyPrefix: string): ReactNode[] {
59
+ if (!tokens) return [];
60
+ return tokens.map((token, index) => {
61
+ const key = `${keyPrefix}.${index}`;
62
+ switch (token.type) {
63
+ case "strong":
64
+ return <Text key={key} style={styles.strong}>{renderInlines(token.tokens, styles, key)}</Text>;
65
+ case "em":
66
+ return <Text key={key} style={styles.em}>{renderInlines(token.tokens, styles, key)}</Text>;
67
+ case "del":
68
+ return <Text key={key} style={styles.del}>{renderInlines(token.tokens, styles, key)}</Text>;
69
+ case "codespan":
70
+ return <Text key={key} style={styles.codespan}> {token.text} </Text>;
71
+ case "link":
72
+ return <Text key={key} style={styles.link}>{renderInlines(token.tokens, styles, key)}</Text>;
73
+ case "br":
74
+ return "\n";
75
+ case "image":
76
+ return <Text key={key} style={styles.link}>{token.text}</Text>;
77
+ default: {
78
+ const nested = (token as Tokens.Generic).tokens;
79
+ if (nested?.length) return <Text key={key}>{renderInlines(nested, styles, key)}</Text>;
80
+ const { text } = token as Tokens.Text;
81
+ return text ?? token.raw;
82
+ }
83
+ }
84
+ });
85
+ }
86
+
87
+ function renderListItem(item: Tokens.ListItem, marker: string, key: string, styles: Styles, textStyle: TextStyle): ReactNode {
88
+ return (
89
+ <View key={key} style={styles.listItem}>
90
+ <Text style={[styles.marker, textStyle]}>{item.task ? (item.checked ? "☑" : "☐") : marker}</Text>
91
+ <View style={{ flex: 1, gap: 4 }}>{renderBlocks(item.tokens, styles, key, textStyle)}</View>
92
+ </View>
93
+ );
94
+ }
95
+
96
+ function renderBlocks(tokens: Token[] | undefined, styles: Styles, keyPrefix: string, textStyle: TextStyle): ReactNode[] {
97
+ if (!tokens) return [];
98
+ return tokens.map((token, index) => {
99
+ const key = `${keyPrefix}.${index}`;
100
+ switch (token.type) {
101
+ case "space":
102
+ case "checkbox":
103
+ case "def":
104
+ return null;
105
+ case "hr":
106
+ return <View key={key} style={styles.hr} />;
107
+ case "code":
108
+ return <Text key={key} selectable style={styles.code}>{token.text}</Text>;
109
+ case "heading":
110
+ return (
111
+ <Text key={key} selectable style={[textStyle, styles.heading(token.depth)]}>
112
+ {renderInlines(token.tokens, styles, key)}
113
+ </Text>
114
+ );
115
+ case "blockquote":
116
+ return <View key={key} style={styles.quote}>{renderBlocks(token.tokens, styles, key, styles.quoteText)}</View>;
117
+ case "list": {
118
+ const list = token as Tokens.List;
119
+ const start = typeof list.start === "number" ? list.start : 1;
120
+ return (
121
+ <View key={key} style={styles.list}>
122
+ {list.items.map((item, itemIndex) =>
123
+ renderListItem(item, list.ordered ? `${start + itemIndex}.` : "•", `${key}.${itemIndex}`, styles, textStyle))}
124
+ </View>
125
+ );
126
+ }
127
+ case "table": {
128
+ const table = token as Tokens.Table;
129
+ return (
130
+ <View key={key} style={styles.table}>
131
+ {[table.header, ...table.rows].map((row, rowIndex) => (
132
+ <View key={`${key}.${rowIndex}`} style={[styles.tableRow, rowIndex < table.rows.length && {
133
+ borderBottomWidth: StyleSheet.hairlineWidth, borderBottomColor: styles.table.borderColor,
134
+ }]}>
135
+ {row.map((cell, cellIndex) => (
136
+ <Text
137
+ key={`${key}.${rowIndex}.${cellIndex}`}
138
+ selectable
139
+ style={[textStyle, styles.tableCell, { textAlign: cell.align ?? "left" }, cell.header && styles.strong]}
140
+ >
141
+ {renderInlines(cell.tokens, styles, `${key}.${rowIndex}.${cellIndex}`)}
142
+ </Text>
143
+ ))}
144
+ </View>
145
+ ))}
146
+ </View>
147
+ );
148
+ }
149
+ default: {
150
+ const generic = token as Tokens.Generic;
151
+ return (
152
+ <Text key={key} selectable style={textStyle}>
153
+ {generic.tokens?.length ? renderInlines(generic.tokens, styles, key) : generic.text ?? generic.raw}
154
+ </Text>
155
+ );
156
+ }
157
+ }
158
+ });
159
+ }
160
+
161
+ export function NoteInline({ text, paper, color, numberOfLines }: {
162
+ text: string;
163
+ paper: PaperPalette;
164
+ color?: string;
165
+ numberOfLines?: number;
166
+ }) {
167
+ const styles = markdownStyles(paper);
168
+ return (
169
+ <Text numberOfLines={numberOfLines} style={{ ...styles.text, color: color ?? paper.ink }}>
170
+ {renderInlines(Lexer.lexInline(text), styles, "inline")}
171
+ </Text>
172
+ );
173
+ }
174
+
175
+ export function NoteMarkdown({ text, paper, muted = false }: { text: string; paper: PaperPalette; muted?: boolean }) {
176
+ const styles = markdownStyles(paper);
177
+ const textStyle = muted ? styles.muted : styles.text;
178
+ return <View style={styles.block}>{renderBlocks(lexer(text), styles, "block", textStyle)}</View>;
179
+ }
@@ -2,46 +2,46 @@ import type { PluginTimelineItemProps } from "@getpaseo/plugin/client";
2
2
  import { Icon } from "@getpaseo/plugin/client/react-native";
3
3
  import { useState } from "react";
4
4
  import { Pressable, ScrollView, Text, View } from "react-native";
5
- import type { NotesOp } from "../shared/notes-op.ts";
6
- import { MONO, PAPER, PaperCard } from "./paper-card.tsx";
5
+ import { COLLAPSED_PREVIEW_MAX_CHARS, outputPreview, type NotesOp } from "../shared/notes-op.ts";
6
+ import { NoteInline, NoteMarkdown } from "./markdown.tsx";
7
+ import { MONO, PaperCard } from "./paper-card.tsx";
8
+ import { paperPalette, type PaperPalette } from "./paper-palette.ts";
7
9
 
8
10
  const OP_LABEL: Record<NotesOp["op"], string> = { read: "read", write: "wrote", update: "edited" };
9
11
  const OP_LABEL_RUNNING: Record<NotesOp["op"], string> = { read: "reading", write: "writing", update: "editing" };
10
12
 
11
13
  /** First added line of an update diff, without its line-number prefix: the sentence the agent just wrote down. */
12
14
  function addedLine(diff: string): string | undefined {
13
- for (const line of diff.split("\n")) {
14
- if (!line.startsWith("+")) continue;
15
- return line.replace(/^\+\s*\d+\s+\+\s?/, "");
16
- }
17
- return undefined;
15
+ return /^\+.*/m.exec(diff)?.[0].replace(/^\+\s*\d+\s+\+\s?/, "");
18
16
  }
19
17
 
20
- function DiffBody({ diff }: { diff: string }) {
18
+ function DiffBody({ diff, paper }: { diff: string; paper: PaperPalette }) {
19
+ const runs: { color: string; lines: string[] }[] = [];
20
+ for (const line of diff.split("\n")) {
21
+ const color = line.startsWith("+") ? paper.added : line.startsWith("-") ? paper.removed : paper.inkMuted;
22
+ const last = runs[runs.length - 1];
23
+ if (last?.color === color) last.lines.push(line);
24
+ else runs.push({ color, lines: [line] });
25
+ }
21
26
  return (
22
- <View style={{ gap: 2 }}>
23
- {diff.split("\n").map((line, index) => {
24
- const color = line.startsWith("+") ? PAPER.added
25
- : line.startsWith("-") ? PAPER.removed
26
- : PAPER.inkMuted;
27
- return <Text key={index} selectable style={{ color, fontSize: 12, fontFamily: MONO }}>{line}</Text>;
28
- })}
29
- </View>
27
+ <Text selectable style={{ fontSize: 12, lineHeight: 18, fontFamily: MONO }}>
28
+ {runs.map((run, index) => <Text key={index} style={{ color: run.color }}>{index > 0 ? "\n" : ""}{run.lines.join("\n")}</Text>)}
29
+ </Text>
30
30
  );
31
31
  }
32
32
 
33
- export function NotesOpCard({ item, layout }: PluginTimelineItemProps<NotesOp>) {
33
+ export function NotesOpCard({ item, layout, theme }: PluginTimelineItemProps<NotesOp>) {
34
34
  const [expanded, setExpanded] = useState(false);
35
+ const paper = paperPalette(theme);
35
36
  const data = item.data;
36
37
  const title = data.status === "running" ? OP_LABEL_RUNNING[data.op] : OP_LABEL[data.op];
37
- const showEllipsis = data.truncated && data.diff === undefined;
38
38
  const hasBody = Boolean(data.text || data.preview || data.diff);
39
39
  // Collapsed: one glance at what happened. Updates show the new sentence; writes the first of the content.
40
40
  const peek = expanded || data.crumpled ? undefined
41
41
  : data.diff !== undefined ? addedLine(data.diff)
42
42
  : data.preview;
43
43
  return (
44
- <PaperCard compact={layout.compact} crumpled={data.crumpled}>
44
+ <PaperCard paper={paper} compact={layout.compact} crumpled={data.crumpled}>
45
45
  <Pressable
46
46
  accessibilityRole="button"
47
47
  accessibilityLabel={`${expanded ? "收起" : "展开"} ${data.address}`}
@@ -50,30 +50,31 @@ export function NotesOpCard({ item, layout }: PluginTimelineItemProps<NotesOp>)
50
50
  disabled={!hasBody}
51
51
  style={({ pressed }) => ({ gap: 4, opacity: pressed && hasBody ? 0.7 : 1 })}
52
52
  >
53
- <View style={{ flexDirection: "row", alignItems: "baseline", gap: 8 }}>
54
- <Text style={{ color: PAPER.inkMuted, fontSize: 11.5 }}>
53
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 8 }}>
54
+ <Text style={{ color: paper.inkMuted, fontSize: 11.5 }}>
55
55
  {data.crumpled ? "crumpled" : title}{data.status === "running" ? " …" : ""}
56
56
  </Text>
57
- <Text style={{ color: data.crumpled ? PAPER.inkMuted : PAPER.ink, fontSize: 13, flexShrink: 1, textDecorationLine: data.crumpled ? "line-through" : "none" }}>
57
+ <Text numberOfLines={1} style={{ color: data.crumpled ? paper.inkMuted : paper.ink, fontSize: 13, flex: 1, textDecorationLine: data.crumpled ? "line-through" : "none" }}>
58
58
  {data.address}
59
59
  </Text>
60
- <View style={{ flex: 1 }} />
61
- {hasBody && <Icon name={expanded ? "ChevronUp" : "ChevronDown"} size={16} color={PAPER.inkMuted} />}
60
+ {hasBody && <Icon name={expanded ? "ChevronUp" : "ChevronDown"} size={16} color={paper.inkMuted} />}
62
61
  </View>
63
62
  {peek !== undefined && (
64
- <Text numberOfLines={2} style={{ color: data.diff !== undefined ? PAPER.added : PAPER.ink, fontSize: 13, lineHeight: 19 }}>
65
- {data.diff !== undefined ? "+ " : ""}{peek}
66
- </Text>
63
+ <NoteInline
64
+ text={`${data.diff !== undefined ? "+ " : ""}${outputPreview(peek, COLLAPSED_PREVIEW_MAX_CHARS).replace(/\s+/g, " ")}`}
65
+ paper={paper}
66
+ color={data.diff !== undefined ? paper.added : paper.ink}
67
+ numberOfLines={2}
68
+ />
67
69
  )}
68
- {data.error !== undefined && <Text selectable style={{ color: PAPER.removed, fontSize: 13, lineHeight: 19 }}>{data.error}</Text>}
70
+ {data.error !== undefined && <Text selectable style={{ color: paper.removed, fontSize: 13, lineHeight: 19 }}>{data.error}</Text>}
69
71
  </Pressable>
70
72
  {expanded && hasBody && (
71
- <ScrollView style={{ maxHeight: layout.compact ? 280 : 400 }} contentContainerStyle={{ gap: 5 }} nestedScrollEnabled>
72
- {data.text !== undefined && <Text selectable style={{ color: PAPER.ink, fontSize: 13, lineHeight: 19 }}>{data.text}{showEllipsis && " …"}</Text>}
73
- {data.preview !== undefined && <Text selectable style={{ color: PAPER.inkMuted, fontSize: 13, lineHeight: 19 }}>{data.preview}{showEllipsis && " …"}</Text>}
74
- {data.diff !== undefined && <DiffBody diff={data.diff} />}
75
- {data.renamedFrom !== undefined && <Text style={{ color: PAPER.inkMuted, fontSize: 11 }}>renamed from {data.renamedFrom}</Text>}
76
- {data.truncated && <Text style={{ color: PAPER.inkMuted, fontSize: 11 }}>shortened for display</Text>}
73
+ <ScrollView style={{ maxHeight: layout.compact ? 280 : 400, 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} muted />}
76
+ {data.diff !== undefined && <DiffBody diff={outputPreview(data.diff)} paper={paper} />}
77
+ {data.renamedFrom !== undefined && <Text style={{ color: paper.inkMuted, fontSize: 11 }}>renamed from {data.renamedFrom}</Text>}
77
78
  </ScrollView>
78
79
  )}
79
80
  </PaperCard>
@@ -1,10 +1,8 @@
1
1
  import type { PluginClientContext } from "@getpaseo/plugin/client";
2
2
  import {
3
- DIFF_MAX_CHARS,
4
3
  NOTES_OP_KIND,
5
4
  NOTES_OP_TOOLS,
6
- PREVIEW_MAX_CHARS,
7
- READ_TEXT_MAX_CHARS,
5
+ outputPreview,
8
6
  type NotesOp,
9
7
  type NotesOpTool,
10
8
  } from "../shared/notes-op.ts";
@@ -20,80 +18,31 @@ const OP_BY_TOOL: Record<NotesOpTool, NotesOp["op"]> = {
20
18
  notes_update: "update",
21
19
  };
22
20
 
23
- function clip(text: string, maxChars: number): { text: string; truncated: boolean } {
24
- const chars = Array.from(text);
25
- return chars.length <= maxChars
26
- ? { text, truncated: false }
27
- : { text: chars.slice(0, maxChars).join(""), truncated: true };
28
- }
29
-
30
- function baseData(item: ToolCallItem, op: NotesOp["op"], input: unknown): NotesOp | undefined {
31
- const address = isRecord(input) && typeof input.address === "string" ? input.address : undefined;
32
- if (!address) return undefined;
33
- const status = item.status === "running" ? "running" : item.status === "failed" ? "failed" : "completed";
34
- const crumpled = isRecord(input) && input.crumpled === true ? true : undefined;
35
- return { op, address, status, ...(crumpled ? { crumpled } : {}) };
36
- }
37
-
38
21
  function notesOpData(item: ToolCallItem, tool: NotesOpTool): NotesOp | undefined {
39
22
  const op = OP_BY_TOOL[tool];
40
23
  if (item.detail.type !== "unknown") return undefined;
41
24
  const { input, output } = item.detail;
42
- const data = baseData(item, op, input);
43
- if (!data) return undefined;
25
+ const address = isRecord(input) && typeof input.address === "string" ? input.address : undefined;
26
+ if (!address) return undefined;
27
+ const data: NotesOp = {
28
+ op,
29
+ address,
30
+ status: item.status === "running" ? "running" : item.status === "failed" ? "failed" : "completed",
31
+ ...(isRecord(input) && input.crumpled === true ? { crumpled: true } : {}),
32
+ };
44
33
  if (data.status === "running") return data;
45
34
 
46
- const wire = isRecord(output) && isRecord(output.structuredContent) ? output.structuredContent : undefined;
47
- if (wire && typeof wire.error === "string") return { ...data, error: wire.error };
48
35
  if (data.status === "failed") return { ...data, error: resultError(output, item.error) };
49
- if (!wire) {
50
- // Pi history and Claude carry rendered text, not the structured Notesoup payload.
51
- const text = resultText(output);
52
- if (text === undefined) return data;
53
- if (op === "read") {
54
- const clipped = clip(text.split("\n").slice(2).join("\n").replace(/^\n/, ""), READ_TEXT_MAX_CHARS);
55
- return { ...data, text: clipped.text, ...(clipped.truncated ? { truncated: true } : {}) };
56
- }
57
- if (op === "write") {
58
- const outcome = text.split(" ")[0];
59
- // Replay still carries the call arguments; the preview comes from input on every path.
60
- const preview = isRecord(input) && typeof input.content === "string" ? clip(input.content, PREVIEW_MAX_CHARS) : undefined;
61
- return { ...data, ...(["created", "overwrote", "uncrumpled"].includes(outcome) ? { outcome } : {}), ...(preview ? { preview: preview.text, ...(preview.truncated ? { truncated: true } : {}) } : {}) };
62
- }
63
- const head = text.split("\n")[0] ?? "";
64
- const changeKind = head.startsWith("moved ") ? "moved" : head.startsWith("updated ") ? "body" : head.startsWith("unchanged ") ? "none" : undefined;
65
- const diffStart = text.indexOf("\ndiff:\n");
66
- const clippedDiff = diffStart >= 0 ? clip(text.slice(diffStart + 7), DIFF_MAX_CHARS) : undefined;
67
- return {
68
- ...data,
69
- ...(changeKind ? { changeKind } : {}),
70
- ...(clippedDiff && clippedDiff.text.length > 0 ? { diff: clippedDiff.text, ...(clippedDiff.truncated ? { truncated: true } : {}) } : {}),
71
- };
72
- }
73
-
74
- if (op === "read" && typeof wire.text === "string") {
75
- const clipped = clip(wire.text, READ_TEXT_MAX_CHARS);
76
- return {
77
- ...data,
78
- text: clipped.text,
79
- truncated: clipped.truncated || wire.next_offset_chars !== null,
80
- ...(typeof wire.total_chars === "number" ? { totalChars: wire.total_chars } : {}),
81
- };
82
- }
83
- if (op === "write") {
84
- const preview = isRecord(input) && typeof input.content === "string" ? clip(input.content, PREVIEW_MAX_CHARS) : undefined;
85
- return {
86
- ...data,
87
- ...(typeof wire.outcome === "string" ? { outcome: wire.outcome } : {}),
88
- ...(preview ? { preview: preview.text, ...(preview.truncated ? { truncated: true } : {}) } : {}),
89
- };
90
- }
91
- const clippedDiff = typeof wire.diff === "string" && wire.diff.length > 0 ? clip(wire.diff, DIFF_MAX_CHARS) : undefined;
36
+ if (op === "write") return { ...data, ...(isRecord(input) && typeof input.content === "string" ? { preview: outputPreview(input.content) } : {}) };
37
+ // One projection for Pi live/history and Claude; keep upstream continuation markers.
38
+ const text = resultText(output);
39
+ if (text === undefined) return data;
40
+ if (op === "read") return { ...data, text: outputPreview(text.split("\n").slice(2).join("\n").replace(/^\n/, "")) };
41
+ const diffStart = text.indexOf("\ndiff:\n");
92
42
  return {
93
43
  ...data,
94
- ...(typeof wire.change_kind === "string" ? { changeKind: wire.change_kind } : {}),
95
- ...(typeof wire.rename_from === "string" ? { renamedFrom: wire.rename_from } : {}),
96
- ...(clippedDiff ? { diff: clippedDiff.text, ...(clippedDiff.truncated ? { truncated: true } : {}) } : {}),
44
+ ...(text.startsWith("moved ") && isRecord(input) && typeof input.rename_to === "string" ? { renamedFrom: data.address, address: input.rename_to } : {}),
45
+ ...(diffStart >= 0 ? { diff: outputPreview(text.slice(diffStart + 7)) } : {}),
97
46
  };
98
47
  }
99
48