heartcode 0.1.56 → 0.1.57

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,15 @@
2
2
 
3
3
  What changed in each version of HeartCode, newest first.
4
4
 
5
+ ## 0.1.57 (2026-11-06)
6
+
7
+ - **The `/settings` link can be copied over SSH**: while the page is on, the mouse is the terminal's,
8
+ so you select the link and copy it as usual (some terminals, like macOS Terminal, drop the copy
9
+ HeartCode sends through them). The link is shorter and stays on one row at 80 columns, uses the
10
+ address you reached the machine at, and no browser is started on the remote machine. Copies sent
11
+ through the terminal now say "if your terminal allows it".
12
+ - **Turning the page off closes it**: no second box to close; Enter, Esc or Ctrl+C turn it off.
13
+
5
14
  ## 0.1.56 (2026-11-05)
6
15
 
7
16
  - **Questions as tabs**: several questions come in one dialog, a tab each; go back and forth with
package/bin/heartcode.js CHANGED
@@ -9,7 +9,7 @@ import { Session, transcript, contextReport } from '../src/agent.js'
9
9
  import { listJobs, getJob, stopJob, removeJob, runningJobs, tailLines, ago as ranFor } from '../src/background.js'
10
10
  import { checkUpdate, installKind, UPDATE_COMMANDS, packageDir, whatsNew } from '../src/update.js'
11
11
  import { treeItems, codePlan, move, leaving, leftText, leftFiles } from '../src/tree.js'
12
- import { UI, c, PERMISSIONS, duration, copyText, rank, setTheme, themeCodes, renderDiff, diffLines, DEFAULT_KEYS, loadKeys, width, shortError, wrapWords } from '../src/ui.js'
12
+ import { UI, c, PERMISSIONS, duration, copyText, overSsh, rank, setTheme, themeCodes, renderDiff, diffLines, DEFAULT_KEYS, loadKeys, width, shortError, wrapWords } from '../src/ui.js'
13
13
  import { listFiles, runCommand, clip } from '../src/tools.js'
14
14
  import { notify } from '../src/telegram.js'
15
15
  import { log, LOG_FILE, LOG_DIR, requestLog, useRequestLog, useLogs, pruneLogs, logDays } from '../src/log.js'
@@ -1205,7 +1205,7 @@ let settingsPage = null
1205
1205
  const effortOf = (cfg) => cfg.effort ?? 'low'
1206
1206
 
1207
1207
  function openBrowser(url) {
1208
- if (process.env.HEART_NO_BROWSER) return
1208
+ if (process.env.HEART_NO_BROWSER || overSsh) return // over SSH your browser isn't on this machine
1209
1209
  const [cmd, ...args] = process.platform === 'darwin' ? ['open', url] : process.platform === 'win32' ? ['rundll32', 'url.dll,FileProtocolHandler', url] : ['xdg-open', url]
1210
1210
  spawnSync(cmd, args, { stdio: 'ignore' })
1211
1211
  }
