notesoup 0.61.0 → 0.63.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 +24 -5
- package/dist/plugins/claude/src/text.d.ts +7 -0
- package/dist/plugins/claude/src/text.js +12 -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 +4 -1
- package/dist/plugins/pi/budget.js +35 -8
- package/dist/plugins/pi/entries.d.ts +2 -0
- package/dist/plugins/pi/entries.js +2 -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/artifacts.d.ts +1 -1
- package/dist/plugins/pi/reset/artifacts.js +4 -4
- package/dist/plugins/pi/reset/lifecycle.d.ts +9 -2
- package/dist/plugins/pi/reset/lifecycle.js +109 -31
- package/dist/plugins/pi/runtime.js +104 -63
- package/dist/plugins/pi/tool-result.js +7 -7
- package/dist/plugins/pi/window.d.ts +25 -3
- package/dist/plugins/pi/window.js +219 -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 +7 -3
- package/dist/src/budget/text.js +24 -15
- 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 +2 -2
- 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 +394 -56
- 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 +156 -15
- package/dist/test/budget-settings.integration.test.js +4 -4
- package/dist/test/claude-history.test.js +14 -13
- package/dist/test/claude-mod.test.js +199 -16
- package/dist/test/claude-validation.test.js +69 -2
- 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 +68 -3
- package/dist/test/helpers/extension.js +74 -5
- 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/model-facing-text.test.js +13 -3
- 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 +12 -2
- package/docs/antigravity.md +44 -0
- package/docs/architecture.md +6 -4
- package/docs/claude-code-mod.md +7 -7
- 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/reset-lifecycle.md +1 -1
- 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 +1108 -539
- package/plugins/claude/hooks/register.ts +202 -62
- package/plugins/claude/playbook.md +1 -1
- package/plugins/claude/skills/dream/SKILL.md +1 -1
- package/plugins/claude/skills/notesoup-guide/SKILL.md +92 -0
- package/plugins/claude/src/helper.ts +24 -5
- package/plugins/claude/src/text.ts +14 -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 +31 -8
- package/plugins/pi/entries.ts +2 -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/artifacts.ts +4 -3
- package/plugins/pi/reset/lifecycle.ts +125 -32
- package/plugins/pi/runtime.ts +98 -62
- package/plugins/pi/tool-result.ts +8 -8
- package/plugins/pi/window.ts +210 -10
- package/skills/dream/SKILL.md +1 -1
- package/skills/notesoup-guide/SKILL.md +92 -0
- package/src/boot/render.ts +18 -15
- package/src/boot/text.ts +23 -19
- package/src/budget/text.ts +27 -15
- 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 +2 -2
- 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/src/tools/notes.ts
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import type { NotesIdentity } from "../notes/identity.js";
|
|
2
2
|
import { assertAddress } from "../notes/address.js";
|
|
3
3
|
import { noteFileName } from "../notes/paths.js";
|
|
4
|
-
import { effectiveNotePolicy,
|
|
4
|
+
import { effectiveNotePolicy, noteDescriptionWarnings, noteWarnings, renderWarnings } from "../notes/policy.js";
|
|
5
5
|
import { Type, type Static } from "typebox";
|
|
6
6
|
import { localIso } from "../notes/frontmatter.js";
|
|
7
7
|
import { isFilesystemError } from "../notes/fs-error.js";
|
|
8
|
-
import { createNotesStore, NoteError, noteIdentity, type NoteChange, type NoteMeta, type NoteQueryStatus, type NoteRow } from "../notes/index.js";
|
|
8
|
+
import { compareNoteRows, createNotesStore, NoteError, noteIdentity, type NoteChange, type NotePolicy, type NoteMeta, type NoteQueryStatus, type NoteRow, type NoteSearchRow } from "../notes/index.js";
|
|
9
9
|
import { TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
10
10
|
import { failure, success, type Outcome } from "../result.js";
|
|
11
11
|
import { InvalidQueryError, prefixFit, searchQueries } from "../text-match.js";
|
|
12
|
-
import { fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
13
|
-
import { searchQuery } from "./schema.js";
|
|
12
|
+
import { fitsResult, fitsText, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
13
|
+
import { parseIsoTimestamp, searchQuery, stringEnum } from "./schema.js";
|
|
14
14
|
import { notesIdentityForCall, type NotesToolContext } from "./notes-context.js";
|
|
15
15
|
|
|
16
|
-
const ORIGIN_VALUES = [
|
|
17
|
-
const ORIGIN = Type.Optional(
|
|
18
|
-
description: "
|
|
16
|
+
const ORIGIN_VALUES = ["user", "self", "external"] as const;
|
|
17
|
+
const ORIGIN = Type.Optional(stringEnum(ORIGIN_VALUES, {
|
|
18
|
+
description: "Author tag. Omit to keep existing.",
|
|
19
19
|
}));
|
|
20
|
-
const DESCRIPTION_PARAMETER = Type.Optional(Type.String({ description: "One-line summary
|
|
20
|
+
const DESCRIPTION_PARAMETER = Type.Optional(Type.String({ description: "One-line summary for the boot index (empty string clears it)." }));
|
|
21
21
|
const POLICY_PARAMETERS = {
|
|
22
|
-
pinned: Type.Optional(Type.Boolean({ description: "
|
|
23
|
-
|
|
24
|
-
readonly: Type.Optional(Type.Boolean({ description: "A paperclip that keeps your own hands off. `false` takes it off — same call is fine." })),
|
|
22
|
+
pinned: Type.Optional(Type.Boolean({ description: "Inject at wake-up (truncated to byte budget if oversized)." })),
|
|
23
|
+
readonly: Type.Optional(Type.Boolean({ description: "Soft lock against edits, moves, and deletion." })),
|
|
25
24
|
};
|
|
26
25
|
const PolicySchema = {
|
|
27
26
|
pinned: Type.Boolean(), budget: Type.Integer(), readonly: Type.Boolean(),
|
|
@@ -30,19 +29,29 @@ const WarningsSchema = { warnings: Type.Array(Type.String()) };
|
|
|
30
29
|
function policyAt(meta: NoteMeta, address: string) {
|
|
31
30
|
return effectiveNotePolicy(meta, noteFileName(assertAddress(address).path));
|
|
32
31
|
}
|
|
33
|
-
function renderPolicy(policy:
|
|
32
|
+
function renderPolicy(policy: NotePolicy): string {
|
|
34
33
|
return `pinned ${policy.pinned} | budget ${policy.budget} | readonly ${policy.readonly}`;
|
|
35
34
|
}
|
|
35
|
+
/** Only policy that differs from the note's own path defaults; an ordinary note renders nothing. */
|
|
36
|
+
function renderSparsePolicy(policy: NotePolicy, address: string): string {
|
|
37
|
+
const defaults = effectiveNotePolicy({}, noteFileName(assertAddress(address).path));
|
|
38
|
+
const tokens: string[] = [];
|
|
39
|
+
if (policy.pinned) tokens.push("pinned");
|
|
40
|
+
else if (defaults.pinned) tokens.push("pinned false");
|
|
41
|
+
if (policy.budget !== defaults.budget) tokens.push(`budget ${policy.budget}`);
|
|
42
|
+
if (policy.readonly) tokens.push("readonly");
|
|
43
|
+
return tokens.join(" | ");
|
|
44
|
+
}
|
|
36
45
|
function withWarnings(text: string, data: { warnings: string[] }): string {
|
|
37
|
-
return
|
|
46
|
+
return data.warnings.length === 0 ? text : `${text}\n${renderWarnings(data.warnings)}`;
|
|
38
47
|
}
|
|
39
48
|
|
|
40
|
-
const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "`true`
|
|
41
|
-
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "
|
|
42
|
-
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "
|
|
43
|
-
const GLOB_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "
|
|
49
|
+
const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "Crumple (`true`) or restore (`false`) the note." }));
|
|
50
|
+
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "List crumpled notes instead of live ones." }));
|
|
51
|
+
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "Maximum notes to return." }));
|
|
52
|
+
const GLOB_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Address glob. Omit for current notebooks; `**` for all; `@projects/*/**` or `@sessions/*/**` for named notebooks." }));
|
|
44
53
|
const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "Treat this directory's project as `@project/`." }));
|
|
45
|
-
const ADDRESS_PARAMETER = Type.String({ description: "
|
|
54
|
+
const ADDRESS_PARAMETER = Type.String({ description: "Note address (per boot protocol). Never pass `@` addresses to filesystem tools." });
|
|
46
55
|
|
|
47
56
|
/**
|
|
48
57
|
* Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
|
|
@@ -66,7 +75,7 @@ const TOO_LARGE_EXTRA_VALUE = "[omitted: too large]";
|
|
|
66
75
|
|
|
67
76
|
export const NoteMetadataSchema = Type.Object({
|
|
68
77
|
...PolicySchema,
|
|
69
|
-
origin:
|
|
78
|
+
origin: stringEnum(ORIGIN_VALUES),
|
|
70
79
|
created_at: Type.String(),
|
|
71
80
|
updated_at: Type.String(),
|
|
72
81
|
crumpled_at: Type.Optional(Type.String()),
|
|
@@ -145,42 +154,9 @@ export const NoteIdentitySchema = {
|
|
|
145
154
|
...ProjectReceiptSchema,
|
|
146
155
|
};
|
|
147
156
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
...WarningsSchema,
|
|
152
|
-
updated_at: Type.String(),
|
|
153
|
-
crumpled_at: Type.Optional(Type.String()),
|
|
154
|
-
description: Type.Optional(Type.String()),
|
|
155
|
-
}, { additionalProperties: false });
|
|
156
|
-
|
|
157
|
-
const MatchSchema = Type.Object({
|
|
158
|
-
line: Type.Integer(),
|
|
159
|
-
text: Type.String(),
|
|
160
|
-
offset_chars: Type.Integer(),
|
|
161
|
-
}, { additionalProperties: false });
|
|
162
|
-
|
|
163
|
-
export const SnapshotSchema = {
|
|
164
|
-
more: Type.Integer({ description: "How many more were left out." }),
|
|
165
|
-
namespaces_unavailable: Type.Array(Type.String(), { description: "Unreadable notebooks or notes." }),
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
export const NotesWriteDataSchema = Type.Object({
|
|
169
|
-
...NoteIdentitySchema,
|
|
170
|
-
...PolicySchema,
|
|
171
|
-
...WarningsSchema,
|
|
172
|
-
outcome: Type.Union([Type.Literal("created"), Type.Literal("overwrote"), Type.Literal("uncrumpled")]),
|
|
173
|
-
}, { additionalProperties: false });
|
|
174
|
-
export type NotesWriteData = Static<typeof NotesWriteDataSchema>;
|
|
175
|
-
|
|
176
|
-
export const NotesUpdateDataSchema = Type.Object({
|
|
177
|
-
...NoteIdentitySchema,
|
|
178
|
-
...PolicySchema,
|
|
179
|
-
...WarningsSchema,
|
|
180
|
-
change_kind: Type.Union([Type.Literal("none"), Type.Literal("body"), Type.Literal("metadata"), Type.Literal("moved")]),
|
|
181
|
-
rename_from: Type.Optional(Type.String()),
|
|
182
|
-
}, { additionalProperties: false });
|
|
183
|
-
export type NotesUpdateData = Static<typeof NotesUpdateDataSchema>;
|
|
157
|
+
type NoteReceipt = ReturnType<typeof noteIdentity> & NotePolicy & { warnings: string[] };
|
|
158
|
+
export type NotesWriteData = NoteReceipt & { outcome: "created" | "overwrote" | "uncrumpled" };
|
|
159
|
+
export type NotesUpdateData = NoteReceipt & { change_kind: NoteChange["kind"] | "moved"; rename_from?: string };
|
|
184
160
|
|
|
185
161
|
export const NotesReadDataSchema = Type.Object({
|
|
186
162
|
...NoteIdentitySchema,
|
|
@@ -190,18 +166,11 @@ export const NotesReadDataSchema = Type.Object({
|
|
|
190
166
|
}, { additionalProperties: false });
|
|
191
167
|
export type NotesReadData = Static<typeof NotesReadDataSchema>;
|
|
192
168
|
|
|
193
|
-
export
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
...SnapshotSchema,
|
|
199
|
-
}, { additionalProperties: false });
|
|
200
|
-
export type NotesListData = Static<typeof NotesListDataSchema>;
|
|
201
|
-
type ListedFile = Static<typeof ListedFileSchema>;
|
|
202
|
-
type SearchFile = ListedFile & { matches: Static<typeof MatchSchema>[]; more_matches?: number };
|
|
203
|
-
|
|
204
|
-
type Snapshot<T> = Omit<NotesListData, "files"> & { files: T[] };
|
|
169
|
+
export type ListedFile = NoteReceipt & { updated_at: string; crumpled_at?: string; description?: string };
|
|
170
|
+
type Match = { line: number; text: string; offset_chars: number };
|
|
171
|
+
type ListFile = ListedFile & { matches?: Match[]; more_matches?: number };
|
|
172
|
+
export type Snapshot<T> = { files: T[]; more: number; namespaces_unavailable: string[] };
|
|
173
|
+
export type NotesListData = Snapshot<ListFile> & { older?: string };
|
|
205
174
|
|
|
206
175
|
/** Keep identities intact. Only search previews may shrink to make the first row fit. */
|
|
207
176
|
export function snapshot<T extends { address: string }>(
|
|
@@ -214,7 +183,7 @@ export function snapshot<T extends { address: string }>(
|
|
|
214
183
|
const files: T[] = [];
|
|
215
184
|
const data = (selected: T[]): Snapshot<T> => ({ files: selected, more: rows.length - selected.length, namespaces_unavailable: status.namespacesUnavailable });
|
|
216
185
|
const render = (outcome: Outcome<Snapshot<T>>) => renderOutcome(outcome, renderData);
|
|
217
|
-
const fits = (item: T) =>
|
|
186
|
+
const fits = (item: T) => fitsText(render(success(data([...files, item]))));
|
|
218
187
|
for (const item of rows.slice(0, limit)) {
|
|
219
188
|
if (fits(item)) {
|
|
220
189
|
files.push(item);
|
|
@@ -228,28 +197,30 @@ export function snapshot<T extends { address: string }>(
|
|
|
228
197
|
break;
|
|
229
198
|
}
|
|
230
199
|
const outcome = success(data(files));
|
|
231
|
-
return
|
|
200
|
+
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.`);
|
|
232
201
|
}
|
|
233
202
|
|
|
234
203
|
export function listedFile(row: Pick<NoteRow, "address" | "meta"> & { body?: string; warnings?: string[] }, identity: NotesIdentity): ListedFile {
|
|
235
204
|
const policy = policyAt(row.meta, row.address);
|
|
236
|
-
|
|
205
|
+
const warnings = row.warnings ?? (row.body === undefined ? noteDescriptionWarnings(row.meta.description) : noteWarnings(row.body, policy, row.meta.description));
|
|
206
|
+
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 } : {}) };
|
|
237
207
|
}
|
|
238
208
|
|
|
239
|
-
export const notesWriteParameters = Type.Object({ address: ADDRESS_PARAMETER, content: Type.String({ description: "
|
|
209
|
+
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 });
|
|
240
210
|
|
|
241
211
|
function renderWriteData(data: NotesWriteData): string {
|
|
242
|
-
|
|
212
|
+
const sparse = renderSparsePolicy(data, data.address);
|
|
213
|
+
return withWarnings(`${data.outcome} ${renderIdentity(data)}${sparse === "" ? "" : ` | ${sparse}`}`, data);
|
|
243
214
|
}
|
|
244
215
|
|
|
245
216
|
export const notesWrite = {
|
|
246
217
|
name: "notes_write", label: "Notes write",
|
|
247
|
-
description: "
|
|
248
|
-
parameters: notesWriteParameters,
|
|
218
|
+
description: "Create or overwrite a note. Set `description` (one line) so boot indexes it.",
|
|
219
|
+
parameters: notesWriteParameters, executionMode: "sequential",
|
|
249
220
|
async execute(params: Static<typeof notesWriteParameters>, context: NotesToolContext): Promise<Outcome<NotesWriteData>> {
|
|
250
221
|
try {
|
|
251
222
|
const identity = notesIdentityForCall(context, params.cwd);
|
|
252
|
-
const { outcome, meta, warnings } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin, description: params.description, pinned: params.pinned,
|
|
223
|
+
const { outcome, meta, warnings } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin, description: params.description, pinned: params.pinned, readonly: params.readonly });
|
|
253
224
|
return success({ ...noteIdentity(identity, params.address), outcome, ...policyAt(meta, params.address), warnings });
|
|
254
225
|
} catch (error) { return failureOf(error); }
|
|
255
226
|
},
|
|
@@ -258,13 +229,17 @@ export const notesWrite = {
|
|
|
258
229
|
|
|
259
230
|
export const notesUpdateParameters = Type.Object({
|
|
260
231
|
address: ADDRESS_PARAMETER,
|
|
261
|
-
edits: Type.Optional(Type.Array(Type.Object({
|
|
232
|
+
edits: Type.Optional(Type.Array(Type.Object({
|
|
233
|
+
oldText: Type.String({ description: "Exact text to replace." }),
|
|
234
|
+
newText: Type.String({ description: "Replacement text." }),
|
|
235
|
+
replace_all: Type.Optional(Type.Boolean({ description: "Replace every occurrence (overrides top-level `replace_all`)." })),
|
|
236
|
+
}, { additionalProperties: false }), { description: "Sequential exact text replacements." })),
|
|
262
237
|
origin: ORIGIN,
|
|
263
238
|
description: DESCRIPTION_PARAMETER,
|
|
264
239
|
...POLICY_PARAMETERS,
|
|
265
240
|
crumpled: CRUMPLED_PARAMETER,
|
|
266
|
-
replace_all: Type.Optional(Type.Boolean({ description: "
|
|
267
|
-
rename_to: Type.Optional(Type.String({ description: "Move
|
|
241
|
+
replace_all: Type.Optional(Type.Boolean({ description: "Replace every occurrence in edits that omit `replace_all`." })),
|
|
242
|
+
rename_to: Type.Optional(Type.String({ description: "Move note to this address." })),
|
|
268
243
|
cwd: CWD_PARAMETER,
|
|
269
244
|
}, { additionalProperties: false });
|
|
270
245
|
|
|
@@ -272,20 +247,22 @@ function renderUpdateData(data: NotesUpdateData): string {
|
|
|
272
247
|
const receipt = data.rename_from === undefined
|
|
273
248
|
? `${data.change_kind === "none" ? "unchanged" : "updated"} ${renderIdentity(data)}`
|
|
274
249
|
: `moved ${data.rename_from} -> ${data.address}`;
|
|
275
|
-
|
|
250
|
+
const sparse = renderSparsePolicy(data, data.address);
|
|
251
|
+
return withWarnings(`${receipt}${sparse === "" ? "" : ` | ${sparse}`}`, data);
|
|
276
252
|
}
|
|
277
253
|
|
|
278
254
|
export const notesUpdate = {
|
|
279
255
|
name: "notes_update", label: "Notes update",
|
|
280
|
-
description: "
|
|
281
|
-
parameters: notesUpdateParameters,
|
|
256
|
+
description: "Edit an existing note's text or metadata, move it (`rename_to`), or crumple/restore it (`crumpled`).",
|
|
257
|
+
parameters: notesUpdateParameters, executionMode: "sequential",
|
|
282
258
|
async execute(params: Static<typeof notesUpdateParameters>, context: NotesToolContext, onChange?: (change: NoteChange) => void): Promise<Outcome<NotesUpdateData>> {
|
|
283
259
|
try {
|
|
284
260
|
const identity = notesIdentityForCall(context, params.cwd);
|
|
285
261
|
const store = createNotesStore(identity);
|
|
286
262
|
// Empty filler is not a request: models that pass every parameter get the edit path.
|
|
287
263
|
const renameTo = params.rename_to === "" ? undefined : params.rename_to;
|
|
288
|
-
const
|
|
264
|
+
const edits = params.edits?.map((edit) => ({ oldText: edit.oldText, newText: edit.newText, ...(edit.replace_all === undefined ? {} : { replaceAll: edit.replace_all }) }));
|
|
265
|
+
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 });
|
|
289
266
|
onChange?.(change);
|
|
290
267
|
const from = noteIdentity(identity, params.address).address;
|
|
291
268
|
const to = noteIdentity(identity, renameTo ?? params.address);
|
|
@@ -303,7 +280,7 @@ function renderReadData(data: NotesReadData): string {
|
|
|
303
280
|
|
|
304
281
|
export const notesRead = {
|
|
305
282
|
name: "notes_read", label: "Notes read",
|
|
306
|
-
description: "Read a
|
|
283
|
+
description: "Read a note (supports windowed reads via `offset_chars` and `max_chars`).",
|
|
307
284
|
parameters: notesReadParameters, outputSchema: resultSchema(NotesReadDataSchema),
|
|
308
285
|
async execute(params: Static<typeof notesReadParameters>, context: NotesToolContext): Promise<Outcome<NotesReadData>> {
|
|
309
286
|
try {
|
|
@@ -314,8 +291,9 @@ export const notesRead = {
|
|
|
314
291
|
const totalChars = Array.from(note.body).length;
|
|
315
292
|
if (params.offset_chars !== undefined && params.offset_chars > totalChars) return failure("invalid_offset", `This note ends at char ${totalChars}; offset_chars ${params.offset_chars} is past the last word.`);
|
|
316
293
|
const metadata = noteMetadata(note.meta, resolved.address);
|
|
317
|
-
const warnings =
|
|
318
|
-
|
|
294
|
+
const warnings = noteWarnings(note.body, metadata, metadata.description);
|
|
295
|
+
const render = (result: Outcome<NotesReadData>) => renderOutcome(result, renderReadData);
|
|
296
|
+
return readTextWindow(note.body, params.offset_chars, params.max_chars, (window) => ({ ...resolved, metadata, warnings, ...window }), render, (result) => fitsResult(result, render));
|
|
319
297
|
} catch (error) { return failureOf(error); }
|
|
320
298
|
},
|
|
321
299
|
render: (result: Outcome<NotesReadData>): string => renderOutcome(result, renderReadData),
|
|
@@ -323,74 +301,128 @@ export const notesRead = {
|
|
|
323
301
|
|
|
324
302
|
export const notesListParameters = Type.Object({
|
|
325
303
|
glob: GLOB_PARAMETER,
|
|
326
|
-
query: Type.Optional(searchQuery()),
|
|
327
|
-
|
|
304
|
+
query: Type.Optional(searchQuery("Case-insensitive literal text, or a list (any match). Omit to list.")),
|
|
305
|
+
max_matches_per_note: Type.Optional(Type.Integer({ minimum: 1, description: "Maximum matching lines shown per note." })),
|
|
328
306
|
crumpled: CRUMPLED_LIST_PARAMETER,
|
|
329
307
|
limit: FILE_LIMIT_PARAMETER,
|
|
308
|
+
cursor: Type.Optional(Type.String({ description: "Cursor from an `→ older` footer (`<updated_at> <address>`)." })),
|
|
330
309
|
cwd: CWD_PARAMETER,
|
|
331
310
|
}, { additionalProperties: false });
|
|
332
311
|
|
|
333
|
-
|
|
312
|
+
function moreMatches(more: number, tail: string): string {
|
|
313
|
+
return `${more} more matching ${more === 1 ? "note" : "notes"}${tail}`;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function renderListData<T extends NotesListData["files"][number] & { last_accessed?: string }>(data: Snapshot<T>, renderMore: (more: number, files: T[]) => string = (more) => moreMatches(more, " omitted; narrow with glob"), options: { omitNamedProjectContext?: boolean } = {}): string {
|
|
334
317
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
335
318
|
for (const file of data.files) {
|
|
336
|
-
|
|
319
|
+
// The current project is already the context of a `@project/` row; named notebooks keep their receipt.
|
|
320
|
+
const identity = file.address.startsWith("@project/") || options.omitNamedProjectContext
|
|
321
|
+
? renderIdentity({ address: file.address })
|
|
322
|
+
: renderIdentity(file);
|
|
323
|
+
const sparse = renderSparsePolicy(file, file.address);
|
|
324
|
+
const fields = [`- ${identity}${file.description === undefined ? "" : ` — ${file.description}`}`, ...(sparse === "" ? [] : [sparse]), `updated ${file.updated_at}`];
|
|
337
325
|
if (file.last_accessed !== undefined) fields.push(`accessed ${file.last_accessed}`);
|
|
338
326
|
if (file.crumpled_at !== undefined) fields.push(`crumpled ${file.crumpled_at}`);
|
|
339
327
|
if (file.matches) fields.push(`${file.matches.length} ${file.matches.length === 1 ? "match" : "matches"}${file.more_matches ? `, ${file.more_matches} more lines` : ""}`);
|
|
340
328
|
lines.push(fields.join(" | "));
|
|
341
|
-
lines.push(...file.warnings.map(warning => ` ${warning}`));
|
|
329
|
+
lines.push(...file.warnings.map(warning => ` ${renderWarnings([warning])}`));
|
|
342
330
|
for (const match of file.matches ?? []) lines.push(` line ${match.line} at offset_chars ${match.offset_chars}: ${match.text}`);
|
|
343
331
|
}
|
|
344
|
-
if (data.more > 0) lines.push(
|
|
332
|
+
if (data.more > 0) lines.push(renderMore(data.more, data.files));
|
|
345
333
|
for (const namespace of data.namespaces_unavailable) lines.push(`${namespace} could not be read`);
|
|
346
334
|
return lines.join("\n");
|
|
347
335
|
}
|
|
348
336
|
|
|
349
|
-
function keepMatches(file:
|
|
350
|
-
const
|
|
351
|
-
|
|
337
|
+
function keepMatches(file: ListFile, count = file.matches?.length ?? 0): ListFile {
|
|
338
|
+
const matches = file.matches ?? [];
|
|
339
|
+
const more = (file.more_matches ?? 0) + Math.max(0, matches.length - count);
|
|
340
|
+
return { ...file, matches: matches.slice(0, count), ...(more ? { more_matches: more } : {}) };
|
|
352
341
|
}
|
|
353
342
|
|
|
354
343
|
/** A shortened match line still ends with a marker, so its own text says it was cut. */
|
|
355
344
|
export const MATCH_SHORTENED_MARKER = " [truncated]";
|
|
356
345
|
|
|
357
346
|
/** Prefer whole match lines; shorten the first line only if no whole line fits, and mark it. */
|
|
358
|
-
function fitSearchFile(file:
|
|
347
|
+
function fitSearchFile(file: ListFile, fits: (candidate: ListFile) => boolean): ListFile {
|
|
348
|
+
const matches = file.matches ?? [];
|
|
359
349
|
let low = 0;
|
|
360
|
-
let high =
|
|
350
|
+
let high = matches.length;
|
|
361
351
|
while (low < high) {
|
|
362
352
|
const mid = Math.ceil((low + high) / 2);
|
|
363
353
|
if (fits(keepMatches(file, mid))) low = mid;
|
|
364
354
|
else high = mid - 1;
|
|
365
355
|
}
|
|
366
|
-
if (low > 0 ||
|
|
367
|
-
const first =
|
|
368
|
-
const withText = (text: string):
|
|
356
|
+
if (low > 0 || matches.length === 0) return keepMatches(file, low);
|
|
357
|
+
const first = matches[0]!;
|
|
358
|
+
const withText = (text: string): ListFile => ({ ...keepMatches(file, 1), matches: [{ ...first, text: `${text}${MATCH_SHORTENED_MARKER}` }] });
|
|
369
359
|
return withText(prefixFit(first.text, text => fits(withText(text))));
|
|
370
360
|
}
|
|
371
361
|
|
|
362
|
+
type ListCursor = { atMs: number; address: string };
|
|
363
|
+
|
|
364
|
+
function parseCursor(raw: string | undefined, identity: NotesIdentity): Outcome<ListCursor | undefined> {
|
|
365
|
+
if (raw === undefined || raw === "") return success(undefined);
|
|
366
|
+
const space = raw.indexOf(" ");
|
|
367
|
+
if (space <= 0 || space === raw.length - 1) return failure("invalid_params", "`cursor` must be `<updated_at> <address>`.");
|
|
368
|
+
const atMs = parseIsoTimestamp(raw.slice(0, space));
|
|
369
|
+
if (atMs === undefined) return failure("invalid_params", "`cursor` starts with an invalid ISO 8601 timestamp.");
|
|
370
|
+
try {
|
|
371
|
+
return success({ atMs, address: noteIdentity(identity, raw.slice(space + 1)).address });
|
|
372
|
+
} catch {
|
|
373
|
+
return failure("invalid_params", "`cursor` ends with an invalid note address.");
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** Newest first, address ascending on a tie; a cursor keeps only the pages strictly after itself. */
|
|
378
|
+
function olderThan(file: ListFile, cursor: ListCursor): boolean {
|
|
379
|
+
const atMs = parseIsoTimestamp(file.updated_at)!;
|
|
380
|
+
return atMs < cursor.atMs || (atMs === cursor.atMs && file.address.localeCompare(cursor.address) > 0);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function renderOlderPage(more: number, files: ListFile[], params: Static<typeof notesListParameters>, searching: boolean): string {
|
|
384
|
+
const last = files[files.length - 1];
|
|
385
|
+
if (last === undefined) return moreMatches(more, " omitted; narrow glob");
|
|
386
|
+
const next: Record<string, unknown> = {};
|
|
387
|
+
if (params.glob !== undefined) next.glob = params.glob;
|
|
388
|
+
if (searching) next.query = params.query;
|
|
389
|
+
if (params.max_matches_per_note !== undefined) next.max_matches_per_note = params.max_matches_per_note;
|
|
390
|
+
if (params.crumpled !== undefined) next.crumpled = params.crumpled;
|
|
391
|
+
if (params.limit !== undefined) next.limit = params.limit;
|
|
392
|
+
if (params.cwd !== undefined) next.cwd = params.cwd;
|
|
393
|
+
next.cursor = `${last.updated_at} ${last.address}`;
|
|
394
|
+
return moreMatches(more, ` | → older: ${JSON.stringify(next)}`);
|
|
395
|
+
}
|
|
396
|
+
|
|
372
397
|
export const notesList = {
|
|
373
398
|
name: "notes_list", label: "Notes list",
|
|
374
|
-
description: "List or search notes, newest
|
|
375
|
-
parameters: notesListParameters,
|
|
399
|
+
description: "List or search notes, newest first. Literal case-insensitive `query` returns matching lines and `offset_chars`.",
|
|
400
|
+
parameters: notesListParameters,
|
|
376
401
|
async execute(params: Static<typeof notesListParameters>, context: NotesToolContext): Promise<Outcome<NotesListData>> {
|
|
377
402
|
try {
|
|
378
403
|
const queries = searchQueries(params.query);
|
|
379
404
|
const { glob, crumpled, limit } = params;
|
|
380
|
-
if (!queries.length && params.
|
|
405
|
+
if (!queries.length && params.max_matches_per_note !== undefined) return failure("invalid_params", "`max_matches_per_note` requires a non-empty `query`.");
|
|
381
406
|
const identity = notesIdentityForCall(context, params.cwd);
|
|
407
|
+
const cursor = parseCursor(params.cursor, identity);
|
|
408
|
+
if (!cursor.ok) return cursor;
|
|
382
409
|
const store = createNotesStore(identity);
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const files = rows.
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
410
|
+
const result = queries.length
|
|
411
|
+
? await store.searchWithStatus(queries, { glob, crumpled })
|
|
412
|
+
: await store.listWithStatus({ glob, crumpled });
|
|
413
|
+
const rows: Array<NoteRow | NoteSearchRow> = result.rows;
|
|
414
|
+
rows.sort(compareNoteRows);
|
|
415
|
+
const files = rows.map(row => "matches" in row
|
|
416
|
+
? keepMatches({
|
|
417
|
+
...listedFile(row, identity),
|
|
418
|
+
matches: row.matches.map(match => ({ line: match.line, text: match.text, offset_chars: match.offsetChars })),
|
|
419
|
+
}, params.max_matches_per_note)
|
|
420
|
+
: listedFile(row, identity));
|
|
421
|
+
const page = files.filter(file => cursor.data === undefined || olderThan(file, cursor.data));
|
|
422
|
+
const outcome = snapshot(page, limit, result.status, data => renderListData(data, (more, shown) => renderOlderPage(more, shown, params, queries.length > 0)), queries.length ? fitSearchFile : undefined);
|
|
423
|
+
if (!outcome.ok || outcome.data.more === 0) return outcome;
|
|
424
|
+
return success({ ...outcome.data, older: renderOlderPage(outcome.data.more, outcome.data.files, params, queries.length > 0) });
|
|
393
425
|
} catch (error) { return failureOf(error); }
|
|
394
426
|
},
|
|
395
|
-
render: (result: Outcome<NotesListData>): string => renderOutcome(result, renderListData),
|
|
427
|
+
render: (result: Outcome<NotesListData>): string => renderOutcome(result, data => renderListData(data, more => data.older ?? moreMatches(more, " omitted; narrow with glob"))),
|
|
396
428
|
} as const;
|
package/src/tools/output.ts
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;
|
package/src/tools/result.ts
CHANGED
|
@@ -29,12 +29,12 @@ export function structuredBytes(value: unknown): number {
|
|
|
29
29
|
return Buffer.byteLength(JSON.stringify(value), "utf8");
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export function fitsResult<T>(result: Outcome<T>, render:
|
|
37
|
-
return
|
|
32
|
+
export function fitsText(text: string): boolean {
|
|
33
|
+
return Buffer.byteLength(text, "utf8") <= TOOL_OUTPUT_MAX_BYTES;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function fitsResult<T>(result: Outcome<T>, render: Renderer<T>): boolean {
|
|
37
|
+
return fitsText(render(result)) && structuredBytes(wireResult(result)) <= TOOL_OUTPUT_MAX_BYTES;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/** `text` is verbatim, with no marker inserted, so windows concatenate back into the source. */
|
|
@@ -50,7 +50,7 @@ export type TextWindow = Static<typeof TextWindowSchema>;
|
|
|
50
50
|
* because `readTextWindow` already owns the defaults.
|
|
51
51
|
*/
|
|
52
52
|
export const TextWindowRequestSchema = {
|
|
53
|
-
offset_chars: Type.Optional(Type.Integer({ description: "
|
|
53
|
+
offset_chars: Type.Optional(Type.Integer({ description: "Character offset to start reading (negative counts from the end)." })),
|
|
54
54
|
max_chars: Type.Optional(Type.Integer({ minimum: 1, maximum: MAX_READ_WINDOW_CHARS, description: "How much to read at once." })),
|
|
55
55
|
};
|
|
56
56
|
|
|
@@ -67,7 +67,8 @@ export function readTextWindow<T>(
|
|
|
67
67
|
offset: number | undefined,
|
|
68
68
|
limit: number | undefined,
|
|
69
69
|
makeData: (window: TextWindow) => T,
|
|
70
|
-
render:
|
|
70
|
+
render: Renderer<T>,
|
|
71
|
+
fitsOutcome: (result: Outcome<T>) => boolean = (result) => fitsText(render(result)),
|
|
71
72
|
): Outcome<T> {
|
|
72
73
|
const chars = Array.from(text);
|
|
73
74
|
const requested = offset ?? 0;
|
|
@@ -83,7 +84,7 @@ export function readTextWindow<T>(
|
|
|
83
84
|
next_offset_chars: end < chars.length ? end : null,
|
|
84
85
|
};
|
|
85
86
|
};
|
|
86
|
-
const fits = (delivered: number): boolean =>
|
|
87
|
+
const fits = (delivered: number): boolean => fitsOutcome(success(makeData(window(delivered))));
|
|
87
88
|
// Test the full range first: its footer can disappear at the end of the document, and an
|
|
88
89
|
// empty source is a complete window rather than a refusal.
|
|
89
90
|
if (fits(range)) return success(makeData(window(range)));
|
|
@@ -96,7 +97,7 @@ export function readTextWindow<T>(
|
|
|
96
97
|
/** The continuation line never becomes part of `window.text`, and a complete window has none. */
|
|
97
98
|
export function renderTextWindow(window: TextWindow): string {
|
|
98
99
|
const next = window.next_offset_chars;
|
|
99
|
-
return next === null ? window.text : `${window.text}\n\n[truncated; continue at offset_chars=${next}]`;
|
|
100
|
+
return next === null ? window.text : `${window.text}\n\n[truncated at ${next}/${window.total_chars} chars; continue at offset_chars=${next}]`;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
/** One outcome in, model-facing text out. */
|
|
@@ -111,7 +112,7 @@ export type Operation<TParams extends TSchema, TData, TRest extends readonly unk
|
|
|
111
112
|
/** Absent leaves concurrency to the host default. */
|
|
112
113
|
readonly executionMode?: "sequential" | "parallel";
|
|
113
114
|
/** Schema of wireResult(outcome), not the internal outcome envelope. */
|
|
114
|
-
readonly outputSchema
|
|
115
|
+
readonly outputSchema?: TSchema;
|
|
115
116
|
readonly execute: (params: Static<TParams>, ...rest: TRest) => Promise<Outcome<TData>>;
|
|
116
117
|
readonly render: Renderer<TData>;
|
|
117
118
|
};
|
package/src/tools/schema.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Type, type TSchema } 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
|
+
|
|
6
|
+
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
7
|
|
|
6
8
|
/** First parameter violation; skip false subschemas so additionalProperties can name the field. */
|
|
7
9
|
export function paramProblem(schema: TSchema, params: unknown): string {
|
|
@@ -14,3 +16,24 @@ export function paramProblem(schema: TSchema, params: unknown): string {
|
|
|
14
16
|
|
|
15
17
|
/** Search query parameter: one literal, or several literals combined with OR. */
|
|
16
18
|
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 });
|
|
19
|
+
|
|
20
|
+
/** Strict ISO date or timestamp; a missing offset denotes the host local timezone. */
|
|
21
|
+
export function parseIsoTimestamp(value: string): number | undefined {
|
|
22
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:?\d{2})?)?$/.exec(value);
|
|
23
|
+
if (!match) return undefined;
|
|
24
|
+
const year = Number(match[1]), month = Number(match[2]), day = Number(match[3]);
|
|
25
|
+
const hour = Number(match[4] ?? 0), minute = Number(match[5] ?? 0), second = Number(match[6] ?? 0);
|
|
26
|
+
if (hour > 23 || minute > 59 || second > 59) return undefined;
|
|
27
|
+
const check = new Date(0);
|
|
28
|
+
check.setUTCFullYear(year, month - 1, day);
|
|
29
|
+
if (check.getUTCFullYear() !== year || check.getUTCMonth() !== month - 1 || check.getUTCDate() !== day) 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
|
+
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: memory
|
|
3
|
-
description: How notesoup's `notes_*` and `history_*` tools fit together — note addresses and notebooks, finding things again, and saving recovery state. Use when the context-window protocol is missing or unclear, or when unsure where a note belongs or how to find something again.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Memory
|
|
7
|
-
|
|
8
|
-
Two stores outlive the context window. Anything in neither is lost when the window ends or is wiped.
|
|
9
|
-
|
|
10
|
-
- **Notes** (`notes_*`) — what you choose to keep. Plain markdown, written on purpose.
|
|
11
|
-
- **History** (`history_*`) — recorded messages, tool calls and summaries. Current session by default; other local sessions/harnesses through `session`. Read-only.
|
|
12
|
-
|
|
13
|
-
Each tool's own description covers its parameters and paging. This guide covers what the descriptions cannot: where notes belong, and how the tools work together.
|
|
14
|
-
|
|
15
|
-
## Addresses
|
|
16
|
-
|
|
17
|
-
The address decides who a note belongs to and how long it lasts.
|
|
18
|
-
|
|
19
|
-
| Address | Note | Keep there |
|
|
20
|
-
| --- | --- | --- |
|
|
21
|
-
| `<path>`, no `@` | session note | current task state and loose ends; gone with the session |
|
|
22
|
-
| `@project/<path>` | project note | decisions and constraints future work must respect |
|
|
23
|
-
| `@human/<path>` | human note | how to work with this human, across projects |
|
|
24
|
-
| `@self/<path>` | self note | your reminders; yours alone if you have a name, shared by everyone nameless |
|
|
25
|
-
| `@model/<path>` | model note | what applies to this model only |
|
|
26
|
-
| `@projects/<name>/<path>` | named project, read-only | discover names and root paths with `notes_list` glob `@projects/*/**` |
|
|
27
|
-
| `@sessions/<id>/<path>` | named session, read-only | recover earlier task state; discover with glob `@sessions/*/**` |
|
|
28
|
-
|
|
29
|
-
When notes conflict, the one most relevant to what you're doing applies. If that doesn't settle it, judge the case.
|
|
30
|
-
|
|
31
|
-
Any other `@` prefix is refused. A path is relative and `/`-separated, with no empty, `.` or `..` segments.
|
|
32
|
-
|
|
33
|
-
`@` addresses are not file paths: never pass them to file tools like `read`, `write`, `edit`, or `bash`. That creates a stray directory instead of a note.
|
|
34
|
-
|
|
35
|
-
`CHEATSHEET.md` at each notebook's root is the default-pinned page you wake up with; absent or crumpled pages are skipped. Set `pinned`, `budget`, and `readonly` through `notes_write`/`notes_update` or frontmatter. Explicit `pinned:false` unpins even a default page. Each notebook allows five live pins; ordinary pages default to a 4096-code-point advisory budget (2048 for root `CHEATSHEET.md`), adjustable per note. Overflow warns but saves, and pinned bodies load whole. `readonly:true` is a soft lock, not security; explicitly set `readonly:false` to unlock, alone or alongside your changes. Keep standing reminders in `CHEATSHEET.md`, to five lines. Give each durable note a one-line `description` (max 160 characters, set with `notes_write`/`notes_update`): boot lists every notebook's unpinned pages newest first as address, age, and description, so it is the only index. Do not create empty pages.
|
|
36
|
-
|
|
37
|
-
Keep notes focused on what is true now; if a piece of past context still matters (such as why an approach was ruled out), keep only a brief summary rather than a blow-by-blow log. Crumple notes that are no longer true; a stale note is worse than none.
|
|
38
|
-
|
|
39
|
-
## Finding things again
|
|
40
|
-
|
|
41
|
-
In `notes_list`, omit `glob` for this session and the current shared notebooks. Use `**` for all notebooks or `@sessions/*/**` for all sessions.
|
|
42
|
-
|
|
43
|
-
- **A note**: add `glob` to narrow where `notes_list` looks, and `query` if you remember a phrase. Then use `notes_read` with the address and, for a match, its `offset_chars`.
|
|
44
|
-
- **Something that happened**: `history_list` browses or searches this session's events. Add `context: 1` with a `query` to include neighboring events. Use `history_read` with the seq for the whole event.
|
|
45
|
-
- **An earlier window**: use its seq range from the boot window tree with `history_list`'s exclusive `after` / `before` bounds, or search for a remembered phrase. With `after` you page forward; otherwise you page back from the newest eligible end.
|
|
46
|
-
- **Another session**: pass `session: "<id-or-prefix>"` or `"pi:<id>"`, `"claude:<id>"`, `"codex:<id>"`, `"dsh:<id>"`. An unqualified selector checks this harness first. If ambiguous, use a longer ID or a harness prefix; never pick a candidate blindly.
|
|
47
|
-
- **A phrase across sessions**: `history_list({ session: "*", query: "remembered phrase" })`, or restrict to a harness with `"pi:*"`. A wildcard takes ISO 8601 times only in `after` / `before` and cannot use `history_read`. Hits cover every role unless `roles` narrows them. Results are chronological and have no paging cursors; narrow by time, role, query or session pattern instead. DSH sessions are discoverable only from DSH.
|
|
48
|
-
|
|
49
|
-
- **Recent sessions, no remembered phrase**: `history_list({ session: "*" })` returns one representative event per session, preferring its first visible user prompt, up to `limit` (default 20). Sessions are chosen newest-modified first (oldest-modified first with `after`), then results are sorted chronologically. Empty queries also browse. Role/time filters apply before choosing representatives; with `roles`, the latest matching event represents each session. No paging cursors.
|
|
50
|
-
|
|
51
|
-
Seqs are stable **within a session**. When a hit carries `session`, copy it together with `seq` into `history_read` and save both in your note. The paging/expand/neighborhood recipes already preserve the resolved session. Omit `session` only when you mean your current host session. A single unreadable or unsupported local transcript refuses explicitly; wildcards skip individual sessions that cannot load. An empty result is not proof the remembered event never happened.
|
|
52
|
-
|
|
53
|
-
## Saving recovery state
|
|
54
|
-
|
|
55
|
-
Before a long or risky step, or when room runs low, keep session notes named for what they hold (not `current.md`) and rewrite them to the current state instead of starting new ones or appending a timeline. Record:
|
|
56
|
-
|
|
57
|
-
- the goal and the current step
|
|
58
|
-
- decisions made, and why
|
|
59
|
-
- blockers and the next action
|
|
60
|
-
- how the work was being done, and which skills are still needed
|
|
61
|
-
- where to dig: seqs, note addresses, files
|
|
62
|
-
|
|
63
|
-
`get_context_remaining` reports the room left. `empty_brain` starts a fresh window, so save the note first.
|
|
64
|
-
|
|
65
|
-
## When a tool is missing or refuses
|
|
66
|
-
|
|
67
|
-
A refusal returns `{ error, code }`; read `error` before retrying.
|
|
68
|
-
|
|
69
|
-
If a `notes_*` or `history_*` tool is absent or fails at the host level, do not imitate it: no filesystem tools on `@` addresses, and no reading or editing note storage or session files directly. Use the tools that remain, tell the human which one is missing, and keep essential state in the reply.
|