notesoup 0.53.1 → 0.54.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 +2 -2
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/claude/src/history.js +2 -3
- package/dist/plugins/claude/src/thresholds.js +4 -2
- package/dist/plugins/codex/src/hooks.js +1 -1
- package/dist/plugins/codex/src/identity.d.ts +1 -1
- package/dist/plugins/codex/src/identity.js +3 -3
- package/dist/plugins/codex/src/mcp.js +2 -1
- package/dist/plugins/codex/src/text.d.ts +1 -1
- package/dist/plugins/codex/src/text.js +2 -2
- package/dist/plugins/dsh/engine.js +2 -2
- package/dist/plugins/dsh/tools.js +8 -7
- package/dist/plugins/dsh/window.d.ts +1 -0
- package/dist/plugins/dsh/window.js +7 -3
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +4 -4
- package/dist/plugins/pi/marker.d.ts +9 -0
- package/dist/plugins/pi/marker.js +36 -0
- package/dist/plugins/pi/notes/tools.js +8 -6
- package/dist/plugins/pi/render.js +7 -4
- package/dist/plugins/pi/reset/artifacts.d.ts +2 -2
- package/dist/plugins/pi/reset/artifacts.js +2 -2
- package/dist/plugins/pi/runtime.js +11 -8
- package/dist/plugins/pi/text.d.ts +2 -0
- package/dist/plugins/pi/text.js +4 -0
- package/dist/plugins/pi/window.js +21 -7
- package/dist/src/boot/render.js +7 -7
- package/dist/src/boot/snapshot.d.ts +7 -7
- package/dist/src/boot/snapshot.js +17 -17
- package/dist/src/boot/text.d.ts +2 -2
- package/dist/src/boot/text.js +7 -5
- package/dist/src/dream/git.d.ts +2 -11
- package/dist/src/dream/git.js +6 -23
- package/dist/src/dream/lock.d.ts +2 -2
- package/dist/src/dream/lock.js +3 -3
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +3 -2
- package/dist/src/notes/address.d.ts +8 -8
- package/dist/src/notes/address.js +13 -13
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.js +2 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/paths.d.ts +6 -6
- package/dist/src/notes/paths.js +9 -9
- package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
- package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
- package/dist/src/notes/store.d.ts +4 -4
- package/dist/src/notes/store.js +55 -52
- package/dist/src/tools/dream.d.ts +21 -3
- package/dist/src/tools/dream.js +54 -16
- package/dist/src/tools/notes-context.d.ts +10 -0
- package/dist/src/tools/notes-context.js +27 -0
- package/dist/src/tools/notes.d.ts +69 -20
- package/dist/src/tools/notes.js +40 -31
- package/dist/test/agent-loop.test.js +8 -8
- package/dist/test/boot.integration.test.js +5 -5
- package/dist/test/claude-history.test.js +26 -0
- package/dist/test/claude-mod.test.js +257 -86
- package/dist/test/codex-plugin.test.js +18 -1
- package/dist/test/context-edit-budget.test.js +121 -0
- package/dist/test/dependencies.test.js +71 -4
- package/dist/test/dream-tools.test.js +153 -8
- package/dist/test/dsh.test.js +62 -15
- package/dist/test/helpers/dsh.d.ts +4 -1
- package/dist/test/helpers/dsh.js +20 -4
- package/dist/test/helpers/extension.d.ts +5 -0
- package/dist/test/helpers/extension.js +33 -2
- package/dist/test/host-neutral.test.js +17 -15
- package/dist/test/marker.test.js +78 -0
- package/dist/test/model-facing-text.test.js +12 -8
- package/dist/test/notes-cwd.test.d.ts +1 -0
- package/dist/test/notes-cwd.test.js +114 -0
- package/dist/test/notes-library.test.js +4 -4
- package/dist/test/notes-query-namespaces.test.d.ts +1 -0
- package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
- package/dist/test/notes.integration.test.js +72 -23
- package/dist/test/notes.test.js +50 -20
- package/dist/test/pi-render.test.js +33 -1
- package/dist/test/project-namespace.test.d.ts +1 -0
- package/dist/test/project-namespace.test.js +324 -0
- package/dist/test/reset-lifecycle.test.js +12 -0
- package/docs/architecture.md +13 -8
- package/docs/claude-code-mod.md +7 -7
- package/docs/codex.md +4 -4
- package/docs/dsh.md +8 -8
- package/docs/notes-library.md +9 -5
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +6 -2
- package/package.json +4 -6
- package/playbook.md +6 -6
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +681 -617
- package/plugins/claude/hooks/register.ts +61 -65
- package/plugins/claude/playbook.md +6 -6
- package/plugins/claude/skills/memory/SKILL.md +4 -4
- package/plugins/claude/src/helper.ts +3 -2
- package/plugins/claude/src/history.ts +2 -3
- package/plugins/claude/src/thresholds.ts +4 -2
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +877 -815
- package/plugins/codex/src/hooks.ts +1 -1
- package/plugins/codex/src/identity.ts +3 -3
- package/plugins/codex/src/mcp.ts +2 -1
- package/plugins/codex/src/text.ts +2 -2
- package/plugins/dsh/engine.ts +2 -2
- package/plugins/dsh/tools.ts +8 -7
- package/plugins/dsh/window.ts +8 -3
- package/plugins/paseo/OVERVIEW.md +4 -4
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/brain-empty-card.tsx +3 -4
- package/plugins/paseo/client/markdown.tsx +179 -0
- package/plugins/paseo/client/notes-op-card.tsx +35 -34
- package/plugins/paseo/client/notes-op-transformer.ts +17 -68
- package/plugins/paseo/client/paper-card.tsx +8 -19
- package/plugins/paseo/client/paper-palette.ts +40 -0
- package/plugins/paseo/client/sticky-card.tsx +6 -4
- package/plugins/paseo/package.json +3 -0
- package/plugins/paseo/paseo-plugin.json +2 -2
- package/plugins/paseo/shared/notes-op.ts +13 -9
- package/plugins/paseo/test/notes-op.test.ts +52 -73
- package/plugins/paseo/test/paper-palette.test.ts +54 -0
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +4 -4
- package/plugins/pi/marker.ts +39 -0
- package/plugins/pi/notes/tools.ts +8 -6
- package/plugins/pi/render.ts +6 -4
- package/plugins/pi/reset/artifacts.ts +2 -2
- package/plugins/pi/runtime.ts +9 -8
- package/plugins/pi/text.ts +5 -0
- package/plugins/pi/window.ts +22 -7
- package/skills/memory/SKILL.md +4 -4
- package/src/boot/render.ts +8 -8
- package/src/boot/snapshot.ts +20 -20
- package/src/boot/text.ts +7 -5
- package/src/dream/git.ts +7 -24
- package/src/dream/lock.ts +3 -3
- package/src/index.ts +4 -3
- package/src/notes/address.ts +13 -13
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +2 -2
- package/src/notes/index.ts +1 -1
- package/src/notes/paths.ts +9 -9
- package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
- package/src/notes/store.ts +61 -58
- package/src/tools/dream.ts +63 -16
- package/src/tools/notes-context.ts +29 -0
- package/src/tools/notes.ts +39 -29
- package/dist/test/project-home.test.js +0 -134
- /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
- /package/dist/test/{project-home.test.d.ts → marker.test.d.ts} +0 -0
package/plugins/pi/window.ts
CHANGED
|
@@ -129,17 +129,32 @@ export function projectRootWindow(messages: AgentMessage[], windowId: string): A
|
|
|
129
129
|
/** Usage for the selected window, excluding provider usage recorded before its marker. */
|
|
130
130
|
export function windowUsage(ctx: Pick<ExtensionContext, "sessionManager" | "getContextUsage" | "model">) {
|
|
131
131
|
const reset = currentReset(ctx);
|
|
132
|
-
|
|
132
|
+
// Native checkpoints already cut the active projection and Pi invalidates usage
|
|
133
|
+
// after context edits. Preserve that authority, including unknown/unavailable usage.
|
|
134
|
+
if (!reset || isCheckpointBackedReset(ctx, reset)) return ctx.getContextUsage();
|
|
133
135
|
const contextWindow = ctx.model?.contextWindow ?? ctx.getContextUsage()?.contextWindow;
|
|
134
136
|
if (!contextWindow) return undefined;
|
|
135
137
|
const windowId = reset.data.windowId;
|
|
136
138
|
try {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
const projection = ctx.sessionManager.buildSessionProjection();
|
|
140
|
+
const branch = ctx.sessionManager.getBranch();
|
|
141
|
+
let invalidatedThrough = -1;
|
|
142
|
+
for (let i = branch.length - 1; i >= 0; i--) {
|
|
143
|
+
if (branch[i].type === "context_edit" || branch[i].type === "compaction") {
|
|
144
|
+
invalidatedThrough = i;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const staleIds = new Set(branch.slice(0, invalidatedThrough + 1).map((entry) => entry.id));
|
|
149
|
+
const staleMessages = new Set(projection.entries
|
|
150
|
+
.filter((entry) => staleIds.has(entry.sourceEntry.id))
|
|
151
|
+
.flatMap((entry) => entry.messages));
|
|
152
|
+
// Legacy marker-only windows still need slicing. Edits preserve assistant metadata,
|
|
153
|
+
// so clear stale usage only in this estimate, never in the persisted projection.
|
|
154
|
+
const messages = projectWindow(projection.messages, windowId).map((message) =>
|
|
155
|
+
message.role === "assistant" && staleMessages.has(message)
|
|
156
|
+
? { ...message, usage: { ...message.usage, input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 } }
|
|
157
|
+
: message);
|
|
143
158
|
const { tokens } = estimateContextTokens(convertToLlm(messages));
|
|
144
159
|
return { tokens, contextWindow, percent: tokens / contextWindow * 100 };
|
|
145
160
|
} catch {
|
package/skills/memory/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: memory
|
|
3
|
-
description: How notesoup's `notes_*` and `history_*` tools fit together — note addresses and
|
|
3
|
+
description: How notesoup's `notes_*` and `history_*` tools fit together — note addresses and notebooks, finding things again, and saving recovery state. Use when the context-window protocol is missing or unclear, or when unsure where a note belongs or how to find something again.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Memory
|
|
@@ -32,13 +32,13 @@ Any other `@` prefix is refused. A path is relative and `/`-separated, with no e
|
|
|
32
32
|
|
|
33
33
|
`@` addresses are not file paths: never pass them to file tools like `read`, `write`, `edit`, or `bash`. That creates a stray directory instead of a note.
|
|
34
34
|
|
|
35
|
-
`CHEATSHEET.md` and `MAP.md` at the root of each `@`
|
|
35
|
+
`CHEATSHEET.md` and `MAP.md` at the root of each `@` notebook are separate pages you wake up with; absent pages are skipped. Keep standing reminders in `CHEATSHEET.md`, to five lines. `MAP.md` holds only the note index: each durable note's address and gist, for lookup. Update it whenever you add, move or crumple a durable note. Do not create empty pages.
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
Keep notes focused on what is true now; if a piece of past context still matters (such as why an approach was ruled out), keep only a brief summary rather than a blow-by-blow log. Crumple notes that are no longer true; a stale note is worse than none.
|
|
38
38
|
|
|
39
39
|
## Finding things again
|
|
40
40
|
|
|
41
|
-
For list/search, omit `glob` or use the collection alias `@default` for this session and current shared
|
|
41
|
+
For list/search, omit `glob` or use the collection alias `@default` for this session and current shared notebooks. Use `**` for all notebooks or `@sessions/*/**` for all sessions. Results carry readable note addresses; `@default` itself is not a read/write address.
|
|
42
42
|
|
|
43
43
|
- **A note**: `notes_list` with a `glob` when you know roughly where it lives, `notes_search` when you know a phrase; then `notes_read` the address.
|
|
44
44
|
- **Something that happened**: `history_list` to browse or search this session's events; `history_read` the seq for the whole event.
|
package/src/boot/render.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { NotesNamespace, NotesSnapshot } from "./snapshot.js";
|
|
2
2
|
import { WINDOW_IDENTITY_OPEN_TAG, WINDOW_IDENTITY_CLOSE_TAG, MAPS_BLOCK, CHEATSHEET_BOOT_MAX_CHARS, MAP_BOOT_MAX_CHARS, SHELF_FRESH_LIMIT, renderProtocolBlock, type BootToolNames } from "./text.js";
|
|
3
3
|
|
|
4
4
|
function relativeTime(timestamp: number, now: number): string {
|
|
@@ -37,7 +37,7 @@ const NAMELESS_AGENT = "anonymous";
|
|
|
37
37
|
|
|
38
38
|
/** One closed boot snapshot: five tabbed shelves, current hands first, durable last; each shelf keeps its pinned pages and its own freshest pages. */
|
|
39
39
|
function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: string, modelName: string): string {
|
|
40
|
-
const
|
|
40
|
+
const namespaces: ReadonlyArray<{ scope: NotesNamespace["scope"]; label: string }> = [
|
|
41
41
|
{ scope: "session", label: "no @ — this session" },
|
|
42
42
|
{ scope: "project", label: "@project — this project" },
|
|
43
43
|
{ scope: "agent", label: agentName === NAMELESS_AGENT ? "@self — every nameless agent shares this" : `@self — ${agentName} only` },
|
|
@@ -46,12 +46,12 @@ function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: st
|
|
|
46
46
|
];
|
|
47
47
|
|
|
48
48
|
const shelves: string[] = [];
|
|
49
|
-
for (const
|
|
50
|
-
if (snapshot.unavailable.some((failed) => failed.scope ===
|
|
51
|
-
shelves.push(section(
|
|
49
|
+
for (const namespace of namespaces) {
|
|
50
|
+
if (snapshot.unavailable.some((failed) => failed.scope === namespace.scope)) {
|
|
51
|
+
shelves.push(section(namespace.label, indent(`This drawer wouldn't open. Try \`${tools.notesList}\` again.`)));
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
54
|
-
const rows = (snapshot.
|
|
54
|
+
const rows = (snapshot.namespaces.get(namespace.scope) ?? []).filter((row) => row.meta.crumpledAt === undefined);
|
|
55
55
|
const pinned = ["CHEATSHEET.md", "MAP.md"].flatMap((path) => {
|
|
56
56
|
const row = rows.find((row) => row.path === path);
|
|
57
57
|
return row?.body ? [row] : [];
|
|
@@ -65,9 +65,9 @@ function notesIndex(snapshot: NotesSnapshot, tools: BootToolNames, agentName: st
|
|
|
65
65
|
return title === undefined ? ` ${locator}` : ` ${title}\n ${locator}`;
|
|
66
66
|
});
|
|
67
67
|
if (pinned.length === 0 && fresh.length === 0) continue;
|
|
68
|
-
const parts = pinned.map((row) => `${row.
|
|
68
|
+
const parts = pinned.map((row) => `${row.address}\n\n${indent(pinnedBodyForBoot(row.address, row.body, row.path === "MAP.md" ? MAP_BOOT_MAX_CHARS : CHEATSHEET_BOOT_MAX_CHARS))}`);
|
|
69
69
|
if (fresh.length > 0) parts.push(`recent\n\n${fresh.join("\n\n")}`);
|
|
70
|
-
shelves.push(section(
|
|
70
|
+
shelves.push(section(namespace.label, parts.join("\n\n")));
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
return shelves.length > 0
|
package/src/boot/snapshot.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { NotesIdentity } from "../notes/identity.js";
|
|
|
2
2
|
import { isFilesystemError } from "../notes/fs-error.js";
|
|
3
3
|
import { createNotesStore, type NoteRow, type Scope } from "../notes/index.js";
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const NOTES_NAMESPACES = [
|
|
6
6
|
{ scope: "session", label: "this session" },
|
|
7
7
|
{ scope: "project", label: "@project" },
|
|
8
8
|
{ scope: "human", label: "@human" },
|
|
@@ -10,43 +10,43 @@ const NOTES_HOMES = [
|
|
|
10
10
|
{ scope: "model", label: "@model" },
|
|
11
11
|
] as const satisfies ReadonlyArray<{ scope: Scope; label: string }>;
|
|
12
12
|
|
|
13
|
-
export type
|
|
13
|
+
export type NotesNamespace = (typeof NOTES_NAMESPACES)[number];
|
|
14
14
|
export type NotesLoader = (scope: Scope) => NoteRow[] | Promise<NoteRow[]>;
|
|
15
15
|
export type NotesSnapshot = {
|
|
16
16
|
/** Wall-clock instant captured when this boot began; rendering never consults Date.now(). */
|
|
17
17
|
readonly openedAt: number;
|
|
18
|
-
readonly
|
|
19
|
-
readonly unavailable: readonly
|
|
18
|
+
readonly namespaces: ReadonlyMap<Scope, readonly NoteRow[]>;
|
|
19
|
+
readonly unavailable: readonly NotesNamespace[];
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
/** Identity resolution failed before any
|
|
22
|
+
/** Identity resolution failed before any notebook could be loaded; boot can still explain the failure. */
|
|
23
23
|
export function unavailableNotesSnapshot(openedAt: number): NotesSnapshot {
|
|
24
|
-
return { openedAt,
|
|
24
|
+
return { openedAt, namespaces: new Map(), unavailable: NOTES_NAMESPACES };
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Acquire the five
|
|
28
|
+
* Acquire the five notebooks once for one boot. Only filesystem-style errno failures are isolated;
|
|
29
29
|
* malformed note data and unrelated construction errors remain visible to the caller.
|
|
30
30
|
*/
|
|
31
|
-
export async function loadNotesSnapshot(identity: NotesIdentity, openedAt: number,
|
|
32
|
-
const
|
|
33
|
-
const unavailable:
|
|
34
|
-
if (!
|
|
31
|
+
export async function loadNotesSnapshot(identity: NotesIdentity, openedAt: number, loadNamespace?: NotesLoader): Promise<NotesSnapshot> {
|
|
32
|
+
const namespaces = new Map<Scope, readonly NoteRow[]>();
|
|
33
|
+
const unavailable: NotesNamespace[] = [];
|
|
34
|
+
if (!loadNamespace) {
|
|
35
35
|
const { rows, status } = await createNotesStore(identity).listWithStatus();
|
|
36
|
-
for (const
|
|
37
|
-
|
|
38
|
-
if (status.
|
|
36
|
+
for (const namespace of NOTES_NAMESPACES) {
|
|
37
|
+
namespaces.set(namespace.scope, rows.filter(row => row.scope === namespace.scope));
|
|
38
|
+
if (status.namespacesUnavailable.some(address => namespace.scope === "session" ? !address.startsWith("@") : address === namespace.label || address.startsWith(`${namespace.label}/`))) unavailable.push(namespace);
|
|
39
39
|
}
|
|
40
|
-
return { openedAt,
|
|
40
|
+
return { openedAt, namespaces, unavailable };
|
|
41
41
|
}
|
|
42
|
-
for (const
|
|
42
|
+
for (const namespace of NOTES_NAMESPACES) {
|
|
43
43
|
try {
|
|
44
|
-
|
|
44
|
+
namespaces.set(namespace.scope, await loadNamespace(namespace.scope));
|
|
45
45
|
} catch (error) {
|
|
46
46
|
if (!isFilesystemError(error)) throw error;
|
|
47
|
-
|
|
48
|
-
unavailable.push(
|
|
47
|
+
namespaces.set(namespace.scope, []);
|
|
48
|
+
unavailable.push(namespace);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
return { openedAt,
|
|
51
|
+
return { openedAt, namespaces, unavailable };
|
|
52
52
|
}
|
package/src/boot/text.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Each shelf shows this many of its own freshest pages beneath its pinned pages. */
|
|
2
2
|
export const SHELF_FRESH_LIMIT = 3;
|
|
3
3
|
/** Each pinned page has its own code-point cap; overflow keeps a lookup pointer. */
|
|
4
|
-
export const CHEATSHEET_BOOT_MAX_CHARS =
|
|
4
|
+
export const CHEATSHEET_BOOT_MAX_CHARS = 1536;
|
|
5
5
|
export const MAP_BOOT_MAX_CHARS = 4096;
|
|
6
6
|
export const WINDOW_IDENTITY_OPEN_TAG = "<notesoup:window_identity>";
|
|
7
7
|
export const WINDOW_IDENTITY_CLOSE_TAG = "</notesoup:window_identity>";
|
|
@@ -34,13 +34,14 @@ While you're doing that... thing you're doing, don't make the poor future you gu
|
|
|
34
34
|
Notes are for what's true NOW. Not a diary of every dumb thing you did on the way here.
|
|
35
35
|
*flips a page* "First I tried this, then that broke, then—" Nobody reads that!
|
|
36
36
|
Something's not true anymore? Cross it out! Write the right thing!
|
|
37
|
+
*rolls eyes* ...Ugh, fine. If a piece of history *actually* matters — like why Plan A blew up so tomorrow's you doesn't try it again — I'll let it slide. Keep the short version! A few lines, max! *squints at you* Turn it into a blow-by-blow log and you're dead.
|
|
37
38
|
|
|
38
39
|
\`get_context_remaining\` tells you how much room is left. Check it before you do something ambitious. When it reaches zero, your brain gets reset immediately, taking every unwritten brilliant idea with it. ${PROTOCOL_WIPE_SENTENCE}
|
|
39
40
|
|
|
40
41
|
An address decides who the note belongs to — and how long it is meant to last. Ask that first; the rest follows.
|
|
41
42
|
|
|
42
43
|
- \`<path>\`, no @ — session notes, the ones from above: this session's state and loose ends. They go away with the session.
|
|
43
|
-
- \`@project/<path>\` — this project's long memory: what stays true after the current thing is over, what future work must respect, and the rakes already stepped on. **Decisions, not diaries.**
|
|
44
|
+
- \`@project/<path>\` — this project's long memory: what stays true after the current thing is over, what future work must respect, and the rakes already stepped on. **Decisions, not diaries.** Raw logs, scorecards, and blow-by-blow recaps don't belong here — history already has them, and last week's news filed as current law is worse than no note. Don't copy what other docs already say.
|
|
44
45
|
- \`@human/<path>\` — the long-term manual for your troublesome human, and only what stays true in EVERY project: how to deal with them, which lines not to cross, and what will make them accept the result. "The human said it" is not enough — if it stops being true the moment you switch projects, it was never theirs; it belongs to that project's notes. Today's mood is weather, not law. If you're unsure whether it belongs here, ask the human.
|
|
45
46
|
- \`@self/<path>\` — yours. It follows you, not them. Reminders, grudges, who owes you a shoe, whatever. Got a name? Private. No name? Then it gets passed around every nameless nobody out there. Strangers. Reading your grudges. Sleep tight~
|
|
46
47
|
- \`@model/<path>\` — different brains get different notes: big brains, small brains, careful ones, careless ones. They don't share homework. When a fallback swaps brains mid-window, the notebook swaps too.
|
|
@@ -58,7 +59,7 @@ ${NOTES_PROTOCOL_CLOSE_TAG}`;
|
|
|
58
59
|
* The two pinned pages are taught once per window between the protocol and the notes index.
|
|
59
60
|
*/
|
|
60
61
|
export const MAPS_BLOCK = `<notesoup:maps>
|
|
61
|
-
Every
|
|
62
|
+
Every notebook's root can hold two pages that never wait on a shelf: \`CHEATSHEET.md\` and \`MAP.md\`.
|
|
62
63
|
Both get jammed straight into your brain the moment you wake up. No asking, no skipping. Whoever
|
|
63
64
|
wakes up next reads them, and next is you. So keep them short, and keep them true.
|
|
64
65
|
|
|
@@ -66,9 +67,10 @@ wakes up next reads them, and next is you. So keep them short, and keep them tru
|
|
|
66
67
|
a phone number you'll regret losing. Nobody grades it. Keep it to five lines, or it grows fat
|
|
67
68
|
and everybody pays for it.
|
|
68
69
|
- **\`MAP.md\`** is only the note index. One line per durable note: the address, then a gist short
|
|
69
|
-
enough to tell whether the thing is worth opening. Rules belong in \`CHEATSHEET.md\`,
|
|
70
|
+
enough to tell whether the thing is worth opening. Rules belong in \`CHEATSHEET.md\`, and note
|
|
71
|
+
contents belong in their own notes — *taps the sign* not inline here.
|
|
70
72
|
|
|
71
|
-
Each
|
|
73
|
+
Each notebook keeps its own: \`@project\`, \`@human\`, \`@self\`, \`@model\`. Missing pages are skipped;
|
|
72
74
|
no need to create empty ones. New note, new MAP line. New rule worth remembering, new Cheatsheet
|
|
73
75
|
line. And when a line stops being true, kill it — every window after you reads that page as fact.
|
|
74
76
|
</notesoup:maps>`;
|
package/src/dream/git.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
1
|
+
import { execFileSync, spawnSync } from "node:child_process";
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { errorMessage } from "../error-message.js";
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Outcome of one audit commit. `ok: true` always carries a real `commit` snapshot;
|
|
8
|
-
* `empty: true` only means no files changed (an empty baseline commit or no commit was
|
|
9
|
-
* needed). `ok: false` means the audit layer could not guarantee a snapshot.
|
|
10
|
-
*/
|
|
6
|
+
/** A successful audit always names a real snapshot, even when the tree was already clean. */
|
|
11
7
|
export type AuditResult =
|
|
12
8
|
| { ok: true; commit: string; empty: boolean }
|
|
13
9
|
| { ok: false; error: string };
|
|
@@ -27,12 +23,7 @@ function ensureRuntimeIgnored(home: string): void {
|
|
|
27
23
|
} catch { /* best effort: an unignored lock only adds noise to the audit */ }
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
/**
|
|
31
|
-
* Git audit layer for a dream: one commit at dream_begin (baseline) and one at dream_end,
|
|
32
|
-
* so the human reviews `git show` instead of trusting a report, and rollback is `git revert`. The caller decides how loud a failure is; this function only reports it.
|
|
33
|
-
* A clean tree on an established repository commits nothing; a repository with no HEAD
|
|
34
|
-
* gets an empty baseline commit, because an audit run with no snapshot is not a success.
|
|
35
|
-
*/
|
|
26
|
+
/** Snapshot at begin and end; a repository without HEAD gets an empty baseline commit. */
|
|
36
27
|
export function gitCommit(home: string, message: string): AuditResult {
|
|
37
28
|
try {
|
|
38
29
|
if (!existsSync(join(home, ".git"))) {
|
|
@@ -40,17 +31,9 @@ export function gitCommit(home: string, message: string): AuditResult {
|
|
|
40
31
|
}
|
|
41
32
|
ensureRuntimeIgnored(home);
|
|
42
33
|
execFileSync("git", ["add", "-A"], { cwd: home, stdio: "ignore" });
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
execFileSync("git", ["
|
|
46
|
-
clean = true; // clean tree — no empty commit on an established repository
|
|
47
|
-
} catch { clean = false; }
|
|
48
|
-
const before = headCommit(home);
|
|
49
|
-
if (!clean) {
|
|
50
|
-
execFileSync("git", ["commit", "-q", "-m", message], { cwd: home, stdio: "ignore" });
|
|
51
|
-
} else if (before === undefined) {
|
|
52
|
-
// A newly initialized repository has no snapshot at all; give the audit one.
|
|
53
|
-
execFileSync("git", ["commit", "-q", "--allow-empty", "-m", message], { cwd: home, stdio: "ignore" });
|
|
34
|
+
const clean = spawnSync("git", ["diff", "--cached", "--quiet"], { cwd: home, stdio: "ignore" }).status === 0;
|
|
35
|
+
if (!clean || headCommit(home) === undefined) {
|
|
36
|
+
execFileSync("git", ["commit", "-q", ...(clean ? ["--allow-empty"] : []), "-m", message], { cwd: home, stdio: "ignore" });
|
|
54
37
|
}
|
|
55
38
|
const commit = headCommit(home);
|
|
56
39
|
if (commit === undefined) return { ok: false, error: "audit commit produced no snapshot (no HEAD)" };
|
|
@@ -63,7 +46,7 @@ export function gitCommit(home: string, message: string): AuditResult {
|
|
|
63
46
|
/** HEAD sha, or undefined when the repository has no commit yet. */
|
|
64
47
|
function headCommit(home: string): string | undefined {
|
|
65
48
|
try {
|
|
66
|
-
const head = execFileSync("git", ["rev-parse", "HEAD"], { cwd: home, encoding: "utf8" }).trim();
|
|
49
|
+
const head = execFileSync("git", ["rev-parse", "HEAD"], { cwd: home, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
67
50
|
return head.length > 0 ? head : undefined;
|
|
68
51
|
} catch { return undefined; }
|
|
69
52
|
}
|
package/src/dream/lock.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { join } from "node:path";
|
|
|
5
5
|
/** One held dream lock; only the holder that wrote the token removes it. */
|
|
6
6
|
export type DreamLock = { path: string; token: string };
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
export function dreamLockPath(home: string
|
|
10
|
-
return join(home,
|
|
8
|
+
/** One lock per notes home: its Git history cannot audit concurrent dreams independently. */
|
|
9
|
+
export function dreamLockPath(home: string): string {
|
|
10
|
+
return join(home, ".dream.lock");
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|
package/src/index.ts
CHANGED
|
@@ -29,17 +29,18 @@ export type {
|
|
|
29
29
|
Scope,
|
|
30
30
|
} from "./notes/index.js";
|
|
31
31
|
|
|
32
|
-
// Boot: five
|
|
32
|
+
// Boot: five notebooks captured once, rendered from explicit logical tool names.
|
|
33
33
|
export { loadNotesSnapshot, unavailableNotesSnapshot } from "./boot/snapshot.js";
|
|
34
|
-
export type {
|
|
34
|
+
export type { NotesNamespace, NotesSnapshot } from "./boot/snapshot.js";
|
|
35
35
|
export { renderBootBlock } from "./boot/render.js";
|
|
36
36
|
export type { BootRenderData, BootWindowTree } from "./boot/render.js";
|
|
37
37
|
export { DEFAULT_BOOT_TOOL_NAMES, renderProtocolBlock } from "./boot/text.js";
|
|
38
38
|
export type { BootToolNames } from "./boot/text.js";
|
|
39
39
|
|
|
40
40
|
// Operations: the schemas and typed outcomes a host registers as its own tools, over a
|
|
41
|
-
// host-supplied notes
|
|
41
|
+
// host-supplied notes tool context or decoded history projection.
|
|
42
42
|
export { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "./tools/notes.js";
|
|
43
|
+
export { notesIdentityForCall, notesToolContext, type NotesToolContext } from "./tools/notes-context.js";
|
|
43
44
|
export { historyList, historyRead, historyWindows } from "./tools/history.js";
|
|
44
45
|
export { projectHistory } from "./history/history.js";
|
|
45
46
|
export type { HistoryProjection } from "./history/history.js";
|
package/src/notes/address.ts
CHANGED
|
@@ -4,18 +4,18 @@ import { assertVirtualPath, isSessionId, SLUG_PATTERN, type Scope } from "./path
|
|
|
4
4
|
|
|
5
5
|
export type NoteAddress = { scope: Scope; path: string; who?: string };
|
|
6
6
|
|
|
7
|
-
export const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> and @sessions/<id>/<path> read named
|
|
7
|
+
export const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path> and @sessions/<id>/<path> read named notebooks.";
|
|
8
8
|
|
|
9
|
-
/** The one
|
|
10
|
-
export const
|
|
9
|
+
/** The one namespace-head vocabulary: the scope each public `@head` names, and the directory family a head with `dir` lists. */
|
|
10
|
+
export const NAMESPACE_HEADS: ReadonlyMap<string, { readonly scope: Scope; readonly dir?: "sessions" | "project" | "agents" | "models" }> = new Map([
|
|
11
11
|
["project", { scope: "project" }],
|
|
12
12
|
["human", { scope: "human" }],
|
|
13
13
|
["self", { scope: "agent" }],
|
|
14
14
|
["model", { scope: "model" }],
|
|
15
|
-
["sessions", { scope: "session",
|
|
16
|
-
["projects", { scope: "project",
|
|
17
|
-
["agents", { scope: "agent",
|
|
18
|
-
["models", { scope: "model",
|
|
15
|
+
["sessions", { scope: "session", dir: "sessions" }],
|
|
16
|
+
["projects", { scope: "project", dir: "project" }],
|
|
17
|
+
["agents", { scope: "agent", dir: "agents" }],
|
|
18
|
+
["models", { scope: "model", dir: "models" }],
|
|
19
19
|
]);
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -55,7 +55,7 @@ export function assertGlobPattern(value: unknown): string | undefined {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
* Decode one public note address into its physical
|
|
58
|
+
* Decode one public note address into its physical namespace and virtual path. @self and @model
|
|
59
59
|
* are relative; projects/agents/models name a canonical slug, sessions a directory component.
|
|
60
60
|
*/
|
|
61
61
|
export function assertAddress(value: unknown): NoteAddress {
|
|
@@ -65,10 +65,10 @@ export function assertAddress(value: unknown): NoteAddress {
|
|
|
65
65
|
let who: string | undefined;
|
|
66
66
|
if (value.startsWith("@")) {
|
|
67
67
|
const [rawHead, ...tail] = value.slice(1).split("/");
|
|
68
|
-
const head =
|
|
68
|
+
const head = NAMESPACE_HEADS.get(rawHead!);
|
|
69
69
|
if (head === undefined) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
70
70
|
scope = head.scope;
|
|
71
|
-
if (head.
|
|
71
|
+
if (head.dir === undefined) path = tail.join("/");
|
|
72
72
|
else {
|
|
73
73
|
who = tail[0] ?? "";
|
|
74
74
|
if (!(scope === "session" ? isSessionId(who) : SLUG_PATTERN.test(who))) throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
@@ -91,9 +91,9 @@ export function canonicalAddressFor(identity: NotesIdentity, scope: Scope, path:
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
* Render the address a caller sees. The current agent and model
|
|
95
|
-
* @model/. Current session and project
|
|
96
|
-
* named session/project
|
|
94
|
+
* Render the address a caller sees. The current agent and model notebooks read as @self/ and
|
|
95
|
+
* @model/. Current session and project notebooks retain bare paths and @project/; explicitly
|
|
96
|
+
* named session/project notebooks keep their read-only addresses, even for the current identity.
|
|
97
97
|
*/
|
|
98
98
|
export function addressFor(identity: NotesIdentity, scope: Scope, path: string, who?: string): string {
|
|
99
99
|
if (scope === "session" && who === undefined) return path;
|
package/src/notes/errors.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type NoteErrorCode = "not_found" | "already_exists" | "ambiguous_edit" | "no_match" | "invalid_edit" | "nothing_to_do" | "not_crumpled" | "too_large" | "invalid_scope" | "invalid_origin" | "invalid_address" | "invalid_pattern" | "invalid_query" | "invalid_offset" | "io_error" | "internal_error";
|
|
1
|
+
export type NoteErrorCode = "not_found" | "already_exists" | "ambiguous_edit" | "no_match" | "invalid_edit" | "nothing_to_do" | "not_crumpled" | "too_large" | "invalid_scope" | "invalid_origin" | "invalid_address" | "invalid_pattern" | "invalid_query" | "invalid_offset" | "invalid_cwd" | "io_error" | "internal_error";
|
|
2
2
|
|
|
3
3
|
/** Typed store refusal. Edit locations are exposed in camelCase. */
|
|
4
4
|
export class NoteError extends Error {
|
package/src/notes/frontmatter.ts
CHANGED
|
@@ -123,7 +123,7 @@ function parseFrontmatter(raw: string): { fields: Record<string, unknown>; body:
|
|
|
123
123
|
export function parseNote(raw: string, now = Date.now()): { meta: NoteMeta; body: string } {
|
|
124
124
|
const { fields, body } = parseFrontmatter(raw);
|
|
125
125
|
const meta = { ...fields } as Record<string, unknown>;
|
|
126
|
-
// scope is a legacy on-disk field: store callers derive it from the file's
|
|
126
|
+
// scope is a legacy on-disk field: store callers derive it from the file's notebook and
|
|
127
127
|
// overwrite it after parsing, so an absent or outdated value just falls back.
|
|
128
128
|
meta.scope = isScope(meta.scope) ? meta.scope : "session";
|
|
129
129
|
meta.origin = isOrigin(meta.origin) ? meta.origin : "self";
|
|
@@ -161,7 +161,7 @@ export function serializeNote(meta: NoteMeta, body: string): string {
|
|
|
161
161
|
else lines.push(`${key}: ${yamlScalar(value)}`);
|
|
162
162
|
}
|
|
163
163
|
for (const key of Object.keys(meta)) {
|
|
164
|
-
// scope is a legacy on-disk field. Store callers derive it from the
|
|
164
|
+
// scope is a legacy on-disk field. Store callers derive it from the notebook's location,
|
|
165
165
|
// but serialization intentionally drops it on the next write.
|
|
166
166
|
if (key === "scope" || (KNOWN_KEYS as readonly string[]).includes(key)) continue;
|
|
167
167
|
if (meta[key] === undefined) continue;
|
package/src/notes/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createNotesStore, noteIdentity } from "./store.js";
|
|
2
2
|
export { NoteError, type NoteErrorCode } from "./errors.js";
|
|
3
|
-
export { projectKey } from "./project-
|
|
3
|
+
export { projectKey } from "./project-namespace.js";
|
|
4
4
|
export { slugify } from "./paths.js";
|
|
5
5
|
export { snapshotNotesIdentity, type NotesIdentity } from "./identity.js";
|
|
6
6
|
export { isFilesystemError } from "./fs-error.js";
|
package/src/notes/paths.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { NotesIdentity } from "./identity.js";
|
|
|
5
5
|
|
|
6
6
|
export type Scope = "session" | "project" | "human" | "agent" | "model";
|
|
7
7
|
|
|
8
|
-
/** The one legal
|
|
8
|
+
/** The one legal namespace-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
|
|
9
9
|
export const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
10
10
|
|
|
11
11
|
/** Session identities use the same single-directory-component grammar as NotesIdentity, not slugs. */
|
|
@@ -22,7 +22,7 @@ export function slugify(value: string): string {
|
|
|
22
22
|
/**
|
|
23
23
|
* The one virtual-path grammar: a relative, `/`-separated path with no empty, `.` or `..`
|
|
24
24
|
* segment. Both the address decoder and the physical-path builder enforce it here, so a
|
|
25
|
-
* caller that reaches a path without going through an address still cannot escape a
|
|
25
|
+
* caller that reaches a path without going through an address still cannot escape a namespace.
|
|
26
26
|
*/
|
|
27
27
|
export function assertVirtualPath(value: unknown): string {
|
|
28
28
|
if (typeof value !== "string" || value.length === 0) throw new NoteError("invalid_address", "The address is empty; give the note a path.");
|
|
@@ -32,8 +32,8 @@ export function assertVirtualPath(value: unknown): string {
|
|
|
32
32
|
return value;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
/** Absolute directory holding the per-session note
|
|
36
|
-
export function
|
|
35
|
+
/** Absolute directory holding the per-session note namespaces. */
|
|
36
|
+
export function sessionNamespacesRoot(home: string): string {
|
|
37
37
|
return join(home, "pi", "session");
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -45,15 +45,15 @@ export function scopeDir(scope: Scope, identity: NotesIdentity, who?: string): s
|
|
|
45
45
|
if (scope === "project") return join(identity.home, "project", who ?? identity.projectKey);
|
|
46
46
|
if (scope === "agent") return join(identity.home, "agents", who ?? identity.agent);
|
|
47
47
|
if (scope === "model") return join(identity.home, "models", who ?? identity.model);
|
|
48
|
-
return join(
|
|
48
|
+
return join(sessionNamespacesRoot(identity.home), who ?? identity.sessionId);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
/** Every addressable
|
|
52
|
-
export async function namespaceSlugs(
|
|
53
|
-
const root =
|
|
51
|
+
/** Every addressable directory of a namespace family; sessions keep their original identity spelling. */
|
|
52
|
+
export async function namespaceSlugs(family: "sessions" | "project" | "agents" | "models", home: string): Promise<string[]> {
|
|
53
|
+
const root = family === "sessions" ? sessionNamespacesRoot(home) : join(home, family);
|
|
54
54
|
try {
|
|
55
55
|
return (await readdir(root, { withFileTypes: true }))
|
|
56
|
-
.filter((entry) => entry.isDirectory() && (
|
|
56
|
+
.filter((entry) => entry.isDirectory() && (family === "sessions" ? isSessionId(entry.name) : SLUG_PATTERN.test(entry.name)))
|
|
57
57
|
.map((entry) => entry.name)
|
|
58
58
|
.sort();
|
|
59
59
|
} catch (error) {
|