heartcode 0.1.58 → 0.1.60
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 +57 -0
- package/README.md +27 -10
- package/SKILL.md +59 -17
- package/bin/heart.js +1 -1
- package/bin/heartcode.js +92 -66
- package/package.json +1 -1
- package/prompts/agent.md +64 -15
- package/src/acp.js +3 -3
- package/src/agent.js +175 -44
- package/src/capabilities.js +1 -1
- package/src/client.js +41 -10
- package/src/config.js +3 -3
- package/src/context.js +1 -1
- package/src/guided.js +26 -17
- package/src/headless.js +63 -15
- package/src/importer.js +7 -7
- package/src/log.js +3 -3
- package/src/mcp.js +1 -1
- package/src/memory.js +1 -1
- package/src/oauth.js +1 -1
- package/src/probe.js +14 -4
- package/src/reset.js +2 -2
- package/src/sessions.js +2 -2
- package/src/settings.html +203 -159
- package/src/settings.js +49 -20
- package/src/tabs.js +4 -1
- package/src/telegram.js +1 -1
- package/src/tools.js +102 -33
- package/src/tree.js +1 -1
- package/src/ui.js +110 -26
- package/src/usage.js +9 -0
- package/src/voice.js +1 -1
- package/src/web.js +1 -1
package/src/ui.js
CHANGED
|
@@ -107,11 +107,14 @@ export function setTheme(name = 'dark') {
|
|
|
107
107
|
}
|
|
108
108
|
setTheme()
|
|
109
109
|
|
|
110
|
-
// keybindings.json: { "alt+
|
|
110
|
+
// keybindings.json: { "alt+g": "cycle_permissions", "alt+r": "/rewind", "shift+tab": "none" }.
|
|
111
111
|
// Actions: stop, send_first, send_all, queue_mode, cycle_permissions, newline, clear_input, scroll_up, scroll_down (a page),
|
|
112
|
-
// scroll_line_up, scroll_line_down (3 lines), scroll_top, scroll_bottom, voice, new_tab,
|
|
112
|
+
// scroll_line_up, scroll_line_down (3 lines), scroll_top, scroll_bottom, voice, toggle_thinking, background_log, new_tab,
|
|
113
113
|
// close_tab, next_tab, prev_tab, tab_1…tab_9, none (turns a
|
|
114
114
|
// built-in key off); anything else is sent as typed (a /command or a message). Ctrl+C stays Ctrl+C.
|
|
115
|
+
// A key as people read it ("alt+shift+down" → "Alt+Shift+↓")
|
|
116
|
+
const KEY_NAMES = { pageup: 'PgUp', pagedown: 'PgDn', up: '↑', down: '↓', left: '←', right: '→', ctrl: 'Ctrl', alt: 'Alt', shift: 'Shift' }
|
|
117
|
+
export const prettyKey = (k) => k.split('+').map((p) => KEY_NAMES[p] ?? (p.length === 1 ? p.toUpperCase() : p[0].toUpperCase() + p.slice(1))).join('+')
|
|
115
118
|
const CONTROL_KEYS = { '\x1c': 'ctrl+\\', '\x1d': 'ctrl+]', '\x1e': 'ctrl+^', '\x1f': 'ctrl+_' } // no name from readline
|
|
116
119
|
export const keyId = (key, s = '') => CONTROL_KEYS[key.sequence ?? s] ?? [key.ctrl && 'ctrl', key.meta && 'alt', key.shift && 'shift', key.name ?? s].filter(Boolean).join('+').toLowerCase()
|
|
117
120
|
// The built-in keys use Alt/Option, never Ctrl (the user's rule; Ctrl keys also clash with the shell and
|
|
@@ -124,7 +127,7 @@ export const keyId = (key, s = '') => CONTROL_KEYS[key.sequence ?? s] ?? [key.ct
|
|
|
124
127
|
// Alt+N/P, Alt+1…9: tabs; Shift+↑↓ and Alt+↑↓ scroll the conversation (as PgUp/PgDn and the mouse
|
|
125
128
|
// wheel do), Alt+Shift+↑↓ to its top and bottom; Alt+O: all of the model's thinking, or its last lines.
|
|
126
129
|
// keybindings.json can move any of them.
|
|
127
|
-
export const DEFAULT_KEYS = { 'alt+o': '
|
|
130
|
+
export const DEFAULT_KEYS = { 'alt+o': 'toggle_thinking', 'alt+b': 'background_log', 'alt+s': 'send_first', 'alt+a': 'send_all', 'alt+m': 'queue_mode', 'shift+up': 'scroll_line_up', 'shift+down': 'scroll_line_down', 'alt+up': 'scroll_up', 'alt+down': 'scroll_down', 'alt+shift+up': 'scroll_top', 'alt+shift+down': 'scroll_bottom', 'alt+t': 'new_tab', 'alt+w': 'close_tab', 'alt+n': 'next_tab', 'alt+p': 'prev_tab', ...Object.fromEntries([1, 2, 3, 4, 5, 6, 7, 8, 9].map((n) => [`alt+${n}`, `tab_${n}`])) }
|
|
128
131
|
export function loadKeys(file = path.join(HOME, 'keybindings.json')) {
|
|
129
132
|
let raw = {}
|
|
130
133
|
try {
|
|
@@ -747,6 +750,7 @@ export const PERMISSIONS = [
|
|
|
747
750
|
]
|
|
748
751
|
|
|
749
752
|
let drewLast = null // the UI (tab) that last drew the screen: only its own last frame can be diffed against
|
|
753
|
+
let drewAt = null // the tab whose frame lastFrame is (another tab drawing in between: it's no longer on screen)
|
|
750
754
|
export class UI {
|
|
751
755
|
constructor({ yes = false, input = process.stdin, output = process.stdout } = {}) {
|
|
752
756
|
this.permission = yes ? 'all' : 'ask' // see PERMISSIONS
|
|
@@ -780,7 +784,7 @@ export class UI {
|
|
|
780
784
|
this.frame = 0
|
|
781
785
|
this.dialog = null // a box over the screen (the background commands' logs)
|
|
782
786
|
this.waitingFor = null // () → the model a request waits on (the app's), for "waiting for <model>"
|
|
783
|
-
this.helpers = new Map() // helpers at work (agent.js): label → what it's doing now, shown under the spinner
|
|
787
|
+
this.helpers = new Map() // helpers at work (agent.js): label → { model, what it's doing now }, shown under the spinner
|
|
784
788
|
}
|
|
785
789
|
|
|
786
790
|
// A dialog: a box in the middle, 70% of the screen each way, the conversation going on around it;
|
|
@@ -894,7 +898,7 @@ export class UI {
|
|
|
894
898
|
const own = pick?.items.some((x) => x.own) // typing goes into "Something else", not a filter
|
|
895
899
|
const typingOwn = m.items[m.sel]?.item?.own && m.items[m.sel].item.text // ←/→ move in what's typed; Tab goes on
|
|
896
900
|
const body = pick?.body ? String(pick.body).split('\n') : []
|
|
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
|
|
901
|
+
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 an answer' : 'type to filter'}` : `↑↓ move · Enter choose · Esc cancel${own ? ' · type an answer' : cards ? '' : ' · type to filter'}`) : 'Enter send · Esc cancel')
|
|
898
902
|
const timer = this.autoLine() // on its own line, so it's seen (and not cut off with the keys)
|
|
899
903
|
const long = width(title) > this.#dialogBox(cols, rows).w - 6 // too long for the border: inside instead, said once
|
|
900
904
|
// at most n rows; the rest said to be there
|
|
@@ -970,8 +974,9 @@ export class UI {
|
|
|
970
974
|
const open = todos.filter((t) => t.status !== 'completed')
|
|
971
975
|
if (!open.length) return []
|
|
972
976
|
const done = todos.length - open.length
|
|
973
|
-
const mark = { pending: c.muted('☐'), in_progress: c.info('◐'), completed: c.faint('☑') }
|
|
974
|
-
const
|
|
977
|
+
const mark = { pending: c.muted('☐'), in_progress: c.info('◐'), completed: c.faint('☑'), stuck: c.warn('⚠') }
|
|
978
|
+
const by = (t) => (t.by ? c.faint(' · ') + (t.status === 'in_progress' ? c.info(t.by) : c.faint(t.by)) : '') // the model a part was given to
|
|
979
|
+
const line = (t) => fit(` ${mark[t.status]} ${t.status === 'in_progress' ? c.info(c.bold(t.content)) : t.status === 'completed' ? c.faint(t.content) : t.status === 'stuck' ? c.warn(t.content) : c.muted(t.content)}${by(t)}`, cols)
|
|
975
980
|
const shown = todos.length <= 8 ? todos : open.slice(0, 7)
|
|
976
981
|
return [
|
|
977
982
|
fit(` ${c.muted('Plan')} ${c.faint(`· ${done} of ${todos.length} done`)}`, cols),
|
|
@@ -1015,6 +1020,7 @@ export class UI {
|
|
|
1015
1020
|
// who: the model thinking, named over its thinking (helpers say their own: helperUI in agent.js)
|
|
1016
1021
|
response(who) {
|
|
1017
1022
|
const t0 = Date.now()
|
|
1023
|
+
this.lastThought = null // the key shows this reply's thinking from now on, not an older one's
|
|
1018
1024
|
const secs = () => duration(Date.now() - t0)
|
|
1019
1025
|
const write = (x) => this.write(x)
|
|
1020
1026
|
let think = null
|
|
@@ -1025,7 +1031,7 @@ export class UI {
|
|
|
1025
1031
|
if (thought.trim() && !think) {
|
|
1026
1032
|
// what it thought stays in the conversation: its last two lines (all of it: Alt+O)
|
|
1027
1033
|
const last = thought.split('\n').map((l) => l.trim()).filter(Boolean).slice(-2)
|
|
1028
|
-
this.print(c.faint(c.italic(`✻ ${who ? `${who} ` : ''}thought for ${secs()} ·
|
|
1034
|
+
this.print(c.faint(c.italic(`✻ ${who ? `${who} ` : ''}thought for ${secs()}${this.keyFor('toggle_thinking') ? ` · ${this.keyFor('toggle_thinking')} shows all of it` : ''}`)))
|
|
1029
1035
|
this.print(c.think(c.italic(last.map((l) => ` ${l}`).join('\n'))))
|
|
1030
1036
|
this.lastThought = { who, text: thought } // Alt+O shows it, now that it's over (showLastThought)
|
|
1031
1037
|
}
|
|
@@ -1041,6 +1047,8 @@ export class UI {
|
|
|
1041
1047
|
}
|
|
1042
1048
|
if (!think) {
|
|
1043
1049
|
this.thinkTail = ''
|
|
1050
|
+
this.replying = true // its own text shows it's at work: no spinner line after it
|
|
1051
|
+
this.liveStep = null
|
|
1044
1052
|
this.gap()
|
|
1045
1053
|
this.print(c.faint(c.italic(`✻ ${who ? `${who} is thinking` : 'Thinking'}…`)))
|
|
1046
1054
|
const style = (x) => c.think(c.italic(x))
|
|
@@ -1054,6 +1062,8 @@ export class UI {
|
|
|
1054
1062
|
if (!t) return
|
|
1055
1063
|
this.tokenAt = Date.now()
|
|
1056
1064
|
if (!text) {
|
|
1065
|
+
this.replying = true
|
|
1066
|
+
this.liveStep = null
|
|
1057
1067
|
if (this.label === 'thinking') this.label = 'answering'
|
|
1058
1068
|
think?.end()
|
|
1059
1069
|
this.gap()
|
|
@@ -1067,6 +1077,7 @@ export class UI {
|
|
|
1067
1077
|
if (text) text.end()
|
|
1068
1078
|
else if (think) think.end()
|
|
1069
1079
|
else summary()
|
|
1080
|
+
this.replying = false
|
|
1070
1081
|
this.afterBlock = Boolean(text || think)
|
|
1071
1082
|
},
|
|
1072
1083
|
}
|
|
@@ -1116,8 +1127,10 @@ export class UI {
|
|
|
1116
1127
|
// alternate screen · kitty keyboard protocol (Shift/Cmd+Enter are told apart) · bracketed paste
|
|
1117
1128
|
// · mouse reports (SGR), when HeartCode takes the mouse
|
|
1118
1129
|
this.out.write('\x1b[?1049h\x1b[H\x1b[2J\x1b[>1u\x1b[?2004h' + this.mouseOn)
|
|
1119
|
-
this.frame0 = null
|
|
1120
|
-
|
|
1130
|
+
this.frame0 = this.lastFrame = null
|
|
1131
|
+
// a new size: the whole screen again, after readline's own handler (it clears from its cursor down,
|
|
1132
|
+
// which took the input box and the status bar with it)
|
|
1133
|
+
this.out.on('resize', () => setImmediate(() => ((this.frameSize = this.lastFrame = null), this.render())))
|
|
1121
1134
|
this.#rl()
|
|
1122
1135
|
process.on('exit', () => this.leaveFullscreen())
|
|
1123
1136
|
}
|
|
@@ -1135,12 +1148,18 @@ export class UI {
|
|
|
1135
1148
|
this.rl?.resume()
|
|
1136
1149
|
if (wasFull) {
|
|
1137
1150
|
this.out.write('\x1b[?1049h\x1b[>1u\x1b[?2004h' + this.mouseOn)
|
|
1138
|
-
this.frame0 = null
|
|
1151
|
+
this.frame0 = this.lastFrame = null
|
|
1139
1152
|
this.render()
|
|
1140
1153
|
}
|
|
1141
1154
|
}
|
|
1142
1155
|
}
|
|
1143
1156
|
|
|
1157
|
+
// The key bound to an action now (keybindings.json can move or remove it), as people read it; null: none
|
|
1158
|
+
keyFor(action) {
|
|
1159
|
+
const k = Object.entries(this.keys ?? {}).find(([, v]) => v === action)?.[0]
|
|
1160
|
+
return k ? prettyKey(k) : null
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1144
1163
|
// Taking the mouse, or giving it back to the terminal, now (the settings page's switch)
|
|
1145
1164
|
setMouse(on) {
|
|
1146
1165
|
this.mouseOn = on ? MOUSE_ON : ''
|
|
@@ -1214,7 +1233,7 @@ export class UI {
|
|
|
1214
1233
|
this.render()
|
|
1215
1234
|
}
|
|
1216
1235
|
#copied(text) {
|
|
1217
|
-
this.notice(`copied ${text.length} character${text.length === 1 ? '' : 's'}${copyText(text) === 'osc' ? ' (if
|
|
1236
|
+
this.notice(`copied ${text.length} character${text.length === 1 ? '' : 's'}${copyText(text) === 'osc' ? ' (if the terminal allows it)' : ''}`)
|
|
1218
1237
|
}
|
|
1219
1238
|
// A double click: the word under it (no spaces; quotes and brackets around it left out), copied.
|
|
1220
1239
|
#copyWord(x, y) {
|
|
@@ -1325,14 +1344,23 @@ export class UI {
|
|
|
1325
1344
|
}
|
|
1326
1345
|
|
|
1327
1346
|
// The conversation as screen rows (wrapped to the width; cached per line).
|
|
1347
|
+
// While it works, the conversation shows where too: the step running (its ● spins until its
|
|
1348
|
+
// result), else (waiting on the model between steps) a line of its own at the end, as the
|
|
1349
|
+
// spinner under the conversation says it.
|
|
1328
1350
|
#rows(cols) {
|
|
1329
1351
|
if (this.wrapCols !== cols) [this.wrapped, this.wrapCols] = [[], cols]
|
|
1352
|
+
const spin = this.timer && !this.asking ? c.brand(FRAMES[this.frame % FRAMES.length]) : null
|
|
1353
|
+
let last = this.log.length - 1
|
|
1354
|
+
while (last >= 0 && !this.log[last]) last--
|
|
1355
|
+
const live = spin && this.liveStep && this.log[last] === this.liveStep ? last : -1 // only while nothing came after it
|
|
1330
1356
|
const out = []
|
|
1331
1357
|
this.log.forEach((line, i) => {
|
|
1358
|
+
if (i === live) return out.push(...wrapHang(line.replace('●', spin), cols)) // not kept: it changes every frame
|
|
1332
1359
|
const w = this.wrapped[i]
|
|
1333
1360
|
if (!w || w.src !== line) this.wrapped[i] = { src: line, rows: wrapHang(line, cols) } // at spaces, wrapped rows under the text
|
|
1334
1361
|
out.push(...this.wrapped[i].rows)
|
|
1335
1362
|
})
|
|
1363
|
+
if (spin && live === -1 && !this.replying && this.statusText) out.push(...wrapHang(`${spin} ${c.muted(this.statusText)}`, cols))
|
|
1336
1364
|
return out
|
|
1337
1365
|
}
|
|
1338
1366
|
|
|
@@ -1364,26 +1392,27 @@ export class UI {
|
|
|
1364
1392
|
const label = this.#label()
|
|
1365
1393
|
const waiting = request && !(this.tokenAt >= request) && this.beforeRetry === undefined
|
|
1366
1394
|
const status = waiting ? `${/^(working|thinking|answering)$/.test(plainOf(label)) ? '' : `${label} · `}waiting for ${this.waitingFor?.() || 'the model'} ${short(Date.now() - request)}` : label
|
|
1367
|
-
const timer = this.busySince ? [this.beforeRetry !== undefined && 'no answer yet', `${short(this.worked())} in all`, 'Esc to stop', this.thinkTail && '
|
|
1395
|
+
const timer = this.busySince ? [this.beforeRetry !== undefined && 'no answer yet', `${short(this.worked())} in all`, 'Esc twice to stop', this.thinkTail && this.keyFor('toggle_thinking') && `${this.keyFor('toggle_thinking')} shows all thinking`].filter(Boolean).join(' · ') : ''
|
|
1368
1396
|
if (this.thinkTail) {
|
|
1369
1397
|
// the thinking's last two lines (long ones wrapped), dim, changing as it comes
|
|
1370
1398
|
const w = Math.max(20, cols - 6)
|
|
1371
1399
|
const lines = this.thinkTail.split('\n').map((l) => l.replace(/\s+/g, ' ').trim()).filter(Boolean).flatMap((l) => l.match(new RegExp(`.{1,${w}}(\\s|$)|.{${w}}`, 'g')) ?? [l]).map((l) => l.trim()).filter(Boolean)
|
|
1372
1400
|
for (const l of lines.slice(-2)) bottom.push(fit(` ${c.think(c.italic(l))}`, cols))
|
|
1373
1401
|
}
|
|
1402
|
+
this.statusText = status // the same, at the end of the conversation (#rows)
|
|
1374
1403
|
bottom.push(fit(`${c.brand(FRAMES[this.frame % FRAMES.length])} ${c.muted(status)}`, cols))
|
|
1375
1404
|
if (timer) bottom.push(...wrapParts(timer, cols - 2).map((r) => fit(` ${c.faint(r)}`, cols)))
|
|
1376
1405
|
// helpers at work (agent.js keeps them in this.helpers: label → what it's doing), then the plan
|
|
1377
1406
|
const helpers = [...this.helpers]
|
|
1378
|
-
for (const [name, what] of helpers.slice(0, helpers.length > 6 ? 5 : 6)) bottom.push(fit(` ${c.faint('◦')} ${c.muted(name)}${what ? c.faint(` · ${what}`) : ''}`, cols))
|
|
1407
|
+
for (const [name, { model, what }] of helpers.slice(0, helpers.length > 6 ? 5 : 6)) bottom.push(fit(` ${c.faint('◦')} ${c.muted(name)}${model ? `${c.faint(' · ')}${c.info(model)}` : ''}${what ? c.faint(` · ${what}`) : ''}`, cols))
|
|
1379
1408
|
if (helpers.length > 6) bottom.push(c.faint(` … ${helpers.length - 5} more`))
|
|
1380
1409
|
bottom.push(...this.#todoLines(cols))
|
|
1381
1410
|
}
|
|
1382
|
-
if (this.scroll) bottom.push(c.dim(` ↓ ${Number.isFinite(this.scroll) ? this.scroll : 'more'} lines below · held here
|
|
1411
|
+
if (this.scroll) bottom.push(c.dim(` ↓ ${Number.isFinite(this.scroll) ? this.scroll : 'more'} lines below · held here for reading${this.keyFor('scroll_bottom') ? ` · ${this.keyFor('scroll_bottom')} to the bottom` : ''}`))
|
|
1383
1412
|
if (this.ahead.length) {
|
|
1384
1413
|
const key = (k, d) => `${c.muted(k)} ${c.faint(d)}`
|
|
1385
1414
|
const sep = c.ghost(' · ')
|
|
1386
|
-
const queued = `${c.bright(`queued ${this.ahead.length}`)}${sep}${c.faint(`when done: ${this.queueMode === 'one' ? 'one by one' : 'all together'}`)}${sep}${[
|
|
1415
|
+
const queued = `${c.bright(`queued ${this.ahead.length}`)}${sep}${c.faint(`when done: ${this.queueMode === 'one' ? 'one by one' : 'all together'}`)}${sep}${[['Esc', 'edit or cancel'], [this.keyFor('send_first'), 'send first now'], [this.keyFor('send_all'), 'send all now'], [this.keyFor('queue_mode'), 'change when done']].filter(([k]) => k).map(([k, d]) => key(k, d)).join(sep)}`
|
|
1387
1416
|
bottom.push(...wrapParts(queued, cols - 2, sep).map((r) => fit(` ${r}`, cols))) // on more lines, not cut
|
|
1388
1417
|
for (const [i, l] of this.ahead.slice(0, 5).entries()) bottom.push(fit(` ${c.accent(`${i + 1}.`)} ${c.muted(l.replace(/\s+/g, ' '))}`, cols))
|
|
1389
1418
|
if (this.ahead.length > 5) bottom.push(c.faint(` … ${this.ahead.length - 5} more`))
|
|
@@ -1416,12 +1445,18 @@ export class UI {
|
|
|
1416
1445
|
}
|
|
1417
1446
|
// only the rows that changed since the last frame are written (scrolling rewrote the whole screen
|
|
1418
1447
|
// every time); a dialog or a selection over it, or a resize: all of them
|
|
1419
|
-
|
|
1420
|
-
|
|
1448
|
+
// a dialog open in the last frame too: the same, as long as the box itself stays where it was (it's
|
|
1449
|
+
// drawn over the rows again each frame; all of them once it moved, grew or closed). Writing every
|
|
1450
|
+
// row each frame under it made it flicker, 12 times a second while the spinner turns.
|
|
1451
|
+
// (a selection drawn over the screen: all of them, every time, as its old cells must go)
|
|
1452
|
+
const overlay = this.ssel || this.flash ? 'selection' : this.dialog || asked ? 'dialog' : ''
|
|
1453
|
+
const was = overlay !== 'selection' && overlay === this.frameOverlay && this.frameSize === `${rows}x${cols}` && drewLast === this ? this.frame0 : null // another tab drew since: all of it
|
|
1421
1454
|
const frame = []
|
|
1455
|
+
let every = s // all the rows, for when the box moved (decided once it's drawn)
|
|
1422
1456
|
const put = (r, line, always = false) => {
|
|
1423
1457
|
const text = row(line)
|
|
1424
1458
|
frame[r] = text
|
|
1459
|
+
every += `\x1b[${r};1H${text}`
|
|
1425
1460
|
if (always || was?.[r] !== text) s += `\x1b[${r};1H${text}`
|
|
1426
1461
|
}
|
|
1427
1462
|
for (let r = 0; r < inputTop - 1; r++) {
|
|
@@ -1445,13 +1480,19 @@ export class UI {
|
|
|
1445
1480
|
if (this.dialog || asked) {
|
|
1446
1481
|
this.regions = new Map()
|
|
1447
1482
|
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(cols, rows))
|
|
1483
|
+
const rect = JSON.stringify(this.dialogAt)
|
|
1484
|
+
if (rect !== this.frameRect) s = every // it moved, grew or shrank: the rows it no longer covers again
|
|
1485
|
+
this.frameRect = rect
|
|
1448
1486
|
s += box
|
|
1449
1487
|
cursor = cur // a question: its cursor in the box; else hidden
|
|
1450
1488
|
} else {
|
|
1451
|
-
this.dialogAt = null
|
|
1489
|
+
this.dialogAt = this.frameRect = null
|
|
1452
1490
|
cursor = this.asking || typing ? `\x1b[${inputTop + input.cur.row - first};${input.cur.col + 1}H\x1b[?25h` : `\x1b[${inputTop};1H`
|
|
1453
1491
|
}
|
|
1454
|
-
|
|
1492
|
+
const frameText = `\x1b[?2026h${s}${this.#screenSelection()}${cursor}\x1b[?2026l` // shown at once where the terminal can (synchronized output), never half-drawn
|
|
1493
|
+
if (frameText === this.lastFrame && drewAt === this) return // the same as on screen (a spinner tick under a dialog): nothing written
|
|
1494
|
+
;[this.lastFrame, drewAt] = [frameText, this]
|
|
1495
|
+
out.write(frameText)
|
|
1455
1496
|
}
|
|
1456
1497
|
|
|
1457
1498
|
// A selection outside the conversation (in a dialog, the header, the input, the status bar), or a
|
|
@@ -1493,7 +1534,7 @@ export class UI {
|
|
|
1493
1534
|
const bound = !(key.ctrl && key.name === 'c') && this.keys[keyId(key, s)] // ~/.heart/keybindings.json
|
|
1494
1535
|
// a dialog: its keys, all of them; Esc (or its own key) closes it; Ctrl+C still stops and quits
|
|
1495
1536
|
if (this.dialog && !(key.ctrl && key.name === 'c')) {
|
|
1496
|
-
if (key.name === 'escape' || (bound && bound === this.dialog.toggle)) return this.setDialog(null)
|
|
1537
|
+
if (key.name === 'escape' || (bound && bound.replace(/^\//, '') === String(this.dialog.toggle ?? '').replace(/^\//, ''))) return this.setDialog(null)
|
|
1497
1538
|
return this.dialog.key?.(key, s), this.render()
|
|
1498
1539
|
}
|
|
1499
1540
|
if (this.recording) return this.recording.key(key, bound) // voice: Space, Enter, Esc; the rest waits
|
|
@@ -1570,7 +1611,7 @@ export class UI {
|
|
|
1570
1611
|
const onOwn = own && it?.item === own
|
|
1571
1612
|
const typing = own && !key.ctrl && !key.meta && ((key.name === 'backspace' && onOwn) || (/^[^\x00-\x1f\x7f]+$/.test(s ?? '') && !(key.name === 'space' && m.pick.multi && !onOwn)))
|
|
1572
1613
|
if (typing) {
|
|
1573
|
-
own.hint ??= own.text ? 'type
|
|
1614
|
+
own.hint ??= own.text ? 'type an answer' : own.desc // what it says before anything's typed
|
|
1574
1615
|
own.text = key.name === 'backspace' ? (own.text ?? '').slice(0, -1) : (own.text ?? '') + s
|
|
1575
1616
|
own.desc = own.text ? `› ${own.text}▏` : own.hint
|
|
1576
1617
|
if (m.pick.multi) own.checked = Boolean(own.text)
|
|
@@ -1650,15 +1691,40 @@ export class UI {
|
|
|
1650
1691
|
}
|
|
1651
1692
|
|
|
1652
1693
|
// input), sent when the answer is done, or at once with send_first / send_all. Esc stops the task.
|
|
1694
|
+
// Queued messages taken back into the box (Esc, ↑): before what's typed there, one a line.
|
|
1695
|
+
#unqueue(msgs) {
|
|
1696
|
+
const rl = this.rl
|
|
1697
|
+
rl.line = [...msgs, rl.line].filter((x) => x.trim()).join('\n')
|
|
1698
|
+
rl.cursor = rl.line.length
|
|
1699
|
+
this.escArm = 0
|
|
1700
|
+
this.render()
|
|
1701
|
+
}
|
|
1653
1702
|
#typeAhead(s, key, write) {
|
|
1654
1703
|
const rl = this.rl
|
|
1655
1704
|
const m = this.menu
|
|
1656
1705
|
const it = m.on && m.items[m.sel] // a suggestion is highlighted (commands/@files show while working too)
|
|
1706
|
+
// Esc, a layer at a time, and the work goes on: the queued messages come back into the box (to
|
|
1707
|
+
// change, or drop); then what's in the box is cleared; only then does Esc stop the work
|
|
1657
1708
|
if (key.name === 'escape') {
|
|
1658
1709
|
if (m.on) return (m.off = rl.line), this.#suggestWhileWorking() // first Esc just closes the suggestions
|
|
1710
|
+
if (this.ahead.length) {
|
|
1711
|
+
const n = this.ahead.length
|
|
1712
|
+
this.#unqueue(this.ahead.splice(0))
|
|
1713
|
+
return this.notice(`${n === 1 ? 'The queued message is' : `${n} queued messages are`} back in the box: change ${n === 1 ? 'it' : 'them'} and press Enter, or Esc to clear`, 4000)
|
|
1714
|
+
}
|
|
1715
|
+
if (rl.line.trim()) return this.clearInput(), (this.escArm = 0), this.notice('Cleared · Esc twice stops the answer', 2500)
|
|
1659
1716
|
return this.escStop()
|
|
1660
1717
|
}
|
|
1718
|
+
// ↑ in an empty box: the last queued message back into it, to change or drop
|
|
1719
|
+
if (key.name === 'up' && !rl.line && this.ahead.length && !it) return this.#unqueue([this.ahead.pop()])
|
|
1661
1720
|
if (key.name === 'tab' && key.shift) return this.cyclePermission()
|
|
1721
|
+
// Shift+Enter, Option+Enter: a new line in the box, as at the prompt (readline would send the line)
|
|
1722
|
+
if (key.name === 'enter' || (key.name === 'return' && key.meta)) {
|
|
1723
|
+
rl.line = rl.line.slice(0, rl.cursor) + '\n' + rl.line.slice(rl.cursor)
|
|
1724
|
+
rl.cursor++
|
|
1725
|
+
m.items = []
|
|
1726
|
+
return this.render()
|
|
1727
|
+
}
|
|
1662
1728
|
if (key.name === 'pageup' || key.name === 'pagedown') return this.scrollBy(key.name === 'pageup' ? this.page() : -this.page())
|
|
1663
1729
|
if (it && (key.name === 'up' || key.name === 'down')) {
|
|
1664
1730
|
m.sel = (m.sel + (key.name === 'up' ? m.items.length - 1 : 1)) % m.items.length
|
|
@@ -1707,6 +1773,19 @@ export class UI {
|
|
|
1707
1773
|
switch (what) {
|
|
1708
1774
|
case 'none':
|
|
1709
1775
|
return
|
|
1776
|
+
// the model's thinking: all of it as it comes, or its last two lines; one just over, all of it in a
|
|
1777
|
+
// box now (the key closes it). A key, not a message: nothing is sent, queued or kept in ↑
|
|
1778
|
+
// after an answer: its whole thinking in a box (the key closes it again; how thinking shows
|
|
1779
|
+
// stays as it was); else how thinking shows switches: all of it as it comes, or its last two
|
|
1780
|
+
// lines (a thought shown in full already goes on in full until its reply ends)
|
|
1781
|
+
case 'toggle_thinking':
|
|
1782
|
+
case '/toggle_thinking': {
|
|
1783
|
+
const t = !this.busySince ? this.lastThought : null
|
|
1784
|
+
if (t?.text?.trim()) return this.showText(`${t.who ? `${t.who}'s thinking` : 'Thinking'}`, t.text.trim(), 'toggle_thinking')
|
|
1785
|
+
this.showThinking = !this.showThinking
|
|
1786
|
+
const k = this.keyFor('toggle_thinking') ?? 'the key'
|
|
1787
|
+
return this.notice(this.showThinking ? `Thinking: all of it, as it comes · ${k}: its last two lines` : `Thinking: its last two lines from the next reply on · ${k}: all of it`, 2500)
|
|
1788
|
+
}
|
|
1710
1789
|
case 'new_tab':
|
|
1711
1790
|
case 'close_tab':
|
|
1712
1791
|
case 'next_tab':
|
|
@@ -2104,7 +2183,7 @@ export class UI {
|
|
|
2104
2183
|
const said = (x) => (x.own && x.text?.trim() ? x.text.trim() : x.label) // their own answer: what they typed
|
|
2105
2184
|
const picked = Array.isArray(pick?.chosen) ? pick.chosen.map(said).join(', ') : pick?.chosen && said(pick.chosen)
|
|
2106
2185
|
if (pick?.quiet) this.render()
|
|
2107
|
-
else if (pick) this.write(echo + (picked ?? c.dim(pick.closedAs ?? 'cancelled')) + (pick.auto?.fired ? c.dim(` · no answer in ${pick.auto.secs}s: ${pick.auto.fired === 'theirs' ? '
|
|
2186
|
+
else if (pick) this.write(echo + (picked ?? c.dim(pick.closedAs ?? 'cancelled')) + (pick.auto?.fired ? c.dim(` · no answer in ${pick.auto.secs}s: ${pick.auto.fired === 'theirs' ? 'the typed one' : 'the recommended one'}`) : '') + '\n')
|
|
2108
2187
|
else if (l !== null && history && this.isCommand(l.trim()) && !/^\s*\/skill:/.test(l)) this.notice(/^\S+/.exec(l.trim())[0], 3000, '›') // a command isn't part of the conversation: its name for a moment (not its arguments: maybe a key)
|
|
2109
2188
|
else if (l?.trim()) this.write(echo + c.bright(l.replace(/\n/g, '\n' + ' '.repeat(width(echo.replace(/\x1b\[[0-9;]*m/g, ''))))) + '\n')
|
|
2110
2189
|
else this.render()
|
|
@@ -2194,7 +2273,7 @@ export class UI {
|
|
|
2194
2273
|
const a = pick?.auto
|
|
2195
2274
|
if (!a) return ''
|
|
2196
2275
|
const theirs = pick.items.some((x) => x.checked || (x.own && x.text?.trim())) // ticked or typed: that's what goes
|
|
2197
|
-
return `◷ ${Math.max(0, Math.ceil((a.until - Date.now()) / 1000))}s · then ${theirs ? '
|
|
2276
|
+
return `◷ ${Math.max(0, Math.ceil((a.until - Date.now()) / 1000))}s · then ${theirs ? 'the typed answer is sent' : (a.say ?? 'the recommended answer is chosen')} · a key restarts it`
|
|
2198
2277
|
}
|
|
2199
2278
|
|
|
2200
2279
|
setPermission(mode) {
|
|
@@ -2295,12 +2374,16 @@ export class UI {
|
|
|
2295
2374
|
print(s = '') {
|
|
2296
2375
|
this.write(s + '\n')
|
|
2297
2376
|
}
|
|
2298
|
-
|
|
2377
|
+
// who: the model that made this call (named after it)
|
|
2378
|
+
step(name, detail = '', who = '') {
|
|
2299
2379
|
if (this.afterBlock) this.gap()
|
|
2300
2380
|
this.afterBlock = false
|
|
2301
|
-
|
|
2381
|
+
const line = `${c.accent('●')} ${c.accent(c.bold(name))} ${c.info(detail)}${who ? c.faint(` · ${who}`) : ''}`
|
|
2382
|
+
this.print(line)
|
|
2383
|
+
this.liveStep = line // its ● spins until its result (#rows)
|
|
2302
2384
|
}
|
|
2303
2385
|
result(text) {
|
|
2386
|
+
this.liveStep = null
|
|
2304
2387
|
this.print(` ${c.ghost('⎿')} ${c.faint(text)}`)
|
|
2305
2388
|
}
|
|
2306
2389
|
warn(text) {
|
|
@@ -2349,6 +2432,7 @@ export class UI {
|
|
|
2349
2432
|
if (this.busySince) return void (this.label = 'working') // still busy: keep spinning, generically
|
|
2350
2433
|
clearInterval(this.timer)
|
|
2351
2434
|
this.timer = null
|
|
2435
|
+
this.liveStep = null
|
|
2352
2436
|
if (this.full) this.render()
|
|
2353
2437
|
else this.out.write('\r\x1b[K')
|
|
2354
2438
|
}
|
package/src/usage.js
CHANGED
|
@@ -106,8 +106,17 @@ function newestOf(name) {
|
|
|
106
106
|
// however it's written (google/gemini-2.5-flash, models/gemini-2.5-flash, gpt-oss:120b ≈
|
|
107
107
|
// gpt-oss-120b): at this provider first; else, among all that list it, the size most say (a
|
|
108
108
|
// proxy or a provider models.dev doesn't know serves the model at its usual size).
|
|
109
|
+
// Remembered per models.dev list (a new list: worked out again): the settings page asks for every
|
|
110
|
+
// model of every provider each time it loads.
|
|
111
|
+
const looked = new WeakMap()
|
|
109
112
|
export function limitsOf(provider, baseUrl, model) {
|
|
110
113
|
if (!table || !model) return null
|
|
114
|
+
const memo = looked.get(table) ?? looked.set(table, new Map()).get(table)
|
|
115
|
+
const key = `${provider}\n${baseUrl}\n${model}`
|
|
116
|
+
if (!memo.has(key)) memo.set(key, lookUpLimits(provider, baseUrl, model))
|
|
117
|
+
return memo.get(key)
|
|
118
|
+
}
|
|
119
|
+
function lookUpLimits(provider, baseUrl, model) {
|
|
111
120
|
const last = (m) => m.split('/').pop()
|
|
112
121
|
const own = ownBy(provider, baseUrl)
|
|
113
122
|
const found = { own: [], all: [] }
|
package/src/voice.js
CHANGED
|
@@ -36,7 +36,7 @@ export function localModel(cfg = {}, { fast = false } = {}) {
|
|
|
36
36
|
// Why voice can't work here, or null when it can.
|
|
37
37
|
export function voiceProblem(cfg = {}, providers = {}) {
|
|
38
38
|
if (!onPath('ffmpeg')) return 'voice input needs ffmpeg to record (brew install ffmpeg)'
|
|
39
|
-
if (cfg.provider) return providers[cfg.provider] ? null : `voice.provider "${cfg.provider}" isn't one of
|
|
39
|
+
if (cfg.provider) return providers[cfg.provider] ? null : `voice.provider "${cfg.provider}" isn't one of the providers`
|
|
40
40
|
if (!onPath('whisper-cli')) return 'voice input needs whisper-cli (brew install whisper-cpp) and a model, or "voice": { "provider": …, "model": … } in ~/.heart/config.json'
|
|
41
41
|
return localModel(cfg) ? null : 'voice input needs a whisper model: put a ggml-*.bin in ~/.whisper-models, or set "voice": { "model": "/path/to/ggml-….bin" }'
|
|
42
42
|
}
|
package/src/web.js
CHANGED
|
@@ -336,7 +336,7 @@ export async function testSearxng(url) {
|
|
|
336
336
|
// go (on 2026-10-31 most LibreY, Whoogle and 4get ones were down or blocked, so they aren't here),
|
|
337
337
|
// and DuckDuckGo is blocked on some networks.
|
|
338
338
|
export const ENGINES = { searxng: mySearxng, searx, duckduckgo, mwmbl, stackoverflow, npm, github }
|
|
339
|
-
export const ENGINE_NAMES = { searxng: '
|
|
339
|
+
export const ENGINE_NAMES = { searxng: 'SearXNG (self-hosted)', searx: 'Public SearXNG instances', duckduckgo: 'DuckDuckGo', mwmbl: 'Mwmbl', stackoverflow: 'Stack Overflow', npm: 'npm', github: 'GitHub' }
|
|
340
340
|
// The settings page's order and switches (cfg.search: { searxng, order, off }), read at each search
|
|
341
341
|
// (a change applies at once, also in other HeartCodes). Engines missing from a saved order go after it.
|
|
342
342
|
export function searchSettings() {
|