notesoup 0.60.1 → 0.62.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 (200) hide show
  1. package/.agents/plugins/marketplace.json +15 -0
  2. package/README.md +14 -10
  3. package/dist/plugins/antigravity/src/cli.d.ts +1 -0
  4. package/dist/plugins/antigravity/src/cli.js +23 -0
  5. package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
  6. package/dist/plugins/antigravity/src/hooks.js +53 -0
  7. package/dist/plugins/antigravity/src/identity.d.ts +26 -0
  8. package/dist/plugins/antigravity/src/identity.js +129 -0
  9. package/dist/plugins/claude/src/helper.js +2 -1
  10. package/dist/plugins/codex/src/hooks.js +1 -0
  11. package/dist/plugins/codex/src/identity.d.ts +6 -1
  12. package/dist/plugins/codex/src/identity.js +13 -1
  13. package/dist/plugins/codex/src/mcp.d.ts +35 -7
  14. package/dist/plugins/codex/src/mcp.js +26 -88
  15. package/dist/plugins/codex/src/text.js +3 -3
  16. package/dist/plugins/dsh/tools.js +8 -4
  17. package/dist/plugins/mcp/operations.d.ts +15 -0
  18. package/dist/plugins/mcp/operations.js +43 -0
  19. package/dist/plugins/mcp/server.d.ts +14 -0
  20. package/dist/plugins/mcp/server.js +13 -0
  21. package/dist/plugins/pi/budget.d.ts +1 -1
  22. package/dist/plugins/pi/budget.js +3 -2
  23. package/dist/plugins/pi/entries.d.ts +1 -0
  24. package/dist/plugins/pi/entries.js +1 -0
  25. package/dist/plugins/pi/history-tools.js +2 -1
  26. package/dist/plugins/pi/history.js +18 -1
  27. package/dist/plugins/pi/notes/tools.js +7 -3
  28. package/dist/plugins/pi/render.d.ts +7 -1
  29. package/dist/plugins/pi/render.js +2 -2
  30. package/dist/plugins/pi/reset/lifecycle.d.ts +1 -1
  31. package/dist/plugins/pi/reset/lifecycle.js +8 -9
  32. package/dist/plugins/pi/runtime.js +102 -61
  33. package/dist/plugins/pi/tool-result.js +7 -7
  34. package/dist/plugins/pi/window.d.ts +33 -3
  35. package/dist/plugins/pi/window.js +209 -9
  36. package/dist/src/boot/render.d.ts +5 -0
  37. package/dist/src/boot/render.js +60 -28
  38. package/dist/src/boot/text.d.ts +3 -3
  39. package/dist/src/boot/text.js +27 -26
  40. package/dist/src/budget/text.d.ts +2 -2
  41. package/dist/src/budget/text.js +13 -13
  42. package/dist/src/history/claude.d.ts +2 -0
  43. package/dist/src/history/claude.js +46 -0
  44. package/dist/src/history/codex-transcript.js +7 -5
  45. package/dist/src/history/codex.js +3 -0
  46. package/dist/src/history/corpus.d.ts +28 -1
  47. package/dist/src/history/corpus.js +40 -0
  48. package/dist/src/history/history.d.ts +37 -46
  49. package/dist/src/history/history.js +21 -40
  50. package/dist/src/history/local.js +67 -32
  51. package/dist/src/history/pi.d.ts +2 -1
  52. package/dist/src/history/pi.js +122 -48
  53. package/dist/src/history/prefilter.js +76 -19
  54. package/dist/src/history/query.d.ts +28 -49
  55. package/dist/src/history/query.js +83 -68
  56. package/dist/src/history/summary-cache.d.ts +8 -1
  57. package/dist/src/history/summary-cache.js +138 -12
  58. package/dist/src/index.d.ts +1 -1
  59. package/dist/src/index.js +1 -1
  60. package/dist/src/notes/frontmatter.d.ts +4 -0
  61. package/dist/src/notes/frontmatter.js +15 -1
  62. package/dist/src/notes/index.d.ts +1 -1
  63. package/dist/src/notes/index.js +1 -1
  64. package/dist/src/notes/policy.d.ts +15 -1
  65. package/dist/src/notes/policy.js +47 -6
  66. package/dist/src/notes/store.d.ts +14 -0
  67. package/dist/src/notes/store.js +33 -12
  68. package/dist/src/text-match.d.ts +10 -1
  69. package/dist/src/text-match.js +42 -3
  70. package/dist/src/tools/dream.d.ts +22 -91
  71. package/dist/src/tools/dream.js +30 -27
  72. package/dist/src/tools/history.d.ts +33 -26
  73. package/dist/src/tools/history.js +257 -163
  74. package/dist/src/tools/notes.d.ts +58 -160
  75. package/dist/src/tools/notes.js +151 -99
  76. package/dist/src/tools/output.d.ts +2 -1
  77. package/dist/src/tools/output.js +2 -1
  78. package/dist/src/tools/result.d.ts +4 -7
  79. package/dist/src/tools/result.js +8 -9
  80. package/dist/src/tools/schema.d.ts +4 -1
  81. package/dist/src/tools/schema.js +25 -1
  82. package/dist/test/agent-loop.test.js +198 -16
  83. package/dist/test/antigravity-live.test.d.ts +1 -0
  84. package/dist/test/antigravity-live.test.js +142 -0
  85. package/dist/test/antigravity-plugin.test.d.ts +1 -0
  86. package/dist/test/antigravity-plugin.test.js +101 -0
  87. package/dist/test/boot.integration.test.js +133 -14
  88. package/dist/test/claude-history.test.js +14 -13
  89. package/dist/test/claude-mod.test.js +9 -6
  90. package/dist/test/codex-history.test.js +15 -3
  91. package/dist/test/codex-plugin.test.js +76 -38
  92. package/dist/test/dependencies.test.js +7 -3
  93. package/dist/test/dream-skill.test.js +3 -3
  94. package/dist/test/dream-tools.test.js +101 -56
  95. package/dist/test/dsh.test.js +34 -19
  96. package/dist/test/helpers/dependency-graph.js +2 -2
  97. package/dist/test/helpers/extension.d.ts +65 -2
  98. package/dist/test/helpers/extension.js +72 -3
  99. package/dist/test/history-corpus.test.js +79 -77
  100. package/dist/test/history-summary-cache.test.js +97 -9
  101. package/dist/test/history.integration.test.js +234 -168
  102. package/dist/test/host-neutral.test.js +69 -19
  103. package/dist/test/marker.test.js +1 -1
  104. package/dist/test/note-policy.test.js +189 -56
  105. package/dist/test/notes.integration.test.js +212 -94
  106. package/dist/test/notes.test.js +184 -113
  107. package/dist/test/pi-render.test.js +20 -12
  108. package/dist/test/project-namespace.test.js +3 -2
  109. package/dist/test/reset-lifecycle.test.js +2 -2
  110. package/docs/antigravity.md +44 -0
  111. package/docs/architecture.md +6 -4
  112. package/docs/claude-code-mod.md +2 -2
  113. package/docs/codex.md +36 -38
  114. package/docs/dsh.md +4 -4
  115. package/docs/history-sessions.md +28 -50
  116. package/docs/notes-library.md +6 -6
  117. package/docs/reset-lifecycle.md +1 -1
  118. package/docs/skills.md +3 -3
  119. package/docs/tool-results.md +47 -28
  120. package/package.json +3 -2
  121. package/playbook.md +3 -3
  122. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  123. package/plugins/antigravity/hooks.json +7 -0
  124. package/plugins/antigravity/mcp_config.json +8 -0
  125. package/plugins/antigravity/plugin.json +6 -0
  126. package/plugins/antigravity/src/cli.ts +22 -0
  127. package/plugins/antigravity/src/hooks.ts +51 -0
  128. package/plugins/antigravity/src/identity.ts +127 -0
  129. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  130. package/plugins/claude/dist/claude/helper.js +1129 -549
  131. package/plugins/claude/hooks/register.ts +2 -2
  132. package/plugins/claude/playbook.md +3 -3
  133. package/plugins/claude/skills/dream/SKILL.md +2 -2
  134. package/plugins/claude/skills/notesoup/SKILL.md +92 -0
  135. package/plugins/claude/src/helper.ts +2 -1
  136. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  137. package/plugins/codex/.mcp.json +11 -0
  138. package/plugins/codex/README.md +5 -21
  139. package/plugins/codex/dist/codex/notesoup.js +18494 -17905
  140. package/plugins/codex/src/hooks.ts +1 -0
  141. package/plugins/codex/src/identity.ts +14 -1
  142. package/plugins/codex/src/mcp.ts +28 -98
  143. package/plugins/codex/src/text.ts +3 -3
  144. package/plugins/dsh/tools.ts +8 -4
  145. package/plugins/mcp/operations.ts +50 -0
  146. package/plugins/mcp/server.ts +23 -0
  147. package/plugins/paseo/README.md +5 -10
  148. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  149. package/plugins/paseo/client/markdown.tsx +50 -38
  150. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  151. package/plugins/paseo/client/paper-card.tsx +6 -5
  152. package/plugins/paseo/client/paper-palette.ts +2 -9
  153. package/plugins/paseo/client/sticky-card.tsx +2 -2
  154. package/plugins/paseo/client/tool-result.ts +7 -14
  155. package/plugins/paseo/package-lock.json +3406 -0
  156. package/plugins/paseo/package.json +1 -0
  157. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  158. package/plugins/pi/budget.ts +3 -3
  159. package/plugins/pi/entries.ts +1 -0
  160. package/plugins/pi/history-tools.ts +2 -1
  161. package/plugins/pi/history.ts +30 -1
  162. package/plugins/pi/notes/tools.ts +7 -3
  163. package/plugins/pi/render.ts +6 -6
  164. package/plugins/pi/reset/lifecycle.ts +9 -10
  165. package/plugins/pi/runtime.ts +96 -60
  166. package/plugins/pi/tool-result.ts +8 -8
  167. package/plugins/pi/window.ts +198 -9
  168. package/skills/dream/SKILL.md +2 -2
  169. package/skills/notesoup/SKILL.md +92 -0
  170. package/src/boot/render.ts +59 -25
  171. package/src/boot/text.ts +30 -27
  172. package/src/budget/text.ts +13 -13
  173. package/src/history/claude.ts +41 -0
  174. package/src/history/codex-transcript.ts +6 -4
  175. package/src/history/codex.ts +2 -0
  176. package/src/history/corpus.ts +51 -2
  177. package/src/history/history.ts +35 -44
  178. package/src/history/local.ts +67 -27
  179. package/src/history/pi.ts +113 -35
  180. package/src/history/prefilter.ts +73 -15
  181. package/src/history/query.ts +93 -73
  182. package/src/history/summary-cache.ts +142 -17
  183. package/src/index.ts +1 -1
  184. package/src/notes/frontmatter.ts +16 -1
  185. package/src/notes/index.ts +1 -1
  186. package/src/notes/policy.ts +45 -6
  187. package/src/notes/store.ts +30 -15
  188. package/src/text-match.ts +46 -4
  189. package/src/tools/dream.ts +29 -31
  190. package/src/tools/history.ts +249 -142
  191. package/src/tools/notes.ts +150 -112
  192. package/src/tools/output.ts +2 -1
  193. package/src/tools/result.ts +12 -11
  194. package/src/tools/schema.ts +24 -1
  195. package/plugins/claude/skills/memory/SKILL.md +0 -69
  196. package/plugins/codex/mcp.json +0 -10
  197. package/plugins/codex/plugin.json +0 -6
  198. package/plugins/paseo/client/markdown-core.tsx +0 -189
  199. package/plugins/paseo/client/typography.ts +0 -24
  200. package/skills/memory/SKILL.md +0 -69
