notesoup 0.57.3 → 0.58.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 (129) hide show
  1. package/README.md +15 -1
  2. package/dist/plugins/claude/src/helper.js +2 -11
  3. package/dist/plugins/claude/src/thresholds.js +5 -18
  4. package/dist/plugins/codex/src/mcp.js +3 -11
  5. package/dist/plugins/codex/src/state.d.ts +1 -1
  6. package/dist/plugins/codex/src/state.js +1 -1
  7. package/dist/plugins/dsh/tools.js +1 -1
  8. package/dist/plugins/pi/boot.d.ts +1 -1
  9. package/dist/plugins/pi/boot.js +2 -3
  10. package/dist/plugins/pi/budget.d.ts +1 -1
  11. package/dist/plugins/pi/budget.js +1 -1
  12. package/dist/plugins/pi/render.d.ts +1 -1
  13. package/dist/plugins/pi/render.js +20 -11
  14. package/dist/plugins/pi/runtime.js +6 -2
  15. package/dist/plugins/pi/tool-result.d.ts +2 -1
  16. package/dist/plugins/pi/window.js +24 -1
  17. package/dist/src/boot/render.d.ts +3 -4
  18. package/dist/src/boot/render.js +23 -21
  19. package/dist/src/boot/text.d.ts +2 -5
  20. package/dist/src/boot/text.js +12 -9
  21. package/dist/src/budget/text.d.ts +1 -1
  22. package/dist/src/budget/text.js +1 -1
  23. package/dist/src/history/corpus.d.ts +1 -1
  24. package/dist/src/history/corpus.js +1 -1
  25. package/dist/src/history/history.d.ts +2 -2
  26. package/dist/src/history/history.js +5 -8
  27. package/dist/src/history/query.d.ts +11 -3
  28. package/dist/src/history/query.js +7 -11
  29. package/dist/src/index.d.ts +4 -3
  30. package/dist/src/index.js +1 -1
  31. package/dist/src/notes/constants.d.ts +1 -1
  32. package/dist/src/notes/constants.js +1 -1
  33. package/dist/src/notes/errors.d.ts +1 -1
  34. package/dist/src/notes/frontmatter.d.ts +2 -1
  35. package/dist/src/notes/frontmatter.js +3 -1
  36. package/dist/src/notes/index.d.ts +1 -0
  37. package/dist/src/notes/index.js +1 -0
  38. package/dist/src/notes/policy.d.ts +16 -0
  39. package/dist/src/notes/policy.js +43 -0
  40. package/dist/src/notes/store.d.ts +8 -3
  41. package/dist/src/notes/store.js +64 -20
  42. package/dist/src/result.d.ts +21 -0
  43. package/dist/src/result.js +18 -0
  44. package/dist/src/text-match.d.ts +8 -0
  45. package/dist/src/text-match.js +34 -0
  46. package/dist/src/tools/dream.d.ts +9 -1
  47. package/dist/src/tools/dream.js +2 -1
  48. package/dist/src/tools/history.js +14 -5
  49. package/dist/src/tools/notes.d.ts +75 -13
  50. package/dist/src/tools/notes.js +58 -19
  51. package/dist/src/tools/output.d.ts +1 -3
  52. package/dist/src/tools/output.js +1 -19
  53. package/dist/src/tools/result.d.ts +2 -20
  54. package/dist/src/tools/result.js +4 -18
  55. package/dist/src/tools/schema.d.ts +3 -7
  56. package/dist/src/tools/schema.js +10 -16
  57. package/dist/test/agent-loop.test.js +78 -6
  58. package/dist/test/boot.integration.test.js +30 -3
  59. package/dist/test/claude-mod.test.js +7 -6
  60. package/dist/test/codex-history.test.js +2 -2
  61. package/dist/test/codex-plugin.test.js +2 -0
  62. package/dist/test/dependencies.test.js +38 -3
  63. package/dist/test/dsh.test.js +1 -1
  64. package/dist/test/helpers/dependency-graph.js +12 -6
  65. package/dist/test/helpers/extension.d.ts +2 -1
  66. package/dist/test/history.integration.test.js +47 -1
  67. package/dist/test/host-neutral.test.js +4 -3
  68. package/dist/test/model-facing-text.test.js +20 -16
  69. package/dist/test/note-policy.test.d.ts +1 -0
  70. package/dist/test/note-policy.test.js +227 -0
  71. package/dist/test/notes-query-namespaces.test.js +7 -3
  72. package/dist/test/notes.integration.test.js +10 -10
  73. package/dist/test/notes.test.js +4 -4
  74. package/dist/test/pi-render.test.js +28 -1
  75. package/dist/test/project-namespace.test.js +1 -1
  76. package/docs/architecture.md +10 -7
  77. package/docs/dsh.md +1 -1
  78. package/docs/notes-library.md +20 -7
  79. package/docs/reset-lifecycle.md +2 -2
  80. package/docs/tool-results.md +3 -1
  81. package/package.json +12 -12
  82. package/playbook.md +1 -1
  83. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  84. package/plugins/claude/dist/claude/helper.js +528 -422
  85. package/plugins/claude/hooks/register.ts +1 -10
  86. package/plugins/claude/playbook.md +1 -1
  87. package/plugins/claude/skills/dream/SKILL.md +1 -1
  88. package/plugins/claude/skills/memory/SKILL.md +1 -1
  89. package/plugins/claude/src/helper.ts +2 -11
  90. package/plugins/claude/src/thresholds.ts +5 -15
  91. package/plugins/codex/dist/codex/notesoup.js +520 -403
  92. package/plugins/codex/src/mcp.ts +5 -12
  93. package/plugins/codex/src/state.ts +1 -1
  94. package/plugins/dsh/tools.ts +2 -1
  95. package/plugins/pi/boot.ts +3 -4
  96. package/plugins/pi/budget.ts +1 -1
  97. package/plugins/pi/render.ts +20 -8
  98. package/plugins/pi/runtime.ts +6 -2
  99. package/plugins/pi/tool-result.ts +2 -1
  100. package/plugins/pi/window.ts +20 -1
  101. package/skills/dream/SKILL.md +1 -1
  102. package/skills/memory/SKILL.md +1 -1
  103. package/src/boot/render.ts +24 -21
  104. package/src/boot/text.ts +12 -9
  105. package/src/budget/text.ts +1 -1
  106. package/src/history/corpus.ts +1 -1
  107. package/src/history/history.ts +5 -6
  108. package/src/history/query.ts +11 -14
  109. package/src/index.ts +5 -2
  110. package/src/notes/constants.ts +1 -1
  111. package/src/notes/errors.ts +1 -1
  112. package/src/notes/frontmatter.ts +4 -2
  113. package/src/notes/index.ts +1 -0
  114. package/src/notes/policy.ts +49 -0
  115. package/src/notes/store.ts +66 -26
  116. package/src/result.ts +26 -0
  117. package/src/text-match.ts +32 -0
  118. package/src/tools/dream.ts +2 -1
  119. package/src/tools/history.ts +15 -6
  120. package/src/tools/notes.ts +60 -20
  121. package/src/tools/output.ts +1 -17
  122. package/src/tools/result.ts +4 -26
  123. package/src/tools/schema.ts +11 -17
  124. package/dist/plugins/codex/src/history.d.ts +0 -3
  125. package/dist/plugins/codex/src/history.js +0 -2
  126. package/dist/plugins/codex/src/transcript.d.ts +0 -3
  127. package/dist/plugins/codex/src/transcript.js +0 -2
  128. package/plugins/codex/src/history.ts +0 -3
  129. package/plugins/codex/src/transcript.ts +0 -3
