heartcode 0.1.59 → 0.1.62
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 +70 -0
- package/README.md +35 -15
- package/SKILL.md +2 -1
- package/bin/heart.js +1 -1
- package/bin/heartcode.js +86 -58
- package/package.json +1 -1
- package/prompts/agent.md +97 -15
- package/src/acp.js +3 -3
- package/src/agent.js +191 -25
- package/src/background.js +2 -8
- package/src/capabilities.js +2 -2
- package/src/check.js +69 -4
- package/src/client.js +37 -12
- package/src/config.js +30 -1
- package/src/context.js +1 -1
- package/src/format.js +5 -3
- package/src/headless.js +3 -2
- package/src/http.js +96 -0
- package/src/importer.js +8 -7
- package/src/log.js +2 -2
- package/src/lsp.js +3 -6
- package/src/mcp.js +5 -7
- package/src/memory.js +1 -1
- package/src/oauth.js +2 -1
- package/src/probe.js +14 -4
- package/src/rankings.js +7 -0
- package/src/reset.js +2 -2
- package/src/sessions.js +2 -2
- package/src/settings.html +236 -178
- package/src/settings.js +51 -24
- package/src/spawn.js +48 -0
- package/src/telegram.js +2 -1
- package/src/tools.js +274 -29
- package/src/tree.js +1 -1
- package/src/ui.js +66 -27
- package/src/update.js +1 -0
- package/src/usage.js +10 -0
- package/src/voice.js +21 -7
- package/src/web.js +2 -1
package/src/ui.js
CHANGED
|
@@ -109,11 +109,28 @@ setTheme()
|
|
|
109
109
|
|
|
110
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, toggle_thinking, background_log, new_tab,
|
|
112
|
+
// scroll_line_up, scroll_line_down (3 lines), scroll_top, scroll_bottom, voice, toggle_thinking, show_plan, 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
115
|
// A key as people read it ("alt+shift+down" → "Alt+Shift+↓")
|
|
116
116
|
const KEY_NAMES = { pageup: 'PgUp', pagedown: 'PgDn', up: '↑', down: '↓', left: '←', right: '→', ctrl: 'Ctrl', alt: 'Alt', shift: 'Shift' }
|
|
117
|
+
// A text's last n rows at width w (its lines' spaces squeezed, long ones wrapped at spaces), the
|
|
118
|
+
// first starting with … when there was more before it: thinking shown in two rows, however long.
|
|
119
|
+
export function lastRows(text, w, n) {
|
|
120
|
+
w = Math.max(4, w - 2) // room for the "… " in front
|
|
121
|
+
const rows = String(text).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)
|
|
122
|
+
const out = rows.slice(-n)
|
|
123
|
+
if (rows.length > n) out[0] = `… ${out[0]}`
|
|
124
|
+
return out
|
|
125
|
+
}
|
|
126
|
+
// The steps of a plan to show when only n fit: what's being done or stuck first, then what's next,
|
|
127
|
+
// then the last ones done; in the plan's order. The rest: a count, and the key that shows all of it.
|
|
128
|
+
export function planPick(todos, n = 3) {
|
|
129
|
+
const rank = { in_progress: 0, stuck: 0, pending: 1, completed: 2 }
|
|
130
|
+
const order = todos.map((t, i) => [t, i]).sort((a, b) => rank[a[0].status] - rank[b[0].status] || (a[0].status === 'completed' ? b[1] - a[1] : a[1] - b[1]))
|
|
131
|
+
const keep = new Set(order.slice(0, n).map(([, i]) => i))
|
|
132
|
+
return { shown: todos.filter((_, i) => keep.has(i)), hidden: todos.length - keep.size }
|
|
133
|
+
}
|
|
117
134
|
export const prettyKey = (k) => k.split('+').map((p) => KEY_NAMES[p] ?? (p.length === 1 ? p.toUpperCase() : p[0].toUpperCase() + p.slice(1))).join('+')
|
|
118
135
|
const CONTROL_KEYS = { '\x1c': 'ctrl+\\', '\x1d': 'ctrl+]', '\x1e': 'ctrl+^', '\x1f': 'ctrl+_' } // no name from readline
|
|
119
136
|
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()
|
|
@@ -125,9 +142,10 @@ export const keyId = (key, s = '') => CONTROL_KEYS[key.sequence ?? s] ?? [key.ct
|
|
|
125
142
|
// Alt+A all of them (as one message); Alt+M switches what goes when an answer is done (all or the
|
|
126
143
|
// next one). /voice records (Space in an empty box, or a key in keybindings.json); Alt+T, Alt+W,
|
|
127
144
|
// Alt+N/P, Alt+1…9: tabs; Shift+↑↓ and Alt+↑↓ scroll the conversation (as PgUp/PgDn and the mouse
|
|
128
|
-
// wheel do), Alt+Shift+↑↓ to its top and bottom; Alt+O: all of the model's thinking, or its last lines
|
|
145
|
+
// wheel do), Alt+Shift+↑↓ to its top and bottom; Alt+O: all of the model's thinking, or its last lines;
|
|
146
|
+
// Alt+L: the whole plan.
|
|
129
147
|
// keybindings.json can move any of them.
|
|
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}`])) }
|
|
148
|
+
export const DEFAULT_KEYS = { 'alt+o': 'toggle_thinking', 'alt+l': 'show_plan', '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}`])) }
|
|
131
149
|
export function loadKeys(file = path.join(HOME, 'keybindings.json')) {
|
|
132
150
|
let raw = {}
|
|
133
151
|
try {
|
|
@@ -898,7 +916,7 @@ export class UI {
|
|
|
898
916
|
const own = pick?.items.some((x) => x.own) // typing goes into "Something else", not a filter
|
|
899
917
|
const typingOwn = m.items[m.sel]?.item?.own && m.items[m.sel].item.text // ←/→ move in what's typed; Tab goes on
|
|
900
918
|
const body = pick?.body ? String(pick.body).split('\n') : []
|
|
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
|
|
919
|
+
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')
|
|
902
920
|
const timer = this.autoLine() // on its own line, so it's seen (and not cut off with the keys)
|
|
903
921
|
const long = width(title) > this.#dialogBox(cols, rows).w - 6 // too long for the border: inside instead, said once
|
|
904
922
|
// at most n rows; the rest said to be there
|
|
@@ -967,25 +985,34 @@ export class UI {
|
|
|
967
985
|
}
|
|
968
986
|
}
|
|
969
987
|
|
|
970
|
-
// The plan (todo list) while it works, kept in sight under the spinner: how much is done,
|
|
971
|
-
// being done, what's
|
|
988
|
+
// The plan (todo list) while it works, kept in sight under the spinner: how much is done, and three
|
|
989
|
+
// of its steps (what's being done, then what's next); the rest on a key (show_plan).
|
|
972
990
|
#todoLines(cols) {
|
|
973
991
|
const todos = this.todos?.() ?? []
|
|
974
992
|
const open = todos.filter((t) => t.status !== 'completed')
|
|
975
993
|
if (!open.length) return []
|
|
976
994
|
const done = todos.length - open.length
|
|
977
|
-
const mark = { pending: c.muted('☐'), in_progress: c.info('◐'), completed: c.faint('☑') }
|
|
995
|
+
const mark = { pending: c.muted('☐'), in_progress: c.info('◐'), completed: c.faint('☑'), stuck: c.warn('⚠') }
|
|
978
996
|
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) : c.muted(t.content)}${by(t)}`, cols)
|
|
980
|
-
const shown
|
|
997
|
+
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)
|
|
998
|
+
const { shown, hidden } = planPick(todos)
|
|
981
999
|
return [
|
|
982
1000
|
fit(` ${c.muted('Plan')} ${c.faint(`· ${done} of ${todos.length} done`)}`, cols),
|
|
983
|
-
...(todos.length > 8 && done ? [fit(` ${c.faint(`☑ ${done} done`)}`, cols)] : []),
|
|
984
1001
|
...shown.map(line),
|
|
985
|
-
...(
|
|
1002
|
+
...(hidden ? [fit(` ${c.faint(`… ${hidden} more${this.keyFor('show_plan') ? ` · ${this.keyFor('show_plan')} shows all of it` : ''}`)}`, cols)] : []),
|
|
986
1003
|
]
|
|
987
1004
|
}
|
|
988
1005
|
|
|
1006
|
+
// The whole plan in a box (show_plan, /todos): every step and its state; the key closes it again.
|
|
1007
|
+
showPlan() {
|
|
1008
|
+
const todos = this.todos?.() ?? []
|
|
1009
|
+
if (!todos.length) return this.notice('No plan right now: the model writes one for a task of a few steps', 2500)
|
|
1010
|
+
const mark = { pending: '☐', in_progress: '◐', completed: '☑', stuck: '⚠' }
|
|
1011
|
+
const paint = { pending: c.muted, in_progress: (x) => c.info(c.bold(x)), completed: c.faint, stuck: c.warn }
|
|
1012
|
+
const done = todos.filter((t) => t.status === 'completed').length
|
|
1013
|
+
this.showText(`Plan · ${done} of ${todos.length} done`, todos.map((t) => paint[t.status](`${mark[t.status]} ${t.content}`) + (t.status === 'stuck' && t.why ? c.warn(`: ${t.why}`) : '') + (t.by ? c.faint(` · ${t.by}`) : '')).join('\n'), 'show_plan')
|
|
1014
|
+
}
|
|
1015
|
+
|
|
989
1016
|
// The last lines of this task's output, at most n rows of w (what a question in the middle of the work
|
|
990
1017
|
// is about): whole lines, from the start of a block (not mid-sentence), without what the question
|
|
991
1018
|
// itself says (about: its text, e.g. the command it asks to run).
|
|
@@ -1029,8 +1056,8 @@ export class UI {
|
|
|
1029
1056
|
const summary = () => {
|
|
1030
1057
|
this.thinkTail = ''
|
|
1031
1058
|
if (thought.trim() && !think) {
|
|
1032
|
-
// what it thought stays in the conversation: its last two
|
|
1033
|
-
const last = thought.
|
|
1059
|
+
// what it thought stays in the conversation: its last two rows on this screen (all of it: Alt+O)
|
|
1060
|
+
const last = lastRows(thought, Math.max(20, (this.out.columns || 80) - 4), 2)
|
|
1034
1061
|
this.print(c.faint(c.italic(`✻ ${who ? `${who} ` : ''}thought for ${secs()}${this.keyFor('toggle_thinking') ? ` · ${this.keyFor('toggle_thinking')} shows all of it` : ''}`)))
|
|
1035
1062
|
this.print(c.think(c.italic(last.map((l) => ` ${l}`).join('\n'))))
|
|
1036
1063
|
this.lastThought = { who, text: thought } // Alt+O shows it, now that it's over (showLastThought)
|
|
@@ -1233,7 +1260,7 @@ export class UI {
|
|
|
1233
1260
|
this.render()
|
|
1234
1261
|
}
|
|
1235
1262
|
#copied(text) {
|
|
1236
|
-
this.notice(`copied ${text.length} character${text.length === 1 ? '' : 's'}${copyText(text) === 'osc' ? ' (if
|
|
1263
|
+
this.notice(`copied ${text.length} character${text.length === 1 ? '' : 's'}${copyText(text) === 'osc' ? ' (if the terminal allows it)' : ''}`)
|
|
1237
1264
|
}
|
|
1238
1265
|
// A double click: the word under it (no spaces; quotes and brackets around it left out), copied.
|
|
1239
1266
|
#copyWord(x, y) {
|
|
@@ -1344,9 +1371,8 @@ export class UI {
|
|
|
1344
1371
|
}
|
|
1345
1372
|
|
|
1346
1373
|
// The conversation as screen rows (wrapped to the width; cached per line).
|
|
1347
|
-
// While it works, the
|
|
1348
|
-
//
|
|
1349
|
-
// spinner under the conversation says it.
|
|
1374
|
+
// While it works, the step running spins its ● until its result; what it waits on between steps is
|
|
1375
|
+
// said once, by the spinner under the conversation.
|
|
1350
1376
|
#rows(cols) {
|
|
1351
1377
|
if (this.wrapCols !== cols) [this.wrapped, this.wrapCols] = [[], cols]
|
|
1352
1378
|
const spin = this.timer && !this.asking ? c.brand(FRAMES[this.frame % FRAMES.length]) : null
|
|
@@ -1360,7 +1386,6 @@ export class UI {
|
|
|
1360
1386
|
if (!w || w.src !== line) this.wrapped[i] = { src: line, rows: wrapHang(line, cols) } // at spaces, wrapped rows under the text
|
|
1361
1387
|
out.push(...this.wrapped[i].rows)
|
|
1362
1388
|
})
|
|
1363
|
-
if (spin && live === -1 && !this.replying && this.statusText) out.push(...wrapHang(`${spin} ${c.muted(this.statusText)}`, cols))
|
|
1364
1389
|
return out
|
|
1365
1390
|
}
|
|
1366
1391
|
|
|
@@ -1395,11 +1420,8 @@ export class UI {
|
|
|
1395
1420
|
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(' · ') : ''
|
|
1396
1421
|
if (this.thinkTail) {
|
|
1397
1422
|
// the thinking's last two lines (long ones wrapped), dim, changing as it comes
|
|
1398
|
-
const
|
|
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)
|
|
1400
|
-
for (const l of lines.slice(-2)) bottom.push(fit(` ${c.think(c.italic(l))}`, cols))
|
|
1423
|
+
for (const l of lastRows(this.thinkTail, Math.max(20, cols - 6), 2)) bottom.push(fit(` ${c.think(c.italic(l))}`, cols))
|
|
1401
1424
|
}
|
|
1402
|
-
this.statusText = status // the same, at the end of the conversation (#rows)
|
|
1403
1425
|
bottom.push(fit(`${c.brand(FRAMES[this.frame % FRAMES.length])} ${c.muted(status)}`, cols))
|
|
1404
1426
|
if (timer) bottom.push(...wrapParts(timer, cols - 2).map((r) => fit(` ${c.faint(r)}`, cols)))
|
|
1405
1427
|
// helpers at work (agent.js keeps them in this.helpers: label → what it's doing), then the plan
|
|
@@ -1408,7 +1430,7 @@ export class UI {
|
|
|
1408
1430
|
if (helpers.length > 6) bottom.push(c.faint(` … ${helpers.length - 5} more`))
|
|
1409
1431
|
bottom.push(...this.#todoLines(cols))
|
|
1410
1432
|
}
|
|
1411
|
-
if (this.scroll) bottom.push(c.dim(` ↓ ${Number.isFinite(this.scroll) ? this.scroll : 'more'} lines below · held here
|
|
1433
|
+
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` : ''}`))
|
|
1412
1434
|
if (this.ahead.length) {
|
|
1413
1435
|
const key = (k, d) => `${c.muted(k)} ${c.faint(d)}`
|
|
1414
1436
|
const sep = c.ghost(' · ')
|
|
@@ -1611,7 +1633,7 @@ export class UI {
|
|
|
1611
1633
|
const onOwn = own && it?.item === own
|
|
1612
1634
|
const typing = own && !key.ctrl && !key.meta && ((key.name === 'backspace' && onOwn) || (/^[^\x00-\x1f\x7f]+$/.test(s ?? '') && !(key.name === 'space' && m.pick.multi && !onOwn)))
|
|
1613
1635
|
if (typing) {
|
|
1614
|
-
own.hint ??= own.text ? 'type
|
|
1636
|
+
own.hint ??= own.text ? 'type an answer' : own.desc // what it says before anything's typed
|
|
1615
1637
|
own.text = key.name === 'backspace' ? (own.text ?? '').slice(0, -1) : (own.text ?? '') + s
|
|
1616
1638
|
own.desc = own.text ? `› ${own.text}▏` : own.hint
|
|
1617
1639
|
if (m.pick.multi) own.checked = Boolean(own.text)
|
|
@@ -1796,6 +1818,8 @@ export class UI {
|
|
|
1796
1818
|
return this.dictateIn()
|
|
1797
1819
|
case 'background_log':
|
|
1798
1820
|
return this.onPanel?.()
|
|
1821
|
+
case 'show_plan':
|
|
1822
|
+
return this.showPlan()
|
|
1799
1823
|
case 'stop':
|
|
1800
1824
|
return this.asking ? undefined : this.onEscape?.()
|
|
1801
1825
|
case 'cycle_permissions':
|
|
@@ -2183,7 +2207,7 @@ export class UI {
|
|
|
2183
2207
|
const said = (x) => (x.own && x.text?.trim() ? x.text.trim() : x.label) // their own answer: what they typed
|
|
2184
2208
|
const picked = Array.isArray(pick?.chosen) ? pick.chosen.map(said).join(', ') : pick?.chosen && said(pick.chosen)
|
|
2185
2209
|
if (pick?.quiet) this.render()
|
|
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' ? '
|
|
2210
|
+
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')
|
|
2187
2211
|
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)
|
|
2188
2212
|
else if (l?.trim()) this.write(echo + c.bright(l.replace(/\n/g, '\n' + ' '.repeat(width(echo.replace(/\x1b\[[0-9;]*m/g, ''))))) + '\n')
|
|
2189
2213
|
else this.render()
|
|
@@ -2273,7 +2297,7 @@ export class UI {
|
|
|
2273
2297
|
const a = pick?.auto
|
|
2274
2298
|
if (!a) return ''
|
|
2275
2299
|
const theirs = pick.items.some((x) => x.checked || (x.own && x.text?.trim())) // ticked or typed: that's what goes
|
|
2276
|
-
return `◷ ${Math.max(0, Math.ceil((a.until - Date.now()) / 1000))}s · then ${theirs ? '
|
|
2300
|
+
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`
|
|
2277
2301
|
}
|
|
2278
2302
|
|
|
2279
2303
|
setPermission(mode) {
|
|
@@ -2375,16 +2399,31 @@ export class UI {
|
|
|
2375
2399
|
this.write(s + '\n')
|
|
2376
2400
|
}
|
|
2377
2401
|
// who: the model that made this call (named after it)
|
|
2402
|
+
// The same call again right after it (nothing printed between but its result, as a model polling a
|
|
2403
|
+
// page does): the line it has counts it (×2, ×3…) instead of another of the same, and its result
|
|
2404
|
+
// makes way for the new one's.
|
|
2378
2405
|
step(name, detail = '', who = '') {
|
|
2406
|
+
const line = `${c.accent('●')} ${c.accent(c.bold(name))} ${c.info(detail)}${who ? c.faint(` · ${who}`) : ''}`
|
|
2407
|
+
const was = this.lastStep
|
|
2408
|
+
const end = this.log.length - 1 // the line being written (empty, after a whole line)
|
|
2409
|
+
if (this.full && was?.line === line && was.log === this.log && this.log[was.at] === was.shown && !plainOf(this.log[end]) && (end === was.at + 1 || end === was.after)) {
|
|
2410
|
+
const open = this.log[end]
|
|
2411
|
+
this.log.length = was.at + 1 // its result out: the new one's comes
|
|
2412
|
+
this.log.push(open)
|
|
2413
|
+
was.shown = `${line}${c.faint(` ×${++was.n}`)}`
|
|
2414
|
+
this.log[was.at] = this.liveStep = was.shown // its ● spins until its result (#rows)
|
|
2415
|
+
return this.render()
|
|
2416
|
+
}
|
|
2379
2417
|
if (this.afterBlock) this.gap()
|
|
2380
2418
|
this.afterBlock = false
|
|
2381
|
-
const line = `${c.accent('●')} ${c.accent(c.bold(name))} ${c.info(detail)}${who ? c.faint(` · ${who}`) : ''}`
|
|
2382
2419
|
this.print(line)
|
|
2383
2420
|
this.liveStep = line // its ● spins until its result (#rows)
|
|
2421
|
+
this.lastStep = { line, shown: line, n: 1, log: this.log, at: this.log.length - 2 }
|
|
2384
2422
|
}
|
|
2385
2423
|
result(text) {
|
|
2386
2424
|
this.liveStep = null
|
|
2387
2425
|
this.print(` ${c.ghost('⎿')} ${c.faint(text)}`)
|
|
2426
|
+
if (this.lastStep?.log === this.log && this.lastStep.at === this.log.length - 3) this.lastStep.after = this.log.length - 1 // its step's, right under it
|
|
2388
2427
|
}
|
|
2389
2428
|
warn(text) {
|
|
2390
2429
|
log('warn', text)
|
package/src/update.js
CHANGED
|
@@ -5,6 +5,7 @@ import fs from 'node:fs'
|
|
|
5
5
|
import path from 'node:path'
|
|
6
6
|
import { fileURLToPath } from 'node:url'
|
|
7
7
|
import { HOME, VERSION, readJson, writeJson } from './config.js'
|
|
8
|
+
import { fetch } from './http.js' // not the built-in one: see http.js
|
|
8
9
|
|
|
9
10
|
const FILE = path.join(HOME, 'update-check.json')
|
|
10
11
|
const PKG = fileURLToPath(new URL('..', import.meta.url))
|
package/src/usage.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import path from 'node:path'
|
|
7
7
|
import { HOME, readJson, writeJson } from './config.js'
|
|
8
8
|
import { log } from './log.js'
|
|
9
|
+
import { fetch } from './http.js' // not the built-in one: see http.js
|
|
9
10
|
|
|
10
11
|
const FILE = path.join(HOME, 'prices.json')
|
|
11
12
|
const DAY = 86_400_000
|
|
@@ -106,8 +107,17 @@ function newestOf(name) {
|
|
|
106
107
|
// however it's written (google/gemini-2.5-flash, models/gemini-2.5-flash, gpt-oss:120b ≈
|
|
107
108
|
// gpt-oss-120b): at this provider first; else, among all that list it, the size most say (a
|
|
108
109
|
// proxy or a provider models.dev doesn't know serves the model at its usual size).
|
|
110
|
+
// Remembered per models.dev list (a new list: worked out again): the settings page asks for every
|
|
111
|
+
// model of every provider each time it loads.
|
|
112
|
+
const looked = new WeakMap()
|
|
109
113
|
export function limitsOf(provider, baseUrl, model) {
|
|
110
114
|
if (!table || !model) return null
|
|
115
|
+
const memo = looked.get(table) ?? looked.set(table, new Map()).get(table)
|
|
116
|
+
const key = `${provider}\n${baseUrl}\n${model}`
|
|
117
|
+
if (!memo.has(key)) memo.set(key, lookUpLimits(provider, baseUrl, model))
|
|
118
|
+
return memo.get(key)
|
|
119
|
+
}
|
|
120
|
+
function lookUpLimits(provider, baseUrl, model) {
|
|
111
121
|
const last = (m) => m.split('/').pop()
|
|
112
122
|
const own = ownBy(provider, baseUrl)
|
|
113
123
|
const found = { own: [], all: [] }
|
package/src/voice.js
CHANGED
|
@@ -10,12 +10,13 @@
|
|
|
10
10
|
import fs from 'node:fs'
|
|
11
11
|
import os from 'node:os'
|
|
12
12
|
import path from 'node:path'
|
|
13
|
-
import { spawn } from 'node:child_process'
|
|
13
|
+
import { spawn, spawnSync } from 'node:child_process'
|
|
14
14
|
import { HOME } from './config.js'
|
|
15
15
|
import { runCommand } from './tools.js'
|
|
16
|
+
import { onPath } from './spawn.js'
|
|
16
17
|
import { log } from './log.js'
|
|
18
|
+
import { fetch } from './http.js' // not the built-in one: see http.js
|
|
17
19
|
|
|
18
|
-
const onPath = (cmd) => (process.env.PATH ?? '').split(path.delimiter).find((d) => d && fs.existsSync(path.join(d, cmd)))
|
|
19
20
|
|
|
20
21
|
// A whisper.cpp model already on disk: the configured one, else the best found (small > base > tiny).
|
|
21
22
|
// fast: the quickest found instead (tiny > base > small), for the words shown while you speak.
|
|
@@ -33,11 +34,24 @@ export function localModel(cfg = {}, { fast = false } = {}) {
|
|
|
33
34
|
return found.sort((a, b) => (rank(a) === -1 ? 9 : rank(a)) - (rank(b) === -1 ? 9 : rank(b)))[0] ?? (fast ? localModel(cfg) : null)
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
// How to install a program here: the usual package manager of this OS
|
|
38
|
+
const install = (mac, win, linux) => (process.platform === 'darwin' ? `brew install ${mac}` : process.platform === 'win32' ? `winget install ${win}` : linux)
|
|
39
|
+
|
|
40
|
+
// The microphone, as ffmpeg's input: the default device (macOS, PulseAudio/PipeWire on Linux); on
|
|
41
|
+
// Windows DirectShow needs a device's name, so the first microphone ffmpeg lists (kept once found)
|
|
42
|
+
let winMic
|
|
43
|
+
function micInput() {
|
|
44
|
+
if (process.platform === 'darwin') return ['-f', 'avfoundation', '-i', ':default']
|
|
45
|
+
if (process.platform !== 'win32') return ['-f', 'pulse', '-i', 'default']
|
|
46
|
+
winMic ??= /"([^"]+)"\s*\(audio\)/.exec(spawnSync('ffmpeg', ['-hide_banner', '-list_devices', 'true', '-f', 'dshow', '-i', 'dummy'], { encoding: 'utf8' }).stderr ?? '')?.[1] ?? ''
|
|
47
|
+
return ['-f', 'dshow', '-i', `audio=${winMic || 'default'}`]
|
|
48
|
+
}
|
|
49
|
+
|
|
36
50
|
// Why voice can't work here, or null when it can.
|
|
37
51
|
export function voiceProblem(cfg = {}, providers = {}) {
|
|
38
|
-
if (!onPath('ffmpeg')) return
|
|
39
|
-
if (cfg.provider) return providers[cfg.provider] ? null : `voice.provider "${cfg.provider}" isn't one of
|
|
40
|
-
if (!onPath('whisper-cli')) return
|
|
52
|
+
if (!onPath('ffmpeg')) return `voice input needs ffmpeg to record (${install('ffmpeg', 'ffmpeg', 'install ffmpeg with your package manager')})`
|
|
53
|
+
if (cfg.provider) return providers[cfg.provider] ? null : `voice.provider "${cfg.provider}" isn't one of the providers`
|
|
54
|
+
if (!onPath('whisper-cli')) return `voice input needs whisper-cli (${process.platform === 'darwin' ? 'brew install whisper-cpp' : 'whisper.cpp, from github.com/ggml-org/whisper.cpp'}) and a model, or "voice": { "provider": …, "model": … } in ~/.heart/config.json`
|
|
41
55
|
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
56
|
}
|
|
43
57
|
|
|
@@ -47,7 +61,7 @@ const RATE = 16000 // 16 kHz mono, 16-bit: what whisper wants
|
|
|
47
61
|
// said so far (raw), seconds(), stop() → all of it, cancel() }.
|
|
48
62
|
export function listen() {
|
|
49
63
|
// HEART_VOICE_FILE: a sound file played in at its own speed instead of the microphone (tests)
|
|
50
|
-
const input = process.env.HEART_VOICE_FILE ? ['-re', '-i', process.env.HEART_VOICE_FILE] :
|
|
64
|
+
const input = process.env.HEART_VOICE_FILE ? ['-re', '-i', process.env.HEART_VOICE_FILE] : micInput()
|
|
51
65
|
const child = spawn('ffmpeg', ['-hide_banner', '-loglevel', 'error', ...input, '-ac', '1', '-ar', String(RATE), '-f', 's16le', 'pipe:1'], { stdio: ['pipe', 'pipe', 'pipe'] })
|
|
52
66
|
const chunks = []
|
|
53
67
|
let size = 0
|
|
@@ -106,7 +120,7 @@ export async function transcribePcm(pcm, cfg = {}, providers = {}, { fast = fals
|
|
|
106
120
|
// Starts recording to a 16 kHz mono WAV. Returns { stop() → the file, cancel() }.
|
|
107
121
|
export function record() {
|
|
108
122
|
const file = path.join(os.tmpdir(), `heartcode-voice-${process.pid}-${Date.now()}.wav`)
|
|
109
|
-
const input =
|
|
123
|
+
const input = micInput()
|
|
110
124
|
const start = (inp) => spawn('ffmpeg', ['-hide_banner', '-loglevel', 'error', '-y', ...inp, '-ac', '1', '-ar', '16000', file], { stdio: ['pipe', 'ignore', 'pipe'] })
|
|
111
125
|
let child = start(input)
|
|
112
126
|
let err = ''
|
package/src/web.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import path from 'node:path'
|
|
8
8
|
import { HOME, CONFIG_FILE, readJson, writeJson } from './config.js'
|
|
9
9
|
import { keywords } from './memory.js'
|
|
10
|
+
import { fetch } from './http.js' // not the built-in one: see http.js
|
|
10
11
|
// ponytail: scraping, no API; add a keyed backend (Brave, Tavily) if DuckDuckGo blocks for good.
|
|
11
12
|
|
|
12
13
|
const UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124 Safari/537.36'
|
|
@@ -336,7 +337,7 @@ export async function testSearxng(url) {
|
|
|
336
337
|
// go (on 2026-10-31 most LibreY, Whoogle and 4get ones were down or blocked, so they aren't here),
|
|
337
338
|
// and DuckDuckGo is blocked on some networks.
|
|
338
339
|
export const ENGINES = { searxng: mySearxng, searx, duckduckgo, mwmbl, stackoverflow, npm, github }
|
|
339
|
-
export const ENGINE_NAMES = { searxng: '
|
|
340
|
+
export const ENGINE_NAMES = { searxng: 'SearXNG (self-hosted)', searx: 'Public SearXNG instances', duckduckgo: 'DuckDuckGo', mwmbl: 'Mwmbl', stackoverflow: 'Stack Overflow', npm: 'npm', github: 'GitHub' }
|
|
340
341
|
// The settings page's order and switches (cfg.search: { searxng, order, off }), read at each search
|
|
341
342
|
// (a change applies at once, also in other HeartCodes). Engines missing from a saved order go after it.
|
|
342
343
|
export function searchSettings() {
|