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,250 @@
1
+ import type { NotesIdentity } from "../notes/identity.js";
2
+ import { Type, type Static } from "typebox";
3
+ import { type NoteChange } from "../notes/index.js";
4
+ import { type Outcome } from "./result.js";
5
+ /** One unrecognized entry, and the verbatim extras together, are bounded so `extra` cannot outgrow the read. */
6
+ export declare const MAX_METADATA_ENTRY_BYTES = 1024;
7
+ /** An extra value that cannot be carried is named in place, never silently dropped. */
8
+ export declare const TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
9
+ export declare const NoteMetadataSchema: Type.TObject<{
10
+ origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
11
+ created_at: Type.TString;
12
+ updated_at: Type.TString;
13
+ crumpled_at: Type.TOptional<Type.TString>;
14
+ project: Type.TOptional<Type.TString>;
15
+ extra: Type.TRecord<"^.*$", Type.TUnknown>;
16
+ }>;
17
+ export type NoteMetadata = Static<typeof NoteMetadataSchema>;
18
+ export declare const NotesWriteDataSchema: Type.TObject<{
19
+ address: Type.TString;
20
+ project_key: Type.TOptional<Type.TString>;
21
+ outcome: Type.TUnion<[Type.TLiteral<"created">, Type.TLiteral<"overwrote">, Type.TLiteral<"uncrumpled">]>;
22
+ }>;
23
+ export type NotesWriteData = Static<typeof NotesWriteDataSchema>;
24
+ export declare const NotesUpdateDataSchema: Type.TObject<{
25
+ address: Type.TString;
26
+ project_key: Type.TOptional<Type.TString>;
27
+ change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
28
+ diff: Type.TString;
29
+ rename_from: Type.TOptional<Type.TString>;
30
+ }>;
31
+ export type NotesUpdateData = Static<typeof NotesUpdateDataSchema>;
32
+ export declare const NotesReadDataSchema: Type.TObject<{
33
+ text: Type.TString;
34
+ total_chars: Type.TInteger;
35
+ next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
36
+ address: Type.TString;
37
+ project_key: Type.TOptional<Type.TString>;
38
+ metadata: Type.TObject<{
39
+ origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
40
+ created_at: Type.TString;
41
+ updated_at: Type.TString;
42
+ crumpled_at: Type.TOptional<Type.TString>;
43
+ project: Type.TOptional<Type.TString>;
44
+ extra: Type.TRecord<"^.*$", Type.TUnknown>;
45
+ }>;
46
+ }>;
47
+ export type NotesReadData = Static<typeof NotesReadDataSchema>;
48
+ export declare const NotesListDataSchema: Type.TObject<{
49
+ more: Type.TInteger;
50
+ homes_unavailable: Type.TArray<Type.TString>;
51
+ files: Type.TArray<Type.TObject<{
52
+ address: Type.TString;
53
+ project_key: Type.TOptional<Type.TString>;
54
+ updated_at: Type.TString;
55
+ crumpled_at: Type.TOptional<Type.TString>;
56
+ }>>;
57
+ }>;
58
+ export type NotesListData = Static<typeof NotesListDataSchema>;
59
+ export declare const NotesSearchDataSchema: Type.TObject<{
60
+ more: Type.TInteger;
61
+ homes_unavailable: Type.TArray<Type.TString>;
62
+ files: Type.TArray<Type.TObject<{
63
+ matches: Type.TArray<Type.TObject<{
64
+ line: Type.TInteger;
65
+ text: Type.TString;
66
+ offset_chars: Type.TInteger;
67
+ }>>;
68
+ address: Type.TString;
69
+ project_key: Type.TOptional<Type.TString>;
70
+ updated_at: Type.TString;
71
+ crumpled_at: Type.TOptional<Type.TString>;
72
+ }>>;
73
+ }>;
74
+ export type NotesSearchData = Static<typeof NotesSearchDataSchema>;
75
+ export declare const notesWriteParameters: Type.TObject<{
76
+ address: Type.TString;
77
+ content: Type.TString;
78
+ origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
79
+ }>;
80
+ export declare const notesWrite: {
81
+ readonly name: "notes_write";
82
+ readonly label: "Notes write";
83
+ readonly description: "Create or replace a note's body, keeping metadata; uncrumples a crumpled note. Name it for what it holds and when to use it. Store what git and history can't recover. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
84
+ readonly parameters: Type.TObject<{
85
+ address: Type.TString;
86
+ content: Type.TString;
87
+ origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
88
+ }>;
89
+ readonly outputSchema: Type.TUnion<[Type.TObject<{
90
+ address: Type.TString;
91
+ project_key: Type.TOptional<Type.TString>;
92
+ outcome: Type.TUnion<[Type.TLiteral<"created">, Type.TLiteral<"overwrote">, Type.TLiteral<"uncrumpled">]>;
93
+ }>, Type.TObject<{
94
+ error: Type.TString;
95
+ code: Type.TString;
96
+ }>]>;
97
+ readonly executionMode: "sequential";
98
+ readonly execute: (params: Static<typeof notesWriteParameters>, identity: NotesIdentity) => Promise<Outcome<NotesWriteData>>;
99
+ readonly render: (result: Outcome<NotesWriteData>) => string;
100
+ };
101
+ export declare const notesUpdateParameters: Type.TObject<{
102
+ address: Type.TString;
103
+ edits: Type.TOptional<Type.TArray<Type.TObject<{
104
+ oldText: Type.TString;
105
+ newText: Type.TString;
106
+ }>>>;
107
+ origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
108
+ crumpled: Type.TOptional<Type.TBoolean>;
109
+ replace_all: Type.TOptional<Type.TBoolean>;
110
+ rename_to: Type.TOptional<Type.TString>;
111
+ }>;
112
+ declare function renderUpdate(result: Outcome<NotesUpdateData>): string;
113
+ /** A shortened diff still says so in the receipt's own text, on both surfaces. */
114
+ export declare const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
115
+ export declare const notesUpdate: {
116
+ readonly name: "notes_update";
117
+ readonly label: "Notes update";
118
+ readonly description: "Edit a note's body, change its origin or crumpled state, or move it. Each `oldText` must match exactly once unless `replace_all` is true; frontmatter can't be edited. Returns a diff. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
119
+ readonly parameters: Type.TObject<{
120
+ address: Type.TString;
121
+ edits: Type.TOptional<Type.TArray<Type.TObject<{
122
+ oldText: Type.TString;
123
+ newText: Type.TString;
124
+ }>>>;
125
+ origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
126
+ crumpled: Type.TOptional<Type.TBoolean>;
127
+ replace_all: Type.TOptional<Type.TBoolean>;
128
+ rename_to: Type.TOptional<Type.TString>;
129
+ }>;
130
+ readonly outputSchema: Type.TUnion<[Type.TObject<{
131
+ address: Type.TString;
132
+ project_key: Type.TOptional<Type.TString>;
133
+ change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
134
+ diff: Type.TString;
135
+ rename_from: Type.TOptional<Type.TString>;
136
+ }>, Type.TObject<{
137
+ error: Type.TString;
138
+ code: Type.TString;
139
+ }>]>;
140
+ readonly executionMode: "sequential";
141
+ readonly execute: (params: Static<typeof notesUpdateParameters>, identity: NotesIdentity, renderDiff: (change: NoteChange) => string) => Promise<Outcome<NotesUpdateData>>;
142
+ readonly render: typeof renderUpdate;
143
+ };
144
+ export declare const notesReadParameters: Type.TObject<{
145
+ offset_chars: Type.TOptional<Type.TInteger>;
146
+ max_chars: Type.TOptional<Type.TInteger>;
147
+ address: Type.TString;
148
+ }>;
149
+ export declare const notesRead: {
150
+ readonly name: "notes_read";
151
+ readonly label: "Notes read";
152
+ readonly description: "Read a note's metadata and body, without frontmatter. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
153
+ readonly parameters: Type.TObject<{
154
+ offset_chars: Type.TOptional<Type.TInteger>;
155
+ max_chars: Type.TOptional<Type.TInteger>;
156
+ address: Type.TString;
157
+ }>;
158
+ readonly outputSchema: Type.TUnion<[Type.TObject<{
159
+ text: Type.TString;
160
+ total_chars: Type.TInteger;
161
+ next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
162
+ address: Type.TString;
163
+ project_key: Type.TOptional<Type.TString>;
164
+ metadata: Type.TObject<{
165
+ origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
166
+ created_at: Type.TString;
167
+ updated_at: Type.TString;
168
+ crumpled_at: Type.TOptional<Type.TString>;
169
+ project: Type.TOptional<Type.TString>;
170
+ extra: Type.TRecord<"^.*$", Type.TUnknown>;
171
+ }>;
172
+ }>, Type.TObject<{
173
+ error: Type.TString;
174
+ code: Type.TString;
175
+ }>]>;
176
+ readonly execute: (params: Static<typeof notesReadParameters>, identity: NotesIdentity) => Promise<Outcome<NotesReadData>>;
177
+ readonly render: (result: Outcome<NotesReadData>) => string;
178
+ };
179
+ export declare const notesListParameters: Type.TObject<{
180
+ glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
181
+ limit: Type.TOptional<Type.TInteger>;
182
+ crumpled: Type.TOptional<Type.TBoolean>;
183
+ }>;
184
+ export declare const notesList: {
185
+ readonly name: "notes_list";
186
+ readonly label: "Notes list";
187
+ readonly description: "List notes in this session and the four @ homes, newest first. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
188
+ readonly parameters: Type.TObject<{
189
+ glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
190
+ limit: Type.TOptional<Type.TInteger>;
191
+ crumpled: Type.TOptional<Type.TBoolean>;
192
+ }>;
193
+ readonly outputSchema: Type.TUnion<[Type.TObject<{
194
+ more: Type.TInteger;
195
+ homes_unavailable: Type.TArray<Type.TString>;
196
+ files: Type.TArray<Type.TObject<{
197
+ address: Type.TString;
198
+ project_key: Type.TOptional<Type.TString>;
199
+ updated_at: Type.TString;
200
+ crumpled_at: Type.TOptional<Type.TString>;
201
+ }>>;
202
+ }>, Type.TObject<{
203
+ error: Type.TString;
204
+ code: Type.TString;
205
+ }>]>;
206
+ readonly execute: (params: Static<typeof notesListParameters>, identity: NotesIdentity) => Promise<Outcome<NotesListData>>;
207
+ readonly render: (result: Outcome<NotesListData>) => string;
208
+ };
209
+ export declare const notesSearchParameters: Type.TObject<{
210
+ query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
211
+ glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
212
+ limit: Type.TOptional<Type.TInteger>;
213
+ max_matches_per_file: Type.TOptional<Type.TInteger>;
214
+ crumpled: Type.TOptional<Type.TBoolean>;
215
+ }>;
216
+ /** A shortened match line still ends with a marker, so its own text says it was cut. */
217
+ export declare const MATCH_SHORTENED_MARKER = " [truncated]";
218
+ export declare const notesSearch: {
219
+ readonly name: "notes_search";
220
+ readonly label: "Notes search";
221
+ readonly description: "Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
222
+ readonly parameters: Type.TObject<{
223
+ query: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
224
+ glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
225
+ limit: Type.TOptional<Type.TInteger>;
226
+ max_matches_per_file: Type.TOptional<Type.TInteger>;
227
+ crumpled: Type.TOptional<Type.TBoolean>;
228
+ }>;
229
+ readonly outputSchema: Type.TUnion<[Type.TObject<{
230
+ more: Type.TInteger;
231
+ homes_unavailable: Type.TArray<Type.TString>;
232
+ files: Type.TArray<Type.TObject<{
233
+ matches: Type.TArray<Type.TObject<{
234
+ line: Type.TInteger;
235
+ text: Type.TString;
236
+ offset_chars: Type.TInteger;
237
+ }>>;
238
+ address: Type.TString;
239
+ project_key: Type.TOptional<Type.TString>;
240
+ updated_at: Type.TString;
241
+ crumpled_at: Type.TOptional<Type.TString>;
242
+ }>>;
243
+ }>, Type.TObject<{
244
+ error: Type.TString;
245
+ code: Type.TString;
246
+ }>]>;
247
+ readonly execute: (params: Static<typeof notesSearchParameters>, identity: NotesIdentity) => Promise<Outcome<NotesSearchData>>;
248
+ readonly render: (result: Outcome<NotesSearchData>) => string;
249
+ };
250
+ export {};
@@ -0,0 +1,360 @@
1
+ import { Type } from "typebox";
2
+ import { localIso } from "../notes/frontmatter.js";
3
+ import { isFilesystemError } from "../notes/fs-error.js";
4
+ import { createNotesStore, NoteError, noteIdentity } from "../notes/index.js";
5
+ import { prefixFit } from "./output.js";
6
+ import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, success, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
7
+ import { nullableString, InvalidQueryError, searchQueries, searchQuery } from "./schema.js";
8
+ const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")];
9
+ const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
10
+ description: "(optional, default self) Who wrote it: user, self, or external.",
11
+ }));
12
+ const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
13
+ const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
14
+ const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
15
+ const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses.");
16
+ const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable homes. Not file paths: never pass them to file tools.";
17
+ /** The one receipt field a caller cannot derive from the address itself. */
18
+ function projectKeyField(scope, projectKey) {
19
+ return scope === "project" ? { project_key: projectKey } : {};
20
+ }
21
+ /**
22
+ * Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
23
+ * Convert expected refusals; unexpected errors propagate unchanged.
24
+ */
25
+ function failureOf(error) {
26
+ if (error instanceof NoteError)
27
+ return failure(error.code, error.message);
28
+ // Address, glob, and query guards raise declared types; nothing else is converted.
29
+ if (error instanceof InvalidQueryError)
30
+ return failure("invalid_query", error.message);
31
+ if (isFilesystemError(error))
32
+ return failure("io_error", "notes operation failed");
33
+ throw error;
34
+ }
35
+ function byRecent(a, b) {
36
+ return b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address);
37
+ }
38
+ /** Metadata keys this layer normalizes; everything else is exposed verbatim under `extra`. */
39
+ const NORMALIZED_META_KEYS = new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project"]);
40
+ /** One unrecognized entry, and the verbatim extras together, are bounded so `extra` cannot outgrow the read. */
41
+ export const MAX_METADATA_ENTRY_BYTES = 1024;
42
+ const MAX_METADATA_VERBATIM_BYTES = 2048;
43
+ /** An extra value that cannot be carried is named in place, never silently dropped. */
44
+ export const TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
45
+ /** Include the key: hand-written frontmatter can have arbitrarily long keys. */
46
+ function extraEntryBytes(key, value) {
47
+ return structuredBytes(key) + 1 + structuredBytes(value);
48
+ }
49
+ export const NoteMetadataSchema = Type.Object({
50
+ origin: Type.Union([...ORIGIN_VALUES]),
51
+ created_at: Type.String(),
52
+ updated_at: Type.String(),
53
+ crumpled_at: Type.Optional(Type.String()),
54
+ project: Type.Optional(Type.String()),
55
+ extra: Type.Record(Type.String(), Type.Unknown()),
56
+ }, { additionalProperties: false });
57
+ /** Normalize known metadata and bound extras, naming an oversized value instead of hiding it. */
58
+ function noteMetadata(meta) {
59
+ const extra = {};
60
+ let verbatimBytes = 0;
61
+ const put = (key, value) => {
62
+ // defineProperty keeps a hand-written `__proto__` key as ordinary data.
63
+ Object.defineProperty(extra, key, { value, enumerable: true, writable: true, configurable: true });
64
+ };
65
+ for (const [key, value] of Object.entries(meta)) {
66
+ if (NORMALIZED_META_KEYS.has(key) || value === undefined)
67
+ continue;
68
+ // A key too large to carry cannot be named at all; an oversized value is named in place.
69
+ if (structuredBytes(key) > MAX_METADATA_ENTRY_BYTES)
70
+ continue;
71
+ const entryBytes = extraEntryBytes(key, value);
72
+ if (entryBytes > MAX_METADATA_ENTRY_BYTES || verbatimBytes + entryBytes > MAX_METADATA_VERBATIM_BYTES) {
73
+ put(key, TOO_LARGE_EXTRA_VALUE);
74
+ continue;
75
+ }
76
+ verbatimBytes += entryBytes;
77
+ put(key, value);
78
+ }
79
+ return {
80
+ origin: meta.origin,
81
+ created_at: localIso(meta.createdAt),
82
+ updated_at: localIso(meta.updatedAt),
83
+ ...(typeof meta.crumpledAt === "string" ? { crumpled_at: meta.crumpledAt } : {}),
84
+ ...(typeof meta.project === "string" ? { project: meta.project } : {}),
85
+ extra,
86
+ };
87
+ }
88
+ function renderMetadata(metadata) {
89
+ const fields = [
90
+ `origin ${metadata.origin}`,
91
+ `created ${metadata.created_at}`,
92
+ `updated ${metadata.updated_at}`,
93
+ ...(metadata.crumpled_at === undefined ? [] : [`crumpled ${metadata.crumpled_at}`]),
94
+ ...(metadata.project === undefined ? [] : [`project ${metadata.project}`]),
95
+ ];
96
+ const extra = Object.keys(metadata.extra);
97
+ if (extra.length > 0)
98
+ fields.push(`extra ${JSON.stringify(metadata.extra)}`);
99
+ return fields.join(" | ");
100
+ }
101
+ /** Address plus project key in one line; the project key never replaces the address. */
102
+ function renderIdentity(identity) {
103
+ return identity.project_key === undefined ? identity.address : `${identity.address} (project ${identity.project_key})`;
104
+ }
105
+ const ListedFileSchema = Type.Object({
106
+ address: Type.String(),
107
+ project_key: Type.Optional(Type.String()),
108
+ updated_at: Type.String(),
109
+ crumpled_at: Type.Optional(Type.String()),
110
+ }, { additionalProperties: false });
111
+ const MatchSchema = Type.Object({
112
+ line: Type.Integer(),
113
+ text: Type.String(),
114
+ offset_chars: Type.Integer(),
115
+ }, { additionalProperties: false });
116
+ const SearchedFileSchema = Type.Object({
117
+ ...ListedFileSchema.properties,
118
+ matches: Type.Array(MatchSchema),
119
+ }, { additionalProperties: false });
120
+ const SnapshotSchema = {
121
+ more: Type.Integer({ description: "How many more were left out." }),
122
+ homes_unavailable: Type.Array(Type.String()),
123
+ };
124
+ export const NotesWriteDataSchema = Type.Object({
125
+ address: Type.String(),
126
+ project_key: Type.Optional(Type.String()),
127
+ outcome: Type.Union([Type.Literal("created"), Type.Literal("overwrote"), Type.Literal("uncrumpled")]),
128
+ }, { additionalProperties: false });
129
+ export const NotesUpdateDataSchema = Type.Object({
130
+ address: Type.String(),
131
+ project_key: Type.Optional(Type.String()),
132
+ change_kind: Type.Union([Type.Literal("none"), Type.Literal("body"), Type.Literal("metadata"), Type.Literal("moved")]),
133
+ diff: Type.String(),
134
+ rename_from: Type.Optional(Type.String()),
135
+ }, { additionalProperties: false });
136
+ export const NotesReadDataSchema = Type.Object({
137
+ address: Type.String(),
138
+ project_key: Type.Optional(Type.String()),
139
+ metadata: NoteMetadataSchema,
140
+ ...TextWindowSchema.properties,
141
+ }, { additionalProperties: false });
142
+ export const NotesListDataSchema = Type.Object({
143
+ files: Type.Array(ListedFileSchema),
144
+ ...SnapshotSchema,
145
+ }, { additionalProperties: false });
146
+ export const NotesSearchDataSchema = Type.Object({
147
+ files: Type.Array(SearchedFileSchema),
148
+ ...SnapshotSchema,
149
+ }, { additionalProperties: false });
150
+ /** Keep identities intact. Only search previews may shrink to make the first row fit. */
151
+ function snapshot(rows, limit, status, renderData, shrink) {
152
+ const files = [];
153
+ const data = (selected) => ({ files: selected, more: rows.length - selected.length, homes_unavailable: status.homesUnavailable });
154
+ const render = (outcome) => renderOutcome(outcome, renderData);
155
+ const fits = (item) => fitsResult(success(data([...files, item])), render);
156
+ for (const item of rows.slice(0, limit)) {
157
+ if (fits(item)) {
158
+ files.push(item);
159
+ continue;
160
+ }
161
+ if (files.length === 0 && shrink) {
162
+ const reduced = shrink(item, fits);
163
+ if (fits(reduced))
164
+ files.push(reduced);
165
+ }
166
+ if (files.length === 0)
167
+ return failure("output_too_large", "The first matching note cannot fit in a response without losing its identity.");
168
+ break;
169
+ }
170
+ const outcome = success(data(files));
171
+ return fitsResult(outcome, render) ? outcome : failure("output_too_large", "The notes snapshot metadata exceeds the response budget.");
172
+ }
173
+ function listedFile(row, identity) {
174
+ return { address: row.address, ...projectKeyField(row.scope, identity.projectKey), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
175
+ }
176
+ export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN }, { additionalProperties: false });
177
+ function renderWriteData(data) {
178
+ return `${data.outcome} ${renderIdentity(data)}`;
179
+ }
180
+ export const notesWrite = {
181
+ name: "notes_write", label: "Notes write",
182
+ description: `Create or replace a note's body, keeping metadata; uncrumples a crumpled note. Name it for what it holds and when to use it. Store what git and history can't recover. ${ADDRESS_DESCRIPTION}`,
183
+ parameters: notesWriteParameters, outputSchema: resultSchema(NotesWriteDataSchema), executionMode: "sequential",
184
+ async execute(params, identity) {
185
+ try {
186
+ const { outcome } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin ?? "self" });
187
+ return success({ ...noteIdentity(identity, params.address), outcome });
188
+ }
189
+ catch (error) {
190
+ return failureOf(error);
191
+ }
192
+ },
193
+ render: (result) => renderOutcome(result, renderWriteData),
194
+ };
195
+ export const notesUpdateParameters = Type.Object({
196
+ address: Type.String(),
197
+ edits: Type.Optional(Type.Array(Type.Object({ oldText: Type.String(), newText: Type.String() }, { additionalProperties: false }))),
198
+ origin: ORIGIN,
199
+ crumpled: CRUMPLED_PARAMETER,
200
+ replace_all: Type.Optional(Type.Boolean({ description: "(optional) true = replace every match of `oldText`." })),
201
+ rename_to: Type.Optional(Type.String({ description: "(optional) Move to this address, keeping metadata. Use alone. Won't overwrite a live note; references aren't updated." })),
202
+ }, { additionalProperties: false });
203
+ function renderUpdateData(data) {
204
+ const head = data.rename_from === undefined
205
+ ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}`
206
+ : `moved ${data.rename_from} -> ${data.address}`;
207
+ const lines = [head];
208
+ if (data.diff.length > 0)
209
+ lines.push("diff:", data.diff);
210
+ return lines.join("\n");
211
+ }
212
+ function renderUpdate(result) {
213
+ return renderOutcome(result, renderUpdateData);
214
+ }
215
+ /** A shortened diff still says so in the receipt's own text, on both surfaces. */
216
+ export const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
217
+ /** Bound a mutation receipt on both surfaces; a huge diff is cut to the longest fitting prefix and marked. */
218
+ function boundedUpdate(data) {
219
+ if (fitsResult(success(data), renderUpdate))
220
+ return success(data);
221
+ if (data.diff === "")
222
+ return failure("output_too_large", "The update was applied, but its receipt metadata exceeds the response budget.");
223
+ const diff = prefixFit(data.diff, (candidate) => fitsResult(success({ ...data, diff: `${candidate}\n${DIFF_SHORTENED_MARKER}` }), renderUpdate));
224
+ const result = success({ ...data, diff: `${diff}\n${DIFF_SHORTENED_MARKER}` });
225
+ return fitsResult(result, renderUpdate) ? result : failure("output_too_large", "The update was applied, but its receipt metadata exceeds the response budget.");
226
+ }
227
+ export const notesUpdate = {
228
+ name: "notes_update", label: "Notes update",
229
+ description: `Edit a note's body, change its origin or crumpled state, or move it. Each \`oldText\` must match exactly once unless \`replace_all\` is true; frontmatter can't be edited. Returns a diff. ${ADDRESS_DESCRIPTION}`,
230
+ parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
231
+ async execute(params, identity, renderDiff) {
232
+ try {
233
+ const store = createNotesStore(identity);
234
+ // Empty filler is not a request: models that pass every parameter get the edit path.
235
+ const renameTo = params.rename_to === "" ? undefined : params.rename_to;
236
+ if (renameTo !== undefined) {
237
+ if ((params.edits?.length ?? 0) > 0 || params.origin !== undefined || params.crumpled !== undefined || params.replace_all === true) {
238
+ return failureOf(new NoteError("invalid_scope", "rename_to is used alone: do not combine it with edits, origin, crumpled, or replace_all"));
239
+ }
240
+ await store.rename(params.address, renameTo);
241
+ const from = noteIdentity(identity, params.address).address;
242
+ const to = noteIdentity(identity, renameTo);
243
+ return boundedUpdate({ ...to, rename_from: from, change_kind: "moved", diff: `rename ${from} -> ${to.address}` });
244
+ }
245
+ const { change } = await store.update(params.address, params.edits, { origin: params.origin, crumpled: params.crumpled, replaceAll: params.replace_all });
246
+ return boundedUpdate({ ...noteIdentity(identity, params.address), change_kind: change.kind, diff: renderDiff(change) });
247
+ }
248
+ catch (error) {
249
+ return failureOf(error);
250
+ }
251
+ },
252
+ render: renderUpdate,
253
+ };
254
+ export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema }, { additionalProperties: false });
255
+ function renderReadData(data) {
256
+ return `${renderIdentity(data)}\n${renderMetadata(data.metadata)}\n\n${renderTextWindow(data)}`;
257
+ }
258
+ export const notesRead = {
259
+ name: "notes_read", label: "Notes read",
260
+ description: `Read a note's metadata and body, without frontmatter. ${ADDRESS_DESCRIPTION}`,
261
+ parameters: notesReadParameters, outputSchema: resultSchema(NotesReadDataSchema),
262
+ async execute(params, identity) {
263
+ try {
264
+ const note = await createNotesStore(identity).read(params.address);
265
+ if (!note)
266
+ return failure("not_found", "note not found");
267
+ const totalChars = Array.from(note.body).length;
268
+ if (params.offset_chars !== undefined && params.offset_chars > totalChars)
269
+ return failure("invalid_offset", `offset_chars ${params.offset_chars} is past the end of the body: the note has ${totalChars} body chars; the largest legal offset is ${totalChars} (an empty end-read)`);
270
+ const resolved = noteIdentity(identity, params.address);
271
+ const metadata = noteMetadata(note.meta);
272
+ return readTextWindow(note.body, params.offset_chars, params.max_chars, (window) => ({ ...resolved, metadata, ...window }), (result) => renderOutcome(result, renderReadData));
273
+ }
274
+ catch (error) {
275
+ return failureOf(error);
276
+ }
277
+ },
278
+ render: (result) => renderOutcome(result, renderReadData),
279
+ };
280
+ export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
281
+ function renderListData(data) {
282
+ const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
283
+ for (const file of data.files) {
284
+ lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at}${file.crumpled_at === undefined ? "" : ` | crumpled ${file.crumpled_at}`}`);
285
+ }
286
+ if (data.more > 0)
287
+ lines.push(`${data.more} more matching notes omitted; narrow with glob`);
288
+ for (const home of data.homes_unavailable)
289
+ lines.push(`${home} could not be read`);
290
+ return lines.join("\n");
291
+ }
292
+ export const notesList = {
293
+ name: "notes_list", label: "Notes list",
294
+ description: `List notes in this session and the four @ homes, newest first. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
295
+ parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
296
+ async execute(params, identity) {
297
+ try {
298
+ const { rows, status } = await createNotesStore(identity).listWithStatus({ glob: params.glob ?? undefined, crumpled: params.crumpled });
299
+ return snapshot(rows.map(row => listedFile(row, identity)), params.limit, status, renderListData);
300
+ }
301
+ catch (error) {
302
+ return failureOf(error);
303
+ }
304
+ },
305
+ render: (result) => renderOutcome(result, renderListData),
306
+ };
307
+ export const notesSearchParameters = Type.Object({ query: searchQuery(), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
308
+ function renderSearchData(data) {
309
+ const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
310
+ for (const file of data.files) {
311
+ lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}`);
312
+ for (const match of file.matches)
313
+ lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
314
+ }
315
+ if (data.more > 0)
316
+ lines.push(`${data.more} more matching notes omitted; narrow with glob`);
317
+ for (const home of data.homes_unavailable)
318
+ lines.push(`${home} could not be read`);
319
+ return lines.join("\n");
320
+ }
321
+ /** A shortened match line still ends with a marker, so its own text says it was cut. */
322
+ export const MATCH_SHORTENED_MARKER = " [truncated]";
323
+ /** Prefer whole match lines; shorten the first line only if no whole line fits, and mark it. */
324
+ function fitSearchFile(file, fits) {
325
+ let low = 0;
326
+ let high = file.matches.length;
327
+ while (low < high) {
328
+ const mid = Math.ceil((low + high) / 2);
329
+ if (fits({ ...file, matches: file.matches.slice(0, mid) }))
330
+ low = mid;
331
+ else
332
+ high = mid - 1;
333
+ }
334
+ if (low > 0)
335
+ return { ...file, matches: file.matches.slice(0, low) };
336
+ const first = file.matches[0];
337
+ if (!first)
338
+ return file;
339
+ const withText = (text) => ({ ...file, matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
340
+ return withText(prefixFit(first.text, text => fits(withText(text))));
341
+ }
342
+ export const notesSearch = {
343
+ name: "notes_search", label: "Notes search",
344
+ description: `Search note bodies for literal text, case-insensitive. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${ADDRESS_DESCRIPTION}`,
345
+ parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
346
+ async execute(params, identity) {
347
+ try {
348
+ const { rows, status } = await createNotesStore(identity).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? undefined, crumpled: params.crumpled });
349
+ const files = rows.sort(byRecent).map(row => ({
350
+ ...listedFile(row, identity),
351
+ matches: row.matches.slice(0, params.max_matches_per_file).map(match => ({ line: match.line, text: match.text, offset_chars: match.offsetChars })),
352
+ }));
353
+ return snapshot(files, params.limit, status, renderSearchData, fitSearchFile);
354
+ }
355
+ catch (error) {
356
+ return failureOf(error);
357
+ }
358
+ },
359
+ render: (result) => renderOutcome(result, renderSearchData),
360
+ };
@@ -0,0 +1,23 @@
1
+ /** Budget primitives. Notes/history use result.ts; reset/budget tools retain output(). */
2
+ export { earliestMatchOffsetChars } from "../text-match.js";
3
+ export declare const TOOL_OUTPUT_MAX_BYTES: number;
4
+ export declare const DEFAULT_READ_WINDOW_CHARS = 12000;
5
+ export declare const MAX_READ_WINDOW_CHARS = 50000;
6
+ export declare const HISTORY_PREVIEW_CHARS = 1200;
7
+ /** True when `text` fits the wire budget verbatim, for raw payloads with no JSON encoding. */
8
+ export declare function withinTextBudget(text: string, budget?: number): boolean;
9
+ /** Longest fitting code-point prefix, without inserted markers. Callers report omissions. */
10
+ export declare function prefixFit(text: string, fits: (content: string) => boolean): string;
11
+ /**
12
+ * Encode a structured result through the common tool result boundary. `details` is slim
13
+ * metadata for logs/UI (pi convention: never a second copy of the payload) and stays
14
+ * undefined unless the tool has metadata worth persisting.
15
+ */
16
+ export declare function output(value: unknown, details?: unknown, terminate?: boolean): {
17
+ content: {
18
+ type: "text";
19
+ text: string;
20
+ }[];
21
+ details: unknown;
22
+ terminate: boolean;
23
+ };