heartcode 0.1.37 → 0.1.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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 88px 88px 88px 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,10 @@
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 b { color: var(--text); font-weight: 600; margin-right: 5px; }
433
+ .mtable .rk.top b { color: inherit; }
434
+ .mtable .rk.top { color: var(--ok); font-weight: 600; }
416
435
  .mtable .m { font-family: var(--mono); font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
417
436
  .mtable .p { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
418
437
  .mtable .yes { color: var(--ok); }
@@ -481,20 +500,23 @@
481
500
  .sort-live { color: var(--warn); }
482
501
  /* Your models: the header's buttons, the list's settings, the toolbar (sticky), the table */
483
502
  .mt-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
484
- /* 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); }
486
- .mt-set { display: flex; flex-direction: column; gap: 6px; padding: 14px 18px; border-left: 1px solid var(--line); min-width: 0; }
487
- .mt-set:first-child { border-left: 0; }
488
- .mt-setl { font-size: 12px; font-weight: 600; color: var(--muted); }
503
+ .mt-sets { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
504
+ .mt-set { display: flex; align-items: center; gap: 8px; min-width: 0; }
505
+ .mt-setl { font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
489
506
  .mt-setc { display: flex; align-items: center; gap: 8px; }
490
- .mt-setc select { flex: 1; width: 100%; min-width: 0; height: 34px; }
491
- .mt-setc input[type=number] { width: 96px; height: 34px; }
507
+ .mt-setc select { width: auto; min-width: 0; height: 34px; padding-top: 0; padding-bottom: 0; line-height: 32px; }
508
+ .mt-setc input[type=number] { width: 64px; height: 34px; }
492
509
  .mt-setc input.tries { width: 64px; }
493
510
  .mt-setc .unit { color: var(--muted); font-size: 13px; }
494
511
  .mt-sets + .mt-tools { border-radius: 0; }
495
- .mt-line { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 16px; padding: 0 18px 12px; }
496
- .mt-status { flex: 1 1 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; min-height: 30px; font-size: 13px; color: var(--muted); }
497
- .mt-do { display: flex; align-items: center; gap: 8px; flex: none; }
512
+ .mt-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 18px; }
513
+ .mt-row .mt-filters, .mt-row .f-togs { display: contents; } /* filters, toggles and buttons flow as one line, wrapping only when it's full */
514
+ .mt-row .f-search { flex: 1 1 220px; }
515
+ .mt-line { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; font-size: 13px; color: var(--muted); }
516
+ .mt-line .count { white-space: nowrap; }
517
+ .mt-sets[inert], .mt-row[inert], .mt-hwrap[inert], .mt-actions[inert] { opacity: .5; transition: opacity .15s; }
518
+ .mt-row[inert] .sort-live { opacity: 1; }
519
+ .mt-line .count b { color: var(--text); }
498
520
  .mt-hpick .mt-pickbar { grid-column: 3 / -1; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
499
521
  .mt-hpick { background: var(--brand-soft); }
500
522
  .mt-h.mt-hpick .mt-pickbar button { display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-s); background: var(--panel) !important; color: var(--text); font-size: 12.5px; font-weight: 500; }
@@ -510,11 +532,6 @@
510
532
  .mt-filters select { height: 34px; width: auto; padding-top: 0; padding-bottom: 0; line-height: 32px; }
511
533
  .mt-filters select.on { border-color: var(--accent); background-color: color-mix(in srgb, var(--accent-soft) 50%, var(--input)); }
512
534
  .f-togs { display: inline-flex; gap: 6px; flex-wrap: wrap; }
513
- .mt-status .count b { color: var(--text); }
514
- .mt-status .chip { display: inline-flex; align-items: center; gap: 2px; border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); border-radius: 999px; padding: 2px 4px 2px 10px; color: var(--text); font-size: 12.5px; }
515
- .mt-status .chip.sort { border-color: var(--line-strong); background: var(--panel2); }
516
- .mt-status .chip button { border: 0; background: none; padding: 0 5px; font-size: 11px; color: var(--muted); border-radius: 999px; }
517
- .mt-status .chip button:hover { color: var(--text); background: var(--hover); }
518
535
  .mt-tools .mt-outcomes { border-bottom: 0; border-top: 1px solid var(--line); padding: 9px 18px; }
519
536
  .mt-hwrap { overflow: hidden; border-top: 1px solid var(--line); }
520
537
  .mt-hwrap .mt-h { border-bottom: 0; }
@@ -615,11 +632,8 @@
615
632
  nav a .count, .using, .nav-group { display: none; }
616
633
  .theme-btn { top: 10px; right: 12px; }
617
634
  .mt-tools { position: static; } /* a phone: too tall to stay in sight, it scrolls with the page */
618
- .mt-sets { grid-template-columns: minmax(0, 1fr); }
619
- .mt-set { border-left: 0; border-top: 1px solid var(--line); }
620
- .mt-set:first-child { border-top: 0; }
621
- .mt-do { width: 100%; }
622
- .mt-do button { flex: 1; }
635
+ .mt-line { width: 100%; }
636
+ .mt-line button.primary { margin-left: auto; }
623
637
  main { padding: 20px 16px 60px; }
624
638
  .steps { grid-template-columns: 1fr; }
625
639
  .choices, .choices.three { grid-template-columns: 1fr; }
@@ -741,7 +755,8 @@
741
755
  <body>
742
756
  <div class="app">
743
757
  <aside>
744
- <div class="brand"><span>♥</span> HeartCode <small>settings</small></div>
758
+ <div class="brand"><span>♥</span> HeartCode <small>settings <span id="version"></span></small></div>
759
+ <div class="update-note" id="update-note" hidden></div>
745
760
  <nav id="nav">
746
761
  <div class="nav-group" role="separator"></div>
747
762
  <a href="#models" data-page="models" data-tabs="models providers"><span class="ic">☰</span> Models <span class="count" id="n-mine"></span></a>
@@ -786,7 +801,7 @@
786
801
 
787
802
  <!-- Your models: all at once, sortable -->
788
803
  <section class="page" id="page-models">
789
- <div class="head"><div><h1>Your models</h1><p class="lead">HeartCode uses #1, and the next one when it fails. Filter, sort or drag, then Save list.</p></div><div class="mt-actions" id="mt-actions"></div></div>
804
+ <div class="head"><div><h1>Your models</h1><p class="lead" id="mt-lead"></p></div><div class="mt-actions" id="mt-actions"></div></div>
790
805
  <div class="card mt-card" id="mt"></div>
791
806
  </section>
792
807
 
@@ -815,36 +830,22 @@
815
830
  <section class="page" id="page-logging">
816
831
  <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
832
  <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>
833
+ <div class="kinds-top">
834
+ <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>
835
+ <button class="small" id="l-alloff">All off</button>
837
836
  </div>
837
+ <div class="kinds" id="l-kinds"></div>
838
838
  <div class="log-days">
839
839
  <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">
840
+ <input type="number" id="l-days" min="1" max="3650" step="1" value="3">
841
841
  <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>
842
+ <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
843
  </div>
844
844
  </div>
845
845
  <div class="card reqs-card">
846
846
  <div class="reqs-top">
847
- <h2 style="margin:0">Requests logged</h2>
847
+ <div class="seg" id="l-view"></div>
848
+ <div id="l-tools" style="display:flex;gap:8px;align-items:center;flex-wrap:wrap"></div>
848
849
  <div class="seg" id="l-filter">
849
850
  <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
851
  </div>
@@ -854,6 +855,7 @@
854
855
  <div class="req-list" id="l-list"></div>
855
856
  <div class="req-detail" id="l-detail-pane"><div class="empty">Click a request to see it in full.</div></div>
856
857
  </div>
858
+ <div class="logtext" id="l-text" hidden></div>
857
859
  </div>
858
860
  </section>
859
861
 
@@ -1061,7 +1063,7 @@
1061
1063
  </dialog>
1062
1064
  <dialog id="pr" aria-labelledby="pr-title">
1063
1065
  <form>
1064
- <h2 id="pr-title">Provider ranking</h2>
1066
+ <h2 id="pr-title">Order providers</h2>
1065
1067
  <p class="sub">Drag the providers into order, best first. Your models are then sorted by it.</p>
1066
1068
  <ol id="pr-list"></ol>
1067
1069
  <div class="actions"><button id="pr-cancel" type="button">Cancel</button><button class="primary" id="pr-save" type="button">Save</button></div>
@@ -1297,6 +1299,7 @@ const DOING = {
1297
1299
  '/api/telegram/connect': 'Checking the token with Telegram',
1298
1300
  '/api/telegram/test': 'Sending a test message',
1299
1301
  '/api/search/test': 'Trying a search on your SearXNG',
1302
+ '/api/rankings': null, // with models.dev, in its strip
1300
1303
  '/api/models-dev': null, // its own strip
1301
1304
  }
1302
1305
  let acting = 0
@@ -1688,6 +1691,9 @@ async function tryModel(t) {
1688
1691
  return r
1689
1692
  }
1690
1693
  let testingAll = false // a run is going (on the server)
1694
+ let lookingUp = false // Update model info is going
1695
+ // while either goes, the list holds still: no filtering, sorting, dragging, selecting or changing rows
1696
+ const locked = () => testingAll || lookingUp
1691
1697
  // a run of tests: all your models, or the ones given
1692
1698
  async function tryAll(only) {
1693
1699
  if (testingAll) return toast('a test is running: wait for it, or stop it', true)
@@ -1707,7 +1713,9 @@ function gotResult(key, result) {
1707
1713
  // the run, as the server says it is: its progress strip, and the models waiting marked as testing
1708
1714
  function showRun(run) {
1709
1715
  for (const key of run?.pending ?? []) if (!TRIES[key]?.going) TRIES[key] = { going: true, before: TRIES[key] } // its last result, kept if it isn't reached
1716
+ const was = testingAll
1710
1717
  testingAll = Boolean(run && !run.over)
1718
+ if (was !== testingAll) mineSoon() // the list locked or unlocked
1711
1719
  if (!testingAll) {
1712
1720
  for (const [key, r] of Object.entries(TRIES)) if (r.going) r.before ? (TRIES[key] = r.before) : delete TRIES[key] // stopped before it: as it was
1713
1721
  job('test-all')
@@ -1723,13 +1731,15 @@ function showRun(run) {
1723
1731
  mineSoon()
1724
1732
  }
1725
1733
 
1726
- // models.dev looked up again: one model (its Retry), or all of yours (Refresh from models.dev)
1734
+ // models.dev looked up again: one model (its Retry), or all of yours with their scores (Update model info)
1727
1735
  const retry = (t) => h('button', { className: 'small', textContent: 'Retry', title: 'look it up in models.dev again', onclick: (e) => (e.stopPropagation(), lookUp(t)) })
1728
1736
  async function lookUp(t) {
1729
- job('models.dev', { where: ['catalog', 'table'], what: t ? `Looking up ${t.model} in models.dev` : 'Asking models.dev about your models', detail: 'context, tool calls, thinking, images' })
1730
- const r = await act('/api/models-dev', t ? { provider: t.provider, model: t.model } : {})
1737
+ job('models.dev', { where: ['catalog', 'table'], what: t ? `Looking up ${t.model} in models.dev` : 'Updating your models: models.dev and LMArena', detail: t ? 'context, tool calls, thinking, images' : 'context, tool calls, thinking, images, price; scores' })
1738
+ if (!t) (lookingUp = true), mineSoon()
1739
+ const [r, scored] = await Promise.all([act('/api/models-dev', t ? { provider: t.provider, model: t.model } : {}), t ? null : act('/api/rankings', {})])
1740
+ if (!t) (lookingUp = false), mineSoon()
1731
1741
  job('models.dev')
1732
- if (r) toast(t ? (r.found ? `${t.model}: found in models.dev` : `${t.model}: still not in models.dev`) : `models.dev: ${r.found} of ${r.of} found`)
1742
+ if (r) toast(t ? (r.found ? `${t.model}: found in models.dev` : `${t.model}: still not in models.dev`) : `models.dev: ${r.found} of ${r.of} found${scored ? ' · scores updated' : ''}`)
1733
1743
  return r
1734
1744
  }
1735
1745
 
@@ -1825,7 +1835,7 @@ function drawProviders(s) {
1825
1835
  const shown = shownOrder()
1826
1836
  $('p-mine').hidden = !shown.length
1827
1837
  $('p-mine').textContent = `Your models (${shown.length}) →`
1828
- $('p-mine').title = shown.length ? `HeartCode uses ${shown[0].provider} · ${shown[0].model}. Open the Your models page: the order, tests, and what happens when one fails` : ''
1838
+ $('p-mine').title = shown.length ? `${S.settings.modelChoice === 'fit' ? 'HeartCode picks the best of them for each task' : `HeartCode uses ${shown[0].provider} · ${shown[0].model}`}. Open the Your models page: the order, tests, and what happens when one fails` : ''
1829
1839
  fillHeight()
1830
1840
 
1831
1841
  // every provider's models, A to Z; one click adds it (the first one becomes #1). Built
@@ -1853,7 +1863,7 @@ function sortable(v, onMove) {
1853
1863
  const scrolled = () => (scroller === window ? scrollY : scroller.scrollTop)
1854
1864
  box.addEventListener('pointerdown', (e) => {
1855
1865
  const li = e.target.closest('li.in')
1856
- if (!li || e.button !== 0 || e.target.closest('button, a, input, select, textarea')) return
1866
+ if (!li || e.button !== 0 || e.target.closest('button, a, input, select, textarea') || !box.classList.contains('drag')) return
1857
1867
  if (e.pointerType !== 'mouse' && !e.target.closest('.grip')) return // a finger scrolls the list, except on the grip
1858
1868
  const n = v.items
1859
1869
  const from = Number(li.dataset.i)
@@ -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
@@ -2278,7 +2290,7 @@ function sorted(order) {
2278
2290
  }
2279
2291
  const dirText = (key, dir) => COLS[key].words[dir === 'up' ? 0 : 1] + (key === 'works' ? ' (then not tested, then not working)' : '')
2280
2292
  // Filters on the Your models page: which models are shown (and tested by "Test N shown", counted,
2281
- // sorted, selected by "select all", saved first by Save list). Combined: a model shows when it passes
2293
+ // sorted, selected by "select all", saved first by Save order). Combined: a model shows when it passes
2282
2294
  // all of them. Kept with the page's choices.
2283
2295
  const NO_FILTER = { text: '', provider: '', works: '', context: 0, tools: false, thinking: false, images: false, free: false }
2284
2296
  let FILTER = { ...NO_FILTER }
@@ -2308,19 +2320,7 @@ const setFilter = (change) => {
2308
2320
  savePref('filters', FILTER)
2309
2321
  drawMine(S)
2310
2322
  }
2311
- const RESULT_NAME = (w) => (w === 'works' ? '✓ works' : w === 'fails' ? "✗ doesn't work" : w === 'untested' ? 'not tested' : `✗ ${w}`)
2312
2323
  const CONTEXTS = [[0, 'Any context'], [32_000, '32k+'], [128_000, '128k+'], [200_000, '200k+'], [1_000_000, '1M+']]
2313
- // the active filters, as chips to take off one by one
2314
- const filterChips = () => [
2315
- FILTER.text && [`“${FILTER.text}”`, { text: '' }],
2316
- FILTER.provider && [`Provider: ${FILTER.provider}`, { provider: '' }],
2317
- FILTER.works && [`Result: ${RESULT_NAME(FILTER.works)}`, { works: '' }],
2318
- FILTER.context && [`Context ${CONTEXTS.find(([v]) => v === FILTER.context)?.[1] ?? FILTER.context}`, { context: 0 }],
2319
- FILTER.tools && ['Tools', { tools: false }],
2320
- FILTER.thinking && ['Thinking', { thinking: false }],
2321
- FILTER.images && ['Images', { images: false }],
2322
- FILTER.free && ['Free', { free: false }],
2323
- ].filter(Boolean)
2324
2324
  const clearView = () => {
2325
2325
  SORT = []
2326
2326
  savePref('sorts', SORT)
@@ -2402,7 +2402,7 @@ function drawMine(s) {
2402
2402
  slots.forEach((k, m) => (all[k] = list[m]))
2403
2403
  return keep(all, true)
2404
2404
  }
2405
- // Save list: the models HeartCode uses become the ones shown, in the order shown. Filtered: only
2405
+ // Save order: the models HeartCode uses become the ones shown, in the order shown. Filtered: only
2406
2406
  // those (asked first; the others stay under Providers, to add back any time)
2407
2407
  const saveList = () => {
2408
2408
  if (filtered && !confirm(`HeartCode will use only these ${n(view.length)}, in this order.\n\nThe other ${n(order.length - view.length)} stay under Providers: add any back whenever you like.`)) return
@@ -2417,41 +2417,53 @@ function drawMine(s) {
2417
2417
  }
2418
2418
  const pickedList = order.filter((t) => PICKED.has(keyOf(t)))
2419
2419
 
2420
- // --- the page's header, right: what's known about the models ---
2420
+ // --- the page's header: how a model is picked (left), what's known about the models (right) ---
2421
+ $('mt-lead').textContent = S.settings.modelChoice === 'fit'
2422
+ ? 'Each message goes to the models that score best for it. Your order breaks ties, and decides among models with no score. Filter, sort or drag, then Save order.'
2423
+ : 'HeartCode uses #1, and the next one when it fails. Filter, sort or drag, then Save order.'
2424
+ const busy = locked()
2425
+ $('mt-actions').inert = busy
2421
2426
  put($('mt-actions'),
2422
- 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
- 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() }))
2427
+ ((why) => h('span', { title: why ?? '' }, h('button', { className: 'small', textContent: 'Order providers', disabled: Boolean(why), title: why ? '' : 'drag your providers into order; the Provider column sorts by it', onclick: openRanking })))( // disabled: why, on a span (a disabled button shows no tooltip in every browser)
2428
+ S.settings.modelChoice === 'fit' ? 'Not used while Pick is "the best for each task": each message gets the models ranked best for it, whatever their provider. Pick "in your order" to use it'
2429
+ : !order.some((t) => t.provider !== order[0]?.provider) ? 'All your models are from one provider: nothing to order' : null),
2430
+ h('button', { className: 'small', textContent: 'Update model info', disabled: !order.length, title: `what each model can do (context, tools, thinking, images, price) from models.dev, and its scores in LMArena's public rankings (coding, web apps, vision${S.rankings ? `; scores from ${new Date(S.rankings.fetched).toLocaleDateString()}` : ''}). Best fit also gets the scores again once a week`, onclick: () => lookUp() }))
2424
2431
 
2425
- // --- the list's settings: three cells across, a label over each control ---
2432
+ // --- the list's settings: one line, a short label beside each control ---
2426
2433
  const ro = s.rotation
2427
2434
  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))
2428
- const settings = h('div', { className: 'mt-sets' },
2429
- 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",
2435
+ const fit = S.settings.modelChoice === 'fit'
2436
+ const settings = h('div', { className: 'mt-sets', inert: busy },
2437
+ cell('Pick', 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',
2438
+ 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') },
2439
+ [['order', 'in your order'], ['fit', 'the best for each task']].map(([v, t]) => h('option', { value: v, textContent: t, selected: S.settings.modelChoice === v })))),
2440
+ cell('If one 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
2441
  h('select', { onchange: (e) => saveOrder(S.order, 'saved', { on: e.target.value }) },
2431
- [['failure', 'the next one answers'], ['retries', 'try it again first']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.on === v }))),
2442
+ [['failure', 'go to the next'], ['retries', 'retry it first']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.on === v }))),
2432
2443
  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 }) },
