heartcode 0.1.40 → 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/CHANGELOG.md +24 -0
- package/README.md +11 -9
- package/SKILL.md +17 -4
- package/bin/heart.js +1 -1
- package/bin/heartcode.js +29 -49
- package/package.json +1 -1
- package/prompts/README.md +0 -1
- package/prompts/agent.md +0 -5
- package/src/agent.js +8 -9
- package/src/capabilities.js +2 -2
- package/src/guided.js +12 -21
- package/src/importer.js +50 -12
- package/src/log.js +1 -1
- package/src/probe.js +20 -310
- package/src/prompts.js +1 -1
- package/src/rankings.js +15 -8
- package/src/settings.html +79 -86
- package/src/settings.js +15 -10
- package/src/ui.js +18 -0
- package/prompts/probe.md +0 -67
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
2
2
|
|
|
3
3
|
What changed in each version of HeartCode, newest first.
|
|
4
4
|
|
|
5
|
+
## 0.1.41 (2026-11-03)
|
|
6
|
+
|
|
7
|
+
- **Model scores on Your models**: Coding, Web apps and Vision show each model's LMArena score with
|
|
8
|
+
its place (`1478 #60`; hover for the votes); green is the top tenth. The page opens fast again
|
|
9
|
+
with thousands of models (each name matched once, not once per ranking entry).
|
|
10
|
+
- **Your models in three rows**: the title with Order providers and Update model info (models.dev
|
|
11
|
+
and the scores in one click); the settings on one line with short names (Pick, If one fails, Give
|
|
12
|
+
up after, New message to, Tests wait); search, filters, the count, Clear, Test all and Save order
|
|
13
|
+
on one line. The sort shows in the column heads.
|
|
14
|
+
- **Best fit said plainly**: with Pick on "the best for each task", the page and the sidebar say
|
|
15
|
+
each message goes to the models that score best for it (not "HeartCode uses #1"), and Order
|
|
16
|
+
providers is off, with why on hover.
|
|
17
|
+
- **The list holds still while models are tested** (or Update model info runs): filters, sorting,
|
|
18
|
+
the settings, dragging and each row's changes wait; Stop and Request still work.
|
|
19
|
+
- **Settings from another device**: the link shows your machine's network address
|
|
20
|
+
(`http://192.168.1.108:43135/?t=…`) and the page answers there; only with its key, and only to
|
|
21
|
+
this machine's addresses.
|
|
22
|
+
- **Slash commands leave nothing behind**: a command shows a toast for a few seconds; what it shows
|
|
23
|
+
opens in a dialog, and nothing stays in the conversation.
|
|
24
|
+
- **/import asks before a duplicate**: one you already have (same name, same text, or the same MCP
|
|
25
|
+
server under another name) is marked, and added only if you say so, under a new name.
|
|
26
|
+
- **Removed**: /test_model and `heart probe` (models.dev says what a model can do), and the
|
|
27
|
+
settings only those tests could switch on.
|
|
28
|
+
|
|
5
29
|
## 0.1.40 (2026-11-03)
|
|
6
30
|
|
|
7
31
|
- **A smaller, general system prompt** (about 6,700 tokens to start a task, from 13,000+): its rules
|
package/README.md
CHANGED
|
@@ -59,7 +59,7 @@ tried did what I needed:
|
|
|
59
59
|
- **Tells you when a newer version is out** (a check with npm at most once a day, in the status bar):
|
|
60
60
|
`/update` shows what changed and installs it the way you installed HeartCode. Switch it off in
|
|
61
61
|
`/settings` → General.
|
|
62
|
-
- **Best fit by public rankings**: with "
|
|
62
|
+
- **Best fit by public rankings**: with "Pick" set to "the best for each task", each message's
|
|
63
63
|
lead and code reviewer are your models ranked on the skills that task needs (web
|
|
64
64
|
pages, code, images…) by LMArena's public rankings, fetched once a week. Your models shows each
|
|
65
65
|
one's Coding, Web apps and Vision rank.
|
|
@@ -105,9 +105,11 @@ heart
|
|
|
105
105
|
|
|
106
106
|
### 3. Open the settings page
|
|
107
107
|
|
|
108
|
-
Type `/settings`. The settings page opens in your browser.
|
|
109
|
-
(
|
|
110
|
-
|
|
108
|
+
Type `/settings`. The settings page opens in your browser. The link shown has your machine's
|
|
109
|
+
network address (like `http://192.168.1.108:43135/?t=…`), so it opens from another device on the
|
|
110
|
+
same network too: HeartCode on a server over SSH, the page on your laptop. Only that link works:
|
|
111
|
+
it has a secret key, and the page answers only to this machine's own addresses. A running
|
|
112
|
+
HeartCode picks up what you change right away.
|
|
111
113
|
|
|
112
114
|
<!-- image: the settings page -->
|
|
113
115
|

|
|
@@ -138,15 +140,15 @@ On **Models → Your list**:
|
|
|
138
140
|
1. **Sort them by context and abilities.** Click the *Abilities* column, then *Context*: the
|
|
139
141
|
models that can do the most come first, the biggest context window first among those (each
|
|
140
142
|
column clicked breaks the ties of the ones before; click one again to reverse it, a third time to
|
|
141
|
-
drop it). Click **Save
|
|
143
|
+
drop it). Click **Save order** to keep it.
|
|
142
144
|
2. **Rearrange a bit more.** Drag a row to move it. #1 is the one HeartCode uses; the others are
|
|
143
145
|
its fallbacks, tried in order.
|
|
144
146
|
3. **Test them** (optional): **Test all** sends each a short message and shows which really answer.
|
|
145
|
-
Each test waits up to 10 seconds;
|
|
147
|
+
Each test waits up to 10 seconds; **Tests wait**, above the list, changes that.
|
|
146
148
|
4. **Filter them** (optional): by name, provider, test result (works, doesn't, not tested, or one
|
|
147
|
-
error like 402), context, tools, thinking, images or free. **Test
|
|
148
|
-
shown, and **Use these N** makes them the models HeartCode uses, in the order you see (the others
|
|
149
|
-
stay under Providers). Filter to the working ones, sort by Works?, Use these: HeartCode uses your
|
|
149
|
+
error like 402), context, tools, thinking, images or free. **Test N** then tests only the ones
|
|
150
|
+
shown, and **Use only these N** makes them the models HeartCode uses, in the order you see (the others
|
|
151
|
+
stay under Providers). Filter to the working ones, sort by Works?, Use only these: HeartCode uses your
|
|
150
152
|
working models, fastest first.
|
|
151
153
|
|
|
152
154
|
If a model says *not found* in models.dev, **Retry** looks it up again, or **Set up** tells
|
package/SKILL.md
CHANGED
|
@@ -58,7 +58,7 @@ reached has an `error` (in text: a line on stderr) and is skipped; the command s
|
|
|
58
58
|
|
|
59
59
|
| `-m` | What runs |
|
|
60
60
|
|---|---|
|
|
61
|
-
| `auto`, or no `-m` | the user's list: #1, and the next one in order when it fails. Use this unless you need one particular model. |
|
|
61
|
+
| `auto`, or no `-m` | the user's list: #1, and the next one in order when it fails (with the user's "best fit" setting: their models ranked for each task, below). Use this unless you need one particular model. |
|
|
62
62
|
| `provider/model` (`-m groq/openai/gpt-oss-120b`), or a model of #1's provider alone | that model alone: never another one, also when it fails (a rate limit or an outage is tried again, up to `--max-retries`) |
|
|
63
63
|
| that, plus `--fallback-model provider/model` (repeatable) | that model, then the fallbacks in order when it fails (as `claude -p --fallback-model`) |
|
|
64
64
|
|
|
@@ -80,6 +80,13 @@ image, one that can't call tools gets the tool calls as text.
|
|
|
80
80
|
|
|
81
81
|
`--provider <name>` and `-u <url>` (a server for this run) also mean one model, alone.
|
|
82
82
|
|
|
83
|
+
**Best fit** (the user's setting "Pick: the best for each task", on Your models in `heart settings`): with `auto`,
|
|
84
|
+
each new message first names the skills the task needs (code, web pages, images, long inputs…) in
|
|
85
|
+
one short request, and the user's models are ordered by their places in the public LMArena rankings
|
|
86
|
+
of those skills (fetched once a week); the best leads, the next take over when it fails, and the
|
|
87
|
+
code review goes to the best of the others. Models the rankings don't know come last, in the user's
|
|
88
|
+
order. With "Your order" (the default), the list is the user's order, as is.
|
|
89
|
+
|
|
83
90
|
A run picks up settings the user changes meanwhile (`heart settings`, another HeartCode, or
|
|
84
91
|
`~/.heart` by hand) without being restarted, from its next request: the model order, prompts,
|
|
85
92
|
hooks, skills, MCP servers. `--temp` runs share one throwaway folder, so a change in one reaches the
|
|
@@ -126,7 +133,9 @@ heart -p --continue "…" # or: the last session in this folder
|
|
|
126
133
|
## Keep it safe
|
|
127
134
|
|
|
128
135
|
Headless never asks anyone. What the permission mode would ask about is declined, and the
|
|
129
|
-
model is told why.
|
|
136
|
+
model is told why. A question the model would ask the user (what to build, how it should look,
|
|
137
|
+
what testing) it decides itself, and says in its reply what it assumed: put the choices that
|
|
138
|
+
matter in the prompt. An MCP tool its server marks read-only is never asked about. The model can't
|
|
130
139
|
give itself a freer permission mode (its `manage` tool asks the user, so headless refuses it), and
|
|
131
140
|
can't switch the model you chose.
|
|
132
141
|
|
|
@@ -162,7 +171,7 @@ assumptions, and the user can set it up on the settings page. Models that can't
|
|
|
162
171
|
work, in a slower guided mode.
|
|
163
172
|
|
|
164
173
|
The model in use knows the user's other models (what each can do, how often it failed this
|
|
165
|
-
session) and works with them through its `agent` tool: it asks a model that can for what it
|
|
174
|
+
session, and in best fit their ranks for code, web apps and vision) and works with them through its `agent` tool: it asks a model that can for what it
|
|
166
175
|
can't do itself (a model that can't see asks one that can about a screenshot: "which tiles show a
|
|
167
176
|
chair?"), several at once when there are many images or parts, and a helper that fails is handed to
|
|
168
177
|
the next capable model until one does the job. A helper works until its job is done (no step
|
|
@@ -191,7 +200,7 @@ answers. A run that fails with a wrong key or an unknown model: ask the user to
|
|
|
191
200
|
| Flag | |
|
|
192
201
|
|---|---|
|
|
193
202
|
| `--append-system-prompt "<text>"` | your instructions for this run, at the end of the system prompt. HeartCode's own part then says less (no role of its own, no "stay in the project folder", no way of finishing of its own) and tells the model to follow yours where they differ; its `manage` tool is left out, and nothing from the run's messages is saved to its memory |
|
|
194
|
-
| `--mcp-config <file or JSON>` | more MCP servers (repeatable); `--strict-mcp-config`: only those. The model sees every server's tools by name, one line each, and gets a tool's arguments when it uses it (a call that doesn't fit them comes back with what's wrong, not run). What a server says about using its tools
|
|
203
|
+
| `--mcp-config <file or JSON>` | more MCP servers (repeatable); `--strict-mcp-config`: only those. The model sees every server's tools by name, one line each, and gets a tool's arguments when it uses it (a call that doesn't fit them comes back with what's wrong, not run). What a server says about using its tools comes once, with the first result of one of them |
|
|
195
204
|
| `--skills-dir <folder>` | more skills (repeatable) |
|
|
196
205
|
| `--no-memory` | nothing read or kept: no memory notes, no web pages saved in the project, no wrap-up at the end (see "What a run leaves") |
|
|
197
206
|
|
|
@@ -245,6 +254,10 @@ Every `assistant` line's `message.model` is the model that wrote it (`provider/m
|
|
|
245
254
|
fallback, the one that took over, not the one the run started with (the `init` line's `model`).
|
|
246
255
|
`modelUsage` in the `result` has each model that answered.
|
|
247
256
|
|
|
257
|
+
Not in the stream: HeartCode's own prompts (the system prompt, its nudges), the skill-picking
|
|
258
|
+
request of best fit, the review's verdict and the wrap-up. Their tokens are in `usage` and
|
|
259
|
+
`modelUsage`. Retries and switches to another model go to stderr with `--verbose`.
|
|
260
|
+
|
|
248
261
|
## Don't
|
|
249
262
|
|
|
250
263
|
- Don't run `heart` without `-p` from an agent: it's a full-screen app and waits for a person.
|
package/bin/heart.js
CHANGED
|
@@ -64,7 +64,7 @@ if (temp) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
// a folder first: HeartCode opens it (subcommands and options go straight through)
|
|
67
|
-
const SUBCOMMANDS = ['
|
|
67
|
+
const SUBCOMMANDS = ['models', 'providers', 'config', 'settings']
|
|
68
68
|
const first = args[0]
|
|
69
69
|
if (first && !first.startsWith('-') && !SUBCOMMANDS.includes(first)) {
|
|
70
70
|
const where = path.resolve(first.replace(/^~(?=\/|$)/, os.homedir()))
|
package/bin/heartcode.js
CHANGED
|
@@ -3,7 +3,7 @@ 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'
|
|
@@ -46,7 +46,6 @@ ${c.bold('usage')}
|
|
|
46
46
|
as provider/model, #1 first
|
|
47
47
|
heart models --all [filter] every provider's models (provider/model)
|
|
48
48
|
heart models --json as JSON (with --all too), for other programs
|
|
49
|
-
heart probe test the current model for real (otherwise its abilities come from models.dev)
|
|
50
49
|
heart config show the config file
|
|
51
50
|
heart settings change providers, models and settings in your browser
|
|
52
51
|
|
|
@@ -64,7 +63,6 @@ ${c.bold('options')}
|
|
|
64
63
|
copied in), shared by the --temp runs going on at once and deleted
|
|
65
64
|
after the last; ~/.heart isn't touched
|
|
66
65
|
--context <n> context window size in tokens
|
|
67
|
-
--force re-run the probe
|
|
68
66
|
--save keep the given -u/-m/--api-key/... in ${CONFIG_FILE}
|
|
69
67
|
-w, --worktree work in a new git worktree and branch (--worktree=name to name it,
|
|
70
68
|
or to continue in it); removed on exit if nothing changed
|
|
@@ -123,7 +121,6 @@ const SECTIONS = [
|
|
|
123
121
|
['/context', "what's in the context now: system prompt, tools, messages, tool results, and the biggest pieces"],
|
|
124
122
|
['/background', 'commands running in the background (servers, watchers): their logs live, a tab each (Alt+B) · /background stop [id] · /background files', true],
|
|
125
123
|
['/model_info', 'what the model can do and how HeartCode uses it'],
|
|
126
|
-
['/test_model', 'test the model for real (otherwise what it can do comes from models.dev, or your settings)'],
|
|
127
124
|
['/tidy_memory', 'merge, update and link the memory notes now'],
|
|
128
125
|
['/import', 'bring commands, skills, MCP servers and memory from other CLIs'],
|
|
129
126
|
['/install_skill', 'install a skill from a GitHub repo or a SKILL.md URL (add --project for this folder only)', true],
|
|
@@ -350,8 +347,7 @@ class App {
|
|
|
350
347
|
ui.print(c.dim(`↻ ${t.provider} · ${t.model} answered${i ? ` (#${i + 1} in your model list)` : ' (#1 again)'}`))
|
|
351
348
|
}
|
|
352
349
|
if (cfg.maxRetries !== undefined) client.retryIf = (e, attempt) => attempt < cfg.maxRetries // headless: then give up
|
|
353
|
-
let profile = await getProfile(client, ui,
|
|
354
|
-
if (!quiet) cfg.force = false
|
|
350
|
+
let profile = await getProfile(client, ui, quiet)
|
|
355
351
|
const strat = {}
|
|
356
352
|
// The model asked from now on (at first, and when the model list moves on): its own profile,
|
|
357
353
|
// abilities (sees images? calls tools? its window), thinking effort, price, and what its
|
|
@@ -689,7 +685,7 @@ class App {
|
|
|
689
685
|
const parts = {
|
|
690
686
|
provider: `${c.brand('●')} ${c.muted(now.provider)} ${c.faint(`(${on})`)}`,
|
|
691
687
|
model,
|
|
692
|
-
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'),
|
|
693
689
|
thinking: strat?.thinking ? c.think(`thinking${cfg.effort ? ` · ${cfg.effort}` : ''}`) + (ui.showThinking ? '' : c.faint(' (collapsed)')) : null,
|
|
694
690
|
images: strat?.vision ? c.muted('images') : null,
|
|
695
691
|
ctx: null,
|
|
@@ -1305,7 +1301,7 @@ function afterReset(apps, level) {
|
|
|
1305
1301
|
setTheme(fresh.theme)
|
|
1306
1302
|
reloadPrompts()
|
|
1307
1303
|
for (const app of apps) {
|
|
1308
|
-
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]
|
|
1309
1305
|
Object.assign(app.cfg, fresh)
|
|
1310
1306
|
const { ui } = app
|
|
1311
1307
|
ui.permission = fresh.permissions ?? 'all' // not setPermission: that saves it again
|
|
@@ -1335,31 +1331,22 @@ function leaveTabWorktree(app) {
|
|
|
1335
1331
|
|
|
1336
1332
|
// A model's profile: the saved one; else what models.dev says (nothing is sent to the model to
|
|
1337
1333
|
// find out); a model it doesn't know: plain assumptions, until you set it up on the settings page.
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
if (!p && !force) {
|
|
1334
|
+
async function getProfile(client, ui, quiet = false) {
|
|
1335
|
+
let p = loadProfile(client)
|
|
1336
|
+
if (!p) {
|
|
1342
1337
|
await loadPrices()
|
|
1343
1338
|
p = profileFrom(client, limitsOf(client.provider, client.baseUrl, client.model))
|
|
1344
1339
|
writeJson(profilePath(client), p)
|
|
1345
1340
|
}
|
|
1346
1341
|
// one models.dev didn't know when it was saved: looked up again (it may have been added, or the list
|
|
1347
1342
|
// couldn't be had then)
|
|
1348
|
-
if (p
|
|
1343
|
+
if (p.source === 'assumed') {
|
|
1349
1344
|
await loadPrices()
|
|
1350
1345
|
const known = limitsOf(client.provider, client.baseUrl, client.model)
|
|
1351
1346
|
if (known) writeJson(profilePath(client), (p = { ...p, known, source: 'models.dev' }))
|
|
1352
1347
|
}
|
|
1353
|
-
if (p) {
|
|
1354
|
-
|
|
1355
|
-
return p
|
|
1356
|
-
}
|
|
1357
|
-
ui.print(c.dim(`Testing ${client.model}…`))
|
|
1358
|
-
const t0 = Date.now()
|
|
1359
|
-
const tested = await probe(client, (label) => ui.spinner(`testing: ${label}`), signal)
|
|
1360
|
-
ui.stopSpin()
|
|
1361
|
-
ui.print(c.dim(`done in ${duration(Date.now() - t0)} · saved to ${profilePath(client)}`))
|
|
1362
|
-
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
|
|
1363
1350
|
}
|
|
1364
1351
|
|
|
1365
1352
|
// A setting from its choices: the argument if valid, else a picker. Returns the choice or null.
|
|
@@ -1424,8 +1411,8 @@ async function slash(app, line, working = false) {
|
|
|
1424
1411
|
}
|
|
1425
1412
|
case 'settings': {
|
|
1426
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) })
|
|
1427
|
-
const { url, close } = await settingsPage
|
|
1428
|
-
openBrowser(
|
|
1414
|
+
const { url, local, close } = await settingsPage
|
|
1415
|
+
openBrowser(local)
|
|
1429
1416
|
ui.print(`${c.info('↗')} ${c.bold('settings')} ${c.muted('opened in your browser:')}\n ${c.faint(url)}`)
|
|
1430
1417
|
// a dialog until it's turned off: nothing else meanwhile, in any tab (Esc turns it off too).
|
|
1431
1418
|
// Not busy meanwhile: what's changed on the page applies at once, here too (opened while a task
|
|
@@ -1647,10 +1634,17 @@ async function slash(app, line, working = false) {
|
|
|
1647
1634
|
case 'import': {
|
|
1648
1635
|
const items = findImports(app.root)
|
|
1649
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}`
|
|
1650
1638
|
const chosen = await ui.pick(`Import from other CLIs (${items.length} found)`, items, { multi: true })
|
|
1651
1639
|
if (!chosen) return
|
|
1652
1640
|
for (const it of chosen) {
|
|
1653
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
|
+
}
|
|
1654
1648
|
ui.print(`${c.green('✓')} ${it.run()}`)
|
|
1655
1649
|
} catch (e) {
|
|
1656
1650
|
ui.print(`${c.red('✗')} ${it.label}: ${e.message}`)
|
|
@@ -1688,7 +1682,7 @@ async function slash(app, line, working = false) {
|
|
|
1688
1682
|
ui.showThinking = !ui.showThinking
|
|
1689
1683
|
return ui.print(c.dim(`thinking ${ui.showThinking ? 'shown' : 'collapsed'}`))
|
|
1690
1684
|
}
|
|
1691
|
-
if (!['model_info', '
|
|
1685
|
+
if (!['model_info', 'compact'].includes(cmd)) {
|
|
1692
1686
|
app.skills = loadSkills(app.root) // edits to skill files apply right away
|
|
1693
1687
|
if (app.s) app.s.skills = app.skills
|
|
1694
1688
|
if (cmd.startsWith('skill:')) {
|
|
@@ -1711,13 +1705,6 @@ async function slash(app, line, working = false) {
|
|
|
1711
1705
|
}
|
|
1712
1706
|
case 'model_info':
|
|
1713
1707
|
return ui.showText(s.client.model, describe(s.profile, s.strat))
|
|
1714
|
-
case 'test_model': {
|
|
1715
|
-
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
|
|
1716
|
-
s.reset()
|
|
1717
|
-
app.s = null // built again from the saved profile (one profile and strategy, kept up to date as the model list moves on)
|
|
1718
|
-
await app.session()
|
|
1719
|
-
return ui.print(`${c.cyan(tested.model)}\n${describe(tested, strategy(tested, cfg))}`)
|
|
1720
|
-
}
|
|
1721
1708
|
}
|
|
1722
1709
|
}
|
|
1723
1710
|
|
|
@@ -1860,7 +1847,9 @@ async function repl(app, f = {}) {
|
|
|
1860
1847
|
app.signal = ctl.signal // Esc stops whatever this line started (a task, a probe, …)
|
|
1861
1848
|
ui.escArm = 0 // a fresh task: a first Esc from before doesn't count toward stopping this one
|
|
1862
1849
|
ui.busy() // the spinner stays until this line's work is done
|
|
1863
|
-
|
|
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
|
|
1864
1853
|
try {
|
|
1865
1854
|
if ((await slash(app, t)) === 'exit') {
|
|
1866
1855
|
if (app.tabs) app.tabs.quitting = true
|
|
@@ -1871,6 +1860,7 @@ async function repl(app, f = {}) {
|
|
|
1871
1860
|
log('error', e.stack)
|
|
1872
1861
|
ui.print(c.red(`error: ${e.message}`))
|
|
1873
1862
|
}
|
|
1863
|
+
if (mark) ui.unmark(mark, /^\S+/.exec(t)[0])
|
|
1874
1864
|
} else {
|
|
1875
1865
|
let ok = await runTask(app, t, ctl)
|
|
1876
1866
|
// plan mode: the plan is done; go ahead with it?
|
|
@@ -1891,7 +1881,7 @@ async function repl(app, f = {}) {
|
|
|
1891
1881
|
ctl = null
|
|
1892
1882
|
app.afterLine()
|
|
1893
1883
|
app.tabs?.onChange?.() // the conversation may be another now (/resume, /fork, /clear_chat)
|
|
1894
|
-
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)
|
|
1895
1885
|
}
|
|
1896
1886
|
ui.close()
|
|
1897
1887
|
}
|
|
@@ -1917,7 +1907,6 @@ async function main() {
|
|
|
1917
1907
|
'hide-thinking': { type: 'boolean' },
|
|
1918
1908
|
cwd: { type: 'string', short: 'C' },
|
|
1919
1909
|
context: { type: 'string' },
|
|
1920
|
-
force: { type: 'boolean' },
|
|
1921
1910
|
save: { type: 'boolean' },
|
|
1922
1911
|
continue: { type: 'boolean', short: 'c' },
|
|
1923
1912
|
resume: { type: 'boolean', short: 'r' },
|
|
@@ -1968,7 +1957,6 @@ async function main() {
|
|
|
1968
1957
|
useLogs(cfg)
|
|
1969
1958
|
const safe = { ...cfg, providers: Object.fromEntries(Object.entries(cfg.providers).map(([n, p]) => [n, { ...p, apiKey: p.apiKey && mask(p.apiKey) }])) }
|
|
1970
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 })
|
|
1971
|
-
cfg.force = f.force
|
|
1972
1960
|
if (f.provider) {
|
|
1973
1961
|
if (!cfg.providers[f.provider]) throw new Error(`no provider "${f.provider}" (heartcode providers lists them)`)
|
|
1974
1962
|
Object.assign(cfg, { provider: f.provider, fixed: true })
|
|
@@ -1987,12 +1975,12 @@ async function main() {
|
|
|
1987
1975
|
saveConfig(cfg)
|
|
1988
1976
|
console.log(c.dim(`saved to ${CONFIG_FILE}`))
|
|
1989
1977
|
}
|
|
1990
|
-
const sub = ['
|
|
1978
|
+
const sub = ['models', 'providers', 'config', 'settings'].includes(positionals[0]) && positionals.length <= 2 ? positionals[0] : null
|
|
1991
1979
|
|
|
1992
1980
|
if (sub === 'settings') {
|
|
1993
|
-
const { url } = await startSettings({ cfg })
|
|
1994
|
-
console.log(`${c.brand('♥')} HeartCode settings: ${url}\n${c.dim('opened in your browser · Ctrl+C to stop')}`)
|
|
1995
|
-
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)
|
|
1996
1984
|
return new Promise(() => {}) // until Ctrl+C
|
|
1997
1985
|
}
|
|
1998
1986
|
|
|
@@ -2085,14 +2073,6 @@ async function main() {
|
|
|
2085
2073
|
app.worktree = wt
|
|
2086
2074
|
if (sub === 'providers') return app.listProviders(), ui.close()
|
|
2087
2075
|
if (sub === 'models') return await app.listModels(positionals[1] ?? '', { all: f.all, json: f.json }), ui.close()
|
|
2088
|
-
if (sub === 'probe') {
|
|
2089
|
-
cfg.force = true
|
|
2090
|
-
const s = await app.session()
|
|
2091
|
-
if (s) ui.print(describe(s.profile, s.strat))
|
|
2092
|
-
ui.close()
|
|
2093
|
-
process.exitCode = s ? 0 : 1
|
|
2094
|
-
return
|
|
2095
|
-
}
|
|
2096
2076
|
if (f['no-memory']) app.memory = null
|
|
2097
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
|
|
2098
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
|
package/prompts/agent.md
CHANGED
|
@@ -103,11 +103,6 @@ Reply now, without using tools: what did you do, and what is the result? If some
|
|
|
103
103
|
<!-- HeartCode's own answer when the model gives none at all. {{model}}: its name; {{changed}}: files changed in this message (may be empty). -->
|
|
104
104
|
{{model}} stopped without a final answer.{{#if changed}} Files changed in this message: {{changed}} (/rewind can undo them).{{/if}} Say "continue" to make it carry on.
|
|
105
105
|
|
|
106
|
-
## system-acknowledged
|
|
107
|
-
|
|
108
|
-
<!-- For models without a system role: the system prompt goes in as the first user message, and this is the model's reply to it. -->
|
|
109
|
-
Understood.
|
|
110
|
-
|
|
111
106
|
## instructions
|
|
112
107
|
|
|
113
108
|
<!-- Added to the system prompt when the user has instructions: HEARTCODE.md or AGENTS.md in the
|
package/src/agent.js
CHANGED
|
@@ -119,7 +119,7 @@ export class Session {
|
|
|
119
119
|
// is asked for again once; then the compaction fails (the conversation is trimmed instead).
|
|
120
120
|
const request = (extra) => prompt('compact/summarize', { conversation: cut(), focus }) + extra
|
|
121
121
|
const send = (extra) =>
|
|
122
|
-
client.chat({ messages:
|
|
122
|
+
client.chat({ messages: [{ role: 'system', content: prompt('compact/summarizer') }, { role: 'user', content: request(extra) }] }, { signal })
|
|
123
123
|
const ask = (extra = '') => send(extra)
|
|
124
124
|
let summary = notSummary((await ask()).content)
|
|
125
125
|
if (!summary) {
|
|
@@ -358,7 +358,7 @@ export class Session {
|
|
|
358
358
|
const room = Math.floor((strat.context * 0.6 * 3.5) / (strat.ratio ?? 1))
|
|
359
359
|
const text = conversation.length > room ? `[… the earliest part is cut]\n${conversation.slice(-room)}` : conversation
|
|
360
360
|
const request = prompt('compact/branch-summarize', { conversation: text, files: files.join(', ') })
|
|
361
|
-
const messages =
|
|
361
|
+
const messages = [{ role: 'system', content: prompt('compact/summarizer') }, { role: 'user', content: request }]
|
|
362
362
|
const summary = notSummary((await client.chat({ messages }, { signal })).content)
|
|
363
363
|
if (!summary) throw new Error('the model did not write a summary')
|
|
364
364
|
return summary
|
|
@@ -730,8 +730,8 @@ async function runNative(s, task, images, signal) {
|
|
|
730
730
|
// Unchanged, it stays the same text, so a provider's prompt cache still holds.
|
|
731
731
|
const sys = SYSTEM(s)
|
|
732
732
|
if (!s.messages) {
|
|
733
|
-
s.messages =
|
|
734
|
-
} else if (s.messages[0]?.content !== sys &&
|
|
733
|
+
s.messages = [{ role: 'system', content: sys }]
|
|
734
|
+
} else if (s.messages[0]?.content !== sys && s.messages[0]?.role === 'system') {
|
|
735
735
|
s.messages[0] = { ...s.messages[0], content: sys }
|
|
736
736
|
}
|
|
737
737
|
if (s.chat.branchNote && !s.isSub) {
|
|
@@ -859,15 +859,15 @@ async function runNative(s, task, images, signal) {
|
|
|
859
859
|
}
|
|
860
860
|
// the model answering can change mid-message (your model list): the system prompt follows it
|
|
861
861
|
const now = SYSTEM(s)
|
|
862
|
-
if (s.messages[0]?.content !== now &&
|
|
862
|
+
if (s.messages[0]?.content !== now && s.messages[0]?.role === 'system') s.messages[0] = { ...s.messages[0], content: now }
|
|
863
863
|
pairTools(s.messages)
|
|
864
864
|
ui.spinner('thinking')
|
|
865
865
|
const out = ui.response(client.model) // named: helpers think too (theirs are named in helperUI)
|
|
866
|
-
const stream = strat.
|
|
866
|
+
const stream = strat.stream
|
|
867
867
|
// A long tool call (a whole file) streams in silently: say what's being written.
|
|
868
868
|
const onToolDelta = (name, args) => ui.spinner(`${name === 'run_command' ? 'preparing a command' : `writing ${/"path"\s*:\s*"([^"]+)"/.exec(args)?.[1] ?? name}`} · ${args.length >= 1000 ? `${(args.length / 1000).toFixed(1)}k` : args.length} chars`)
|
|
869
869
|
// the prompts or HEARTCODE.md changed meanwhile (applySettings): the system prompt again, now
|
|
870
|
-
if (s.refreshSystem &&
|
|
870
|
+
if (s.refreshSystem && s.messages[0]?.role === 'system') s.messages[0] = { ...s.messages[0], content: SYSTEM(s) }
|
|
871
871
|
s.refreshSystem = false
|
|
872
872
|
let res
|
|
873
873
|
try {
|
|
@@ -1507,8 +1507,7 @@ export function contextReport(s) {
|
|
|
1507
1507
|
msgs.forEach((m, i) => {
|
|
1508
1508
|
const n = Math.round(estMessages([m]) * ratio)
|
|
1509
1509
|
const ago = msgs.length - 1 - i
|
|
1510
|
-
if (i === 0 &&
|
|
1511
|
-
if (i === 1 && s.strat?.mergeSystem && m.role === 'assistant') return void (parts.system += n)
|
|
1510
|
+
if (i === 0 && m.role === 'system') return void (parts.system += n)
|
|
1512
1511
|
if (m.role === 'tool') {
|
|
1513
1512
|
const old = typeof m.content === 'string' && /^\[older output/.test(m.content)
|
|
1514
1513
|
old ? (parts.pointers += n, cut++) : (parts.results += n, whole++)
|
package/src/capabilities.js
CHANGED
|
@@ -38,8 +38,8 @@ export function capabilities(cfg = {}) {
|
|
|
38
38
|
const npx = onPath('npx')
|
|
39
39
|
caps.push({
|
|
40
40
|
id: 'browser',
|
|
41
|
-
name: 'Browser
|
|
42
|
-
what: '
|
|
41
|
+
name: 'Browser',
|
|
42
|
+
what: 'The browser tools: the model opens a page in a real browser, uses it, reads the console and takes screenshots.',
|
|
43
43
|
ok: chrome && npx,
|
|
44
44
|
need: !npx ? 'Node.js' : !chrome ? 'Google Chrome' : '',
|
|
45
45
|
})
|
package/src/guided.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Guided mode, for models without (reliable) tool calls. HeartCode drives the
|
|
2
2
|
// task as a series of single questions; every answer has one trivial shape
|
|
3
3
|
// (a number, a path, or "the whole reply is code") and is checked against
|
|
4
|
-
// reality before use.
|
|
4
|
+
// reality before use.
|
|
5
5
|
import fs from 'node:fs'
|
|
6
6
|
import { log } from './log.js'
|
|
7
7
|
import { prompt, userInstructions } from './prompts.js'
|
|
@@ -39,7 +39,7 @@ export function nextActions(st) {
|
|
|
39
39
|
return [...new Set([...first, ...ACTIONS.map(([n]) => n)])].filter((n) => n !== 'delegate' || st.canDelegate)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
// A reply may be plain text or
|
|
42
|
+
// A reply may be plain text or JSON like {"path": "a.js"}.
|
|
43
43
|
export function answerText(reply) {
|
|
44
44
|
const t = String(reply).trim()
|
|
45
45
|
if (t.startsWith('{')) {
|
|
@@ -172,8 +172,7 @@ class Guided {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
async yesNo(question, fallback) {
|
|
175
|
-
const
|
|
176
|
-
const res = await this.query(prompt('guided/yes-no', { question }), { room: 20, schema, oneLine: true })
|
|
175
|
+
const res = await this.query(prompt('guided/yes-no', { question }), { room: 20, oneLine: true })
|
|
177
176
|
const m = /\b(yes|no)\b/i.exec(answerText(res.content))
|
|
178
177
|
return m ? m[1].toLowerCase() === 'yes' : fallback
|
|
179
178
|
}
|
|
@@ -229,24 +228,21 @@ class Guided {
|
|
|
229
228
|
return this.ask1(question, opts)
|
|
230
229
|
}
|
|
231
230
|
|
|
232
|
-
async ask1(question, { room = 32,
|
|
231
|
+
async ask1(question, { room = 32, oneLine, onToken, answer, skipKey } = {}, tries = 0) {
|
|
233
232
|
const { client, strat } = this.s
|
|
234
233
|
const think = strat.thinking ? 4096 : 0
|
|
235
234
|
const user = `${this.context(est(question) + room + think + tries * 600, skipKey)}\n\n${question}`
|
|
236
235
|
this.instructions ??= userInstructions(this.s.root)
|
|
237
236
|
const system = [prompt('guided/system'), this.instructions && prompt('agent/instructions', { instructions: this.instructions }), this.s.appendSystem].filter(Boolean).join('\n\n')
|
|
238
|
-
const messages =
|
|
239
|
-
|
|
240
|
-
:
|
|
241
|
-
|
|
242
|
-
{ role: 'user', content: user },
|
|
243
|
-
]
|
|
237
|
+
const messages = [
|
|
238
|
+
{ role: 'system', content: system },
|
|
239
|
+
{ role: 'user', content: user },
|
|
240
|
+
]
|
|
244
241
|
const out = this.ui.response()
|
|
245
242
|
if (answer) onToken = out.text
|
|
246
243
|
const stream = Boolean(strat.stream && (onToken || strat.thinking))
|
|
247
244
|
const body = { messages, temperature: 0, stream } // no max_tokens: the model decides how long
|
|
248
|
-
if (
|
|
249
|
-
else if (oneLine && strat.stop) body.stop = ['\n\n']
|
|
245
|
+
if (oneLine && strat.stop) body.stop = ['\n\n']
|
|
250
246
|
const res = await client.chat(body, { signal: this.signal, onToken, onReasoning: out.think })
|
|
251
247
|
if (!stream) out.think(res.reasoning)
|
|
252
248
|
if (answer && !stream) out.text(res.content)
|
|
@@ -331,9 +327,8 @@ class Guided {
|
|
|
331
327
|
const names = nextActions(this.st)
|
|
332
328
|
const menu = names.map((n, i) => `${i + 1}. ${n} - ${DESC[n]}`).join('\n')
|
|
333
329
|
let q = prompt('guided/next-action', { menu })
|
|
334
|
-
const schema = { type: 'object', properties: { choice: { type: 'integer', enum: names.map((_, i) => i + 1) } }, required: ['choice'], additionalProperties: false }
|
|
335
330
|
for (let i = 0; i < 2; i++) {
|
|
336
|
-
const res = await this.query(q, { room: 16,
|
|
331
|
+
const res = await this.query(q, { room: 16, oneLine: true })
|
|
337
332
|
const a = parsePick(res.content, names)
|
|
338
333
|
if (a) return a
|
|
339
334
|
q += '\n\n' + prompt('guided/next-action-retry', { reply: clip(res.content, 40), count: names.length })
|
|
@@ -346,11 +341,9 @@ class Guided {
|
|
|
346
341
|
this.note(null, 'note', prompt('guided/note-no-files'))
|
|
347
342
|
return null
|
|
348
343
|
}
|
|
349
|
-
const schema =
|
|
350
|
-
candidates.length <= 300 ? { type: 'object', properties: { path: { type: 'string', enum: candidates } }, required: ['path'], additionalProperties: false } : undefined
|
|
351
344
|
let q = prompt('guided/pick-file', { question })
|
|
352
345
|
for (let i = 0; i < 2; i++) {
|
|
353
|
-
const res = await this.query(q, { room: 60,
|
|
346
|
+
const res = await this.query(q, { room: 60, oneLine: true })
|
|
354
347
|
const said = answerText(res.content)
|
|
355
348
|
const f = matchFile(candidates, said)
|
|
356
349
|
if (f) return f
|
|
@@ -387,7 +380,7 @@ class Guided {
|
|
|
387
380
|
const old = fs.readFileSync(resolveIn(this.s.root, f), 'utf8')
|
|
388
381
|
this.ui.step('edit', f)
|
|
389
382
|
let next = null
|
|
390
|
-
|
|
383
|
+
next = await this.editBlocks(f, old)
|
|
391
384
|
if (next === null) next = await this.editRewrite(f, old)
|
|
392
385
|
if (next === null) return `edit:${f}`
|
|
393
386
|
const lost = lostNames(old, next, this.task)
|
|
@@ -443,11 +436,9 @@ class Guided {
|
|
|
443
436
|
win = focusWindow(lines, answerText(res.content), room) ?? [0, lines.length]
|
|
444
437
|
}
|
|
445
438
|
const view = clip(numberLines(lines.slice(win[0], win[1]), win[0] + 1), room)
|
|
446
|
-
const schema = { type: 'object', properties: { start: { type: 'integer' }, end: { type: 'integer' } }, required: ['start', 'end'], additionalProperties: false }
|
|
447
439
|
const part = win[0] > 0 || win[1] < lines.length ? ` (lines ${win[0] + 1}-${win[1]} of ${lines.length})` : ''
|
|
448
440
|
const rres = await this.query(prompt('guided/pick-range', { file: f, part, view: fence(view) }), {
|
|
449
441
|
room: 20,
|
|
450
|
-
schema,
|
|
451
442
|
oneLine: true,
|
|
452
443
|
skipKey,
|
|
453
444
|
})
|