heartcode 0.1.37 → 0.1.40

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,115 @@
1
+ // What each model is good at, from public rankings (LMArena: people comparing two models' answers
2
+ // to the same prompt, by skill): coding, web apps, images, long inputs… Fetched once a week into
3
+ // ~/.heart/rankings.json (best fit only); a model is matched to its entry by name.
4
+ import path from 'node:path'
5
+ import { HOME, readJson, writeJson } from './config.js'
6
+ import { log } from './log.js'
7
+ import { readParquet } from './parquet.js'
8
+
9
+ const FILE = path.join(HOME, 'rankings.json')
10
+ const WEEK = 7 * 24 * 3600_000
11
+ const FILES = 'https://huggingface.co/datasets/lmarena-ai/leaderboard-dataset/resolve/main' // one Parquet file per ranking: text, webdev, vision, agent
12
+
13
+ // The skills a task can need: [ranking, its category, what it's for] (the pick names them).
14
+ export const SKILLS = {
15
+ coding: ['text', 'coding', 'writing and fixing code'],
16
+ webdev: ['webdev', 'webdev', 'building web apps (any stack)'],
17
+ 'webdev-html': ['webdev', 'webdev-html', 'plain HTML/CSS/JS pages, canvas and browser games'],
18
+ 'webdev-react': ['webdev', 'webdev-react', 'React apps'],
19
+ hard: ['text', 'hard_prompts', 'hard, multi-part problems'],
20
+ instructions: ['text', 'instruction_following', 'following detailed instructions exactly'],
21
+ 'long-input': ['text', 'longer_query', 'long inputs: big files, long specs'],
22
+ 'multi-turn': ['text', 'multi_turn', 'long back-and-forth work'],
23
+ math: ['text', 'math', 'math and algorithms'],
24
+ writing: ['text', 'creative_writing', 'prose, docs, copy'],
25
+ software: ['text', 'industry_software_and_it_services', 'software and IT know-how'],
26
+ vision: ['vision', 'overall', 'understanding images and screenshots'],
27
+ ocr: ['vision', 'ocr', 'reading text in images'],
28
+ diagrams: ['vision', 'diagram', 'reading diagrams and charts'],
29
+ agent: ['agent', 'overall', 'agent work: tool calls, commands, many steps'],
30
+ }
31
+ const OVERALL = 'text:overall' // a skill a model isn't ranked on: its overall place stands in
32
+
33
+ export const loadRankings = () => readJson(FILE, null)
34
+
35
+ // One ranking (text, webdev…), every category in it: { 'text:coding': [{ name, rank }], … }
36
+ async function fetchRanking(config, signal) {
37
+ const res = await fetch(`${FILES}/${config}/latest-00000-of-00001.parquet`, { signal: AbortSignal.any([AbortSignal.timeout(120_000), ...(signal ? [signal] : [])]) })
38
+ if (!res.ok) throw new Error(`rankings ${config}: HTTP ${res.status}`)
39
+ const out = {}
40
+ for (const r of readParquet(Buffer.from(await res.arrayBuffer()), ['model_name', 'rank', 'category'])) (out[`${config}:${r.category}`] ??= []).push({ name: r.model_name, rank: r.rank })
41
+ return out
42
+ }
43
+
44
+ // The rankings: fetched when there are none or they're a week old (then the old ones are used
45
+ // meanwhile, refreshed behind). null when there are none and fetching failed.
46
+ let refreshing = null
47
+ export async function rankings({ signal, onWait, now = false } = {}) {
48
+ const have = loadRankings()
49
+ if (have && Date.now() - have.fetched < WEEK && !now) return have
50
+ refreshing ??= (async () => {
51
+ const wanted = new Set([...Object.values(SKILLS).map(([c, k]) => `${c}:${k}`), OVERALL])
52
+ const all = Object.assign({}, ...(await Promise.all([...new Set([...wanted].map((p) => p.split(':')[0]))].map((c) => fetchRanking(c, have ? undefined : signal)))))
53
+ const lists = Object.fromEntries(Object.entries(all).filter(([k]) => wanted.has(k)))
54
+ const out = { fetched: Date.now(), source: 'LMArena (huggingface.co/datasets/lmarena-ai/leaderboard-dataset)', lists }
55
+ writeJson(FILE, out)
56
+ log('fit', `rankings fetched: ${Object.entries(lists).map(([k, v]) => `${k} ${v.length}`).join(', ')}`)
57
+ return out
58
+ })().finally(() => (refreshing = null))
59
+ if (have && !now) {
60
+ refreshing.catch((e) => log('fit', `rankings not refreshed: ${e.message}`))
61
+ return have
62
+ }
63
+ onWait?.()
64
+ try {
65
+ return await refreshing
66
+ } catch (e) {
67
+ if (signal?.aborted) throw e
68
+ log('fit', `no rankings: ${e.message}`)
69
+ return null
70
+ }
71
+ }
72
+
73
+ // A name as words: "models/gemini-3.6-flash" and "Gemini 3.6 Flash (High)" are both "gemini 3 6 flash"
74
+ const DROP = new Set(['latest', 'preview', 'free', 'it', 'instruct', 'exp', 'chat'])
75
+ export const words = (name) =>
76
+ String(name)
77
+ .toLowerCase()
78
+ .replace(/\([^)]*\)/g, ' ')
79
+ .replace(/^.*\//, '')
80
+ .replace(/([a-z])(\d)/g, '$1 $2')
81
+ .replace(/(\d)([a-z])/g, '$1 $2')
82
+ .split(/[^a-z0-9]+/)
83
+ .filter((w) => w && !DROP.has(w) && !/^\d{4}$/.test(w)) // dated versions (2512, 0127)
84
+
85
+ // Where a model stands in a list, 0 (best) to 1 (last); null when it isn't in it. Its entry: the
86
+ // same words, or those followed only by its size ("nemotron 3 super" = "Nemotron 3 Super 120B A12B"),
87
+ // maybe after the maker's name; of several (High, Low…), the best.
88
+ export function place(model, list) {
89
+ const mine = words(model)
90
+ if (!mine.length || !list?.length) return null
91
+ const size = /^(\d+|[abmkt])$/
92
+ const at = list.filter((e) => {
93
+ const theirs = words(e.name)
94
+ // from their first word, or their second (a maker's name first: "NVIDIA-Nemotron-3-Super-120B-A12B")
95
+ return [0, 1].some((from) => theirs.length >= from + mine.length && mine.every((w, i) => theirs[from + i] === w) && theirs.slice(from + mine.length).every((w) => size.test(w)))
96
+ })
97
+ return at.length ? Math.min(...at.map((e) => e.rank)) / list.length : null
98
+ }
99
+
100
+ // A model's score for some skills, 0 (best) to 1: the average of its places; a skill it isn't
101
+ // ranked on counts as its overall place. null: not ranked at all.
102
+ export function score(model, skills, data) {
103
+ const overall = place(model, data?.lists[OVERALL])
104
+ const each = skills.map((k) => place(model, data?.lists[SKILLS[k] && `${SKILLS[k][0]}:${SKILLS[k][1]}`]) ?? overall)
105
+ return each.every((x) => x == null) ? null : each.reduce((n, x) => n + (x ?? 1), 0) / each.length
106
+ }
107
+
108
+ // A model's place in one list ('text:coding'…), for showing: { rank, of, as } (as: its name there); null when not in it
109
+ export function rankIn(model, key, data) {
110
+ const list = data?.lists[key]
111
+ const at = list?.filter((e) => place(model, [e]) != null)
112
+ if (!at?.length) return null
113
+ const best = at.reduce((a, b) => (b.rank < a.rank ? b : a))
114
+ return { rank: best.rank, of: list.length, as: best.name }
115
+ }
package/src/settings.html CHANGED
@@ -66,6 +66,9 @@
66
66
  .brand { display: flex; align-items: baseline; gap: 8px; font-weight: 650; font-size: 15px; letter-spacing: -.01em; padding: 0 10px 22px; }
67
67
  .brand span { color: var(--accent); font-size: 17px; }
68
68
  .brand small { color: var(--faint); font-weight: 500; font-size: 13px; }
69
+ .brand small span { color: var(--faint); font-size: 12px; }
70
+ .update-note { margin: -14px 10px 16px; padding: 7px 10px; border-radius: 8px; background: color-mix(in srgb, var(--c-green, #22c55e) 14%, transparent); color: var(--text); font-size: 12.5px; }
71
+ .update-note code { font-size: 12px; }
69
72
  nav a { position: relative; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: var(--radius-s); color: var(--muted); text-decoration: none; margin-bottom: 1px; font-weight: 500; transition: background .15s, color .15s; }
70
73
  nav a:hover { background: var(--hover); color: var(--text); }
71
74
  nav a.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow), inset 0 0 0 1px var(--line); }
@@ -293,9 +296,21 @@
293
296
  .mwrap { padding-left: 16px; align-items: center; }
294
297
  .mwrap .pick + .mrow { padding-left: 12px; }
295
298
  .mwrap .forget:hover { color: var(--err); }
296
- .log-opts { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; }
297
- .log-opts .opt { border-bottom: 0; padding-bottom: 0; }
298
- @media (max-width: 860px) { .log-opts { grid-template-columns: 1fr; } }
299
+ .kinds-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
300
+ .kinds { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0 24px; }
301
+ .kinds .opt { border-bottom: 1px solid var(--line); padding: 10px 0; }
302
+ .kinds .opt, .kinds .opt:first-child { align-items: flex-start; padding: 10px 0; }
303
+ #l-tools select { width: auto; max-width: 260px; }
304
+ #l-tools input[type=search] { width: 200px; }
305
+ .kinds .opt .file { display: block; margin-top: 3px; font-family: var(--mono, ui-monospace, monospace); font-size: 11.5px; color: var(--faint); }
306
+ .kinds .opt select { margin-top: 6px; width: 100%; }
307
+ .logtext { max-height: 70vh; overflow: auto; font: 12px/1.55 var(--mono, ui-monospace, monospace); padding: 10px 18px 16px; }
308
+ .logtext .ln { white-space: pre-wrap; word-break: break-word; padding: 1px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 50%, transparent); }
309
+ .logtext .ln .ts { color: var(--faint); }
310
+ .logtext .ln .tp { color: var(--accent); font-weight: 600; }
311
+ .logtext .ln.bad .tp { color: var(--err, #e5484d); }
312
+ .logtext mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 2px; }
313
+ .logtext .empty { padding: 30px 0; }
299
314
  .log-days { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
300
315
  .log-days input { width: 90px; }
301
316
  .log-days .muted { font-size: 12.5px; flex: 1; min-width: 220px; }
@@ -392,9 +407,9 @@
392
407
  .pill .again:hover:not(:disabled) { color: var(--text); }
393
408
  .pill.on { border-color: var(--accent); background: var(--accent-soft); }
394
409
  .pill.on .again { border-left-color: color-mix(in srgb, var(--accent) 40%, transparent); }
395
- .mt-h, .mtable li { display: grid; grid-template-columns: 14px 18px 44px minmax(240px, 1fr) 110px 62px 52px 70px 58px 116px 84px 132px; /* the last: Test · Request · Edit · ✕, as wide as they are */ align-items: center; column-gap: 6px; padding: 8px 18px; }
410
+ .mt-h, .mtable li { display: grid; grid-template-columns: 14px 18px 44px minmax(240px, 1fr) 110px 62px 52px 70px 58px 58px 58px 58px 116px 84px 132px; /* the last: Test · Request · Edit · ✕, as wide as they are */ align-items: center; column-gap: 6px; padding: 8px 18px; }
396
411
  .mt-h button.mid, .mtable .mid { text-align: center; }
397
- .mt-h > :nth-child(11), .mtable .try { padding-left: 12px; } /* Works?: a little room after the right-aligned price */
412
+ .mt-h > :nth-child(14), .mtable .try { padding-left: 12px; } /* Works?: a little room after the right-aligned price */
398
413
  .mtable li .acts { justify-content: flex-start; }
399
414
  .mt-h { border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 500; color: var(--faint); padding-top: 10px; padding-bottom: 10px; background: var(--panel2); }
400
415
  .mt-h button { display: inline; border: 0; background: none !important; padding: 0; font: inherit; color: inherit; text-align: left; white-space: nowrap; transform: none !important; }
@@ -413,6 +428,8 @@
413
428
  .mtable:not(.drag) .grip { visibility: hidden; }
414
429
  .mtable .n { font-weight: 650; color: var(--faint); }
415
430
  .mtable li:first-child .n { color: var(--accent); }
431
+ .mtable .rk { color: var(--muted); }
432
+ .mtable .rk.top { color: var(--ok); font-weight: 600; }
416
433
  .mtable .m { font-family: var(--mono); font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
417
434
  .mtable .p { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
418
435
  .mtable .yes { color: var(--ok); }
@@ -482,7 +499,7 @@
482
499
  /* Your models: the header's buttons, the list's settings, the toolbar (sticky), the table */
483
500
  .mt-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
484
501
  /* Your models: the settings (three cells across), the toolbar (sticky), the table */
485
- .mt-sets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
502
+ .mt-sets { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
486
503
  .mt-set { display: flex; flex-direction: column; gap: 6px; padding: 14px 18px; border-left: 1px solid var(--line); min-width: 0; }
487
504
  .mt-set:first-child { border-left: 0; }
488
505
  .mt-setl { font-size: 12px; font-weight: 600; color: var(--muted); }
@@ -598,6 +615,10 @@
598
615
  @keyframes job-slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
599
616
 
600
617
  @media (max-width: 1180px) {
618
+ .mt-sets { grid-template-columns: repeat(2, minmax(0, 1fr)); } /* the cells: two by two */
619
+ .mt-set:nth-child(2n+1) { border-left: 0; }
620
+ .mt-set:last-child:nth-child(odd) { grid-column: span 2; } /* an odd one out: the whole row, no hole beside it */
621
+ .mt-set:nth-child(n+3) { border-top: 1px solid var(--line); }
601
622
  .split { grid-template-columns: 1fr; }
602
623
  .work { grid-template-columns: 1fr; height: auto !important; }
603
624
  .work .mine { order: -1; }
@@ -741,7 +762,8 @@
741
762
  <body>
742
763
  <div class="app">
743
764
  <aside>
744
- <div class="brand"><span>♥</span> HeartCode <small>settings</small></div>
765
+ <div class="brand"><span>♥</span> HeartCode <small>settings <span id="version"></span></small></div>
766
+ <div class="update-note" id="update-note" hidden></div>
745
767
  <nav id="nav">
746
768
  <div class="nav-group" role="separator"></div>
747
769
  <a href="#models" data-page="models" data-tabs="models providers"><span class="ic">☰</span> Models <span class="count" id="n-mine"></span></a>
@@ -815,36 +837,22 @@
815
837
  <section class="page" id="page-logging">
816
838
  <div class="head"><div><h1>Logs</h1><p class="lead">What HeartCode writes down, for finding out what went wrong. Off unless you switch it on.</p></div><div class="disk" id="l-disk"></div></div>
817
839
  <div class="card">
818
- <div class="log-opts">
819
- <div>
820
- <h2>The run's log</h2>
821
- <p class="sub">Everything each run does, as text: requests, replies, retries, tools, commands, what you typed.</p>
822
- <div id="l-run"></div>
823
- </div>
824
- <div>
825
- <h2>Requests</h2>
826
- <p class="sub">Each request to a model and its reply or error: which failed, which worked, and which fallback answered.</p>
827
- <div id="l-req"></div>
828
- <div class="row" style="align-items:center;gap:10px;margin-top:12px">
829
- <label class="f" for="l-detail" style="margin:0">Keep</label>
830
- <select id="l-detail" style="flex:1">
831
- <option value="full">Everything: what was sent and what came back</option>
832
- <option value="summary">Only a summary: model, result, error, timings, tokens</option>
833
- </select>
834
- </div>
835
- <div class="hint">Everything can make big files on long conversations. API keys are never written.</div>
836
- </div>
840
+ <div class="kinds-top">
841
+ <div><h2 style="margin:0">What to log</h2><p class="sub" style="margin:4px 0 0">Each kind on its own, all off unless you switch one on. A running HeartCode takes a change in at once. Written to <span class="mono" id="l-where"></span>, a folder per run.</p></div>
842
+ <button class="small" id="l-alloff">All off</button>
837
843
  </div>
844
+ <div class="kinds" id="l-kinds"></div>
838
845
  <div class="log-days">
839
846
  <label for="l-days"><b>Keep logs for</b></label>
840
- <input type="number" id="l-days" min="1" max="3650" step="1" value="30">
847
+ <input type="number" id="l-days" min="1" max="3650" step="1" value="3">
841
848
  <span>days</span>
842
- <span class="muted">Older ones (both kinds) are deleted when HeartCode starts, and right away when you change this. 3 days unless you change it.</span>
849
+ <span class="muted">Older ones (every kind) are deleted when HeartCode starts, and right away when you change this. API keys are never written.</span>
843
850
  </div>
844
851
  </div>
845
852
  <div class="card reqs-card">
846
853
  <div class="reqs-top">
847
- <h2 style="margin:0">Requests logged</h2>
854
+ <div class="seg" id="l-view"></div>
855
+ <div id="l-tools" style="display:flex;gap:8px;align-items:center;flex-wrap:wrap"></div>
848
856
  <div class="seg" id="l-filter">
849
857
  <label class="on"><input type="radio" name="l-filter" value="all" checked>All</label><label><input type="radio" name="l-filter" value="failed">Failed</label><label><input type="radio" name="l-filter" value="fallback">Fallbacks</label>
850
858
  </div>
@@ -854,6 +862,7 @@
854
862
  <div class="req-list" id="l-list"></div>
855
863
  <div class="req-detail" id="l-detail-pane"><div class="empty">Click a request to see it in full.</div></div>
856
864
  </div>
865
+ <div class="logtext" id="l-text" hidden></div>
857
866
  </div>
858
867
  </section>
859
868
 
@@ -1297,6 +1306,7 @@ const DOING = {
1297
1306
  '/api/telegram/connect': 'Checking the token with Telegram',
1298
1307
  '/api/telegram/test': 'Sending a test message',
1299
1308
  '/api/search/test': 'Trying a search on your SearXNG',
1309
+ '/api/rankings': 'Getting the public model rankings',
1300
1310
  '/api/models-dev': null, // its own strip
1301
1311
  }
1302
1312
  let acting = 0
@@ -2202,6 +2212,8 @@ const COLS = {
2202
2212
  tools: { label: 'Tools', first: 'down', get: (t) => can(t).tools, words: ['without first', 'with first'] },
2203
2213
  thinking: { label: 'Thinking', first: 'down', get: (t) => can(t).thinking, words: ['without first', 'with first'] },
2204
2214
  images: { label: 'Images', first: 'down', get: (t) => can(t).images, words: ['without first', 'with first'] },
2215
+ // its place in a public ranking (LMArena), by its share of the list: not ranked, last
2216
+ ...Object.fromEntries([['coding', 'Coding'], ['web', 'Web apps'], ['vision', 'Vision']].map(([k, label]) => [k, { label, first: 'up', get: (t) => (t.ranks?.[k] ? t.ranks[k].rank / t.ranks[k].of : null), words: ['best first', 'worst first'] }])),
2205
2217
  input: { label: 'In $/M', first: 'up', get: (t) => t.price?.input ?? null, words: ['cheapest first', 'priciest first'] },
2206
2218
  output: { label: 'Out $/M', first: 'up', get: (t) => t.price?.output ?? null, words: ['cheapest first', 'priciest first'] },
2207
2219
  // in and out together, per million tokens
@@ -2422,16 +2434,26 @@ function drawMine(s) {
2422
2434
  h('button', { className: 'small', textContent: 'Provider ranking', disabled: !order.some((t) => t.provider !== order[0]?.provider), title: 'drag your providers into order; the Provider column sorts by it', onclick: openRanking }),
2423
2435
  h('button', { className: 'small', textContent: 'Refresh from models.dev', disabled: !order.length, title: 'ask models.dev again what each model can do: context, tools, thinking, images, price', onclick: () => lookUp() }))
2424
2436
 
2425
- // --- the list's settings: three cells across, a label over each control ---
2437
+ // --- the list's settings: five cells across, a label over each control ---
2426
2438
  const ro = s.rotation
2427
2439
  const cell = (label, about, ...control) => h('label', { className: 'mt-set', title: about }, h('span', { className: 'mt-setl', textContent: label }), h('span', { className: 'mt-setc' }, ...control))
2440
+ const fit = S.settings.modelChoice === 'fit'
2428
2441
  const settings = h('div', { className: 'mt-sets' },
2442
+ cell('HeartCode picks the model by', fit ? 'for each new message, your models ranked by public rankings (LMArena, fetched once a week) on the skills it needs: web pages, code, images…; models not ranked come after, in your order' : 'your order: #1 works, the next takes over when it fails',
2443
+ h('select', { onchange: (e) => act('/api/setting', { name: 'modelChoice', value: e.target.value }, e.target.value === 'fit' ? 'models picked for each task by public rankings' : 'models used in your order') },
2444
+ [['order', 'your order'], ['fit', 'best fit per task']].map(([v, t]) => h('option', { value: v, textContent: t, selected: S.settings.modelChoice === v })))),
2429
2445
  cell('When a model fails', ro.on === 'retries' ? 'a rate limit or outage: that model is tried again that many times first; any other error moves on at once' : "any error moves on at once, to another provider's model first",
2430
2446
  h('select', { onchange: (e) => saveOrder(S.order, 'saved', { on: e.target.value }) },
2431
2447
  [['failure', 'the next one answers'], ['retries', 'try it again first']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.on === v }))),
2432
2448
  ro.on === 'retries' ? h('input', { type: 'number', className: 'tries', 'aria-label': 'tries', title: 'tries of the same model first (rate limits, outages)', min: 1, max: 20, value: ro.retries, onchange: (e) => saveOrder(S.order, 'saved', { retries: Number(e.target.value) }) }) : null),
2433
- cell('A new message starts with', 'the model a new message goes to first',
2434
- h('select', { onchange: (e) => saveOrder(S.order, 'saved', { next: e.target.value }) },
2449
+ cell('A reply must start within', "a model that hasn't started answering (text, thinking or a tool call) in this many seconds counts as failed: the next one answers",
2450
+ h('input', { type: 'number', className: 'tries', 'aria-label': 'seconds a reply must start within', title: "a model that hasn't started answering (text, thinking or a tool call) in this many seconds counts as failed: the next one answers", min: 5, max: 600, value: S.settings.replyStart ?? 60, onchange: (e) => {
2451
+ const v = Math.round(Number(e.target.value))
2452
+ if (!(v >= 5 && v <= 600)) return (e.target.value = S.settings.replyStart ?? 60), toast('a whole number of seconds, 5 to 600', true)
2453
+ act('/api/setting', { name: 'replyStart', value: v }, `a model that hasn't started answering in ${v}s counts as failed`)
2454
+ } }), h('span', { className: 'unit', textContent: 'seconds' })),
2455
+ cell('A new message starts with', fit ? 'best fit picks it for each message' : 'the model a new message goes to first',
2456
+ h('select', { disabled: fit, onchange: (e) => saveOrder(S.order, 'saved', { next: e.target.value }) },
2435
2457
  [['first', '#1'], ['stay', 'the last that answered']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.next === v })))),
2436
2458
  cell('A test waits for an answer', 'every model test: Test, Test all, Request',
2437
2459
  h('input', { type: 'number', min: 1, max: 600, step: 1, value: S.settings.testTimeout ?? 10, 'aria-label': 'Test timeout in seconds', onchange: (e) => {
@@ -2444,12 +2466,13 @@ function drawMine(s) {
2444
2466
  const chip = (label, off, cls = '') => h('span', { className: 'chip ' + cls }, label, h('button', { type: 'button', textContent: '✕', 'aria-label': `remove ${label}`, onclick: off }))
2445
2467
  const line = h('div', { className: 'mt-line' },
2446
2468
  h('div', { className: 'mt-status' },
2447
- h('span', { className: 'count' }, filtered ? [h('b', { textContent: n(shown.length) }), ` of ${n(order.length)} shown`] : [h('b', { textContent: n(order.length) }), ` model${order.length === 1 ? '' : 's'}, in your order`]),
2469
+ h('span', { className: 'count' }, filtered ? [h('b', { textContent: n(shown.length) }), ` of ${n(order.length)} shown`] : [h('b', { textContent: n(order.length) }), ` model${order.length === 1 ? '' : 's'}${fit ? ', the order breaks ties' : ', in your order'}`]),
2448
2470
  ...filterChips().map(([label, off]) => chip(label, () => setFilter(off))),
2449
2471
  ...SORT.map(({ key, dir }, k) => chip(`${SORT.length > 1 ? `${k + 1}. ` : 'Sorted: '}${COLS[key].label} ${COLS[key].words[dir === 'up' ? 0 : 1]}`, () => setSort(SORT.filter((x) => x.key !== key)), 'sort')),
2450
2472
  testingAll && SORT.some((x) => x.key === 'works') ? h('span', { className: 'sort-live', textContent: 'tests running: the order moves as results come in' }) : null,
2451
2473
  filtering() || SORT.length ? h('button', { className: 'small ghost', textContent: 'Clear all', title: 'every filter and the sort off: your whole list, in your order', onclick: clearView }) : null),
2452
2474
  h('div', { className: 'mt-do' },
2475
+ h('button', { className: 'small', textContent: S.rankings ? 'Refresh rankings' : 'Get rankings', title: `${S.rankings ? `rankings from ${new Date(S.rankings.fetched).toLocaleDateString()}; ` : ''}each model's place in LMArena's public rankings (coding, web apps, vision): best fit picks by them, and gets them again once a week`, onclick: () => act('/api/rankings', {}, 'rankings updated') }),
2453
2476
  h('button', { className: 'small', textContent: filtered ? `Test ${n(shown.length)} shown` : 'Test all', disabled: testingAll || !shown.length, title: `send ${filtered ? 'the models shown' : 'each model'} a short message to see which really answer`, onclick: () => tryAll(filtered ? shown : order) }),
2454
2477
  h('button', { className: 'small primary', textContent: filtered ? `Use these ${n(view.length)}` : 'Save list', disabled: !view.length || order.length < 2, title: filtered ? `HeartCode uses only these ${n(view.length)}, in the order shown (the others stay under Providers)` : 'save the list in the order shown (#1 first)', onclick: saveList })))
2455
2478
 
@@ -2471,7 +2494,7 @@ function drawMine(s) {
2471
2494
  h('button', { className: 'small ghost', textContent: 'Invert', title: "select the ones shown that aren't selected, unselect the ones that are", onclick: () => (view.forEach((t) => (PICKED.has(keyOf(t)) ? PICKED.delete(keyOf(t)) : PICKED.add(keyOf(t)))), (lastPicked = null), drawMine(S)) }),
2472
2495
  h('button', { className: 'small ghost', textContent: 'Select none', onclick: () => (PICKED.clear(), drawMine(S)) })))
2473
2496
  : h('div', { className: 'mt mt-h' }, h('span'), selectAll,
2474
- h('span', { textContent: '#', title: 'its place in your list' }), head('model'), head('provider'), head('context', 'num'), head('tools', 'mid'), head('thinking', 'mid'), head('images', 'mid'), head('price', 'num'), head('works'), h('span', { className: 'num', textContent: '' }))
2497
+ h('span', { textContent: '#', title: 'its place in your list' }), head('model'), head('provider'), head('context', 'num'), head('tools', 'mid'), head('thinking', 'mid'), head('images', 'mid'), head('coding', 'num'), head('web', 'num'), head('vision', 'num'), head('price', 'num'), head('works'), h('span', { className: 'num', textContent: '' }))
2475
2498
  const table = view.length ? h('ol', { className: 'mtable' + (view.length < 2 ? '' : ' drag') }) : null
2476
2499
  // ticked or not; with Shift, every row from the last one ticked to this one
2477
2500
  const pick = (i, e) => {
@@ -2519,6 +2542,12 @@ function drawMine(s) {
2519
2542
  }
2520
2543
  // the table's cells: yes or no; where what it can do comes from
2521
2544
  const yes = (v) => h('span', { className: (v ? 'yes' : 'no') + ' mid', textContent: v ? '✓' : '–' })
2545
+ // its place in LMArena's ranking of that skill (#1 is the best of all models there); the top tenth stands out
2546
+ const RANK_OF = { coding: 'coding', web: 'web apps (WebDev)', vision: 'vision' }
2547
+ const rankCell = (t, k) => {
2548
+ const r = t.ranks?.[k]
2549
+ return h('span', { className: 'num rk' + (r && r.rank / r.of <= 0.1 ? ' top' : ''), textContent: r ? `#${r.rank}` : '–', title: r ? `#${r.rank} of ${r.of} models in LMArena's ${RANK_OF[k]} ranking (as "${r.as}")` : S.rankings ? `not in LMArena's ${RANK_OF[k]} ranking` : 'no rankings yet: Get rankings, above the list' })
2550
+ }
2522
2551
  const src = (t) => {
2523
2552
  const x = t.tested
2524
2553
  if (!x) return h('div', { className: 'src', textContent: 'looking it up…' })
@@ -2546,6 +2575,7 @@ function tableRow(t, at, pick) {
2546
2575
  h('span', { className: 'p', textContent: isOff(t.provider) ? `${t.provider} · off` : t.provider, title: t.provider }),
2547
2576
  h('span', { className: 'num', textContent: ctx ? `${t.tested?.sure === false ? '~' : ''}${kTok(ctx)}` : '–', title: ctx ? `${ctx.toLocaleString()} tokens${t.tested?.sure === false ? ' (assumed: the server and models.dev don\'t say)' : ''}` : '' }),
2548
2577
  yes(c.tools), yes(c.thinking), yes(c.images),
2578
+ rankCell(t, 'coding'), rankCell(t, 'web'), rankCell(t, 'vision'),
2549
2579
  h('span', { className: 'num price', textContent: priceOf(t), title: t.price ? `in ${money(t.price.input)} · out ${money(t.price.output)} per million tokens` : 'price not known' }),
2550
2580
  triedCell(t),
2551
2581
  h('span', { className: 'acts' },
@@ -2580,7 +2610,7 @@ function drawUsing(s) {
2580
2610
  // --- General ---
2581
2611
  const PERM_INFO = { all: ['Everything', 'Edits files and runs commands without asking'], commands: ['Edits only', 'Edits files; asks before running commands'], ask: ['Ask first', 'Asks before every edit and command'] }
2582
2612
  const THEME_INFO = { dark: ["Your terminal's background", ['#1f2328', '#d4d4d8', '#ff6b9d', '#7aa2f7']], light: ['White background', ['#fafbfc', '#24292f', '#d6336c', '#0969da']], midnight: ['Deep blue background', ['#1a1b26', '#c0caf5', '#ff7ab2', '#7aa2f7']], mono: ['No colors: bold and dim', ['#000000', '#bbbbbb', '#ffffff', '#777777']] }
2583
- const TOGGLE_INFO = { autoCompact: 'Compact long conversations', director: 'Let the model set things up', format: 'Format files after edits', lsp: 'Language server checks' }
2613
+ const TOGGLE_INFO = { autoCompact: 'Compact long conversations', director: 'Let the model set things up', format: 'Format files after edits', lsp: 'Language server checks', updateCheck: 'Check for updates' }
2584
2614
  function choices(id, list, cur, name) {
2585
2615
  put($(id), list.map(([v, title, desc, colors]) => h('label', { className: 'choice' + (v === cur ? ' on' : '') },
2586
2616
  h('input', { type: 'radio', name: id, checked: v === cur, onchange: () => act('/api/setting', { name, value: v }, `${title}: saved`) }),
@@ -2780,20 +2810,106 @@ async function clearAll() {
2780
2810
  api('/api/requests').then(({ items }) => ((REQS = items), drawReqs()), () => {})
2781
2811
  toast(`deleted: logs on disk now ${bytes(r.size.total)}`)
2782
2812
  }
2813
+ // The kinds of log: requests (their own viewer), then the text logs (choices.logKinds)
2814
+ const logKindsOf = (s) => ({ requests: { label: 'Requests', about: 'each request to a model and its reply or error: which failed, which worked, which fallback answered' }, ...s.choices.logKinds })
2783
2815
  function drawLogging(s) {
2784
2816
  drawDisk()
2785
- put($('l-run'), logSwitch(s, 'log', 'Keep a log of every run', `From now on: a folder per run in ${s.logs.runs}, a file per tab (tab-1.log, tab-2.log…).`))
2786
- put($('l-req'), logSwitch(s, 'logRequests', 'Log every request and reply', `Right away: a file per request in ${s.logs.requests}, a folder per run.`))
2787
- $('l-detail').value = s.settings.logDetail
2817
+ const on = s.settings.logs
2818
+ put($('l-kinds'), Object.entries(logKindsOf(s)).map(([k, { label, about }]) => h('label', { className: 'opt' },
2819
+ h('div', { className: 't' }, h('b', { textContent: label }), h('span', { textContent: about[0].toUpperCase() + about.slice(1) }),
2820
+ h('span', { className: 'file', textContent: k === 'requests' ? 'requests/<run>/ · a file per request' : `runs/<run>/${k}.log` }),
2821
+ k === 'requests' ? h('select', { disabled: !on.requests, 'aria-label': 'how much of each request', onchange: (e) => act('/api/setting', { name: 'logDetail', value: e.target.value }, 'saved: from the next request') },
2822
+ [['full', 'Everything: what was sent and what came back'], ['summary', 'Only a summary: model, result, error, timings, tokens']].map(([v, l]) => h('option', { value: v, textContent: l, selected: s.settings.logDetail === v }))) : null),
2823
+ sw({ checked: on[k], 'aria-label': label, onchange: (e) => act('/api/log-kind', { kind: k, on: e.target.checked }, `${label}: ${e.target.checked ? 'logged from now on' : 'off'}`) }))))
2824
+ $('l-alloff').disabled = !Object.values(on).some(Boolean)
2825
+ $('l-where').textContent = s.logs.runs.replace(/[\\/]runs$/, '')
2788
2826
  if (document.activeElement !== $('l-days')) $('l-days').value = s.settings.logDays
2789
- $('l-detail').disabled = !s.settings.logRequests
2827
+ drawViewTabs(s)
2790
2828
  }
2829
+ $('l-alloff').onclick = () => act('/api/log-kind', { all: false }, 'every log off')
2791
2830
  $('l-days').onchange = (e) => {
2792
2831
  const days = Number(e.target.value)
2793
2832
  if (!Number.isInteger(days) || days < 1) return toast('a whole number of days, 1 or more', true), (e.target.value = S.settings.logDays)
2794
2833
  act('/api/setting', { name: 'logDays', value: days }, `logs kept for ${days} day${days === 1 ? '' : 's'}; older ones deleted`)
2795
2834
  }
2796
- $('l-detail').onchange = (e) => act('/api/setting', { name: 'logDetail', value: e.target.value }, 'saved: from the next request')
2835
+
2836
+ // --- reading the logs: a tab per kind; the text ones by run, searched, followed live ---
2837
+ let VIEW = 'requests' // the kind shown
2838
+ let LOGRUN = null // its run ("day-month-year-…"), the newest when left out
2839
+ let LOGRUNS = [] // the runs that have this kind
2840
+ let LOGLINES = [] // its lines, as read
2841
+ let FIND = ''
2842
+ let LIVE = true
2843
+ function drawViewTabs(s) {
2844
+ put($('l-view'), Object.entries(logKindsOf(s)).map(([k, { label }]) => h('label', { className: VIEW === k ? 'on' : '' },
2845
+ h('input', { type: 'radio', name: 'l-view', value: k, checked: VIEW === k, onchange: () => ((VIEW = k), (LOGRUN = null), drawViewTabs(S), showView()) }), label)))
2846
+ }
2847
+ async function showView() {
2848
+ const req = VIEW === 'requests'
2849
+ $('l-filter').style.display = req ? '' : 'none'
2850
+ document.querySelector('#page-logging .reqs').style.display = req ? '' : 'none'
2851
+ $('l-text').hidden = req
2852
+ if (req) return put($('l-tools'))
2853
+ try {
2854
+ LOGRUNS = (await api('/api/log-runs')).runs.filter((r) => r.kinds[VIEW] !== undefined)
2855
+ } catch (e) {
2856
+ LOGRUNS = []
2857
+ }
2858
+ if (!LOGRUNS.some((r) => r.run === LOGRUN)) LOGRUN = LOGRUNS[0]?.run ?? null
2859
+ const cur = LOGRUNS.find((r) => r.run === LOGRUN)
2860
+ put($('l-tools'),
2861
+ LOGRUNS.length ? h('select', { 'aria-label': 'which run', onchange: (e) => ((LOGRUN = e.target.value), showView()) },
2862
+ LOGRUNS.map((r) => h('option', { value: r.run, selected: r.run === LOGRUN, textContent: `${r.current ? 'this run · ' : r.live ? 'running · ' : ''}${new Date(r.at).toLocaleString([], { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit' })} · ${bytes(r.kinds[VIEW])}` }))) : null,
2863
+ h('input', { type: 'search', id: 'l-find', placeholder: 'search this log', value: FIND, style: 'width:200px', oninput: (e) => ((FIND = e.target.value), drawText()) }),
2864
+ cur?.live ? h('label', { className: 'row', style: 'gap:6px;align-items:center', title: 'new lines come in as HeartCode writes them' }, h('input', { type: 'checkbox', checked: LIVE, onchange: (e) => (LIVE = e.target.checked) }), 'live') : null)
2865
+ await readText()
2866
+ }
2867
+ async function readText() {
2868
+ if (!LOGRUN) {
2869
+ LOGLINES = []
2870
+ return drawText()
2871
+ }
2872
+ try {
2873
+ const d = await api('/api/log-read', { run: LOGRUN, kind: VIEW })
2874
+ LOGLINES = d.text.split('\n').filter(Boolean)
2875
+ LOGLINES.cut = d.cut
2876
+ } catch (e) {
2877
+ LOGLINES = []
2878
+ }
2879
+ drawText()
2880
+ }
2881
+ // A line: "2026-11-02T10:00:00.000Z tab 2 [topic] text" (a long one goes on over several lines)
2882
+ function drawText() {
2883
+ const box = $('l-text')
2884
+ const atEnd = box.scrollHeight - box.scrollTop - box.clientHeight < 40
2885
+ const label = logKindsOf(S)[VIEW]?.label ?? VIEW
2886
+ if (!LOGLINES.length) return put(box, h('div', { className: 'empty', textContent: S.settings.logs[VIEW] ? `Nothing logged here yet: "${label}" lines show up as HeartCode writes them.` : `"${label}" is off: switch it on above, and its lines show up here from then on.` }))
2887
+ const groups = []
2888
+ for (const l of LOGLINES) if (/^\d{4}-\d\d-\d\dT/.test(l) || !groups.length) groups.push(l)
2889
+ else groups[groups.length - 1] += '\n' + l
2890
+ const find = FIND.trim().toLowerCase()
2891
+ const shown = (find ? groups.filter((g) => g.toLowerCase().includes(find)) : groups).slice(-3000)
2892
+ const mark = (text) => {
2893
+ if (!find) return [text]
2894
+ const out = []
2895
+ let i = 0
2896
+ for (let j; (j = text.toLowerCase().indexOf(find, i)) >= 0; i = j + find.length) out.push(text.slice(i, j), h('mark', { textContent: text.slice(j, j + find.length) }))
2897
+ return [...out, text.slice(i)]
2898
+ }
2899
+ put(box,
2900
+ LOGLINES.cut ? h('div', { className: 'muted', style: 'padding:4px 0 8px', textContent: 'Only the last part of a long log is shown: the whole file is on disk.' }) : null,
2901
+ shown.length ? shown.map((g) => {
2902
+ const m = /^(\S+?)T(\S+?)Z( tab \d+)? \[([\w-]+)\] ([\s\S]*)$/.exec(g)
2903
+ if (!m) return h('div', { className: 'ln' }, ...mark(g))
2904
+ return h('div', { className: `ln${/^(error|crash|warn)$/.test(m[4]) ? ' bad' : ''}` },
2905
+ h('span', { className: 'ts', textContent: `${new Date(`${m[1]}T${m[2]}Z`).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', second: '2-digit' })}${m[3] ?? ''} ` }), h('span', { className: 'tp', textContent: `[${m[4]}] ` }), ...mark(m[5]))
2906
+ }) : h('div', { className: 'empty', textContent: `No line has "${FIND}".` }))
2907
+ if (atEnd) box.scrollTop = box.scrollHeight // following the end, unless you scrolled up to read
2908
+ }
2909
+ setInterval(() => {
2910
+ if (page() !== 'logging' || VIEW === 'requests' || !LIVE || document.hidden) return
2911
+ if (LOGRUNS.find((r) => r.run === LOGRUN)?.live || !LOGRUN) readText().then(() => !LOGRUN && showView())
2912
+ }, 2000)
2797
2913
 
2798
2914
  let REQS = null // the requests logged, newest first
2799
2915
  let reqOpen = null // the one shown in full: "run/file"
@@ -2836,7 +2952,7 @@ function drawReqs() {
2836
2952
  const shown = REQS.filter(reqShown)
2837
2953
  const failed = REQS.filter((r) => r.result === 'failed').length
2838
2954
  $('n-failed').textContent = failed ? `${failed} failed` : ''
2839
- put($('l-list'), shown.length ? shown.map(reqRow) : h('div', { className: 'empty', textContent: REQS.length ? 'None of these.' : S?.settings.logRequests ? 'Nothing yet: requests show here as HeartCode sends them.' : 'Nothing logged. Switch on "Log every request and reply" above.' }))
2955
+ put($('l-list'), shown.length ? shown.map(reqRow) : h('div', { className: 'empty', textContent: REQS.length ? 'None of these.' : S?.settings.logs?.requests ? 'Nothing yet: requests show here as HeartCode sends them.' : 'Nothing logged. Switch on "Requests" above.' }))
2840
2956
  }
2841
2957
  async function openReq(r) {
2842
2958
  reqOpen = `${r.run}/${r.file}`
@@ -2928,7 +3044,7 @@ function drawMcp(s) {
2928
3044
  }
2929
3045
 
2930
3046
  // --- skills: a form (name, who uses it, what it's for, the prompt); SKILL.md is made from it ---
2931
- const USES = [['both', 'You and the model', 'type /skill:name, or the model uses it when it fits'], ['me', 'Only you', 'only when you type /skill:name'], ['model', 'Only the model', "when it fits; you don't type it"]]
3047
+ const USES = [['both', 'You and the model', 'type /skill:name, or the model uses it when it fits'], ['me', 'Only you', 'only when you type /skill:name'], ['model', 'Only the model', "when it fits; you don't type it"], ['always', 'Always on', 'in every message: how to work, not a task']]
2932
3048
  function parseSkill(text) {
2933
3049
  const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(text)
2934
3050
  const out = { description: '', use: 'both', extra: [], body: (m ? m[2] : text).replace(/^\s*\n/, '') }
@@ -3016,7 +3132,8 @@ async function openImport() {
3016
3132
 
3017
3133
  function drawSkills(s) {
3018
3134
  const mine = s.skills.filter((k) => k.mine)
3019
- const theirs = s.skills.filter((k) => !k.mine)
3135
+ const theirs = s.skills.filter((k) => !k.mine && !k.builtIn)
3136
+ const builtIn = s.skills.filter((k) => k.builtIn)
3020
3137
  const item = (k) => ({ id: k.name, title: '/skill:' + k.name, sub: k.description, k })
3021
3138
  const install = async () => {
3022
3139
  const url = $('k-url').value.trim()
@@ -3038,17 +3155,19 @@ function drawSkills(s) {
3038
3155
  if (e.key === 'Enter') install()
3039
3156
  }
3040
3157
  $('k-import').onclick = openImport
3041
- masterDetail('skills', $('k-items'), $('k-detail'), [{ title: mine.length && theirs.length ? 'Yours' : '', items: mine.map(item) }, { title: 'From projects', items: theirs.map(item) }], (x) => {
3158
+ masterDetail('skills', $('k-items'), $('k-detail'), [{ title: mine.length && (theirs.length || builtIn.length) ? 'Yours' : '', items: mine.map(item) }, { title: 'From projects', items: theirs.map(item) }, { title: 'Comes with HeartCode', items: builtIn.map(item) }], (x) => {
3042
3159
  if (!x) return h('div', { className: 'card' }, h('h2', { textContent: 'No skills yet' }), h('p', { className: 'sub', textContent: 'A skill is a prompt you use again and again, like "review this" or "write the release notes". Make one with + New skill, install one from GitHub above, or bring them from Claude Code and others with /import in HeartCode.' }))
3043
3160
  const k = x.k
3044
3161
  const f = skillForm(k.name, parseSkill(k.text), { readOnly: !k.mine })
3045
3162
  return h('div', { className: 'card' },
3046
- h('div', { className: 'row', style: 'justify-content:space-between;align-items:center' }, h('h2', { style: 'margin:0', className: 'mono', textContent: '/skill:' + k.name }), k.mine ? null : h('span', { className: 'tag', textContent: 'from a project: read only' })),
3163
+ h('div', { className: 'row', style: 'justify-content:space-between;align-items:center' }, h('h2', { style: 'margin:0', className: 'mono', textContent: '/skill:' + k.name }), k.mine ? null : h('span', { className: 'tag', textContent: k.builtIn ? 'comes with HeartCode: read only' : 'from a project: read only' })),
3047
3164
  f.el,
3048
3165
  k.mine ? h('div', { className: 'actions' },
3049
3166
  h('button', { className: 'primary', textContent: 'Save', onclick: () => saveItem('skills', k.name, '/api/skill', { name: k.name, was: k.name, text: skillText(f.d) }, `saved /skill:${k.name}`) }),
3050
3167
  h('span', { className: 'spacer' }),
3051
- h('button', { className: 'danger', textContent: 'Delete', onclick: () => confirm(`Delete the skill /skill:${k.name}?`) && saveItem('skills', k.name, '/api/skill/delete', { name: k.name }, `deleted /skill:${k.name}`) })) : null)
3168
+ h('button', { className: 'danger', textContent: 'Delete', onclick: () => confirm(`Delete the skill /skill:${k.name}?`) && saveItem('skills', k.name, '/api/skill/delete', { name: k.name }, `deleted /skill:${k.name}`) }))
3169
+ : k.builtIn ? h('div', { className: 'actions' },
3170
+ h('button', { textContent: 'Make my own copy', title: 'Saved with your skills under the same name, it replaces this one: change it, or set it to "Only you" to turn it off', onclick: () => saveItem('skills', k.name, '/api/skill', { name: k.name, text: k.text }, `/skill:${k.name} is yours now: change it here`) })) : null)
3052
3171
  })
3053
3172
  $('n-skills').textContent = s.skills.length || ''
3054
3173
  }
@@ -3180,6 +3299,9 @@ function sbSave() {
3180
3299
  }
3181
3300
 
3182
3301
  function render(s) {
3302
+ $('version').textContent = s.version ? `v${s.version}` : ''
3303
+ $('update-note').hidden = !s.update
3304
+ if (s.update) $('update-note').innerHTML = `⬆ <b>${s.update}</b> is out · type <code>/update</code> in HeartCode`
3183
3305
  if (s.prefs) {
3184
3306
  // the page's choices, as kept (also changed on another page: shown here too)
3185
3307
  const p = s.prefs