heartcode 0.1.32 → 0.1.33

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,18 @@
2
2
 
3
3
  What changed in each version of HeartCode, newest first.
4
4
 
5
+ ## 0.1.33 (2026-11-01)
6
+
7
+ - Text you may need can be selected and copied, not only the conversation: drag to select (copied
8
+ when you let go), double-click to copy a word (an address, a path, a model's name). Inside a
9
+ dialog (the settings page's address, /help, /context, /diff, the background logs, a permission's
10
+ command, the choices), the header's folder (a double click copies the whole path, also when it's
11
+ shown cut), the input box and the status bar. Not the tab bar, the borders or the key hints. A
12
+ plain click in a dialog still does its job (a tab in the background logs). /help lists it, and
13
+ Shift+drag (Option+drag on macOS) for the terminal's own selection.
14
+ - Windows: the browser opens through Windows' URL handler (rundll32 url.dll,FileProtocolHandler)
15
+ instead of `cmd /c start`, for /settings and an MCP server's sign-in page.
16
+
5
17
  ## 0.1.32 (2026-11-01)
6
18
 
7
19
  - Dialogs: pickers (`/select_model`, `/resume`, `/rewind`, `/export`…), permission questions, typed
package/bin/heartcode.js CHANGED
@@ -173,6 +173,9 @@ function keysHelp(keys = {}) {
173
173
  [[forAct('scroll_up'), forAct('scroll_down')].filter(Boolean).join(' / '), 'scroll the conversation a page'],
174
174
  [[forAct('scroll_line_up'), forAct('scroll_line_down')].filter(Boolean).join(' / '), 'scroll a few lines'],
175
175
  ['Ctrl+C', 'stop · twice quits HeartCode'],
176
+ ['Drag', 'select and copy: the conversation, a dialog, the folder, the input, the status bar'],
177
+ ['Double-click', 'copy the word under it (an address, a path, a model)'],
178
+ [process.platform === 'darwin' ? 'Option+drag' : 'Shift+drag', "the terminal's own selection, past HeartCode's"],
176
179
  ].filter(([k]) => k)
177
180
  return rows
178
181
  }
