notesoup 0.0.0-stage → 0.40.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/LICENSE +21 -0
- package/README.md +94 -2
- package/dist/src/boot/render.d.ts +16 -0
- package/dist/src/boot/render.js +95 -0
- package/dist/src/boot/snapshot.d.ts +32 -0
- package/dist/src/boot/snapshot.js +36 -0
- package/dist/src/boot/text.d.ts +17 -0
- package/dist/src/boot/text.js +48 -0
- package/dist/src/budget/constants.d.ts +9 -0
- package/dist/src/budget/constants.js +9 -0
- package/dist/src/budget/policy.d.ts +19 -0
- package/dist/src/budget/policy.js +36 -0
- package/dist/src/budget/text.d.ts +8 -0
- package/dist/src/budget/text.js +10 -0
- package/dist/src/claude/helper.d.ts +15 -0
- package/dist/src/claude/helper.js +87 -0
- package/dist/src/dream/doctor.d.ts +2 -0
- package/dist/src/dream/doctor.js +160 -0
- package/dist/src/dream/gates.d.ts +10 -0
- package/dist/src/dream/gates.js +26 -0
- package/dist/src/dream/git.d.ts +21 -0
- package/dist/src/dream/git.js +71 -0
- package/dist/src/dream/jail.d.ts +11 -0
- package/dist/src/dream/jail.js +71 -0
- package/dist/src/dream/lock.d.ts +31 -0
- package/dist/src/dream/lock.js +99 -0
- package/dist/src/dream/playbook.d.ts +1 -0
- package/dist/src/dream/playbook.js +2 -0
- package/dist/src/dream/report.d.ts +7 -0
- package/dist/src/dream/report.js +43 -0
- package/dist/src/dream/result.d.ts +9 -0
- package/dist/src/dream/result.js +1 -0
- package/dist/src/dream/settings.d.ts +10 -0
- package/dist/src/dream/settings.js +14 -0
- package/dist/src/history/history.d.ts +156 -0
- package/dist/src/history/history.js +212 -0
- package/dist/src/history/query.d.ts +63 -0
- package/dist/src/history/query.js +201 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/notes/address.d.ts +31 -0
- package/dist/src/notes/address.js +123 -0
- package/dist/src/notes/constants.d.ts +3 -0
- package/dist/src/notes/constants.js +3 -0
- package/dist/src/notes/errors.d.ts +11 -0
- package/dist/src/notes/errors.js +13 -0
- package/dist/src/notes/frontmatter.d.ts +44 -0
- package/dist/src/notes/frontmatter.js +145 -0
- package/dist/src/notes/fs-error.d.ts +2 -0
- package/dist/src/notes/fs-error.js +5 -0
- package/dist/src/notes/identity.d.ts +10 -0
- package/dist/src/notes/identity.js +33 -0
- package/dist/src/notes/index.d.ts +5 -0
- package/dist/src/notes/index.js +3 -0
- package/dist/src/notes/paths.d.ts +21 -0
- package/dist/src/notes/paths.js +113 -0
- package/dist/src/notes/store.d.ts +103 -0
- package/dist/src/notes/store.js +474 -0
- package/dist/src/pi/boot.d.ts +24 -0
- package/dist/src/pi/boot.js +56 -0
- package/dist/src/pi/budget.d.ts +13 -0
- package/dist/src/pi/budget.js +178 -0
- package/dist/src/pi/dream/cli.d.ts +10 -0
- package/dist/src/pi/dream/cli.js +140 -0
- package/dist/src/pi/dream/runner.d.ts +27 -0
- package/dist/src/pi/dream/runner.js +90 -0
- package/dist/src/pi/dream/settings.d.ts +7 -0
- package/dist/src/pi/dream/settings.js +17 -0
- package/dist/src/pi/entries.d.ts +7 -0
- package/dist/src/pi/entries.js +7 -0
- package/dist/src/pi/estimate.d.ts +16 -0
- package/dist/src/pi/estimate.js +99 -0
- package/dist/src/pi/extension.d.ts +10 -0
- package/dist/src/pi/extension.js +24 -0
- package/dist/src/pi/history-tools.d.ts +3 -0
- package/dist/src/pi/history-tools.js +9 -0
- package/dist/src/pi/history.d.ts +4 -0
- package/dist/src/pi/history.js +150 -0
- package/dist/src/pi/notes/adapter.d.ts +10 -0
- package/dist/src/pi/notes/adapter.js +27 -0
- package/dist/src/pi/notes/tools.d.ts +3 -0
- package/dist/src/pi/notes/tools.js +15 -0
- package/dist/src/pi/reset/artifacts.d.ts +24 -0
- package/dist/src/pi/reset/artifacts.js +84 -0
- package/dist/src/pi/reset/committed.d.ts +7 -0
- package/dist/src/pi/reset/committed.js +28 -0
- package/dist/src/pi/reset/lifecycle.d.ts +101 -0
- package/dist/src/pi/reset/lifecycle.js +277 -0
- package/dist/src/pi/reset/text.d.ts +5 -0
- package/dist/src/pi/reset/text.js +6 -0
- package/dist/src/pi/runtime.d.ts +3 -0
- package/dist/src/pi/runtime.js +206 -0
- package/dist/src/pi/session-reader.d.ts +5 -0
- package/dist/src/pi/session-reader.js +1 -0
- package/dist/src/pi/thresholds.d.ts +17 -0
- package/dist/src/pi/thresholds.js +33 -0
- package/dist/src/pi/tool-names.d.ts +7 -0
- package/dist/src/pi/tool-names.js +7 -0
- package/dist/src/pi/tool-result.d.ts +15 -0
- package/dist/src/pi/tool-result.js +29 -0
- package/dist/src/pi/window.d.ts +41 -0
- package/dist/src/pi/window.js +127 -0
- package/dist/src/settings.d.ts +9 -0
- package/dist/src/settings.js +18 -0
- package/dist/src/text-match.d.ts +5 -0
- package/dist/src/text-match.js +16 -0
- package/dist/src/tools/history.d.ts +58 -0
- package/dist/src/tools/history.js +210 -0
- package/dist/src/tools/notes.d.ts +250 -0
- package/dist/src/tools/notes.js +360 -0
- package/dist/src/tools/output.d.ts +23 -0
- package/dist/src/tools/output.js +39 -0
- package/dist/src/tools/result.d.ts +82 -0
- package/dist/src/tools/result.js +104 -0
- package/dist/src/tools/schema.d.ts +18 -0
- package/dist/src/tools/schema.js +31 -0
- package/dist/test/agent-loop.test.d.ts +1 -0
- package/dist/test/agent-loop.test.js +1497 -0
- package/dist/test/boot.integration.test.d.ts +1 -0
- package/dist/test/boot.integration.test.js +294 -0
- package/dist/test/budget-settings.integration.test.d.ts +1 -0
- package/dist/test/budget-settings.integration.test.js +144 -0
- package/dist/test/claude-mod.test.d.ts +1 -0
- package/dist/test/claude-mod.test.js +404 -0
- package/dist/test/dependencies.test.d.ts +1 -0
- package/dist/test/dependencies.test.js +101 -0
- package/dist/test/doctor.test.d.ts +1 -0
- package/dist/test/doctor.test.js +37 -0
- package/dist/test/dream-skill.test.d.ts +1 -0
- package/dist/test/dream-skill.test.js +72 -0
- package/dist/test/dream.test.d.ts +1 -0
- package/dist/test/dream.test.js +136 -0
- package/dist/test/helpers/dependency-graph.d.ts +5 -0
- package/dist/test/helpers/dependency-graph.js +73 -0
- package/dist/test/helpers/extension-test-environment.d.ts +1 -0
- package/dist/test/helpers/extension-test-environment.js +9 -0
- package/dist/test/helpers/extension.d.ts +119 -0
- package/dist/test/helpers/extension.js +367 -0
- package/dist/test/helpers/notes.d.ts +6 -0
- package/dist/test/helpers/notes.js +13 -0
- package/dist/test/history.integration.test.d.ts +1 -0
- package/dist/test/history.integration.test.js +633 -0
- package/dist/test/host-neutral.test.d.ts +1 -0
- package/dist/test/host-neutral.test.js +274 -0
- package/dist/test/notes-library.test.d.ts +1 -0
- package/dist/test/notes-library.test.js +214 -0
- package/dist/test/notes.integration.test.d.ts +1 -0
- package/dist/test/notes.integration.test.js +515 -0
- package/dist/test/notes.test.d.ts +1 -0
- package/dist/test/notes.test.js +530 -0
- package/dist/test/reset-lifecycle.test.d.ts +1 -0
- package/dist/test/reset-lifecycle.test.js +605 -0
- package/docs/architecture.md +63 -0
- package/docs/claude-code-mod.md +9 -0
- package/docs/notes-library.md +74 -0
- package/docs/reset-lifecycle.md +75 -0
- package/docs/sdk-integration.md +39 -0
- package/docs/skills.md +30 -0
- package/docs/tool-results.md +78 -0
- package/mods/notesoup/.claude-plugin/plugin.json +8 -0
- package/mods/notesoup/dist/claude/helper.js +9265 -0
- package/mods/notesoup/hooks/hooks.json +4 -0
- package/mods/notesoup/hooks/register.ts +240 -0
- package/mods/notesoup/playbook.md +34 -0
- package/mods/notesoup/skills/dream/SKILL.md +12 -0
- package/mods/pi-context/dist/claude/helper.js +9324 -0
- package/package.json +89 -5
- package/playbook.md +34 -0
- package/skills/dream/SKILL.md +12 -0
- package/skills/memory/SKILL.md +59 -0
- package/src/boot/render.ts +115 -0
- package/src/boot/snapshot.ts +46 -0
- package/src/boot/text.ts +58 -0
- package/src/budget/constants.ts +9 -0
- package/src/budget/policy.ts +36 -0
- package/src/budget/text.ts +11 -0
- package/src/claude/helper.ts +94 -0
- package/src/dream/doctor.ts +117 -0
- package/src/dream/gates.ts +26 -0
- package/src/dream/git.ts +73 -0
- package/src/dream/jail.ts +62 -0
- package/src/dream/lock.ts +82 -0
- package/src/dream/playbook.ts +3 -0
- package/src/dream/report.ts +36 -0
- package/src/dream/result.ts +2 -0
- package/src/dream/settings.ts +16 -0
- package/src/history/history.ts +286 -0
- package/src/history/query.ts +222 -0
- package/src/index.ts +1 -0
- package/src/notes/address.ts +110 -0
- package/src/notes/constants.ts +3 -0
- package/src/notes/errors.ts +15 -0
- package/src/notes/frontmatter.ts +166 -0
- package/src/notes/fs-error.ts +5 -0
- package/src/notes/identity.ts +40 -0
- package/src/notes/index.ts +24 -0
- package/src/notes/paths.ts +109 -0
- package/src/notes/store.ts +494 -0
- package/src/pi/boot.ts +88 -0
- package/src/pi/budget.ts +178 -0
- package/src/pi/dream/cli.ts +92 -0
- package/src/pi/dream/runner.ts +91 -0
- package/src/pi/dream/settings.ts +17 -0
- package/src/pi/entries.ts +7 -0
- package/src/pi/estimate.ts +116 -0
- package/src/pi/extension.ts +27 -0
- package/src/pi/history-tools.ts +11 -0
- package/src/pi/history.ts +162 -0
- package/src/pi/notes/adapter.ts +33 -0
- package/src/pi/notes/tools.ts +18 -0
- package/src/pi/reset/artifacts.ts +100 -0
- package/src/pi/reset/committed.ts +26 -0
- package/src/pi/reset/lifecycle.ts +342 -0
- package/src/pi/reset/text.ts +10 -0
- package/src/pi/runtime.ts +200 -0
- package/src/pi/session-reader.ts +6 -0
- package/src/pi/thresholds.ts +50 -0
- package/src/pi/tool-names.ts +9 -0
- package/src/pi/tool-result.ts +41 -0
- package/src/pi/window.ts +133 -0
- package/src/settings.ts +22 -0
- package/src/text-match.ts +14 -0
- package/src/tools/history.ts +234 -0
- package/src/tools/notes.ts +381 -0
- package/src/tools/output.ts +41 -0
- package/src/tools/result.ts +144 -0
- package/src/tools/schema.ts +31 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { NoteError } from "./errors.js";
|
|
2
|
+
import { SLUG_PATTERN } from "./paths.js";
|
|
3
|
+
export const ADDRESS_FORMS = "use <path> with no @ for this session, or @project/, @human/, @self/, or @model/ followed by a path";
|
|
4
|
+
/** A refusal names the offending input; JSON quoting keeps control chars visible, and stringify misses get String(). */
|
|
5
|
+
function shown(value) {
|
|
6
|
+
const json = JSON.stringify(value);
|
|
7
|
+
return json === undefined ? String(value) : json;
|
|
8
|
+
}
|
|
9
|
+
export function assertVirtualPath(value) {
|
|
10
|
+
if (typeof value !== "string" || value.length === 0)
|
|
11
|
+
throw new NoteError("invalid_address", `invalid address ${shown(value)}: path must be a non-empty string`);
|
|
12
|
+
if (value.includes("\0") || value.includes("\\") || value.startsWith("/"))
|
|
13
|
+
throw new NoteError("invalid_address", `invalid address ${shown(value)}: paths reject backslashes, leading "/", and NUL`);
|
|
14
|
+
const parts = value.split("/");
|
|
15
|
+
if (parts.some((part) => part.length === 0 || part === "." || part === ".."))
|
|
16
|
+
throw new NoteError("invalid_address", `invalid address ${shown(value)}: paths reject "..", ".", and empty segments`);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Minimal glob over virtual note paths: `*` matches any run within a segment (never
|
|
21
|
+
* `/`), `**` matches any run across segments (a leading double-star followed by a
|
|
22
|
+
* slash also matches zero segments, so it covers the root too), `?` matches exactly
|
|
23
|
+
* one non-`/` character. Everything else is literal and the match is anchored to the
|
|
24
|
+
* whole path.
|
|
25
|
+
*/
|
|
26
|
+
export function globToRegExp(pattern) {
|
|
27
|
+
let source = "^";
|
|
28
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
29
|
+
const char = pattern[index];
|
|
30
|
+
if (char === "*") {
|
|
31
|
+
if (pattern[index + 1] === "*") {
|
|
32
|
+
const followedBySlash = pattern[index + 2] === "/";
|
|
33
|
+
source += followedBySlash ? "(?:[^]*\\/)?" : "[^]*";
|
|
34
|
+
index += followedBySlash ? 2 : 1;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
source += "[^/]*";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
source += char.replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return new RegExp(`${source}$`);
|
|
45
|
+
}
|
|
46
|
+
/** Glob patterns are not virtual paths (`*` is legal), so they get their own guard. */
|
|
47
|
+
export function assertGlobPattern(value) {
|
|
48
|
+
if (value === undefined || value === null || value === "")
|
|
49
|
+
return undefined;
|
|
50
|
+
if (typeof value !== "string")
|
|
51
|
+
throw new NoteError("invalid_pattern", `invalid pattern ${shown(value)}: glob patterns must be strings`);
|
|
52
|
+
if (value.includes("\0") || value.includes("\\"))
|
|
53
|
+
throw new NoteError("invalid_pattern", `invalid pattern ${shown(value)}: glob patterns reject NUL and backslashes`);
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Decode one public note address into its physical home and virtual path. @self and @model
|
|
58
|
+
* are relative; explicit agents/models addresses always name a canonical slug.
|
|
59
|
+
*/
|
|
60
|
+
export function assertAddress(value) {
|
|
61
|
+
if (typeof value !== "string")
|
|
62
|
+
throw new NoteError("invalid_address", `invalid address ${shown(value)}: ${ADDRESS_FORMS}`);
|
|
63
|
+
let scope = "session";
|
|
64
|
+
let path = value;
|
|
65
|
+
let who;
|
|
66
|
+
if (value.startsWith("@")) {
|
|
67
|
+
const rest = value.slice(1);
|
|
68
|
+
const headEnd = rest.indexOf("/");
|
|
69
|
+
const head = headEnd === -1 ? rest : rest.slice(0, headEnd);
|
|
70
|
+
const tail = headEnd === -1 ? "" : rest.slice(headEnd + 1);
|
|
71
|
+
path = tail;
|
|
72
|
+
if (head === "project")
|
|
73
|
+
scope = "project";
|
|
74
|
+
else if (head === "human")
|
|
75
|
+
scope = "human";
|
|
76
|
+
else if (head === "self")
|
|
77
|
+
scope = "agent";
|
|
78
|
+
else if (head === "model")
|
|
79
|
+
scope = "model";
|
|
80
|
+
else if (head === "agents" || head === "models") {
|
|
81
|
+
const nameEnd = tail.indexOf("/");
|
|
82
|
+
who = nameEnd === -1 ? tail : tail.slice(0, nameEnd);
|
|
83
|
+
if (!SLUG_PATTERN.test(who))
|
|
84
|
+
throw new NoteError("invalid_address", `invalid address ${shown(value)}: ${ADDRESS_FORMS}`);
|
|
85
|
+
scope = head === "agents" ? "agent" : "model";
|
|
86
|
+
path = nameEnd === -1 ? "" : tail.slice(nameEnd + 1);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
throw new NoteError("invalid_address", `invalid address ${shown(value)}: ${ADDRESS_FORMS}`);
|
|
90
|
+
}
|
|
91
|
+
if (path === "" && scope !== "agent" && scope !== "model")
|
|
92
|
+
throw new NoteError("invalid_address", `invalid address ${shown(value)}: ${ADDRESS_FORMS}`);
|
|
93
|
+
if (path === "" && who === undefined)
|
|
94
|
+
throw new NoteError("invalid_address", `invalid address ${shown(value)}: ${ADDRESS_FORMS}`);
|
|
95
|
+
}
|
|
96
|
+
if (path.includes("@"))
|
|
97
|
+
throw new NoteError("invalid_address", `invalid address ${shown(value)}: ${ADDRESS_FORMS}`);
|
|
98
|
+
assertVirtualPath(path);
|
|
99
|
+
return { scope, path, who };
|
|
100
|
+
}
|
|
101
|
+
/** Render a virtual path in its one unambiguous address form, used to match patterns. */
|
|
102
|
+
export function canonicalAddressFor(identity, scope, path, who) {
|
|
103
|
+
if (scope === "session")
|
|
104
|
+
return path;
|
|
105
|
+
if (scope === "project")
|
|
106
|
+
return `@project/${path}`;
|
|
107
|
+
if (scope === "human")
|
|
108
|
+
return `@human/${path}`;
|
|
109
|
+
if (scope === "agent")
|
|
110
|
+
return `@agents/${who ?? identity.agent}/${path}`;
|
|
111
|
+
return `@models/${who ?? identity.model}/${path}`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Render the address a caller sees. The current agent and model homes read as @self/ and
|
|
115
|
+
* @model/ so ordinary sessions are not taught explicit ids; only other homes (dream) name one.
|
|
116
|
+
*/
|
|
117
|
+
export function addressFor(identity, scope, path, who) {
|
|
118
|
+
if (scope === "agent" && (who === undefined || who === identity.agent))
|
|
119
|
+
return `@self/${path}`;
|
|
120
|
+
if (scope === "model" && (who === undefined || who === identity.model))
|
|
121
|
+
return `@model/${path}`;
|
|
122
|
+
return canonicalAddressFor(identity, scope, path, who);
|
|
123
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type NoteErrorCode = "not_found" | "already_exists" | "ambiguous_edit" | "no_match" | "nothing_to_do" | "too_large" | "invalid_scope" | "invalid_origin" | "invalid_address" | "invalid_pattern" | "invalid_query" | "invalid_offset" | "io_error" | "internal_error";
|
|
2
|
+
/** Typed store refusal. Edit locations are exposed in camelCase. */
|
|
3
|
+
export declare class NoteError extends Error {
|
|
4
|
+
readonly code: NoteErrorCode;
|
|
5
|
+
readonly lineNumbers?: number[];
|
|
6
|
+
readonly editIndex?: number;
|
|
7
|
+
constructor(code: NoteErrorCode, message: string, extra?: {
|
|
8
|
+
lineNumbers?: number[];
|
|
9
|
+
editIndex?: number;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Typed store refusal. Edit locations are exposed in camelCase. */
|
|
2
|
+
export class NoteError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
lineNumbers;
|
|
5
|
+
editIndex;
|
|
6
|
+
constructor(code, message, extra = {}) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "NoteError";
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.lineNumbers = extra.lineNumbers;
|
|
11
|
+
this.editIndex = extra.editIndex;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Scope } from "./paths.js";
|
|
2
|
+
export type Origin = "user" | "self" | "external";
|
|
3
|
+
/**
|
|
4
|
+
* Harness-owned note metadata. The eight required keys are always written; the four optional
|
|
5
|
+
* sleep-shift keys survive this layer untouched when present. `[key: string]: unknown` carries
|
|
6
|
+
* any frontmatter key this layer does not know, preserved verbatim across rewrites.
|
|
7
|
+
*/
|
|
8
|
+
export type NoteMeta = {
|
|
9
|
+
scope: Scope;
|
|
10
|
+
origin: Origin;
|
|
11
|
+
/** Present only while the note is in the wastebasket; serialized as an ISO timestamp. */
|
|
12
|
+
crumpledAt?: string;
|
|
13
|
+
createdAt: number;
|
|
14
|
+
updatedAt: number;
|
|
15
|
+
lastAccessed: number;
|
|
16
|
+
accessCount: number;
|
|
17
|
+
sourceWindow?: string;
|
|
18
|
+
supersedes?: string;
|
|
19
|
+
recurrenceCount?: number;
|
|
20
|
+
recurrenceWindows?: string[];
|
|
21
|
+
/** Project ownership on newly-created session notes; legacy/invalid values are preserved as-is. */
|
|
22
|
+
project?: unknown;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Format epoch milliseconds as an ISO 8601 string in the host's local time zone with an
|
|
27
|
+
* explicit numeric offset (e.g. 2026-09-15T17:31:45.392+08:00). A UTC host renders
|
|
28
|
+
* "+00:00"; the "Z" designator is never used, and Date.parse round-trips the value.
|
|
29
|
+
*/
|
|
30
|
+
export declare function localIso(epochMs: number): string;
|
|
31
|
+
export declare function isScope(value: unknown): value is Scope;
|
|
32
|
+
export declare function isOrigin(value: unknown): value is Origin;
|
|
33
|
+
/**
|
|
34
|
+
* Parse a note file. Missing known keys take the defaults (accessCount 0, timestamps now);
|
|
35
|
+
* crumpledAt stays absent until explicitly set, and unknown keys survive untouched.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseNote(raw: string, now?: number): {
|
|
38
|
+
meta: NoteMeta;
|
|
39
|
+
body: string;
|
|
40
|
+
};
|
|
41
|
+
/** Serialize frontmatter + blank line + body. Known keys emit in Design order, extras after. */
|
|
42
|
+
export declare function serializeNote(meta: NoteMeta, body: string): string;
|
|
43
|
+
/** Strip a leading frontmatter block from user content, so a note body is pure content. */
|
|
44
|
+
export declare function stripLeadingFrontmatter(content: string): string;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const SCOPES = ["session", "project", "human", "agent", "model"];
|
|
2
|
+
const ORIGINS = ["user", "self", "external"];
|
|
3
|
+
const TIMESTAMP_KEYS = ["createdAt", "updatedAt", "lastAccessed"];
|
|
4
|
+
/** Emission order, exactly the Design's key list. */
|
|
5
|
+
const KNOWN_KEYS = ["origin", "crumpledAt", "createdAt", "updatedAt", "lastAccessed", "accessCount", "sourceWindow", "supersedes", "recurrenceCount", "recurrenceWindows"];
|
|
6
|
+
const pad2 = (value) => String(value).padStart(2, "0");
|
|
7
|
+
/**
|
|
8
|
+
* Format epoch milliseconds as an ISO 8601 string in the host's local time zone with an
|
|
9
|
+
* explicit numeric offset (e.g. 2026-09-15T17:31:45.392+08:00). A UTC host renders
|
|
10
|
+
* "+00:00"; the "Z" designator is never used, and Date.parse round-trips the value.
|
|
11
|
+
*/
|
|
12
|
+
export function localIso(epochMs) {
|
|
13
|
+
const date = new Date(epochMs);
|
|
14
|
+
const offsetMinutes = -date.getTimezoneOffset();
|
|
15
|
+
const absOffset = Math.abs(offsetMinutes);
|
|
16
|
+
const offset = `${offsetMinutes < 0 ? "-" : "+"}${pad2(Math.floor(absOffset / 60))}:${pad2(absOffset % 60)}`;
|
|
17
|
+
const wallClock = `${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}.${String(date.getMilliseconds()).padStart(3, "0")}`;
|
|
18
|
+
return `${wallClock}${offset}`;
|
|
19
|
+
}
|
|
20
|
+
export function isScope(value) {
|
|
21
|
+
return typeof value === "string" && SCOPES.includes(value);
|
|
22
|
+
}
|
|
23
|
+
export function isOrigin(value) {
|
|
24
|
+
return typeof value === "string" && ORIGINS.includes(value);
|
|
25
|
+
}
|
|
26
|
+
function toEpoch(value, fallback) {
|
|
27
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
28
|
+
return value;
|
|
29
|
+
if (typeof value === "string") {
|
|
30
|
+
const parsed = Date.parse(value);
|
|
31
|
+
if (Number.isFinite(parsed))
|
|
32
|
+
return parsed;
|
|
33
|
+
}
|
|
34
|
+
return fallback;
|
|
35
|
+
}
|
|
36
|
+
/** A frontmatter scalar encoded as JSON, falling back to a plain string for hand-written YAML. */
|
|
37
|
+
function parseScalar(text) {
|
|
38
|
+
const trimmed = text.trim();
|
|
39
|
+
if (trimmed === "")
|
|
40
|
+
return "";
|
|
41
|
+
try {
|
|
42
|
+
return JSON.parse(trimmed);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
if ((trimmed.startsWith('"') && trimmed.endsWith('"')) || (trimmed.startsWith("'") && trimmed.endsWith("'")))
|
|
46
|
+
return trimmed.slice(1, -1);
|
|
47
|
+
return trimmed;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Split raw file text into its frontmatter fields and body. When the file does not open with
|
|
52
|
+
* a closed `---` block, the whole text is body and the field map is empty.
|
|
53
|
+
*/
|
|
54
|
+
function parseFrontmatter(raw) {
|
|
55
|
+
const stripped = raw.charCodeAt(0) === 0xfeff ? raw.slice(1) : raw;
|
|
56
|
+
const lines = stripped.split("\n").map((line) => (line.endsWith("\r") ? line.slice(0, -1) : line));
|
|
57
|
+
if (lines[0]?.trim() !== "---")
|
|
58
|
+
return { fields: {}, body: raw };
|
|
59
|
+
let close = -1;
|
|
60
|
+
for (let index = 1; index < lines.length; index++) {
|
|
61
|
+
if (lines[index]?.trim() === "---") {
|
|
62
|
+
close = index;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (close === -1)
|
|
67
|
+
return { fields: {}, body: raw };
|
|
68
|
+
const fields = Object.create(null);
|
|
69
|
+
for (let index = 1; index < close; index++) {
|
|
70
|
+
const line = lines[index];
|
|
71
|
+
const match = /^([A-Za-z_][A-Za-z0-9_-]*):(.*)$/.exec(line);
|
|
72
|
+
if (!match)
|
|
73
|
+
continue;
|
|
74
|
+
const key = match[1];
|
|
75
|
+
const rest = match[2];
|
|
76
|
+
if (rest.trim() === "") {
|
|
77
|
+
// A bare key opens a block sequence of `- item` lines, the only multi-line shape we parse.
|
|
78
|
+
const items = [];
|
|
79
|
+
while (index + 1 < close && /^\s*-\s+/.test(lines[index + 1])) {
|
|
80
|
+
index++;
|
|
81
|
+
items.push(parseScalar(lines[index].replace(/^\s*-\s+/, "")));
|
|
82
|
+
}
|
|
83
|
+
fields[key] = items;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
fields[key] = parseScalar(rest);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const rest = lines.slice(close + 1);
|
|
90
|
+
if (rest[0] === "")
|
|
91
|
+
rest.shift();
|
|
92
|
+
return { fields, body: rest.join("\n") };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Parse a note file. Missing known keys take the defaults (accessCount 0, timestamps now);
|
|
96
|
+
* crumpledAt stays absent until explicitly set, and unknown keys survive untouched.
|
|
97
|
+
*/
|
|
98
|
+
export function parseNote(raw, now = Date.now()) {
|
|
99
|
+
const { fields, body } = parseFrontmatter(raw);
|
|
100
|
+
const meta = { ...fields };
|
|
101
|
+
// scope is a legacy on-disk field: store callers derive it from the file's home and
|
|
102
|
+
// overwrite it after parsing, so an absent or outdated value just falls back.
|
|
103
|
+
meta.scope = isScope(meta.scope) ? meta.scope : "session";
|
|
104
|
+
meta.origin = isOrigin(meta.origin) ? meta.origin : "self";
|
|
105
|
+
for (const key of TIMESTAMP_KEYS)
|
|
106
|
+
meta[key] = toEpoch(meta[key], now);
|
|
107
|
+
meta.accessCount = typeof meta.accessCount === "number" && Number.isFinite(meta.accessCount) ? meta.accessCount : 0;
|
|
108
|
+
return { meta: meta, body };
|
|
109
|
+
}
|
|
110
|
+
/** Emit a YAML scalar: bare for safe strings and JSON literals, JSON-quoted otherwise. */
|
|
111
|
+
function yamlScalar(value) {
|
|
112
|
+
if (typeof value === "string") {
|
|
113
|
+
const reserved = new Set(["true", "false", "null", "yes", "no", "on", "off", "~"]);
|
|
114
|
+
if (/^[A-Za-z0-9_.+\-:/]+$/.test(value) && !reserved.has(value.toLowerCase()))
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
return JSON.stringify(value);
|
|
118
|
+
}
|
|
119
|
+
/** Serialize frontmatter + blank line + body. Known keys emit in Design order, extras after. */
|
|
120
|
+
export function serializeNote(meta, body) {
|
|
121
|
+
const lines = [];
|
|
122
|
+
for (const key of KNOWN_KEYS) {
|
|
123
|
+
const value = meta[key];
|
|
124
|
+
if (value === undefined)
|
|
125
|
+
continue;
|
|
126
|
+
if (TIMESTAMP_KEYS.includes(key))
|
|
127
|
+
lines.push(`${key}: ${yamlScalar(localIso(value))}`);
|
|
128
|
+
else
|
|
129
|
+
lines.push(`${key}: ${yamlScalar(value)}`);
|
|
130
|
+
}
|
|
131
|
+
for (const key of Object.keys(meta)) {
|
|
132
|
+
// scope is a legacy on-disk field. Store callers derive it from the home's location,
|
|
133
|
+
// but serialization intentionally drops it on the next write.
|
|
134
|
+
if (key === "scope" || KNOWN_KEYS.includes(key))
|
|
135
|
+
continue;
|
|
136
|
+
if (meta[key] === undefined)
|
|
137
|
+
continue;
|
|
138
|
+
lines.push(`${key}: ${yamlScalar(meta[key])}`);
|
|
139
|
+
}
|
|
140
|
+
return `---\n${lines.join("\n")}\n---\n\n${body}`;
|
|
141
|
+
}
|
|
142
|
+
/** Strip a leading frontmatter block from user content, so a note body is pure content. */
|
|
143
|
+
export function stripLeadingFrontmatter(content) {
|
|
144
|
+
return parseFrontmatter(content).body;
|
|
145
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The store's own errno classification: a filesystem refusal, never a Node `ERR_*` code. */
|
|
2
|
+
export function isFilesystemError(error) {
|
|
3
|
+
const code = typeof error === "object" && error !== null ? error.code : undefined;
|
|
4
|
+
return typeof code === "string" && /^E[A-Z0-9_]+$/.test(code) && !code.startsWith("ERR_");
|
|
5
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Explicit, host-neutral identity for one notes store. */
|
|
2
|
+
export type NotesIdentity = Readonly<{
|
|
3
|
+
home: string;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
projectKey: string;
|
|
6
|
+
agent: string;
|
|
7
|
+
model: string;
|
|
8
|
+
}>;
|
|
9
|
+
/** Validate and snapshot caller identity; no global or environment defaults are consulted. */
|
|
10
|
+
export declare function snapshotNotesIdentity(value: NotesIdentity): NotesIdentity;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { SLUG_PATTERN } from "./paths.js";
|
|
3
|
+
function requireString(field, value) {
|
|
4
|
+
if (typeof value !== "string" || value.length === 0)
|
|
5
|
+
throw new TypeError(`notes context ${field} must be a non-empty string`);
|
|
6
|
+
return value;
|
|
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
|
+
/** Validate and snapshot caller identity; no global or environment defaults are consulted. */
|
|
14
|
+
export function snapshotNotesIdentity(value) {
|
|
15
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
16
|
+
throw new TypeError("notes context must be a plain object");
|
|
17
|
+
const prototype = Object.getPrototypeOf(value);
|
|
18
|
+
if (prototype !== Object.prototype && prototype !== null)
|
|
19
|
+
throw new TypeError("notes context must be a plain object");
|
|
20
|
+
const homeValue = requireString("home", value.home);
|
|
21
|
+
const sessionId = requireString("sessionId", value.sessionId);
|
|
22
|
+
const projectKey = requireString("projectKey", value.projectKey);
|
|
23
|
+
const agent = requireString("agent", value.agent);
|
|
24
|
+
const model = requireString("model", value.model);
|
|
25
|
+
assertDirectoryComponent("sessionId", sessionId);
|
|
26
|
+
assertDirectoryComponent("projectKey", projectKey);
|
|
27
|
+
if (!SLUG_PATTERN.test(agent))
|
|
28
|
+
throw new TypeError("notes context agent must be a canonical lowercase slug");
|
|
29
|
+
if (!SLUG_PATTERN.test(model))
|
|
30
|
+
throw new TypeError("notes context model must be a canonical lowercase slug");
|
|
31
|
+
const home = resolve(homeValue);
|
|
32
|
+
return Object.freeze({ home, sessionId, projectKey, agent, model });
|
|
33
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { createNotesStore, noteIdentity } from "./store.js";
|
|
2
|
+
export { NoteError, type NoteErrorCode } from "./errors.js";
|
|
3
|
+
export { projectKey, slugify } from "./paths.js";
|
|
4
|
+
export type { NotesIdentity } from "./identity.js";
|
|
5
|
+
export type { EditOperation, EditOptions, NoteChange, NoteEditResult, NoteMatch, NoteMeta, NoteQueryResult, NoteQueryStatus, NoteReadResult, NoteRenameResult, NoteRow, NoteSearchRow, NoteWriteResult, NotesQuery, NotesStore, Origin, Scope, WriteOptions, } from "./store.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { NotesIdentity } from "./identity.js";
|
|
2
|
+
export type Scope = "session" | "project" | "human" | "agent" | "model";
|
|
3
|
+
/** The one legal home-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
|
|
4
|
+
export declare const SLUG_PATTERN: RegExp;
|
|
5
|
+
/** Slugify a caller-declared identity; identity is never inferred from note content. */
|
|
6
|
+
export declare function slugify(value: string): string;
|
|
7
|
+
/** `<basename(absGitRoot)-sha1(absGitRoot)[:8]>`, or the same formula over cwd with no git root. */
|
|
8
|
+
export declare function projectKey(cwd: string): string;
|
|
9
|
+
/** Absolute directory holding the per-session note homes. */
|
|
10
|
+
export declare function sessionHomesRoot(home: string): string;
|
|
11
|
+
/** Absolute directory holding one scope's notes. The identity's home is already resolved. */
|
|
12
|
+
export declare function scopeDir(scope: Scope, identity: NotesIdentity, who?: string): string;
|
|
13
|
+
/** Every existing home directory of the agents/ or models/ namespace, as names. */
|
|
14
|
+
export declare function namespaceSlugs(namespace: "agents" | "models", home: string): Promise<string[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Notes are markdown files: a virtual path without an `.md` suffix gains one, an explicit
|
|
17
|
+
* `.md` is kept as-is, so `a/b` and `a/b.md` name the same physical file.
|
|
18
|
+
*/
|
|
19
|
+
export declare function noteFileName(vpath: string): string;
|
|
20
|
+
/** Absolute file path for a virtual path in a scope. Callers validate the vpath first. */
|
|
21
|
+
export declare function physicalPath(scope: Scope, vpath: string, identity: NotesIdentity, who?: string): string;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { readdir } from "node:fs/promises";
|
|
4
|
+
import { basename, dirname, join, resolve, sep } from "node:path";
|
|
5
|
+
/** The one legal home-name shape: lowercase [a-z0-9-] runs separated by single dashes. */
|
|
6
|
+
export const SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
7
|
+
/** Slugify a caller-declared identity; identity is never inferred from note content. */
|
|
8
|
+
export function slugify(value) {
|
|
9
|
+
const slug = value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
10
|
+
return slug.length > 0 ? slug : "root";
|
|
11
|
+
}
|
|
12
|
+
/** `<basename(absGitRoot)-sha1(absGitRoot)[:8]>`, or the same formula over cwd with no git root. */
|
|
13
|
+
export function projectKey(cwd) {
|
|
14
|
+
const absolute = resolve(cwd);
|
|
15
|
+
const root = gitRoot(absolute) ?? absolute;
|
|
16
|
+
const digest = createHash("sha1").update(root).digest("hex").slice(0, 8);
|
|
17
|
+
return `${basename(root)}-${digest}`;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Repository root behind one `.git` entry. A `.git` directory is the main checkout
|
|
21
|
+
* itself. A `.git` file is a worktree or submodule pointer: a linked worktree names
|
|
22
|
+
* `<main>/.git/worktrees/<name>` and resolves to `<main>`, so every worktree of one
|
|
23
|
+
* repository shares one project identity. Submodules, bare repositories, and separate
|
|
24
|
+
* git dirs keep the current directory.
|
|
25
|
+
*/
|
|
26
|
+
function repositoryRoot(dir) {
|
|
27
|
+
let stats;
|
|
28
|
+
try {
|
|
29
|
+
stats = statSync(join(dir, ".git"));
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return dir;
|
|
33
|
+
}
|
|
34
|
+
if (stats.isDirectory())
|
|
35
|
+
return dir;
|
|
36
|
+
let pointer;
|
|
37
|
+
try {
|
|
38
|
+
pointer = readFileSync(join(dir, ".git"), "utf8");
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return dir;
|
|
42
|
+
}
|
|
43
|
+
const match = /^gitdir:\s*(.+)$/m.exec(pointer);
|
|
44
|
+
if (!match)
|
|
45
|
+
return dir;
|
|
46
|
+
const parts = resolve(dir, match[1].trim()).split(sep);
|
|
47
|
+
const worktrees = parts.lastIndexOf("worktrees");
|
|
48
|
+
if (worktrees <= 0 || worktrees !== parts.length - 2)
|
|
49
|
+
return dir;
|
|
50
|
+
const common = parts.slice(0, worktrees).join(sep);
|
|
51
|
+
return basename(common) === ".git" ? dirname(common) : dir;
|
|
52
|
+
}
|
|
53
|
+
/** Absolute repository root for cwd, walking upward until a directory holds a `.git` entry. */
|
|
54
|
+
function gitRoot(cwd) {
|
|
55
|
+
let dir = resolve(cwd);
|
|
56
|
+
for (;;) {
|
|
57
|
+
if (existsSync(join(dir, ".git")))
|
|
58
|
+
return repositoryRoot(dir);
|
|
59
|
+
const parent = dirname(dir);
|
|
60
|
+
if (parent === dir)
|
|
61
|
+
return undefined;
|
|
62
|
+
dir = parent;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Absolute directory holding the per-session note homes. */
|
|
66
|
+
export function sessionHomesRoot(home) {
|
|
67
|
+
return join(home, "pi", "session");
|
|
68
|
+
}
|
|
69
|
+
/** Absolute directory holding one scope's notes. The identity's home is already resolved. */
|
|
70
|
+
export function scopeDir(scope, identity, who) {
|
|
71
|
+
if (!["session", "project", "human", "agent", "model"].includes(scope))
|
|
72
|
+
throw new TypeError("invalid notes scope");
|
|
73
|
+
if (who !== undefined && (scope !== "agent" && scope !== "model" || !SLUG_PATTERN.test(who)))
|
|
74
|
+
throw new TypeError("who must be a canonical agent/model slug");
|
|
75
|
+
if (scope === "human")
|
|
76
|
+
return join(identity.home, "human");
|
|
77
|
+
if (scope === "project")
|
|
78
|
+
return join(identity.home, "project", identity.projectKey);
|
|
79
|
+
if (scope === "agent")
|
|
80
|
+
return join(identity.home, "agents", who ?? identity.agent);
|
|
81
|
+
if (scope === "model")
|
|
82
|
+
return join(identity.home, "models", who ?? identity.model);
|
|
83
|
+
return join(sessionHomesRoot(identity.home), identity.sessionId);
|
|
84
|
+
}
|
|
85
|
+
/** Every existing home directory of the agents/ or models/ namespace, as names. */
|
|
86
|
+
export async function namespaceSlugs(namespace, home) {
|
|
87
|
+
try {
|
|
88
|
+
return (await readdir(join(home, namespace), { withFileTypes: true }))
|
|
89
|
+
.filter((entry) => entry.isDirectory())
|
|
90
|
+
.map((entry) => entry.name)
|
|
91
|
+
.sort();
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (error.code === "ENOENT")
|
|
95
|
+
return [];
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Notes are markdown files: a virtual path without an `.md` suffix gains one, an explicit
|
|
101
|
+
* `.md` is kept as-is, so `a/b` and `a/b.md` name the same physical file.
|
|
102
|
+
*/
|
|
103
|
+
export function noteFileName(vpath) {
|
|
104
|
+
return vpath.endsWith(".md") ? vpath : `${vpath}.md`;
|
|
105
|
+
}
|
|
106
|
+
/** Absolute file path for a virtual path in a scope. Callers validate the vpath first. */
|
|
107
|
+
export function physicalPath(scope, vpath, identity, who) {
|
|
108
|
+
if (typeof vpath !== "string" || vpath.length === 0 || vpath.includes("\0") || vpath.includes("\\") || vpath.startsWith("/"))
|
|
109
|
+
throw new TypeError("path must be a safe virtual relative path");
|
|
110
|
+
if (vpath.split("/").some((part) => part.length === 0 || part === "." || part === ".."))
|
|
111
|
+
throw new TypeError("path contains an unsupported component");
|
|
112
|
+
return join(scopeDir(scope, identity, who), ...noteFileName(vpath).split("/"));
|
|
113
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type NotesIdentity } from "./identity.js";
|
|
2
|
+
import { type NoteMeta, type Origin } from "./frontmatter.js";
|
|
3
|
+
import { type Scope } from "./paths.js";
|
|
4
|
+
export type { NoteMeta, Origin, Scope };
|
|
5
|
+
export type NoteRow = {
|
|
6
|
+
address: string;
|
|
7
|
+
scope: Scope;
|
|
8
|
+
path: string;
|
|
9
|
+
meta: NoteMeta;
|
|
10
|
+
body: string;
|
|
11
|
+
sizeBytes: number;
|
|
12
|
+
};
|
|
13
|
+
export type NoteMatch = {
|
|
14
|
+
line: number;
|
|
15
|
+
text: string; /** Code-point offset into the note body, not into the serialized file. */
|
|
16
|
+
offsetChars: number;
|
|
17
|
+
};
|
|
18
|
+
export type NoteSearchRow = {
|
|
19
|
+
address: string;
|
|
20
|
+
scope: Scope;
|
|
21
|
+
path: string;
|
|
22
|
+
meta: NoteMeta;
|
|
23
|
+
matches: NoteMatch[];
|
|
24
|
+
};
|
|
25
|
+
export type EditOperation = {
|
|
26
|
+
oldText: string;
|
|
27
|
+
newText: string;
|
|
28
|
+
};
|
|
29
|
+
export type WriteOptions = {
|
|
30
|
+
origin?: Origin;
|
|
31
|
+
};
|
|
32
|
+
export type EditOptions = {
|
|
33
|
+
origin?: Origin;
|
|
34
|
+
crumpled?: boolean;
|
|
35
|
+
replaceAll?: boolean;
|
|
36
|
+
};
|
|
37
|
+
export type NotesQuery = ({
|
|
38
|
+
scope?: undefined;
|
|
39
|
+
who?: never;
|
|
40
|
+
} | {
|
|
41
|
+
scope: "session" | "project" | "human";
|
|
42
|
+
who?: never;
|
|
43
|
+
} | {
|
|
44
|
+
scope: "agent" | "model";
|
|
45
|
+
who?: string;
|
|
46
|
+
}) & {
|
|
47
|
+
glob?: string;
|
|
48
|
+
crumpled?: boolean;
|
|
49
|
+
};
|
|
50
|
+
/** A read exposes metadata and the pure body; the serialized frontmatter is never part of the body. */
|
|
51
|
+
export type NoteReadResult = {
|
|
52
|
+
meta: NoteMeta;
|
|
53
|
+
body: string;
|
|
54
|
+
resolvedScope: Scope;
|
|
55
|
+
};
|
|
56
|
+
export type NoteWriteResult = {
|
|
57
|
+
meta: NoteMeta;
|
|
58
|
+
outcome: "created" | "overwrote" | "uncrumpled";
|
|
59
|
+
};
|
|
60
|
+
export type NoteChange = {
|
|
61
|
+
kind: "none";
|
|
62
|
+
before: "";
|
|
63
|
+
after: "";
|
|
64
|
+
} | {
|
|
65
|
+
kind: "body" | "metadata";
|
|
66
|
+
before: string;
|
|
67
|
+
after: string;
|
|
68
|
+
};
|
|
69
|
+
export type NoteEditResult = {
|
|
70
|
+
meta: NoteMeta;
|
|
71
|
+
applied: number;
|
|
72
|
+
resolvedScope: Scope;
|
|
73
|
+
change: NoteChange;
|
|
74
|
+
};
|
|
75
|
+
export type NoteRenameResult = {
|
|
76
|
+
meta: NoteMeta;
|
|
77
|
+
replacedCrumpledTarget: boolean;
|
|
78
|
+
};
|
|
79
|
+
export type NoteQueryStatus = {
|
|
80
|
+
homesUnavailable: string[];
|
|
81
|
+
};
|
|
82
|
+
export type NoteQueryResult<T> = {
|
|
83
|
+
rows: T[];
|
|
84
|
+
status: NoteQueryStatus;
|
|
85
|
+
};
|
|
86
|
+
/** Public identity resolved for an operation, never a filesystem path. */
|
|
87
|
+
export declare function noteIdentity(identity: NotesIdentity, address: string): {
|
|
88
|
+
address: string;
|
|
89
|
+
project_key?: string;
|
|
90
|
+
};
|
|
91
|
+
/** Host-neutral, filesystem-backed notes API. */
|
|
92
|
+
export interface NotesStore {
|
|
93
|
+
write(address: string, content: string, options?: WriteOptions): Promise<NoteWriteResult>;
|
|
94
|
+
read(address: string): Promise<NoteReadResult | undefined>;
|
|
95
|
+
update(address: string, edits?: EditOperation[], options?: EditOptions): Promise<NoteEditResult>;
|
|
96
|
+
rename(fromAddress: string, toAddress: string): Promise<NoteRenameResult>;
|
|
97
|
+
list(options?: NotesQuery): Promise<NoteRow[]>;
|
|
98
|
+
search(queries: string[], options?: NotesQuery): Promise<NoteSearchRow[]>;
|
|
99
|
+
listWithStatus(options?: NotesQuery): Promise<NoteQueryResult<NoteRow>>;
|
|
100
|
+
searchWithStatus(queries: string[], options?: NotesQuery): Promise<NoteQueryResult<NoteSearchRow>>;
|
|
101
|
+
}
|
|
102
|
+
/** Create a store over one validated, immutable snapshot of the supplied explicit identity. */
|
|
103
|
+
export declare function createNotesStore(input: NotesIdentity): NotesStore;
|