notesoup 0.53.1 → 0.54.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/README.md +2 -2
- package/dist/plugins/claude/src/helper.js +2 -1
- package/dist/plugins/claude/src/history.js +2 -3
- package/dist/plugins/claude/src/thresholds.js +4 -2
- package/dist/plugins/codex/src/hooks.js +1 -1
- package/dist/plugins/codex/src/identity.d.ts +1 -1
- package/dist/plugins/codex/src/identity.js +3 -3
- package/dist/plugins/codex/src/mcp.js +2 -1
- package/dist/plugins/codex/src/text.d.ts +1 -1
- package/dist/plugins/codex/src/text.js +2 -2
- package/dist/plugins/dsh/engine.js +2 -2
- package/dist/plugins/dsh/tools.js +8 -7
- package/dist/plugins/dsh/window.d.ts +1 -0
- package/dist/plugins/dsh/window.js +7 -3
- package/dist/plugins/pi/entries.d.ts +1 -0
- package/dist/plugins/pi/entries.js +1 -0
- package/dist/plugins/pi/history-tools.d.ts +1 -1
- package/dist/plugins/pi/history-tools.js +4 -4
- package/dist/plugins/pi/marker.d.ts +9 -0
- package/dist/plugins/pi/marker.js +36 -0
- package/dist/plugins/pi/notes/tools.js +8 -6
- package/dist/plugins/pi/render.js +7 -4
- package/dist/plugins/pi/reset/artifacts.d.ts +2 -2
- package/dist/plugins/pi/reset/artifacts.js +2 -2
- package/dist/plugins/pi/runtime.js +11 -8
- package/dist/plugins/pi/text.d.ts +2 -0
- package/dist/plugins/pi/text.js +4 -0
- package/dist/plugins/pi/window.js +21 -7
- package/dist/src/boot/render.js +7 -7
- package/dist/src/boot/snapshot.d.ts +7 -7
- package/dist/src/boot/snapshot.js +17 -17
- package/dist/src/boot/text.d.ts +2 -2
- package/dist/src/boot/text.js +7 -5
- package/dist/src/dream/git.d.ts +2 -11
- package/dist/src/dream/git.js +6 -23
- package/dist/src/dream/lock.d.ts +2 -2
- package/dist/src/dream/lock.js +3 -3
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +3 -2
- package/dist/src/notes/address.d.ts +8 -8
- package/dist/src/notes/address.js +13 -13
- package/dist/src/notes/errors.d.ts +1 -1
- package/dist/src/notes/frontmatter.js +2 -2
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +1 -1
- package/dist/src/notes/paths.d.ts +6 -6
- package/dist/src/notes/paths.js +9 -9
- package/dist/src/notes/{project-home.d.ts → project-namespace.d.ts} +7 -7
- package/dist/src/notes/{project-home.js → project-namespace.js} +67 -25
- package/dist/src/notes/store.d.ts +4 -4
- package/dist/src/notes/store.js +55 -52
- package/dist/src/tools/dream.d.ts +21 -3
- package/dist/src/tools/dream.js +54 -16
- package/dist/src/tools/notes-context.d.ts +10 -0
- package/dist/src/tools/notes-context.js +27 -0
- package/dist/src/tools/notes.d.ts +69 -20
- package/dist/src/tools/notes.js +40 -31
- package/dist/test/agent-loop.test.js +8 -8
- package/dist/test/boot.integration.test.js +5 -5
- package/dist/test/claude-history.test.js +26 -0
- package/dist/test/claude-mod.test.js +257 -86
- package/dist/test/codex-plugin.test.js +18 -1
- package/dist/test/context-edit-budget.test.js +121 -0
- package/dist/test/dependencies.test.js +71 -4
- package/dist/test/dream-tools.test.js +153 -8
- package/dist/test/dsh.test.js +62 -15
- package/dist/test/helpers/dsh.d.ts +4 -1
- package/dist/test/helpers/dsh.js +20 -4
- package/dist/test/helpers/extension.d.ts +5 -0
- package/dist/test/helpers/extension.js +33 -2
- package/dist/test/host-neutral.test.js +17 -15
- package/dist/test/marker.test.js +78 -0
- package/dist/test/model-facing-text.test.js +12 -8
- package/dist/test/notes-cwd.test.d.ts +1 -0
- package/dist/test/notes-cwd.test.js +114 -0
- package/dist/test/notes-library.test.js +4 -4
- package/dist/test/notes-query-namespaces.test.d.ts +1 -0
- package/dist/test/{notes-query-homes.test.js → notes-query-namespaces.test.js} +13 -13
- package/dist/test/notes.integration.test.js +72 -23
- package/dist/test/notes.test.js +50 -20
- package/dist/test/pi-render.test.js +33 -1
- package/dist/test/project-namespace.test.d.ts +1 -0
- package/dist/test/project-namespace.test.js +324 -0
- package/dist/test/reset-lifecycle.test.js +12 -0
- package/docs/architecture.md +13 -8
- package/docs/claude-code-mod.md +7 -7
- package/docs/codex.md +4 -4
- package/docs/dsh.md +8 -8
- package/docs/notes-library.md +9 -5
- package/docs/skills.md +3 -3
- package/docs/tool-results.md +6 -2
- package/package.json +4 -6
- package/playbook.md +6 -6
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +681 -617
- package/plugins/claude/hooks/register.ts +61 -65
- package/plugins/claude/playbook.md +6 -6
- package/plugins/claude/skills/memory/SKILL.md +4 -4
- package/plugins/claude/src/helper.ts +3 -2
- package/plugins/claude/src/history.ts +2 -3
- package/plugins/claude/src/thresholds.ts +4 -2
- package/plugins/codex/README.md +1 -1
- package/plugins/codex/dist/codex/notesoup.js +877 -815
- package/plugins/codex/src/hooks.ts +1 -1
- package/plugins/codex/src/identity.ts +3 -3
- package/plugins/codex/src/mcp.ts +2 -1
- package/plugins/codex/src/text.ts +2 -2
- package/plugins/dsh/engine.ts +2 -2
- package/plugins/dsh/tools.ts +8 -7
- package/plugins/dsh/window.ts +8 -3
- package/plugins/paseo/OVERVIEW.md +4 -4
- package/plugins/paseo/README.md +1 -1
- package/plugins/paseo/client/brain-empty-card.tsx +3 -4
- package/plugins/paseo/client/markdown.tsx +179 -0
- package/plugins/paseo/client/notes-op-card.tsx +35 -34
- package/plugins/paseo/client/notes-op-transformer.ts +17 -68
- package/plugins/paseo/client/paper-card.tsx +8 -19
- package/plugins/paseo/client/paper-palette.ts +40 -0
- package/plugins/paseo/client/sticky-card.tsx +6 -4
- package/plugins/paseo/package.json +3 -0
- package/plugins/paseo/paseo-plugin.json +2 -2
- package/plugins/paseo/shared/notes-op.ts +13 -9
- package/plugins/paseo/test/notes-op.test.ts +52 -73
- package/plugins/paseo/test/paper-palette.test.ts +54 -0
- package/plugins/pi/entries.ts +1 -0
- package/plugins/pi/history-tools.ts +4 -4
- package/plugins/pi/marker.ts +39 -0
- package/plugins/pi/notes/tools.ts +8 -6
- package/plugins/pi/render.ts +6 -4
- package/plugins/pi/reset/artifacts.ts +2 -2
- package/plugins/pi/runtime.ts +9 -8
- package/plugins/pi/text.ts +5 -0
- package/plugins/pi/window.ts +22 -7
- package/skills/memory/SKILL.md +4 -4
- package/src/boot/render.ts +8 -8
- package/src/boot/snapshot.ts +20 -20
- package/src/boot/text.ts +7 -5
- package/src/dream/git.ts +7 -24
- package/src/dream/lock.ts +3 -3
- package/src/index.ts +4 -3
- package/src/notes/address.ts +13 -13
- package/src/notes/errors.ts +1 -1
- package/src/notes/frontmatter.ts +2 -2
- package/src/notes/index.ts +1 -1
- package/src/notes/paths.ts +9 -9
- package/src/notes/{project-home.ts → project-namespace.ts} +59 -28
- package/src/notes/store.ts +61 -58
- package/src/tools/dream.ts +63 -16
- package/src/tools/notes-context.ts +29 -0
- package/src/tools/notes.ts +39 -29
- package/dist/test/project-home.test.js +0 -134
- /package/dist/test/{notes-query-homes.test.d.ts → context-edit-budget.test.d.ts} +0 -0
- /package/dist/test/{project-home.test.d.ts → marker.test.d.ts} +0 -0
package/dist/src/tools/dream.js
CHANGED
|
@@ -1,17 +1,40 @@
|
|
|
1
1
|
/** Dream operations: open one project's notes for consolidation, delete crumpled notes, close. */
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import { createNotesStore, noteIdentity } from "../notes/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { projectNamespaces } from "../notes/project-namespace.js";
|
|
5
5
|
import { gitCommit } from "../dream/git.js";
|
|
6
6
|
import { acquireDreamLock, dreamLockPath, releaseDreamLock } from "../dream/lock.js";
|
|
7
7
|
import { failure, renderOutcome, resultSchema, success } from "./result.js";
|
|
8
|
-
import { failureOf, listedFile, NotesListDataSchema, renderListData, snapshot } from "./notes.js";
|
|
8
|
+
import { failureOf, listedFile, NoteIdentitySchema, NotesListDataSchema, renderListData, snapshot } from "./notes.js";
|
|
9
|
+
function currentOpening(state, opening) {
|
|
10
|
+
return state.pending === opening && state.generation === opening.generation;
|
|
11
|
+
}
|
|
12
|
+
function nextGeneration(state) {
|
|
13
|
+
const generation = (state.generation ?? 0) + 1;
|
|
14
|
+
state.generation = generation;
|
|
15
|
+
return generation;
|
|
16
|
+
}
|
|
9
17
|
/** Drop an open dream without an end commit, e.g. when its session shuts down. */
|
|
10
18
|
export function abandonDream(state) {
|
|
11
|
-
|
|
19
|
+
const pending = state.pending;
|
|
20
|
+
if (pending)
|
|
21
|
+
releaseDreamLock(pending.lock);
|
|
22
|
+
if (state.lock && state.lock !== pending?.lock)
|
|
12
23
|
releaseDreamLock(state.lock);
|
|
24
|
+
nextGeneration(state);
|
|
13
25
|
delete state.project;
|
|
14
26
|
delete state.lock;
|
|
27
|
+
delete state.pending;
|
|
28
|
+
}
|
|
29
|
+
/** Release an opening without disturbing a newer opening in the same state. */
|
|
30
|
+
function releaseOpening(state, opening) {
|
|
31
|
+
releaseDreamLock(opening.lock);
|
|
32
|
+
if (currentOpening(state, opening))
|
|
33
|
+
delete state.pending;
|
|
34
|
+
}
|
|
35
|
+
function cancelledOpening(state, opening) {
|
|
36
|
+
releaseOpening(state, opening);
|
|
37
|
+
return failure("cancelled", "The dream opening was cancelled before it completed.");
|
|
15
38
|
}
|
|
16
39
|
/** The identity a store uses while `state` holds an open dream. */
|
|
17
40
|
export function dreamingIdentity(identity, state) {
|
|
@@ -27,18 +50,23 @@ function renderBeginData(data) {
|
|
|
27
50
|
}
|
|
28
51
|
export const dreamBegin = {
|
|
29
52
|
name: "dream_begin", label: "Dream begin",
|
|
30
|
-
description: "Dream: open one project's notes for consolidation, one project at a time. Lists its @projects/<name>/ notes and every session note born in it, crumpled ones included. Until dream_end, notes_write/notes_update can edit those addresses and reads leave no access stamp.
|
|
53
|
+
description: "Dream: open one project's notes for consolidation, one project at a time. Lists its @projects/<name>/ notes and every session note born in it, crumpled ones included. Until dream_end, notes_write/notes_update can edit those addresses and reads leave no access stamp. Holds the notes home's dream lock through dream_end so Git audits cannot interleave, and commits a baseline of the notes home.",
|
|
31
54
|
parameters: dreamBeginParameters, outputSchema: resultSchema(DreamBeginDataSchema),
|
|
32
55
|
async execute(params, identity, state) {
|
|
33
|
-
if (state.project !== undefined)
|
|
34
|
-
|
|
56
|
+
if (state.project !== undefined || state.pending !== undefined) {
|
|
57
|
+
const project = state.project ?? state.pending?.project;
|
|
58
|
+
return failure("already_dreaming", `Already dreaming over ${project}; call dream_end before opening another project.`);
|
|
59
|
+
}
|
|
35
60
|
const project = params.project ?? identity.projectKey;
|
|
36
|
-
if (project !== identity.projectKey && !
|
|
61
|
+
if (project !== identity.projectKey && !projectNamespaces(identity.home).some(namespace => namespace.name === project)) {
|
|
37
62
|
return failure("not_found", `No project named ${JSON.stringify(project)}; notes_list with glob @projects/*/** shows the names.`);
|
|
38
63
|
}
|
|
39
|
-
const lock = acquireDreamLock(dreamLockPath(identity.home
|
|
64
|
+
const lock = acquireDreamLock(dreamLockPath(identity.home));
|
|
40
65
|
if (!lock)
|
|
41
|
-
return failure("already_dreaming", `Another dream holds ${dreamLockPath(identity.home
|
|
66
|
+
return failure("already_dreaming", `Another dream holds ${dreamLockPath(identity.home)}. If none is running, delete that file by hand.`);
|
|
67
|
+
// Publish ownership before the first await. Shutdown can therefore release this exact token.
|
|
68
|
+
const opening = { project, lock, generation: nextGeneration(state) };
|
|
69
|
+
state.pending = opening;
|
|
42
70
|
try {
|
|
43
71
|
const store = createNotesStore({ ...identity, dreaming: project });
|
|
44
72
|
const rows = [];
|
|
@@ -46,33 +74,43 @@ export const dreamBegin = {
|
|
|
46
74
|
for (const crumpled of [false, true]) {
|
|
47
75
|
for (const glob of [`@projects/${project}/**`, "@sessions/*/**"]) {
|
|
48
76
|
const result = await store.listWithStatus({ glob, crumpled });
|
|
77
|
+
if (!currentOpening(state, opening))
|
|
78
|
+
return cancelledOpening(state, opening);
|
|
49
79
|
rows.push(...result.rows.filter(row => row.scope === "project" || row.meta.project === project));
|
|
50
|
-
unavailable.push(...result.status.
|
|
80
|
+
unavailable.push(...result.status.namespacesUnavailable);
|
|
51
81
|
}
|
|
52
82
|
}
|
|
53
83
|
rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address));
|
|
54
|
-
const listed = snapshot(rows.map(row => listedFile(row, identity)), undefined, {
|
|
84
|
+
const listed = snapshot(rows.map(row => listedFile(row, identity)), undefined, { namespacesUnavailable: unavailable }, renderListData);
|
|
55
85
|
if (!listed.ok) {
|
|
56
|
-
|
|
86
|
+
releaseOpening(state, opening);
|
|
57
87
|
return listed;
|
|
58
88
|
}
|
|
89
|
+
if (!currentOpening(state, opening))
|
|
90
|
+
return cancelledOpening(state, opening);
|
|
59
91
|
const baseline = gitCommit(identity.home, `dream baseline ${project}`);
|
|
60
92
|
if (!baseline.ok) {
|
|
61
|
-
|
|
93
|
+
releaseOpening(state, opening);
|
|
62
94
|
return failure("audit_failed", `Couldn't commit the Git baseline, so nothing could be rolled back; no dream was opened: ${baseline.error}`);
|
|
63
95
|
}
|
|
64
|
-
|
|
96
|
+
if (!currentOpening(state, opening))
|
|
97
|
+
return cancelledOpening(state, opening);
|
|
98
|
+
state.project = opening.project;
|
|
99
|
+
state.lock = opening.lock;
|
|
100
|
+
delete state.pending;
|
|
65
101
|
return success({ project, baseline: baseline.commit, ...listed.data });
|
|
66
102
|
}
|
|
67
103
|
catch (error) {
|
|
68
|
-
|
|
104
|
+
if (!currentOpening(state, opening))
|
|
105
|
+
return cancelledOpening(state, opening);
|
|
106
|
+
releaseOpening(state, opening);
|
|
69
107
|
return failureOf(error);
|
|
70
108
|
}
|
|
71
109
|
},
|
|
72
110
|
render: (result) => renderOutcome(result, renderBeginData),
|
|
73
111
|
};
|
|
74
112
|
export const dreamForgetParameters = Type.Object({ address: Type.String() }, { additionalProperties: false });
|
|
75
|
-
export const DreamForgetDataSchema = Type.Object({
|
|
113
|
+
export const DreamForgetDataSchema = Type.Object({ ...NoteIdentitySchema }, { additionalProperties: false });
|
|
76
114
|
export const dreamForget = {
|
|
77
115
|
name: "dream_forget", label: "Dream forget",
|
|
78
116
|
description: "Dream: permanently delete one crumpled note in the project being dreamed over, or in @human/, @self/, @model/. Crumple it first; live notes refuse.",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type NotesIdentity } from "../notes/index.js";
|
|
2
|
+
/** Host-supplied facts for one notes tool registration; overrides never mutate this context. */
|
|
3
|
+
export type NotesToolContext = Readonly<{
|
|
4
|
+
identity: NotesIdentity;
|
|
5
|
+
cwd: string;
|
|
6
|
+
}>;
|
|
7
|
+
/** Capture the host's base cwd alongside its default identity. */
|
|
8
|
+
export declare function notesToolContext(identity: NotesIdentity, cwd: string): NotesToolContext;
|
|
9
|
+
/** Resolve the current-project override once, before any address, receipt, or ownership decision. */
|
|
10
|
+
export declare function notesIdentityForCall(context: NotesToolContext, cwd?: string): NotesIdentity;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { statSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { NoteError } from "../notes/errors.js";
|
|
4
|
+
import { projectKey, snapshotNotesIdentity } from "../notes/index.js";
|
|
5
|
+
/** Capture the host's base cwd alongside its default identity. */
|
|
6
|
+
export function notesToolContext(identity, cwd) {
|
|
7
|
+
if (typeof cwd !== "string" || cwd.length === 0)
|
|
8
|
+
throw new TypeError("notes tool cwd must be a non-empty string");
|
|
9
|
+
return Object.freeze({ identity: snapshotNotesIdentity(identity), cwd: resolve(cwd) });
|
|
10
|
+
}
|
|
11
|
+
/** Resolve the current-project override once, before any address, receipt, or ownership decision. */
|
|
12
|
+
export function notesIdentityForCall(context, cwd) {
|
|
13
|
+
if (cwd === undefined)
|
|
14
|
+
return context.identity;
|
|
15
|
+
const resolved = resolve(context.cwd, cwd);
|
|
16
|
+
let directory = false;
|
|
17
|
+
try {
|
|
18
|
+
directory = statSync(resolved).isDirectory();
|
|
19
|
+
}
|
|
20
|
+
catch { /* Report one typed refusal below. */ }
|
|
21
|
+
if (!directory)
|
|
22
|
+
throw new NoteError("invalid_cwd", `cwd is not an existing directory: ${JSON.stringify(cwd)} (resolved to ${resolved}).`);
|
|
23
|
+
return snapshotNotesIdentity({
|
|
24
|
+
...context.identity,
|
|
25
|
+
projectKey: projectKey(resolved, context.identity.home),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -2,6 +2,7 @@ import type { NotesIdentity } from "../notes/identity.js";
|
|
|
2
2
|
import { Type, type Static } from "typebox";
|
|
3
3
|
import { type NoteChange, type NoteQueryStatus, type NoteRow } from "../notes/index.js";
|
|
4
4
|
import { type Outcome } from "./result.js";
|
|
5
|
+
import { type NotesToolContext } from "./notes-context.js";
|
|
5
6
|
/**
|
|
6
7
|
* Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
|
|
7
8
|
* Convert expected refusals; unexpected errors propagate unchanged.
|
|
@@ -17,18 +18,46 @@ export declare const NoteMetadataSchema: Type.TObject<{
|
|
|
17
18
|
extra: Type.TRecord<"^.*$", Type.TUnknown>;
|
|
18
19
|
}>;
|
|
19
20
|
export type NoteMetadata = Static<typeof NoteMetadataSchema>;
|
|
20
|
-
|
|
21
|
+
/** Display context a named project notebook adds to its receipts; ordinary notebooks omit both. */
|
|
22
|
+
export declare const ProjectReceiptSchema: {
|
|
23
|
+
project_root: Type.TOptional<Type.TString>;
|
|
24
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
25
|
+
name: Type.TString;
|
|
26
|
+
path: Type.TString;
|
|
27
|
+
}>>>;
|
|
28
|
+
};
|
|
29
|
+
/** One note identity, shared by every receipt: read/list/search rows and all mutations alike. */
|
|
30
|
+
export declare const NoteIdentitySchema: {
|
|
31
|
+
project_root: Type.TOptional<Type.TString>;
|
|
32
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
33
|
+
name: Type.TString;
|
|
34
|
+
path: Type.TString;
|
|
35
|
+
}>>>;
|
|
21
36
|
address: Type.TString;
|
|
22
37
|
project_key: Type.TOptional<Type.TString>;
|
|
38
|
+
};
|
|
39
|
+
export declare const NotesWriteDataSchema: Type.TObject<{
|
|
23
40
|
outcome: Type.TUnion<[Type.TLiteral<"created">, Type.TLiteral<"overwrote">, Type.TLiteral<"uncrumpled">]>;
|
|
41
|
+
project_root: Type.TOptional<Type.TString>;
|
|
42
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
43
|
+
name: Type.TString;
|
|
44
|
+
path: Type.TString;
|
|
45
|
+
}>>>;
|
|
46
|
+
address: Type.TString;
|
|
47
|
+
project_key: Type.TOptional<Type.TString>;
|
|
24
48
|
}>;
|
|
25
49
|
export type NotesWriteData = Static<typeof NotesWriteDataSchema>;
|
|
26
50
|
export declare const NotesUpdateDataSchema: Type.TObject<{
|
|
27
|
-
address: Type.TString;
|
|
28
|
-
project_key: Type.TOptional<Type.TString>;
|
|
29
51
|
change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
|
|
30
52
|
diff: Type.TString;
|
|
31
53
|
rename_from: Type.TOptional<Type.TString>;
|
|
54
|
+
project_root: Type.TOptional<Type.TString>;
|
|
55
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
56
|
+
name: Type.TString;
|
|
57
|
+
path: Type.TString;
|
|
58
|
+
}>>>;
|
|
59
|
+
address: Type.TString;
|
|
60
|
+
project_key: Type.TOptional<Type.TString>;
|
|
32
61
|
}>;
|
|
33
62
|
export type NotesUpdateData = Static<typeof NotesUpdateDataSchema>;
|
|
34
63
|
export declare const NotesReadDataSchema: Type.TObject<{
|
|
@@ -55,7 +84,7 @@ export declare const NotesReadDataSchema: Type.TObject<{
|
|
|
55
84
|
export type NotesReadData = Static<typeof NotesReadDataSchema>;
|
|
56
85
|
export declare const NotesListDataSchema: Type.TObject<{
|
|
57
86
|
more: Type.TInteger;
|
|
58
|
-
|
|
87
|
+
namespaces_unavailable: Type.TArray<Type.TString>;
|
|
59
88
|
files: Type.TArray<Type.TObject<{
|
|
60
89
|
updated_at: Type.TString;
|
|
61
90
|
last_accessed: Type.TString;
|
|
@@ -72,7 +101,7 @@ export declare const NotesListDataSchema: Type.TObject<{
|
|
|
72
101
|
export type NotesListData = Static<typeof NotesListDataSchema>;
|
|
73
102
|
export declare const NotesSearchDataSchema: Type.TObject<{
|
|
74
103
|
more: Type.TInteger;
|
|
75
|
-
|
|
104
|
+
namespaces_unavailable: Type.TArray<Type.TString>;
|
|
76
105
|
files: Type.TArray<Type.TObject<{
|
|
77
106
|
matches: Type.TArray<Type.TObject<{
|
|
78
107
|
line: Type.TInteger;
|
|
@@ -104,26 +133,33 @@ export declare const notesWriteParameters: Type.TObject<{
|
|
|
104
133
|
address: Type.TString;
|
|
105
134
|
content: Type.TString;
|
|
106
135
|
origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
|
|
136
|
+
cwd: Type.TOptional<Type.TString>;
|
|
107
137
|
}>;
|
|
108
138
|
export declare const notesWrite: {
|
|
109
139
|
readonly name: "notes_write";
|
|
110
140
|
readonly label: "Notes write";
|
|
111
|
-
readonly description: "Create a note, or overwrite its whole body. Name it for what it holds and when to use it. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable
|
|
141
|
+
readonly description: "Create a note, or overwrite its whole body. Name it for what it holds and when to use it. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
|
|
112
142
|
readonly parameters: Type.TObject<{
|
|
113
143
|
address: Type.TString;
|
|
114
144
|
content: Type.TString;
|
|
115
145
|
origin: Type.TOptional<Type.TUnion<[Type.TLiteral<"user">, Type.TLiteral<"self">, Type.TLiteral<"external">]>>;
|
|
146
|
+
cwd: Type.TOptional<Type.TString>;
|
|
116
147
|
}>;
|
|
117
148
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
149
|
+
outcome: Type.TUnion<[Type.TLiteral<"created">, Type.TLiteral<"overwrote">, Type.TLiteral<"uncrumpled">]>;
|
|
150
|
+
project_root: Type.TOptional<Type.TString>;
|
|
151
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
152
|
+
name: Type.TString;
|
|
153
|
+
path: Type.TString;
|
|
154
|
+
}>>>;
|
|
118
155
|
address: Type.TString;
|
|
119
156
|
project_key: Type.TOptional<Type.TString>;
|
|
120
|
-
outcome: Type.TUnion<[Type.TLiteral<"created">, Type.TLiteral<"overwrote">, Type.TLiteral<"uncrumpled">]>;
|
|
121
157
|
}>, Type.TObject<{
|
|
122
158
|
error: Type.TString;
|
|
123
159
|
code: Type.TString;
|
|
124
160
|
}>]>;
|
|
125
161
|
readonly executionMode: "sequential";
|
|
126
|
-
readonly execute: (params: Static<typeof notesWriteParameters>,
|
|
162
|
+
readonly execute: (params: Static<typeof notesWriteParameters>, context: NotesToolContext) => Promise<Outcome<NotesWriteData>>;
|
|
127
163
|
readonly render: (result: Outcome<NotesWriteData>) => string;
|
|
128
164
|
};
|
|
129
165
|
export declare const notesUpdateParameters: Type.TObject<{
|
|
@@ -136,6 +172,7 @@ export declare const notesUpdateParameters: Type.TObject<{
|
|
|
136
172
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
137
173
|
replace_all: Type.TOptional<Type.TBoolean>;
|
|
138
174
|
rename_to: Type.TOptional<Type.TString>;
|
|
175
|
+
cwd: Type.TOptional<Type.TString>;
|
|
139
176
|
}>;
|
|
140
177
|
declare function renderUpdate(result: Outcome<NotesUpdateData>): string;
|
|
141
178
|
/** A shortened diff still says so in the receipt's own text, on both surfaces. */
|
|
@@ -143,7 +180,7 @@ export declare const DIFF_SHORTENED_MARKER = "[diff truncated; update applied]";
|
|
|
143
180
|
export declare const notesUpdate: {
|
|
144
181
|
readonly name: "notes_update";
|
|
145
182
|
readonly label: "Notes update";
|
|
146
|
-
readonly description: "Change part of a note's body, its origin or crumpled state, or its address. When
|
|
183
|
+
readonly description: "Change part of a note's body, its origin or crumpled state, or its address. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each `oldText` must match exactly once unless `replace_all` is true. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
|
|
147
184
|
readonly parameters: Type.TObject<{
|
|
148
185
|
address: Type.TString;
|
|
149
186
|
edits: Type.TOptional<Type.TArray<Type.TObject<{
|
|
@@ -154,22 +191,29 @@ export declare const notesUpdate: {
|
|
|
154
191
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
155
192
|
replace_all: Type.TOptional<Type.TBoolean>;
|
|
156
193
|
rename_to: Type.TOptional<Type.TString>;
|
|
194
|
+
cwd: Type.TOptional<Type.TString>;
|
|
157
195
|
}>;
|
|
158
196
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
159
|
-
address: Type.TString;
|
|
160
|
-
project_key: Type.TOptional<Type.TString>;
|
|
161
197
|
change_kind: Type.TUnion<[Type.TLiteral<"none">, Type.TLiteral<"body">, Type.TLiteral<"metadata">, Type.TLiteral<"moved">]>;
|
|
162
198
|
diff: Type.TString;
|
|
163
199
|
rename_from: Type.TOptional<Type.TString>;
|
|
200
|
+
project_root: Type.TOptional<Type.TString>;
|
|
201
|
+
project_siblings: Type.TOptional<Type.TArray<Type.TObject<{
|
|
202
|
+
name: Type.TString;
|
|
203
|
+
path: Type.TString;
|
|
204
|
+
}>>>;
|
|
205
|
+
address: Type.TString;
|
|
206
|
+
project_key: Type.TOptional<Type.TString>;
|
|
164
207
|
}>, Type.TObject<{
|
|
165
208
|
error: Type.TString;
|
|
166
209
|
code: Type.TString;
|
|
167
210
|
}>]>;
|
|
168
211
|
readonly executionMode: "sequential";
|
|
169
|
-
readonly execute: (params: Static<typeof notesUpdateParameters>,
|
|
212
|
+
readonly execute: (params: Static<typeof notesUpdateParameters>, context: NotesToolContext, renderDiff?: (change: NoteChange) => string) => Promise<Outcome<NotesUpdateData>>;
|
|
170
213
|
readonly render: typeof renderUpdate;
|
|
171
214
|
};
|
|
172
215
|
export declare const notesReadParameters: Type.TObject<{
|
|
216
|
+
cwd: Type.TOptional<Type.TString>;
|
|
173
217
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
174
218
|
max_chars: Type.TOptional<Type.TInteger>;
|
|
175
219
|
address: Type.TString;
|
|
@@ -177,8 +221,9 @@ export declare const notesReadParameters: Type.TObject<{
|
|
|
177
221
|
export declare const notesRead: {
|
|
178
222
|
readonly name: "notes_read";
|
|
179
223
|
readonly label: "Notes read";
|
|
180
|
-
readonly description: "Read a note. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable
|
|
224
|
+
readonly description: "Read a note. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
|
|
181
225
|
readonly parameters: Type.TObject<{
|
|
226
|
+
cwd: Type.TOptional<Type.TString>;
|
|
182
227
|
offset_chars: Type.TOptional<Type.TInteger>;
|
|
183
228
|
max_chars: Type.TOptional<Type.TInteger>;
|
|
184
229
|
address: Type.TString;
|
|
@@ -207,27 +252,29 @@ export declare const notesRead: {
|
|
|
207
252
|
error: Type.TString;
|
|
208
253
|
code: Type.TString;
|
|
209
254
|
}>]>;
|
|
210
|
-
readonly execute: (params: Static<typeof notesReadParameters>,
|
|
255
|
+
readonly execute: (params: Static<typeof notesReadParameters>, context: NotesToolContext) => Promise<Outcome<NotesReadData>>;
|
|
211
256
|
readonly render: (result: Outcome<NotesReadData>) => string;
|
|
212
257
|
};
|
|
213
258
|
export declare const notesListParameters: Type.TObject<{
|
|
214
259
|
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
215
260
|
limit: Type.TOptional<Type.TInteger>;
|
|
216
261
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
262
|
+
cwd: Type.TOptional<Type.TString>;
|
|
217
263
|
}>;
|
|
218
264
|
export declare function renderListData(data: NotesListData): string;
|
|
219
265
|
export declare const notesList: {
|
|
220
266
|
readonly name: "notes_list";
|
|
221
267
|
readonly label: "Notes list";
|
|
222
|
-
readonly description: "List notes, newest first. Not pageable; `more` counts the rest. Omit `glob` or use `@default` for this session and current shared
|
|
268
|
+
readonly description: "List notes, newest first. Not pageable; `more` counts the rest. Omit `glob` or use `@default` for this session and current shared notebooks; `**` searches all notebooks, `@sessions/*/**` searches all sessions. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
|
|
223
269
|
readonly parameters: Type.TObject<{
|
|
224
270
|
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
225
271
|
limit: Type.TOptional<Type.TInteger>;
|
|
226
272
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
273
|
+
cwd: Type.TOptional<Type.TString>;
|
|
227
274
|
}>;
|
|
228
275
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
229
276
|
more: Type.TInteger;
|
|
230
|
-
|
|
277
|
+
namespaces_unavailable: Type.TArray<Type.TString>;
|
|
231
278
|
files: Type.TArray<Type.TObject<{
|
|
232
279
|
updated_at: Type.TString;
|
|
233
280
|
last_accessed: Type.TString;
|
|
@@ -244,7 +291,7 @@ export declare const notesList: {
|
|
|
244
291
|
error: Type.TString;
|
|
245
292
|
code: Type.TString;
|
|
246
293
|
}>]>;
|
|
247
|
-
readonly execute: (params: Static<typeof notesListParameters>,
|
|
294
|
+
readonly execute: (params: Static<typeof notesListParameters>, context: NotesToolContext) => Promise<Outcome<NotesListData>>;
|
|
248
295
|
readonly render: (result: Outcome<NotesListData>) => string;
|
|
249
296
|
};
|
|
250
297
|
export declare const notesSearchParameters: Type.TObject<{
|
|
@@ -253,23 +300,25 @@ export declare const notesSearchParameters: Type.TObject<{
|
|
|
253
300
|
limit: Type.TOptional<Type.TInteger>;
|
|
254
301
|
max_matches_per_file: Type.TOptional<Type.TInteger>;
|
|
255
302
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
303
|
+
cwd: Type.TOptional<Type.TString>;
|
|
256
304
|
}>;
|
|
257
305
|
/** A shortened match line still ends with a marker, so its own text says it was cut. */
|
|
258
306
|
export declare const MATCH_SHORTENED_MARKER = " [truncated]";
|
|
259
307
|
export declare const notesSearch: {
|
|
260
308
|
readonly name: "notes_search";
|
|
261
309
|
readonly label: "Notes search";
|
|
262
|
-
readonly description: "Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. Omit `glob` or use `@default` for this session and current shared
|
|
310
|
+
readonly description: "Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for `notes_read`. Not pageable; `more` counts the rest. Omit `glob` or use `@default` for this session and current shared notebooks; `**` searches all notebooks, `@sessions/*/**` searches all sessions. Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
|
|
263
311
|
readonly parameters: Type.TObject<{
|
|
264
312
|
query: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
265
313
|
glob: Type.TOptional<Type.TUnion<[Type.TString, Type.TNull]>>;
|
|
266
314
|
limit: Type.TOptional<Type.TInteger>;
|
|
267
315
|
max_matches_per_file: Type.TOptional<Type.TInteger>;
|
|
268
316
|
crumpled: Type.TOptional<Type.TBoolean>;
|
|
317
|
+
cwd: Type.TOptional<Type.TString>;
|
|
269
318
|
}>;
|
|
270
319
|
readonly outputSchema: Type.TUnion<[Type.TObject<{
|
|
271
320
|
more: Type.TInteger;
|
|
272
|
-
|
|
321
|
+
namespaces_unavailable: Type.TArray<Type.TString>;
|
|
273
322
|
files: Type.TArray<Type.TObject<{
|
|
274
323
|
matches: Type.TArray<Type.TObject<{
|
|
275
324
|
line: Type.TInteger;
|
|
@@ -291,7 +340,7 @@ export declare const notesSearch: {
|
|
|
291
340
|
error: Type.TString;
|
|
292
341
|
code: Type.TString;
|
|
293
342
|
}>]>;
|
|
294
|
-
readonly execute: (params: Static<typeof notesSearchParameters>,
|
|
343
|
+
readonly execute: (params: Static<typeof notesSearchParameters>, context: NotesToolContext) => Promise<Outcome<NotesSearchData>>;
|
|
295
344
|
readonly render: (result: Outcome<NotesSearchData>) => string;
|
|
296
345
|
};
|
|
297
346
|
export {};
|
package/dist/src/tools/notes.js
CHANGED
|
@@ -5,6 +5,7 @@ import { createNotesStore, NoteError, noteIdentity } from "../notes/index.js";
|
|
|
5
5
|
import { prefixFit, TOOL_OUTPUT_LIMIT } from "./output.js";
|
|
6
6
|
import { failure, fitsResult, resultSchema, readTextWindow, renderOutcome, renderTextWindow, structuredBytes, success, TextWindowRequestSchema, TextWindowSchema } from "./result.js";
|
|
7
7
|
import { nullableString, InvalidQueryError, searchQueries, searchQuery } from "./schema.js";
|
|
8
|
+
import { notesIdentityForCall } from "./notes-context.js";
|
|
8
9
|
const ORIGIN_VALUES = [Type.Literal("user"), Type.Literal("self"), Type.Literal("external")];
|
|
9
10
|
const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
|
|
10
11
|
description: "(optional) Who wrote it: user, self, or external. Omit to keep the existing origin; new notes default to self.",
|
|
@@ -12,9 +13,10 @@ const ORIGIN = Type.Optional(Type.Union([...ORIGIN_VALUES], {
|
|
|
12
13
|
const CRUMPLED_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = crumple (hide from list and search, still readable); false = restore." }));
|
|
13
14
|
const CRUMPLED_LIST_PARAMETER = Type.Optional(Type.Boolean({ description: "(optional) true = list only crumpled notes." }));
|
|
14
15
|
const FILE_LIMIT_PARAMETER = Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default as many as fit) Max notes." }));
|
|
15
|
-
const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
const GLOB_PARAMETER = nullableString("(optional) Glob over full addresses, or @default for the current notebooks.");
|
|
17
|
+
const CWD_PARAMETER = Type.Optional(Type.String({ minLength: 1, description: "(optional) Select the current project for this call. A relative path resolves against the host session cwd; the path must be an existing directory." }));
|
|
18
|
+
const QUERY_NAMESPACES_DESCRIPTION = "Omit `glob` or use `@default` for this session and current shared notebooks; `**` searches all notebooks, `@sessions/*/**` searches all sessions.";
|
|
19
|
+
const ADDRESS_DESCRIPTION = "Addresses: a bare path is this session's note; `@project/`, `@human/`, `@self/`, `@model/` are durable notebooks; `@projects/<name>/<path>` and `@sessions/<id>/<path>` read named project and session notes (read-only). Not file paths: never pass them to file tools.";
|
|
18
20
|
/**
|
|
19
21
|
* Typed refusal. Every fact a caller needs is already in the message; there is no separate context.
|
|
20
22
|
* Convert expected refusals; unexpected errors propagate unchanged.
|
|
@@ -101,14 +103,19 @@ function renderIdentity(identity) {
|
|
|
101
103
|
text += `\n Same-basename projects: ${identity.project_siblings.map(sibling => `${sibling.name} (${sibling.path})`).join(", ")}`;
|
|
102
104
|
return text;
|
|
103
105
|
}
|
|
104
|
-
|
|
106
|
+
/** Display context a named project notebook adds to its receipts; ordinary notebooks omit both. */
|
|
107
|
+
export const ProjectReceiptSchema = {
|
|
105
108
|
project_root: Type.Optional(Type.String()),
|
|
106
109
|
project_siblings: Type.Optional(Type.Array(Type.Object({ name: Type.String(), path: Type.String() }, { additionalProperties: false }))),
|
|
107
110
|
};
|
|
108
|
-
|
|
111
|
+
/** One note identity, shared by every receipt: read/list/search rows and all mutations alike. */
|
|
112
|
+
export const NoteIdentitySchema = {
|
|
109
113
|
address: Type.String(),
|
|
110
114
|
project_key: Type.Optional(Type.String()),
|
|
111
115
|
...ProjectReceiptSchema,
|
|
116
|
+
};
|
|
117
|
+
const ListedFileSchema = Type.Object({
|
|
118
|
+
...NoteIdentitySchema,
|
|
112
119
|
updated_at: Type.String(),
|
|
113
120
|
last_accessed: Type.String(),
|
|
114
121
|
crumpled_at: Type.Optional(Type.String()),
|
|
@@ -124,24 +131,20 @@ const SearchedFileSchema = Type.Object({
|
|
|
124
131
|
}, { additionalProperties: false });
|
|
125
132
|
const SnapshotSchema = {
|
|
126
133
|
more: Type.Integer({ description: "How many more were left out." }),
|
|
127
|
-
|
|
134
|
+
namespaces_unavailable: Type.Array(Type.String()),
|
|
128
135
|
};
|
|
129
136
|
export const NotesWriteDataSchema = Type.Object({
|
|
130
|
-
|
|
131
|
-
project_key: Type.Optional(Type.String()),
|
|
137
|
+
...NoteIdentitySchema,
|
|
132
138
|
outcome: Type.Union([Type.Literal("created"), Type.Literal("overwrote"), Type.Literal("uncrumpled")]),
|
|
133
139
|
}, { additionalProperties: false });
|
|
134
140
|
export const NotesUpdateDataSchema = Type.Object({
|
|
135
|
-
|
|
136
|
-
project_key: Type.Optional(Type.String()),
|
|
141
|
+
...NoteIdentitySchema,
|
|
137
142
|
change_kind: Type.Union([Type.Literal("none"), Type.Literal("body"), Type.Literal("metadata"), Type.Literal("moved")]),
|
|
138
143
|
diff: Type.String(),
|
|
139
144
|
rename_from: Type.Optional(Type.String()),
|
|
140
145
|
}, { additionalProperties: false });
|
|
141
146
|
export const NotesReadDataSchema = Type.Object({
|
|
142
|
-
|
|
143
|
-
project_key: Type.Optional(Type.String()),
|
|
144
|
-
...ProjectReceiptSchema,
|
|
147
|
+
...NoteIdentitySchema,
|
|
145
148
|
metadata: NoteMetadataSchema,
|
|
146
149
|
...TextWindowSchema.properties,
|
|
147
150
|
}, { additionalProperties: false });
|
|
@@ -156,7 +159,7 @@ export const NotesSearchDataSchema = Type.Object({
|
|
|
156
159
|
/** Keep identities intact. Only search previews may shrink to make the first row fit. */
|
|
157
160
|
export function snapshot(rows, limit, status, renderData, shrink) {
|
|
158
161
|
const files = [];
|
|
159
|
-
const data = (selected) => ({ files: selected, more: rows.length - selected.length,
|
|
162
|
+
const data = (selected) => ({ files: selected, more: rows.length - selected.length, namespaces_unavailable: status.namespacesUnavailable });
|
|
160
163
|
const render = (outcome) => renderOutcome(outcome, renderData);
|
|
161
164
|
const fits = (item) => fitsResult(success(data([...files, item])), render);
|
|
162
165
|
for (const item of rows.slice(0, limit)) {
|
|
@@ -174,12 +177,12 @@ export function snapshot(rows, limit, status, renderData, shrink) {
|
|
|
174
177
|
break;
|
|
175
178
|
}
|
|
176
179
|
const outcome = success(data(files));
|
|
177
|
-
return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable
|
|
180
|
+
return fitsResult(outcome, render) ? outcome : failure("output_too_large", `The list of unreachable notebooks is itself over ${TOOL_OUTPUT_LIMIT}; narrow \`glob\` to fewer notebooks.`);
|
|
178
181
|
}
|
|
179
182
|
export function listedFile(row, identity) {
|
|
180
183
|
return { ...noteIdentity(identity, row.address), updated_at: localIso(row.meta.updatedAt), last_accessed: localIso(row.meta.lastAccessed), ...(row.meta.crumpledAt === undefined ? {} : { crumpled_at: row.meta.crumpledAt }) };
|
|
181
184
|
}
|
|
182
|
-
export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN }, { additionalProperties: false });
|
|
185
|
+
export const notesWriteParameters = Type.Object({ address: Type.String(), content: Type.String(), origin: ORIGIN, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
183
186
|
function renderWriteData(data) {
|
|
184
187
|
return `${data.outcome} ${renderIdentity(data)}`;
|
|
185
188
|
}
|
|
@@ -187,8 +190,9 @@ export const notesWrite = {
|
|
|
187
190
|
name: "notes_write", label: "Notes write",
|
|
188
191
|
description: `Create a note, or overwrite its whole body. Name it for what it holds and when to use it. ${ADDRESS_DESCRIPTION}`,
|
|
189
192
|
parameters: notesWriteParameters, outputSchema: resultSchema(NotesWriteDataSchema), executionMode: "sequential",
|
|
190
|
-
async execute(params,
|
|
193
|
+
async execute(params, context) {
|
|
191
194
|
try {
|
|
195
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
192
196
|
const { outcome } = await createNotesStore(identity).write(params.address, params.content, { origin: params.origin });
|
|
193
197
|
return success({ ...noteIdentity(identity, params.address), outcome });
|
|
194
198
|
}
|
|
@@ -205,6 +209,7 @@ export const notesUpdateParameters = Type.Object({
|
|
|
205
209
|
crumpled: CRUMPLED_PARAMETER,
|
|
206
210
|
replace_all: Type.Optional(Type.Boolean({ description: "(optional) true = replace every match of `oldText`." })),
|
|
207
211
|
rename_to: Type.Optional(Type.String({ description: "(optional) Move to this address, optionally with edits or metadata changes. Won't overwrite a live note; references aren't updated." })),
|
|
212
|
+
cwd: CWD_PARAMETER,
|
|
208
213
|
}, { additionalProperties: false });
|
|
209
214
|
function renderUpdateData(data) {
|
|
210
215
|
const head = data.rename_from === undefined
|
|
@@ -233,10 +238,11 @@ function boundedUpdate(data) {
|
|
|
233
238
|
}
|
|
234
239
|
export const notesUpdate = {
|
|
235
240
|
name: "notes_update", label: "Notes update",
|
|
236
|
-
description: `Change part of a note's body, its origin or crumpled state, or its address. When
|
|
241
|
+
description: `Change part of a note's body, its origin or crumpled state, or its address. When things change, replace the stale part in place; don't just tack an update onto the bottom. Each \`oldText\` must match exactly once unless \`replace_all\` is true. ${ADDRESS_DESCRIPTION}`,
|
|
237
242
|
parameters: notesUpdateParameters, outputSchema: resultSchema(NotesUpdateDataSchema), executionMode: "sequential",
|
|
238
|
-
async execute(params,
|
|
243
|
+
async execute(params, context, renderDiff = (change) => change.kind === "none" ? "" : `note ${change.kind}`) {
|
|
239
244
|
try {
|
|
245
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
240
246
|
const store = createNotesStore(identity);
|
|
241
247
|
// Empty filler is not a request: models that pass every parameter get the edit path.
|
|
242
248
|
const renameTo = params.rename_to === "" ? undefined : params.rename_to;
|
|
@@ -252,7 +258,7 @@ export const notesUpdate = {
|
|
|
252
258
|
},
|
|
253
259
|
render: renderUpdate,
|
|
254
260
|
};
|
|
255
|
-
export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema }, { additionalProperties: false });
|
|
261
|
+
export const notesReadParameters = Type.Object({ address: Type.String(), ...TextWindowRequestSchema, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
256
262
|
function renderReadData(data) {
|
|
257
263
|
return `${renderIdentity(data)}\n${renderMetadata(data.metadata)}\n\n${renderTextWindow(data)}`;
|
|
258
264
|
}
|
|
@@ -260,8 +266,9 @@ export const notesRead = {
|
|
|
260
266
|
name: "notes_read", label: "Notes read",
|
|
261
267
|
description: `Read a note. ${ADDRESS_DESCRIPTION}`,
|
|
262
268
|
parameters: notesReadParameters, outputSchema: resultSchema(NotesReadDataSchema),
|
|
263
|
-
async execute(params,
|
|
269
|
+
async execute(params, context) {
|
|
264
270
|
try {
|
|
271
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
265
272
|
const note = await createNotesStore(identity).read(params.address);
|
|
266
273
|
const resolved = noteIdentity(identity, params.address);
|
|
267
274
|
if (!note)
|
|
@@ -279,7 +286,7 @@ export const notesRead = {
|
|
|
279
286
|
},
|
|
280
287
|
render: (result) => renderOutcome(result, renderReadData),
|
|
281
288
|
};
|
|
282
|
-
export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
289
|
+
export const notesListParameters = Type.Object({ glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
283
290
|
export function renderListData(data) {
|
|
284
291
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
285
292
|
for (const file of data.files) {
|
|
@@ -287,16 +294,17 @@ export function renderListData(data) {
|
|
|
287
294
|
}
|
|
288
295
|
if (data.more > 0)
|
|
289
296
|
lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
290
|
-
for (const
|
|
291
|
-
lines.push(`${
|
|
297
|
+
for (const namespace of data.namespaces_unavailable)
|
|
298
|
+
lines.push(`${namespace} could not be read`);
|
|
292
299
|
return lines.join("\n");
|
|
293
300
|
}
|
|
294
301
|
export const notesList = {
|
|
295
302
|
name: "notes_list", label: "Notes list",
|
|
296
|
-
description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${
|
|
303
|
+
description: `List notes, newest first. Not pageable; \`more\` counts the rest. ${QUERY_NAMESPACES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
|
|
297
304
|
parameters: notesListParameters, outputSchema: resultSchema(NotesListDataSchema),
|
|
298
|
-
async execute(params,
|
|
305
|
+
async execute(params, context) {
|
|
299
306
|
try {
|
|
307
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
300
308
|
const { rows, status } = await createNotesStore(identity).listWithStatus({ glob: params.glob ?? undefined, crumpled: params.crumpled });
|
|
301
309
|
return snapshot(rows.map(row => listedFile(row, identity)), params.limit, status, renderListData);
|
|
302
310
|
}
|
|
@@ -306,7 +314,7 @@ export const notesList = {
|
|
|
306
314
|
},
|
|
307
315
|
render: (result) => renderOutcome(result, renderListData),
|
|
308
316
|
};
|
|
309
|
-
export const notesSearchParameters = Type.Object({ query: Type.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER }, { additionalProperties: false });
|
|
317
|
+
export const notesSearchParameters = Type.Object({ query: Type.Optional(searchQuery()), glob: GLOB_PARAMETER, limit: FILE_LIMIT_PARAMETER, max_matches_per_file: Type.Optional(Type.Integer({ minimum: 1, description: "(optional, default all) Max matching lines per note." })), crumpled: CRUMPLED_LIST_PARAMETER, cwd: CWD_PARAMETER }, { additionalProperties: false });
|
|
310
318
|
function renderSearchData(data) {
|
|
311
319
|
const lines = [`${data.files.length} ${data.files.length === 1 ? "note" : "notes"}`];
|
|
312
320
|
for (const file of data.files) {
|
|
@@ -316,8 +324,8 @@ function renderSearchData(data) {
|
|
|
316
324
|
}
|
|
317
325
|
if (data.more > 0)
|
|
318
326
|
lines.push(`${data.more} more matching notes omitted; narrow with glob`);
|
|
319
|
-
for (const
|
|
320
|
-
lines.push(`${
|
|
327
|
+
for (const namespace of data.namespaces_unavailable)
|
|
328
|
+
lines.push(`${namespace} could not be read`);
|
|
321
329
|
return lines.join("\n");
|
|
322
330
|
}
|
|
323
331
|
/** A shortened match line still ends with a marker, so its own text says it was cut. */
|
|
@@ -343,10 +351,11 @@ function fitSearchFile(file, fits) {
|
|
|
343
351
|
}
|
|
344
352
|
export const notesSearch = {
|
|
345
353
|
name: "notes_search", label: "Notes search",
|
|
346
|
-
description: `Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${
|
|
354
|
+
description: `Search note bodies for literal text, case-insensitive. Without a query, lists notes with no match lines. Returns matching lines with offsets for \`notes_read\`. Not pageable; \`more\` counts the rest. ${QUERY_NAMESPACES_DESCRIPTION} ${ADDRESS_DESCRIPTION}`,
|
|
347
355
|
parameters: notesSearchParameters, outputSchema: resultSchema(NotesSearchDataSchema),
|
|
348
|
-
async execute(params,
|
|
356
|
+
async execute(params, context) {
|
|
349
357
|
try {
|
|
358
|
+
const identity = notesIdentityForCall(context, params.cwd);
|
|
350
359
|
const { rows, status } = await createNotesStore(identity).searchWithStatus(searchQueries(params.query), { glob: params.glob ?? undefined, crumpled: params.crumpled });
|
|
351
360
|
const files = rows.sort((a, b) => b.meta.updatedAt - a.meta.updatedAt || a.address.localeCompare(b.address)).map(row => ({
|
|
352
361
|
...listedFile(row, identity),
|