notesoup 0.52.5 → 0.52.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugins/claude/src/helper.js +34 -7
- package/dist/plugins/claude/src/history.d.ts +7 -2
- package/dist/plugins/claude/src/history.js +53 -22
- package/dist/plugins/claude/src/text.d.ts +5 -0
- package/dist/plugins/claude/src/text.js +12 -0
- package/dist/src/history/history.js +12 -11
- package/dist/src/notes/store.d.ts +2 -0
- package/dist/src/notes/store.js +2 -2
- package/dist/src/tools/dream.d.ts +2 -0
- package/dist/src/tools/history.d.ts +5 -3
- package/dist/src/tools/history.js +9 -11
- package/dist/src/tools/notes.d.ts +7 -0
- package/dist/src/tools/notes.js +8 -3
- package/dist/test/claude-history.test.js +135 -3
- package/dist/test/dream-skill.test.js +5 -0
- package/dist/test/dream-tools.test.js +15 -0
- package/dist/test/history.integration.test.js +26 -1
- package/dist/test/notes-library.test.js +1 -1
- package/dist/test/notes.test.js +1 -1
- package/dist/test/pi-render.test.js +2 -2
- package/docs/claude-code-mod.md +6 -2
- package/docs/tool-results.md +2 -2
- package/package.json +1 -1
- package/playbook.md +24 -13
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +105 -44
- package/plugins/claude/playbook.md +24 -13
- package/plugins/claude/skills/dream/SKILL.md +8 -0
- package/plugins/claude/src/helper.ts +34 -9
- package/plugins/claude/src/history.ts +54 -22
- package/plugins/claude/src/text.ts +13 -0
- package/plugins/paseo/OVERVIEW.md +6 -2
- package/plugins/paseo/client/brain-empty-card.tsx +3 -1
- package/plugins/paseo/client/brain-empty-transformer.ts +7 -14
- package/plugins/paseo/client/notes-op-transformer.ts +10 -18
- package/plugins/paseo/client/tool-result.ts +31 -0
- package/plugins/paseo/test/brain-empty.test.ts +24 -1
- package/plugins/paseo/test/fixtures/claude-tool-calls.ts +86 -0
- package/plugins/paseo/test/notes-op.test.ts +39 -1
- package/skills/dream/SKILL.md +8 -0
- package/src/history/history.ts +12 -10
- package/src/notes/store.ts +4 -3
- package/src/tools/history.ts +14 -13
- package/src/tools/notes.ts +8 -3
|
@@ -4,9 +4,12 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
4
4
|
import { contentText, projectHistory, type DecodedHistoryItem, type DecodedHistoryWindow, type HistoryProjection } from "../../../src/history/history.js";
|
|
5
5
|
|
|
6
6
|
type Row = Record<string, unknown>;
|
|
7
|
-
type
|
|
7
|
+
type WindowPosition = { ordinal: number } | { unknownAncestor: string };
|
|
8
|
+
type Version = { row: Row; ancestorUuid?: string; ancestor?: Version; position?: WindowPosition };
|
|
8
9
|
type Node = { first: Version; latest: Version; items: DecodedHistoryItem[] };
|
|
9
10
|
export type ClaudeHistorySource = { sessionId: string; transcriptPath: string; headUuid?: string };
|
|
11
|
+
/** Claude graph evidence stays in the adapter; shared queries only see addressed windows. */
|
|
12
|
+
export type ClaudeHistoryProjection = HistoryProjection & { missingAncestors: string[]; currentWindowOrdinal: number | undefined };
|
|
10
13
|
const MESSAGE_TYPES = new Set(["user", "assistant", "system", "attachment"]);
|
|
11
14
|
const NON_TEXT_BLOCKS = new Set(["thinking", "redacted_thinking", "image", "document", "audio", "video", "server_tool_use", "web_search_tool_result", "tool_reference"]);
|
|
12
15
|
function object(value: unknown): value is Row { return typeof value === "object" && value !== null && !Array.isArray(value); }
|
|
@@ -112,12 +115,12 @@ function bootOrdinal(row: Row, retained: boolean): number | undefined {
|
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
/** All addresses are allocated on the full first-occurrence log, before branch selection. */
|
|
115
|
-
export function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistorySource, "transcriptPath">):
|
|
118
|
+
export function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistorySource, "transcriptPath">): ClaudeHistoryProjection {
|
|
116
119
|
const nodes = new Map<string, Node>();
|
|
117
120
|
let nextSeq = 1;
|
|
118
121
|
for (const row of rowsOf(text)) {
|
|
119
|
-
// Ignore non-message records, including future metadata.
|
|
120
|
-
//
|
|
122
|
+
// Ignore non-message records, including future metadata. If selected ancestry
|
|
123
|
+
// reaches a skipped UUID, it becomes a gap, never permission to expose its payload.
|
|
121
124
|
if (!MESSAGE_TYPES.has(row.type as string)) continue;
|
|
122
125
|
const uuid = requiredString(row.uuid, "uuid");
|
|
123
126
|
parent(row);
|
|
@@ -141,29 +144,37 @@ export function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistoryS
|
|
|
141
144
|
nextSeq += items.length;
|
|
142
145
|
nodes.set(uuid, { first: version, latest: version, items });
|
|
143
146
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// Resolve long
|
|
147
|
+
const missingAncestors = new Set<string>();
|
|
148
|
+
function positionOf(version: Version): WindowPosition {
|
|
149
|
+
// Resolve long chains iteratively. A gap destroys ordinal evidence, not the
|
|
150
|
+
// confirmed suffix. Only a retained boot can re-anchor that suffix's ordinal.
|
|
147
151
|
const chain: Version[] = [], calculating = new Set<Version>();
|
|
148
152
|
let cursor = version;
|
|
149
|
-
|
|
150
|
-
|
|
153
|
+
let before: WindowPosition = { ordinal: 0 };
|
|
154
|
+
while (cursor.position === undefined) {
|
|
155
|
+
// Forward references use the parent's first eventual version, not a rewrite.
|
|
151
156
|
cursor.ancestor ??= cursor.ancestorUuid === undefined ? undefined : nodes.get(cursor.ancestorUuid)?.first;
|
|
152
157
|
if (calculating.has(cursor)) throw new Error("cyclic Claude transcript ancestry");
|
|
153
|
-
if (cursor.ancestorUuid !== undefined && cursor.ancestor === undefined) throw new Error(`missing Claude transcript ancestor: ${cursor.ancestorUuid}`);
|
|
154
158
|
calculating.add(cursor);
|
|
155
159
|
chain.push(cursor);
|
|
160
|
+
if (cursor.ancestorUuid !== undefined && cursor.ancestor === undefined) {
|
|
161
|
+
missingAncestors.add(cursor.ancestorUuid);
|
|
162
|
+
before = { unknownAncestor: cursor.ancestorUuid };
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
156
165
|
if (cursor.ancestor === undefined) break;
|
|
157
166
|
cursor = cursor.ancestor;
|
|
158
167
|
}
|
|
159
|
-
|
|
168
|
+
before = cursor.position ?? before;
|
|
160
169
|
for (const current of chain.reverse()) {
|
|
161
170
|
const retained = current.row.isCompactSummary === true || (current.ancestor !== undefined && boundary(current.ancestor.row));
|
|
162
171
|
const marked = bootOrdinal(current.row, retained);
|
|
163
|
-
current.
|
|
164
|
-
|
|
172
|
+
current.position = marked !== undefined
|
|
173
|
+
? { ordinal: "ordinal" in before ? Math.max(before.ordinal, marked) : marked }
|
|
174
|
+
: "ordinal" in before ? { ordinal: before.ordinal + (boundary(current.row) ? 1 : 0) } : before;
|
|
175
|
+
before = current.position;
|
|
165
176
|
}
|
|
166
|
-
return version.
|
|
177
|
+
return version.position!;
|
|
167
178
|
}
|
|
168
179
|
if (!source.headUuid) throw new Error("Claude history has no confirmed active head yet; wait for a main-session append after startup/resume");
|
|
169
180
|
if (!nodes.has(source.headUuid)) throw new Error("Claude history active head is not persisted yet; retry after the transcript write");
|
|
@@ -182,7 +193,7 @@ export function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistoryS
|
|
|
182
193
|
visiting.add(key);
|
|
183
194
|
stack.push({ ...step, exit: true });
|
|
184
195
|
const node = nodes.get(uuid);
|
|
185
|
-
if (!node)
|
|
196
|
+
if (!node) { missingAncestors.add(uuid); continue; }
|
|
186
197
|
selected.add(uuid);
|
|
187
198
|
const row = (historical ? node.first : node.latest).row;
|
|
188
199
|
const ancestor = parent(row);
|
|
@@ -207,20 +218,41 @@ export function claudeHistoryFromJsonl(text: string, source: Omit<ClaudeHistoryS
|
|
|
207
218
|
}
|
|
208
219
|
}
|
|
209
220
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const
|
|
221
|
+
const current = positionOf(nodes.get(source.headUuid)!.latest);
|
|
222
|
+
const windowId = (position: WindowPosition) => `claude:${source.sessionId}:${"ordinal" in position ? position.ordinal : `unknown:${position.unknownAncestor}`}`;
|
|
223
|
+
const windowsById = new Map<string, DecodedHistoryWindow & { ordinal?: number }>();
|
|
213
224
|
const branchSeqs = new Set<number>();
|
|
225
|
+
let maxOrdinal = "ordinal" in current ? current.ordinal : 0;
|
|
214
226
|
for (const [uuid, node] of nodes) {
|
|
215
227
|
if (!selected.has(uuid)) continue;
|
|
216
|
-
const
|
|
228
|
+
const position = positionOf(node.first);
|
|
229
|
+
if ("ordinal" in position) maxOrdinal = Math.max(maxOrdinal, position.ordinal);
|
|
230
|
+
const id = windowId(position);
|
|
231
|
+
let window = windowsById.get(id);
|
|
232
|
+
if (!window) {
|
|
233
|
+
window = { windowId: id, ...("ordinal" in position ? { ordinal: position.ordinal } : {}), items: [] };
|
|
234
|
+
windowsById.set(id, window);
|
|
235
|
+
}
|
|
217
236
|
window.createdAt ??= node.items[0]?.createdAt;
|
|
218
|
-
for (const item of node.items) { branchSeqs.add(item.seq); window.items.push({ ...item, windowId:
|
|
237
|
+
for (const item of node.items) { branchSeqs.add(item.seq); window.items.push({ ...item, windowId: id }); }
|
|
238
|
+
}
|
|
239
|
+
// Preserve complete-history empty windows (including copied boot ordinals).
|
|
240
|
+
// With gaps, report only evidenced windows, never invent the missing ordinals.
|
|
241
|
+
if (missingAncestors.size === 0) {
|
|
242
|
+
for (let ordinal = 0; ordinal <= maxOrdinal; ordinal++) {
|
|
243
|
+
const id = windowId({ ordinal });
|
|
244
|
+
if (!windowsById.has(id)) windowsById.set(id, { windowId: id, ordinal, items: [] });
|
|
245
|
+
}
|
|
219
246
|
}
|
|
220
|
-
|
|
247
|
+
// Forward references can put a newer numbered window on disk first. Unknown
|
|
248
|
+
// segments are a separate, unordered group, not an inferred place in that timeline.
|
|
249
|
+
const windows = [...windowsById.values()].sort((a, b) => a.ordinal === undefined
|
|
250
|
+
? b.ordinal === undefined ? 0 : 1
|
|
251
|
+
: b.ordinal === undefined ? -1 : a.ordinal - b.ordinal);
|
|
252
|
+
return { ...projectHistory(windows, nextSeq - 1, branchSeqs), missingAncestors: [...missingAncestors], currentWindowOrdinal: "ordinal" in current ? current.ordinal : undefined };
|
|
221
253
|
}
|
|
222
254
|
|
|
223
|
-
export async function readClaudeHistory(source: ClaudeHistorySource): Promise<
|
|
255
|
+
export async function readClaudeHistory(source: ClaudeHistorySource): Promise<ClaudeHistoryProjection> {
|
|
224
256
|
if (!source || typeof source.transcriptPath !== "string" || !source.transcriptPath || typeof source.sessionId !== "string") throw new Error("Claude history transcript_path is unavailable");
|
|
225
257
|
return claudeHistoryFromJsonl(await readFile(source.transcriptPath, "utf8"), source);
|
|
226
258
|
}
|
|
@@ -5,3 +5,16 @@ export const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in t
|
|
|
5
5
|
|
|
6
6
|
/** The same notice as Pi; empty_brain's result explains Claude's deferred reset. */
|
|
7
7
|
export const CLAUDE_WARNING_PROMPT = warningNotice();
|
|
8
|
+
|
|
9
|
+
export const CLAUDE_HISTORY_UNKNOWN_WINDOW = "Claude history cannot determine the current window ordinal across a missing ancestor; restore the ancestry or use a retained notesoup boot to re-anchor it.";
|
|
10
|
+
export const CLAUDE_HISTORY_UNKNOWN_PREVIOUS = 'Cannot resolve "@previous": the immediately preceding window is not confirmed across the ancestry gap. Use an explicit window id from history_windows.';
|
|
11
|
+
export function claudeHistoryUnconfirmedSeq(seq: number): string {
|
|
12
|
+
return `Seq ${seq} is outside the confirmed selected history; it may be on another branch or beyond an unresolved ancestry gap.`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Bounded host-only evidence, outside event documents/search offsets and shared schemas. */
|
|
16
|
+
export function claudeHistoryGapNotice(missing: readonly string[]): string {
|
|
17
|
+
if (missing.length === 0) return "";
|
|
18
|
+
const evidence = missing.slice(0, 5).map((uuid) => JSON.stringify(uuid.length > 160 ? `${uuid.slice(0, 160)}…` : uuid)).join(", ");
|
|
19
|
+
return `Claude history is incomplete: missing ancestor UUID(s): ${evidence}${missing.length > 5 ? `; ${missing.length - 5} more` : ""}. Only confirmed selected ancestry is returned; disconnected prefixes and unrelated branches are excluded. Window IDs containing :unknown: have unconfirmed ordinal/ownership and may span native compactions; they are listed separately after numbered windows, not placed in a chronological order. A later retained boot can re-anchor window numbering, but cannot fill the history gap.\n\n`;
|
|
20
|
+
}
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
|
|
3
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.
|
|
4
4
|
|
|
5
|
-
This client-only plugin transforms existing timeline rows in place: last-word custom messages become sticky cards, and notes_read/notes_write/notes_update tool calls become paper cards with the address, state, and a content or diff preview. It does not read session files or append messages. Other timeline items are unchanged.
|
|
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
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.
|
|
8
8
|
|
|
9
|
-
Notes cards prefer
|
|
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.
|
|
10
|
+
|
|
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
|
+
|
|
13
|
+
Automated tests check transformer payloads with source-derived adapter fixtures, not a live Paseo UI session.
|
|
10
14
|
|
|
11
15
|
Paseo 0.11.2 drops Pi boundary `entry_appended` events from its live timeline. This plugin cannot display messages that Paseo has not received; that adapter gap needs an upstream fix. Messages available through history can be rendered.
|
|
@@ -7,7 +7,9 @@ function label(data: BrainEmpty): string {
|
|
|
7
7
|
if (data.status === "running") return "✂ emptying brain …";
|
|
8
8
|
if (data.error !== undefined) return "✂ brain refused to empty";
|
|
9
9
|
if (data.outcome === "rollover_already_pending") return "✂ already emptying";
|
|
10
|
-
return "✂
|
|
10
|
+
if (data.outcome === "rollover_requested") return "✂ reset requested";
|
|
11
|
+
// A completed tool call (including Claude's acknowledgement) does not prove a reset committed.
|
|
12
|
+
return "✂ empty_brain completed";
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
/** Single-side dashed borders are unreliable on iOS, so the cut line is a row of dash segments. */
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import type { PluginClientContext } from "@getpaseo/plugin/client";
|
|
2
2
|
import { BRAIN_EMPTY_KIND, BRAIN_EMPTY_TOOL, type BrainEmpty } from "../shared/brain-empty.ts";
|
|
3
|
+
import { isRecord, notesoupToolName, resultError, resultText } from "./tool-result.ts";
|
|
3
4
|
|
|
4
5
|
type Transformer = Extract<Parameters<PluginClientContext["addTimelineTransformer"]>[0], { query: { itemType: "tool_call" } }>;
|
|
5
6
|
type Source = Parameters<Transformer["transform"]>[0];
|
|
6
7
|
type ToolCallItem = Extract<Source["item"], { type: "tool_call" }>;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
return typeof value === "object" && value !== null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** empty_brain answers in a plain JSON text block; there is no structured payload. */
|
|
9
|
+
/** Pi answers in JSON text; Claude normally returns a plain acknowledgement. */
|
|
13
10
|
function resultJson(output: unknown): Record<string, unknown> | undefined {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (!part) return undefined;
|
|
11
|
+
const text = resultText(output);
|
|
12
|
+
if (text === undefined) return undefined;
|
|
17
13
|
try {
|
|
18
|
-
const parsed: unknown = JSON.parse(
|
|
14
|
+
const parsed: unknown = JSON.parse(text);
|
|
19
15
|
return isRecord(parsed) ? parsed : undefined;
|
|
20
16
|
} catch {
|
|
21
17
|
return undefined;
|
|
@@ -27,10 +23,7 @@ function brainEmptyData(item: ToolCallItem): BrainEmpty | undefined {
|
|
|
27
23
|
if (item.status === "running") return { status: "running" };
|
|
28
24
|
const wire = resultJson(item.detail.output);
|
|
29
25
|
if (wire && typeof wire.error === "string") return { status: item.status === "failed" ? "failed" : "completed", error: wire.error };
|
|
30
|
-
if (item.status === "failed") {
|
|
31
|
-
const hostError = isRecord(item.error) && typeof item.error.message === "string" ? item.error.message : undefined;
|
|
32
|
-
return { status: "failed", error: hostError ?? "failed" };
|
|
33
|
-
}
|
|
26
|
+
if (item.status === "failed") return { status: "failed", error: resultError(item.detail.output, item.error) };
|
|
34
27
|
if (wire && typeof wire.status === "string") return { status: "completed", outcome: wire.status };
|
|
35
28
|
return { status: "completed" };
|
|
36
29
|
}
|
|
@@ -39,7 +32,7 @@ export const brainEmptyTransformer = {
|
|
|
39
32
|
id: "brain-empty-source",
|
|
40
33
|
query: { itemType: "tool_call" },
|
|
41
34
|
transform: ({ item }: Pick<Source, "item">) => {
|
|
42
|
-
if (item.type !== "tool_call" || item.name !== BRAIN_EMPTY_TOOL) return undefined;
|
|
35
|
+
if (item.type !== "tool_call" || notesoupToolName(item.name) !== BRAIN_EMPTY_TOOL) return undefined;
|
|
43
36
|
const data = brainEmptyData(item);
|
|
44
37
|
return data === undefined ? undefined : { items: [{ type: "plugin" as const, kind: BRAIN_EMPTY_KIND, version: 1, data }] };
|
|
45
38
|
},
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type NotesOp,
|
|
9
9
|
type NotesOpTool,
|
|
10
10
|
} from "../shared/notes-op.ts";
|
|
11
|
+
import { isRecord, notesoupToolName, resultError, resultText } from "./tool-result.ts";
|
|
11
12
|
|
|
12
13
|
type Transformer = Extract<Parameters<PluginClientContext["addTimelineTransformer"]>[0], { query: { itemType: "tool_call" } }>;
|
|
13
14
|
type Source = Parameters<Transformer["transform"]>[0];
|
|
@@ -19,10 +20,6 @@ const OP_BY_TOOL: Record<NotesOpTool, NotesOp["op"]> = {
|
|
|
19
20
|
notes_update: "update",
|
|
20
21
|
};
|
|
21
22
|
|
|
22
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
23
|
-
return typeof value === "object" && value !== null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
23
|
function clip(text: string, maxChars: number): { text: string; truncated: boolean } {
|
|
27
24
|
const chars = Array.from(text);
|
|
28
25
|
return chars.length <= maxChars
|
|
@@ -30,13 +27,6 @@ function clip(text: string, maxChars: number): { text: string; truncated: boolea
|
|
|
30
27
|
: { text: chars.slice(0, maxChars).join(""), truncated: true };
|
|
31
28
|
}
|
|
32
29
|
|
|
33
|
-
/** Prefer the structured payload; fall back to the rendered text blocks. */
|
|
34
|
-
function resultText(output: unknown): string | undefined {
|
|
35
|
-
if (!isRecord(output) || !Array.isArray(output.content)) return undefined;
|
|
36
|
-
const parts = output.content.filter(isRecord).filter((block) => block.type === "text" && typeof block.text === "string");
|
|
37
|
-
return parts.length > 0 ? parts.map((block) => block.text as string).join("\n") : undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
30
|
function baseData(item: ToolCallItem, op: NotesOp["op"], input: unknown): NotesOp | undefined {
|
|
41
31
|
const address = isRecord(input) && typeof input.address === "string" ? input.address : undefined;
|
|
42
32
|
if (!address) return undefined;
|
|
@@ -45,9 +35,9 @@ function baseData(item: ToolCallItem, op: NotesOp["op"], input: unknown): NotesO
|
|
|
45
35
|
return { op, address, status, ...(crumpled ? { crumpled } : {}) };
|
|
46
36
|
}
|
|
47
37
|
|
|
48
|
-
function notesOpData(item: ToolCallItem): NotesOp | undefined {
|
|
49
|
-
const op = OP_BY_TOOL[
|
|
50
|
-
if (
|
|
38
|
+
function notesOpData(item: ToolCallItem, tool: NotesOpTool): NotesOp | undefined {
|
|
39
|
+
const op = OP_BY_TOOL[tool];
|
|
40
|
+
if (item.detail.type !== "unknown") return undefined;
|
|
51
41
|
const { input, output } = item.detail;
|
|
52
42
|
const data = baseData(item, op, input);
|
|
53
43
|
if (!data) return undefined;
|
|
@@ -55,9 +45,9 @@ function notesOpData(item: ToolCallItem): NotesOp | undefined {
|
|
|
55
45
|
|
|
56
46
|
const wire = isRecord(output) && isRecord(output.structuredContent) ? output.structuredContent : undefined;
|
|
57
47
|
if (wire && typeof wire.error === "string") return { ...data, error: wire.error };
|
|
58
|
-
if (data.status === "failed"
|
|
48
|
+
if (data.status === "failed") return { ...data, error: resultError(output, item.error) };
|
|
59
49
|
if (!wire) {
|
|
60
|
-
//
|
|
50
|
+
// Pi history and Claude carry rendered text, not the structured Notesoup payload.
|
|
61
51
|
const text = resultText(output);
|
|
62
52
|
if (text === undefined) return data;
|
|
63
53
|
if (op === "read") {
|
|
@@ -111,8 +101,10 @@ export const notesOpTransformer = {
|
|
|
111
101
|
id: "notes-op-source",
|
|
112
102
|
query: { itemType: "tool_call" },
|
|
113
103
|
transform: ({ item }: Pick<Source, "item">) => {
|
|
114
|
-
if (item.type !== "tool_call"
|
|
115
|
-
const
|
|
104
|
+
if (item.type !== "tool_call") return undefined;
|
|
105
|
+
const tool = notesoupToolName(item.name) as NotesOpTool;
|
|
106
|
+
if (!NOTES_OP_TOOLS.includes(tool)) return undefined;
|
|
107
|
+
const data = notesOpData(item, tool);
|
|
116
108
|
return data === undefined ? undefined : { items: [{ type: "plugin" as const, kind: NOTES_OP_KIND, version: 1, data }] };
|
|
117
109
|
},
|
|
118
110
|
} satisfies Transformer;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Paseo's Pi and Claude adapters use different tool-result envelopes.
|
|
2
|
+
export function isRecord(value: unknown): value is Record<string, unknown> {
|
|
3
|
+
return typeof value === "object" && value !== null;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Strip only Notesoup's exact MCP server prefix, never another server's. */
|
|
7
|
+
export function notesoupToolName(name: string): string {
|
|
8
|
+
const prefix = "mcp__notesoup__";
|
|
9
|
+
return name.startsWith(prefix) ? name.slice(prefix.length) : name;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function textContent(content: unknown): string | undefined {
|
|
13
|
+
if (typeof content === "string") return content;
|
|
14
|
+
if (!Array.isArray(content)) return undefined;
|
|
15
|
+
const parts = content.filter(isRecord).filter((block) => block.type === "text" && typeof block.text === "string");
|
|
16
|
+
return parts.length > 0 ? parts.map((block) => block.text as string).join("\n") : undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Pi live/history: content blocks. Claude: buildToolOutput's output field. */
|
|
20
|
+
export function resultText(output: unknown): string | undefined {
|
|
21
|
+
if (!isRecord(output)) return undefined;
|
|
22
|
+
return textContent(output.content) ?? (typeof output.output === "string" ? output.output : undefined);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Claude failures have no output; handleToolResult preserves the raw block in error. */
|
|
26
|
+
export function resultError(output: unknown, error: unknown): string {
|
|
27
|
+
return resultText(output)
|
|
28
|
+
?? (typeof error === "string" ? error : undefined)
|
|
29
|
+
?? (isRecord(error) ? textContent(error.content) ?? (typeof error.message === "string" ? error.message : undefined) : undefined)
|
|
30
|
+
?? "failed";
|
|
31
|
+
}
|
|
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
import { brainEmptyTransformer } from "../client/brain-empty-transformer.ts";
|
|
4
4
|
import { brainEmptySchema } from "../shared/brain-empty.ts";
|
|
5
|
+
import { claudeEmptyCompleted, claudeEmptyFailed } from "./fixtures/claude-tool-calls.ts";
|
|
5
6
|
|
|
6
7
|
function toolCall(overrides: Record<string, unknown>) {
|
|
7
8
|
return {
|
|
@@ -45,7 +46,29 @@ test("a failed transport call without a payload still fails", () => {
|
|
|
45
46
|
assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "failed", error: "boom" });
|
|
46
47
|
});
|
|
47
48
|
|
|
49
|
+
test("Claude's plain acknowledgement completes the call without inventing a Pi rollover outcome", () => {
|
|
50
|
+
const result = transform(claudeEmptyCompleted);
|
|
51
|
+
assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "completed" });
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("Claude empty_brain running and failed calls use the adapter's null output and raw error", () => {
|
|
55
|
+
const running = transform({ ...claudeEmptyCompleted, status: "running", detail: { ...claudeEmptyCompleted.detail, output: null } });
|
|
56
|
+
assert.deepEqual(brainEmptySchema.parse(running!.items[0]!.data), { status: "running" });
|
|
57
|
+
assert.deepEqual(brainEmptySchema.parse(transform(claudeEmptyFailed)!.items[0]!.data), {
|
|
58
|
+
status: "failed", error: "notesoup: only the main agent can empty this brain",
|
|
59
|
+
});
|
|
60
|
+
const blocks = transform({ ...claudeEmptyFailed, error: { ...claudeEmptyFailed.error, content: [{ type: "text", text: "notesoup: last_word must be a string" }] } });
|
|
61
|
+
assert.deepEqual(brainEmptySchema.parse(blocks!.items[0]!.data), { status: "failed", error: "notesoup: last_word must be a string" });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("Pi failed calls still surface text-block errors when no JSON receipt exists", () => {
|
|
65
|
+
const result = transform({ status: "failed", detail: { type: "unknown", input: {}, output: { content: [{ type: "text", text: "io failed" }] } } });
|
|
66
|
+
assert.deepEqual(brainEmptySchema.parse(result!.items[0]!.data), { status: "failed", error: "io failed" });
|
|
67
|
+
});
|
|
68
|
+
|
|
48
69
|
test("other tools and non-tool items stay untouched", () => {
|
|
49
|
-
|
|
70
|
+
for (const name of ["notes_read", "mcp__other__empty_brain", "mcp__notesoup_extra__empty_brain", "mcp__notesoup__empty_brain_extra", "mcp__notesoup__mcp__notesoup__empty_brain"]) {
|
|
71
|
+
assert.equal(transform({ name }), undefined, name);
|
|
72
|
+
}
|
|
50
73
|
assert.equal(brainEmptyTransformer.transform({ item: { type: "user_message", text: "hi" } as never }), undefined);
|
|
51
74
|
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Source-derived timeline fixtures, not a live UI capture.
|
|
2
|
+
// Paseo packages/server/src/server/agent/providers/claude/agent.ts:
|
|
3
|
+
// handleToolUseStart -> { input, output: null }; handleToolResult/buildToolOutput
|
|
4
|
+
// -> { output: text } on success, null output + raw tool_result in error on failure.
|
|
5
|
+
// tool-call-mapper.ts / tool-call-detail-parser.ts keep Notesoup calls as "unknown".
|
|
6
|
+
// Receipt strings follow src/tools/notes.ts and plugins/claude/hooks/register.ts.
|
|
7
|
+
|
|
8
|
+
export const claudeReadCompleted = {
|
|
9
|
+
type: "tool_call",
|
|
10
|
+
callId: "toolu_notes_read",
|
|
11
|
+
name: "mcp__notesoup__notes_read",
|
|
12
|
+
status: "completed",
|
|
13
|
+
error: null,
|
|
14
|
+
detail: {
|
|
15
|
+
type: "unknown",
|
|
16
|
+
input: { address: "@self/foo.md" },
|
|
17
|
+
output: { output: "@self/foo.md\norigin self | created 2026-10-17T10:00:00+08:00 | updated 2026-10-17T10:00:00+08:00 | accessed 2026-10-17T10:00:00+08:00\n\nbody line one\nbody line two" },
|
|
18
|
+
},
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
export const claudeWriteCompleted = {
|
|
22
|
+
type: "tool_call",
|
|
23
|
+
callId: "toolu_notes_write",
|
|
24
|
+
name: "mcp__notesoup__notes_write",
|
|
25
|
+
status: "completed",
|
|
26
|
+
error: null,
|
|
27
|
+
detail: {
|
|
28
|
+
type: "unknown",
|
|
29
|
+
input: { address: "a.md", content: "the new body" },
|
|
30
|
+
output: { output: "overwrote a.md (project pi-context)" },
|
|
31
|
+
},
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
export const claudeUpdateCompleted = {
|
|
35
|
+
type: "tool_call",
|
|
36
|
+
callId: "toolu_notes_update",
|
|
37
|
+
name: "mcp__notesoup__notes_update",
|
|
38
|
+
status: "completed",
|
|
39
|
+
error: null,
|
|
40
|
+
detail: {
|
|
41
|
+
type: "unknown",
|
|
42
|
+
input: { address: "a.md", edits: [{ oldText: "old", newText: "new" }] },
|
|
43
|
+
output: { output: "updated a.md (project pi-context)\ndiff:\n- 1 - old\n+ 1 + new" },
|
|
44
|
+
},
|
|
45
|
+
} as const;
|
|
46
|
+
|
|
47
|
+
export const claudeReadFailed = {
|
|
48
|
+
type: "tool_call",
|
|
49
|
+
callId: "toolu_notes_read",
|
|
50
|
+
name: "mcp__notesoup__notes_read",
|
|
51
|
+
status: "failed",
|
|
52
|
+
error: {
|
|
53
|
+
type: "tool_result",
|
|
54
|
+
tool_use_id: "toolu_notes_read",
|
|
55
|
+
is_error: true,
|
|
56
|
+
content: [{ type: "text", text: "No note at @self/foo.md." }],
|
|
57
|
+
},
|
|
58
|
+
detail: { type: "unknown", input: { address: "@self/foo.md" }, output: null },
|
|
59
|
+
} as const;
|
|
60
|
+
|
|
61
|
+
export const claudeEmptyCompleted = {
|
|
62
|
+
type: "tool_call",
|
|
63
|
+
callId: "toolu_empty_brain",
|
|
64
|
+
name: "mcp__notesoup__empty_brain",
|
|
65
|
+
status: "completed",
|
|
66
|
+
error: null,
|
|
67
|
+
detail: {
|
|
68
|
+
type: "unknown",
|
|
69
|
+
input: { last_word: "bye" },
|
|
70
|
+
output: { output: "Brain will be emptied after this turn. End your turn now; do not call more tools or explain things to the human before the reset." },
|
|
71
|
+
},
|
|
72
|
+
} as const;
|
|
73
|
+
|
|
74
|
+
export const claudeEmptyFailed = {
|
|
75
|
+
type: "tool_call",
|
|
76
|
+
callId: "toolu_empty_brain",
|
|
77
|
+
name: "mcp__notesoup__empty_brain",
|
|
78
|
+
status: "failed",
|
|
79
|
+
error: {
|
|
80
|
+
type: "tool_result",
|
|
81
|
+
tool_use_id: "toolu_empty_brain",
|
|
82
|
+
is_error: true,
|
|
83
|
+
content: "notesoup: only the main agent can empty this brain",
|
|
84
|
+
},
|
|
85
|
+
detail: { type: "unknown", input: {}, output: null },
|
|
86
|
+
} as const;
|
|
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
|
|
|
2
2
|
import test from "node:test";
|
|
3
3
|
import { notesOpTransformer } from "../client/notes-op-transformer.ts";
|
|
4
4
|
import { DIFF_MAX_CHARS, PREVIEW_MAX_CHARS, READ_TEXT_MAX_CHARS, notesOpSchema } from "../shared/notes-op.ts";
|
|
5
|
+
import { claudeReadCompleted, claudeReadFailed, claudeUpdateCompleted, claudeWriteCompleted } from "./fixtures/claude-tool-calls.ts";
|
|
5
6
|
|
|
6
7
|
function toolCall(overrides: Record<string, unknown>) {
|
|
7
8
|
return {
|
|
@@ -118,12 +119,49 @@ test("history replay has no structured payload: the rendered text is parsed inst
|
|
|
118
119
|
});
|
|
119
120
|
|
|
120
121
|
test("non-notes tools, unknown shapes and missing addresses stay untouched", () => {
|
|
121
|
-
|
|
122
|
+
for (const name of ["bash", "mcp__other__notes_read", "mcp__notesoup_extra__notes_write", "mcp__notesoup__notes_list", "mcp__notesoup__mcp__notesoup__notes_read"]) {
|
|
123
|
+
assert.equal(transform({ name }), undefined, name);
|
|
124
|
+
}
|
|
122
125
|
assert.equal(notesOpTransformer.transform({ item: toolCall({ detail: { type: "plain_text", text: "hi" } }) as never }), undefined);
|
|
123
126
|
assert.equal(notesOpTransformer.transform({ item: toolCall({ detail: { type: "unknown", input: {}, output: {} } }) as never }), undefined);
|
|
124
127
|
assert.equal(notesOpTransformer.transform({ item: { type: "user_message", text: "hi" } as never }), undefined);
|
|
125
128
|
});
|
|
126
129
|
|
|
130
|
+
test("Claude completed calls use the adapter's output text for read, write preview and update diff", () => {
|
|
131
|
+
const read = notesOpSchema.parse(transform(claudeReadCompleted)!.items[0]!.data);
|
|
132
|
+
assert.deepEqual(read, { op: "read", address: "@self/foo.md", status: "completed", text: "body line one\nbody line two" });
|
|
133
|
+
assert.deepEqual(notesOpSchema.parse(transform(claudeWriteCompleted)!.items[0]!.data), {
|
|
134
|
+
op: "write", address: "a.md", status: "completed", outcome: "overwrote", preview: "the new body",
|
|
135
|
+
});
|
|
136
|
+
assert.deepEqual(notesOpSchema.parse(transform(claudeUpdateCompleted)!.items[0]!.data), {
|
|
137
|
+
op: "update", address: "a.md", status: "completed", changeKind: "body", diff: "- 1 - old\n+ 1 + new",
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test("Claude running calls render from input with null output", () => {
|
|
142
|
+
for (const [op, call] of [["read", claudeReadCompleted], ["write", claudeWriteCompleted], ["update", claudeUpdateCompleted]] as const) {
|
|
143
|
+
const running = transform({ ...call, status: "running", detail: { ...call.detail, output: null } });
|
|
144
|
+
assert.deepEqual(notesOpSchema.parse(running!.items[0]!.data), { op, address: call.detail.input.address, status: "running" });
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test("Claude failures keep raw error content and transport messages instead of parsing them as notes", () => {
|
|
149
|
+
assert.deepEqual(notesOpSchema.parse(transform(claudeReadFailed)!.items[0]!.data), {
|
|
150
|
+
op: "read", address: "@self/foo.md", status: "failed", error: "No note at @self/foo.md.",
|
|
151
|
+
});
|
|
152
|
+
const write = transform({
|
|
153
|
+
...claudeWriteCompleted, status: "failed",
|
|
154
|
+
detail: { ...claudeWriteCompleted.detail, output: null },
|
|
155
|
+
error: { type: "tool_result", tool_use_id: claudeWriteCompleted.callId, is_error: true, content: "Disk full" },
|
|
156
|
+
});
|
|
157
|
+
assert.deepEqual(notesOpSchema.parse(write!.items[0]!.data), { op: "write", address: "a.md", status: "failed", error: "Disk full" });
|
|
158
|
+
const update = transform({
|
|
159
|
+
...claudeUpdateCompleted, status: "failed", error: { message: "MCP connection closed" },
|
|
160
|
+
detail: { ...claudeUpdateCompleted.detail, output: null },
|
|
161
|
+
});
|
|
162
|
+
assert.deepEqual(notesOpSchema.parse(update!.items[0]!.data), { op: "update", address: "a.md", status: "failed", error: "MCP connection closed" });
|
|
163
|
+
});
|
|
164
|
+
|
|
127
165
|
function result_items(result: { items: Array<{ data: unknown }> } | undefined) {
|
|
128
166
|
return result!.items.map((item) => item.data);
|
|
129
167
|
}
|
package/skills/dream/SKILL.md
CHANGED
|
@@ -10,3 +10,11 @@ Read `../../playbook.md` completely, resolving the path from this skill's direct
|
|
|
10
10
|
Dream in this agent's current session. Do not start another agent or model unless the human asks.
|
|
11
11
|
|
|
12
12
|
Work within the supplied readable and writable scope. If the scope or permission to write has not been established, ask rather than inventing it or setting up execution machinery yourself.
|
|
13
|
+
|
|
14
|
+
## Tools
|
|
15
|
+
|
|
16
|
+
Use `dream_begin`, `dream_forget`, and `dream_end` for the dream lifecycle. If any are missing from the current tool list, search for them before proceeding. If they remain unavailable, report that limitation rather than inventing a replacement backend.
|
|
17
|
+
|
|
18
|
+
- Every dream starts with `dream_begin`, before reading or editing any notes.
|
|
19
|
+
- Use `notes_*` to read and organize notes within the established scope. `dream_forget` permanently deletes a crumpled note when the playbook permits it; never delete a live note.
|
|
20
|
+
- `dream_end` closes the open dream. Close it when finished, and report any partial failures.
|
package/src/history/history.ts
CHANGED
|
@@ -146,28 +146,30 @@ function toolEvent(item: DecodedHistoryItem, result?: DecodedHistoryItem): Histo
|
|
|
146
146
|
|
|
147
147
|
/** Pair results into call events; consumed result seqs are not alternate read addresses. */
|
|
148
148
|
export function projectHistory(rawWindows: DecodedHistoryWindow[], highestSeq: number, branchSeqs: Set<number>): HistoryProjection {
|
|
149
|
-
|
|
149
|
+
// Pair in durable address order, not window presentation order. Unnumbered
|
|
150
|
+
// segments need not have a provable chronological order relative to each other.
|
|
151
|
+
const raw = rawWindows.flatMap((current) => current.items).sort((a, b) => a.seq - b.seq);
|
|
150
152
|
const resultsById = new Map<string, DecodedHistoryItem>();
|
|
151
153
|
for (const item of raw) {
|
|
152
154
|
if (item.role === "tool" && item.toolCallId && !resultsById.has(item.toolCallId)) resultsById.set(item.toolCallId, item);
|
|
153
155
|
}
|
|
154
156
|
const pairedResults = new Map<number, number>();
|
|
155
|
-
const
|
|
157
|
+
for (const item of raw) {
|
|
158
|
+
const result = item.role === "tool_call" && item.toolCallId ? resultsById.get(item.toolCallId) : undefined;
|
|
159
|
+
if (result && result.seq > item.seq && !pairedResults.has(result.seq)) {
|
|
160
|
+
pairedResults.set(result.seq, item.seq);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
156
163
|
const windows: HistoryWindow[] = rawWindows.map((current) => ({
|
|
157
164
|
windowId: current.windowId,
|
|
158
165
|
...(current.createdAt ? { createdAt: current.createdAt } : {}),
|
|
159
166
|
items: current.items.flatMap((item): HistoryEvent[] => {
|
|
160
|
-
if (
|
|
161
|
-
if (item.role === "tool_call") {
|
|
167
|
+
if (pairedResults.has(item.seq)) return [];
|
|
168
|
+
if (item.role === "tool_call" || item.role === "tool") {
|
|
162
169
|
const result = item.toolCallId ? resultsById.get(item.toolCallId) : undefined;
|
|
163
|
-
const paired = result && result.seq
|
|
164
|
-
if (paired) {
|
|
165
|
-
consumed.add(paired.seq);
|
|
166
|
-
pairedResults.set(paired.seq, item.seq);
|
|
167
|
-
}
|
|
170
|
+
const paired = result && pairedResults.get(result.seq) === item.seq ? result : undefined;
|
|
168
171
|
return [toolEvent(item, paired)];
|
|
169
172
|
}
|
|
170
|
-
if (item.role === "tool") return [toolEvent(item)];
|
|
171
173
|
return [{ seq: item.seq, windowId: item.windowId, role: item.role === "system" || item.role === "developer" ? "context" : item.role, text: item.text, createdAt: item.createdAt }];
|
|
172
174
|
}),
|
|
173
175
|
}));
|
package/src/notes/store.ts
CHANGED
|
@@ -33,7 +33,8 @@ export type EditOptions = { origin?: Origin; crumpled?: boolean; replaceAll?: bo
|
|
|
33
33
|
*/
|
|
34
34
|
export type NotesQuery = { glob?: string | null; crumpled?: boolean };
|
|
35
35
|
/** A read exposes metadata and the pure body; the serialized frontmatter is never part of the body. */
|
|
36
|
-
|
|
36
|
+
/** `accessedBefore` is the last access before this read, so a read never hides how long a note sat unread. */
|
|
37
|
+
export type NoteReadResult = { meta: NoteMeta; body: string; resolvedScope: Scope; accessedBefore: number };
|
|
37
38
|
export type NoteWriteResult = { meta: NoteMeta; outcome: "created" | "overwrote" | "uncrumpled" };
|
|
38
39
|
export type NoteChange =
|
|
39
40
|
| { kind: "none"; before: ""; after: "" }
|
|
@@ -328,11 +329,11 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
|
|
|
328
329
|
const now = Date.now();
|
|
329
330
|
const parsed = parseNote(raw, now);
|
|
330
331
|
// Named homes, and every read during a dream, leave no access stamp.
|
|
331
|
-
if (identity.dreaming !== undefined || ((scope === "project" || scope === "session") && destination.who !== undefined)) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
|
|
332
|
+
if (identity.dreaming !== undefined || ((scope === "project" || scope === "session") && destination.who !== undefined)) return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope, accessedBefore: parsed.meta.lastAccessed };
|
|
332
333
|
// A read records its own access, exactly as a write records an edit.
|
|
333
334
|
const meta: NoteMeta = { ...parsed.meta, scope, lastAccessed: now, accessCount: (typeof parsed.meta.accessCount === "number" ? parsed.meta.accessCount : 0) + 1 };
|
|
334
335
|
await atomicWrite(path, serializeNote(meta, parsed.body));
|
|
335
|
-
return { meta, body: parsed.body, resolvedScope: scope };
|
|
336
|
+
return { meta, body: parsed.body, resolvedScope: scope, accessedBefore: parsed.meta.lastAccessed };
|
|
336
337
|
});
|
|
337
338
|
}
|
|
338
339
|
|