@@ -244,7 +247,7 @@ class App {
244
247
  if (!this.ui.noUser)
245
248
  mcp.onSignIn = (name, url) => {
246
249
  this.ui.print(`${c.info('↗')} ${c.bold(name)} ${c.muted('needs you to sign in; opening your browser…')}\n ${c.faint(url)}`)
247
- const [cmd, ...args] = process.platform === 'darwin' ? ['open', url] : process.platform === 'win32' ? ['cmd', '/c', 'start', '', url] : ['xdg-open', url]
250
+ const [cmd, ...args] = process.platform === 'darwin' ? ['open', url] : process.platform === 'win32' ? ['rundll32', 'url.dll,FileProtocolHandler', url] : ['xdg-open', url]
248
251
  spawnSync(cmd, args, { stdio: 'ignore' })
249
252
  this.ui.spinner(`waiting for you to sign in to ${name} in the browser · Esc to stop`)
250
253
  }
@@ -1164,9 +1167,11 @@ function useModel(app, { provider, model }) {
1164
1167
  // The settings page (/settings): on while its dialog is (one at a time).
1165
1168
  let settingsPage = null
1166
1169
 
1170
+ // The browser, with a page. Windows: its URL handler (cmd's start mangles a URL whose arguments
1171
+ // it reads as its own, and wants a quoted empty title first).
1167
1172
  function openBrowser(url) {
1168
1173
  if (process.env.HEART_NO_BROWSER) return
1169
- const [cmd, ...args] = process.platform === 'darwin' ? ['open', url] : process.platform === 'win32' ? ['cmd', '/c', 'start', '', url] : ['xdg-open', url]
1174
+ const [cmd, ...args] = process.platform === 'darwin' ? ['open', url] : process.platform === 'win32' ? ['rundll32', 'url.dll,FileProtocolHandler', url] : ['xdg-open', url]
1170
1175
  spawnSync(cmd, args, { stdio: 'ignore' })
1171
1176
  }
1172
1177
 
@@ -1781,6 +1786,7 @@ async function repl(app, f = {}) {
1781
1786
  // Pinned to the top of the screen; /clear_chat and scrolling leave it alone.
1782
1787
  const home = process.env.HOME
1783
1788
  const where = home && app.root.startsWith(home) ? '~' + app.root.slice(home.length) : app.root
1789
+ ui.folder = app.root // what a double click on the header's folder copies
1784
1790
  ui.header = (cols = 100) => [
1785
1791
  `${c.brand('♥')} ${c.bright(c.bold('HeartCode'))} ${c.faint(VERSION)} ${c.muted(where.length > cols - 16 ? '…' + where.slice(-(cols - 17)) : where)}`,
1786
1792
  [['/', 'run a command'], ['@', 'attach a file'], ...(ui.voiceReady?.() ? [['Space', 'talk (voice)']] : []), [NEWLINE_KEY, 'add a new line'], ['Esc', 'stop'], ['Shift+Tab', 'change permissions']].map(([k, d]) => `${c.muted(k)} ${c.faint(d)}`).join(c.ghost(' · ')),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heartcode",
3
- "version": "0.1.32",
3
+ "version": "0.1.33",
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/ui.js CHANGED
@@ -739,10 +739,13 @@ export class UI {
739
739
  const blank = c.brand('│') + ' '.repeat(W) + c.brand('│')
740
740
  for (let i = 0; i < PY; i++) out += row(1 + i, blank)
741
741
  for (let i = 0; i < h; i++) out += row(1 + PY + i, c.brand('│') + ' '.repeat(PX) + pad(lines[i] ?? '', w) + ' '.repeat(PX) + c.brand('│'))
742
+ // what's in it can be selected (copied), all but its last line (the keys)
743
+ const last = lines.findLastIndex((l) => String(l ?? '').trim())
744
+ for (let i = 0; i < Math.min(h, last); i++) this.regions.set(y + 1 + PY + i, { x: x + 1 + PX, text: fit(lines[i] ?? '', w).replace(/\x1b\[[0-9;]*m/g, '').trimEnd() })
742
745
  for (let i = 0; i < PY; i++) out += row(1 + PY + h + i, blank)
743
746
  out += row(2 + 2 * PY + h - 1, c.brand('╰' + '─'.repeat(W) + '╯'))
744
747
  const cur = d.cursor?.(w)
745
- return out + (cur ? `\x1b[${y + 1 + PY + cur.row};${x + 1 + PX + Math.min(cur.col, w - 1)}H\x1b[?25h` : '\x1b[?25l')
748
+ return [out, cur ? `\x1b[${y + 1 + PY + cur.row};${x + 1 + PX + Math.min(cur.col, w - 1)}H\x1b[?25h` : '\x1b[?25l']
746
749
  }
747
750
 
748
751
  // The question being asked, as a dialog: its title; what's typed (the filter, or the answer) with the
@@ -916,25 +919,57 @@ export class UI {
916
919
 
917
920
  // The mouse: the wheel scrolls the conversation; dragging selects in it, copied when let go
918
921
  // (the terminal can't select itself while HeartCode takes the mouse). A click or a key clears it.
922
+ // The mouse: the wheel scrolls (a dialog's own text, else the conversation); dragging selects, copied
923
+ // when let go: in the conversation (it stays selected as it scrolls), in a dialog, the header's
924
+ // folder, the input box or the status bar; a double click copies the word under it (an address, a
925
+ // path, a model's name). The terminal can't select itself while HeartCode takes the mouse
926
+ // (Shift+drag, or Option+drag on macOS, still lets it). A click or a key clears a selection.
919
927
  #mouse(b, x, y, up) {
920
928
  if (!this.full) return
921
- if (b & 64) return (b & 0xc3) === 64 || (b & 0xc3) === 65 ? this.scrollBy(b & 1 ? -3 : 3) : undefined // 64 up, 65 down
929
+ const modal = Boolean(this.dialog || (this.asking && !this.histOn && this.rl))
930
+ if (b & 64) {
931
+ if ((b & 0xc3) !== 64 && (b & 0xc3) !== 65) return
932
+ if (this.dialog) return this.dialog.key?.({ name: b & 1 ? 'down' : 'up', wheel: true }), this.render()
933
+ return this.scrollBy(b & 1 ? -3 : 3) // 64 up, 65 down
934
+ }
922
935
  if ((b & 3) !== 0 && !up) return // the left button only (a release says 3 in some terminals)
923
- if (this.dialog) {
924
- // the wheel scrolls it; a click inside goes to it, outside closes it
936
+ const press = !(b & 32) && !up
937
+ if (press) {
938
+ const twice = this.lastClick && Date.now() - this.lastClick.t < 450 && this.lastClick.x === x && this.lastClick.y === y
939
+ this.lastClick = { t: Date.now(), x, y }
940
+ if (twice) return this.#copyWord(x, y)
941
+ this.sel = null
942
+ this.ssel = null
943
+ this.flash = null
925
944
  const d = this.dialogAt
926
- if (b & 64) return (b & 0xc3) === 64 || (b & 0xc3) === 65 ? (this.dialog.key?.({ name: b & 1 ? 'down' : 'up', wheel: true }), this.render()) : undefined
927
- if ((b & 32) || up || !d) return
928
- if (x < d.x || y < d.y || x > d.x + d.W + 1 || y > d.y + d.H + 1) return this.setDialog(null) // outside it
929
- return this.dialog.click?.(x - d.cx, y - d.cy), this.render()
945
+ if (modal && d && (x < d.x || y < d.y || x > d.x + d.W + 1 || y > d.y + d.H + 1)) return this.dialog ? this.setDialog(null) : this.render() // outside a dialog: closed (a question stays)
946
+ if (!modal && y <= 3 && this.onTabClick) return this.onTabClick(x - 1) // the tab bar's 3 rows
947
+ if (modal || this.regions?.has(y)) {
948
+ // a dialog, the header, the input, the status bar: a screen selection (a click without a drag: the dialog's own)
949
+ this.ssel = { a: { x, y }, b: { x, y }, moved: false, rows: this.regions, inDialog: modal }
950
+ return this.render()
951
+ }
930
952
  }
931
- if (!(b & 32) && !up && y <= 3 && this.onTabClick) return this.onTabClick(x - 1) // the tab bar's 3 rows
932
-
953
+ if (this.ssel) {
954
+ const sel = this.ssel
955
+ if (x !== sel.b.x || y !== sel.b.y) Object.assign(sel, { b: { x, y }, moved: true })
956
+ if (up) {
957
+ this.ssel = null
958
+ const text = sel.moved && this.#selectedRows(sel).map((r) => r.text.trimEnd()).join('\n').trim()
959
+ if (text) this.#copied(text)
960
+ else if (sel.inDialog && this.dialog && this.dialogAt) this.dialog.click?.(x - this.dialogAt.cx, y - this.dialogAt.cy)
961
+ else if (sel.inDialog) return this.render()
962
+ if (text) this.flash = sel // left lit a moment, so you see what was copied
963
+ if (text) setTimeout(() => this.flash === sel && ((this.flash = null), this.render()), 700).unref?.()
964
+ }
965
+ return this.render()
966
+ }
967
+ if (modal) return
933
968
  const v = this.viewAt
934
969
  if (!v) return
935
970
  const r = Math.min(Math.max(y - 1 - v.first, 0), v.avail - 1) // a drag past the edge stops at it
936
971
  const at = { row: v.top + Math.min(r, Math.max(0, v.count - 1)), col: x - 1 }
937
- if (!(b & 32) && !up) {
972
+ if (press) {
938
973
  // a press: starts a selection, inside the conversation only
939
974
  this.sel = y - 1 >= v.first && y - 1 < v.first + v.count ? { a: at, b: at, moved: false } : null
940
975
  return this.render()
@@ -944,10 +979,39 @@ export class UI {
944
979
  if (up) {
945
980
  const text = this.sel.moved && this.#selected()
946
981
  if (!text) this.sel = null
947
- else this.notice(`copied ${text.length} character${text.length === 1 ? '' : 's'}${copyText(text) === 'osc' ? ' (through the terminal)' : ''}`)
982
+ else this.#copied(text)
948
983
  }
949
984
  this.render()
950
985
  }
986
+ #copied(text) {
987
+ this.notice(`copied ${text.length} character${text.length === 1 ? '' : 's'}${copyText(text) === 'osc' ? ' (through the terminal)' : ''}`)
988
+ }
989
+ // A double click: the word under it (no spaces; quotes and brackets around it left out), copied.
990
+ #copyWord(x, y) {
991
+ this.sel = null
992
+ let row = this.regions?.get(y)
993
+ const v = this.viewAt
994
+ if (!row && v && !this.dialog && y - 1 >= v.first && y - 1 < v.first + v.count) row = { x: 1, text: (this.#rows(this.out.columns || 80)[v.top + y - 1 - v.first] ?? '').replace(/\x1b\[[0-9;]*m/g, '') }
995
+ if (!row) return
996
+ const cells = [] // [char, its column]
997
+ let col = row.x
998
+ for (const ch of row.text) cells.push([ch, col]), (col += width(ch))
999
+ const at = cells.findIndex(([, cx], i) => x >= cx && x < (cells[i + 1]?.[1] ?? cx + 1))
1000
+ if (at === -1 || /\s/.test(cells[at][0])) return
1001
+ let s = at
1002
+ let e = at
1003
+ while (s > 0 && !/\s/.test(cells[s - 1][0])) s--
1004
+ while (e < cells.length - 1 && !/\s/.test(cells[e + 1][0])) e++
1005
+ while (s < e && /["'`(\[{<]/.test(cells[s][0])) s++
1006
+ while (e > s && /["'`)\]}>,;:.!?]/.test(cells[e][0]) && !/^https?:\/\/\S+\/$/.test(cells.slice(s, e + 1).map((c) => c[0]).join(''))) e--
1007
+ let word = cells.slice(s, e + 1).map((c) => c[0]).join('')
1008
+ if (row.path && /[\\/~…]/.test(word)) word = row.path // the folder in the header: all of it, not what fits
1009
+ this.#copied(word)
1010
+ const sel = { a: { x: cells[s][1], y }, b: { x: cells[e][1], y }, rows: new Map([[y, row]]) }
1011
+ this.flash = sel
1012
+ setTimeout(() => this.flash === sel && ((this.flash = null), this.render()), 700).unref?.()
1013
+ this.render()
1014
+ }
951
1015
  #selRange() {
952
1016
  const { a, b } = this.sel
953
1017
  return a.row < b.row || (a.row === b.row && a.col <= b.col) ? [a, b] : [b, a]
@@ -1098,11 +1162,49 @@ export class UI {
1098
1162
  }
1099
1163
  box.forEach((line, i) => (s += `\x1b[${inputTop + i};1H${row(line)}`))
1100
1164
  below.forEach((line, i) => (s += `\x1b[${inputTop + inputRows + i};1H${row(line)}`))
1101
- if (this.dialog) s += this.#drawDialog(cols, rows, { title: this.dialog.title, fill: this.dialog.fill, lines: (w, h) => this.dialog.draw(w, h) }) // over everything, the cursor hidden
1102
- else if (asked) s += this.#drawDialog(cols, rows, this.#question()) // a question: its cursor in the box
1103
- else if (this.asking || typing) s += `\x1b[${inputTop + input.cur.row - first};${input.cur.col + 1}H\x1b[?25h`
1104
- else s += `\x1b[${inputTop};1H`
1105
- out.write(s)
1165
+ // what can be selected besides the conversation (screen rows from 1): the header's first line (the
1166
+ // project's folder), the input box, the status bar; with a dialog open, only what's in it
1167
+ const plain = (t) => String(t ?? '').replace(/\x1b\[[0-9;]*m/g, '')
1168
+ const tabRows = this.tabBar?.(cols)?.length ?? 0
1169
+ this.regions = new Map()
1170
+ if (this.header && head[tabRows] !== undefined) this.regions.set(tabRows + 1, { x: 1, text: plain(head[tabRows]), path: this.folder }) // path: the whole folder (shown cut when long)
1171
+ box.forEach((line, i) => this.regions.set(inputTop + i, { x: 1, text: plain(line) }))
1172
+ below.slice(1).forEach((line, i) => this.regions.set(inputTop + inputRows + 1 + i, { x: 1, text: plain(line) }))
1173
+ let cursor
1174
+ if (this.dialog || asked) {
1175
+ this.regions = new Map()
1176
+ const [box, cur] = this.#drawDialog(cols, rows, this.dialog ? { title: this.dialog.title, fill: this.dialog.fill, lines: (w, h) => this.dialog.draw(w, h) } : this.#question())
1177
+ s += box
1178
+ cursor = cur // a question: its cursor in the box; else hidden
1179
+ } else {
1180
+ this.dialogAt = null
1181
+ cursor = this.asking || typing ? `\x1b[${inputTop + input.cur.row - first};${input.cur.col + 1}H\x1b[?25h` : `\x1b[${inputTop};1H`
1182
+ }
1183
+ out.write(s + this.#screenSelection() + cursor)
1184
+ }
1185
+
1186
+ // A selection outside the conversation (in a dialog, the header, the input, the status bar), or a
1187
+ // word just double-clicked: drawn reversed over what's there.
1188
+ #screenSelection() {
1189
+ const sel = this.ssel ?? this.flash
1190
+ if (!sel) return ''
1191
+ let out = ''
1192
+ for (const { y, x, text } of this.#selectedRows(sel)) out += `\x1b[${y};${x}H\x1b[7m${text}\x1b[27m`
1193
+ return out
1194
+ }
1195
+ // The rows a screen selection covers: [{ y, x, text }] (x: where the selected part starts).
1196
+ #selectedRows(sel) {
1197
+ const [a, b] = sel.a.y < sel.b.y || (sel.a.y === sel.b.y && sel.a.x <= sel.b.x) ? [sel.a, sel.b] : [sel.b, sel.a]
1198
+ const out = []
1199
+ for (let y = a.y; y <= b.y; y++) {
1200
+ const r = sel.rows?.get(y) ?? this.regions?.get(y)
1201
+ if (!r) continue
1202
+ const end = r.x + width(r.text) // just past its last cell
1203
+ const from = Math.max(r.x, y === a.y ? a.x : r.x)
1204
+ const to = Math.min(end, y === b.y ? b.x + 1 : end)
1205
+ if (to > from) out.push({ y, x: from, text: sliceCols(r.text, from - r.x, to - r.x) })
1206
+ }
1207
+ return out
1106
1208
  }
1107
1209
 
1108
1210
 
@@ -1115,7 +1217,7 @@ export class UI {
1115
1217
  this.ttyWrite = write
1116
1218
  rl._ttyWrite = (s, key = {}) => {
1117
1219
  if (!this.full) return write(s, key)
1118
- if (this.sel) (this.sel = null), this.render() // a key ends a selection
1220
+ if (this.sel || this.ssel) (this.sel = this.ssel = null), this.render() // a key ends a selection
1119
1221
  const bound = !(key.ctrl && key.name === 'c') && this.keys[keyId(key, s)] // ~/.heart/keybindings.json
1120
1222
  // a dialog: its keys, all of them; Esc (or its own key) closes it; Ctrl+C still stops and quits
1121
1223
  if (this.dialog && !(key.ctrl && key.name === 'c')) {