2435
- [['first', '#1'], ['stay', 'the last that answered']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.next === v })))),
2436
- cell('A test waits for an answer', 'every model test: Test, Test all, Request',
2444
+ cell('Give up after', "a model that hasn't started answering (text, thinking or a tool call) in this many seconds counts as failed: the next one answers",
2445
+ 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) => {
2446
+ const v = Math.round(Number(e.target.value))
2447
+ if (!(v >= 5 && v <= 600)) return (e.target.value = S.settings.replyStart ?? 60), toast('a whole number of seconds, 5 to 600', true)
2448
+ act('/api/setting', { name: 'replyStart', value: v }, `a model that hasn't started answering in ${v}s counts as failed`)
2449
+ } }), h('span', { className: 'unit', textContent: 'seconds of silence' })),
2450
+ cell('New message to', fit ? 'best fit picks it for each message' : 'the model a new message goes to first',
2451
+ h('select', { disabled: fit, onchange: (e) => saveOrder(S.order, 'saved', { next: e.target.value }) },
2452
+ [['first', '#1'], ['stay', 'the last that worked']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.next === v })))),
2453
+ cell('Tests wait', 'every model test: Test, Test all, Request',
2437
2454
  h('input', { type: 'number', min: 1, max: 600, step: 1, value: S.settings.testTimeout ?? 10, 'aria-label': 'Test timeout in seconds', onchange: (e) => {
2438
2455
  const v = Math.round(Number(e.target.value))
2439
2456
  if (!(v >= 1 && v <= 600)) return (e.target.value = S.settings.testTimeout ?? 10), toast('a whole number of seconds, 1 to 600', true)
2440
2457
  act('/api/setting', { name: 'testTimeout', value: v }, `tests wait ${v} second${v === 1 ? '' : 's'} for an answer`)
2441
2458
  } }), h('span', { className: 'unit', textContent: 'seconds' })))
