notesoup 0.52.6 → 0.53.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 (84) hide show
  1. package/README.md +3 -1
  2. package/dist/plugins/claude/src/helper.js +34 -7
  3. package/dist/plugins/claude/src/history.d.ts +7 -2
  4. package/dist/plugins/claude/src/history.js +53 -22
  5. package/dist/plugins/claude/src/text.d.ts +5 -0
  6. package/dist/plugins/claude/src/text.js +12 -0
  7. package/dist/plugins/codex/src/cli.d.ts +2 -0
  8. package/dist/plugins/codex/src/cli.js +25 -0
  9. package/dist/plugins/codex/src/history.d.ts +8 -0
  10. package/dist/plugins/codex/src/history.js +238 -0
  11. package/dist/plugins/codex/src/hooks.d.ts +9 -0
  12. package/dist/plugins/codex/src/hooks.js +196 -0
  13. package/dist/plugins/codex/src/identity.d.ts +35 -0
  14. package/dist/plugins/codex/src/identity.js +134 -0
  15. package/dist/plugins/codex/src/mcp.d.ts +7 -0
  16. package/dist/plugins/codex/src/mcp.js +159 -0
  17. package/dist/plugins/codex/src/state.d.ts +23 -0
  18. package/dist/plugins/codex/src/state.js +92 -0
  19. package/dist/plugins/codex/src/text.d.ts +14 -0
  20. package/dist/plugins/codex/src/text.js +25 -0
  21. package/dist/plugins/codex/src/transcript.d.ts +39 -0
  22. package/dist/plugins/codex/src/transcript.js +313 -0
  23. package/dist/src/boot/render.js +11 -10
  24. package/dist/src/boot/text.d.ts +4 -5
  25. package/dist/src/boot/text.js +14 -28
  26. package/dist/src/budget/text.d.ts +1 -1
  27. package/dist/src/budget/text.js +1 -1
  28. package/dist/src/history/history.js +12 -11
  29. package/dist/src/tools/history.d.ts +5 -3
  30. package/dist/src/tools/history.js +9 -11
  31. package/dist/test/claude-history.test.js +135 -3
  32. package/dist/test/codex-history.test.d.ts +1 -0
  33. package/dist/test/codex-history.test.js +330 -0
  34. package/dist/test/codex-plugin.test.d.ts +1 -0
  35. package/dist/test/codex-plugin.test.js +365 -0
  36. package/dist/test/dependencies.test.js +8 -2
  37. package/dist/test/dsh.test.js +1 -1
  38. package/dist/test/helpers/dependency-graph.js +1 -1
  39. package/dist/test/history.integration.test.js +26 -1
  40. package/dist/test/model-facing-text.test.js +41 -26
  41. package/dist/test/notes.integration.test.js +3 -0
  42. package/docs/claude-code-mod.md +6 -2
  43. package/docs/codex.md +91 -0
  44. package/docs/dsh.md +1 -1
  45. package/docs/reset-lifecycle.md +1 -1
  46. package/docs/tool-results.md +2 -2
  47. package/package.json +6 -3
  48. package/playbook.md +1 -1
  49. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  50. package/plugins/claude/dist/claude/helper.js +120 -74
  51. package/plugins/claude/playbook.md +1 -1
  52. package/plugins/claude/skills/dream/SKILL.md +1 -1
  53. package/plugins/claude/skills/memory/SKILL.md +1 -1
  54. package/plugins/claude/src/helper.ts +34 -9
  55. package/plugins/claude/src/history.ts +54 -22
  56. package/plugins/claude/src/text.ts +13 -0
  57. package/plugins/codex/README.md +43 -0
  58. package/plugins/codex/dist/codex/notesoup.js +27800 -0
  59. package/plugins/codex/hooks/hooks.json +41 -0
  60. package/plugins/codex/mcp.json +10 -0
  61. package/plugins/codex/plugin.json +6 -0
  62. package/plugins/codex/src/cli.ts +26 -0
  63. package/plugins/codex/src/history.ts +193 -0
  64. package/plugins/codex/src/hooks.ts +190 -0
  65. package/plugins/codex/src/identity.ts +147 -0
  66. package/plugins/codex/src/mcp.ts +171 -0
  67. package/plugins/codex/src/state.ts +102 -0
  68. package/plugins/codex/src/text.ts +31 -0
  69. package/plugins/codex/src/transcript.ts +275 -0
  70. package/plugins/paseo/OVERVIEW.md +6 -2
  71. package/plugins/paseo/client/brain-empty-card.tsx +3 -1
  72. package/plugins/paseo/client/brain-empty-transformer.ts +7 -14
  73. package/plugins/paseo/client/notes-op-transformer.ts +10 -18
  74. package/plugins/paseo/client/tool-result.ts +31 -0
  75. package/plugins/paseo/test/brain-empty.test.ts +24 -1
  76. package/plugins/paseo/test/fixtures/claude-tool-calls.ts +86 -0
  77. package/plugins/paseo/test/notes-op.test.ts +39 -1
  78. package/skills/dream/SKILL.md +1 -1
  79. package/skills/memory/SKILL.md +1 -1
  80. package/src/boot/render.ts +11 -9
  81. package/src/boot/text.ts +16 -30
  82. package/src/budget/text.ts +1 -1
  83. package/src/history/history.ts +12 -10
  84. package/src/tools/history.ts +14 -13
