standardnotes-mcp 3.0.0 → 3.1.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/CHANGELOG.md +55 -0
- package/README.md +118 -55
- package/SECURITY.md +2 -1
- package/dist/cli/clients.js +124 -0
- package/dist/cli/folders.js +63 -0
- package/dist/cli/install.js +60 -18
- package/dist/cli/isMain.js +21 -0
- package/dist/cli/login.js +15 -12
- package/dist/cli/logout.js +1 -1
- package/dist/cli/setup.js +168 -72
- package/dist/config.js +30 -2
- package/dist/confirmDelete.js +88 -0
- package/dist/server.js +79 -86
- package/dist/slimTools.js +78 -0
- package/dist/sn/client.js +189 -44
- package/dist/sn/entitlement.js +25 -6
- package/dist/sn/frontmatter.js +15 -4
- package/dist/sn/markdownSections.js +16 -1
- package/dist/sn/protocol004.js +11 -8
- package/dist/sn/scope.js +34 -0
- package/dist/sn/session.js +22 -4
- package/dist/tools/daily.js +7 -19
- package/dist/tools/history.js +1 -1
- package/dist/tools/links.js +2 -9
- package/dist/tools/notes.js +142 -42
- package/dist/tools/smartviews.js +5 -5
- package/dist/tools/tags.js +1 -1
- package/dist/tools/templates.js +42 -32
- package/dist/version.js +12 -0
- package/docs/self-hosted.md +7 -10
- package/docs/troubleshooting.md +97 -89
- package/package.json +6 -5
- package/dist/cli/install.js.map +0 -1
- package/dist/cli/login.js.map +0 -1
- package/dist/cli/logout.js.map +0 -1
- package/dist/cli/setup.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/security/errors.js.map +0 -1
- package/dist/security/logger.js.map +0 -1
- package/dist/security/redact.js.map +0 -1
- package/dist/security/regex.js.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/sn/cache.js.map +0 -1
- package/dist/sn/client.js.map +0 -1
- package/dist/sn/crypto.js.map +0 -1
- package/dist/sn/dates.js.map +0 -1
- package/dist/sn/entitlement.js.map +0 -1
- package/dist/sn/frontmatter.js.map +0 -1
- package/dist/sn/governance.js.map +0 -1
- package/dist/sn/http.js.map +0 -1
- package/dist/sn/links.js.map +0 -1
- package/dist/sn/markdownSections.js.map +0 -1
- package/dist/sn/predicates.js.map +0 -1
- package/dist/sn/protocol004.js.map +0 -1
- package/dist/sn/scope.js.map +0 -1
- package/dist/sn/search.js.map +0 -1
- package/dist/sn/session.js.map +0 -1
- package/dist/sn/tagHierarchy.js.map +0 -1
- package/dist/sn/tasks.js.map +0 -1
- package/dist/sn/templates.js.map +0 -1
- package/dist/sn/types.js.map +0 -1
- package/dist/tools/daily.js.map +0 -1
- package/dist/tools/export.js.map +0 -1
- package/dist/tools/history.js.map +0 -1
- package/dist/tools/links.js.map +0 -1
- package/dist/tools/notes.js.map +0 -1
- package/dist/tools/smartviews.js.map +0 -1
- package/dist/tools/tags.js.map +0 -1
- package/dist/tools/tasks.js.map +0 -1
- package/dist/tools/templates.js.map +0 -1
package/dist/sn/session.js
CHANGED
|
@@ -12,7 +12,24 @@ const MIGRATE = process.env.KEYCHAIN_SERVICE === undefined;
|
|
|
12
12
|
export async function saveSession(email, session) {
|
|
13
13
|
if (!email)
|
|
14
14
|
throw new Error("email required");
|
|
15
|
-
|
|
15
|
+
// Save over an existing entry that differs only in case, so one account
|
|
16
|
+
// never ends up with two keychain entries.
|
|
17
|
+
await keytar.setPassword(KEYCHAIN_SERVICE, await resolveAccount(email), JSON.stringify(session));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The keychain entry name actually stored for this email. Emails are not
|
|
21
|
+
* case-sensitive, but keychain entry names are: a session saved at login as
|
|
22
|
+
* "Me@example.com" must still be found when SN_EMAIL says "me@example.com".
|
|
23
|
+
* An exact match wins; otherwise the one stored entry that differs only in
|
|
24
|
+
* case is used. The email sent to Standard Notes is never changed.
|
|
25
|
+
*/
|
|
26
|
+
export async function resolveAccount(email) {
|
|
27
|
+
const wanted = email.trim();
|
|
28
|
+
const accounts = await storedAccounts();
|
|
29
|
+
if (accounts.includes(wanted))
|
|
30
|
+
return wanted;
|
|
31
|
+
const matches = accounts.filter((a) => a.toLowerCase() === wanted.toLowerCase());
|
|
32
|
+
return matches.length === 1 && matches[0] ? matches[0] : wanted;
|
|
16
33
|
}
|
|
17
34
|
/** Read the session, moving it from the legacy service name if needed. */
|
|
18
35
|
async function readRaw(email) {
|
|
@@ -29,17 +46,18 @@ async function readRaw(email) {
|
|
|
29
46
|
export async function loadSession(email) {
|
|
30
47
|
if (!email)
|
|
31
48
|
throw new Error("email required");
|
|
32
|
-
const raw = await readRaw(email);
|
|
49
|
+
const raw = await readRaw(await resolveAccount(email));
|
|
33
50
|
if (!raw)
|
|
34
51
|
return null;
|
|
35
52
|
try {
|
|
36
53
|
return JSON.parse(raw);
|
|
37
54
|
}
|
|
38
55
|
catch {
|
|
39
|
-
throw new Error("Stored session is corrupt; run `
|
|
56
|
+
throw new Error("Stored session is corrupt; run `standardnotes-mcp-login` again.");
|
|
40
57
|
}
|
|
41
58
|
}
|
|
42
|
-
export async function deleteSession(
|
|
59
|
+
export async function deleteSession(rawEmail) {
|
|
60
|
+
const email = await resolveAccount(rawEmail);
|
|
43
61
|
const deleted = await keytar.deletePassword(KEYCHAIN_SERVICE, email);
|
|
44
62
|
const legacyDeleted = MIGRATE
|
|
45
63
|
? await keytar.deletePassword(LEGACY_SERVICE, email)
|
package/dist/tools/daily.js
CHANGED
|
@@ -16,20 +16,19 @@ const DATE = z
|
|
|
16
16
|
.string()
|
|
17
17
|
.regex(/^\d{4}-\d{2}-\d{2}$/, "date must be YYYY-MM-DD")
|
|
18
18
|
.optional()
|
|
19
|
-
.describe("
|
|
19
|
+
.describe("YYYY-MM-DD, any day in the period; default today");
|
|
20
20
|
const PERIOD = z
|
|
21
21
|
.enum(["day", "week", "month"])
|
|
22
22
|
.default("day")
|
|
23
23
|
.describe("day = daily journal, week = ISO week (Mon–Sun), month = calendar month");
|
|
24
|
-
export const dailyListInput = z.object({ date: DATE });
|
|
25
|
-
export const dailyAppendInput = z.object({
|
|
26
|
-
content: z.string().min(1).max(1024 * 1024),
|
|
27
|
-
date: DATE,
|
|
28
|
-
});
|
|
29
24
|
export const periodicListInput = z.object({ period: PERIOD, date: DATE });
|
|
30
25
|
export const periodicAppendInput = z.object({
|
|
31
26
|
period: PERIOD,
|
|
32
|
-
content: z
|
|
27
|
+
content: z
|
|
28
|
+
.string()
|
|
29
|
+
.min(1)
|
|
30
|
+
.max(1024 * 1024)
|
|
31
|
+
.describe("The text to add (this field is `content`, not `text`)"),
|
|
33
32
|
date: DATE,
|
|
34
33
|
});
|
|
35
34
|
export function periodInfo(period, day) {
|
|
@@ -97,22 +96,11 @@ export function registerDailyHandlers(client, periodicTag = null) {
|
|
|
97
96
|
uuid,
|
|
98
97
|
created: true,
|
|
99
98
|
...(periodicTag !== null && tagUuid === null
|
|
100
|
-
? { notices: [`
|
|
99
|
+
? { notices: [`Tag "${periodicTag}" (SN_PERIODIC_TAG) isn't visible, so the note wasn't given it.`] }
|
|
101
100
|
: {}),
|
|
102
101
|
};
|
|
103
102
|
};
|
|
104
103
|
return {
|
|
105
|
-
// Back-compat aliases with the original response shape keys.
|
|
106
|
-
daily_list: async (raw) => {
|
|
107
|
-
const { date } = dailyListInput.parse(raw ?? {});
|
|
108
|
-
const r = await list("day", date);
|
|
109
|
-
return { date: r.label, timezone: r.timezone, count: r.count, notes: r.notes };
|
|
110
|
-
},
|
|
111
|
-
daily_append: async (raw) => {
|
|
112
|
-
const { content, date } = dailyAppendInput.parse(raw);
|
|
113
|
-
const r = await append("day", content, date);
|
|
114
|
-
return { ...r, date: r.label };
|
|
115
|
-
},
|
|
116
104
|
periodic_list: async (raw) => {
|
|
117
105
|
const { period, date } = periodicListInput.parse(raw ?? {});
|
|
118
106
|
return list(period, date);
|
package/dist/tools/history.js
CHANGED
|
@@ -23,7 +23,7 @@ export function registerHistoryHandlers(client) {
|
|
|
23
23
|
uuid,
|
|
24
24
|
count: revisions.length,
|
|
25
25
|
revisions,
|
|
26
|
-
notice: "
|
|
26
|
+
notice: "Only recent revisions are available on this account.",
|
|
27
27
|
};
|
|
28
28
|
},
|
|
29
29
|
notes_revision_get: async (raw) => {
|
package/dist/tools/links.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { isPaid } from "../sn/entitlement.js";
|
|
3
2
|
import { refuseWrite, uuidSchema } from "./notes.js";
|
|
4
3
|
export const linksInput = z.object({
|
|
5
4
|
uuid: uuidSchema.describe("The note whose links and backlinks to list"),
|
|
@@ -11,7 +10,7 @@ export const linkInput = z.object({
|
|
|
11
10
|
.string()
|
|
12
11
|
.max(500)
|
|
13
12
|
.optional()
|
|
14
|
-
.describe('
|
|
13
|
+
.describe('Heading for the link, e.g. "Related"'),
|
|
15
14
|
});
|
|
16
15
|
// Second line of defence: the client never returns protected notes.
|
|
17
16
|
const visible = (n) => !n.protected;
|
|
@@ -38,13 +37,7 @@ export function registerLinkHandlers(client) {
|
|
|
38
37
|
}
|
|
39
38
|
const result = await client.linkNotes(args);
|
|
40
39
|
await client.sync();
|
|
41
|
-
|
|
42
|
-
if (!isPaid(client.entitlement())) {
|
|
43
|
-
notices.push("Linked with a [[wikilink]] in the note text. Native Standard Notes note links are a paid Standard Notes feature, so the link shows as text in the app.");
|
|
44
|
-
}
|
|
45
|
-
return notices.length > 0
|
|
46
|
-
? { ok: true, ...result, notices }
|
|
47
|
-
: { ok: true, ...result };
|
|
40
|
+
return { ok: true, ...result };
|
|
48
41
|
},
|
|
49
42
|
};
|
|
50
43
|
}
|
package/dist/tools/notes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { NOTE_TYPES } from "../sn/types.js";
|
|
3
|
-
import { decideNoteType } from "../sn/entitlement.js";
|
|
3
|
+
import { decideNoteType, noticeOnce } from "../sn/entitlement.js";
|
|
4
4
|
import { ToolError } from "../security/errors.js";
|
|
5
5
|
import { parseDateInput, resolveTimeZone } from "../sn/dates.js";
|
|
6
6
|
import { parseFrontmatter } from "../sn/frontmatter.js";
|
|
@@ -8,7 +8,7 @@ const MAX_TEXT_BYTES = 10 * 1024 * 1024;
|
|
|
8
8
|
export const uuidSchema = z.string().uuid();
|
|
9
9
|
export const noteTypeSchema = z.enum(NOTE_TYPES);
|
|
10
10
|
export const listInput = z.object({
|
|
11
|
-
limit: z.number().int().min(1).max(200).default(
|
|
11
|
+
limit: z.number().int().min(1).max(200).default(25),
|
|
12
12
|
offset: z.number().int().min(0).default(0),
|
|
13
13
|
includeTrashed: z.boolean().default(false),
|
|
14
14
|
tag: z
|
|
@@ -20,7 +20,7 @@ export const listInput = z.object({
|
|
|
20
20
|
includeDescendants: z
|
|
21
21
|
.boolean()
|
|
22
22
|
.default(false)
|
|
23
|
-
.describe("
|
|
23
|
+
.describe("Also include notes under child tags"),
|
|
24
24
|
});
|
|
25
25
|
export const statsInput = z.object({});
|
|
26
26
|
export const searchInput = z.object({
|
|
@@ -28,16 +28,16 @@ export const searchInput = z.object({
|
|
|
28
28
|
.string()
|
|
29
29
|
.min(1)
|
|
30
30
|
.max(500)
|
|
31
|
-
.describe('
|
|
31
|
+
.describe('Words (text mode) or one regular expression (regex mode)'),
|
|
32
32
|
mode: z.enum(["text", "regex"]).default("text"),
|
|
33
33
|
sort: z
|
|
34
34
|
.enum(["relevance", "updated"])
|
|
35
35
|
.optional()
|
|
36
|
-
.describe('
|
|
36
|
+
.describe('Default: relevance (text mode), updated (regex mode)'),
|
|
37
37
|
fuzzy: z
|
|
38
38
|
.boolean()
|
|
39
39
|
.default(true)
|
|
40
|
-
.describe("
|
|
40
|
+
.describe("false = exact words only"),
|
|
41
41
|
limit: z.number().int().min(1).max(100).default(20),
|
|
42
42
|
cursor: z
|
|
43
43
|
.string()
|
|
@@ -50,7 +50,7 @@ export const searchInput = z.object({
|
|
|
50
50
|
.max(500)
|
|
51
51
|
.default(100)
|
|
52
52
|
.describe("Approximate characters of context around each match snippet"),
|
|
53
|
-
maxMatchesPerHit: z.number().int().min(1).max(50).default(
|
|
53
|
+
maxMatchesPerHit: z.number().int().min(1).max(50).default(3),
|
|
54
54
|
tag: z
|
|
55
55
|
.string()
|
|
56
56
|
.min(1)
|
|
@@ -62,7 +62,7 @@ export const searchInput = z.object({
|
|
|
62
62
|
updatedAfter: z
|
|
63
63
|
.string()
|
|
64
64
|
.optional()
|
|
65
|
-
.describe('
|
|
65
|
+
.describe('YYYY-MM-DD (user\'s timezone) or ISO datetime'),
|
|
66
66
|
updatedBefore: z.string().optional(),
|
|
67
67
|
includeTrashed: z.boolean().default(false),
|
|
68
68
|
});
|
|
@@ -71,7 +71,7 @@ export const getInput = z.object({
|
|
|
71
71
|
format: z
|
|
72
72
|
.enum(["content", "full", "outline", "section"])
|
|
73
73
|
.default("content")
|
|
74
|
-
.describe("
|
|
74
|
+
.describe("See tool description"),
|
|
75
75
|
section: z
|
|
76
76
|
.string()
|
|
77
77
|
.min(1)
|
|
@@ -94,43 +94,79 @@ export const createInput = z.object({
|
|
|
94
94
|
export const createManyInput = z.object({
|
|
95
95
|
notes: z.array(createInput).min(1).max(50),
|
|
96
96
|
});
|
|
97
|
-
|
|
98
|
-
.
|
|
97
|
+
const confirmTokenSchema = z
|
|
98
|
+
.string()
|
|
99
|
+
.max(64)
|
|
100
|
+
.optional()
|
|
101
|
+
.describe("Only after the user said yes to a delete: the confirmToken from the previous call");
|
|
102
|
+
const updateFields = z.object({
|
|
99
103
|
uuid: uuidSchema,
|
|
100
104
|
title: z.string().max(500).optional(),
|
|
101
105
|
text: z.string().max(MAX_TEXT_BYTES).optional(),
|
|
102
106
|
noteType: noteTypeSchema.optional(),
|
|
103
|
-
|
|
107
|
+
addTags: tagsArraySchema.optional().describe("Tag uuids to add; other tags stay"),
|
|
108
|
+
removeTags: tagsArraySchema.optional().describe("Tag uuids to remove; other tags stay"),
|
|
109
|
+
tags: tagsArraySchema
|
|
110
|
+
.optional()
|
|
111
|
+
.describe("Replaces ALL the note's tags; needs replaceTags=true. To add or remove one, use addTags / removeTags"),
|
|
112
|
+
replaceTags: z.boolean().optional().describe("Must be true when `tags` is given"),
|
|
104
113
|
trashed: z
|
|
105
114
|
.boolean()
|
|
106
115
|
.optional()
|
|
107
|
-
.describe("Set true to trash the note, false to restore from trash"),
|
|
116
|
+
.describe("Set true to trash the note (asks the user first), false to restore from trash"),
|
|
108
117
|
archived: z.boolean().optional().describe("Archive / unarchive the note"),
|
|
109
118
|
pinned: z.boolean().optional().describe("Pin / unpin the note"),
|
|
110
|
-
})
|
|
111
|
-
.refine((v) => v.title !== undefined ||
|
|
112
|
-
v.text !== undefined ||
|
|
113
|
-
v.noteType !== undefined ||
|
|
114
|
-
v.tags !== undefined ||
|
|
115
|
-
v.trashed !== undefined ||
|
|
116
|
-
v.archived !== undefined ||
|
|
117
|
-
v.pinned !== undefined, {
|
|
118
|
-
message: "provide at least one of title, text, noteType, tags, trashed, archived, or pinned",
|
|
119
119
|
});
|
|
120
|
+
function onlyTagChanges(v) {
|
|
121
|
+
return (v.title === undefined &&
|
|
122
|
+
v.text === undefined &&
|
|
123
|
+
v.noteType === undefined &&
|
|
124
|
+
v.tags === undefined &&
|
|
125
|
+
v.trashed === undefined &&
|
|
126
|
+
v.archived === undefined &&
|
|
127
|
+
v.pinned === undefined);
|
|
128
|
+
}
|
|
129
|
+
function checkUpdate(v, ctx) {
|
|
130
|
+
const adds = (v.addTags?.length ?? 0) > 0 || (v.removeTags?.length ?? 0) > 0;
|
|
131
|
+
if (onlyTagChanges(v) && !adds) {
|
|
132
|
+
ctx.addIssue({
|
|
133
|
+
code: "custom",
|
|
134
|
+
message: "provide at least one of title, text, noteType, addTags, removeTags, tags, trashed, archived, or pinned",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (v.tags !== undefined && v.replaceTags !== true) {
|
|
138
|
+
ctx.addIssue({
|
|
139
|
+
code: "custom",
|
|
140
|
+
path: ["replaceTags"],
|
|
141
|
+
message: "`tags` replaces ALL of the note's tags, so it needs replaceTags=true. To add or remove a tag, use addTags / removeTags instead",
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (v.tags !== undefined && adds) {
|
|
145
|
+
ctx.addIssue({
|
|
146
|
+
code: "custom",
|
|
147
|
+
path: ["tags"],
|
|
148
|
+
message: "use either tags (replace all) or addTags / removeTags, not both",
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const updateItem = updateFields.superRefine(checkUpdate);
|
|
153
|
+
export const updateInput = updateFields
|
|
154
|
+
.extend({ confirmToken: confirmTokenSchema })
|
|
155
|
+
.superRefine(checkUpdate);
|
|
120
156
|
export const appendInput = z.object({
|
|
121
157
|
uuid: uuidSchema,
|
|
122
158
|
content: z
|
|
123
159
|
.string()
|
|
124
160
|
.min(1)
|
|
125
161
|
.max(MAX_TEXT_BYTES)
|
|
126
|
-
.describe("
|
|
162
|
+
.describe("The text to add (this field is `content`, not `text`)"),
|
|
127
163
|
position: z.enum(["append", "prepend"]).default("append"),
|
|
128
164
|
section: z
|
|
129
165
|
.string()
|
|
130
166
|
.min(1)
|
|
131
167
|
.max(500)
|
|
132
168
|
.optional()
|
|
133
|
-
.describe('
|
|
169
|
+
.describe('Heading or "Parent::Child"; omit for the whole note'),
|
|
134
170
|
});
|
|
135
171
|
export const replaceInInput = z.object({
|
|
136
172
|
uuid: uuidSchema,
|
|
@@ -149,17 +185,20 @@ export const replaceInInput = z.object({
|
|
|
149
185
|
export const deleteInput = z.object({
|
|
150
186
|
uuid: uuidSchema,
|
|
151
187
|
permanent: z.boolean().default(false),
|
|
188
|
+
confirmToken: confirmTokenSchema,
|
|
152
189
|
});
|
|
153
190
|
export const updateManyInput = z.object({
|
|
154
191
|
updates: z
|
|
155
|
-
.array(
|
|
192
|
+
.array(updateItem)
|
|
156
193
|
.min(1)
|
|
157
194
|
.max(50)
|
|
158
195
|
.describe("One patch object per note, same fields as notes_update"),
|
|
196
|
+
confirmToken: confirmTokenSchema,
|
|
159
197
|
});
|
|
160
198
|
export const deleteManyInput = z.object({
|
|
161
199
|
uuids: z.array(uuidSchema).min(1).max(50),
|
|
162
200
|
permanent: z.boolean().default(false),
|
|
201
|
+
confirmToken: confirmTokenSchema,
|
|
163
202
|
});
|
|
164
203
|
export const frontmatterInput = z
|
|
165
204
|
.object({
|
|
@@ -170,7 +209,7 @@ export const frontmatterInput = z
|
|
|
170
209
|
.min(1)
|
|
171
210
|
.max(128)
|
|
172
211
|
.optional()
|
|
173
|
-
.describe("
|
|
212
|
+
.describe("Omit with get for all keys"),
|
|
174
213
|
value: z
|
|
175
214
|
.unknown()
|
|
176
215
|
.optional()
|
|
@@ -206,6 +245,30 @@ export function refuseWrite(note, op) {
|
|
|
206
245
|
throw new Error(`Note ${note.uuid} is ${reason} — cannot ${op} via MCP. ` +
|
|
207
246
|
`Unlock it in the Standard Notes app first.`);
|
|
208
247
|
}
|
|
248
|
+
/** Adds, then removes, tags one at a time through the scope-checked attach/detach. */
|
|
249
|
+
async function applyTagChanges(client, uuid, add, remove) {
|
|
250
|
+
for (const t of add ?? [])
|
|
251
|
+
await client.attachTag(uuid, t);
|
|
252
|
+
for (const t of remove ?? [])
|
|
253
|
+
await client.detachTag(uuid, t);
|
|
254
|
+
return {
|
|
255
|
+
...(add && add.length > 0 ? { addedTags: add } : {}),
|
|
256
|
+
...(remove && remove.length > 0 ? { removedTags: remove } : {}),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/** The fields client.updateNote understands. */
|
|
260
|
+
function clientPatch(v) {
|
|
261
|
+
return {
|
|
262
|
+
uuid: v.uuid,
|
|
263
|
+
title: v.title,
|
|
264
|
+
text: v.text,
|
|
265
|
+
noteType: v.noteType,
|
|
266
|
+
tags: v.tags,
|
|
267
|
+
trashed: v.trashed,
|
|
268
|
+
archived: v.archived,
|
|
269
|
+
pinned: v.pinned,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
209
272
|
/**
|
|
210
273
|
* Explains a paid-editor note type being saved as plain text on a free
|
|
211
274
|
* account (see decideNoteType). `super` never reaches here — the client
|
|
@@ -214,7 +277,7 @@ export function refuseWrite(note, op) {
|
|
|
214
277
|
function noteTypeNotice(client, requested) {
|
|
215
278
|
if (requested === undefined || requested === "super")
|
|
216
279
|
return undefined;
|
|
217
|
-
return decideNoteType(requested, client.entitlement()).notice;
|
|
280
|
+
return noticeOnce(client, decideNoteType(requested, client.entitlement()).notice);
|
|
218
281
|
}
|
|
219
282
|
function withNotices(result, notices) {
|
|
220
283
|
const unique = [...new Set(notices.filter((n) => !!n))];
|
|
@@ -302,9 +365,15 @@ export function registerNoteHandlers(client, opts = {}) {
|
|
|
302
365
|
if (existing && (existing.protected || existing.locked)) {
|
|
303
366
|
refuseWrite(existing, "update");
|
|
304
367
|
}
|
|
305
|
-
|
|
368
|
+
if (opts.guardDelete && existing && args.trashed === true && !existing.trashed) {
|
|
369
|
+
const decision = await opts.guardDelete({ tool: "notes_update", notes: [{ uuid: existing.uuid, title: existing.title }], permanent: false }, args.confirmToken);
|
|
370
|
+
if (!decision.proceed)
|
|
371
|
+
return decision.result;
|
|
372
|
+
}
|
|
373
|
+
const delta = onlyTagChanges(args) ? {} : await client.updateNote(clientPatch(args));
|
|
374
|
+
const tagged = await applyTagChanges(client, args.uuid, args.addTags, args.removeTags);
|
|
306
375
|
await client.sync();
|
|
307
|
-
return withNotices({ ok: true, ...delta }, [
|
|
376
|
+
return withNotices({ ok: true, ...delta, ...tagged }, [
|
|
308
377
|
args.noteType !== undefined && args.noteType !== existing?.noteType
|
|
309
378
|
? noteTypeNotice(client, args.noteType)
|
|
310
379
|
: undefined,
|
|
@@ -331,34 +400,65 @@ export function registerNoteHandlers(client, opts = {}) {
|
|
|
331
400
|
return { ok: true, ...result };
|
|
332
401
|
},
|
|
333
402
|
notes_update_many: async (raw) => {
|
|
334
|
-
const { updates } = updateManyInput.parse(raw);
|
|
335
|
-
|
|
403
|
+
const { updates, confirmToken } = updateManyInput.parse(raw);
|
|
404
|
+
if (opts.guardDelete) {
|
|
405
|
+
const trashing = [];
|
|
406
|
+
for (const u of updates.filter((x) => x.trashed === true)) {
|
|
407
|
+
const n = await client.getNote(u.uuid);
|
|
408
|
+
if (n && !n.trashed)
|
|
409
|
+
trashing.push({ uuid: n.uuid, title: n.title });
|
|
410
|
+
}
|
|
411
|
+
const decision = await opts.guardDelete({ tool: "notes_update_many", notes: trashing, permanent: false }, confirmToken);
|
|
412
|
+
if (!decision.proceed)
|
|
413
|
+
return decision.result;
|
|
414
|
+
}
|
|
415
|
+
const patches = updates.filter((u) => !onlyTagChanges(u)).map(clientPatch);
|
|
416
|
+
const result = patches.length > 0
|
|
417
|
+
? await client.updateNotesBatch(patches)
|
|
418
|
+
: { updated: [], failed: [] };
|
|
419
|
+
for (const u of updates) {
|
|
420
|
+
if ((u.addTags?.length ?? 0) === 0 && (u.removeTags?.length ?? 0) === 0)
|
|
421
|
+
continue;
|
|
422
|
+
if (result.failed.some((f) => f.uuid === u.uuid))
|
|
423
|
+
continue;
|
|
424
|
+
try {
|
|
425
|
+
await applyTagChanges(client, u.uuid, u.addTags, u.removeTags);
|
|
426
|
+
if (!result.updated.includes(u.uuid))
|
|
427
|
+
result.updated.push(u.uuid);
|
|
428
|
+
}
|
|
429
|
+
catch (err) {
|
|
430
|
+
result.failed.push({ uuid: u.uuid, error: err instanceof Error ? err.message : String(err) });
|
|
431
|
+
}
|
|
432
|
+
}
|
|
336
433
|
await client.sync();
|
|
337
434
|
return withNotices({ ok: result.failed.length === 0, ...result }, updates.map((u) => noteTypeNotice(client, u.noteType)));
|
|
338
435
|
},
|
|
339
436
|
notes_delete_many: async (raw) => {
|
|
340
|
-
const { uuids, permanent } = deleteManyInput.parse(raw);
|
|
341
|
-
if (opts.
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
437
|
+
const { uuids, permanent, confirmToken } = deleteManyInput.parse(raw);
|
|
438
|
+
if (opts.guardDelete) {
|
|
439
|
+
const notes = [];
|
|
440
|
+
for (const u of uuids) {
|
|
441
|
+
const n = await client.getNote(u);
|
|
442
|
+
notes.push({ uuid: u, title: n?.title ?? "(not found)" });
|
|
345
443
|
}
|
|
444
|
+
const decision = await opts.guardDelete({ tool: "notes_delete_many", notes, permanent }, confirmToken);
|
|
445
|
+
if (!decision.proceed)
|
|
446
|
+
return decision.result;
|
|
346
447
|
}
|
|
347
448
|
const result = await client.deleteNotesBatch(uuids, permanent);
|
|
348
449
|
await client.sync();
|
|
349
450
|
return { ok: result.failed.length === 0, permanent, ...result };
|
|
350
451
|
},
|
|
351
452
|
notes_delete: async (raw) => {
|
|
352
|
-
const { uuid, permanent } = deleteInput.parse(raw);
|
|
453
|
+
const { uuid, permanent, confirmToken } = deleteInput.parse(raw);
|
|
353
454
|
const existing = await client.getNote(uuid);
|
|
354
455
|
if (existing && (existing.protected || existing.locked)) {
|
|
355
456
|
refuseWrite(existing, "delete");
|
|
356
457
|
}
|
|
357
|
-
if (opts.
|
|
358
|
-
const
|
|
359
|
-
if (!
|
|
360
|
-
return
|
|
361
|
-
}
|
|
458
|
+
if (opts.guardDelete && existing) {
|
|
459
|
+
const decision = await opts.guardDelete({ tool: "notes_delete", notes: [{ uuid, title: existing.title }], permanent }, confirmToken);
|
|
460
|
+
if (!decision.proceed)
|
|
461
|
+
return decision.result;
|
|
362
462
|
}
|
|
363
463
|
await client.deleteNote(uuid, permanent);
|
|
364
464
|
await client.sync();
|
package/dist/tools/smartviews.js
CHANGED
|
@@ -6,8 +6,8 @@ export const smartviewsNotesInput = z.object({
|
|
|
6
6
|
.string()
|
|
7
7
|
.min(1)
|
|
8
8
|
.max(256)
|
|
9
|
-
.describe("Smart
|
|
10
|
-
limit: z.number().int().min(1).max(200).default(
|
|
9
|
+
.describe("Smart View uuid or title"),
|
|
10
|
+
limit: z.number().int().min(1).max(200).default(25),
|
|
11
11
|
offset: z.number().int().min(0).default(0),
|
|
12
12
|
});
|
|
13
13
|
// Predicate trees are validated structurally in the client (isPredicateJson);
|
|
@@ -15,8 +15,8 @@ export const smartviewsNotesInput = z.object({
|
|
|
15
15
|
export const notesQueryInput = z.object({
|
|
16
16
|
predicate: z
|
|
17
17
|
.record(z.string(), z.unknown())
|
|
18
|
-
.describe('
|
|
19
|
-
limit: z.number().int().min(1).max(200).default(
|
|
18
|
+
.describe('Leaf {"keypath","operator","value"} or {"operator":"and"|"or","value":[...]}. Operators: = != < > <= >= startsWith includes matches(regex) in not. Keypaths: title, text, trashed, archived, pinned, noteType, tagsCount, created_at_timestamp, updated_at_timestamp, frontmatter.<key> (includes for list values). E.g. {"keypath":"frontmatter.status","operator":"=","value":"active"}'),
|
|
19
|
+
limit: z.number().int().min(1).max(200).default(25),
|
|
20
20
|
offset: z.number().int().min(0).default(0),
|
|
21
21
|
});
|
|
22
22
|
// Second line of defence: the client never returns protected notes.
|
|
@@ -29,7 +29,7 @@ export function registerSmartViewHandlers(client) {
|
|
|
29
29
|
if (smartViews.length === 0 && !isPaid(client.entitlement())) {
|
|
30
30
|
return {
|
|
31
31
|
smartViews,
|
|
32
|
-
notice: "
|
|
32
|
+
notice: "This account has no Smart Views. notes_query can run the same kind of filter on demand.",
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
return { smartViews };
|
package/dist/tools/tags.js
CHANGED
|
@@ -18,7 +18,7 @@ export const tagsUpdateInput = z
|
|
|
18
18
|
parent: uuidSchema
|
|
19
19
|
.nullable()
|
|
20
20
|
.optional()
|
|
21
|
-
.describe("
|
|
21
|
+
.describe("Tag uuid, or null for top level"),
|
|
22
22
|
})
|
|
23
23
|
.refine((v) => v.title !== undefined || v.parent !== undefined, {
|
|
24
24
|
message: "provide at least one of title or parent",
|
package/dist/tools/templates.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { ToolError
|
|
2
|
+
import { ToolError } from "../security/errors.js";
|
|
3
3
|
import { isoWeek, resolveTimeZone, timeInZone, todayInZone } from "../sn/dates.js";
|
|
4
4
|
import { renderTemplate } from "../sn/templates.js";
|
|
5
|
-
import { decideNoteType } from "../sn/entitlement.js";
|
|
5
|
+
import { decideNoteType, noticeOnce } from "../sn/entitlement.js";
|
|
6
6
|
import { uuidSchema } from "./notes.js";
|
|
7
7
|
export const templatesListInput = z.object({});
|
|
8
8
|
export const createFromTemplateInput = z.object({
|
|
@@ -15,38 +15,30 @@ export const createFromTemplateInput = z.object({
|
|
|
15
15
|
.string()
|
|
16
16
|
.max(500)
|
|
17
17
|
.optional()
|
|
18
|
-
.describe("
|
|
18
|
+
.describe("May use placeholders; default: the template's title"),
|
|
19
19
|
vars: z
|
|
20
20
|
.record(z.string().regex(/^[A-Za-z0-9_-]+$/), z.string().max(10_000))
|
|
21
21
|
.optional()
|
|
22
|
-
.describe('
|
|
22
|
+
.describe('e.g. {"client": "Acme"} fills {{client}}'),
|
|
23
23
|
tags: z
|
|
24
24
|
.array(uuidSchema)
|
|
25
25
|
.max(20)
|
|
26
26
|
.optional()
|
|
27
|
-
.describe("Extra tag uuids
|
|
27
|
+
.describe("Extra tag uuids"),
|
|
28
28
|
});
|
|
29
29
|
const BUILTINS = "{{date}}, {{time}}, {{datetime}}, {{title}}, {{week}}, {{month}}, {{year}}";
|
|
30
|
-
export function registerTemplateHandlers(client,
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
catch (err) {
|
|
43
|
-
// No such folder, or it's outside this client's scope: no templates.
|
|
44
|
-
if (isToolError(err) && err.reason === "tag_not_found")
|
|
45
|
-
return null;
|
|
46
|
-
throw err;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const noTemplatesNotice = `No "${templatesTag}" folder is visible. Create a top-level "${templatesTag}" folder in Standard Notes and put template notes in it (placeholders: ${BUILTINS}, or any {{name}} you pass in vars).`;
|
|
30
|
+
export function registerTemplateHandlers(client, opts) {
|
|
31
|
+
const { templatesTag } = opts;
|
|
32
|
+
const shared = opts.shared === true;
|
|
33
|
+
/**
|
|
34
|
+
* Notes filed under the templates folder (and its subfolders). The folder
|
|
35
|
+
* may sit outside this client's scope; see listTemplateNotes.
|
|
36
|
+
*/
|
|
37
|
+
const listTemplates = () => client.listTemplateNotes(templatesTag, { shared });
|
|
38
|
+
const scopeHint = shared
|
|
39
|
+
? ""
|
|
40
|
+
: ` If this client is limited to certain tags (SN_READ_TAGS), also give each template one of those tags, or set SN_SHARED_TEMPLATES=true in this client's config to use every note tagged "${templatesTag}".`;
|
|
41
|
+
const noTemplatesNotice = `No "${templatesTag}" tag found. Create a tag named "${templatesTag}" in Standard Notes and add it to your template notes.${scopeHint} Placeholders: ${BUILTINS}, or any {{name}} you pass in vars.`;
|
|
50
42
|
return {
|
|
51
43
|
templates_list: async (raw) => {
|
|
52
44
|
templatesListInput.parse(raw ?? {});
|
|
@@ -55,6 +47,9 @@ export function registerTemplateHandlers(client, templatesTag) {
|
|
|
55
47
|
return { folder: templatesTag, templates: [], notice: noTemplatesNotice };
|
|
56
48
|
return {
|
|
57
49
|
folder: templatesTag,
|
|
50
|
+
...(templates.length === 0
|
|
51
|
+
? { notice: `No notes tagged "${templatesTag}" are templates this client can use.${scopeHint}` }
|
|
52
|
+
: {}),
|
|
58
53
|
templates: templates.map((t) => ({
|
|
59
54
|
uuid: t.uuid,
|
|
60
55
|
title: t.title,
|
|
@@ -72,9 +67,11 @@ export function registerTemplateHandlers(client, templatesTag) {
|
|
|
72
67
|
const summary = templates.find((t) => t.uuid === args.template) ??
|
|
73
68
|
templates.find((t) => t.title.toLowerCase() === wanted);
|
|
74
69
|
if (!summary) {
|
|
75
|
-
throw new ToolError("template_not_found", `No template "${args.template}"
|
|
70
|
+
throw new ToolError("template_not_found", `No template "${args.template}" tagged "${templatesTag}".`, "Run templates_list to see the available templates.");
|
|
76
71
|
}
|
|
77
|
-
|
|
72
|
+
// getTemplate, not getNote: a shared template outside this client's
|
|
73
|
+
// scope is readable here and nowhere else.
|
|
74
|
+
const template = await client.getTemplate(templatesTag, summary.uuid, { shared });
|
|
78
75
|
if (!template) {
|
|
79
76
|
throw new ToolError("template_not_found", `Template ${summary.uuid} not found.`);
|
|
80
77
|
}
|
|
@@ -94,11 +91,24 @@ export function registerTemplateHandlers(client, templatesTag) {
|
|
|
94
91
|
const values = { ...base, title: renderedTitle.text };
|
|
95
92
|
const isSuper = template.noteType === "super";
|
|
96
93
|
const body = renderTemplate(template.text, values, isSuper);
|
|
97
|
-
// Folders: the template's own
|
|
98
|
-
// plus any requested. createNote enforces
|
|
94
|
+
// Folders: the template's own that this client can see, minus the
|
|
95
|
+
// templates folder subtree, plus any requested. createNote enforces
|
|
96
|
+
// scope on all of them.
|
|
99
97
|
const templateFolders = new Set((await listTemplateFolderUuids(client, templatesTag)) ?? []);
|
|
100
|
-
const ownTags =
|
|
101
|
-
|
|
98
|
+
const ownTags = template.visibleTagUuids.filter((t) => !templateFolders.has(t));
|
|
99
|
+
let tags = [...new Set([...ownTags, ...(args.tags ?? [])])];
|
|
100
|
+
// A shared template outside the scope brings no in-scope folder. File
|
|
101
|
+
// the note in the scope folder when there is exactly one; with several,
|
|
102
|
+
// the caller has to choose.
|
|
103
|
+
const roots = client.scopeRootUuids();
|
|
104
|
+
if (tags.length === 0 && roots !== null) {
|
|
105
|
+
if (roots.length === 1) {
|
|
106
|
+
tags = [roots[0]];
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
throw new ToolError("tag_required", "This template has no tag this client can use, so the new note needs one.", "Run tags_list and pass an in-scope tag's uuid in `tags`.");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
102
112
|
// Same plan rules as notes_create: a super template is refused on a
|
|
103
113
|
// free account, other paid editor types become plain text.
|
|
104
114
|
const decision = decideNoteType(template.noteType, client.entitlement());
|
|
@@ -117,7 +127,7 @@ export function registerTemplateHandlers(client, templatesTag) {
|
|
|
117
127
|
// {{date}}/{{time}} were filled in this zone (SN_TIMEZONE, else the computer's).
|
|
118
128
|
timezone: tz,
|
|
119
129
|
...(unfilled.length > 0 ? { unfilled } : {}),
|
|
120
|
-
...(decision.notice ? { notices: [decision.notice] } : {}),
|
|
130
|
+
...(noticeOnce(client, decision.notice) ? { notices: [decision.notice] } : {}),
|
|
121
131
|
};
|
|
122
132
|
},
|
|
123
133
|
};
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
/** Package version, read from package.json (one level above src/ and dist/). */
|
|
3
|
+
export const VERSION = (() => {
|
|
4
|
+
try {
|
|
5
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
6
|
+
return typeof pkg.version === "string" ? pkg.version : "unknown";
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return "unknown";
|
|
10
|
+
}
|
|
11
|
+
})();
|
|
12
|
+
//# sourceMappingURL=version.js.map
|