2442
2459
 
2443
- // --- under the filters: what's shown (left) · what you do with it (right) ---
2444
- const chip = (label, off, cls = '') => h('span', { className: 'chip ' + cls }, label, h('button', { type: 'button', textContent: '✕', 'aria-label': `remove ${label}`, onclick: off }))
2460
+ // --- beside the filters: what's shown · what you do with it (the sorts show in the column heads) ---
2445
2461
  const line = h('div', { className: 'mt-line' },
2446
- 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`]),
2448
- ...filterChips().map(([label, off]) => chip(label, () => setFilter(off))),
2449
- ...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
- testingAll && SORT.some((x) => x.key === 'works') ? h('span', { className: 'sort-live', textContent: 'tests running: the order moves as results come in' }) : null,
2451
- 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
- h('div', { className: 'mt-do' },
2453
- 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
- 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 })))
2462
+ h('span', { className: 'count', title: SORT.length ? `sorted by ${SORT.map(({ key, dir }) => `${COLS[key].label} ${COLS[key].words[dir === 'up' ? 0 : 1]}`).join(', then ')}; ties keep your order` : '' }, filtered ? [h('b', { textContent: n(shown.length) }), ` of ${n(order.length)}`] : [h('b', { textContent: n(order.length) }), ` model${order.length === 1 ? '' : 's'}`]),
2463
+ busy ? h('span', { className: 'sort-live', textContent: `${testingAll ? 'testing' : 'updating'}: filters and changes wait until it's done (or Stop)` }) : null,
2464
+ filtering() || SORT.length ? h('button', { className: 'small ghost', textContent: 'Clear', title: 'every filter and the sort off: your whole list, in your order', onclick: clearView }) : null,
2465
+ h('button', { className: 'small', textContent: filtered ? `Test ${n(shown.length)}` : '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) }),
2466
+ h('button', { className: 'small primary', textContent: filtered ? `Use only these ${n(view.length)}` : 'Save order', disabled: !view.length || order.length < 2, title: filtered ? `HeartCode uses only these ${n(view.length)}, in the order shown (the others stay under Providers)` : S.settings.modelChoice === 'fit' ? 'keep the order shown: it breaks ties between equally scored models' : 'HeartCode uses them in the order shown (#1 first)', onclick: saveList }))
2455
2467
 
2456
2468
  // --- the table ---
2457
2469
  const all = view.length > 0 && view.every((t) => PICKED.has(keyOf(t)))
@@ -2471,8 +2483,8 @@ function drawMine(s) {
2471
2483
  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
2484
  h('button', { className: 'small ghost', textContent: 'Select none', onclick: () => (PICKED.clear(), drawMine(S)) })))
2473
2485
  : 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: '' }))