@@ -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
- function isRecord(value: unknown): value is Record<string, unknown> {
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
- if (!isRecord(output) || !Array.isArray(output.content)) return undefined;
15
- const part = output.content.filter(isRecord).find((block) => block.type === "text" && typeof block.text === "string");
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(part.text as string);
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[item.name as NotesOpTool];
50
- if (!op || item.detail.type !== "unknown") return undefined;
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" && !wire) return { ...data, error: resultText(output) ?? "failed" };
48
+ if (data.status === "failed") return { ...data, error: resultError(output, item.error) };
59
49
  if (!wire) {
60
- // History replay reconstructs results without the structured payload; parse the rendered text.
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" || !NOTES_OP_TOOLS.includes(item.name as NotesOpTool)) return undefined;
115
- const data = notesOpData(item);
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
- assert.equal(brainEmptyTransformer.transform({ item: toolCall({ name: "notes_read" }) as never }), undefined);
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
- assert.equal(notesOpTransformer.transform({ item: toolCall({ name: "bash" }) as never }), undefined);
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
  }
@@ -5,7 +5,7 @@ description: Review and consolidate durable notes using notesoup's shared dream
5
5
 
6
6
  # Dream
7
7
 
8
- Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. MAP may include a short Cheatsheet of rules that apply in every window (about 5 lines); the rest stays the note index, for lookup.
8
+ Read `../../playbook.md` completely, resolving the path from this skill's directory. It is the shared guide to reviewing and organizing notes. Standing reminders belong in a separate `CHEATSHEET.md` (five lines); `MAP.md` holds only the note index. Both load every window when present.
9
9
 
10
10
  Dream in this agent's current session. Do not start another agent or model unless the human asks.
11
11
 
@@ -32,7 +32,7 @@ Any other `@` prefix is refused. A path is relative and `/`-separated, with no e
32
32
 
33
33
  `@` addresses are not file paths: never pass them to file tools like `read`, `write`, `edit`, or `bash`. That creates a stray directory instead of a note.
34
34
 
35
- `MAP.md` at the root of each `@` home is a page you wake up with. It may include a Cheatsheet of rules that apply in every window; keep it short, about 5 lines. The rest is the note index: each durable note's address and gist, for lookup. Update it whenever you add, move or crumple a durable note.
35
+ `CHEATSHEET.md` and `MAP.md` at the root of each `@` home are separate pages you wake up with; absent pages are skipped. Keep standing reminders in `CHEATSHEET.md`, to five lines. `MAP.md` holds only the note index: each durable note's address and gist, for lookup. Update it whenever you add, move or crumple a durable note. Do not create empty pages.
36
36
 
37
37
  Write only what git and history cannot give back. Crumple notes that are no longer true; a stale note is worse than none.
38
38
 
@@ -35,7 +35,7 @@ function section(label: string, body: string): string {
35
35
  /** Pi's default agent slug: an unnamed agent shares its `@self` shelf with every other nameless one. */
36
36
  const NAMELESS_AGENT = "anonymous";
37
37
 
38
- /** One closed boot snapshot: five tabbed shelves, current hands first, durable last; each shelf keeps its map and its own freshest pages. */
38
+ /** One closed boot snapshot: five tabbed shelves, current hands first, durable last; each shelf keeps its pinned pages and its own freshest pages. */
39
39
  function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: string, modelName: string): string {
40
40
  const homes: ReadonlyArray<{ scope: NotesHome["scope"]; label: string }> = [
41
41
  { scope: "session", label: "no @ — this session" },
@@ -52,18 +52,20 @@ function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: st
52
52
  continue;
53
53
  }
54
54
  const rows = (snapshot.homes.get(home.scope) ?? []).filter((row) => row.meta.crumpledAt === undefined);
55
- const map = rows.find((row) => row.path === "MAP.md");
55
+ const pinned = ["CHEATSHEET.md", "MAP.md"].flatMap((path) => {
56
+ const row = rows.find((row) => row.path === path);
57
+ return row?.body ? [row] : [];
58
+ });
56
59
  const fresh = rows
57
- .filter((row) => row.path !== "MAP.md")
60
+ .filter((row) => row.path !== "MAP.md" && row.path !== "CHEATSHEET.md")
58
61
  .slice(0, SHELF_FRESH_LIMIT)
59
62
  .map((row) => {
60
63
  const locator = `${row.address} · ${relativeTime(row.meta.updatedAt, snapshot.openedAt)}`;
61
64
  const title = feedTitle(row.body);
62
65
  return title === undefined ? ` ${locator}` : ` ${title}\n ${locator}`;
63
66
  });
64
- if (!map?.body && fresh.length === 0) continue;
65
- const parts: string[] = [];
66
- if (map?.body) parts.push(`map\n\n${indent(mapBodyForBoot(map.address, map.body))}`);
67
+ if (pinned.length === 0 && fresh.length === 0) continue;
68
+ const parts = pinned.map((row) => `${row.path === "MAP.md" ? "map" : "cheatsheet"}\n\n${indent(pinnedBodyForBoot(row.address, row.body))}`);
67
69
  if (fresh.length > 0) parts.push(`recent\n\n${fresh.join("\n\n")}`);
68
70
  shelves.push(section(home.label, parts.join("\n\n")));
69
71
  }
@@ -73,11 +75,11 @@ function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: st
73
75
  : "YOUR NOTES\n──────────\n\nNone yet. A blank slate is a fine place to start — just don't finish there.";
74
76
  }
