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.
Files changed (227) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -2
  3. package/dist/src/boot/render.d.ts +16 -0
  4. package/dist/src/boot/render.js +95 -0
  5. package/dist/src/boot/snapshot.d.ts +32 -0
  6. package/dist/src/boot/snapshot.js +36 -0
  7. package/dist/src/boot/text.d.ts +17 -0
  8. package/dist/src/boot/text.js +48 -0
  9. package/dist/src/budget/constants.d.ts +9 -0
  10. package/dist/src/budget/constants.js +9 -0
  11. package/dist/src/budget/policy.d.ts +19 -0
  12. package/dist/src/budget/policy.js +36 -0
  13. package/dist/src/budget/text.d.ts +8 -0
  14. package/dist/src/budget/text.js +10 -0
  15. package/dist/src/claude/helper.d.ts +15 -0
  16. package/dist/src/claude/helper.js +87 -0
  17. package/dist/src/dream/doctor.d.ts +2 -0
  18. package/dist/src/dream/doctor.js +160 -0
  19. package/dist/src/dream/gates.d.ts +10 -0
  20. package/dist/src/dream/gates.js +26 -0
  21. package/dist/src/dream/git.d.ts +21 -0
  22. package/dist/src/dream/git.js +71 -0
  23. package/dist/src/dream/jail.d.ts +11 -0
  24. package/dist/src/dream/jail.js +71 -0
  25. package/dist/src/dream/lock.d.ts +31 -0
  26. package/dist/src/dream/lock.js +99 -0
  27. package/dist/src/dream/playbook.d.ts +1 -0
  28. package/dist/src/dream/playbook.js +2 -0
  29. package/dist/src/dream/report.d.ts +7 -0
  30. package/dist/src/dream/report.js +43 -0
  31. package/dist/src/dream/result.d.ts +9 -0
  32. package/dist/src/dream/result.js +1 -0
  33. package/dist/src/dream/settings.d.ts +10 -0
  34. package/dist/src/dream/settings.js +14 -0
  35. package/dist/src/history/history.d.ts +156 -0
  36. package/dist/src/history/history.js +212 -0
  37. package/dist/src/history/query.d.ts +63 -0
  38. package/dist/src/history/query.js +201 -0
  39. package/dist/src/index.d.ts +1 -0
  40. package/dist/src/index.js +1 -0
  41. package/dist/src/notes/address.d.ts +31 -0
  42. package/dist/src/notes/address.js +123 -0
  43. package/dist/src/notes/constants.d.ts +3 -0
  44. package/dist/src/notes/constants.js +3 -0
  45. package/dist/src/notes/errors.d.ts +11 -0
  46. package/dist/src/notes/errors.js +13 -0
  47. package/dist/src/notes/frontmatter.d.ts +44 -0
  48. package/dist/src/notes/frontmatter.js +145 -0
  49. package/dist/src/notes/fs-error.d.ts +2 -0
  50. package/dist/src/notes/fs-error.js +5 -0
  51. package/dist/src/notes/identity.d.ts +10 -0
  52. package/dist/src/notes/identity.js +33 -0
  53. package/dist/src/notes/index.d.ts +5 -0
  54. package/dist/src/notes/index.js +3 -0
  55. package/dist/src/notes/paths.d.ts +21 -0
  56. package/dist/src/notes/paths.js +113 -0
  57. package/dist/src/notes/store.d.ts +103 -0
  58. package/dist/src/notes/store.js +474 -0
  59. package/dist/src/pi/boot.d.ts +24 -0
  60. package/dist/src/pi/boot.js +56 -0
  61. package/dist/src/pi/budget.d.ts +13 -0
  62. package/dist/src/pi/budget.js +178 -0
  63. package/dist/src/pi/dream/cli.d.ts +10 -0
  64. package/dist/src/pi/dream/cli.js +140 -0
  65. package/dist/src/pi/dream/runner.d.ts +27 -0
  66. package/dist/src/pi/dream/runner.js +90 -0
  67. package/dist/src/pi/dream/settings.d.ts +7 -0
  68. package/dist/src/pi/dream/settings.js +17 -0
  69. package/dist/src/pi/entries.d.ts +7 -0
  70. package/dist/src/pi/entries.js +7 -0
  71. package/dist/src/pi/estimate.d.ts +16 -0
  72. package/dist/src/pi/estimate.js +99 -0
  73. package/dist/src/pi/extension.d.ts +10 -0
  74. package/dist/src/pi/extension.js +24 -0
  75. package/dist/src/pi/history-tools.d.ts +3 -0
  76. package/dist/src/pi/history-tools.js +9 -0
  77. package/dist/src/pi/history.d.ts +4 -0
  78. package/dist/src/pi/history.js +150 -0
  79. package/dist/src/pi/notes/adapter.d.ts +10 -0
  80. package/dist/src/pi/notes/adapter.js +27 -0
  81. package/dist/src/pi/notes/tools.d.ts +3 -0
  82. package/dist/src/pi/notes/tools.js +15 -0
  83. package/dist/src/pi/reset/artifacts.d.ts +24 -0
  84. package/dist/src/pi/reset/artifacts.js +84 -0
  85. package/dist/src/pi/reset/committed.d.ts +7 -0
  86. package/dist/src/pi/reset/committed.js +28 -0
  87. package/dist/src/pi/reset/lifecycle.d.ts +101 -0
  88. package/dist/src/pi/reset/lifecycle.js +277 -0
  89. package/dist/src/pi/reset/text.d.ts +5 -0
  90. package/dist/src/pi/reset/text.js +6 -0
  91. package/dist/src/pi/runtime.d.ts +3 -0
  92. package/dist/src/pi/runtime.js +206 -0
  93. package/dist/src/pi/session-reader.d.ts +5 -0
  94. package/dist/src/pi/session-reader.js +1 -0
  95. package/dist/src/pi/thresholds.d.ts +17 -0
  96. package/dist/src/pi/thresholds.js +33 -0
  97. package/dist/src/pi/tool-names.d.ts +7 -0
  98. package/dist/src/pi/tool-names.js +7 -0
  99. package/dist/src/pi/tool-result.d.ts +15 -0
  100. package/dist/src/pi/tool-result.js +29 -0
  101. package/dist/src/pi/window.d.ts +41 -0
  102. package/dist/src/pi/window.js +127 -0
  103. package/dist/src/settings.d.ts +9 -0
  104. package/dist/src/settings.js +18 -0
  105. package/dist/src/text-match.d.ts +5 -0
  106. package/dist/src/text-match.js +16 -0
  107. package/dist/src/tools/history.d.ts +58 -0
  108. package/dist/src/tools/history.js +210 -0
  109. package/dist/src/tools/notes.d.ts +250 -0
  110. package/dist/src/tools/notes.js +360 -0
  111. package/dist/src/tools/output.d.ts +23 -0
  112. package/dist/src/tools/output.js +39 -0
  113. package/dist/src/tools/result.d.ts +82 -0
  114. package/dist/src/tools/result.js +104 -0
  115. package/dist/src/tools/schema.d.ts +18 -0
  116. package/dist/src/tools/schema.js +31 -0
  117. package/dist/test/agent-loop.test.d.ts +1 -0
  118. package/dist/test/agent-loop.test.js +1497 -0
  119. package/dist/test/boot.integration.test.d.ts +1 -0
  120. package/dist/test/boot.integration.test.js +294 -0
  121. package/dist/test/budget-settings.integration.test.d.ts +1 -0
  122. package/dist/test/budget-settings.integration.test.js +144 -0
  123. package/dist/test/claude-mod.test.d.ts +1 -0
  124. package/dist/test/claude-mod.test.js +404 -0
  125. package/dist/test/dependencies.test.d.ts +1 -0
  126. package/dist/test/dependencies.test.js +101 -0
  127. package/dist/test/doctor.test.d.ts +1 -0
  128. package/dist/test/doctor.test.js +37 -0
  129. package/dist/test/dream-skill.test.d.ts +1 -0
  130. package/dist/test/dream-skill.test.js +72 -0
  131. package/dist/test/dream.test.d.ts +1 -0
  132. package/dist/test/dream.test.js +136 -0
  133. package/dist/test/helpers/dependency-graph.d.ts +5 -0
  134. package/dist/test/helpers/dependency-graph.js +73 -0
  135. package/dist/test/helpers/extension-test-environment.d.ts +1 -0
  136. package/dist/test/helpers/extension-test-environment.js +9 -0
  137. package/dist/test/helpers/extension.d.ts +119 -0
  138. package/dist/test/helpers/extension.js +367 -0
  139. package/dist/test/helpers/notes.d.ts +6 -0
  140. package/dist/test/helpers/notes.js +13 -0
  141. package/dist/test/history.integration.test.d.ts +1 -0
  142. package/dist/test/history.integration.test.js +633 -0
  143. package/dist/test/host-neutral.test.d.ts +1 -0
  144. package/dist/test/host-neutral.test.js +274 -0
  145. package/dist/test/notes-library.test.d.ts +1 -0
  146. package/dist/test/notes-library.test.js +214 -0
  147. package/dist/test/notes.integration.test.d.ts +1 -0
  148. package/dist/test/notes.integration.test.js +515 -0
  149. package/dist/test/notes.test.d.ts +1 -0
  150. package/dist/test/notes.test.js +530 -0
  151. package/dist/test/reset-lifecycle.test.d.ts +1 -0
  152. package/dist/test/reset-lifecycle.test.js +605 -0
  153. package/docs/architecture.md +63 -0
  154. package/docs/claude-code-mod.md +9 -0
  155. package/docs/notes-library.md +74 -0
  156. package/docs/reset-lifecycle.md +75 -0
  157. package/docs/sdk-integration.md +39 -0
  158. package/docs/skills.md +30 -0
  159. package/docs/tool-results.md +78 -0
  160. package/mods/notesoup/.claude-plugin/plugin.json +8 -0
  161. package/mods/notesoup/dist/claude/helper.js +9265 -0
  162. package/mods/notesoup/hooks/hooks.json +4 -0
  163. package/mods/notesoup/hooks/register.ts +240 -0
  164. package/mods/notesoup/playbook.md +34 -0
  165. package/mods/notesoup/skills/dream/SKILL.md +12 -0
  166. package/mods/pi-context/dist/claude/helper.js +9324 -0
  167. package/package.json +89 -5
  168. package/playbook.md +34 -0
  169. package/skills/dream/SKILL.md +12 -0
  170. package/skills/memory/SKILL.md +59 -0
  171. package/src/boot/render.ts +115 -0
  172. package/src/boot/snapshot.ts +46 -0
  173. package/src/boot/text.ts +58 -0
  174. package/src/budget/constants.ts +9 -0
  175. package/src/budget/policy.ts +36 -0
  176. package/src/budget/text.ts +11 -0
  177. package/src/claude/helper.ts +94 -0
  178. package/src/dream/doctor.ts +117 -0
  179. package/src/dream/gates.ts +26 -0
  180. package/src/dream/git.ts +73 -0
  181. package/src/dream/jail.ts +62 -0
  182. package/src/dream/lock.ts +82 -0
  183. package/src/dream/playbook.ts +3 -0
  184. package/src/dream/report.ts +36 -0
  185. package/src/dream/result.ts +2 -0
  186. package/src/dream/settings.ts +16 -0
  187. package/src/history/history.ts +286 -0
  188. package/src/history/query.ts +222 -0
  189. package/src/index.ts +1 -0
  190. package/src/notes/address.ts +110 -0
  191. package/src/notes/constants.ts +3 -0
  192. package/src/notes/errors.ts +15 -0
  193. package/src/notes/frontmatter.ts +166 -0
  194. package/src/notes/fs-error.ts +5 -0
  195. package/src/notes/identity.ts +40 -0
  196. package/src/notes/index.ts +24 -0
  197. package/src/notes/paths.ts +109 -0
  198. package/src/notes/store.ts +494 -0
  199. package/src/pi/boot.ts +88 -0
  200. package/src/pi/budget.ts +178 -0
  201. package/src/pi/dream/cli.ts +92 -0
  202. package/src/pi/dream/runner.ts +91 -0
  203. package/src/pi/dream/settings.ts +17 -0
  204. package/src/pi/entries.ts +7 -0
  205. package/src/pi/estimate.ts +116 -0
  206. package/src/pi/extension.ts +27 -0
  207. package/src/pi/history-tools.ts +11 -0
  208. package/src/pi/history.ts +162 -0
  209. package/src/pi/notes/adapter.ts +33 -0
  210. package/src/pi/notes/tools.ts +18 -0
  211. package/src/pi/reset/artifacts.ts +100 -0
  212. package/src/pi/reset/committed.ts +26 -0
  213. package/src/pi/reset/lifecycle.ts +342 -0
  214. package/src/pi/reset/text.ts +10 -0
  215. package/src/pi/runtime.ts +200 -0
  216. package/src/pi/session-reader.ts +6 -0
  217. package/src/pi/thresholds.ts +50 -0
  218. package/src/pi/tool-names.ts +9 -0
  219. package/src/pi/tool-result.ts +41 -0
  220. package/src/pi/window.ts +133 -0
  221. package/src/settings.ts +22 -0
  222. package/src/text-match.ts +14 -0
  223. package/src/tools/history.ts +234 -0
  224. package/src/tools/notes.ts +381 -0
  225. package/src/tools/output.ts +41 -0
  226. package/src/tools/result.ts +144 -0
  227. package/src/tools/schema.ts +31 -0
