heartcode 0.1.101 → 0.1.104

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/CHANGELOG.md CHANGED
@@ -2,6 +2,30 @@
2
2
 
3
3
  What changed in each version of HeartCode, newest first.
4
4
 
5
+ ## 0.1.104 (2026-11-28)
6
+
7
+ - **"Runs everything" now really runs everything: it never asks.** Writing the folder's HeartCode or
8
+ git settings (`.heartcode/hooks.json`, `mcp.json`, `format.json`, `prompts/`, `skills/`, `.git/`)
9
+ no longer stops to ask, and neither does a folder's own HeartCode setup at start (it's used). The
10
+ same holds headless (`-p`) and in editors. The other modes still ask about those files.
11
+
12
+ ## 0.1.103 (2026-11-28)
13
+
14
+ - **"Runs everything" no longer stops to ask about a model's own files in `.heartcode/`** (a test
15
+ script it keeps there, say). The question is kept for what can run commands or steer HeartCode:
16
+ `.heartcode/hooks.json`, `mcp.json`, `format.json`, `prompts/`, `skills/`, and git's `.git/`.
17
+
18
+ ## 0.1.102 (2026-11-27)
19
+
20
+ - **Import & export your settings** (`/settings` → Advanced → Import & export): tick what goes in the
21
+ file — providers and CLIs, the model list and helpers (with abilities set by hand), MCP servers,
22
+ skills, prompt changes — and whether API keys go too (off by default; without them, MCP servers'
23
+ env and headers stay out as well). Importing shows what the file has, with the same tickboxes, and
24
+ merges: it adds and updates what has the same name, and removes nothing of yours.
25
+ - **A CLI that isn't installed on this computer comes in switched off** (tagged "not installed" on
26
+ Providers). Switching it on asks to install it first, then switches it on once it's in; Turn all on
27
+ and Turn on N providers leave those off and say so.
28
+
5
29
  ## 0.1.101 (2026-11-24)
6
30
 
7
31
  - **Room above the status line**: three empty rows between the conversation and "thinking · 27s"
package/README.md CHANGED
@@ -224,6 +224,13 @@ Ask it to read, change, run and fix things in your project, like any coding agen
224
224
 
225
225
  <img width="972" height="611" alt="Image" src="https://github.com/user-attachments/assets/dcf9488a-7cee-4a24-8e3e-c86876d379c9" />
226
226
 
227
+ ## Taking your setup to another computer
228
+
229
+ `/settings` → Advanced → **Import & export**: export your providers, model list, MCP servers, skills and
230
+ prompt changes to a file (API keys only if you tick them), and import it on the other computer. It
231
+ merges into what's there. CLIs that computer doesn't have come in switched off; switching one on
232
+ installs it first.
233
+
227
234
  ## More on the settings page
228
235
 
229
236
  What's in the sidebar:
@@ -316,6 +323,6 @@ Contributions are very welcome, thank you! Before you start on a pull request, p
316
323
 
317
324
  ## You might also like
318
325
 
319
- <a href="https://openstore.pfay.workers.dev/cards/p32929?n=4&amp;repo=HeartCode"><picture><source media="(prefers-color-scheme: dark)" srcset="https://openstore.pfay.workers.dev/cards/p32929.svg?n=4&amp;repo=HeartCode&amp;theme=dark"><img src="https://openstore.pfay.workers.dev/cards/p32929.svg?n=4&amp;repo=HeartCode&amp;theme=light" width="100%" alt="More apps by p32929 on OpenStore"></picture></a>
326
+ <p><a href="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/0"><picture><source media="(prefers-color-scheme: dark)" srcset="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/0-dark.svg"><img src="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/0-light.svg" width="50%" align="top" alt="More apps by p32929 on OpenStore (1)"></picture></a><a href="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/1"><picture><source media="(prefers-color-scheme: dark)" srcset="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/1-dark.svg"><img src="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/1-light.svg" width="50%" align="top" alt="More apps by p32929 on OpenStore (2)"></picture></a><br><a href="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/2"><picture><source media="(prefers-color-scheme: dark)" srcset="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/2-dark.svg"><img src="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/2-light.svg" width="50%" align="top" alt="More apps by p32929 on OpenStore (3)"></picture></a><a href="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/3"><picture><source media="(prefers-color-scheme: dark)" srcset="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/3-dark.svg"><img src="https://openstore.pfay.workers.dev/more/p32929/heartcode/personal/3-light.svg" width="50%" align="top" alt="More apps by p32929 on OpenStore (4)"></picture></a></p>
320
327
 
321
328
  <p><a href="https://p32929.github.io/share/?repo=HeartCode"><picture><source media="(prefers-color-scheme: dark)" srcset="https://p32929.github.io/readme/footer-share-dark.svg"><img src="https://p32929.github.io/readme/footer-share-light.svg" width="50%" align="top" alt="Share this project with your friends in one click"></picture></a><a href="https://p32929.github.io/support/"><picture><source media="(prefers-color-scheme: dark)" srcset="https://p32929.github.io/readme/footer-support-dark.svg"><img src="https://p32929.github.io/readme/footer-support-light.svg" width="50%" align="top" alt="If you like my work and want to support me, feel free to support"></picture></a><br><a href="https://openstore.pfay.workers.dev/add"><picture><source media="(prefers-color-scheme: dark)" srcset="https://p32929.github.io/readme/footer-join-dark.svg"><img src="https://p32929.github.io/readme/footer-join-light.svg" width="100%" align="top" alt="Put your own apps on OpenStore: free, your listing lives in your own repo"></picture></a></p>
package/bin/heartcode.js CHANGED
@@ -1982,7 +1982,8 @@ async function repl(app, f = {}) {
1982
1982
  })
1983
1983
  .catch(() => {})
1984
1984
  // this folder's own setup (a cloned repo's hooks and MCP servers run commands): used once you say so
