notesoup 0.60.1 → 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.
Files changed (40) hide show
  1. package/README.md +5 -4
  2. package/dist/src/boot/render.d.ts +5 -0
  3. package/dist/src/boot/render.js +48 -19
  4. package/dist/src/boot/text.d.ts +1 -3
  5. package/dist/src/boot/text.js +10 -11
  6. package/dist/src/budget/text.d.ts +1 -1
  7. package/dist/src/budget/text.js +1 -1
  8. package/dist/src/notes/errors.d.ts +1 -1
  9. package/dist/src/notes/frontmatter.d.ts +6 -0
  10. package/dist/src/notes/frontmatter.js +17 -1
  11. package/dist/src/notes/policy.js +1 -1
  12. package/dist/src/notes/store.d.ts +2 -0
  13. package/dist/src/notes/store.js +30 -5
  14. package/dist/src/tools/dream.d.ts +2 -0
  15. package/dist/src/tools/notes.d.ts +10 -0
  16. package/dist/src/tools/notes.js +14 -8
  17. package/dist/test/host-neutral.test.js +1 -1
  18. package/dist/test/note-policy.test.js +122 -8
  19. package/docs/dsh.md +2 -2
  20. package/docs/notes-library.md +4 -4
  21. package/docs/reset-lifecycle.md +1 -1
  22. package/docs/tool-results.md +1 -1
  23. package/package.json +1 -1
  24. package/playbook.md +3 -3
  25. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  26. package/plugins/claude/dist/claude/helper.js +100 -45
  27. package/plugins/claude/playbook.md +3 -3
  28. package/plugins/claude/skills/dream/SKILL.md +2 -2
  29. package/plugins/claude/skills/memory/SKILL.md +1 -1
  30. package/plugins/codex/dist/codex/notesoup.js +99 -44
  31. package/skills/dream/SKILL.md +2 -2
  32. package/skills/memory/SKILL.md +1 -1
  33. package/src/boot/render.ts +48 -17
  34. package/src/boot/text.ts +10 -11
  35. package/src/budget/text.ts +1 -1
  36. package/src/notes/errors.ts +1 -1
  37. package/src/notes/frontmatter.ts +19 -1
  38. package/src/notes/policy.ts +1 -1
  39. package/src/notes/store.ts +25 -7
  40. package/src/tools/notes.ts +14 -8
@@ -5,7 +5,7 @@ export type NotePolicy = Required<NotePolicyFields>;
5
5
  export const DEFAULT_NOTE_BUDGET = 4096;
6
6
  export const MAX_PINNED_NOTES = 5;
7
7
  /** Defaults and ordering live here; no other layer assigns behavior by page name. */
8
- const DEFAULT_PINNED_PAGES = ["CHEATSHEET.md", "MAP.md"] as const;
8
+ const DEFAULT_PINNED_PAGES = ["CHEATSHEET.md"] as const;
9
9
 
