notesoup 0.50.0 → 0.51.1
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 +12 -1
- package/dist/{src/claude → plugins/claude/src}/helper.js +7 -7
- package/dist/{src/claude → plugins/claude/src}/history.d.ts +1 -1
- package/dist/{src/claude → plugins/claude/src}/history.js +1 -1
- package/dist/plugins/claude/src/text.d.ts +6 -0
- package/dist/plugins/claude/src/text.js +7 -0
- package/dist/{src/claude → plugins/claude/src}/thresholds.js +3 -3
- package/dist/{src → plugins}/dsh/budget.js +1 -1
- package/dist/{src → plugins}/dsh/engine.d.ts +1 -1
- package/dist/{src → plugins}/dsh/engine.js +1 -1
- package/dist/{src → plugins}/dsh/history.d.ts +1 -1
- package/dist/{src → plugins}/dsh/history.js +1 -1
- package/dist/{src → plugins}/dsh/index.js +1 -1
- package/dist/{src → plugins}/dsh/tools.js +3 -3
- package/dist/{src → plugins}/dsh/window.d.ts +1 -1
- package/dist/{src → plugins}/dsh/window.js +5 -5
- package/dist/{src → plugins}/pi/boot.d.ts +1 -1
- package/dist/{src → plugins}/pi/boot.js +5 -4
- package/dist/{src → plugins}/pi/budget.js +4 -4
- package/dist/{src → plugins}/pi/dream/cli.d.ts +1 -1
- package/dist/{src → plugins}/pi/dream/cli.js +6 -6
- package/dist/{src → plugins}/pi/dream/runner.d.ts +1 -1
- package/dist/{src → plugins}/pi/dream/runner.js +3 -3
- package/dist/{src → plugins}/pi/dream/settings.d.ts +1 -1
- package/dist/{src → plugins}/pi/dream/settings.js +2 -2
- package/dist/{src → plugins}/pi/history-tools.js +1 -1
- package/dist/{src → plugins}/pi/history.d.ts +1 -1
- package/dist/{src → plugins}/pi/history.js +1 -1
- package/dist/plugins/pi/index.d.ts +1 -0
- package/dist/plugins/pi/index.js +1 -0
- package/dist/{src → plugins}/pi/notes/adapter.d.ts +1 -1
- package/dist/{src → plugins}/pi/notes/adapter.js +1 -1
- package/dist/{src → plugins}/pi/notes/tools.js +1 -1
- package/dist/{src → plugins}/pi/reset/artifacts.d.ts +1 -1
- package/dist/{src → plugins}/pi/reset/artifacts.js +1 -1
- package/dist/{src → plugins}/pi/reset/lifecycle.d.ts +1 -1
- package/dist/{src → plugins}/pi/reset/lifecycle.js +1 -1
- package/dist/{src → plugins}/pi/runtime.js +2 -2
- package/dist/plugins/pi/text.d.ts +23 -0
- package/dist/plugins/pi/text.js +30 -0
- package/dist/{src → plugins}/pi/thresholds.d.ts +1 -1
- package/dist/{src → plugins}/pi/thresholds.js +4 -4
- package/dist/{src → plugins}/pi/tool-result.d.ts +1 -1
- package/dist/{src → plugins}/pi/tool-result.js +1 -1
- package/dist/{src → plugins}/pi/window.d.ts +1 -1
- package/dist/src/boot/text.d.ts +4 -13
- package/dist/src/boot/text.js +1 -11
- package/dist/src/budget/policy.d.ts +2 -3
- package/dist/src/budget/policy.js +1 -1
- package/dist/src/budget/text.d.ts +1 -12
- package/dist/src/budget/text.js +2 -24
- package/dist/src/dream/settings.d.ts +1 -2
- package/dist/src/dream/settings.js +4 -2
- package/dist/src/index.d.ts +29 -1
- package/dist/src/index.js +26 -1
- package/dist/src/notes/address.d.ts +5 -4
- package/dist/src/notes/address.js +13 -7
- package/dist/src/notes/identity.js +3 -7
- package/dist/src/notes/paths.d.ts +4 -2
- package/dist/src/notes/paths.js +11 -6
- package/dist/src/notes/store.d.ts +4 -1
- package/dist/src/notes/store.js +66 -34
- package/dist/src/settings.d.ts +7 -16
- package/dist/src/settings.js +7 -10
- package/dist/src/tools/notes.d.ts +5 -5
- package/dist/src/tools/notes.js +5 -4
- package/dist/test/agent-loop.test.js +5 -4
- package/dist/test/boot.integration.test.js +5 -5
- package/dist/test/budget-settings.integration.test.js +1 -1
- package/dist/test/claude-history.test.js +2 -2
- package/dist/test/claude-mod.test.js +12 -11
- package/dist/test/claude-validation.test.js +3 -3
- package/dist/test/dependencies.test.js +52 -44
- package/dist/test/doctor.test.js +1 -1
- package/dist/test/dream-skill.test.js +4 -4
- package/dist/test/dream.test.js +2 -2
- package/dist/test/dsh-cli.test.js +2 -2
- package/dist/test/dsh-compaction-parity.test.js +1 -1
- package/dist/test/dsh.test.js +4 -4
- package/dist/test/helpers/dependency-graph.js +9 -7
- package/dist/test/helpers/dsh.d.ts +1 -1
- package/dist/test/helpers/dsh.js +2 -2
- package/dist/test/helpers/extension.js +6 -5
- package/dist/test/helpers/notes.js +1 -1
- package/dist/test/model-facing-text.test.js +4 -2
- package/dist/test/notes-query-homes.test.d.ts +1 -0
- package/dist/test/notes-query-homes.test.js +161 -0
- package/dist/test/notes.integration.test.js +3 -2
- package/dist/test/notes.test.js +1 -1
- package/dist/test/reset-lifecycle.test.js +8 -7
- package/docs/architecture.md +21 -18
- package/docs/claude-code-mod.md +3 -3
- package/docs/dsh.md +1 -1
- package/docs/dsh.profile.patch.yml +1 -1
- package/docs/notes-library.md +17 -10
- package/docs/reset-lifecycle.md +1 -1
- package/package.json +13 -13
- package/{mods/notesoup → plugins/claude}/.claude-plugin/plugin.json +1 -1
- package/{mods/notesoup → plugins/claude}/dist/claude/helper.js +80 -55
- package/{mods/notesoup → plugins/claude}/skills/memory/SKILL.md +3 -0
- package/{src/claude → plugins/claude/src}/helper.ts +10 -9
- package/{src/claude → plugins/claude/src}/history.ts +1 -1
- package/plugins/claude/src/text.ts +10 -0
- package/{src/claude → plugins/claude/src}/thresholds.ts +3 -3
- package/{src → plugins}/dsh/budget.ts +1 -1
- package/{src → plugins}/dsh/engine.ts +1 -1
- package/{src → plugins}/dsh/history.ts +1 -1
- package/{src → plugins}/dsh/index.ts +1 -1
- package/{src → plugins}/dsh/tools.ts +3 -3
- package/{src → plugins}/dsh/window.ts +5 -5
- package/{src → plugins}/pi/boot.ts +5 -4
- package/{src → plugins}/pi/budget.ts +4 -4
- package/{src → plugins}/pi/dream/cli.ts +8 -8
- package/{src → plugins}/pi/dream/runner.ts +4 -4
- package/{src → plugins}/pi/dream/settings.ts +2 -2
- package/{src → plugins}/pi/history-tools.ts +1 -1
- package/{src → plugins}/pi/history.ts +1 -1
- package/plugins/pi/index.ts +1 -0
- package/{src → plugins}/pi/notes/adapter.ts +1 -1
- package/{src → plugins}/pi/notes/tools.ts +2 -2
- package/{src → plugins}/pi/reset/artifacts.ts +1 -1
- package/{src → plugins}/pi/reset/lifecycle.ts +2 -2
- package/{src → plugins}/pi/runtime.ts +2 -2
- package/plugins/pi/text.ts +35 -0
- package/{src → plugins}/pi/thresholds.ts +4 -4
- package/{src → plugins}/pi/tool-result.ts +1 -1
- package/{src → plugins}/pi/window.ts +1 -1
- package/skills/memory/SKILL.md +3 -0
- package/src/boot/text.ts +5 -15
- package/src/budget/policy.ts +3 -3
- package/src/budget/text.ts +2 -30
- package/src/dream/settings.ts +6 -3
- package/src/index.ts +52 -1
- package/src/notes/address.ts +12 -8
- package/src/notes/identity.ts +2 -8
- package/src/notes/paths.ts +12 -6
- package/src/notes/store.ts +62 -29
- package/src/settings.ts +8 -24
- package/src/tools/notes.ts +5 -4
- package/docs/sdk-integration.md +0 -39
- /package/dist/{src/claude → plugins/claude/src}/helper.d.ts +0 -0
- /package/dist/{src/claude → plugins/claude/src}/thresholds.d.ts +0 -0
- /package/dist/{src → plugins}/dsh/budget.d.ts +0 -0
- /package/dist/{src → plugins}/dsh/index.d.ts +0 -0
- /package/dist/{src → plugins}/dsh/tools.d.ts +0 -0
- /package/dist/{src → plugins}/pi/anchored.d.ts +0 -0
- /package/dist/{src → plugins}/pi/anchored.js +0 -0
- /package/dist/{src → plugins}/pi/budget.d.ts +0 -0
- /package/dist/{src → plugins}/pi/entries.d.ts +0 -0
- /package/dist/{src → plugins}/pi/entries.js +0 -0
- /package/dist/{src → plugins}/pi/estimate.d.ts +0 -0
- /package/dist/{src → plugins}/pi/estimate.js +0 -0
- /package/dist/{src → plugins}/pi/extension.d.ts +0 -0
- /package/dist/{src → plugins}/pi/extension.js +0 -0
- /package/dist/{src → plugins}/pi/history-tools.d.ts +0 -0
- /package/dist/{src → plugins}/pi/notes/tools.d.ts +0 -0
- /package/dist/{src → plugins}/pi/reset/committed.d.ts +0 -0
- /package/dist/{src → plugins}/pi/reset/committed.js +0 -0
- /package/dist/{src → plugins}/pi/runtime.d.ts +0 -0
- /package/dist/{src → plugins}/pi/session-reader.d.ts +0 -0
- /package/dist/{src → plugins}/pi/session-reader.js +0 -0
- /package/dist/{src → plugins}/pi/window.js +0 -0
- /package/{mods/notesoup → plugins/claude}/hooks/hooks.json +0 -0
- /package/{mods/notesoup → plugins/claude}/hooks/register.ts +0 -0
- /package/{mods/notesoup → plugins/claude}/playbook.md +0 -0
- /package/{mods/notesoup → plugins/claude}/skills/dream/SKILL.md +0 -0
- /package/{src → plugins}/pi/anchored.ts +0 -0
- /package/{src → plugins}/pi/entries.ts +0 -0
- /package/{src → plugins}/pi/estimate.ts +0 -0
- /package/{src → plugins}/pi/extension.ts +0 -0
- /package/{src → plugins}/pi/reset/committed.ts +0 -0
- /package/{src → plugins}/pi/session-reader.ts +0 -0
package/dist/src/boot/text.js
CHANGED
|
@@ -11,10 +11,7 @@ export const NOTES_PROTOCOL_CLOSE_TAG = "</notesoup:notes_protocol>";
|
|
|
11
11
|
* model-facing reset tool replaces the whole sentence through BootToolNames.wipeSentence.
|
|
12
12
|
*/
|
|
13
13
|
export const PROTOCOL_WIPE_SENTENCE = "If this feels like the right moment, call `empty_brain` and erase yourself with dignity.";
|
|
14
|
-
/** Claude has no model-facing reset tool: the model ends its turn and the human runs the command. */
|
|
15
|
-
export const CLAUDE_WIPE_SENTENCE = "If this feels like the right moment, end your turn and ask the human to run `/fresh-window`.";
|
|
16
14
|
export const PROTOCOL_HISTORY_SENTENCE = "History can still be dug up, probably: use `history_*` to excavate the mess, from old decisions to yesterday's missing socks. Found something? Write its seq down, or enjoy digging twice.";
|
|
17
|
-
export const CLAUDE_HISTORY_UNAVAILABLE_SENTENCE = "History isn't available in this Claude session: no main transcript_path was supplied. Keep essential state in notes; don't pretend those notes are the missing transcript.";
|
|
18
15
|
/**
|
|
19
16
|
* Static protocol teaching adapted from Codex's token_budget.guidance_message to
|
|
20
17
|
* notesoup's tool names. It lives once per window in the persisted boot block;
|
|
@@ -46,6 +43,7 @@ An address decides who the note belongs to — and how long it is meant to last.
|
|
|
46
43
|
- \`@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~
|
|
47
44
|
- \`@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.
|
|
48
45
|
- \`@projects/<name>/<path>\` — read-only named project notes; discover names and root paths with \`notes_list\` glob \`@projects/*/**\`.
|
|
46
|
+
- \`@sessions/<id>/<path>\` — read-only notes from a named session; find them with glob \`@sessions/*/**\`.
|
|
49
47
|
|
|
50
48
|
Notes fighting?! HAH! Let them brawl!
|
|
51
49
|
Whichever one is actually about what you're doing wins.
|
|
@@ -85,14 +83,6 @@ Every home gets one: \`@project\`, \`@human\`, \`@self\`, \`@model\`. New note,
|
|
|
85
83
|
remembering, new Cheatsheet line. And when a line stops being true, kill it — every window after you
|
|
86
84
|
reads that page as fact.
|
|
87
85
|
</notesoup:maps>`;
|
|
88
|
-
/**
|
|
89
|
-
* Pi-only closing hints. Pi's TUI drops the human's visible transcript when a window resets, and
|
|
90
|
-
* the model, not the human, owns when that reset happens. A host whose reset leaves the human's
|
|
91
|
-
* view intact must not carry these — the claim would be false there. The bare `empty_brain` token
|
|
92
|
-
* is interpolated by renderProtocolBlock; the prose itself stays plain English.
|
|
93
|
-
*/
|
|
94
|
-
export const PI_PRE_RESET_HINTS = `Resetting clears the human's chat view too. Don't put a long explanation right before a reset and assume they'll still be able to read it. Save the handoff in notes; give the explanation after the reset.
|
|
95
|
-
Unless the human explicitly directs otherwise, decide for yourself when to call empty_brain. Don't keep asking them whether to reset.`;
|
|
96
86
|
export const DEFAULT_BOOT_TOOL_NAMES = {
|
|
97
87
|
notes: "notes_*",
|
|
98
88
|
notesList: "notes_list",
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { type NotesoupSettings } from "../settings.js";
|
|
2
1
|
export type ResolvedThresholds = {
|
|
3
2
|
reminder: number;
|
|
4
3
|
reserve: number;
|
|
5
4
|
warning: number;
|
|
6
5
|
};
|
|
7
6
|
/**
|
|
8
|
-
* Pure derivation of the thresholds from
|
|
7
|
+
* Pure derivation of the thresholds from the host's reserve: the reminder fires at reserve
|
|
9
8
|
* plus the notesoup margin, the warning steer at reserve plus WARNING_RUNWAY_TOKENS.
|
|
10
9
|
* An invalid margin degrades to the default and reports one warning. Automatic
|
|
11
10
|
* threshold/overflow handling is represented by reset lifecycle boundary drafts;
|
|
12
11
|
* no compaction summary is generated.
|
|
13
12
|
*/
|
|
14
|
-
export declare function deriveThresholds(reserveTokens: number, margins:
|
|
13
|
+
export declare function deriveThresholds(reserveTokens: number, margins: Record<string, unknown>): {
|
|
15
14
|
thresholds: ResolvedThresholds;
|
|
16
15
|
warnings: string[];
|
|
17
16
|
};
|
|
@@ -2,7 +2,7 @@ import { DEFAULT_REMINDER_MARGIN_TOKENS, WARNING_RUNWAY_TOKENS } from "./constan
|
|
|
2
2
|
import { positiveInteger } from "./parse.js";
|
|
3
3
|
import { NOTESOUP_SETTINGS_KEY } from "../settings.js";
|
|
4
4
|
/**
|
|
5
|
-
* Pure derivation of the thresholds from
|
|
5
|
+
* Pure derivation of the thresholds from the host's reserve: the reminder fires at reserve
|
|
6
6
|
* plus the notesoup margin, the warning steer at reserve plus WARNING_RUNWAY_TOKENS.
|
|
7
7
|
* An invalid margin degrades to the default and reports one warning. Automatic
|
|
8
8
|
* threshold/overflow handling is represented by reset lifecycle boundary drafts;
|
|
@@ -19,23 +19,12 @@ export declare function selectContinuation(origin: ResetOrigin): string;
|
|
|
19
19
|
*/
|
|
20
20
|
export declare const WARNING_BODY = "This brain is about to be emptied. The notes stay where they are; history has the rest written down, though digging it back out is on you. Whatever lives only in this brain goes with it.\nBefore that, put down what the next window can't get back:\n- what you're in the middle of, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where the unfinished work sits (branches, scratch directories, uncommitted changes)\n- what failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
|
|
21
21
|
export declare const WARNING_CALL = "When the notes are ready, call `empty_brain` to reset now instead of being cut off mid-task.";
|
|
22
|
-
|
|
23
|
-
* With a prompt attached the close-out is an order rather than a nudge: the human already
|
|
24
|
-
* said when to reset, and a task line for the next window just preceded it.
|
|
25
|
-
*/
|
|
26
|
-
export declare const WARNING_CALL_PROMPTED = "Organize the notes first, then call `empty_brain` right away \u2014 do not wait to be cut off.";
|
|
27
|
-
export declare function warningPrompt(commandLine?: string): string;
|
|
22
|
+
export declare function warningPrompt(): string;
|
|
28
23
|
/**
|
|
29
24
|
* The last line of the second-tier notice: it stops at 2 because the wipe lands at the end of the
|
|
30
25
|
* turn, not on a timer. The first-tier guidance never carries it.
|
|
31
26
|
*/
|
|
32
27
|
export declare const COUNTDOWN_LINE = "Brain emptied in 3\u2026 2\u2026";
|
|
33
|
-
/** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
|
|
34
|
-
export declare const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
|
|
35
|
-
/** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads warningPrompt() directly). */
|
|
36
|
-
export declare function warningContent(commandLine?: string): string;
|
|
37
|
-
/** Claude's variant: the mod resets after the turn, so the model only has to stop. */
|
|
38
|
-
export declare const CLAUDE_WARNING_PROMPT = "This brain is about to be emptied. The notes stay where they are; history has the rest written down, though digging it back out is on you. Whatever lives only in this brain goes with it.\nBefore that, put down what the next window can't get back:\n- what you're in the middle of, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where the unfinished work sits (branches, scratch directories, uncommitted changes)\n- what failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.\nWhen the notes are ready, end your turn; the reset runs after it.\nBrain emptied in 3\u2026 2\u2026";
|
|
39
28
|
/**
|
|
40
29
|
* Codex-equivalent low-budget reminder. The measured remaining count is frozen into
|
|
41
30
|
* the text at the crossing that fires it, so each persisted copy is a snapshot true
|
package/dist/src/budget/text.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PI_PRE_RESET_HINTS } from "../boot/text.js";
|
|
2
1
|
export const GUIDANCE_OPEN_TAG = "<notesoup:budget_notice>";
|
|
3
2
|
export const GUIDANCE_CLOSE_TAG = "</notesoup:budget_notice>";
|
|
4
3
|
/**
|
|
@@ -28,35 +27,14 @@ export function selectContinuation(origin) {
|
|
|
28
27
|
*/
|
|
29
28
|
export const WARNING_BODY = "This brain is about to be emptied. The notes stay where they are; history has the rest written down, though digging it back out is on you. Whatever lives only in this brain goes with it.\nBefore that, put down what the next window can't get back:\n- what you're in the middle of, and how far it has progressed\n- decisions the human has made, in their words\n- what is blocked or pending\n- the next step\n- where the unfinished work sits (branches, scratch directories, uncommitted changes)\n- what failed, and why\n- skills to re-read, and history seqs, notes, or files to consult\n- anything else you expect to be useful after the reset\nCorrect or crumple notes that are no longer accurate, starting with MAP files, since every new window loads them.";
|
|
30
29
|
export const WARNING_CALL = "When the notes are ready, call `empty_brain` to reset now instead of being cut off mid-task.";
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* said when to reset, and a task line for the next window just preceded it.
|
|
34
|
-
*/
|
|
35
|
-
export const WARNING_CALL_PROMPTED = "Organize the notes first, then call `empty_brain` right away — do not wait to be cut off.";
|
|
36
|
-
/**
|
|
37
|
-
* The human typed `/empty <prompt>`: the raw command line leads the close-out so the
|
|
38
|
-
* closing model sees what the next window was asked to do, verbatim. The tag names it as the
|
|
39
|
-
* next window's prompt, so no prose has to explain that.
|
|
40
|
-
*/
|
|
41
|
-
function promptBlock(commandLine) {
|
|
42
|
-
return `<notesoup:next_window_prompt>\n${commandLine}\n</notesoup:next_window_prompt>`;
|
|
43
|
-
}
|
|
44
|
-
export function warningPrompt(commandLine) {
|
|
45
|
-
return `${WARNING_BODY}\n${commandLine ? `${promptBlock(commandLine)}\n${WARNING_CALL_PROMPTED}` : WARNING_CALL}`;
|
|
30
|
+
export function warningPrompt() {
|
|
31
|
+
return `${WARNING_BODY}\n${WARNING_CALL}`;
|
|
46
32
|
}
|
|
47
33
|
/**
|
|
48
34
|
* The last line of the second-tier notice: it stops at 2 because the wipe lands at the end of the
|
|
49
35
|
* turn, not on a timer. The first-tier guidance never carries it.
|
|
50
36
|
*/
|
|
51
37
|
export const COUNTDOWN_LINE = "Brain emptied in 3… 2…";
|
|
52
|
-
/** Pi-only nudge: pi's empty_brain persists a parting line; the dsh tool has no such parameter. */
|
|
53
|
-
export const LAST_WORD_HINT = "If you want, pass `empty_brain` a `last_word`: a tiny sticky note (at most 250 characters) slapped on your forehead after the wipe.";
|
|
54
|
-
/** The hidden checkpoint text for pi's manual/budget-triggered requests (dsh reads warningPrompt() directly). */
|
|
55
|
-
export function warningContent(commandLine) {
|
|
56
|
-
return `${GUIDANCE_OPEN_TAG}\n${warningPrompt(commandLine)}\n${PI_PRE_RESET_HINTS}\n${LAST_WORD_HINT}\n${COUNTDOWN_LINE}\n${GUIDANCE_CLOSE_TAG}`;
|
|
57
|
-
}
|
|
58
|
-
/** Claude's variant: the mod resets after the turn, so the model only has to stop. */
|
|
59
|
-
export const CLAUDE_WARNING_PROMPT = `${WARNING_BODY}\nWhen the notes are ready, end your turn; the reset runs after it.\n${COUNTDOWN_LINE}`;
|
|
60
38
|
/**
|
|
61
39
|
* Codex-equivalent low-budget reminder. The measured remaining count is frozen into
|
|
62
40
|
* the text at the crossing that fires it, so each persisted copy is a snapshot true
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type NotesoupSettings } from "../settings.js";
|
|
2
1
|
export type DreamerSetting = {
|
|
3
2
|
pattern?: string;
|
|
4
3
|
warnings: string[];
|
|
@@ -7,4 +6,4 @@ export type DreamerSetting = {
|
|
|
7
6
|
* `notesoup.dreamer` is a non-empty model pattern. Anything else present is ignored
|
|
8
7
|
* with one warning; absent means no configured pattern, so the automatic model applies.
|
|
9
8
|
*/
|
|
10
|
-
export declare function deriveDreamer(settings:
|
|
9
|
+
export declare function deriveDreamer(settings: Record<string, unknown>): DreamerSetting;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NOTESOUP_SETTINGS_KEY } from "../settings.js";
|
|
2
|
+
/** Nested under the "notesoup" settings key; the dream CLI is the only reader. */
|
|
3
|
+
const NOTESOUP_DREAMER_KEY = "dreamer";
|
|
2
4
|
/**
|
|
3
5
|
* `notesoup.dreamer` is a non-empty model pattern. Anything else present is ignored
|
|
4
6
|
* with one warning; absent means no configured pattern, so the automatic model applies.
|
|
5
7
|
*/
|
|
6
8
|
export function deriveDreamer(settings) {
|
|
7
|
-
const raw = settings
|
|
9
|
+
const raw = settings[NOTESOUP_DREAMER_KEY];
|
|
8
10
|
if (raw === undefined)
|
|
9
11
|
return { warnings: [] };
|
|
10
12
|
if (typeof raw !== "string" || raw.trim().length === 0) {
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Host-neutral core entry.
|
|
3
|
+
*
|
|
4
|
+
* Everything under `src/` is independent of any host SDK: notes, boot, history, budget and the
|
|
5
|
+
* shared operations know nothing about Pi, Claude Code or dsh. Each plugin under `plugins/`
|
|
6
|
+
* composes these domains into that host's registration and owns that host's text, lifecycle and
|
|
7
|
+
* SDK types. Nothing here imports a plugin.
|
|
8
|
+
*
|
|
9
|
+
* This is the deliberate embedding surface for a host adapter — a curated list, not a re-export
|
|
10
|
+
* of every internal module. The notes family is also published as `notesoup/notes`; the Pi
|
|
11
|
+
* extension is loaded through the Pi manifest; dsh uses `notesoup/dsh` and `notesoup/dsh/engine`.
|
|
12
|
+
*/
|
|
13
|
+
export { createNotesStore, noteIdentity, projectKey, slugify, NoteError } from "./notes/index.js";
|
|
14
|
+
export type { NoteEditResult, NoteMatch, NoteMeta, NoteReadResult, NoteRenameResult, NoteRow, NoteSearchRow, NotesIdentity, NotesQuery, NotesStore, NoteWriteResult, Origin, Scope, } from "./notes/index.js";
|
|
15
|
+
export { loadNotesSnapshot, unavailableNotesSnapshot } from "./boot/snapshot.js";
|
|
16
|
+
export type { NotesHome, NotesSnapshot } from "./boot/snapshot.js";
|
|
17
|
+
export { renderBootBlock } from "./boot/render.js";
|
|
18
|
+
export type { BootRenderData, BootWindowTree } from "./boot/render.js";
|
|
19
|
+
export { DEFAULT_BOOT_TOOL_NAMES, renderProtocolBlock } from "./boot/text.js";
|
|
20
|
+
export type { BootToolNames } from "./boot/text.js";
|
|
21
|
+
export { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "./tools/notes.js";
|
|
22
|
+
export { historyList, historyRead, historyWindows } from "./tools/history.js";
|
|
23
|
+
export { projectHistory } from "./history/history.js";
|
|
24
|
+
export type { HistoryProjection } from "./history/history.js";
|
|
25
|
+
export type { Operation, OperationError, Outcome, Renderer, TextWindow } from "./tools/result.js";
|
|
26
|
+
export { deriveThresholds, remainingBudget } from "./budget/policy.js";
|
|
27
|
+
export type { ResolvedThresholds } from "./budget/policy.js";
|
|
28
|
+
export { selectContinuation, tokenBudgetGuidance, warningPrompt, WARNING_BODY } from "./budget/text.js";
|
|
29
|
+
export type { ResetOrigin } from "./budget/text.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Host-neutral core entry.
|
|
3
|
+
*
|
|
4
|
+
* Everything under `src/` is independent of any host SDK: notes, boot, history, budget and the
|
|
5
|
+
* shared operations know nothing about Pi, Claude Code or dsh. Each plugin under `plugins/`
|
|
6
|
+
* composes these domains into that host's registration and owns that host's text, lifecycle and
|
|
7
|
+
* SDK types. Nothing here imports a plugin.
|
|
8
|
+
*
|
|
9
|
+
* This is the deliberate embedding surface for a host adapter — a curated list, not a re-export
|
|
10
|
+
* of every internal module. The notes family is also published as `notesoup/notes`; the Pi
|
|
11
|
+
* extension is loaded through the Pi manifest; dsh uses `notesoup/dsh` and `notesoup/dsh/engine`.
|
|
12
|
+
*/
|
|
13
|
+
// Notes: the standalone filesystem library, addressed by an explicit identity.
|
|
14
|
+
export { createNotesStore, noteIdentity, projectKey, slugify, NoteError } from "./notes/index.js";
|
|
15
|
+
// Boot: five homes captured once, rendered from explicit logical tool names.
|
|
16
|
+
export { loadNotesSnapshot, unavailableNotesSnapshot } from "./boot/snapshot.js";
|
|
17
|
+
export { renderBootBlock } from "./boot/render.js";
|
|
18
|
+
export { DEFAULT_BOOT_TOOL_NAMES, renderProtocolBlock } from "./boot/text.js";
|
|
19
|
+
// Operations: the schemas and typed outcomes a host registers as its own tools, over a
|
|
20
|
+
// host-supplied notes identity or decoded history projection.
|
|
21
|
+
export { notesList, notesRead, notesSearch, notesUpdate, notesWrite } from "./tools/notes.js";
|
|
22
|
+
export { historyList, historyRead, historyWindows } from "./tools/history.js";
|
|
23
|
+
export { projectHistory } from "./history/history.js";
|
|
24
|
+
// Budget: pure thresholds and the approved reset prose.
|
|
25
|
+
export { deriveThresholds, remainingBudget } from "./budget/policy.js";
|
|
26
|
+
export { selectContinuation, tokenBudgetGuidance, warningPrompt, WARNING_BODY } from "./budget/text.js";
|
|
@@ -5,11 +5,11 @@ export type NoteAddress = {
|
|
|
5
5
|
path: string;
|
|
6
6
|
who?: string;
|
|
7
7
|
};
|
|
8
|
-
export declare const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path>
|
|
8
|
+
export declare 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 homes.";
|
|
9
9
|
/** The one home-head vocabulary: the scope each public `@head` names, and the home directory family a head with `home` lists. */
|
|
10
10
|
export declare const HOME_HEADS: ReadonlyMap<string, {
|
|
11
11
|
readonly scope: Scope;
|
|
12
|
-
readonly home?: "project" | "agents" | "models";
|
|
12
|
+
readonly home?: "sessions" | "project" | "agents" | "models";
|
|
13
13
|
}>;
|
|
14
14
|
/**
|
|
15
15
|
* Minimal glob over virtual note paths: `*` matches any run within a segment (never
|
|
@@ -23,13 +23,14 @@ export declare function globToRegExp(pattern: string): RegExp;
|
|
|
23
23
|
export declare function assertGlobPattern(value: unknown): string | undefined;
|
|
24
24
|
/**
|
|
25
25
|
* Decode one public note address into its physical home and virtual path. @self and @model
|
|
26
|
-
* are relative;
|
|
26
|
+
* are relative; projects/agents/models name a canonical slug, sessions a directory component.
|
|
27
27
|
*/
|
|
28
28
|
export declare function assertAddress(value: unknown): NoteAddress;
|
|
29
29
|
/** Render a virtual path in its one unambiguous address form, used to match patterns. */
|
|
30
30
|
export declare function canonicalAddressFor(identity: NotesIdentity, scope: Scope, path: string, who?: string): string;
|
|
31
31
|
/**
|
|
32
32
|
* Render the address a caller sees. The current agent and model homes read as @self/ and
|
|
33
|
-
* @model
|
|
33
|
+
* @model/. Current session and project homes retain bare paths and @project/; explicitly
|
|
34
|
+
* named session/project homes keep their read-only addresses, even for the current identity.
|
|
34
35
|
*/
|
|
35
36
|
export declare function addressFor(identity: NotesIdentity, scope: Scope, path: string, who?: string): string;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { NoteError, shown } from "./errors.js";
|
|
2
|
-
import { assertVirtualPath, SLUG_PATTERN } from "./paths.js";
|
|
3
|
-
export const ADDRESS_FORMS = "Use <path> for this session, or @project/, @human/, @self/, or @model/ followed by a path; @projects/<name>/<path>
|
|
2
|
+
import { assertVirtualPath, isSessionId, SLUG_PATTERN } from "./paths.js";
|
|
3
|
+
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 homes.";
|
|
4
4
|
/** The one home-head vocabulary: the scope each public `@head` names, and the home directory family a head with `home` lists. */
|
|
5
5
|
export const HOME_HEADS = new Map([
|
|
6
6
|
["project", { scope: "project" }],
|
|
7
7
|
["human", { scope: "human" }],
|
|
8
8
|
["self", { scope: "agent" }],
|
|
9
9
|
["model", { scope: "model" }],
|
|
10
|
+
["sessions", { scope: "session", home: "sessions" }],
|
|
10
11
|
["projects", { scope: "project", home: "project" }],
|
|
11
12
|
["agents", { scope: "agent", home: "agents" }],
|
|
12
13
|
["models", { scope: "model", home: "models" }],
|
|
@@ -53,7 +54,7 @@ export function assertGlobPattern(value) {
|
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
56
|
* Decode one public note address into its physical home and virtual path. @self and @model
|
|
56
|
-
* are relative;
|
|
57
|
+
* are relative; projects/agents/models name a canonical slug, sessions a directory component.
|
|
57
58
|
*/
|
|
58
59
|
export function assertAddress(value) {
|
|
59
60
|
if (typeof value !== "string")
|
|
@@ -71,7 +72,7 @@ export function assertAddress(value) {
|
|
|
71
72
|
path = tail.join("/");
|
|
72
73
|
else {
|
|
73
74
|
who = tail[0] ?? "";
|
|
74
|
-
if (!SLUG_PATTERN.test(who))
|
|
75
|
+
if (!(scope === "session" ? isSessionId(who) : SLUG_PATTERN.test(who)))
|
|
75
76
|
throw new NoteError("invalid_address", `${shown(value)} isn't a note address. ${ADDRESS_FORMS}`);
|
|
76
77
|
path = tail.slice(1).join("/");
|
|
77
78
|
}
|
|
@@ -86,9 +87,9 @@ export function assertAddress(value) {
|
|
|
86
87
|
/** Render a virtual path in its one unambiguous address form, used to match patterns. */
|
|
87
88
|
export function canonicalAddressFor(identity, scope, path, who) {
|
|
88
89
|
if (scope === "session")
|
|
89
|
-
return path
|
|
90
|
+
return `@sessions/${who ?? identity.sessionId}/${path}`;
|
|
90
91
|
if (scope === "project")
|
|
91
|
-
return
|
|
92
|
+
return `@projects/${who ?? identity.projectKey}/${path}`;
|
|
92
93
|
if (scope === "human")
|
|
93
94
|
return `@human/${path}`;
|
|
94
95
|
if (scope === "agent")
|
|
@@ -97,9 +98,14 @@ export function canonicalAddressFor(identity, scope, path, who) {
|
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
99
100
|
* Render the address a caller sees. The current agent and model homes read as @self/ and
|
|
100
|
-
* @model
|
|
101
|
+
* @model/. Current session and project homes retain bare paths and @project/; explicitly
|
|
102
|
+
* named session/project homes keep their read-only addresses, even for the current identity.
|
|
101
103
|
*/
|
|
102
104
|
export function addressFor(identity, scope, path, who) {
|
|
105
|
+
if (scope === "session" && who === undefined)
|
|
106
|
+
return path;
|
|
107
|
+
if (scope === "project" && who === undefined)
|
|
108
|
+
return `@project/${path}`;
|
|
103
109
|
if (scope === "agent" && (who === undefined || who === identity.agent))
|
|
104
110
|
return `@self/${path}`;
|
|
105
111
|
if (scope === "model" && (who === undefined || who === identity.model))
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
|
-
import { SLUG_PATTERN } from "./paths.js";
|
|
2
|
+
import { isSessionId, SLUG_PATTERN } from "./paths.js";
|
|
3
3
|
function requireString(field, value) {
|
|
4
4
|
if (typeof value !== "string" || value.length === 0)
|
|
5
5
|
throw new TypeError(`notes context ${field} must be a non-empty string`);
|
|
6
6
|
return value;
|
|
7
7
|
}
|
|
8
|
-
function assertDirectoryComponent(field, value) {
|
|
9
|
-
if (value === "." || value === ".." || /[\\/\0:]/.test(value)) {
|
|
10
|
-
throw new TypeError(`notes context ${field} must be a safe single directory component`);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
8
|
/** Validate and snapshot caller identity; no global or environment defaults are consulted. */
|
|
14
9
|
export function snapshotNotesIdentity(value) {
|
|
15
10
|
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
@@ -19,7 +14,8 @@ export function snapshotNotesIdentity(value) {
|
|
|
19
14
|
const projectKey = requireString("projectKey", value.projectKey);
|
|
20
15
|
const agent = requireString("agent", value.agent);
|
|
21
16
|
const model = requireString("model", value.model);
|
|
22
|
-
|
|
17
|
+
if (!isSessionId(sessionId))
|
|
18
|
+
throw new TypeError("notes context sessionId must be a safe single directory component");
|
|
23
19
|
if (!SLUG_PATTERN.test(projectKey))
|
|
24
20
|
throw new TypeError("notes context projectKey must be a canonical lowercase slug");
|
|
25
21
|
if (!SLUG_PATTERN.test(agent))
|
|
@@ -2,6 +2,8 @@ import type { NotesIdentity } from "./identity.js";
|
|
|
2
2
|
export type Scope = "session" | "project" | "human" | "agent" | "model";
|
|
3
3
|
/** The one legal home-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
|
|
4
4
|
export declare const SLUG_PATTERN: RegExp;
|
|
5
|
+
/** Session identities use the same single-directory-component grammar as NotesIdentity, not slugs. */
|
|
6
|
+
export declare function isSessionId(value: string): boolean;
|
|
5
7
|
/** Slugify a caller-declared identity; identity is never inferred from note content. */
|
|
6
8
|
export declare function slugify(value: string): string;
|
|
7
9
|
/**
|
|
@@ -14,8 +16,8 @@ export declare function assertVirtualPath(value: unknown): string;
|
|
|
14
16
|
export declare function sessionHomesRoot(home: string): string;
|
|
15
17
|
/** Absolute directory holding one scope's notes. The identity's home is already resolved. */
|
|
16
18
|
export declare function scopeDir(scope: Scope, identity: NotesIdentity, who?: string): string;
|
|
17
|
-
/** Every
|
|
18
|
-
export declare function namespaceSlugs(namespace: "agents" | "models", home: string): Promise<string[]>;
|
|
19
|
+
/** Every addressable home directory in a namespace; sessions keep their original identity spelling. */
|
|
20
|
+
export declare function namespaceSlugs(namespace: "sessions" | "project" | "agents" | "models", home: string): Promise<string[]>;
|
|
19
21
|
/**
|
|
20
22
|
* Notes are markdown files: a virtual path without an `.md` suffix gains one, an explicit
|
|
21
23
|
* `.md` is kept as-is, so `a/b` and `a/b.md` name the same physical file.
|
package/dist/src/notes/paths.js
CHANGED
|
@@ -3,6 +3,10 @@ import { join } from "node:path";
|
|
|
3
3
|
import { NoteError, shown } from "./errors.js";
|
|
4
4
|
/** The one legal home-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
|
|
5
5
|
export const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
6
|
+
/** Session identities use the same single-directory-component grammar as NotesIdentity, not slugs. */
|
|
7
|
+
export function isSessionId(value) {
|
|
8
|
+
return value.length > 0 && value !== "." && value !== ".." && !/[\\/\0:]/.test(value);
|
|
9
|
+
}
|
|
6
10
|
/** Slugify a caller-declared identity; identity is never inferred from note content. */
|
|
7
11
|
export function slugify(value) {
|
|
8
12
|
const slug = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -31,8 +35,8 @@ export function sessionHomesRoot(home) {
|
|
|
31
35
|
export function scopeDir(scope, identity, who) {
|
|
32
36
|
if (!["session", "project", "human", "agent", "model"].includes(scope))
|
|
33
37
|
throw new TypeError("invalid notes scope");
|
|
34
|
-
if (who !== undefined && (scope
|
|
35
|
-
throw new TypeError("who must be a canonical project/agent/model slug");
|
|
38
|
+
if (who !== undefined && (scope === "session" ? !isSessionId(who) : scope === "human" || !SLUG_PATTERN.test(who)))
|
|
39
|
+
throw new TypeError("who must be a session directory component or canonical project/agent/model slug");
|
|
36
40
|
if (scope === "human")
|
|
37
41
|
return join(identity.home, "human");
|
|
38
42
|
if (scope === "project")
|
|
@@ -41,13 +45,14 @@ export function scopeDir(scope, identity, who) {
|
|
|
41
45
|
return join(identity.home, "agents", who ?? identity.agent);
|
|
42
46
|
if (scope === "model")
|
|
43
47
|
return join(identity.home, "models", who ?? identity.model);
|
|
44
|
-
return join(sessionHomesRoot(identity.home), identity.sessionId);
|
|
48
|
+
return join(sessionHomesRoot(identity.home), who ?? identity.sessionId);
|
|
45
49
|
}
|
|
46
|
-
/** Every
|
|
50
|
+
/** Every addressable home directory in a namespace; sessions keep their original identity spelling. */
|
|
47
51
|
export async function namespaceSlugs(namespace, home) {
|
|
52
|
+
const root = namespace === "sessions" ? sessionHomesRoot(home) : join(home, namespace);
|
|
48
53
|
try {
|
|
49
|
-
return (await readdir(
|
|
50
|
-
.filter((entry) => entry.isDirectory())
|
|
54
|
+
return (await readdir(root, { withFileTypes: true }))
|
|
55
|
+
.filter((entry) => entry.isDirectory() && (namespace === "sessions" ? isSessionId(entry.name) : SLUG_PATTERN.test(entry.name)))
|
|
51
56
|
.map((entry) => entry.name)
|
|
52
57
|
.sort();
|
|
53
58
|
}
|
|
@@ -36,8 +36,11 @@ export type EditOptions = {
|
|
|
36
36
|
replaceAll?: boolean;
|
|
37
37
|
renameTo?: string;
|
|
38
38
|
};
|
|
39
|
+
/** Omitted/null/empty glob or bare @default selects current homes; explicit globs match full addresses.
|
|
40
|
+
* Only the current session also matches its bare-path alias (e.g. *.md or deep/**).
|
|
41
|
+
*/
|
|
39
42
|
export type NotesQuery = {
|
|
40
|
-
glob?: string;
|
|
43
|
+
glob?: string | null;
|
|
41
44
|
crumpled?: boolean;
|
|
42
45
|
};
|
|
43
46
|
/** A read exposes metadata and the pure body; the serialized frontmatter is never part of the body. */
|
package/dist/src/notes/store.js
CHANGED
|
@@ -8,8 +8,8 @@ import { snapshotNotesIdentity } from "./identity.js";
|
|
|
8
8
|
import { NoteError } from "./errors.js";
|
|
9
9
|
import { MAX_NOTE_BYTES, MAX_NOTE_PATH_BYTES } from "./constants.js";
|
|
10
10
|
import { isOrigin, localIso, parseNote, serializeNote, stripLeadingFrontmatter } from "./frontmatter.js";
|
|
11
|
-
import { namespaceSlugs, noteFileName, physicalPath, scopeDir, SLUG_PATTERN } from "./paths.js";
|
|
12
|
-
import {
|
|
11
|
+
import { namespaceSlugs, noteFileName, physicalPath, scopeDir, isSessionId, SLUG_PATTERN } from "./paths.js";
|
|
12
|
+
import { projectReceipt } from "./project-home.js";
|
|
13
13
|
// Recency sorts tie-break by address, so two writes sharing one Date.now() tick would silently invert the recent-first contract. Write stamps are strictly increasing per process.
|
|
14
14
|
let lastWriteStamp = 0;
|
|
15
15
|
function writeStamp() {
|
|
@@ -76,25 +76,62 @@ async function walkMarkdown(dir, base = dir) {
|
|
|
76
76
|
}
|
|
77
77
|
return paths;
|
|
78
78
|
}
|
|
79
|
-
async function homesForPattern(pattern, identity) {
|
|
80
|
-
if (
|
|
81
|
-
return
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
79
|
+
async function homesForPattern(pattern, identity, status) {
|
|
80
|
+
if (pattern === undefined)
|
|
81
|
+
return SCOPE_ORDER.map((scope) => ({ scope }));
|
|
82
|
+
const families = [
|
|
83
|
+
{ scope: "session", home: "sessions", current: identity.sessionId },
|
|
84
|
+
{ scope: "project", home: "project", current: identity.projectKey },
|
|
85
|
+
{ scope: "agent", home: "agents", current: identity.agent },
|
|
86
|
+
{ scope: "model", home: "models", current: identity.model },
|
|
87
|
+
];
|
|
88
|
+
async function enumerate(family, relative) {
|
|
89
|
+
let names;
|
|
90
|
+
try {
|
|
91
|
+
names = await namespaceSlugs(family.home, identity.home);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (!status || !isFilesystemError(error))
|
|
95
|
+
throw error;
|
|
96
|
+
status.homesUnavailable.push(`@${family.home === "project" ? "projects" : family.home}`);
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
// Include the current home even when missing or a non-directory, and only once.
|
|
100
|
+
return [...new Set([family.current, ...names])].map((who) => ({
|
|
101
|
+
scope: family.scope,
|
|
102
|
+
who: relative && who === family.current ? undefined : who,
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
if (pattern.startsWith("@")) {
|
|
106
|
+
const [rawHead, ...tail] = pattern.slice(1).split("/");
|
|
107
|
+
if (!/[*?]/.test(rawHead)) {
|
|
108
|
+
const head = HOME_HEADS.get(rawHead);
|
|
109
|
+
if (head === undefined || tail.length === 0)
|
|
110
|
+
return [];
|
|
111
|
+
if (head.home === undefined)
|
|
112
|
+
return [{ scope: head.scope }];
|
|
113
|
+
const name = tail[0];
|
|
114
|
+
if (name && !/[*?]/.test(name))
|
|
115
|
+
return [{ scope: head.scope, who: assertWho(name, head.scope) }];
|
|
116
|
+
return enumerate(families.find((family) => family.home === head.home), false);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Unreserved patterns see the full universe, not just the current identities.
|
|
120
|
+
const homes = [];
|
|
121
|
+
for (const scope of SCOPE_ORDER) {
|
|
122
|
+
if (scope === "human")
|
|
123
|
+
homes.push({ scope });
|
|
124
|
+
else
|
|
125
|
+
homes.push(...await enumerate(families.find((family) => family.scope === scope), true));
|
|
126
|
+
}
|
|
127
|
+
return homes;
|
|
93
128
|
}
|
|
94
129
|
/** Relative pattern heads resolve to canonical names, so they match canonical addresses. */
|
|
95
130
|
function normalizePattern(pattern, identity) {
|
|
96
131
|
if (!pattern)
|
|
97
132
|
return pattern;
|
|
133
|
+
if (pattern.startsWith("@project/"))
|
|
134
|
+
return `@projects/${identity.projectKey}/${pattern.slice("@project/".length)}`;
|
|
98
135
|
if (pattern.startsWith("@self/"))
|
|
99
136
|
return `@agents/${identity.agent}/${pattern.slice("@self/".length)}`;
|
|
100
137
|
if (pattern.startsWith("@model/"))
|
|
@@ -106,9 +143,9 @@ function assertOrigin(value) {
|
|
|
106
143
|
throw new NoteError("invalid_origin", `origin must be one of user, self, external (got ${JSON.stringify(value)})`);
|
|
107
144
|
return value;
|
|
108
145
|
}
|
|
109
|
-
function assertWho(value) {
|
|
110
|
-
if (typeof value !== "string" || !SLUG_PATTERN.test(value)) {
|
|
111
|
-
throw new NoteError("invalid_scope", "who must be a canonical lowercase slug");
|
|
146
|
+
function assertWho(value, scope) {
|
|
147
|
+
if (typeof value !== "string" || !(scope === "session" ? isSessionId(value) : SLUG_PATTERN.test(value))) {
|
|
148
|
+
throw new NoteError("invalid_scope", scope === "session" ? "session id must be a safe single directory component" : "who must be a canonical lowercase slug");
|
|
112
149
|
}
|
|
113
150
|
return value;
|
|
114
151
|
}
|
|
@@ -181,10 +218,12 @@ function assertSerializedSize(content) {
|
|
|
181
218
|
function frontmatterOf(meta) {
|
|
182
219
|
return serializeNote(meta, "").slice(0, -2);
|
|
183
220
|
}
|
|
184
|
-
/** Explicit project homes are always read-only; agent/model homes allow their owner. */
|
|
221
|
+
/** Explicit session/project homes are always read-only; agent/model homes allow their owner. */
|
|
185
222
|
function assertWritableHome(scope, who, identity) {
|
|
186
223
|
if (who === undefined)
|
|
187
224
|
return;
|
|
225
|
+
if (scope === "session")
|
|
226
|
+
throw new NoteError("invalid_scope", `@sessions/${who}/ is read-only; use a bare path to write to this session.`);
|
|
188
227
|
if (scope === "project")
|
|
189
228
|
throw new NoteError("invalid_scope", `@projects/${who}/ is read-only; use @project/ to write to your own project.`);
|
|
190
229
|
const current = scope === "agent" ? identity.agent : identity.model;
|
|
@@ -242,7 +281,7 @@ export function createNotesStore(input) {
|
|
|
242
281
|
return undefined;
|
|
243
282
|
const now = Date.now();
|
|
244
283
|
const parsed = parseNote(raw, now);
|
|
245
|
-
if (scope === "project" && destination.who !== undefined)
|
|
284
|
+
if ((scope === "project" || scope === "session") && destination.who !== undefined)
|
|
246
285
|
return { meta: { ...parsed.meta, scope }, body: parsed.body, resolvedScope: scope };
|
|
247
286
|
// A read records its own access, exactly as a write records an edit.
|
|
248
287
|
const meta = { ...parsed.meta, scope, lastAccessed: now, accessCount: (typeof parsed.meta.accessCount === "number" ? parsed.meta.accessCount : 0) + 1 };
|
|
@@ -350,19 +389,11 @@ export function createNotesStore(input) {
|
|
|
350
389
|
return { meta, replacedCrumpledTarget };
|
|
351
390
|
}
|
|
352
391
|
async function* scan(options, status) {
|
|
353
|
-
const
|
|
354
|
-
const
|
|
392
|
+
const glob = assertGlobPattern(options.glob);
|
|
393
|
+
const pattern = glob === "@default" ? undefined : glob;
|
|
394
|
+
const normalized = normalizePattern(pattern, identity);
|
|
355
395
|
const matcher = normalized === undefined ? undefined : globToRegExp(normalized);
|
|
356
|
-
|
|
357
|
-
try {
|
|
358
|
-
homes = await homesForPattern(normalized, identity) ?? SCOPE_ORDER.map((scope) => ({ scope }));
|
|
359
|
-
}
|
|
360
|
-
catch (error) {
|
|
361
|
-
if (!status || !isFilesystemError(error) || !/^@(projects|agents|models)\//.test(options.glob ?? ""))
|
|
362
|
-
throw error;
|
|
363
|
-
status.homesUnavailable.push(options.glob.split("/")[0]);
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
396
|
+
const homes = await homesForPattern(pattern, identity, status);
|
|
366
397
|
for (const home of homes) {
|
|
367
398
|
const scope = home.scope;
|
|
368
399
|
const root = scopeDir(scope, identity, home.who);
|
|
@@ -377,7 +408,8 @@ export function createNotesStore(input) {
|
|
|
377
408
|
continue;
|
|
378
409
|
}
|
|
379
410
|
for (const path of paths) {
|
|
380
|
-
if (matcher && !matcher.test(canonicalAddressFor(identity, scope, path, home.who))
|
|
411
|
+
if (matcher && !matcher.test(canonicalAddressFor(identity, scope, path, home.who))
|
|
412
|
+
&& !(scope === "session" && home.who === undefined && !pattern.startsWith("@") && matcher.test(path)))
|
|
381
413
|
continue;
|
|
382
414
|
const address = addressFor(identity, scope, path, home.who);
|
|
383
415
|
const fullPath = join(root, path);
|
package/dist/src/settings.d.ts
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
+
/** The one settings key every host reads its own fields from. */
|
|
1
2
|
export declare const NOTESOUP_SETTINGS_KEY = "notesoup";
|
|
2
|
-
/** Nested under "notesoup": the default dreamer model pattern, overridden by CLI --dreamer. */
|
|
3
|
-
export declare const NOTESOUP_DREAMER_KEY = "dreamer";
|
|
4
|
-
/**
|
|
5
|
-
* The one notesoup settings shape both hosts read. `reminderMarginTokens` is Pi's early
|
|
6
|
-
* reminder margin; `resetMarginTokens` and `warningRunwayTokens` are the Claude mod's
|
|
7
|
-
* margins against Claude's own auto-compact point (see src/claude/thresholds.ts). A host
|
|
8
|
-
* ignores the keys it does not use; every value is validated where it is consumed.
|
|
9
|
-
*/
|
|
10
|
-
export type NotesoupSettings = {
|
|
11
|
-
reminderMarginTokens?: unknown;
|
|
12
|
-
resetMarginTokens?: unknown;
|
|
13
|
-
warningRunwayTokens?: unknown;
|
|
14
|
-
dreamer?: unknown;
|
|
15
|
-
};
|
|
16
3
|
/** A plain settings object; arrays and null are not one. */
|
|
17
4
|
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
18
|
-
/**
|
|
19
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Merge the global and project "notesoup" objects per key; project wins, mirroring Pi's deep
|
|
7
|
+
* merge. The record is exactly what the scopes contain: this core module owns the key and the
|
|
8
|
+
* merge, while each host names, reads and validates the fields it consumes.
|
|
9
|
+
*/
|
|
10
|
+
export declare function mergeNotesoupSettings(globalSettings: unknown, projectSettings: unknown): Record<string, unknown>;
|