notesoup 0.43.0 → 0.44.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/dist/src/boot/snapshot.d.ts +2 -0
- package/dist/src/boot/snapshot.js +4 -0
- package/dist/src/boot/text.js +3 -1
- package/dist/src/claude/helper.js +2 -2
- package/dist/src/notes/address.d.ts +2 -2
- package/dist/src/notes/address.js +5 -5
- package/dist/src/notes/identity.js +2 -1
- package/dist/src/notes/paths.d.ts +1 -6
- package/dist/src/notes/paths.js +5 -68
- package/dist/src/notes/project-home.d.ts +25 -0
- package/dist/src/notes/project-home.js +231 -0
- package/dist/src/notes/store.d.ts +3 -2
- package/dist/src/notes/store.js +14 -8
- package/dist/src/pi/boot.js +17 -5
- package/dist/src/pi/notes/adapter.js +1 -1
- package/dist/src/tools/notes.d.ts +47 -17
- package/dist/src/tools/notes.js +15 -4
- package/dist/test/claude-mod.test.js +32 -1
- package/dist/test/notes.test.js +22 -19
- package/dist/test/project-home.test.d.ts +1 -0
- package/dist/test/project-home.test.js +134 -0
- package/mods/notesoup/.claude-plugin/plugin.json +1 -1
- package/mods/notesoup/dist/claude/helper.js +223 -56
- package/mods/notesoup/skills/memory/SKILL.md +1 -0
- package/package.json +1 -1
- package/skills/memory/SKILL.md +1 -0
- package/src/boot/snapshot.ts +5 -0
- package/src/boot/text.ts +3 -1
- package/src/claude/helper.ts +2 -2
- package/src/notes/address.ts +5 -5
- package/src/notes/identity.ts +1 -1
- package/src/notes/paths.ts +4 -60
- package/src/notes/project-home.ts +197 -0
- package/src/notes/store.ts +13 -9
- package/src/pi/boot.ts +15 -5
- package/src/pi/notes/adapter.ts +1 -1
- package/src/tools/notes.ts +16 -6
|
@@ -29,8 +29,6 @@ export declare const NotesReadDataSchema: Type.TObject<{
|
|
|
29
29
|
text: Type.TString;
|
|
30
30
|
total_chars: Type.TInteger;
|
|
31
31
|
next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
32
|
-
address: Type.TString;
|
|
33
|
-
project_key: Type.TOptional<Type.TString>;
|
|
34
32
|
metadata: Type.TObject<{
|
|
35
33
|
origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
|
|
36
34
|
created_at: Type.TString;
|
|
@@ -39,16 +37,28 @@ export declare const NotesReadDataSchema: Type.TObject<{
|
|
|
39
37
|
project: Type.TOptional<Type.TString>;
|
|
40
38
|
extra: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
41
39
|
}>;
|
|
40
|
+
project_root: Type.TOptional<Type.TString>;
|
|
41
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
42
|
+
name: Type.TString;
|
|
43
|
+
path: Type.TString;
|
|
44
|
+
}>>>;
|
|
45
|
+
address: Type.TString;
|
|
46
|
+
project_key: Type.TOptional<Type.TString>;
|
|
42
47
|
}>;
|
|
43
48
|
export type NotesReadData = Static<typeof NotesReadDataSchema>;
|
|
44
49
|
export declare const NotesListDataSchema: Type.TObject<{
|
|
45
50
|
more: Type.TInteger;
|
|
46
51
|
homes_unavailable: Type.TArray<Type.TString>;
|
|
47
52
|
files: Type.TArray<Type.TObject<{
|
|
48
|
-
address: Type.TString;
|
|
49
|
-
project_key: Type.TOptional<Type.TString>;
|
|
50
53
|
updated_at: Type.TString;
|
|
51
54
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
55
|
+
project_root: Type.TOptional<Type.TString>;
|
|
56
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
57
|
+
name: Type.TString;
|
|
58
|
+
path: Type.TString;
|
|
59
|
+
}>>>;
|
|
60
|
+
address: Type.TString;
|
|
61
|
+
project_key: Type.TOptional<Type.TString>;
|
|
52
62
|
}>>;
|
|
53
63
|
}>;
|
|
54
64
|
export type NotesListData = Static<typeof NotesListDataSchema>;
|
|
@@ -61,10 +71,15 @@ export declare const NotesSearchDataSchema: Type.TObject<{
|
|
|
61
71
|
text: Type.TString;
|
|
62
72
|
offset_chars: Type.TInteger;
|
|
63
73
|
}>>;
|
|
64
|
-
address: Type.TString;
|
|
65
|
-
project_key: Type.TOptional<Type.TString>;
|
|
66
74
|
updated_at: Type.TString;
|
|
67
75
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
76
|
+
project_root: Type.TOptional<Type.TString>;
|
|
77
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
78
|
+
name: Type.TString;
|
|
79
|
+
path: Type.TString;
|
|
80
|
+
}>>>;
|
|
81
|
+
address: Type.TString;
|
|
82
|
+
project_key: Type.TOptional<Type.TString>;
|
|
68
83
|
}>>;
|
|
69
84
|
}>;
|
|
70
85
|
export type NotesSearchData = Static<typeof NotesSearchDataSchema>;
|
|
@@ -76,7 +91,7 @@ export declare const notesWriteParameters: Type.TObject<{
|
|
|
76
91
|
export declare const notesWrite: {
|
|
77
92
|
readonly name: "notes_write";
|
|
78
93
|
readonly label: "Notes write";
|
|
79
|
-
readonly description: "Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
94
|
+
readonly description: "Create or replace a note. Name it for what it holds and when to use it. Store what git and history can't recover. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
|
|
80
95
|
readonly parameters: Type.TObject<{
|
|
81
96
|
address: Type.TString;
|
|
82
97
|
content: Type.TString;
|
|
@@ -111,7 +126,7 @@ export declare const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
|
|
|
111
126
|
export declare const notesUpdate: {
|
|
112
127
|
readonly name: "notes_update";
|
|
113
128
|
readonly label: "Notes update";
|
|
114
|
-
readonly description: "Edit a note, change its origin or crumpled state, or move it. Each `oldText` must match exactly once unless `replace_all` is true. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
129
|
+
readonly description: "Edit a note, change its origin or crumpled state, or move it. Each `oldText` must match exactly once unless `replace_all` is true. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
|
|
115
130
|
readonly parameters: Type.TObject<{
|
|
116
131
|
address: Type.TString;
|
|
117
132
|
edits: Type.TOptional<Type.TArray<Type.TObject<{
|
|
@@ -145,7 +160,7 @@ export declare const notesReadParameters: Type.TObject<{
|
|
|
145
160
|
export declare const notesRead: {
|
|
146
161
|
readonly name: "notes_read";
|
|
147
162
|
readonly label: "Notes read";
|
|
148
|
-
readonly description: "Read a note. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
163
|
+
readonly description: "Read a note. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
|
|
149
164
|
readonly parameters: Type.TObject<{
|
|
150
165
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
151
166
|
max_chars: Type.TOptional<Type.TInteger>;
|
|
@@ -155,8 +170,6 @@ export declare const notesRead: {
|
|
|
155
170
|
text: Type.TString;
|
|
156
171
|
total_chars: Type.TInteger;
|
|
157
172
|
next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
|
|
158
|
-
address: Type.TString;
|
|
159
|
-
project_key: Type.TOptional<Type.TString>;
|
|
160
173
|
metadata: Type.TObject<{
|
|
161
174
|
origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
|
|
162
175
|
created_at: Type.TString;
|
|
@@ -165,6 +178,13 @@ export declare const notesRead: {
|
|
|
165
178
|
project: Type.TOptional<Type.TString>;
|
|
166
179
|
extra: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
167
180
|
}>;
|
|
181
|
+
project_root: Type.TOptional<Type.TString>;
|
|
182
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
183
|
+
name: Type.TString;
|
|
184
|
+
path: Type.TString;
|
|
185
|
+
}>>>;
|
|
186
|
+
address: Type.TString;
|
|
187
|
+
project_key: Type.TOptional<Type.TString>;
|
|
168
188
|
}>, Type.TObject<{
|
|
169
189
|
error: Type.TString;
|
|
170
190
|
code: Type.TString;
|
|
@@ -180,7 +200,7 @@ export declare const notesListParameters: Type.TObject<{
|
|
|
180
200
|
export declare const notesList: {
|
|
181
201
|
readonly name: "notes_list";
|
|
182
202
|
readonly label: "Notes list";
|
|
183
|
-
readonly description: "List notes in this session and the four @ homes, newest first. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
203
|
+
readonly description: "List notes in this session and the four @ homes, newest first. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
|
|
184
204
|
readonly parameters: Type.TObject<{
|
|
185
205
|
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
186
206
|
limit: Type.TOptional<Type.TInteger>;
|
|
@@ -190,10 +210,15 @@ export declare const notesList: {
|
|
|
190
210
|
more: Type.TInteger;
|
|
191
211
|
homes_unavailable: Type.TArray<Type.TString>;
|
|
192
212
|
files: Type.TArray<Type.TObject<{
|
|
193
|
-
address: Type.TString;
|
|
194
|
-
project_key: Type.TOptional<Type.TString>;
|
|
195
213
|
updated_at: Type.TString;
|
|
196
214
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
215
|
+
project_root: Type.TOptional<Type.TString>;
|
|
216
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
217
|
+
name: Type.TString;
|
|
218
|
+
path: Type.TString;
|
|
219
|
+
}>>>;
|
|
220
|
+
address: Type.TString;
|
|
221
|
+
project_key: Type.TOptional<Type.TString>;
|
|
197
222
|
}>>;
|
|
198
223
|
}>, Type.TObject<{
|
|
199
224
|
error: Type.TString;
|
|
@@ -214,7 +239,7 @@ export declare const MATCH_SHORTENED_MARKER = " [truncated]";
|
|
|
214
239
|
export declare const notesSearch: {
|
|
215
240
|
readonly name: "notes_search";
|
|
216
241
|
readonly label: "Notes search";
|
|
217
|
-
readonly description: "Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
242
|
+
readonly description: "Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
|
|
218
243
|
readonly parameters: Type.TObject<{
|
|
219
244
|
query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
|
|
220
245
|
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
@@ -231,10 +256,15 @@ export declare const notesSearch: {
|
|
|
231
256
|
text: Type.TString;
|
|
232
257
|
offset_chars: Type.TInteger;
|
|
233
258
|
}>>;
|
|
234
|
-
address: Type.TString;
|
|
235
|
-
project_key: Type.TOptional<Type.TString>;
|
|
236
259
|
updated_at: Type.TString;
|
|
237
260
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
261
|
+
project_root: Type.TOptional<Type.TString>;
|
|
262
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
263
|
+
name: Type.TString;
|
|
264
|
+
path: Type.TString;
|
|
265
|
+
}>>>;
|
|
266
|
+
address: Type.TString;
|
|
267
|
+
project_key: Type.TOptional<Type.TString>;
|
|
238
268
|
}>>;
|
|
239
269
|
}>, Type.TObject<{
|
|
240
270
|
error: Type.TString;
|
package/dist/src/tools/notes.js
CHANGED
|
@@ -13,7 +13,7 @@ const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional)
|
|
|
13
13
|
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
|
|
14
14
|
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
|
|
15
15
|
const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses.");
|
|
16
|
-
const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
|
|
16
|
+
const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes; `@projects/<name>/<path>` reads a named project (discover with glob `@projects/*/**`). Not file paths: never pass them to file tools.";
|
|
17
17
|
/**
|
|
18
18
|
* Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
|
|
19
19
|
* Convert expected refusals; unexpected errors propagate unchanged.
|
|
@@ -88,13 +88,23 @@ function renderMetadata(metadata) {
|
|
|
88
88
|
fields.push(`extra ${JSON.stringify(metadata.extra)}`);
|
|
89
89
|
return fields.join(" | ");
|
|
90
90
|
}
|
|
91
|
-
/**
|
|
91
|
+
/** Keep the address visible, with project context and at most one sibling hint line. */
|
|
92
92
|
function renderIdentity(identity) {
|
|
93
|
-
|
|
93
|
+
let text = identity.project_key === undefined ? identity.address : `${identity.address} (project ${identity.project_key})`;
|
|
94
|
+
if (identity.project_root !== undefined)
|
|
95
|
+
text += ` (project_root ${identity.project_root})`;
|
|
96
|
+
if (identity.project_siblings !== undefined)
|
|
97
|
+
text += `\n Same-basename projects: ${identity.project_siblings.map(sibling => `${sibling.name} (${sibling.path})`).join(", ")}`;
|
|
98
|
+
return text;
|
|
94
99
|
}
|
|
100
|
+
const ProjectReceiptSchema = {
|
|
101
|
+
project_root: Type.Optional(Type.String()),
|
|
102
|
+
project_siblings: Type.Optional(Type.Array(Type.Object({ name: Type.String(), path: Type.String() }, { additionalProperties: false }))),
|
|
103
|
+
};
|
|
95
104
|
const ListedFileSchema = Type.Object({
|
|
96
105
|
address: Type.String(),
|
|
97
106
|
project_key: Type.Optional(Type.String()),
|
|
107
|
+
...ProjectReceiptSchema,
|
|
98
108
|
updated_at: Type.String(),
|
|
99
109
|
crumpled_at: Type.Optional(Type.String()),
|
|
100
110
|
}, { additionalProperties: false });
|
|
@@ -126,6 +136,7 @@ export const NotesUpdateDataSchema = Type.Object({
|
|
|
126
136
|
export const NotesReadDataSchema = Type.Object({
|
|
127
137
|
address: Type.String(),
|
|
128
138
|
project_key: Type.Optional(Type.String()),
|
|
139
|
+
...ProjectReceiptSchema,
|
|
129
140
|
metadata: NoteMetadataSchema,
|
|
130
141
|
...TextWindowSchema.properties,
|
|
131
142
|
}, { additionalProperties: false });
|
|
@@ -161,7 +172,7 @@ function snapshot(rows, limit, status, renderData, shrink) {
|
|
|
161
172
|
return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable homes is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer homes.`);
|
|
162
173
|
}
|
|
163
174
|
function listedFile(row, identity) {
|
|
164
|
-
return {
|
|
175
|
+
return { ...noteIdentity(identity, row.address), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
|
|
165
176
|
}
|
|
166
177
|
export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN }, { additionalProperties: false });
|
|
167
178
|
function renderWriteData(data) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { cpSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { execFileSync } from "node:child_process";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
5
5
|
import { join } from "node:path";
|
|
@@ -11,6 +11,10 @@ import { DEFAULT_CLAUDE_RESET_MARGIN_TOKENS, resolveClaudeLimits } from "../src/
|
|
|
11
11
|
import { WARNING_RUNWAY_TOKENS } from "../src/budget/constants.js";
|
|
12
12
|
import { PROTOCOL_WIPE_SENTENCE, CLAUDE_WIPE_SENTENCE, renderProtocolBlock } from "../src/boot/text.js";
|
|
13
13
|
import { CLAUDE_WARNING_PROMPT, CONTINUATION } from "../src/budget/text.js";
|
|
14
|
+
import { createNotesStore } from "../src/notes/index.js";
|
|
15
|
+
import { resolveProjectHome } from "../src/notes/project-home.js";
|
|
16
|
+
import { notesIdentityFromPi } from "../src/pi/notes/adapter.js";
|
|
17
|
+
import { context, manager } from "./helpers/extension.js";
|
|
14
18
|
const identity = { home: mkdtempSync(join(tmpdir(), "claude-mod-")), sessionId: "session", cwd: process.cwd(), agent: "claude", model: "claude" };
|
|
15
19
|
async function callTool(tool, params) {
|
|
16
20
|
return await dispatch({ op: "tool", tool, identity, params });
|
|
@@ -779,6 +783,33 @@ test("Claude identity uses the documented current model and cwd, with a safe mod
|
|
|
779
783
|
await write("@model/model.md", "fallback");
|
|
780
784
|
assert.equal(seen.at(-1).identity.model, "claude");
|
|
781
785
|
});
|
|
786
|
+
test("Claude current-cwd project resolution shares Pi's remote home across checkout spellings", async (t) => {
|
|
787
|
+
const { host, home, invoke } = await retainedFixture(t);
|
|
788
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "claude-project-home-")));
|
|
789
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
790
|
+
const first = join(root, "api");
|
|
791
|
+
const second = join(root, "renamed");
|
|
792
|
+
for (const [cwd, remote] of [[first, "git@HOST:team/backend.git"], [second, "https://host/team/backend.git"]]) {
|
|
793
|
+
mkdirSync(join(cwd, ".git"), { recursive: true });
|
|
794
|
+
writeFileSync(join(cwd, ".git/config"), `[remote "origin"]\nurl = ${remote}\n`);
|
|
795
|
+
}
|
|
796
|
+
let cwd = first;
|
|
797
|
+
host.session.cwd = async () => cwd;
|
|
798
|
+
const piIdentity = notesIdentityFromPi(context(manager(), undefined, undefined, true, first), home);
|
|
799
|
+
assert.equal(piIdentity.projectKey, "api");
|
|
800
|
+
await createNotesStore(piIdentity).write("@project/shared", "Pi body");
|
|
801
|
+
const call = (tool, params) => invoke("tool.call", {
|
|
802
|
+
tool: `mcp__notesoup__${tool}`, tool_use_id: "project-call", ...params,
|
|
803
|
+
});
|
|
804
|
+
assert.match((await call("notes_read", { address: "@project/shared" })).result, /Pi body/);
|
|
805
|
+
cwd = second;
|
|
806
|
+
const written = await call("notes_write", { address: "@project/shared", content: "Claude body" });
|
|
807
|
+
assert.equal(written.isError, undefined);
|
|
808
|
+
assert.equal(written.result, "overwrote @project/shared.md (project api)");
|
|
809
|
+
assert.equal((await createNotesStore(piIdentity).read("@project/shared"))?.body, "Claude body");
|
|
810
|
+
assert.deepEqual(JSON.parse(readFileSync(join(home, "project/api/.project"), "utf8")), { id: "host/team/backend", path: second });
|
|
811
|
+
assert.equal(resolveProjectHome(second, home).name, piIdentity.projectKey);
|
|
812
|
+
});
|
|
782
813
|
test("Claude session.end cannot be undone by an in-flight old reset", async (t) => {
|
|
783
814
|
const { host, invoke, context } = await retainedFixture(t);
|
|
784
815
|
let prepared;
|
package/dist/test/notes.test.js
CHANGED
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import assert from "node:assert/strict";
|
|
10
10
|
import { execFileSync } from "node:child_process";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { basename, join } from "node:path";
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { join } from "node:path";
|
|
14
13
|
import test from "node:test";
|
|
15
14
|
import { Check } from "typebox/value";
|
|
16
15
|
import { parseNote } from "../src/notes/frontmatter.js";
|
|
17
16
|
import { projectKey } from "../src/notes/paths.js";
|
|
18
17
|
import { globToRegExp } from "../src/notes/address.js";
|
|
19
18
|
import { listNotes, physicalPath, scopeDir } from "./helpers/notes.js";
|
|
19
|
+
import { notesList, notesSearch } from "../src/tools/notes.js";
|
|
20
|
+
import { notesIdentityFromPi } from "../src/pi/notes/adapter.js";
|
|
20
21
|
import { call, context, explicitBoot, makeExtension, manager, resultData, resultError, resultRead } from "./helpers/extension.js";
|
|
21
22
|
import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
|
|
22
23
|
const testEnvironment = installExtensionTestHooks("notesoup-notes");
|
|
@@ -25,7 +26,7 @@ function freshRoot() {
|
|
|
25
26
|
}
|
|
26
27
|
function assertReceiptIdentity(value, address, scope, ctx) {
|
|
27
28
|
assert.equal(value.address, address);
|
|
28
|
-
assert.equal(value.project_key, scope === "project" ? projectKey(ctx.cwd) : undefined);
|
|
29
|
+
assert.equal(value.project_key, scope === "project" ? projectKey(ctx.cwd, process.env.PI_NOTES_HOME) : undefined);
|
|
29
30
|
}
|
|
30
31
|
test("exactly the five notes tools are registered; the legacy five are gone", () => {
|
|
31
32
|
const captured = makeExtension(manager());
|
|
@@ -112,7 +113,7 @@ test("write lands a real markdown file with harness frontmatter and a pure body"
|
|
|
112
113
|
for (const key of ["createdAt", "updatedAt", "lastAccessed"]) {
|
|
113
114
|
assert.match(raw, new RegExp(`^${key}: \\d{4}-\\d{2}-\\d{2}T`, "m"), `frontmatter renders ${key} via localIso`);
|
|
114
115
|
}
|
|
115
|
-
assert.equal(parseNote(raw).meta.project, projectKey(ctx.cwd), "a newly-created session note records its existing project key");
|
|
116
|
+
assert.equal(parseNote(raw).meta.project, projectKey(ctx.cwd, root), "a newly-created session note records its existing project key");
|
|
116
117
|
assertReceiptIdentity(result, "a/b.md", "session", ctx);
|
|
117
118
|
assert.equal(result.outcome, "created");
|
|
118
119
|
assert.equal(existsSync(join(scopeDir("session", ctx), ".session.json")), false, "ownership is stored in note frontmatter, not a sidecar");
|
|
@@ -128,8 +129,8 @@ test("session-note project ownership is per note, persistent across sessions, an
|
|
|
128
129
|
const cwdB = join(testEnvironment.cwd, "project-b");
|
|
129
130
|
mkdirSync(cwdA, { recursive: true });
|
|
130
131
|
mkdirSync(cwdB, { recursive: true });
|
|
131
|
-
const projectA = projectKey(cwdA);
|
|
132
|
-
const projectB = projectKey(cwdB);
|
|
132
|
+
const projectA = projectKey(cwdA, process.env.PI_NOTES_HOME);
|
|
133
|
+
const projectB = projectKey(cwdB, process.env.PI_NOTES_HOME);
|
|
133
134
|
assert.notEqual(projectA, projectB);
|
|
134
135
|
const firstSession = manager();
|
|
135
136
|
const firstCaptured = makeExtension(firstSession);
|
|
@@ -177,8 +178,8 @@ test("linked git worktrees share the main checkout's project key", () => {
|
|
|
177
178
|
git(["commit", "-q", "--allow-empty", "-m", "init"]);
|
|
178
179
|
const worktree = join(root, "wt");
|
|
179
180
|
git(["worktree", "add", "-q", "--detach", worktree]);
|
|
180
|
-
assert.equal(projectKey(worktree), projectKey(main), "a linked worktree resolves to the main checkout's key");
|
|
181
|
-
assert.equal(projectKey(join(worktree, "gone", "deeper")), projectKey(main), "a nonexistent subdirectory still resolves through its worktree");
|
|
181
|
+
assert.equal(projectKey(worktree, process.env.PI_NOTES_HOME), projectKey(main, process.env.PI_NOTES_HOME), "a linked worktree resolves to the main checkout's key");
|
|
182
|
+
assert.equal(projectKey(join(worktree, "gone", "deeper"), process.env.PI_NOTES_HOME), projectKey(main, process.env.PI_NOTES_HOME), "a nonexistent subdirectory still resolves through its worktree");
|
|
182
183
|
assert.equal(scopeDir("project", context(manager(), undefined, undefined, true, worktree)), scopeDir("project", context(manager(), undefined, undefined, true, main)), "@project uses the same physical home from both checkouts");
|
|
183
184
|
});
|
|
184
185
|
test("unrecognized metadata remains ordinary frontmatter; invalid project ownership stays unknown", async () => {
|
|
@@ -224,7 +225,7 @@ project: 17
|
|
|
224
225
|
|
|
225
226
|
invalid owner`);
|
|
226
227
|
assert.equal(parseNote(readFileSync(invalidFile, "utf8")).meta.project, 17);
|
|
227
|
-
assert.notEqual(parseNote(readFileSync(invalidFile, "utf8")).meta.project, projectKey(ctx.cwd), "invalid ownership does not match the current project key");
|
|
228
|
+
assert.notEqual(parseNote(readFileSync(invalidFile, "utf8")).meta.project, projectKey(ctx.cwd, process.env.PI_NOTES_HOME), "invalid ownership does not match the current project key");
|
|
228
229
|
await call(captured, "notes_write", { address: "invalid.md", content: "still invalid" }, ctx);
|
|
229
230
|
assert.equal(parseNote(readFileSync(invalidFile, "utf8")).meta.project, 17, "an invalid value remains unknown and is not replaced with cwd-derived ownership");
|
|
230
231
|
assert.equal(existsSync(join(scopeDir("session", ctx), ".session.json")), false, "new notes use no ownership sidecar");
|
|
@@ -339,14 +340,19 @@ test("empty results distinguish hidden notes and unavailable homes", async () =>
|
|
|
339
340
|
await call(captured, "notes_update", { address: "@human/hidden.md", crumpled: true }, ctx);
|
|
340
341
|
const hidden = resultData(await call(captured, "notes_search", { query: "needle", glob: "@human/**" }, ctx));
|
|
341
342
|
assert.deepEqual(hidden.files, [], "a crumpled note is hidden from search");
|
|
343
|
+
const identity = notesIdentityFromPi(ctx);
|
|
342
344
|
const broken = scopeDir("project", ctx);
|
|
343
345
|
mkdirSync(join(broken, ".."), { recursive: true });
|
|
346
|
+
rmSync(broken, { recursive: true });
|
|
344
347
|
writeFileSync(broken, "not a directory");
|
|
345
|
-
const
|
|
348
|
+
const partialResult = await notesList.execute({ glob: "**" }, identity);
|
|
349
|
+
assert.ok(partialResult.ok);
|
|
350
|
+
const partial = partialResult.data;
|
|
346
351
|
assert.deepEqual(partial.homes_unavailable, ["@project"]);
|
|
347
352
|
assert.deepEqual(partial.files, []);
|
|
348
|
-
const
|
|
349
|
-
assert.
|
|
353
|
+
const searchResult = await notesSearch.execute({ query: "needle", glob: "**" }, identity);
|
|
354
|
+
assert.ok(searchResult.ok);
|
|
355
|
+
assert.deepEqual(searchResult.data.homes_unavailable, ["@project"]);
|
|
350
356
|
writeFileSync(join(process.env.PI_NOTES_HOME, "agents"), "not a directory");
|
|
351
357
|
const namespace = resultData(await call(captured, "notes_list", { glob: "@agents/*/note.md" }, ctx));
|
|
352
358
|
assert.deepEqual(namespace.homes_unavailable, ["@agents"]);
|
|
@@ -529,17 +535,14 @@ async function withAgent(name, run) {
|
|
|
529
535
|
process.env.PI_NOTES_AGENT = previous;
|
|
530
536
|
}
|
|
531
537
|
}
|
|
532
|
-
test("a symlinked checkout
|
|
538
|
+
test("a symlinked checkout resolves the canonical root, so one checkout has one project home", () => {
|
|
533
539
|
const root = realpathSync(testEnvironment.cwd);
|
|
534
540
|
const real = join(root, "real-repo");
|
|
535
541
|
mkdirSync(join(real, ".git"), { recursive: true });
|
|
536
542
|
const linked = join(root, "linked-repo");
|
|
537
543
|
symlinkSync(real, linked);
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
assert.equal(projectKey(linked), canonicalKey, "the symlinked spelling hashes the canonical root");
|
|
541
|
-
assert.equal(projectKey(real), canonicalKey, "the canonical spelling hashes the same root");
|
|
542
|
-
assert.notEqual(`${basename(linked)}-${createHash("sha1").update(linked).digest("hex").slice(0, 8)}`, canonicalKey, "a path-spelled key would differ");
|
|
544
|
+
assert.equal(projectKey(linked, process.env.PI_NOTES_HOME), "real-repo", "the name comes from the canonical root");
|
|
545
|
+
assert.equal(projectKey(real, process.env.PI_NOTES_HOME), "real-repo", "both spellings reuse one home");
|
|
543
546
|
});
|
|
544
547
|
test("a glob ? matches exactly one non-slash character", () => {
|
|
545
548
|
const pattern = globToRegExp("a?.md");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import test from "node:test";
|
|
6
|
+
import { Check } from "typebox/value";
|
|
7
|
+
import { createNotesStore } from "../src/notes/index.js";
|
|
8
|
+
import { assertAddress } from "../src/notes/address.js";
|
|
9
|
+
import { normalizeRemote, projectKey } from "../src/notes/project-home.js";
|
|
10
|
+
import { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "../src/tools/notes.js";
|
|
11
|
+
import { success } from "../src/tools/result.js";
|
|
12
|
+
function fixture(t) {
|
|
13
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "notesoup-project-home-")));
|
|
14
|
+
t.after(() => rmSync(root, { recursive: true, force: true }));
|
|
15
|
+
const home = join(root, "notes");
|
|
16
|
+
const repo = (path, origin) => {
|
|
17
|
+
const cwd = join(root, path);
|
|
18
|
+
mkdirSync(join(cwd, ".git"), { recursive: true });
|
|
19
|
+
writeFileSync(join(cwd, ".git/config"), origin ? `[remote "origin"]\n\turl = ${origin}\n` : "");
|
|
20
|
+
return cwd;
|
|
21
|
+
};
|
|
22
|
+
const marker = (key) => JSON.parse(readFileSync(join(home, "project", key, ".project"), "utf8"));
|
|
23
|
+
const identity = (cwd) => ({ home, projectKey: projectKey(cwd, home), sessionId: "session", agent: "test", model: "test" });
|
|
24
|
+
return { root, home, repo, marker, identity };
|
|
25
|
+
}
|
|
26
|
+
function data(result) {
|
|
27
|
+
if (!result.ok)
|
|
28
|
+
assert.fail(result.error.message);
|
|
29
|
+
return result.data;
|
|
30
|
+
}
|
|
31
|
+
function refused(result) {
|
|
32
|
+
if (result.ok)
|
|
33
|
+
assert.fail("expected refusal");
|
|
34
|
+
return result.error.message;
|
|
35
|
+
}
|
|
36
|
+
test("origin identity normalizes https, scp and port-less ssh without invoking Git", t => {
|
|
37
|
+
const { home, repo, marker } = fixture(t);
|
|
38
|
+
for (const remote of ["https://user:secret@GitHub.COM/team/api.git/", "git@GitHub.COM:team/api.git", "ssh://git@GitHub.COM/team/api.git"]) {
|
|
39
|
+
assert.equal(normalizeRemote(remote), "github.com/team/api");
|
|
40
|
+
}
|
|
41
|
+
assert.equal(normalizeRemote("ssh://git@EXAMPLE.com:2222/team/api.git"), "example.com:2222/team/api");
|
|
42
|
+
const first = repo("one/api", "git@GitHub.COM:team/api.git");
|
|
43
|
+
const second = repo("two/renamed", "https://github.com/team/api.git");
|
|
44
|
+
assert.equal(projectKey(first, home), "api");
|
|
45
|
+
assert.equal(projectKey(second, home), "api");
|
|
46
|
+
assert.deepEqual(marker("api"), { id: "github.com/team/api", path: second });
|
|
47
|
+
});
|
|
48
|
+
test("same-basename repositories get readable suffixes and unmarked legacy names are taken", t => {
|
|
49
|
+
const { home, repo } = fixture(t);
|
|
50
|
+
const first = repo("one/x", "https://host/one/x");
|
|
51
|
+
const second = repo("two/x", "https://host/two/x");
|
|
52
|
+
assert.equal(projectKey(first, home), "x");
|
|
53
|
+
assert.equal(projectKey(second, home), "x-1");
|
|
54
|
+
mkdirSync(join(home, "project", "legacy"));
|
|
55
|
+
writeFileSync(join(home, "project", "legacy", "keep.md"), "old notes");
|
|
56
|
+
assert.equal(projectKey(repo("legacy"), home), "legacy-1");
|
|
57
|
+
assert.equal(readFileSync(join(home, "project", "legacy", "keep.md"), "utf8"), "old notes");
|
|
58
|
+
});
|
|
59
|
+
test("linked worktrees and nested directories share the main checkout home and origin", t => {
|
|
60
|
+
const { root, home, repo, marker } = fixture(t);
|
|
61
|
+
const main = repo("api", "ssh://git@HOST/team/api.git");
|
|
62
|
+
const worktree = join(root, "worktree");
|
|
63
|
+
mkdirSync(worktree);
|
|
64
|
+
mkdirSync(join(main, ".git/worktrees/wt"), { recursive: true });
|
|
65
|
+
writeFileSync(join(worktree, ".git"), `gitdir: ${join(main, ".git/worktrees/wt")}\n`);
|
|
66
|
+
writeFileSync(join(main, ".git/worktrees/wt/commondir"), "../..\n");
|
|
67
|
+
assert.equal(projectKey(main, home), "api");
|
|
68
|
+
assert.equal(projectKey(join(worktree, "missing/subdir"), home), "api");
|
|
69
|
+
assert.deepEqual(marker("api"), { id: "host/team/api", path: main });
|
|
70
|
+
});
|
|
71
|
+
test("a moved checkout reuses its remote home and updates only the display root", async (t) => {
|
|
72
|
+
const { root, home, repo, marker, identity } = fixture(t);
|
|
73
|
+
const old = repo("api", "https://host/team/api.git");
|
|
74
|
+
await createNotesStore(identity(old)).write("@project/decision", "keep me");
|
|
75
|
+
const moved = join(root, "new-name");
|
|
76
|
+
renameSync(old, moved);
|
|
77
|
+
const current = identity(moved);
|
|
78
|
+
assert.equal(current.projectKey, "api");
|
|
79
|
+
assert.deepEqual(marker("api"), { id: "host/team/api", path: moved });
|
|
80
|
+
assert.equal((await createNotesStore(current).read("@project/decision"))?.body, "keep me");
|
|
81
|
+
assert.equal(projectKey(moved, home), "api");
|
|
82
|
+
});
|
|
83
|
+
test("adding origin adopts the canonical path identity without orphaning notes", async (t) => {
|
|
84
|
+
const { home, repo, marker, identity } = fixture(t);
|
|
85
|
+
const cwd = repo("api");
|
|
86
|
+
await createNotesStore(identity(cwd)).write("@project/decision", "still here");
|
|
87
|
+
assert.deepEqual(marker("api"), { id: cwd, path: cwd });
|
|
88
|
+
writeFileSync(join(cwd, ".git/config"), '[remote "backup"]\nurl = https://host/wrong\n[remote "origin"]\nurl = git@HOST:team/api.git\n');
|
|
89
|
+
assert.equal(projectKey(cwd, home), "api");
|
|
90
|
+
assert.deepEqual(marker("api"), { id: "host/team/api", path: cwd });
|
|
91
|
+
assert.equal((await createNotesStore(identity(cwd)).read("@project/decision"))?.body, "still here");
|
|
92
|
+
});
|
|
93
|
+
test("named projects read/list/search with root and sibling receipts, without touching stored bytes", async (t) => {
|
|
94
|
+
const { home, repo, identity } = fixture(t);
|
|
95
|
+
const first = repo("one/api", "https://host/one/backend");
|
|
96
|
+
const second = repo("two/api", "https://host/two/service");
|
|
97
|
+
const own = identity(first);
|
|
98
|
+
const other = identity(second);
|
|
99
|
+
await createNotesStore(own).write("@project/decision", "needle first");
|
|
100
|
+
await createNotesStore(other).write("@project/decision", "needle second");
|
|
101
|
+
const address = "@projects/api-1/decision.md";
|
|
102
|
+
const file = join(home, "project/api-1/decision.md");
|
|
103
|
+
const before = readFileSync(file, "utf8");
|
|
104
|
+
const read = data(await notesRead.execute({ address }, own));
|
|
105
|
+
assert.equal(read.text, "needle second");
|
|
106
|
+
assert.equal(read.project_root, second);
|
|
107
|
+
assert.deepEqual(read.project_siblings, [{ name: "api", path: first }]);
|
|
108
|
+
assert.equal(Check(notesRead.outputSchema, read), true);
|
|
109
|
+
assert.match(notesRead.render(success(read)), /Same-basename projects: api \(/);
|
|
110
|
+
const listed = data(await notesList.execute({ glob: "@projects/*/**" }, own));
|
|
111
|
+
assert.deepEqual(listed.files.map(row => [row.address, row.project_root]).sort(), [["@projects/api-1/decision.md", second], ["@projects/api/decision.md", first]].sort());
|
|
112
|
+
assert.equal(Check(notesList.outputSchema, listed), true);
|
|
113
|
+
const searched = data(await notesSearch.execute({ glob: "@projects/api-1/**", query: "needle" }, own));
|
|
114
|
+
assert.equal(searched.files[0]?.project_root, second);
|
|
115
|
+
assert.equal(Check(notesSearch.outputSchema, searched), true);
|
|
116
|
+
assert.equal(readFileSync(file, "utf8"), before, "named-home reads never rewrite access metadata");
|
|
117
|
+
});
|
|
118
|
+
test("named project writes, edits, crumples and both move endpoints refuse, including the current home", async (t) => {
|
|
119
|
+
const { repo, identity } = fixture(t);
|
|
120
|
+
const own = identity(repo("api"));
|
|
121
|
+
await createNotesStore(own).write("@project/decision", "body");
|
|
122
|
+
const address = "@projects/api/decision";
|
|
123
|
+
for (const result of [
|
|
124
|
+
await notesWrite.execute({ address, content: "replacement" }, own),
|
|
125
|
+
await notesUpdate.execute({ address, edits: [{ oldText: "body", newText: "changed" }] }, own, () => ""),
|
|
126
|
+
await notesUpdate.execute({ address, crumpled: true }, own, () => ""),
|
|
127
|
+
await notesUpdate.execute({ address, rename_to: "@project/moved" }, own, () => ""),
|
|
128
|
+
await notesUpdate.execute({ address: "@project/decision", rename_to: "@projects/api/moved" }, own, () => ""),
|
|
129
|
+
])
|
|
130
|
+
assert.match(refused(result), /read-only; use @project\//);
|
|
131
|
+
assert.equal(data(await notesRead.execute({ address }, own)).text, "body");
|
|
132
|
+
assert.throws(() => assertAddress("@projects/api/../decision"));
|
|
133
|
+
assert.throws(() => assertAddress("@projects/api"));
|
|
134
|
+
});
|