notesoup 0.61.0 → 0.63.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 (210) hide show
  1. package/.agents/plugins/marketplace.json +15 -0
  2. package/README.md +14 -11
  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 +24 -5
  10. package/dist/plugins/claude/src/text.d.ts +7 -0
  11. package/dist/plugins/claude/src/text.js +12 -1
  12. package/dist/plugins/codex/src/hooks.js +1 -0
  13. package/dist/plugins/codex/src/identity.d.ts +6 -1
  14. package/dist/plugins/codex/src/identity.js +13 -1
  15. package/dist/plugins/codex/src/mcp.d.ts +35 -7
  16. package/dist/plugins/codex/src/mcp.js +26 -88
  17. package/dist/plugins/codex/src/text.js +3 -3
  18. package/dist/plugins/dsh/tools.js +8 -4
  19. package/dist/plugins/mcp/operations.d.ts +15 -0
  20. package/dist/plugins/mcp/operations.js +43 -0
  21. package/dist/plugins/mcp/server.d.ts +14 -0
  22. package/dist/plugins/mcp/server.js +13 -0
  23. package/dist/plugins/pi/budget.d.ts +4 -1
  24. package/dist/plugins/pi/budget.js +35 -8
  25. package/dist/plugins/pi/entries.d.ts +2 -0
  26. package/dist/plugins/pi/entries.js +2 -0
  27. package/dist/plugins/pi/history-tools.js +2 -1
  28. package/dist/plugins/pi/history.js +18 -1
  29. package/dist/plugins/pi/notes/tools.js +7 -3
  30. package/dist/plugins/pi/render.d.ts +7 -1
  31. package/dist/plugins/pi/render.js +2 -2
  32. package/dist/plugins/pi/reset/artifacts.d.ts +1 -1
  33. package/dist/plugins/pi/reset/artifacts.js +4 -4
  34. package/dist/plugins/pi/reset/lifecycle.d.ts +9 -2
  35. package/dist/plugins/pi/reset/lifecycle.js +109 -31
  36. package/dist/plugins/pi/runtime.js +104 -63
  37. package/dist/plugins/pi/tool-result.js +7 -7
  38. package/dist/plugins/pi/window.d.ts +25 -3
  39. package/dist/plugins/pi/window.js +219 -9
  40. package/dist/src/boot/render.js +18 -15
  41. package/dist/src/boot/text.d.ts +3 -1
  42. package/dist/src/boot/text.js +22 -20
  43. package/dist/src/budget/text.d.ts +7 -3
  44. package/dist/src/budget/text.js +24 -15
  45. package/dist/src/history/claude.d.ts +2 -0
  46. package/dist/src/history/claude.js +46 -0
  47. package/dist/src/history/codex-transcript.js +7 -5
  48. package/dist/src/history/codex.js +3 -0
  49. package/dist/src/history/corpus.d.ts +28 -1
  50. package/dist/src/history/corpus.js +40 -0
  51. package/dist/src/history/history.d.ts +37 -46
  52. package/dist/src/history/history.js +21 -40
  53. package/dist/src/history/local.js +67 -32
  54. package/dist/src/history/pi.d.ts +2 -1
  55. package/dist/src/history/pi.js +122 -48
  56. package/dist/src/history/prefilter.js +76 -19
  57. package/dist/src/history/query.d.ts +28 -49
  58. package/dist/src/history/query.js +83 -68
  59. package/dist/src/history/summary-cache.d.ts +8 -1
  60. package/dist/src/history/summary-cache.js +138 -12
  61. package/dist/src/index.d.ts +2 -2
  62. package/dist/src/index.js +1 -1
  63. package/dist/src/notes/errors.d.ts +1 -1
  64. package/dist/src/notes/frontmatter.d.ts +0 -2
  65. package/dist/src/notes/frontmatter.js +0 -2
  66. package/dist/src/notes/index.d.ts +1 -1
  67. package/dist/src/notes/index.js +1 -1
  68. package/dist/src/notes/policy.d.ts +15 -1
  69. package/dist/src/notes/policy.js +46 -5
  70. package/dist/src/notes/store.d.ts +12 -0
  71. package/dist/src/notes/store.js +16 -20
  72. package/dist/src/text-match.d.ts +10 -1
  73. package/dist/src/text-match.js +42 -3
  74. package/dist/src/tools/dream.d.ts +22 -93
  75. package/dist/src/tools/dream.js +30 -27
  76. package/dist/src/tools/history.d.ts +33 -26
  77. package/dist/src/tools/history.js +257 -163
  78. package/dist/src/tools/notes.d.ts +51 -163
  79. package/dist/src/tools/notes.js +146 -100
  80. package/dist/src/tools/output.d.ts +2 -1
  81. package/dist/src/tools/output.js +2 -1
  82. package/dist/src/tools/result.d.ts +4 -7
  83. package/dist/src/tools/result.js +8 -9
  84. package/dist/src/tools/schema.d.ts +4 -1
  85. package/dist/src/tools/schema.js +25 -1
  86. package/dist/test/agent-loop.test.js +394 -56
  87. package/dist/test/antigravity-live.test.d.ts +1 -0
  88. package/dist/test/antigravity-live.test.js +142 -0
  89. package/dist/test/antigravity-plugin.test.d.ts +1 -0
  90. package/dist/test/antigravity-plugin.test.js +101 -0
  91. package/dist/test/boot.integration.test.js +156 -15
  92. package/dist/test/budget-settings.integration.test.js +4 -4
  93. package/dist/test/claude-history.test.js +14 -13
  94. package/dist/test/claude-mod.test.js +199 -16
  95. package/dist/test/claude-validation.test.js +69 -2
  96. package/dist/test/codex-history.test.js +15 -3
  97. package/dist/test/codex-plugin.test.js +76 -38
  98. package/dist/test/dependencies.test.js +7 -3
  99. package/dist/test/dream-skill.test.js +3 -3
  100. package/dist/test/dream-tools.test.js +101 -56
  101. package/dist/test/dsh.test.js +34 -19
  102. package/dist/test/helpers/dependency-graph.js +2 -2
  103. package/dist/test/helpers/extension.d.ts +68 -3
  104. package/dist/test/helpers/extension.js +74 -5
  105. package/dist/test/history-corpus.test.js +79 -77
  106. package/dist/test/history-summary-cache.test.js +97 -9
  107. package/dist/test/history.integration.test.js +234 -168
  108. package/dist/test/host-neutral.test.js +69 -19
  109. package/dist/test/marker.test.js +1 -1
  110. package/dist/test/model-facing-text.test.js +13 -3
  111. package/dist/test/note-policy.test.js +96 -77
  112. package/dist/test/notes.integration.test.js +212 -94
  113. package/dist/test/notes.test.js +184 -113
  114. package/dist/test/pi-render.test.js +20 -12
  115. package/dist/test/project-namespace.test.js +3 -2
  116. package/dist/test/reset-lifecycle.test.js +12 -2
  117. package/docs/antigravity.md +44 -0
  118. package/docs/architecture.md +6 -4
  119. package/docs/claude-code-mod.md +7 -7
  120. package/docs/codex.md +36 -38
  121. package/docs/dsh.md +3 -3
  122. package/docs/history-sessions.md +28 -50
  123. package/docs/notes-library.md +4 -4
  124. package/docs/reset-lifecycle.md +1 -1
  125. package/docs/skills.md +3 -3
  126. package/docs/tool-results.md +47 -28
  127. package/package.json +3 -2
  128. package/playbook.md +1 -1
  129. package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
  130. package/plugins/antigravity/hooks.json +7 -0
  131. package/plugins/antigravity/mcp_config.json +8 -0
  132. package/plugins/antigravity/plugin.json +6 -0
  133. package/plugins/antigravity/src/cli.ts +22 -0
  134. package/plugins/antigravity/src/hooks.ts +51 -0
  135. package/plugins/antigravity/src/identity.ts +127 -0
  136. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  137. package/plugins/claude/dist/claude/helper.js +1108 -539
  138. package/plugins/claude/hooks/register.ts +202 -62
  139. package/plugins/claude/playbook.md +1 -1
  140. package/plugins/claude/skills/dream/SKILL.md +1 -1
  141. package/plugins/claude/skills/notesoup-guide/SKILL.md +92 -0
  142. package/plugins/claude/src/helper.ts +24 -5
  143. package/plugins/claude/src/text.ts +14 -1
  144. package/plugins/codex/.codex-plugin/plugin.json +8 -0
  145. package/plugins/codex/.mcp.json +11 -0
  146. package/plugins/codex/README.md +5 -21
  147. package/plugins/codex/dist/codex/notesoup.js +18480 -17946
  148. package/plugins/codex/src/hooks.ts +1 -0
  149. package/plugins/codex/src/identity.ts +14 -1
  150. package/plugins/codex/src/mcp.ts +28 -98
  151. package/plugins/codex/src/text.ts +3 -3
  152. package/plugins/dsh/tools.ts +8 -4
  153. package/plugins/mcp/operations.ts +50 -0
  154. package/plugins/mcp/server.ts +23 -0
  155. package/plugins/paseo/README.md +5 -10
  156. package/plugins/paseo/client/brain-empty-card.tsx +3 -3
  157. package/plugins/paseo/client/markdown.tsx +50 -38
  158. package/plugins/paseo/client/notes-op-card.tsx +12 -9
  159. package/plugins/paseo/client/paper-card.tsx +6 -5
  160. package/plugins/paseo/client/paper-palette.ts +2 -9
  161. package/plugins/paseo/client/sticky-card.tsx +2 -2
  162. package/plugins/paseo/client/tool-result.ts +7 -14
  163. package/plugins/paseo/package-lock.json +3406 -0
  164. package/plugins/paseo/package.json +1 -0
  165. package/plugins/paseo/test/markdown-core.test.ts +73 -66
  166. package/plugins/pi/budget.ts +31 -8
  167. package/plugins/pi/entries.ts +2 -0
  168. package/plugins/pi/history-tools.ts +2 -1
  169. package/plugins/pi/history.ts +30 -1
  170. package/plugins/pi/notes/tools.ts +7 -3
  171. package/plugins/pi/render.ts +6 -6
  172. package/plugins/pi/reset/artifacts.ts +4 -3
  173. package/plugins/pi/reset/lifecycle.ts +125 -32
  174. package/plugins/pi/runtime.ts +98 -62
  175. package/plugins/pi/tool-result.ts +8 -8
  176. package/plugins/pi/window.ts +210 -10
  177. package/skills/dream/SKILL.md +1 -1
  178. package/skills/notesoup-guide/SKILL.md +92 -0
  179. package/src/boot/render.ts +18 -15
  180. package/src/boot/text.ts +23 -19
  181. package/src/budget/text.ts +27 -15
  182. package/src/history/claude.ts +41 -0
  183. package/src/history/codex-transcript.ts +6 -4
  184. package/src/history/codex.ts +2 -0
  185. package/src/history/corpus.ts +51 -2
  186. package/src/history/history.ts +35 -44
  187. package/src/history/local.ts +67 -27
  188. package/src/history/pi.ts +113 -35
  189. package/src/history/prefilter.ts +73 -15
  190. package/src/history/query.ts +93 -73
  191. package/src/history/summary-cache.ts +142 -17
  192. package/src/index.ts +2 -2
  193. package/src/notes/errors.ts +1 -1
  194. package/src/notes/frontmatter.ts +0 -3
  195. package/src/notes/index.ts +1 -1
  196. package/src/notes/policy.ts +44 -5
  197. package/src/notes/store.ts +17 -20
  198. package/src/text-match.ts +46 -4
  199. package/src/tools/dream.ts +29 -31
  200. package/src/tools/history.ts +249 -142
  201. package/src/tools/notes.ts +145 -113
  202. package/src/tools/output.ts +2 -1
  203. package/src/tools/result.ts +12 -11
  204. package/src/tools/schema.ts +24 -1
  205. package/plugins/claude/skills/memory/SKILL.md +0 -69
  206. package/plugins/codex/mcp.json +0 -10
  207. package/plugins/codex/plugin.json +0 -6
  208. package/plugins/paseo/client/markdown-core.tsx +0 -189
  209. package/plugins/paseo/client/typography.ts +0 -24
  210. 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
  });