@@ -2,7 +2,7 @@
2
2
  import { Type, type Static } from "typebox";
3
3
  import { type NotesIdentity } from "../notes/index.js";
4
4
  import { type DreamLock } from "../dream/lock.js";
5
- import { type Outcome } from "./result.js";
5
+ import { type Outcome } from "../result.js";
6
6
  /** The one open dream per session; the host owns where it lives. */
7
7
  type DreamOpening = {
8
8
  project: string;
@@ -31,6 +31,10 @@ export declare const DreamBeginDataSchema: Type.TObject<{
31
31
  last_accessed: Type.TString;
32
32
  updated_at: Type.TString;
33
33
  crumpled_at: Type.TOptional<Type.TString>;
34
+ warnings: Type.TArray<Type.TString>;
35
+ pinned: Type.TBoolean;
36
+ budget: Type.TInteger;
37
+ readonly: Type.TBoolean;
34
38
  project_root: Type.TOptional<Type.TString>;
35
39
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
36
40
  name: Type.TString;
@@ -57,6 +61,10 @@ export declare const dreamBegin: {
57
61
  last_accessed: Type.TString;
58
62
  updated_at: Type.TString;
59
63
  crumpled_at: Type.TOptional<Type.TString>;
64
+ warnings: Type.TArray<Type.TString>;
65
+ pinned: Type.TBoolean;
66
+ budget: Type.TInteger;
67
+ readonly: Type.TBoolean;
60
68
  project_root: Type.TOptional<Type.TString>;
61
69
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
62
70
  name: Type.TString;
@@ -5,7 +5,8 @@ import { createNotesStore, noteIdentity } from "../notes/index.js";
5
5
  import { projectNamespaces } from "../notes/project-namespace.js";
6
6
  import { gitCommit } from "../dream/git.js";
7
7
  import { acquireDreamLock, dreamLockPath, releaseDreamLock } from "../dream/lock.js";
8
- import { failure, renderOutcome, resultSchema, success } from "./result.js";
8
+ import { failure, success } from "../result.js";
9
+ import { renderOutcome, resultSchema } from "./result.js";
9
10
  import { failureOf, listedFile, ListedFileSchema, NoteIdentitySchema, renderListData, snapshot, SnapshotSchema } from "./notes.js";
10
11
  function currentOpening(state, opening) {
11
12
  return state.pending === opening && state.generation === opening.generation;
@@ -1,7 +1,8 @@
1
1
  /** Host-neutral history operations: one bounded payload for text and structured results. */
2
2
  import { Type } from "typebox";
3
- import { HISTORY_PREVIEW_CHARS, MAX_READ_WINDOW_CHARS } from "./output.js";
4
- import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, success, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
3
+ import { HISTORY_PREVIEW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_LIMIT } from "./output.js";
4
+ import { failure, success } from "../result.js";
5
+ import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
5
6
  import { historyRoles, searchQuery } from "./schema.js";
6
7
  import { HistoryPageSchema, CorpusCollector, corpusSelection, isMultiPage, markMultiPage, selectPage } from "../history/query.js";
7
8
  import { currentHistory, loadHistoryRepresentative, loadHistorySession, matchesSession, parseSessionSelector, resolveSession, sessionIdentity } from "../history/corpus.js";
@@ -69,6 +70,14 @@ function renderRead(data) {
69
70
  return (data.notice ?? "") + [header(data), ...(tool ? [tool] : []), neighborhood, "", data.total_chars === 0 ? "No visible text recorded for this event." : renderTextWindow(data)].join("\n");
70
71
  }
71
72
  const plainText = (text) => text;
73
+ /** Translate query budget facts into this tool's bounded refusal; successful pages are unchanged. */
74
+ function pageOutcome(result) {
75
+ if (!("pageTooLarge" in result))
76
+ return result;
77
+ const { count, multi } = result.pageTooLarge;
78
+ const narrow = multi ? "narrow the session pattern, query, roles or `since`/`until`, or read one session/seq with `history_read`" : "narrow with `before_seq`/`after_seq` or `since`/`until`, pass `roles` to skip folding, or `history_read` one seq";
79
+ return failure("page_too_large", `Even trimmed to their shortest, these ${count} rows${multi ? "" : " and their folded runs"} fill the ${TOOL_OUTPUT_LIMIT} a call can carry; ${narrow}.`);
80
+ }
72
81
  /* ------------------------------------------------------------------ history_list */
73
82
  const sessionParameter = Type.Optional(Type.String({ minLength: 1, description: "(optional) Session ID or unique prefix, optionally pi:, claude:, codex:, or dsh:. Omit for this session. In history_list, * searches sessions with query or lists recent sessions without it; history_read needs one session." }));
74
83
  export const historyListParameters = Type.Object({
@@ -94,7 +103,7 @@ export const historyList = {
94
103
  const fits = (page) => fitsResult(success(page), (result) => wrapText(renderOutcome(result, renderPage)));
95
104
  const maxChars = params.max_chars_per_item ?? HISTORY_PREVIEW_CHARS;
96
105
  if (params.session === undefined)
97
- return selectPage(await currentHistory(context), params, fits, maxChars);
106
+ return pageOutcome(selectPage(await currentHistory(context), params, fits, maxChars));
98
107
  const selector = parseSessionSelector(params.session);
99
108
  if (!selector.ok)
100
109
  return selector;
@@ -130,7 +139,7 @@ export const historyList = {
130
139
  }
131
140
  }
132
141
  const notice = notices.length ? { notice: notices.join("") } : {};
133
- const result = collector.page((page) => fits(markMultiPage({ ...page, ...notice })), maxChars, unvisited);
142
+ const result = pageOutcome(collector.page((page) => fits(markMultiPage({ ...page, ...notice })), maxChars, unvisited));
134
143
  return result.ok ? success(markMultiPage({ ...result.data, ...notice })) : result;
135
144
  }
136
145
  const target = await resolveSession(corpus, selector.data);
@@ -140,7 +149,7 @@ export const historyList = {
140
149
  if (!loaded.ok)
141
150
  return loaded;
142
151
  const notice = loaded.data.notice === undefined ? {} : { notice: loaded.data.notice };
143
- const result = selectPage(loaded.data.projection, { ...params, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars);
152
+ const result = pageOutcome(selectPage(loaded.data.projection, { ...params, session: sessionIdentity(target.data) }, (page) => fits({ ...page, ...notice }), maxChars));
144
153
  return result.ok ? success({ ...result.data, ...notice }) : result;
145
154
  },
146
155
  render: (result) => renderOutcome(result, renderPage),
@@ -1,7 +1,7 @@
1
1
  import type { NotesIdentity } from "../notes/identity.js";
2
2
  import { Type, type Static } from "typebox";
3
3
  import { type NoteChange, type NoteQueryStatus, type NoteRow } from "../notes/index.js";
4
- import { type Outcome } from "./result.js";
4
+ import { type Outcome } from "../result.js";
5
5
  import { type NotesToolContext } from "./notes-context.js";
6
6
  /**
7
7
  * Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
@@ -15,6 +15,9 @@ export declare const NoteMetadataSchema: Type.TObject<{
15
15
  crumpled_at: Type.TOptional<Type.TString>;
16
16
  project: Type.TOptional<Type.TString>;
17
17
  extra: Type.TRecord<"^.*$", Type.TUnknown>;
18
+ pinned: Type.TBoolean;
19
+ budget: Type.TInteger;
20
+ readonly: Type.TBoolean;
18
21
  }>;
19
22
  export type NoteMetadata = Static<typeof NoteMetadataSchema>;
20
23
  /** Display context a named project notebook adds to its receipts; ordinary notebooks omit both. */
@@ -38,6 +41,10 @@ export declare const NoteIdentitySchema: {
38
41
  export declare const ListedFileSchema: Type.TObject<{
39
42
  updated_at: Type.TString;
40
43
  crumpled_at: Type.TOptional<Type.TString>;
44
+ warnings: Type.TArray<Type.TString>;
45
+ pinned: Type.TBoolean;
46
+ budget: Type.TInteger;
47
+ readonly: Type.TBoolean;
41
48
  project_root: Type.TOptional<Type.TString>;
42
49
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
43
50
  name: Type.TString;
@@ -52,6 +59,10 @@ export declare const SnapshotSchema: {
52
59
  };
53
60
  export declare const NotesWriteDataSchema: Type.TObject<{
54
61
  outcome: Type.TUnion<[Type.TLiteral<"created">, Type.TLiteral<"overwrote">, Type.TLiteral<"uncrumpled">]>;
62
+ warnings: Type.TArray<Type.TString>;
63
+ pinned: Type.TBoolean;
64
+ budget: Type.TInteger;
65
+ readonly: Type.TBoolean;
55
66
  project_root: Type.TOptional<Type.TString>;
56
67
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
57
68
  name: Type.TString;
@@ -64,6 +75,10 @@ export type NotesWriteData = Static<typeof NotesWriteDataSchema>;
64
75
  export declare const NotesUpdateDataSchema: Type.TObject<{
65
76
  change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
66
77
  rename_from: Type.TOptional<Type.TString>;
78
+ warnings: Type.TArray<Type.TString>;
79
+ pinned: Type.TBoolean;
80
+ budget: Type.TInteger;
81
+ readonly: Type.TBoolean;
67
82
  project_root: Type.TOptional<Type.TString>;
68
83
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
69
84
  name: Type.TString;
@@ -77,6 +92,7 @@ export declare const NotesReadDataSchema: Type.TObject<{
77
92
  text: Type.TString;
78
93
  total_chars: Type.TInteger;
79
94
  next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
95
+ warnings: Type.TArray<Type.TString>;
80
96
  metadata: Type.TObject<{
81
97
  origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
82
98
  created_at: Type.TString;
@@ -84,6 +100,9 @@ export declare const NotesReadDataSchema: Type.TObject<{
84
100
  crumpled_at: Type.TOptional<Type.TString>;
85
101
  project: Type.TOptional<Type.TString>;
86
102
  extra: Type.TRecord<"^.*$", Type.TUnknown>;
103
+ pinned: Type.TBoolean;
104
+ budget: Type.TInteger;
105
+ readonly: Type.TBoolean;
87
106
  }>;
88
107
  project_root: Type.TOptional<Type.TString>;
89
108
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
@@ -100,6 +119,10 @@ export declare const NotesListDataSchema: Type.TObject<{
100
119
  files: Type.TArray<Type.TObject<{
101
120
  updated_at: Type.TString;
102
121
  crumpled_at: Type.TOptional<Type.TString>;
122
+ warnings: Type.TArray<Type.TString>;
123
+ pinned: Type.TBoolean;
124
+ budget: Type.TInteger;
125
+ readonly: Type.TBoolean;
103
126
  project_root: Type.TOptional<Type.TString>;
104
127
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
105
128
  name: Type.TString;
@@ -121,6 +144,10 @@ export declare const NotesSearchDataSchema: Type.TObject<{
121
144
  }>>;
122
145
  updated_at: Type.TString;
123
146
  crumpled_at: Type.TOptional<Type.TString>;
147
+ warnings: Type.TArray<Type.TString>;
148
+ pinned: Type.TBoolean;
149
+ budget: Type.TInteger;
150
+ readonly: Type.TBoolean;
124
151
  project_root: Type.TOptional<Type.TString>;
125
152
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
126
153
  name: Type.TString;
@@ -138,25 +165,38 @@ type Snapshot<T> = Omit<NotesListData, "files"> & {
138
165
  export declare function snapshot<T extends {
139
166
  address: string;
140
167
  }>(rows: T[], limit: number | undefined, status: NoteQueryStatus, renderData: (data: Snapshot<T>) => string, shrink?: (item: T, fits: (candidate: T) => boolean) => T): Outcome<Snapshot<T>>;
141
- export declare function listedFile(row: Pick<NoteRow, "address" | "meta">, identity: NotesIdentity): NotesListData["files"][number];
168
+ export declare function listedFile(row: Pick<NoteRow, "address" | "meta"> & {
169
+ body?: string;
170
+ warnings?: string[];
171
+ }, identity: NotesIdentity): NotesListData["files"][number];
142
172
  export declare const notesWriteParameters: Type.TObject<{
173
+ cwd: Type.TOptional<Type.TString>;
174
+ pinned: Type.TOptional<Type.TBoolean>;
175
+ budget: Type.TOptional<Type.TInteger>;
176
+ readonly: Type.TOptional<Type.TBoolean>;
143
177
  address: Type.TString;
144
178
  content: Type.TString;
145
179
  origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
146
- cwd: Type.TOptional<Type.TString>;
147
180
  }>;
148
181
  export declare const notesWrite: {
149
182
  readonly name: "notes_write";
150
183
  readonly label: "Notes write";
151
184
  readonly description: "Create a note, or overwrite its whole body. Name it for what it holds and when to use it. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
152
185
  readonly parameters: Type.TObject<{
186
+ cwd: Type.TOptional<Type.TString>;
187
+ pinned: Type.TOptional<Type.TBoolean>;
188
+ budget: Type.TOptional<Type.TInteger>;
189
+ readonly: Type.TOptional<Type.TBoolean>;
153
190
  address: Type.TString;
154
191
  content: Type.TString;
155
192
  origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
156
- cwd: Type.TOptional<Type.TString>;
157
193
  }>;
158
194
  readonly outputSchema: Type.TUnion<[Type.TObject<{
159
195
  outcome: Type.TUnion<[Type.TLiteral<"created">, Type.TLiteral<"overwrote">, Type.TLiteral<"uncrumpled">]>;
196
+ warnings: Type.TArray<Type.TString>;
197
+ pinned: Type.TBoolean;
198
+ budget: Type.TInteger;
199
+ readonly: Type.TBoolean;
160
200
  project_root: Type.TOptional<Type.TString>;
161
201
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
162
202
  name: Type.TString;
@@ -173,36 +213,46 @@ export declare const notesWrite: {
173
213
  readonly render: (result: Outcome<NotesWriteData>) => string;
174
214
  };
175
215
  export declare const notesUpdateParameters: Type.TObject<{
216
+ crumpled: Type.TOptional<Type.TBoolean>;
217
+ replace_all: Type.TOptional<Type.TBoolean>;
218
+ rename_to: Type.TOptional<Type.TString>;
219
+ cwd: Type.TOptional<Type.TString>;
220
+ pinned: Type.TOptional<Type.TBoolean>;
221
+ budget: Type.TOptional<Type.TInteger>;
222
+ readonly: Type.TOptional<Type.TBoolean>;
176
223
  address: Type.TString;
177
224
  edits: Type.TOptional<Type.TArray<Type.TObject<{
178
225
  oldText: Type.TString;
179
226
  newText: Type.TString;
180
227
  }>>>;
181
228
  origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
182
- crumpled: Type.TOptional<Type.TBoolean>;
183
- replace_all: Type.TOptional<Type.TBoolean>;
184
- rename_to: Type.TOptional<Type.TString>;
185
- cwd: Type.TOptional<Type.TString>;
186
229
  }>;
187
230
  export declare const notesUpdate: {
188
231
  readonly name: "notes_update";
189
232
  readonly label: "Notes update";
190
- readonly description: "Change part of a note's body, its origin or crumpled state, or its address. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each `oldText` must match exactly once unless `replace_all` is true. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
233
+ readonly description: "Change part of a note's body, policy (pinned/budget/readonly), origin, crumpled state, or address. A readonly note requires explicit readonly:false before any change, or in the same call. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each `oldText` must match exactly once unless `replace_all` is true. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
191
234
  readonly parameters: Type.TObject<{
235
+ crumpled: Type.TOptional<Type.TBoolean>;
236
+ replace_all: Type.TOptional<Type.TBoolean>;
237
+ rename_to: Type.TOptional<Type.TString>;
238
+ cwd: Type.TOptional<Type.TString>;
239
+ pinned: Type.TOptional<Type.TBoolean>;
240
+ budget: Type.TOptional<Type.TInteger>;
241
+ readonly: Type.TOptional<Type.TBoolean>;
192
242
  address: Type.TString;
193
243
  edits: Type.TOptional<Type.TArray<Type.TObject<{
194
244
  oldText: Type.TString;
195
245
  newText: Type.TString;
196
246
  }>>>;
197
247
  origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
198
- crumpled: Type.TOptional<Type.TBoolean>;
199
- replace_all: Type.TOptional<Type.TBoolean>;
200
- rename_to: Type.TOptional<Type.TString>;
201
- cwd: Type.TOptional<Type.TString>;
202
248
  }>;
203
249
  readonly outputSchema: Type.TUnion<[Type.TObject<{
204
250
  change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
205
251
  rename_from: Type.TOptional<Type.TString>;
252
+ warnings: Type.TArray<Type.TString>;
253
+ pinned: Type.TBoolean;
254
+ budget: Type.TInteger;
255
+ readonly: Type.TBoolean;
206
256
  project_root: Type.TOptional<Type.TString>;
207
257
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
208
258
  name: Type.TString;
@@ -238,6 +288,7 @@ export declare const notesRead: {
238
288
  text: Type.TString;
239
289
  total_chars: Type.TInteger;
240
290
  next_offset_chars: Type.TUnion<[Type.TInteger, Type.TNull]>;
291
+ warnings: Type.TArray<Type.TString>;
241
292
  metadata: Type.TObject<{
242
293
  origin: Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>;
243
294
  created_at: Type.TString;
@@ -245,6 +296,9 @@ export declare const notesRead: {
245
296
  crumpled_at: Type.TOptional<Type.TString>;
246
297
  project: Type.TOptional<Type.TString>;
247
298
  extra: Type.TRecord<"^.*$", Type.TUnknown>;
299
+ pinned: Type.TBoolean;
300
+ budget: Type.TInteger;
301
+ readonly: Type.TBoolean;
248
302
  }>;
249
303
  project_root: Type.TOptional<Type.TString>;
250
304
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
@@ -285,6 +339,10 @@ export declare const notesList: {
285
339
  files: Type.TArray<Type.TObject<{
286
340
  updated_at: Type.TString;
287
341
  crumpled_at: Type.TOptional<Type.TString>;
342
+ warnings: Type.TArray<Type.TString>;
343
+ pinned: Type.TBoolean;
344
+ budget: Type.TInteger;
345
+ readonly: Type.TBoolean;
288
346
  project_root: Type.TOptional<Type.TString>;
289
347
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
290
348
  name: Type.TString;
@@ -333,6 +391,10 @@ export declare const notesSearch: {
333
391
  }>>;
334
392
  updated_at: Type.TString;
335
393
  crumpled_at: Type.TOptional<Type.TString>;
394
+ warnings: Type.TArray<Type.TString>;
395
+ pinned: Type.TBoolean;
396
+ budget: Type.TInteger;
397
+ readonly: Type.TBoolean;
336
398
  project_root: Type.TOptional<Type.TString>;
337
399
  project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
338
400
  name: Type.TString;
@@ -1,15 +1,38 @@
1
+ import { assertAddress } from "../notes/address.js";
2
+ import { noteFileName } from "../notes/paths.js";
3
+ import { effectiveNotePolicy, noteBudgetWarnings } from "../notes/policy.js";
1
4
  import { Type } from "typebox";
2
5
  import { localIso } from "../notes/frontmatter.js";
3
6
  import { isFilesystemError } from "../notes/fs-error.js";
4
7
  import { createNotesStore, NoteError, noteIdentity } from "../notes/index.js";
5
- import { prefixFit, TOOL_OUTPUT_LIMIT } 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
+ import { TOOL_OUTPUT_LIMIT } from "./output.js";
9
+ import { failure, success } from "../result.js";
10
+ import { InvalidQueryError, prefixFit, searchQueries } from "../text-match.js";
11
+ import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
12
+ import { nullableString, searchQuery } from "./schema.js";
8
13
  import { notesIdentityForCall } from "./notes-context.js";
9
14
  const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")];
10
15
  const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
11
16
  description: "(optional) Who wrote it: user, self, or external. Omit to keep the existing origin; new notes default to self.",
12
17
  }));
18
+ const POLICY_PARAMETERS = {
19
+ pinned: Type.Optional(Type.Boolean({ description: "Inject the full body at boot. At most 5 live pins per notebook; root CHEATSHEET.md/MAP.md default true, all others false. Explicit false overrides the default." })),
20
+ budget: Type.Optional(Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER, description: "Body budget in Unicode code points (default 2048 for every note). Over budget warns but saves; boot does not truncate." })),
21
+ readonly: Type.Optional(Type.Boolean({ description: "Soft lock, not a security boundary. true locks changes; explicitly pass false to unlock, including in the same call as edits or overwrite." })),
22
+ };
23
+ const PolicySchema = {
24
+ pinned: Type.Boolean(), budget: Type.Integer(), readonly: Type.Boolean(),
25
+ };
26
+ const WarningsSchema = { warnings: Type.Array(Type.String()) };
27
+ function policyAt(meta, address) {
28
+ return effectiveNotePolicy(meta, noteFileName(assertAddress(address).path));
29
+ }
30
+ function renderPolicy(policy) {
31
+ return `pinned ${policy.pinned} | budget ${policy.budget} | readonly ${policy.readonly}`;
32
+ }
33
+ function withWarnings(text, data) {
34
+ return [text, ...data.warnings].join("\n");
35
+ }
13
36
  const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
14
37
  const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
15
38
  const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
@@ -32,13 +55,14 @@ export function failureOf(error) {
32
55
  throw error;
33
56
  }
34
57
  /** Metadata keys this layer normalizes; everything else is exposed verbatim under `extra`. */
35
- const NORMALIZED_META_KEYS = new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project"]);
58
+ const NORMALIZED_META_KEYS = new Set(["scope", "origin", "createdAt", "updatedAt", "lastAccessed", "accessCount", "crumpledAt", "project", "pinned", "budget", "readonly"]);
36
59
  /** One unrecognized entry, and the verbatim extras together, are bounded so `extra` cannot outgrow the read. */
37
60
  const MAX_METADATA_ENTRY_BYTES = 1024;
38
61
  const MAX_METADATA_VERBATIM_BYTES = 2048;
39
62
  /** An extra value that cannot be carried is named in place, never silently dropped. */
40
63
  const TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
41
64
  export const NoteMetadataSchema = Type.Object({
65
+ ...PolicySchema,
42
66
  origin: Type.Union([...ORIGIN_VALUES]),
43
67
  created_at: Type.String(),
44
68
  updated_at: Type.String(),
@@ -47,7 +71,7 @@ export const NoteMetadataSchema = Type.Object({
47
71
  extra: Type.Record(Type.String(), Type.Unknown()),
48
72
  }, { additionalProperties: false });
49
73
  /** Normalize known metadata and bound extras, naming an oversized value instead of hiding it. */
50
- function noteMetadata(meta) {
74
+ function noteMetadata(meta, address) {
51
75
  const extra = {};
52
76
  let verbatimBytes = 0;
53
77
  const put = (key, value) => {
@@ -70,6 +94,7 @@ function noteMetadata(meta) {
70
94
  put(key, value);
71
95
  }
72
96
  return {
97
+ ...policyAt(meta, address),
73
98
  origin: meta.origin,
74
99
  created_at: localIso(meta.createdAt),
75
100
  updated_at: localIso(meta.updatedAt),
@@ -80,6 +105,7 @@ function noteMetadata(meta) {
80
105
  }
81
106
  function renderMetadata(metadata) {
82
107
  const fields = [
108
+ renderPolicy(metadata),
83
109
  `origin ${metadata.origin}`,
84
110
  `created ${metadata.created_at}`,
85
111
  `updated ${metadata.updated_at}`,
@@ -113,6 +139,8 @@ export const NoteIdentitySchema = {
113
139
  };
114
140
  export const ListedFileSchema = Type.Object({
115
141
  ...NoteIdentitySchema,
142
+ ...PolicySchema,
143
+ ...WarningsSchema,
116
144
  updated_at: Type.String(),
117
145
  crumpled_at: Type.Optional(Type.String()),
118
146
  }, { additionalProperties: false });
@@ -131,16 +159,21 @@ export const SnapshotSchema = {
131
159
  };
132
160
  export const NotesWriteDataSchema = Type.Object({
133
161
  ...NoteIdentitySchema,
162
+ ...PolicySchema,
163
+ ...WarningsSchema,
134
164
  outcome: Type.Union([Type.Literal("created"), Type.Literal("overwrote"), Type.Literal("uncrumpled")]),
135
165
  }, { additionalProperties: false });
136
166
  export const NotesUpdateDataSchema = Type.Object({
137
167
  ...NoteIdentitySchema,
168
+ ...PolicySchema,
169
+ ...WarningsSchema,
138
170
  change_kind: Type.Union([Type.Literal("none"), Type.Literal("body"), Type.Literal("metadata"), Type.Literal("moved")]),
139
171
  rename_from: Type.Optional(Type.String()),
140
172
  }, { additionalProperties: false });
141
173
  export const NotesReadDataSchema = Type.Object({
142
174
  ...NoteIdentitySchema,
143
175
  metadata: NoteMetadataSchema,
176
+ ...WarningsSchema,
144
177
  ...TextWindowSchema.properties,
145
178
  }, { additionalProperties: false });
146
179
  export const NotesListDataSchema = Type.Object({
@@ -175,11 +208,12 @@ export function snapshot(rows, limit, status, renderData, shrink) {
175
208
  return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable notebooks is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer notebooks.`);
176
209
  }
177
210
  export function listedFile(row, identity) {
178
- return { ...noteIdentity(identity, row.address), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
211
+ const policy = policyAt(row.meta, row.address);
212
+ return { ...noteIdentity(identity, row.address), ...policy, warnings: row.warnings ?? (row.body === undefined ? [] : noteBudgetWarnings(row.body, policy)), updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
179
213
  }
180
- export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN, cwd: CWD_PARAMETER }, { additionalProperties: false });
214
+ export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN, ...POLICY_PARAMETERS, cwd: CWD_PARAMETER }, { additionalProperties: false });
181
215
  function renderWriteData(data) {
182
- return `${data.outcome} ${renderIdentity(data)}`;
216
+ return withWarnings(`${data.outcome} ${renderIdentity(data)} | ${renderPolicy(data)}`, data);
183
217
  }
184
218
  export const notesWrite = {
185
219
  name: "notes_write", label: "Notes write",
@@ -188,8 +222,8 @@ export const notesWrite = {
188
222
  async execute(params, context) {
189
223
  try {
190
224
  const identity = notesIdentityForCall(context, params.cwd);
191
- const { outcome } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin });
192
- return success({ ...noteIdentity(identity, params.address), outcome });
225
+ const { outcome, meta, warnings } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin, pinned: params.pinned, budget: params.budget, readonly: params.readonly });
226
+ return success({ ...noteIdentity(identity, params.address), outcome, ...policyAt(meta, params.address), warnings });
193
227
  }
194
228
  catch (error) {
195
229
  return failureOf(error);
@@ -201,19 +235,21 @@ export const notesUpdateParameters = Type.Object({
201
235
  address: Type.String(),
202
236
  edits: Type.Optional(Type.Array(Type.Object({ oldText: Type.String(), newText: Type.String() }, { additionalProperties: false }))),
203
237
  origin: ORIGIN,
238
+ ...POLICY_PARAMETERS,
204
239
  crumpled: CRUMPLED_PARAMETER,
205
240
  replace_all: Type.Optional(Type.Boolean({ description: "(optional) true = replace every match of `oldText`." })),
206
241
  rename_to: Type.Optional(Type.String({ description: "(optional) Move to this address, optionally with edits or metadata changes. Won't overwrite a live note; references aren't updated." })),
207
242
  cwd: CWD_PARAMETER,
208
243
  }, { additionalProperties: false });
209
244
  function renderUpdateData(data) {
210
- return data.rename_from === undefined
245
+ const receipt = data.rename_from === undefined
211
246
  ? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}`
212
247
  : `moved ${data.rename_from} -> ${data.address}`;
248
+ return withWarnings(`${receipt} | ${renderPolicy(data)}`, data);
213
249
  }
214
250
  export const notesUpdate = {
215
251
  name: "notes_update", label: "Notes update",
216
- description: `Change part of a note's body, its origin or crumpled state, or its address. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
252
+ description: `Change part of a note's body, policy (pinned/budget/readonly), origin, crumpled state, or address. A readonly note requires explicit readonly:false before any change, or in the same call. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
217
253
  parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
218
254
  async execute(params, context, onChange) {
219
255
  try {
@@ -221,11 +257,11 @@ export const notesUpdate = {
221
257
  const store = createNotesStore(identity);
222
258
  // Empty filler is not a request: models that pass every parameter get the edit path.
223
259
  const renameTo = params.rename_to === "" ? undefined : params.rename_to;
224
- const { change, moved } = await store.update(params.address, params.edits, { origin: params.origin, crumpled: params.crumpled, replaceAll: params.replace_all, renameTo });
260
+ const { change, moved, meta, warnings } = await store.update(params.address, params.edits, { origin: params.origin, pinned: params.pinned, budget: params.budget, readonly: params.readonly, crumpled: params.crumpled, replaceAll: params.replace_all, renameTo });
225
261
  onChange?.(change);
226
262
  const from = noteIdentity(identity, params.address).address;
227
263
  const to = noteIdentity(identity, renameTo ?? params.address);
228
- return success({ ...to, ...(moved ? { rename_from: from } : {}), change_kind: moved ? "moved" : change.kind });
264
+ return success({ ...to, ...policyAt(meta, to.address), warnings, ...(moved ? { rename_from: from } : {}), change_kind: moved ? "moved" : change.kind });
229
265
  }
230
266
  catch (error) {
231
267
  return failureOf(error);
@@ -235,7 +271,7 @@ export const notesUpdate = {
235
271
  };
236
272
  export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
237
273
  function renderReadData(data) {
238
- return `${renderIdentity(data)}\n${renderMetadata(data.metadata)}\n\n${renderTextWindow(data)}`;
274
+ return withWarnings(`${renderIdentity(data)}\n${renderMetadata(data.metadata)}`, data) + `\n\n${renderTextWindow(data)}`;
239
275
  }
240
276
  export const notesRead = {
241
277
  name: "notes_read", label: "Notes read",
@@ -251,8 +287,9 @@ export const notesRead = {
251
287
  const totalChars = Array.from(note.body).length;
252
288
  if (params.offset_chars !== undefined && params.offset_chars > totalChars)
253
289
  return failure("invalid_offset", `This note ends at char ${totalChars}; offset_chars ${params.offset_chars} is past the last word.`);
254
- const metadata = noteMetadata(note.meta);
255
- return readTextWindow(note.body, params.offset_chars, params.max_chars, (window) => ({ ...resolved, metadata, ...window }), (result) => renderOutcome(result, renderReadData));
290
+ const metadata = noteMetadata(note.meta, resolved.address);
291
+ const warnings = noteBudgetWarnings(note.body, metadata);
292
+ return readTextWindow(note.body, params.offset_chars, params.max_chars, (window) => ({ ...resolved, metadata, warnings, ...window }), (result) => renderOutcome(result, renderReadData));
256
293
  }
257
294
  catch (error) {
258
295
  return failureOf(error);
@@ -264,7 +301,8 @@ export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FI
264
301
  export function renderListData(data) {
265
302
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
266
303
  for (const file of data.files) {
267
- lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at}${file.last_accessed === undefined ? "" : ` | accessed ${file.last_accessed}`}${file.crumpled_at === undefined ? "" : ` | crumpled ${file.crumpled_at}`}`);
304
+ lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at}${file.last_accessed === undefined ? "" : ` | accessed ${file.last_accessed}`}${file.crumpled_at === undefined ? "" : ` | crumpled ${file.crumpled_at}`}`);
305
+ lines.push(...file.warnings.map(warning => ` ${warning}`));
268
306
  }
269
307
  if (data.more > 0)
270
308
  lines.push(`${data.more} more matching notes omitted; narrow with glob`);
@@ -292,7 +330,8 @@ export const notesSearchParameters = Type.Object({ query: Type.Optional(searchQu
292
330
  function renderSearchData(data) {
293
331
  const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
294
332
  for (const file of data.files) {
295
- lines.push(`- ${renderIdentity(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}`);
333
+ lines.push(`- ${renderIdentity(file)} | ${renderPolicy(file)} | updated ${file.updated_at} | ${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}`);
334
+ lines.push(...file.warnings.map(warning => ` ${warning}`));
296
335
  for (const match of file.matches)
297
336
  lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
298
337
  }
@@ -1,9 +1,7 @@
1
- /** Shared output budget primitives. */
1
+ /** Tool output budgets and default window sizes. */
2
2
  export declare const TOOL_OUTPUT_MAX_BYTES: number;
3
3
  /** The per-call limit as the model reads it in refusals. */
4
4
  export declare const TOOL_OUTPUT_LIMIT = "32 KB";
5
5
  export declare const DEFAULT_READ_WINDOW_CHARS = 12000;
6
6
  export declare const MAX_READ_WINDOW_CHARS = 50000;
7
7
  export declare const HISTORY_PREVIEW_CHARS = 1200;
8
- /** Longest fitting code-point prefix, without inserted markers. Callers report omissions. */
9
- export declare function prefixFit(text: string, fits: (content: string) => boolean): string;
@@ -1,25 +1,7 @@
1
- /** Shared output budget primitives. */
1
+ /** Tool output budgets and default window sizes. */
2
2
  export const TOOL_OUTPUT_MAX_BYTES = 32 * 1024;
3
3
  /** The per-call limit as the model reads it in refusals. */
4
4
  export const TOOL_OUTPUT_LIMIT = `${TOOL_OUTPUT_MAX_BYTES / 1024} KB`;
5
5
  export const DEFAULT_READ_WINDOW_CHARS = 12000;
6
6
  export const MAX_READ_WINDOW_CHARS = 50000;
7
7
  export const HISTORY_PREVIEW_CHARS = 1200;
8
- /** Longest fitting code-point prefix, without inserted markers. Callers report omissions. */
9
- export function prefixFit(text, fits) {
10
- if (fits(text))
11
- return text;
12
- const chars = Array.from(text);
13
- // Serialized size is non-decreasing in the kept count, so the largest fitting prefix is
14
- // found by a monotone binary search instead of a quadratic shrink loop.
15
- let low = 0;
16
- let high = chars.length;
17
- while (low < high) {
18
- const mid = Math.ceil((low + high) / 2);
19
- if (fits(chars.slice(0, mid).join("")))
20
- low = mid;
21
- else
22
- high = mid - 1;
23
- }
24
- return chars.slice(0, low).join("");
25
- }
@@ -1,24 +1,6 @@
1
- /** Internal outcomes, compact wire results, and bounded read windows. */
1
+ /** Compact tool wire results and bounded read windows. */
2
2
  import { Type, type Static, type TSchema } from "typebox";
3
- /** The one refusal shape: `code` is a stable internal identifier, `message` the bounded reading. */
4
- export declare const OperationErrorSchema: Type.TObject<{
5
- code: Type.TString;
6
- message: Type.TString;
7
- }>;
8
- export type OperationError = Static<typeof OperationErrorSchema>;
9
- /** `data` exists without `error`, never both, never neither. */
10
- export type Outcome<T> = {
11
- ok: true;
12
- data: T;
13
- } | {
14
- ok: false;
15
- error: OperationError;
16
- };
17
- export declare function success<T>(data: T): Outcome<T>;
18
- /** A code is an internal stable identifier and is never clipped; the dynamic message is the bounded surface. */
19
- export declare const ERROR_MESSAGE_MAX_CHARS = 2000;
20
- /** Bounded refusal: a runaway message is clipped with a marker instead of filling the wire. */
21
- export declare function failure(code: string, message: string): Outcome<never>;
3
+ import { type Outcome } from "../result.js";
22
4
  /** Public results have no success envelope. `error` is reserved for a refusal message. */
23
5
  export declare const WireErrorSchema: Type.TObject<{
24
6
  error: Type.TString;
@@ -1,22 +1,8 @@
1
- /** Internal outcomes, compact wire results, and bounded read windows. */
1
+ /** Compact tool wire results and bounded read windows. */
2
2
  import { Type } from "typebox";
3
- import { DEFAULT_READ_WINDOW_CHARS, MAX_READ_WINDOW_CHARS, prefixFit, TOOL_OUTPUT_LIMIT, TOOL_OUTPUT_MAX_BYTES } from "./output.js";
4
- /** The one refusal shape: `code` is a stable internal identifier, `message` the bounded reading. */
5
- export const OperationErrorSchema = Type.Object({
6
- code: Type.String(),
7
- message: Type.String(),
8
- }, { additionalProperties: false });
9
- export function success(data) {
10
- return { ok: true, data };
11
- }
12
- /** A code is an internal stable identifier and is never clipped; the dynamic message is the bounded surface. */
13
- export const ERROR_MESSAGE_MAX_CHARS = 2000;
14
- /** Bounded refusal: a runaway message is clipped with a marker instead of filling the wire. */
15
- export function failure(code, message) {
16
- const chars = Array.from(message);
17
- const bounded = chars.length <= ERROR_MESSAGE_MAX_CHARS ? message : `${chars.slice(0, ERROR_MESSAGE_MAX_CHARS).join("")}…[truncated ${chars.length - ERROR_MESSAGE_MAX_CHARS} chars]`;
18
- return { ok: false, error: { code, message: bounded } };
19
- }
3
+ import { failure, success } from "../result.js";
4
+ import { prefixFit } from "../text-match.js";
5
+ import { DEFAULT_READ_WINDOW_CHARS, MAX_READ_WINDOW_CHARS, TOOL_OUTPUT_LIMIT, TOOL_OUTPUT_MAX_BYTES } from "./output.js";
20
6
  /** Public results have no success envelope. `error` is reserved for a refusal message. */
21
7
  export const WireErrorSchema = Type.Object({ error: Type.String(), code: Type.String() }, { additionalProperties: false });
22
8
  export function wireResult(result) {