standardnotes-mcp 0.0.0-stage → 3.0.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 +165 -0
- package/LICENSE +22 -0
- package/README.md +320 -3
- package/SECURITY.md +56 -0
- package/dist/cli/install.js +187 -0
- package/dist/cli/install.js.map +1 -0
- package/dist/cli/login.js +126 -0
- package/dist/cli/login.js.map +1 -0
- package/dist/cli/logout.js +22 -0
- package/dist/cli/logout.js.map +1 -0
- package/dist/cli/setup.js +200 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/config.js +60 -0
- package/dist/config.js.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/security/errors.js +20 -0
- package/dist/security/errors.js.map +1 -0
- package/dist/security/logger.js +17 -0
- package/dist/security/logger.js.map +1 -0
- package/dist/security/redact.js +31 -0
- package/dist/security/redact.js.map +1 -0
- package/dist/security/regex.js +27 -0
- package/dist/security/regex.js.map +1 -0
- package/dist/server.js +327 -0
- package/dist/server.js.map +1 -0
- package/dist/sn/cache.js +53 -0
- package/dist/sn/cache.js.map +1 -0
- package/dist/sn/client.js +1999 -0
- package/dist/sn/client.js.map +1 -0
- package/dist/sn/crypto.js +63 -0
- package/dist/sn/crypto.js.map +1 -0
- package/dist/sn/dates.js +157 -0
- package/dist/sn/dates.js.map +1 -0
- package/dist/sn/entitlement.js +75 -0
- package/dist/sn/entitlement.js.map +1 -0
- package/dist/sn/frontmatter.js +171 -0
- package/dist/sn/frontmatter.js.map +1 -0
- package/dist/sn/governance.js +40 -0
- package/dist/sn/governance.js.map +1 -0
- package/dist/sn/http.js +289 -0
- package/dist/sn/http.js.map +1 -0
- package/dist/sn/links.js +78 -0
- package/dist/sn/links.js.map +1 -0
- package/dist/sn/markdownSections.js +141 -0
- package/dist/sn/markdownSections.js.map +1 -0
- package/dist/sn/predicates.js +135 -0
- package/dist/sn/predicates.js.map +1 -0
- package/dist/sn/protocol004.js +401 -0
- package/dist/sn/protocol004.js.map +1 -0
- package/dist/sn/scope.js +68 -0
- package/dist/sn/scope.js.map +1 -0
- package/dist/sn/search.js +260 -0
- package/dist/sn/search.js.map +1 -0
- package/dist/sn/session.js +55 -0
- package/dist/sn/session.js.map +1 -0
- package/dist/sn/tagHierarchy.js +105 -0
- package/dist/sn/tagHierarchy.js.map +1 -0
- package/dist/sn/tasks.js +32 -0
- package/dist/sn/tasks.js.map +1 -0
- package/dist/sn/templates.js +23 -0
- package/dist/sn/templates.js.map +1 -0
- package/dist/sn/types.js +12 -0
- package/dist/sn/types.js.map +1 -0
- package/dist/tools/daily.js +126 -0
- package/dist/tools/daily.js.map +1 -0
- package/dist/tools/export.js +96 -0
- package/dist/tools/export.js.map +1 -0
- package/dist/tools/history.js +41 -0
- package/dist/tools/history.js.map +1 -0
- package/dist/tools/links.js +51 -0
- package/dist/tools/links.js.map +1 -0
- package/dist/tools/notes.js +404 -0
- package/dist/tools/notes.js.map +1 -0
- package/dist/tools/smartviews.js +52 -0
- package/dist/tools/smartviews.js.map +1 -0
- package/dist/tools/tags.js +82 -0
- package/dist/tools/tags.js.map +1 -0
- package/dist/tools/tasks.js +43 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/templates.js +145 -0
- package/dist/tools/templates.js.map +1 -0
- package/docs/protocol-004.md +72 -0
- package/docs/self-hosted.md +123 -0
- package/docs/troubleshooting.md +89 -0
- package/package.json +85 -6
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { ToolError } from "../security/errors.js";
|
|
2
|
+
import { assertSafeRegex } from "../security/regex.js";
|
|
3
|
+
import { snTimestampToMs } from "./dates.js";
|
|
4
|
+
function updatedTs(n) {
|
|
5
|
+
if (n.updated_at_timestamp > 0)
|
|
6
|
+
return snTimestampToMs(n.updated_at_timestamp);
|
|
7
|
+
const parsed = Date.parse(n.updatedAt);
|
|
8
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
9
|
+
}
|
|
10
|
+
function snippetAround(text, index, length, context) {
|
|
11
|
+
const start = Math.max(0, index - Math.floor(context / 2));
|
|
12
|
+
const end = Math.min(text.length, index + length + Math.floor(context / 2));
|
|
13
|
+
const prefix = start > 0 ? "…" : "";
|
|
14
|
+
const suffix = end < text.length ? "…" : "";
|
|
15
|
+
return prefix + text.slice(start, end).replace(/\s+/g, " ").trim() + suffix;
|
|
16
|
+
}
|
|
17
|
+
function collectMatches(text, matcher, contextLength, maxMatches) {
|
|
18
|
+
const matches = [];
|
|
19
|
+
let totalMatches = 0;
|
|
20
|
+
matcher.lastIndex = 0;
|
|
21
|
+
let m;
|
|
22
|
+
while ((m = matcher.exec(text)) !== null) {
|
|
23
|
+
// Zero-width matches would loop forever; nudge lastIndex forward.
|
|
24
|
+
if (m[0].length === 0) {
|
|
25
|
+
matcher.lastIndex++;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
totalMatches++;
|
|
29
|
+
if (matches.length < maxMatches) {
|
|
30
|
+
matches.push({
|
|
31
|
+
snippet: snippetAround(text, m.index, m[0].length, contextLength),
|
|
32
|
+
index: m.index,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return { matches, totalMatches, truncated: totalMatches > matches.length };
|
|
37
|
+
}
|
|
38
|
+
function escapeRegExp(s) {
|
|
39
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
40
|
+
}
|
|
41
|
+
// ---------- fuzzy helpers ----------
|
|
42
|
+
const WORD = /[\p{L}\p{N}]+/gu;
|
|
43
|
+
export function words(text) {
|
|
44
|
+
return text.toLowerCase().match(WORD) ?? [];
|
|
45
|
+
}
|
|
46
|
+
/** Allowed edit distance for a query word: none below 4 chars, 1 up to 7, 2 beyond. */
|
|
47
|
+
export function maxEditDistance(len) {
|
|
48
|
+
if (len < 4)
|
|
49
|
+
return 0;
|
|
50
|
+
if (len < 8)
|
|
51
|
+
return 1;
|
|
52
|
+
return 2;
|
|
53
|
+
}
|
|
54
|
+
/** Levenshtein distance with an early exit once it exceeds `max`. */
|
|
55
|
+
export function editDistance(a, b, max) {
|
|
56
|
+
if (a === b)
|
|
57
|
+
return 0;
|
|
58
|
+
if (Math.abs(a.length - b.length) > max)
|
|
59
|
+
return max + 1;
|
|
60
|
+
let prev = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
61
|
+
for (let i = 1; i <= a.length; i++) {
|
|
62
|
+
const cur = [i];
|
|
63
|
+
let rowMin = i;
|
|
64
|
+
for (let j = 1; j <= b.length; j++) {
|
|
65
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
66
|
+
const v = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + cost);
|
|
67
|
+
cur.push(v);
|
|
68
|
+
if (v < rowMin)
|
|
69
|
+
rowMin = v;
|
|
70
|
+
}
|
|
71
|
+
if (rowMin > max)
|
|
72
|
+
return max + 1;
|
|
73
|
+
prev = cur;
|
|
74
|
+
}
|
|
75
|
+
return prev[b.length];
|
|
76
|
+
}
|
|
77
|
+
function trigrams(s) {
|
|
78
|
+
const t = ` ${s.toLowerCase().replace(/\s+/g, " ").trim()} `;
|
|
79
|
+
const out = new Set();
|
|
80
|
+
for (let i = 0; i + 3 <= t.length; i++)
|
|
81
|
+
out.add(t.slice(i, i + 3));
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
/** Jaccard similarity of character trigrams, 0..1. */
|
|
85
|
+
export function titleSimilarity(a, b) {
|
|
86
|
+
const A = trigrams(a);
|
|
87
|
+
const B = trigrams(b);
|
|
88
|
+
if (A.size === 0 || B.size === 0)
|
|
89
|
+
return 0;
|
|
90
|
+
let inter = 0;
|
|
91
|
+
for (const g of A)
|
|
92
|
+
if (B.has(g))
|
|
93
|
+
inter++;
|
|
94
|
+
return inter / (A.size + B.size - inter);
|
|
95
|
+
}
|
|
96
|
+
/** Title similarity at or above this counts as a match on its own (fuzzy mode). */
|
|
97
|
+
const TITLE_MATCH_THRESHOLD = 0.45;
|
|
98
|
+
function countOccurrences(haystack, needle) {
|
|
99
|
+
if (needle === "")
|
|
100
|
+
return 0;
|
|
101
|
+
let count = 0;
|
|
102
|
+
let i = haystack.indexOf(needle);
|
|
103
|
+
while (i !== -1) {
|
|
104
|
+
count++;
|
|
105
|
+
i = haystack.indexOf(needle, i + needle.length);
|
|
106
|
+
}
|
|
107
|
+
return count;
|
|
108
|
+
}
|
|
109
|
+
const K1 = 1.2;
|
|
110
|
+
const B = 0.75;
|
|
111
|
+
function bm25Tf(tf, len, avgLen) {
|
|
112
|
+
if (tf === 0)
|
|
113
|
+
return 0;
|
|
114
|
+
const norm = avgLen > 0 ? len / avgLen : 1;
|
|
115
|
+
return (tf * (K1 + 1)) / (tf + K1 * (1 - B + B * norm));
|
|
116
|
+
}
|
|
117
|
+
// ---------- search ----------
|
|
118
|
+
function passesFilters(n, opts) {
|
|
119
|
+
if (!opts.includeTrashed && n.trashed)
|
|
120
|
+
return false;
|
|
121
|
+
if (opts.isAllowed && !opts.isAllowed(n.uuid))
|
|
122
|
+
return false;
|
|
123
|
+
if (opts.noteType !== undefined && n.noteType !== opts.noteType)
|
|
124
|
+
return false;
|
|
125
|
+
const ts = updatedTs(n);
|
|
126
|
+
if (opts.updatedAfter !== undefined && ts < opts.updatedAfter)
|
|
127
|
+
return false;
|
|
128
|
+
if (opts.updatedBefore !== undefined && ts > opts.updatedBefore)
|
|
129
|
+
return false;
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
function sortHits(hits, sort) {
|
|
133
|
+
hits.sort((a, b) => sort === "relevance" && b.score !== a.score
|
|
134
|
+
? b.score - a.score
|
|
135
|
+
: updatedTs(b.note) - updatedTs(a.note));
|
|
136
|
+
}
|
|
137
|
+
function searchRegex(candidates, opts) {
|
|
138
|
+
assertSafeRegex(opts.query);
|
|
139
|
+
const re = new RegExp(opts.query, "gi");
|
|
140
|
+
const probe = new RegExp(opts.query, "i");
|
|
141
|
+
const hits = [];
|
|
142
|
+
for (const n of candidates) {
|
|
143
|
+
const haystack = `${n.title}\n${n.text}`;
|
|
144
|
+
if (!probe.test(haystack))
|
|
145
|
+
continue;
|
|
146
|
+
const r = collectMatches(haystack, re, opts.contextLength, opts.maxMatchesPerHit);
|
|
147
|
+
hits.push({ note: n, ...r, fuzzy: false, score: r.totalMatches });
|
|
148
|
+
}
|
|
149
|
+
sortHits(hits, opts.sort ?? "updated");
|
|
150
|
+
return { hits: hits.map(stripScore), totalCount: hits.length };
|
|
151
|
+
}
|
|
152
|
+
function stripScore(h) {
|
|
153
|
+
const { score: _score, ...rest } = h;
|
|
154
|
+
return rest;
|
|
155
|
+
}
|
|
156
|
+
export function searchDecryptedNotes(notes, opts) {
|
|
157
|
+
// The candidate set is exactly what this client may see; every statistic
|
|
158
|
+
// below is derived from it alone.
|
|
159
|
+
const candidates = [];
|
|
160
|
+
for (const n of notes)
|
|
161
|
+
if (passesFilters(n, opts))
|
|
162
|
+
candidates.push(n);
|
|
163
|
+
if (opts.mode === "regex")
|
|
164
|
+
return searchRegex(candidates, opts);
|
|
165
|
+
const query = opts.query.trim();
|
|
166
|
+
const tokens = [...new Set(opts.query
|
|
167
|
+
.split(/\s+/)
|
|
168
|
+
.map((t) => t.trim().toLowerCase())
|
|
169
|
+
.filter((t) => t.length > 0))];
|
|
170
|
+
if (tokens.length === 0) {
|
|
171
|
+
throw new ToolError("query_empty", "Search query has no searchable tokens.", "Pass at least one non-whitespace character.");
|
|
172
|
+
}
|
|
173
|
+
const fuzzy = opts.fuzzy ?? true;
|
|
174
|
+
// Corpus statistics over visible candidates only.
|
|
175
|
+
const N = candidates.length;
|
|
176
|
+
const df = new Map();
|
|
177
|
+
let totalBodyLen = 0;
|
|
178
|
+
let totalTitleLen = 0;
|
|
179
|
+
const lowered = candidates.map((n) => {
|
|
180
|
+
const title = n.title.toLowerCase();
|
|
181
|
+
const body = n.text.toLowerCase();
|
|
182
|
+
totalBodyLen += body.length;
|
|
183
|
+
totalTitleLen += title.length;
|
|
184
|
+
for (const t of tokens) {
|
|
185
|
+
if (title.includes(t) || body.includes(t))
|
|
186
|
+
df.set(t, (df.get(t) ?? 0) + 1);
|
|
187
|
+
}
|
|
188
|
+
return { title, body };
|
|
189
|
+
});
|
|
190
|
+
const avgBody = N > 0 ? totalBodyLen / N : 0;
|
|
191
|
+
const avgTitle = N > 0 ? totalTitleLen / N : 0;
|
|
192
|
+
const idf = (t) => {
|
|
193
|
+
const d = df.get(t) ?? 0;
|
|
194
|
+
return Math.log(1 + (N - d + 0.5) / (d + 0.5));
|
|
195
|
+
};
|
|
196
|
+
const hits = [];
|
|
197
|
+
candidates.forEach((n, i) => {
|
|
198
|
+
const { title, body } = lowered[i];
|
|
199
|
+
let noteWords = null;
|
|
200
|
+
const fuzzyWordsFound = new Set();
|
|
201
|
+
let allTokensMatch = true;
|
|
202
|
+
let usedFuzzy = false;
|
|
203
|
+
let score = 0;
|
|
204
|
+
for (const t of tokens) {
|
|
205
|
+
let tfTitle = countOccurrences(title, t);
|
|
206
|
+
let tfBody = countOccurrences(body, t);
|
|
207
|
+
if (tfTitle + tfBody === 0 && fuzzy) {
|
|
208
|
+
const max = maxEditDistance(t.length);
|
|
209
|
+
if (max > 0) {
|
|
210
|
+
noteWords ??= new Set([...words(n.title), ...words(n.text)]);
|
|
211
|
+
for (const w of noteWords) {
|
|
212
|
+
if (editDistance(t, w, max) <= max) {
|
|
213
|
+
fuzzyWordsFound.add(w);
|
|
214
|
+
// Fuzzy hits count for half an exact hit.
|
|
215
|
+
tfTitle += countOccurrences(title, w) * 0.5;
|
|
216
|
+
tfBody += countOccurrences(body, w) * 0.5;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (tfTitle + tfBody > 0)
|
|
220
|
+
usedFuzzy = true;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (tfTitle + tfBody === 0)
|
|
224
|
+
allTokensMatch = false;
|
|
225
|
+
const w = idf(t);
|
|
226
|
+
score += w * bm25Tf(tfBody, body.length, avgBody);
|
|
227
|
+
score += 2 * w * bm25Tf(tfTitle, title.length, avgTitle);
|
|
228
|
+
}
|
|
229
|
+
const sim = fuzzy ? titleSimilarity(query, n.title) : 0;
|
|
230
|
+
const titleMatch = sim >= TITLE_MATCH_THRESHOLD;
|
|
231
|
+
if (!allTokensMatch && !titleMatch)
|
|
232
|
+
return;
|
|
233
|
+
score += 3 * sim;
|
|
234
|
+
if (tokens.length > 1 && `${title}\n${body}`.includes(query.toLowerCase())) {
|
|
235
|
+
score += 1; // exact phrase bonus
|
|
236
|
+
}
|
|
237
|
+
const haystack = `${n.title}\n${n.text}`;
|
|
238
|
+
const needles = [...tokens, ...fuzzyWordsFound];
|
|
239
|
+
const all = [];
|
|
240
|
+
let total = 0;
|
|
241
|
+
for (const needle of needles) {
|
|
242
|
+
const r = collectMatches(haystack, new RegExp(escapeRegExp(needle), "gi"), opts.contextLength, opts.maxMatchesPerHit);
|
|
243
|
+
all.push(...r.matches);
|
|
244
|
+
total += r.totalMatches;
|
|
245
|
+
}
|
|
246
|
+
all.sort((a, b) => a.index - b.index);
|
|
247
|
+
const matches = all.slice(0, opts.maxMatchesPerHit);
|
|
248
|
+
hits.push({
|
|
249
|
+
note: n,
|
|
250
|
+
matches,
|
|
251
|
+
totalMatches: total,
|
|
252
|
+
truncated: total > matches.length,
|
|
253
|
+
fuzzy: usedFuzzy || !allTokensMatch,
|
|
254
|
+
score,
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
sortHits(hits, opts.sort ?? "relevance");
|
|
258
|
+
return { hits: hits.map(stripScore), totalCount: hits.length };
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/sn/search.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB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EAAE,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import keytar from "@napi-rs/keyring/keytar.js";
|
|
2
|
+
/**
|
|
3
|
+
* Keychain service name. Renamed from "mcp-standardnotes" to
|
|
4
|
+
* "standardnotes-mcp" in 3.0.0; sessions stored under the old name are
|
|
5
|
+
* moved over transparently the first time they're read, so nobody has to
|
|
6
|
+
* log in again. An explicit KEYCHAIN_SERVICE disables the migration — the
|
|
7
|
+
* operator chose the name, we don't touch anything else.
|
|
8
|
+
*/
|
|
9
|
+
const LEGACY_SERVICE = "mcp-standardnotes";
|
|
10
|
+
export const KEYCHAIN_SERVICE = process.env.KEYCHAIN_SERVICE ?? "standardnotes-mcp";
|
|
11
|
+
const MIGRATE = process.env.KEYCHAIN_SERVICE === undefined;
|
|
12
|
+
export async function saveSession(email, session) {
|
|
13
|
+
if (!email)
|
|
14
|
+
throw new Error("email required");
|
|
15
|
+
await keytar.setPassword(KEYCHAIN_SERVICE, email, JSON.stringify(session));
|
|
16
|
+
}
|
|
17
|
+
/** Read the session, moving it from the legacy service name if needed. */
|
|
18
|
+
async function readRaw(email) {
|
|
19
|
+
const raw = await keytar.getPassword(KEYCHAIN_SERVICE, email);
|
|
20
|
+
if (raw || !MIGRATE)
|
|
21
|
+
return raw;
|
|
22
|
+
const legacy = await keytar.getPassword(LEGACY_SERVICE, email);
|
|
23
|
+
if (!legacy)
|
|
24
|
+
return null;
|
|
25
|
+
await keytar.setPassword(KEYCHAIN_SERVICE, email, legacy);
|
|
26
|
+
await keytar.deletePassword(LEGACY_SERVICE, email);
|
|
27
|
+
return legacy;
|
|
28
|
+
}
|
|
29
|
+
export async function loadSession(email) {
|
|
30
|
+
if (!email)
|
|
31
|
+
throw new Error("email required");
|
|
32
|
+
const raw = await readRaw(email);
|
|
33
|
+
if (!raw)
|
|
34
|
+
return null;
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(raw);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
throw new Error("Stored session is corrupt; run `npm run login` again.");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export async function deleteSession(email) {
|
|
43
|
+
const deleted = await keytar.deletePassword(KEYCHAIN_SERVICE, email);
|
|
44
|
+
const legacyDeleted = MIGRATE
|
|
45
|
+
? await keytar.deletePassword(LEGACY_SERVICE, email)
|
|
46
|
+
: false;
|
|
47
|
+
return deleted || legacyDeleted;
|
|
48
|
+
}
|
|
49
|
+
/** Emails with a stored session, under the current or legacy service name. */
|
|
50
|
+
export async function storedAccounts() {
|
|
51
|
+
const current = await keytar.findCredentials(KEYCHAIN_SERVICE);
|
|
52
|
+
const legacy = MIGRATE ? await keytar.findCredentials(LEGACY_SERVICE) : [];
|
|
53
|
+
return [...new Set([...current, ...legacy].map((c) => c.account))];
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/sn/session.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,4BAA4B,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAC3C,MAAM,CAAC,MAAM,gBAAgB,GAC3B,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,mBAAmB,CAAC;AACtD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC;AAiB3D,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,KAAa,EACb,OAAsB;IAEtB,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;IAC9C,MAAM,MAAM,CAAC,WAAW,CAAC,gBAAgB,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,0EAA0E;AAC1E,KAAK,UAAU,OAAO,CAAC,KAAa;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U,cAAc;IAClC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAC/D,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,MAAM,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3E,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standard Notes stores tag folder hierarchy as a TagToParentTag reference
|
|
3
|
+
* on the CHILD tag. See standardnotes/app packages/models .../Tag.ts
|
|
4
|
+
* `parentId` getter and .../Reference/Functions.ts `isTagToParentTagReference`.
|
|
5
|
+
*
|
|
6
|
+
* Modern references carry `reference_type: "TagToParentTag"`. Payloads written
|
|
7
|
+
* by older clients omit `reference_type` and just have `content_type: "SN|Tag"`;
|
|
8
|
+
* historically that shape only ever meant "parent of" (there is no reverse
|
|
9
|
+
* link from parent to children in SN), so we accept it.
|
|
10
|
+
*
|
|
11
|
+
* A reference with `reference_type` set to anything other than TagToParentTag
|
|
12
|
+
* (e.g. TagToFile) is NOT a parent link even when content_type is SN|Tag —
|
|
13
|
+
* so gate on the value, not just presence.
|
|
14
|
+
*/
|
|
15
|
+
export function parentUuidOf(t) {
|
|
16
|
+
for (const r of t.references) {
|
|
17
|
+
if (r.reference_type === "TagToParentTag")
|
|
18
|
+
return r.uuid;
|
|
19
|
+
if (r.reference_type === undefined && r.content_type === "SN|Tag") {
|
|
20
|
+
return r.uuid;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
export function stripParentRefs(refs) {
|
|
26
|
+
return refs.filter((r) => {
|
|
27
|
+
if (r.reference_type === "TagToParentTag")
|
|
28
|
+
return false;
|
|
29
|
+
if (r.reference_type === undefined && r.content_type === "SN|Tag") {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export function makeParentRef(parentUuid) {
|
|
36
|
+
return {
|
|
37
|
+
uuid: parentUuid,
|
|
38
|
+
content_type: "SN|Tag",
|
|
39
|
+
reference_type: "TagToParentTag",
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* All tag UUIDs in the subtree rooted at `rootUuid`, INCLUDING the root
|
|
44
|
+
* itself. Order is BFS by depth but callers should treat the result as a
|
|
45
|
+
* set. A pre-existing cycle in the vault (data corruption) is handled
|
|
46
|
+
* defensively via a visited-set — no infinite loop, no throw.
|
|
47
|
+
*
|
|
48
|
+
* Returns an empty set when the root is unknown; a leaf tag returns just
|
|
49
|
+
* its own uuid.
|
|
50
|
+
*/
|
|
51
|
+
export function subtreeTagUuids(tags, rootUuid) {
|
|
52
|
+
const result = new Set();
|
|
53
|
+
if (!tags.has(rootUuid))
|
|
54
|
+
return result;
|
|
55
|
+
// One-pass parent → children index so BFS is O(n + edges) rather than
|
|
56
|
+
// O(n * depth) if we walked ancestors per tag.
|
|
57
|
+
const childrenByParent = new Map();
|
|
58
|
+
for (const t of tags.values()) {
|
|
59
|
+
const p = parentUuidOf(t);
|
|
60
|
+
if (p === null)
|
|
61
|
+
continue;
|
|
62
|
+
const list = childrenByParent.get(p);
|
|
63
|
+
if (list)
|
|
64
|
+
list.push(t.uuid);
|
|
65
|
+
else
|
|
66
|
+
childrenByParent.set(p, [t.uuid]);
|
|
67
|
+
}
|
|
68
|
+
const queue = [rootUuid];
|
|
69
|
+
while (queue.length > 0) {
|
|
70
|
+
const cur = queue.shift();
|
|
71
|
+
if (result.has(cur))
|
|
72
|
+
continue;
|
|
73
|
+
result.add(cur);
|
|
74
|
+
const kids = childrenByParent.get(cur);
|
|
75
|
+
if (kids)
|
|
76
|
+
queue.push(...kids);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Would re-parenting `childUuid` under `newParentUuid` create a cycle?
|
|
82
|
+
*
|
|
83
|
+
* Walks up the ancestor chain from `newParentUuid`. If the walk ever visits
|
|
84
|
+
* `childUuid`, the child is currently an ancestor of the proposed parent —
|
|
85
|
+
* setting the link would close the loop. A pre-existing cycle in the vault
|
|
86
|
+
* (data-corruption case) is detected and treated as "not our cycle" so a
|
|
87
|
+
* legitimate re-parent can still repair a broken tree.
|
|
88
|
+
*/
|
|
89
|
+
export function wouldCreateCycle(tags, childUuid, newParentUuid) {
|
|
90
|
+
if (childUuid === newParentUuid)
|
|
91
|
+
return true;
|
|
92
|
+
let cursor = newParentUuid;
|
|
93
|
+
const seen = new Set();
|
|
94
|
+
while (cursor) {
|
|
95
|
+
if (seen.has(cursor))
|
|
96
|
+
return false;
|
|
97
|
+
seen.add(cursor);
|
|
98
|
+
if (cursor === childUuid)
|
|
99
|
+
return true;
|
|
100
|
+
const t = tags.get(cursor);
|
|
101
|
+
cursor = t ? parentUuidOf(t) : null;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=tagHierarchy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tagHierarchy.js","sourceRoot":"","sources":["../../src/sn/tagHierarchy.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,YAAY,CAAC,CAAe;IAC1C,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC;QAC7B,IAAI,CAAC,CAAC,cAAc,KAAK,gBAAgB;YAAE,OAAO,CAAC,CAAC,IAAI,CAAC;QACzD,IAAI,CAAC,CAAC,cAAc,KAAK,SAAS,IAAI,CAAC,CAAC,YAAY,KAAK,QAAQ,EA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/errors.js";
|
|
2
|
+
const TASK_LINE = /^(\s*[-*+]\s+)\[([ xX])\]\s+(.*)$/;
|
|
3
|
+
export function extractTasks(text) {
|
|
4
|
+
const lines = text.split(/\r?\n/);
|
|
5
|
+
const tasks = [];
|
|
6
|
+
for (let i = 0; i < lines.length; i++) {
|
|
7
|
+
const m = TASK_LINE.exec(lines[i] ?? "");
|
|
8
|
+
if (!m)
|
|
9
|
+
continue;
|
|
10
|
+
tasks.push({
|
|
11
|
+
line: i,
|
|
12
|
+
text: (m[3] ?? "").trim(),
|
|
13
|
+
done: (m[2] ?? " ").toLowerCase() === "x",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return tasks;
|
|
17
|
+
}
|
|
18
|
+
export function setTaskState(text, line, done) {
|
|
19
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
20
|
+
const lines = text.split(/\r?\n/);
|
|
21
|
+
const target = lines[line];
|
|
22
|
+
if (target === undefined) {
|
|
23
|
+
throw new ToolError("task_not_found", `Line ${line} does not exist in this note.`, "Re-run notes_tasks to get current line numbers — the note may have changed.");
|
|
24
|
+
}
|
|
25
|
+
const m = TASK_LINE.exec(target);
|
|
26
|
+
if (!m) {
|
|
27
|
+
throw new ToolError("task_not_found", `Line ${line} is not a checkbox task line.`, "Re-run notes_tasks to get current line numbers — the note may have changed.");
|
|
28
|
+
}
|
|
29
|
+
lines[line] = `${m[1]}[${done ? "x" : " "}] ${m[3]}`;
|
|
30
|
+
return lines.join(eol);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/sn/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAelD,MAAM,SAAS,GAAG,mCAAmC,CAAC;AAEtD,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,KAAK,GAAG,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AA6E,CAC9E,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template rendering: plain `{{name}}` substitution, nothing else. No
|
|
3
|
+
* expressions, no code — template notes are data, and a template written
|
|
4
|
+
* by anyone (or injected into a note) can only ever produce text.
|
|
5
|
+
*/
|
|
6
|
+
const PLACEHOLDER = /\{\{\s*([A-Za-z0-9_-]+)\s*\}\}/g;
|
|
7
|
+
/**
|
|
8
|
+
* Replace `{{name}}` with values[name]. `jsonSafe` escapes values for
|
|
9
|
+
* insertion inside a JSON string (Super notes store Lexical JSON).
|
|
10
|
+
*/
|
|
11
|
+
export function renderTemplate(text, values, jsonSafe = false) {
|
|
12
|
+
const unfilled = new Set();
|
|
13
|
+
const out = text.replace(PLACEHOLDER, (whole, name) => {
|
|
14
|
+
const v = Object.prototype.hasOwnProperty.call(values, name) ? values[name] : undefined;
|
|
15
|
+
if (v === undefined) {
|
|
16
|
+
unfilled.add(name);
|
|
17
|
+
return whole;
|
|
18
|
+
}
|
|
19
|
+
return jsonSafe ? JSON.stringify(v).slice(1, -1) : v;
|
|
20
|
+
});
|
|
21
|
+
return { text: out, unfilled: [...unfilled] };
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../../src/sn/templates.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,GAAG,iCAAiC,CAAC;AAQtD;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,IAAY,EACZ,MAA8B,EAC9B,QAAQ,GAAG,KAAK;IAEhB,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,IAAY,EAAE,EAAE;QAC5D,MAAM,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QACxF,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;YACpB,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACnB,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC;AAChD,CAAC"}
|
package/dist/sn/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sn/types.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,YAAY;IACZ,UAAU;IACV,OAAO;IACP,MAAM;IACN,WAAW;IACX,MAAM;IACN,aAAa;IACb,gBAAgB;IAChB,SAAS;CACD,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { isoWeek, monthRange, parseDateInput, resolveTimeZone, todayInZone, weekRange, } from "../sn/dates.js";
|
|
3
|
+
import { ToolError } from "../security/errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* Periodic notes: daily, weekly and monthly. Each period has one note with
|
|
6
|
+
* a fixed title — "Journal 2026-12-05", "Week 2026-W49", "Month 2026-12" —
|
|
7
|
+
* found among the notes created during that period, or created on demand
|
|
8
|
+
* for the current period. These are ordinary notes, so they work on every
|
|
9
|
+
* Standard Notes plan (the SN app's Daily Notebook view is a paid feature
|
|
10
|
+
* and is never switched on by this server).
|
|
11
|
+
*
|
|
12
|
+
* Creation dates can't be backdated, so a past period can only be appended
|
|
13
|
+
* to when its note already exists.
|
|
14
|
+
*/
|
|
15
|
+
const DATE = z
|
|
16
|
+
.string()
|
|
17
|
+
.regex(/^\d{4}-\d{2}-\d{2}$/, "date must be YYYY-MM-DD")
|
|
18
|
+
.optional()
|
|
19
|
+
.describe("Any day inside the period; defaults to today in SN_TIMEZONE (or the computer's timezone)");
|
|
20
|
+
const PERIOD = z
|
|
21
|
+
.enum(["day", "week", "month"])
|
|
22
|
+
.default("day")
|
|
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
|
+
export const periodicListInput = z.object({ period: PERIOD, date: DATE });
|
|
30
|
+
export const periodicAppendInput = z.object({
|
|
31
|
+
period: PERIOD,
|
|
32
|
+
content: z.string().min(1).max(1024 * 1024),
|
|
33
|
+
date: DATE,
|
|
34
|
+
});
|
|
35
|
+
export function periodInfo(period, day) {
|
|
36
|
+
if (period === "week") {
|
|
37
|
+
const { start, end } = weekRange(day);
|
|
38
|
+
const label = isoWeek(day).label;
|
|
39
|
+
return { period, label, title: `Week ${label}`, startDay: start, endDay: end };
|
|
40
|
+
}
|
|
41
|
+
if (period === "month") {
|
|
42
|
+
const { start, end, label } = monthRange(day);
|
|
43
|
+
return { period, label, title: `Month ${label}`, startDay: start, endDay: end };
|
|
44
|
+
}
|
|
45
|
+
return { period, label: day, title: `Journal ${day}`, startDay: day, endDay: day };
|
|
46
|
+
}
|
|
47
|
+
export function registerDailyHandlers(client, periodicTag = null) {
|
|
48
|
+
const bounds = (p, tz) => ({
|
|
49
|
+
start: parseDateInput(p.startDay, tz, false),
|
|
50
|
+
end: parseDateInput(p.endDay, tz, true),
|
|
51
|
+
});
|
|
52
|
+
/** uuid of the configured periodic folder, if set and visible. */
|
|
53
|
+
const periodicTagUuid = async () => {
|
|
54
|
+
if (periodicTag === null)
|
|
55
|
+
return null;
|
|
56
|
+
const tags = await client.listTags();
|
|
57
|
+
const hit = tags.find((t) => t.uuid === periodicTag) ??
|
|
58
|
+
tags.find((t) => t.title.toLowerCase() === periodicTag.toLowerCase());
|
|
59
|
+
return hit?.uuid ?? null;
|
|
60
|
+
};
|
|
61
|
+
const list = async (period, date) => {
|
|
62
|
+
const tz = resolveTimeZone();
|
|
63
|
+
const p = periodInfo(period, date ?? todayInZone(tz));
|
|
64
|
+
const { start, end } = bounds(p, tz);
|
|
65
|
+
const notes = await client.listNotesCreatedBetween(start, end);
|
|
66
|
+
return { period, label: p.label, from: p.startDay, to: p.endDay, timezone: tz, count: notes.length, notes };
|
|
67
|
+
};
|
|
68
|
+
const append = async (period, content, date) => {
|
|
69
|
+
const tz = resolveTimeZone();
|
|
70
|
+
const today = todayInZone(tz);
|
|
71
|
+
const p = periodInfo(period, date ?? today);
|
|
72
|
+
const { start, end } = bounds(p, tz);
|
|
73
|
+
const created = await client.listNotesCreatedBetween(start, end);
|
|
74
|
+
const wanted = p.title.toLowerCase();
|
|
75
|
+
const existing = created.find((n) => n.title.toLowerCase() === wanted);
|
|
76
|
+
if (existing) {
|
|
77
|
+
const delta = await client.appendNote({ uuid: existing.uuid, content, position: "append" });
|
|
78
|
+
await client.sync();
|
|
79
|
+
return { ok: true, period, label: p.label, title: p.title, uuid: existing.uuid, created: false, ...delta };
|
|
80
|
+
}
|
|
81
|
+
if (periodInfo(period, today).label !== p.label) {
|
|
82
|
+
throw new ToolError("periodic_note_not_found", `No "${p.title}" note exists, and notes can't be created with a past creation date.`, "Omit `date` to use the current period, or use notes_create with a title of your choice.");
|
|
83
|
+
}
|
|
84
|
+
const tagUuid = await periodicTagUuid();
|
|
85
|
+
const uuid = await client.createNote({
|
|
86
|
+
title: p.title,
|
|
87
|
+
text: content,
|
|
88
|
+
// No explicit type: plan default (markdown on paid, plain-text on free).
|
|
89
|
+
...(tagUuid !== null ? { tags: [tagUuid] } : {}),
|
|
90
|
+
});
|
|
91
|
+
await client.sync();
|
|
92
|
+
return {
|
|
93
|
+
ok: true,
|
|
94
|
+
period,
|
|
95
|
+
label: p.label,
|
|
96
|
+
title: p.title,
|
|
97
|
+
uuid,
|
|
98
|
+
created: true,
|
|
99
|
+
...(periodicTag !== null && tagUuid === null
|
|
100
|
+
? { notices: [`Folder "${periodicTag}" (SN_PERIODIC_TAG) isn't visible, so the note was not filed under it.`] }
|
|
101
|
+
: {}),
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
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
|
+
periodic_list: async (raw) => {
|
|
117
|
+
const { period, date } = periodicListInput.parse(raw ?? {});
|
|
118
|
+
return list(period, date);
|
|
119
|
+
},
|
|
120
|
+
periodic_append: async (raw) => {
|
|
121
|
+
const { period, content, date } = periodicAppendInput.parse(raw);
|
|
122
|
+
return append(period, content, date);
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=daily.js.map
|