@@ -1,9 +1,10 @@
1
1
  import { DEFAULT_BOOT_TOOL_NAMES } from "../../src/boot/text.js";
2
2
  import { remainingBudget, type ResolvedThresholds } from "../../src/budget/policy.js";
3
3
  import type { AgentMessage } from "@earendil-works/pi-agent-core";
4
+ import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
4
5
  import { Type } from "typebox";
5
6
  import { convertToLlm, defineTool, type ExtensionAPI, type ExtensionContext, type SessionBoundaryDraft, type SettingsManager } from "@earendil-works/pi-coding-agent";
6
- import { GUIDANCE_TYPE, WARNING_TYPE } from "./entries.js";
7
+ import { GUIDANCE_TYPE, TURNOVER_TRIGGER_TYPE, WARNING_TYPE } from "./entries.js";
7
8
  import { estimateContextTokens } from "./estimate.js";
8
9
  import { warningContent } from "./text.js";
9
10
  import { readThresholdSettings, type ThresholdSettingsResolution } from "./thresholds.js";
@@ -24,7 +25,7 @@ function remainingTokens(ctx: Pick<ExtensionContext, "sessionManager" | "getCont
24
25
 
25
26
  export function registerBudget(
26
27
  pi: ExtensionAPI,
27
- isEnabled: () => boolean,
28
+ isEnabled: (ctx: ExtensionContext) => boolean,
28
29
  settingsManager?: SettingsManager,
29
30
  ) {
30
31
  let cap: number | undefined;
@@ -45,17 +46,35 @@ export function registerBudget(
45
46
  const automaticResetEnabled = (ctx: ExtensionContext): boolean => resolvePolicy(ctx).automatic;
46
47
  const hardReserveDue = (ctx: ExtensionContext, preSendMessages?: AgentMessage[]): boolean => {
47
48
  if (!automaticResetEnabled(ctx)) return false;
49
+ const { reserve } = thresholdsFor(ctx);
50
+ const remaining = ctx.sessionManager ? remainingTokens(ctx, cap) : null;
48
51
  if (preSendMessages) {
52
+ if (remaining !== null && remaining <= reserve) return true;
49
53
  const nativeWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
50
54
  if (!nativeWindow || nativeWindow <= 0) return false;
51
55
  const contextWindow = Math.min(nativeWindow, cap ?? Infinity);
52
- const { reserve } = thresholdsFor(ctx);
53
56
  const estimate = estimateContextTokens(convertToLlm(preSendMessages));
54
- if (estimate.lastUsageIndex !== null && contextWindow - estimate.usageTokens <= reserve) return false;
57
+ if (remaining !== null) return remaining - estimate.trailingTokens <= reserve;
55
58
  return contextWindow - estimate.tokens <= reserve;
56
59
  }
57
- const remaining = remainingTokens(ctx, cap);
58
- return remaining !== null && remaining <= thresholdsFor(ctx).reserve;
60
+ return remaining !== null && remaining <= reserve;
61
+ };
62
+ const inputTokensFor = (content: string | Array<TextContent | ImageContent>): number =>
63
+ estimateContextTokens([{ role: "user", content, timestamp: 0 }]).tokens;
64
+ const hardReserveDueForInput = (ctx: ExtensionContext, content: string | Array<TextContent | ImageContent>): boolean => {
65
+ if (!automaticResetEnabled(ctx)) return false;
66
+ const { reserve } = thresholdsFor(ctx);
67
+ const remaining = ctx.sessionManager ? remainingTokens(ctx, cap) : null;
68
+ if (remaining === null) return false;
69
+ return remaining <= reserve || remaining - inputTokensFor(content) <= reserve;
70
+ };
71
+ const fitsInFreshWindow = (ctx: ExtensionContext, content: string | Array<TextContent | ImageContent>): boolean => {
72
+ const nativeWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
73
+ if (!nativeWindow || nativeWindow <= 0) return true;
74
+ const contextWindow = Math.min(nativeWindow, cap ?? Infinity);
75
+ const { reserve } = thresholdsFor(ctx);
76
+ const freshBudget = Math.max(0, contextWindow - reserve);
77
+ return inputTokensFor(content) <= Math.floor(freshBudget / 2);
59
78
  };
60
79
  let pendingGuidance: { windowId: string; content: string } | undefined;
61
80
  let pendingWarning: { windowId: string; content: string } | undefined;
@@ -89,13 +108,13 @@ export function registerBudget(
89
108
  }));
90
109
  };
