@abhishekmcp/notes 0.2.0 → 0.4.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 +85 -40
- package/dist/config.d.ts +30 -0
- package/dist/config.js +51 -0
- package/dist/config.js.map +1 -1
- package/dist/embed.d.ts +9 -0
- package/dist/embed.js +134 -0
- package/dist/embed.js.map +1 -0
- package/dist/extras.d.ts +31 -0
- package/dist/extras.js +146 -0
- package/dist/extras.js.map +1 -0
- package/dist/index.js +122 -3
- package/dist/index.js.map +1 -1
- package/dist/prompts.d.ts +16 -0
- package/dist/prompts.js +56 -0
- package/dist/prompts.js.map +1 -0
- package/dist/semantic.d.ts +14 -0
- package/dist/semantic.js +142 -0
- package/dist/semantic.js.map +1 -0
- package/dist/store.d.ts +5 -0
- package/dist/store.js +11 -0
- package/dist/store.js.map +1 -1
- package/dist/tokenizer.d.ts +30 -0
- package/dist/tokenizer.js +140 -0
- package/dist/tokenizer.js.map +1 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,40 +1,96 @@
|
|
|
1
1
|
# @abhishekmcp/notes
|
|
2
2
|
|
|
3
|
-
An [MCP](https://modelcontextprotocol.io) server for managing local markdown notes. Lets any MCP client (Claude Desktop, Claude Code, Cursor, …) search,
|
|
3
|
+
An [MCP](https://modelcontextprotocol.io) server for managing local markdown notes. Lets any MCP client (Claude Desktop, Claude Code, Cursor, …) search, link, and organize the notes in a folder on your machine — with ranked full-text search, tags, todos, and a wiki-link knowledge graph.
|
|
4
|
+
|
|
5
|
+
Pure JavaScript, no native dependencies, no API keys — everything runs locally.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
- `list_notes` — list
|
|
9
|
-
- `read_note` — read a note's
|
|
10
|
-
- `
|
|
11
|
-
- `
|
|
9
|
+
### Notes (token-efficient I/O)
|
|
10
|
+
- `list_notes` — list notes (newest first) with pagination (`offset`/`limit`) and an optional `tag` filter
|
|
11
|
+
- `read_note` — read a note; optionally just one heading's `section`, or a character window (`offset`/`limit`) with a truncation flag
|
|
12
|
+
- `get_outline` — return only a note's heading tree (grasp a big note in a few tokens)
|
|
13
|
+
- `create_note` — create a new note (optional `overwrite`)
|
|
14
|
+
- `append_note` — append to a note, creating it if missing (great for journals/logs)
|
|
12
15
|
- `delete_note` — delete a note
|
|
13
|
-
- `
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
- `move_note` — rename/move a note **and rewrite every `[[wiki-link]]`** across the vault that points at it
|
|
17
|
+
|
|
18
|
+
### Search & discovery
|
|
19
|
+
- `search_notes` — ranked full-text search ([MiniSearch](https://github.com/lucaong/minisearch)); supports `fuzzy` and `prefix` matching, a `field` filter (`title`/`tag`/`body`/`path`), and returns ranked snippets with surrounding context
|
|
20
|
+
- `semantic_search` — **meaning-based** search using local embeddings; finds related notes even with no shared keywords (e.g. "puppy" matches a note about "canine companions"). Optional `hybrid` mode fuses semantic + keyword ranking
|
|
21
|
+
- `list_tags` — every tag across the vault with note counts
|
|
22
|
+
- `list_todos` — aggregate `- [ ]` / `- [x]` checkboxes across all notes
|
|
23
|
+
|
|
24
|
+
### Knowledge graph
|
|
25
|
+
- `get_backlinks` — notes linking to a note via `[[wiki-link]]` syntax
|
|
26
|
+
- `get_neighbors` — notes within N hops over the (undirected) link graph (depth/limit capped)
|
|
27
|
+
- `find_path` — shortest wiki-link chain between two notes
|
|
28
|
+
- `related_notes` — notes ranked by shared links + shared tags
|
|
29
|
+
- `graph_overview` — aggregate health: note/link/tag counts, top hubs, orphans, broken-link count
|
|
30
|
+
- `broken_links` — wiki-links that point at notes which don't exist
|
|
31
|
+
|
|
32
|
+
### Organization & daily workflow
|
|
33
|
+
- `daily_note` — open today's daily note (creating it if needed) and append a timestamped entry
|
|
34
|
+
- `list_templates` / `create_from_template` — instantiate a note from a template, substituting `{{date}}`/`{{time}}`/`{{title}}` plus your own vars
|
|
35
|
+
- `rename_tag` — rename a tag across the whole vault (frontmatter + inline `#hashtags`)
|
|
36
|
+
- `unlinked_mentions` — find notes that mention a note's title as plain text but don't yet `[[link]]` to it
|
|
37
|
+
|
|
38
|
+
### Prompts (slash-command workflows)
|
|
39
|
+
Exposed via the MCP Prompts primitive — your client surfaces these as slash commands:
|
|
40
|
+
- `weekly_review` — summarize the last 7 days of notes + open todos
|
|
41
|
+
- `summarize_note` — summarize one note (with note-name autocomplete)
|
|
42
|
+
- `daily_standup` — draft a standup from yesterday/today's daily notes + open todos
|
|
43
|
+
|
|
44
|
+
### Resources
|
|
17
45
|
- Every note is exposed as a `notes://<name>` resource.
|
|
18
46
|
|
|
19
|
-
|
|
47
|
+
### Frontmatter & tags
|
|
48
|
+
Notes may start with a YAML frontmatter block; `title` and `tags` (a list or comma-separated string) are recognized. Inline `#hashtags` in the body are also collected as tags.
|
|
20
49
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
50
|
+
```markdown
|
|
51
|
+
---
|
|
52
|
+
title: My Note
|
|
53
|
+
tags: [project, ideas]
|
|
54
|
+
---
|
|
55
|
+
# My Note
|
|
56
|
+
Links to [[another-note]]. Some inline #tag too.
|
|
26
57
|
```
|
|
27
58
|
|
|
28
59
|
## Configuration
|
|
29
60
|
|
|
30
|
-
|
|
61
|
+
All via environment variables:
|
|
62
|
+
|
|
63
|
+
| Variable | Default | Effect |
|
|
64
|
+
|----------|---------|--------|
|
|
65
|
+
| `NOTES_DIR` | `~/notes` | Directory where notes live (a leading `~` is expanded). |
|
|
66
|
+
| `NOTES_READONLY` | _unset_ | Set to `1` to disable all mutating tools (`create`/`append`/`delete`/`move` are not even registered) — safe for sharing a vault. |
|
|
67
|
+
| `NOTES_NO_CACHE` | _unset_ | Set to `1` to skip the on-disk index cache and rebuild in memory each start. |
|
|
68
|
+
| `NOTES_MODEL_DIR` | `~/.cache/mcp-notes/models` | Where the semantic-search embedding model is cached. |
|
|
69
|
+
| `NOTES_DAILY_DIR` | `daily` | Subdirectory (within the vault) for daily notes. |
|
|
70
|
+
| `NOTES_TEMPLATE_DIR` | `templates` | Subdirectory (within the vault) holding note templates. |
|
|
71
|
+
|
|
72
|
+
### Semantic search & the embedding model
|
|
73
|
+
`semantic_search` runs the [all-MiniLM-L6-v2](https://huggingface.co/Xenova/all-MiniLM-L6-v2) model **locally** via WebAssembly ([onnxruntime-web](https://github.com/microsoft/onnxruntime)) — no API keys, no native dependencies, no data leaves your machine. The quantized model (~23 MB) is downloaded **once** on first use into `NOTES_MODEL_DIR` and cached; embeddings are stored in `<NOTES_DIR>/.notes-embeddings.json` and incrementally updated as notes change. The first `semantic_search` call needs network access for the download and embeds the whole vault; everything after that is offline and fast. Keyword search and all other tools work without ever triggering this.
|
|
74
|
+
|
|
75
|
+
### Index cache
|
|
76
|
+
For fast warm starts the server persists its search index to `<NOTES_DIR>/.notes-index.json` and, on startup, incrementally re-parses only the notes that changed (by mtime/size) since last run. The cache is rebuilt automatically if it's missing, unreadable, or from an older index version. Files on disk are always the source of truth.
|
|
77
|
+
|
|
78
|
+
## Security
|
|
79
|
+
|
|
80
|
+
All filesystem access is sandboxed to the notes directory:
|
|
81
|
+
- Path traversal (`../`) and absolute paths are rejected.
|
|
82
|
+
- Symlinks inside the vault that resolve outside it are rejected (realpath containment).
|
|
83
|
+
- Single files above a size limit are refused (DoS / context guard).
|
|
84
|
+
- Writes are atomic (temp file + rename), so a crash can't leave a torn note.
|
|
85
|
+
|
|
86
|
+
## Usage
|
|
87
|
+
|
|
88
|
+
### Claude Code
|
|
31
89
|
|
|
32
90
|
```bash
|
|
33
|
-
|
|
91
|
+
claude mcp add notes --env NOTES_DIR=$HOME/notes -- npx -y @abhishekmcp/notes
|
|
34
92
|
```
|
|
35
93
|
|
|
36
|
-
## Connecting to a client
|
|
37
|
-
|
|
38
94
|
### Claude Desktop
|
|
39
95
|
|
|
40
96
|
Add to `claude_desktop_config.json`:
|
|
@@ -43,38 +99,27 @@ Add to `claude_desktop_config.json`:
|
|
|
43
99
|
{
|
|
44
100
|
"mcpServers": {
|
|
45
101
|
"notes": {
|
|
46
|
-
"command": "
|
|
47
|
-
"args": ["
|
|
102
|
+
"command": "npx",
|
|
103
|
+
"args": ["-y", "@abhishekmcp/notes"],
|
|
48
104
|
"env": { "NOTES_DIR": "/absolute/path/to/your/notes" }
|
|
49
105
|
}
|
|
50
106
|
}
|
|
51
107
|
}
|
|
52
108
|
```
|
|
53
109
|
|
|
54
|
-
|
|
110
|
+
To share a vault read-only, add `"NOTES_READONLY": "1"` to `env`.
|
|
111
|
+
|
|
112
|
+
## Develop from source
|
|
55
113
|
|
|
56
114
|
```bash
|
|
57
|
-
|
|
115
|
+
npm install # from the repo root
|
|
116
|
+
npm run build -w servers/notes
|
|
117
|
+
node servers/notes/dist/index.js # NOTES_DIR=... to point at a vault
|
|
58
118
|
```
|
|
59
119
|
|
|
60
120
|
## Publishing to npm
|
|
61
121
|
|
|
62
|
-
|
|
63
|
-
release tagged `notes-v<version>` is created. See the repo root for the CD workflow.
|
|
64
|
-
|
|
65
|
-
Once published, users can run it without cloning:
|
|
66
|
-
|
|
67
|
-
```json
|
|
68
|
-
{
|
|
69
|
-
"mcpServers": {
|
|
70
|
-
"notes": {
|
|
71
|
-
"command": "npx",
|
|
72
|
-
"args": ["-y", "@abhishekmcp/notes"],
|
|
73
|
-
"env": { "NOTES_DIR": "/path/to/notes" }
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
```
|
|
122
|
+
Publishes automatically via GitHub Actions (Trusted Publishing / OIDC) when a release tagged `notes-v<version>` is created. See the repo root for the CD workflow.
|
|
78
123
|
|
|
79
124
|
## License
|
|
80
125
|
|
package/dist/config.d.ts
CHANGED
|
@@ -15,3 +15,33 @@ export declare function getIndexPath(): string;
|
|
|
15
15
|
export declare function isReadOnly(): boolean;
|
|
16
16
|
/** When true, skip the on-disk index cache and rebuild in memory each start. */
|
|
17
17
|
export declare function cacheDisabled(): boolean;
|
|
18
|
+
/** Embedding model identity (recorded in the cache to invalidate on change). */
|
|
19
|
+
export declare const EMBED_MODEL_ID = "Xenova/all-MiniLM-L6-v2:quantized";
|
|
20
|
+
/** Embedding dimensionality of all-MiniLM-L6-v2. */
|
|
21
|
+
export declare const EMBED_DIM = 384;
|
|
22
|
+
/** Max WordPiece tokens fed to the model (longer notes are truncated). */
|
|
23
|
+
export declare const EMBED_MAX_TOKENS = 256;
|
|
24
|
+
/** Bump to force re-embedding of every note on upgrade. */
|
|
25
|
+
export declare const EMBED_CACHE_VERSION = 1;
|
|
26
|
+
/** Sidecar cache of per-note vectors, kept inside the notes dir. */
|
|
27
|
+
export declare const EMBEDDINGS_FILENAME = ".notes-embeddings.json";
|
|
28
|
+
/** Quantized ONNX model (~23 MB) — downloaded once at runtime. */
|
|
29
|
+
export declare const EMBED_MODEL_URL = "https://huggingface.co/Xenova/all-MiniLM-L6-v2/resolve/main/onnx/model_quantized.onnx";
|
|
30
|
+
/** BERT-uncased vocabulary (~232 KB) for the hand-rolled tokenizer. */
|
|
31
|
+
export declare const EMBED_VOCAB_URL = "https://huggingface.co/Xenova/all-MiniLM-L6-v2/resolve/main/vocab.txt";
|
|
32
|
+
/** Local filenames for the cached artifacts. */
|
|
33
|
+
export declare const EMBED_MODEL_FILE = "all-MiniLM-L6-v2.quantized.onnx";
|
|
34
|
+
export declare const EMBED_VOCAB_FILE = "all-MiniLM-L6-v2.vocab.txt";
|
|
35
|
+
/**
|
|
36
|
+
* Directory where the embedding model + vocab are cached (downloaded once per
|
|
37
|
+
* machine). Override with NOTES_MODEL_DIR; defaults to ~/.cache/mcp-notes/models.
|
|
38
|
+
*/
|
|
39
|
+
export declare function getModelDir(): string;
|
|
40
|
+
/** Absolute path to the persisted embeddings cache (sidecar to the text index). */
|
|
41
|
+
export declare function getEmbeddingsPath(): string;
|
|
42
|
+
/** Subdirectory (within the vault) for daily notes. Override with NOTES_DAILY_DIR. */
|
|
43
|
+
export declare function getDailyDir(): string;
|
|
44
|
+
/** Subdirectory (within the vault) holding note templates. Override with NOTES_TEMPLATE_DIR. */
|
|
45
|
+
export declare function getTemplateDir(): string;
|
|
46
|
+
/** Local-time date stamp, YYYY-MM-DD (the daily-note naming scheme). */
|
|
47
|
+
export declare function todayStamp(d?: Date): string;
|
package/dist/config.js
CHANGED
|
@@ -29,4 +29,55 @@ export function isReadOnly() {
|
|
|
29
29
|
export function cacheDisabled() {
|
|
30
30
|
return process.env.NOTES_NO_CACHE === "1";
|
|
31
31
|
}
|
|
32
|
+
// --- Semantic search (v0.3) ----------------------------------------------
|
|
33
|
+
/** Embedding model identity (recorded in the cache to invalidate on change). */
|
|
34
|
+
export const EMBED_MODEL_ID = "Xenova/all-MiniLM-L6-v2:quantized";
|
|
35
|
+
/** Embedding dimensionality of all-MiniLM-L6-v2. */
|
|
36
|
+
export const EMBED_DIM = 384;
|
|
37
|
+
/** Max WordPiece tokens fed to the model (longer notes are truncated). */
|
|
38
|
+
export const EMBED_MAX_TOKENS = 256;
|
|
39
|
+
/** Bump to force re-embedding of every note on upgrade. */
|
|
40
|
+
export const EMBED_CACHE_VERSION = 1;
|
|
41
|
+
/** Sidecar cache of per-note vectors, kept inside the notes dir. */
|
|
42
|
+
export const EMBEDDINGS_FILENAME = ".notes-embeddings.json";
|
|
43
|
+
const HF_BASE = "https://huggingface.co/Xenova/all-MiniLM-L6-v2/resolve/main";
|
|
44
|
+
/** Quantized ONNX model (~23 MB) — downloaded once at runtime. */
|
|
45
|
+
export const EMBED_MODEL_URL = `${HF_BASE}/onnx/model_quantized.onnx`;
|
|
46
|
+
/** BERT-uncased vocabulary (~232 KB) for the hand-rolled tokenizer. */
|
|
47
|
+
export const EMBED_VOCAB_URL = `${HF_BASE}/vocab.txt`;
|
|
48
|
+
/** Local filenames for the cached artifacts. */
|
|
49
|
+
export const EMBED_MODEL_FILE = "all-MiniLM-L6-v2.quantized.onnx";
|
|
50
|
+
export const EMBED_VOCAB_FILE = "all-MiniLM-L6-v2.vocab.txt";
|
|
51
|
+
/**
|
|
52
|
+
* Directory where the embedding model + vocab are cached (downloaded once per
|
|
53
|
+
* machine). Override with NOTES_MODEL_DIR; defaults to ~/.cache/mcp-notes/models.
|
|
54
|
+
*/
|
|
55
|
+
export function getModelDir() {
|
|
56
|
+
const override = process.env.NOTES_MODEL_DIR;
|
|
57
|
+
if (override) {
|
|
58
|
+
const expanded = override.startsWith("~") ? path.join(homedir(), override.slice(1)) : override;
|
|
59
|
+
return path.resolve(expanded);
|
|
60
|
+
}
|
|
61
|
+
return path.join(homedir(), ".cache", "mcp-notes", "models");
|
|
62
|
+
}
|
|
63
|
+
/** Absolute path to the persisted embeddings cache (sidecar to the text index). */
|
|
64
|
+
export function getEmbeddingsPath() {
|
|
65
|
+
return path.join(getNotesDir(), EMBEDDINGS_FILENAME);
|
|
66
|
+
}
|
|
67
|
+
// --- Note-app quality-of-life (v0.4) -------------------------------------
|
|
68
|
+
/** Subdirectory (within the vault) for daily notes. Override with NOTES_DAILY_DIR. */
|
|
69
|
+
export function getDailyDir() {
|
|
70
|
+
return process.env.NOTES_DAILY_DIR || "daily";
|
|
71
|
+
}
|
|
72
|
+
/** Subdirectory (within the vault) holding note templates. Override with NOTES_TEMPLATE_DIR. */
|
|
73
|
+
export function getTemplateDir() {
|
|
74
|
+
return process.env.NOTES_TEMPLATE_DIR || "templates";
|
|
75
|
+
}
|
|
76
|
+
/** Local-time date stamp, YYYY-MM-DD (the daily-note naming scheme). */
|
|
77
|
+
export function todayStamp(d = new Date()) {
|
|
78
|
+
const y = d.getFullYear();
|
|
79
|
+
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
80
|
+
const day = String(d.getDate()).padStart(2, "0");
|
|
81
|
+
return `${y}-${m}-${day}`;
|
|
82
|
+
}
|
|
32
83
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],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AAO,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,WAAW,CAAC;AACvD,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,UAAU,CAAC,IAAU,IAAI,IAAI,EAAE;IAC7C,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1B,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACpD,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACjD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;AAC5B,CAAC"}
|
package/dist/embed.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Idempotent, concurrency-safe lazy initialization. */
|
|
2
|
+
export declare function ensureModel(): Promise<void>;
|
|
3
|
+
/** True once the model has been downloaded + loaded. */
|
|
4
|
+
export declare function isReady(): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Embed a single text into an L2-normalized 384-dim vector (cosine == dot
|
|
7
|
+
* product). Mean-pools the model's last_hidden_state over the attention mask.
|
|
8
|
+
*/
|
|
9
|
+
export declare function embed(text: string): Promise<Float32Array>;
|
package/dist/embed.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy embedding engine: runs all-MiniLM-L6-v2 (ONNX) on onnxruntime-web (WASM,
|
|
3
|
+
* no native deps). The model + vocab are downloaded once to a persistent cache
|
|
4
|
+
* on first use; nothing here runs at server startup. `onnxruntime-web` is
|
|
5
|
+
* dynamically imported so a server that never does semantic search never loads
|
|
6
|
+
* the WASM runtime.
|
|
7
|
+
*/
|
|
8
|
+
import { promises as fs } from "node:fs";
|
|
9
|
+
import { createRequire } from "node:module";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { EMBED_DIM, EMBED_MAX_TOKENS, EMBED_MODEL_FILE, EMBED_MODEL_URL, EMBED_VOCAB_FILE, EMBED_VOCAB_URL, getModelDir, } from "./config.js";
|
|
12
|
+
import { WordPieceTokenizer } from "./tokenizer.js";
|
|
13
|
+
let session = null;
|
|
14
|
+
let tokenizer = null;
|
|
15
|
+
let initPromise = null;
|
|
16
|
+
/** Download a URL to `dest` atomically (temp + rename), retrying on 429/5xx. */
|
|
17
|
+
async function download(url, dest) {
|
|
18
|
+
let lastErr;
|
|
19
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
20
|
+
try {
|
|
21
|
+
const res = await fetch(url);
|
|
22
|
+
if (res.status === 429 || res.status >= 500) {
|
|
23
|
+
throw new Error(`HTTP ${res.status} fetching ${url}`);
|
|
24
|
+
}
|
|
25
|
+
if (!res.ok)
|
|
26
|
+
throw new Error(`HTTP ${res.status} fetching ${url}`);
|
|
27
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
28
|
+
const tmp = `${dest}.${process.pid}.tmp`;
|
|
29
|
+
await fs.writeFile(tmp, buf);
|
|
30
|
+
await fs.rename(tmp, dest);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
lastErr = err;
|
|
35
|
+
await new Promise((r) => setTimeout(r, 500 * 2 ** attempt)); // backoff
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
throw new Error(`Failed to download ${url}: ${lastErr?.message ?? lastErr}`);
|
|
39
|
+
}
|
|
40
|
+
/** Ensure a cached file exists, downloading it if missing. */
|
|
41
|
+
async function ensureFile(url, dest) {
|
|
42
|
+
try {
|
|
43
|
+
await fs.access(dest);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
47
|
+
await download(url, dest);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Download artifacts (once) and build the tokenizer + WASM inference session. */
|
|
51
|
+
async function init() {
|
|
52
|
+
const dir = getModelDir();
|
|
53
|
+
const modelPath = path.join(dir, EMBED_MODEL_FILE);
|
|
54
|
+
const vocabPath = path.join(dir, EMBED_VOCAB_FILE);
|
|
55
|
+
await ensureFile(EMBED_VOCAB_URL, vocabPath);
|
|
56
|
+
await ensureFile(EMBED_MODEL_URL, modelPath);
|
|
57
|
+
tokenizer = new WordPieceTokenizer(await fs.readFile(vocabPath, "utf8"));
|
|
58
|
+
const ort = await import("onnxruntime-web");
|
|
59
|
+
ort.env.wasm.numThreads = 1; // single-thread: no SharedArrayBuffer / worker isolation needed
|
|
60
|
+
// Best-effort: point the WASM loader at the .wasm shipped in node_modules.
|
|
61
|
+
// (onnxruntime-web self-resolves from its own module URL when this isn't set.)
|
|
62
|
+
try {
|
|
63
|
+
const require = createRequire(import.meta.url);
|
|
64
|
+
ort.env.wasm.wasmPaths = path.dirname(require.resolve("onnxruntime-web")) + path.sep;
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
/* fall back to onnxruntime-web's own resolution */
|
|
68
|
+
}
|
|
69
|
+
const modelBytes = new Uint8Array(await fs.readFile(modelPath));
|
|
70
|
+
session = await ort.InferenceSession.create(modelBytes, { executionProviders: ["wasm"] });
|
|
71
|
+
}
|
|
72
|
+
/** Idempotent, concurrency-safe lazy initialization. */
|
|
73
|
+
export async function ensureModel() {
|
|
74
|
+
if (session && tokenizer)
|
|
75
|
+
return;
|
|
76
|
+
if (!initPromise) {
|
|
77
|
+
initPromise = init().catch((err) => {
|
|
78
|
+
initPromise = null; // allow retry on a later call
|
|
79
|
+
throw err;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
await initPromise;
|
|
83
|
+
}
|
|
84
|
+
/** True once the model has been downloaded + loaded. */
|
|
85
|
+
export function isReady() {
|
|
86
|
+
return session !== null && tokenizer !== null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Embed a single text into an L2-normalized 384-dim vector (cosine == dot
|
|
90
|
+
* product). Mean-pools the model's last_hidden_state over the attention mask.
|
|
91
|
+
*/
|
|
92
|
+
export async function embed(text) {
|
|
93
|
+
await ensureModel();
|
|
94
|
+
const ort = await import("onnxruntime-web");
|
|
95
|
+
const tok = tokenizer.encode(text, EMBED_MAX_TOKENS);
|
|
96
|
+
const seq = tok.inputIds.length;
|
|
97
|
+
const dims = [1, seq];
|
|
98
|
+
const feeds = {
|
|
99
|
+
input_ids: new ort.Tensor("int64", BigInt64Array.from(tok.inputIds, BigInt), dims),
|
|
100
|
+
attention_mask: new ort.Tensor("int64", BigInt64Array.from(tok.attentionMask, BigInt), dims),
|
|
101
|
+
};
|
|
102
|
+
// Some exports require token_type_ids (all-zero for a single segment).
|
|
103
|
+
if (session.inputNames.includes("token_type_ids")) {
|
|
104
|
+
feeds.token_type_ids = new ort.Tensor("int64", new BigInt64Array(seq), dims);
|
|
105
|
+
}
|
|
106
|
+
const results = await session.run(feeds);
|
|
107
|
+
const outName = session.outputNames.includes("last_hidden_state")
|
|
108
|
+
? "last_hidden_state"
|
|
109
|
+
: session.outputNames[0];
|
|
110
|
+
const data = results[outName].data; // [1, seq, EMBED_DIM]
|
|
111
|
+
// Mean-pool over tokens weighted by the attention mask, then L2-normalize.
|
|
112
|
+
const out = new Float32Array(EMBED_DIM);
|
|
113
|
+
let maskSum = 0;
|
|
114
|
+
for (let t = 0; t < seq; t++) {
|
|
115
|
+
const m = tok.attentionMask[t];
|
|
116
|
+
if (!m)
|
|
117
|
+
continue;
|
|
118
|
+
maskSum += m;
|
|
119
|
+
const base = t * EMBED_DIM;
|
|
120
|
+
for (let d = 0; d < EMBED_DIM; d++)
|
|
121
|
+
out[d] += data[base + d] * m;
|
|
122
|
+
}
|
|
123
|
+
const denom = maskSum || 1;
|
|
124
|
+
let norm = 0;
|
|
125
|
+
for (let d = 0; d < EMBED_DIM; d++) {
|
|
126
|
+
out[d] /= denom;
|
|
127
|
+
norm += out[d] * out[d];
|
|
128
|
+
}
|
|
129
|
+
norm = Math.sqrt(norm) || 1;
|
|
130
|
+
for (let d = 0; d < EMBED_DIM; d++)
|
|
131
|
+
out[d] /= norm;
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=embed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,IAAI,OAAO,GAAkC,IAAI,CAAC;AAClD,IAAI,SAAS,GAA8B,IAAI,CAAC;AAChD,IAAI,WAAW,GAAyB,IAAI,CAAC;AAE7C,gFAAgF;AAChF,KAAK,UAAU,QAAQ,CAAC,GAAW,EAAE,IAAY;IAC/C,IAAI,OAAgB,CAAC;IACrB,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,CAAC;QAC7C,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;gBAC5C,MAAM,IAAI,KAAK,CAAC,QAAQ,GAAG,CAAC,MAAM,aAAa,GAAG,EAAE,CAAC,CAAC;YACxD,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,MAAM,IAAI,KAAK,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E,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE;QAAE,GAAG,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IACnD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/dist/extras.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface DailyResult {
|
|
2
|
+
name: string;
|
|
3
|
+
created: boolean;
|
|
4
|
+
appended: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Open (creating if needed) the daily note for `date` (YYYY-MM-DD, default
|
|
8
|
+
* today) and optionally append a timestamped entry.
|
|
9
|
+
*/
|
|
10
|
+
export declare function dailyNote(entry?: string, date?: string): Promise<DailyResult>;
|
|
11
|
+
/** List available template names (without the .md extension). */
|
|
12
|
+
export declare function listTemplates(): Promise<string[]>;
|
|
13
|
+
/** Instantiate a template into a new note, substituting placeholders. */
|
|
14
|
+
export declare function createFromTemplate(template: string, name: string, vars?: Record<string, string>): Promise<string>;
|
|
15
|
+
export interface RenameTagResult {
|
|
16
|
+
from: string;
|
|
17
|
+
to: string;
|
|
18
|
+
changed: string[];
|
|
19
|
+
}
|
|
20
|
+
/** Rename a tag across every note that carries it. */
|
|
21
|
+
export declare function renameTag(from: string, to: string): Promise<RenameTagResult>;
|
|
22
|
+
export interface Mention {
|
|
23
|
+
note: string;
|
|
24
|
+
line: number;
|
|
25
|
+
text: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Find notes that mention `name`'s title as plain text but do NOT already link
|
|
29
|
+
* to it via [[wiki-link]] — candidates for linking (Obsidian-style).
|
|
30
|
+
*/
|
|
31
|
+
export declare function unlinkedMentions(name: string): Promise<Mention[]>;
|
package/dist/extras.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quality-of-life note operations (v0.4): daily notes, templates, vault-wide
|
|
3
|
+
* tag rename, and unlinked-mention discovery. Pure logic layered over store +
|
|
4
|
+
* fsutil + parse; all mutations go through store so the index stays in sync.
|
|
5
|
+
*/
|
|
6
|
+
import { promises as fs } from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { getDailyDir, getNotesDir, getTemplateDir, todayStamp } from "./config.js";
|
|
9
|
+
import { readRaw, resolveSafe } from "./fsutil.js";
|
|
10
|
+
import { normalizeLinkTarget, parseNote } from "./parse.js";
|
|
11
|
+
import { appendNote, createNote, getAllMeta, getMeta, updateNoteRaw, } from "./store.js";
|
|
12
|
+
/** Local-time HH:MM stamp for daily-note entries. */
|
|
13
|
+
function timeStamp(d = new Date()) {
|
|
14
|
+
return `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Open (creating if needed) the daily note for `date` (YYYY-MM-DD, default
|
|
18
|
+
* today) and optionally append a timestamped entry.
|
|
19
|
+
*/
|
|
20
|
+
export async function dailyNote(entry, date) {
|
|
21
|
+
const stamp = date ?? todayStamp();
|
|
22
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(stamp)) {
|
|
23
|
+
throw new Error(`Invalid date "${stamp}" — expected YYYY-MM-DD.`);
|
|
24
|
+
}
|
|
25
|
+
const name = `${getDailyDir()}/${stamp}`;
|
|
26
|
+
const existed = getMeta(name) !== undefined;
|
|
27
|
+
if (!existed)
|
|
28
|
+
await createNote(name, `# ${stamp}\n`);
|
|
29
|
+
let appended = false;
|
|
30
|
+
if (entry && entry.trim()) {
|
|
31
|
+
await appendNote(name, `- ${timeStamp()} ${entry.trim()}`);
|
|
32
|
+
appended = true;
|
|
33
|
+
}
|
|
34
|
+
return { name: normalizeLinkTarget(name), created: !existed, appended };
|
|
35
|
+
}
|
|
36
|
+
// --- Templates ------------------------------------------------------------
|
|
37
|
+
/** Path to the template dir, rejecting an override that escapes the vault. */
|
|
38
|
+
function templateDirAbs() {
|
|
39
|
+
const root = getNotesDir();
|
|
40
|
+
const abs = path.resolve(root, getTemplateDir());
|
|
41
|
+
const rel = path.relative(root, abs);
|
|
42
|
+
if (rel.startsWith("..") || path.isAbsolute(rel)) {
|
|
43
|
+
throw new Error("NOTES_TEMPLATE_DIR escapes the notes directory.");
|
|
44
|
+
}
|
|
45
|
+
return abs;
|
|
46
|
+
}
|
|
47
|
+
/** List available template names (without the .md extension). */
|
|
48
|
+
export async function listTemplates() {
|
|
49
|
+
try {
|
|
50
|
+
const entries = await fs.readdir(templateDirAbs(), { withFileTypes: true });
|
|
51
|
+
return entries
|
|
52
|
+
.filter((e) => e.isFile() && e.name.endsWith(".md"))
|
|
53
|
+
.map((e) => e.name.replace(/\.md$/, ""))
|
|
54
|
+
.sort();
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (err.code === "ENOENT")
|
|
58
|
+
return [];
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** Substitute {{date}} / {{time}} / {{title}} / {{var}} placeholders. */
|
|
63
|
+
function applyVars(tpl, vars) {
|
|
64
|
+
return tpl.replace(/\{\{\s*([\w-]+)\s*\}\}/g, (whole, key) => key in vars ? vars[key] : whole);
|
|
65
|
+
}
|
|
66
|
+
/** Instantiate a template into a new note, substituting placeholders. */
|
|
67
|
+
export async function createFromTemplate(template, name, vars = {}) {
|
|
68
|
+
const raw = await readRaw(await resolveSafe(`${getTemplateDir()}/${template}`));
|
|
69
|
+
const title = vars.title ?? name.split("/").pop() ?? name;
|
|
70
|
+
const content = applyVars(raw, { date: todayStamp(), time: timeStamp(), title, ...vars });
|
|
71
|
+
return createNote(name, content, false);
|
|
72
|
+
}
|
|
73
|
+
// --- Tag rename -----------------------------------------------------------
|
|
74
|
+
function escapeRegExp(s) {
|
|
75
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
76
|
+
}
|
|
77
|
+
/** Rewrite a tag token inside a YAML frontmatter block (list or inline forms). */
|
|
78
|
+
function rewriteFrontmatterTag(block, from, to) {
|
|
79
|
+
const re = new RegExp(`(^|[\\s\\[,'"-])(${escapeRegExp(from)})(?=[\\s\\],'"]|$)`, "gm");
|
|
80
|
+
return block.replace(re, (_m, pre) => `${pre}${to}`);
|
|
81
|
+
}
|
|
82
|
+
/** Rewrite inline #hashtags (word-boundary, tag chars are [\w/-]). */
|
|
83
|
+
function rewriteInlineHashtag(text, from, to) {
|
|
84
|
+
const re = new RegExp(`(^|[^\\w#/-])#${escapeRegExp(from)}(?![\\w/-])`, "g");
|
|
85
|
+
return text.replace(re, (_m, pre) => `${pre}#${to}`);
|
|
86
|
+
}
|
|
87
|
+
const FRONTMATTER_RE = /^(---[ \t]*\r?\n[\s\S]*?\r?\n---[ \t]*(?:\r?\n|$))([\s\S]*)$/;
|
|
88
|
+
/** Rewrite a tag across the whole note (frontmatter + inline). */
|
|
89
|
+
function rewriteNoteTag(raw, from, to) {
|
|
90
|
+
const m = FRONTMATTER_RE.exec(raw);
|
|
91
|
+
if (m) {
|
|
92
|
+
const fm = rewriteFrontmatterTag(m[1], from, to);
|
|
93
|
+
const body = rewriteInlineHashtag(m[2], from, to);
|
|
94
|
+
return fm + body;
|
|
95
|
+
}
|
|
96
|
+
return rewriteInlineHashtag(raw, from, to);
|
|
97
|
+
}
|
|
98
|
+
/** Rename a tag across every note that carries it. */
|
|
99
|
+
export async function renameTag(from, to) {
|
|
100
|
+
const f = from.replace(/^#/, "").trim();
|
|
101
|
+
const t = to.replace(/^#/, "").trim();
|
|
102
|
+
if (!f || !t)
|
|
103
|
+
throw new Error("Both tag names are required.");
|
|
104
|
+
const changed = [];
|
|
105
|
+
for (const [name, meta] of getAllMeta()) {
|
|
106
|
+
if (!meta.tags.some((tag) => tag.toLowerCase() === f.toLowerCase()))
|
|
107
|
+
continue;
|
|
108
|
+
const raw = await readRaw(await resolveSafe(name));
|
|
109
|
+
const updated = rewriteNoteTag(raw, f, t);
|
|
110
|
+
if (updated !== raw) {
|
|
111
|
+
await updateNoteRaw(name, updated);
|
|
112
|
+
changed.push(name);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return { from: f, to: t, changed: changed.sort() };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Find notes that mention `name`'s title as plain text but do NOT already link
|
|
119
|
+
* to it via [[wiki-link]] — candidates for linking (Obsidian-style).
|
|
120
|
+
*/
|
|
121
|
+
export async function unlinkedMentions(name) {
|
|
122
|
+
const target = normalizeLinkTarget(name);
|
|
123
|
+
const self = getMeta(target);
|
|
124
|
+
const title = (self?.title ?? target).trim();
|
|
125
|
+
if (title.length < 2)
|
|
126
|
+
return [];
|
|
127
|
+
const re = new RegExp(`\\b${escapeRegExp(title)}\\b`, "i");
|
|
128
|
+
const out = [];
|
|
129
|
+
for (const [n, meta] of getAllMeta()) {
|
|
130
|
+
if (n === target)
|
|
131
|
+
continue;
|
|
132
|
+
if (meta.outLinks.some((l) => normalizeLinkTarget(l) === target))
|
|
133
|
+
continue; // already linked
|
|
134
|
+
const { body } = parseNote(await readRaw(await resolveSafe(n)));
|
|
135
|
+
const lines = body.split(/\r?\n/);
|
|
136
|
+
for (let i = 0; i < lines.length; i++) {
|
|
137
|
+
const stripped = lines[i].replace(/\[\[[^\]]+\]\]/g, ""); // ignore mentions inside links
|
|
138
|
+
if (re.test(stripped)) {
|
|
139
|
+
out.push({ note: n, line: i + 1, text: lines[i].trim() });
|
|
140
|
+
break; // one hit per note is enough to flag it
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return out;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=extras.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extras.js","sourceRoot":"","sources":["../src/extras.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cA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