heartcode 0.1.37 → 0.1.41
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/.claude/scheduled_tasks.lock +1 -0
- package/CHANGELOG.md +99 -0
- package/README.md +27 -12
- package/SKILL.md +22 -7
- package/bin/heart.js +8 -21
- package/bin/heartcode.js +90 -62
- package/package.json +1 -1
- package/prompts/README.md +0 -1
- package/prompts/agent.md +114 -120
- package/src/agent.js +71 -261
- package/src/background.js +39 -12
- package/src/capabilities.js +2 -2
- package/src/client.js +41 -6
- package/src/config.js +1 -1
- package/src/fit.js +65 -0
- package/src/guided.js +12 -21
- package/src/importer.js +50 -12
- package/src/log.js +69 -18
- package/src/parquet.js +209 -0
- package/src/probe.js +20 -310
- package/src/prompts.js +1 -1
- package/src/rankings.js +122 -0
- package/src/settings.html +230 -115
- package/src/settings.js +59 -22
- package/src/skills.js +7 -3
- package/src/tools.js +189 -50
- package/src/ui.js +55 -10
- package/src/update.js +59 -0
- package/prompts/probe.md +0 -67
package/bin/heartcode.js
CHANGED
|
@@ -3,10 +3,11 @@ import path from 'node:path'
|
|
|
3
3
|
import { parseArgs } from 'node:util'
|
|
4
4
|
import { Client } from '../src/client.js'
|
|
5
5
|
import { loadConfig, saveConfig, readJson, writeJson, providerName, CONFIG_FILE, HOME, AUTO_MODEL, isAuto, parseModel, takeIn, whatOf, VERSION } from '../src/config.js'
|
|
6
|
-
import {
|
|
6
|
+
import { loadProfile, strategy, describe, profilePath, profileFrom } from '../src/probe.js'
|
|
7
7
|
import { learnFromUsage, LIMIT_MS } from '../src/context.js'
|
|
8
8
|
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
|
+
import { checkUpdate, installKind, UPDATE_COMMANDS, packageDir, whatsNew } from '../src/update.js'
|
|
10
11
|
import { treeItems, codePlan, move, leaving, leftText, leftFiles } from '../src/tree.js'
|
|
11
12
|
import { UI, c, PERMISSIONS, duration, copyText, rank, setTheme, themeCodes, renderDiff, diffLines, DEFAULT_KEYS, loadKeys, width } from '../src/ui.js'
|
|
12
13
|
import { listFiles, runCommand, clip } from '../src/tools.js'
|
|
@@ -45,7 +46,6 @@ ${c.bold('usage')}
|
|
|
45
46
|
as provider/model, #1 first
|
|
46
47
|
heart models --all [filter] every provider's models (provider/model)
|
|
47
48
|
heart models --json as JSON (with --all too), for other programs
|
|
48
|
-
heart probe test the current model for real (otherwise its abilities come from models.dev)
|
|
49
49
|
heart config show the config file
|
|
50
50
|
heart settings change providers, models and settings in your browser
|
|
51
51
|
|
|
@@ -63,7 +63,6 @@ ${c.bold('options')}
|
|
|
63
63
|
copied in), shared by the --temp runs going on at once and deleted
|
|
64
64
|
after the last; ~/.heart isn't touched
|
|
65
65
|
--context <n> context window size in tokens
|
|
66
|
-
--force re-run the probe
|
|
67
66
|
--save keep the given -u/-m/--api-key/... in ${CONFIG_FILE}
|
|
68
67
|
-w, --worktree work in a new git worktree and branch (--worktree=name to name it,
|
|
69
68
|
or to continue in it); removed on exit if nothing changed
|
|
@@ -80,6 +79,7 @@ ${c.bold('headless')} (for other programs; flags and output as in Claude Code's
|
|
|
80
79
|
--skills-dir <dir> more skills (repeatable)
|
|
81
80
|
--allowedTools <list> only these tools (HeartCode's or Claude Code's names: Read, Edit, Bash…)
|
|
82
81
|
--disallowedTools <list> never these tools
|
|
82
|
+
--model-choice <order|fit> your models' order (#1, then the next), or the best fit for each task
|
|
83
83
|
--permission-mode <m> all, commands, ask, plan (or bypassPermissions, acceptEdits, default);
|
|
84
84
|
--dangerously-skip-permissions = all. Nothing is asked: the rest is declined
|
|
85
85
|
--session-id <id> start (or continue) the session with this id
|
|
@@ -93,7 +93,7 @@ ${c.bold('headless')} (for other programs; flags and output as in Claude Code's
|
|
|
93
93
|
${c.bold('editors')} heartcode --acp the Agent Client Protocol on stdin/stdout (Zed, JetBrains, Neovim)
|
|
94
94
|
|
|
95
95
|
${c.bold('env')} HEART_BASE_URL, HEART_MODEL, HEART_API_KEY (or OPENAI_BASE_URL / OPENAI_API_KEY)
|
|
96
|
-
HEART_LOG=<file>
|
|
96
|
+
HEART_LOG=<file> every kind of log of this run in that one file, whatever is switched on (off: none)
|
|
97
97
|
|
|
98
98
|
${c.bold('in a session')} attach an image with @path/to/shot.png · /help for commands`
|
|
99
99
|
|
|
@@ -121,11 +121,11 @@ const SECTIONS = [
|
|
|
121
121
|
['/context', "what's in the context now: system prompt, tools, messages, tool results, and the biggest pieces"],
|
|
122
122
|
['/background', 'commands running in the background (servers, watchers): their logs live, a tab each (Alt+B) · /background stop [id] · /background files', true],
|
|
123
123
|
['/model_info', 'what the model can do and how HeartCode uses it'],
|
|
124
|
-
['/test_model', 'test the model for real (otherwise what it can do comes from models.dev, or your settings)'],
|
|
125
124
|
['/tidy_memory', 'merge, update and link the memory notes now'],
|
|
126
125
|
['/import', 'bring commands, skills, MCP servers and memory from other CLIs'],
|
|
127
126
|
['/install_skill', 'install a skill from a GitHub repo or a SKILL.md URL (add --project for this folder only)', true],
|
|
128
127
|
['/doctor', 'check the outside tools HeartCode features need (voice, browser, git) and what to install'],
|
|
128
|
+
['/update', 'install the newest HeartCode (shows what changed first)'],
|
|
129
129
|
['/mcp', 'your MCP servers and whether each needs signing in'],
|
|
130
130
|
['/login_mcp', 'sign in (again) to a remote MCP server', true],
|
|
131
131
|
['/compact', 'summarize the conversation to free up context (add what to keep)', true],
|
|
@@ -149,7 +149,7 @@ const SLASH = helpText(SECTIONS)
|
|
|
149
149
|
|
|
150
150
|
// The keyboard shortcuts, as [keys, what] rows, read from the effective keybindings (keybindings.json
|
|
151
151
|
// can change any of them) plus the fixed ones (Space, Enter, Esc, Shift+Tab, Ctrl+C).
|
|
152
|
-
function keysHelp(keys = {}) {
|
|
152
|
+
function keysHelp(keys = {}, mouse = false) {
|
|
153
153
|
const NAMES = { pageup: 'PgUp', pagedown: 'PgDn', up: '↑', down: '↓', left: '←', right: '→', ctrl: 'Ctrl', alt: 'Alt', shift: 'Shift' }
|
|
154
154
|
const pretty = (k) => k.split('+').map((p) => NAMES[p] ?? (p.length === 1 ? p.toUpperCase() : p[0].toUpperCase() + p.slice(1))).join('+')
|
|
155
155
|
const forAct = (a) => Object.entries(keys).filter(([, v]) => v === a).map(([k]) => pretty(k)).join(' / ')
|
|
@@ -171,11 +171,13 @@ function keysHelp(keys = {}) {
|
|
|
171
171
|
[forAct('send_all'), 'queue: send all now'],
|
|
172
172
|
[forAct('queue_mode'), 'queue: one by one, or all together'],
|
|
173
173
|
[[forAct('scroll_up'), forAct('scroll_down')].filter(Boolean).join(' / '), 'scroll the conversation a page'],
|
|
174
|
+
[[forAct('scroll_top'), forAct('scroll_bottom')].filter(Boolean).join(' / '), 'to the top / bottom of the conversation (scrolled up, it stays put while the answer comes in)'],
|
|
174
175
|
[[forAct('scroll_line_up'), forAct('scroll_line_down')].filter(Boolean).join(' / '), 'scroll a few lines'],
|
|
175
176
|
['Ctrl+C', 'stop · twice quits HeartCode'],
|
|
176
|
-
['Drag', 'select and copy: the conversation, a dialog, the folder, the input, the status bar'],
|
|
177
|
-
['Double-click', 'copy the word under it (an address, a path, a model)'],
|
|
178
|
-
[process.platform === 'darwin' ? 'Option+drag' : 'Shift+drag', "the terminal's own selection, past HeartCode's"],
|
|
177
|
+
[mouse ? 'Drag' : '', 'select and copy: the conversation, a dialog, the folder, the input, the status bar'],
|
|
178
|
+
[mouse ? 'Double-click' : '', 'copy the word under it (an address, a path, a model)'],
|
|
179
|
+
[mouse ? (process.platform === 'darwin' ? 'Option+drag' : 'Shift+drag') : '', "the terminal's own selection, past HeartCode's"],
|
|
180
|
+
[mouse ? '' : 'Mouse', 'the terminal\'s own: select and copy as usual (HeartCode takes the mouse, for the wheel and drag to copy, with "mouse": true in config.json)'],
|
|
179
181
|
].filter(([k]) => k)
|
|
180
182
|
return rows
|
|
181
183
|
}
|
|
@@ -345,8 +347,7 @@ class App {
|
|
|
345
347
|
ui.print(c.dim(`↻ ${t.provider} · ${t.model} answered${i ? ` (#${i + 1} in your model list)` : ' (#1 again)'}`))
|
|
346
348
|
}
|
|
347
349
|
if (cfg.maxRetries !== undefined) client.retryIf = (e, attempt) => attempt < cfg.maxRetries // headless: then give up
|
|
348
|
-
let profile = await getProfile(client, ui,
|
|
349
|
-
if (!quiet) cfg.force = false
|
|
350
|
+
let profile = await getProfile(client, ui, quiet)
|
|
350
351
|
const strat = {}
|
|
351
352
|
// The model asked from now on (at first, and when the model list moves on): its own profile,
|
|
352
353
|
// abilities (sees images? calls tools? its window), thinking effort, price, and what its
|
|
@@ -374,6 +375,7 @@ class App {
|
|
|
374
375
|
// to the window (a command can run for minutes). Nothing goes on with an old copy.
|
|
375
376
|
client.refresh = () => {
|
|
376
377
|
syncSettings()
|
|
378
|
+
client.startMs = 1000 * (Number(this.cfg.replyStart) > 0 ? Number(this.cfg.replyStart) : 60) // a reply must start within this, else the next model
|
|
377
379
|
if (stampOf(profilePath(client)) !== stamp) client.onUse({ provider: client.provider, model: client.model })
|
|
378
380
|
}
|
|
379
381
|
// What this run learned about the model, onto its file as it is now: the rest (what you set up for
|
|
@@ -585,7 +587,7 @@ class App {
|
|
|
585
587
|
// Built-in commands (/name), then the skills you can type, namespaced as /skill:name so they're
|
|
586
588
|
// easy to tell apart from HeartCode's own commands (and can't clash with them).
|
|
587
589
|
commands() {
|
|
588
|
-
const mine = [...this.skills.values()].filter((k) => k.use
|
|
590
|
+
const mine = [...this.skills.values()].filter((k) => k.use === 'me' || k.use === 'both').map((k) => [`/skill:${k.name}`, k.description, true]).sort(byName)
|
|
589
591
|
return [...COMMANDS, ...mine]
|
|
590
592
|
}
|
|
591
593
|
|
|
@@ -603,7 +605,7 @@ class App {
|
|
|
603
605
|
const mine = this.commands().slice(COMMANDS.length)
|
|
604
606
|
const sections = [...SECTIONS]
|
|
605
607
|
if (mine.length) sections.push(['your skills (type /skill:name)', mine])
|
|
606
|
-
sections.push(['keyboard', keysHelp(this.ui.keys)])
|
|
608
|
+
sections.push(['keyboard', keysHelp(this.ui.keys, this.cfg?.mouse === true)])
|
|
607
609
|
return helpText(sections)
|
|
608
610
|
}
|
|
609
611
|
|
|
@@ -674,7 +676,7 @@ class App {
|
|
|
674
676
|
const rotated = rot && rot.at > 0
|
|
675
677
|
const name = rotated ? c.yellow('↻ ' + now.model) : c.info(now.model)
|
|
676
678
|
const model =
|
|
677
|
-
count === 1 ? name : cfg.session ? `${name} ${c.faint(`(${count} chosen)`)}` : `${c.muted('auto')} ${c.faint('(')}${name}${c.faint(')')} ${c.faint(`(${count})`)}`
|
|
679
|
+
count === 1 ? name : cfg.session ? `${name} ${c.faint(`(${count} chosen)`)}` : `${c.muted(fitMode(cfg) ? 'best fit' : 'auto')} ${c.faint('(')}${name}${c.faint(')')} ${c.faint(`(${count})`)}`
|
|
678
680
|
const key = `${now.provider}/${now.model}`
|
|
679
681
|
if (this.profileKey !== key) [this.profileKey, this.profile] = [key, this.s?.profile ?? loadProfile(this.client(now.provider, now.model))]
|
|
680
682
|
const profile = this.s?.profile ?? this.profile
|
|
@@ -683,7 +685,7 @@ class App {
|
|
|
683
685
|
const parts = {
|
|
684
686
|
provider: `${c.brand('●')} ${c.muted(now.provider)} ${c.faint(`(${on})`)}`,
|
|
685
687
|
model,
|
|
686
|
-
mode: strat ? c.muted(strat.actions === 'tools' ? 'tools' : 'guided') : c.dim('not
|
|
688
|
+
mode: strat ? c.muted(strat.actions === 'tools' ? 'tools' : 'guided') : c.dim('not loaded yet'),
|
|
687
689
|
thinking: strat?.thinking ? c.think(`thinking${cfg.effort ? ` · ${cfg.effort}` : ''}`) + (ui.showThinking ? '' : c.faint(' (collapsed)')) : null,
|
|
688
690
|
images: strat?.vision ? c.muted('images') : null,
|
|
689
691
|
ctx: null,
|
|
@@ -692,6 +694,7 @@ class App {
|
|
|
692
694
|
autocompact: cfg.autoCompact === false ? c.faint('auto-compact off') : null,
|
|
693
695
|
worktree: this.worktree ? c.info(`⎇ ${this.worktree.branch}`) : null,
|
|
694
696
|
background: runningJobs(this.root).length ? c.info(`⚙ ${runningJobs(this.root).length} running`) + c.faint(' Alt+B') : null,
|
|
697
|
+
update: this.update?.newer ? c.green(`⬆ ${this.update.latest}`) + c.faint(' /update') : null,
|
|
695
698
|
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],
|
|
696
699
|
}
|
|
697
700
|
if (strat) {
|
|
@@ -707,8 +710,8 @@ class App {
|
|
|
707
710
|
const sep = c.ghost(' │ ')
|
|
708
711
|
const vis = (str) => width(str.replace(/\x1b\[[0-9;]*m/g, ''))
|
|
709
712
|
let layout = Array.isArray(cfg.statusBar) && cfg.statusBar.length ? cfg.statusBar : DEFAULT_STATUS
|
|
710
|
-
// commands
|
|
711
|
-
if (parts
|
|
713
|
+
// background commands and a newer HeartCode are shown also on a bar laid out before there were these items
|
|
714
|
+
for (const id of ['update', 'background']) if (parts[id] && !JSON.stringify(layout).includes(`"${id}"`)) layout = [...layout.slice(0, -1), ...layout.slice(-1).map((row) => (Array.isArray(row) ? { left: row, right: [id] } : { ...row, right: [id, ...(row.right ?? [])] }))]
|
|
712
715
|
const line = (row) => {
|
|
713
716
|
const names = (g) => (g ?? []).map((t) => parts[t]).filter(Boolean).join(sep)
|
|
714
717
|
const left = names(Array.isArray(row) ? row : row?.left)
|
|
@@ -772,6 +775,8 @@ class App {
|
|
|
772
775
|
Object.assign(this.s, { noFormat: cfg.format === false, noLsp: cfg.lsp === false })
|
|
773
776
|
Object.assign(this.s, { mcp: this.mcp, memory: this.memory, skills: this.skills, director: this.director })
|
|
774
777
|
this.s.team = () => this.team() // your other models: a job this one can't do goes to one of them
|
|
778
|
+
this.s.allModels = () => this.sessionModels().map((t) => ({ ...t, ...this.abilities(t) })) // all of them, for a best-fit pick
|
|
779
|
+
this.s.fitMode = () => fitMode(this.cfg) // models picked by strengths per message, not by the list's order
|
|
775
780
|
this.s.engineFor = (t) => this.engine(t.provider, t.model, ui, undefined, { quiet: true })
|
|
776
781
|
// A model's context window, read from its saved profile (no probe, no network): so the agent can
|
|
777
782
|
// see, before compacting, whether another model in the list has room for the whole conversation.
|
|
@@ -1169,6 +1174,10 @@ let settingsPage = null
|
|
|
1169
1174
|
|
|
1170
1175
|
// The browser, with a page. Windows: its URL handler (cmd's start mangles a URL whose arguments
|
|
1171
1176
|
// it reads as its own, and wants a quoted empty title first).
|
|
1177
|
+
// How HeartCode picks your models: "fit" (by strengths, per message) or your order; --model-choice for this run wins.
|
|
1178
|
+
let modelChoiceFlag
|
|
1179
|
+
const fitMode = (cfg) => (modelChoiceFlag ?? cfg.modelChoice) === 'fit'
|
|
1180
|
+
|
|
1172
1181
|
function openBrowser(url) {
|
|
1173
1182
|
if (process.env.HEART_NO_BROWSER) return
|
|
1174
1183
|
const [cmd, ...args] = process.platform === 'darwin' ? ['open', url] : process.platform === 'win32' ? ['rundll32', 'url.dll,FileProtocolHandler', url] : ['xdg-open', url]
|
|
@@ -1182,7 +1191,7 @@ function applySettings(apps, cfg, what) {
|
|
|
1182
1191
|
const before = themeCodes()
|
|
1183
1192
|
if (what === 'theme' || what === 'setting:theme') setTheme(cfg.theme)
|
|
1184
1193
|
if (what === 'prompts') reloadPrompts()
|
|
1185
|
-
if (['setting:log', 'setting:logRequests', 'setting:logDetail'].includes(what)) useRequestLog(cfg) //
|
|
1194
|
+
if (['setting:logs', 'setting:log', 'setting:logRequests', 'setting:logDetail'].includes(what)) useRequestLog(cfg) // each kind of log, on or off now
|
|
1186
1195
|
if (what === 'setting:logDays') pruneLogs(logDays(cfg))
|
|
1187
1196
|
settingsSeen(what) // the watcher (watchSettings) mustn't take it in a second time
|
|
1188
1197
|
for (const app of apps) {
|
|
@@ -1292,7 +1301,7 @@ function afterReset(apps, level) {
|
|
|
1292
1301
|
setTheme(fresh.theme)
|
|
1293
1302
|
reloadPrompts()
|
|
1294
1303
|
for (const app of apps) {
|
|
1295
|
-
for (const k of Object.keys(app.cfg)) if (!['
|
|
1304
|
+
for (const k of Object.keys(app.cfg)) if (!['maxRetries', 'maxTurns', 'mcp', 'adhoc', 'fixed'].includes(k)) delete app.cfg[k]
|
|
1296
1305
|
Object.assign(app.cfg, fresh)
|
|
1297
1306
|
const { ui } = app
|
|
1298
1307
|
ui.permission = fresh.permissions ?? 'all' // not setPermission: that saves it again
|
|
@@ -1322,31 +1331,22 @@ function leaveTabWorktree(app) {
|
|
|
1322
1331
|
|
|
1323
1332
|
// A model's profile: the saved one; else what models.dev says (nothing is sent to the model to
|
|
1324
1333
|
// find out); a model it doesn't know: plain assumptions, until you set it up on the settings page.
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
if (!p && !force) {
|
|
1334
|
+
async function getProfile(client, ui, quiet = false) {
|
|
1335
|
+
let p = loadProfile(client)
|
|
1336
|
+
if (!p) {
|
|
1329
1337
|
await loadPrices()
|
|
1330
1338
|
p = profileFrom(client, limitsOf(client.provider, client.baseUrl, client.model))
|
|
1331
1339
|
writeJson(profilePath(client), p)
|
|
1332
1340
|
}
|
|
1333
1341
|
// one models.dev didn't know when it was saved: looked up again (it may have been added, or the list
|
|
1334
1342
|
// couldn't be had then)
|
|
1335
|
-
if (p
|
|
1343
|
+
if (p.source === 'assumed') {
|
|
1336
1344
|
await loadPrices()
|
|
1337
1345
|
const known = limitsOf(client.provider, client.baseUrl, client.model)
|
|
1338
1346
|
if (known) writeJson(profilePath(client), (p = { ...p, known, source: 'models.dev' }))
|
|
1339
1347
|
}
|
|
1340
|
-
if (p) {
|
|
1341
|
-
|
|
1342
|
-
return p
|
|
1343
|
-
}
|
|
1344
|
-
ui.print(c.dim(`Testing ${client.model}…`))
|
|
1345
|
-
const t0 = Date.now()
|
|
1346
|
-
const tested = await probe(client, (label) => ui.spinner(`testing: ${label}`), signal)
|
|
1347
|
-
ui.stopSpin()
|
|
1348
|
-
ui.print(c.dim(`done in ${duration(Date.now() - t0)} · saved to ${profilePath(client)}`))
|
|
1349
|
-
return tested
|
|
1348
|
+
if (p.source === 'assumed' && !quiet) ui.warn(`${client.model} isn't in models.dev: assuming it calls tools and streams, with a ~128k window. Set what it can do on /settings`)
|
|
1349
|
+
return p
|
|
1350
1350
|
}
|
|
1351
1351
|
|
|
1352
1352
|
// A setting from its choices: the argument if valid, else a picker. Returns the choice or null.
|
|
@@ -1411,8 +1411,8 @@ async function slash(app, line, working = false) {
|
|
|
1411
1411
|
}
|
|
1412
1412
|
case 'settings': {
|
|
1413
1413
|
settingsPage ??= startSettings({ cfg, root: app.root, onLoginMcp: (name) => signInMcp(app, name, null), apply: (what) => applySettings(app.tabs ? app.tabs.list.map((t) => t.app) : [app], cfg, what) })
|
|
1414
|
-
const { url, close } = await settingsPage
|
|
1415
|
-
openBrowser(
|
|
1414
|
+
const { url, local, close } = await settingsPage
|
|
1415
|
+
openBrowser(local)
|
|
1416
1416
|
ui.print(`${c.info('↗')} ${c.bold('settings')} ${c.muted('opened in your browser:')}\n ${c.faint(url)}`)
|
|
1417
1417
|
// a dialog until it's turned off: nothing else meanwhile, in any tab (Esc turns it off too).
|
|
1418
1418
|
// Not busy meanwhile: what's changed on the page applies at once, here too (opened while a task
|
|
@@ -1441,6 +1441,28 @@ async function slash(app, line, working = false) {
|
|
|
1441
1441
|
}
|
|
1442
1442
|
case 'help':
|
|
1443
1443
|
return ui.showText('Commands and keys', app.help())
|
|
1444
|
+
case 'update': {
|
|
1445
|
+
ui.spinner('asking npm for the newest HeartCode')
|
|
1446
|
+
const u = await checkUpdate({ force: true })
|
|
1447
|
+
ui.stopSpin()
|
|
1448
|
+
if (!u) return ui.warn("couldn't reach npm to check for a newer HeartCode")
|
|
1449
|
+
app.update = u
|
|
1450
|
+
ui.render?.()
|
|
1451
|
+
if (!u.newer) return ui.print(c.dim(`HeartCode ${u.current} is the newest`))
|
|
1452
|
+
const kind = installKind()
|
|
1453
|
+
const notes = await whatsNew(u.current, u.latest)
|
|
1454
|
+
if (kind === 'git') return ui.showText(`HeartCode ${u.latest} is out (you have ${u.current})`, `${notes || '(no changelog found)'}\n\nThis HeartCode runs from a git checkout (${packageDir}): update it there with git pull.`)
|
|
1455
|
+
const cmd = UPDATE_COMMANDS[kind]
|
|
1456
|
+
ui.showText(`HeartCode ${u.latest} is out (you have ${u.current})`, notes || '(no changelog found)')
|
|
1457
|
+
if ((await ui.confirm(`Update now with ${c.bold(cmd)}?`, 'command')) !== true) return ui.print(c.dim('not updated'))
|
|
1458
|
+
ui.spinner(`running ${cmd}`)
|
|
1459
|
+
const r = await runCommand(process.cwd(), cmd, { timeout: 300_000 })
|
|
1460
|
+
ui.stopSpin()
|
|
1461
|
+
if (r.code !== 0) return ui.warn(`the update failed (exit ${r.code}): ${r.output.trim().split('\n').slice(-3).join(' · ')}`)
|
|
1462
|
+
app.update = { ...u, newer: false }
|
|
1463
|
+
ui.render?.()
|
|
1464
|
+
return ui.print(`${c.green('✓')} HeartCode ${u.latest} installed ${c.dim('· restart HeartCode to use it (/exit, then heart)')}`)
|
|
1465
|
+
}
|
|
1444
1466
|
case 'select_model':
|
|
1445
1467
|
return app.pickModel(args, working)
|
|
1446
1468
|
case 'rename': {
|
|
@@ -1612,10 +1634,17 @@ async function slash(app, line, working = false) {
|
|
|
1612
1634
|
case 'import': {
|
|
1613
1635
|
const items = findImports(app.root)
|
|
1614
1636
|
if (!items.length) return ui.print('Nothing to import: no commands, skills, MCP servers, instructions or memory from Claude Code, Codex, Gemini CLI, OpenCode or Cursor found.')
|
|
1637
|
+
for (const it of items) if (it.dup?.()) it.desc = `${c.yellow('already have it')} · ${it.desc}`
|
|
1615
1638
|
const chosen = await ui.pick(`Import from other CLIs (${items.length} found)`, items, { multi: true })
|
|
1616
1639
|
if (!chosen) return
|
|
1617
1640
|
for (const it of chosen) {
|
|
1618
1641
|
try {
|
|
1642
|
+
// a duplicate (also of one just imported): added only if you say so, under a free name
|
|
1643
|
+
const dup = it.dup?.()
|
|
1644
|
+
if (dup && (await ui.pick(`${it.label}: ${dup}. Add it anyway?`, [{ label: 'No, skip it', value: false }, { label: 'Yes, add it under a new name', value: true }]))?.value !== true) {
|
|
1645
|
+
ui.print(`${c.dim('–')} ${it.label} ${c.dim(`skipped: ${dup}`)}`)
|
|
1646
|
+
continue
|
|
1647
|
+
}
|
|
1619
1648
|
ui.print(`${c.green('✓')} ${it.run()}`)
|
|
1620
1649
|
} catch (e) {
|
|
1621
1650
|
ui.print(`${c.red('✗')} ${it.label}: ${e.message}`)
|
|
@@ -1653,13 +1682,13 @@ async function slash(app, line, working = false) {
|
|
|
1653
1682
|
ui.showThinking = !ui.showThinking
|
|
1654
1683
|
return ui.print(c.dim(`thinking ${ui.showThinking ? 'shown' : 'collapsed'}`))
|
|
1655
1684
|
}
|
|
1656
|
-
if (!['model_info', '
|
|
1685
|
+
if (!['model_info', 'compact'].includes(cmd)) {
|
|
1657
1686
|
app.skills = loadSkills(app.root) // edits to skill files apply right away
|
|
1658
1687
|
if (app.s) app.s.skills = app.skills
|
|
1659
1688
|
if (cmd.startsWith('skill:')) {
|
|
1660
1689
|
const name = cmd.slice(6)
|
|
1661
1690
|
const k = app.skills.get(name)
|
|
1662
|
-
if (k && k.use
|
|
1691
|
+
if (k && (k.use === 'me' || k.use === 'both')) return runTask(app, await app.expandSkill(k, args.join(' ')), { signal: app.signal })
|
|
1663
1692
|
return ui.print(`unknown skill /skill:${name} ${c.dim('· /help lists your skills')}`)
|
|
1664
1693
|
}
|
|
1665
1694
|
if (app.skills.has(cmd)) return ui.print(`${c.dim(`/${cmd} is a skill — run it as`)} ${c.cyan(`/skill:${cmd}`)}`) // bare skill name: point to the namespaced form
|
|
@@ -1676,13 +1705,6 @@ async function slash(app, line, working = false) {
|
|
|
1676
1705
|
}
|
|
1677
1706
|
case 'model_info':
|
|
1678
1707
|
return ui.showText(s.client.model, describe(s.profile, s.strat))
|
|
1679
|
-
case 'test_model': {
|
|
1680
|
-
const tested = await getProfile(app.client(s.client.provider, s.client.model), ui, true, app.signal) // tested on a fresh connection (requests not fitted to what it was thought to do), and saved
|
|
1681
|
-
s.reset()
|
|
1682
|
-
app.s = null // built again from the saved profile (one profile and strategy, kept up to date as the model list moves on)
|
|
1683
|
-
await app.session()
|
|
1684
|
-
return ui.print(`${c.cyan(tested.model)}\n${describe(tested, strategy(tested, cfg))}`)
|
|
1685
|
-
}
|
|
1686
1708
|
}
|
|
1687
1709
|
}
|
|
1688
1710
|
|
|
@@ -1713,7 +1735,7 @@ async function runTask(app, task, ctl) {
|
|
|
1713
1735
|
|
|
1714
1736
|
async function repl(app, f = {}) {
|
|
1715
1737
|
const { ui, cfg } = app
|
|
1716
|
-
ui.fullscreen()
|
|
1738
|
+
ui.fullscreen({ mouse: cfg.mouse === true }) // off: the terminal selects and copies text itself
|
|
1717
1739
|
ui.onDoubleEscape = () => '/rewind'
|
|
1718
1740
|
let ctl = null
|
|
1719
1741
|
ui.onEscape = () => ctl?.abort()
|
|
@@ -1805,6 +1827,16 @@ async function repl(app, f = {}) {
|
|
|
1805
1827
|
// models this folder picked earlier (/select_model): said, with the way back to your whole list
|
|
1806
1828
|
if (app.folderModels && cfg.session?.length) ui.print(`${c.muted('this folder uses')} ${c.cyan(cfg.session.map((t) => t.model).join(', '))} ${c.faint(`(picked earlier) · ${c.cyan('/select_model auto')} for your whole list again`)}`)
|
|
1807
1829
|
app.tabs?.onChange?.() // the conversation it opened with
|
|
1830
|
+
// a newer HeartCode: asked in the background (once a day at most), said once and kept in the status bar
|
|
1831
|
+
if (cfg.updateCheck !== false)
|
|
1832
|
+
checkUpdate()
|
|
1833
|
+
.then((u) => {
|
|
1834
|
+
if (!u?.newer) return
|
|
1835
|
+
app.update = u
|
|
1836
|
+
ui.print(`${c.green('⬆')} ${c.muted('HeartCode')} ${c.green(u.latest)} ${c.muted(`is out (you have ${u.current})`)} ${c.faint('·')} ${c.cyan('/update')}`)
|
|
1837
|
+
ui.render?.()
|
|
1838
|
+
})
|
|
1839
|
+
.catch(() => {})
|
|
1808
1840
|
for (;;) {
|
|
1809
1841
|
const line = await ui.ask(` ${c.magenta('♥')} `, { suggest: true, initial: app.nextInput, history: true })
|
|
1810
1842
|
app.nextInput = undefined
|
|
@@ -1815,7 +1847,9 @@ async function repl(app, f = {}) {
|
|
|
1815
1847
|
app.signal = ctl.signal // Esc stops whatever this line started (a task, a probe, …)
|
|
1816
1848
|
ui.escArm = 0 // a fresh task: a first Esc from before doesn't count toward stopping this one
|
|
1817
1849
|
ui.busy() // the spinner stays until this line's work is done
|
|
1818
|
-
|
|
1850
|
+
const command = app.isCommand(t)
|
|
1851
|
+
if (command) {
|
|
1852
|
+
const mark = ui.mark?.() // what it prints goes back out of the conversation when it's done
|
|
1819
1853
|
try {
|
|
1820
1854
|
if ((await slash(app, t)) === 'exit') {
|
|
1821
1855
|
if (app.tabs) app.tabs.quitting = true
|
|
@@ -1826,6 +1860,7 @@ async function repl(app, f = {}) {
|
|
|
1826
1860
|
log('error', e.stack)
|
|
1827
1861
|
ui.print(c.red(`error: ${e.message}`))
|
|
1828
1862
|
}
|
|
1863
|
+
if (mark) ui.unmark(mark, /^\S+/.exec(t)[0])
|
|
1829
1864
|
} else {
|
|
1830
1865
|
let ok = await runTask(app, t, ctl)
|
|
1831
1866
|
// plan mode: the plan is done; go ahead with it?
|
|
@@ -1846,7 +1881,7 @@ async function repl(app, f = {}) {
|
|
|
1846
1881
|
ctl = null
|
|
1847
1882
|
app.afterLine()
|
|
1848
1883
|
app.tabs?.onChange?.() // the conversation may be another now (/resume, /fork, /clear_chat)
|
|
1849
|
-
if (ui.tail) ui.print() // nothing after /clear_chat
|
|
1884
|
+
if (ui.tail && !command) ui.print() // nothing after /clear_chat, nor after a command (it left nothing)
|
|
1850
1885
|
}
|
|
1851
1886
|
ui.close()
|
|
1852
1887
|
}
|
|
@@ -1872,7 +1907,6 @@ async function main() {
|
|
|
1872
1907
|
'hide-thinking': { type: 'boolean' },
|
|
1873
1908
|
cwd: { type: 'string', short: 'C' },
|
|
1874
1909
|
context: { type: 'string' },
|
|
1875
|
-
force: { type: 'boolean' },
|
|
1876
1910
|
save: { type: 'boolean' },
|
|
1877
1911
|
continue: { type: 'boolean', short: 'c' },
|
|
1878
1912
|
resume: { type: 'boolean', short: 'r' },
|
|
@@ -1892,6 +1926,7 @@ async function main() {
|
|
|
1892
1926
|
disallowedTools: { type: 'string', multiple: true },
|
|
1893
1927
|
'disallowed-tools': { type: 'string', multiple: true },
|
|
1894
1928
|
'permission-mode': { type: 'string' },
|
|
1929
|
+
'model-choice': { type: 'string' },
|
|
1895
1930
|
'dangerously-skip-permissions': { type: 'boolean' },
|
|
1896
1931
|
'session-id': { type: 'string' },
|
|
1897
1932
|
effort: { type: 'string' },
|
|
@@ -1914,13 +1949,14 @@ async function main() {
|
|
|
1914
1949
|
if (f.context && !(Number(f.context) > 0)) throw new Error('--context must be a number of tokens')
|
|
1915
1950
|
for (const k of ['output-format', 'input-format']) if (f[k] && !['text', 'json', 'stream-json'].includes(f[k])) throw new Error(`--${k} must be text, json or stream-json`)
|
|
1916
1951
|
if (f['permission-mode'] && !PERMISSION_MODES[f['permission-mode']]) throw new Error(`--permission-mode must be one of ${Object.keys(PERMISSION_MODES).join(', ')}`)
|
|
1952
|
+
if (f['model-choice'] && !['order', 'fit'].includes(f['model-choice'])) throw new Error('--model-choice must be order or fit')
|
|
1953
|
+
modelChoiceFlag = f['model-choice']
|
|
1917
1954
|
|
|
1918
1955
|
const cfg = loadConfig({ baseUrl: f['base-url'], model: f.model, apiKey: f['api-key'], context: f.context })
|
|
1919
1956
|
setTheme(cfg.theme)
|
|
1920
1957
|
useLogs(cfg)
|
|
1921
1958
|
const safe = { ...cfg, providers: Object.fromEntries(Object.entries(cfg.providers).map(([n, p]) => [n, { ...p, apiKey: p.apiKey && mask(p.apiKey) }])) }
|
|
1922
1959
|
log('start', `heartcode ${VERSION} · node ${process.version} · ${process.platform} · cwd ${process.cwd()}`, { args: process.argv.slice(2).map((a) => (a === f['api-key'] ? mask(a) : a)), config: safe })
|
|
1923
|
-
cfg.force = f.force
|
|
1924
1960
|
if (f.provider) {
|
|
1925
1961
|
if (!cfg.providers[f.provider]) throw new Error(`no provider "${f.provider}" (heartcode providers lists them)`)
|
|
1926
1962
|
Object.assign(cfg, { provider: f.provider, fixed: true })
|
|
@@ -1939,12 +1975,12 @@ async function main() {
|
|
|
1939
1975
|
saveConfig(cfg)
|
|
1940
1976
|
console.log(c.dim(`saved to ${CONFIG_FILE}`))
|
|
1941
1977
|
}
|
|
1942
|
-
const sub = ['
|
|
1978
|
+
const sub = ['models', 'providers', 'config', 'settings'].includes(positionals[0]) && positionals.length <= 2 ? positionals[0] : null
|
|
1943
1979
|
|
|
1944
1980
|
if (sub === 'settings') {
|
|
1945
|
-
const { url } = await startSettings({ cfg })
|
|
1946
|
-
console.log(`${c.brand('♥')} HeartCode settings: ${url}\n${c.dim('opened in your browser · Ctrl+C to stop')}`)
|
|
1947
|
-
openBrowser(
|
|
1981
|
+
const { url, local } = await startSettings({ cfg })
|
|
1982
|
+
console.log(`${c.brand('♥')} HeartCode settings: ${url}\n${c.dim('opened in your browser · from another device on this network, open the link above · Ctrl+C to stop')}`)
|
|
1983
|
+
openBrowser(local)
|
|
1948
1984
|
return new Promise(() => {}) // until Ctrl+C
|
|
1949
1985
|
}
|
|
1950
1986
|
|
|
@@ -2037,14 +2073,6 @@ async function main() {
|
|
|
2037
2073
|
app.worktree = wt
|
|
2038
2074
|
if (sub === 'providers') return app.listProviders(), ui.close()
|
|
2039
2075
|
if (sub === 'models') return await app.listModels(positionals[1] ?? '', { all: f.all, json: f.json }), ui.close()
|
|
2040
|
-
if (sub === 'probe') {
|
|
2041
|
-
cfg.force = true
|
|
2042
|
-
const s = await app.session()
|
|
2043
|
-
if (s) ui.print(describe(s.profile, s.strat))
|
|
2044
|
-
ui.close()
|
|
2045
|
-
process.exitCode = s ? 0 : 1
|
|
2046
|
-
return
|
|
2047
|
-
}
|
|
2048
2076
|
if (f['no-memory']) app.memory = null
|
|
2049
2077
|
const chat = f['resume-id'] ? loadChat(f['resume-id']) : f.continue && headless ? listChats(app.root)[0] : f['session-id'] ? (loadChat(f['session-id']) ?? { ...newChat(app.root), id: f['session-id'] }) : null
|
|
2050
2078
|
if (f['resume-id'] && !chat) throw new Error(`no session ${f['resume-id']}`)
|
package/package.json
CHANGED
package/prompts/README.md
CHANGED
|
@@ -7,7 +7,6 @@ Everything HeartCode sends to a model, in four files. Each `## name` heading is
|
|
|
7
7
|
| `agent.md` | tool mode (capable models): the system prompt, tool descriptions, memory, notes HeartCode adds |
|
|
8
8
|
| `guided.md` | guided mode (weak models): one question at a time |
|
|
9
9
|
| `compact.md` | `/compact` and auto-compact |
|
|
10
|
-
| `probe.md` | the one-time test of a new model |
|
|
11
10
|
|
|
12
11
|
In a prompt, `{{name}}` is filled in by HeartCode (the note under each heading lists them),
|
|
13
12
|
`{{#if name}} … {{else}} … {{/if}}` keeps a part only when `name` has a value, and a
|