notesoup 0.45.0 → 0.45.2
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/dist/src/boot/text.d.ts +7 -0
- package/dist/src/boot/text.js +7 -0
- package/dist/src/budget/text.d.ts +4 -2
- package/dist/src/budget/text.js +4 -2
- package/dist/src/claude/helper.js +3 -8
- package/dist/src/dsh/engine.d.ts +6 -0
- package/dist/src/dsh/engine.js +34 -1
- package/dist/src/dsh/index.js +1 -1
- package/dist/src/dsh/tools.d.ts +1 -1
- package/dist/src/dsh/tools.js +2 -2
- package/dist/src/dsh/window.d.ts +1 -1
- package/dist/src/dsh/window.js +4 -6
- package/dist/src/notes/index.d.ts +4 -2
- package/dist/src/notes/index.js +4 -1
- package/dist/src/notes/paths.d.ts +0 -1
- package/dist/src/notes/paths.js +0 -1
- package/dist/src/pi/boot.d.ts +0 -5
- package/dist/src/pi/boot.js +4 -30
- package/dist/src/pi/budget.js +3 -3
- package/dist/src/pi/entries.d.ts +1 -0
- package/dist/src/pi/entries.js +1 -0
- package/dist/src/pi/notes/adapter.d.ts +1 -1
- package/dist/src/pi/notes/adapter.js +1 -1
- package/dist/src/pi/reset/artifacts.d.ts +6 -2
- package/dist/src/pi/reset/artifacts.js +14 -3
- package/dist/src/pi/reset/lifecycle.d.ts +6 -2
- package/dist/src/pi/reset/lifecycle.js +28 -18
- package/dist/src/pi/runtime.js +33 -8
- package/dist/src/pi/tool-result.d.ts +9 -0
- package/dist/src/pi/tool-result.js +4 -0
- package/dist/src/tools/notes.d.ts +1 -1
- package/dist/src/tools/notes.js +1 -1
- package/dist/src/tools/output.d.ts +1 -14
- package/dist/src/tools/output.js +1 -9
- package/dist/test/dependencies.test.js +53 -17
- package/dist/test/dsh.test.js +1 -1
- package/dist/test/helpers/dependency-graph.d.ts +3 -3
- package/dist/test/helpers/dependency-graph.js +64 -14
- package/dist/test/helpers/extension.js +2 -2
- package/dist/test/host-neutral.test.js +5 -0
- package/dist/test/notes.integration.test.js +4 -4
- package/dist/test/notes.test.js +1 -1
- package/dist/test/reset-lifecycle.test.js +47 -3
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +166 -166
- package/package.json +1 -1
- package/src/boot/text.ts +8 -0
- package/src/budget/text.ts +5 -2
- package/src/claude/helper.ts +3 -10
- package/src/dsh/engine.ts +27 -1
- package/src/dsh/index.ts +1 -1
- package/src/dsh/tools.ts +2 -3
- package/src/dsh/window.ts +4 -6
- package/src/notes/index.ts +4 -2
- package/src/notes/paths.ts +0 -1
- package/src/pi/boot.ts +4 -33
- package/src/pi/budget.ts +3 -3
- package/src/pi/entries.ts +1 -0
- package/src/pi/notes/adapter.ts +1 -2
- package/src/pi/notes/tools.ts +1 -1
- package/src/pi/reset/artifacts.ts +15 -2
- package/src/pi/reset/lifecycle.ts +34 -21
- package/src/pi/runtime.ts +36 -8
- package/src/pi/tool-result.ts +5 -0
- package/src/tools/notes.ts +1 -1
- package/src/tools/output.ts +1 -10
- package/dist/src/dsh/preflight.d.ts +0 -8
- package/dist/src/dsh/preflight.js +0 -35
- package/dist/src/pi/tool-names.d.ts +0 -7
- package/dist/src/pi/tool-names.js +0 -7
- package/src/dsh/preflight.ts +0 -29
- package/src/pi/tool-names.ts +0 -9
|
@@ -5,10 +5,11 @@ import { join } from "node:path";
|
|
|
5
5
|
import test from "node:test";
|
|
6
6
|
import { SessionManager as Manager } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import notesoup from "../src/pi/extension.js";
|
|
8
|
-
import { BOOT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_MARKER_TYPE } from "../src/pi/entries.js";
|
|
8
|
+
import { BOOT_TYPE, CONTINUATION_TYPE, GUIDANCE_TYPE, RESET_LAST_WORD_TYPE, RESET_MARKER_TYPE } from "../src/pi/entries.js";
|
|
9
9
|
import { MANUAL_WIPE_TYPE } from "../src/pi/entries.js";
|
|
10
10
|
import { toolContext } from "./helpers/extension.js";
|
|
11
11
|
import { WARNING_CONTENT } from "../src/budget/text.js";
|
|
12
|
+
import { MAX_LAST_WORD_CHARS, sanitizeLastWord } from "../src/pi/reset/artifacts.js";
|
|
12
13
|
import { initialResetControl, reduceResetControl, registerResetLifecycle, } from "../src/pi/reset/lifecycle.js";
|
|
13
14
|
const previousNotesHome = process.env.PI_NOTES_HOME;
|
|
14
15
|
const testNotesHome = mkdtempSync(join(tmpdir(), "notesoup-lifecycle-notes-"));
|
|
@@ -72,11 +73,11 @@ function harness() {
|
|
|
72
73
|
});
|
|
73
74
|
await command.handler(args, commandCtx);
|
|
74
75
|
};
|
|
75
|
-
const callTool = async (name) => {
|
|
76
|
+
const callTool = async (name, params = {}) => {
|
|
76
77
|
const tool = tools.get(name);
|
|
77
78
|
assert.ok(tool, `${name} is registered`);
|
|
78
79
|
// Pi 1.0 hands a tool the session context plus the nested-call surface; toolContext builds it.
|
|
79
|
-
return tool.execute("call",
|
|
80
|
+
return tool.execute("call", params, new AbortController().signal, () => { }, toolContext(ctx));
|
|
80
81
|
};
|
|
81
82
|
return { sessionManager, handlers, sent, notices, emit, runCommand, callTool };
|
|
82
83
|
}
|
|
@@ -603,3 +604,46 @@ test("a committed reset places incoming and budget drafts before marker -> boot
|
|
|
603
604
|
CONTINUATION_TYPE,
|
|
604
605
|
], "the persisted reset shape remains marker -> boot -> continuation");
|
|
605
606
|
});
|
|
607
|
+
test("a clear_memory last word lands as a visible entry after the continuation", async () => {
|
|
608
|
+
const h = harness();
|
|
609
|
+
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
610
|
+
await h.callTool("clear_memory", { last_word: "feed the ants" });
|
|
611
|
+
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
612
|
+
const lastWords = boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE);
|
|
613
|
+
assert.equal(lastWords.length, 1, "the boundary persists exactly one parting line");
|
|
614
|
+
assert.deepEqual(lastWords[0], { type: "custom_message", customType: RESET_LAST_WORD_TYPE, content: "feed the ants", display: true });
|
|
615
|
+
const continuationIndex = boundary.entries.findIndex((entry) => entry.type === "custom_message" && entry.customType === CONTINUATION_TYPE);
|
|
616
|
+
assert.ok(boundary.entries.indexOf(lastWords[0]) > continuationIndex, "the parting line follows the continuation");
|
|
617
|
+
});
|
|
618
|
+
test("clear_memory sanitizes the last word: trim, cap, and blank persists no entry", async () => {
|
|
619
|
+
assert.equal(sanitizeLastWord(" hi "), "hi");
|
|
620
|
+
assert.equal(sanitizeLastWord(" "), undefined);
|
|
621
|
+
assert.equal(sanitizeLastWord(undefined), undefined);
|
|
622
|
+
assert.equal(sanitizeLastWord("x".repeat(MAX_LAST_WORD_CHARS + 10))?.length, MAX_LAST_WORD_CHARS + 1, "capped with an ellipsis");
|
|
623
|
+
const h = harness();
|
|
624
|
+
h.sessionManager.appendMessage({ role: "user", content: [{ type: "text", text: "before reset" }], timestamp: Date.now() });
|
|
625
|
+
await h.callTool("clear_memory", { last_word: " " });
|
|
626
|
+
const boundary = resultEntries(await h.emit("turn_end", fakeBoundaryEvent()));
|
|
627
|
+
assert.equal(boundary.entries.filter((entry) => entry.type === "custom_message" && entry.customType === RESET_LAST_WORD_TYPE).length, 0, "a blank last word persists no entry");
|
|
628
|
+
});
|
|
629
|
+
test("reset-control: a tool request carries its last word to the turn-end commit", () => {
|
|
630
|
+
const windowId = "pcw:test:window";
|
|
631
|
+
const armed = reduceResetControl(initialResetControl(), { type: "tool_request", windowId, lastWord: "the shoes were loyal" });
|
|
632
|
+
assert.equal(armed.effect, "close-out-armed");
|
|
633
|
+
assert.deepEqual(armed.state.request, { phase: "tool-requested", windowId, source: "tool", lastWord: "the shoes were loyal" });
|
|
634
|
+
const commit = reduceResetControl(armed.state, { type: "turn_end", facts: turnEndFacts() });
|
|
635
|
+
assert.equal(commit.effect, "commit-boundary");
|
|
636
|
+
assert.equal(commit.lastWord, "the shoes were loyal");
|
|
637
|
+
});
|
|
638
|
+
test("reset-control: a manual close-out adopts the acknowledging call's last word and still stops at settlement", () => {
|
|
639
|
+
const windowId = "pcw:test:window";
|
|
640
|
+
const manual = reduceResetControl(initialResetControl(), { type: "close_out", windowId, source: "manual" });
|
|
641
|
+
const ack = reduceResetControl(manual.state, { type: "tool_request", windowId, lastWord: "tell them I was funny" });
|
|
642
|
+
assert.equal(ack.effect, "already-pending", "the acknowledgement never converts the manual close-out");
|
|
643
|
+
assert.deepEqual(ack.state.request, { phase: "close-out", windowId, source: "manual", lastWord: "tell them I was funny" });
|
|
644
|
+
const silentAck = reduceResetControl(reduceResetControl(initialResetControl(), { type: "close_out", windowId, source: "manual" }).state, { type: "tool_request", windowId });
|
|
645
|
+
assert.deepEqual(silentAck.state.request, { phase: "close-out", windowId, source: "manual" }, "no new key without a last word");
|
|
646
|
+
const commit = reduceResetControl(ack.state, { type: "before_settle", facts: beforeSettleFacts() });
|
|
647
|
+
assert.equal(commit.effect, "commit-boundary-stop");
|
|
648
|
+
assert.equal(commit.lastWord, "tell them I was funny");
|
|
649
|
+
});
|
|
@@ -8010,12 +8010,152 @@ function shown(value) {
|
|
|
8010
8010
|
|
|
8011
8011
|
// src/notes/paths.ts
|
|
8012
8012
|
import { readdir } from "node:fs/promises";
|
|
8013
|
-
import { join
|
|
8013
|
+
import { join } from "node:path";
|
|
8014
|
+
var SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
8015
|
+
function slugify(value) {
|
|
8016
|
+
const slug = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
8017
|
+
return slug.length > 0 ? slug : "root";
|
|
8018
|
+
}
|
|
8019
|
+
function assertVirtualPath(value) {
|
|
8020
|
+
if (typeof value !== "string" || value.length === 0) throw new NoteError("invalid_address", "The address is empty; give the note a path.");
|
|
8021
|
+
if (value.includes("\0") || value.includes("\\") || value.startsWith("/")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't start with "/" or contain "\\" or NUL.`);
|
|
8022
|
+
const parts = value.split("/");
|
|
8023
|
+
if (parts.some((part) => part.length === 0 || part === "." || part === "..")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't have empty, ".", or ".." folder names.`);
|
|
8024
|
+
return value;
|
|
8025
|
+
}
|
|
8026
|
+
function sessionHomesRoot(home) {
|
|
8027
|
+
return join(home, "pi", "session");
|
|
8028
|
+
}
|
|
8029
|
+
function scopeDir(scope, identity2, who) {
|
|
8030
|
+
if (!["session", "project", "human", "agent", "model"].includes(scope)) throw new TypeError("invalid notes scope");
|
|
8031
|
+
if (who !== void 0 && (scope !== "project" && scope !== "agent" && scope !== "model" || !SLUG_PATTERN.test(who))) throw new TypeError("who must be a canonical project/agent/model slug");
|
|
8032
|
+
if (scope === "human") return join(identity2.home, "human");
|
|
8033
|
+
if (scope === "project") return join(identity2.home, "project", who ?? identity2.projectKey);
|
|
8034
|
+
if (scope === "agent") return join(identity2.home, "agents", who ?? identity2.agent);
|
|
8035
|
+
if (scope === "model") return join(identity2.home, "models", who ?? identity2.model);
|
|
8036
|
+
return join(sessionHomesRoot(identity2.home), identity2.sessionId);
|
|
8037
|
+
}
|
|
8038
|
+
async function namespaceSlugs(namespace, home) {
|
|
8039
|
+
try {
|
|
8040
|
+
return (await readdir(join(home, namespace), { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
8041
|
+
} catch (error) {
|
|
8042
|
+
if (error.code === "ENOENT") return [];
|
|
8043
|
+
throw error;
|
|
8044
|
+
}
|
|
8045
|
+
}
|
|
8046
|
+
function noteFileName(vpath) {
|
|
8047
|
+
return vpath.endsWith(".md") ? vpath : `${vpath}.md`;
|
|
8048
|
+
}
|
|
8049
|
+
function physicalPath(scope, vpath, identity2, who) {
|
|
8050
|
+
return join(scopeDir(scope, identity2, who), ...noteFileName(vpath).split("/"));
|
|
8051
|
+
}
|
|
8052
|
+
|
|
8053
|
+
// src/notes/address.ts
|
|
8054
|
+
var ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> reads a named project home.";
|
|
8055
|
+
function globToRegExp(pattern) {
|
|
8056
|
+
let source = "^";
|
|
8057
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
8058
|
+
const char = pattern[index];
|
|
8059
|
+
if (char === "*") {
|
|
8060
|
+
if (pattern[index + 1] === "*") {
|
|
8061
|
+
const followedBySlash = pattern[index + 2] === "/";
|
|
8062
|
+
source += followedBySlash ? "(?:[^]*\\/)?" : "[^]*";
|
|
8063
|
+
index += followedBySlash ? 2 : 1;
|
|
8064
|
+
} else {
|
|
8065
|
+
source += "[^/]*";
|
|
8066
|
+
}
|
|
8067
|
+
} else if (char === "?") {
|
|
8068
|
+
source += "[^/]";
|
|
8069
|
+
} else {
|
|
8070
|
+
source += char.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
8071
|
+
}
|
|
8072
|
+
}
|
|
8073
|
+
return new RegExp(`${source}$`);
|
|
8074
|
+
}
|
|
8075
|
+
function assertGlobPattern(value) {
|
|
8076
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
8077
|
+
if (typeof value !== "string") throw new NoteError("invalid_pattern", `glob ${shown(value)} must be a string.`);
|
|
8078
|
+
if (value.includes("\0") || value.includes("\\")) throw new NoteError("invalid_pattern", `glob ${shown(value)} can't contain "\\" or NUL.`);
|
|
8079
|
+
return value;
|
|
8080
|
+
}
|
|
8081
|
+
function assertAddress(value) {
|
|
8082
|
+
if (typeof value !== "string") throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8083
|
+
let scope = "session";
|
|
8084
|
+
let path = value;
|
|
8085
|
+
let who;
|
|
8086
|
+
if (value.startsWith("@")) {
|
|
8087
|
+
const rest = value.slice(1);
|
|
8088
|
+
const headEnd = rest.indexOf("/");
|
|
8089
|
+
const head = headEnd === -1 ? rest : rest.slice(0, headEnd);
|
|
8090
|
+
const tail = headEnd === -1 ? "" : rest.slice(headEnd + 1);
|
|
8091
|
+
path = tail;
|
|
8092
|
+
if (head === "project") scope = "project";
|
|
8093
|
+
else if (head === "human") scope = "human";
|
|
8094
|
+
else if (head === "self") scope = "agent";
|
|
8095
|
+
else if (head === "model") scope = "model";
|
|
8096
|
+
else if (head === "projects" || head === "agents" || head === "models") {
|
|
8097
|
+
const nameEnd = tail.indexOf("/");
|
|
8098
|
+
who = nameEnd === -1 ? tail : tail.slice(0, nameEnd);
|
|
8099
|
+
if (!SLUG_PATTERN.test(who)) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8100
|
+
scope = head === "projects" ? "project" : head === "agents" ? "agent" : "model";
|
|
8101
|
+
path = nameEnd === -1 ? "" : tail.slice(nameEnd + 1);
|
|
8102
|
+
} else {
|
|
8103
|
+
throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8104
|
+
}
|
|
8105
|
+
if (path === "" && scope !== "agent" && scope !== "model") throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8106
|
+
if (path === "" && who === void 0) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8107
|
+
}
|
|
8108
|
+
if (path.includes("@")) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8109
|
+
assertVirtualPath(path);
|
|
8110
|
+
return { scope, path, who };
|
|
8111
|
+
}
|
|
8112
|
+
function canonicalAddressFor(identity2, scope, path, who) {
|
|
8113
|
+
if (scope === "session") return path;
|
|
8114
|
+
if (scope === "project") return who === void 0 ? `@project/${path}` : `@projects/${who}/${path}`;
|
|
8115
|
+
if (scope === "human") return `@human/${path}`;
|
|
8116
|
+
if (scope === "agent") return `@agents/${who ?? identity2.agent}/${path}`;
|
|
8117
|
+
return `@models/${who ?? identity2.model}/${path}`;
|
|
8118
|
+
}
|
|
8119
|
+
function addressFor(identity2, scope, path, who) {
|
|
8120
|
+
if (scope === "agent" && (who === void 0 || who === identity2.agent)) return `@self/${path}`;
|
|
8121
|
+
if (scope === "model" && (who === void 0 || who === identity2.model)) return `@model/${path}`;
|
|
8122
|
+
return canonicalAddressFor(identity2, scope, path, who);
|
|
8123
|
+
}
|
|
8124
|
+
|
|
8125
|
+
// src/notes/identity.ts
|
|
8126
|
+
import { resolve } from "node:path";
|
|
8127
|
+
function requireString(field, value) {
|
|
8128
|
+
if (typeof value !== "string" || value.length === 0) throw new TypeError(`notes context ${field} must be a non-empty string`);
|
|
8129
|
+
return value;
|
|
8130
|
+
}
|
|
8131
|
+
function assertDirectoryComponent(field, value) {
|
|
8132
|
+
if (value === "." || value === ".." || /[\\/\0:]/.test(value)) {
|
|
8133
|
+
throw new TypeError(`notes context ${field} must be a safe single directory component`);
|
|
8134
|
+
}
|
|
8135
|
+
}
|
|
8136
|
+
function snapshotNotesIdentity(value) {
|
|
8137
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("notes context must be a plain object");
|
|
8138
|
+
const homeValue = requireString("home", value.home);
|
|
8139
|
+
const sessionId = requireString("sessionId", value.sessionId);
|
|
8140
|
+
const projectKey2 = requireString("projectKey", value.projectKey);
|
|
8141
|
+
const agent = requireString("agent", value.agent);
|
|
8142
|
+
const model = requireString("model", value.model);
|
|
8143
|
+
assertDirectoryComponent("sessionId", sessionId);
|
|
8144
|
+
if (!SLUG_PATTERN.test(projectKey2)) throw new TypeError("notes context projectKey must be a canonical lowercase slug");
|
|
8145
|
+
if (!SLUG_PATTERN.test(agent)) throw new TypeError("notes context agent must be a canonical lowercase slug");
|
|
8146
|
+
if (!SLUG_PATTERN.test(model)) throw new TypeError("notes context model must be a canonical lowercase slug");
|
|
8147
|
+
const home = resolve(homeValue);
|
|
8148
|
+
return Object.freeze({ home, sessionId, projectKey: projectKey2, agent, model });
|
|
8149
|
+
}
|
|
8150
|
+
|
|
8151
|
+
// src/notes/constants.ts
|
|
8152
|
+
var MAX_NOTE_BYTES = 1e6;
|
|
8153
|
+
var MAX_NOTE_PATH_BYTES = 512;
|
|
8014
8154
|
|
|
8015
8155
|
// src/notes/project-home.ts
|
|
8016
8156
|
import { randomUUID } from "node:crypto";
|
|
8017
8157
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8018
|
-
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
8158
|
+
import { basename, dirname, join as join2, resolve as resolve2, sep } from "node:path";
|
|
8019
8159
|
function errno(error) {
|
|
8020
8160
|
return typeof error === "object" && error !== null ? error.code : void 0;
|
|
8021
8161
|
}
|
|
@@ -8041,7 +8181,7 @@ function normalizeRemote(value) {
|
|
|
8041
8181
|
return text;
|
|
8042
8182
|
}
|
|
8043
8183
|
function canonicalRoot(cwd) {
|
|
8044
|
-
const absolute =
|
|
8184
|
+
const absolute = resolve2(cwd);
|
|
8045
8185
|
const spelled = gitRoot(absolute) ?? absolute;
|
|
8046
8186
|
try {
|
|
8047
8187
|
return realpathSync(spelled);
|
|
@@ -8050,20 +8190,20 @@ function canonicalRoot(cwd) {
|
|
|
8050
8190
|
}
|
|
8051
8191
|
}
|
|
8052
8192
|
function originRemote(root) {
|
|
8053
|
-
let gitDir =
|
|
8193
|
+
let gitDir = join2(root, ".git");
|
|
8054
8194
|
let raw;
|
|
8055
8195
|
try {
|
|
8056
8196
|
if (!statSync(gitDir).isDirectory()) {
|
|
8057
8197
|
const pointer = /^gitdir:\s*(.+)$/m.exec(readFileSync(gitDir, "utf8"));
|
|
8058
8198
|
if (!pointer) return void 0;
|
|
8059
|
-
gitDir =
|
|
8199
|
+
gitDir = resolve2(root, pointer[1].trim());
|
|
8060
8200
|
}
|
|
8061
8201
|
try {
|
|
8062
|
-
gitDir =
|
|
8202
|
+
gitDir = resolve2(gitDir, readFileSync(join2(gitDir, "commondir"), "utf8").trim());
|
|
8063
8203
|
} catch (error) {
|
|
8064
8204
|
if (errno(error) !== "ENOENT") throw error;
|
|
8065
8205
|
}
|
|
8066
|
-
raw = readFileSync(
|
|
8206
|
+
raw = readFileSync(join2(gitDir, "config"), "utf8");
|
|
8067
8207
|
} catch (error) {
|
|
8068
8208
|
if (errno(error) === "ENOENT") return void 0;
|
|
8069
8209
|
throw error;
|
|
@@ -8086,7 +8226,7 @@ function originRemote(root) {
|
|
|
8086
8226
|
function readMarker(dir) {
|
|
8087
8227
|
let raw;
|
|
8088
8228
|
try {
|
|
8089
|
-
raw = readFileSync(
|
|
8229
|
+
raw = readFileSync(join2(dir, ".project"), "utf8");
|
|
8090
8230
|
} catch (error) {
|
|
8091
8231
|
if (errno(error) === "ENOENT") return void 0;
|
|
8092
8232
|
throw error;
|
|
@@ -8100,7 +8240,7 @@ function readMarker(dir) {
|
|
|
8100
8240
|
}
|
|
8101
8241
|
}
|
|
8102
8242
|
function projectRoot(home) {
|
|
8103
|
-
return
|
|
8243
|
+
return join2(home, "project");
|
|
8104
8244
|
}
|
|
8105
8245
|
function projectHomes(home) {
|
|
8106
8246
|
const root = projectRoot(home);
|
|
@@ -8111,10 +8251,10 @@ function projectHomes(home) {
|
|
|
8111
8251
|
if (errno(error) === "ENOENT") return [];
|
|
8112
8252
|
throw error;
|
|
8113
8253
|
}
|
|
8114
|
-
return entries.filter((entry) => entry.isDirectory()).map((entry) => readMarker(
|
|
8254
|
+
return entries.filter((entry) => entry.isDirectory()).map((entry) => readMarker(join2(root, entry.name))).filter((entry) => entry !== void 0).sort((a, b) => a.name.localeCompare(b.name));
|
|
8115
8255
|
}
|
|
8116
8256
|
function updateMarker(home, marker) {
|
|
8117
|
-
const markerPath =
|
|
8257
|
+
const markerPath = join2(home.dir, ".project");
|
|
8118
8258
|
const temp = `${markerPath}.${process.pid}.${randomUUID()}.tmp`;
|
|
8119
8259
|
try {
|
|
8120
8260
|
writeFileSync(temp, JSON.stringify(marker));
|
|
@@ -8149,10 +8289,10 @@ function resolveProjectHome(cwd, home) {
|
|
|
8149
8289
|
for (let suffix = 0; ; suffix++) {
|
|
8150
8290
|
const name = suffix === 0 ? base : `${base}-${suffix}`;
|
|
8151
8291
|
if (taken.has(name)) continue;
|
|
8152
|
-
const dir =
|
|
8292
|
+
const dir = join2(markerRoot, name);
|
|
8153
8293
|
try {
|
|
8154
8294
|
mkdirSync(dir, { recursive: true });
|
|
8155
|
-
writeFileSync(
|
|
8295
|
+
writeFileSync(join2(dir, ".project"), JSON.stringify({ id, path: root }), { flag: "wx" });
|
|
8156
8296
|
return { name, dir, id, path: root };
|
|
8157
8297
|
} catch (error) {
|
|
8158
8298
|
if (errno(error) === "EEXIST") continue;
|
|
@@ -8161,9 +8301,9 @@ function resolveProjectHome(cwd, home) {
|
|
|
8161
8301
|
}
|
|
8162
8302
|
}
|
|
8163
8303
|
function gitRoot(cwd) {
|
|
8164
|
-
let dir =
|
|
8304
|
+
let dir = resolve2(cwd);
|
|
8165
8305
|
for (; ; ) {
|
|
8166
|
-
if (existsSync(
|
|
8306
|
+
if (existsSync(join2(dir, ".git"))) return repositoryRoot(dir);
|
|
8167
8307
|
const parent = dirname(dir);
|
|
8168
8308
|
if (parent === dir) return void 0;
|
|
8169
8309
|
dir = parent;
|
|
@@ -8172,27 +8312,27 @@ function gitRoot(cwd) {
|
|
|
8172
8312
|
function repositoryRoot(dir) {
|
|
8173
8313
|
let stats;
|
|
8174
8314
|
try {
|
|
8175
|
-
stats = statSync(
|
|
8315
|
+
stats = statSync(join2(dir, ".git"));
|
|
8176
8316
|
} catch {
|
|
8177
8317
|
return dir;
|
|
8178
8318
|
}
|
|
8179
8319
|
if (stats.isDirectory()) return dir;
|
|
8180
8320
|
let pointer;
|
|
8181
8321
|
try {
|
|
8182
|
-
pointer = readFileSync(
|
|
8322
|
+
pointer = readFileSync(join2(dir, ".git"), "utf8");
|
|
8183
8323
|
} catch {
|
|
8184
8324
|
return dir;
|
|
8185
8325
|
}
|
|
8186
8326
|
const match = /^gitdir:\s*(.+)$/m.exec(pointer);
|
|
8187
8327
|
if (!match) return dir;
|
|
8188
|
-
const parts =
|
|
8328
|
+
const parts = resolve2(dir, match[1].trim()).split(sep);
|
|
8189
8329
|
const worktrees = parts.lastIndexOf("worktrees");
|
|
8190
8330
|
if (worktrees <= 0 || worktrees !== parts.length - 2) return dir;
|
|
8191
8331
|
const common = parts.slice(0, worktrees).join(sep);
|
|
8192
8332
|
return basename(common) === ".git" ? dirname(common) : dir;
|
|
8193
8333
|
}
|
|
8194
8334
|
function projectReceipt(home, name) {
|
|
8195
|
-
const project = readMarker(
|
|
8335
|
+
const project = readMarker(join2(projectRoot(home), name));
|
|
8196
8336
|
if (!project) return {};
|
|
8197
8337
|
const base = slugify(basename(project.path));
|
|
8198
8338
|
const siblings = projectHomes(home).filter((candidate) => candidate.name !== name && slugify(basename(candidate.path)) === base);
|
|
@@ -8201,149 +8341,10 @@ function projectReceipt(home, name) {
|
|
|
8201
8341
|
...siblings.length === 0 ? {} : { project_siblings: siblings.map(({ name: name2, path }) => ({ name: name2, path })) }
|
|
8202
8342
|
};
|
|
8203
8343
|
}
|
|
8204
|
-
|
|
8205
|
-
|
|
8206
|
-
var SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
8207
|
-
function slugify(value) {
|
|
8208
|
-
const slug = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
8209
|
-
return slug.length > 0 ? slug : "root";
|
|
8210
|
-
}
|
|
8211
|
-
function assertVirtualPath(value) {
|
|
8212
|
-
if (typeof value !== "string" || value.length === 0) throw new NoteError("invalid_address", "The address is empty; give the note a path.");
|
|
8213
|
-
if (value.includes("\0") || value.includes("\\") || value.startsWith("/")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't start with "/" or contain "\\" or NUL.`);
|
|
8214
|
-
const parts = value.split("/");
|
|
8215
|
-
if (parts.some((part) => part.length === 0 || part === "." || part === "..")) throw new NoteError("invalid_address", `${shown(value)}: a note path can't have empty, ".", or ".." folder names.`);
|
|
8216
|
-
return value;
|
|
8217
|
-
}
|
|
8218
|
-
function sessionHomesRoot(home) {
|
|
8219
|
-
return join2(home, "pi", "session");
|
|
8220
|
-
}
|
|
8221
|
-
function scopeDir(scope, identity2, who) {
|
|
8222
|
-
if (!["session", "project", "human", "agent", "model"].includes(scope)) throw new TypeError("invalid notes scope");
|
|
8223
|
-
if (who !== void 0 && (scope !== "project" && scope !== "agent" && scope !== "model" || !SLUG_PATTERN.test(who))) throw new TypeError("who must be a canonical project/agent/model slug");
|
|
8224
|
-
if (scope === "human") return join2(identity2.home, "human");
|
|
8225
|
-
if (scope === "project") return join2(identity2.home, "project", who ?? identity2.projectKey);
|
|
8226
|
-
if (scope === "agent") return join2(identity2.home, "agents", who ?? identity2.agent);
|
|
8227
|
-
if (scope === "model") return join2(identity2.home, "models", who ?? identity2.model);
|
|
8228
|
-
return join2(sessionHomesRoot(identity2.home), identity2.sessionId);
|
|
8229
|
-
}
|
|
8230
|
-
async function namespaceSlugs(namespace, home) {
|
|
8231
|
-
try {
|
|
8232
|
-
return (await readdir(join2(home, namespace), { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
|
|
8233
|
-
} catch (error) {
|
|
8234
|
-
if (error.code === "ENOENT") return [];
|
|
8235
|
-
throw error;
|
|
8236
|
-
}
|
|
8237
|
-
}
|
|
8238
|
-
function noteFileName(vpath) {
|
|
8239
|
-
return vpath.endsWith(".md") ? vpath : `${vpath}.md`;
|
|
8240
|
-
}
|
|
8241
|
-
function physicalPath(scope, vpath, identity2, who) {
|
|
8242
|
-
return join2(scopeDir(scope, identity2, who), ...noteFileName(vpath).split("/"));
|
|
8344
|
+
function projectKey(cwd, home) {
|
|
8345
|
+
return resolveProjectHome(cwd, home).name;
|
|
8243
8346
|
}
|
|
8244
8347
|
|
|
8245
|
-
// src/notes/address.ts
|
|
8246
|
-
var ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> reads a named project home.";
|
|
8247
|
-
function globToRegExp(pattern) {
|
|
8248
|
-
let source = "^";
|
|
8249
|
-
for (let index = 0; index < pattern.length; index++) {
|
|
8250
|
-
const char = pattern[index];
|
|
8251
|
-
if (char === "*") {
|
|
8252
|
-
if (pattern[index + 1] === "*") {
|
|
8253
|
-
const followedBySlash = pattern[index + 2] === "/";
|
|
8254
|
-
source += followedBySlash ? "(?:[^]*\\/)?" : "[^]*";
|
|
8255
|
-
index += followedBySlash ? 2 : 1;
|
|
8256
|
-
} else {
|
|
8257
|
-
source += "[^/]*";
|
|
8258
|
-
}
|
|
8259
|
-
} else if (char === "?") {
|
|
8260
|
-
source += "[^/]";
|
|
8261
|
-
} else {
|
|
8262
|
-
source += char.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
8263
|
-
}
|
|
8264
|
-
}
|
|
8265
|
-
return new RegExp(`${source}$`);
|
|
8266
|
-
}
|
|
8267
|
-
function assertGlobPattern(value) {
|
|
8268
|
-
if (value === void 0 || value === null || value === "") return void 0;
|
|
8269
|
-
if (typeof value !== "string") throw new NoteError("invalid_pattern", `glob ${shown(value)} must be a string.`);
|
|
8270
|
-
if (value.includes("\0") || value.includes("\\")) throw new NoteError("invalid_pattern", `glob ${shown(value)} can't contain "\\" or NUL.`);
|
|
8271
|
-
return value;
|
|
8272
|
-
}
|
|
8273
|
-
function assertAddress(value) {
|
|
8274
|
-
if (typeof value !== "string") throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8275
|
-
let scope = "session";
|
|
8276
|
-
let path = value;
|
|
8277
|
-
let who;
|
|
8278
|
-
if (value.startsWith("@")) {
|
|
8279
|
-
const rest = value.slice(1);
|
|
8280
|
-
const headEnd = rest.indexOf("/");
|
|
8281
|
-
const head = headEnd === -1 ? rest : rest.slice(0, headEnd);
|
|
8282
|
-
const tail = headEnd === -1 ? "" : rest.slice(headEnd + 1);
|
|
8283
|
-
path = tail;
|
|
8284
|
-
if (head === "project") scope = "project";
|
|
8285
|
-
else if (head === "human") scope = "human";
|
|
8286
|
-
else if (head === "self") scope = "agent";
|
|
8287
|
-
else if (head === "model") scope = "model";
|
|
8288
|
-
else if (head === "projects" || head === "agents" || head === "models") {
|
|
8289
|
-
const nameEnd = tail.indexOf("/");
|
|
8290
|
-
who = nameEnd === -1 ? tail : tail.slice(0, nameEnd);
|
|
8291
|
-
if (!SLUG_PATTERN.test(who)) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8292
|
-
scope = head === "projects" ? "project" : head === "agents" ? "agent" : "model";
|
|
8293
|
-
path = nameEnd === -1 ? "" : tail.slice(nameEnd + 1);
|
|
8294
|
-
} else {
|
|
8295
|
-
throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8296
|
-
}
|
|
8297
|
-
if (path === "" && scope !== "agent" && scope !== "model") throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8298
|
-
if (path === "" && who === void 0) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8299
|
-
}
|
|
8300
|
-
if (path.includes("@")) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
8301
|
-
assertVirtualPath(path);
|
|
8302
|
-
return { scope, path, who };
|
|
8303
|
-
}
|
|
8304
|
-
function canonicalAddressFor(identity2, scope, path, who) {
|
|
8305
|
-
if (scope === "session") return path;
|
|
8306
|
-
if (scope === "project") return who === void 0 ? `@project/${path}` : `@projects/${who}/${path}`;
|
|
8307
|
-
if (scope === "human") return `@human/${path}`;
|
|
8308
|
-
if (scope === "agent") return `@agents/${who ?? identity2.agent}/${path}`;
|
|
8309
|
-
return `@models/${who ?? identity2.model}/${path}`;
|
|
8310
|
-
}
|
|
8311
|
-
function addressFor(identity2, scope, path, who) {
|
|
8312
|
-
if (scope === "agent" && (who === void 0 || who === identity2.agent)) return `@self/${path}`;
|
|
8313
|
-
if (scope === "model" && (who === void 0 || who === identity2.model)) return `@model/${path}`;
|
|
8314
|
-
return canonicalAddressFor(identity2, scope, path, who);
|
|
8315
|
-
}
|
|
8316
|
-
|
|
8317
|
-
// src/notes/identity.ts
|
|
8318
|
-
import { resolve as resolve2 } from "node:path";
|
|
8319
|
-
function requireString(field, value) {
|
|
8320
|
-
if (typeof value !== "string" || value.length === 0) throw new TypeError(`notes context ${field} must be a non-empty string`);
|
|
8321
|
-
return value;
|
|
8322
|
-
}
|
|
8323
|
-
function assertDirectoryComponent(field, value) {
|
|
8324
|
-
if (value === "." || value === ".." || /[\\/\0:]/.test(value)) {
|
|
8325
|
-
throw new TypeError(`notes context ${field} must be a safe single directory component`);
|
|
8326
|
-
}
|
|
8327
|
-
}
|
|
8328
|
-
function snapshotNotesIdentity(value) {
|
|
8329
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError("notes context must be a plain object");
|
|
8330
|
-
const homeValue = requireString("home", value.home);
|
|
8331
|
-
const sessionId = requireString("sessionId", value.sessionId);
|
|
8332
|
-
const projectKey2 = requireString("projectKey", value.projectKey);
|
|
8333
|
-
const agent = requireString("agent", value.agent);
|
|
8334
|
-
const model = requireString("model", value.model);
|
|
8335
|
-
assertDirectoryComponent("sessionId", sessionId);
|
|
8336
|
-
if (!SLUG_PATTERN.test(projectKey2)) throw new TypeError("notes context projectKey must be a canonical lowercase slug");
|
|
8337
|
-
if (!SLUG_PATTERN.test(agent)) throw new TypeError("notes context agent must be a canonical lowercase slug");
|
|
8338
|
-
if (!SLUG_PATTERN.test(model)) throw new TypeError("notes context model must be a canonical lowercase slug");
|
|
8339
|
-
const home = resolve2(homeValue);
|
|
8340
|
-
return Object.freeze({ home, sessionId, projectKey: projectKey2, agent, model });
|
|
8341
|
-
}
|
|
8342
|
-
|
|
8343
|
-
// src/notes/constants.ts
|
|
8344
|
-
var MAX_NOTE_BYTES = 1e6;
|
|
8345
|
-
var MAX_NOTE_PATH_BYTES = 512;
|
|
8346
|
-
|
|
8347
8348
|
// src/notes/store.ts
|
|
8348
8349
|
var lastWriteStamp = 0;
|
|
8349
8350
|
function writeStamp() {
|
|
@@ -9060,7 +9061,7 @@ var notesUpdate = {
|
|
|
9060
9061
|
parameters: notesUpdateParameters,
|
|
9061
9062
|
outputSchema: resultSchema(NotesUpdateDataSchema),
|
|
9062
9063
|
executionMode: "sequential",
|
|
9063
|
-
async execute(params, identity2, renderDiff) {
|
|
9064
|
+
async execute(params, identity2, renderDiff = (change) => change.kind === "none" ? "" : `note ${change.kind}`) {
|
|
9064
9065
|
try {
|
|
9065
9066
|
const store = createNotesStore(identity2);
|
|
9066
9067
|
const renameTo = params.rename_to === "" ? void 0 : params.rename_to;
|
|
@@ -9346,8 +9347,10 @@ var CONTINUATION = "WIPED! Your whole brain, poof! Who? No idea! Definitely not
|
|
|
9346
9347
|
var WARNING_BODY = "This context window will be cleared soon. Notes and history persist; anything else is lost.\nConsider whether to record in your notes:\n- what you are working on, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where unfinished work is located (branches, scratch directories, uncommitted changes)\n- approaches that failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
|
|
9347
9348
|
var WARNING_PROMPT = `${WARNING_BODY}
|
|
9348
9349
|
When the notes are ready, call \`clear_memory\` to reset now instead of being cut off mid-task.`;
|
|
9350
|
+
var LAST_WORD_HINT = "If you want, pass `clear_memory` a `last_word`: one short line left visible where this window closes.";
|
|
9349
9351
|
var WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}
|
|
9350
9352
|
${WARNING_PROMPT}
|
|
9353
|
+
${LAST_WORD_HINT}
|
|
9351
9354
|
${GUIDANCE_CLOSE_TAG}`;
|
|
9352
9355
|
var CLAUDE_WARNING_PROMPT = `${WARNING_BODY}
|
|
9353
9356
|
When the notes are ready, end your turn; the reset runs after it.`;
|
|
@@ -9491,7 +9494,7 @@ var MAX_RESPONSE_BYTES = 1024 * 1024;
|
|
|
9491
9494
|
var TOOL_NAMES = ["notes_write", "notes_update", "notes_read", "notes_list", "notes_search"];
|
|
9492
9495
|
function identity(input) {
|
|
9493
9496
|
if (!input || typeof input !== "object" || typeof input.cwd !== "string") throw new Error("invalid identity");
|
|
9494
|
-
return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey:
|
|
9497
|
+
return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey: projectKey(input.cwd, input.home), agent: input.agent, model: input.model });
|
|
9495
9498
|
}
|
|
9496
9499
|
function paramProblem(schema, params) {
|
|
9497
9500
|
const first = Errors2(schema, params).find((error) => error.keyword !== "boolean");
|
|
@@ -9511,12 +9514,9 @@ function boundOperation(operation, ...rest) {
|
|
|
9511
9514
|
}
|
|
9512
9515
|
};
|
|
9513
9516
|
}
|
|
9514
|
-
function claudeDiff(change) {
|
|
9515
|
-
return change.kind === "none" ? "" : `note ${change.kind}`;
|
|
9516
|
-
}
|
|
9517
9517
|
var OPERATIONS = {
|
|
9518
9518
|
notes_write: boundOperation(notesWrite),
|
|
9519
|
-
notes_update: boundOperation(notesUpdate
|
|
9519
|
+
notes_update: boundOperation(notesUpdate),
|
|
9520
9520
|
notes_read: boundOperation(notesRead),
|
|
9521
9521
|
notes_list: boundOperation(notesList),
|
|
9522
9522
|
notes_search: boundOperation(notesSearch)
|
package/package.json
CHANGED
package/src/boot/text.ts
CHANGED
|
@@ -69,6 +69,14 @@ export type BootToolNames = Readonly<{
|
|
|
69
69
|
wipeSentence?: string;
|
|
70
70
|
}>;
|
|
71
71
|
|
|
72
|
+
export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
73
|
+
notes: "notes_*",
|
|
74
|
+
notesList: "notes_list",
|
|
75
|
+
history: "history_*",
|
|
76
|
+
remaining: "get_context_remaining",
|
|
77
|
+
wipe: "clear_memory",
|
|
78
|
+
} as const satisfies BootToolNames;
|
|
79
|
+
|
|
72
80
|
export function renderProtocolBlock(tools: BootToolNames): string {
|
|
73
81
|
const names: Record<string, string> = {
|
|
74
82
|
"notes_*": tools.notes,
|
package/src/budget/text.ts
CHANGED
|
@@ -15,8 +15,11 @@ export const WARNING_BODY =
|
|
|
15
15
|
|
|
16
16
|
export const WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, call \`clear_memory\` to reset now instead of being cut off mid-task.`;
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
export const
|
|
18
|
+
/** Pi-only nudge: pi's clear_memory persists a parting line; the dsh tool has no such parameter. */
|
|
19
|
+
export const LAST_WORD_HINT = "If you want, pass `clear_memory` a `last_word`: one short line left visible where this window closes.";
|
|
20
|
+
|
|
21
|
+
/** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads WARNING_PROMPT directly). */
|
|
22
|
+
export const WARNING_CONTENT = `${GUIDANCE_OPEN_TAG}\n${WARNING_PROMPT}\n${LAST_WORD_HINT}\n${GUIDANCE_CLOSE_TAG}`;
|
|
20
23
|
|
|
21
24
|
/** Claude's variant: the mod resets after the turn, so the model only has to stop. */
|
|
22
25
|
export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.`;
|
package/src/claude/helper.ts
CHANGED
|
@@ -8,9 +8,7 @@ import { renderBootBlock } from "../boot/render.js";
|
|
|
8
8
|
import { CLAUDE_WIPE_SENTENCE, type BootToolNames } from "../boot/text.js";
|
|
9
9
|
import { CLAUDE_WARNING_PROMPT, CONTINUATION } from "../budget/text.js";
|
|
10
10
|
import { resolveClaudeLimits } from "./thresholds.js";
|
|
11
|
-
import {
|
|
12
|
-
import { snapshotNotesIdentity, type NotesIdentity } from "../notes/identity.js";
|
|
13
|
-
import type { NoteChange } from "../notes/store.js";
|
|
11
|
+
import { projectKey, snapshotNotesIdentity, type NotesIdentity } from "../notes/index.js";
|
|
14
12
|
import type { Operation, Outcome } from "../tools/result.js";
|
|
15
13
|
|
|
16
14
|
const MAX_REQUEST_BYTES = 512 * 1024;
|
|
@@ -28,7 +26,7 @@ type BoundOperation = {
|
|
|
28
26
|
|
|
29
27
|
function identity(input: ClaudeIdentityInput): NotesIdentity {
|
|
30
28
|
if (!input || typeof input !== "object" || typeof input.cwd !== "string") throw new Error("invalid identity");
|
|
31
|
-
return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey:
|
|
29
|
+
return snapshotNotesIdentity({ home: input.home, sessionId: input.sessionId, projectKey: projectKey(input.cwd, input.home), agent: input.agent, model: input.model });
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
/** The first schema violation, named by parameter so the model can fix that one field. */
|
|
@@ -59,14 +57,9 @@ function boundOperation<TParams extends TSchema, TData, TRest extends readonly u
|
|
|
59
57
|
};
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
/** Claude has no diff renderer, so an update receipt names the change kind instead of a diff. */
|
|
63
|
-
function claudeDiff(change: NoteChange): string {
|
|
64
|
-
return change.kind === "none" ? "" : `note ${change.kind}`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
60
|
const OPERATIONS: Record<ClaudeToolName, BoundOperation> = {
|
|
68
61
|
notes_write: boundOperation(notesWrite),
|
|
69
|
-
notes_update: boundOperation(notesUpdate
|
|
62
|
+
notes_update: boundOperation(notesUpdate),
|
|
70
63
|
notes_read: boundOperation(notesRead),
|
|
71
64
|
notes_list: boundOperation(notesList),
|
|
72
65
|
notes_search: boundOperation(notesSearch),
|