remimem 0.1.0 → 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.
@@ -0,0 +1,207 @@
1
+ // The dashboard's JSON API. Every handler works on the same ToolContext as the MCP tools, so
2
+ // the page shows exactly what the agent sees, and changes take effect for the agent at once.
3
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
4
+ import { createRequire } from 'node:module';
5
+ import { join } from 'node:path';
6
+ import { runDoctor } from '../cli/commands.js';
7
+ import { CONFIG_DIR, parseConfig } from '../config/index.js';
8
+ import { createProvider } from '../embedder/index.js';
9
+ import { RemimemError } from '../errors.js';
10
+ import { indexRepo, pendingChanges } from '../indexer/index.js';
11
+ import { confirmMemory, forget, MEMORY_KINDS, MemoryError, remember, } from '../memory/index.js';
12
+ import { pack } from '../packer/index.js';
13
+ import { search } from '../retriever/index.js';
14
+ import { refreshIndex } from '../mcp/tools.js';
15
+ import { folderView } from './graph.js';
16
+ const pkg = createRequire(import.meta.url)('../../package.json');
17
+ export class NotFoundError extends RemimemError {
18
+ }
19
+ const object = (body) => typeof body === 'object' && body !== null && !Array.isArray(body)
20
+ ? body
21
+ : {};
22
+ const strings = (value) => Array.isArray(value)
23
+ ? value.filter((v) => typeof v === 'string' && v.trim() !== '')
24
+ : [];
25
+ function memoryInput(body) {
26
+ const b = object(body);
27
+ const kind = typeof b['kind'] === 'string' ? b['kind'] : 'decision';
28
+ if (!MEMORY_KINDS.includes(kind)) {
29
+ throw new MemoryError(`Unknown kind "${kind}". Use one of: ${MEMORY_KINDS.join(', ')}.`);
30
+ }
31
+ return {
32
+ text: typeof b['text'] === 'string' ? b['text'] : '',
33
+ kind: kind,
34
+ paths: strings(b['paths']),
35
+ symbols: strings(b['symbols']),
36
+ tags: strings(b['tags']),
37
+ };
38
+ }
39
+ /** Re-indexes now, after any refresh already running, and lets tool calls wait for it. */
40
+ async function reindex(ctx, full) {
41
+ if (ctx.refreshing)
42
+ await ctx.refreshing;
43
+ const run = indexRepo(ctx.root, ctx.store, ctx.config, { provider: ctx.provider, full });
44
+ ctx.refreshing = run.catch(() => undefined).finally(() => (ctx.refreshing = undefined));
45
+ return await run;
46
+ }
47
+ function configPath(root) {
48
+ return join(root, CONFIG_DIR, 'config.json');
49
+ }
50
+ function readRawConfig(root) {
51
+ try {
52
+ return JSON.parse(readFileSync(configPath(root), 'utf8'));
53
+ }
54
+ catch {
55
+ return {};
56
+ }
57
+ }
58
+ export async function handleApi(ctx, req) {
59
+ const { store } = ctx;
60
+ const route = `${req.method} ${req.path}`;
61
+ const memoryId = /^\/api\/memories\/([\w-]+)$/.exec(req.path)?.[1];
62
+ switch (route) {
63
+ case 'GET /api/overview': {
64
+ const counts = store.counts();
65
+ const files = store.fileSummaries();
66
+ const languages = new Map();
67
+ for (const f of files)
68
+ languages.set(f.language ?? 'text', (languages.get(f.language ?? 'text') ?? 0) + 1);
69
+ const memories = store.listMemories();
70
+ return {
71
+ root: ctx.root,
72
+ version: pkg.version,
73
+ counts: { ...counts, edges: store.edgeCount(), vectors: store.vectorCount() },
74
+ embeddingModel: store.embeddingModel() ?? null,
75
+ lastIndexedAt: store.getMeta('last_indexed_at') ?? null,
76
+ lastIndexedCommit: store.getMeta('last_indexed_commit') ?? null,
77
+ languages: [...languages]
78
+ .map(([language, count]) => ({ language, files: count }))
79
+ .sort((a, b) => b.files - a.files),
80
+ memories: { total: memories.length, stale: memories.filter((m) => m.stale).length },
81
+ pending: counts.files > 0 ? await pendingChanges(ctx.root, store, ctx.config) : null,
82
+ indexing: ctx.refreshing !== undefined,
83
+ };
84
+ }
85
+ case 'GET /api/graph':
86
+ return folderView(store.fileSummaries(), store.fileEdges(), req.query.get('dir') ?? '');
87
+ case 'GET /api/file': {
88
+ const path = req.query.get('path') ?? '';
89
+ const language = store.fileLanguage(path);
90
+ if (language === undefined)
91
+ throw new NotFoundError(`No file "${path}" in the index.`);
92
+ const symbols = store.symbolsInFile(path);
93
+ const neighbors = store.neighbors(symbols.map((s) => s.id));
94
+ return {
95
+ path,
96
+ language,
97
+ symbols: symbols.map((s) => ({
98
+ ...s,
99
+ // The parent and children are shown by nesting, so only cross-symbol edges are listed.
100
+ neighbors: neighbors
101
+ .filter((n) => n.of === s.id && n.relation !== 'inside' && n.relation !== 'contains')
102
+ .map((n) => ({
103
+ id: n.id,
104
+ path: n.path,
105
+ name: n.qualifiedName,
106
+ kind: n.kind,
107
+ line: n.startLine,
108
+ relation: n.relation,
109
+ confidence: n.confidence,
110
+ })),
111
+ })),
112
+ memories: store.listMemories().filter((m) => m.links.some((l) => l.path === path)),
113
+ };
114
+ }
115
+ case 'GET /api/symbol': {
116
+ const chunks = store.chunksOfSymbol(Number(req.query.get('id')));
117
+ if (chunks.length === 0)
118
+ throw new NotFoundError('No code for that symbol in the index.');
119
+ const first = chunks[0];
120
+ return {
121
+ path: first.path,
122
+ startLine: first.startLine,
123
+ code: chunks.map((c) => c.content).join('\n'),
124
+ };
125
+ }
126
+ case 'POST /api/search': {
127
+ const b = object(req.body);
128
+ const text = typeof b['query'] === 'string' ? b['query'].trim() : '';
129
+ if (!text)
130
+ throw new RemimemError('Type something to search for.');
131
+ const retrieval = ctx.config.retrieval;
132
+ const budget = Number.isFinite(b['budget'])
133
+ ? Number(b['budget'])
134
+ : retrieval.defaultBudgetTokens;
135
+ const k = Number.isFinite(b['k']) ? Number(b['k']) : retrieval.defaultK;
136
+ await refreshIndex(ctx);
137
+ const started = performance.now();
138
+ // Not logged: trying queries here should not count toward the savings in `remimem stats`.
139
+ const results = await search(store, text, retrieval, ctx.provider, k);
140
+ const packed = pack(results, budget, '', retrieval.neighborBudgetShare);
141
+ const shown = new Set(packed.included.map((item) => item.chunk.id));
142
+ return {
143
+ ms: Math.round(performance.now() - started),
144
+ tokens: packed.tokens,
145
+ budget,
146
+ text: packed.text,
147
+ results: results.map((r) => ({
148
+ path: r.chunk.path,
149
+ startLine: r.chunk.startLine,
150
+ endLine: r.chunk.endLine,
151
+ symbol: r.chunk.symbol,
152
+ kind: r.chunk.kind,
153
+ score: r.score,
154
+ reasons: r.reasons,
155
+ ranks: r.ranks,
156
+ detail: r.detail,
157
+ tokens: r.chunk.tokenCount,
158
+ included: shown.has(r.chunk.id),
159
+ })),
160
+ };
161
+ }
162
+ case 'POST /api/memories/confirm': {
163
+ const id = object(req.body)['id'];
164
+ if (typeof id !== 'string')
165
+ throw new MemoryError('Which memory? Send its id.');
166
+ return confirmMemory(ctx.root, store, id);
167
+ }
168
+ case 'GET /api/memories':
169
+ return { kinds: MEMORY_KINDS, memories: store.listMemories() };
170
+ case 'POST /api/memories':
171
+ return remember(ctx.root, store, memoryInput(req.body));
172
+ case 'GET /api/activity': {
173
+ // Polled by the page: the calls after the last one it has, at most 100 at a time.
174
+ const after = Number(req.query.get('after') ?? 0);
175
+ return { calls: store.queryLogAfter(Number.isFinite(after) ? after : 0, 100) };
176
+ }
177
+ case 'GET /api/stats':
178
+ return { byTool: store.queryLogSummary(), daily: store.queryLogDaily() };
179
+ case 'GET /api/doctor':
180
+ return await runDoctor(ctx.root);
181
+ case 'POST /api/index':
182
+ return { stats: await reindex(ctx, object(req.body)['full'] === true) };
183
+ case 'GET /api/config':
184
+ return { raw: readRawConfig(ctx.root), effective: ctx.config };
185
+ case 'PUT /api/config': {
186
+ const raw = object(req.body)['config'];
187
+ // Throws a ConfigError with the schema's message when the edit is not valid.
188
+ const config = parseConfig(raw);
189
+ mkdirSync(join(ctx.root, CONFIG_DIR), { recursive: true });
190
+ writeFileSync(configPath(ctx.root), `${JSON.stringify(raw, null, 2)}\n`);
191
+ const embeddingChanged = JSON.stringify(config.embedding) !== JSON.stringify(ctx.config.embedding);
192
+ ctx.config = config;
193
+ if (embeddingChanged)
194
+ ctx.provider = createProvider(config.embedding);
195
+ return { effective: config, needsFullIndex: embeddingChanged };
196
+ }
197
+ }
198
+ if (memoryId !== undefined && req.method === 'PUT') {
199
+ return remember(ctx.root, store, { ...memoryInput(req.body), id: memoryId });
200
+ }
201
+ if (memoryId !== undefined && req.method === 'DELETE') {
202
+ if (!forget(ctx.root, store, memoryId))
203
+ throw new NotFoundError(`No memory with id ${memoryId}.`);
204
+ return { deleted: memoryId };
205
+ }
206
+ throw new NotFoundError(`No such API route: ${route}`);
207
+ }
@@ -0,0 +1,58 @@
1
+ // The dashboard's code graph, one folder at a time: each child folder or file of the current
2
+ // folder is a node, and resolved symbol edges between files are summed onto those nodes.
3
+ /** The graph of the children of `dir` ('' is the project root). */
4
+ export function folderView(files, fileEdges, dir) {
5
+ const prefix = dir === '' ? '' : `${dir.replace(/\/+$/, '')}/`;
6
+ // The child of `dir` a file belongs to, or undefined when it is outside `dir`.
7
+ const childOf = (path) => {
8
+ if (!path.startsWith(prefix))
9
+ return undefined;
10
+ const rest = path.slice(prefix.length);
11
+ const slash = rest.indexOf('/');
12
+ return slash === -1 ? path : prefix + rest.slice(0, slash);
13
+ };
14
+ const nodes = new Map();
15
+ for (const file of files) {
16
+ const id = childOf(file.path);
17
+ if (id === undefined)
18
+ continue;
19
+ const node = nodes.get(id) ?? {
20
+ id,
21
+ label: id.slice(prefix.length),
22
+ type: id === file.path ? 'file' : 'folder',
23
+ files: 0,
24
+ symbols: 0,
25
+ language: null,
26
+ languages: new Map(),
27
+ };
28
+ node.files += 1;
29
+ node.symbols += file.symbols;
30
+ if (file.language)
31
+ node.languages.set(file.language, (node.languages.get(file.language) ?? 0) + 1);
32
+ nodes.set(id, node);
33
+ }
34
+ const edges = new Map();
35
+ for (const edge of fileEdges) {
36
+ const source = childOf(edge.src);
37
+ const target = childOf(edge.dst);
38
+ if (source === undefined || target === undefined || source === target)
39
+ continue;
40
+ const key = `${source}\n${target}`;
41
+ const existing = edges.get(key);
42
+ if (existing)
43
+ existing.weight += edge.weight;
44
+ else
45
+ edges.set(key, { source, target, weight: edge.weight });
46
+ }
47
+ return {
48
+ dir: prefix.replace(/\/$/, ''),
49
+ nodes: [...nodes.values()]
50
+ .map(({ languages, ...node }) => ({
51
+ ...node,
52
+ language: [...languages].sort((a, b) => b[1] - a[1])[0]?.[0] ?? null,
53
+ }))
54
+ // Folders first, then files, each by name.
55
+ .sort((a, b) => a.type === b.type ? a.id.localeCompare(b.id) : a.type === 'folder' ? -1 : 1),
56
+ edges: [...edges.values()],
57
+ };
58
+ }
@@ -0,0 +1,179 @@
1
+ // The local dashboard: a small HTTP server on 127.0.0.1 that serves the page and its JSON API.
2
+ // The page can change memories, the index, and the config, so every request is checked:
3
+ // the Host header must name this server (against DNS rebinding), every API call must carry the
4
+ // token from the printed URL, and changes must be JSON from this origin (against cross-site
5
+ // forms). Nothing here writes to stdout: under `remimem serve` it belongs to the MCP protocol.
6
+ import { createHash, randomBytes, timingSafeEqual } from 'node:crypto';
7
+ import { readFileSync, rmSync, writeFileSync } from 'node:fs';
8
+ import { createServer } from 'node:http';
9
+ import { tmpdir } from 'node:os';
10
+ import { dirname, join } from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { RemimemError } from '../errors.js';
13
+ import { log } from '../log.js';
14
+ import { handleApi, NotFoundError } from './api.js';
15
+ /** Where the built page lives: next to this file, in `ui/`. */
16
+ const UI_DIR = join(dirname(fileURLToPath(import.meta.url)), 'ui');
17
+ const STATIC = {
18
+ '/': ['index.html', 'text/html; charset=utf-8'],
19
+ '/app.js': ['app.js', 'text/javascript; charset=utf-8'],
20
+ '/app.css': ['app.css', 'text/css; charset=utf-8'],
21
+ };
22
+ const MAX_BODY_BYTES = 1_048_576;
23
+ /** The file that tells `remimem dashboard` where a running server for `root` is. */
24
+ export function discoveryFile(root) {
25
+ const id = createHash('sha256').update(root).digest('hex').slice(0, 16);
26
+ return join(tmpdir(), `remimem-dashboard-${id}.json`);
27
+ }
28
+ /** The running dashboard for `root`, if its server process is still alive. */
29
+ export function findDashboard(root) {
30
+ try {
31
+ const found = JSON.parse(readFileSync(discoveryFile(root), 'utf8'));
32
+ process.kill(found.pid, 0); // throws when the process is gone
33
+ return found;
34
+ }
35
+ catch {
36
+ return undefined;
37
+ }
38
+ }
39
+ function sameToken(given, token) {
40
+ if (given === undefined || given.length !== token.length)
41
+ return false;
42
+ return timingSafeEqual(Buffer.from(given), Buffer.from(token));
43
+ }
44
+ function send(res, status, body, type) {
45
+ res.writeHead(status, {
46
+ 'content-type': type,
47
+ 'cache-control': 'no-store',
48
+ // The token is in the page's URL: never leak it in a Referer, never allow framing.
49
+ 'referrer-policy': 'no-referrer',
50
+ 'x-frame-options': 'DENY',
51
+ 'x-content-type-options': 'nosniff',
52
+ 'content-security-policy': "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; frame-ancestors 'none'",
53
+ });
54
+ res.end(body);
55
+ }
56
+ const json = (res, status, value) => send(res, status, JSON.stringify(value), 'application/json; charset=utf-8');
57
+ async function readBody(req) {
58
+ let size = 0;
59
+ const parts = [];
60
+ for await (const part of req) {
61
+ size += part.length;
62
+ if (size > MAX_BODY_BYTES)
63
+ throw new RemimemError('Request body too large.');
64
+ parts.push(part);
65
+ }
66
+ const text = Buffer.concat(parts).toString('utf8');
67
+ if (!text)
68
+ return undefined;
69
+ try {
70
+ return JSON.parse(text);
71
+ }
72
+ catch {
73
+ throw new RemimemError('Request body is not valid JSON.');
74
+ }
75
+ }
76
+ /**
77
+ * Starts the dashboard for an open project. `port` 0 picks a free port. The URL is written to
78
+ * the discovery file, which is removed again by `close`.
79
+ */
80
+ export async function startDashboard(ctx, port = 0) {
81
+ const token = randomBytes(24).toString('base64url');
82
+ let origins = new Set();
83
+ let hosts = new Set();
84
+ const server = createServer((req, res) => {
85
+ void (async () => {
86
+ const host = req.headers.host ?? '';
87
+ if (!hosts.has(host))
88
+ return send(res, 421, 'Unknown host', 'text/plain');
89
+ const url = new URL(req.url ?? '/', `http://${host}`);
90
+ const method = req.method ?? 'GET';
91
+ if (!url.pathname.startsWith('/api/')) {
92
+ // The bundled fonts: a bare file name only, so nothing outside UI_DIR can be reached.
93
+ const font = /^\/([\w-]+\.woff2)$/.exec(url.pathname)?.[1];
94
+ if (method === 'GET' && font) {
95
+ try {
96
+ res.writeHead(200, {
97
+ 'content-type': 'font/woff2',
98
+ 'cache-control': 'public, max-age=31536000, immutable',
99
+ 'x-content-type-options': 'nosniff',
100
+ });
101
+ return res.end(readFileSync(join(UI_DIR, font)));
102
+ }
103
+ catch {
104
+ return send(res, 404, 'Not found', 'text/plain');
105
+ }
106
+ }
107
+ const asset = method === 'GET' ? STATIC[url.pathname] : undefined;
108
+ if (!asset)
109
+ return send(res, 404, 'Not found', 'text/plain');
110
+ try {
111
+ return send(res, 200, readFileSync(join(UI_DIR, asset[0]), 'utf8'), asset[1]);
112
+ }
113
+ catch {
114
+ return send(res, 500, 'The dashboard page is missing. Run `npm run build`.', 'text/plain');
115
+ }
116
+ }
117
+ const given = req.headers['x-remimem-token'];
118
+ if (!sameToken(typeof given === 'string' ? given : undefined, token)) {
119
+ return json(res, 401, {
120
+ error: 'Missing or wrong token. Open the URL that remimem printed.',
121
+ });
122
+ }
123
+ if (method !== 'GET') {
124
+ const origin = req.headers.origin;
125
+ const type = req.headers['content-type'] ?? '';
126
+ if ((origin !== undefined && !origins.has(origin)) ||
127
+ !type.startsWith('application/json')) {
128
+ return json(res, 403, {
129
+ error: 'Changes must be JSON requests from the dashboard page.',
130
+ });
131
+ }
132
+ }
133
+ try {
134
+ const body = method === 'GET' ? undefined : await readBody(req);
135
+ json(res, 200, await handleApi(ctx, { method, path: url.pathname, query: url.searchParams, body }));
136
+ }
137
+ catch (error) {
138
+ if (error instanceof RemimemError) {
139
+ return json(res, error instanceof NotFoundError ? 404 : 400, { error: error.message });
140
+ }
141
+ log.error(`dashboard: ${method} ${url.pathname} failed: ${String(error)}`);
142
+ json(res, 500, { error: 'Internal error; see the remimem log.' });
143
+ }
144
+ })();
145
+ });
146
+ await new Promise((resolve, reject) => {
147
+ server.once('error', reject);
148
+ server.listen(port, '127.0.0.1', () => resolve());
149
+ });
150
+ const actual = server.address().port;
151
+ hosts = new Set([`127.0.0.1:${actual}`, `localhost:${actual}`]);
152
+ origins = new Set([...hosts].map((h) => `http://${h}`));
153
+ const url = `http://127.0.0.1:${actual}/?token=${token}`;
154
+ const file = discoveryFile(ctx.root);
155
+ try {
156
+ writeFileSync(file, JSON.stringify({ url, pid: process.pid }), { mode: 0o600 });
157
+ }
158
+ catch (error) {
159
+ log.warn(`could not write ${file}: ${String(error)}`);
160
+ }
161
+ log.info(`dashboard at ${url}`);
162
+ // Only remove the discovery file if it still points at this server.
163
+ const cleanup = () => {
164
+ if (findDashboard(ctx.root)?.url === url)
165
+ rmSync(file, { force: true });
166
+ };
167
+ process.once('exit', cleanup);
168
+ return {
169
+ url,
170
+ port: actual,
171
+ unref: () => server.unref(),
172
+ close: async () => {
173
+ process.off('exit', cleanup);
174
+ cleanup();
175
+ server.closeAllConnections();
176
+ await new Promise((resolve) => server.close(() => resolve()));
177
+ },
178
+ };
179
+ }
@@ -0,0 +1 @@
1
+ @font-face{font-family:Geist Pixel;src:url("./geist-pixel-latin-400-normal-ODEFW7VT.woff2") format("woff2");font-weight:400;font-display:swap}@font-face{font-family:Inter;src:url("./inter-latin-400-normal-55WT6UWF.woff2") format("woff2");font-weight:400;font-display:swap}@font-face{font-family:Inter;src:url("./inter-latin-500-normal-W62DVTXI.woff2") format("woff2");font-weight:500;font-display:swap}@font-face{font-family:Inter;src:url("./inter-latin-600-normal-R6Y2SZCR.woff2") format("woff2");font-weight:600;font-display:swap}@font-face{font-family:JetBrains Mono;src:url("./jetbrains-mono-latin-400-normal-3OOWLGQ2.woff2") format("woff2");font-weight:400;font-display:swap}@font-face{font-family:JetBrains Mono;src:url("./jetbrains-mono-latin-500-normal-V4XIP5OW.woff2") format("woff2");font-weight:500;font-display:swap}:root{--brand: #1f2bff;--bg: #05061a;--fg: #eef0ff;--card: #0a0c24;--muted: #12153a;--muted-fg: #9aa0c8;--border: #1c2050;--primary: #7581ff;--primary-fg: #05061a;--danger: #ff7a8a;--ok: #7ee0a8;--warn: #f6c177;--display: "Geist Pixel", ui-monospace, monospace;--sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;--mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;--ease-out: cubic-bezier(.23, 1, .32, 1);color-scheme:dark}*{box-sizing:border-box}html,body{margin:0;height:100%}body{background:var(--bg);color:var(--fg);font:14px/1.5 var(--sans)}a{color:inherit}button,input,select,textarea{font:inherit;color:inherit}.shell{display:grid;grid-template-columns:220px minmax(0,1fr);min-height:100%}.side{position:sticky;top:0;height:100vh;display:flex;flex-direction:column;gap:4px;padding:20px 14px;border-right:1px solid rgb(255 255 255 / .2);background:radial-gradient(circle,rgb(255 255 255 / .18) 1px,transparent 1.6px) 0 0 / 7px 7px,linear-gradient(180deg,#2c38ff,#141fd8);color:#fff}.brand{display:flex;align-items:center;gap:10px;font:400 22px var(--display);letter-spacing:-.02em}.mark{display:grid;place-items:center;width:26px;height:26px;background:#fff;color:var(--brand);font:15px var(--sans)}.root{margin:6px 0 14px;font:12px var(--mono);color:#ffffffb3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;direction:rtl;text-align:left}.tabs{display:flex;flex-direction:column;gap:2px}.tabs a{padding:8px 10px;text-decoration:none;color:#fffc;transition:background-color .15s ease}.tabs a:hover{background:#ffffff1f;color:#fff}.tabs a[aria-current=page]{background:#fff;color:var(--brand);font-weight:500}.version{margin-top:auto;font:12px var(--mono);color:#ffffffb3}main{padding:28px 32px 64px;outline:none;min-width:0}h1{margin:0 0 4px;font:400 34px/1.05 var(--display);letter-spacing:-.02em}h2{margin:30px 0 10px;font:400 22px var(--display);letter-spacing:-.01em}.lede{margin:0 0 20px;color:var(--muted-fg)}.grid{display:grid;gap:12px;grid-template-columns:repeat(auto-fill,minmax(160px,1fr))}.card{border:1px solid var(--border);border-radius:0;background:var(--card);padding:14px 16px;min-width:0}.stat .value{font:400 30px var(--display);color:var(--primary);font-variant-numeric:tabular-nums}.stat .label{color:var(--muted-fg);font-size:12px}.row{display:flex;flex-wrap:wrap;align-items:center;gap:8px}.spacer{flex:1}.btn{display:inline-flex;align-items:center;gap:6px;padding:8px 14px;border:1px solid var(--border);background:var(--card);font:12.5px var(--mono);cursor:pointer;transition:transform .16s var(--ease-out),border-color .15s ease;-webkit-tap-highlight-color:transparent}.btn:active{transform:scale(.97)}.btn:hover{border-color:var(--primary)}.btn.primary{background:#fff;border-color:#fff;color:#0b0c1e}.btn.danger{color:var(--danger)}.btn:disabled{opacity:.55;cursor:progress}input[type=text],input[type=search],input[type=number],select,textarea{padding:7px 10px;border:1px solid var(--border);border-radius:0;background:var(--bg);min-width:0}input:focus-visible,select:focus-visible,textarea:focus-visible,.btn:focus-visible,.tabs a:focus-visible{outline:2px solid var(--primary);outline-offset:1px}textarea{width:100%;font:13px/1.5 var(--mono)}.mono{font-family:var(--mono);font-size:12.5px}.muted{color:var(--muted-fg)}.chip{display:inline-block;padding:1px 8px;border:1px solid var(--border);border-radius:999px;font-size:11.5px;color:var(--muted-fg);white-space:nowrap}.chip.exact,.chip.ok{color:var(--ok);border-color:color-mix(in oklab,var(--ok) 40%,transparent)}.chip.import{color:var(--primary);border-color:color-mix(in oklab,var(--primary) 40%,transparent)}.chip.name-match,.chip.stale,.chip.bad{color:var(--danger);border-color:color-mix(in oklab,var(--danger) 40%,transparent)}.bar{height:8px;border-radius:999px;background:var(--muted);overflow:hidden}.bar>span{display:block;height:100%;background:var(--primary)}table{width:100%;border-collapse:collapse}th,td{padding:7px 8px;border-bottom:1px solid var(--border);text-align:left;vertical-align:top}th{font-weight:500;color:var(--muted-fg);font-size:12px}.table-wrap{overflow-x:auto}pre.code{margin:0;padding:12px 14px;border:1px solid var(--border);border-radius:0;background:var(--card);overflow:auto;max-height:460px;font:12.5px/1.5 var(--mono)}.chart{width:100%;height:160px;display:block}.graph-layout{display:grid;grid-template-columns:minmax(0,1fr) 360px;gap:14px}.crumbs{display:flex;flex-wrap:wrap;gap:4px;align-items:center;margin-bottom:10px;font:13px var(--mono)}.crumbs button{border:0;background:none;padding:2px 4px;color:var(--primary);cursor:pointer}#cy{height:min(68vh,640px);border:1px solid var(--border);border-radius:0;background:var(--card)}.panel{max-height:min(68vh,640px);overflow:auto}.symbol{padding:6px 0;border-bottom:1px solid var(--border)}.symbol>button{border:0;background:none;padding:0;cursor:pointer;text-align:left}.neighbors{margin:4px 0 0;padding:0;list-style:none;font-size:12.5px}.neighbors li{display:flex;gap:6px;align-items:baseline;padding:1px 0}.neighbors button{border:0;background:none;padding:0;color:var(--primary);cursor:pointer;font:12px var(--mono);text-align:left;overflow-wrap:anywhere}.legend{display:flex;flex-wrap:wrap;gap:10px;margin-top:8px;font-size:12px;color:var(--muted-fg)}.legend i{display:inline-block;width:10px;height:10px;border-radius:999px;margin-right:4px;vertical-align:-1px}.calls{display:grid;padding:4px 16px}.call{display:grid;grid-template-columns:max-content 130px minmax(0,1fr) auto;gap:12px;align-items:center;padding:9px 0;border-bottom:1px solid var(--border)}.call:last-child{border-bottom:0}.call-tool{justify-self:start;font-family:var(--mono)}.call-query{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.call-stats{font-variant-numeric:tabular-nums;white-space:nowrap}.call-saved{color:var(--ok)}.call.fresh{animation:call-in .26s var(--ease-out),call-glow 2.4s ease-out}@keyframes call-in{0%{opacity:0;transform:translateY(-6px)}}@keyframes call-glow{0%{background:color-mix(in oklab,var(--primary) 18%,transparent)}}.live{display:inline-flex;align-items:center;gap:6px;font:12px var(--mono);color:var(--ok)}.live i{width:8px;height:8px;background:currentColor;animation:pulse 1.6s ease-in-out infinite}.live.off{color:var(--danger)}.live.off i{animation:none}@keyframes pulse{50%{opacity:.25}}.memory{display:grid;gap:8px}.memory p{margin:0;white-space:pre-wrap;overflow-wrap:anywhere}.form{display:grid;gap:10px}.form label{display:grid;gap:4px;font-size:12.5px;color:var(--muted-fg)}.error{color:var(--danger);white-space:pre-wrap}.toast{position:fixed;right:16px;bottom:16px;max-width:min(420px,calc(100vw - 32px));padding:10px 14px;border:1px solid var(--border);border-radius:0;background:var(--fg);color:var(--bg);opacity:0;transform:translateY(8px);transition:opacity .2s,transform .2s;pointer-events:none}.toast.show{opacity:1;transform:none}@media(max-width:860px){.shell{grid-template-columns:minmax(0,1fr)}.side{position:sticky;z-index:5;height:auto;flex-direction:row;align-items:center;gap:12px;padding:10px 14px;border-right:0;border-bottom:1px solid var(--border)}.root,.version,.brand .name{display:none}.tabs{flex-direction:row;overflow-x:auto;scrollbar-width:none}.tabs a{white-space:nowrap}main{padding:20px 16px 48px}h1{font-size:25px}.graph-layout{grid-template-columns:minmax(0,1fr)}.call{grid-template-columns:auto minmax(0,1fr);row-gap:4px}.call-query,.call-stats{grid-column:1 / -1}#cy{height:56vh}.panel{max-height:none}}@media(prefers-reduced-motion:reduce){.toast,.btn{transition:none}.call.fresh{animation:call-glow 2.4s ease-out}.live i{animation:none}.btn:active{transform:none}}