10
10
  export function validateNotePolicy(fields: NotePolicyFields): void {
11
11
  for (const key of ["pinned", "readonly"] as const) {
@@ -8,7 +8,7 @@ import { isFilesystemError } from "./fs-error.js";
8
8
  import { snapshotNotesIdentity, type NotesIdentity } from "./identity.js";
9
9
  import { NoteError } from "./errors.js";
10
10
  import { MAX_NOTE_BYTES, MAX_NOTE_PATH_BYTES } from "./constants.js";
11
- import { isOrigin, localIso, parseNote, serializeNote, stripLeadingFrontmatter, type NoteMeta, type Origin } from "./frontmatter.js";
11
+ import { collapseDescription, isOrigin, localIso, MAX_DESCRIPTION_CHARS, parseNote, serializeNote, stripLeadingFrontmatter, type NoteMeta, type Origin } from "./frontmatter.js";
12
12
  import { namespaceSlugs, noteFileName, physicalPath, scopeDir, isSessionId, SLUG_PATTERN, type Scope } from "./paths.js";
13
13
  import { projectReceipt, type ProjectReceipt } from "./project-namespace.js";
14
14
  import { applyNotePolicy, assertNoteUnlocked, effectiveNotePolicy, MAX_PINNED_NOTES, noteBudgetWarnings, validateNotePolicy, type NotePolicyFields } from "./policy.js";
@@ -27,8 +27,8 @@ function writeStamp(): number {
27
27
  export type NoteMatch = { line: number; text: string; /** Code-point offset into the note body, not into the serialized file. */ offsetChars: number };
28
28
  export type NoteSearchRow = { address: string; scope: Scope; path: string; meta: NoteMeta; warnings: string[]; matches: NoteMatch[] };
29
29
  export type EditOperation = { oldText: string; newText: string };
30
- export type WriteOptions = NotePolicyFields & { origin?: Origin };
31
- export type EditOptions = NotePolicyFields & { origin?: Origin; crumpled?: boolean; replaceAll?: boolean; renameTo?: string };
30
+ export type WriteOptions = NotePolicyFields & { origin?: Origin; description?: string };
31
+ export type EditOptions = NotePolicyFields & { origin?: Origin; description?: string; crumpled?: boolean; replaceAll?: boolean; renameTo?: string };
32
32
  /** Omit glob for current notebooks. A pattern without `@` or `/` matches filenames at any depth. */
33
33
  export type NotesQuery = { glob?: string; crumpled?: boolean };
34
34
  /** A read exposes metadata and the pure body; the serialized frontmatter is never part of the body. */
@@ -188,6 +188,15 @@ function assertOrigin(value: unknown): Origin {
188
188
  return value;
189
189
  }
190
190
 
191
+ /** A description is one normalized line; empty clears it. Only the authored value is refused, never read. */
192
+ function normalizeDescription(value: string): string | undefined {
193
+ const collapsed = collapseDescription(value);
194
+ if (collapsed === undefined) return undefined;
195
+ const count = Array.from(collapsed).length;
196
+ if (count > MAX_DESCRIPTION_CHARS) throw new NoteError("invalid_description", `description is ${count} characters; limit is ${MAX_DESCRIPTION_CHARS}.`);
197
+ return collapsed;
198
+ }
199
+
191
200
  function assertWho(value: unknown, scope: Scope): string {
192
201
  if (typeof value !== "string" || !(scope === "session" ? isSessionId(value) : SLUG_PATTERN.test(value))) {
193
202
  throw new NoteError("invalid_scope", scope === "session" ? "session id must be a safe single directory component" : "who must be a canonical lowercase slug");
@@ -310,6 +319,7 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
310
319
  async function write(address: string, content: string, options: WriteOptions = {}): Promise<NoteWriteResult> {
311
320
  const stableOptions = { ...options };
312
321
  validateNotePolicy(stableOptions);
322
+ const description = stableOptions.description === undefined ? undefined : normalizeDescription(stableOptions.description);
313
323
  const destination = assertAddress(address);
314
324
  assertWritablePath(destination.path);
315
325
  const scope = destination.scope;
@@ -339,6 +349,9 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
339
349
  };
340
350
  meta.scope = scope;
341
351
  applyNotePolicy(meta, stableOptions);
352
+ if (description === undefined) {
353
+ if (stableOptions.description !== undefined) delete meta.description;
354
+ } else meta.description = description;
342
355
  if (origin !== undefined) meta.origin = origin;
343
356
  delete meta.crumpledAt;
344
357
  meta.updatedAt = now;
@@ -372,14 +385,15 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
372
385
  const operations = edits === undefined ? [] : edits.map((operation) => ({ ...operation }));
373
386
  const stableOptions = { ...options };
374
387
  validateNotePolicy(stableOptions);
388
+ const description = stableOptions.description === undefined ? undefined : normalizeDescription(stableOptions.description);
375
389
  const from = assertAddress(address);
376
390
  const destination = stableOptions.renameTo === undefined ? from : assertAddress(stableOptions.renameTo);
377
391
  assertWritablePath(destination.path);
378
392
  const scope = destination.scope;
379
393
  assertWritableNamespace(from.scope, from.who, identity);
380
394
  assertWritableNamespace(scope, destination.who, identity);
381
- if (operations.length === 0 && stableOptions.origin === undefined && stableOptions.crumpled === undefined && stableOptions.renameTo === undefined && stableOptions.pinned === undefined && stableOptions.budget === undefined && stableOptions.readonly === undefined) {
382
- throw new NoteError("nothing_to_do", "Nothing to change: provide edits, policy, an origin, a crumpled state, or a new address.");
395
+ if (operations.length === 0 && stableOptions.origin === undefined && stableOptions.description === undefined && stableOptions.crumpled === undefined && stableOptions.renameTo === undefined && stableOptions.pinned === undefined && stableOptions.budget === undefined && stableOptions.readonly === undefined) {
396
+ throw new NoteError("nothing_to_do", "Nothing to change: provide edits, a description, policy, an origin, a crumpled state, or a new address.");
383
397
  }
384
398
  const fromPath = physicalPath(from.scope, from.path, identity, from.who);
385
399
  const path = physicalPath(scope, destination.path, identity, destination.who);
@@ -405,6 +419,9 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
405
419
  if (moved && targetRaw !== undefined) assertNoteUnlocked(parseNote(targetRaw).meta, stableOptions.readonly);
406
420
  const beforeMeta: NoteMeta = { ...meta };
407
421
  applyNotePolicy(meta, stableOptions);
422
+ if (description === undefined) {
423
+ if (stableOptions.description !== undefined) delete meta.description;
424
+ } else meta.description = description;
408
425
  meta.scope = scope;
409
426
  if (from.scope !== "session" && scope === "session") meta.project = identity.projectKey;
410
427
  if (from.scope === "session" && scope !== "session") delete meta.project;
@@ -434,10 +451,11 @@ export function createNotesStore(input: NotesIdentity): NotesStore {
434
451
  const bodyChanged = body !== next;
435
452
  const originChanged = beforeMeta.origin !== meta.origin;
436
453
  const policyChanged = beforeMeta.pinned !== meta.pinned || beforeMeta.budget !== meta.budget || beforeMeta.readonly !== meta.readonly;
437
- if (bodyChanged || originChanged || policyChanged || moved) meta.updatedAt = writeStamp();
454
+ const descriptionChanged = beforeMeta.description !== meta.description;
455
+ if (bodyChanged || originChanged || policyChanged || descriptionChanged || moved) meta.updatedAt = writeStamp();
438
456
  const serialized = serializeNote(meta, next);
439
457
  assertSerializedSize(serialized);
440
- const metadataChanged = originChanged || policyChanged || beforeMeta.crumpledAt !== meta.crumpledAt;
458
+ const metadataChanged = originChanged || policyChanged || descriptionChanged || beforeMeta.crumpledAt !== meta.crumpledAt;
441
459
  let change: NoteChange;
442
460
  // A body edit that also rewrites frontmatter is still a body change; its diff inputs span the
443
461
  // whole serialized file, so the frontmatter part stays visible in the diff.
@@ -17,8 +17,9 @@ const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal(
17
17
  const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
18
18
  description: "Whose handwriting: user, self, or external. Leave it out to keep what's there.",
19
19
  }));
20
+ 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." }));
20
21
  const POLICY_PARAMETERS = {
21
- pinned: Type.Optional(Type.Boolean({ description: "Tape the page inside the cover: read whole at every wake-up. Five per notebook, CHEATSHEET and MAP included." })),
22
+ pinned: Type.Optional(Type.Boolean({ description: "Tape the page inside the cover: read whole at every wake-up. Five per notebook, CHEATSHEET included." })),
22
23
  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." })),
23
24
  readonly: Type.Optional(Type.Boolean({ description: "A paperclip that keeps your own hands off. `false` takes it off — same call is fine." })),
24
25
  };
@@ -39,7 +40,7 @@ function withWarnings(text: string, data: { warnings: string[] }): string {
39
40
  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." }));
40
41
  const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "Only the crumpled balls." }));
41
42
  const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "How many pages at most." }));
