@aaryanbindage/omnicontext 0.1.3 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aaryanbindage/omnicontext",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "Persistent, cross-device memory for Claude: your profile, your projects, and resumable handoffs — shared by every Claude session (Claude Code plugin + MCP server + desktop app).",
5
5
  "type": "module",
6
6
  "bin": {
package/src/cli.js CHANGED
@@ -5,6 +5,7 @@ import { spawn } from 'node:child_process';
5
5
  import { Store, VERSION } from './store.js';
6
6
  import { buildContext, projectLine, handoffLine } from './context.js';
7
7
  import { resolveProjects } from './resolve.js';
8
+ import { buildGraph, neighborhood } from './graph.js';
8
9
  import { sync, pull, initSync, createGithubRemote, syncStatus } from './sync.js';
9
10
  import { installClaudeDesktop, installClaudeCode } from './install.js';
10
11
 
@@ -16,17 +17,24 @@ Usage:
16
17
  omnicontext status Data folder, device, sync state
17
18
 
18
19
  omnicontext remember "<fact>" Add a fact to your profile
20
+ omnicontext forget "<words>" Remove profile facts containing these words
21
+ omnicontext capture "<text>" [--project P] Drop a quick note in the inbox
22
+ omnicontext inbox List inbox items (captures from the watch and elsewhere)
19
23
  omnicontext profile [--edit FILE] Print profile, or replace it from FILE
20
24
  omnicontext projects List projects
21
25
  omnicontext project add <name> [--alias A]... [--tag T]... [--desc D] [--path DIR] [--repo URL]
22
26
  omnicontext project note <project> "<note>"
23
27
  omnicontext resolve "<reference>" e.g. omnicontext resolve "my game project"
24
28
  omnicontext handoffs [--all] List handoffs
29
+ omnicontext graph [--json] Knowledge graph: counts, hubs (or the full graph as JSON)
30
+ omnicontext related "<thing>" What's linked to a project, #tag, device or topic
25
31
 
26
32
  omnicontext sync Sync now
27
33
  omnicontext sync --github [NAME] Create a private GitHub repo (via gh) and sync to it
28
34
  omnicontext sync --remote <git-url> Sync to any git remote you own
29
35
  omnicontext device <name> Name this device
36
+ omnicontext export [FILE] Write everything to one JSON file (stdout if no FILE)
37
+ omnicontext import FILE [--replace-profile] Merge an export into this device's memory
30
38
 
31
39
  omnicontext install claude-desktop Add the MCP server to Claude Desktop
32
40
  omnicontext install claude-code Install the Claude Code plugin
@@ -115,7 +123,7 @@ export async function main(argv = process.argv.slice(2)) {
115
123
  case 'status': {
116
124
  const st = syncStatus(store.home);
117
125
  console.log(`Data: ${store.home}\nDevice: ${store.device}`);
118
- console.log(`Projects: ${store.listProjects().length} Open handoffs: ${store.listHandoffs({ status: 'open' }).length}`);
126
+ console.log(`Projects: ${store.listProjects().length} Open handoffs: ${store.listHandoffs({ status: 'open' }).length} Inbox: ${store.listInbox().length}`);
119
127
  console.log(`Sync: ${st.configured ? `${st.remote}${st.dirty ? ' (unsynced changes)' : ''}` : 'not configured (omnicontext sync --github)'}`);
120
128
  return;
121
129
  }
@@ -125,6 +133,36 @@ export async function main(argv = process.argv.slice(2)) {
125
133
  console.log('Saved:', store.remember(pos.join(' ')));
126
134
  return;
127
135
 
136
+ case 'forget': {
137
+ const removed = store.forget(pos.join(' '));
138
+ console.log(removed.length ? `Removed:\n${removed.join('\n')}` : 'No matching fact.');
139
+ return;
140
+ }
141
+
142
+ case 'capture': {
143
+ const item = store.capture(pos.join(' '), { project: typeof flags.project === 'string' ? flags.project : '' });
144
+ return console.log(`Captured ${item.id}`);
145
+ }
146
+
147
+ case 'inbox':
148
+ for (const i of store.listInbox()) console.log(`${i.id} ${i.text}${i.project ? ` (${i.project})` : ''} — ${i.source}`);
149
+ return;
150
+
151
+ case 'export': {
152
+ const json = JSON.stringify(store.exportAll(), null, 2) + '\n';
153
+ if (pos[0]) {
154
+ fs.writeFileSync(pos[0], json);
155
+ return console.log(`Exported to ${pos[0]}`);
156
+ }
157
+ return process.stdout.write(json);
158
+ }
159
+
160
+ case 'import': {
161
+ if (!pos[0]) throw new Error('Usage: omnicontext import FILE');
162
+ const r = store.importAll(JSON.parse(fs.readFileSync(pos[0], 'utf8')), { replaceProfile: !!flags['replace-profile'] });
163
+ return console.log(`Imported ${r.projects} projects, ${r.handoffs} handoffs, ${r.inbox} inbox items.`);
164
+ }
165
+
128
166
  case 'profile':
129
167
  if (typeof flags.edit === 'string') store.setProfile(fs.readFileSync(flags.edit, 'utf8'));
130
168
  return console.log(store.getProfile());
@@ -164,6 +202,30 @@ export async function main(argv = process.argv.slice(2)) {
164
202
  return;
165
203
  }
166
204
 
205
+ case 'graph': {
206
+ const g = buildGraph(store);
207
+ if (flags.json) return console.log(JSON.stringify(g, null, 2));
208
+ const by = {};
209
+ for (const n of g.nodes) by[n.type] = (by[n.type] || 0) + 1;
210
+ console.log(`${g.nodes.length} nodes, ${g.edges.length} links: ${Object.entries(by).map(([t, c]) => `${c} ${t}`).join(', ')}`);
211
+ console.log('Most connected:');
212
+ for (const n of g.nodes.filter((n) => n.id !== 'you').sort((a, b) => b.degree - a.degree).slice(0, 8)) console.log(` ${String(n.degree).padStart(3)} ${n.label} (${n.type})`);
213
+ return;
214
+ }
215
+
216
+ case 'related': {
217
+ const g = buildGraph(store);
218
+ const q = pos.join(' ').trim().toLowerCase();
219
+ let start = g.nodes.filter((n) => n.id !== 'you' && (n.label.toLowerCase() === q || n.id.endsWith(`:${q}`)));
220
+ if (!start.length) {
221
+ const p = resolveProjects(store.listProjects(), q, 1)[0]?.project;
222
+ if (p) start = g.nodes.filter((n) => n.id === `project:${p.slug}`);
223
+ }
224
+ if (!start.length) return console.log('No match.');
225
+ for (const n of neighborhood(g, start.map((n) => n.id))) console.log(` ${n.label} (${n.type})`);
226
+ return;
227
+ }
228
+
167
229
  case 'handoffs':
168
230
  for (const h of store.listHandoffs({ status: flags.all ? 'all' : 'open' })) console.log(handoffLine(h), `[${h.status}]`);
169
231
  return;
package/src/context.js CHANGED
@@ -26,14 +26,20 @@ export function projectLine(p, device, current) {
26
26
 
27
27
  export function handoffLine(h) {
28
28
  const next = h.nextSteps?.length ? ` Next: ${h.nextSteps.slice(0, 2).join('; ')}` : '';
29
- return `- \`${h.id}\` **${h.title}**${h.project ? ` (${h.project})` : ''} — from ${h.device}, ${ago(h.createdAt)}.${next}`;
29
+ const branch = h.git?.branch ? ` Branch \`${h.git.branch}\`.` : '';
30
+ return `- \`${h.id}\` **${h.title}**${h.project ? ` (${h.project})` : ''} — from ${h.device}, ${ago(h.createdAt)}.${branch}${next}`;
30
31
  }
31
32
 
33
+ const STALE_DAYS = 30;
34
+
32
35
  export function buildContext(store, { cwd } = {}) {
33
36
  const device = store.device;
34
37
  const projects = store.listProjects();
35
38
  const current = store.projectForCwd(cwd);
36
- const open = store.listHandoffs({ status: 'open', limit: 5 });
39
+ const allOpen = store.listHandoffs({ status: 'open' });
40
+ const fresh = allOpen.filter((h) => Date.now() - new Date(h.createdAt).getTime() < STALE_DAYS * 86400000);
41
+ const open = fresh.slice(0, 5);
42
+ const inbox = store.listInbox();
37
43
  const profile = store.getProfile().replace(/<!--[\s\S]*?-->/g, '').replace(/\n{3,}/g, '\n\n').trim();
38
44
 
39
45
  const out = [];
@@ -73,6 +79,15 @@ export function buildContext(store, { cwd } = {}) {
73
79
  for (const h of open) out.push(handoffLine(h));
74
80
  out.push('If the user says "resume", "continue", or "pick up where I left off", call `resume_handoff`.');
75
81
  }
82
+ const hidden = allOpen.length - open.length;
83
+ if (hidden > 0) out.push(`${open.length ? '' : '\n'}(${hidden} more open handoff${hidden > 1 ? 's' : ''}, older or beyond the first five: \`list_handoffs\`.)`);
84
+
85
+ if (inbox.length) {
86
+ out.push(`\n## Inbox (${inbox.length} quick capture${inbox.length > 1 ? 's' : ''} to file)`);
87
+ for (const i of inbox.slice(0, 10))
88
+ out.push(`- \`${i.id}\` "${i.text.slice(0, 200)}"${i.project ? ` (for ${i.project})` : ''} — from ${i.source}, ${ago(i.createdAt)}`);
89
+ out.push('At a natural moment, mention these and offer to file each one with `file_inbox` (as a profile fact, a project note, or dismiss).');
90
+ }
76
91
 
77
92
  out.push(
78
93
  `\n## Keeping this memory useful\n` +
package/src/graph.js ADDED
@@ -0,0 +1,130 @@
1
+ // Knowledge graph over everything in memory, Obsidian-style: you, your projects, their tags,
2
+ // devices, handoffs, inbox items and profile facts, linked by structure and by mentions.
3
+ // A project named in any text (or written as [[Name]]) links to it; an unknown [[Topic]] becomes a topic node.
4
+
5
+ const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
6
+
7
+ function mentionFinder(projects) {
8
+ const terms = [];
9
+ for (const p of projects) {
10
+ for (const t of [p.name, p.slug, ...(p.aliases || [])]) {
11
+ const term = String(t || '').trim();
12
+ if (term.length >= 3 && /[a-z]/i.test(term)) terms.push({ term: term.toLowerCase(), slug: p.slug });
13
+ }
14
+ }
15
+ // Longest first so "my game engine" wins over "game".
16
+ terms.sort((a, b) => b.term.length - a.term.length);
17
+ const re = terms.length ? new RegExp(`(?<![\\w-])(${terms.map((t) => esc(t.term)).join('|')})(?![\\w-])`, 'gi') : null;
18
+ const bySlug = new Map(terms.map((t) => [t.term, t.slug]));
19
+ return (text) => {
20
+ const found = new Set();
21
+ const topics = new Set();
22
+ const s = String(text || '');
23
+ for (const m of s.matchAll(/\[\[([^\]|#]{1,80})(?:[|#][^\]]*)?\]\]/g)) {
24
+ const name = m[1].trim();
25
+ const slug = bySlug.get(name.toLowerCase());
26
+ if (slug) found.add(slug);
27
+ else topics.add(name);
28
+ }
29
+ if (re) for (const m of s.matchAll(re)) found.add(bySlug.get(m[1].toLowerCase()));
30
+ return { projects: found, topics };
31
+ };
32
+ }
33
+
34
+ export function buildGraph(store) {
35
+ const nodes = new Map();
36
+ const edges = new Map();
37
+ const node = (id, type, label, extra = {}) => {
38
+ if (!nodes.has(id)) nodes.set(id, { id, type, label, ...extra });
39
+ return id;
40
+ };
41
+ const link = (a, b, kind) => {
42
+ if (a === b) return;
43
+ const key = a < b ? `${a}|${b}` : `${b}|${a}`;
44
+ if (!edges.has(key)) edges.set(key, { source: a, target: b, kind });
45
+ };
46
+
47
+ const projects = store.listProjects();
48
+ const find = mentionFinder(projects);
49
+ const mentions = (from, text) => {
50
+ const { projects: ps, topics } = find(text);
51
+ for (const slug of ps) link(from, `project:${slug}`, 'mentions');
52
+ for (const t of topics) link(from, node(`topic:${t.toLowerCase()}`, 'topic', t), 'mentions');
53
+ };
54
+
55
+ const you = node('you', 'you', 'You', { detail: store.getProfile().replace(/<!--[\s\S]*?-->/g, '').trim() });
56
+
57
+ // Profile facts: bullet lines.
58
+ let i = 0;
59
+ for (const line of store.getProfile().split('\n')) {
60
+ const m = line.match(/^\s*[-*]\s+(.+)/);
61
+ if (!m) continue;
62
+ const text = m[1].replace(/\s*_\(\d{4}-\d\d-\d\d\)_\s*$/, '');
63
+ const id = node(`fact:${i++}`, 'fact', text.length > 48 ? text.slice(0, 46) + '…' : text, { detail: text });
64
+ link(you, id, 'fact');
65
+ mentions(id, text);
66
+ }
67
+
68
+ for (const p of projects) {
69
+ const id = node(`project:${p.slug}`, 'project', p.name, {
70
+ slug: p.slug,
71
+ status: p.status || 'active',
72
+ detail: [p.description, p.aliases?.length ? `Aka: ${p.aliases.join(', ')}` : '', p.repo ? `Repo: ${p.repo}` : '']
73
+ .filter(Boolean)
74
+ .join('\n'),
75
+ notes: (p.notes || []).slice(-8).map((n) => n.text),
76
+ });
77
+ link(you, id, 'project');
78
+ for (const t of p.tags || []) link(id, node(`tag:${t.toLowerCase()}`, 'tag', `#${t}`), 'tag');
79
+ for (const d of Object.keys(p.paths || {})) link(id, node(`device:${d}`, 'device', d), 'device');
80
+ mentions(id, [p.description, ...(p.notes || []).map((n) => n.text)].join('\n'));
81
+ }
82
+
83
+ for (const h of store.listHandoffs({ status: 'all' })) {
84
+ const id = node(`handoff:${h.id}`, 'handoff', h.title, {
85
+ status: h.status,
86
+ detail: [h.summary, h.nextSteps?.length ? `Next: ${h.nextSteps.join('; ')}` : ''].filter(Boolean).join('\n\n'),
87
+ });
88
+ if (h.project && nodes.has(`project:${h.project}`)) link(id, `project:${h.project}`, 'handoff');
89
+ else link(id, you, 'handoff');
90
+ if (h.device) link(id, node(`device:${h.device}`, 'device', h.device), 'device');
91
+ mentions(id, `${h.title}\n${h.summary}\n${(h.nextSteps || []).join('\n')}`);
92
+ }
93
+
94
+ for (const it of store.listInbox()) {
95
+ const id = node(`inbox:${it.id}`, 'inbox', it.text.length > 40 ? it.text.slice(0, 38) + '…' : it.text, { detail: it.text });
96
+ const target = it.project && nodes.has(`project:${it.project}`) ? `project:${it.project}` : you;
97
+ link(id, target, 'inbox');
98
+ mentions(id, it.text);
99
+ }
100
+
101
+ const list = [...nodes.values()];
102
+ const degree = new Map(list.map((n) => [n.id, 0]));
103
+ for (const e of edges.values()) {
104
+ degree.set(e.source, degree.get(e.source) + 1);
105
+ degree.set(e.target, degree.get(e.target) + 1);
106
+ }
107
+ for (const n of list) n.degree = degree.get(n.id);
108
+ return { nodes: list, edges: [...edges.values()] };
109
+ }
110
+
111
+ /** Everything one hop (or `depth` hops) from the nodes matching `query`, for the `related` tool. */
112
+ export function neighborhood(graph, startIds, depth = 1) {
113
+ const adj = new Map(graph.nodes.map((n) => [n.id, []]));
114
+ for (const e of graph.edges) {
115
+ adj.get(e.source).push({ id: e.target, kind: e.kind });
116
+ adj.get(e.target).push({ id: e.source, kind: e.kind });
117
+ }
118
+ const byId = new Map(graph.nodes.map((n) => [n.id, n]));
119
+ const seen = new Map(startIds.map((id) => [id, 0]));
120
+ let frontier = [...startIds];
121
+ for (let d = 1; d <= depth; d++) {
122
+ const next = [];
123
+ for (const id of frontier) for (const { id: nb } of adj.get(id) || []) if (!seen.has(nb)) { seen.set(nb, d); next.push(nb); }
124
+ frontier = next;
125
+ }
126
+ return [...seen.entries()]
127
+ .filter(([id, d]) => d > 0 && id !== 'you')
128
+ .map(([id, d]) => ({ ...byId.get(id), distance: d }))
129
+ .sort((a, b) => a.distance - b.distance || b.degree - a.degree);
130
+ }
package/src/index.js CHANGED
@@ -3,3 +3,4 @@ export { resolveProjects, scoreProject } from './resolve.js';
3
3
  export { buildContext } from './context.js';
4
4
  export { sync, pull, initSync, createGithubRemote, syncStatus } from './sync.js';
5
5
  export { installClaudeDesktop, installClaudeCode, claudeDesktopConfigPath } from './install.js';
6
+ export { buildGraph, neighborhood } from './graph.js';
package/src/mcp.js CHANGED
@@ -1,16 +1,29 @@
1
1
  // MCP server (stdio). Works in Claude Code, Claude Desktop, and any MCP client.
2
2
 
3
- import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
4
4
  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
5
5
  import { z } from 'zod';
6
- import { Store, VERSION } from './store.js';
6
+ import { Store, VERSION, gitStateOf } from './store.js';
7
7
  import { resolveProjects } from './resolve.js';
8
8
  import { buildContext } from './context.js';
9
+ import { buildGraph, neighborhood } from './graph.js';
9
10
  import { sync, syncStatus } from './sync.js';
10
11
 
11
12
  const text = (t) => ({ content: [{ type: 'text', text: typeof t === 'string' ? t : JSON.stringify(t, null, 2) }] });
12
13
  const fail = (t) => ({ content: [{ type: 'text', text: t }], isError: true });
13
14
 
15
+ /** How to get this device's checkout to where the handoff left off. */
16
+ function gitSection(h, device) {
17
+ const g = h.git;
18
+ if (!g) return '';
19
+ const lines = [`\n## Git state on ${h.device}`, `Branch \`${g.branch}\` at \`${g.commit}\`${g.remote ? ` (${g.remote})` : ''}.`];
20
+ if (g.unpushed) lines.push(`⚠ ${g.unpushed} commit(s) were not pushed from ${h.device}; they won't be on the remote.`);
21
+ if (g.uncommitted?.length)
22
+ lines.push(`⚠ Uncommitted changes on ${h.device} (not available here unless pushed): ${g.uncommitted.slice(0, 10).join(', ')}${g.uncommitted.length > 10 ? ', …' : ''}`);
23
+ if (h.device !== device) lines.push(`To match it here: \`git fetch && git checkout ${g.branch} && git pull\`.`);
24
+ return lines.join('\n') + '\n';
25
+ }
26
+
14
27
  export async function startMcpServer(store = new Store()) {
15
28
  const server = new McpServer({ name: 'omnicontext', version: VERSION });
16
29
 
@@ -72,6 +85,22 @@ export async function startMcpServer(store = new Store()) {
72
85
  }),
73
86
  );
74
87
 
88
+ server.registerTool(
89
+ 'forget',
90
+ {
91
+ title: 'Forget a fact',
92
+ description: 'Remove profile facts (bullet lines) that contain the given text, e.g. when the user says something is no longer true.',
93
+ inputSchema: { text: z.string().min(3).describe('Words from the fact to remove') },
94
+ annotations: { destructiveHint: true },
95
+ },
96
+ guard(async ({ text: q }) => {
97
+ const removed = store.forget(q);
98
+ if (!removed.length) return fail(`No profile fact contains "${q}". Use get_profile to see the exact wording.`);
99
+ changed();
100
+ return text(`Removed ${removed.length} line(s):\n${removed.join('\n')}`);
101
+ }),
102
+ );
103
+
75
104
  server.registerTool(
76
105
  'update_profile',
77
106
  {
@@ -187,7 +216,9 @@ export async function startMcpServer(store = new Store()) {
187
216
  },
188
217
  guard(async ({ title, summary, next_steps, project, files, cwd }) => {
189
218
  const proj = project ? store.getProject(project) || resolveProjects(store.listProjects(), project, 1)[0]?.project : null;
190
- const h = store.saveHandoff({ title, summary, nextSteps: next_steps, files, cwd, project: proj?.slug || project });
219
+ // Claude Code starts MCP servers in the project folder, so fall back to it to capture the git state.
220
+ const dir = cwd || (gitStateOf(process.cwd()) ? process.cwd() : '');
221
+ const h = store.saveHandoff({ title, summary, nextSteps: next_steps, files, cwd: dir, project: proj?.slug || project });
191
222
  changed();
192
223
  return text(`Handoff saved: ${h.id}. Resume on any device with "resume ${h.title}" or /omnicontext:resume.`);
193
224
  }),
@@ -238,6 +269,7 @@ export async function startMcpServer(store = new Store()) {
238
269
  return text(
239
270
  `# Resuming: ${h.title}\nFrom ${h.device} at ${h.createdAt}${proj ? ` · project ${proj.name}` : ''}\n` +
240
271
  (localPath ? `Project folder on this device: ${localPath}\n` : proj ? `Project folder isn't linked on this device yet.\n` : '') +
272
+ gitSection(h, store.device) +
241
273
  `\n## Summary\n${h.summary}\n` +
242
274
  (h.nextSteps?.length ? `\n## Next steps\n${h.nextSteps.map((s) => `- ${s}`).join('\n')}\n` : '') +
243
275
  (h.files?.length ? `\n## Files\n${h.files.map((s) => `- ${s}`).join('\n')}\n` : ''),
@@ -277,11 +309,121 @@ export async function startMcpServer(store = new Store()) {
277
309
  for (const n of p.notes || []) if (n.text.toLowerCase().includes(q)) hits.push({ in: `project:${p.slug}`, text: n.text, at: n.at });
278
310
  }
279
311
  for (const h of store.listHandoffs({ status: 'all' }))
280
- if (`${h.title} ${h.summary}`.toLowerCase().includes(q)) hits.push({ in: `handoff:${h.id}`, text: h.title, status: h.status });
312
+ if (`${h.title} ${h.summary} ${(h.nextSteps || []).join(' ')}`.toLowerCase().includes(q))
313
+ hits.push({ in: `handoff:${h.id}`, text: h.title, status: h.status });
314
+ for (const i of store.listInbox()) if (i.text.toLowerCase().includes(q)) hits.push({ in: `inbox:${i.id}`, text: i.text });
281
315
  return text(hits.length ? hits.slice(0, 30) : `Nothing found for "${query}".`);
282
316
  }),
283
317
  );
284
318
 
319
+ server.registerTool(
320
+ 'related',
321
+ {
322
+ title: 'Find related things',
323
+ description:
324
+ 'Walk the knowledge graph from a project, tag (e.g. "#godot"), device, or [[topic]]: returns linked projects, tags, handoffs, facts and inbox items. Use for "what else is connected to X" or "which of my projects use Y".',
325
+ inputSchema: {
326
+ query: z.string().describe('Project reference, #tag, device name, or topic'),
327
+ depth: z.number().int().min(1).max(3).optional().describe('Hops to follow (default 1)'),
328
+ },
329
+ annotations: { readOnlyHint: true },
330
+ },
331
+ guard(async ({ query, depth = 1 }) => {
332
+ const g = buildGraph(store);
333
+ const q = query.trim().toLowerCase().replace(/^\[\[|\]\]$/g, '');
334
+ let start = g.nodes.filter((n) => n.id !== 'you' && (n.label.toLowerCase() === q || n.label.toLowerCase() === `#${q}` || n.id.endsWith(`:${q}`)));
335
+ if (!start.length) {
336
+ const p = resolveProjects(store.listProjects(), query, 1)[0]?.project;
337
+ if (p) start = g.nodes.filter((n) => n.id === `project:${p.slug}`);
338
+ }
339
+ if (!start.length) return fail(`Nothing in the graph matches "${query}".`);
340
+ const hits = neighborhood(g, start.map((n) => n.id), depth);
341
+ return text({
342
+ from: start.map((n) => n.label),
343
+ related: hits.map(({ id, type, label, distance, status }) => ({ type, label, id, distance, ...(status ? { status } : {}) })),
344
+ });
345
+ }),
346
+ );
347
+
348
+ server.registerTool(
349
+ 'capture',
350
+ {
351
+ title: 'Capture to inbox',
352
+ description:
353
+ "Drop a quick thought into the user's inbox to sort out later (all devices see it). Prefer remember / add_project_note when you already know where it belongs.",
354
+ inputSchema: {
355
+ text: z.string().min(1),
356
+ project: z.string().optional().describe('Project it probably relates to'),
357
+ },
358
+ },
359
+ guard(async ({ text: t, project }) => {
360
+ const item = store.capture(t, { project });
361
+ changed();
362
+ return text(`Captured ${item.id}.`);
363
+ }),
364
+ );
365
+
366
+ server.registerTool(
367
+ 'list_inbox',
368
+ {
369
+ title: 'List inbox',
370
+ description: 'Quick captures (for example dictated on the Apple Watch app) waiting to be filed.',
371
+ inputSchema: {},
372
+ annotations: { readOnlyHint: true },
373
+ },
374
+ guard(async () => {
375
+ const items = store.listInbox();
376
+ return text(items.length ? items : 'Inbox is empty.');
377
+ }),
378
+ );
379
+
380
+ server.registerTool(
381
+ 'file_inbox',
382
+ {
383
+ title: 'File inbox item',
384
+ description:
385
+ 'Move an inbox item into memory: as a profile fact, as a note on a project, or dismiss it. You may pass cleaned-up `text` (dictations are often rough).',
386
+ inputSchema: {
387
+ id: z.string(),
388
+ as: z.enum(['fact', 'note', 'dismiss']),
389
+ project: z.string().optional().describe('Required when as=note, unless the item already names a project'),
390
+ text: z.string().optional().describe('Rewritten wording to store instead of the raw capture'),
391
+ },
392
+ },
393
+ guard(async ({ id, as, project, text: t }) => {
394
+ const target = project ? store.getProject(project) || resolveProjects(store.listProjects(), project, 1)[0]?.project : null;
395
+ const r = store.fileInbox(id, { as, project: target?.slug || project, text: t });
396
+ changed();
397
+ return text(as === 'dismiss' ? `Dismissed ${id}.` : `Filed ${id} as ${as}${as === 'note' ? ` on ${r.result}` : ''}.`);
398
+ }),
399
+ );
400
+
401
+ // Read-only resources, for clients that browse MCP resources.
402
+ server.registerResource(
403
+ 'profile',
404
+ 'omnicontext://profile',
405
+ { title: 'Profile', description: "The user's profile", mimeType: 'text/markdown' },
406
+ async (uri) => ({ contents: [{ uri: uri.href, mimeType: 'text/markdown', text: store.getProfile() }] }),
407
+ );
408
+ server.registerResource(
409
+ 'briefing',
410
+ 'omnicontext://context',
411
+ { title: 'Briefing', description: 'The full session briefing', mimeType: 'text/markdown' },
412
+ async (uri) => ({ contents: [{ uri: uri.href, mimeType: 'text/markdown', text: buildContext(store) }] }),
413
+ );
414
+ server.registerResource(
415
+ 'project',
416
+ new ResourceTemplate('omnicontext://projects/{slug}', {
417
+ list: async () => ({
418
+ resources: store.listProjects().map((p) => ({ uri: `omnicontext://projects/${p.slug}`, name: p.name, mimeType: 'application/json' })),
419
+ }),
420
+ }),
421
+ { title: 'Project', description: 'One project with notes', mimeType: 'application/json' },
422
+ async (uri, { slug }) => ({
423
+ contents: [{ uri: uri.href, mimeType: 'application/json', text: JSON.stringify(store.getProject(String(slug)), null, 2) }],
424
+ }),
425
+ );
426
+
285
427
  server.registerTool(
286
428
  'sync_now',
287
429
  {