tr-plugin-embeddings 0.0.0-stage → 0.2.5

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,25 @@
1
+ ---
2
+ name: embeddings
3
+ description: "Local embedding model management: provider/model status, benchmark, index build and coverage"
4
+ version: 0.2.5
5
+ repo_scoped: false
6
+ ---
7
+
8
+ # Embeddings
9
+
10
+ Local embedding model management: provider/model status, benchmark, index build and coverage
11
+
12
+ ## When to Use
13
+
14
+ Use the `embeddings` Total Recall plugin (`total-recall embeddings`) instead of ad-hoc scripts or raw commands whenever working on embeddings tasks.
15
+
16
+ ## Commands
17
+
18
+ ```bash
19
+ total-recall embeddings --help
20
+ total-recall embeddings status # Provider, model, locality and vault coverage in one view
21
+ total-recall embeddings models # List models on the endpoint and which can produce embeddings
22
+ total-recall embeddings pull # Pull an explicitly named local model onto the configured loopback endpoint
23
+ total-recall embeddings benchmark # Measure latency per verified local embedding and project full-vault time
24
+ total-recall embeddings coverage # How many vault nodes have a current, correct-width vector, and why the rest do not
25
+ ```
@@ -0,0 +1,49 @@
1
+ ---
2
+ type: ui-chunk:chunk
3
+ plugin: embeddings
4
+ id: benchmark
5
+ title: Embedding benchmark
6
+ description: Measures milliseconds per embedding for the selected local model using a neutral sentence, verifies each vector is 768 wide, and projects the time to embed the whole vault.
7
+ timestamp: '2026-11-08T08:12:00Z'
8
+ intents:
9
+ - benchmark embedding speed
10
+ - estimate time to embed the vault
11
+ surfaces:
12
+ - page
13
+ operations:
14
+ - benchmark
15
+ data:
16
+ - benchmark:/ok
17
+ - benchmark:/reason
18
+ - benchmark:/url
19
+ - benchmark:/locality
20
+ - benchmark:/model
21
+ - benchmark:/dims
22
+ - benchmark:/samples
23
+ - benchmark:/ms_per_embedding
24
+ - benchmark:/min_ms
25
+ - benchmark:/max_ms
26
+ - benchmark:/vault_nodes
27
+ - benchmark:/projected_minutes
28
+ - benchmark:/completed
29
+ panel: home
30
+ ---
31
+ <style>
32
+ .emb-benchmark { color: var(--colors-text, #ecfeff); background: var(--colors-surface, #0e2a35); border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-md, 6px); padding: var(--spacing-md, 12px); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 13px; }
33
+ .emb-benchmark h3 { margin: 0 0 var(--spacing-sm, 8px); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--colors-muted, #67e8f9); }
34
+ .emb-benchmark dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--spacing-xs, 4px) var(--spacing-md, 12px); margin: 0; }
35
+ .emb-benchmark dt { color: var(--colors-muted, #67e8f9); }
36
+ .emb-benchmark dd { margin: 0; }
37
+ .emb-benchmark code { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; }
38
+ .emb-benchmark p { margin: var(--spacing-sm, 8px) 0 0; color: var(--colors-muted, #67e8f9); }
39
+ </style>
40
+ <section class="emb-benchmark" data-design-component="section">
41
+ <h3>Embedding benchmark</h3>
42
+ <dl>
43
+ <dt>Reports</dt><dd>Average, minimum and maximum milliseconds per embedding, the sample count, and the model and endpoint measured.</dd>
44
+ <dt>Projection</dt><dd>Average time multiplied by the vault node count, in minutes.</dd>
45
+ <dt>Bounds</dt><dd>1 to 20 samples (default 10), within a 280-second deadline.</dd>
46
+ <dt>Refuses</dt><dd>A remote, upstream or missing model. No vault text is sent.</dd>
47
+ </dl>
48
+ <p>Run it from the Embeddings page. It never runs on its own.</p>
49
+ </section>
@@ -0,0 +1,53 @@
1
+ ---
2
+ type: ui-chunk:chunk
3
+ plugin: embeddings
4
+ id: coverage
5
+ title: Vault vector coverage
6
+ description: How many vault nodes have a current, correct-width vector in the index, and why the rest are not usable. Reads the index without modifying it.
7
+ timestamp: '2026-11-08T08:12:00Z'
8
+ intents:
9
+ - check vault vector coverage
10
+ - find stale or missing embeddings
11
+ surfaces:
12
+ - page
13
+ operations:
14
+ - coverage
15
+ data:
16
+ - coverage:/ok
17
+ - coverage:/brain
18
+ - coverage:/state
19
+ - coverage:/reason
20
+ - coverage:/vault_nodes
21
+ - coverage:/parse_errors
22
+ - coverage:/rows
23
+ - coverage:/embedded
24
+ - coverage:/stale
25
+ - coverage:/mismatched
26
+ - coverage:/orphaned
27
+ - coverage:/missing
28
+ - coverage:/percent
29
+ - coverage:/model
30
+ - coverage:/models
31
+ - coverage:/db_bytes
32
+ panel: home
33
+ ---
34
+ <style>
35
+ .emb-coverage { color: var(--colors-text, #ecfeff); background: var(--colors-surface, #0e2a35); border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-md, 6px); padding: var(--spacing-md, 12px); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 13px; }
36
+ .emb-coverage h3 { margin: 0 0 var(--spacing-sm, 8px); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--colors-muted, #67e8f9); }
37
+ .emb-coverage ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--spacing-xs, 4px); }
38
+ .emb-coverage li { display: flex; justify-content: space-between; gap: var(--spacing-md, 12px); font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; color: var(--colors-muted, #67e8f9); }
39
+ .emb-coverage li span:first-child { color: var(--colors-text, #ecfeff); }
40
+ .emb-coverage code { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; }
41
+ .emb-coverage p { margin: var(--spacing-sm, 8px) 0 0; color: var(--colors-muted, #67e8f9); }
42
+ </style>
43
+ <section class="emb-coverage" data-design-component="section">
44
+ <h3>Vault vector coverage</h3>
45
+ <ul>
46
+ <li data-design-component="count-row"><span>usable</span><span>current text hash, 768 finite numbers</span></li>
47
+ <li data-design-component="count-row"><span>stale</span><span>the node changed after it was embedded</span></li>
48
+ <li data-design-component="count-row"><span>wrong width</span><span>the vector is not 768 numbers</span></li>
49
+ <li data-design-component="count-row"><span>missing</span><span>the node has no row</span></li>
50
+ <li data-design-component="count-row"><span>orphaned</span><span>the row has no active node</span></li>
51
+ </ul>
52
+ <p>The percentage counts usable vectors out of all <code>memory</code> and <code>plugin_record</code> nodes. A missing or unreadable index is reported by its state, not as 0%. Rebuild with <code>total-recall compile</code>.</p>
53
+ </section>
@@ -0,0 +1,43 @@
1
+ ---
2
+ type: ui-chunk:chunk
3
+ plugin: embeddings
4
+ id: models
5
+ title: Embedding models
6
+ description: Every model on the resolved Ollama endpoint, with its declared embedding capability, vector width, vault compatibility, upstream flag and which one is selected.
7
+ timestamp: '2026-11-08T08:12:00Z'
8
+ intents:
9
+ - list embedding models
10
+ - see which model can embed the vault
11
+ surfaces:
12
+ - page
13
+ operations:
14
+ - models
15
+ data:
16
+ - models:/url
17
+ - models:/reachable
18
+ - models:/locality
19
+ - models:/vault_dims
20
+ - models:/selected
21
+ - models:/models
22
+ - models:/attempts
23
+ panel: home
24
+ ---
25
+ <style>
26
+ .emb-models { color: var(--colors-text, #ecfeff); background: var(--colors-surface, #0e2a35); border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-md, 6px); padding: var(--spacing-md, 12px); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 13px; }
27
+ .emb-models h3 { margin: 0 0 var(--spacing-sm, 8px); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--colors-muted, #67e8f9); }
28
+ .emb-models ul { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--spacing-xs, 4px); }
29
+ .emb-models li { background: var(--colors-background, #07171d); border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-sm, 4px); padding: var(--spacing-sm, 8px); }
30
+ .emb-models code { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; }
31
+ .emb-models .ok { color: var(--colors-ok, #10b981); }
32
+ .emb-models .warn { color: var(--colors-warn, #f59e0b); }
33
+ .emb-models p { margin: var(--spacing-sm, 8px) 0 0; color: var(--colors-muted, #67e8f9); }
34
+ </style>
35
+ <section class="emb-models" data-design-component="section">
36
+ <h3>Embedding models</h3>
37
+ <ul>
38
+ <li data-design-component="model-row"><span class="ok">vault-compatible</span>: the model declares the <code>embedding</code> capability, and its family width is 768.</li>
39
+ <li data-design-component="model-row"><span class="ok">selected</span>: the pinned <code>TR_OLLAMA_EMBED_MODEL</code> when compatible, otherwise the smallest compatible model.</li>
40
+ <li data-design-component="model-row"><span class="warn">upstream</span>: the service relays the model from another machine, so it does not count as local.</li>
41
+ </ul>
42
+ <p>When no endpoint answers, the endpoints tried are reported instead of a model list. The Embeddings page shows the live roster.</p>
43
+ </section>
@@ -0,0 +1,41 @@
1
+ ---
2
+ type: ui-chunk:chunk
3
+ plugin: embeddings
4
+ id: pull
5
+ title: Pull an embedding model
6
+ description: Downloads an explicitly named local model onto the configured loopback Ollama endpoint. Refuses non-loopback endpoints and cloud or upstream models.
7
+ timestamp: '2026-11-08T08:12:00Z'
8
+ intents:
9
+ - install a local embedding model
10
+ - pull an embedding model
11
+ surfaces:
12
+ - page
13
+ operations:
14
+ - pull
15
+ data:
16
+ - pull:/ok
17
+ - pull:/model
18
+ - pull:/url
19
+ - pull:/locality
20
+ - pull:/reason
21
+ - pull:/status
22
+ panel: home
23
+ ---
24
+ <style>
25
+ .emb-pull { color: var(--colors-text, #ecfeff); background: var(--colors-surface, #0e2a35); border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-md, 6px); padding: var(--spacing-md, 12px); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 13px; }
26
+ .emb-pull h3 { margin: 0 0 var(--spacing-sm, 8px); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--colors-muted, #67e8f9); }
27
+ .emb-pull ol { margin: 0; padding-left: 1.25em; display: grid; gap: var(--spacing-xs, 4px); }
28
+ .emb-pull code { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; }
29
+ .emb-pull .warn { color: var(--colors-warn, #f59e0b); }
30
+ .emb-pull p { margin: var(--spacing-sm, 8px) 0 0; color: var(--colors-muted, #67e8f9); }
31
+ </style>
32
+ <section class="emb-pull" data-design-component="section">
33
+ <h3>Pull an embedding model</h3>
34
+ <ol>
35
+ <li>Name the model exactly. Nothing is pulled by default.</li>
36
+ <li>The target is <code>TR_OLLAMA_URL</code>, <code>OLLAMA_HOST</code> or <code>127.0.0.1:11434</code>, and it must be loopback.</li>
37
+ <li><span class="warn">Refused:</span> models that are cloud-hosted or relayed from another machine.</li>
38
+ <li>The download may take up to ten minutes. The result names the model and endpoint, or the reason for failure.</li>
39
+ </ol>
40
+ <p>This changes the endpoint's model store. Start it from the Embeddings page.</p>
41
+ </section>
@@ -0,0 +1,59 @@
1
+ ---
2
+ type: ui-chunk:chunk
3
+ plugin: embeddings
4
+ id: status
5
+ title: Embedding provider status
6
+ description: Which provider and model serve vectors for this brain, whether text sent for embedding stays on this machine, and how much of the vault has a usable vector.
7
+ timestamp: '2026-11-08T08:12:00Z'
8
+ intents:
9
+ - check which embedding model is active
10
+ - check whether embeddings run locally
11
+ - check vault vector coverage
12
+ surfaces:
13
+ - page
14
+ operations:
15
+ - status
16
+ data:
17
+ - status:/provider
18
+ - status:/endpoint
19
+ - status:/locality
20
+ - status:/local
21
+ - status:/selected_model
22
+ - status:/embedding_dims
23
+ - status:/hosted_fallback
24
+ - status:/reason
25
+ - status:/attempts
26
+ - status:/brain/state
27
+ - status:/brain/reason
28
+ - status:/brain/vault_nodes
29
+ - status:/brain/embedded
30
+ - status:/brain/percent
31
+ - status:/brain/stale
32
+ - status:/brain/mismatched
33
+ - status:/brain/missing
34
+ - status:/brain/orphaned
35
+ - status:/brain/model
36
+ panel: home
37
+ ---
38
+ <style>
39
+ .emb-status { color: var(--colors-text, #ecfeff); background: var(--colors-surface, #0e2a35); border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-md, 6px); padding: var(--spacing-md, 12px); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 13px; }
40
+ .emb-status h3 { margin: 0 0 var(--spacing-sm, 8px); font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--colors-muted, #67e8f9); }
41
+ .emb-status dl { display: grid; grid-template-columns: max-content 1fr; gap: var(--spacing-xs, 4px) var(--spacing-md, 12px); margin: 0; }
42
+ .emb-status dt { color: var(--colors-muted, #67e8f9); }
43
+ .emb-status dd { margin: 0; }
44
+ .emb-status code { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 12px; }
45
+ .emb-status .local { color: var(--colors-ok, #10b981); }
46
+ .emb-status .away { color: var(--colors-warn, #f59e0b); }
47
+ .emb-status p { margin: var(--spacing-sm, 8px) 0 0; color: var(--colors-muted, #67e8f9); }
48
+ </style>
49
+ <section class="emb-status" data-design-component="section">
50
+ <h3>Embedding provider status</h3>
51
+ <dl>
52
+ <dt>Provider</dt><dd><code>ollama</code> or <code>hosted-fallback</code></dd>
53
+ <dt>Locality</dt><dd><span class="local" data-design-component="locality-chip">local</span> only when a loopback endpoint serves a non-upstream model. Otherwise <span class="away">remote</span> or <span class="away">unknown</span>.</dd>
54
+ <dt>Model</dt><dd>The selected model and its vector width. The vault requires 768 dimensions.</dd>
55
+ <dt>Coverage</dt><dd>Usable vectors out of vault nodes, with stale, wrong-width, missing and orphaned counts.</dd>
56
+ <dt>Credentials</dt><dd>Hosted fallback keys stay with the Auth owner and are reported as <code>unknown</code>, never read here.</dd>
57
+ </dl>
58
+ <p>Open the Embeddings page for the live reading, the endpoints that were tried, and refresh.</p>
59
+ </section>
package/ui/home.js ADDED
@@ -0,0 +1,353 @@
1
+ /**
2
+ * Embeddings Home — the plugin's native page.
3
+ *
4
+ * Answers, from the plugin's own JSON operations: which provider serves
5
+ * vectors and whether text leaves this machine, how much of the vault has a
6
+ * usable vector, which models the endpoint offers, and how fast the selected
7
+ * model embeds. Reads `status` and `models` on open; benchmark and pull run
8
+ * only when the operator asks. Anything not reported renders as a dash.
9
+ */
10
+
11
+ const DASH = '—';
12
+ const BENCHMARK_MAX = 20;
13
+
14
+ function escapeHtml(value) {
15
+ return String(value).replace(/[&<>"']/g, c => ({
16
+ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;',
17
+ }[c]));
18
+ }
19
+
20
+ /** A reported value, or a dash when the operation did not report one. */
21
+ function shown(value) {
22
+ return value === null || value === undefined || value === '' ? DASH : escapeHtml(value);
23
+ }
24
+
25
+ function formatBytes(n) {
26
+ if (!Number.isFinite(n)) return DASH;
27
+ if (n < 1024) return `${n} B`;
28
+ if (n < 1024 ** 2) return `${(n / 1024).toFixed(1)} KB`;
29
+ if (n < 1024 ** 3) return `${(n / 1024 ** 2).toFixed(1)} MB`;
30
+ return `${(n / 1024 ** 3).toFixed(2)} GB`;
31
+ }
32
+
33
+ /** host.run may hand back parsed JSON, raw stdout, or a { stdout } envelope. */
34
+ export function parseResult(res) {
35
+ if (res && typeof res === 'object' && typeof res.stdout === 'string') return parseResult(res.stdout);
36
+ if (res && typeof res === 'object') return res;
37
+ if (typeof res === 'string' && res.trim().startsWith('{')) return JSON.parse(res);
38
+ throw new Error('the operation returned no JSON');
39
+ }
40
+
41
+ const LOCALITY = {
42
+ local: { tone: 'ok', label: 'Local', note: 'Text sent for embedding stays on this machine.' },
43
+ remote: { tone: 'warn', label: 'Remote', note: 'The endpoint or the selected model runs on another machine, so vault text leaves this host.' },
44
+ unknown: { tone: 'warn', label: 'Unknown', note: 'No local model qualifies. Total Recall may try a hosted provider, which would send vault text off this machine.' },
45
+ };
46
+
47
+ export class EmbeddingsHome extends HTMLElement {
48
+ constructor() {
49
+ super();
50
+ this.status = { phase: 'loading' };
51
+ this.models = { phase: 'loading' };
52
+ this.bench = { phase: 'idle' };
53
+ this.pull = { phase: 'idle' };
54
+ this.count = 10;
55
+ this.pullModel = '';
56
+ }
57
+
58
+ connectedCallback() {
59
+ if (!this.shadowRoot) this.attachShadow({ mode: 'open' });
60
+ this.render();
61
+ this.load();
62
+ }
63
+
64
+ async read(op, args) {
65
+ try {
66
+ return { phase: 'ready', data: parseResult(await this.host.run(op, args)) };
67
+ } catch (err) {
68
+ return { phase: 'unavailable', error: err?.message || String(err) };
69
+ }
70
+ }
71
+
72
+ async load() {
73
+ if (!this.host) {
74
+ const error = 'No Total Recall host is connected, so the plugin operations cannot run.';
75
+ this.status = { phase: 'unavailable', error };
76
+ this.models = { phase: 'unavailable', error };
77
+ this.render();
78
+ return;
79
+ }
80
+ this.status = { phase: 'loading' };
81
+ this.models = { phase: 'loading' };
82
+ this.render();
83
+ [this.status, this.models] = await Promise.all([
84
+ this.read('status', ['--json']),
85
+ this.read('models', ['--json']),
86
+ ]);
87
+ this.render();
88
+ }
89
+
90
+ /** Runs a user-triggered operation; a JSON body with ok:false is a failure. */
91
+ async act(slot, op, args) {
92
+ if (!this.host || this[slot].phase === 'running') return;
93
+ this[slot] = { phase: 'running' };
94
+ this.render();
95
+ const result = await this.read(op, args);
96
+ if (result.phase !== 'ready') this[slot] = { phase: 'failed', error: result.error };
97
+ else if (result.data.ok === false) this[slot] = { phase: 'failed', error: result.data.reason || 'the operation reported a failure', data: result.data };
98
+ else this[slot] = { phase: 'done', data: result.data };
99
+ this.render();
100
+ }
101
+
102
+ runBenchmark() {
103
+ const n = Number(this.count);
104
+ if (!Number.isInteger(n) || n < 1 || n > BENCHMARK_MAX) {
105
+ this.bench = { phase: 'failed', error: `Samples must be a whole number from 1 to ${BENCHMARK_MAX}.` };
106
+ this.render();
107
+ return;
108
+ }
109
+ this.act('bench', 'benchmark', ['--count', String(n), '--json']);
110
+ }
111
+
112
+ async runPull() {
113
+ const model = this.pullModel.trim();
114
+ if (!model) {
115
+ this.pull = { phase: 'failed', error: 'Type the exact model name to pull.' };
116
+ this.render();
117
+ return;
118
+ }
119
+ await this.act('pull', 'pull', [model, '--json']);
120
+ if (this.pull.phase === 'done') this.load();
121
+ }
122
+
123
+ renderProvider() {
124
+ const s = this.status;
125
+ if (s.phase === 'loading') return `<p class="notice" data-design-component="notice">Reading provider status${DASH}</p>`;
126
+ if (s.phase !== 'ready') return `<p class="notice bad" data-design-component="notice">Provider status unavailable: ${escapeHtml(s.error)}</p>`;
127
+ const d = s.data;
128
+ const loc = LOCALITY[d.locality] || { tone: 'warn', label: d.locality || 'Unreported', note: '' };
129
+ const attempts = Array.isArray(d.attempts) ? d.attempts : [];
130
+ return `
131
+ <div class="verdict">
132
+ <span class="chip ${loc.tone}" data-design-component="locality-chip">${escapeHtml(loc.label)}</span>
133
+ <span class="note">${escapeHtml(loc.note)}</span>
134
+ </div>
135
+ <dl class="facts">
136
+ <div><dt>Provider</dt><dd>${shown(d.provider)}</dd></div>
137
+ <div><dt>Endpoint</dt><dd class="mono">${shown(d.endpoint)}</dd></div>
138
+ <div><dt>Selected model</dt><dd class="mono">${shown(d.selected_model)}</dd></div>
139
+ <div><dt>Vector width</dt><dd class="mono">${d.embedding_dims ? `${escapeHtml(d.embedding_dims)} dims` : DASH}</dd></div>
140
+ </dl>
141
+ ${d.reason ? `<p class="notice" data-design-component="notice">${escapeHtml(d.reason)}</p>` : ''}
142
+ ${attempts.length ? `
143
+ <ul class="attempts">
144
+ ${attempts.map(a => `
145
+ <li class="mono ${a.reachable ? 'ok' : 'bad'}">${escapeHtml(a.url)} ${DASH} ${a.reachable ? 'reachable' : `unreachable: ${shown(a.reason)}`}</li>`).join('')}
146
+ </ul>` : ''}`;
147
+ }
148
+
149
+ renderCredentials() {
150
+ const fallback = this.status.phase === 'ready' ? this.status.data.hosted_fallback : null;
151
+ return `
152
+ <dl class="facts">
153
+ <div><dt>Hosted fallback</dt><dd class="mono">${shown(fallback)}</dd></div>
154
+ <div><dt>Credential owner</dt><dd>Auth</dd></div>
155
+ </dl>
156
+ <p class="notice" data-design-component="notice">Keys for hosted embedding providers are held by the Auth owner. This plugin does not read, list or display them, so their readiness is reported as unknown rather than guessed.</p>`;
157
+ }
158
+
159
+ renderCoverage() {
160
+ const s = this.status;
161
+ if (s.phase === 'loading') return `<p class="notice" data-design-component="notice">Counting vectors${DASH}</p>`;
162
+ if (s.phase !== 'ready') return `<p class="notice bad" data-design-component="notice">Coverage unavailable: ${escapeHtml(s.error)}</p>`;
163
+ const b = s.data.brain;
164
+ if (!b) return '<p class="notice" data-design-component="notice">No brain was found in the working directory or home, so there is no vault to measure.</p>';
165
+ if (b.state !== 'ok') {
166
+ return `
167
+ <p class="notice warn" data-design-component="notice">Index state <span class="mono">${shown(b.state)}</span>: ${shown(b.reason)}</p>
168
+ <dl class="facts">
169
+ <div><dt>Brain</dt><dd class="mono">${shown(b.dir)}</dd></div>
170
+ <div><dt>Vault nodes</dt><dd class="mono">${shown(b.vault_nodes)}</dd></div>
171
+ <div><dt>Missing a vector</dt><dd class="mono">${shown(b.missing)}</dd></div>
172
+ </dl>`;
173
+ }
174
+ const counts = [
175
+ ['Usable', b.embedded, 'ok'],
176
+ ['Stale', b.stale, b.stale ? 'warn' : ''],
177
+ ['Wrong width', b.mismatched, b.mismatched ? 'warn' : ''],
178
+ ['Missing', b.missing, b.missing ? 'warn' : ''],
179
+ ['Orphaned rows', b.orphaned, ''],
180
+ ];
181
+ return `
182
+ <div class="coverage">
183
+ <div class="figure" data-design-component="coverage-figure">${b.percent === null || b.percent === undefined ? DASH : `${escapeHtml(b.percent)}%`}</div>
184
+ <div class="figure-caption">${shown(b.embedded)} of ${shown(b.vault_nodes)} vault nodes have a current, correct-width vector</div>
185
+ </div>
186
+ <ul class="counts">
187
+ ${counts.map(([label, value, tone]) => `
188
+ <li class="count-row ${tone}" data-design-component="count-row"><span>${label}</span><span class="mono">${shown(value)}</span></li>`).join('')}
189
+ </ul>
190
+ <dl class="facts">
191
+ <div><dt>Indexed by</dt><dd class="mono">${shown(b.model)}</dd></div>
192
+ <div><dt>Index rows</dt><dd class="mono">${shown(b.rows)}</dd></div>
193
+ <div><dt>Index size</dt><dd class="mono">${formatBytes(b.db_bytes)}</dd></div>
194
+ <div><dt>Unparseable files</dt><dd class="mono">${shown(b.parse_errors)}</dd></div>
195
+ <div><dt>Brain</dt><dd class="mono">${shown(b.dir)}</dd></div>
196
+ </dl>
197
+ ${b.stale || b.mismatched || b.missing ? '<p class="notice" data-design-component="notice">Rebuild the unusable vectors with <span class="mono">total-recall compile</span>.</p>' : ''}`;
198
+ }
199
+
200
+ renderModels() {
201
+ const m = this.models;
202
+ if (m.phase === 'loading') return `<p class="notice" data-design-component="notice">Listing models${DASH}</p>`;
203
+ if (m.phase !== 'ready') return `<p class="notice bad" data-design-component="notice">Model list unavailable: ${escapeHtml(m.error)}</p>`;
204
+ const d = m.data;
205
+ if (d.reachable === false) return '<p class="notice bad" data-design-component="notice">No endpoint answered. The endpoints tried are listed under Provider.</p>';
206
+ const rows = Array.isArray(d.models) ? d.models : [];
207
+ if (!rows.length) return `<p class="notice" data-design-component="notice">${shown(d.url)} reports no models. Pull one below.</p>`;
208
+ return `
209
+ <p class="caption">${shown(d.url)} ${DASH} the vault needs ${shown(d.vault_dims)}-dim vectors</p>
210
+ <ul class="models">
211
+ ${rows.map(r => `
212
+ <li class="model-row${r.name === d.selected ? ' selected' : ''}" data-design-component="model-row">
213
+ <span class="mono name">${shown(r.name)}${r.name === d.selected ? ' <span class="tag ok">selected</span>' : ''}</span>
214
+ <span class="tags">
215
+ <span class="tag">${r.dims ? `${escapeHtml(r.dims)} dims` : 'width unknown'}</span>
216
+ <span class="tag ${r.embedding_capable ? 'ok' : ''}">${r.embedding_capable ? 'embeds' : 'no embedding'}</span>
217
+ <span class="tag ${r.compatible ? 'ok' : 'warn'}">${r.compatible ? 'vault-compatible' : 'not usable'}</span>
218
+ ${r.upstream ? '<span class="tag warn">upstream</span>' : ''}
219
+ </span>
220
+ </li>`).join('')}
221
+ </ul>`;
222
+ }
223
+
224
+ renderBenchmark() {
225
+ const b = this.bench;
226
+ const running = b.phase === 'running';
227
+ const d = b.data || {};
228
+ return `
229
+ <div class="action">
230
+ <label class="field">Samples
231
+ <input id="bench-count" type="number" min="1" max="${BENCHMARK_MAX}" step="1" value="${escapeHtml(this.count)}" ${running ? 'disabled' : ''}>
232
+ </label>
233
+ <button id="bench-run" type="button" class="primary" data-design-component="button-primary" ${running || !this.host ? 'disabled' : ''}>${running ? 'Measuring' : 'Run benchmark'}</button>
234
+ </div>
235
+ <p class="caption">Embeds a neutral sentence with the selected model, never vault text. Runs only against a local model.</p>
236
+ ${b.phase === 'failed' ? `<p class="notice bad" data-design-component="notice">Benchmark failed: ${escapeHtml(b.error)}</p>` : ''}
237
+ ${b.phase === 'done' ? `
238
+ <dl class="facts">
239
+ <div><dt>Per embedding</dt><dd class="mono">${shown(d.ms_per_embedding)} ms</dd></div>
240
+ <div><dt>Range</dt><dd class="mono">${shown(d.min_ms)}${DASH}${shown(d.max_ms)} ms</dd></div>
241
+ <div><dt>Samples</dt><dd class="mono">${shown(d.samples)} × ${shown(d.dims)} dims</dd></div>
242
+ <div><dt>Full vault</dt><dd class="mono">${d.projected_minutes === null || d.projected_minutes === undefined ? DASH : `about ${escapeHtml(d.projected_minutes)} min for ${shown(d.vault_nodes)} nodes`}</dd></div>
243
+ <div><dt>Measured</dt><dd class="mono">${shown(d.model)} on ${shown(d.url)}</dd></div>
244
+ </dl>` : ''}`;
245
+ }
246
+
247
+ renderPull() {
248
+ const p = this.pull;
249
+ const running = p.phase === 'running';
250
+ const d = p.data || {};
251
+ return `
252
+ <div class="action">
253
+ <label class="field grow">Model name
254
+ <input id="pull-model" type="text" spellcheck="false" autocomplete="off" value="${escapeHtml(this.pullModel)}" ${running ? 'disabled' : ''}>
255
+ </label>
256
+ <button id="pull-run" type="button" class="primary" data-design-component="button-primary" ${running || !this.host ? 'disabled' : ''}>${running ? 'Pulling' : 'Pull model'}</button>
257
+ </div>
258
+ <p class="caption">Downloads the named model to the configured loopback endpoint. Cloud and upstream models are refused. A pull can take several minutes.</p>
259
+ ${p.phase === 'failed' ? `<p class="notice bad" data-design-component="notice">Pull failed${d.model ? ` for <span class="mono">${escapeHtml(d.model)}</span>` : ''}: ${escapeHtml(p.error)}</p>` : ''}
260
+ ${p.phase === 'done' ? `<p class="notice ok" data-design-component="notice"><span class="mono">${shown(d.model)}</span> is ready on <span class="mono">${shown(d.url)}</span>.</p>` : ''}`;
261
+ }
262
+
263
+ render() {
264
+ const root = this.shadowRoot;
265
+ if (!root) return;
266
+ const loading = this.status.phase === 'loading' || this.models.phase === 'loading';
267
+ root.innerHTML = `
268
+ <style>
269
+ :host {
270
+ display: block;
271
+ box-sizing: border-box;
272
+ padding: var(--spacing-lg, 16px);
273
+ color: var(--colors-text, #ecfeff);
274
+ background: var(--colors-background, #07171d);
275
+ font-family: var(--typography-body-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
276
+ font-size: var(--typography-body-font-size, 13px);
277
+ }
278
+ *, *::before, *::after { box-sizing: border-box; }
279
+ @media (prefers-reduced-motion: reduce) {
280
+ *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
281
+ }
282
+ header { display: flex; align-items: center; justify-content: space-between; gap: var(--spacing-md, 12px); flex-wrap: wrap; margin-bottom: var(--spacing-lg, 16px); }
283
+ h1 { margin: 0; font-size: 18px; }
284
+ h1 + p { margin: 2px 0 0; color: var(--colors-muted, #67e8f9); font-size: var(--typography-label-font-size, 11px); }
285
+ h2 { margin: 0 0 var(--spacing-md, 12px); font-size: var(--typography-label-font-size, 11px); font-weight: var(--typography-label-font-weight, 700); letter-spacing: 0.05em; text-transform: uppercase; color: var(--colors-muted, #67e8f9); }
286
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: var(--spacing-md, 12px); }
287
+ section { background: var(--colors-surface, #0e2a35); border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-md, 6px); padding: var(--spacing-md, 12px); min-width: 0; }
288
+ .mono { font-family: var(--typography-mono-font-family, 'JetBrains Mono', 'Fira Code', monospace); font-size: var(--typography-mono-font-size, 12px); overflow-wrap: anywhere; }
289
+ .verdict { display: flex; align-items: center; gap: var(--spacing-sm, 8px); flex-wrap: wrap; margin-bottom: var(--spacing-md, 12px); }
290
+ .chip { font-size: var(--typography-label-font-size, 11px); font-weight: 700; text-transform: uppercase; padding: var(--spacing-xs, 4px) var(--spacing-sm, 8px); border-radius: var(--rounded-md, 6px); border: 1px solid currentColor; }
291
+ .note, .caption { color: var(--colors-muted, #67e8f9); font-size: var(--typography-label-font-size, 11px); }
292
+ .caption { margin: 0 0 var(--spacing-sm, 8px); }
293
+ .ok { color: var(--colors-ok, #10b981); }
294
+ .warn { color: var(--colors-warn, #f59e0b); }
295
+ .bad { color: var(--colors-danger, #ef4444); }
296
+ .muted { color: var(--colors-muted, #67e8f9); }
297
+ .facts { display: grid; gap: var(--spacing-xs, 4px); margin: 0; }
298
+ .facts div { display: flex; justify-content: space-between; gap: var(--spacing-md, 12px); }
299
+ dt { color: var(--colors-muted, #67e8f9); }
300
+ dt, dd { min-width: 0; }
301
+ dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
302
+ .notice { margin: var(--spacing-sm, 8px) 0 0; padding: var(--spacing-sm, 8px); background: var(--colors-background, #07171d); border-radius: var(--rounded-sm, 4px); }
303
+ .attempts, .counts, .models { list-style: none; margin: var(--spacing-sm, 8px) 0 0; padding: 0; display: grid; gap: var(--spacing-xs, 4px); }
304
+ .coverage { display: flex; align-items: baseline; gap: var(--spacing-md, 12px); flex-wrap: wrap; margin-bottom: var(--spacing-sm, 8px); }
305
+ .figure { font-family: var(--typography-figure-font-family, 'JetBrains Mono', monospace); font-size: var(--typography-figure-font-size, 28px); font-weight: var(--typography-figure-font-weight, 800); }
306
+ .figure-caption { color: var(--colors-muted, #67e8f9); }
307
+ .count-row { display: flex; justify-content: space-between; font-family: var(--typography-mono-font-family, 'JetBrains Mono', monospace); font-size: var(--typography-mono-font-size, 12px); }
308
+ .count-row:not(.ok):not(.warn) { color: var(--colors-muted, #67e8f9); }
309
+ .counts { margin-bottom: var(--spacing-md, 12px); }
310
+ .model-row { display: flex; justify-content: space-between; align-items: center; gap: var(--spacing-sm, 8px); flex-wrap: wrap; background: var(--colors-background, #07171d); border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-sm, 4px); padding: var(--spacing-sm, 8px); }
311
+ .model-row.selected { border-color: var(--colors-primary, #06b6d4); }
312
+ .tags { display: flex; gap: var(--spacing-xs, 4px); flex-wrap: wrap; }
313
+ .tag { font-size: 10px; padding: 2px 6px; border-radius: var(--rounded-sm, 4px); border: 1px solid var(--colors-line, #164e63); color: var(--colors-muted, #67e8f9); }
314
+ .tag.ok { color: var(--colors-ok, #10b981); }
315
+ .tag.warn { color: var(--colors-warn, #f59e0b); }
316
+ .action { display: flex; align-items: flex-end; gap: var(--spacing-sm, 8px); flex-wrap: wrap; margin-bottom: var(--spacing-sm, 8px); }
317
+ .field { display: grid; gap: var(--spacing-xs, 4px); color: var(--colors-muted, #67e8f9); font-size: var(--typography-label-font-size, 11px); }
318
+ .field.grow { flex: 1 1 180px; }
319
+ input { min-height: 44px; padding: 0 var(--spacing-sm, 8px); color: var(--colors-text, #ecfeff); background: var(--colors-background, #07171d); border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-sm, 4px); font-family: var(--typography-mono-font-family, 'JetBrains Mono', monospace); }
320
+ input[type=number] { width: 88px; }
321
+ button.primary { min-height: 44px; padding: 0 var(--spacing-lg, 16px); border: 0; border-radius: var(--rounded-sm, 4px); cursor: pointer; font-weight: 700; color: var(--colors-on-primary, #07171d); background: var(--colors-primary, #06b6d4); transition: background 0.15s ease; }
322
+ button.primary:hover:not(:disabled) { background: var(--colors-primary-hover, #22d3ee); }
323
+ button:disabled { opacity: 0.6; cursor: not-allowed; }
324
+ button.refresh { min-height: 44px; padding: 0 var(--spacing-md, 12px); color: var(--colors-text, #ecfeff); background: transparent; border: 1px solid var(--colors-line, #164e63); border-radius: var(--rounded-sm, 4px); cursor: pointer; }
325
+ button:focus-visible, input:focus-visible { outline: 2px solid var(--colors-primary-hover, #22d3ee); outline-offset: 2px; }
326
+ </style>
327
+ <header>
328
+ <div>
329
+ <h1>Embeddings</h1>
330
+ <p>Vectors behind Total Recall search for this brain</p>
331
+ </div>
332
+ <button id="refresh" type="button" class="refresh" ${loading || !this.host ? 'disabled' : ''}>${loading ? 'Reading' : 'Refresh'}</button>
333
+ </header>
334
+ <div class="grid">
335
+ <section data-design-component="section" aria-labelledby="h-provider"><h2 id="h-provider">Provider</h2>${this.renderProvider()}</section>
336
+ <section data-design-component="section" aria-labelledby="h-coverage"><h2 id="h-coverage">Vault coverage</h2>${this.renderCoverage()}</section>
337
+ <section data-design-component="section" aria-labelledby="h-models"><h2 id="h-models">Models on the endpoint</h2>${this.renderModels()}</section>
338
+ <section data-design-component="section" aria-labelledby="h-credentials"><h2 id="h-credentials">Credentials</h2>${this.renderCredentials()}</section>
339
+ <section data-design-component="section" aria-labelledby="h-benchmark"><h2 id="h-benchmark">Benchmark</h2>${this.renderBenchmark()}</section>
340
+ <section data-design-component="section" aria-labelledby="h-pull"><h2 id="h-pull">Pull a model</h2>${this.renderPull()}</section>
341
+ </div>`;
342
+
343
+ root.getElementById('refresh')?.addEventListener('click', () => this.load());
344
+ root.getElementById('bench-count')?.addEventListener('input', e => { this.count = e.target.value; });
345
+ root.getElementById('bench-run')?.addEventListener('click', () => this.runBenchmark());
346
+ root.getElementById('pull-model')?.addEventListener('input', e => { this.pullModel = e.target.value; });
347
+ root.getElementById('pull-run')?.addEventListener('click', () => this.runPull());
348
+ }
349
+ }
350
+
351
+ if (!customElements.get('tr-embeddings-home')) {
352
+ customElements.define('tr-embeddings-home', EmbeddingsHome);
353
+ }