notesoup 0.61.0 → 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 -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 +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.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 +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/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 +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 +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 +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 +3 -3
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +4 -4
- 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 +1059 -534
- package/plugins/claude/hooks/register.ts +2 -2
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- 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 +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 +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 +1 -1
- package/skills/notesoup/SKILL.md +92 -0
- package/src/boot/render.ts +18 -15
- package/src/boot/text.ts +23 -19
- 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/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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { runToolServer } from "../../mcp/server.js";
|
|
2
|
+
import { createNoteTools } from "../../mcp/operations.js";
|
|
3
|
+
import { preInvocation } from "./hooks.js";
|
|
4
|
+
import { resolveContext } from "./identity.js";
|
|
5
|
+
|
|
6
|
+
async function main(): Promise<void> {
|
|
7
|
+
if (process.argv[2] === "mcp") {
|
|
8
|
+
await runToolServer({ name: "notesoup", ...createNoteTools(meta => resolveContext(meta)) });
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (process.argv[2] !== "pre-invocation") throw new Error("Expected mcp or pre-invocation.");
|
|
12
|
+
let raw = "";
|
|
13
|
+
for await (const chunk of process.stdin) {
|
|
14
|
+
raw += chunk;
|
|
15
|
+
if (Buffer.byteLength(raw) > 1024 * 1024) throw new Error("Hook input exceeds 1 MiB.");
|
|
16
|
+
}
|
|
17
|
+
const value: unknown = JSON.parse(raw);
|
|
18
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("Expected a hook object.");
|
|
19
|
+
process.stdout.write(JSON.stringify(await preInvocation(value as Record<string, unknown>)) + "\n");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
main().catch(error => { process.stderr.write(`notesoup: ${error instanceof Error ? error.message : String(error)}\n`); process.exitCode = 1; });
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { renderBootContext } from "../../../src/boot/render.js";
|
|
2
|
+
import { loadNotesSnapshot } from "../../../src/boot/snapshot.js";
|
|
3
|
+
import { DEFAULT_BOOT_TOOL_NAMES, MAPS_BLOCK, renderProtocolBlock } from "../../../src/boot/text.js";
|
|
4
|
+
import { AntigravityIdentityError, bindingFromHook, contextForBinding, invalidateBinding, readBinding, writeBinding, type ConversationBinding } from "./identity.js";
|
|
5
|
+
|
|
6
|
+
const TOOLS = {
|
|
7
|
+
...DEFAULT_BOOT_TOOL_NAMES,
|
|
8
|
+
historySentence: "Notesoup has no Antigravity history tool. Record important details in notes rather than relying on a Notesoup history index.",
|
|
9
|
+
budgetParagraph: "Notesoup has no Antigravity context-budget or reset tool. The host manages its own conversation context; this plugin does not promise recovery after native context compaction.",
|
|
10
|
+
};
|
|
11
|
+
const MAX_BOOT_BYTES = 128 * 1024;
|
|
12
|
+
|
|
13
|
+
type InjectedStep = { systemMessage: { systemMessage: string } } | { userMessage: string } | { errorMessage: { userMessage: string } };
|
|
14
|
+
type HookOutput = { injectSteps?: InjectedStep[]; terminationBehavior?: "terminate" };
|
|
15
|
+
function inject(message: string): HookOutput { return { injectSteps: [{ systemMessage: { systemMessage: message } }] }; }
|
|
16
|
+
|
|
17
|
+
/** PreInvocation is the host's model boundary, for both a new conversation and subsequent invocations. */
|
|
18
|
+
export async function preInvocation(payload: Record<string, unknown>, env: NodeJS.ProcessEnv = process.env): Promise<HookOutput> {
|
|
19
|
+
let binding: ConversationBinding;
|
|
20
|
+
try {
|
|
21
|
+
if (payload.hookEventName !== "PreInvocation") throw new Error("Unexpected hook event.");
|
|
22
|
+
binding = bindingFromHook(payload, env);
|
|
23
|
+
const existing = await readBinding(env, binding.conversationId);
|
|
24
|
+
if (existing && ((existing.rootConversationId !== undefined && binding.rootConversationId !== undefined && existing.rootConversationId !== binding.rootConversationId) || (existing.parentConversationId !== undefined && binding.parentConversationId !== undefined && existing.parentConversationId !== binding.parentConversationId))) throw new Error("Conversation ancestry changed; refusing to overwrite an existing binding.");
|
|
25
|
+
// Retain known ancestry through later hooks that omit these optional fields.
|
|
26
|
+
binding = { ...binding, bootEmitted: existing?.bootEmitted ?? false, ...(existing?.rootConversationId === undefined ? {} : { rootConversationId: existing.rootConversationId }), ...(existing?.parentConversationId === undefined ? {} : { parentConversationId: existing.parentConversationId }) };
|
|
27
|
+
await writeBinding(env, binding);
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (!(error instanceof AntigravityIdentityError && error.code === "mismatched_home")) await invalidateBinding(env, payload.conversationId).catch(() => {});
|
|
30
|
+
// Never let a failed identity refresh continue the invocation with an older model/cwd.
|
|
31
|
+
return { injectSteps: [{ errorMessage: { userMessage: `Notesoup: could not establish this invocation (${error instanceof Error ? error.message : String(error)}).` } }], terminationBehavior: "terminate" };
|
|
32
|
+
}
|
|
33
|
+
// The first PreInvocation is a model boundary for both root and child conversations.
|
|
34
|
+
if (binding.bootEmitted) return {};
|
|
35
|
+
try {
|
|
36
|
+
const { identity } = contextForBinding(binding);
|
|
37
|
+
const notes = await loadNotesSnapshot(identity, Date.now());
|
|
38
|
+
const protocol = `${renderProtocolBlock(TOOLS, identity.agent)}\n\n${MAPS_BLOCK}`;
|
|
39
|
+
const boot = renderBootContext({
|
|
40
|
+
agentName: identity.agent, modelName: binding.model, notes, tools: TOOLS,
|
|
41
|
+
tree: { trunk: `Antigravity conversation ${binding.conversationId}`, windows: [{ shortName: "conversation", isCurrent: true }] },
|
|
42
|
+
});
|
|
43
|
+
if (Buffer.byteLength(protocol + boot, "utf8") > MAX_BOOT_BYTES) throw new Error("Boot exceeds 128 KiB; slim the pinned notes. No partial boot was injected.");
|
|
44
|
+
await writeBinding(env, { ...binding, bootEmitted: true });
|
|
45
|
+
return { injectSteps: [{ systemMessage: { systemMessage: protocol } }, { userMessage: boot }] };
|
|
46
|
+
} catch (error) {
|
|
47
|
+
// Do not place diagnostics derived from note contents into a trusted message.
|
|
48
|
+
process.stderr.write(`notesoup: boot failed: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
49
|
+
return inject("Notesoup: could not render the notes boot. No partial boot was injected; use notes_list to inspect the library.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
5
|
+
import { projectKey, slugify, snapshotNotesIdentity } from "../../../src/notes/index.js";
|
|
6
|
+
import { NAMELESS_AGENT } from "../../../src/boot/text.js";
|
|
7
|
+
import { notesToolContext, type NotesToolContext } from "../../../src/tools/notes-context.js";
|
|
8
|
+
|
|
9
|
+
const PREFIX = "antigravity.google/";
|
|
10
|
+
const UUID = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i;
|
|
11
|
+
|
|
12
|
+
export class AntigravityIdentityError extends Error {
|
|
13
|
+
constructor(readonly code: string, message: string) { super(message); }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function text(value: unknown): string | undefined {
|
|
17
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function conversationId(value: unknown): string {
|
|
21
|
+
if (typeof value !== "string" || !UUID.test(value)) throw new AntigravityIdentityError("invalid_conversation", "Antigravity did not supply a valid native conversation ID.");
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function modelName(value: unknown): string {
|
|
26
|
+
const id = text(value)?.split("/").pop();
|
|
27
|
+
if (!id || !/[a-z0-9]/i.test(id) || /^(?:auto|default)$/i.test(id)) throw new AntigravityIdentityError("missing_model", "The Antigravity hook did not name a concrete model; select a specific model before using Notesoup.");
|
|
28
|
+
return slugify(id);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function absolute(value: unknown, field: string): string {
|
|
32
|
+
if (typeof value !== "string" || !isAbsolute(value) || value.includes("\0")) throw new AntigravityIdentityError("invalid_identity", `Antigravity ${field} is not an absolute path.`);
|
|
33
|
+
return resolve(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function notesHome(env: NodeJS.ProcessEnv): string {
|
|
37
|
+
return env.NOTESOUP_HOME === undefined ? join(homedir(), ".agents", "notes") : absolute(env.NOTESOUP_HOME, "NOTESOUP_HOME");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type ConversationBinding = Readonly<{
|
|
41
|
+
conversationId: string;
|
|
42
|
+
rootConversationId?: string;
|
|
43
|
+
parentConversationId?: string;
|
|
44
|
+
cwd: string;
|
|
45
|
+
model: string;
|
|
46
|
+
/** Absent in many native hooks, including 1.5.17's dynamically defined subagents. */
|
|
47
|
+
agent?: string;
|
|
48
|
+
home: string;
|
|
49
|
+
bootEmitted: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
|
|
52
|
+
export function bindingFromHook(payload: Record<string, unknown>, env: NodeJS.ProcessEnv): ConversationBinding {
|
|
53
|
+
const id = conversationId(payload.conversationId);
|
|
54
|
+
const parent = text(payload.parentConversationId);
|
|
55
|
+
const root = text(payload.rootConversationId);
|
|
56
|
+
if (parent !== undefined) conversationId(parent);
|
|
57
|
+
if (root !== undefined) conversationId(root);
|
|
58
|
+
if (parent === id || (root === id && parent !== undefined)) throw new AntigravityIdentityError("invalid_identity", "The Antigravity hook's conversation ancestry is inconsistent.");
|
|
59
|
+
const agent = text(payload.agentName);
|
|
60
|
+
return {
|
|
61
|
+
conversationId: id, ...(root === undefined ? {} : { rootConversationId: root }), ...(parent === undefined ? {} : { parentConversationId: parent }),
|
|
62
|
+
cwd: absolute(payload.cwd, "hook cwd"), model: modelName(payload.modelName),
|
|
63
|
+
...(agent === undefined ? {} : { agent: slugify(agent) }), home: notesHome(env), bootEmitted: false,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function bindingPath(env: NodeJS.ProcessEnv, id: string): string {
|
|
68
|
+
return join(absolute(env.PLUGIN_DATA, "PLUGIN_DATA"), "conversations", `${conversationId(id)}.json`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function contextForBinding(binding: ConversationBinding, agent = binding.agent ?? NAMELESS_AGENT): NotesToolContext {
|
|
72
|
+
return notesToolContext(snapshotNotesIdentity({
|
|
73
|
+
home: binding.home, sessionId: binding.conversationId, projectKey: projectKey(binding.cwd, binding.home),
|
|
74
|
+
agent, model: binding.model,
|
|
75
|
+
}), binding.cwd);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export async function readBinding(env: NodeJS.ProcessEnv, id: string): Promise<ConversationBinding | undefined> {
|
|
79
|
+
let content: string;
|
|
80
|
+
try { content = await readFile(bindingPath(env, id), "utf8"); }
|
|
81
|
+
catch (error) {
|
|
82
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return undefined;
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
const row: ConversationBinding = JSON.parse(content);
|
|
86
|
+
if (!row || row.conversationId !== id || typeof row.bootEmitted !== "boolean" || typeof row.model !== "string" || slugify(row.model) !== row.model ||
|
|
87
|
+
(row.agent !== undefined && (typeof row.agent !== "string" || slugify(row.agent) !== row.agent))) throw new AntigravityIdentityError("invalid_binding", "Antigravity's saved conversation binding is invalid.");
|
|
88
|
+
if (row.rootConversationId !== undefined) conversationId(row.rootConversationId);
|
|
89
|
+
if (row.parentConversationId !== undefined) conversationId(row.parentConversationId);
|
|
90
|
+
if (row.parentConversationId === id || (row.rootConversationId === id && row.parentConversationId !== undefined)) throw new AntigravityIdentityError("invalid_binding", "Antigravity's saved conversation ancestry is inconsistent.");
|
|
91
|
+
absolute(row.cwd, "saved cwd");
|
|
92
|
+
if (absolute(row.home, "saved notes home") !== notesHome(env)) throw new AntigravityIdentityError("mismatched_home", "The conversation binding belongs to another NOTESOUP_HOME. Start a new conversation with the intended home.");
|
|
93
|
+
return row;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function writeBinding(env: NodeJS.ProcessEnv, binding: ConversationBinding): Promise<void> {
|
|
97
|
+
const path = bindingPath(env, binding.conversationId);
|
|
98
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
99
|
+
const temp = `${path}.${randomUUID()}.tmp`;
|
|
100
|
+
try {
|
|
101
|
+
await writeFile(temp, `${JSON.stringify(binding)}\n`, { mode: 0o600 });
|
|
102
|
+
await rename(temp, path);
|
|
103
|
+
} finally { await unlink(temp).catch(() => {}); }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** A hook lacking current model/cwd facts must not leave a usable older binding. */
|
|
107
|
+
export async function invalidateBinding(env: NodeJS.ProcessEnv, id: unknown): Promise<void> {
|
|
108
|
+
try { await unlink(bindingPath(env, conversationId(id))); }
|
|
109
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error; }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Never fall back to root ID, MCP process cwd, a previous call, or model-supplied arguments. */
|
|
113
|
+
export async function resolveContext(meta: Record<string, unknown>, env: NodeJS.ProcessEnv = process.env): Promise<NotesToolContext> {
|
|
114
|
+
const id = conversationId(meta[`${PREFIX}conversation_id`]);
|
|
115
|
+
const root = conversationId(meta[`${PREFIX}root_conversation_id`]);
|
|
116
|
+
const binding = await readBinding(env, id);
|
|
117
|
+
if (!binding) throw new AntigravityIdentityError("unknown_conversation", "No Notesoup hook binding exists for this Antigravity conversation. Enable the plugin hooks and start a model invocation in this conversation.");
|
|
118
|
+
const parent = text(meta[`${PREFIX}parent_conversation_id`]);
|
|
119
|
+
const agent = text(meta[`${PREFIX}agent_name`]);
|
|
120
|
+
if (parent !== undefined) conversationId(parent);
|
|
121
|
+
if ((binding.rootConversationId !== undefined && binding.rootConversationId !== root) ||
|
|
122
|
+
(binding.parentConversationId !== undefined && parent !== undefined && parent !== binding.parentConversationId) ||
|
|
123
|
+
(binding.agent !== undefined && agent !== undefined && slugify(agent) !== binding.agent) || parent === id || (parent !== undefined && root === id)) {
|
|
124
|
+
throw new AntigravityIdentityError("mismatched_conversation", "The Antigravity call disagrees with its own hook identity; no notes were accessed.");
|
|
125
|
+
}
|
|
126
|
+
return contextForBinding(binding, agent === undefined ? binding.agent : slugify(agent));
|
|
127
|
+
}
|