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.
- package/.agents/plugins/marketplace.json +15 -0
- package/README.md +14 -11
- package/dist/plugins/antigravity/src/cli.d.ts +1 -0
- package/dist/plugins/antigravity/src/cli.js +23 -0
- package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
- package/dist/plugins/antigravity/src/hooks.js +53 -0
- package/dist/plugins/antigravity/src/identity.d.ts +26 -0
- package/dist/plugins/antigravity/src/identity.js +129 -0
- package/dist/plugins/claude/src/helper.js +24 -5
- package/dist/plugins/claude/src/text.d.ts +7 -0
- package/dist/plugins/claude/src/text.js +12 -1
- package/dist/plugins/codex/src/hooks.js +1 -0
- package/dist/plugins/codex/src/identity.d.ts +6 -1
- package/dist/plugins/codex/src/identity.js +13 -1
- package/dist/plugins/codex/src/mcp.d.ts +35 -7
- package/dist/plugins/codex/src/mcp.js +26 -88
- package/dist/plugins/codex/src/text.js +3 -3
- package/dist/plugins/dsh/tools.js +8 -4
- package/dist/plugins/mcp/operations.d.ts +15 -0
- package/dist/plugins/mcp/operations.js +43 -0
- package/dist/plugins/mcp/server.d.ts +14 -0
- package/dist/plugins/mcp/server.js +13 -0
- package/dist/plugins/pi/budget.d.ts +4 -1
- package/dist/plugins/pi/budget.js +35 -8
- package/dist/plugins/pi/entries.d.ts +2 -0
- package/dist/plugins/pi/entries.js +2 -0
- package/dist/plugins/pi/history-tools.js +2 -1
- package/dist/plugins/pi/history.js +18 -1
- package/dist/plugins/pi/notes/tools.js +7 -3
- package/dist/plugins/pi/render.d.ts +7 -1
- package/dist/plugins/pi/render.js +2 -2
- package/dist/plugins/pi/reset/artifacts.d.ts +1 -1
- package/dist/plugins/pi/reset/artifacts.js +4 -4
- package/dist/plugins/pi/reset/lifecycle.d.ts +9 -2
- package/dist/plugins/pi/reset/lifecycle.js +109 -31
- package/dist/plugins/pi/runtime.js +104 -63
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +25 -3
- package/dist/plugins/pi/window.js +219 -9
- package/dist/src/boot/render.js +18 -15
- package/dist/src/boot/text.d.ts +3 -1
- package/dist/src/boot/text.js +22 -20
- package/dist/src/budget/text.d.ts +7 -3
- package/dist/src/budget/text.js +24 -15
- package/dist/src/history/claude.d.ts +2 -0
- package/dist/src/history/claude.js +46 -0
- package/dist/src/history/codex-transcript.js +7 -5
- package/dist/src/history/codex.js +3 -0
- package/dist/src/history/corpus.d.ts +28 -1
- package/dist/src/history/corpus.js +40 -0
- package/dist/src/history/history.d.ts +37 -46
- package/dist/src/history/history.js +21 -40
- package/dist/src/history/local.js +67 -32
- package/dist/src/history/pi.d.ts +2 -1
- package/dist/src/history/pi.js +122 -48
- package/dist/src/history/prefilter.js +76 -19
- package/dist/src/history/query.d.ts +28 -49
- package/dist/src/history/query.js +83 -68
- package/dist/src/history/summary-cache.d.ts +8 -1
- package/dist/src/history/summary-cache.js +138 -12
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +1 -1
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.d.ts +0 -2
- package/dist/src/notes/frontmatter.js +0 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/policy.d.ts +15 -1
- package/dist/src/notes/policy.js +46 -5
- package/dist/src/notes/store.d.ts +12 -0
- package/dist/src/notes/store.js +16 -20
- package/dist/src/text-match.d.ts +10 -1
- package/dist/src/text-match.js +42 -3
- package/dist/src/tools/dream.d.ts +22 -93
- package/dist/src/tools/dream.js +30 -27
- package/dist/src/tools/history.d.ts +33 -26
- package/dist/src/tools/history.js +257 -163
- package/dist/src/tools/notes.d.ts +51 -163
- package/dist/src/tools/notes.js +146 -100
- package/dist/src/tools/output.d.ts +2 -1
- package/dist/src/tools/output.js +2 -1
- package/dist/src/tools/result.d.ts +4 -7
- package/dist/src/tools/result.js +8 -9
- package/dist/src/tools/schema.d.ts +4 -1
- package/dist/src/tools/schema.js +25 -1
- package/dist/test/agent-loop.test.js +394 -56
- package/dist/test/antigravity-live.test.d.ts +1 -0
- package/dist/test/antigravity-live.test.js +142 -0
- package/dist/test/antigravity-plugin.test.d.ts +1 -0
- package/dist/test/antigravity-plugin.test.js +101 -0
- package/dist/test/boot.integration.test.js +156 -15
- package/dist/test/budget-settings.integration.test.js +4 -4
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +199 -16
- package/dist/test/claude-validation.test.js +69 -2
- package/dist/test/codex-history.test.js +15 -3
- package/dist/test/codex-plugin.test.js +76 -38
- package/dist/test/dependencies.test.js +7 -3
- package/dist/test/dream-skill.test.js +3 -3
- package/dist/test/dream-tools.test.js +101 -56
- package/dist/test/dsh.test.js +34 -19
- package/dist/test/helpers/dependency-graph.js +2 -2
- package/dist/test/helpers/extension.d.ts +68 -3
- package/dist/test/helpers/extension.js +74 -5
- package/dist/test/history-corpus.test.js +79 -77
- package/dist/test/history-summary-cache.test.js +97 -9
- package/dist/test/history.integration.test.js +234 -168
- package/dist/test/host-neutral.test.js +69 -19
- package/dist/test/marker.test.js +1 -1
- package/dist/test/model-facing-text.test.js +13 -3
- package/dist/test/note-policy.test.js +96 -77
- package/dist/test/notes.integration.test.js +212 -94
- package/dist/test/notes.test.js +184 -113
- package/dist/test/pi-render.test.js +20 -12
- package/dist/test/project-namespace.test.js +3 -2
- package/dist/test/reset-lifecycle.test.js +12 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +7 -7
- package/docs/codex.md +36 -38
- package/docs/dsh.md +3 -3
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +4 -4
- package/docs/reset-lifecycle.md +1 -1
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +47 -28
- package/package.json +3 -2
- package/playbook.md +1 -1
- package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
- package/plugins/antigravity/hooks.json +7 -0
- package/plugins/antigravity/mcp_config.json +8 -0
- package/plugins/antigravity/plugin.json +6 -0
- package/plugins/antigravity/src/cli.ts +22 -0
- package/plugins/antigravity/src/hooks.ts +51 -0
- package/plugins/antigravity/src/identity.ts +127 -0
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +1108 -539
- package/plugins/claude/hooks/register.ts +202 -62
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/notesoup-guide/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +24 -5
- package/plugins/claude/src/text.ts +14 -1
- package/plugins/codex/.codex-plugin/plugin.json +8 -0
- package/plugins/codex/.mcp.json +11 -0
- package/plugins/codex/README.md +5 -21
- package/plugins/codex/dist/codex/notesoup.js +18480 -17946
- package/plugins/codex/src/hooks.ts +1 -0
- package/plugins/codex/src/identity.ts +14 -1
- package/plugins/codex/src/mcp.ts +28 -98
- package/plugins/codex/src/text.ts +3 -3
- package/plugins/dsh/tools.ts +8 -4
- package/plugins/mcp/operations.ts +50 -0
- package/plugins/mcp/server.ts +23 -0
- package/plugins/paseo/README.md +5 -10
- package/plugins/paseo/client/brain-empty-card.tsx +3 -3
- package/plugins/paseo/client/markdown.tsx +50 -38
- package/plugins/paseo/client/notes-op-card.tsx +12 -9
- package/plugins/paseo/client/paper-card.tsx +6 -5
- package/plugins/paseo/client/paper-palette.ts +2 -9
- package/plugins/paseo/client/sticky-card.tsx +2 -2
- package/plugins/paseo/client/tool-result.ts +7 -14
- package/plugins/paseo/package-lock.json +3406 -0
- package/plugins/paseo/package.json +1 -0
- package/plugins/paseo/test/markdown-core.test.ts +73 -66
- package/plugins/pi/budget.ts +31 -8
- package/plugins/pi/entries.ts +2 -0
- package/plugins/pi/history-tools.ts +2 -1
- package/plugins/pi/history.ts +30 -1
- package/plugins/pi/notes/tools.ts +7 -3
- package/plugins/pi/render.ts +6 -6
- package/plugins/pi/reset/artifacts.ts +4 -3
- package/plugins/pi/reset/lifecycle.ts +125 -32
- package/plugins/pi/runtime.ts +98 -62
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +210 -10
- package/skills/dream/SKILL.md +1 -1
- package/skills/notesoup-guide/SKILL.md +92 -0
- package/src/boot/render.ts +18 -15
- package/src/boot/text.ts +23 -19
- package/src/budget/text.ts +27 -15
- package/src/history/claude.ts +41 -0
- package/src/history/codex-transcript.ts +6 -4
- package/src/history/codex.ts +2 -0
- package/src/history/corpus.ts +51 -2
- package/src/history/history.ts +35 -44
- package/src/history/local.ts +67 -27
- package/src/history/pi.ts +113 -35
- package/src/history/prefilter.ts +73 -15
- package/src/history/query.ts +93 -73
- package/src/history/summary-cache.ts +142 -17
- package/src/index.ts +2 -2
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +0 -3
- package/src/notes/index.ts +1 -1
- package/src/notes/policy.ts +44 -5
- package/src/notes/store.ts +17 -20
- package/src/text-match.ts +46 -4
- package/src/tools/dream.ts +29 -31
- package/src/tools/history.ts +249 -142
- package/src/tools/notes.ts +145 -113
- package/src/tools/output.ts +2 -1
- package/src/tools/result.ts +12 -11
- package/src/tools/schema.ts +24 -1
- package/plugins/claude/skills/memory/SKILL.md +0 -69
- package/plugins/codex/mcp.json +0 -10
- package/plugins/codex/plugin.json +0 -6
- package/plugins/paseo/client/markdown-core.tsx +0 -189
- package/plugins/paseo/client/typography.ts +0 -24
- package/skills/memory/SKILL.md +0 -69
|
@@ -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 {
|
|
4
|
-
import {
|
|
5
|
-
import ts from "typescript";
|
|
4
|
+
import { typography } from "@astrosheep/paseo-ui/theme";
|
|
5
|
+
import { paperPalette } from "../client/paper-palette.ts";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const active = elements(render("[ok](https://example.com?a=1&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("
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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** — `code`"), styles, "ns")), "bold — code");
|
|
81
|
+
assert.equal(textOf(renderInlines(Lexer.lexInline("*italic* & `x`"), styles, "in")), "italic & x");
|
|
75
82
|
});
|
package/plugins/pi/budget.ts
CHANGED
|
@@ -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 (
|
|
57
|
+
if (remaining !== null) return remaining - estimate.trailingTokens <= reserve;
|
|
55
58
|
return contextWindow - estimate.tokens <= reserve;
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
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 }),
|
package/plugins/pi/entries.ts
CHANGED
|
@@ -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
|
}
|
package/plugins/pi/history.ts
CHANGED
|
@@ -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
|
-
|
|
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) =>
|
|
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
|
|
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
|
}
|
package/plugins/pi/render.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|