@@ -8,6 +8,7 @@
8
8
  "test": "node --experimental-strip-types --test test/*.test.ts"
9
9
  },
10
10
  "dependencies": {
11
+ "@astrosheep/paseo-ui": "^0.2.0",
11
12
  "marked": "^17.0.6"
12
13
  },
13
14
  "devDependencies": {
@@ -1,75 +1,82 @@
1
1
  import assert from "node:assert/strict";
2
+ import { registerHooks } from "node:module";
2
3
  import test from "node:test";
3
- import { readFileSync } from "node:fs";
4
- import { createRequire } from "node:module";
5
- import ts from "typescript";
4
+ import { typography } from "@astrosheep/paseo-ui/theme";
5
+ import { paperPalette } from "../client/paper-palette.ts";
6
6
 
7
- // Exercise the actual renderer with RN host primitives, not a native layout emulator.
8
- const require = createRequire(import.meta.url);
9
- const opened: string[] = [];
10
- const source = readFileSync(new URL("../client/markdown-core.tsx", import.meta.url), "utf8");
11
- const { outputText } = ts.transpileModule(source, {
12
- compilerOptions: { jsx: ts.JsxEmit.ReactJSX, module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
7
+ registerHooks({
8
+ resolve(specifier, context, nextResolve) {
9
+ if (specifier === "react-native") {
10
+ return { shortCircuit: true, url: "notesoup-test:react-native" };
11
+ }
12
+ return nextResolve(specifier, context);
13
+ },
14
+ load(url, context, nextLoad) {
15
+ if (url === "notesoup-test:react-native") {
16
+ return {
17
+ shortCircuit: true,
18
+ format: "module",
19
+ source: `
20
+ export const Linking = { openURL: () => Promise.resolve() };
21
+ export const Text = "Text";
22
+ export const View = "View";
23
+ export const ScrollView = "ScrollView";
24
+ export const StyleSheet = { hairlineWidth: 0.5 };
25
+ `,
26
+ };
27
+ }
28
+ return nextLoad(url, context);
29
+ },
13
30
  });
14
- const compiled = { exports: {} as any };
15
- new Function("require", "module", "exports", outputText)(
16
- (id: string) => id === "react-native"
17
- ? { Text: "Text", View: "View", ScrollView: "ScrollView", Linking: { openURL: (url: string) => { opened.push(url); return Promise.resolve(); } } }
18
- : require(id),
19
- compiled, compiled.exports,
20
- );
21
- const { renderBlocks, renderInlines } = compiled.exports;
22
- const { lexer, Lexer } = require("marked");
23
- const styles = new Proxy({}, { get: () => ({}) });
24
- function elements(node: any): any[] {
25
- if (Array.isArray(node)) return node.flatMap(elements);
26
- if (!node || typeof node !== "object") return [];
27
- return [node, ...elements(node.props?.children)];
28
- }
29
- function text(node: any): string {
30
- if (Array.isArray(node)) return node.map(text).join("");
31
- if (node == null) return "";
32
- return typeof node === "object" ? text(node.props?.children) : String(node);
33
- }
34
- const render = (markdown: string, openLinks?: boolean) => renderBlocks(lexer(markdown), styles, "test", undefined, openLinks);
35
31
 
36
- test("inline nesting, entities, br and empty-alt images render cleanly", () => {
37
- const result = renderInlines(Lexer.lexInline("**bold *nested*** &mdash; &#65; `a < b & c`<br>![](https://example.com/a.png)"), styles, "inline");
38
- assert.equal(text(result), "bold nested — A a < b & c\n[image]");
39
- });
32
+ const { createMarkdownStyles, renderBlocks, renderInlines } = await import("@astrosheep/paseo-ui/markdown");
33
+ const { Lexer, lexer } = await import("marked");
40
34
 
41
- test("ordered starts, tight and loose task markers survive without duplicate checkboxes", () => {
42
- assert.match(text(render("3. third\n4. fourth")), /3\.third4\.fourth/);
43
- const tight = text(render("- [x] done\n- [ ] pending\n - child"));
44
- assert.match(tight, /☑done/);
45
- assert.match(tight, /☐pending/);
46
- assert.match(tight, /•child/);
47
- const loose = text(render("- [x] first\n\n- [ ] second"));
48
- assert.equal(loose, "☑first☐second");
49
- });
35
+ const lightTheme = {
36
+ colors: {
37
+ surface0: "#ffffff",
38
+ surface1: "#fafafa",
39
+ surface2: "#f4f4f5",
40
+ border: "#e4e4e7",
41
+ foreground: "#1a1a1e",
42
+ foregroundMuted: "#71717a",
43
+ accent: "#20744A",
44
+ accentForeground: "#ffffff",
45
+ statusSuccess: "#3e704a",
46
+ statusWarning: "#7b5d39",
47
+ statusDanger: "#9d433b",
48
+ },
49
+ };
50
50
 
51
- test("safe links open only when enabled and block unsafe schemes", () => {
52
- opened.length = 0;
53
- const disabled = elements(render("[ok](https://example.com?a=1&amp;b=2)", false)).find(n => typeof n.props?.onPress === "function");
54
- assert.equal(disabled, undefined);
55
- const inlineDefault = elements(renderInlines(Lexer.lexInline("[peek](https://example.com)"), styles, "peek")).find(n => typeof n.props?.onPress === "function");
56
- assert.equal(inlineDefault, undefined);
57
-
58
- const active = elements(render("[ok](https://example.com?a=1&amp;b=2) [bad](javascript:alert(1)) [mail](mailto:hi@example.com)"));
59
- const handlers = active.filter(n => typeof n.props?.onPress === "function");
60
- assert.equal(handlers.length, 2);
61
- handlers.forEach(n => n.props.onPress());
62
- assert.deepEqual(opened, ["https://example.com?a=1&b=2", "mailto:hi@example.com"]);
63
- });
51
+ function textOf(node: unknown): string {
52
+ if (Array.isArray(node)) return node.map(textOf).join("");
53
+ if (node == null) return "";
54
+ if (typeof node === "object") return textOf((node as { props?: { children?: unknown } }).props?.children);
55
+ return String(node);
56
+ }
64
57
 
65
- test("tables size by visible CJK/link text and stay horizontally scrollable", () => {
66
- const md = "# Heading\n\n| [详情](https://very-long.example.com/path/to/doc) | 状态说明 |\n| :--- | ---: |\n| x<br>y | 值 |\n\n```\n&amp;\n```";
67
- const nodes = elements(render(md));
68
- assert.equal(nodes.filter(n => n.type === "ScrollView" && n.props.horizontal).length, 2);
69
- assert.ok(nodes.filter(n => n.type === "Text" && n.props.selectable !== undefined).every(n => n.props.selectable));
70
- const headerCells = nodes.filter(n => Array.isArray(n.props.style) && n.props.style.some((s: any) => typeof s?.width === "number")).slice(0, 2);
71
- const [linkColWidth, cjkColWidth] = headerCells.map(n => n.props.style.find((s: any) => typeof s?.width === "number").width);
72
- assert.ok(linkColWidth < 80, `expected visible link text width, got ${linkColWidth}`);
73
- assert.ok(cjkColWidth > 64, `expected CJK header width above ASCII floor, got ${cjkColWidth}`);
74
- assert.ok(nodes.some(n => n.type === "Text" && text(n) === "&amp;"));
58
+ test("notesoup paper palette maps cleanly into @astrosheep/paseo-ui/markdown", () => {
59
+ const paper = paperPalette(lightTheme);
60
+ const type = typography(lightTheme, "ios");
61
+ const styles = createMarkdownStyles(
62
+ {
63
+ text: paper.ink,
64
+ muted: paper.inkMuted,
65
+ heading: paper.ink,
66
+ strong: paper.ink,
67
+ em: paper.ink,
68
+ link: paper.added,
69
+ code: paper.ink,
70
+ inlineCodeBg: `${paper.ink}10`,
71
+ codeBg: paper.crumpled,
72
+ border: paper.edge,
73
+ quoteBg: "transparent",
74
+ quoteBorder: paper.edge,
75
+ tableHeadBg: paper.crumpled,
76
+ },
77
+ type,
78
+ );
79
+ assert.equal("borderRadius" in styles.inlineCode, false);
80
+ assert.equal(textOf(renderBlocks(lexer("**bold** &mdash; `code`"), styles, "ns")), "bold — code");
81
+ assert.equal(textOf(renderInlines(Lexer.lexInline("*italic* &amp; `x`"), styles, "in")), "italic & x");
75
82
  });
@@ -24,7 +24,7 @@ function remainingTokens(ctx: Pick<ExtensionContext, "sessionManager" | "getCont
24
24
 
25
25
  export function registerBudget(
26
26
  pi: ExtensionAPI,
27
- isEnabled: () => boolean,
27
+ isEnabled: (ctx: ExtensionContext) => boolean,
28
28
  settingsManager?: SettingsManager,
29
29
  ) {
30
30
  let cap: number | undefined;
@@ -89,13 +89,13 @@ export function registerBudget(
89
89
  }));
90
90
  };
91
91
 
92
- pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition(); thresholdsFor(ctx); });
92
+ pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition(); if (isEnabled(ctx)) thresholdsFor(ctx); });
93
93
  pi.on("session_tree", resetForTransition);
94
94
  pi.on("model_select", resetForTransition);
95
95
  pi.on("session_shutdown", () => { cap = undefined; resetForTransition(); });
96
96
  pi.on("agent_settled", clearStaged);
97
97
  pi.on("context", (event, ctx) => {
98
- if (!isEnabled()) return undefined;
98
+ if (!isEnabled(ctx)) return undefined;
99
99
  // Durable reminders return to the slot where the model first read them.
100
100
  const messages = arrangeAnchoredReminders(event.messages, ctx);
101
101
  const result = (extra?: { customType: string; content: string }) => {
@@ -7,3 +7,4 @@ export const CONTINUATION_TYPE = "notesoup/continuation";
7
7
  export const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
8
8
  export const CARRIED_INPUT_TYPE = "notesoup/carried-input";
9
9
  export const MARKER_TYPE = "notesoup/marker";
10
+ export const ENABLED_TYPE = "notesoup/enabled";
@@ -1,5 +1,5 @@
1
1
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
- import { historyList, historyRead } from "../../src/tools/history.js";
2
+ import { historyList, historySearch, historyRead } from "../../src/tools/history.js";
3
3
  import { historyFromSession } from "./history.js";
4
4
  import { localHistoryCorpus } from "../../src/history/local.js";
5
5
  import type { SessionReader } from "./session-reader.js";
@@ -13,5 +13,6 @@ function historyContext(ctx: SessionReader) {
13
13
  /** Register the two deferred history operations; the adapter allocates addresses and supplies them. */
14
14
  export function registerHistoryTools(pi: ExtensionAPI) {
15
15
  registerOperation(pi, historyList, (params, ctx) => historyList.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
16
+ registerOperation(pi, historySearch, (params, ctx) => historySearch.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
16
17
  registerOperation(pi, historyRead, (params, ctx) => historyRead.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
17
18
  }
@@ -8,7 +8,36 @@ export function nextHistorySeq(ctx: SessionReader, pending: readonly SessionBoun
8
8
  return 1 + [...ctx.sessionManager.getEntries(), ...pending].reduce((sum, entry) => sum + piSequenceCount(entry), 0);
9
9
  }
10
10
 
11
+ type CachedProjection = {
12
+ sessionId: string;
13
+ entryCount: number;
14
+ lastEntry: unknown;
15
+ branchCount: number;
16
+ lastBranch: unknown;
17
+ projection: HistoryProjection;
18
+ };
19
+
20
+ const projectionCache = new WeakMap<object, CachedProjection>();
21
+
11
22
  export function historyFromSession(ctx: SessionReader): HistoryProjection {
12
23
  const manager = ctx.sessionManager;
13
- return piHistoryFromEntries(manager.getSessionId(), manager.getEntries(), manager.getBranch());
24
+ const sessionId = manager.getSessionId();
25
+ const entries = manager.getEntries();
26
+ const branch = manager.getBranch();
27
+ const lastEntry = entries.at(-1);
28
+ const lastBranch = branch.at(-1);
29
+ const cached = projectionCache.get(manager);
30
+ if (
31
+ cached
32
+ && cached.sessionId === sessionId
33
+ && cached.entryCount === entries.length
34
+ && cached.lastEntry === lastEntry
35
+ && cached.branchCount === branch.length
36
+ && cached.lastBranch === lastBranch
37
+ ) {
38
+ return cached.projection;
39
+ }
40
+ const projection = piHistoryFromEntries(sessionId, entries, branch);
41
+ projectionCache.set(manager, { sessionId, entryCount: entries.length, lastEntry, branchCount: branch.length, lastBranch, projection });
42
+ return projection;
14
43
  }
@@ -5,6 +5,7 @@ import { notesIdentityFromPi } from "./adapter.js";
5
5
  import { notesReadRenderers, notesUpdateRenderers, notesWriteRenderers } from "../render.js";
6
6
  import { DREAM_NAMESPACE, NOTES_NAMESPACE, registerOperation } from "../tool-result.js";
7
7
  import type { NoteChange } from "../../../src/notes/index.js";
8
+ import { wireResult } from "../../../src/tools/result.js";
8
9
  import { notesToolContext } from "../../../src/tools/notes-context.js";
9
10
 
10
11
  function renderDiff(change: NoteChange): string {
@@ -27,15 +28,18 @@ export function registerNotesTools(pi: ExtensionAPI) {
27
28
  };
28
29
  const identity = (ctx: ExtensionContext) => dreamingIdentity(notesIdentityFromPi(ctx), dreamOf(ctx));
29
30
  const toolContext = (ctx: ExtensionContext) => notesToolContext(identity(ctx), ctx.cwd);
30
- registerOperation(pi, notesWrite, (params, ctx) => notesWrite.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesWriteRenderers);
31
+ registerOperation(pi, notesWrite, async (params, ctx) => {
32
+ const outcome = await notesWrite.execute(params, toolContext(ctx));
33
+ return { ...outcome, details: { receipt: wireResult(outcome) } };
34
+ }, NOTES_NAMESPACE, notesWriteRenderers);
31
35
  registerOperation(pi, notesUpdate, async (params, ctx) => {
32
36
  let diff = "";
33
37
  const outcome = await notesUpdate.execute(params, toolContext(ctx), (change) => { diff = renderDiff(change); });
34
- return diff ? { ...outcome, details: { diff } } : outcome;
38
+ return { ...outcome, details: { receipt: wireResult(outcome), ...(diff ? { diff } : {}) } };
35
39
  }, NOTES_NAMESPACE, notesUpdateRenderers);
36
40
  registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesReadRenderers);
37
41
  registerOperation(pi, notesList, (params, ctx) => notesList.execute(params, toolContext(ctx)), NOTES_NAMESPACE);
38
- registerOperation(pi, dreamBegin, (params, ctx) => dreamBegin.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
42
+ registerOperation(pi, dreamBegin, (params, ctx) => dreamBegin.execute(params, notesToolContext(notesIdentityFromPi(ctx), ctx.cwd), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
39
43
  registerOperation(pi, dreamForget, (params, ctx) => dreamForget.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
40
44
  registerOperation(pi, dreamEnd, (params, ctx) => dreamEnd.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
41
45
  }
@@ -2,6 +2,7 @@
2
2
  import { renderDiff, type AgentToolResult, type Theme } from "@earendil-works/pi-coding-agent";
3
3
  import { Container, Text, TruncatedText, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
4
4
  import type { Static } from "typebox";
5
+ import type { WireError, WireResult } from "../../src/tools/result.js";
5
6
  import type { NotePolicy } from "../../src/notes/index.js";
6
7
  import type { NotesReadData, NotesUpdateData, NotesWriteData } from "../../src/tools/notes.js";
7
8
  import { notesReadParameters, notesUpdateParameters, notesWriteParameters } from "../../src/tools/notes.js";
@@ -12,11 +13,9 @@ type CallContext<TArgs> = { args: TArgs };
12
13
  /** Expanded bodies show this many lines before a "more lines" marker; the full text is in the receipt. */
13
14
  const EXPANDED_LINE_CAP = 80;
14
15
 
15
- type WireError = { error: string; code: string };
16
-
17
- /** structuredContent is wireResult(outcome): the data itself, or {error, code}. Old sessions may lack it. */
16
+ /** Receipts are wireResult(outcome), stored in mutation details or notes_read structuredContent. */
18
17
  function wireOf<T>(result: AgentToolResult<unknown>): { data?: T; error?: WireError } {
19
- const sc = result.structuredContent;
18
+ const sc = result.structuredContent ?? (result.details as { receipt?: unknown } | undefined)?.receipt;
20
19
  if (sc !== null && typeof sc === "object" && !Array.isArray(sc)) {
21
20
  const obj = sc as Record<string, unknown>;
22
21
  if (typeof obj.error === "string") return { error: { error: obj.error, code: typeof obj.code === "string" ? obj.code : "error" } };
@@ -76,10 +75,11 @@ function noteResult(head: string, policy: Partial<NotePolicy> | undefined, warni
76
75
  return result;
77
76
  }
78
77
 
78
+ export type NotesWriteDetails = { receipt: WireResult<NotesWriteData> };
79
79
  export type NotesWriteArgs = Static<typeof notesWriteParameters>;
80
80
  export const notesWriteRenderers = {
81
81
  renderCall: (args: NotesWriteArgs, theme: Theme): Component => callLine(theme, "notes_write", args.address),
82
- renderResult(result: AgentToolResult<undefined>, options: { expanded: boolean }, theme: Theme, context: CallContext<NotesWriteArgs>): Component {
82
+ renderResult(result: AgentToolResult<NotesWriteDetails | undefined>, options: { expanded: boolean }, theme: Theme, context: CallContext<NotesWriteArgs>): Component {
83
83
  const { data, error } = wireOf<NotesWriteData>(result);
84
84
  if (error) return errorComponent(theme, error, options.expanded);
85
85
  if (!data) return receiptFallback(result, theme);
@@ -91,7 +91,7 @@ export const notesWriteRenderers = {
91
91
  };
92
92
 
93
93
  export type NotesUpdateArgs = Static<typeof notesUpdateParameters>;
94
- export type NotesUpdateDetails = { diff?: string };
94
+ export type NotesUpdateDetails = { receipt: WireResult<NotesUpdateData>; diff?: string };
95
95
  export const notesUpdateRenderers = {
96
96
  renderCall(args: NotesUpdateArgs, theme: Theme): Component {
97
97
  let suffix = "";
@@ -17,7 +17,7 @@ type BudgetOwner = {
17
17
  };
18
18
 
19
19
  type ResetOptions = {
20
- isEnabled: () => boolean;
20
+ isEnabled: (ctx: ExtensionContext) => boolean;
21
21
  budget: BudgetOwner;
22
22
  buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, lastWord: string | undefined, firstSeq: number, origin: ResetOrigin) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
23
23
  getLifecycleGeneration?: () => number;
@@ -247,7 +247,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
247
247
  const sessionId = ctx.sessionManager.getSessionId();
248
248
  const windowId = currentWindowId(ctx);
249
249
  const isCurrent = () => sessionActive && lifecycleGeneration === generation &&
250
- (outerGeneration === undefined || options.getLifecycleGeneration?.() === outerGeneration) && options.isEnabled() &&
250
+ (outerGeneration === undefined || options.getLifecycleGeneration?.() === outerGeneration) && options.isEnabled(ctx) &&
251
251
  (preSendHardReserve || ctx.signal?.aborted !== true) && ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
252
252
  // The retain-none checkpoint belongs to the old window; capture its successor before notes await.
253
253
  const firstSeq = nextHistorySeq(ctx, entries) + 1;
@@ -274,7 +274,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
274
274
  };
275
275
 
276
276
  pi.on("input", (event, ctx) => {
277
- if (event.source === "extension" || !sessionActive || !options.isEnabled()) return undefined;
277
+ if (event.source === "extension" || !sessionActive || !options.isEnabled(ctx)) return undefined;
278
278
  const request = control.request;
279
279
  if (request.phase !== "pending" || !request.command || request.windowId !== currentWindowId(ctx)) return undefined;
280
280
  const content: CarriedInput = event.images?.length
@@ -301,7 +301,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
301
301
  const system = getCurrentSystemMessage(event.messages);
302
302
  return { messages: system ? [system] : [] };
303
303
  }
304
- if (!options.isEnabled() || ctx.signal?.aborted) return undefined;
304
+ if (!options.isEnabled(ctx) || ctx.signal?.aborted) return undefined;
305
305
  if (control.request.phase === "pending" && control.request.command !== undefined) return undefined;
306
306
  if (!options.budget.hardReserveDue(ctx, event.messages)) return undefined;
307
307
  preSendHardReserveWindowId = currentWindowId(ctx);
@@ -317,7 +317,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
317
317
  preSendHardReserveWindowId = undefined;
318
318
  const aborted = preSendHardReserve ? false : isAbort(event.message, event.outcome, ctx);
319
319
  const stagedBudgetEntries = options.budget.consumeTurnEnd(ctx, event.messageEntryId);
320
- const budgetEntries = options.isEnabled() && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
320
+ const budgetEntries = options.isEnabled(ctx) && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
321
321
  const entries = [...(event.entries ?? []), ...budgetEntries];
322
322
  const decision = reduceResetControl(control, {
323
323
  type: "turn_end",
@@ -326,7 +326,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
326
326
  aborted,
327
327
  overflow: aborted ? false : isOverflowLike(event.message, ctx),
328
328
  failed: event.outcome === "error",
329
- enabled: options.isEnabled(),
329
+ enabled: options.isEnabled(ctx),
330
330
  get queued() { return event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
331
331
  get automaticResetEnabled() { return options.budget.automaticResetEnabled(ctx); },
332
332
  get hardReserveDue() { return preSendHardReserve || options.budget.hardReserveDue(ctx); },
@@ -336,7 +336,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
336
336
  if (aborted) restoreCommandInputs();
337
337
  else if (event.outcome === "error" && decision.state.request.phase === "none") restoreCommandInputs(true);
338
338
  control = decision.state;
339
- if (!aborted && event.outcome !== "error" && options.isEnabled()) {
339
+ if (!aborted && event.outcome !== "error" && options.isEnabled(ctx)) {
340
340
  const marker = buildMarkerDraft(ctx, entries);
341
341
  if (marker) entries.push(marker);
342
342
  }
@@ -350,7 +350,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
350
350
  facts: {
351
351
  windowId: currentWindowId(ctx),
352
352
  get queued() { return event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
353
- get enabled() { return options.isEnabled(); },
353
+ get enabled() { return options.isEnabled(ctx); },
354
354
  get automaticResetEnabled() { return options.budget.automaticResetEnabled(ctx); },
355
355
  aborted: event.outcome === "aborted" || ctx.signal?.aborted === true,
356
356
  failed: event.outcome === "error",
@@ -366,8 +366,7 @@ export function registerResetLifecycle(pi: ExtensionAPI, options: ResetOptions)
366
366
  pi.on("session_before_compact", (event, ctx) => {
367
367
  if (!sessionActive) return undefined;
368
368
  if (event.signal.aborted) return { cancel: true };
369
- const markerExists = currentReset(ctx) !== undefined;
370
- if (options.isEnabled() || markerExists) {
369
+ if (options.isEnabled(ctx)) {
371
370
  if (event.reason === "manual") {
372
371
  ctx.ui.notify("🥣 No compacting brains here · use /fresh-window", "warning");
373
372
  }