42
- 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 · `MAP.md` that page in every notebook · `**` everything · `@sessions/*/**` every session." }));
43
+ 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." }));
43
44
  const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
44
45
  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." });
45
46
 
@@ -56,7 +57,7 @@ export function failureOf(error: unknown): Outcome<never> {
56
57
  }
57
58
 
58
59
  /** Metadata keys this layer normalizes; everything else is exposed verbatim under `extra`. */
59
- const NORMALIZED_META_KEYS = new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project", "pinned", "budget", "readonly"]);
60
+ const NORMALIZED_META_KEYS = new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project", "pinned", "budget", "readonly", "description"]);
60
61
  /** One unrecognized entry, and the verbatim extras together, are bounded so `extra` cannot outgrow the read. */
61
62
  const MAX_METADATA_ENTRY_BYTES = 1024;
62
63
  const MAX_METADATA_VERBATIM_BYTES = 2048;
@@ -70,6 +71,7 @@ export const NoteMetadataSchema = Type.Object({
70
71
  updated_at: Type.String(),
71
72
  crumpled_at: Type.Optional(Type.String()),
72
73
  project: Type.Optional(Type.String()),
74
+ description: Type.Optional(Type.String()),
73
75
  extra: Type.Record(Type.String(), Type.Unknown()),
74
76
  }, { additionalProperties: false });
75
77
  export type NoteMetadata = Static<typeof NoteMetadataSchema>;
@@ -102,6 +104,7 @@ function noteMetadata(meta: NoteMeta, address: string): NoteMetadata {
102
104
  updated_at: localIso(meta.updatedAt),
103
105
  ...(typeof meta.crumpledAt === "string" ? { crumpled_at: meta.crumpledAt } : {}),
104
106
  ...(typeof meta.project === "string" ? { project: meta.project } : {}),
107
+ ...(typeof meta.description === "string" ? { description: meta.description } : {}),
105
108
  extra,
106
109
  };
