notesoup 0.60.0 → 0.61.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/README.md +5 -4
- package/dist/src/boot/render.d.ts +5 -0
- package/dist/src/boot/render.js +48 -19
- package/dist/src/boot/text.d.ts +1 -3
- package/dist/src/boot/text.js +10 -11
- package/dist/src/budget/text.d.ts +1 -1
- package/dist/src/budget/text.js +1 -1
- package/dist/src/dream/git.js +12 -13
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.d.ts +6 -0
- package/dist/src/notes/frontmatter.js +17 -1
- package/dist/src/notes/policy.js +1 -1
- package/dist/src/notes/project-namespace.js +39 -73
- package/dist/src/notes/store.d.ts +2 -0
- package/dist/src/notes/store.js +30 -5
- package/dist/src/sqlite-lock.d.ts +2 -0
- package/dist/src/sqlite-lock.js +17 -0
- package/dist/src/tools/dream.d.ts +4 -4
- package/dist/src/tools/dream.js +15 -16
- package/dist/src/tools/notes.d.ts +10 -0
- package/dist/src/tools/notes.js +14 -8
- package/dist/test/dream-tools.test.js +42 -14
- package/dist/test/host-neutral.test.js +1 -1
- package/dist/test/note-policy.test.js +122 -8
- package/dist/test/notes.integration.test.js +3 -7
- package/dist/test/project-namespace.test.js +33 -88
- package/docs/dsh.md +2 -2
- package/docs/notes-library.md +10 -4
- package/docs/reset-lifecycle.md +1 -1
- package/docs/skills.md +2 -6
- package/docs/tool-results.md +1 -1
- package/package.json +1 -1
- package/playbook.md +3 -3
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +150 -103
- package/plugins/claude/playbook.md +3 -3
- package/plugins/claude/skills/dream/SKILL.md +2 -2
- package/plugins/claude/skills/memory/SKILL.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +149 -102
- package/skills/dream/SKILL.md +2 -2
- package/skills/memory/SKILL.md +1 -1
- package/src/boot/render.ts +48 -17
- package/src/boot/text.ts +10 -11
- package/src/budget/text.ts +1 -1
- package/src/dream/git.ts +11 -11
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +19 -1
- package/src/notes/policy.ts +1 -1
- package/src/notes/project-namespace.ts +37 -59
- package/src/notes/store.ts +25 -7
- package/src/sqlite-lock.ts +14 -0
- package/src/tools/dream.ts +15 -14
- package/src/tools/notes.ts +14 -8
- package/dist/src/dream/lock.d.ts +0 -14
- package/dist/src/dream/lock.js +0 -29
- package/src/dream/lock.ts +0 -28
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
/** Dream operations: open one project's notes for consolidation, delete crumpled notes, close. */
|
|
2
1
|
import { Type, type Static } from "typebox";
|
|
3
2
|
import { type NotesIdentity } from "../notes/index.js";
|
|
4
|
-
import { type DreamLock } from "../dream/lock.js";
|
|
5
3
|
import { type Outcome } from "../result.js";
|
|
6
4
|
/** The one open dream per session; the host owns where it lives. */
|
|
7
5
|
type DreamOpening = {
|
|
8
6
|
project: string;
|
|
9
|
-
|
|
7
|
+
release: () => void;
|
|
10
8
|
generation: number;
|
|
11
9
|
};
|
|
12
10
|
export type DreamState = {
|
|
13
11
|
project?: string;
|
|
14
|
-
|
|
12
|
+
release?: () => void;
|
|
15
13
|
pending?: DreamOpening;
|
|
16
14
|
generation?: number;
|
|
17
15
|
};
|
|
@@ -31,6 +29,7 @@ export declare const DreamBeginDataSchema: Type.TObject<{
|
|
|
31
29
|
last_accessed: Type.TString;
|
|
32
30
|
updated_at: Type.TString;
|
|
33
31
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
32
|
+
description: Type.TOptional<Type.TString>;
|
|
34
33
|
warnings: Type.TArray<Type.TString>;
|
|
35
34
|
pinned: Type.TBoolean;
|
|
36
35
|
budget: Type.TInteger;
|
|
@@ -61,6 +60,7 @@ export declare const dreamBegin: {
|
|
|
61
60
|
last_accessed: Type.TString;
|
|
62
61
|
updated_at: Type.TString;
|
|
63
62
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
63
|
+
description: Type.TOptional<Type.TString>;
|
|
64
64
|
warnings: Type.TArray<Type.TString>;
|
|
65
65
|
pinned: Type.TBoolean;
|
|
66
66
|
budget: Type.TInteger;
|
package/dist/src/tools/dream.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** Dream operations: open one project's notes for consolidation, delete crumpled notes, close. */
|
|
2
|
+
import { join } from "node:path";
|
|
2
3
|
import { Type } from "typebox";
|
|
3
4
|
import { localIso } from "../notes/frontmatter.js";
|
|
4
5
|
import { createNotesStore, noteIdentity } from "../notes/index.js";
|
|
5
6
|
import { projectNamespaces } from "../notes/project-namespace.js";
|
|
6
7
|
import { gitCommit } from "../dream/git.js";
|
|
7
|
-
import {
|
|
8
|
+
import { trySqliteLock } from "../sqlite-lock.js";
|
|
8
9
|
import { failure, success } from "../result.js";
|
|
9
10
|
import { renderOutcome, resultSchema } from "./result.js";
|
|
10
11
|
import { failureOf, listedFile, ListedFileSchema, NoteIdentitySchema, renderListData, snapshot, SnapshotSchema } from "./notes.js";
|
|
@@ -18,21 +19,19 @@ function nextGeneration(state) {
|
|
|
18
19
|
}
|
|
19
20
|
/** Drop an open dream without an end commit, e.g. when its session shuts down. */
|
|
20
21
|
export function abandonDream(state) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
releaseDreamLock(pending.lock);
|
|
24
|
-
if (state.lock && state.lock !== pending?.lock)
|
|
25
|
-
releaseDreamLock(state.lock);
|
|
22
|
+
state.pending?.release();
|
|
23
|
+
state.release?.();
|
|
26
24
|
nextGeneration(state);
|
|
27
25
|
delete state.project;
|
|
28
|
-
delete state.
|
|
26
|
+
delete state.release;
|
|
29
27
|
delete state.pending;
|
|
30
28
|
}
|
|
31
29
|
/** Release an opening without disturbing a newer opening in the same state. */
|
|
32
30
|
function releaseOpening(state, opening) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
if (!currentOpening(state, opening))
|
|
32
|
+
return;
|
|
33
|
+
opening.release();
|
|
34
|
+
delete state.pending;
|
|
36
35
|
}
|
|
37
36
|
function cancelledOpening(state, opening) {
|
|
38
37
|
releaseOpening(state, opening);
|
|
@@ -67,11 +66,11 @@ export const dreamBegin = {
|
|
|
67
66
|
if (project !== identity.projectKey && !projectNamespaces(identity.home).some(namespace => namespace.name === project)) {
|
|
68
67
|
return failure("not_found", `No project named ${JSON.stringify(project)}; notes_list with glob @projects/*/** shows the names.`);
|
|
69
68
|
}
|
|
70
|
-
const
|
|
71
|
-
if (!
|
|
72
|
-
return failure("already_dreaming",
|
|
73
|
-
// Publish ownership before the first await
|
|
74
|
-
const opening = { project,
|
|
69
|
+
const release = trySqliteLock(join(identity.home, ".dream.lock.sqlite"), 0);
|
|
70
|
+
if (!release)
|
|
71
|
+
return failure("already_dreaming", "Another dream is open in this notes home.");
|
|
72
|
+
// Publish ownership before the first await so shutdown can release this transaction.
|
|
73
|
+
const opening = { project, release, generation: nextGeneration(state) };
|
|
75
74
|
state.pending = opening;
|
|
76
75
|
try {
|
|
77
76
|
const store = createNotesStore({ ...identity, dreaming: project });
|
|
@@ -102,7 +101,7 @@ export const dreamBegin = {
|
|
|
102
101
|
if (!currentOpening(state, opening))
|
|
103
102
|
return cancelledOpening(state, opening);
|
|
104
103
|
state.project = opening.project;
|
|
105
|
-
state.
|
|
104
|
+
state.release = opening.release;
|
|
106
105
|
delete state.pending;
|
|
107
106
|
return success({ project, baseline: baseline.commit, ...listed.data });
|
|
108
107
|
}
|
|
@@ -14,6 +14,7 @@ export declare const NoteMetadataSchema: Type.TObject<{
|
|
|
14
14
|
updated_at: Type.TString;
|
|
15
15
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
16
16
|
project: Type.TOptional<Type.TString>;
|
|
17
|
+
description: Type.TOptional<Type.TString>;
|
|
17
18
|
extra: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
18
19
|
pinned: Type.TBoolean;
|
|
19
20
|
budget: Type.TInteger;
|
|
@@ -41,6 +42,7 @@ export declare const NoteIdentitySchema: {
|
|
|
41
42
|
export declare const ListedFileSchema: Type.TObject<{
|
|
42
43
|
updated_at: Type.TString;
|
|
43
44
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
45
|
+
description: Type.TOptional<Type.TString>;
|
|
44
46
|
warnings: Type.TArray<Type.TString>;
|
|
45
47
|
pinned: Type.TBoolean;
|
|
46
48
|
budget: Type.TInteger;
|
|
@@ -99,6 +101,7 @@ export declare const NotesReadDataSchema: Type.TObject<{
|
|
|
99
101
|
updated_at: Type.TString;
|
|
100
102
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
101
103
|
project: Type.TOptional<Type.TString>;
|
|
104
|
+
description: Type.TOptional<Type.TString>;
|
|
102
105
|
extra: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
103
106
|
pinned: Type.TBoolean;
|
|
104
107
|
budget: Type.TInteger;
|
|
@@ -125,6 +128,7 @@ export declare const NotesListDataSchema: Type.TObject<{
|
|
|
125
128
|
more_matches: Type.TOptional<Type.TInteger>;
|
|
126
129
|
updated_at: Type.TString;
|
|
127
130
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
131
|
+
description: Type.TOptional<Type.TString>;
|
|
128
132
|
warnings: Type.TArray<Type.TString>;
|
|
129
133
|
pinned: Type.TBoolean;
|
|
130
134
|
budget: Type.TInteger;
|
|
@@ -159,6 +163,7 @@ export declare const notesWriteParameters: Type.TObject<{
|
|
|
159
163
|
address: Type.TString;
|
|
160
164
|
content: Type.TString;
|
|
161
165
|
origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
|
|
166
|
+
description: Type.TOptional<Type.TString>;
|
|
162
167
|
}>;
|
|
163
168
|
export declare const notesWrite: {
|
|
164
169
|
readonly name: "notes_write";
|
|
@@ -172,6 +177,7 @@ export declare const notesWrite: {
|
|
|
172
177
|
address: Type.TString;
|
|
173
178
|
content: Type.TString;
|
|
174
179
|
origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
|
|
180
|
+
description: Type.TOptional<Type.TString>;
|
|
175
181
|
}>;
|
|
176
182
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
177
183
|
outcome: Type.TUnion<[Type.TLiteral<"created">, Type.TLiteral<"overwrote">, Type.TLiteral<"uncrumpled">]>;
|
|
@@ -208,6 +214,7 @@ export declare const notesUpdateParameters: Type.TObject<{
|
|
|
208
214
|
newText: Type.TString;
|
|
209
215
|
}>>>;
|
|
210
216
|
origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
|
|
217
|
+
description: Type.TOptional<Type.TString>;
|
|
211
218
|
}>;
|
|
212
219
|
export declare const notesUpdate: {
|
|
213
220
|
readonly name: "notes_update";
|
|
@@ -227,6 +234,7 @@ export declare const notesUpdate: {
|
|
|
227
234
|
newText: Type.TString;
|
|
228
235
|
}>>>;
|
|
229
236
|
origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
|
|
237
|
+
description: Type.TOptional<Type.TString>;
|
|
230
238
|
}>;
|
|
231
239
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
232
240
|
change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
|
|
@@ -277,6 +285,7 @@ export declare const notesRead: {
|
|
|
277
285
|
updated_at: Type.TString;
|
|
278
286
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
279
287
|
project: Type.TOptional<Type.TString>;
|
|
288
|
+
description: Type.TOptional<Type.TString>;
|
|
280
289
|
extra: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
281
290
|
pinned: Type.TBoolean;
|
|
282
291
|
budget: Type.TInteger;
|
|
@@ -333,6 +342,7 @@ export declare const notesList: {
|
|
|
333
342
|
more_matches: Type.TOptional<Type.TInteger>;
|
|
334
343
|
updated_at: Type.TString;
|
|
335
344
|
crumpled_at: Type.TOptional<Type.TString>;
|
|
345
|
+
description: Type.TOptional<Type.TString>;
|
|
336
346
|
warnings: Type.TArray<Type.TString>;
|
|
337
347
|
pinned: Type.TBoolean;
|
|
338
348
|
budget: Type.TInteger;
|
package/dist/src/tools/notes.js
CHANGED
|
@@ -15,8 +15,9 @@ const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal(
|
|
|
15
15
|
const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
|
|
16
16
|
description: "Whose handwriting: user, self, or external. Leave it out to keep what's there.",
|
|
17
17
|
}));
|
|
18
|
+
const DESCRIPTION_PARAMETER = Type.Optional(Type.String({ description: "One-line summary of what's inside and when to open it (max 160 chars). Empty string clears it." }));
|
|
18
19
|
const POLICY_PARAMETERS = {
|
|
19
|
-
pinned: Type.Optional(Type.Boolean({ description: "Tape the page inside the cover: read whole at every wake-up. Five per notebook, CHEATSHEET
|
|
20
|
+
pinned: Type.Optional(Type.Boolean({ description: "Tape the page inside the cover: read whole at every wake-up. Five per notebook, CHEATSHEET included." })),
|
|
20
21
|
budget: Type.Optional(Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, description: "How much paper the page gets. Writing past it still saves, with a warning. A page over budget gets boiled down: stale lines out, repeats merged, the rest said shorter. More paper is for a page already boiled down that still needs the room." })),
|
|
21
22
|
readonly: Type.Optional(Type.Boolean({ description: "A paperclip that keeps your own hands off. `false` takes it off — same call is fine." })),
|
|
22
23
|
};
|
|
@@ -36,7 +37,7 @@ function withWarnings(text, data) {
|
|
|
36
37
|
const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "`true` balls the page up: gone from list and search, still readable. `false` smooths it flat again." }));
|
|
37
38
|
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "Only the crumpled balls." }));
|
|
38
39
|
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "How many pages at most." }));
|
|
39
|
-
const GLOB_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Which drawers to open. Leave it out for this session and your current notebooks. `@project/**` one shelf · `
|
|
40
|
+
const GLOB_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Which drawers to open. Leave it out for this session and your current notebooks. `@project/**` one shelf · `CHEATSHEET.md` that page in every notebook · `**` everything · `@sessions/*/**` every session." }));
|
|
40
41
|
const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
|
|
41
42
|
const ADDRESS_PARAMETER = Type.String({ description: "Which drawer the page sits in. `plan.md` — this session's desk, cleared when it ends. `@project/` this project's shelf · `@human/` your human's file · `@self/` your own notebook · `@model/` your brain's. `@projects/<name>/`, `@sessions/<id>/`, `@agents/<name>/`, `@models/<name>/` — someone else's shelf: read only. Paper, not files: hand one to read/write/edit/bash and a real `@project` folder is born." });
|
|
42
43
|
/**
|
|
@@ -54,7 +55,7 @@ export function failureOf(error) {
|
|
|
54
55
|
throw error;
|
|
55
56
|
}
|
|
56
57
|
/** Metadata keys this layer normalizes; everything else is exposed verbatim under `extra`. */
|
|
57
|
-
const NORMALIZED_META_KEYS = new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project", "pinned", "budget", "readonly"]);
|
|
58
|
+
const NORMALIZED_META_KEYS = new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project", "pinned", "budget", "readonly", "description"]);
|
|
58
59
|
/** One unrecognized entry, and the verbatim extras together, are bounded so `extra` cannot outgrow the read. */
|
|
59
60
|
const MAX_METADATA_ENTRY_BYTES = 1024;
|
|
60
61
|
const MAX_METADATA_VERBATIM_BYTES = 2048;
|
|
@@ -67,6 +68,7 @@ export const NoteMetadataSchema = Type.Object({
|
|
|
67
68
|
updated_at: Type.String(),
|
|
68
69
|
crumpled_at: Type.Optional(Type.String()),
|
|
69
70
|
project: Type.Optional(Type.String()),
|
|
71
|
+
description: Type.Optional(Type.String()),
|
|
70
72
|
extra: Type.Record(Type.String(), Type.Unknown()),
|
|
71
73
|
}, { additionalProperties: false });
|
|
72
74
|
/** Normalize known metadata and bound extras, naming an oversized value instead of hiding it. */
|
|
@@ -99,6 +101,7 @@ function noteMetadata(meta, address) {
|
|
|
99
101
|
updated_at: localIso(meta.updatedAt),
|
|
100
102
|
...(typeof meta.crumpledAt === "string" ? { crumpled_at: meta.crumpledAt } : {}),
|
|
101
103
|
...(typeof meta.project === "string" ? { project: meta.project } : {}),
|
|
104
|
+
...(typeof meta.description === "string" ? { description: meta.description } : {}),
|
|
102
105
|
extra,
|
|
103
106
|
};
|
|
104
107
|
}
|
|
@@ -110,6 +113,7 @@ function renderMetadata(metadata) {
|
|
|
110
113
|
`updated ${metadata.updated_at}`,
|
|
111
114
|
...(metadata.crumpled_at === undefined ? [] : [`crumpled ${metadata.crumpled_at}`]),
|
|
112
115
|
...(metadata.project === undefined ? [] : [`project ${metadata.project}`]),
|
|
116
|
+
...(metadata.description === undefined ? [] : [`description ${metadata.description}`]),
|
|
113
117
|
];
|
|
114
118
|
const extra = Object.keys(metadata.extra);
|
|
115
119
|
if (extra.length > 0)
|
|
@@ -142,6 +146,7 @@ export const ListedFileSchema = Type.Object({
|
|
|
142
146
|
...WarningsSchema,
|
|
143
147
|
updated_at: Type.String(),
|
|
144
148
|
crumpled_at: Type.Optional(Type.String()),
|
|
149
|
+
description: Type.Optional(Type.String()),
|
|
145
150
|
}, { additionalProperties: false });
|
|
146
151
|
const MatchSchema = Type.Object({
|
|
147
152
|
line: Type.Integer(),
|
|
@@ -203,9 +208,9 @@ export function snapshot(rows, limit, status, renderData, shrink) {
|
|
|
203
208
|
}
|
|
204
209
|
export function listedFile(row, identity) {
|
|
205
210
|
const policy = policyAt(row.meta, row.address);
|
|
206
|
-
return { ...noteIdentity(identity, row.address), ...policy, warnings: row.warnings ?? (row.body === undefined ? [] : noteBudgetWarnings(row.body, policy)), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
|
|
211
|
+
return { ...noteIdentity(identity, row.address), ...policy, warnings: row.warnings ?? (row.body === undefined ? [] : noteBudgetWarnings(row.body, policy)), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }), ...(typeof row.meta.description === "string" ? { description: row.meta.description } : {}) };
|
|
207
212
|
}
|
|
208
|
-
export const notesWriteParameters = Type.Object({ address: ADDRESS_PARAMETER, content: Type.String({ description: "The whole page." }), origin: ORIGIN, ...POLICY_PARAMETERS, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
213
|
+
export const notesWriteParameters = Type.Object({ address: ADDRESS_PARAMETER, content: Type.String({ description: "The whole page." }), origin: ORIGIN, description: DESCRIPTION_PARAMETER, ...POLICY_PARAMETERS, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
209
214
|
function renderWriteData(data) {
|
|
210
215
|
return withWarnings(`${data.outcome} ${renderIdentity(data)} | ${renderPolicy(data)}`, data);
|
|
211
216
|
}
|
|
@@ -216,7 +221,7 @@ export const notesWrite = {
|
|
|
216
221
|
async execute(params, context) {
|
|
217
222
|
try {
|
|
218
223
|
const identity = notesIdentityForCall(context, params.cwd);
|
|
219
|
-
const { outcome, meta, warnings } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin, pinned: params.pinned, budget: params.budget, readonly: params.readonly });
|
|
224
|
+
const { outcome, meta, warnings } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin, description: params.description, pinned: params.pinned, budget: params.budget, readonly: params.readonly });
|
|
220
225
|
return success({ ...noteIdentity(identity, params.address), outcome, ...policyAt(meta, params.address), warnings });
|
|
221
226
|
}
|
|
222
227
|
catch (error) {
|
|
@@ -229,6 +234,7 @@ export const notesUpdateParameters = Type.Object({
|
|
|
229
234
|
address: ADDRESS_PARAMETER,
|
|
230
235
|
edits: Type.Optional(Type.Array(Type.Object({ oldText: Type.String({ description: "The passage as it stands on the page." }), newText: Type.String({ description: "What goes in its place." }) }, { additionalProperties: false }), { description: "Pen strokes, in order. Each `oldText` is the exact passage — same case, found once — and `newText` is what goes in its place." })),
|
|
231
236
|
origin: ORIGIN,
|
|
237
|
+
description: DESCRIPTION_PARAMETER,
|
|
232
238
|
...POLICY_PARAMETERS,
|
|
233
239
|
crumpled: CRUMPLED_PARAMETER,
|
|
234
240
|
replace_all: Type.Optional(Type.Boolean({ description: "Strike every copy of `oldText`, not just one." })),
|
|
@@ -251,7 +257,7 @@ export const notesUpdate = {
|
|
|
251
257
|
const store = createNotesStore(identity);
|
|
252
258
|
// Empty filler is not a request: models that pass every parameter get the edit path.
|
|
253
259
|
const renameTo = params.rename_to === "" ? undefined : params.rename_to;
|
|
254
|
-
const { change, moved, meta, warnings } = await store.update(params.address, params.edits, { origin: params.origin, pinned: params.pinned, budget: params.budget, readonly: params.readonly, crumpled: params.crumpled, replaceAll: params.replace_all, renameTo });
|
|
260
|
+
const { change, moved, meta, warnings } = await store.update(params.address, params.edits, { origin: params.origin, description: params.description, pinned: params.pinned, budget: params.budget, readonly: params.readonly, crumpled: params.crumpled, replaceAll: params.replace_all, renameTo });
|
|
255
261
|
onChange?.(change);
|
|
256
262
|
const from = noteIdentity(identity, params.address).address;
|
|
257
263
|
const to = noteIdentity(identity, renameTo ?? params.address);
|
|
@@ -302,7 +308,7 @@ export const notesListParameters = Type.Object({
|
|
|
302
308
|
export function renderListData(data) {
|
|
303
309
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
304
310
|
for (const file of data.files) {
|
|
305
|
-
const fields = [`- ${renderIdentity(file)}`, renderPolicy(file), `updated ${file.updated_at}`];
|
|
311
|
+
const fields = [file.description === undefined ? `- ${renderIdentity(file)}` : `- ${renderIdentity(file)} — ${file.description}`, renderPolicy(file), `updated ${file.updated_at}`];
|
|
306
312
|
if (file.last_accessed !== undefined)
|
|
307
313
|
fields.push(`accessed ${file.last_accessed}`);
|
|
308
314
|
if (file.crumpled_at !== undefined)
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
-
import { existsSync, mkdirSync, mkdtempSync,
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
3
|
import fs from "node:fs/promises";
|
|
4
4
|
import { syncBuiltinESMExports } from "node:module";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import test from "node:test";
|
|
8
|
-
import {
|
|
8
|
+
import { once } from "node:events";
|
|
9
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
9
10
|
import { Check } from "typebox/value";
|
|
10
|
-
import { createNotesStore } from "../src/notes/index.js";
|
|
11
|
+
import { createNotesStore, projectKey } from "../src/notes/index.js";
|
|
11
12
|
import { abandonDream, dreamBegin, dreamEnd, dreamForget, dreamingIdentity } from "../src/tools/dream.js";
|
|
12
13
|
import { notesRead, notesUpdate, notesWrite } from "../src/tools/notes.js";
|
|
13
14
|
import { notesToolContext } from "../src/tools/notes-context.js";
|
|
@@ -43,7 +44,6 @@ test("a dream opens one other project, writes its notes, deletes only crumpled o
|
|
|
43
44
|
assert.ok(begun.data.files.every(f => typeof f.last_accessed === "string"), "the dream's list shows each note's last access");
|
|
44
45
|
assert.match(dreamBegin.render(begun), /\| accessed /);
|
|
45
46
|
assert.equal((await dreamBegin.execute({}, me, state)).ok, false, "only one dream at a time");
|
|
46
|
-
assert.ok(existsSync(join(home, ".dream.lock")), "the notes-home lock is held");
|
|
47
47
|
assert.equal((await dreamBegin.execute({ project: "beta" }, as("other", "alpha"), {})).ok, false, "another session can't dream the same project");
|
|
48
48
|
assert.ok((await notesWrite.execute({ address: "@projects/beta/rule", content: "merged" }, ident())).ok);
|
|
49
49
|
assert.ok((await notesUpdate.execute({ address: "@sessions/b1/checkpoint", edits: [{ oldText: "old", newText: "new" }] }, ident())).ok);
|
|
@@ -60,13 +60,12 @@ test("a dream opens one other project, writes its notes, deletes only crumpled o
|
|
|
60
60
|
assert.equal(existsSync(join(home, "pi", "session", "b2", "trash.md")), false);
|
|
61
61
|
const ended = await dreamEnd.execute({}, me, state);
|
|
62
62
|
assert.ok(ended.ok && ended.data.commit && ended.data.commit !== begun.data.baseline, "dream_end commits the changes");
|
|
63
|
-
assert.equal(existsSync(join(home, ".dream.lock")), false, "the lock is released");
|
|
64
63
|
assert.equal(execFileSync("git", ["status", "--porcelain"], { cwd: home, encoding: "utf8" }), "", "the audit leaves a clean tree");
|
|
65
64
|
assert.equal((await notesWrite.execute({ address: "@projects/beta/rule", content: "x" }, ident())).ok, false, "closed again");
|
|
66
65
|
assert.equal((await dreamEnd.execute({}, me, state)).ok, false);
|
|
67
66
|
});
|
|
68
67
|
test("pending openings exclude concurrent begins and stale cleanup preserves a newer generation", async (t) => {
|
|
69
|
-
const {
|
|
68
|
+
const { as } = fixture(t);
|
|
70
69
|
const me = as("s", "alpha");
|
|
71
70
|
const state = {};
|
|
72
71
|
const old = dreamBegin.execute({}, me, state);
|
|
@@ -78,20 +77,18 @@ test("pending openings exclude concurrent begins and stale cleanup preserves a n
|
|
|
78
77
|
assert.ok(!concurrent.ok && concurrent.error.code === "already_dreaming");
|
|
79
78
|
assert.equal(state.pending, pending);
|
|
80
79
|
abandonDream(state);
|
|
81
|
-
assert.equal(existsSync(join(home, ".dream.lock")), false);
|
|
82
80
|
const newer = dreamBegin.execute({ project: "beta" }, me, state);
|
|
83
81
|
const newerPending = state.pending;
|
|
84
82
|
assert.ok(newerPending && newerPending.generation > pending.generation);
|
|
85
|
-
const token = readFileSync(join(home, ".dream.lock"), "utf8");
|
|
86
83
|
const cancelled = await old;
|
|
87
84
|
assert.ok(!cancelled.ok && cancelled.error.code === "cancelled");
|
|
88
|
-
|
|
85
|
+
const refused = await dreamBegin.execute({}, me, {});
|
|
86
|
+
assert.ok(!refused.ok && refused.error.code === "already_dreaming");
|
|
89
87
|
const begun = await newer;
|
|
90
88
|
assert.ok(begun.ok);
|
|
91
89
|
assert.equal(state.project, "beta");
|
|
92
90
|
assert.equal(state.pending, undefined);
|
|
93
91
|
assert.ok((await dreamEnd.execute({}, me, state)).ok);
|
|
94
|
-
assert.equal(existsSync(join(home, ".dream.lock")), false);
|
|
95
92
|
});
|
|
96
93
|
test("a thrown scan releases pending ownership before propagating the defect", async (t) => {
|
|
97
94
|
const { home, as } = fixture(t);
|
|
@@ -106,10 +103,9 @@ test("a thrown scan releases pending ownership before propagating the defect", a
|
|
|
106
103
|
syncBuiltinESMExports();
|
|
107
104
|
t.after(() => { t.mock.restoreAll(); syncBuiltinESMExports(); });
|
|
108
105
|
await assert.rejects(dreamBegin.execute({}, as("s", "alpha"), state), error => error === sentinel);
|
|
109
|
-
assert.equal(existsSync(join(home, ".dream.lock")), false);
|
|
110
106
|
assert.equal(state.pending, undefined);
|
|
111
107
|
assert.equal(state.project, undefined);
|
|
112
|
-
assert.equal(state.
|
|
108
|
+
assert.equal(state.release, undefined);
|
|
113
109
|
t.mock.restoreAll();
|
|
114
110
|
syncBuiltinESMExports();
|
|
115
111
|
assert.ok((await dreamBegin.execute({}, as("s", "alpha"), state)).ok, "the same state can retry after a failed scan");
|
|
@@ -122,10 +118,9 @@ test("baseline failure releases pending ownership and permits a retry", async (t
|
|
|
122
118
|
writeFileSync(join(home, ".git"), "not a Git repository");
|
|
123
119
|
const failed = await dreamBegin.execute({}, me, state);
|
|
124
120
|
assert.ok(!failed.ok && failed.error.code === "audit_failed");
|
|
125
|
-
assert.equal(existsSync(join(home, ".dream.lock")), false);
|
|
126
121
|
assert.equal(state.pending, undefined);
|
|
127
122
|
assert.equal(state.project, undefined);
|
|
128
|
-
assert.equal(state.
|
|
123
|
+
assert.equal(state.release, undefined);
|
|
129
124
|
const ended = await dreamEnd.execute({}, me, state);
|
|
130
125
|
assert.ok(!ended.ok && ended.error.code === "not_dreaming");
|
|
131
126
|
rmSync(join(home, ".git"));
|
|
@@ -220,11 +215,41 @@ test("named-project mutation receipts carry their project metadata and fit their
|
|
|
220
215
|
assert.equal(Check(dreamForget.outputSchema, forgotten.data), true, "dream_forget accepts its own named-project receipt");
|
|
221
216
|
assert.ok((await dreamEnd.execute({}, me, state)).ok);
|
|
222
217
|
});
|
|
218
|
+
test("a killed dream releases its lock without blocking project claims or note writes", { timeout: 20_000 }, async (t) => {
|
|
219
|
+
const { as } = fixture(t);
|
|
220
|
+
const script = `
|
|
221
|
+
import { dreamBegin } from ${JSON.stringify(new URL("../src/tools/dream.js", import.meta.url).href)};
|
|
222
|
+
globalThis.dream = {};
|
|
223
|
+
const result = await dreamBegin.execute({}, JSON.parse(process.argv[1]), globalThis.dream);
|
|
224
|
+
if (!result.ok) throw new Error(result.error.message);
|
|
225
|
+
process.send("open");
|
|
226
|
+
setInterval(() => {}, 60000);
|
|
227
|
+
`;
|
|
228
|
+
const child = spawn(process.execPath, ["--input-type=module", "-e", script, JSON.stringify(as("child", "alpha"))], { stdio: ["ignore", "ignore", "inherit", "ipc"] });
|
|
229
|
+
t.after(() => { child.kill("SIGKILL"); });
|
|
230
|
+
const exit = once(child, "exit");
|
|
231
|
+
assert.equal(await Promise.race([once(child, "message").then(([message]) => message), exit]), "open");
|
|
232
|
+
const next = as("next", "beta");
|
|
233
|
+
const state = {};
|
|
234
|
+
const refused = await dreamBegin.execute({}, next, state);
|
|
235
|
+
assert.ok(!refused.ok && refused.error.code === "already_dreaming");
|
|
236
|
+
assert.equal(projectKey("/work/another", next.home), "another");
|
|
237
|
+
await createNotesStore(next).write("@project/live", "still writable");
|
|
238
|
+
assert.ok(child.kill("SIGKILL"));
|
|
239
|
+
assert.deepEqual(await exit, [null, "SIGKILL"]);
|
|
240
|
+
assert.ok((await dreamBegin.execute({}, next, state)).ok);
|
|
241
|
+
assert.equal((await createNotesStore(next).read("@project/live"))?.body, "still writable");
|
|
242
|
+
assert.ok((await dreamEnd.execute({}, next, state)).ok);
|
|
243
|
+
});
|
|
223
244
|
test("a notes-home lock prevents interleaved dream Git audits", async (t) => {
|
|
224
245
|
const { home, as } = fixture(t);
|
|
225
246
|
const alpha = as("alpha-session", "alpha"), beta = as("beta-session", "beta");
|
|
226
247
|
await createNotesStore(alpha).write("@project/note", "before alpha");
|
|
227
248
|
await createNotesStore(beta).write("@project/note", "before beta");
|
|
249
|
+
// A crashed project claim may leave a staged marker. Neither it nor the lock DB belongs in Git.
|
|
250
|
+
const staged = mkdtempSync(join(home, ".project-pending-"));
|
|
251
|
+
writeFileSync(join(staged, ".project"), "{}");
|
|
252
|
+
projectKey("/work/another", home);
|
|
228
253
|
const alphaState = {}, betaState = {};
|
|
229
254
|
const begun = await dreamBegin.execute({ project: "alpha" }, alpha, alphaState);
|
|
230
255
|
assert.ok(begun.ok);
|
|
@@ -237,6 +262,9 @@ test("a notes-home lock prevents interleaved dream Git audits", async (t) => {
|
|
|
237
262
|
const ended = await dreamEnd.execute({}, alpha, alphaState);
|
|
238
263
|
assert.ok(ended.ok && ended.data.commit !== undefined);
|
|
239
264
|
assert.notEqual(ended.data.commit, begun.data.baseline);
|
|
265
|
+
for (const commit of [begun.data.baseline, ended.data.commit]) {
|
|
266
|
+
assert.equal(execFileSync("git", ["ls-tree", "--name-only", commit], { cwd: home, encoding: "utf8" }), "project\n");
|
|
267
|
+
}
|
|
240
268
|
const changed = execFileSync("git", ["show", "--format=", "--name-only", ended.data.commit], { cwd: home, encoding: "utf8" });
|
|
241
269
|
assert.match(changed, /project\/alpha\/note\.md/);
|
|
242
270
|
assert.doesNotMatch(changed, /project\/beta\/note\.md/);
|
|
@@ -50,7 +50,7 @@ test("shared boot uses only explicit identity, loader, captured time and logical
|
|
|
50
50
|
const block = { agentName: notesIdentity.agent, modelName: notesIdentity.model, tree: { trunk: "test", windows: [{ shortName: "root", isCurrent: false }, { shortName: "next", isCurrent: true }] }, notes: snapshot, tools };
|
|
51
51
|
const rendered = renderBootBlock(block);
|
|
52
52
|
assert.equal(renderBootBlock(block), rendered);
|
|
53
|
-
assert.ok(rendered.includes("
|
|
53
|
+
assert.ok(rendered.includes(" checkpoint.md · 1m ago — 😀"), "an index entry is the locator plus the note's own first line");
|
|
54
54
|
assert.ok(rendered.includes("Try `memo_list` again"));
|
|
55
55
|
assert.equal(/notes_\*|notes_list|history_\*|history_list|history_read|get_context_remaining|empty_brain/.test(rendered), false);
|
|
56
56
|
});
|
|
@@ -22,7 +22,7 @@ function data(outcome) {
|
|
|
22
22
|
const refused = (code) => (error) => error instanceof NoteError && error.code === code;
|
|
23
23
|
async function fillPins(notes, prefix = "") {
|
|
24
24
|
for (const name of ["CHEATSHEET.md", "MAP.md", "one.md", "two.md", "three.md"]) {
|
|
25
|
-
await notes.write(`${prefix}${name}`, `body ${name}`,
|
|
25
|
+
await notes.write(`${prefix}${name}`, `body ${name}`, { pinned: true });
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
async function boot(identity) {
|
|
@@ -37,7 +37,8 @@ test("frontmatter policy round-trips without materializing defaults; arbitrary e
|
|
|
37
37
|
await notes.write("MAP", "index");
|
|
38
38
|
const defaults = (await notes.read("MAP")).meta;
|
|
39
39
|
assert.equal(defaults.pinned, undefined);
|
|
40
|
-
assert.deepEqual(effectiveNotePolicy(defaults, "MAP.md"), { pinned:
|
|
40
|
+
assert.deepEqual(effectiveNotePolicy(defaults, "MAP.md"), { pinned: false, budget: 4096, readonly: false });
|
|
41
|
+
assert.deepEqual(effectiveNotePolicy(defaults, "CHEATSHEET.md"), { pinned: true, budget: 2048, readonly: false });
|
|
41
42
|
assert.equal(effectiveNotePolicy(defaults, "nested/MAP.md").pinned, false);
|
|
42
43
|
writeFileSync(file("MAP.md"), readFileSync(file("MAP.md"), "utf8").replace("\n---\n\n", "\npinned: false\nbudget: 3000\nreadonly: true\ncustom: {\"nested\":[1,\"two\"]}\n---\n\n"));
|
|
43
44
|
const meta = (await notes.read("MAP")).meta;
|
|
@@ -53,7 +54,7 @@ test("frontmatter policy round-trips without materializing defaults; arbitrary e
|
|
|
53
54
|
test("default budgets distinguish root index pages from ordinary notes, independently of pinning", async (t) => {
|
|
54
55
|
const { context, notes } = fixture(t);
|
|
55
56
|
for (const [address, budget, pinned] of [
|
|
56
|
-
["MAP",
|
|
57
|
+
["MAP", 4096, undefined],
|
|
57
58
|
["CHEATSHEET", 2048, undefined],
|
|
58
59
|
["ordinary", 4096, undefined],
|
|
59
60
|
["custom-pin", 4096, true],
|
|
@@ -206,8 +207,8 @@ test("pin admission serializes across store instances without blocking reads or
|
|
|
206
207
|
});
|
|
207
208
|
test("moves resolve absent policy at the new path, preserving explicit false/true", async (t) => {
|
|
208
209
|
const { notes, file } = fixture(t);
|
|
209
|
-
await notes.write("
|
|
210
|
-
await notes.rename("
|
|
210
|
+
await notes.write("CHEATSHEET", "default");
|
|
211
|
+
await notes.rename("CHEATSHEET", "ordinary");
|
|
211
212
|
assert.deepEqual(effectiveNotePolicy((await notes.read("ordinary")).meta, "ordinary.md"), { pinned: false, budget: 4096, readonly: false });
|
|
212
213
|
await notes.rename("ordinary", "CHEATSHEET");
|
|
213
214
|
assert.equal(effectiveNotePolicy((await notes.read("CHEATSHEET")).meta, "CHEATSHEET.md").pinned, true);
|
|
@@ -219,10 +220,10 @@ test("moves resolve absent policy at the new path, preserving explicit false/tru
|
|
|
219
220
|
for (let n = 0; n < 4; n++)
|
|
220
221
|
await notes.write(`extra-${n}`, "pin", { pinned: true });
|
|
221
222
|
await notes.write("candidate", "candidate");
|
|
222
|
-
await assert.rejects(() => notes.rename("candidate", "
|
|
223
|
+
await assert.rejects(() => notes.rename("candidate", "CHEATSHEET"), refused("pin_limit"));
|
|
223
224
|
assert.equal((await notes.read("candidate")).body, "candidate");
|
|
224
|
-
await notes.update("candidate", undefined, { renameTo: "
|
|
225
|
-
assert.equal(effectiveNotePolicy((await notes.read("
|
|
225
|
+
await notes.update("candidate", undefined, { renameTo: "CHEATSHEET", pinned: false });
|
|
226
|
+
assert.equal(effectiveNotePolicy((await notes.read("CHEATSHEET")).meta, "CHEATSHEET.md").pinned, false);
|
|
226
227
|
});
|
|
227
228
|
test("boot uses metadata pins, full bodies, explicit false and visible legacy over-cap omissions", async (t) => {
|
|
228
229
|
const { identity, notes, file } = fixture(t);
|
|
@@ -248,3 +249,116 @@ test("boot uses metadata pins, full bodies, explicit false and visible legacy ov
|
|
|
248
249
|
assert.equal(rendered.includes("OMITTED_PIN_BODY"), false);
|
|
249
250
|
assert.ok(rendered.includes("TAIL_IS_HERE"));
|
|
250
251
|
});
|
|
252
|
+
test("MAP.md is an ordinary note by default while CHEATSHEET.md stays the one default pin", async (t) => {
|
|
253
|
+
const { notes, context } = fixture(t);
|
|
254
|
+
await notes.write("MAP", "legacy hand-written index");
|
|
255
|
+
await notes.write("CHEATSHEET", "rules");
|
|
256
|
+
const map = (await notes.read("MAP")).meta;
|
|
257
|
+
const cheatsheet = (await notes.read("CHEATSHEET")).meta;
|
|
258
|
+
assert.deepEqual(effectiveNotePolicy(map, "MAP.md"), { pinned: false, budget: 4096, readonly: false });
|
|
259
|
+
assert.deepEqual(effectiveNotePolicy(cheatsheet, "CHEATSHEET.md"), { pinned: true, budget: 2048, readonly: false });
|
|
260
|
+
await notes.rename("MAP", "moved-map");
|
|
261
|
+
assert.deepEqual(effectiveNotePolicy((await notes.read("moved-map")).meta, "moved-map.md"), { pinned: false, budget: 4096, readonly: false });
|
|
262
|
+
const listed = data(await notesList.execute({}, context));
|
|
263
|
+
assert.equal(listed.files.find(file => file.address === "CHEATSHEET.md")?.pinned, true);
|
|
264
|
+
assert.equal(listed.files.find(file => file.address === "moved-map.md")?.pinned, false, "MAP.md keeps no special role after a move");
|
|
265
|
+
});
|
|
266
|
+
test("description normalizes to one line, persists, renders in read and list, and clears on empty", async (t) => {
|
|
267
|
+
const { notes, file, context } = fixture(t);
|
|
268
|
+
const written = await notesWrite.execute({ address: "described", content: "body", description: " first\n\tsecond third " }, context);
|
|
269
|
+
assert.equal(written.ok, true);
|
|
270
|
+
assert.equal((await notes.read("described")).meta.description, "first second third");
|
|
271
|
+
assert.match(readFileSync(file("described.md"), "utf8"), /^description: "first second third"$/m);
|
|
272
|
+
const read = data(await notesRead.execute({ address: "described" }, context));
|
|
273
|
+
assert.equal(read.metadata.description, "first second third");
|
|
274
|
+
assert.equal("description" in read.metadata.extra, false, "description is normalized metadata, not an extra");
|
|
275
|
+
assert.match(notesRead.render(await notesRead.execute({ address: "described" }, context)), /description first second third/);
|
|
276
|
+
const listed = data(await notesList.execute({}, context));
|
|
277
|
+
assert.equal(listed.files.find(file => file.address === "described.md")?.description, "first second third");
|
|
278
|
+
assert.match(notesList.render(await notesList.execute({}, context)), /described\.md — first second third/);
|
|
279
|
+
// Omitting description on an edit keeps it; providing the same one is a valid no-op.
|
|
280
|
+
await notes.update("described", [{ oldText: "body", newText: "body two" }]);
|
|
281
|
+
assert.equal((await notes.read("described")).meta.description, "first second third");
|
|
282
|
+
const unchanged = data(await notesUpdate.execute({ address: "described", description: "first second third" }, context));
|
|
283
|
+
assert.equal(unchanged.change_kind, "none");
|
|
284
|
+
const changed = data(await notesUpdate.execute({ address: "described", description: "now this" }, context));
|
|
285
|
+
assert.equal(changed.change_kind, "metadata", "description alone is an operation");
|
|
286
|
+
assert.equal((await notes.read("described")).meta.description, "now this");
|
|
287
|
+
// An empty value clears the key; a whitespace-only value is empty too.
|
|
288
|
+
await notesUpdate.execute({ address: "described", description: " \n\t " }, context);
|
|
289
|
+
assert.equal((await notes.read("described")).meta.description, undefined);
|
|
290
|
+
assert.equal(/^description:/m.test(readFileSync(file("described.md"), "utf8")), false);
|
|
291
|
+
// Exactly 160 code points is accepted; 161 is refused naming the count and the limit.
|
|
292
|
+
await notes.write("max", "body", { description: "😀".repeat(160) });
|
|
293
|
+
assert.equal((await notes.read("max")).meta.description, "😀".repeat(160), "160 astral code points fit");
|
|
294
|
+
const tooLong = "😀".repeat(161);
|
|
295
|
+
for (const attempt of [
|
|
296
|
+
() => notesWrite.execute({ address: "too-long", content: "body", description: tooLong }, context),
|
|
297
|
+
() => notesUpdate.execute({ address: "described", description: tooLong }, context),
|
|
298
|
+
]) {
|
|
299
|
+
const refusal = await attempt();
|
|
300
|
+
assert.equal(refusal.ok, false);
|
|
301
|
+
if (!refusal.ok) {
|
|
302
|
+
assert.equal(refusal.error.code, "invalid_description");
|
|
303
|
+
assert.match(refusal.error.message, /161 characters; limit is 160/);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
assert.equal((await notes.read("too-long")), undefined, "a refused write saves nothing");
|
|
307
|
+
assert.equal((await notes.read("described")).meta.description, undefined, "a refused update leaves the note alone");
|
|
308
|
+
});
|
|
309
|
+
test("boot auto-indexes unpinned notes newest first with description, fallback title, and pinned/crumpled omissions", async (t) => {
|
|
310
|
+
const { identity, notes } = fixture(t);
|
|
311
|
+
await notes.write("CHEATSHEET", "rules");
|
|
312
|
+
await notes.write("described", "body", { description: "when to open this" });
|
|
313
|
+
await notes.write("heading", "# Heading title\nbody");
|
|
314
|
+
await notes.write("plain", "first line only\nsecond line");
|
|
315
|
+
await notes.write("hidden", "PINNED_BODY", { pinned: true });
|
|
316
|
+
await notes.write("gone", "CRUMPLED_BODY");
|
|
317
|
+
await notes.update("gone", undefined, { crumpled: true });
|
|
318
|
+
const rendered = await boot(identity);
|
|
319
|
+
assert.equal(rendered.includes("recent"), false, "the old recent label is gone");
|
|
320
|
+
assert.match(rendered, /^notes$/m, "the index follows pinned pages under one subheader");
|
|
321
|
+
assert.match(rendered, / {2}plain\.md · just now — first line only/);
|
|
322
|
+
assert.match(rendered, / {2}heading\.md · just now — Heading title/);
|
|
323
|
+
assert.match(rendered, / {2}described\.md · just now — when to open this/);
|
|
324
|
+
assert.ok(rendered.indexOf("plain.md ·") < rendered.indexOf("heading.md ·"), "newest unpinned note leads");
|
|
325
|
+
assert.ok(rendered.indexOf("heading.md ·") < rendered.indexOf("described.md ·"));
|
|
326
|
+
assert.equal(rendered.includes("hidden.md ·"), false, "pinned pages do not repeat in the index");
|
|
327
|
+
assert.equal(rendered.includes("gone.md ·"), false, "crumpled pages do not index");
|
|
328
|
+
assert.equal(rendered.includes("PINNED_BODY"), true, "pinned pages still load whole");
|
|
329
|
+
assert.equal(rendered.includes("CRUMPLED_BODY"), false);
|
|
330
|
+
// A shelf with no pinned pages drops the redundant subheader and still indexes.
|
|
331
|
+
await notes.update("CHEATSHEET", undefined, { pinned: false, crumpled: true });
|
|
332
|
+
await notes.update("hidden", undefined, { crumpled: true });
|
|
333
|
+
const bare = await boot(identity);
|
|
334
|
+
assert.equal(/^notes$/m.test(bare), false);
|
|
335
|
+
assert.match(bare, / {2}plain\.md · just now — first line only/);
|
|
336
|
+
});
|
|
337
|
+
test("boot shelf index enforces entry and character caps with an explicit omission marker", async (t) => {
|
|
338
|
+
const { identity, notes } = fixture(t);
|
|
339
|
+
for (let index = 0; index < 26; index++)
|
|
340
|
+
await notes.write(`bulk-${index}`, "body", { description: "d" });
|
|
341
|
+
const entries = await boot(identity);
|
|
342
|
+
assert.equal(entries.split(" · just now — d").length - 1, 25, "only 25 entries fit");
|
|
343
|
+
assert.match(entries, / {2}… and 1 more \(use notes_list\)/);
|
|
344
|
+
assert.equal(entries.includes("bulk-0.md ·"), false, "the oldest entry is the one left out");
|
|
345
|
+
const wide = fixture(t);
|
|
346
|
+
for (let index = 0; index < 25; index++)
|
|
347
|
+
await wide.notes.write(`big-${index}`, "body", { description: `${index}`.padStart(2, "0") + "x".repeat(158) });
|
|
348
|
+
const capped = await boot(wide.identity);
|
|
349
|
+
const shown = capped.split("big-").length - 1;
|
|
350
|
+
assert.ok(shown > 0 && shown < 25, `the character cap cuts the list (${shown} shown)`);
|
|
351
|
+
assert.match(capped, /… and \d+ more \(use notes_list\)/);
|
|
352
|
+
assert.equal(capped.includes("big-00.md ·"), false, "the oldest page falls past the character cap");
|
|
353
|
+
});
|
|
354
|
+
test("a hand-edited oversized description never breaks boot and is cut for display", async (t) => {
|
|
355
|
+
const { identity, notes, file } = fixture(t);
|
|
356
|
+
await notes.write("long", "body");
|
|
357
|
+
const oversized = "z".repeat(200);
|
|
358
|
+
writeFileSync(file("long.md"), readFileSync(file("long.md"), "utf8").replace("\n---\n\n", `\ndescription: ${oversized}\n---\n\n`));
|
|
359
|
+
const snapshot = await loadNotesSnapshot(identity, Date.now());
|
|
360
|
+
assert.equal(snapshot.namespaces.get("session")?.find(row => row.path === "long.md")?.meta.description, oversized, "reads tolerate a hand-edited oversize value");
|
|
361
|
+
const rendered = await boot(identity);
|
|
362
|
+
assert.ok(rendered.includes(`${"z".repeat(160)}…`), "display truncates at 160 code points");
|
|
363
|
+
assert.equal(rendered.includes(oversized), false);
|
|
364
|
+
});
|