91
110
 
92
- pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition(); thresholdsFor(ctx); });
111
+ pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition(); if (isEnabled(ctx)) thresholdsFor(ctx); });
93
112
  pi.on("session_tree", resetForTransition);
94
113
  pi.on("model_select", resetForTransition);
95
114
  pi.on("session_shutdown", () => { cap = undefined; resetForTransition(); });
96
115
  pi.on("agent_settled", clearStaged);
97
116
  pi.on("context", (event, ctx) => {
98
- if (!isEnabled()) return undefined;
117
+ if (!isEnabled(ctx)) return undefined;
99
118
  // Durable reminders return to the slot where the model first read them.
100
119
  const messages = arrangeAnchoredReminders(event.messages, ctx);
101
120
  const result = (extra?: { customType: string; content: string }) => {
@@ -106,6 +125,8 @@ export function registerBudget(
106
125
  // measured for that request, and persists the same text at its successful turn_end.
107
126
  // Without automatic reset nothing gets cleared, so there is nothing to remind about.
108
127
  if (!automaticResetEnabled(ctx)) return result();
128
+ const last = event.messages.at(-1);
129
+ if (last?.role === "custom" && last.customType === TURNOVER_TRIGGER_TYPE) return result();
109
130
  const remaining = remainingTokens(ctx, cap);
110
131
  if (remaining === null) return result();
111
132
  const windowId = currentWindowId(ctx);
@@ -150,6 +171,8 @@ export function registerBudget(
150
171
  return {
151
172
  automaticResetEnabled,
152
173
  hardReserveDue,
174
+ hardReserveDueForInput,
175
+ fitsInFreshWindow,
153
176
  consumeTurnEnd,
154
177
  /** The same room before the hard-reserve wipe the model sees; null when usage is unknown. */
155
178
  statusFor: (ctx: ExtensionContext) => ({ remaining: remainingBudget(remainingTokens(ctx, cap), thresholdsFor(ctx).reserve), cap }),
@@ -2,8 +2,10 @@ export const BOOT_TYPE = "notesoup/boot";
2
2
  export const GUIDANCE_TYPE = "notesoup/guidance";
3
3
  export const WARNING_TYPE = "notesoup/warning";
4
4
  export const MANUAL_WIPE_TYPE = "notesoup/manual-wipe";
5
+ export const TURNOVER_TRIGGER_TYPE = "notesoup/turnover";
5
6
  export const RESET_MARKER_TYPE = "notesoup/reset-marker";
6
7
  export const CONTINUATION_TYPE = "notesoup/continuation";
7
8
  export const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
8
9
  export const CARRIED_INPUT_TYPE = "notesoup/carried-input";
9
10
  export const MARKER_TYPE = "notesoup/marker";
11
+ 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 = "";
@@ -60,6 +60,7 @@ export async function buildResetDrafts(
60
60
  lastWord?: string,
61
61
  firstSeq?: number,
62
62
  origin: ResetOrigin = "normal",
63
+ betweenTurns = false,
63
64
  ): Promise<SessionBoundaryDraft[]> {
64
65
  const sessionId = ctx.sessionManager.getSessionId();
65
66
  const sessionPrefix = sessionId.slice(0, 8);
@@ -73,9 +74,9 @@ export async function buildResetDrafts(
73
74
  const boot = await buildBootMessage(ctx, windowId, firstSeq, notifyIncompleteNotes, isCurrent);
74
75
  return [
75
76
  { type: "compaction", summary: "", firstKeptEntryId: null },
76
- { type: "custom", customType: RESET_MARKER_TYPE, data: { windowId, origin } },
77
+ { type: "custom", customType: RESET_MARKER_TYPE, data: { windowId, origin, ...(betweenTurns ? { betweenTurns: true } : {}) } },
77
78
  { type: "custom_message", customType: BOOT_TYPE, content: boot.content, display: false, details: { windowId } },
78
- { type: "custom_message", customType: CONTINUATION_TYPE, content: selectContinuation(origin), display: false },
79
+ { type: "custom_message", customType: CONTINUATION_TYPE, content: selectContinuation(origin, { betweenTurns }), display: false },
79
80
  ...(lastWord ? [{ type: "custom_message" as const, customType: RESET_LAST_WORD_TYPE, content: `${LAST_WORD_PREFIX}${lastWord}`, display: true }] : []),
80
81
  ];
81
82
  }
@@ -136,5 +137,5 @@ export async function repairResetTail(
136
137
  const latest = inspectResetTail(ctx, marker.id, marker.data.windowId);
137
138
  if (!latest) return;
138
139
  if (!latest.boot && boot) sendBoot(pi, boot);
139
- if (!latest.continuation && (latest.boot || boot)) sendContinuation(pi, selectContinuation(markerResetOrigin(marker)));
140
+ if (!latest.continuation && (latest.boot || boot)) sendContinuation(pi, selectContinuation(markerResetOrigin(marker), { betweenTurns: marker.data.betweenTurns === true }));
140
141
  }