75
77
 
76
- /** One unbounded MAP body fits the boot only up to the cap; the cut names where the rest lives. */
77
- function mapBodyForBoot(address: string, body: string): string {
78
+ /** Each pinned page is bounded; the cut names where the rest lives. */
79
+ function pinnedBodyForBoot(address: string, body: string): string {
78
80
  const chars = Array.from(body);
79
81
  if (chars.length <= MAP_BOOT_MAX_CHARS) return body;
80
- return `${chars.slice(0, MAP_BOOT_MAX_CHARS).join("")}\n[truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this MAP down, full body at \`${address}\`]`;
82
+ return `${chars.slice(0, MAP_BOOT_MAX_CHARS).join("")}\n[truncated at ${MAP_BOOT_MAX_CHARS} chars; slim this page down, full body at \`${address}\`]`;
81
83
  }
82
84
 
83
85
  export type BootWindowTree = {
package/src/boot/text.ts CHANGED
@@ -1,6 +1,6 @@
1
- /** Each shelf shows this many of its own freshest pages beneath the map. */
1
+ /** Each shelf shows this many of its own freshest pages beneath its pinned pages. */
2
2
  export const SHELF_FRESH_LIMIT = 3;
3
- /** One MAP body is inlined per home; past this many code points the boot shows a fitting prefix plus a pointer. */
3
+ /** Each pinned page is inlined per home up to this many code points, then a lookup pointer. */
4
4
  export const MAP_BOOT_MAX_CHARS = 4096;
5
5
  export const WINDOW_IDENTITY_OPEN_TAG = "<notesoup:window_identity>";
6
6
  export const WINDOW_IDENTITY_CLOSE_TAG = "</notesoup:window_identity>";
@@ -54,36 +54,22 @@ Any other @ address is fake. End of discussion. @ addresses are not file paths:
54
54
  ${NOTES_PROTOCOL_CLOSE_TAG}`;
55
55
 
56
56
  /**
57
- * The MAP page is taught once per window, as its own section between the protocol and the notes
58
- * index. A MAP is the one note every waking window loads, so this block says what one holds.
57
+ * The two pinned pages are taught once per window between the protocol and the notes index.
59
58
  */
60
59
  export const MAPS_BLOCK = `<notesoup:maps>
61
- Every home's root can hold a \`MAP.md\`, and a MAP is the one page that never waits on a shelf — it
62
- gets jammed straight into your brain the moment you wake up. No asking, no skipping. Whoever wakes
63
- up next reads it, and next is you. So keep it short, and keep it true.
64
-
65
- Two things live in there:
66
-
67
- - **Cheatsheet.** A cheatsheet is a cheatsheet. Scribble whatever you'll want next time — a rule, a
68
- warning, a grudge, a name, a phone number you'll regret losing. Nobody grades it. Just keep it
69
- under five lines, or it grows fat and everybody pays for it.
70
- - **Index.** One line per durable note: the address, then a gist short enough to tell whether the
71
- thing is worth opening.
72
-
73
- \`\`\`
74
- # CHEATSHEET
75
- - Read the repo before asking; run it before believing it
76
- - Report times in Beijing time
77
-
78
- # INDEX
79
- - release-and-local-install.md — version bump, local override install, host load timing
80
- - history-api-v2-design.md — seq addressing; read before touching history
81
- - current-reset-and-dream-scope.md — reset scope, dream territory, session ownership
82
- \`\`\`
83
-
84
- Every home gets one: \`@project\`, \`@human\`, \`@self\`, \`@model\`. New note, new line. New rule worth
85
- remembering, new Cheatsheet line. And when a line stops being true, kill it — every window after you
86
- reads that page as fact.
60
+ Every home's root can hold two pages that never wait on a shelf: \`CHEATSHEET.md\` and \`MAP.md\`.
61
+ Both get jammed straight into your brain the moment you wake up. No asking, no skipping. Whoever
62
+ wakes up next reads them, and next is you. So keep them short, and keep them true.
63
+
64
+ - **\`CHEATSHEET.md\`** holds what you'll want next time — a rule, a warning, a grudge, a name,
65
+ a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
66
+ and everybody pays for it.
67
+ - **\`MAP.md\`** is only the note index. One line per durable note: the address, then a gist short
68
+ enough to tell whether the thing is worth opening. Rules belong in \`CHEATSHEET.md\`, not here.
69
+
70
+ Each home keeps its own: \`@project\`, \`@human\`, \`@self\`, \`@model\`. Missing pages are skipped;
71
+ no need to create empty ones. New note, new MAP line. New rule worth remembering, new Cheatsheet
72
+ line. And when a line stops being true, kill it — every window after you reads that page as fact.
87
73
  </notesoup:maps>`;
88
74
 
89
75
  /** Logical tool names are supplied by the composing host, not discovered here. */
@@ -33,7 +33,7 @@ export const WARNING_TIMING = "The reserve is nearly spent. The wipe lands at th
33
33
 
34
34
  /** The shared handoff instructions, used for both budget and manual close-outs. */
35
35
  export const WARNING_BODY =
36
- "Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim the MAP files; every new window loads them. The next window gets whatever you leave, dead notes and dead sections alike.\nDon't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.";
36
+ "Stop the task. Write down what git and history can't give back:\n- where you are, and how far you got\n- what the human decided, in their words\n- what's blocked or waiting\n- the next move\n- where the half-done work sits\n- what failed, and why\n- which skills, seqs, notes, or files to reopen\n- anything else worth noting\nThen leave the shelf current: replace what's stale, a whole note or a section inside one, and crumple the dead ones. Update and trim CHEATSHEET.md and MAP.md; every new window loads them. The next window gets whatever you leave, dead notes and dead sections alike.\nDon't call anything that might return a large output. One big read can spend the rest of the reserve before your notes are saved.";
37
37
 
38
38
  export const WARNING_CALL = "Then call `empty_brain`. Nothing in between.";
39
39
 
@@ -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
- const raw = rawWindows.flatMap((current) => current.items);
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 consumed = new Set<number>();
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 (consumed.has(item.seq)) return [];
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 > item.seq && !consumed.has(result.seq) ? result : undefined;
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
  }));
