notesoup 0.61.0 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agents/plugins/marketplace.json +15 -0
- package/README.md +14 -11
- package/dist/plugins/antigravity/src/cli.d.ts +1 -0
- package/dist/plugins/antigravity/src/cli.js +23 -0
- package/dist/plugins/antigravity/src/hooks.d.ts +18 -0
- package/dist/plugins/antigravity/src/hooks.js +53 -0
- package/dist/plugins/antigravity/src/identity.d.ts +26 -0
- package/dist/plugins/antigravity/src/identity.js +129 -0
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/codex/src/hooks.js +1 -0
- package/dist/plugins/codex/src/identity.d.ts +6 -1
- package/dist/plugins/codex/src/identity.js +13 -1
- package/dist/plugins/codex/src/mcp.d.ts +35 -7
- package/dist/plugins/codex/src/mcp.js +26 -88
- package/dist/plugins/codex/src/text.js +3 -3
- package/dist/plugins/dsh/tools.js +8 -4
- package/dist/plugins/mcp/operations.d.ts +15 -0
- package/dist/plugins/mcp/operations.js +43 -0
- package/dist/plugins/mcp/server.d.ts +14 -0
- package/dist/plugins/mcp/server.js +13 -0
- package/dist/plugins/pi/budget.d.ts +1 -1
- package/dist/plugins/pi/budget.js +3 -2
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.js +2 -1
- package/dist/plugins/pi/history.js +18 -1
- package/dist/plugins/pi/notes/tools.js +7 -3
- package/dist/plugins/pi/render.d.ts +7 -1
- package/dist/plugins/pi/render.js +2 -2
- package/dist/plugins/pi/reset/lifecycle.d.ts +1 -1
- package/dist/plugins/pi/reset/lifecycle.js +8 -9
- package/dist/plugins/pi/runtime.js +102 -61
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +33 -3
- package/dist/plugins/pi/window.js +209 -9
- package/dist/src/boot/render.js +18 -15
- package/dist/src/boot/text.d.ts +3 -1
- package/dist/src/boot/text.js +22 -20
- package/dist/src/budget/text.d.ts +2 -2
- package/dist/src/budget/text.js +13 -13
- package/dist/src/history/claude.d.ts +2 -0
- package/dist/src/history/claude.js +46 -0
- package/dist/src/history/codex-transcript.js +7 -5
- package/dist/src/history/codex.js +3 -0
- package/dist/src/history/corpus.d.ts +28 -1
- package/dist/src/history/corpus.js +40 -0
- package/dist/src/history/history.d.ts +37 -46
- package/dist/src/history/history.js +21 -40
- package/dist/src/history/local.js +67 -32
- package/dist/src/history/pi.d.ts +2 -1
- package/dist/src/history/pi.js +122 -48
- package/dist/src/history/prefilter.js +76 -19
- package/dist/src/history/query.d.ts +28 -49
- package/dist/src/history/query.js +83 -68
- package/dist/src/history/summary-cache.d.ts +8 -1
- package/dist/src/history/summary-cache.js +138 -12
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.d.ts +0 -2
- package/dist/src/notes/frontmatter.js +0 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/policy.d.ts +15 -1
- package/dist/src/notes/policy.js +46 -5
- package/dist/src/notes/store.d.ts +12 -0
- package/dist/src/notes/store.js +16 -20
- package/dist/src/text-match.d.ts +10 -1
- package/dist/src/text-match.js +42 -3
- package/dist/src/tools/dream.d.ts +22 -93
- package/dist/src/tools/dream.js +30 -27
- package/dist/src/tools/history.d.ts +33 -26
- package/dist/src/tools/history.js +257 -163
- package/dist/src/tools/notes.d.ts +51 -163
- package/dist/src/tools/notes.js +146 -100
- package/dist/src/tools/output.d.ts +2 -1
- package/dist/src/tools/output.js +2 -1
- package/dist/src/tools/result.d.ts +4 -7
- package/dist/src/tools/result.js +8 -9
- package/dist/src/tools/schema.d.ts +4 -1
- package/dist/src/tools/schema.js +25 -1
- package/dist/test/agent-loop.test.js +198 -16
- package/dist/test/antigravity-live.test.d.ts +1 -0
- package/dist/test/antigravity-live.test.js +142 -0
- package/dist/test/antigravity-plugin.test.d.ts +1 -0
- package/dist/test/antigravity-plugin.test.js +101 -0
- package/dist/test/boot.integration.test.js +133 -14
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +9 -6
- package/dist/test/codex-history.test.js +15 -3
- package/dist/test/codex-plugin.test.js +76 -38
- package/dist/test/dependencies.test.js +7 -3
- package/dist/test/dream-skill.test.js +3 -3
- package/dist/test/dream-tools.test.js +101 -56
- package/dist/test/dsh.test.js +34 -19
- package/dist/test/helpers/dependency-graph.js +2 -2
- package/dist/test/helpers/extension.d.ts +65 -2
- package/dist/test/helpers/extension.js +72 -3
- package/dist/test/history-corpus.test.js +79 -77
- package/dist/test/history-summary-cache.test.js +97 -9
- package/dist/test/history.integration.test.js +234 -168
- package/dist/test/host-neutral.test.js +69 -19
- package/dist/test/marker.test.js +1 -1
- package/dist/test/note-policy.test.js +96 -77
- package/dist/test/notes.integration.test.js +212 -94
- package/dist/test/notes.test.js +184 -113
- package/dist/test/pi-render.test.js +20 -12
- package/dist/test/project-namespace.test.js +3 -2
- package/dist/test/reset-lifecycle.test.js +2 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +2 -2
- package/docs/codex.md +36 -38
- package/docs/dsh.md +3 -3
- package/docs/history-sessions.md +28 -50
- package/docs/notes-library.md +4 -4
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +47 -28
- package/package.json +3 -2
- package/playbook.md +1 -1
- package/plugins/antigravity/dist/antigravity/notesoup.js +26886 -0
- package/plugins/antigravity/hooks.json +7 -0
- package/plugins/antigravity/mcp_config.json +8 -0
- package/plugins/antigravity/plugin.json +6 -0
- package/plugins/antigravity/src/cli.ts +22 -0
- package/plugins/antigravity/src/hooks.ts +51 -0
- package/plugins/antigravity/src/identity.ts +127 -0
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +1059 -534
- package/plugins/claude/hooks/register.ts +2 -2
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/notesoup/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +2 -1
- package/plugins/codex/.codex-plugin/plugin.json +8 -0
- package/plugins/codex/.mcp.json +11 -0
- package/plugins/codex/README.md +5 -21
- package/plugins/codex/dist/codex/notesoup.js +18480 -17946
- package/plugins/codex/src/hooks.ts +1 -0
- package/plugins/codex/src/identity.ts +14 -1
- package/plugins/codex/src/mcp.ts +28 -98
- package/plugins/codex/src/text.ts +3 -3
- package/plugins/dsh/tools.ts +8 -4
- package/plugins/mcp/operations.ts +50 -0
- package/plugins/mcp/server.ts +23 -0
- package/plugins/paseo/README.md +5 -10
- package/plugins/paseo/client/brain-empty-card.tsx +3 -3
- package/plugins/paseo/client/markdown.tsx +50 -38
- package/plugins/paseo/client/notes-op-card.tsx +12 -9
- package/plugins/paseo/client/paper-card.tsx +6 -5
- package/plugins/paseo/client/paper-palette.ts +2 -9
- package/plugins/paseo/client/sticky-card.tsx +2 -2
- package/plugins/paseo/client/tool-result.ts +7 -14
- package/plugins/paseo/package-lock.json +3406 -0
- package/plugins/paseo/package.json +1 -0
- package/plugins/paseo/test/markdown-core.test.ts +73 -66
- package/plugins/pi/budget.ts +3 -3
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +2 -1
- package/plugins/pi/history.ts +30 -1
- package/plugins/pi/notes/tools.ts +7 -3
- package/plugins/pi/render.ts +6 -6
- package/plugins/pi/reset/lifecycle.ts +9 -10
- package/plugins/pi/runtime.ts +96 -60
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +198 -9
- package/skills/dream/SKILL.md +1 -1
- package/skills/notesoup/SKILL.md +92 -0
- package/src/boot/render.ts +18 -15
- package/src/boot/text.ts +23 -19
- package/src/budget/text.ts +13 -13
- package/src/history/claude.ts +41 -0
- package/src/history/codex-transcript.ts +6 -4
- package/src/history/codex.ts +2 -0
- package/src/history/corpus.ts +51 -2
- package/src/history/history.ts +35 -44
- package/src/history/local.ts +67 -27
- package/src/history/pi.ts +113 -35
- package/src/history/prefilter.ts +73 -15
- package/src/history/query.ts +93 -73
- package/src/history/summary-cache.ts +142 -17
- package/src/index.ts +1 -1
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +0 -3
- package/src/notes/index.ts +1 -1
- package/src/notes/policy.ts +44 -5
- package/src/notes/store.ts +17 -20
- package/src/text-match.ts +46 -4
- package/src/tools/dream.ts +29 -31
- package/src/tools/history.ts +249 -142
- package/src/tools/notes.ts +145 -113
- package/src/tools/output.ts +2 -1
- package/src/tools/result.ts +12 -11
- package/src/tools/schema.ts +24 -1
- package/plugins/claude/skills/memory/SKILL.md +0 -69
- package/plugins/codex/mcp.json +0 -10
- package/plugins/codex/plugin.json +0 -6
- package/plugins/paseo/client/markdown-core.tsx +0 -189
- package/plugins/paseo/client/typography.ts +0 -24
- package/skills/memory/SKILL.md +0 -69
package/dist/src/tools/notes.js
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { assertAddress } from "../notes/address.js";
|
|
2
2
|
import { noteFileName } from "../notes/paths.js";
|
|
3
|
-
import { effectiveNotePolicy,
|
|
3
|
+
import { effectiveNotePolicy, noteDescriptionWarnings, noteWarnings, renderWarnings } from "../notes/policy.js";
|
|
4
4
|
import { Type } from "typebox";
|
|
5
5
|
import { localIso } from "../notes/frontmatter.js";
|
|
6
6
|
import { isFilesystemError } from "../notes/fs-error.js";
|
|
7
|
-
import { createNotesStore, NoteError, noteIdentity } from "../notes/index.js";
|
|
7
|
+
import { compareNoteRows, createNotesStore, NoteError, noteIdentity } from "../notes/index.js";
|
|
8
8
|
import { TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
9
9
|
import { failure, success } from "../result.js";
|
|
10
10
|
import { InvalidQueryError, prefixFit, searchQueries } from "../text-match.js";
|
|
11
|
-
import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
12
|
-
import { searchQuery } from "./schema.js";
|
|
11
|
+
import { fitsResult, fitsText, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
12
|
+
import { parseIsoTimestamp, searchQuery, stringEnum } from "./schema.js";
|
|
13
13
|
import { notesIdentityForCall } from "./notes-context.js";
|
|
14
|
-
const ORIGIN_VALUES = [
|
|
15
|
-
const ORIGIN = Type.Optional(
|
|
16
|
-
description: "
|
|
14
|
+
const ORIGIN_VALUES = ["user", "self", "external"];
|
|
15
|
+
const ORIGIN = Type.Optional(stringEnum(ORIGIN_VALUES, {
|
|
16
|
+
description: "Author tag. Omit to keep existing.",
|
|
17
17
|
}));
|
|
18
|
-
const DESCRIPTION_PARAMETER = Type.Optional(Type.String({ description: "One-line summary
|
|
18
|
+
const DESCRIPTION_PARAMETER = Type.Optional(Type.String({ description: "One-line summary for the boot index (empty string clears it)." }));
|
|
19
19
|
const POLICY_PARAMETERS = {
|
|
20
|
-
pinned: Type.Optional(Type.Boolean({ description: "
|
|
21
|
-
|
|
22
|
-
readonly: Type.Optional(Type.Boolean({ description: "A paperclip that keeps your own hands off. `false` takes it off — same call is fine." })),
|
|
20
|
+
pinned: Type.Optional(Type.Boolean({ description: "Inject at wake-up (truncated to byte budget if oversized)." })),
|
|
21
|
+
readonly: Type.Optional(Type.Boolean({ description: "Soft lock against edits, moves, and deletion." })),
|
|
23
22
|
};
|
|
24
23
|
const PolicySchema = {
|
|
25
24
|
pinned: Type.Boolean(), budget: Type.Integer(), readonly: Type.Boolean(),
|
|
@@ -31,15 +30,29 @@ function policyAt(meta, address) {
|
|
|
31
30
|
function renderPolicy(policy) {
|
|
32
31
|
return `pinned ${policy.pinned} | budget ${policy.budget} | readonly ${policy.readonly}`;
|
|
33
32
|
}
|
|
33
|
+
/** Only policy that differs from the note's own path defaults; an ordinary note renders nothing. */
|
|
34
|
+
function renderSparsePolicy(policy, address) {
|
|
35
|
+
const defaults = effectiveNotePolicy({}, noteFileName(assertAddress(address).path));
|
|
36
|
+
const tokens = [];
|
|
37
|
+
if (policy.pinned)
|
|
38
|
+
tokens.push("pinned");
|
|
39
|
+
else if (defaults.pinned)
|
|
40
|
+
tokens.push("pinned false");
|
|
41
|
+
if (policy.budget !== defaults.budget)
|
|
42
|
+
tokens.push(`budget ${policy.budget}`);
|
|
43
|
+
if (policy.readonly)
|
|
44
|
+
tokens.push("readonly");
|
|
45
|
+
return tokens.join(" | ");
|
|
46
|
+
}
|
|
34
47
|
function withWarnings(text, data) {
|
|
35
|
-
return
|
|
48
|
+
return data.warnings.length === 0 ? text : `${text}\n${renderWarnings(data.warnings)}`;
|
|
36
49
|
}
|
|
37
|
-
const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "`true`
|
|
38
|
-
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "
|
|
39
|
-
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "
|
|
40
|
-
const GLOB_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "
|
|
50
|
+
const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "Crumple (`true`) or restore (`false`) the note." }));
|
|
51
|
+
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "List crumpled notes instead of live ones." }));
|
|
52
|
+
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "Maximum notes to return." }));
|
|
53
|
+
const GLOB_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Address glob. Omit for current notebooks; `**` for all; `@projects/*/**` or `@sessions/*/**` for named notebooks." }));
|
|
41
54
|
const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
|
|
42
|
-
const ADDRESS_PARAMETER = Type.String({ description: "
|
|
55
|
+
const ADDRESS_PARAMETER = Type.String({ description: "Note address (per boot protocol). Never pass `@` addresses to filesystem tools." });
|
|
43
56
|
/**
|
|
44
57
|
* Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
|
|
45
58
|
* Convert expected refusals; unexpected errors propagate unchanged.
|
|
@@ -63,7 +76,7 @@ const MAX_METADATA_VERBATIM_BYTES = 2048;
|
|
|
63
76
|
const TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
|
|
64
77
|
export const NoteMetadataSchema = Type.Object({
|
|
65
78
|
...PolicySchema,
|
|
66
|
-
origin:
|
|
79
|
+
origin: stringEnum(ORIGIN_VALUES),
|
|
67
80
|
created_at: Type.String(),
|
|
68
81
|
updated_at: Type.String(),
|
|
69
82
|
crumpled_at: Type.Optional(Type.String()),
|
|
@@ -140,55 +153,18 @@ export const NoteIdentitySchema = {
|
|
|
140
153
|
project_key: Type.Optional(Type.String()),
|
|
141
154
|
...ProjectReceiptSchema,
|
|
142
155
|
};
|
|
143
|
-
export const ListedFileSchema = Type.Object({
|
|
144
|
-
...NoteIdentitySchema,
|
|
145
|
-
...PolicySchema,
|
|
146
|
-
...WarningsSchema,
|
|
147
|
-
updated_at: Type.String(),
|
|
148
|
-
crumpled_at: Type.Optional(Type.String()),
|
|
149
|
-
description: Type.Optional(Type.String()),
|
|
150
|
-
}, { additionalProperties: false });
|
|
151
|
-
const MatchSchema = Type.Object({
|
|
152
|
-
line: Type.Integer(),
|
|
153
|
-
text: Type.String(),
|
|
154
|
-
offset_chars: Type.Integer(),
|
|
155
|
-
}, { additionalProperties: false });
|
|
156
|
-
export const SnapshotSchema = {
|
|
157
|
-
more: Type.Integer({ description: "How many more were left out." }),
|
|
158
|
-
namespaces_unavailable: Type.Array(Type.String(), { description: "Unreadable notebooks or notes." }),
|
|
159
|
-
};
|
|
160
|
-
export const NotesWriteDataSchema = Type.Object({
|
|
161
|
-
...NoteIdentitySchema,
|
|
162
|
-
...PolicySchema,
|
|
163
|
-
...WarningsSchema,
|
|
164
|
-
outcome: Type.Union([Type.Literal("created"), Type.Literal("overwrote"), Type.Literal("uncrumpled")]),
|
|
165
|
-
}, { additionalProperties: false });
|
|
166
|
-
export const NotesUpdateDataSchema = Type.Object({
|
|
167
|
-
...NoteIdentitySchema,
|
|
168
|
-
...PolicySchema,
|
|
169
|
-
...WarningsSchema,
|
|
170
|
-
change_kind: Type.Union([Type.Literal("none"), Type.Literal("body"), Type.Literal("metadata"), Type.Literal("moved")]),
|
|
171
|
-
rename_from: Type.Optional(Type.String()),
|
|
172
|
-
}, { additionalProperties: false });
|
|
173
156
|
export const NotesReadDataSchema = Type.Object({
|
|
174
157
|
...NoteIdentitySchema,
|
|
175
158
|
metadata: NoteMetadataSchema,
|
|
176
159
|
...WarningsSchema,
|
|
177
160
|
...TextWindowSchema.properties,
|
|
178
161
|
}, { additionalProperties: false });
|
|
179
|
-
export const NotesListDataSchema = Type.Object({
|
|
180
|
-
files: Type.Array(Type.Object({
|
|
181
|
-
...ListedFileSchema.properties,
|
|
182
|
-
matches: Type.Optional(Type.Array(MatchSchema)), more_matches: Type.Optional(Type.Integer({ minimum: 1 })),
|
|
183
|
-
}, { additionalProperties: false })),
|
|
184
|
-
...SnapshotSchema,
|
|
185
|
-
}, { additionalProperties: false });
|
|
186
162
|
/** Keep identities intact. Only search previews may shrink to make the first row fit. */
|
|
187
163
|
export function snapshot(rows, limit, status, renderData, shrink) {
|
|
188
164
|
const files = [];
|
|
189
165
|
const data = (selected) => ({ files: selected, more: rows.length - selected.length, namespaces_unavailable: status.namespacesUnavailable });
|
|
190
166
|
const render = (outcome) => renderOutcome(outcome, renderData);
|
|
191
|
-
const fits = (item) =>
|
|
167
|
+
const fits = (item) => fitsText(render(success(data([...files, item]))));
|
|
192
168
|
for (const item of rows.slice(0, limit)) {
|
|
193
169
|
if (fits(item)) {
|
|
194
170
|
files.push(item);
|
|
@@ -204,24 +180,26 @@ export function snapshot(rows, limit, status, renderData, shrink) {
|
|
|
204
180
|
break;
|
|
205
181
|
}
|
|
206
182
|
const outcome = success(data(files));
|
|
207
|
-
return
|
|
183
|
+
return fitsText(render(outcome)) ? outcome : failure("output_too_large", `The list of unreachable notebooks is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer notebooks.`);
|
|
208
184
|
}
|
|
209
185
|
export function listedFile(row, identity) {
|
|
210
186
|
const policy = policyAt(row.meta, row.address);
|
|
211
|
-
|
|
187
|
+
const warnings = row.warnings ?? (row.body === undefined ? noteDescriptionWarnings(row.meta.description) : noteWarnings(row.body, policy, row.meta.description));
|
|
188
|
+
return { ...noteIdentity(identity, row.address), ...policy, warnings, updated_at: localIso(row.meta.updatedAt), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }), ...(typeof row.meta.description === "string" ? { description: row.meta.description } : {}) };
|
|
212
189
|
}
|
|
213
|
-
export const notesWriteParameters = Type.Object({ address: ADDRESS_PARAMETER, content: Type.String({ description: "
|
|
190
|
+
export const notesWriteParameters = Type.Object({ address: ADDRESS_PARAMETER, content: Type.String({ description: "Full markdown body." }), origin: ORIGIN, description: DESCRIPTION_PARAMETER, ...POLICY_PARAMETERS, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
214
191
|
function renderWriteData(data) {
|
|
215
|
-
|
|
192
|
+
const sparse = renderSparsePolicy(data, data.address);
|
|
193
|
+
return withWarnings(`${data.outcome} ${renderIdentity(data)}${sparse === "" ? "" : ` | ${sparse}`}`, data);
|
|
216
194
|
}
|
|
217
195
|
export const notesWrite = {
|
|
218
196
|
name: "notes_write", label: "Notes write",
|
|
219
|
-
description: "
|
|
220
|
-
parameters: notesWriteParameters,
|
|
197
|
+
description: "Create or overwrite a note. Set `description` (one line) so boot indexes it.",
|
|
198
|
+
parameters: notesWriteParameters, executionMode: "sequential",
|
|
221
199
|
async execute(params, context) {
|
|
222
200
|
try {
|
|
223
201
|
const identity = notesIdentityForCall(context, params.cwd);
|
|
224
|
-
const { outcome, meta, warnings } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin, description: params.description, pinned: params.pinned,
|
|
202
|
+
const { outcome, meta, warnings } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin, description: params.description, pinned: params.pinned, readonly: params.readonly });
|
|
225
203
|
return success({ ...noteIdentity(identity, params.address), outcome, ...policyAt(meta, params.address), warnings });
|
|
226
204
|
}
|
|
227
205
|
catch (error) {
|
|
@@ -232,32 +210,38 @@ export const notesWrite = {
|
|
|
232
210
|
};
|
|
233
211
|
export const notesUpdateParameters = Type.Object({
|
|
234
212
|
address: ADDRESS_PARAMETER,
|
|
235
|
-
edits: Type.Optional(Type.Array(Type.Object({
|
|
213
|
+
edits: Type.Optional(Type.Array(Type.Object({
|
|
214
|
+
oldText: Type.String({ description: "Exact text to replace." }),
|
|
215
|
+
newText: Type.String({ description: "Replacement text." }),
|
|
216
|
+
replace_all: Type.Optional(Type.Boolean({ description: "Replace every occurrence (overrides top-level `replace_all`)." })),
|
|
217
|
+
}, { additionalProperties: false }), { description: "Sequential exact text replacements." })),
|
|
236
218
|
origin: ORIGIN,
|
|
237
219
|
description: DESCRIPTION_PARAMETER,
|
|
238
220
|
...POLICY_PARAMETERS,
|
|
239
221
|
crumpled: CRUMPLED_PARAMETER,
|
|
240
|
-
replace_all: Type.Optional(Type.Boolean({ description: "
|
|
241
|
-
rename_to: Type.Optional(Type.String({ description: "Move
|
|
222
|
+
replace_all: Type.Optional(Type.Boolean({ description: "Replace every occurrence in edits that omit `replace_all`." })),
|
|
223
|
+
rename_to: Type.Optional(Type.String({ description: "Move note to this address." })),
|
|
242
224
|
cwd: CWD_PARAMETER,
|
|
243
225
|
}, { additionalProperties: false });
|
|
244
226
|
function renderUpdateData(data) {
|
|
245
227
|
const receipt = data.rename_from === undefined
|
|
246
228
|
? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}`
|
|
247
229
|
: `moved ${data.rename_from} -> ${data.address}`;
|
|
248
|
-
|
|
230
|
+
const sparse = renderSparsePolicy(data, data.address);
|
|
231
|
+
return withWarnings(`${receipt}${sparse === "" ? "" : ` | ${sparse}`}`, data);
|
|
249
232
|
}
|
|
250
233
|
export const notesUpdate = {
|
|
251
234
|
name: "notes_update", label: "Notes update",
|
|
252
|
-
description: "
|
|
253
|
-
parameters: notesUpdateParameters,
|
|
235
|
+
description: "Edit an existing note's text or metadata, move it (`rename_to`), or crumple/restore it (`crumpled`).",
|
|
236
|
+
parameters: notesUpdateParameters, executionMode: "sequential",
|
|
254
237
|
async execute(params, context, onChange) {
|
|
255
238
|
try {
|
|
256
239
|
const identity = notesIdentityForCall(context, params.cwd);
|
|
257
240
|
const store = createNotesStore(identity);
|
|
258
241
|
// Empty filler is not a request: models that pass every parameter get the edit path.
|
|
259
242
|
const renameTo = params.rename_to === "" ? undefined : params.rename_to;
|
|
260
|
-
const
|
|
243
|
+
const edits = params.edits?.map((edit) => ({ oldText: edit.oldText, newText: edit.newText, ...(edit.replace_all === undefined ? {} : { replaceAll: edit.replace_all }) }));
|
|
244
|
+
const { change, moved, meta, warnings } = await store.update(params.address, edits, { origin: params.origin, description: params.description, pinned: params.pinned, readonly: params.readonly, crumpled: params.crumpled, replaceAll: params.replace_all, renameTo });
|
|
261
245
|
onChange?.(change);
|
|
262
246
|
const from = noteIdentity(identity, params.address).address;
|
|
263
247
|
const to = noteIdentity(identity, renameTo ?? params.address);
|
|
@@ -275,7 +259,7 @@ function renderReadData(data) {
|
|
|
275
259
|
}
|
|
276
260
|
export const notesRead = {
|
|
277
261
|
name: "notes_read", label: "Notes read",
|
|
278
|
-
description: "Read a
|
|
262
|
+
description: "Read a note (supports windowed reads via `offset_chars` and `max_chars`).",
|
|
279
263
|
parameters: notesReadParameters, outputSchema: resultSchema(NotesReadDataSchema),
|
|
280
264
|
async execute(params, context) {
|
|
281
265
|
try {
|
|
@@ -288,8 +272,9 @@ export const notesRead = {
|
|
|
288
272
|
if (params.offset_chars !== undefined && params.offset_chars > totalChars)
|
|
289
273
|
return failure("invalid_offset", `This note ends at char ${totalChars}; offset_chars ${params.offset_chars} is past the last word.`);
|
|
290
274
|
const metadata = noteMetadata(note.meta, resolved.address);
|
|
291
|
-
const warnings =
|
|
292
|
-
|
|
275
|
+
const warnings = noteWarnings(note.body, metadata, metadata.description);
|
|
276
|
+
const render = (result) => renderOutcome(result, renderReadData);
|
|
277
|
+
return readTextWindow(note.body, params.offset_chars, params.max_chars, (window) => ({ ...resolved, metadata, warnings, ...window }), render, (result) => fitsResult(result, render));
|
|
293
278
|
}
|
|
294
279
|
catch (error) {
|
|
295
280
|
return failureOf(error);
|
|
@@ -299,16 +284,25 @@ export const notesRead = {
|
|
|
299
284
|
};
|
|
300
285
|
export const notesListParameters = Type.Object({
|
|
301
286
|
glob: GLOB_PARAMETER,
|
|
302
|
-
query: Type.Optional(searchQuery()),
|
|
303
|
-
|
|
287
|
+
query: Type.Optional(searchQuery("Case-insensitive literal text, or a list (any match). Omit to list.")),
|
|
288
|
+
max_matches_per_note: Type.Optional(Type.Integer({ minimum: 1, description: "Maximum matching lines shown per note." })),
|
|
304
289
|
crumpled: CRUMPLED_LIST_PARAMETER,
|
|
305
290
|
limit: FILE_LIMIT_PARAMETER,
|
|
291
|
+
cursor: Type.Optional(Type.String({ description: "Cursor from an `→ older` footer (`<updated_at> <address>`)." })),
|
|
306
292
|
cwd: CWD_PARAMETER,
|
|
307
293
|
}, { additionalProperties: false });
|
|
308
|
-
|
|
294
|
+
function moreMatches(more, tail) {
|
|
295
|
+
return `${more} more matching ${more === 1 ? "note" : "notes"}${tail}`;
|
|
296
|
+
}
|
|
297
|
+
export function renderListData(data, renderMore = (more) => moreMatches(more, " omitted; narrow with glob"), options = {}) {
|
|
309
298
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
310
299
|
for (const file of data.files) {
|
|
311
|
-
|
|
300
|
+
// The current project is already the context of a `@project/` row; named notebooks keep their receipt.
|
|
301
|
+
const identity = file.address.startsWith("@project/") || options.omitNamedProjectContext
|
|
302
|
+
? renderIdentity({ address: file.address })
|
|
303
|
+
: renderIdentity(file);
|
|
304
|
+
const sparse = renderSparsePolicy(file, file.address);
|
|
305
|
+
const fields = [`- ${identity}${file.description === undefined ? "" : ` — ${file.description}`}`, ...(sparse === "" ? [] : [sparse]), `updated ${file.updated_at}`];
|
|
312
306
|
if (file.last_accessed !== undefined)
|
|
313
307
|
fields.push(`accessed ${file.last_accessed}`);
|
|
314
308
|
if (file.crumpled_at !== undefined)
|
|
@@ -316,26 +310,28 @@ export function renderListData(data) {
|
|
|
316
310
|
if (file.matches)
|
|
317
311
|
fields.push(`${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
|
|
318
312
|
lines.push(fields.join(" | "));
|
|
319
|
-
lines.push(...file.warnings.map(warning => ` ${warning}`));
|
|
313
|
+
lines.push(...file.warnings.map(warning => ` ${renderWarnings([warning])}`));
|
|
320
314
|
for (const match of file.matches ?? [])
|
|
321
315
|
lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
322
316
|
}
|
|
323
317
|
if (data.more > 0)
|
|
324
|
-
lines.push(
|
|
318
|
+
lines.push(renderMore(data.more, data.files));
|
|
325
319
|
for (const namespace of data.namespaces_unavailable)
|
|
326
320
|
lines.push(`${namespace} could not be read`);
|
|
327
321
|
return lines.join("\n");
|
|
328
322
|
}
|
|
329
|
-
function keepMatches(file, count = file.matches
|
|
330
|
-
const
|
|
331
|
-
|
|
323
|
+
function keepMatches(file, count = file.matches?.length ?? 0) {
|
|
324
|
+
const matches = file.matches ?? [];
|
|
325
|
+
const more = (file.more_matches ?? 0) + Math.max(0, matches.length - count);
|
|
326
|
+
return { ...file, matches: matches.slice(0, count), ...(more ? { more_matches: more } : {}) };
|
|
332
327
|
}
|
|
333
328
|
/** A shortened match line still ends with a marker, so its own text says it was cut. */
|
|
334
329
|
export const MATCH_SHORTENED_MARKER = " [truncated]";
|
|
335
330
|
/** Prefer whole match lines; shorten the first line only if no whole line fits, and mark it. */
|
|
336
331
|
function fitSearchFile(file, fits) {
|
|
332
|
+
const matches = file.matches ?? [];
|
|
337
333
|
let low = 0;
|
|
338
|
-
let high =
|
|
334
|
+
let high = matches.length;
|
|
339
335
|
while (low < high) {
|
|
340
336
|
const mid = Math.ceil((low + high) / 2);
|
|
341
337
|
if (fits(keepMatches(file, mid)))
|
|
@@ -343,38 +339,88 @@ function fitSearchFile(file, fits) {
|
|
|
343
339
|
else
|
|
344
340
|
high = mid - 1;
|
|
345
341
|
}
|
|
346
|
-
if (low > 0 ||
|
|
342
|
+
if (low > 0 || matches.length === 0)
|
|
347
343
|
return keepMatches(file, low);
|
|
348
|
-
const first =
|
|
344
|
+
const first = matches[0];
|
|
349
345
|
const withText = (text) => ({ ...keepMatches(file, 1), matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
|
|
350
346
|
return withText(prefixFit(first.text, text => fits(withText(text))));
|
|
351
347
|
}
|
|
348
|
+
function parseCursor(raw, identity) {
|
|
349
|
+
if (raw === undefined || raw === "")
|
|
350
|
+
return success(undefined);
|
|
351
|
+
const space = raw.indexOf(" ");
|
|
352
|
+
if (space <= 0 || space === raw.length - 1)
|
|
353
|
+
return failure("invalid_params", "`cursor` must be `<updated_at> <address>`.");
|
|
354
|
+
const atMs = parseIsoTimestamp(raw.slice(0, space));
|
|
355
|
+
if (atMs === undefined)
|
|
356
|
+
return failure("invalid_params", "`cursor` starts with an invalid ISO 8601 timestamp.");
|
|
357
|
+
try {
|
|
358
|
+
return success({ atMs, address: noteIdentity(identity, raw.slice(space + 1)).address });
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
return failure("invalid_params", "`cursor` ends with an invalid note address.");
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/** Newest first, address ascending on a tie; a cursor keeps only the pages strictly after itself. */
|
|
365
|
+
function olderThan(file, cursor) {
|
|
366
|
+
const atMs = parseIsoTimestamp(file.updated_at);
|
|
367
|
+
return atMs < cursor.atMs || (atMs === cursor.atMs && file.address.localeCompare(cursor.address) > 0);
|
|
368
|
+
}
|
|
369
|
+
function renderOlderPage(more, files, params, searching) {
|
|
370
|
+
const last = files[files.length - 1];
|
|
371
|
+
if (last === undefined)
|
|
372
|
+
return moreMatches(more, " omitted; narrow glob");
|
|
373
|
+
const next = {};
|
|
374
|
+
if (params.glob !== undefined)
|
|
375
|
+
next.glob = params.glob;
|
|
376
|
+
if (searching)
|
|
377
|
+
next.query = params.query;
|
|
378
|
+
if (params.max_matches_per_note !== undefined)
|
|
379
|
+
next.max_matches_per_note = params.max_matches_per_note;
|
|
380
|
+
if (params.crumpled !== undefined)
|
|
381
|
+
next.crumpled = params.crumpled;
|
|
382
|
+
if (params.limit !== undefined)
|
|
383
|
+
next.limit = params.limit;
|
|
384
|
+
if (params.cwd !== undefined)
|
|
385
|
+
next.cwd = params.cwd;
|
|
386
|
+
next.cursor = `${last.updated_at} ${last.address}`;
|
|
387
|
+
return moreMatches(more, ` | → older: ${JSON.stringify(next)}`);
|
|
388
|
+
}
|
|
352
389
|
export const notesList = {
|
|
353
390
|
name: "notes_list", label: "Notes list",
|
|
354
|
-
description: "List or search notes, newest
|
|
355
|
-
parameters: notesListParameters,
|
|
391
|
+
description: "List or search notes, newest first. Literal case-insensitive `query` returns matching lines and `offset_chars`.",
|
|
392
|
+
parameters: notesListParameters,
|
|
356
393
|
async execute(params, context) {
|
|
357
394
|
try {
|
|
358
395
|
const queries = searchQueries(params.query);
|
|
359
396
|
const { glob, crumpled, limit } = params;
|
|
360
|
-
if (!queries.length && params.
|
|
361
|
-
return failure("invalid_params", "`
|
|
397
|
+
if (!queries.length && params.max_matches_per_note !== undefined)
|
|
398
|
+
return failure("invalid_params", "`max_matches_per_note` requires a non-empty `query`.");
|
|
362
399
|
const identity = notesIdentityForCall(context, params.cwd);
|
|
400
|
+
const cursor = parseCursor(params.cursor, identity);
|
|
401
|
+
if (!cursor.ok)
|
|
402
|
+
return cursor;
|
|
363
403
|
const store = createNotesStore(identity);
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const files = rows.
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
404
|
+
const result = queries.length
|
|
405
|
+
? await store.searchWithStatus(queries, { glob, crumpled })
|
|
406
|
+
: await store.listWithStatus({ glob, crumpled });
|
|
407
|
+
const rows = result.rows;
|
|
408
|
+
rows.sort(compareNoteRows);
|
|
409
|
+
const files = rows.map(row => "matches" in row
|
|
410
|
+
? keepMatches({
|
|
411
|
+
...listedFile(row, identity),
|
|
412
|
+
matches: row.matches.map(match => ({ line: match.line, text: match.text, offset_chars: match.offsetChars })),
|
|
413
|
+
}, params.max_matches_per_note)
|
|
414
|
+
: listedFile(row, identity));
|
|
415
|
+
const page = files.filter(file => cursor.data === undefined || olderThan(file, cursor.data));
|
|
416
|
+
const outcome = snapshot(page, limit, result.status, data => renderListData(data, (more, shown) => renderOlderPage(more, shown, params, queries.length > 0)), queries.length ? fitSearchFile : undefined);
|
|
417
|
+
if (!outcome.ok || outcome.data.more === 0)
|
|
418
|
+
return outcome;
|
|
419
|
+
return success({ ...outcome.data, older: renderOlderPage(outcome.data.more, outcome.data.files, params, queries.length > 0) });
|
|
374
420
|
}
|
|
375
421
|
catch (error) {
|
|
376
422
|
return failureOf(error);
|
|
377
423
|
}
|
|
378
424
|
},
|
|
379
|
-
render: (result) => renderOutcome(result, renderListData),
|
|
425
|
+
render: (result) => renderOutcome(result, data => renderListData(data, more => data.older ?? moreMatches(more, " omitted; narrow with glob"))),
|
|
380
426
|
};
|
|
@@ -4,4 +4,5 @@ export declare const TOOL_OUTPUT_MAX_BYTES: number;
|
|
|
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
|
-
export declare const HISTORY_PREVIEW_CHARS =
|
|
7
|
+
export declare const HISTORY_PREVIEW_CHARS = 2500;
|
|
8
|
+
export declare const HISTORY_READ_WINDOW_CHARS = 8000;
|
package/dist/src/tools/output.js
CHANGED
|
@@ -4,4 +4,5 @@ export const TOOL_OUTPUT_MAX_BYTES = 32 * 1024;
|
|
|
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
|
-
export const HISTORY_PREVIEW_CHARS =
|
|
7
|
+
export const HISTORY_PREVIEW_CHARS = 2500;
|
|
8
|
+
export const HISTORY_READ_WINDOW_CHARS = 8000;
|
|
@@ -17,11 +17,8 @@ export declare function resultSchema<S extends TSchema>(dataSchema: S): Type.TUn
|
|
|
17
17
|
export declare function renderOutcome<T>(result: Outcome<T>, renderData: (data: T) => string): string;
|
|
18
18
|
/** Bytes of the structured payload as delivered: compact JSON, not the model-facing text. A value with no JSON representation has no size to measure. */
|
|
19
19
|
export declare function structuredBytes(value: unknown): number;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* measure covers everything the renderer puts around the payload, headers and footers included.
|
|
23
|
-
*/
|
|
24
|
-
export declare function fitsResult<T>(result: Outcome<T>, render: (result: Outcome<T>) => string): boolean;
|
|
20
|
+
export declare function fitsText(text: string): boolean;
|
|
21
|
+
export declare function fitsResult<T>(result: Outcome<T>, render: Renderer<T>): boolean;
|
|
25
22
|
/** `text` is verbatim, with no marker inserted, so windows concatenate back into the source. */
|
|
26
23
|
export declare const TextWindowSchema: Type.TObject<{
|
|
27
24
|
text: Type.TString;
|
|
@@ -45,7 +42,7 @@ export declare const TextWindowRequestSchema: {
|
|
|
45
42
|
* An envelope that cannot fit even empty is refused instead of returned: a zero-length window
|
|
46
43
|
* would resume at the offset it started from, so paging could never make progress.
|
|
47
44
|
*/
|
|
48
|
-
export declare function readTextWindow<T>(text: string, offset: number | undefined, limit: number | undefined, makeData: (window: TextWindow) => T, render: (result: Outcome<T>) =>
|
|
45
|
+
export declare function readTextWindow<T>(text: string, offset: number | undefined, limit: number | undefined, makeData: (window: TextWindow) => T, render: Renderer<T>, fitsOutcome?: (result: Outcome<T>) => boolean): Outcome<T>;
|
|
49
46
|
/** The continuation line never becomes part of `window.text`, and a complete window has none. */
|
|
50
47
|
export declare function renderTextWindow(window: TextWindow): string;
|
|
51
48
|
/** One outcome in, model-facing text out. */
|
|
@@ -59,7 +56,7 @@ export type Operation<TParams extends TSchema, TData, TRest extends readonly unk
|
|
|
59
56
|
/** Absent leaves concurrency to the host default. */
|
|
60
57
|
readonly executionMode?: "sequential" | "parallel";
|
|
61
58
|
/** Schema of wireResult(outcome), not the internal outcome envelope. */
|
|
62
|
-
readonly outputSchema
|
|
59
|
+
readonly outputSchema?: TSchema;
|
|
63
60
|
readonly execute: (params: Static<TParams>, ...rest: TRest) => Promise<Outcome<TData>>;
|
|
64
61
|
readonly render: Renderer<TData>;
|
|
65
62
|
};
|
package/dist/src/tools/result.js
CHANGED
|
@@ -22,12 +22,11 @@ export function renderOutcome(result, renderData) {
|
|
|
22
22
|
export function structuredBytes(value) {
|
|
23
23
|
return Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
25
|
+
export function fitsText(text) {
|
|
26
|
+
return Buffer.byteLength(text, "utf8") <= TOOL_OUTPUT_MAX_BYTES;
|
|
27
|
+
}
|
|
29
28
|
export function fitsResult(result, render) {
|
|
30
|
-
return
|
|
29
|
+
return fitsText(render(result)) && structuredBytes(wireResult(result)) <= TOOL_OUTPUT_MAX_BYTES;
|
|
31
30
|
}
|
|
32
31
|
/** `text` is verbatim, with no marker inserted, so windows concatenate back into the source. */
|
|
33
32
|
export const TextWindowSchema = Type.Object({
|
|
@@ -40,7 +39,7 @@ export const TextWindowSchema = Type.Object({
|
|
|
40
39
|
* because `readTextWindow` already owns the defaults.
|
|
41
40
|
*/
|
|
42
41
|
export const TextWindowRequestSchema = {
|
|
43
|
-
offset_chars: Type.Optional(Type.Integer({ description: "
|
|
42
|
+
offset_chars: Type.Optional(Type.Integer({ description: "Character offset to start reading (negative counts from the end)." })),
|
|
44
43
|
max_chars: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much to read at once." })),
|
|
45
44
|
};
|
|
46
45
|
/**
|
|
@@ -51,7 +50,7 @@ export const TextWindowRequestSchema = {
|
|
|
51
50
|
* An envelope that cannot fit even empty is refused instead of returned: a zero-length window
|
|
52
51
|
* would resume at the offset it started from, so paging could never make progress.
|
|
53
52
|
*/
|
|
54
|
-
export function readTextWindow(text, offset, limit, makeData, render) {
|
|
53
|
+
export function readTextWindow(text, offset, limit, makeData, render, fitsOutcome = (result) => fitsText(render(result))) {
|
|
55
54
|
const chars = Array.from(text);
|
|
56
55
|
const requested = offset ?? 0;
|
|
57
56
|
const start = requested < 0 ? Math.max(0, chars.length + requested) : requested;
|
|
@@ -66,7 +65,7 @@ export function readTextWindow(text, offset, limit, makeData, render) {
|
|
|
66
65
|
next_offset_chars: end < chars.length ? end : null,
|
|
67
66
|
};
|
|
68
67
|
};
|
|
69
|
-
const fits = (delivered) =>
|
|
68
|
+
const fits = (delivered) => fitsOutcome(success(makeData(window(delivered))));
|
|
70
69
|
// Test the full range first: its footer can disappear at the end of the document, and an
|
|
71
70
|
// empty source is a complete window rather than a refusal.
|
|
72
71
|
if (fits(range))
|
|
@@ -80,5 +79,5 @@ export function readTextWindow(text, offset, limit, makeData, render) {
|
|
|
80
79
|
/** The continuation line never becomes part of `window.text`, and a complete window has none. */
|
|
81
80
|
export function renderTextWindow(window) {
|
|
82
81
|
const next = window.next_offset_chars;
|
|
83
|
-
return next === null ? window.text : `${window.text}\n\n[truncated; continue at offset_chars=${next}]`;
|
|
82
|
+
return next === null ? window.text : `${window.text}\n\n[truncated at ${next}/${window.total_chars} chars; continue at offset_chars=${next}]`;
|
|
84
83
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Type, type TSchema } from "typebox";
|
|
2
|
-
export
|
|
2
|
+
export { stringEnum } from "../history/history.js";
|
|
3
|
+
export declare const historyRoles: (foldsWithoutRoles?: boolean) => Type.TOptional<Type.TArray<Type.TUnsafe<"user" | "assistant" | "tool" | "context">>>;
|
|
3
4
|
/** First parameter violation; skip false subschemas so additionalProperties can name the field. */
|
|
4
5
|
export declare function paramProblem(schema: TSchema, params: unknown): string;
|
|
5
6
|
/** Search query parameter: one literal, or several literals combined with OR. */
|
|
6
7
|
export declare const searchQuery: (description?: string) => Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
|
|
8
|
+
/** Strict ISO date or timestamp; a missing offset denotes the host local timezone. */
|
|
9
|
+
export declare function parseIsoTimestamp(value: string): number | undefined;
|
package/dist/src/tools/schema.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { Errors } from "typebox/value";
|
|
3
3
|
import { HistoryRoleSchema } from "../history/history.js";
|
|
4
|
-
export
|
|
4
|
+
export { stringEnum } from "../history/history.js";
|
|
5
|
+
export const historyRoles = (foldsWithoutRoles = false) => Type.Optional(Type.Array(HistoryRoleSchema, { minItems: 1, description: "Filter by event role." + (foldsWithoutRoles ? " Omit to fold tool and context runs." : "") }));
|
|
5
6
|
/** First parameter violation; skip false subschemas so additionalProperties can name the field. */
|
|
6
7
|
export function paramProblem(schema, params) {
|
|
7
8
|
const first = Errors(schema, params).find((error) => error.keyword !== "boolean");
|
|
@@ -13,3 +14,26 @@ export function paramProblem(schema, params) {
|
|
|
13
14
|
}
|
|
14
15
|
/** Search query parameter: one literal, or several literals combined with OR. */
|
|
15
16
|
export const searchQuery = (description = "Text to look for, or a list (any match). Leave it out to just list the pages.") => Type.Union([Type.String(), Type.Array(Type.String())], { description });
|
|
17
|
+
/** Strict ISO date or timestamp; a missing offset denotes the host local timezone. */
|
|
18
|
+
export function parseIsoTimestamp(value) {
|
|
19
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:?\d{2})?)?$/.exec(value);
|
|
20
|
+
if (!match)
|
|
21
|
+
return undefined;
|
|
22
|
+
const year = Number(match[1]), month = Number(match[2]), day = Number(match[3]);
|
|
23
|
+
const hour = Number(match[4] ?? 0), minute = Number(match[5] ?? 0), second = Number(match[6] ?? 0);
|
|
24
|
+
if (hour > 23 || minute > 59 || second > 59)
|
|
25
|
+
return undefined;
|
|
26
|
+
const check = new Date(0);
|
|
27
|
+
check.setUTCFullYear(year, month - 1, day);
|
|
28
|
+
if (check.getUTCFullYear() !== year || check.getUTCMonth() !== month - 1 || check.getUTCDate() !== day)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (match[8]) {
|
|
31
|
+
const at = Date.parse(value);
|
|
32
|
+
return Number.isFinite(at) ? at : undefined;
|
|
33
|
+
}
|
|
34
|
+
const ms = match[7] ? Number(match[7].slice(0, 3).padEnd(3, "0")) : 0;
|
|
35
|
+
const local = new Date(year, month - 1, day, hour, minute, second, ms);
|
|
36
|
+
// Years 0000-0099 map to 1900+ through the Date constructor; set them back explicitly.
|
|
37
|
+
local.setFullYear(year, month - 1, day);
|
|
38
|
+
return Number.isFinite(local.getTime()) ? local.getTime() : undefined;
|
|
39
|
+
}
|