obsidian-sync-mcp 0.9.0 → 0.11.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 +31 -4
- package/dist/{chunk-VR63UUCB.js → chunk-XZ4HUASL.js} +150 -47
- package/dist/chunk-XZ4HUASL.js.map +1 -0
- package/dist/main.js +568 -18
- package/dist/main.js.map +1 -1
- package/dist/{vault-6H64Y46A.js → vault-7FFBJ5QT.js} +168 -5
- package/dist/vault-7FFBJ5QT.js.map +1 -0
- package/dist/vault-local-MF65KDVB.js +309 -0
- package/dist/vault-local-MF65KDVB.js.map +1 -0
- package/package.json +2 -2
- package/dist/chunk-VR63UUCB.js.map +0 -1
- package/dist/vault-6H64Y46A.js.map +0 -1
- package/dist/vault-local-OURGENR5.js +0 -154
- package/dist/vault-local-OURGENR5.js.map +0 -1
package/README.md
CHANGED
|
@@ -101,6 +101,7 @@ cd obsidian-sync-mcp
|
|
|
101
101
|
|
|
102
102
|
cat > .env <<EOF
|
|
103
103
|
COUCHDB_PASSWORD=changeme
|
|
104
|
+
MCP_AUTH_TOKEN=changeme-too
|
|
104
105
|
VAULT_NAME=MyVault
|
|
105
106
|
EOF
|
|
106
107
|
|
|
@@ -110,7 +111,7 @@ docker compose up -d
|
|
|
110
111
|
**After deployment:**
|
|
111
112
|
|
|
112
113
|
1. In Obsidian, install [Self-hosted LiveSync](https://github.com/vrtmrz/obsidian-livesync) and configure it with the credentials from the setup output
|
|
113
|
-
2. Your MCP endpoint is `https://your-app.fly.dev/mcp` (Fly.io)
|
|
114
|
+
2. Your MCP endpoint is `https://your-app.fly.dev/mcp` (Fly.io). With Docker Compose the MCP port is published on `localhost:8787` only; to reach it from other machines, put an HTTPS tunnel or reverse proxy in front (see [remote access](#c-run-on-your-machine)) and set `BASE_URL` to its public URL
|
|
114
115
|
3. The `MCP_AUTH_TOKEN` is the password you enter when an agent connects
|
|
115
116
|
|
|
116
117
|
```
|
|
@@ -175,7 +176,7 @@ Omit `COUCHDB_PASSPHRASE` if you don't use E2E encryption in LiveSync. Set `COUC
|
|
|
175
176
|
**Or with Docker:**
|
|
176
177
|
|
|
177
178
|
```bash
|
|
178
|
-
docker run -p 8787:8787 \
|
|
179
|
+
docker run -p 127.0.0.1:8787:8787 \
|
|
179
180
|
-v mcp-data:/data -e DATA_DIR=/data \
|
|
180
181
|
-e VAULT_PATH=/vault -v ~/Documents/MyVault:/vault \
|
|
181
182
|
-e VAULT_NAME=MyVault \
|
|
@@ -211,6 +212,27 @@ Set `BASE_URL` to the tunnel URL when using authentication.
|
|
|
211
212
|
| `move_note` | Move or rename a note — works across folders, creates destination folders automatically |
|
|
212
213
|
| `get_note_metadata` | Get frontmatter, tags, outgoing links, backlinks, size, and timestamps — navigate the knowledge graph |
|
|
213
214
|
|
|
215
|
+
### Attachments (opt-in)
|
|
216
|
+
|
|
217
|
+
With `ATTACHMENTS_ENABLED=true`, agents can also store images, PDFs, audio and video in the vault. In CouchDB mode they are written through livesync-commonlib, chunked and encrypted the same way as a file added in Obsidian, so they sync to every device.
|
|
218
|
+
|
|
219
|
+
| Tool | Description |
|
|
220
|
+
|---|---|
|
|
221
|
+
| `create_attachment_upload` | Get a one-time upload URL for a vault path. The agent sends the raw bytes there with HTTP `PUT`, e.g. `curl -fsS -X PUT --data-binary @shot.png '<url>'`. Use this for anything but tiny files |
|
|
222
|
+
| `write_attachment` | Fallback for clients that cannot make HTTP requests: save a tiny file from base64 (default limit 32 KB). Every byte is a model output token, so a 32 KB file is already ~13k tokens and minutes of generation |
|
|
223
|
+
| `move_attachment` | Move or rename an attachment (embeds in notes are not rewritten; the response lists notes that still point at the old path) |
|
|
224
|
+
| `delete_attachment` | Delete an attachment |
|
|
225
|
+
| `get_attachment_metadata` | Size, timestamps, and the notes that embed or link it |
|
|
226
|
+
| `list_attachments` | List attachments with size, date and how many notes use each. Filter by folder, name or extension, sort by name, date or size, or pass `unreferenced=true` to find files no note embeds or links |
|
|
227
|
+
|
|
228
|
+
The agent then embeds the file in a note with `edit_note`, e.g. `![[Attachments/shot.png]]`.
|
|
229
|
+
|
|
230
|
+
Upload URLs are served by this server at `BASE_URL/attachments/upload/<token>`, so `BASE_URL` must be reachable by the agent. The token in the URL is the only credential for that request: 32 random bytes, valid for one upload, one path, and `ATTACHMENT_UPLOAD_TTL_SECONDS`. Path checks, `WRITE_FOLDERS` and the size limit are applied when the URL is created, and existing files are never replaced unless the agent passed `overwrite=true`. That last rule is checked again when the file is written, in the same step as the write, so of two concurrent uploads to one new path only the first succeeds and the other gets `409`.
|
|
231
|
+
|
|
232
|
+
**Behind a reverse proxy that allowlists paths:** match the exact upload URL, `PUT` with path `^/attachments/upload/[A-Za-z0-9_-]{43}$`, not the `/attachments/upload/` prefix. The server resolves `..` and `%2e%2e` in the path after the proxy has matched it, so with a prefix rule `/attachments/upload/../../mcp` reaches `/mcp`.
|
|
233
|
+
|
|
234
|
+
Allowed extensions: `avif`, `bmp`, `gif`, `jpeg`, `jpg`, `png`, `webp`, `flac`, `m4a`, `mp3`, `ogg`, `wav`, `3gp`, `mkv`, `mov`, `mp4`, `ogv`, `webm`, `pdf`. Text formats (`.md`, `.svg`, `.html`, `.js`, `.json`, `.canvas`, ...) and dot-folders such as `.obsidian/` are always refused. Attachments never appear in `list_notes` or `search_notes`. For `list_attachments` the server keeps their path, size and modification time in its metadata index, learned from the CouchDB change feed (from the metadata alone, so file contents are never downloaded) or, in filesystem mode, from a scan at startup and the file watcher. References are matched by file name, the way Obsidian resolves `![[shot.png]]`, from `[[wikilinks]]`, `![[embeds]]` and markdown links such as ``. Two files with the same name in different folders therefore count as referenced if either one is, which errs on the safe side when cleaning up.
|
|
235
|
+
|
|
214
236
|
Every tool response includes an [Obsidian deep link](https://help.obsidian.md/Extending+Obsidian/Obsidian+URI) (`obsidian://open?vault=...&file=...`) that works on Mac and iOS.
|
|
215
237
|
|
|
216
238
|
> "Add a bullet point to my daily note." "Find my notes about the MCP server and fix the typo in the second one."
|
|
@@ -264,6 +286,11 @@ Without `MCP_AUTH_TOKEN`, the server runs without authentication — suitable fo
|
|
|
264
286
|
| `MCP_REFRESH_DAYS` | Optional | `14` | Days before auth session expires |
|
|
265
287
|
| `READ_ONLY` | Optional | `false` | Set to `true` to disable all write tools (`write_note`, `edit_note`, `delete_note`, `move_note`). Only read tools are exposed via MCP, and the vault backend rejects writes as well. Useful when sharing the server with multiple AI clients and write access should be opt-in. This protects the vault from MCP clients; it is not a database-level guarantee. To make CouchDB itself refuse writes, use CouchDB-side controls, such as a `validate_doc_update` function that rejects the server's CouchDB user. |
|
|
266
288
|
| `WRITE_FOLDERS` | Optional | — | Comma-separated list of vault-relative folders where writes are allowed (e.g. `MCP,Inbox`). When set, the whole vault stays readable but `write_note`, `edit_note`, `delete_note`, and `move_note` refuse paths outside these folders (`move_note` requires both source and destination to be writable). Enforced server-side, unlike `MCP_INSTRUCTIONS`. Matching is case-sensitive and folder-boundary-aware (`MCP` matches `MCP/note.md` but not `MCP-private/note.md`). Ignored when `READ_ONLY=true`; unset means the whole vault is writable. |
|
|
289
|
+
| `ATTACHMENTS_ENABLED` | Optional | `false` | Set to `true` to enable the [attachment tools](#attachments-opt-in) and the upload endpoint. Under `READ_ONLY=true` only `get_attachment_metadata` and `list_attachments` are exposed and the endpoint is not mounted. With CouchDB, startup then always reads the change feed from the beginning to learn existing attachments (it already does so whenever notes are indexed, to rebuild the search text) |
|
|
290
|
+
| `ATTACHMENT_MAX_BYTES` | Optional | `20971520` (20 MB) | Largest file accepted by an upload URL. The whole file is held in memory while it is written |
|
|
291
|
+
| `ATTACHMENT_INLINE_MAX_BYTES` | Optional | `32768` (32 KB) | Largest decoded file accepted by `write_attachment`. Base64 costs about one output token per 2.5 bytes, so raising this mainly makes slow, error-prone calls possible |
|
|
292
|
+
| `ATTACHMENT_UPLOAD_TTL_SECONDS` | Optional | `600` | How long an upload URL stays valid |
|
|
293
|
+
| `ATTACHMENT_EXTENSIONS` | Optional | all supported | Comma-separated subset of the supported extensions to allow, e.g. `png,jpg,pdf`. Can only narrow the list; an unsupported extension is a startup error |
|
|
267
294
|
| `MCP_INSTRUCTIONS` | Optional | — | Extra text appended to the server's MCP `instructions` (the string clients inject into the system prompt). Use this to bake vault-specific conventions into the server — e.g. folder structure, naming rules, folders to avoid — so they apply across every MCP client without per-client config. Best-effort: not all clients respect `instructions`. |
|
|
268
295
|
| `MCP_INSTRUCTIONS_FILE` | Optional | — | Path to a file (e.g. markdown) whose contents are appended to the MCP `instructions`. Easier than `MCP_INSTRUCTIONS` for multi-line conventions. If both are set, the file wins and `MCP_INSTRUCTIONS` is ignored (with a startup warning). Missing/unreadable file or files larger than 32 KB are fatal startup errors. **Store this file somewhere only the service user can write (e.g. `chmod 600`)** — its contents land in every MCP session's system prompt, so write access to it = prompt-injection access to every client. |
|
|
269
296
|
|
|
@@ -290,7 +317,7 @@ Set transport to **Streamable HTTP**, enter `http://localhost:8787/mcp`, and con
|
|
|
290
317
|
|---|---|
|
|
291
318
|
| `npx obsidian-sync-mcp` | Automatic — npx pulls latest |
|
|
292
319
|
| Fly.io | From the same directory where you ran setup: `fly deploy`. If you lost the fly.toml, run `fly config save --app your-app-name` to restore it. |
|
|
293
|
-
| Docker | `docker pull ghcr.io/es617/obsidian-sync-mcp:latest` and restart |
|
|
320
|
+
| Docker | `docker pull ghcr.io/es617/obsidian-sync-mcp:latest` and restart. The image runs as the unprivileged `node` user (uid 1000). If your data volume was created by an older image that ran as root, make it writable once: `docker run --rm -v mcp-data:/data alpine chown -R 1000:1000 /data` (for a bind mount, `chown -R 1000:1000` the host directory) |
|
|
294
321
|
|
|
295
322
|
---
|
|
296
323
|
|
|
@@ -299,7 +326,7 @@ Set transport to **Streamable HTTP**, enter `http://localhost:8787/mcp`, and con
|
|
|
299
326
|
- **Single vault per instance.** Each server connects to one vault. For multiple vaults, run multiple instances on different ports.
|
|
300
327
|
- **Single machine on Fly.io.** Auth state is in-memory, so multiple machines break the OAuth flow. The setup script enforces this automatically.
|
|
301
328
|
- **No conflict resolution.** If an agent and Obsidian edit the same note simultaneously, last write wins.
|
|
302
|
-
- **
|
|
329
|
+
- **Attachments are write-and-describe only.** With `ATTACHMENTS_ENABLED=true` agents can store, move and delete media files, but the server does not return attachment contents to the model.
|
|
303
330
|
- **Deep links depend on the client.** Obsidian `obsidian://` deep links are included in every tool response. They work on Claude Mobile and in browsers, but some clients (Claude Desktop) may not render them as clickable links.
|
|
304
331
|
- **Node 22+ required.**
|
|
305
332
|
- **Setup script requires bash.** The `deploy/setup.sh` script works on macOS and Linux. On Windows, use WSL or Git Bash.
|
|
@@ -15,7 +15,108 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
};
|
|
16
16
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
17
|
|
|
18
|
+
// src/note-path.ts
|
|
19
|
+
var RESERVED_ROOT_FILES = /* @__PURE__ */ new Set([
|
|
20
|
+
"redflag.md",
|
|
21
|
+
"redflag2.md",
|
|
22
|
+
"redflag3.md",
|
|
23
|
+
"flag_rebuild.md",
|
|
24
|
+
"flag_fetch.md"
|
|
25
|
+
]);
|
|
26
|
+
function validateVaultPathShape(path, kind) {
|
|
27
|
+
const problem = vaultPathShapeProblem(path);
|
|
28
|
+
if (problem !== null) throw new Error(`Invalid ${kind} path${problem}`);
|
|
29
|
+
}
|
|
30
|
+
function vaultPathShapeProblem(path) {
|
|
31
|
+
if (!path || path.length > 1e3) return "";
|
|
32
|
+
if (path.startsWith("/") || path.includes("\0") || path.includes("..")) return "";
|
|
33
|
+
if (path.includes(":")) return ": ':' is not allowed";
|
|
34
|
+
for (const segment of path.split(/[/\\]/)) {
|
|
35
|
+
if (segment === "") return ": empty path segment";
|
|
36
|
+
if (segment.startsWith(".")) return ": dot-folders and hidden files (e.g. .obsidian) are not allowed";
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
function validateNotePath(path) {
|
|
41
|
+
validateVaultPathShape(path, "note");
|
|
42
|
+
if (!path.endsWith(".md")) {
|
|
43
|
+
throw new Error("Invalid note path: must be a vault-relative path ending in .md");
|
|
44
|
+
}
|
|
45
|
+
if (!path.includes("/") && !path.includes("\\") && RESERVED_ROOT_FILES.has(path.toLowerCase())) {
|
|
46
|
+
throw new Error("Invalid note path: reserved LiveSync control file");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function isValidNotePath(path) {
|
|
50
|
+
try {
|
|
51
|
+
validateNotePath(path);
|
|
52
|
+
return true;
|
|
53
|
+
} catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/attachment-path.ts
|
|
59
|
+
var SUPPORTED_ATTACHMENT_EXTENSIONS = [
|
|
60
|
+
// images
|
|
61
|
+
"avif",
|
|
62
|
+
"bmp",
|
|
63
|
+
"gif",
|
|
64
|
+
"jpeg",
|
|
65
|
+
"jpg",
|
|
66
|
+
"png",
|
|
67
|
+
"webp",
|
|
68
|
+
// audio
|
|
69
|
+
"flac",
|
|
70
|
+
"m4a",
|
|
71
|
+
"mp3",
|
|
72
|
+
"ogg",
|
|
73
|
+
"wav",
|
|
74
|
+
"3gp",
|
|
75
|
+
// video
|
|
76
|
+
"mkv",
|
|
77
|
+
"mov",
|
|
78
|
+
"mp4",
|
|
79
|
+
"ogv",
|
|
80
|
+
"webm",
|
|
81
|
+
// documents
|
|
82
|
+
"pdf"
|
|
83
|
+
];
|
|
84
|
+
function parseAttachmentExtensions(raw) {
|
|
85
|
+
if (raw === void 0 || raw.trim() === "") return new Set(SUPPORTED_ATTACHMENT_EXTENSIONS);
|
|
86
|
+
const requested = raw.split(",").map((e) => e.trim().toLowerCase().replace(/^\./, "")).filter(Boolean);
|
|
87
|
+
const unsupported = requested.filter((e) => !SUPPORTED_ATTACHMENT_EXTENSIONS.includes(e));
|
|
88
|
+
if (unsupported.length > 0) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`ATTACHMENT_EXTENSIONS contains unsupported extensions: ${unsupported.join(", ")}. Supported: ${SUPPORTED_ATTACHMENT_EXTENSIONS.join(", ")}.`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return new Set(requested);
|
|
94
|
+
}
|
|
95
|
+
function attachmentExtension(path) {
|
|
96
|
+
const name = path.split(/[/\\]/).pop() ?? "";
|
|
97
|
+
const dot = name.lastIndexOf(".");
|
|
98
|
+
return dot <= 0 ? "" : name.slice(dot + 1).toLowerCase();
|
|
99
|
+
}
|
|
100
|
+
var SUPPORTED = new Set(SUPPORTED_ATTACHMENT_EXTENSIONS);
|
|
101
|
+
function validateAttachmentPath(path, allowed = SUPPORTED) {
|
|
102
|
+
validateVaultPathShape(path, "attachment");
|
|
103
|
+
const ext = attachmentExtension(path);
|
|
104
|
+
if (!ext || !allowed.has(ext)) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Invalid attachment path: extension must be one of ${[...allowed].sort().join(", ")}`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function isValidAttachmentPath(path, allowed = SUPPORTED) {
|
|
111
|
+
const ext = attachmentExtension(path);
|
|
112
|
+
return !!ext && allowed.has(ext) && vaultPathShapeProblem(path) === null;
|
|
113
|
+
}
|
|
114
|
+
|
|
18
115
|
// src/parse.ts
|
|
116
|
+
var WIKILINK = /\[\[([^[\]|#\n]+)(?:#[^[\]|\n]*)?(?:\|[^[\]\n]*)?\]\]/g;
|
|
117
|
+
var LINK_LABEL = String.raw`[^[\]\n]|\[[^[\]\n]*\]`;
|
|
118
|
+
var NOTE_LINK = new RegExp(String.raw`\[(?:${LINK_LABEL})+\]\(([^()#\n]+\.md)(?:#[^()\n]*)?\)`, "g");
|
|
119
|
+
var ATTACHMENT_LINK = new RegExp(String.raw`\[((?:${LINK_LABEL})*)\]\((<[^<>\n]+>|[^()\s]+)(?:\s+"[^"\n]*")?\)`, "g");
|
|
19
120
|
function parseFrontmatterAndLinks(content) {
|
|
20
121
|
const frontmatter = {};
|
|
21
122
|
const tags = /* @__PURE__ */ new Set();
|
|
@@ -58,14 +159,25 @@ function parseFrontmatterAndLinks(content) {
|
|
|
58
159
|
if (new RegExp("^\\p{Nd}+$", "u").test(match[2])) continue;
|
|
59
160
|
tags.add(match[2]);
|
|
60
161
|
}
|
|
61
|
-
for (const match of content.matchAll(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
for (const match of content.matchAll(/\[([^\]]+)\]\(([^)]+\.md)\)/g)) {
|
|
65
|
-
links.push(match[2]);
|
|
66
|
-
}
|
|
162
|
+
for (const match of content.matchAll(WIKILINK)) links.push(match[1]);
|
|
163
|
+
for (const match of content.matchAll(NOTE_LINK)) links.push(match[1]);
|
|
164
|
+
addAttachmentLinks(content, links);
|
|
67
165
|
return { frontmatter, tags: [...tags], links: [...new Set(links)] };
|
|
68
166
|
}
|
|
167
|
+
function addAttachmentLinks(text, links, nested = false) {
|
|
168
|
+
for (const match of text.matchAll(ATTACHMENT_LINK)) {
|
|
169
|
+
if (!nested && match[1].includes("[")) addAttachmentLinks(match[1], links, true);
|
|
170
|
+
let target = match[2].replace(/^<|>$/g, "").replace(/#.*$/, "");
|
|
171
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(target) || target.endsWith(".md")) continue;
|
|
172
|
+
try {
|
|
173
|
+
target = decodeURIComponent(target);
|
|
174
|
+
} catch {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
target = target.replace(/^(\.\.?\/)+/, "");
|
|
178
|
+
if (isValidAttachmentPath(target)) links.push(target);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
69
181
|
function maskCode(content) {
|
|
70
182
|
const lines = content.split("\n");
|
|
71
183
|
const out = [];
|
|
@@ -135,52 +247,43 @@ function maskInlineSpans(text) {
|
|
|
135
247
|
return result + text.slice(from);
|
|
136
248
|
}
|
|
137
249
|
|
|
138
|
-
// src/
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
function validateNotePath(path) {
|
|
147
|
-
if (!path || path.length > 1e3) {
|
|
148
|
-
throw new Error("Invalid note path");
|
|
149
|
-
}
|
|
150
|
-
if (path.startsWith("/") || path.includes("\0") || path.includes("..")) {
|
|
151
|
-
throw new Error("Invalid note path");
|
|
152
|
-
}
|
|
153
|
-
if (path.includes(":")) {
|
|
154
|
-
throw new Error("Invalid note path: ':' is not allowed");
|
|
250
|
+
// src/vault-backend.ts
|
|
251
|
+
var AttachmentTooLargeError = class extends Error {
|
|
252
|
+
constructor(path, size, limit) {
|
|
253
|
+
super(`Attachment is ${size} bytes, over the ${limit}-byte limit for moving it: ${path}`);
|
|
254
|
+
this.path = path;
|
|
255
|
+
this.size = size;
|
|
256
|
+
this.limit = limit;
|
|
257
|
+
this.name = "AttachmentTooLargeError";
|
|
155
258
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (segment.startsWith(".")) {
|
|
164
|
-
throw new Error("Invalid note path: dot-folders and hidden files (e.g. .obsidian) are not allowed");
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (!path.includes("/") && !path.includes("\\") && RESERVED_ROOT_FILES.has(path.toLowerCase())) {
|
|
168
|
-
throw new Error("Invalid note path: reserved LiveSync control file");
|
|
259
|
+
};
|
|
260
|
+
var AttachmentMoveIncompleteError = class extends Error {
|
|
261
|
+
constructor(from, to) {
|
|
262
|
+
super(`Copied ${from} to ${to}, but could not delete ${from}`);
|
|
263
|
+
this.from = from;
|
|
264
|
+
this.to = to;
|
|
265
|
+
this.name = "AttachmentMoveIncompleteError";
|
|
169
266
|
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return false;
|
|
267
|
+
};
|
|
268
|
+
var AttachmentExistsError = class extends Error {
|
|
269
|
+
constructor(path) {
|
|
270
|
+
super(`Attachment already exists: ${path}`);
|
|
271
|
+
this.path = path;
|
|
272
|
+
this.name = "AttachmentExistsError";
|
|
177
273
|
}
|
|
178
|
-
}
|
|
274
|
+
};
|
|
179
275
|
|
|
180
276
|
export {
|
|
181
277
|
__reExport,
|
|
182
|
-
parseFrontmatterAndLinks,
|
|
183
278
|
validateNotePath,
|
|
184
|
-
isValidNotePath
|
|
279
|
+
isValidNotePath,
|
|
280
|
+
parseAttachmentExtensions,
|
|
281
|
+
attachmentExtension,
|
|
282
|
+
validateAttachmentPath,
|
|
283
|
+
isValidAttachmentPath,
|
|
284
|
+
parseFrontmatterAndLinks,
|
|
285
|
+
AttachmentTooLargeError,
|
|
286
|
+
AttachmentMoveIncompleteError,
|
|
287
|
+
AttachmentExistsError
|
|
185
288
|
};
|
|
186
|
-
//# sourceMappingURL=chunk-
|
|
289
|
+
//# sourceMappingURL=chunk-XZ4HUASL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/note-path.ts","../src/attachment-path.ts","../src/parse.ts","../src/vault-backend.ts"],"sourcesContent":["/**\n * Shared validation for note paths, applied by both the CouchDB and local\n * backends before any read, write, delete or move.\n *\n * The note model is markdown-only: `list_notes` only ever surfaces `*.md`\n * files; binary attachments have their own validator (attachment-path.ts)\n * built on validateVaultPathShape below. Enforcing that here keeps\n * the tools from reaching anything that isn't a note, which closes two real\n * problems:\n * - CouchDB mode: a path like `obsydian_livesync_version` or a `ix:`/`ps:`\n * prefixed id would otherwise become a document id and overwrite LiveSync's\n * own control documents, stopping sync on every device.\n * - Local mode: a path like `.obsidian/plugins/x/main.js` would otherwise\n * write executable plugin code into the vault, and `.obsidian/.../data.json`\n * would expose LiveSync credentials.\n *\n * Rules: vault-relative, ends in `.md`, no `..`, no leading `/`, no `:` (its\n * only use here is LiveSync's internal id prefixes), no NUL, and no path\n * segment (split on either slash) that starts with `.` (hidden files and the\n * `.obsidian` config dir). Root-level LiveSync control flag files are also\n * rejected even though they are `.md`.\n */\n\n// LiveSync's note-shaped control files, all at the vault root. Writing one and\n// letting it sync triggers a vault-wide rebuild/fetch on every device, so they\n// are not writable through the note tools. Compared lowercase because LiveSync\n// lowercases ids when case-insensitive handling is on.\nconst RESERVED_ROOT_FILES = new Set([\n \"redflag.md\",\n \"redflag2.md\",\n \"redflag3.md\",\n \"flag_rebuild.md\",\n \"flag_fetch.md\",\n]);\n\n/**\n * The rules every vault path must pass, note or attachment: vault-relative,\n * no `..`, no leading `/`, no `:`, no NUL, no empty segment and no segment\n * starting with `.`. `kind` only names the path in error messages.\n */\nexport function validateVaultPathShape(path: string, kind: string): void {\n const problem = vaultPathShapeProblem(path);\n if (problem !== null) throw new Error(`Invalid ${kind} path${problem}`);\n}\n\n/**\n * Why `path` fails validateVaultPathShape, as the suffix of its error message\n * (\"\" when there is no detail), or null when it passes. Non-throwing so hot\n * paths like link parsing don't pay for an exception per rejected target.\n */\nexport function vaultPathShapeProblem(path: string): string | null {\n if (!path || path.length > 1000) return \"\";\n if (path.startsWith(\"/\") || path.includes(\"\\0\") || path.includes(\"..\")) return \"\";\n if (path.includes(\":\")) return \": ':' is not allowed\";\n for (const segment of path.split(/[/\\\\]/)) {\n if (segment === \"\") return \": empty path segment\";\n if (segment.startsWith(\".\")) return \": dot-folders and hidden files (e.g. .obsidian) are not allowed\";\n }\n return null;\n}\n\nexport function validateNotePath(path: string): void {\n validateVaultPathShape(path, \"note\");\n if (!path.endsWith(\".md\")) {\n throw new Error(\"Invalid note path: must be a vault-relative path ending in .md\");\n }\n // Root-level control flag files (no folder segment).\n if (!path.includes(\"/\") && !path.includes(\"\\\\\") && RESERVED_ROOT_FILES.has(path.toLowerCase())) {\n throw new Error(\"Invalid note path: reserved LiveSync control file\");\n }\n}\n\n/** Boolean form of validateNotePath, for filtering listings and the index. */\nexport function isValidNotePath(path: string): boolean {\n try {\n validateNotePath(path);\n return true;\n } catch {\n return false;\n }\n}\n","/**\n * Validation for attachment paths (images, PDFs, audio, video).\n *\n * Attachments get the same shape rules as notes (see note-path.ts) — no `..`,\n * no `:`, no dot-folders — so they cannot reach LiveSync control documents or\n * `.obsidian/`. On top of that the extension must be on an allowlist of binary\n * media types Obsidian can embed. Text-like formats (`.md`, `.svg`, `.html`,\n * `.js`, `.json`, `.css`, `.canvas`, ...) are never attachments: they are\n * either notes, executable in Obsidian, or stored by LiveSync as plain text.\n */\n\nimport { validateVaultPathShape, vaultPathShapeProblem } from \"./note-path.js\";\n\n/** Binary formats Obsidian embeds natively. SVG is left out on purpose: it is text and can carry script. */\nexport const SUPPORTED_ATTACHMENT_EXTENSIONS: readonly string[] = [\n // images\n \"avif\", \"bmp\", \"gif\", \"jpeg\", \"jpg\", \"png\", \"webp\",\n // audio\n \"flac\", \"m4a\", \"mp3\", \"ogg\", \"wav\", \"3gp\",\n // video\n \"mkv\", \"mov\", \"mp4\", \"ogv\", \"webm\",\n // documents\n \"pdf\",\n];\n\n/**\n * Parse ATTACHMENT_EXTENSIONS into an allowlist. Unset means every supported\n * extension. The variable can only narrow the list: an unsupported entry is an\n * error rather than a silent widening of what may be written.\n */\nexport function parseAttachmentExtensions(raw: string | undefined): Set<string> {\n if (raw === undefined || raw.trim() === \"\") return new Set(SUPPORTED_ATTACHMENT_EXTENSIONS);\n const requested = raw\n .split(\",\")\n .map((e) => e.trim().toLowerCase().replace(/^\\./, \"\"))\n .filter(Boolean);\n const unsupported = requested.filter((e) => !SUPPORTED_ATTACHMENT_EXTENSIONS.includes(e));\n if (unsupported.length > 0) {\n throw new Error(\n `ATTACHMENT_EXTENSIONS contains unsupported extensions: ${unsupported.join(\", \")}. ` +\n `Supported: ${SUPPORTED_ATTACHMENT_EXTENSIONS.join(\", \")}.`,\n );\n }\n return new Set(requested);\n}\n\n/** Lowercased extension without the dot, or \"\" when there is none. */\nexport function attachmentExtension(path: string): string {\n const name = path.split(/[/\\\\]/).pop() ?? \"\";\n const dot = name.lastIndexOf(\".\");\n return dot <= 0 ? \"\" : name.slice(dot + 1).toLowerCase();\n}\n\nconst SUPPORTED = new Set(SUPPORTED_ATTACHMENT_EXTENSIONS);\n\nexport function validateAttachmentPath(path: string, allowed: ReadonlySet<string> = SUPPORTED): void {\n validateVaultPathShape(path, \"attachment\");\n const ext = attachmentExtension(path);\n if (!ext || !allowed.has(ext)) {\n throw new Error(\n `Invalid attachment path: extension must be one of ${[...allowed].sort().join(\", \")}`,\n );\n }\n}\n\n/** Boolean form of validateAttachmentPath. Doesn't throw: link parsing calls it for every link target. */\nexport function isValidAttachmentPath(path: string, allowed: ReadonlySet<string> = SUPPORTED): boolean {\n const ext = attachmentExtension(path);\n return !!ext && allowed.has(ext) && vaultPathShapeProblem(path) === null;\n}\n","/**\n * Parse Obsidian markdown content for frontmatter, tags, and links.\n */\n\nimport { isValidAttachmentPath } from \"./attachment-path.js\";\n\nexport interface NoteMetadata {\n frontmatter: Record<string, string>;\n tags: string[];\n links: string[];\n}\n\n// Link patterns. Each part stops at a bracket, paren or newline, so a failed\n// match only scans up to the next one. Otherwise it rescans the rest of the\n// note, which is quadratic on input like \"[\".repeat(20000), and parsing is\n// synchronous and runs on every note at startup. No length cap is needed on\n// top: attachment targets are capped by isValidAttachmentPath after decoding.\n\n// [[wikilinks]]. A #heading, #^block or #page=2 suffix points into the target,\n// so [[Note#Heading]] links Note and ![[paper.pdf#page=2]] embeds paper.pdf.\n// [[#Heading]] (same note) is not a link.\nconst WIKILINK = /\\[\\[([^[\\]|#\\n]+)(?:#[^[\\]|\\n]*)?(?:\\|[^[\\]\\n]*)?\\]\\]/g;\n\n// Markdown link text: plain characters, or one level of [brackets], so\n// [see [1]](note.md) and [](full.png) parse. The two\n// alternatives never match the same character, so this adds no backtracking.\nconst LINK_LABEL = String.raw`[^[\\]\\n]|\\[[^[\\]\\n]*\\]`;\n\n// [markdown links](path.md), also with a #heading: [x](path.md#Heading) links path.md.\nconst NOTE_LINK = new RegExp(String.raw`\\[(?:${LINK_LABEL})+\\]\\(([^()#\\n]+\\.md)(?:#[^()\\n]*)?\\)`, \"g\");\n\n// Markdown links and embeds to attachments: ,\n// [report](<docs/Q1 report.pdf>), .\nconst ATTACHMENT_LINK = new RegExp(String.raw`\\[((?:${LINK_LABEL})*)\\]\\((<[^<>\\n]+>|[^()\\s]+)(?:\\s+\"[^\"\\n]*\")?\\)`, \"g\");\n\nexport function parseFrontmatterAndLinks(content: string): NoteMetadata {\n const frontmatter: Record<string, any> = {};\n const tags = new Set<string>();\n const links: string[] = [];\n\n // Parse YAML frontmatter\n if (content.startsWith(\"---\\n\")) {\n const end = content.indexOf(\"\\n---\", 4);\n if (end !== -1) {\n const yaml = content.slice(4, end);\n let inTagsList = false;\n for (const line of yaml.split(\"\\n\")) {\n // Multi-line tags list item: \" - tagname\"\n if (inTagsList) {\n const listItem = line.match(/^\\s+-\\s+(.+)/);\n if (listItem) {\n const trimmed = listItem[1].trim();\n if (trimmed) tags.add(trimmed);\n continue;\n }\n inTagsList = false;\n }\n\n const match = line.match(/^([\\p{L}\\p{N}_][\\p{L}\\p{M}\\p{N}_-]*)\\s*:\\s*(.+)/u);\n if (match) {\n frontmatter[match[1]] = match[2].trim();\n }\n // Frontmatter tags (inline: [a, b] or start of multi-line list)\n if (/^tags\\s*:/.test(line)) {\n const value = line.replace(/^tags\\s*:\\s*/, \"\").trim();\n if (value) {\n // Inline: tags: [a, b] or tags: a, b\n const tagValues = value.replace(/[[\\]]/g, \"\");\n for (const t of tagValues.split(\",\")) {\n const trimmed = t.trim();\n if (trimmed) tags.add(trimmed);\n }\n } else {\n // Multi-line list follows\n inTagsList = true;\n }\n }\n }\n }\n }\n\n // Inline #tags. Obsidian does not read tags out of code, and a tag must\n // contain at least one non-numerical character (\"#1984 isn't a valid tag,\n // but #y1984 is\" — obsidian.md/help/tags), so code spans and fenced blocks\n // are masked out first and all-digit matches are dropped.\n for (const match of maskCode(content).matchAll(/(^|\\s)#([\\p{L}\\p{N}_/-][\\p{L}\\p{M}\\p{N}_/-]*)/gu)) {\n if (/^\\p{Nd}+$/u.test(match[2])) continue;\n tags.add(match[2]);\n }\n\n for (const match of content.matchAll(WIKILINK)) links.push(match[1]);\n for (const match of content.matchAll(NOTE_LINK)) links.push(match[1]);\n addAttachmentLinks(content, links);\n\n return { frontmatter, tags: [...tags], links: [...new Set(links)] };\n}\n\n/**\n * Add the attachment targets of markdown links in `text` to `links`, recorded\n * URL-decoded so list_attachments can tell which files are still used. Also\n * looks inside each link's text once, since matches don't overlap and the\n * outer link of [](full.png) would hide the inner image.\n */\nfunction addAttachmentLinks(text: string, links: string[], nested = false): void {\n for (const match of text.matchAll(ATTACHMENT_LINK)) {\n if (!nested && match[1].includes(\"[\")) addAttachmentLinks(match[1], links, true);\n // Drop a #page=2 fragment, as for wikilinks. Before decoding, since a\n // literal # in a file name is written %23.\n let target = match[2].replace(/^<|>$/g, \"\").replace(/#.*$/, \"\");\n if (/^[a-z][a-z0-9+.-]*:/i.test(target) || target.endsWith(\".md\")) continue;\n // Obsidian URL-decodes markdown link targets (a literal % is written %25).\n try { target = decodeURIComponent(target); } catch { continue; }\n target = target.replace(/^(\\.\\.?\\/)+/, \"\");\n if (isValidAttachmentPath(target)) links.push(target);\n }\n}\n\n/**\n * Replace fenced code blocks (``` or ~~~, opener at line start with up to three\n * spaces of indent, closer of the same character and at least the same length;\n * an unclosed fence runs to the end) and inline code spans (a backtick run of\n * length n closes at the next run of exactly n within the same paragraph — a\n * span never crosses a blank line; an unmatched run is literal)\n * with dots, so offsets are preserved and nothing inside can start or extend a\n * tag. Indented code blocks, %% comments and math are not masked.\n */\nexport function maskCode(content: string): string {\n const lines = content.split(\"\\n\");\n const out: string[] = [];\n let fence: { char: string; len: number } | null = null;\n const inline: string[] = [];\n const flushInline = () => {\n if (inline.length === 0) return;\n out.push(...maskInlineSpans(inline.join(\"\\n\")).split(\"\\n\"));\n inline.length = 0;\n };\n for (const line of lines) {\n const open = line.match(/^ {0,3}(`{3,}|~{3,})/);\n if (fence) {\n const close = open && open[1][0] === fence.char && open[1].length >= fence.len && line.trim() === open[1];\n out.push(\".\".repeat(line.length));\n if (close) fence = null;\n continue;\n }\n if (open && (open[1][0] === \"~\" || !line.slice(open[0].length).includes(\"`\"))) {\n flushInline();\n fence = { char: open[1][0], len: open[1].length };\n out.push(\".\".repeat(line.length));\n continue;\n }\n if (line.trim() === \"\") {\n flushInline();\n out.push(line);\n continue;\n }\n inline.push(line);\n }\n flushInline();\n return out.join(\"\\n\");\n}\n\nfunction maskInlineSpans(text: string): string {\n // Collect backtick runs in one pass, then link each run to the next run of\n // the same length (scanning right to left) so matching stays linear.\n const runs: { at: number; len: number }[] = [];\n for (let i = 0; i < text.length; ) {\n if (text[i] !== \"`\") { i++; continue; }\n let n = 0;\n while (text[i + n] === \"`\") n++;\n runs.push({ at: i, len: n });\n i += n;\n }\n const next: number[] = [];\n const seen = new Map<number, number>();\n for (let r = runs.length - 1; r >= 0; r--) {\n next[r] = seen.get(runs[r].len) ?? -1;\n seen.set(runs[r].len, r);\n }\n let result = \"\";\n let from = 0;\n for (let r = 0; r < runs.length; ) {\n const c = next[r];\n if (c === -1) { r++; continue; }\n const start = runs[r].at;\n const end = runs[c].at + runs[c].len;\n result += text.slice(from, start) + text.slice(start, end).replace(/[^\\n]/g, \".\");\n from = end;\n r = c + 1;\n }\n return result + text.slice(from);\n}\n\nexport function extractSnippet(content: string, query: string, context = 80): string {\n const lower = content.toLowerCase();\n\n // Try exact phrase first\n let idx = lower.indexOf(query.toLowerCase());\n\n // Try to find the smallest span containing all query words\n if (idx === -1) {\n const words = query.split(/\\s+/).filter((w) => w.length >= 3).map((w) => w.toLowerCase());\n if (words.length > 1) {\n let bestStart = -1;\n let bestLen = Infinity;\n // For each occurrence of the first word, find the nearest span containing all words\n const first = words[0];\n let pos = 0;\n while (pos < lower.length) {\n const start = lower.indexOf(first, pos);\n if (start === -1) break;\n // Find last position needed to include all words from this start\n let spanEnd = start + first.length;\n let allFound = true;\n for (let i = 1; i < words.length; i++) {\n const wi = lower.indexOf(words[i], Math.max(0, start - 200));\n if (wi === -1) { allFound = false; break; }\n spanEnd = Math.max(spanEnd, wi + words[i].length);\n }\n if (allFound) {\n const spanStart = Math.min(start, ...words.map((w) => lower.indexOf(w, Math.max(0, start - 200))).filter((i) => i >= 0));\n const len = spanEnd - spanStart;\n if (len < bestLen) { bestStart = spanStart; bestLen = len; }\n }\n pos = start + 1;\n }\n if (bestStart >= 0 && bestLen <= 500) idx = bestStart;\n }\n }\n\n // Fall back to longest matching word\n if (idx === -1) {\n const words = query.split(/\\s+/).filter((w) => w.length >= 3).sort((a, b) => b.length - a.length);\n for (const word of words) {\n idx = lower.indexOf(word.toLowerCase());\n if (idx !== -1) break;\n }\n }\n\n if (idx === -1) {\n return content.slice(0, 160) + (content.length > 160 ? \"...\" : \"\");\n }\n const start = Math.max(0, idx - context);\n const end = Math.min(content.length, idx + query.length + context);\n return (start > 0 ? \"...\" : \"\") + content.slice(start, end) + (end < content.length ? \"...\" : \"\");\n}\n","import type { NoteMetadata } from \"./parse.js\";\n\nexport interface NoteInfo extends NoteMetadata {\n path: string;\n size: number;\n ctime: number;\n mtime: number;\n}\n\nexport interface NoteListing {\n path: string;\n mtime: number;\n}\n\nexport interface AttachmentInfo {\n path: string;\n size: number;\n ctime: number;\n mtime: number;\n}\n\n/** An attachment appeared or changed (info), or was deleted (null). */\nexport type AttachmentChangeCallback = (path: string, info: { size: number; mtime: number } | null) => void;\n\nexport interface WriteOptions {\n /** Replace an existing file. Default false. */\n overwrite?: boolean;\n}\n\nexport interface MoveOptions extends WriteOptions {\n /**\n * Largest file a backend may load into memory to move it. CouchDB mode\n * copies the bytes (read, write, delete); local mode renames and ignores it.\n */\n maxBytes?: number;\n}\n\n/** A move would have to load a file larger than `MoveOptions.maxBytes`. */\nexport class AttachmentTooLargeError extends Error {\n constructor(readonly path: string, readonly size: number, readonly limit: number) {\n super(`Attachment is ${size} bytes, over the ${limit}-byte limit for moving it: ${path}`);\n this.name = \"AttachmentTooLargeError\";\n }\n}\n\n/** A copying move wrote the destination but could not delete the source, so both exist. */\nexport class AttachmentMoveIncompleteError extends Error {\n constructor(readonly from: string, readonly to: string) {\n super(`Copied ${from} to ${to}, but could not delete ${from}`);\n this.name = \"AttachmentMoveIncompleteError\";\n }\n}\n\n/** A write or move without `overwrite` found a file already at the destination. */\nexport class AttachmentExistsError extends Error {\n constructor(readonly path: string) {\n super(`Attachment already exists: ${path}`);\n this.name = \"AttachmentExistsError\";\n }\n}\n\nexport interface VaultBackend {\n init(): Promise<void>;\n close(): Promise<void>;\n readNote(path: string): Promise<string | null>;\n writeNote(path: string, content: string): Promise<boolean>;\n deleteNote(path: string): Promise<boolean>;\n moveNote(from: string, to: string): Promise<boolean>;\n getMetadata(path: string): Promise<NoteInfo | null>;\n listNotes(folder?: string): Promise<string[]>;\n listNotesWithMtime(folder?: string): Promise<NoteListing[]>;\n /**\n * Binary attachments (see attachment-path.ts). Paths are validated by the backend too.\n * Without `overwrite`, writing or moving onto an existing file throws\n * AttachmentExistsError, checked in the same step as the write.\n */\n writeAttachment(path: string, data: Uint8Array, options?: WriteOptions): Promise<boolean>;\n deleteAttachment(path: string): Promise<boolean>;\n moveAttachment(from: string, to: string, options?: MoveOptions): Promise<boolean>;\n getAttachmentInfo(path: string): Promise<AttachmentInfo | null>;\n /** Every attachment in the vault. Local mode only; CouchDB mode learns them from the change feed. */\n listAttachments?(): Promise<AttachmentInfo[]>;\n /** `onAttachment` also reports attachment changes, from metadata only (no chunks are loaded). */\n watchChanges?(callback: (path: string, content: string | null, mtime?: number, seq?: string | number) => void, onAttachment?: AttachmentChangeCallback): void;\n /**\n * Catch up on changes since a sequence. Returns the new sequence. CouchDB only.\n * `stats.unreadable` counts documents that could not be decrypted or loaded\n * and were therefore skipped — the caller reports them so \"caught up\" never\n * hides a silent miss.\n */\n catchUp?(since: string, callback: (path: string, content: string | null, mtime?: number) => void, onBatch?: (since: string, processed: number) => Promise<void>, stats?: { unre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