2475
- const table = view.length ? h('ol', { className: 'mtable' + (view.length < 2 ? '' : ' drag') }) : null
2486
+ 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: '' }))
2487
+ const table = view.length ? h('ol', { className: 'mtable' + (view.length < 2 || busy ? '' : ' drag') }) : null
2476
2488
  // ticked or not; with Shift, every row from the last one ticked to this one
2477
2489
  const pick = (i, e) => {
2478
2490
  const on = !PICKED.has(keyOf(view[i]))
@@ -2501,10 +2513,9 @@ function drawMine(s) {
2501
2513
  order.length > 1 ? settings : null,
2502
2514
  order.length
2503
2515
  ? h('div', { className: 'mt-tools' },
2504
- filterBarOf(order, results),
2505
- line,
2516
+ h('div', { className: 'mt-row', inert: busy }, filterBarOf(order, results), line),
2506
2517
  (tableJobs ??= jobSlot('table')), // the same one every time: its Stop button isn't replaced under the mouse
2507
- view.length ? h('div', { className: 'mt-hwrap' }, header) : null)
2518
+ view.length ? h('div', { className: 'mt-hwrap', inert: busy }, header) : null)
2508
2519
  : null,
2509
2520
  order.length
2510
2521
  ? h('div', { className: 'mt-scroll', onscroll: (e) => { const hw = e.target.closest('.card')?.querySelector('.mt-hwrap'); if (hw) hw.scrollLeft = e.target.scrollLeft } }, h('div', { className: 'mt' },
@@ -2519,6 +2530,14 @@ function drawMine(s) {
2519
2530
  }
2520
2531
  // the table's cells: yes or no; where what it can do comes from
2521
2532
  const yes = (v) => h('span', { className: (v ? 'yes' : 'no') + ' mid', textContent: v ? '✓' : '–' })
2533
+ // its score and place in LMArena's ranking of that skill (#1 is the best of all models there); the top tenth stands out
2534
+ const RANK_OF = { coding: 'coding', web: 'web apps (WebDev)', vision: 'vision' }
2535
+ const rankCell = (t, k) => {
2536
+ const r = t.ranks?.[k]
2537
+ if (!r) return h('span', { className: 'num rk', textContent: '–', title: S.rankings ? `not in LMArena's ${RANK_OF[k]} ranking` : 'no scores yet: Update model info, at the top' })
2538
+ return h('span', { className: 'num rk' + (r.rank / r.of <= 0.1 ? ' top' : ''), title: `${r.score != null ? `score ${r.score}${r.votes ? ` from ${r.votes.toLocaleString()} votes` : ''}, ` : ''}#${r.rank} of ${r.of} models in LMArena's ${RANK_OF[k]} ranking (as "${r.as}")${r.score == null ? '. Update model info for the scores' : ''}` },
2539
+ r.score != null ? h('b', { textContent: r.score }) : '', `#${r.rank}`)
2540
+ }
2522
2541
  const src = (t) => {
2523
2542
  const x = t.tested
2524
2543
  if (!x) return h('div', { className: 'src', textContent: 'looking it up…' })
@@ -2538,21 +2557,23 @@ function tableRow(t, at, pick) {
2538
2557
  : x.source === 'assumed' ? h('button', { type: 'button', className: 'tag warn', textContent: 'unknown', title: "models.dev doesn't know it: what it can do is a guess. Click to set it up", onclick: () => openSetup(t) })
2539
2558
  : Object.keys(x.set ?? {}).length ? h('button', { type: 'button', className: 'tag', textContent: 'edited', title: 'what it can do: set by you (click to change)', onclick: () => openSetup(t) }) : null
2540
2559
  const going = Boolean(TRIES[keyOf(t)]?.going)
2560
+ const busy = locked()
2541
2561
  return h('li', { className: 'in' + (picked ? ' picked' : '') + (isOff(t.provider) ? ' off' : ''), 'data-key': `${t.provider}/${t.model}`, title: isOff(t.provider) ? `${t.provider} is switched off: HeartCode skips this model until it's on` : '' },
2542
2562
  h('span', { className: 'grip', textContent: '⋮⋮', 'aria-hidden': 'true' }),
2543
- h('input', { type: 'checkbox', checked: picked, 'aria-label': `select ${t.model}`, title: 'select (Shift: and every row up to the last one selected)', onclick: (e) => (e.preventDefault(), pick(e)) }),
2563
+ h('input', { type: 'checkbox', checked: picked, disabled: busy, 'aria-label': `select ${t.model}`, title: 'select (Shift: and every row up to the last one selected)', onclick: (e) => (e.preventDefault(), pick(e)) }),
2544
2564
  h('span', { className: 'n', textContent: `#${at + 1}`, title: SORT.length || filtering() ? 'its place in your list' : '' }),
2545
2565
  h('span', { className: 'm' }, h('span', { className: 'name', textContent: t.model, title: t.model }), tag),
2546
2566
  h('span', { className: 'p', textContent: isOff(t.provider) ? `${t.provider} · off` : t.provider, title: t.provider }),
2547
2567
  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
2568
  yes(c.tools), yes(c.thinking), yes(c.images),
2569
+ rankCell(t, 'coding'), rankCell(t, 'web'), rankCell(t, 'vision'),
2549
2570
  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
2571
  triedCell(t),
2551
2572
  h('span', { className: 'acts' },
2552
- h('button', { type: 'button', className: 'small ghost ib k-test row-test', disabled: going, title: going ? 'testing…' : 'Test: send it a short message to see that it really answers', 'aria-label': `test ${t.model}`, onclick: () => tryModel(t) }, ic(going ? 'clock' : 'play')),
2573
+ h('button', { type: 'button', className: 'small ghost ib k-test row-test', disabled: going || busy, title: going ? 'testing…' : 'Test: send it a short message to see that it really answers', 'aria-label': `test ${t.model}`, onclick: () => tryModel(t) }, ic(going ? 'clock' : 'play')),
2553
2574
  h('button', { type: 'button', className: 'small ghost ib k-info', title: 'Request: send it "Hello" and see exactly what was sent and what came back', 'aria-label': `raw request to ${t.model}`, onclick: () => hello(t.provider, t.model) }, ic('eye')),
2554
- h('button', { type: 'button', className: 'small ghost ib k-edit', title: 'Edit what it can do: context, tool calls, thinking, images (or look it up in models.dev again)', 'aria-label': `edit ${t.model}`, onclick: () => openSetup(t) }, ic('pencil')),
2555
- h('button', { type: 'button', className: 'small ghost ib k-del', title: 'Remove it from your list (it stays under its provider)', 'aria-label': `remove ${t.model}`, onclick: () => removeMine(t.provider, t.model) }, ic('trash'))))
2575
+ h('button', { type: 'button', className: 'small ghost ib k-edit', disabled: busy, title: 'Edit what it can do: context, tool calls, thinking, images (or look it up in models.dev again)', 'aria-label': `edit ${t.model}`, onclick: () => openSetup(t) }, ic('pencil')),
2576
+ h('button', { type: 'button', className: 'small ghost ib k-del', disabled: busy, title: 'Remove it from your list (it stays under its provider)', 'aria-label': `remove ${t.model}`, onclick: () => removeMine(t.provider, t.model) }, ic('trash'))))
2556
2577
  }
2557
2578
 
2558
2579
  // your list changed: the rows and counts it touches, in place
@@ -2574,13 +2595,15 @@ function markCatalog() {
2574
2595
  function drawUsing(s) {
2575
2596
  const o = s.order.filter((t) => !isOff(t.provider))
2576
2597
  $('using').hidden = page() === 'providers' // there it's on the page itself
2577
- put($('using'), o.length ? [h('span', { className: 'k', textContent: 'HeartCode uses' }), h('b', { textContent: o[0].model }), h('span', { className: 'k', textContent: `${o[0].provider}${o.length > 1 ? ` · ${o.length - 1} fallback${o.length > 2 ? 's' : ''}` : ''}` })] : s.order.length ? [h('span', { className: 'k', textContent: 'The providers of all your models are switched off' }), h('a', { href: '#providers', textContent: 'Switch one on' })] : [h('span', { className: 'k', textContent: 'No model chosen yet' }), h('a', { href: '#providers', textContent: 'Choose one' })])
2598
+ const fit = s.settings.modelChoice === 'fit' // best fit: no one model is "the one"
2599
+ put($('using'), o.length && fit ? [h('span', { className: 'k', textContent: 'HeartCode picks' }), h('b', { textContent: 'the best for each task' }), h('span', { className: 'k', textContent: `from your ${o.length.toLocaleString()} model${o.length > 1 ? 's' : ''}` })]
2600
+ : o.length ? [h('span', { className: 'k', textContent: 'HeartCode uses' }), h('b', { textContent: o[0].model }), h('span', { className: 'k', textContent: `${o[0].provider}${o.length > 1 ? ` · ${o.length - 1} fallback${o.length > 2 ? 's' : ''}` : ''}` })] : s.order.length ? [h('span', { className: 'k', textContent: 'The providers of all your models are switched off' }), h('a', { href: '#providers', textContent: 'Switch one on' })] : [h('span', { className: 'k', textContent: 'No model chosen yet' }), h('a', { href: '#providers', textContent: 'Choose one' })])
2578
2601
  }
2579
2602
 
2580
2603
  // --- General ---
2581
2604
  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
2605
  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' }
2606
+ 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
2607
  function choices(id, list, cur, name) {
2585
2608
  put($(id), list.map(([v, title, desc, colors]) => h('label', { className: 'choice' + (v === cur ? ' on' : '') },
2586
2609
  h('input', { type: 'radio', name: id, checked: v === cur, onchange: () => act('/api/setting', { name, value: v }, `${title}: saved`) }),
@@ -2780,20 +2803,106 @@ async function clearAll() {
2780
2803
  api('/api/requests').then(({ items }) => ((REQS = items), drawReqs()), () => {})
2781
2804
  toast(`deleted: logs on disk now ${bytes(r.size.total)}`)
2782
2805
  }
2806
+ // The kinds of log: requests (their own viewer), then the text logs (choices.logKinds)
2807
+ 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
2808
  function drawLogging(s) {
2784
2809
  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
2810
+ const on = s.settings.logs
2811
+ put($('l-kinds'), Object.entries(logKindsOf(s)).map(([k, { label, about }]) => h('label', { className: 'opt' },
2812
+ h('div', { className: 't' }, h('b', { textContent: label }), h('span', { textContent: about[0].toUpperCase() + about.slice(1) }),
2813
+ h('span', { className: 'file', textContent: k === 'requests' ? 'requests/<run>/ · a file per request' : `runs/<run>/${k}.log` }),
2814
+ 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') },
2815
+ [['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),
2816
+ 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'}`) }))))
2817
+ $('l-alloff').disabled = !Object.values(on).some(Boolean)
2818
+ $('l-where').textContent = s.logs.runs.replace(/[\\/]runs$/, '')
2788
2819
  if (document.activeElement !== $('l-days')) $('l-days').value = s.settings.logDays
2789
- $('l-detail').disabled = !s.settings.logRequests
2820
+ drawViewTabs(s)
2790
2821
  }
2822
+ $('l-alloff').onclick = () => act('/api/log-kind', { all: false }, 'every log off')
2791
2823
  $('l-days').onchange = (e) => {
2792
2824
  const days = Number(e.target.value)
2793
2825
  if (!Number.isInteger(days) || days < 1) return toast('a whole number of days, 1 or more', true), (e.target.value = S.settings.logDays)
2794
2826
  act('/api/setting', { name: 'logDays', value: days }, `logs kept for ${days} day${days === 1 ? '' : 's'}; older ones deleted`)
2795
2827
  }
2796
- $('l-detail').onchange = (e) => act('/api/setting', { name: 'logDetail', value: e.target.value }, 'saved: from the next request')
2828
+
2829
+ // --- reading the logs: a tab per kind; the text ones by run, searched, followed live ---
2830
+ let VIEW = 'requests' // the kind shown
2831
+ let LOGRUN = null // its run ("day-month-year-…"), the newest when left out
2832
+ let LOGRUNS = [] // the runs that have this kind
2833
+ let LOGLINES = [] // its lines, as read
2834
+ let FIND = ''
2835
+ let LIVE = true
2836
+ function drawViewTabs(s) {
2837
+ put($('l-view'), Object.entries(logKindsOf(s)).map(([k, { label }]) => h('label', { className: VIEW === k ? 'on' : '' },
2838
+ h('input', { type: 'radio', name: 'l-view', value: k, checked: VIEW === k, onchange: () => ((VIEW = k), (LOGRUN = null), drawViewTabs(S), showView()) }), label)))
2839
+ }
2840
+ async function showView() {
2841
+ const req = VIEW === 'requests'
2842
+ $('l-filter').style.display = req ? '' : 'none'
2843
+ document.querySelector('#page-logging .reqs').style.display = req ? '' : 'none'
2844
+ $('l-text').hidden = req
2845
+ if (req) return put($('l-tools'))
2846
+ try {
2847
+ LOGRUNS = (await api('/api/log-runs')).runs.filter((r) => r.kinds[VIEW] !== undefined)
2848
+ } catch (e) {
2849
+ LOGRUNS = []
2850
+ }
2851
+ if (!LOGRUNS.some((r) => r.run === LOGRUN)) LOGRUN = LOGRUNS[0]?.run ?? null
2852
+ const cur = LOGRUNS.find((r) => r.run === LOGRUN)
2853
+ put($('l-tools'),
2854
+ LOGRUNS.length ? h('select', { 'aria-label': 'which run', onchange: (e) => ((LOGRUN = e.target.value), showView()) },
2855
+ 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,
2856
+ h('input', { type: 'search', id: 'l-find', placeholder: 'search this log', value: FIND, style: 'width:200px', oninput: (e) => ((FIND = e.target.value), drawText()) }),
2857
+ 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)
2858
+ await readText()
2859
+ }
2860
+ async function readText() {
2861
+ if (!LOGRUN) {
2862
+ LOGLINES = []
2863
+ return drawText()
2864
+ }
2865
+ try {
2866
+ const d = await api('/api/log-read', { run: LOGRUN, kind: VIEW })
2867
+ LOGLINES = d.text.split('\n').filter(Boolean)
2868
+ LOGLINES.cut = d.cut
2869
+ } catch (e) {
2870
+ LOGLINES = []
2871
+ }
2872
+ drawText()
2873
+ }
2874
+ // A line: "2026-11-02T10:00:00.000Z tab 2 [topic] text" (a long one goes on over several lines)
2875
+ function drawText() {
2876
+ const box = $('l-text')
2877
+ const atEnd = box.scrollHeight - box.scrollTop - box.clientHeight < 40
2878
+ const label = logKindsOf(S)[VIEW]?.label ?? VIEW
2879
+ 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.` }))
2880
+ const groups = []
2881
+ for (const l of LOGLINES) if (/^\d{4}-\d\d-\d\dT/.test(l) || !groups.length) groups.push(l)
2882
+ else groups[groups.length - 1] += '\n' + l
2883
+ const find = FIND.trim().toLowerCase()
2884
+ const shown = (find ? groups.filter((g) => g.toLowerCase().includes(find)) : groups).slice(-3000)
2885
+ const mark = (text) => {
2886
+ if (!find) return [text]
2887
+ const out = []
2888
+ let i = 0
2889
+ 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) }))
2890
+ return [...out, text.slice(i)]
2891
+ }
2892
+ put(box,
2893
+ 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,
2894
+ shown.length ? shown.map((g) => {
2895
+ const m = /^(\S+?)T(\S+?)Z( tab \d+)? \[([\w-]+)\] ([\s\S]*)$/.exec(g)
2896
+ if (!m) return h('div', { className: 'ln' }, ...mark(g))
2897
+ return h('div', { className: `ln${/^(error|crash|warn)$/.test(m[4]) ? ' bad' : ''}` },
2898
+ 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]))
2899
+ }) : h('div', { className: 'empty', textContent: `No line has "${FIND}".` }))
2900
+ if (atEnd) box.scrollTop = box.scrollHeight // following the end, unless you scrolled up to read
2901
+ }
2902
+ setInterval(() => {
2903
+ if (page() !== 'logging' || VIEW === 'requests' || !LIVE || document.hidden) return
2904
+ if (LOGRUNS.find((r) => r.run === LOGRUN)?.live || !LOGRUN) readText().then(() => !LOGRUN && showView())
2905
+ }, 2000)
2797
2906
 
2798
2907
  let REQS = null // the requests logged, newest first
2799
2908
  let reqOpen = null // the one shown in full: "run/file"
@@ -2836,7 +2945,7 @@ function drawReqs() {
2836
2945
  const shown = REQS.filter(reqShown)
2837
2946
  const failed = REQS.filter((r) => r.result === 'failed').length
2838
2947
  $('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.' }))
2948
+ 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
2949
  }
2841
2950
  async function openReq(r) {
2842
2951
  reqOpen = `${r.run}/${r.file}`
@@ -2881,7 +2990,7 @@ function drawPrompts(s) {
2881
2990
  const match = (p) => !promptQuery || `${p.id} ${p.title ?? ''} ${p.note}`.toLowerCase().includes(promptQuery)
2882
2991
  const item = (p) => ({ id: p.id, title: p.title ? p.title.replace(/^System prompt /, 'System ') : p.id.split('/')[1], sub: p.title ? p.id : p.note.split('\n')[0], badge: p.changed ? h('span', { className: 'tag brand', textContent: 'yours' }) : null, p })
2883
2992
  const groups = [{ title: 'System prompts', items: s.prompts.filter((p) => p.title && match(p)).map(item) }]
2884
- for (const file of ['agent', 'guided', 'compact', 'probe']) groups.push({ title: { agent: 'Tools, notes and replies', guided: 'Guided mode (models without tool calls)', compact: 'Summaries', probe: 'Model tests' }[file], items: s.prompts.filter((p) => !p.title && p.id.startsWith(file + '/') && match(p)).map(item) })
2993
+ for (const file of ['agent', 'guided', 'compact']) groups.push({ title: { agent: 'Tools, notes and replies', guided: 'Guided mode (models without tool calls)', compact: 'Summaries' }[file], items: s.prompts.filter((p) => !p.title && p.id.startsWith(file + '/') && match(p)).map(item) })
2885
2994
  masterDetail('prompts', $('r-items'), $('r-detail'), groups, (x) => {
2886
2995
  if (!x) return h('div', { className: 'card empty', textContent: 'No prompt matches.' })
2887
2996
  const p = x.p
@@ -2928,7 +3037,7 @@ function drawMcp(s) {
2928
3037
  }
2929
3038
 
2930
3039
  // --- 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"]]
3040
+ 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
3041
  function parseSkill(text) {
2933
3042
  const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/.exec(text)
2934
3043
  const out = { description: '', use: 'both', extra: [], body: (m ? m[2] : text).replace(/^\s*\n/, '') }
@@ -3016,7 +3125,8 @@ async function openImport() {
3016
3125
 
3017
3126
  function drawSkills(s) {
3018
3127
  const mine = s.skills.filter((k) => k.mine)
3019
- const theirs = s.skills.filter((k) => !k.mine)
3128
+ const theirs = s.skills.filter((k) => !k.mine && !k.builtIn)
3129
+ const builtIn = s.skills.filter((k) => k.builtIn)
3020
3130
  const item = (k) => ({ id: k.name, title: '/skill:' + k.name, sub: k.description, k })
3021
3131
  const install = async () => {
3022
3132
  const url = $('k-url').value.trim()
@@ -3038,17 +3148,19 @@ function drawSkills(s) {
3038
3148
  if (e.key === 'Enter') install()
3039
3149
  }
3040
3150
  $('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) => {
3151
+ 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
3152
  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
3153
  const k = x.k
3044
3154
  const f = skillForm(k.name, parseSkill(k.text), { readOnly: !k.mine })
3045
3155
  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' })),
3156
+ 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
3157
  f.el,
3048
3158
  k.mine ? h('div', { className: 'actions' },
3049
3159
  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
3160
  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)
3161
+ 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}`) }))
3162
+ : k.builtIn ? h('div', { className: 'actions' },
3163
+ 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
3164
  })
3053
3165
  $('n-skills').textContent = s.skills.length || ''
3054
3166
  }
@@ -3180,6 +3292,9 @@ function sbSave() {
3180
3292
  }
3181
3293
 
3182
3294
  function render(s) {
3295
+ $('version').textContent = s.version ? `v${s.version}` : ''
3296
+ $('update-note').hidden = !s.update
3297
+ if (s.update) $('update-note').innerHTML = `⬆ <b>${s.update}</b> is out · type <code>/update</code> in HeartCode`
3183
3298
  if (s.prefs) {
3184
3299
  // the page's choices, as kept (also changed on another page: shown here too)
3185
3300
  const p = s.prefs