heartcode 0.1.44 → 0.1.54
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 +243 -0
- package/README.md +147 -126
- package/SKILL.md +16 -18
- package/bin/heartcode.js +65 -62
- package/package.json +2 -2
- package/prompts/README.md +1 -1
- package/prompts/agent.md +249 -352
- package/prompts/compact.md +24 -45
- package/prompts/guided.md +43 -67
- package/prompts/tests.md +15 -0
- package/src/acp.js +1 -1
- package/src/agent.js +91 -81
- package/src/check.js +411 -0
- package/src/client.js +21 -37
- package/src/config.js +10 -1
- package/src/guided.js +13 -12
- package/src/headless.js +28 -2
- package/src/log.js +1 -1
- package/src/mcp.js +30 -21
- package/src/prompts.js +1 -0
- package/src/reset.js +1 -1
- package/src/sessions.js +56 -17
- package/src/settings.html +296 -154
- package/src/settings.js +108 -43
- package/src/skills.js +42 -7
- package/src/tabs.js +1 -1
- package/src/tools.js +40 -29
- package/src/ui.js +126 -30
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
|
|
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. |
|
|
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,14 +80,9 @@ 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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
at once, streaming, when it can (a greeting, a question), and otherwise hands the work to the
|
|
87
|
-
user's other models through its `agent` tool. It picks which one, knowing what each can do and
|
|
88
|
-
its places in the public LMArena rankings. It has no other tool: the models it picks do the work. If no
|
|
89
|
-
orchestrator answers, the list goes on to the next model. With "in your order" (the default), the list
|
|
90
|
-
is the user's order, as is.
|
|
83
|
+
`heartcode page <file|url>` checks a web page in a headless browser (errors, a blank page, a click
|
|
84
|
+
that breaks it, text too faint to read, content hidden at load, icons that don't draw: exit 0 when it
|
|
85
|
+
passes) and saves screenshots to `.heartcode/page-shots/`.
|
|
91
86
|
|
|
92
87
|
A run picks up settings the user changes meanwhile (`heart settings`, another HeartCode, or
|
|
93
88
|
`~/.heart` by hand) without being restarted, from its next request: the model order, prompts,
|
|
@@ -95,7 +90,7 @@ hooks, skills, MCP servers. `--temp` runs share one throwaway folder, so a chang
|
|
|
95
90
|
other `--temp` runs going on, never the real ones.
|
|
96
91
|
|
|
97
92
|
`heart` is installed by `npm start` in the HeartCode folder. `heartcode` is the same command.
|
|
98
|
-
Needs Node.js
|
|
93
|
+
Needs Node.js 22 or newer. No providers? See "Setting up a model" below.
|
|
99
94
|
|
|
100
95
|
## Run a task
|
|
101
96
|
|
|
@@ -125,7 +120,7 @@ goes to stderr. Logs never go to stdout.
|
|
|
125
120
|
|
|
126
121
|
## Continue the same conversation
|
|
127
122
|
|
|
128
|
-
Every run is saved as a session in
|
|
123
|
+
Every run is saved as a session in the project's `.heartcode/sessions/` (and logged, for the kinds of logs the user
|
|
129
124
|
switched on), as when the user works in HeartCode; `--temp` keeps nothing. Pass the `session_id`
|
|
130
125
|
from the last result:
|
|
131
126
|
|
|
@@ -166,7 +161,7 @@ heart -p -m auto "…" # the user's list, with its fa
|
|
|
166
161
|
heart -p -m groq/openai/gpt-oss-120b "…" # that provider and model alone, for this run
|
|
167
162
|
heart -p -m groq/openai/gpt-oss-120b --fallback-model openrouter/qwen/qwen3-coder "…" # and that one when it fails
|
|
168
163
|
heart -p --provider ollama -m qwen3-coder "…" # the same, written apart
|
|
169
|
-
heart -p --effort high "…" # how hard a thinking model thinks
|
|
164
|
+
heart -p --effort high "…" # how hard a thinking model thinks (low unless set)
|
|
170
165
|
```
|
|
171
166
|
|
|
172
167
|
What a model can do (tool calls, context size, thinking, images) comes from models.dev, at once;
|
|
@@ -174,11 +169,10 @@ nothing is sent to the model to find out. A model models.dev doesn't know works
|
|
|
174
169
|
assumptions, and the user can set it up on the settings page. Models that can't call tools still
|
|
175
170
|
work, in a slower guided mode.
|
|
176
171
|
|
|
177
|
-
The model in use knows the user's other models (what each can do
|
|
178
|
-
session, and with an orchestrator their ranks overall, for code, web apps and vision) and works with them through its `agent` tool: it asks a model that can for what it
|
|
172
|
+
The model in use knows the user's other models (in the user's order, with what each can do) and works with them through its `agent` tool: it asks a model that can for what it
|
|
179
173
|
can't do itself (a model that can't see asks one that can about a screenshot: "which tiles show a
|
|
180
174
|
chair?"), several at once when there are many images or parts, and a helper that fails is handed to
|
|
181
|
-
the next capable model until one does the job. A helper works until its job is done (no step
|
|
175
|
+
the next capable model in the user's order until one does the job. A helper works until its job is done (no step
|
|
182
176
|
limit; `--max-turns` applies to it too). Their tokens are in `usage`, and each model's in
|
|
183
177
|
`modelUsage`.
|
|
184
178
|
|
|
@@ -201,8 +195,7 @@ HEART_API_KEY=… heart -u https://api.groq.com/openai/v1 -m openai/gpt-oss-120b
|
|
|
201
195
|
A model server on this machine (Ollama on :11434, LM Studio on :1234, llama.cpp on :8080) is
|
|
202
196
|
found on its own. The user can also set everything up in a browser: `heart settings` (its link has
|
|
203
197
|
the machine's network address, so it opens from another device too, for HeartCode on a server), where
|
|
204
|
-
**Test
|
|
205
|
-
answers. A run that fails with a wrong key or an unknown model: ask the user to test it there.
|
|
198
|
+
**Test all** under *Your models* sends each model a short message to show it really answers, and how fast. A run that fails with a wrong key or an unknown model: ask the user to test it there.
|
|
206
199
|
|
|
207
200
|
## More context for the task
|
|
208
201
|
|
|
@@ -254,6 +247,11 @@ Stdout: one JSON event per line, `system`/`init` (its `tools` include the MCP se
|
|
|
254
247
|
call's `tool_use` is named as in Claude Code, `mcp__<server>__<tool>`, with the tool's own
|
|
255
248
|
arguments as `input`.
|
|
256
249
|
|
|
250
|
+
With `--include-partial-messages`, each reply also comes as it's written, as Claude Code sends it:
|
|
251
|
+
`stream_event` lines (`message_start`, `content_block_start`, `content_block_delta` with a
|
|
252
|
+
`thinking_delta` or `text_delta`, `content_block_stop`, `message_stop`), before its whole
|
|
253
|
+
`assistant` line. Helpers' replies come whole only (their `assistant` lines, with their parent).
|
|
254
|
+
|
|
257
255
|
A helper's steps (the `agent` tool: another of the user's models, or the same one, doing a job;
|
|
258
256
|
several can run at once) come as `assistant` and `user` lines too, as Claude Code sends a
|
|
259
257
|
subagent's: `parent_tool_use_id` is the id of the `agent` call they belong to (`null` for the main
|
|
@@ -264,7 +262,7 @@ fallback, the one that took over, not the one the run started with (the `init` l
|
|
|
264
262
|
`modelUsage` in the `result` has each model that answered.
|
|
265
263
|
|
|
266
264
|
Not in the stream: HeartCode's own prompts (the system prompt, its nudges), the review's verdict
|
|
267
|
-
and the wrap-up.
|
|
265
|
+
and the wrap-up. Helpers' work is in it: `agent` tool calls, with the helper's lines under them. Their tokens are in `usage` and
|
|
268
266
|
`modelUsage`. Retries and switches to another model go to stderr with `--verbose`.
|
|
269
267
|
|
|
270
268
|
## Don't
|
package/bin/heartcode.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import { parseArgs } from 'node:util'
|
|
4
|
-
import { Client } from '../src/client.js'
|
|
5
|
-
import { loadConfig, saveConfig, readJson, writeJson, providerName, CONFIG_FILE, HOME, TEMP, AUTO_MODEL, isAuto, parseModel, takeIn, whatOf, VERSION } from '../src/config.js'
|
|
4
|
+
import { Client, limitSaid } from '../src/client.js'
|
|
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
|
-
import { learnFromUsage, LIMIT_MS } from '../src/context.js'
|
|
7
|
+
import { learnFromUsage, LIMIT_MS, RATE_CAP_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
10
|
import { checkUpdate, installKind, UPDATE_COMMANDS, packageDir, whatsNew } from '../src/update.js'
|
|
@@ -57,7 +57,7 @@ ${c.bold('options')}
|
|
|
57
57
|
--api-key <key> API key for --base-url
|
|
58
58
|
-y, --yes do everything without asking (the default)
|
|
59
59
|
--ask ask before every edit and command, this run
|
|
60
|
-
--hide-thinking
|
|
60
|
+
--hide-thinking the model's thinking: only its last two lines while it thinks (the default; Alt+O shows all of it)
|
|
61
61
|
-C, --cwd <dir> project folder (default: current folder)
|
|
62
62
|
--temp keep nothing: a throwaway settings folder (your providers, model info,
|
|
63
63
|
prices and notes copied in), shared by the --temp runs going on at once
|
|
@@ -80,7 +80,6 @@ ${c.bold('headless')} (for other programs; flags and output as in Claude Code's
|
|
|
80
80
|
--skills-dir <dir> more skills (repeatable)
|
|
81
81
|
--allowedTools <list> only these tools (HeartCode's or Claude Code's names: Read, Edit, Bash…)
|
|
82
82
|
--disallowedTools <list> never these tools
|
|
83
|
-
--model-choice <order|fit> your models' order (#1, then the next), or fit: an orchestrator hands each task out
|
|
84
83
|
--permission-mode <m> all, commands, ask, plan (or bypassPermissions, acceptEdits, default);
|
|
85
84
|
--dangerously-skip-permissions = all. Nothing is asked: the rest is declined
|
|
86
85
|
--session-id <id> start (or continue) the session with this id
|
|
@@ -104,7 +103,7 @@ const SECTIONS = [
|
|
|
104
103
|
['/select_model', 'pick the model(s) for this session: one pins it, several rotate among them, auto = your whole list', true],
|
|
105
104
|
]],
|
|
106
105
|
['settings', [
|
|
107
|
-
['/toggle_thinking', "
|
|
106
|
+
['/toggle_thinking', "the model's thinking: its last two lines, or all of it (Alt+O)"],
|
|
108
107
|
['/voice', 'say your message (or Space in an empty box): it shows in the box as you speak, Enter sends it, Esc cancels'],
|
|
109
108
|
]],
|
|
110
109
|
['session', [
|
|
@@ -158,7 +157,7 @@ function keysHelp(keys = {}, mouse = false) {
|
|
|
158
157
|
const rows = [
|
|
159
158
|
['Space', 'voice: listens at once, Enter sends what you said (in an empty box)'],
|
|
160
159
|
['Enter', 'send · while it works, queue the message (commands like /help, /cost, /select_model run at once)'],
|
|
161
|
-
['Option
|
|
160
|
+
['Option+Enter or Shift+Enter', 'new line in the box'],
|
|
162
161
|
['Esc', 'stop the task (press twice to confirm)'],
|
|
163
162
|
['Esc Esc', 'rewind to an earlier message (at the prompt)'],
|
|
164
163
|
['Shift+Tab', 'change what runs without asking (permissions)'],
|
|
@@ -178,7 +177,7 @@ function keysHelp(keys = {}, mouse = false) {
|
|
|
178
177
|
[mouse ? 'Drag' : '', 'select and copy: the conversation, a dialog, the folder, the input, the status bar'],
|
|
179
178
|
[mouse ? 'Double-click' : '', 'copy the word under it (an address, a path, a model)'],
|
|
180
179
|
[mouse ? (process.platform === 'darwin' ? 'Option+drag' : 'Shift+drag') : '', "the terminal's own selection, past HeartCode's"],
|
|
181
|
-
[mouse ? '' : 'Mouse', 'the terminal\'s own: select and copy as usual (HeartCode takes the mouse
|
|
180
|
+
[mouse ? '' : 'Mouse', 'the terminal\'s own: select and copy as usual (switch "HeartCode takes the mouse" on in /settings → General for the wheel to scroll only the conversation)'],
|
|
182
181
|
].filter(([k]) => k)
|
|
183
182
|
return rows
|
|
184
183
|
}
|
|
@@ -194,7 +193,7 @@ const ALL_OFF = `${c.yellow('The providers of all your models are switched off.'
|
|
|
194
193
|
// Choices for commands that take one (also offered in the "/" menu).
|
|
195
194
|
const ARGS = {
|
|
196
195
|
export: [['md', 'Markdown'], ['html', 'a web page'], ['json', 'the whole session file']],
|
|
197
|
-
set_effort: [['default',
|
|
196
|
+
set_effort: [['default', 'low: a little thinking, shown as it comes'], ['low', 'quick, less thinking'], ['medium', 'balanced'], ['high', 'thinks the longest']],
|
|
198
197
|
}
|
|
199
198
|
|
|
200
199
|
|
|
@@ -224,7 +223,6 @@ class App {
|
|
|
224
223
|
this.memory = new Memory(root) // .heartcode/memory: notes linked with [[name]]
|
|
225
224
|
this.director = new Director(this) // the manage tool: skills, MCP servers and settings by asking
|
|
226
225
|
this.later = [] // setting changes that wait until the current message is done
|
|
227
|
-
this.failures = {} // "provider model" → failed requests this session (engine: onFail)
|
|
228
226
|
this.loadProjectModels() // the model(s) you last chose for this folder (.heartcode/models.json)
|
|
229
227
|
}
|
|
230
228
|
|
|
@@ -305,7 +303,7 @@ class App {
|
|
|
305
303
|
case 'effort':
|
|
306
304
|
if (!ARGS.set_effort.some(([o]) => o === v)) return bad('default, low, medium or high')
|
|
307
305
|
cfg.effort = v === 'default' ? undefined : v
|
|
308
|
-
if (this.s?.strat.thinking) this.s.client.effort = cfg
|
|
306
|
+
if (this.s?.strat.thinking) this.s.client.effort = effortOf(cfg)
|
|
309
307
|
return save(`effort: ${v}`)
|
|
310
308
|
case 'auto_compact':
|
|
311
309
|
case 'director':
|
|
@@ -327,7 +325,7 @@ class App {
|
|
|
327
325
|
}
|
|
328
326
|
|
|
329
327
|
// The model, its probe and strategy for a provider and model (probed once, then cached).
|
|
330
|
-
// quiet: for a helper
|
|
328
|
+
// quiet: for a helper: nothing printed about the model, the settings left alone.
|
|
331
329
|
async engine(provider, model, ui, signal, { quiet = false } = {}) {
|
|
332
330
|
const { cfg } = this
|
|
333
331
|
const client = this.client(provider, model)
|
|
@@ -336,17 +334,30 @@ class App {
|
|
|
336
334
|
client.price = () => price
|
|
337
335
|
client.onSpend = (u) => addUsage((this.chat.usage ??= {}), u, price)
|
|
338
336
|
client.onRetry = (err, ms, attempt, next) => ui.retrying(err, ms, attempt, next) // keep trying until Esc (also while probing)
|
|
339
|
-
//
|
|
340
|
-
// are tried in that order
|
|
337
|
+
// a failed request: what it says about the model's limits is learned
|
|
341
338
|
client.onFail = (e, t) => {
|
|
342
339
|
if (e.name === 'AbortError') return
|
|
343
|
-
|
|
344
|
-
|
|
340
|
+
// "too large" with the limit stated (Groq: "Limit 2000 … tokens per minute"): kept in its profile,
|
|
341
|
+
// so it isn't sent what it can't take
|
|
342
|
+
const said = limitSaid(e)
|
|
343
|
+
if (said) {
|
|
344
|
+
const cl = this.client(t.provider, t.model)
|
|
345
|
+
const p = loadProfile(cl) || profileFrom(cl, limitsOf(t.provider, cl.baseUrl, t.model))
|
|
346
|
+
if (said.rate) p.rateCap = { tokens: said.tokens, until: Date.now() + RATE_CAP_MS }
|
|
347
|
+
else Object.assign(p, { inputLimit: said.tokens, inputLimitAt: Date.now() })
|
|
348
|
+
writeJson(profilePath(cl), p)
|
|
349
|
+
log('context', `${k}: ${said.rate ? 'a per-minute cap' : 'a request limit'} of ${said.tokens} tokens, from its provider`)
|
|
350
|
+
}
|
|
345
351
|
}
|
|
346
352
|
// the model list (settings page): another model answered
|
|
353
|
+
// told once the reply that came is closed (it's known before the reply's last line ends: it'd go on
|
|
354
|
+
// that line): the agent says it then (announceSwitch), else right after
|
|
355
|
+
let switched = null
|
|
356
|
+
client.announceSwitch = () => switched && (ui.print(switched), (switched = null))
|
|
347
357
|
client.onSwitch = (t) => {
|
|
348
358
|
const i = client.rotation.list.indexOf(t)
|
|
349
|
-
|
|
359
|
+
switched = c.dim(`↻ ${t.provider} · ${t.model} answered${i ? ` (#${i + 1} in your model list)` : ' (#1 again)'}`)
|
|
360
|
+
setImmediate(client.announceSwitch)
|
|
350
361
|
}
|
|
351
362
|
if (cfg.maxRetries !== undefined) client.retryIf = (e, attempt) => attempt < cfg.maxRetries // headless: then give up
|
|
352
363
|
let profile = await getProfile(client, ui, quiet)
|
|
@@ -357,7 +368,7 @@ class App {
|
|
|
357
368
|
const apply = () => {
|
|
358
369
|
for (const k of Object.keys(strat)) delete strat[k]
|
|
359
370
|
Object.assign(strat, strategy(profile, cfg))
|
|
360
|
-
Object.assign(client, { tokenRatio: profile.tokenRatio ?? 1, knownGood: profile.largestAccepted ?? 0, can: strat, effort: strat.thinking ? cfg
|
|
371
|
+
Object.assign(client, { tokenRatio: profile.tokenRatio ?? 1, knownGood: profile.largestAccepted ?? 0, can: strat, effort: strat.thinking ? effortOf(cfg) : undefined })
|
|
361
372
|
for (const [q, at] of Object.entries(profile.quirks ?? {})) if (Date.now() - at < LIMIT_MS) client.quirks[q] = true
|
|
362
373
|
price = priceOf(client.provider, client.baseUrl, client.model)
|
|
363
374
|
if (this.s?.client === client) this.s.profile = profile // /model_info, the settings page
|
|
@@ -377,7 +388,9 @@ class App {
|
|
|
377
388
|
// to the window (a command can run for minutes). Nothing goes on with an old copy.
|
|
378
389
|
client.refresh = () => {
|
|
379
390
|
syncSettings()
|
|
380
|
-
|
|
391
|
+
const speed = speedOf(this.cfg) // the settings page's seconds (config.js)
|
|
392
|
+
client.startMs = 1000 * speed.replyStart // a reply must start within this, else the next model
|
|
393
|
+
client.idleMs = 1000 * speed.replyIdle // a reply that stops sending for this long: stalled
|
|
381
394
|
if (stampOf(profilePath(client)) !== stamp) client.onUse({ provider: client.provider, model: client.model })
|
|
382
395
|
}
|
|
383
396
|
// What this run learned about the model, onto its file as it is now: the rest (what you set up for
|
|
@@ -607,7 +620,7 @@ class App {
|
|
|
607
620
|
const mine = this.commands().slice(COMMANDS.length)
|
|
608
621
|
const sections = [...SECTIONS]
|
|
609
622
|
if (mine.length) sections.push(['your skills (type /skill:name)', mine])
|
|
610
|
-
sections.push(['keyboard', keysHelp(this.ui.keys, this.cfg?.mouse
|
|
623
|
+
sections.push(['keyboard', keysHelp(this.ui.keys, this.cfg?.mouse !== false)])
|
|
611
624
|
return helpText(sections)
|
|
612
625
|
}
|
|
613
626
|
|
|
@@ -678,7 +691,7 @@ class App {
|
|
|
678
691
|
const rotated = rot && rot.at > 0
|
|
679
692
|
const name = rotated ? c.yellow('↻ ' + now.model) : c.info(now.model)
|
|
680
693
|
const model =
|
|
681
|
-
count === 1 ? name : cfg.session ? `${name} ${c.faint(`(${count} chosen)`)}` : `${c.muted(
|
|
694
|
+
count === 1 ? name : cfg.session ? `${name} ${c.faint(`(${count} chosen)`)}` : `${c.muted('auto')} ${c.faint('(')}${name}${c.faint(')')} ${c.faint(`(${count})`)}`
|
|
682
695
|
const key = `${now.provider}/${now.model}`
|
|
683
696
|
if (this.profileKey !== key) [this.profileKey, this.profile] = [key, this.s?.profile ?? loadProfile(this.client(now.provider, now.model))]
|
|
684
697
|
const profile = this.s?.profile ?? this.profile
|
|
@@ -688,7 +701,7 @@ class App {
|
|
|
688
701
|
provider: `${c.brand('●')} ${c.muted(now.provider)} ${c.faint(`(${on})`)}`,
|
|
689
702
|
model,
|
|
690
703
|
mode: strat ? c.muted(strat.actions === 'tools' ? 'tools' : 'guided') : c.dim('not loaded yet'),
|
|
691
|
-
thinking: strat?.thinking ? c.think(`thinking
|
|
704
|
+
thinking: strat?.thinking ? c.think(`thinking · ${effortOf(cfg)}`) + (ui.showThinking ? c.faint(' (all)') : '') : null,
|
|
692
705
|
images: strat?.vision ? c.muted('images') : null,
|
|
693
706
|
ctx: null,
|
|
694
707
|
tps: null,
|
|
@@ -777,8 +790,6 @@ class App {
|
|
|
777
790
|
Object.assign(this.s, { noFormat: cfg.format === false, noLsp: cfg.lsp === false })
|
|
778
791
|
Object.assign(this.s, { mcp: this.mcp, memory: this.memory, skills: this.skills, director: this.director })
|
|
779
792
|
this.s.team = () => this.team() // your other models: a job this one can't do goes to one of them
|
|
780
|
-
this.s.fitMode = () => fitMode(this.cfg) // an orchestrator hands each message's work out, not your list's order
|
|
781
|
-
this.s.orchestrators = () => this.orchestrators()
|
|
782
793
|
this.s.engineFor = (t) => this.engine(t.provider, t.model, ui, undefined, { quiet: true })
|
|
783
794
|
// A model's context window, read from its saved profile (no probe, no network): so the agent can
|
|
784
795
|
// see, before compacting, whether another model in the list has room for the whole conversation.
|
|
@@ -791,7 +802,6 @@ class App {
|
|
|
791
802
|
return 0
|
|
792
803
|
}
|
|
793
804
|
}
|
|
794
|
-
this.s.failures = this.failures
|
|
795
805
|
if (this.allowTools?.length) this.s.allowTools = toolNames(this.allowTools) // headless --allowedTools
|
|
796
806
|
if (this.denyTools?.length) this.s.denyTools = toolNames(this.denyTools)
|
|
797
807
|
if (this.cfg.maxTurns) this.s.maxTurns = this.cfg.maxTurns
|
|
@@ -808,7 +818,6 @@ class App {
|
|
|
808
818
|
.filter((t) => cfg.providers[t.provider] && t.model && !seen.has(`${t.provider}/${t.model}`) && seen.add(`${t.provider}/${t.model}`))
|
|
809
819
|
.map((t) => ({ ...t, baseUrl: cfg.providers[t.provider].baseUrl, apiKey: cfg.providers[t.provider].apiKey }))
|
|
810
820
|
this.s?.client.setRotation(list, cfg.rotation ?? {})
|
|
811
|
-
if (fitMode(cfg)) this.s?.client.orderBy(this.orchestrators().map((t) => `${t.provider} ${t.model}`)) // the first orchestrator answers first (and the status bar shows it)
|
|
812
821
|
}
|
|
813
822
|
|
|
814
823
|
async use(name, model) {
|
|
@@ -819,27 +828,17 @@ class App {
|
|
|
819
828
|
await this.session()
|
|
820
829
|
}
|
|
821
830
|
|
|
822
|
-
// Your other models (not the one in use) and what each can do, from its saved
|
|
823
|
-
// models.dev: nothing is sent to them to find out.
|
|
831
|
+
// Your other models (not the one in use), in your order, and what each can do, from its saved
|
|
832
|
+
// profile or models.dev: nothing is sent to them to find out.
|
|
824
833
|
team() {
|
|
825
834
|
// helpers use this session's models (the set you chose, else your list), minus the one in use —
|
|
826
|
-
// so a pinned single model gives no team, and a chosen set keeps helpers within it
|
|
827
|
-
// orchestrates: minus the orchestrators too (they only hand work out)
|
|
835
|
+
// so a pinned single model gives no team, and a chosen set keeps helpers within it
|
|
828
836
|
const now = this.s?.client.rotation?.list[this.s.client.rotation.at] ?? this.sessionModels()[0]
|
|
829
|
-
const lead = this.s?.orchestrating ? this.orchestrators() : []
|
|
830
837
|
return this.sessionModels()
|
|
831
|
-
.filter((t) => !
|
|
838
|
+
.filter((t) => !(t.provider === now?.provider && t.model === now?.model))
|
|
832
839
|
.map((t) => ({ ...t, ...this.abilities(t) }))
|
|
833
840
|
}
|
|
834
841
|
|
|
835
|
-
// The models that orchestrate (Pick: "an orchestrator hands it out"): those picked on Your models
|
|
836
|
-
// that are in this session's set and call tools; none picked: your first that calls tools.
|
|
837
|
-
orchestrators() {
|
|
838
|
-
const mine = this.sessionModels().filter((t) => this.abilities(t).tools)
|
|
839
|
-
const picked = mine.filter((t) => (this.cfg.orchestrators ?? []).some((o) => o.provider === t.provider && o.model === t.model))
|
|
840
|
-
return picked.length ? picked : mine.slice(0, 1)
|
|
841
|
-
}
|
|
842
|
-
|
|
843
842
|
// What a model can do, from its saved profile or models.dev (guessed: neither knows it).
|
|
844
843
|
abilities(t) {
|
|
845
844
|
const cl = this.client(t.provider, t.model)
|
|
@@ -869,7 +868,7 @@ class App {
|
|
|
869
868
|
const rot = this.s?.client.rotation
|
|
870
869
|
if (rot) return rot.list[rot.at]
|
|
871
870
|
if (this.s) return { provider: this.s.client.provider, model: this.s.client.model }
|
|
872
|
-
return
|
|
871
|
+
return this.sessionModels()[0] ?? null
|
|
873
872
|
}
|
|
874
873
|
|
|
875
874
|
// your list has models, but the providers of all of them are switched off
|
|
@@ -1145,7 +1144,7 @@ function saveTabs(tabs) {
|
|
|
1145
1144
|
// last session here.
|
|
1146
1145
|
async function continueTabs(app, saved) {
|
|
1147
1146
|
const { ui, tabs } = app
|
|
1148
|
-
let open = (saved?.tabs ?? []).map((t, i) => ({ ...t, i, chat: loadChat(t.chat) })).filter((t) => t.chat?.turns?.length && (!t.worktree || fs.existsSync(t.chat.root)))
|
|
1147
|
+
let open = (saved?.tabs ?? []).map((t, i) => ({ ...t, i, chat: loadChat(t.chat, app.root) })).filter((t) => t.chat?.turns?.length && (!t.worktree || fs.existsSync(t.chat.root)))
|
|
1149
1148
|
if (!saved) open = listChats(app.root).filter((c) => c.turns?.length).slice(0, 1).map((chat) => ({ chat, worktree: null }))
|
|
1150
1149
|
if (!open.length) return
|
|
1151
1150
|
const many = open.length > 1
|
|
@@ -1187,9 +1186,9 @@ let settingsPage = null
|
|
|
1187
1186
|
|
|
1188
1187
|
// The browser, with a page. Windows: its URL handler (cmd's start mangles a URL whose arguments
|
|
1189
1188
|
// it reads as its own, and wants a quoted empty title first).
|
|
1190
|
-
//
|
|
1191
|
-
|
|
1192
|
-
const
|
|
1189
|
+
// The thinking effort asked of a model that thinks: yours, or low when you haven't chosen (many think
|
|
1190
|
+
// only when asked: then they think a little, and you see it)
|
|
1191
|
+
const effortOf = (cfg) => cfg.effort ?? 'low'
|
|
1193
1192
|
|
|
1194
1193
|
function openBrowser(url) {
|
|
1195
1194
|
if (process.env.HEART_NO_BROWSER) return
|
|
@@ -1211,7 +1210,7 @@ function applySettings(apps, cfg, what) {
|
|
|
1211
1210
|
const { ui } = app
|
|
1212
1211
|
const busy = Boolean(ui.busySince || app.working)
|
|
1213
1212
|
const now = (fn) => (busy ? app.later.push(fn) : fn())
|
|
1214
|
-
if (app.cfg !== cfg) for (const k of ['providers', 'provider', 'model', 'effort', 'theme', 'context', 'autoCompact', 'director', 'format', 'lsp', 'voice', 'rotation', 'statusBar'
|
|
1213
|
+
if (app.cfg !== cfg) for (const k of ['providers', 'provider', 'model', 'effort', 'theme', 'context', 'autoCompact', 'director', 'format', 'lsp', 'voice', 'rotation', 'statusBar']) app.cfg[k] = cfg[k]
|
|
1215
1214
|
// a model pinned in this CLI (/select_model) is a session choice: a model/order change on the
|
|
1216
1215
|
// settings page leaves it alone (only /select_model auto here returns it to the list)
|
|
1217
1216
|
if (what === 'model' && !app.cfg.session) {
|
|
@@ -1219,8 +1218,8 @@ function applySettings(apps, cfg, what) {
|
|
|
1219
1218
|
if (app.s && !(cfg.providers[cfg.provider] && cfg.model)) now(() => ((app.s = null), ui.print(c.dim('settings: no model chosen'))))
|
|
1220
1219
|
else if (app.s && !app.myModels().length) now(() => ((app.s = null), ui.print(c.dim('settings: the providers of all your models are switched off'))))
|
|
1221
1220
|
}
|
|
1222
|
-
// your model list: into the running session now, its next request goes to the new #1
|
|
1223
|
-
if (['model', 'setting:rotation'
|
|
1221
|
+
// your model list: into the running session now, its next request goes to the new #1
|
|
1222
|
+
if (['model', 'setting:rotation'].includes(what) && !app.cfg.session && app.s && cfg.providers[cfg.provider] && cfg.model) {
|
|
1224
1223
|
const was = `${app.s.client.provider} · ${app.s.client.model}`
|
|
1225
1224
|
app.useRotation()
|
|
1226
1225
|
const is = `${app.s.client.provider} · ${app.s.client.model}`
|
|
@@ -1228,8 +1227,9 @@ function applySettings(apps, cfg, what) {
|
|
|
1228
1227
|
}
|
|
1229
1228
|
if (what === 'provider') app.lists = {} // its list switched on or off, a model added by name
|
|
1230
1229
|
if (what === 'setting:permissions') ui.setPermission(cfg.permissions)
|
|
1230
|
+
if (what === 'setting:mouse') ui.setMouse(cfg.mouse !== false)
|
|
1231
1231
|
if (what === 'setting:statusBar') ui.render?.() // the status bar's layout changed: redraw it now
|
|
1232
|
-
if (what === 'setting:effort' && app.s?.strat.thinking) app.s.client.effort = cfg
|
|
1232
|
+
if (what === 'setting:effort' && app.s?.strat.thinking) app.s.client.effort = effortOf(cfg)
|
|
1233
1233
|
if (what === 'setting:autoCompact' && app.s) app.s.autoCompact = cfg.autoCompact !== false
|
|
1234
1234
|
if (what === 'setting:format' && app.s) app.s.noFormat = cfg.format === false
|
|
1235
1235
|
if (what === 'setting:lsp' && app.s) app.s.noLsp = cfg.lsp === false
|
|
@@ -1693,7 +1693,9 @@ async function slash(app, line, working = false) {
|
|
|
1693
1693
|
}
|
|
1694
1694
|
case 'toggle_thinking':
|
|
1695
1695
|
ui.showThinking = !ui.showThinking
|
|
1696
|
-
|
|
1696
|
+
ui.print(c.dim(ui.showThinking ? 'thinking: all of it, as it comes (Alt+O: its last two lines)' : 'thinking: its last two lines while it thinks (Alt+O: all of it)'))
|
|
1697
|
+
if (ui.showThinking && !ui.thinkTail) ui.showLastThought() // the one just over: all of it now
|
|
1698
|
+
return
|
|
1697
1699
|
}
|
|
1698
1700
|
if (!['model_info', 'compact'].includes(cmd)) {
|
|
1699
1701
|
app.skills = loadSkills(app.root) // edits to skill files apply right away
|
|
@@ -1748,7 +1750,7 @@ async function runTask(app, task, ctl) {
|
|
|
1748
1750
|
|
|
1749
1751
|
async function repl(app, f = {}) {
|
|
1750
1752
|
const { ui, cfg } = app
|
|
1751
|
-
ui.fullscreen({ mouse: cfg.mouse
|
|
1753
|
+
ui.fullscreen({ mouse: cfg.mouse !== false }) // HeartCode's wheel and selection ("mouse": false: the terminal's own: then its wheel scrolls the whole screen)
|
|
1752
1754
|
ui.onDoubleEscape = () => '/rewind'
|
|
1753
1755
|
let ctl = null
|
|
1754
1756
|
ui.onEscape = () => ctl?.abort()
|
|
@@ -1816,7 +1818,7 @@ async function repl(app, f = {}) {
|
|
|
1816
1818
|
return ui.clearInput()
|
|
1817
1819
|
}
|
|
1818
1820
|
if (again) return quit() // the second within 2s (also when the first stopped the work)
|
|
1819
|
-
ui.notice(others() ? `Press Ctrl+C again to quit HeartCode (all ${others() + 1} tabs;
|
|
1821
|
+
ui.notice(others() ? `Press Ctrl+C again to quit HeartCode (all ${others() + 1} tabs; Alt+W closes just this one)` : 'Press Ctrl+C again to quit', 2000)
|
|
1820
1822
|
}
|
|
1821
1823
|
// Pinned to the top of the screen; /clear_chat and scrolling leave it alone.
|
|
1822
1824
|
const home = process.env.HOME
|
|
@@ -1834,7 +1836,7 @@ async function repl(app, f = {}) {
|
|
|
1834
1836
|
if (last) await app.resume(last)
|
|
1835
1837
|
else ui.print(c.dim('No earlier session in this folder to continue.'))
|
|
1836
1838
|
}
|
|
1837
|
-
if (f['resume-id']) await app.resume(loadChat(f['resume-id']))
|
|
1839
|
+
if (f['resume-id']) await app.resume(loadChat(f['resume-id'], app.root))
|
|
1838
1840
|
else if (f.resume) await app.resume()
|
|
1839
1841
|
if (f.model) useModel(app, f.model) // a continued tab's own model
|
|
1840
1842
|
// models this folder picked earlier (/select_model): said, with the way back to your whole list
|
|
@@ -1900,6 +1902,10 @@ async function repl(app, f = {}) {
|
|
|
1900
1902
|
}
|
|
1901
1903
|
|
|
1902
1904
|
async function main() {
|
|
1905
|
+
// "heartcode page <file|url>": a web page checked in a browser (src/check.js). Only that: a prompt
|
|
1906
|
+
// that starts with "page" ("page fix the footer") is a prompt
|
|
1907
|
+
const target = process.argv[3]
|
|
1908
|
+
if (process.argv[2] === 'page' && process.argv.length === 4 && (/^https?:\/\//.test(target) || fs.existsSync(target))) return (process.exitCode = await (await import('../src/check.js')).pageCommand(target))
|
|
1903
1909
|
// "--resume <id>" (as in Claude Code) vs a bare "--resume" (pick one): an id follows it
|
|
1904
1910
|
const argv = process.argv.slice(2)
|
|
1905
1911
|
const print = argv.includes('-p') || argv.includes('--print') // headless: an id after --resume is always an id
|
|
@@ -1939,7 +1945,6 @@ async function main() {
|
|
|
1939
1945
|
disallowedTools: { type: 'string', multiple: true },
|
|
1940
1946
|
'disallowed-tools': { type: 'string', multiple: true },
|
|
1941
1947
|
'permission-mode': { type: 'string' },
|
|
1942
|
-
'model-choice': { type: 'string' },
|
|
1943
1948
|
'dangerously-skip-permissions': { type: 'boolean' },
|
|
1944
1949
|
'session-id': { type: 'string' },
|
|
1945
1950
|
effort: { type: 'string' },
|
|
@@ -1949,10 +1954,10 @@ async function main() {
|
|
|
1949
1954
|
'max-turns': { type: 'string' },
|
|
1950
1955
|
all: { type: 'boolean' }, // heart models --all
|
|
1951
1956
|
json: { type: 'boolean' }, // heart models --json
|
|
1957
|
+
'include-partial-messages': { type: 'boolean' }, // stream-json: the replies as they come (thinking too)
|
|
1952
1958
|
// accepted for drop-in use where Claude Code is expected; nothing to do in HeartCode
|
|
1953
1959
|
autocompact: { type: 'string' },
|
|
1954
1960
|
'exclude-dynamic-system-prompt-sections': { type: 'boolean' },
|
|
1955
|
-
'include-partial-messages': { type: 'boolean' },
|
|
1956
1961
|
help: { type: 'boolean', short: 'h' },
|
|
1957
1962
|
version: { type: 'boolean', short: 'v' },
|
|
1958
1963
|
},
|
|
@@ -1962,8 +1967,6 @@ async function main() {
|
|
|
1962
1967
|
if (f.context && !(Number(f.context) > 0)) throw new Error('--context must be a number of tokens')
|
|
1963
1968
|
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`)
|
|
1964
1969
|
if (f['permission-mode'] && !PERMISSION_MODES[f['permission-mode']]) throw new Error(`--permission-mode must be one of ${Object.keys(PERMISSION_MODES).join(', ')}`)
|
|
1965
|
-
if (f['model-choice'] && !['order', 'fit'].includes(f['model-choice'])) throw new Error('--model-choice must be order or fit')
|
|
1966
|
-
modelChoiceFlag = f['model-choice']
|
|
1967
1970
|
|
|
1968
1971
|
const cfg = loadConfig({ baseUrl: f['base-url'], model: f.model, apiKey: f['api-key'], context: f.context })
|
|
1969
1972
|
setTheme(cfg.theme)
|
|
@@ -2032,7 +2035,7 @@ async function main() {
|
|
|
2032
2035
|
saveConfig(cfg)
|
|
2033
2036
|
}
|
|
2034
2037
|
}
|
|
2035
|
-
ui.showThinking =
|
|
2038
|
+
ui.showThinking = false // the thinking's last two lines while it thinks; Alt+O shows all of it (--hide-thinking: the same)
|
|
2036
2039
|
const app = new App(cfg, ui, root)
|
|
2037
2040
|
usePromptsFrom(app.root) // its .heartcode/prompts override the built-in sections
|
|
2038
2041
|
ui.suggest = (line, cursor) => app.suggest(line, cursor)
|
|
@@ -2049,7 +2052,7 @@ async function main() {
|
|
|
2049
2052
|
}
|
|
2050
2053
|
// The full screen: in tabs (the first one is this folder; /tab and Alt+T open more).
|
|
2051
2054
|
if (!headless && !sub && !positionals.length && process.stdin.isTTY && process.stdout.isTTY) {
|
|
2052
|
-
if (f['resume-id'] && !loadChat(f['resume-id'])) throw new Error(`no session ${f['resume-id']}`)
|
|
2055
|
+
if (f['resume-id'] && !loadChat(f['resume-id'], root)) throw new Error(`no session ${f['resume-id']}`)
|
|
2053
2056
|
const saved = readJson(TABS_FILE, {})[root] // before this run's first tab replaces it
|
|
2054
2057
|
const asked = f.continue || f.resume || f['resume-id'] || f['session-id'] // a session was chosen already
|
|
2055
2058
|
const tabs = new Tabs((tab, o) => {
|
|
@@ -2059,7 +2062,7 @@ async function main() {
|
|
|
2059
2062
|
Object.assign(app, { tabs, tab, worktree: o.wt ?? null })
|
|
2060
2063
|
if (o.first) {
|
|
2061
2064
|
if (f['no-memory']) app.memory = null
|
|
2062
|
-
if (f['session-id']) app.setChat(loadChat(f['session-id']) ?? { ...newChat(app.root), id: f['session-id'] })
|
|
2065
|
+
if (f['session-id']) app.setChat(loadChat(f['session-id'], app.root) ?? { ...newChat(app.root), id: f['session-id'] })
|
|
2063
2066
|
}
|
|
2064
2067
|
return (async () => {
|
|
2065
2068
|
await repl(app, o.first ? { ...f, onStart: !asked && ((a) => continueTabs(a, saved)) } : o.chat ? { 'resume-id': o.chat.id, model: o.model } : {})
|
|
@@ -2087,14 +2090,14 @@ async function main() {
|
|
|
2087
2090
|
if (sub === 'providers') return app.listProviders(), ui.close()
|
|
2088
2091
|
if (sub === 'models') return await app.listModels(positionals[1] ?? '', { all: f.all, json: f.json }), ui.close()
|
|
2089
2092
|
if (f['no-memory']) app.memory = null
|
|
2090
|
-
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
|
|
2093
|
+
const chat = f['resume-id'] ? loadChat(f['resume-id'], app.root) : f.continue && headless ? listChats(app.root)[0] : f['session-id'] ? (loadChat(f['session-id'], app.root) ?? { ...newChat(app.root), id: f['session-id'] }) : null
|
|
2091
2094
|
if (f['resume-id'] && !chat) throw new Error(`no session ${f['resume-id']}`)
|
|
2092
2095
|
if (chat && (headless || !f['resume-id'])) app.setChat(chat) // interactive: resumed below, with its transcript
|
|
2093
2096
|
if (headless || positionals.length) watchSettings(() => [app], cfg) // an app's run takes the settings page's changes too
|
|
2094
2097
|
if (headless) {
|
|
2095
2098
|
app.allowTools = [...(f.allowedTools ?? []), ...(f['allowed-tools'] ?? [])]
|
|
2096
2099
|
app.denyTools = [...(f.disallowedTools ?? []), ...(f['disallowed-tools'] ?? [])]
|
|
2097
|
-
const code = await runHeadless(app, { prompt: positionals.join(' '), input: f['input-format'], output: f['output-format'], appendSystem: f['append-system-prompt'] })
|
|
2100
|
+
const code = await runHeadless(app, { prompt: positionals.join(' '), input: f['input-format'], output: f['output-format'], appendSystem: f['append-system-prompt'], partial: f['include-partial-messages'] })
|
|
2098
2101
|
if (wt && worktreeState(wt).empty) removeWorktree(wt) // else kept, for the caller to merge (its path is in the log)
|
|
2099
2102
|
process.exit(code) // MCP servers are stopped by the exit hooks
|
|
2100
2103
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "heartcode",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.54",
|
|
4
4
|
"description": "A coding CLI for any local or OpenAI-compatible model, including small models without tool calling.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"heartcode": "bin/heart.js"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
37
|
+
"node": ">=22"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"start": "node scripts/install.js"
|
package/prompts/README.md
CHANGED