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.
- package/.agents/plugins/marketplace.json +15 -0
- package/README.md +14 -10
- 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 +2 -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 +1 -1
- package/dist/plugins/pi/budget.js +3 -2
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -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/lifecycle.d.ts +1 -1
- package/dist/plugins/pi/reset/lifecycle.js +8 -9
- package/dist/plugins/pi/runtime.js +102 -61
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +33 -3
- package/dist/plugins/pi/window.js +209 -9
- package/dist/src/boot/render.d.ts +5 -0
- package/dist/src/boot/render.js +60 -28
- package/dist/src/boot/text.d.ts +3 -3
- package/dist/src/boot/text.js +27 -26
- package/dist/src/budget/text.d.ts +2 -2
- package/dist/src/budget/text.js +13 -13
- 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 +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/frontmatter.d.ts +4 -0
- package/dist/src/notes/frontmatter.js +15 -1
- 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 +47 -6
- package/dist/src/notes/store.d.ts +14 -0
- package/dist/src/notes/store.js +33 -12
- 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 -91
- 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 +58 -160
- package/dist/src/tools/notes.js +151 -99
- 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 +198 -16
- 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 +133 -14
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +9 -6
- 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 +65 -2
- package/dist/test/helpers/extension.js +72 -3
- 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/note-policy.test.js +189 -56
- 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 +2 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +2 -2
- package/docs/codex.md +36 -38
- package/docs/dsh.md +4 -4
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +6 -6
- 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 +3 -3
- 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 +1129 -549
- package/plugins/claude/hooks/register.ts +2 -2
- package/plugins/claude/playbook.md +3 -3
- package/plugins/claude/skills/dream/SKILL.md +2 -2
- package/plugins/claude/skills/notesoup/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +2 -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 +18494 -17905
- 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 +3 -3
- package/plugins/pi/entries.ts +1 -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/lifecycle.ts +9 -10
- package/plugins/pi/runtime.ts +96 -60
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +198 -9
- package/skills/dream/SKILL.md +2 -2
- package/skills/notesoup/SKILL.md +92 -0
- package/src/boot/render.ts +59 -25
- package/src/boot/text.ts +30 -27
- package/src/budget/text.ts +13 -13
- 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 +1 -1
- package/src/notes/frontmatter.ts +16 -1
- package/src/notes/index.ts +1 -1
- package/src/notes/policy.ts +45 -6
- package/src/notes/store.ts +30 -15
- 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 +150 -112
- 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
|
@@ -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 }) => {
|
package/plugins/pi/entries.ts
CHANGED
|
@@ -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
|
}
|
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 = "";
|
|
@@ -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
|
-
|
|
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
|
}
|