@@ -0,0 +1,156 @@
1
+ /** Recorded details live once, in the pageable event document; tools expose a small summary. */
2
+ import { Type, type Static } from "typebox";
3
+ /** The four public roles a history event carries on the wire, in presentation order. */
4
+ export declare const HistoryRoleSchema: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
5
+ export type HistoryRole = Static<typeof HistoryRoleSchema>;
6
+ /** How a recorded tool run ended. A call with no recorded result has not ended. */
7
+ export declare const ToolCallStatusSchema: Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>;
8
+ export type ToolCallStatus = Static<typeof ToolCallStatusSchema>;
9
+ /** Internal recorded facts, not a second copy in the public read schema. */
10
+ export type NestedCallRecord = {
11
+ id: string;
12
+ name: string;
13
+ arguments?: Record<string, unknown>;
14
+ argumentsBytes?: number;
15
+ status: ToolCallStatus;
16
+ durationMs?: number;
17
+ error?: string;
18
+ };
19
+ export type RecordedNestedCalls = {
20
+ calls: NestedCallRecord[];
21
+ complete: boolean;
22
+ };
23
+ export type ToolExecutionFacts = {
24
+ name: string;
25
+ status: ToolCallStatus;
26
+ arguments?: Record<string, unknown>;
27
+ outputTruncated?: boolean;
28
+ fullOutputPath?: string;
29
+ nestedCalls?: RecordedNestedCalls;
30
+ };
31
+ /** One projection event: its facts, and the document they render to. */
32
+ export type HistoryEvent = {
33
+ seq: number;
34
+ windowId: string;
35
+ role: HistoryRole;
36
+ createdAt: string | undefined;
37
+ /** Message body for user/assistant/context; the run's output for a tool event. */
38
+ text: string;
39
+ /** Whole recorded facts, rendered by eventDocument. */
40
+ execution?: ToolExecutionFacts;
41
+ };
42
+ export type HistoryWindow = {
43
+ windowId: string;
44
+ createdAt?: string;
45
+ items: HistoryEvent[];
46
+ };
47
+ /** Paired result seqs stay on the branch but redirect readers to the call's event. */
48
+ export type HistoryProjection = {
49
+ windows: HistoryWindow[];
50
+ highestSeq: number;
51
+ branchSeqs: Set<number>;
52
+ pairedResults: Map<number, number>;
53
+ };
54
+ /** The filters one selection applies before paging: as-given window and roles, seq bounds, and parsed epoch-ms time bounds. */
55
+ export type HistoryFilter = {
56
+ window_id?: string | null;
57
+ roles?: HistoryRole[] | null;
58
+ after_seq?: number;
59
+ before_seq?: number;
60
+ sinceMs?: number;
61
+ untilMs?: number;
62
+ };
63
+ /** Native entries after the adapter allocates seqs and selects the active branch. */
64
+ export type DecodedHistoryItem = {
65
+ seq: number;
66
+ windowId: string;
67
+ role: "user" | "assistant" | "tool_call" | "tool" | "system" | "developer";
68
+ /** Message body; for a tool call or result, the arguments or output text respectively. */
69
+ text: string;
70
+ createdAt?: string;
71
+ toolName?: string;
72
+ /** Internal pairing key; never serialized. */
73
+ toolCallId?: string;
74
+ /** The recorded arguments object, exactly as the host stored it. */
75
+ arguments?: Record<string, unknown>;
76
+ outputTruncated?: boolean;
77
+ fullOutputPath?: string;
78
+ /** The run reported an error. */
79
+ toolError?: boolean;
80
+ /** Native outcome for a standalone run (e.g. bash exit status). */
81
+ recordedStatus?: ToolCallStatus;
82
+ /** toolResult only: the calls this run made to other tools. */
83
+ nestedCalls?: RecordedNestedCalls;
84
+ };
85
+ export type DecodedHistoryWindow = {
86
+ windowId: string;
87
+ createdAt?: string;
88
+ items: DecodedHistoryItem[];
89
+ };
90
+ export declare function contentText(content: unknown): string;
91
+ /** Canonical searchable/readable text, without UI headers or continuation footers. */
92
+ export declare function historyDocument(event: HistoryEvent): string;
93
+ /** Memoized `historyDocument`: search, preview, and read must agree on the same characters. */
94
+ export declare function eventDocument(event: HistoryEvent): string;
95
+ /** Pair results into call events; consumed result seqs are not alternate read addresses. */
96
+ export declare function projectHistory(rawWindows: DecodedHistoryWindow[], highestSeq: number, branchSeqs: Set<number>): HistoryProjection;
97
+ /** Summary shared by list, search and read. Full arguments/calls are in the document. */
98
+ export declare const NestedCallSummarySchema: Type.TObject<{
99
+ call_count: Type.TInteger;
100
+ complete: Type.TBoolean;
101
+ }>;
102
+ /** Tool-run facts shared by list rows and reads; full arguments and calls live in the document. */
103
+ export declare const ToolSummarySchema: Type.TObject<{
104
+ tool: Type.TOptional<Type.TString>;
105
+ tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
106
+ output_truncated: Type.TOptional<Type.TLiteral<true>>;
107
+ full_output_path: Type.TOptional<Type.TString>;
108
+ }>;
109
+ export declare function toolSummary(event: HistoryEvent): Static<typeof ToolSummarySchema>;
110
+ /** Nested-call evidence is read with one event, not listed on every page row. */
111
+ export declare function nestedCallSummary(event: HistoryEvent): {
112
+ nested_calls?: Static<typeof NestedCallSummarySchema>;
113
+ };
114
+ /** Stable identity and a verbatim preview, starting at the search match when present. */
115
+ export declare const HistoryPageItemSchema: Type.TObject<{
116
+ content: Type.TString;
117
+ truncated: Type.TBoolean;
118
+ offset_chars: Type.TOptional<Type.TInteger>;
119
+ tool: Type.TOptional<Type.TString>;
120
+ tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
121
+ output_truncated: Type.TOptional<Type.TLiteral<true>>;
122
+ full_output_path: Type.TOptional<Type.TString>;
123
+ seq: Type.TInteger;
124
+ window_id: Type.TString;
125
+ role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
126
+ created_at: Type.TUnion<[Type.TString, Type.TNull]>;
127
+ }>;
128
+ export type HistoryPageItem = Static<typeof HistoryPageItemSchema>;
129
+ /** A run of tool/context events the conversation view replaces with counts. */
130
+ export declare const HistoryFoldedRowSchema: Type.TObject<{
131
+ folded: Type.TLiteral<true>;
132
+ first_seq: Type.TInteger;
133
+ last_seq: Type.TInteger;
134
+ count: Type.TInteger;
135
+ tools: Type.TRecord<"^.*$", Type.TInteger>;
136
+ }>;
137
+ export type HistoryFoldedRow = Static<typeof HistoryFoldedRowSchema>;
138
+ /** Bound fold summaries; `count` stays exact even when some tool names do not fit. */
139
+ export declare const MAX_FOLD_TOOL_NAMES = 20;
140
+ /** Longest tool name a fold row lists. */
141
+ export declare const MAX_FOLD_TOOL_NAME_CHARS = 120;
142
+ /** A bounded preview of one event from `matchOffset` on, plus its identity facts. */
143
+ export declare function visibleItem(event: HistoryEvent, maxChars: number, matchOffset?: number): HistoryPageItem;
144
+ export declare function allItems(projection: HistoryProjection): HistoryEvent[];
145
+ export declare function unknownWindowId(projection: HistoryProjection, params: HistoryFilter): {
146
+ message: string;
147
+ known: string[];
148
+ } | undefined;
149
+ /**
150
+ * Whether one event is inside the selection: its window, its seq bounds, and a half-open
151
+ * [sinceMs, untilMs) window on created_at. A bounded time window drops events with no recorded
152
+ * time or a time that cannot be read.
153
+ */
154
+ export declare function inSelection(event: HistoryEvent, params: HistoryFilter): boolean;
155
+ /** Without roles or query a call shows the conversation; either one shows the requested events. */
156
+ export declare function filteredItems(projection: HistoryProjection, params: HistoryFilter, conversation: boolean): HistoryEvent[];
@@ -0,0 +1,212 @@
1
+ /** Recorded details live once, in the pageable event document; tools expose a small summary. */
2
+ import { Type } from "typebox";
3
+ /** The four public roles a history event carries on the wire, in presentation order. */
4
+ export const HistoryRoleSchema = Type.Union([Type.Literal("user"), Type.Literal("assistant"), Type.Literal("tool"), Type.Literal("context")]);
5
+ /** How a recorded tool run ended. A call with no recorded result has not ended. */
6
+ export const ToolCallStatusSchema = Type.Union([Type.Literal("ok"), Type.Literal("error"), Type.Literal("unfinished")]);
7
+ function isTextContent(part) {
8
+ return typeof part === "object" && part !== null && part.type === "text" && typeof part.text === "string";
9
+ }
10
+ export function contentText(content) {
11
+ if (typeof content === "string")
12
+ return content;
13
+ return Array.isArray(content) ? content.filter(isTextContent).map((part) => part.text).join("\n") : "";
14
+ }
15
+ function argumentText(execution) {
16
+ return execution.arguments === undefined ? "(arguments not recorded)" : JSON.stringify(execution.arguments);
17
+ }
18
+ function nestedCallLine(call) {
19
+ const parts = [`${call.id} ${call.name} [${call.status}]`];
20
+ if (call.durationMs !== undefined)
21
+ parts.push(`${call.durationMs}ms`);
22
+ if (call.error !== undefined)
23
+ parts.push(`error: ${call.error}`);
24
+ parts.push(call.arguments === undefined ? (call.argumentsBytes === undefined ? "(arguments not recorded)" : `(arguments omitted: ${call.argumentsBytes} bytes)`) : JSON.stringify(call.arguments));
25
+ return `- ${parts.join(" ")}`;
26
+ }
27
+ /** Canonical searchable/readable text, without UI headers or continuation footers. */
28
+ export function historyDocument(event) {
29
+ if (event.execution === undefined)
30
+ return event.text;
31
+ const sections = [`${event.execution.name} ${argumentText(event.execution)}`];
32
+ // An unfinished call has no recorded output at all, and saying so by omission is truthful.
33
+ if (event.text !== "")
34
+ sections.push(`--- output ---\n${event.text}`);
35
+ const nested = event.execution.nestedCalls;
36
+ if (nested !== undefined) {
37
+ const header = nested.complete ? "complete" : "incomplete";
38
+ sections.push(`--- nested calls (${header}, ${nested.calls.length} recorded) ---\n${nested.calls.map(nestedCallLine).join("\n")}`);
39
+ }
40
+ return sections.join("\n");
41
+ }
42
+ const documents = new WeakMap();
43
+ /** Memoized `historyDocument`: search, preview, and read must agree on the same characters. */
44
+ export function eventDocument(event) {
45
+ const cached = documents.get(event);
46
+ if (cached !== undefined)
47
+ return cached;
48
+ const text = historyDocument(event);
49
+ documents.set(event, text);
50
+ return text;
51
+ }
52
+ /** Pair a call with its result, or preserve a standalone run's recorded outcome. */
53
+ function toolEvent(item, result) {
54
+ const run = result ?? item;
55
+ // Only a call without a result is unfinished; standalone results carry their own outcome.
56
+ const status = item.role === "tool_call" && result === undefined
57
+ ? "unfinished"
58
+ : run.recordedStatus ?? (run.toolError === true ? "error" : "ok");
59
+ const truncated = run.outputTruncated === true;
60
+ return {
61
+ seq: item.seq,
62
+ windowId: item.windowId,
63
+ role: "tool",
64
+ text: result?.text ?? (item.role === "tool" ? item.text : ""),
65
+ createdAt: item.createdAt,
66
+ execution: {
67
+ name: item.toolName ?? "unknown",
68
+ status,
69
+ // A call records its arguments; a bare result records none, and gets none invented.
70
+ ...(item.arguments === undefined ? {} : { arguments: item.arguments }),
71
+ ...(truncated ? { outputTruncated: true, ...(run.fullOutputPath ? { fullOutputPath: run.fullOutputPath } : {}) } : {}),
72
+ ...(run.nestedCalls ? { nestedCalls: run.nestedCalls } : {}),
73
+ },
74
+ };
75
+ }
76
+ /** Pair results into call events; consumed result seqs are not alternate read addresses. */
77
+ export function projectHistory(rawWindows, highestSeq, branchSeqs) {
78
+ const raw = rawWindows.flatMap((current) => current.items);
79
+ const resultsById = new Map();
80
+ for (const item of raw) {
81
+ if (item.role === "tool" && item.toolCallId && !resultsById.has(item.toolCallId))
82
+ resultsById.set(item.toolCallId, item);
83
+ }
84
+ const pairedResults = new Map();
85
+ const consumed = new Set();
86
+ const windows = rawWindows.map((current) => ({
87
+ windowId: current.windowId,
88
+ ...(current.createdAt ? { createdAt: current.createdAt } : {}),
89
+ items: current.items.flatMap((item) => {
90
+ if (consumed.has(item.seq))
91
+ return [];
92
+ if (item.role === "tool_call") {
93
+ const result = item.toolCallId ? resultsById.get(item.toolCallId) : undefined;
94
+ const paired = result && result.seq > item.seq && !consumed.has(result.seq) ? result : undefined;
95
+ if (paired) {
96
+ consumed.add(paired.seq);
97
+ pairedResults.set(paired.seq, item.seq);
98
+ }
99
+ return [toolEvent(item, paired)];
100
+ }
101
+ if (item.role === "tool")
102
+ return [toolEvent(item)];
103
+ return [{ seq: item.seq, windowId: item.windowId, role: item.role === "system" || item.role === "developer" ? "context" : item.role, text: item.text, createdAt: item.createdAt }];
104
+ }),
105
+ }));
106
+ return { windows, highestSeq, branchSeqs, pairedResults };
107
+ }
108
+ /** Summary shared by list, search and read. Full arguments/calls are in the document. */
109
+ export const NestedCallSummarySchema = Type.Object({
110
+ call_count: Type.Integer({ minimum: 0 }),
111
+ complete: Type.Boolean({ description: "true = every nested call was recorded." }),
112
+ }, { additionalProperties: false });
113
+ /** Tool-run facts shared by list rows and reads; full arguments and calls live in the document. */
114
+ export const ToolSummarySchema = Type.Object({
115
+ tool: Type.Optional(Type.String()),
116
+ tool_status: Type.Optional(ToolCallStatusSchema),
117
+ output_truncated: Type.Optional(Type.Literal(true)),
118
+ full_output_path: Type.Optional(Type.String()),
119
+ }, { additionalProperties: false });
120
+ export function toolSummary(event) {
121
+ const execution = event.execution;
122
+ if (!execution)
123
+ return {};
124
+ return {
125
+ tool: execution.name,
126
+ tool_status: execution.status,
127
+ ...(execution.outputTruncated ? { output_truncated: true } : {}),
128
+ ...(execution.fullOutputPath ? { full_output_path: execution.fullOutputPath } : {}),
129
+ };
130
+ }
131
+ /** Nested-call evidence is read with one event, not listed on every page row. */
132
+ export function nestedCallSummary(event) {
133
+ const nested = event.execution?.nestedCalls;
134
+ return nested === undefined ? {} : { nested_calls: { call_count: nested.calls.length, complete: nested.complete } };
135
+ }
136
+ /** Stable identity and a verbatim preview, starting at the search match when present. */
137
+ export const HistoryPageItemSchema = Type.Object({
138
+ seq: Type.Integer({ minimum: 1 }),
139
+ window_id: Type.String(),
140
+ role: HistoryRoleSchema,
141
+ created_at: Type.Union([Type.String(), Type.Null()]),
142
+ ...ToolSummarySchema.properties,
143
+ content: Type.String(),
144
+ truncated: Type.Boolean({ description: "Preview is partial." }),
145
+ offset_chars: Type.Optional(Type.Integer({ minimum: 0, description: "Where the preview starts." })),
146
+ }, { additionalProperties: false });
147
+ /** A run of tool/context events the conversation view replaces with counts. */
148
+ export const HistoryFoldedRowSchema = Type.Object({
149
+ folded: Type.Literal(true),
150
+ first_seq: Type.Integer({ minimum: 1 }),
151
+ last_seq: Type.Integer({ minimum: 1 }),
152
+ count: Type.Integer({ minimum: 1 }),
153
+ tools: Type.Record(Type.String(), Type.Integer({ minimum: 1 }), { description: "Count per tool name." }),
154
+ }, { additionalProperties: false });
155
+ /** Bound fold summaries; `count` stays exact even when some tool names do not fit. */
156
+ export const MAX_FOLD_TOOL_NAMES = 20;
157
+ /** Longest tool name a fold row lists. */
158
+ export const MAX_FOLD_TOOL_NAME_CHARS = 120;
159
+ /** A bounded preview of one event from `matchOffset` on, plus its identity facts. */
160
+ export function visibleItem(event, maxChars, matchOffset) {
161
+ const document = eventDocument(event);
162
+ const chars = Array.from(document);
163
+ const start = matchOffset ?? 0;
164
+ const truncated = start > 0 || start + maxChars < chars.length;
165
+ return {
166
+ seq: event.seq,
167
+ window_id: event.windowId,
168
+ role: event.role,
169
+ created_at: event.createdAt ?? null,
170
+ ...toolSummary(event),
171
+ content: truncated ? chars.slice(start, start + maxChars).join("") : document,
172
+ truncated,
173
+ ...(matchOffset === undefined ? {} : { offset_chars: matchOffset }),
174
+ };
175
+ }
176
+ export function allItems(projection) {
177
+ return projection.windows.flatMap((current) => current.items);
178
+ }
179
+ export function unknownWindowId(projection, params) {
180
+ if (typeof params.window_id !== "string")
181
+ return undefined;
182
+ const known = projection.windows.map((current) => current.windowId);
183
+ return known.includes(params.window_id) ? undefined : { message: `unknown window_id "${params.window_id}"`, known };
184
+ }
185
+ /**
186
+ * Whether one event is inside the selection: its window, its seq bounds, and a half-open
187
+ * [sinceMs, untilMs) window on created_at. A bounded time window drops events with no recorded
188
+ * time or a time that cannot be read.
189
+ */
190
+ export function inSelection(event, params) {
191
+ if (typeof params.window_id === "string" && params.window_id !== event.windowId)
192
+ return false;
193
+ if (params.after_seq !== undefined && event.seq <= params.after_seq)
194
+ return false;
195
+ if (params.before_seq !== undefined && event.seq >= params.before_seq)
196
+ return false;
197
+ if (params.sinceMs === undefined && params.untilMs === undefined)
198
+ return true;
199
+ if (event.createdAt === undefined)
200
+ return false;
201
+ const at = Date.parse(event.createdAt);
202
+ return !Number.isNaN(at) && (params.sinceMs === undefined || at >= params.sinceMs) && (params.untilMs === undefined || at < params.untilMs);
203
+ }
204
+ /** Without roles or query a call shows the conversation; either one shows the requested events. */
205
+ export function filteredItems(projection, params, conversation) {
206
+ let items = allItems(projection).filter((item) => inSelection(item, params));
207
+ if (params.roles)
208
+ items = items.filter((item) => params.roles.includes(item.role));
209
+ if (!params.roles && conversation)
210
+ items = items.filter((item) => (item.role === "user" || item.role === "assistant") && eventDocument(item) !== "");
211
+ return items.sort((a, b) => a.seq - b.seq);
212
+ }
@@ -0,0 +1,63 @@
1
+ /** Stable-anchor paging, folding and literal matching. The operation supplies the full-response budget check. */
2
+ import { Type, type Static } from "typebox";
3
+ import { type Outcome } from "../tools/result.js";
4
+ import { type HistoryFilter, type HistoryProjection } from "./history.js";
5
+ /** Which end of one selection `limit` is taken from; page items always come back ascending. */
6
+ export type HistoryOrder = "newest" | "oldest";
7
+ /**
8
+ * What one list call selects. `before_seq`/`after_seq` choose a seq range and `since`/`until` a time
9
+ * range; `from` chooses the end `limit` counts from; a `query` keeps only matching events, across
10
+ * every role, with no folded rows.
11
+ */
12
+ export type HistorySelection = HistoryFilter & {
13
+ from?: HistoryOrder;
14
+ limit?: number;
15
+ query?: string | string[];
16
+ since?: string;
17
+ until?: string;
18
+ max_chars_per_item?: number;
19
+ };
20
+ /** The params to merge into the previous call to continue toward older events. */
21
+ export declare const HistoryOlderSchema: Type.TObject<{
22
+ before_seq: Type.TInteger;
23
+ }>;
24
+ /** The params to merge into the previous call to continue toward newer events. */
25
+ export declare const HistoryNewerSchema: Type.TObject<{
26
+ after_seq: Type.TInteger;
27
+ from: Type.TLiteral<"oldest">;
28
+ }>;
29
+ export declare const HistoryPageSchema: Type.TObject<{
30
+ items: Type.TArray<Type.TUnion<[Type.TObject<{
31
+ content: Type.TString;
32
+ truncated: Type.TBoolean;
33
+ offset_chars: Type.TOptional<Type.TInteger>;
34
+ tool: Type.TOptional<Type.TString>;
35
+ tool_status: Type.TOptional<Type.TUnion<[Type.TLiteral<"ok">, Type.TLiteral<"error">, Type.TLiteral<"unfinished">]>>;
36
+ output_truncated: Type.TOptional<Type.TLiteral<true>>;
37
+ full_output_path: Type.TOptional<Type.TString>;
38
+ seq: Type.TInteger;
39
+ window_id: Type.TString;
40
+ role: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"assistant">, Type.TLiteral<"tool">, Type.TLiteral<"context">]>;
41
+ created_at: Type.TUnion<[Type.TString, Type.TNull]>;
42
+ }>, Type.TObject<{
43
+ folded: Type.TLiteral<true>;
44
+ first_seq: Type.TInteger;
45
+ last_seq: Type.TInteger;
46
+ count: Type.TInteger;
47
+ tools: Type.TRecord<"^.*$", Type.TInteger>;
48
+ }>]>>;
49
+ page_older: Type.TUnion<[Type.TObject<{
50
+ before_seq: Type.TInteger;
51
+ }>, Type.TNull]>;
52
+ page_newer: Type.TUnion<[Type.TObject<{
53
+ after_seq: Type.TInteger;
54
+ from: Type.TLiteral<"oldest">;
55
+ }>, Type.TNull]>;
56
+ }>;
57
+ /** One whole page payload, before it becomes an outcome. */
58
+ export type HistoryPage = Static<typeof HistoryPageSchema>;
59
+ /**
60
+ * Resolve the time bounds once, then filter and fold against the same [sinceMs, untilMs) window.
61
+ * Grow the page in selection order; shorten the first preview only when no full row fits.
62
+ */
63
+ export declare function selectPage(projection: HistoryProjection, params: HistorySelection, fits: (page: HistoryPage) => boolean, maxChars: number): Outcome<HistoryPage>;
@@ -0,0 +1,201 @@
1
+ /** Stable-anchor paging, folding and literal matching. The operation supplies the full-response budget check. */
2
+ import { Type } from "typebox";
3
+ import { failure, success } from "../tools/result.js";
4
+ import { earliestMatchOffsetChars, prefixFit } from "../tools/output.js";
5
+ import { InvalidQueryError, searchQueries } from "../tools/schema.js";
6
+ import { allItems, eventDocument, filteredItems, inSelection, visibleItem, HistoryFoldedRowSchema, HistoryPageItemSchema, MAX_FOLD_TOOL_NAMES, MAX_FOLD_TOOL_NAME_CHARS } from "./history.js";
7
+ /** ISO 8601 date or date-time; the offset is optional (group 1) and a missing one is read as UTC. */
8
+ const ISO_8601 = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[+-]\d{2}:?\d{2})?$/;
9
+ /** Epoch ms for one ISO 8601 value, with a missing offset read as UTC. */
10
+ function isoUtcMs(value) {
11
+ const match = ISO_8601.exec(value);
12
+ if (match === null)
13
+ return undefined;
14
+ const at = Date.parse(match[1] === undefined ? `${value}Z` : value);
15
+ return Number.isNaN(at) ? undefined : at;
16
+ }
17
+ /** Epoch ms for one optional time param, or a refusal naming it. */
18
+ function timeBound(name, value) {
19
+ if (value === undefined)
20
+ return success(undefined);
21
+ const at = isoUtcMs(value);
22
+ return at === undefined ? failure("invalid_time", `${name} is not an ISO 8601 timestamp: "${value}"`) : success(at);
23
+ }
24
+ /** Parse `since`/`until`; a malformed or inverted pair refuses here. */
25
+ function resolveTimeBounds(params) {
26
+ const since = timeBound("since", params.since);
27
+ if (!since.ok)
28
+ return since;
29
+ const until = timeBound("until", params.until);
30
+ if (!until.ok)
31
+ return until;
32
+ if (since.data !== undefined && until.data !== undefined && since.data >= until.data) {
33
+ return failure("invalid_time", "since must be earlier than until");
34
+ }
35
+ return success({ ...(since.data === undefined ? {} : { sinceMs: since.data }), ...(until.data === undefined ? {} : { untilMs: until.data }) });
36
+ }
37
+ /** The params to merge into the previous call to continue toward older events. */
38
+ export const HistoryOlderSchema = Type.Object({
39
+ before_seq: Type.Integer({ minimum: 1 }),
40
+ }, { additionalProperties: false });
41
+ /** The params to merge into the previous call to continue toward newer events. */
42
+ export const HistoryNewerSchema = Type.Object({
43
+ after_seq: Type.Integer({ minimum: 1 }),
44
+ from: Type.Literal("oldest"),
45
+ }, { additionalProperties: false });
46
+ export const HistoryPageSchema = Type.Object({
47
+ items: Type.Array(Type.Union([HistoryPageItemSchema, HistoryFoldedRowSchema])),
48
+ page_older: Type.Union([HistoryOlderSchema, Type.Null()], { description: "Params for the next page; null at the end." }),
49
+ page_newer: Type.Union([HistoryNewerSchema, Type.Null()], { description: "Params for the next page; null at the end." }),
50
+ }, { additionalProperties: false });
51
+ /** Shorten preview text first; omit an oversized tool name rather than invent a partial name. */
52
+ function truncateHistoryItem(item, fits) {
53
+ if (fits(item))
54
+ return item;
55
+ const shrinkContent = (base) => ({
56
+ ...base,
57
+ truncated: true,
58
+ content: prefixFit(base.content, (candidate) => fits({ ...base, truncated: true, content: candidate })),
59
+ });
60
+ const withContent = shrinkContent(item);
61
+ if (fits(withContent))
62
+ return withContent;
63
+ if (item.tool === undefined)
64
+ return withContent;
65
+ const { tool: _dropped, ...withoutName } = item;
66
+ return fits(withoutName) ? withoutName : shrinkContent(withoutName);
67
+ }
68
+ function isFoldableEvent(event) {
69
+ return event.role === "tool" || event.role === "context";
70
+ }
71
+ /** Only a call without roles or query folds tool/context runs. */
72
+ function foldsRuns(params) {
73
+ return !params.roles && params.query === undefined;
74
+ }
75
+ /** Folded counts stay exact even when some distinct tool names must be omitted. */
76
+ function foldedRuns(events) {
77
+ if (events.length === 0)
78
+ return [];
79
+ const sorted = [...events].sort((a, b) => a.seq - b.seq);
80
+ const counts = new Map();
81
+ for (const event of sorted) {
82
+ if (event.role !== "tool")
83
+ continue;
84
+ const name = event.execution?.name ?? "unknown";
85
+ counts.set(name, (counts.get(name) ?? 0) + 1);
86
+ }
87
+ const entries = [...counts].filter(([name]) => name.length <= MAX_FOLD_TOOL_NAME_CHARS).slice(0, MAX_FOLD_TOOL_NAMES);
88
+ // fromEntries preserves __proto__ as an ordinary key without mutating the prototype.
89
+ const tools = Object.fromEntries(entries);
90
+ return [{ folded: true, first_seq: sorted[0].seq, last_seq: sorted.at(-1).seq, count: sorted.length, tools }];
91
+ }
92
+ /** A cursor exists only when the same selection still has a visible event past that end. */
93
+ function pageCursors(vis, selected, beforeSeq, afterSeq) {
94
+ if (selected.length === 0)
95
+ return { page_older: null, page_newer: null };
96
+ const lower = afterSeq ?? 0;
97
+ const upper = beforeSeq ?? Number.POSITIVE_INFINITY;
98
+ // Selected events are in seq order.
99
+ const first = selected[0].seq;
100
+ const last = selected.at(-1).seq;
101
+ return {
102
+ page_older: vis.some((event) => event.seq > lower && event.seq < first) ? { before_seq: first } : null,
103
+ page_newer: vis.some((event) => event.seq > last && event.seq < upper) ? { after_seq: last, from: "oldest" } : null,
104
+ };
105
+ }
106
+ function foldRows(projection, params, selected, cursors) {
107
+ if (selected.length === 0) {
108
+ // Even a range with no conversation can contain tool/context events.
109
+ return foldedRuns(allItems(projection).filter((event) => inSelection(event, params) && isFoldableEvent(event)));
110
+ }
111
+ const windowEvents = allItems(projection).filter((event) => inSelection(event, params)).sort((a, b) => a.seq - b.seq);
112
+ const folded = [];
113
+ const firstSeq = selected[0].seq;
114
+ const lastSeq = selected.at(-1).seq;
115
+ if (cursors.page_older === null)
116
+ folded.push(...foldedRuns(windowEvents.filter((event) => event.seq < firstSeq && isFoldableEvent(event))));
117
+ // pageData already ordered selected by seq.
118
+ for (let i = 0; i + 1 < selected.length; i++) {
119
+ const left = selected[i].seq;
120
+ const right = selected[i + 1].seq;
121
+ folded.push(...foldedRuns(windowEvents.filter((event) => event.seq > left && event.seq < right && isFoldableEvent(event))));
122
+ }
123
+ if (cursors.page_newer === null)
124
+ folded.push(...foldedRuns(windowEvents.filter((event) => event.seq > lastSeq && isFoldableEvent(event))));
125
+ return folded;
126
+ }
127
+ function pageData(projection, params, vis, selected, maxChars, folds) {
128
+ const orderedSelected = [...selected].sort((a, b) => a.event.seq - b.event.seq);
129
+ const selectedEvents = orderedSelected.map((candidate) => candidate.event);
130
+ const cursors = pageCursors(vis, selectedEvents, params.before_seq, params.after_seq);
131
+ const visible = orderedSelected.map((candidate) => candidate.preview ?? visibleItem(candidate.event, maxChars, candidate.matchOffset));
132
+ let rows = visible;
133
+ if (folds) {
134
+ const folded = foldRows(projection, params, selectedEvents, cursors);
135
+ rows = [...visible, ...folded].sort((a, b) => ("folded" in a ? a.first_seq : a.seq) - ("folded" in b ? b.first_seq : b.seq));
136
+ }
137
+ return { items: rows, ...cursors };
138
+ }
139
+ /** Filter, then keep only literal matches when a query is present. Query shape errors refuse here. */
140
+ function selectionCandidates(projection, params) {
141
+ let queries;
142
+ if (params.query !== undefined) {
143
+ try {
144
+ queries = searchQueries(params.query);
145
+ }
146
+ catch (error) {
147
+ if (error instanceof InvalidQueryError)
148
+ return failure("invalid_query", error.message);
149
+ throw error;
150
+ }
151
+ }
152
+ const events = filteredItems(projection, params, queries === undefined);
153
+ if (queries === undefined)
154
+ return success(events.map((event) => ({ event })));
155
+ const needles = queries;
156
+ return success(events
157
+ .map((event) => ({ event, matchOffset: earliestMatchOffsetChars(eventDocument(event), needles) }))
158
+ .filter((candidate) => candidate.matchOffset >= 0));
159
+ }
160
+ /**
161
+ * Take the limit from the end `from` names, starting there so a budget for one row keeps the most
162
+ * important row. The selection is already filtered to its range; `from` never states a direction.
163
+ */
164
+ function orderedCandidates(vis, params, limit) {
165
+ const ascending = [...vis].sort((a, b) => a.event.seq - b.event.seq);
166
+ const selected = params.from === "oldest" ? ascending.slice(0, limit) : ascending.slice(-limit);
167
+ return params.from === "oldest" ? selected : selected.reverse();
168
+ }
169
+ /**
170
+ * Resolve the time bounds once, then filter and fold against the same [sinceMs, untilMs) window.
171
+ * Grow the page in selection order; shorten the first preview only when no full row fits.
172
+ */
173
+ export function selectPage(projection, params, fits, maxChars) {
174
+ const bounds = resolveTimeBounds(params);
175
+ if (!bounds.ok)
176
+ return bounds;
177
+ const scoped = { ...params, ...bounds.data };
178
+ const candidates = selectionCandidates(projection, scoped);
179
+ if (!candidates.ok)
180
+ return candidates;
181
+ const vis = candidates.data;
182
+ const limit = scoped.limit ?? 20;
183
+ const folds = foldsRuns(scoped);
184
+ const ordered = orderedCandidates(vis, scoped, limit);
185
+ const allVisible = vis.map((candidate) => candidate.event).sort((a, b) => a.seq - b.seq);
186
+ const kept = [];
187
+ for (const candidate of ordered) {
188
+ if (fits(pageData(projection, scoped, allVisible, [...kept, candidate], maxChars, folds))) {
189
+ kept.push(candidate);
190
+ continue;
191
+ }
192
+ if (kept.length === 0)
193
+ kept.push({ ...candidate, preview: truncateHistoryItem(visibleItem(candidate.event, maxChars, candidate.matchOffset), (preview) => fits(pageData(projection, scoped, allVisible, [{ ...candidate, preview }], maxChars, folds))) });
194
+ break;
195
+ }
196
+ const page = pageData(projection, scoped, allVisible, kept, maxChars, folds);
197
+ if (!fits(page)) {
198
+ return failure("page_too_large", `${page.items.length} history rows and their fold summary do not fit one response even at their smallest; narrow with before_seq/after_seq or since/until, or read one seq`);
199
+ }
200
+ return success(page);
201
+ }
@@ -0,0 +1 @@
1
+ export { default, createNotesoup } from "./pi/extension.js";
@@ -0,0 +1 @@
1
+ export { default, createNotesoup } from "./pi/extension.js";
@@ -0,0 +1,31 @@
1
+ import type { NotesIdentity } from "./identity.js";
2
+ import { type Scope } from "./paths.js";
3
+ export type NoteAddress = {
4
+ scope: Scope;
5
+ path: string;
6
+ who?: string;
7
+ };
8
+ export declare const ADDRESS_FORMS = "use <path> with no @ for this session, or @project/, @human/, @self/, or @model/ followed by a path";
9
+ export declare function assertVirtualPath(value: unknown): string;
10
+ /**
11
+ * Minimal glob over virtual note paths: `*` matches any run within a segment (never
12
+ * `/`), `**` matches any run across segments (a leading double-star followed by a
13
+ * slash also matches zero segments, so it covers the root too), `?` matches exactly
14
+ * one non-`/` character. Everything else is literal and the match is anchored to the
15
+ * whole path.
16
+ */
17
+ export declare function globToRegExp(pattern: string): RegExp;
18
+ /** Glob patterns are not virtual paths (`*` is legal), so they get their own guard. */
19
+ export declare function assertGlobPattern(value: unknown): string | undefined;
20
+ /**
21
+ * Decode one public note address into its physical home and virtual path. @self and @model
22
+ * are relative; explicit agents/models addresses always name a canonical slug.
23
+ */
24
+ export declare function assertAddress(value: unknown): NoteAddress;
25
+ /** Render a virtual path in its one unambiguous address form, used to match patterns. */
26
+ export declare function canonicalAddressFor(identity: NotesIdentity, scope: Scope, path: string, who?: string): string;
27
+ /**
28
+ * Render the address a caller sees. The current agent and model homes read as @self/ and
29
+ * @model/ so ordinary sessions are not taught explicit ids; only other homes (dream) name one.
30
+ */
31
+ export declare function addressFor(identity: NotesIdentity, scope: Scope, path: string, who?: string): string;