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.
- package/README.md +2 -2
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/claude/src/history.js +2 -3
- package/dist/plugins/claude/src/thresholds.js +4 -2
- package/dist/plugins/codex/src/hooks.js +1 -1
- package/dist/plugins/codex/src/identity.d.ts +1 -1
- package/dist/plugins/codex/src/identity.js +3 -3
- package/dist/plugins/codex/src/mcp.js +2 -1
- package/dist/plugins/codex/src/text.d.ts +1 -1
- package/dist/plugins/codex/src/text.js +2 -2
- package/dist/plugins/dsh/engine.js +2 -2
- package/dist/plugins/dsh/tools.js +8 -7
- package/dist/plugins/dsh/window.d.ts +1 -0
- package/dist/plugins/dsh/window.js +7 -3
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +4 -4
- package/dist/plugins/pi/marker.d.ts +9 -0
- package/dist/plugins/pi/marker.js +36 -0
- package/dist/plugins/pi/notes/tools.js +8 -6
- package/dist/plugins/pi/render.js +7 -4
- package/dist/plugins/pi/reset/artifacts.d.ts +2 -2
- package/dist/plugins/pi/reset/artifacts.js +2 -2
- package/dist/plugins/pi/runtime.js +11 -8
- package/dist/plugins/pi/text.d.ts +2 -0
- package/dist/plugins/pi/text.js +4 -0
- package/dist/plugins/pi/window.js +21 -7
- package/dist/src/boot/render.js +7 -7
- package/dist/src/boot/snapshot.d.ts +7 -7
- package/dist/src/boot/snapshot.js +17 -17
- package/dist/src/boot/text.d.ts +2 -2
- package/dist/src/boot/text.js +7 -5
- package/dist/src/dream/git.d.ts +2 -11
- package/dist/src/dream/git.js +6 -23
- package/dist/src/dream/lock.d.ts +2 -2
- package/dist/src/dream/lock.js +3 -3
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +3 -2
- package/dist/src/notes/address.d.ts +8 -8
- package/dist/src/notes/address.js +13 -13
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.js +2 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/paths.d.ts +6 -6
- package/dist/src/notes/paths.js +9 -9
- package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
- package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
- package/dist/src/notes/store.d.ts +4 -4
- package/dist/src/notes/store.js +55 -52
- package/dist/src/tools/dream.d.ts +21 -3
- package/dist/src/tools/dream.js +54 -16
- package/dist/src/tools/notes-context.d.ts +10 -0
- package/dist/src/tools/notes-context.js +27 -0
- package/dist/src/tools/notes.d.ts +69 -20
- package/dist/src/tools/notes.js +40 -31
- package/dist/test/agent-loop.test.js +8 -8
- package/dist/test/boot.integration.test.js +5 -5
- package/dist/test/claude-history.test.js +26 -0
- package/dist/test/claude-mod.test.js +257 -86
- package/dist/test/codex-plugin.test.js +18 -1
- package/dist/test/context-edit-budget.test.js +121 -0
- package/dist/test/dependencies.test.js +71 -4
- package/dist/test/dream-tools.test.js +153 -8
- package/dist/test/dsh.test.js +62 -15
- package/dist/test/helpers/dsh.d.ts +4 -1
- package/dist/test/helpers/dsh.js +20 -4
- package/dist/test/helpers/extension.d.ts +5 -0
- package/dist/test/helpers/extension.js +33 -2
- package/dist/test/host-neutral.test.js +17 -15
- package/dist/test/marker.test.js +78 -0
- package/dist/test/model-facing-text.test.js +12 -8
- package/dist/test/notes-cwd.test.d.ts +1 -0
- package/dist/test/notes-cwd.test.js +114 -0
- package/dist/test/notes-library.test.js +4 -4
- package/dist/test/notes-query-namespaces.test.d.ts +1 -0
- package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
- package/dist/test/notes.integration.test.js +72 -23
- package/dist/test/notes.test.js +50 -20
- package/dist/test/pi-render.test.js +33 -1
- package/dist/test/project-namespace.test.d.ts +1 -0
- package/dist/test/project-namespace.test.js +324 -0
- package/dist/test/reset-lifecycle.test.js +12 -0
- package/docs/architecture.md +13 -8
- package/docs/claude-code-mod.md +7 -7
- package/docs/codex.md +4 -4
- package/docs/dsh.md +8 -8
- package/docs/notes-library.md +9 -5
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +6 -2
- package/package.json +4 -6
- package/playbook.md +6 -6
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +681 -617
- package/plugins/claude/hooks/register.ts +61 -65
- package/plugins/claude/playbook.md +6 -6
- package/plugins/claude/skills/memory/SKILL.md +4 -4
- package/plugins/claude/src/helper.ts +3 -2
- package/plugins/claude/src/history.ts +2 -3
- package/plugins/claude/src/thresholds.ts +4 -2
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +877 -815
- package/plugins/codex/src/hooks.ts +1 -1
- package/plugins/codex/src/identity.ts +3 -3
- package/plugins/codex/src/mcp.ts +2 -1
- package/plugins/codex/src/text.ts +2 -2
- package/plugins/dsh/engine.ts +2 -2
- package/plugins/dsh/tools.ts +8 -7
- package/plugins/dsh/window.ts +8 -3
- package/plugins/paseo/OVERVIEW.md +4 -4
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/brain-empty-card.tsx +3 -4
- package/plugins/paseo/client/markdown.tsx +179 -0
- package/plugins/paseo/client/notes-op-card.tsx +35 -34
- package/plugins/paseo/client/notes-op-transformer.ts +17 -68
- package/plugins/paseo/client/paper-card.tsx +8 -19
- package/plugins/paseo/client/paper-palette.ts +40 -0
- package/plugins/paseo/client/sticky-card.tsx +6 -4
- package/plugins/paseo/package.json +3 -0
- package/plugins/paseo/paseo-plugin.json +2 -2
- package/plugins/paseo/shared/notes-op.ts +13 -9
- package/plugins/paseo/test/notes-op.test.ts +52 -73
- package/plugins/paseo/test/paper-palette.test.ts +54 -0
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +4 -4
- package/plugins/pi/marker.ts +39 -0
- package/plugins/pi/notes/tools.ts +8 -6
- package/plugins/pi/render.ts +6 -4
- package/plugins/pi/reset/artifacts.ts +2 -2
- package/plugins/pi/runtime.ts +9 -8
- package/plugins/pi/text.ts +5 -0
- package/plugins/pi/window.ts +22 -7
- package/skills/memory/SKILL.md +4 -4
- package/src/boot/render.ts +8 -8
- package/src/boot/snapshot.ts +20 -20
- package/src/boot/text.ts +7 -5
- package/src/dream/git.ts +7 -24
- package/src/dream/lock.ts +3 -3
- package/src/index.ts +4 -3
- package/src/notes/address.ts +13 -13
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +2 -2
- package/src/notes/index.ts +1 -1
- package/src/notes/paths.ts +9 -9
- package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
- package/src/notes/store.ts +61 -58
- package/src/tools/dream.ts +63 -16
- package/src/tools/notes-context.ts +29 -0
- package/src/tools/notes.ts +39 -29
- package/dist/test/project-home.test.js +0 -134
- /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
- /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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
package/plugins/codex/src/mcp.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
}
|
package/plugins/dsh/engine.ts
CHANGED
|
@@ -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
|
|
133
|
-
// Mint BEFORE writing the checkpoint. A rejected append restores the previous
|
|
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;
|
package/plugins/dsh/tools.ts
CHANGED
|
@@ -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
|
|
74
|
-
register(ctx, notesWrite, (agent) => [
|
|
75
|
-
register(ctx, notesUpdate, (agent) => [
|
|
76
|
-
register(ctx, notesRead, (agent) => [
|
|
77
|
-
register(ctx, notesList, (agent) => [
|
|
78
|
-
register(ctx, notesSearch, (agent) => [
|
|
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);
|
package/plugins/dsh/window.ts
CHANGED
|
@@ -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
|
|
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
|
|
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 (!
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
package/plugins/paseo/README.md
CHANGED
|
@@ -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
|
|
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 ?
|
|
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:
|
|
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
|
|
6
|
-
import {
|
|
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
|
-
|
|
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
|
-
<
|
|
23
|
-
{
|
|
24
|
-
|
|
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: "
|
|
54
|
-
<Text style={{ color:
|
|
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 ?
|
|
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
|
-
<
|
|
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
|
-
<
|
|
65
|
-
{data.diff !== undefined ? "+ " : ""}{peek}
|
|
66
|
-
|
|
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:
|
|
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 && <
|
|
73
|
-
{data.preview !== undefined && <
|
|
74
|
-
{data.diff !== undefined && <DiffBody diff={data.diff} />}
|
|
75
|
-
{data.renamedFrom !== undefined && <Text style={{ color:
|
|
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
|
-
|
|
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
|
|
43
|
-
if (!
|
|
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 (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
|
95
|
-
...(
|
|
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
|
|