@@ -1440,15 +1440,17 @@ async function slash(app, line, working = false) {
1440
1440
  settingsPage ??= startSettings({ cfg, root: app.root, onLoginMcp: (name) => signInMcp(app, name, null), apply: (what) => applySettings(app.tabs ? app.tabs.list.map((t) => t.app) : [app], cfg, what) })
1441
1441
  const { url, local, close } = await settingsPage
1442
1442
  openBrowser(local)
1443
- ui.print(`${c.info('↗')} ${c.bold('settings')} ${c.muted('opened in your browser:')}\n ${c.faint(url)}`)
1443
+ if (!ui.full) ui.print(`${c.info('↗')} ${c.bold('settings')} ${c.muted(overSsh ? 'open this link in your browser:' : 'opened in your browser:')}\n ${c.faint(url)}`)
1444
1444
  // a dialog until it's turned off: nothing else meanwhile, in any tab (Esc turns it off too).
1445
1445
  // Not busy meanwhile: what's changed on the page applies at once, here too (opened while a task
1446
1446
  // works: once it's done).
1447
1447
  if (!working) ui.idle()
1448
1448
  if (app.tabs) app.tabs.locked = true
1449
+ ui.setMouse(false) // the terminal's own selection for the link: OSC 52 copying fails in some terminals
1449
1450
  try {
1450
- await ui.pick('The settings page is on', [{ label: 'Turn off', desc: 'stops the page and gives HeartCode back' }], { fixed: true, body: `It's open in your browser:\n${url}\n\nWhat you change there applies right away.` })
1451
+ await ui.pick('The settings page is on', [{ label: 'Turn off', desc: 'stops the page and gives HeartCode back' }], { fixed: true, quiet: true, ctrlC: true, body: `${overSsh ? 'Open this link in your browser:' : "It's open in your browser:"}\n${url}\n\nTo copy it, select it with the mouse.\nWhat you change there applies right away.` })
1451
1452
  } finally {
1453
+ ui.setMouse(cfg.mouse !== false)
1452
1454
  if (app.tabs) app.tabs.locked = false
1453
1455
  close()
1454
1456
  settingsPage = null
@@ -1550,7 +1552,7 @@ async function slash(app, line, working = false) {
1550
1552
  const answer = app.chat.history.at(-1)?.answer?.trim()
1551
1553
  if (!answer) return ui.print('No answer to copy yet.')
1552
1554
  const how = copyText(answer)
1553
- return ui.print(c.dim(`copied the last answer (${answer.split('\n').length} lines)${how === 'osc' ? ' through the terminal' : ''}`))
1555
+ return ui.print(c.dim(`copied the last answer (${answer.split('\n').length} lines)${how === 'osc' ? ' if your terminal allows it' : ''}`))
1554
1556
  }
1555
1557
  case 'background': {
1556
1558
  const jobs = listJobs(app.root)
@@ -2035,7 +2037,7 @@ async function main() {
2035
2037
 
2036
2038
  if (sub === 'settings') {
2037
2039
  const { url, local } = await startSettings({ cfg })
2038
- console.log(`${c.brand('♥')} HeartCode settings: ${url}\n${c.dim('opened in your browser · from another device on this network, open the link above · Ctrl+C to stop')}`)
2040
+ console.log(`${c.brand('♥')} HeartCode settings: ${url}\n${c.dim(`${overSsh ? 'open it in your browser' : 'opened in your browser'} · from another device on this network, open the link above · Ctrl+C to stop`)}`)
2039
2041
  openBrowser(local)
2040
2042
  return new Promise(() => {}) // until Ctrl+C
2041
2043
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heartcode",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
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/settings.js CHANGED
@@ -159,7 +159,7 @@ function forgetList(...names) {
159
159
 
160
160
  export function startSettings({ cfg, apply = () => {}, port = 0, root = process.cwd(), onLoginMcp = null } = {}) {
161
161
  let importCache = [] // the last /api/imports listing, so /api/imports/run can execute by id
162
- const token = crypto.randomBytes(24).toString('hex')
162
+ const token = crypto.randomBytes(16).toString('hex') // short enough for the link to stay on one row of an 80-column dialog, to select it
163
163
  const changed = (what) => {
164
164
  if (what === 'prompts') reloadPrompts() // this page's own Tests use them too (heart settings has no HeartCode to apply them)
165
165
  try {
@@ -1050,7 +1050,8 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
1050
1050
  server.listen(port, '0.0.0.0', () => {
1051
1051
  const at = (host) => `http://${host}:${server.address().port}/?t=${token}`
1052
1052
  const local = at('127.0.0.1') // for a browser on this machine
1053
- const url = at(addresses()[0] ?? '127.0.0.1') // its network address when it has one: works from another device too
1053
+ const ssh = process.env.SSH_CONNECTION?.split(' ')[2] // over SSH: the address you reached this machine at
1054
+ const url = at((ssh?.includes(':') ? `[${ssh}]` : ssh) ?? addresses()[0] ?? '127.0.0.1') // else its network address when it has one: works from another device too
1054
1055
  log('web', `settings page at ${new URL(url).host}`)
1055
1056
  // models.dev's list (its sizes for your models, whether their providers' lists are on or not):
1056
1057
  // loaded now, and your models' lines brought up to date when it's in
package/src/ui.js CHANGED
@@ -140,11 +140,13 @@ export function loadKeys(file = path.join(HOME, 'keybindings.json')) {
140
140
  const MOUSE_ON = '\x1b[?1000h\x1b[?1002h\x1b[?1006h'
141
141
  const MOUSE_OFF = '\x1b[?1006l\x1b[?1002l\x1b[?1000l'
142
142
 
143
+ export const overSsh = Boolean(process.env.SSH_CONNECTION || process.env.SSH_TTY || process.env.SSH_CLIENT)
144
+
143
145
  // The system clipboard (pbcopy, clip, wl-copy, xclip, xsel); else the terminal's (OSC 52). Over SSH,
144
- // the terminal's only: the system's would be the remote machine's, not the one you're at.
146
+ // the terminal's only: the system's would be the remote machine's, not the one you're at. OSC 52 has
147
+ // no answer and some terminals drop it (macOS Terminal), so 'osc' doesn't mean it got there.
145
148
  export function copyText(text) {
146
- const remote = Boolean(process.env.SSH_CONNECTION || process.env.SSH_TTY || process.env.SSH_CLIENT)
147
- const tools = remote ? [] : process.platform === 'darwin' ? [['pbcopy']] : process.platform === 'win32' ? [['clip']] : [['wl-copy'], ['xclip', '-selection', 'clipboard'], ['xsel', '-b', '-i']]
149
+ const tools = overSsh ? [] : process.platform === 'darwin' ? [['pbcopy']] : process.platform === 'win32' ? [['clip']] : [['wl-copy'], ['xclip', '-selection', 'clipboard'], ['xsel', '-b', '-i']]
148
150
  for (const [cmd, ...args] of tools) if (spawnSync(cmd, args, { input: text, stdio: ['pipe', 'ignore', 'ignore'] }).status === 0) return 'system'
149
151
  process.stdout.write(`\x1b]52;c;${Buffer.from(text).toString('base64')}\x07`)
150
152
  return 'osc'
@@ -892,7 +894,7 @@ export class UI {
892
894
  const own = pick?.items.some((x) => x.own) // typing goes into "Something else", not a filter
893
895
  const typingOwn = m.items[m.sel]?.item?.own && m.items[m.sel].item.text // ←/→ move in what's typed; Tab goes on
894
896
  const body = pick?.body ? String(pick.body).split('\n') : []
895
- const hint = (pick?.nav ? (typingOwn ? 'Tab questions · ' : '←→ questions · ') : '') + (pick ? (pick.fixed ? '↑↓ move · Enter choose · Esc close' : pick.multi ? `↑↓ move · Space tick · Alt+A/N all/none · Enter take · Esc cancel · ${own ? 'type your own' : 'type to filter'}` : `↑↓ move · Enter choose · Esc cancel${own ? ' · type your own' : cards ? '' : ' · type to filter'}`) : 'Enter send · Esc cancel')
897
+ const hint = (pick?.nav ? (typingOwn ? 'Tab questions · ' : '←→ questions · ') : '') + (pick ? (pick.ctrlC ? 'Enter, Esc or Ctrl+C turn it off' : pick.fixed ? '↑↓ move · Enter choose · Esc close' : pick.multi ? `↑↓ move · Space tick · Alt+A/N all/none · Enter take · Esc cancel · ${own ? 'type your own' : 'type to filter'}` : `↑↓ move · Enter choose · Esc cancel${own ? ' · type your own' : cards ? '' : ' · type to filter'}`) : 'Enter send · Esc cancel')
896
898
  const timer = this.autoLine() // on its own line, so it's seen (and not cut off with the keys)
897
899
  const long = width(title) > this.#dialogBox(cols, rows).w - 6 // too long for the border: inside instead, said once
898
900
  // at most n rows; the rest said to be there
@@ -1212,7 +1214,7 @@ export class UI {
1212
1214
  this.render()
1213
1215
  }
1214
1216
  #copied(text) {
1215
- this.notice(`copied ${text.length} character${text.length === 1 ? '' : 's'}${copyText(text) === 'osc' ? ' (through the terminal)' : ''}`)
1217
+ this.notice(`copied ${text.length} character${text.length === 1 ? '' : 's'}${copyText(text) === 'osc' ? ' (if your terminal allows it)' : ''}`)
1216
1218
  }
1217
1219
  // A double click: the word under it (no spaces; quotes and brackets around it left out), copied.
1218
1220
  #copyWord(x, y) {
@@ -1495,6 +1497,7 @@ export class UI {
1495
1497
  return this.dialog.key?.(key, s), this.render()
1496
1498
  }
1497
1499
  if (this.recording) return this.recording.key(key, bound) // voice: Space, Enter, Esc; the rest waits
1500
+ if (this.menu.pick?.ctrlC && key.ctrl && key.name === 'c') return this.cancelAsk()
1498
1501
  // a fixed dialog (pick(…, { fixed })): only its keys, nothing typed and no shortcuts
1499
1502
  if (this.menu.pick?.fixed && !['up', 'down', 'return', 'escape'].includes(key.name) && !(key.ctrl && key.name === 'c')) return
1500
1503
  // In a multi-select: Alt+A ticks all, Alt+N unticks all (before Alt+A sends and Alt+N switches tabs)
@@ -2124,9 +2127,10 @@ export class UI {
2124
2127
  // multi: tick several with Space; returns the ticked items (an array), or null.
2125
2128
  // quiet: the question and answer aren't left in the conversation (a question before it starts).
2126
2129
  // fixed: a dialog: no typing to filter, no other keys meanwhile.
2130
+ // ctrlC: Ctrl+C closes it too, like Esc (not the first half of quitting).
2127
2131
  // auto: { item, secs }: nobody answers for secs seconds (each key starts the wait again) → item is chosen.
2128
2132
  // tabs: a row of tabs above it (several questions); nav: ←/→ (Tab, Shift+Tab) close it with { nav: -1 | 1 }.
2129
- async pick(title, items, { filter = '', multi = false, quiet = false, fixed = false, body = '', auto = null, tabs = '', nav = false } = {}) {
2133
+ async pick(title, items, { filter = '', multi = false, quiet = false, fixed = false, body = '', auto = null, tabs = '', nav = false, ctrlC = false } = {}) {
2130
2134
  if (!this.full) {
2131
2135
  items.forEach((it, i) => this.print(` ${i + 1}. ${it.group ? `${it.group} · ` : ''}${it.label}${it.desc ? ' ' + c.dim(it.desc) : ''}`))
2132
2136
  const a = await this.ask(`${title} ${c.dim(multi ? '(numbers, like 1,3)' : '(number)')}: `)
@@ -2138,7 +2142,7 @@ export class UI {
2138
2142
  }
2139
2143
  await this.#free()
2140
2144
  if (multi) for (const it of items) if (!it.only) it.checked ??= false
2141
- this.menu.pick = { items, chosen: null, multi, quiet, fixed, body, tabs, nav, auto: auto && { ...auto } }
2145
+ this.menu.pick = { items, chosen: null, multi, quiet, fixed, body, tabs, nav, ctrlC, auto: auto && { ...auto } }
2142
2146
  this.autoPicked = false // chosen for the user (nobody answered in time), for the caller to say so
2143
2147
  if (auto) {
2144
2148
  this.#armAuto()