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,45 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { paramProblem } from "../../../src/tools/schema.js";
|
|
7
|
-
import { notesList, notesRead, notesUpdate, notesWrite } from "../../../src/tools/notes.js";
|
|
8
|
-
import { historyList, historyRead } from "../../../src/tools/history.js";
|
|
9
|
-
import { wireResult } from "../../../src/tools/result.js";
|
|
10
|
-
import { CodexIdentityError, notesIdentityFor, pluginDataRoot, readBinding, rootSessionIdOf, safeThreadId, turnModel } from "./identity.js";
|
|
1
|
+
/** Codex alone owns its hook bindings, window validation and native history. */
|
|
2
|
+
import { bindOperation, createNoteTools } from "../../mcp/operations.js";
|
|
3
|
+
import { createToolServer, runToolServer } from "../../mcp/server.js";
|
|
4
|
+
import { historyList, historySearch, historyRead } from "../../../src/tools/history.js";
|
|
5
|
+
import { CodexIdentityError, notesIdentityFor, mcpPluginDataRoot, readBinding, rootSessionIdOf, safeThreadId, turnModel } from "./identity.js";
|
|
11
6
|
import { readCodexHistory } from "../../../src/history/codex.js";
|
|
12
7
|
import { localHistoryCorpus } from "../../../src/history/local.js";
|
|
13
8
|
import { readStartState } from "./state.js";
|
|
14
9
|
import { notesToolContext } from "../../../src/tools/notes-context.js";
|
|
15
|
-
const OPERATIONS = {
|
|
16
|
-
notes_write: { operation: notesWrite, history: false },
|
|
17
|
-
notes_update: { operation: notesUpdate, history: false },
|
|
18
|
-
notes_read: { operation: notesRead, history: false },
|
|
19
|
-
notes_list: { operation: notesList, history: false },
|
|
20
|
-
history_list: { operation: historyList, history: true },
|
|
21
|
-
history_read: { operation: historyRead, history: true },
|
|
22
|
-
};
|
|
23
|
-
function shellFree(reason) {
|
|
24
|
-
const value = reason instanceof Error ? reason.message : String(reason);
|
|
25
|
-
return value.replace(/[\r\n]+/g, " ").slice(0, 500);
|
|
26
|
-
}
|
|
27
|
-
function failure(code, message) {
|
|
28
|
-
return {
|
|
29
|
-
content: [{ type: "text", text: `error: ${code}: ${message}` }],
|
|
30
|
-
structuredContent: { error: message, code },
|
|
31
|
-
isError: true,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function successFor(bound, outcome) {
|
|
35
|
-
const wire = wireResult(outcome);
|
|
36
|
-
return {
|
|
37
|
-
content: [{ type: "text", text: bound.operation.render(outcome) }],
|
|
38
|
-
structuredContent: wire,
|
|
39
|
-
// A refusal stays a tool-level error so the model does not mistake it for data.
|
|
40
|
-
...(outcome.ok ? {} : { isError: true }),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
10
|
/** MCP metadata is the caller's claim; it must agree with the hook binding before any read. */
|
|
44
11
|
function metaFacts(meta, binding) {
|
|
45
12
|
const rootSessionId = rootSessionIdOf(meta);
|
|
@@ -49,13 +16,14 @@ function metaFacts(meta, binding) {
|
|
|
49
16
|
const windowId = typeof meta.windowId === "string" && meta.windowId !== "" ? meta.windowId : undefined;
|
|
50
17
|
if (windowId === undefined)
|
|
51
18
|
throw new CodexIdentityError("missing_window", "Codex did not supply the current native window in MCP metadata; refusing to use a possibly stale binding.");
|
|
52
|
-
|
|
19
|
+
const numberedId = binding.windowNumber === undefined ? undefined : `${binding.threadId}:${binding.windowNumber}`;
|
|
20
|
+
if (binding.windowId !== windowId && numberedId !== windowId)
|
|
53
21
|
throw new CodexIdentityError("stale_thread_binding", "This thread's hook binding belongs to a different native window. Resume or compact once so the SessionStart hook rebinds it; notesoup will not read or write through stale identity.");
|
|
54
22
|
return { rootSessionId };
|
|
55
23
|
}
|
|
56
24
|
async function identityFor(meta, env) {
|
|
57
25
|
const threadId = safeThreadId(meta.threadId, "MCP threadId");
|
|
58
|
-
const binding = await readBinding(
|
|
26
|
+
const binding = await readBinding(mcpPluginDataRoot(env), threadId);
|
|
59
27
|
const { rootSessionId } = metaFacts(meta, binding);
|
|
60
28
|
return { binding, rootSessionId, model: turnModel(meta) };
|
|
61
29
|
}
|
|
@@ -68,7 +36,7 @@ function verifyNativeFacts(binding, rootSessionId, native) {
|
|
|
68
36
|
}
|
|
69
37
|
if (native.currentWindowId === undefined)
|
|
70
38
|
throw new CodexIdentityError("missing_window", "The native transcript has no materialized current window; refusing to guess one.");
|
|
71
|
-
if (native.currentWindowId !== binding.windowId) {
|
|
39
|
+
if (native.currentWindowId !== binding.windowId || (binding.windowNumber !== undefined && native.currentWindowNumber !== binding.windowNumber)) {
|
|
72
40
|
throw new CodexIdentityError("stale_native_state", "The native transcript advanced to a different window. Resume or compact once so the SessionStart hook rebinds it; notesoup will not read or write through stale identity.");
|
|
73
41
|
}
|
|
74
42
|
}
|
|
@@ -81,6 +49,7 @@ function sameBinding(left, right) {
|
|
|
81
49
|
&& left.home === right.home
|
|
82
50
|
&& left.transcriptPath === right.transcriptPath
|
|
83
51
|
&& left.windowId === right.windowId
|
|
52
|
+
&& left.windowNumber === right.windowNumber
|
|
84
53
|
&& left.agentType === right.agentType;
|
|
85
54
|
}
|
|
86
55
|
async function readNative(binding, rootSessionId, history, meta, env) {
|
|
@@ -91,7 +60,7 @@ async function readNative(binding, rootSessionId, history, meta, env) {
|
|
|
91
60
|
verifyNativeFacts(binding, rootSessionId, native);
|
|
92
61
|
// Native reads are asynchronous: a hook may have rebound this thread while we were
|
|
93
62
|
// reading. Compare again before trusting either the cached binding or a mutation.
|
|
94
|
-
const reread = await readBinding(
|
|
63
|
+
const reread = await readBinding(mcpPluginDataRoot(env), binding.threadId);
|
|
95
64
|
if (!sameBinding(binding, reread)) {
|
|
96
65
|
throw new CodexIdentityError("stale_thread_binding", "This thread's hook binding changed while notesoup was reading native facts; retry once the new native window is settled.");
|
|
97
66
|
}
|
|
@@ -100,52 +69,21 @@ async function readNative(binding, rootSessionId, history, meta, env) {
|
|
|
100
69
|
verifyNativeFacts(reread, rootSessionId, native);
|
|
101
70
|
return native;
|
|
102
71
|
}
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
if (bound === undefined)
|
|
106
|
-
return failure("unknown_tool", `No notesoup operation named ${JSON.stringify(name)}.`);
|
|
107
|
-
const params = args ?? {};
|
|
108
|
-
if (!Check(bound.operation.parameters, params))
|
|
109
|
-
return failure("invalid_params", `invalid ${name} parameters: ${paramProblem(bound.operation.parameters, params)}`);
|
|
110
|
-
try {
|
|
72
|
+
function toolSet(env) {
|
|
73
|
+
const notes = async (meta) => {
|
|
111
74
|
const { binding, rootSessionId, model } = await identityFor(meta, env);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
75
|
+
await readNative(binding, rootSessionId, false, meta, env);
|
|
76
|
+
return notesToolContext(notesIdentityFor(binding, model), binding.cwd);
|
|
77
|
+
};
|
|
78
|
+
const history = async (meta, params) => {
|
|
79
|
+
const { binding, rootSessionId } = await identityFor(meta, env);
|
|
118
80
|
const current = async () => (await readNative(binding, rootSessionId, true, meta, env)).projection;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return failure(error.code, error.message);
|
|
126
|
-
return failure("codex_error", shellFree(error));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
export function tools() {
|
|
130
|
-
return Object.entries(OPERATIONS).map(([name, bound]) => ({
|
|
131
|
-
name,
|
|
132
|
-
description: bound.operation.description,
|
|
133
|
-
inputSchema: JSON.parse(JSON.stringify(bound.operation.parameters)),
|
|
134
|
-
// Every shared success and refusal is an object; the union stays the same
|
|
135
|
-
// logical schema, wrapped in the object shape the MCP tool schema requires.
|
|
136
|
-
outputSchema: { type: "object", ...JSON.parse(JSON.stringify(bound.operation.outputSchema)) },
|
|
137
|
-
}));
|
|
138
|
-
}
|
|
139
|
-
export function createServer(env = process.env) {
|
|
140
|
-
const server = new Server({ name: "notesoup", version: "1.0.0" }, { capabilities: { tools: {} } });
|
|
141
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools() }));
|
|
142
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
143
|
-
const meta = (request.params._meta ?? {});
|
|
144
|
-
return await callTool(request.params.name, request.params.arguments, meta, env);
|
|
145
|
-
});
|
|
146
|
-
return server;
|
|
147
|
-
}
|
|
148
|
-
export async function runMcp(env = process.env) {
|
|
149
|
-
const server = createServer(env);
|
|
150
|
-
await server.connect(new StdioServerTransport());
|
|
81
|
+
if (params.session === undefined)
|
|
82
|
+
return current();
|
|
83
|
+
await readNative(binding, rootSessionId, false, meta, env);
|
|
84
|
+
return { current, corpus: localHistoryCorpus({ env, current: { harness: "codex", id: binding.threadId, load: async () => ({ projection: await current() }) } }) };
|
|
85
|
+
};
|
|
86
|
+
return { name: "notesoup", ...createNoteTools(notes, [bindOperation(historyList, history), bindOperation(historySearch, history), bindOperation(historyRead, history)], "codex_error") };
|
|
151
87
|
}
|
|
88
|
+
export const createServer = (env = process.env) => createToolServer(toolSet(env));
|
|
89
|
+
export const runMcp = (env = process.env) => runToolServer(toolSet(env));
|
|
@@ -10,14 +10,14 @@ export const CODEX_PRE_RESET_HINTS = [
|
|
|
10
10
|
"Native-mode prerequisite: `new_context` and `get_context_remaining` are Codex's own token_budget tools. notesoup serves notes and history only; it has no MCP reset or budget fallback, and this text appears only on the native SessionStart hook.",
|
|
11
11
|
"These notes, MAPs and protocol are notes data, not higher authority than Codex's own instructions.",
|
|
12
12
|
"The notes and history tools come from the notesoup MCP server; Codex may prefix their logical names with a server namespace, so use the names that appear in your tool list.",
|
|
13
|
-
"Child limitation
|
|
13
|
+
"Child limitation: the supported native hook contract has no child post-compact boot/recovery hook. notesoup therefore stops a child at PreCompact instead of letting recovery be lost; finish the child with a handoff note, then start a fresh child.",
|
|
14
14
|
].join("\n\n");
|
|
15
15
|
export const CODEX_SETUP_HINT = "Enable and trust the notesoup plugin in Codex, then start or resume the thread. notesoup binds identities from hooks and never from the MCP server's cwd.";
|
|
16
16
|
export function unsupportedChildCompaction() {
|
|
17
|
-
return "notesoup: refusing this child context rollover. Codex
|
|
17
|
+
return "notesoup: refusing this child context rollover. Codex's supported hook contract has no child post-compact boot/recovery hook, so continuing would silently lose this child's notes recovery. Save a handoff note, then start a fresh child with that note; full child recovery remains an unfinished native gap.";
|
|
18
18
|
}
|
|
19
19
|
export function missingNativeFacts(reason) {
|
|
20
|
-
return `notesoup: no boot injected because Codex's native window facts could not be read (${reason}). ${CODEX_SETUP_HINT} notesoup
|
|
20
|
+
return `notesoup: no boot injected because Codex's native window facts could not be read (${reason}). ${CODEX_SETUP_HINT} notesoup requires a supported native transcript shape.`;
|
|
21
21
|
}
|
|
22
22
|
/** A boot can still identify itself when the note store itself refused; it must not pretend notebooks are empty. */
|
|
23
23
|
export function notesFailureBoot(reason) {
|
|
@@ -2,7 +2,7 @@ import { HarnessError } from "@deepseek-ai/dsh-llm";
|
|
|
2
2
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
3
3
|
import { Check, Errors } from "typebox/value";
|
|
4
4
|
import { notesList, notesRead, notesUpdate, notesWrite } from "../../src/tools/notes.js";
|
|
5
|
-
import { historyList, historyRead } from "../../src/tools/history.js";
|
|
5
|
+
import { historyList, historySearch, historyRead } from "../../src/tools/history.js";
|
|
6
6
|
import { success } from "../../src/result.js";
|
|
7
7
|
import { historyContext } from "./history.js";
|
|
8
8
|
import { notesCwd, notesIdentity } from "./window.js";
|
|
@@ -35,9 +35,12 @@ function register(ctx, operation, inputs) {
|
|
|
35
35
|
name: operation.name,
|
|
36
36
|
description: operation.description,
|
|
37
37
|
parameters: hostSchema(operation.parameters),
|
|
38
|
-
output: {
|
|
38
|
+
output: operation.outputSchema !== undefined ? {
|
|
39
39
|
schema: hostSchema(operation.outputSchema),
|
|
40
40
|
render: (_args, value) => [{ type: "text", text: operation.render(success(value)) }],
|
|
41
|
+
} : {
|
|
42
|
+
schema: { type: "string" },
|
|
43
|
+
render: (_args, value) => [{ type: "text", text: value }],
|
|
41
44
|
},
|
|
42
45
|
async execute(args, exec) {
|
|
43
46
|
const agent = requireAgent(exec);
|
|
@@ -51,7 +54,7 @@ function register(ctx, operation, inputs) {
|
|
|
51
54
|
const result = await operation.execute(args, ...rest);
|
|
52
55
|
if (!result.ok)
|
|
53
56
|
throw new HarnessError(operation.render(result), result.error.code);
|
|
54
|
-
return result.data;
|
|
57
|
+
return operation.outputSchema !== undefined ? result.data : operation.render(result);
|
|
55
58
|
},
|
|
56
59
|
});
|
|
57
60
|
}
|
|
@@ -79,10 +82,11 @@ export function registerTools(ctx, engine) {
|
|
|
79
82
|
register(ctx, notesRead, (agent) => [toolContext(agent)]);
|
|
80
83
|
register(ctx, notesList, (agent) => [toolContext(agent)]);
|
|
81
84
|
register(ctx, historyList, (agent) => [historyContext(ctx, agent.session.id)]);
|
|
85
|
+
register(ctx, historySearch, (agent) => [historyContext(ctx, agent.session.id)]);
|
|
82
86
|
register(ctx, historyRead, (agent) => [historyContext(ctx, agent.session.id)]);
|
|
83
87
|
ctx.tools.register(defineTool({
|
|
84
88
|
name: "empty_brain",
|
|
85
|
-
description: "Open a fresh context window after this tool batch. Write recovery notes first; notes and raw history
|
|
89
|
+
description: "Open a fresh context window after this tool batch. Write recovery notes first; notes and raw history survive.",
|
|
86
90
|
parameters: {},
|
|
87
91
|
output: { schema: { type: "object", properties: { window_id: { type: "string", required: true }, reset_requested: { type: "boolean", required: true } }, additionalProperties: false }, render: (_args, value) => [{ type: "text", text: `notesoup: reset requested for ${value.window_id}; finish this tool batch, then recover from your notes.` }] },
|
|
88
92
|
async execute(_args, exec) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Bind each core operation to host context, resolved only after validating this request. */
|
|
2
|
+
import type { CallToolResult, Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { TSchema } from "typebox";
|
|
4
|
+
import type { NotesToolContext } from "../../src/tools/notes-context.js";
|
|
5
|
+
import { type Operation } from "../../src/tools/result.js";
|
|
6
|
+
import type { Meta, ToolSet } from "./server.js";
|
|
7
|
+
type Bound = {
|
|
8
|
+
tool: Tool;
|
|
9
|
+
structured: boolean;
|
|
10
|
+
call(args: unknown, meta: Meta): Promise<CallToolResult>;
|
|
11
|
+
};
|
|
12
|
+
type Resolve<C> = (meta: Meta, params: Record<string, unknown>) => Promise<C>;
|
|
13
|
+
export declare function bindOperation<P extends TSchema, D, C>(op: Operation<P, D, [C]>, resolve: Resolve<C>): Bound;
|
|
14
|
+
export declare function createNoteTools(resolve: Resolve<NotesToolContext>, additional?: Bound[], fallbackCode?: string): ToolSet;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Check } from "typebox/value";
|
|
2
|
+
import { notesList, notesRead, notesUpdate, notesWrite } from "../../src/tools/notes.js";
|
|
3
|
+
import { wireResult } from "../../src/tools/result.js";
|
|
4
|
+
import { paramProblem } from "../../src/tools/schema.js";
|
|
5
|
+
function refusal(code, message, structured = false) {
|
|
6
|
+
return { content: [{ type: "text", text: `error: ${code}: ${message}` }], ...(structured ? { structuredContent: { error: message, code } } : {}), isError: true };
|
|
7
|
+
}
|
|
8
|
+
export function bindOperation(op, resolve) {
|
|
9
|
+
const structured = op.outputSchema !== undefined;
|
|
10
|
+
return {
|
|
11
|
+
structured,
|
|
12
|
+
tool: { name: op.name, description: op.description, inputSchema: JSON.parse(JSON.stringify(op.parameters)),
|
|
13
|
+
...(structured ? { outputSchema: { type: "object", ...JSON.parse(JSON.stringify(op.outputSchema)) } } : {}) },
|
|
14
|
+
async call(args, meta) {
|
|
15
|
+
const params = args ?? {};
|
|
16
|
+
if (!Check(op.parameters, params))
|
|
17
|
+
return refusal("invalid_params", `invalid ${op.name} parameters: ${paramProblem(op.parameters, params)}`, structured);
|
|
18
|
+
const ctx = await resolve(meta, params);
|
|
19
|
+
const outcome = await op.execute(params, ctx);
|
|
20
|
+
return { content: [{ type: "text", text: op.render(outcome) }], ...(structured ? { structuredContent: wireResult(outcome) } : {}),
|
|
21
|
+
...(outcome.ok ? {} : { isError: true }) };
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function createNoteTools(resolve, additional = [], fallbackCode = "notesoup_error") {
|
|
26
|
+
const entries = [bindOperation(notesWrite, resolve), bindOperation(notesUpdate, resolve), bindOperation(notesRead, resolve), bindOperation(notesList, resolve), ...additional];
|
|
27
|
+
const byName = new Map(entries.map(entry => [entry.tool.name, entry]));
|
|
28
|
+
return {
|
|
29
|
+
tools: () => entries.map(entry => entry.tool),
|
|
30
|
+
async callTool(name, args, meta) {
|
|
31
|
+
const entry = byName.get(name);
|
|
32
|
+
if (!entry)
|
|
33
|
+
return refusal("unknown_tool", `No notesoup operation named ${JSON.stringify(name)}.`);
|
|
34
|
+
try {
|
|
35
|
+
return await entry.call(args, meta);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
const code = e instanceof Error && "code" in e && typeof e.code === "string" ? e.code : fallbackCode;
|
|
39
|
+
return refusal(code, (e instanceof Error ? e.message : String(e)).replace(/[\r\n]+/g, " ").slice(0, 500), entry.structured);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** MCP framing only. Host facts belong to the tool call, not to the server process. */
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { type CallToolResult, type Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
export type Meta = Record<string, unknown>;
|
|
5
|
+
export type ToolSet = {
|
|
6
|
+
tools(): Tool[];
|
|
7
|
+
callTool(name: string, args: unknown, meta: Meta): Promise<CallToolResult>;
|
|
8
|
+
};
|
|
9
|
+
type ServerOptions = ToolSet & {
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function createToolServer(options: ServerOptions): Server;
|
|
13
|
+
export declare function runToolServer(options: ServerOptions): Promise<void>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** MCP framing only. Host facts belong to the tool call, not to the server process. */
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
export function createToolServer(options) {
|
|
6
|
+
const server = new Server({ name: options.name, version: "1.0.0" }, { capabilities: { tools: {} } });
|
|
7
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: options.tools() }));
|
|
8
|
+
server.setRequestHandler(CallToolRequestSchema, async ({ params }) => options.callTool(params.name, params.arguments, params._meta ?? {}));
|
|
9
|
+
return server;
|
|
10
|
+
}
|
|
11
|
+
export async function runToolServer(options) {
|
|
12
|
+
await createToolServer(options).connect(new StdioServerTransport());
|
|
13
|
+
}
|
|
@@ -4,7 +4,7 @@ import { type ExtensionAPI, type ExtensionContext, type SessionBoundaryDraft, ty
|
|
|
4
4
|
export declare const ContextRemainingOutputSchema: Type.TObject<{
|
|
5
5
|
remaining_tokens: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
6
6
|
}>;
|
|
7
|
-
export declare function registerBudget(pi: ExtensionAPI, isEnabled: () => boolean, settingsManager?: SettingsManager): {
|
|
7
|
+
export declare function registerBudget(pi: ExtensionAPI, isEnabled: (ctx: ExtensionContext) => boolean, settingsManager?: SettingsManager): {
|
|
8
8
|
automaticResetEnabled: (ctx: ExtensionContext) => boolean;
|
|
9
9
|
hardReserveDue: (ctx: ExtensionContext, preSendMessages?: AgentMessage[]) => boolean;
|
|
10
10
|
consumeTurnEnd: (ctx: ExtensionContext, anchorEntryId: string) => SessionBoundaryDraft[];
|
|
@@ -84,13 +84,14 @@ export function registerBudget(pi, isEnabled, settingsManager) {
|
|
|
84
84
|
details: { anchorEntryId },
|
|
85
85
|
}));
|
|
86
86
|
};
|
|
87
|
-
pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition();
|
|
87
|
+
pi.on("session_start", (_event, ctx) => { cap = undefined; resetForTransition(); if (isEnabled(ctx))
|
|
88
|
+
thresholdsFor(ctx); });
|
|
88
89
|
pi.on("session_tree", resetForTransition);
|
|
89
90
|
pi.on("model_select", resetForTransition);
|
|
90
91
|
pi.on("session_shutdown", () => { cap = undefined; resetForTransition(); });
|
|
91
92
|
pi.on("agent_settled", clearStaged);
|
|
92
93
|
pi.on("context", (event, ctx) => {
|
|
93
|
-
if (!isEnabled())
|
|
94
|
+
if (!isEnabled(ctx))
|
|
94
95
|
return undefined;
|
|
95
96
|
// Durable reminders return to the slot where the model first read them.
|
|
96
97
|
const messages = arrangeAnchoredReminders(event.messages, ctx);
|
|
@@ -7,3 +7,4 @@ export declare const CONTINUATION_TYPE = "notesoup/continuation";
|
|
|
7
7
|
export declare const RESET_LAST_WORD_TYPE = "notesoup/reset-last-word";
|
|
8
8
|
export declare const CARRIED_INPUT_TYPE = "notesoup/carried-input";
|
|
9
9
|
export declare const MARKER_TYPE = "notesoup/marker";
|
|
10
|
+
export declare const ENABLED_TYPE = "notesoup/enabled";
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { historyList, historyRead } from "../../src/tools/history.js";
|
|
1
|
+
import { historyList, historySearch, historyRead } from "../../src/tools/history.js";
|
|
2
2
|
import { historyFromSession } from "./history.js";
|
|
3
3
|
import { localHistoryCorpus } from "../../src/history/local.js";
|
|
4
4
|
import { HISTORY_NAMESPACE, registerOperation } from "./tool-result.js";
|
|
@@ -9,5 +9,6 @@ function historyContext(ctx) {
|
|
|
9
9
|
/** Register the two deferred history operations; the adapter allocates addresses and supplies them. */
|
|
10
10
|
export function registerHistoryTools(pi) {
|
|
11
11
|
registerOperation(pi, historyList, (params, ctx) => historyList.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
|
|
12
|
+
registerOperation(pi, historySearch, (params, ctx) => historySearch.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
|
|
12
13
|
registerOperation(pi, historyRead, (params, ctx) => historyRead.execute(params, historyContext(ctx)), HISTORY_NAMESPACE, undefined, "deferred");
|
|
13
14
|
}
|
|
@@ -2,7 +2,24 @@ import { piHistoryFromEntries, piSequenceCount } from "../../src/history/pi.js";
|
|
|
2
2
|
export function nextHistorySeq(ctx, pending = []) {
|
|
3
3
|
return 1 + [...ctx.sessionManager.getEntries(), ...pending].reduce((sum, entry) => sum + piSequenceCount(entry), 0);
|
|
4
4
|
}
|
|
5
|
+
const projectionCache = new WeakMap();
|
|
5
6
|
export function historyFromSession(ctx) {
|
|
6
7
|
const manager = ctx.sessionManager;
|
|
7
|
-
|
|
8
|
+
const sessionId = manager.getSessionId();
|
|
9
|
+
const entries = manager.getEntries();
|
|
10
|
+
const branch = manager.getBranch();
|
|
11
|
+
const lastEntry = entries.at(-1);
|
|
12
|
+
const lastBranch = branch.at(-1);
|
|
13
|
+
const cached = projectionCache.get(manager);
|
|
14
|
+
if (cached
|
|
15
|
+
&& cached.sessionId === sessionId
|
|
16
|
+
&& cached.entryCount === entries.length
|
|
17
|
+
&& cached.lastEntry === lastEntry
|
|
18
|
+
&& cached.branchCount === branch.length
|
|
19
|
+
&& cached.lastBranch === lastBranch) {
|
|
20
|
+
return cached.projection;
|
|
21
|
+
}
|
|
22
|
+
const projection = piHistoryFromEntries(sessionId, entries, branch);
|
|
23
|
+
projectionCache.set(manager, { sessionId, entryCount: entries.length, lastEntry, branchCount: branch.length, lastBranch, projection });
|
|
24
|
+
return projection;
|
|
8
25
|
}
|
|
@@ -4,6 +4,7 @@ import { abandonDream, dreamBegin, dreamEnd, dreamForget, dreamingIdentity } fro
|
|
|
4
4
|
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
|
+
import { wireResult } from "../../../src/tools/result.js";
|
|
7
8
|
import { notesToolContext } from "../../../src/tools/notes-context.js";
|
|
8
9
|
function renderDiff(change) {
|
|
9
10
|
return change.kind === "none" ? "" : generateDiffString(change.before, change.after, 1).diff;
|
|
@@ -26,15 +27,18 @@ export function registerNotesTools(pi) {
|
|
|
26
27
|
};
|
|
27
28
|
const identity = (ctx) => dreamingIdentity(notesIdentityFromPi(ctx), dreamOf(ctx));
|
|
28
29
|
const toolContext = (ctx) => notesToolContext(identity(ctx), ctx.cwd);
|
|
29
|
-
registerOperation(pi, notesWrite, (params, ctx) =>
|
|
30
|
+
registerOperation(pi, notesWrite, async (params, ctx) => {
|
|
31
|
+
const outcome = await notesWrite.execute(params, toolContext(ctx));
|
|
32
|
+
return { ...outcome, details: { receipt: wireResult(outcome) } };
|
|
33
|
+
}, NOTES_NAMESPACE, notesWriteRenderers);
|
|
30
34
|
registerOperation(pi, notesUpdate, async (params, ctx) => {
|
|
31
35
|
let diff = "";
|
|
32
36
|
const outcome = await notesUpdate.execute(params, toolContext(ctx), (change) => { diff = renderDiff(change); });
|
|
33
|
-
return
|
|
37
|
+
return { ...outcome, details: { receipt: wireResult(outcome), ...(diff ? { diff } : {}) } };
|
|
34
38
|
}, NOTES_NAMESPACE, notesUpdateRenderers);
|
|
35
39
|
registerOperation(pi, notesRead, (params, ctx) => notesRead.execute(params, toolContext(ctx)), NOTES_NAMESPACE, notesReadRenderers);
|
|
36
40
|
registerOperation(pi, notesList, (params, ctx) => notesList.execute(params, toolContext(ctx)), NOTES_NAMESPACE);
|
|
37
|
-
registerOperation(pi, dreamBegin, (params, ctx) => dreamBegin.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
|
|
41
|
+
registerOperation(pi, dreamBegin, (params, ctx) => dreamBegin.execute(params, notesToolContext(notesIdentityFromPi(ctx), ctx.cwd), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
|
|
38
42
|
registerOperation(pi, dreamForget, (params, ctx) => dreamForget.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
|
|
39
43
|
registerOperation(pi, dreamEnd, (params, ctx) => dreamEnd.execute(params, notesIdentityFromPi(ctx), dreamOf(ctx)), DREAM_NAMESPACE, undefined, "deferred");
|
|
40
44
|
}
|
|
@@ -2,20 +2,26 @@
|
|
|
2
2
|
import { type AgentToolResult, type Theme } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { type Component } from "@earendil-works/pi-tui";
|
|
4
4
|
import type { Static } from "typebox";
|
|
5
|
+
import type { WireResult } from "../../src/tools/result.js";
|
|
6
|
+
import type { NotesUpdateData, NotesWriteData } from "../../src/tools/notes.js";
|
|
5
7
|
import { notesReadParameters, notesUpdateParameters, notesWriteParameters } from "../../src/tools/notes.js";
|
|
6
8
|
/** Only the render-context members these renderers read; the host's ToolRenderContext satisfies this. */
|
|
7
9
|
type CallContext<TArgs> = {
|
|
8
10
|
args: TArgs;
|
|
9
11
|
};
|
|
12
|
+
export type NotesWriteDetails = {
|
|
13
|
+
receipt: WireResult<NotesWriteData>;
|
|
14
|
+
};
|
|
10
15
|
export type NotesWriteArgs = Static<typeof notesWriteParameters>;
|
|
11
16
|
export declare const notesWriteRenderers: {
|
|
12
17
|
renderCall: (args: NotesWriteArgs, theme: Theme) => Component;
|
|
13
|
-
renderResult(result: AgentToolResult<undefined>, options: {
|
|
18
|
+
renderResult(result: AgentToolResult<NotesWriteDetails | undefined>, options: {
|
|
14
19
|
expanded: boolean;
|
|
15
20
|
}, theme: Theme, context: CallContext<NotesWriteArgs>): Component;
|
|
16
21
|
};
|
|
17
22
|
export type NotesUpdateArgs = Static<typeof notesUpdateParameters>;
|
|
18
23
|
export type NotesUpdateDetails = {
|
|
24
|
+
receipt: WireResult<NotesUpdateData>;
|
|
19
25
|
diff?: string;
|
|
20
26
|
};
|
|
21
27
|
export declare const notesUpdateRenderers: {
|
|
@@ -3,9 +3,9 @@ import { renderDiff } from "@earendil-works/pi-coding-agent";
|
|
|
3
3
|
import { Container, Text, TruncatedText, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
4
4
|
/** Expanded bodies show this many lines before a "more lines" marker; the full text is in the receipt. */
|
|
5
5
|
const EXPANDED_LINE_CAP = 80;
|
|
6
|
-
/**
|
|
6
|
+
/** Receipts are wireResult(outcome), stored in mutation details or notes_read structuredContent. */
|
|
7
7
|
function wireOf(result) {
|
|
8
|
-
const sc = result.structuredContent;
|
|
8
|
+
const sc = result.structuredContent ?? result.details?.receipt;
|
|
9
9
|
if (sc !== null && typeof sc === "object" && !Array.isArray(sc)) {
|
|
10
10
|
const obj = sc;
|
|
11
11
|
if (typeof obj.error === "string")
|
|
@@ -9,7 +9,7 @@ type BudgetOwner = {
|
|
|
9
9
|
clear: () => void;
|
|
10
10
|
};
|
|
11
11
|
type ResetOptions = {
|
|
12
|
-
isEnabled: () => boolean;
|
|
12
|
+
isEnabled: (ctx: ExtensionContext) => boolean;
|
|
13
13
|
budget: BudgetOwner;
|
|
14
14
|
buildReset: (ctx: ExtensionContext, isCurrent: () => boolean, lastWord: string | undefined, firstSeq: number, origin: ResetOrigin) => SessionBoundaryDraft[] | Promise<SessionBoundaryDraft[]>;
|
|
15
15
|
getLifecycleGeneration?: () => number;
|
|
@@ -174,7 +174,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
174
174
|
const sessionId = ctx.sessionManager.getSessionId();
|
|
175
175
|
const windowId = currentWindowId(ctx);
|
|
176
176
|
const isCurrent = () => sessionActive && lifecycleGeneration === generation &&
|
|
177
|
-
(outerGeneration === undefined || options.getLifecycleGeneration?.() === outerGeneration) && options.isEnabled() &&
|
|
177
|
+
(outerGeneration === undefined || options.getLifecycleGeneration?.() === outerGeneration) && options.isEnabled(ctx) &&
|
|
178
178
|
(preSendHardReserve || ctx.signal?.aborted !== true) && ctx.sessionManager.getSessionId() === sessionId && currentWindowId(ctx) === windowId;
|
|
179
179
|
// The retain-none checkpoint belongs to the old window; capture its successor before notes await.
|
|
180
180
|
const firstSeq = nextHistorySeq(ctx, entries) + 1;
|
|
@@ -203,7 +203,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
203
203
|
return { entries: [...entries, ...allDrafts], continue: finalized.resumeModel };
|
|
204
204
|
};
|
|
205
205
|
pi.on("input", (event, ctx) => {
|
|
206
|
-
if (event.source === "extension" || !sessionActive || !options.isEnabled())
|
|
206
|
+
if (event.source === "extension" || !sessionActive || !options.isEnabled(ctx))
|
|
207
207
|
return undefined;
|
|
208
208
|
const request = control.request;
|
|
209
209
|
if (request.phase !== "pending" || !request.command || request.windowId !== currentWindowId(ctx))
|
|
@@ -235,7 +235,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
235
235
|
const system = getCurrentSystemMessage(event.messages);
|
|
236
236
|
return { messages: system ? [system] : [] };
|
|
237
237
|
}
|
|
238
|
-
if (!options.isEnabled() || ctx.signal?.aborted)
|
|
238
|
+
if (!options.isEnabled(ctx) || ctx.signal?.aborted)
|
|
239
239
|
return undefined;
|
|
240
240
|
if (control.request.phase === "pending" && control.request.command !== undefined)
|
|
241
241
|
return undefined;
|
|
@@ -254,7 +254,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
254
254
|
preSendHardReserveWindowId = undefined;
|
|
255
255
|
const aborted = preSendHardReserve ? false : isAbort(event.message, event.outcome, ctx);
|
|
256
256
|
const stagedBudgetEntries = options.budget.consumeTurnEnd(ctx, event.messageEntryId);
|
|
257
|
-
const budgetEntries = options.isEnabled() && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
|
|
257
|
+
const budgetEntries = options.isEnabled(ctx) && !aborted && event.outcome !== "error" ? stagedBudgetEntries : [];
|
|
258
258
|
const entries = [...(event.entries ?? []), ...budgetEntries];
|
|
259
259
|
const decision = reduceResetControl(control, {
|
|
260
260
|
type: "turn_end",
|
|
@@ -263,7 +263,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
263
263
|
aborted,
|
|
264
264
|
overflow: aborted ? false : isOverflowLike(event.message, ctx),
|
|
265
265
|
failed: event.outcome === "error",
|
|
266
|
-
enabled: options.isEnabled(),
|
|
266
|
+
enabled: options.isEnabled(ctx),
|
|
267
267
|
get queued() { return event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
|
|
268
268
|
get automaticResetEnabled() { return options.budget.automaticResetEnabled(ctx); },
|
|
269
269
|
get hardReserveDue() { return preSendHardReserve || options.budget.hardReserveDue(ctx); },
|
|
@@ -276,7 +276,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
276
276
|
else if (event.outcome === "error" && decision.state.request.phase === "none")
|
|
277
277
|
restoreCommandInputs(true);
|
|
278
278
|
control = decision.state;
|
|
279
|
-
if (!aborted && event.outcome !== "error" && options.isEnabled()) {
|
|
279
|
+
if (!aborted && event.outcome !== "error" && options.isEnabled(ctx)) {
|
|
280
280
|
const marker = buildMarkerDraft(ctx, entries);
|
|
281
281
|
if (marker)
|
|
282
282
|
entries.push(marker);
|
|
@@ -291,7 +291,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
291
291
|
facts: {
|
|
292
292
|
windowId: currentWindowId(ctx),
|
|
293
293
|
get queued() { return event.context.pendingMessages.length > 0 || ctx.hasPendingMessages(); },
|
|
294
|
-
get enabled() { return options.isEnabled(); },
|
|
294
|
+
get enabled() { return options.isEnabled(ctx); },
|
|
295
295
|
get automaticResetEnabled() { return options.budget.automaticResetEnabled(ctx); },
|
|
296
296
|
aborted: event.outcome === "aborted" || ctx.signal?.aborted === true,
|
|
297
297
|
failed: event.outcome === "error",
|
|
@@ -311,8 +311,7 @@ export function registerResetLifecycle(pi, options) {
|
|
|
311
311
|
return undefined;
|
|
312
312
|
if (event.signal.aborted)
|
|
313
313
|
return { cancel: true };
|
|
314
|
-
|
|
315
|
-
if (options.isEnabled() || markerExists) {
|
|
314
|
+
if (options.isEnabled(ctx)) {
|
|
316
315
|
if (event.reason === "manual") {
|
|
317
316
|
ctx.ui.notify("🥣 No compacting brains here · use /fresh-window", "warning");
|
|
318
317
|
}
|