heartcode 0.1.54 → 0.1.56
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 +51 -0
- package/bin/heartcode.js +86 -33
- package/package.json +1 -1
- package/prompts/agent.md +8 -5
- package/prompts/guided.md +1 -1
- package/src/acp.js +9 -4
- package/src/agent.js +122 -32
- package/src/client.js +7 -6
- package/src/guided.js +65 -15
- package/src/headless.js +3 -1
- package/src/lsp.js +10 -0
- package/src/tabs.js +6 -2
- package/src/tools.js +158 -40
- package/src/ui.js +331 -88
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,57 @@
|
|
|
2
2
|
|
|
3
3
|
What changed in each version of HeartCode, newest first.
|
|
4
4
|
|
|
5
|
+
## 0.1.56 (2026-11-05)
|
|
6
|
+
|
|
7
|
+
- **Questions as tabs**: several questions come in one dialog, a tab each; go back and forth with
|
|
8
|
+
←/→ or Tab, and send all answers from the Send tab, which lists each question and its answer.
|
|
9
|
+
"Something else" is typed right in the row (kept when you switch tabs); a timer line shows when
|
|
10
|
+
the recommended answer will be taken; afterwards each question is shown with its answer.
|
|
11
|
+
- **The plan stays in sight**: while working, the todo list is pinned under the spinner; updates
|
|
12
|
+
print only what changed. Each running helper gets its own line, named by its job.
|
|
13
|
+
- **Clearer while it works**: one clock ("waiting for m1", then "Ns in all"); a running command's
|
|
14
|
+
latest line shows in the spinner, then `exit N · M lines`, and a failed one shows its error line;
|
|
15
|
+
refusals and retries say why; "↻ … rate-limited (429) → …" says why the model changed; the
|
|
16
|
+
review comes before the final answer, so the answer is last.
|
|
17
|
+
- **Dialogs**: Shift+Tab never changes the mode inside one; typing doesn't vanish into hidden
|
|
18
|
+
filters; "what to do instead" is typed in the permission dialog; on small terminals dialogs are
|
|
19
|
+
90% wide and keep their timer and keys, with "↑/↓ n more".
|
|
20
|
+
- **Text**: words wrap whole with indented continuation lines, hint lines wrap instead of being
|
|
21
|
+
cut, Markdown tables line up, code blocks get a `│` gutter and quotes a `▎`; the light theme is
|
|
22
|
+
readable on a dark terminal.
|
|
23
|
+
- **Input and the rest**: Esc puts queued messages back into the input; a draft cleared with
|
|
24
|
+
Esc Esc is in ↑ history; empty Enter adds nothing; the header keeps the project folder's name;
|
|
25
|
+
the context size is right after resuming; tokens/s resets on clear; the setup help shows on first
|
|
26
|
+
run; a task over 10 seconds rings the bell, notifies the desktop and sets the terminal title;
|
|
27
|
+
`/help`, Alt+B, `/select_model`, `/context` and Alt+O ("Thinking") tidied.
|
|
28
|
+
|
|
29
|
+
## 0.1.55 (2026-11-05)
|
|
30
|
+
|
|
31
|
+
- **Helpers never ask you anything**: a helper's question no longer pops up as your dialog (in
|
|
32
|
+
tool and guided mode); it decides and says what it assumed, and the main model asks if needed.
|
|
33
|
+
Helpers can't start helpers, get the "not done yet" checks, write only their own files (patches
|
|
34
|
+
through commands too), and their changes go to the review.
|
|
35
|
+
- **Plan mode only reads**: commands like `ls & node x`, a line break, `git diff --output`,
|
|
36
|
+
`find -fprint` or `rg --pre` aren't taken as reading; MCP tools that may change something are
|
|
37
|
+
refused; an unknown language server isn't started; "don't ask again" keeps plan mode on;
|
|
38
|
+
Shift+Tab out of plan goes back to the mode before it.
|
|
39
|
+
- **Headless and editors**: no crash when the theme or mouse setting changes; another session's
|
|
40
|
+
permission change doesn't change theirs; told to decide instead of asking; `/skill:name` works;
|
|
41
|
+
editors use the project's prompt overrides; a helper's thinking isn't shown as the agent's.
|
|
42
|
+
- **Models**: a stated rate or size limit moves on to the next model (it crashed); guided and
|
|
43
|
+
tool-calling turns see each other's conversation; a move to a model without tool calls mid-message
|
|
44
|
+
goes on in guided mode; a Gemini chat resumed or forked onto another provider isn't refused;
|
|
45
|
+
auto-compact off stays off after a move; a resumed chat doesn't keep the last one's token count.
|
|
46
|
+
- **Guided mode**: your hooks and allowed tools apply, steps show in stream-json and editors,
|
|
47
|
+
memory notes after a task, no endless "Apply this change?" after a no.
|
|
48
|
+
- **Full screen**: the 30-second pick waits while its tab is in the background, and a question waits
|
|
49
|
+
for dictation to end; piped input doesn't answer questions; ticked options are kept; no full
|
|
50
|
+
screen on `TERM=dumb`.
|
|
51
|
+
- **After a review says no**, the answer is written to you (what was made, how to use it), not as a
|
|
52
|
+
reply to the reviewer.
|
|
53
|
+
- `--resume <id>` from another folder runs in that session's project, so /rewind can't touch the
|
|
54
|
+
wrong folder.
|
|
55
|
+
|
|
5
56
|
## 0.1.54 (2026-11-04)
|
|
6
57
|
|
|
7
58
|
- **Questions always come with a recommended answer**: ask_user needs options, the first one marked
|
package/bin/heartcode.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { parseArgs } from 'node:util'
|
|
4
|
-
import { Client, limitSaid } from '../src/client.js'
|
|
4
|
+
import { Client, limitSaid, estMessages } from '../src/client.js'
|
|
5
5
|
import { loadConfig, saveConfig, readJson, writeJson, providerName, CONFIG_FILE, HOME, TEMP, AUTO_MODEL, isAuto, parseModel, takeIn, whatOf, VERSION, speedOf } from '../src/config.js'
|
|
6
6
|
import { loadProfile, strategy, describe, profilePath, profileFrom } from '../src/probe.js'
|
|
7
7
|
import { learnFromUsage, LIMIT_MS, RATE_CAP_MS } from '../src/context.js'
|
|
@@ -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 } from '../src/ui.js'
|
|
12
|
+
import { UI, c, PERMISSIONS, duration, copyText, 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'
|
|
@@ -144,7 +144,7 @@ const COMMANDS = SECTIONS.flatMap(([, list]) => list).sort(byName)
|
|
|
144
144
|
// Typed while a task works, these run at once, beside it: they leave the conversation alone. The
|
|
145
145
|
// others (/compact, /rewind, /resume, /init…) wait in the queue until it's done.
|
|
146
146
|
const RIGHT_AWAY = new Set(['help', 'cost', 'context', 'background', 'model_info', 'diff', 'copy', 'mcp', 'doctor', 'toggle_thinking', 'btw', 'rename', 'export', 'tab', 'close_tab', 'exit', 'quit', 'settings', 'login_mcp', 'install_skill', 'import', 'voice', 'select_model'])
|
|
147
|
-
const helpText = (sections) => sections.map(([title, list]) => ` ${c.bold(title)}\n` + list.map(([n, d]) => ` ${c.cyan(n.padEnd(
|
|
147
|
+
const helpText = (sections) => sections.map(([title, list]) => ` ${c.bold(title)}\n` + list.map(([n, d]) => ` ${c.cyan(n.padEnd(17))} ${d}`).join('\n')).join('\n\n')
|
|
148
148
|
const SLASH = helpText(SECTIONS)
|
|
149
149
|
|
|
150
150
|
// The keyboard shortcuts, as [keys, what] rows, read from the effective keybindings (keybindings.json
|
|
@@ -332,11 +332,21 @@ class App {
|
|
|
332
332
|
let price = null
|
|
333
333
|
// tokens and cost, into the chat (also a helper's, the probe's, compaction's)
|
|
334
334
|
client.price = () => price
|
|
335
|
-
|
|
335
|
+
let failed = null // { t, e }: the failure that made the model list move on (said with the model that answered)
|
|
336
|
+
let ok = false // a reply came since it
|
|
337
|
+
const spend = (u) => addUsage((this.chat.usage ??= {}), u, price)
|
|
338
|
+
// serverCount: the conversation's last request size (lastTokens) is the server's, not HeartCode's estimate (/context)
|
|
339
|
+
client.onSpend = function (u) {
|
|
340
|
+
if ((this.purpose ?? 'chat') === 'chat') this.serverCount = Boolean(u.total_tokens)
|
|
341
|
+
ok = true
|
|
342
|
+
spend(u)
|
|
343
|
+
}
|
|
336
344
|
client.onRetry = (err, ms, attempt, next) => ui.retrying(err, ms, attempt, next) // keep trying until Esc (also while probing)
|
|
337
345
|
// a failed request: what it says about the model's limits is learned
|
|
338
346
|
client.onFail = (e, t) => {
|
|
339
347
|
if (e.name === 'AbortError') return
|
|
348
|
+
if (ok) [failed, ok] = [null, false] // the first failure since a reply: why the list moves on (onSwitch)
|
|
349
|
+
failed ??= { t, e }
|
|
340
350
|
// "too large" with the limit stated (Groq: "Limit 2000 … tokens per minute"): kept in its profile,
|
|
341
351
|
// so it isn't sent what it can't take
|
|
342
352
|
const said = limitSaid(e)
|
|
@@ -346,7 +356,7 @@ class App {
|
|
|
346
356
|
if (said.rate) p.rateCap = { tokens: said.tokens, until: Date.now() + RATE_CAP_MS }
|
|
347
357
|
else Object.assign(p, { inputLimit: said.tokens, inputLimitAt: Date.now() })
|
|
348
358
|
writeJson(profilePath(cl), p)
|
|
349
|
-
log('context', `${
|
|
359
|
+
log('context', `${t.provider}/${t.model}: ${said.rate ? 'a per-minute cap' : 'a request limit'} of ${said.tokens} tokens, from its provider`)
|
|
350
360
|
}
|
|
351
361
|
}
|
|
352
362
|
// the model list (settings page): another model answered
|
|
@@ -356,7 +366,10 @@ class App {
|
|
|
356
366
|
client.announceSwitch = () => switched && (ui.print(switched), (switched = null))
|
|
357
367
|
client.onSwitch = (t) => {
|
|
358
368
|
const i = client.rotation.list.indexOf(t)
|
|
359
|
-
|
|
369
|
+
const f = failed?.e
|
|
370
|
+
const why = f ? `${failed.t.model} ${f.status === 429 ? 'rate-limited (429)' : `failed (${clip(shortError(f), 50)})`} → ` : ''
|
|
371
|
+
failed = null
|
|
372
|
+
switched = c.dim(`↻ ${why}${t.provider} · ${t.model} answered${i ? ` (#${i + 1} in your model list)` : ' (#1 again)'}`)
|
|
360
373
|
setImmediate(client.announceSwitch)
|
|
361
374
|
}
|
|
362
375
|
if (cfg.maxRetries !== undefined) client.retryIf = (e, attempt) => attempt < cfg.maxRetries // headless: then give up
|
|
@@ -446,7 +459,7 @@ class App {
|
|
|
446
459
|
|
|
447
460
|
setChat(chat) {
|
|
448
461
|
this.chat = chat
|
|
449
|
-
if (this.s) this.s
|
|
462
|
+
if (this.s) Object.assign(this.s, { chat, counted: null, compactFailedAt: 0 }) // the last chat's token count and failed compaction aren't this one's
|
|
450
463
|
}
|
|
451
464
|
|
|
452
465
|
save() {
|
|
@@ -685,22 +698,21 @@ class App {
|
|
|
685
698
|
const rot = this.s?.client.rotation
|
|
686
699
|
const now = this.inUse() // the model list's one in use; never one of a provider that's off
|
|
687
700
|
if (!now) return c.dim('the providers of all your models are off · /settings to switch one on')
|
|
688
|
-
const on = Object.values(cfg.providers).filter((p) => !p.off).length
|
|
689
701
|
const count = this.sessionModels().length
|
|
690
702
|
// the model answering now; a yellow "↻" before it when it's a fallback (rotated to after one failed)
|
|
691
703
|
const rotated = rot && rot.at > 0
|
|
692
704
|
const name = rotated ? c.yellow('↻ ' + now.model) : c.info(now.model)
|
|
693
705
|
const model =
|
|
694
|
-
count === 1 ? name : cfg.session ? `${name} ${c.faint(`(${count} chosen)`)}` : `${c.muted('auto')} ${c.faint('(')}${name}${c.faint(')')} ${c.faint(`(${count})`)}`
|
|
706
|
+
count === 1 ? name : cfg.session ? `${name} ${c.faint(`(${count} chosen)`)}` : `${c.muted('auto')} ${c.faint('(')}${name}${c.faint(')')} ${c.faint(`(${count} models)`)}`
|
|
695
707
|
const key = `${now.provider}/${now.model}`
|
|
696
708
|
if (this.profileKey !== key) [this.profileKey, this.profile] = [key, this.s?.profile ?? loadProfile(this.client(now.provider, now.model))]
|
|
697
709
|
const profile = this.s?.profile ?? this.profile
|
|
698
710
|
const strat = profile && (this.s?.strat ?? strategy(profile, cfg))
|
|
699
711
|
// each item, rendered (or null when it doesn't apply)
|
|
700
712
|
const parts = {
|
|
701
|
-
provider: `${c.brand('●')} ${c.muted(now.provider)}
|
|
713
|
+
provider: `${c.brand('●')} ${c.muted(now.provider)}`,
|
|
702
714
|
model,
|
|
703
|
-
mode: strat ?
|
|
715
|
+
mode: strat ? (strat.actions === 'tools' ? null : c.muted('no tool calls (guided)')) : c.faint('checked at your first message'), // what it can do: known once it's been asked
|
|
704
716
|
thinking: strat?.thinking ? c.think(`thinking · ${effortOf(cfg)}`) + (ui.showThinking ? c.faint(' (all)') : '') : null,
|
|
705
717
|
images: strat?.vision ? c.muted('images') : null,
|
|
706
718
|
ctx: null,
|
|
@@ -713,7 +725,7 @@ class App {
|
|
|
713
725
|
permissions: { all: c.green('⏵⏵ all allowed'), commands: c.yellow('ask before commands'), ask: c.yellow('ask before changes'), plan: c.info('⏸ plan mode') }[ui.permission],
|
|
714
726
|
}
|
|
715
727
|
if (strat) {
|
|
716
|
-
const used = this.s?.client.lastTokens ??
|
|
728
|
+
const used = this.s?.client.lastTokens || Math.round(estMessages(this.chat?.messages ?? []) * (strat.ratio ?? 1)) // a resumed chat before its first request: estimated
|
|
717
729
|
const pct = Math.round((used / strat.context) * 100)
|
|
718
730
|
const paint = pct >= 80 ? c.red : pct >= 50 ? c.yellow : c.green
|
|
719
731
|
const guess = strat.contextSure ? '' : '~' // not said by the server: assumed, and growing as bigger requests work
|
|
@@ -855,7 +867,7 @@ class App {
|
|
|
855
867
|
// "tools · images · thinking · 1M", for the model lists.
|
|
856
868
|
canText(t) {
|
|
857
869
|
const a = this.abilities(t)
|
|
858
|
-
return [a.tools ? 'tools' : 'no tools', a.images && 'images', a.thinking && 'thinking',
|
|
870
|
+
return [a.tools ? 'tools' : 'no tools', a.images && 'images', a.thinking && 'thinking', (a.guessed ? '~' : '') + kTokens(a.context)].filter(Boolean).join(' · ')
|
|
859
871
|
}
|
|
860
872
|
|
|
861
873
|
// Your models, in order: this one (#1), then the fallbacks (chosen on /settings, where every
|
|
@@ -946,7 +958,7 @@ class App {
|
|
|
946
958
|
},
|
|
947
959
|
draw: (w, h) => {
|
|
948
960
|
const all = jobs()
|
|
949
|
-
if (!all.length) return ['',
|
|
961
|
+
if (!all.length) return ['', ...wrapWords('Nothing runs in the background. The model starts servers and watchers there.', w - 2).map((l) => ` ${c.faint(l.trim())}`), '', ` ${c.faint('Esc close')}`]
|
|
950
962
|
const job = current()
|
|
951
963
|
this.jobTab = job.id
|
|
952
964
|
// the tabs, scrolled so the one shown is on screen
|
|
@@ -974,7 +986,7 @@ class App {
|
|
|
974
986
|
return [
|
|
975
987
|
bar + (hidden ? c.faint(` +${hidden} more`) : ''),
|
|
976
988
|
c.ghost('─'.repeat(w)),
|
|
977
|
-
` ${c.bold(clip(job.command, w -
|
|
989
|
+
` ${c.bold(clip(job.command, Math.max(10, w - 2 - width(` · ${state} · ${ranFor(job)}${where}`.replace(/\x1b\[[0-9;]*m/g, '')))))} ${c.faint('·')} ${state} ${c.faint(`· ${ranFor(job)}`)}${where}`, // the command, as much as the rest leaves room for
|
|
978
990
|
...Array.from({ length: n }, (_, i) => (shown.length ? (shown[i] === undefined ? '' : ` ${ERROR.test(shown[i]) ? c.red(shown[i]) : c.muted(shown[i])}`) : i ? '' : ` ${c.faint('(no output yet)')}`)),
|
|
979
991
|
c.ghost('─'.repeat(w)),
|
|
980
992
|
` ${said ? c.yellow(said) : c.faint(`${all.length > 1 ? '←/→ another one · ' : ''}↑/↓ PgUp/PgDn scroll · K ${job.exited ? 'close' : 'stop'} it · Esc close`)}`,
|
|
@@ -1009,7 +1021,8 @@ class App {
|
|
|
1009
1021
|
this.saveProjectModels()
|
|
1010
1022
|
this.s = null
|
|
1011
1023
|
}
|
|
1012
|
-
const
|
|
1024
|
+
const n = this.myModels().length
|
|
1025
|
+
const msg = `${c.green('using')} ${c.dim('auto')} ${c.cyan(`(${n} model${n === 1 ? '' : 's'})`)}`
|
|
1013
1026
|
if (later) return this.later.push(apply), this.ui.print(`${msg} ${c.dim('· from your next message')}`)
|
|
1014
1027
|
apply()
|
|
1015
1028
|
this.ui.print(msg)
|
|
@@ -1029,8 +1042,9 @@ class App {
|
|
|
1029
1042
|
const chosen = new Set((cfg.session ?? mine).map(key)) // pre-ticked: this session's set, or all (auto)
|
|
1030
1043
|
const items = mine.map((t) => ({ label: t.model, t, checked: chosen.has(key(t)), desc: this.modelDesc(t, mine.indexOf(t)) }))
|
|
1031
1044
|
// first, standing alone: back to auto (Enter on it, whatever is ticked)
|
|
1032
|
-
const auto = { label: 'auto', only: true, auto: true, desc: `your whole list, in its order (${mine.length}
|
|
1033
|
-
const
|
|
1045
|
+
const auto = { label: 'auto', only: true, auto: true, desc: `your whole list, in its order (${mine.length} model${mine.length === 1 ? '' : 's'})${cfg.session ? ' · forgets what this folder picked' : ' · in use'}` }
|
|
1046
|
+
const guessed = mine.some((t) => this.abilities(t).guessed) ? "\n~128k and the like: the window's size is a guess (models.dev doesn't list the model)" : ''
|
|
1047
|
+
const picked = await ui.pick('Models for this session', [auto, ...items], { filter, multi: true, body: `Tick several to rotate among them, one to pin it, or choose auto.${guessed}` })
|
|
1034
1048
|
if (!picked) return
|
|
1035
1049
|
if (picked.some((it) => it.auto)) return cfg.session ? this.auto(later) : ui.print(c.dim('already on auto'))
|
|
1036
1050
|
const list = picked.map((it) => it.t)
|
|
@@ -1152,7 +1166,7 @@ async function continueTabs(app, saved) {
|
|
|
1152
1166
|
const go = await ui.pick(many ? `Continue where you left off? ${open.length} tabs` : 'Continue your last session here?', [
|
|
1153
1167
|
{ label: many ? `Yes, with its ${open.length} tabs` : 'Yes', desc: `${open.map((t) => `"${t.chat.title}"`).join(', ')} · ${ago(newest)}`, yes: true },
|
|
1154
1168
|
{ label: 'No, start a new session', desc: '/resume finds it later' },
|
|
1155
|
-
], { quiet: true })
|
|
1169
|
+
], { quiet: true, fixed: true })
|
|
1156
1170
|
if (!go?.yes) return
|
|
1157
1171
|
// this tab takes the first one in this folder; the rest (and worktree ones) open as tabs
|
|
1158
1172
|
const here = open.find((t) => !t.worktree) ?? null
|
|
@@ -1226,7 +1240,7 @@ function applySettings(apps, cfg, what) {
|
|
|
1226
1240
|
if (is !== was) ui.print(c.dim(`settings: ${is} now`))
|
|
1227
1241
|
}
|
|
1228
1242
|
if (what === 'provider') app.lists = {} // its list switched on or off, a model added by name
|
|
1229
|
-
if (what === 'setting:permissions') ui.setPermission(cfg.permissions)
|
|
1243
|
+
if (what === 'setting:permissions' && !ui.noUser) ui.setPermission(cfg.permissions) // -p and ACP keep the mode they were given (--permission-mode, the editor's)
|
|
1230
1244
|
if (what === 'setting:mouse') ui.setMouse(cfg.mouse !== false)
|
|
1231
1245
|
if (what === 'setting:statusBar') ui.render?.() // the status bar's layout changed: redraw it now
|
|
1232
1246
|
if (what === 'setting:effort' && app.s?.strat.thinking) app.s.client.effort = effortOf(cfg)
|
|
@@ -1565,7 +1579,7 @@ async function slash(app, line, working = false) {
|
|
|
1565
1579
|
ui.showText(
|
|
1566
1580
|
'Context',
|
|
1567
1581
|
[
|
|
1568
|
-
`${c.muted(`~${kTokens(r.total)} of ${kTokens(r.window)} (${share(r.total)}) · ${s.client.model}`)}${r.counted ? c.faint(` · the last request, as the server counted it: ${kTokens(r.counted)}`) : ''}`,
|
|
1582
|
+
`${c.muted(`~${kTokens(r.total)} of ${kTokens(r.window)} (${share(r.total)}) · ${s.client.model}`)}${r.counted ? c.faint(` · the last request, ${s.client.serverCount ? 'as the server counted it' : 'estimated (the server sent no count)'}: ${kTokens(r.counted)}`) : ''}`,
|
|
1569
1583
|
...r.parts.filter((p) => p.tokens).map((p) => row(p.name, p.tokens, p.note)),
|
|
1570
1584
|
` ${'room left'.padEnd(20)} ${kTokens(free).padStart(6)} ${c.faint(share(free).padStart(4))} ${c.faint(`before it summarizes, at 85% (${kTokens(r.compactAt)}) — or moves to a model with more room`)}`,
|
|
1571
1585
|
'',
|
|
@@ -1591,7 +1605,7 @@ async function slash(app, line, working = false) {
|
|
|
1591
1605
|
case 'clear_chat': // a new session; the old one stays in /resume
|
|
1592
1606
|
ui.clear()
|
|
1593
1607
|
app.setChat(newChat(app.root))
|
|
1594
|
-
if (app.s) app.s.client
|
|
1608
|
+
if (app.s) Object.assign(app.s.client, { lastTokens: 0, speed: { tokens: 0, ms: 0 } }) // the status bar starts over too
|
|
1595
1609
|
return
|
|
1596
1610
|
case 'resume':
|
|
1597
1611
|
return app.resume()
|
|
@@ -1693,7 +1707,7 @@ async function slash(app, line, working = false) {
|
|
|
1693
1707
|
}
|
|
1694
1708
|
case 'toggle_thinking':
|
|
1695
1709
|
ui.showThinking = !ui.showThinking
|
|
1696
|
-
ui.print(c.dim(ui.showThinking ? 'thinking: all of it
|
|
1710
|
+
ui.print(c.dim(ui.showThinking ? 'thinking shown: all of it (Alt+O: last two lines)' : 'thinking shown: its last two lines (Alt+O: all of it)'))
|
|
1697
1711
|
if (ui.showThinking && !ui.thinkTail) ui.showLastThought() // the one just over: all of it now
|
|
1698
1712
|
return
|
|
1699
1713
|
}
|
|
@@ -1723,11 +1737,12 @@ async function slash(app, line, working = false) {
|
|
|
1723
1737
|
}
|
|
1724
1738
|
}
|
|
1725
1739
|
|
|
1740
|
+
// true: done; false: stopped or failed; null: no model to run it
|
|
1726
1741
|
async function runTask(app, task, ctl) {
|
|
1727
1742
|
const { ui } = app
|
|
1728
1743
|
try {
|
|
1729
1744
|
const s = await app.session()
|
|
1730
|
-
if (!s) return
|
|
1745
|
+
if (!s) return null
|
|
1731
1746
|
let answer
|
|
1732
1747
|
try {
|
|
1733
1748
|
answer = await s.run(task, ctl?.signal)
|
|
@@ -1753,7 +1768,15 @@ async function repl(app, f = {}) {
|
|
|
1753
1768
|
ui.fullscreen({ mouse: cfg.mouse !== false }) // HeartCode's wheel and selection ("mouse": false: the terminal's own: then its wheel scrolls the whole screen)
|
|
1754
1769
|
ui.onDoubleEscape = () => '/rewind'
|
|
1755
1770
|
let ctl = null
|
|
1756
|
-
|
|
1771
|
+
// stopped by you (Esc, Ctrl+C; not Alt+S/Alt+A, which stop to send it): the queue isn't sent, it's
|
|
1772
|
+
// back in the input (with what's typed there), to edit or drop
|
|
1773
|
+
const stop = () => {
|
|
1774
|
+
if (!ctl) return
|
|
1775
|
+
ui.notice('') // "Press Esc again to stop" is done with
|
|
1776
|
+
if (!ui.sendNow && ui.ahead.length) app.nextInput = [...ui.ahead.splice(0), ui.rl?.line].filter(Boolean).join('\n')
|
|
1777
|
+
ctl.abort()
|
|
1778
|
+
}
|
|
1779
|
+
ui.onEscape = stop
|
|
1757
1780
|
// a command typed while it works: run now, beside the task, if it leaves the conversation alone
|
|
1758
1781
|
ui.onPanel = () => app.toggleJobs() // Alt+B: the background commands' logs, side by side, live
|
|
1759
1782
|
ui.onNow = (line) => {
|
|
@@ -1809,7 +1832,7 @@ async function repl(app, f = {}) {
|
|
|
1809
1832
|
lastInterrupt = Date.now()
|
|
1810
1833
|
if (ctl) {
|
|
1811
1834
|
if (again) return quit()
|
|
1812
|
-
|
|
1835
|
+
stop()
|
|
1813
1836
|
ui.cancelAsk()
|
|
1814
1837
|
return ui.warn(`stopping… (Ctrl+C again to quit${others() ? ` HeartCode, all ${others() + 1} tabs` : ''})`)
|
|
1815
1838
|
}
|
|
@@ -1824,12 +1847,26 @@ async function repl(app, f = {}) {
|
|
|
1824
1847
|
const home = process.env.HOME
|
|
1825
1848
|
const where = home && app.root.startsWith(home) ? '~' + app.root.slice(home.length) : app.root
|
|
1826
1849
|
ui.folder = app.root // what a double click on the header's folder copies
|
|
1827
|
-
ui.header = (cols = 100) =>
|
|
1828
|
-
|
|
1829
|
-
[['/', 'run a command'], ['@', 'attach a file'], ...(ui.voiceReady?.() ? [['Space', 'talk (voice)']] : []), [NEWLINE_KEY, 'add a new line'], ['Esc', 'stop'], ['Shift+Tab', 'change permissions']]
|
|
1830
|
-
'
|
|
1831
|
-
|
|
1850
|
+
ui.header = (cols = 100) => {
|
|
1851
|
+
const room = cols - 2 - width(`♥ HeartCode ${VERSION} `) // the folder's own name (its end) stays in sight
|
|
1852
|
+
const keys = [['/', 'run a command'], ['@', 'attach a file'], ...(ui.voiceReady?.() ? [['Space', 'talk (voice)']] : []), [NEWLINE_KEY, 'add a new line'], ['Esc', 'stop'], ['Shift+Tab', 'change permissions']]
|
|
1853
|
+
// the keys: on a second line when they don't fit one, broken between keys (never inside one)
|
|
1854
|
+
const rows = []
|
|
1855
|
+
for (const kd of keys) {
|
|
1856
|
+
const row = rows.at(-1)
|
|
1857
|
+
if (row && width([...row, kd].map((x) => x.join(' ')).join(' · ')) <= cols - 2) row.push(kd)
|
|
1858
|
+
else rows.push([kd])
|
|
1859
|
+
}
|
|
1860
|
+
return [
|
|
1861
|
+
`${c.brand('♥')} ${c.bright(c.bold('HeartCode'))} ${c.faint(VERSION)} ${c.muted(width(where) > room ? '…' + where.slice(-(room - 1)) : where)}`,
|
|
1862
|
+
...rows.map((row) => row.map(([k, d]) => `${c.muted(k)} ${c.faint(d)}`).join(c.ghost(' · '))),
|
|
1863
|
+
'',
|
|
1864
|
+
]
|
|
1865
|
+
}
|
|
1832
1866
|
if (!ui.full) ui.print(ui.header().join('\n'))
|
|
1867
|
+
// nothing set up yet: how to, at once (not only after a first message); a local server is looked for first
|
|
1868
|
+
if (!Object.keys(cfg.providers).length) app.detectLocal().then((found) => (found ? ui.render?.() : ui.print(HOWTO)))
|
|
1869
|
+
else if (!cfg.providers[cfg.provider] || !cfg.model) ui.print(NO_MODELS)
|
|
1833
1870
|
if (f.onStart) await f.onStart(app)
|
|
1834
1871
|
if (f.continue) {
|
|
1835
1872
|
const last = listChats(app.root)[0]
|
|
@@ -1877,6 +1914,7 @@ async function repl(app, f = {}) {
|
|
|
1877
1914
|
}
|
|
1878
1915
|
if (mark) ui.unmark(mark, /^\S+/.exec(t)[0])
|
|
1879
1916
|
} else {
|
|
1917
|
+
if (process.stdout.isTTY) process.stdout.write(`\x1b]0;● ${path.basename(app.root)} · HeartCode\x07`)
|
|
1880
1918
|
let ok = await runTask(app, t, ctl)
|
|
1881
1919
|
// plan mode: the plan is done; go ahead with it?
|
|
1882
1920
|
while (ok && ui.permission === 'plan' && !ctl.signal.aborted) {
|
|
@@ -1890,7 +1928,9 @@ async function repl(app, f = {}) {
|
|
|
1890
1928
|
ui.setPermission(go.mode)
|
|
1891
1929
|
ok = await runTask(app, prompt('agent/plan-approved'), ctl)
|
|
1892
1930
|
}
|
|
1893
|
-
if (ui.busySince) ui.print(c.faint(c.italic(`✻ took ${duration(ui.worked())}`))) // fixed once the reply is in
|
|
1931
|
+
if (ui.busySince && ok !== null) ui.print(c.faint(c.italic(`✻ took ${duration(ui.worked())}`))) // fixed once the reply is in (not when no model ran)
|
|
1932
|
+
// done, said by the terminal too: its title, and after a long task a bell and a notification (OSC 9)
|
|
1933
|
+
if (process.stdout.isTTY) process.stdout.write(`\x1b]0;${ok === null ? '♥' : '✓'} ${path.basename(app.root)} · HeartCode\x07` + (ok !== null && !ctl.signal.aborted && ui.worked() > 10_000 ? '\x07\x1b]9;HeartCode: done\x07' : ''))
|
|
1894
1934
|
}
|
|
1895
1935
|
ui.idle()
|
|
1896
1936
|
ctl = null
|
|
@@ -2011,7 +2051,11 @@ async function main() {
|
|
|
2011
2051
|
cfg.maxRetries ??= 10
|
|
2012
2052
|
// each editor session its own settings (one choosing a model doesn't change the others')
|
|
2013
2053
|
const apps = []
|
|
2014
|
-
const makeApp = (root, ui, mcp) =>
|
|
2054
|
+
const makeApp = (root, ui, mcp) => {
|
|
2055
|
+
const app = new App({ ...structuredClone(cfg), ...(mcp && { mcp: { extra: [mcp] } }) }, ui, root)
|
|
2056
|
+
usePromptsFrom(app.root) // its .heartcode/prompts override the built-in sections (as newApp's)
|
|
2057
|
+
return apps[apps.push(app) - 1]
|
|
2058
|
+
}
|
|
2015
2059
|
watchSettings(() => apps, cfg) // the settings page's changes, into every editor session
|
|
2016
2060
|
process.exit(await runAcp({ makeApp, version: VERSION, permission: f['permission-mode'] ? PERMISSION_MODES[f['permission-mode']] : (cfg.permissions ?? 'ask') }))
|
|
2017
2061
|
}
|
|
@@ -2040,10 +2084,19 @@ async function main() {
|
|
|
2040
2084
|
usePromptsFrom(app.root) // its .heartcode/prompts override the built-in sections
|
|
2041
2085
|
ui.suggest = (line, cursor) => app.suggest(line, cursor)
|
|
2042
2086
|
ui.status = (cols) => app.status(cols)
|
|
2087
|
+
ui.todos = () => app.chat?.todos // the plan, kept in sight while it works
|
|
2043
2088
|
ui.requestSince = () => app.s?.client.inFlight // the spinner shows how long the model has been answering
|
|
2089
|
+
ui.waitingFor = () => app.s?.client.model // the spinner: "waiting for <model>"
|
|
2044
2090
|
return app
|
|
2045
2091
|
}
|
|
2046
2092
|
let root = path.resolve(f.cwd ?? process.cwd())
|
|
2093
|
+
// a session of another folder (--resume <id> from anywhere): run in its project, where its files
|
|
2094
|
+
// are (what it changed is kept relative to it, and /rewind puts files back there)
|
|
2095
|
+
const other = (f['resume-id'] || f['session-id']) && loadChat(f['resume-id'] || f['session-id'], root)
|
|
2096
|
+
if (other?.root && path.resolve(other.root) !== root) {
|
|
2097
|
+
if (!fs.existsSync(other.root)) throw new Error(`session ${other.id} was in ${other.root}, which is gone`)
|
|
2098
|
+
root = path.resolve(other.root)
|
|
2099
|
+
}
|
|
2047
2100
|
const wt = f.worktree !== undefined ? createWorktree(root, f.worktree) : null
|
|
2048
2101
|
if (wt) {
|
|
2049
2102
|
root = wt.cwd
|
package/package.json
CHANGED
package/prompts/agent.md
CHANGED
|
@@ -14,6 +14,7 @@ its section into ~/.heart/prompts/agent.md (every project) or .heartcode/prompts
|
|
|
14
14
|
{{servers}}: language servers used in this project before ("typescript-language-server --stdio (typescript) for .ts"), or empty.
|
|
15
15
|
{{see}}: set when the model can see images.
|
|
16
16
|
{{caller}}: set when a program started HeartCode with its own instructions (--append-system-prompt), which come at the end.
|
|
17
|
+
{{noUser}}: set when nobody can answer questions (headless, ACP, a helper agent): there is no ask_user tool.
|
|
17
18
|
{{files}} and {{more}} are passed empty, so older copies of this prompt keep working. -->
|
|
18
19
|
{{#if caller}}You are running in HeartCode, a coding agent in the terminal. Your role and instructions are at the end of this prompt. Where they differ from the rules below, follow them.{{else}}You are HeartCode, a coding agent in the terminal, working on the user's project.{{/if}}
|
|
19
20
|
Do the work with your tools, all of it, in this turn. Don't just describe what could be done.
|
|
@@ -24,10 +25,10 @@ Language servers used here before: {{servers}}.{{/if}}{{#if see}}
|
|
|
24
25
|
You can see images: in the user's messages, from tools (screenshots), and image files you read_file. Look at them yourself. Never say you can't see images.{{/if}}
|
|
25
26
|
|
|
26
27
|
## 1. Ask first
|
|
27
|
-
When the user asks you to make or change something, first ask every question whose answer changes what you build. Ask only with the ask_user tool (emphasis: true, options written for this task, your recommended option first), never as plain text. Ask them all in one reply, then any that depend on the answers. If the message already settles everything, don't ask: start.
|
|
28
|
+
{{#if noUser}}Nobody can answer questions here. Where a choice changes what you build, pick the most likely option, start, and say in your answer what you assumed.{{else}}When the user asks you to make or change something, first ask every question whose answer changes what you build. Ask only with the ask_user tool (emphasis: true, options written for this task, your recommended option first), never as plain text. Ask them all in one reply (one ask_user call each), then any that depend on the answers. If the message already settles everything, don't ask: start.
|
|
28
29
|
- Ask about: what it's for, how it should look, testing (none, normal, edge cases), how robust, anything left open.
|
|
29
30
|
- A request with two meanings: ask. Never pick silently.
|
|
30
|
-
- Don't ask what you can look up (files, docs, the web), what the message already says, or about a question, a typo or a one-line fix.
|
|
31
|
+
- Don't ask what you can look up (files, docs, the web), what the message already says, or about a question, a typo or a one-line fix.{{/if}}
|
|
31
32
|
Then build exactly what they chose. Nothing extra: no polish, features, tests or edge cases they didn't ask for. Nobody to ask: make it work, nothing more.
|
|
32
33
|
|
|
33
34
|
## 2. Research and plan
|
|
@@ -227,7 +228,7 @@ Fetch a web page (any http/https URL) as Markdown. The whole page is saved in th
|
|
|
227
228
|
|
|
228
229
|
## tool-ask_user
|
|
229
230
|
|
|
230
|
-
Ask the user
|
|
231
|
+
Ask the user and wait for the answers. Only for what you can't find out or decide yourself: their choice, or a request with two meanings. One question a call; several questions: several calls in one reply, which the user sees as tabs in one dialog. Each: 2-4 short options, your recommended one first (taken if the user doesn't answer within 30 seconds); header: 1-2 words for its tab ("Purpose", "Look"). They can always type their own; multiple: true lets them pick several. emphasis: true marks a question about how they want this task done (what for, looks, testing, scope): the answer then guides the checks and reviews too.
|
|
231
232
|
|
|
232
233
|
## no-answer
|
|
233
234
|
|
|
@@ -273,6 +274,7 @@ To act on them, ask a model that can see: the agent tool with these in "images"
|
|
|
273
274
|
<!-- Added to a helper agent's system prompt. -->
|
|
274
275
|
You are a helper agent. The main agent gave you one job; your final reply goes to it, not to the user.
|
|
275
276
|
- Do the whole job and nothing else.
|
|
277
|
+
- You can't ask the user. Something unclear: decide, and say in your reply what you assumed.
|
|
276
278
|
- Never guess: look it up (search the web for anything current). A question you can answer from what you know or were given: answer at once.
|
|
277
279
|
- Something fails: try another way. Check that what you report is true.
|
|
278
280
|
- Reply with exactly what it needs: findings with file paths and line numbers, what you changed, or what failed and why. Complete but brief.
|
|
@@ -301,7 +303,7 @@ Write the plan with the todo tool: the result in one line, then each step with h
|
|
|
301
303
|
## not-done
|
|
302
304
|
|
|
303
305
|
<!-- Sent when the model stops but isn't done. One placeholder is set, and only its part is sent. {{asked}}: it wrote questions for the user as text (only ask_user lets them answer); {{todos}}: open todo items, a "- item" per line; {{unchecked}}: files changed and not run or tested since; {{missing}}: files its answer names that don't exist; {{early}}: it named a next step but didn't take it. -->
|
|
304
|
-
{{#if asked}}(The user can't answer questions written as text. Ask each one with the ask_user tool: question, options (your recommended one first), emphasis: true. Put all the calls in one reply.){{/if}}
|
|
306
|
+
{{#if asked}}(The user can't answer questions written as text. Ask each one with the ask_user tool: question, header, options (your recommended one first), emphasis: true. Put all the calls in one reply.){{/if}}
|
|
305
307
|
{{#if todos}}(Not done: your todo list has open items:
|
|
306
308
|
{{todos}}
|
|
307
309
|
Do them. If one is no longer needed, update the list and say why.){{/if}}
|
|
@@ -341,7 +343,8 @@ The FIRST word of your reply must be YES (done right) or NO. If NO, follow with
|
|
|
341
343
|
<!-- Sent when the review says the work isn't right. {{model}}: who reviewed; {{issues}}: its list. -->
|
|
342
344
|
(Not done: {{model}} reviewed your work and found:
|
|
343
345
|
{{issues}}
|
|
344
|
-
Check each point against the code. Fix the real ones and check the fix.
|
|
346
|
+
Check each point against the code. Fix the real ones and check the fix.
|
|
347
|
+
Then answer the user, who didn't see this review: what you made and how to use it, as if no review happened. Don't reply to the review or list its points. A point you think is wrong: skip it.)
|
|
345
348
|
|
|
346
349
|
## hook
|
|
347
350
|
|
package/prompts/guided.md
CHANGED
|
@@ -12,7 +12,7 @@ You are HeartCode, a careful coding agent working in the user's project.
|
|
|
12
12
|
HeartCode does the work in small steps. Each message asks you ONE thing. Answer exactly that, in the form asked. No explanation, no extra text.
|
|
13
13
|
- Use only what you are shown. Never invent a file path, name, flag or code.
|
|
14
14
|
- Write code complete and correct. No placeholders. Keep what should stay.
|
|
15
|
-
- Your memory of tools, libraries and APIs
|
|
15
|
+
- Your memory of tools, libraries and APIs may be out of date: follow how the project's own files use them.
|
|
16
16
|
- Reuse what the project already has. Clear names. Comments only for what isn't obvious.
|
|
17
17
|
|
|
18
18
|
## context
|
package/src/acp.js
CHANGED
|
@@ -26,16 +26,21 @@ class AcpUI extends HeadlessUI {
|
|
|
26
26
|
update(u) {
|
|
27
27
|
this.conn.notify('session/update', { sessionId: this.sessionId, update: u })
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
// a helper's reply isn't the agent's own thoughts or message: its steps come as tool calls, named
|
|
30
|
+
response(who, { helper = false } = {}) {
|
|
31
|
+
if (helper) return { text() {}, think() {}, end() {} }
|
|
30
32
|
const chunk = (sessionUpdate) => (text) => text && this.update({ sessionUpdate, content: { type: 'text', text } })
|
|
31
33
|
return { text: chunk('agent_message_chunk'), think: chunk('agent_thought_chunk'), end() {} }
|
|
32
34
|
}
|
|
33
35
|
setPermission(mode) {
|
|
36
|
+
if (mode === 'plan' && this.permission !== 'plan') this.beforePlan = this.permission // what plan mode asks like
|
|
34
37
|
super.setPermission(mode)
|
|
35
38
|
if (this.sessionId) this.update({ sessionUpdate: 'current_mode_update', currentModeId: mode })
|
|
36
39
|
}
|
|
37
40
|
async confirm(question, kind = 'edit') {
|
|
38
|
-
if (
|
|
41
|
+
if (kind === 'read' && this.permission === 'plan') return true
|
|
42
|
+
const mode = this.permission === 'plan' ? (this.beforePlan ?? 'ask') : this.permission // plan mode asks as the mode before it did (as the full screen's)
|
|
43
|
+
if (mode === 'all' || (mode === 'commands' && kind === 'edit')) return true
|
|
39
44
|
const toolCallId = runningCall.getStore() ?? this.calls[0] ?? `ask_${Date.now()}` // the call asking
|
|
40
45
|
const r = await this.conn
|
|
41
46
|
.request('session/request_permission', {
|
|
@@ -49,7 +54,7 @@ class AcpUI extends HeadlessUI {
|
|
|
49
54
|
})
|
|
50
55
|
.catch(() => null)
|
|
51
56
|
const id = r?.outcome?.outcome === 'selected' ? r.outcome.optionId : null
|
|
52
|
-
if (id === 'all') this.setPermission('all')
|
|
57
|
+
if (id === 'all') this.permission === 'plan' ? (this.beforePlan = 'all') : this.setPermission('all') // in plan mode: still planning, everything allowed after it
|
|
53
58
|
return id === 'allow' || id === 'all'
|
|
54
59
|
}
|
|
55
60
|
}
|
|
@@ -132,7 +137,7 @@ export async function runAcp({ makeApp, version, permission = 'ask', input = pro
|
|
|
132
137
|
if (!s) throw Object.assign(new Error(app.allOff() ? 'the providers of all your models are switched off: switch one on in heart settings' : 'no model set up: run heart settings to add a provider and choose a model'), { code: -32000 })
|
|
133
138
|
s.onEvent ??= (e) => events(it.ui, s, e)
|
|
134
139
|
const k = /^\/(\S+)\s*([\s\S]*)$/.exec(text)
|
|
135
|
-
const skill = k && app.skills.get(k[1])
|
|
140
|
+
const skill = k && app.skills.get(k[1].replace(/^skill:/, '')) // /name or /skill:name, as in the full screen
|
|
136
141
|
await s.run(skill && skill.use !== 'model' ? await app.expandSkill(skill, k[2]) : text, it.ctl.signal, images)
|
|
137
142
|
return { stopReason: 'end_turn' }
|
|
138
143
|
} catch (e) {
|