107
110
  }
@@ -114,6 +117,7 @@ function renderMetadata(metadata: NoteMetadata): string {
114
117
  `updated ${metadata.updated_at}`,
115
118
  ...(metadata.crumpled_at === undefined ? [] : [`crumpled ${metadata.crumpled_at}`]),
116
119
  ...(metadata.project === undefined ? [] : [`project ${metadata.project}`]),
120
+ ...(metadata.description === undefined ? [] : [`description ${metadata.description}`]),
117
121
  ];
118
122
  const extra = Object.keys(metadata.extra);
119
123
  if (extra.length > 0) fields.push(`extra ${JSON.stringify(metadata.extra)}`);
@@ -147,6 +151,7 @@ export const ListedFileSchema = Type.Object({
147
151
  ...WarningsSchema,
148
152
  updated_at: Type.String(),
149
153
  crumpled_at: Type.Optional(Type.String()),
154
+ description: Type.Optional(Type.String()),
150
155
  }, { additionalProperties: false });
151
156
 
152
157
  const MatchSchema = Type.Object({
@@ -228,10 +233,10 @@ export function snapshot<T extends { address: string }>(
228
233
 
229
234
  export function listedFile(row: Pick<NoteRow, "address" | "meta"> & { body?: string; warnings?: string[] }, identity: NotesIdentity): ListedFile {
230
235
  const policy = policyAt(row.meta, row.address);
231
- 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 }) };
236
+ 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 } : {}) };
232
237
  }
233
238
 
234
- export const notesWriteParameters = Type.Object({ address: ADDRESS_PARAMETER, content: Type.String({ description: "The whole page." }), origin: ORIGIN, ...POLICY_PARAMETERS, cwd: CWD_PARAMETER }, { additionalProperties: false });
239
+ 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 });
235
240
 
236
241
  function renderWriteData(data: NotesWriteData): string {
237
242
  return withWarnings(`${data.outcome} ${renderIdentity(data)} | ${renderPolicy(data)}`, data);
@@ -244,7 +249,7 @@ export const notesWrite = {
244
249
  async execute(params: Static<typeof notesWriteParameters>, context: NotesToolContext): Promise<Outcome<NotesWriteData>> {
245
250
  try {
246
251
  const identity = notesIdentityForCall(context, params.cwd);
247
- const { outcome, meta, warnings } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin, pinned: params.pinned, budget: params.budget, readonly: params.readonly });
252
+ 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 });
248
253
  return success({ ...noteIdentity(identity, params.address), outcome, ...policyAt(meta, params.address), warnings });
249
254
  } catch (error) { return failureOf(error); }
250
255
  },
@@ -255,6 +260,7 @@ export const notesUpdateParameters = Type.Object({
255
260
  address: ADDRESS_PARAMETER,
256
261
  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." })),
257
262
  origin: ORIGIN,
263
+ description: DESCRIPTION_PARAMETER,
258
264
  ...POLICY_PARAMETERS,
259
265
  crumpled: CRUMPLED_PARAMETER,
260
266
  replace_all: Type.Optional(Type.Boolean({ description: "Strike every copy of `oldText`, not just one." })),
@@ -279,7 +285,7 @@ export const notesUpdate = {
279
285
  const store = createNotesStore(identity);
280
286
  // Empty filler is not a request: models that pass every parameter get the edit path.
281
287
  const renameTo = params.rename_to === "" ? undefined : params.rename_to;
282
- 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 });
288
+ 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 });
283
289
  onChange?.(change);
284
290
  const from = noteIdentity(identity, params.address).address;
285
291
  const to = noteIdentity(identity, renameTo ?? params.address);
@@ -327,7 +333,7 @@ export const notesListParameters = Type.Object({
327
333
  export function renderListData(data: Snapshot<NotesListData["files"][number] & { last_accessed?: string }>): string {
328
334
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
329
335
  for (const file of data.files) {
330
- const fields = [`- ${renderIdentity(file)}`, renderPolicy(file), `updated ${file.updated_at}`];
336
+ const fields = [file.description === undefined ? `- ${renderIdentity(file)}` : `- ${renderIdentity(file)} — ${file.description}`, renderPolicy(file), `updated ${file.updated_at}`];
331
337
  if (file.last_accessed !== undefined) fields.push(`accessed ${file.last_accessed}`);
332
338
  if (file.crumpled_at !== undefined) fields.push(`crumpled ${file.crumpled_at}`);
333
339
  if (file.matches) fields.push(`${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);