@@ -80,10 +80,9 @@ function renderRead(data: HistoryReadData): string {
80
80
 
81
81
  /* ------------------------------------------------------------------ shared bounding */
82
82
 
83
- /** Include rendering and cursors in the budget, not just row contents. */
84
- function pageFits(page: HistoryPage): boolean {
85
- return fitsResult(success(page), (result) => renderOutcome(result, renderPage));
86
- }
83
+ /** Pure host decoration, measured during selection and applied unchanged by the caller at delivery. */
84
+ export type HistoryTextWrapper = (text: string) => string;
85
+ const plainText: HistoryTextWrapper = (text) => text;
87
86
 
88
87
  // Sample known ids in the refusal message itself, never as a second listing.
89
88
  const MAX_REPORTED_WINDOWS = 5;
@@ -114,15 +113,15 @@ function badWindowId(projection: HistoryProjection, params: HistoryFilter): Outc
114
113
 
115
114
  export const historyWindowsParameters = Type.Object({}, { additionalProperties: false });
116
115
 
117
- export const historyWindows: Operation<typeof historyWindowsParameters, HistoryWindowsData, [HistoryProjection, string]> = {
116
+ export const historyWindows: Operation<typeof historyWindowsParameters, HistoryWindowsData, [HistoryProjection, string, HistoryTextWrapper?]> = {
118
117
  name: "history_windows",
119
118
  label: "History list windows",
120
119
  description: "List this session's context windows, oldest first, with seq ranges.",
121
120
  parameters: historyWindowsParameters,
122
121
  outputSchema: resultSchema(HistoryWindowsDataSchema),
123
- async execute(_params, projection, sessionId) {
122
+ async execute(_params, projection, sessionId, wrapText = plainText) {
124
123
  const data: HistoryWindowsData = { session_id: sessionId, windows: [], more: projection.windows.length };
125
- const fits = (candidate: HistoryWindowsData) => fitsResult(success(candidate), (result) => renderOutcome(result, renderWindows));
124
+ const fits = (candidate: HistoryWindowsData) => fitsResult(success(candidate), (result) => wrapText(renderOutcome(result, renderWindows)));
126
125
  for (const window of projection.windows) {
127
126
  let first: number | null = null;
128
127
  let last: number | null = null;
@@ -161,19 +160,21 @@ export const historyListParameters = Type.Object({
161
160
  max_chars_per_item: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: `(optional, default ${HISTORY_PREVIEW_CHARS}) Max preview chars per event.` })),
162
161
  }, { additionalProperties: false });
163
162
 
164
- export const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryProjection]> = {
163
+ export const historyList: Operation<typeof historyListParameters, HistoryPage, [HistoryProjection, HistoryTextWrapper?]> = {
165
164
  name: "history_list",
166
165
  label: "History list items",
167
166
  description: "Browse or search this session's events, a page at a time. Read one in full with `history_read`.",
168
167
  parameters: historyListParameters,
169
168
  outputSchema: resultSchema(HistoryPageSchema),
170
- async execute(params, projection) {
169
+ async execute(params, projection, wrapText = plainText) {
171
170
  const resolved = resolveWindowId(projection, params.window_id);
172
171
  if (!resolved.ok) return resolved.outcome;
173
172
  const scoped = { ...params, window_id: resolved.window_id };
174
173
  const badWindow = badWindowId(projection, scoped);
175
174
  if (badWindow) return badWindow;
176
- return selectPage(projection, scoped, pageFits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
175
+ // Charge wrapped rendering and cursors, not only event previews.
176
+ const fits = (page: HistoryPage) => fitsResult(success(page), (result) => wrapText(renderOutcome(result, renderPage)));
177
+ return selectPage(projection, scoped, fits, scoped.max_chars_per_item ?? HISTORY_PREVIEW_CHARS);
177
178
  },
178
179
  render: (result) => renderOutcome(result, renderPage),
179
180
  };
@@ -182,13 +183,13 @@ export const historyList: Operation<typeof historyListParameters, HistoryPage, [
182
183
 
183
184
  export const historyReadParameters = Type.Object({ seq: Type.Integer({ minimum: 1, description: "Event seq, from `history_list`." }), ...TextWindowRequestSchema }, { additionalProperties: false });
184
185
 
185
- export const historyRead: Operation<typeof historyReadParameters, HistoryReadData, [HistoryProjection]> = {
186
+ export const historyRead: Operation<typeof historyReadParameters, HistoryReadData, [HistoryProjection, HistoryTextWrapper?]> = {
186
187
  name: "history_read",
187
188
  label: "History read item",
188
189
  description: "Read one event in full: tool arguments, output, and nested calls.",
189
190
  parameters: historyReadParameters,
190
191
  outputSchema: resultSchema(HistoryReadDataSchema),
191
- async execute(params, projection) {
192
+ async execute(params, projection, wrapText = plainText) {
192
193
  const item = allItems(projection).find((event) => event.seq === params.seq);
193
194
  // Address checks run in one order: past the end of the file, off this branch, then
194
195
  // consumed by a pairing. Only the last two can mention what is at the address.
@@ -223,7 +224,7 @@ export const historyRead: Operation<typeof historyReadParameters, HistoryReadDat
223
224
  ...nestedCallSummary(item),
224
225
  ...window,
225
226
  }),
226
- (result) => renderOutcome(result, renderRead),
227
+ (result) => wrapText(renderOutcome(result, renderRead)),
227
228
  );
228
229
  },
229
230
  render: (result) => renderOutcome(result, renderRead),