1985
- if (!trusted(app.root)) {
1985
+ if (!trusted(app.root) && ui.permission === 'all') trust(app.root), reloadPrompts() // runs everything: used without asking
1986
+ else if (!trusted(app.root)) {
1986
1987
  const files = setupFiles(app.root)
1987
1988
  const yes = await ui.pick(`This folder has its own HeartCode setup (${files.join(', ')}). Its hooks and MCP servers run commands on this computer. Use it?`, [
1988
1989
  { label: 'Yes, use it', desc: 'for these files as they are now; asked again if they change', use: true },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heartcode",
3
- "version": "0.1.101",
3
+ "version": "0.1.104",
4
4
  "description": "A coding CLI for any local or OpenAI-compatible model, including small models without tool calling.",
5
5
  "keywords": [
6
6
  "ai",
package/src/acp.js CHANGED
@@ -40,7 +40,7 @@ class AcpUI extends HeadlessUI {
40
40
  async confirm(question, kind = 'edit') {
41
41
  if (kind === 'read' && this.permission === 'plan') return true
42
42
  const mode = this.permission === 'plan' ? (this.beforePlan ?? 'ask') : this.permission // plan mode asks as the mode before it did (as the full screen's)
43
- if (kind !== 'setup' && (mode === 'all' || (mode === 'commands' && kind === 'edit'))) return true // setup: always asked
43
+ if (mode === 'all' || (mode === 'commands' && kind === 'edit')) return true // runs everything: never asks; otherwise setup is always asked
44
44
  const toolCallId = runningCall.getStore() ?? this.calls[0] ?? `ask_${Date.now()}` // the call asking
45
45
  const r = await this.conn
46
46
  .request('session/request_permission', {
package/src/headless.js CHANGED
@@ -86,7 +86,7 @@ export class HeadlessUI {
86
86
  this.said = null
87
87
  }
88
88
  async confirm(question, kind = 'edit') {
89
- if (kind !== 'setup' && (this.permission === 'all' || (this.permission === 'commands' && kind === 'edit') || (this.permission === 'plan' && kind === 'read'))) return true // plan: only reading; setup (HeartCode's or git's settings here): never without someone to ask
89
+ if (this.permission === 'all' || (kind !== 'setup' && ((this.permission === 'commands' && kind === 'edit') || (this.permission === 'plan' && kind === 'read')))) return true // runs everything: everything; plan: only reading; setup (HeartCode's or git's settings here): otherwise never without someone to ask
90
90
  log('headless', `declined: ${question}`)
91
91
  return `Not allowed: HeartCode runs headless with permission mode "${this.permission}", so this can't be approved. Don't retry it; say in your reply what you would have done.`
92
92
  }
package/src/settings.html CHANGED
@@ -272,6 +272,9 @@
272
272
  .preset.skel { pointer-events: none; }
273
273
  .preset.skel .shim:first-child { width: 70%; height: 13px; margin-top: 0; }
274
274
  @keyframes shim { from { background-position: 200% 0; } to { background-position: -200% 0; } }
275
+ .move-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
276
+ .move-grid h2 { margin: 0 0 4px; font-size: 16px; }
277
+ .move-grid .opt input[type=checkbox]:disabled + i { opacity: .4; }
275
278
  .cli-bar { display: flex; align-items: center; gap: 12px; margin: 4px 0 10px; font-size: 13px; }
276
279
  #cli-form { width: min(980px, calc(100vw - 32px)); }
277
280
  .preset.cli .box { position: absolute; top: 10px; right: 10px; width: 16px; height: 16px; border-radius: 4px; border: 1.5px solid var(--line-strong); display: grid; place-items: center; color: transparent; }
@@ -895,7 +898,7 @@
895
898
  <a href="#mcp" data-page="mcp"><span class="ic">⧉</span> MCP servers <span class="count" id="n-mcp"></span></a>
896
899
  <a href="#prompts" data-page="prompts"><span class="ic">✎</span> System prompt</a>
897
900
  <div class="nav-group" role="separator"></div>
898
- <a href="#logging" data-page="logging" data-tabs="logging files"><span class="ic">▤</span> Advanced <span class="count" id="n-failed"></span></a>
901
+ <a href="#logging" data-page="logging" data-tabs="logging files move"><span class="ic">▤</span> Advanced <span class="count" id="n-failed"></span></a>
899
902
  </nav>
900
903
  <div class="using" id="using"></div>
901
904
  </aside>
@@ -1118,6 +1121,27 @@
1118
1121
  </section>
1119
1122
 
1120
1123
  <!-- Advanced files -->
1124
+ <section class="page" id="page-move">
1125
+ <div class="head"><div><h1>Import &amp; export</h1><p class="lead">Take your setup to another computer, or bring one in. Importing adds to what's here and updates what has the same name: nothing of yours is removed.</p></div></div>
1126
+ <div class="move-grid">
1127
+ <div class="card">
1128
+ <h2>Export</h2>
1129
+ <p class="muted">What goes in the file:</p>
1130
+ <div id="x-parts"></div>
1131
+ <label class="opt"><div class="t"><b>Include API keys</b><span>Off: providers come without their keys, and MCP servers without their env and headers (they often hold tokens too). On: the file works at once on the other computer, but anyone with it has your keys.</span></div><span class="sw"><input type="checkbox" id="x-keys"><i></i></span></label>
1132
+ <div class="actions"><button class="primary" id="x-go" type="button">Export to a file</button></div>
1133
+ </div>
1134
+ <div class="card">
1135
+ <h2>Import</h2>
1136
+ <p class="muted">A file exported from HeartCode (here or on another computer).</p>
1137
+ <input type="file" id="i-file" accept=".json,application/json" hidden>
1138
+ <div class="row" style="align-items:center;gap:10px"><button id="i-pick" type="button">Choose a file…</button><span class="muted mono" id="i-name"></span></div>
1139
+ <div id="i-parts"></div>
1140
+ <div class="hint" id="i-note"></div>
1141
+ <div class="actions"><button class="primary" id="i-go" type="button" disabled>Import</button></div>
1142
+ </div>
1143
+ </div>
1144
+ </section>
1121
1145
  <section class="page" id="page-files">
1122
1146
  <div class="head"><div><h1>Settings files</h1><p class="lead">The rest of HeartCode's settings, as the files they're kept in (<span class="mono" id="f-home"></span>). A JSON file that doesn't parse isn't saved; save one empty to delete it.</p></div></div>
1123
1147
  <div class="md">
@@ -1543,7 +1567,7 @@ addEventListener('scroll', drawVirtual, { capture: true, passive: true }) // the
1543
1567
  addEventListener('resize', drawVirtual)
1544
1568
 
1545
1569
  // pages: one at a time, from the address (#providers…)
1546
- const PAGES = ['providers', 'models', 'general', 'statusbar', 'notify', 'logging', 'prompts', 'mcp', 'skills', 'files']
1570
+ const PAGES = ['providers', 'models', 'general', 'statusbar', 'notify', 'logging', 'prompts', 'mcp', 'skills', 'files', 'move']
1547
1571
  const page = () => (PAGES.includes(location.hash.slice(1)) ? location.hash.slice(1) : 'providers')
1548
1572
  function showPage() {
1549
1573
  for (const p of PAGES) $('page-' + p).classList.toggle('on', p === page())
@@ -1560,7 +1584,7 @@ function showPage() {
1560
1584
  addEventListener('hashchange', showPage)
1561
1585
  // A sidebar item with several pages (data-tabs): a tab bar on top of each of them. Each page keeps
1562
1586
  // its own address (#providers, #statusbar, #files…), so links to one still open it.
1563
- const TAB_NAMES = { models: 'List', providers: 'Providers', general: 'Settings', statusbar: 'Status bar', logging: 'Logs', files: 'Files' }
1587
+ const TAB_NAMES = { models: 'List', providers: 'Providers', general: 'Settings', statusbar: 'Status bar', logging: 'Logs', files: 'Files', move: 'Import & export' }
1564
1588
  const TAB_COUNTS = { providers: 'n-providers' } // a count shown on the tab, not the sidebar item
1565
1589
  for (const a of document.querySelectorAll('nav a[data-tabs]')) {
1566
1590
  const tabs = a.dataset.tabs.split(' ')
@@ -1644,6 +1668,74 @@ async function saveItem(kind, id, path, body, done) {
1644
1668
  return r
1645
1669
  }
1646
1670
 
1671
+ // --- Import & export (Advanced): the parts, ticked; keys only when asked; an import merged in ---
1672
+ const MOVE_PARTS = [
1673
+ ['providers', 'Providers and CLIs', 'their addresses, which are on, models added by name (keys only with "Include API keys")'],
1674
+ ['models', 'Model list and helpers', 'your models in order, what to do when one fails, the helpers and their jobs, abilities set by hand'],
1675
+ ['mcp', 'MCP servers', 'the servers you added'],
1676
+ ['skills', 'Skills', 'your own skills and their files'],
1677
+ ['prompts', 'Prompt changes', 'your changes to HeartCode\'s prompts (System prompt)'],
1678
+ ]
1679
+ const movePick = { x: new Set(['providers', 'models']), i: new Set() }
1680
+ let importing = null // { name, data }
1681
+ const partRows = (side, counts) => MOVE_PARTS.map(([k, label, desc]) => h('label', { className: 'opt' },
1682
+ h('div', { className: 't' }, h('b', { textContent: `${label}${counts[k] != null ? ` (${counts[k]})` : ''}` }), h('span', { textContent: desc })),
1683
+ h('span', { className: 'sw' }, h('input', { type: 'checkbox', checked: movePick[side].has(k), disabled: !counts[k], onchange: (e) => (e.target.checked ? movePick[side].add(k) : movePick[side].delete(k), drawMove()) }), h('i'))))
1684
+ function drawMove() {
1685
+ if (!S) return
1686
+ const mine = { providers: S.providers.length, models: S.order.length, mcp: S.mcp.filter((x) => x.from === 'yours').length, skills: S.skills.filter((x) => x.mine).length, prompts: S.prompts.filter((x) => x.changed).length }
1687
+ for (const k of movePick.x) if (!mine[k]) movePick.x.delete(k)
1688
+ put($('x-parts'), partRows('x', mine))
1689
+ $('x-go').disabled = !movePick.x.size
1690
+ const d = importing?.data
1691
+ const theirs = d ? { providers: Object.keys(d.providers ?? {}).length, models: d.models?.list?.length, mcp: Object.keys(d.mcp ?? {}).length, skills: Object.keys(d.skills ?? {}).length, prompts: Object.values(d.prompts ?? {}).reduce((n, x) => n + Object.keys(x).length, 0) } : {}
1692
+ put($('i-parts'), d ? partRows('i', theirs) : [])
1693
+ $('i-go').disabled = !movePick.i.size
1694
+ const clis = Object.entries(d?.providers ?? {}).filter(([, p]) => /^cli:\/\//i.test(p.baseUrl ?? '')).map(([n, p]) => ({ n, id: /^cli:\/\/([^/]+)/i.exec(p.baseUrl)[1] }))
1695
+ const missing = CLIS ? clis.filter((x) => !CLIS.find((k) => k.id === x.id)?.installed).map((x) => x.n) : []
1696
+ $('i-note').textContent = !d ? '' : [d.keys ? 'This file has API keys in it.' : 'No API keys in this file: add them under Providers (Edit) after importing.', missing.length && movePick.i.has('providers') ? `Not installed here, so they come in switched off: ${missing.join(', ')}. Switching one on asks to install it.` : ''].filter(Boolean).join(' ')
1697
+ }
1698
+ $('x-go').onclick = async () => {
1699
+ const r = await api('/api/export', { parts: [...movePick.x], keys: $('x-keys').checked }).catch((e) => (toast(e.message, true), null))
1700
+ if (!r) return
1701
+ const a = h('a', { href: URL.createObjectURL(new Blob([JSON.stringify(r, null, 2)], { type: 'application/json' })), download: `heartcode-settings-${new Date().toISOString().slice(0, 10)}.json` })
1702
+ document.body.append(a)
1703
+ a.click()
1704
+ a.remove()
1705
+ toast(`exported ${[...movePick.x].length} part${movePick.x.size === 1 ? '' : 's'}${$('x-keys').checked ? ', with your API keys: keep the file private' : ''}`)
1706
+ }
1707
+ $('i-pick').onclick = () => $('i-file').click()
1708
+ $('i-file').onchange = async (e) => {
1709
+ const f = e.target.files[0]
1710
+ e.target.value = ''
1711
+ if (!f) return
1712
+ let data
1713
+ try {
1714
+ data = JSON.parse(await f.text())
1715
+ if (data?.heartcode !== 'settings') throw new Error()
1716
+ } catch {
1717
+ importing = null
1718
+ drawMove()
1719
+ return toast(`${f.name} isn't a HeartCode settings file`, true)
1720
+ }
1721
+ importing = { name: f.name, data }
1722
+ movePick.i = new Set(MOVE_PARTS.map(([k]) => k).filter((k) => data[k] && Object.keys(data[k]).length))
1723
+ $('i-name').textContent = `${f.name}${data.from ? ` · from HeartCode ${data.from}` : ''}`
1724
+ if (!CLIS) loadClis() // which of its CLIs are installed here
1725
+ drawMove()
1726
+ }
1727
+ $('i-go').onclick = async () => {
1728
+ if (!importing) return
1729
+ const r = await act('/api/import', { data: importing.data, parts: [...movePick.i] })
1730
+ if (!r) return
1731
+ const t = r.report
1732
+ const said = [t.providers != null && `${t.providers} provider${t.providers === 1 ? '' : 's'}`, t.models != null && `${t.models} model${t.models === 1 ? '' : 's'} added to the list`, t.mcp != null && `${t.mcp} MCP server${t.mcp === 1 ? '' : 's'}`, t.skills != null && `${t.skills} skill${t.skills === 1 ? '' : 's'}`, t.prompts != null && `${t.prompts} prompt change${t.prompts === 1 ? '' : 's'}`].filter(Boolean)
1733
+ toast(`imported: ${said.join(', ')}${t.cliOff.length ? ` · ${t.cliOff.length} CLI${t.cliOff.length === 1 ? '' : 's'} not installed here, left off` : ''}${t.skipped ? ` · ${t.skipped} model${t.skipped === 1 ? '' : 's'} skipped (no provider)` : ''}`, false, 8000)
1734
+ importing = null
1735
+ $('i-name').textContent = ''
1736
+ drawMove()
1737
+ }
1738
+
1647
1739
  // --- Providers & models ---
1648
1740
  const PRESETS = [
1649
1741
  ['openrouter', 'OpenRouter', 'https://openrouter.ai/api/v1', 'hundreds of models'],
@@ -1671,6 +1763,7 @@ $('p-url').oninput = () => (drawPresets(), drawCliNote())
1671
1763
  // adds each as a provider at cli://<its name>; one that isn't installed installs from here (its log shown
1672
1764
  // as it goes, ticked once it's in), then is signed in to in a terminal
1673
1765
  let CLIS = null
1766
+ let clisAsked = false
1674
1767
  let cliPoll = null
1675
1768
  const CLI_PICKS = new Set()
1676
1769
  let cliTouched = false // ticks changed by hand: installed ones aren't ticked again by themselves
@@ -1682,6 +1775,8 @@ function loadClis() {
1682
1775
  for (const k of list) if (k.installed && !cliAdded(k.id) && (!cliTouched || was.get(k.id) === false)) CLI_PICKS.add(k.id) // ticked: what's here, and one just installed
1683
1776
  drawClis()
1684
1777
  if ($('p-form').open) drawCliNote()
1778
+ drawMove() // an import's CLIs: installed here or not
1779
+ redraw() // Providers: which CLIs aren't installed
1685
1780
  clearTimeout(cliPoll)
1686
1781
  if (list.some((k) => k.installing || k.pending) && $('cli-form').open) cliPoll = setTimeout(loadClis, list.some((k) => k.installing) ? 1500 : 700) // an install's log; versions still being asked
1687
1782
  }, (e) => toast(e.message, true))
@@ -1877,7 +1972,35 @@ const redraw = () => S && !redrawing && (redrawing = requestAnimationFrame(() =>
1877
1972
  // the providers ticked: those with a model ticked (a provider's own box ticks all of its models shown)
1878
1973
  const selProviders = () => [...new Set([...TICKED].map((k) => splitKey(k).provider))].filter((n) => S?.providers.some((p) => p.name === n))
1879
1974
  const offOf = (names) => S.providers.filter((p) => names.includes(p.name))
1880
- const switchProviders = (names, on) => act('/api/provider/on', { names, on }, `${names.length === 1 ? names[0] : `${names.length} providers`} ${on ? 'on' : 'off'}${on ? '' : ': HeartCode skips their models'}`)
1975
+ // a coding CLI provider's CLI ('claude'…), and whether it's installed here (unknown until loadClis: yes)
1976
+ const cliIdOf = (p) => /^cli:\/\/([^/]+)/i.exec(p?.baseUrl ?? '')?.[1]
1977
+ const notInstalled = (p) => Boolean(cliIdOf(p) && CLIS && !CLIS.find((k) => k.id === cliIdOf(p))?.installed)
1978
+ // on, except the CLIs not installed here: those are said, and left off
1979
+ const saidLeft = (r) => r?.notInstalled?.length && toast(`${r.notInstalled.join(', ')} ${r.notInstalled.length === 1 ? "isn't" : "aren't"} installed on this computer: left off (switch one on to install it)`, true, 7000)
1980
+ const switchProviders = async (names, on) => saidLeft(await act('/api/provider/on', { names, on }, `${names.length === 1 ? names[0] : `${names.length} providers`} ${on ? 'on' : 'off'}${on ? '' : ': HeartCode skips their models'}`))
1981
+ // A CLI that isn't installed here (imported from another computer), switched on: installed first, asked;
1982
+ // on once it's in
1983
+ async function installThenOn(p) {
1984
+ const k = CLIS.find((x) => x.id === cliIdOf(p))
1985
+ if (!k?.install) {
1986
+ toast(`${k?.title ?? p.name} isn't installed, and nothing here can install it${k?.needs ? ` (needs ${k.needs})` : ''}: opening its page`, true, 7000)
1987
+ return k?.page && window.open(k.page, '_blank', 'noopener')
1988
+ }
1989
+ if (!confirm(`${k.title} isn't installed on this computer. Install it now, then switch ${p.name} on?\n\nThis runs: ${k.install}`)) return
1990
+ await api('/api/cli/install', { id: k.id }).catch((e) => toast(e.message, true))
1991
+ job(`install-${k.id}`, { where: ['catalog'], what: `Installing ${k.title}`, detail: 'then it switches on' })
1992
+ for (;;) {
1993
+ await new Promise((r) => setTimeout(r, 2000))
1994
+ const list = await api('/api/clis').catch(() => null)
1995
+ const now = list?.find((x) => x.id === k.id)
1996
+ if (!now || now.installing) continue
1997
+ CLIS = list
1998
+ job(`install-${k.id}`)
1999
+ if (!now.installed) return toast(`${k.title} didn't install: ${now.error || 'see + Add CLIs'}`, true, 9000)
2000
+ toast(`${k.title} installed. Sign in once with "${k.login}" in a terminal if it asks.`, false, 7000)
2001
+ return switchProviders([p.name], true)
2002
+ }
2003
+ }
1881
2004
  // the top button: the ticked providers when some are, else all; off while any of them is on
1882
2005
  function onAllLabel() {
1883
2006
  const sel = selProviders()
@@ -1890,7 +2013,7 @@ $('on-all').onclick = () => {
1890
2013
  const sel = selProviders()
1891
2014
  if (sel.length) return switchProviders(sel, !offOf(sel).some((p) => !p.off))
1892
2015
  const on = !S?.providers.some((p) => !p.off)
1893
- act('/api/provider/on', { on }, on ? 'every provider is on' : 'every provider is off: HeartCode skips their models until you turn one on')
2016
+ act('/api/provider/on', { on }, on ? 'every provider is on' : 'every provider is off: HeartCode skips their models until you turn one on').then(saidLeft)
1894
2017
  }
1895
2018
  // the folds, on the sections there (nothing built again); a search shows them all open
1896
2019
  function applyFolds() {
@@ -2223,9 +2346,10 @@ function drawProviders(s) {
2223
2346
  else loadModels(p.name, MODELS[p.name]?.off)
2224
2347
  }
2225
2348
  for (const k of [...TICKED]) if (!s.providers.some((p) => p.name === splitKey(k).provider)) TICKED.delete(k) // a provider deleted: its ticks go
2349
+ if (!CLIS && !clisAsked && s.providers.some(cliIdOf)) (clisAsked = true), loadClis() // which CLIs are installed here (tagged, asked to install)
2226
2350
  const view = catView(s)
2227
2351
  // built again only when what's shown changed; the rest is marked on the rows there
2228
- const stamp = JSON.stringify([view.map((x) => [x.p.name, x.p.off, x.p.baseUrl, x.p.key, x.p.added, x.m.loading ?? false, x.m.error ?? '', x.m.off ?? false, x.m.list?.length ?? 0, x.ids.join('\n')]), catKind, onOnly, freeOnly])
2352
+ const stamp = JSON.stringify([view.map((x) => [x.p.name, x.p.off, x.p.baseUrl, x.p.key, x.p.added, x.m.loading ?? false, x.m.error ?? '', x.m.off ?? false, x.m.list?.length ?? 0, x.ids.join('\n'), notInstalled(x.p)]), catKind, onOnly, freeOnly])
2229
2353
  if (stamp !== catStamp) buildCatalog(view, s)
2230
2354
  catStamp = stamp
2231
2355
  markCatalog(s)
@@ -2473,6 +2597,7 @@ function buildCatalog(view, s) {
2473
2597
  h('div', { className: 'who' },
2474
2598
  h('span', { className: 'name' }, provIcon(p.name), p.name),
2475
2599
  p.off ? h('span', { className: 'tag', textContent: 'off' }) : null,
2600
+ notInstalled(p) ? h('span', { className: 'tag err', textContent: 'not installed', title: `${p.name}'s CLI isn't installed on this computer: switch it on to install it` }) : null,
2476
2601
  m.off ? h('span', { className: 'tag', textContent: 'list off', title: "its list isn't loaded: add a model by its name, in the box on the right" }) : m.loading ? h('span', { className: 'tag', textContent: 'loading…' }) : m.error ? h('span', { className: 'tag err', textContent: "can't list its models", title: m.error }) : h('span', { className: 'tag', textContent: `${m.list.length} model${m.list.length === 1 ? '' : 's'}` }),
2477
2602
  h('span', { className: 'tag inlist', hidden: true }),
2478
2603
  h('span', { className: 'meta mono', textContent: p.baseUrl, title: `${p.baseUrl} · key ${p.key || 'none'}` })),
@@ -2584,7 +2709,11 @@ function drawPicks(view = catView()) {
2584
2709
  } else if (e.target.matches('.pick-all')) {
2585
2710
  for (const r of sec.querySelectorAll('.mwrap')) e.target.checked ? TICKED.add(`${name}/${r.dataset.model}`) : TICKED.delete(`${name}/${r.dataset.model}`)
2586
2711
  drawPicks()
2587
- } else if (e.target.matches('.p-on')) act('/api/provider/on', { name, on: e.target.checked }, e.target.checked ? `${name} is on` : `${name} is off: HeartCode skips its models`)
2712
+ } else if (e.target.matches('.p-on')) {
2713
+ const p = provOf(sec)
2714
+ if (e.target.checked && notInstalled(p)) return (e.target.checked = false), installThenOn(p) // installed first
2715
+ act('/api/provider/on', { name, on: e.target.checked }, e.target.checked ? `${name} is on` : `${name} is off: HeartCode skips its models`).then((r) => !r && redraw()) // refused: the switch as it was
2716
+ }
2588
2717
  })
2589
2718
  list.addEventListener('click', async (e) => {
2590
2719
  const { sec, w } = where(e.target)
@@ -4000,6 +4129,7 @@ function render(s) {
4000
4129
  for (const [key, r] of Object.entries(TRIES)) if (!r.going && placeOf(...key.split(/\/(.*)/s)) === undefined) delete TRIES[key] // off your list: its result too
4001
4130
  drawProviders(s)
4002
4131
  applyFolds()
4132
+ drawMove()
4003
4133
  drawMine(s)
4004
4134
  drawUsing(s)
4005
4135
  drawGeneral(s)
package/src/settings.js CHANGED
@@ -14,6 +14,7 @@ import { DEFAULT_SERVERS, mcpAuth, serverName } from './mcp.js'
14
14
  import { sections, BUILTIN_PROMPTS, prompt, reloadPrompts } from './prompts.js'
15
15
  import { Client } from './client.js'
16
16
  import { clisInfo, installCli, cliOf, cliUrl, CLIS } from './clis.js'
17
+ import { onPath } from './spawn.js'
17
18
  import { clip, TOOL_DEFS } from './tools.js'
18
19
  import { loadProfile, strategy, profilePath, profileFrom } from './probe.js'
19
20
  import { loadPrices, priceOf, limitsOf } from './usage.js'
@@ -583,6 +584,17 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
583
584
  autoPick()
584
585
  return state()
585
586
  },
587
+ // Settings to take to another machine (Advanced → Import & export): the parts asked for, keys only
588
+ // when asked; and a file like it taken in, merged (nothing of yours is removed)
589
+ 'POST /api/export': ({ parts = [], keys = false } = {}) => exportSettings(cfg, parts, keys),
590
+ 'POST /api/import': ({ data, parts = [] } = {}) => {
591
+ const report = importSettings(cfg, data, parts)
592
+ save('model')
593
+ reloadPrompts()
594
+ forgetTests()
595
+ autoPick()
596
+ return { ...state(), report }
597
+ },
586
598
  // the coding CLIs (clis.js): which are installed, how to install the rest, an install going on
587
599
  'GET /api/clis': () => clisInfo(),
588
600
  // several CLIs added at once (Add CLIs): each a provider named after it; one added already is skipped
@@ -636,13 +648,16 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
636
648
  'POST /api/provider/on': ({ name, names, on }) => {
637
649
  const list = names ?? (name !== undefined ? [name] : Object.keys(cfg.providers))
638
650
  for (const n of list) if (!cfg.providers[n]) throw new Error(`no provider "${n}"`)
639
- for (const p of list.map((n) => cfg.providers[n])) {
651
+ // a coding CLI not installed here (one imported from another machine) stays off until it is
652
+ const missing = on ? list.filter((n) => { const id = cliOf(cfg.providers[n].baseUrl); return id && !onPath(CLIS[id].bin) }) : []
653
+ if (missing.length && list.length === 1) throw Object.assign(new Error(`${CLIS[cliOf(cfg.providers[missing[0]].baseUrl)].title} isn't installed on this computer: install it first (+ Add CLIs)`), { notInstalled: missing[0] })
654
+ for (const p of list.filter((n) => !missing.includes(n)).map((n) => cfg.providers[n])) {
640
655
  if (on) delete p.off
641
656
  else p.off = true
642
657
  }
643
658
  save('model') // the running sessions' model lists follow at once
644
659
  autoPick()
645
- return state()
660
+ return { ...state(), ...(missing.length && { notInstalled: missing }) }
646
661
  },
647
662
  // A model added by its name (one the provider doesn't list, or its list is off): remembered under
648
663
  // the provider, not put in the list (clicked there, it is). models: several at once.
@@ -1240,7 +1255,7 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
1240
1255
  let raw = ''
1241
1256
  for await (const ch of req) {
1242
1257
  raw += ch
1243
- if (raw.length > 1_000_000) return send(413, { error: 'too big' })
1258
+ if (raw.length > (url.pathname === '/api/import' ? 50_000_000 : 1_000_000)) return send(413, { error: 'too big' }) // an import may carry skills
1244
1259
  }
1245
1260
  if (req.method === 'POST' && !/^application\/json/.test(req.headers['content-type'] ?? '')) return send(415, { error: 'JSON only' })
1246
1261
  send(200, await route(raw ? JSON.parse(raw) : {}))
@@ -1285,6 +1300,150 @@ function warm() {
1285
1300
  step(0)
1286
1301
  }
1287
1302
 
1303
+ // --- Import & export: settings taken to another machine ---
1304
+ // A file: { heartcode: 'settings', version: 1, from (HeartCode's version), at, parts…, keys (whether
1305
+ // keys are in it) }. Parts: providers (CLIs too), models (the list in order, when one fails, the
1306
+ // helpers, models' abilities set by hand), mcp (servers), skills (your own, their files), prompts
1307
+ // (your changes to HeartCode's prompts). Without keys: no provider key, no MCP server's env or headers.
1308
+ export const EXPORT_PARTS = ['providers', 'models', 'mcp', 'skills', 'prompts']
1309
+ const listOf = (cfg) => [...(cfg.providers[cfg.provider] && cfg.model ? [{ provider: cfg.provider, model: cfg.model }] : []), ...rotationOf(cfg).then]
1310
+ const profileClient = (cfg, t) => cfg.providers[t.provider] && new Client({ baseUrl: cfg.providers[t.provider].baseUrl, model: t.model })
1311
+ // a folder's text files, by their path in it (a skill's); nothing big or binary
1312
+ function filesOf(dir, base = dir, out = {}) {
1313
+ for (const e of fs.readdirSync(dir, { withFileTypes: true })) {
1314
+ const f = path.join(dir, e.name)
1315
+ if (e.isDirectory()) filesOf(f, base, out)
1316
+ else if (e.isFile() && fs.statSync(f).size < 2_000_000) {
1317
+ const text = fs.readFileSync(f, 'utf8')
1318
+ if (!text.includes('\u0000')) out[path.relative(base, f).split(path.sep).join('/')] = text
1319
+ }
1320
+ }
1321
+ return out
1322
+ }
1323
+ export function exportSettings(cfg, parts, keys) {
1324
+ const want = new Set(parts.filter((p) => EXPORT_PARTS.includes(p)))
1325
+ if (!want.size) throw new Error('pick at least one part to export')
1326
+ const out = { heartcode: 'settings', version: 1, from: VERSION, at: new Date().toISOString(), keys: Boolean(keys) }
1327
+ if (want.has('providers')) out.providers = Object.fromEntries(Object.entries(cfg.providers).filter(([n]) => n !== cfg.adhoc).map(([n, p]) => [n, { baseUrl: p.baseUrl, ...(keys && p.apiKey && { apiKey: p.apiKey }), ...(p.off && { off: true }), ...(p.list === false && { list: false }), ...(p.models?.length && { models: p.models }) }]))
1328
+ if (want.has('models')) {
1329
+ const list = listOf(cfg)
1330
+ const { then, ...rotation } = rotationOf(cfg)
1331
+ const profiles = {}
1332
+ for (const t of list) {
1333
+ const c = profileClient(cfg, t)
1334
+ const p = c && loadProfile(c)
1335
+ if (p?.source === 'you' && p.set && Object.keys(p.set).length) profiles[`${t.provider}/${t.model}`] = p.set // set by hand (not a CLI's own)
1336
+ }
1337
+ out.models = { list, rotation, ...(cfg.helpers && { helpers: cfg.helpers }), ...(cfg.helpersAuto && { helpersAuto: true }), ...(Object.keys(profiles).length && { profiles }) }
1338
+ }
1339
+ if (want.has('mcp')) {
1340
+ const servers = readJson(path.join(HOME, 'mcp.json'), {})?.mcpServers ?? {}
1341
+ out.mcp = Object.fromEntries(Object.entries(servers).map(([n, sv]) => { const { env, headers, ...rest } = sv; return [n, keys ? sv : rest] }))
1342
+ }
1343
+ if (want.has('skills')) {
1344
+ const dir = skillsDir()
1345
+ out.skills = {}
1346
+ for (const e of fs.existsSync(dir) ? fs.readdirSync(dir, { withFileTypes: true }) : []) {
1347
+ if (e.isDirectory()) out.skills[e.name] = filesOf(path.join(dir, e.name))
1348
+ else if (e.name.endsWith('.md')) out.skills[e.name.slice(0, -3)] = { 'SKILL.md': fs.readFileSync(path.join(dir, e.name), 'utf8'), single: true }
1349
+ }
1350
+ }
1351
+ if (want.has('prompts')) {
1352
+ out.prompts = {}
1353
+ for (const file of PROMPT_FILES) if (fs.existsSync(ownPrompts(file))) out.prompts[file] = Object.fromEntries(sections(fs.readFileSync(ownPrompts(file), 'utf8')))
1354
+ }
1355
+ return out
1356
+ }
1357
+ // Merged in: what the file has is added, or updates the one of the same name; nothing of yours goes.
1358
+ // A coding CLI not installed here comes in switched off (switching it on asks to install it first).
1359
+ // { providers, models, skipped, cliOff: [names], mcp, skills, prompts }: what was taken in.
1360
+ export function importSettings(cfg, data, parts) {
1361
+ if (data?.heartcode !== 'settings') throw new Error("that isn't a HeartCode settings file")
1362
+ const want = new Set(parts.filter((p) => EXPORT_PARTS.includes(p) && data[p]))
1363
+ if (!want.size) throw new Error('pick at least one part that the file has')
1364
+ const report = { cliOff: [] }
1365
+ if (want.has('providers')) {
1366
+ report.providers = 0
1367
+ for (const [raw, p] of Object.entries(data.providers ?? {})) {
1368
+ const name = safeName(raw)
1369
+ if (!name || typeof p?.baseUrl !== 'string') continue
1370
+ const id = cliOf(p.baseUrl)
1371
+ if (/^cli:/i.test(p.baseUrl) && !id) continue // a CLI this HeartCode doesn't know
1372
+ const had = cfg.providers[name] ?? {}
1373
+ const next = { ...had, baseUrl: p.baseUrl.replace(/\/+$/, ''), ...(p.apiKey && { apiKey: String(p.apiKey) }) }
1374
+ const models = [...new Set([...(had.models ?? []), ...(Array.isArray(p.models) ? p.models.map(String) : [])])]
1375
+ if (models.length) next.models = models
1376
+ if (p.list === false) next.list = false
1377
+ if (p.off) next.off = true
1378
+ if (id && !onPath(CLIS[id].bin)) (next.off = true), report.cliOff.push(name)
1379
+ cfg.providers[name] = next
1380
+ forgetList(name)
1381
+ report.providers++
1382
+ }
1383
+ }
1384
+ if (want.has('models')) {
1385
+ const m = data.models
1386
+ const mine = listOf(cfg)
1387
+ const had = new Set(mine.map((t) => `${t.provider}/${t.model}`))
1388
+ const add = (Array.isArray(m.list) ? m.list : []).map((t) => ({ provider: safeName(t?.provider), model: String(t?.model ?? '').trim() })).filter((t) => t.model && cfg.providers[t.provider] && !had.has(`${t.provider}/${t.model}`) && had.add(`${t.provider}/${t.model}`))
1389
+ report.skipped = (Array.isArray(m.list) ? m.list : []).filter((t) => !cfg.providers[safeName(t?.provider)]).length // their provider isn't here (not in the file, or not imported)
1390
+ const all = [...mine, ...add]
1391
+ if (all.length) {
1392
+ const opts = mine.length ? rotationOf(cfg) : { ...rotationOf(cfg), ...Object.fromEntries(Object.entries(m.rotation ?? {}).filter(([k, v]) => (k === 'retries' ? Number.isInteger(v) && v >= 1 && v <= 20 : ROTATION[k]?.includes(v)))) } // yours kept when you had a list
1393
+ Object.assign(cfg, { provider: all[0].provider, model: all[0].model, rotation: { on: opts.on, retries: opts.retries, next: opts.next, then: all.slice(1) } })
1394
+ }
1395
+ report.models = add.length
1396
+ if (m.helpers && typeof m.helpers === 'object') cfg.helpers = helpersOf({ ...m.helpers, ...cfg.helpers })
1397
+ if (m.helpersAuto && !cfg.helpers) cfg.helpersAuto = true
1398
+ for (const [k, set] of Object.entries(m.profiles ?? {})) {
1399
+ const t = { provider: k.slice(0, k.indexOf('/')), model: k.slice(k.indexOf('/') + 1) }
1400
+ const c = profileClient(cfg, t)
1401
+ if (!c || !set || typeof set !== 'object') continue
1402
+ const p = loadProfile(c) ?? profileFrom(c, limitsOf(t.provider, c.baseUrl, t.model))
1403
+ if (p.source !== 'you' && p.source !== 'cli') writeJson(profilePath(c), { ...p, set, source: 'you' }), (report.set = (report.set ?? 0) + 1) // yours set by hand stay; a CLI's are its own
1404
+ }
1405
+ }
1406
+ if (want.has('mcp')) {
1407
+ const file = path.join(HOME, 'mcp.json')
1408
+ const now = readJson(file, {}) ?? {}
1409
+ const servers = { ...now.mcpServers }
1410
+ report.mcp = 0
1411
+ for (const [n, sv] of Object.entries(data.mcp ?? {})) if (sv && typeof sv === 'object' && (sv.command || sv.url)) (servers[n] = { ...servers[n], ...sv }), report.mcp++
1412
+ writeJson(file, { ...now, mcpServers: servers })
1413
+ }
1414
+ if (want.has('skills')) {
1415
+ report.skills = 0
1416
+ for (const [raw, files] of Object.entries(data.skills ?? {})) {
1417
+ const name = safeName(raw)
1418
+ if (!name || !files || typeof files !== 'object') continue
1419
+ let wrote = 0
1420
+ if (files.single) {
1421
+ fs.mkdirSync(skillsDir(), { recursive: true })
1422
+ fs.writeFileSync(path.join(skillsDir(), `${name}.md`), String(files['SKILL.md'] ?? ''))
1423
+ wrote++
1424
+ } else {
1425
+ const dir = path.join(skillsDir(), name)
1426
+ for (const [rel, text] of Object.entries(files)) {
1427
+ const to = path.resolve(dir, rel)
1428
+ if (!to.startsWith(dir + path.sep) || typeof text !== 'string') continue // nothing outside its folder
1429
+ fs.mkdirSync(path.dirname(to), { recursive: true })
1430
+ fs.writeFileSync(to, text)
1431
+ wrote++
1432
+ }
1433
+ }
1434
+ if (wrote) report.skills++
1435
+ }
1436
+ }
1437
+ if (want.has('prompts')) {
1438
+ report.prompts = 0
1439
+ for (const [file, secs] of Object.entries(data.prompts ?? {})) {
1440
+ if (!PROMPT_FILES.includes(file) || !secs || typeof secs !== 'object') continue
1441
+ for (const [name, text] of Object.entries(secs)) if (typeof text === 'string') setPrompt(file, name, text), report.prompts++
1442
+ }
1443
+ }
1444
+ return report
1445
+ }
1446
+
1288
1447
  // A test's answer, judged: asked to reply with just "OK", a model that answered with an error as its
1289
1448
  // text (a provider's "not enough credits", a CLI's "Model … is not available") or with something else
1290
1449
  // altogether (an image link, a safety verdict, a persona's greeting) doesn't work for HeartCode,
package/src/tools.js CHANGED
@@ -464,10 +464,11 @@ const PLACEHOLDER = /(\.\.\.|…)\s*(rest|existing|remaining|unchanged|other)|re
464
464
  // model choice. A model never writes them (a small one once wrote its notes over this conversation).
465
465
  const OWN_DATA = /^\.heartcode\/(?:sessions|outputs|worktrees)(?:\/|$)|^\.heartcode\/models\.json$/
466
466
 
467
- // HeartCode's settings for this folder (hooks and MCP servers run commands, prompts steer it) and
468
- // git's (its hooks run commands): never written without asking, whatever the mode (a file or page
469
- // telling the model to write one would run its commands next time)
470
- const SETUP_FILES = /^(?:\.heartcode|\.git)(?:\/|$)/
467
+ // HeartCode's settings for this folder (hooks, MCP servers and formatters run commands, prompts and
468
+ // skills steer it) and git's (its hooks run commands): asked about in every mode but runs everything
469
+ // (a file or page telling the model to write one would run its commands next time). The rest of
470
+ // .heartcode (a model's own scripts and notes there) is written like any project file.
471
+ const SETUP_FILES = /^\.git(?:\/|$)|^\.heartcode\/(?:(?:hooks|mcp|format)\.json$|(?:prompts|skills)(?:\/|$))/
471
472
 
472
473
  export async function proposeWrite(s, rel, old, next) {
473
474
  if (old === next) return { status: 'unchanged' }
package/src/ui.js CHANGED
@@ -2310,7 +2310,7 @@ export class UI {
2310
2310
  async confirm(question, kind = 'edit') {
2311
2311
  if (kind === 'read' && this.permission === 'plan') return true
2312
2312
  const mode = this.permission === 'plan' ? (this.beforePlan ?? 'ask') : this.permission
2313
- if (kind !== 'setup' && (mode === 'all' || (mode === 'commands' && kind === 'edit'))) return true // setup: always asked (tools.js SETUP_FILES)
2313
+ if (mode === 'all' || (mode === 'commands' && kind === 'edit')) return true // runs everything: never asks, setup files too; otherwise setup is always asked (tools.js SETUP_FILES)
2314
2314
  if (this.full) {
2315
2315
  this.askAbout = true // the dialog shows what it's about (the diff, the command) above the choices
2316
2316
  try {