heartcode 0.1.42 → 0.1.44

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 CHANGED
@@ -2,6 +2,28 @@
2
2
 
3
3
  What changed in each version of HeartCode, newest first.
4
4
 
5
+ ## 0.1.44 (2026-11-03)
6
+
7
+ - **Orchestrators first**: with Pick on "an orchestrator hands it out", the model shown (status bar,
8
+ headless `init`) is the first orchestrator, the one that answers first. With several, they go in
9
+ your list's order. Your models lists them at the top. Changing Pick or the orchestrators reaches a
10
+ running HeartCode at once.
11
+ - **Tooltips at once**: every tooltip on the settings page shows the moment you point at it (or tab
12
+ to it), in the page's own style, not the browser's slow one. A **?** beside Mark as orchestrator(s)
13
+ says what it does.
14
+ - A headless run that started on another provider's model named the wrong provider in its `init` line.
15
+
16
+ ## 0.1.43 (2026-11-03)
17
+
18
+ - **An orchestrator in place of best fit**: with Pick on "an orchestrator hands it out", each
19
+ message starts on a model you mark as an orchestrator (a quick, cheap one is enough). It answers
20
+ at once, streaming, when it can ("hi" needs no other model), and otherwise hands the work to
21
+ whichever of your other models it thinks suits it best. It sees what each one can do and its places in LMArena's
22
+ rankings. It only hands work out: its only tools are handing off and asking you. On Your models,
23
+ select models and press Mark as orchestrator(s); click a model's "orchestrator ✕" tag to unmark it.
24
+ None marked: your first model that calls tools. The extra request per message that named a task's
25
+ skills is gone, and nothing assumes a task is about code.
26
+
5
27
  ## 0.1.42 (2026-11-03)
6
28
 
7
29
  - **Your "no, do this instead" reaches the model as you**: what you type when you decline a command,
package/README.md CHANGED
@@ -59,10 +59,11 @@ tried did what I needed:
59
59
  - **Tells you when a newer version is out** (a check with npm each time it starts, 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 "Pick" set to "the best for each task", each message's
63
- lead and code reviewer are your models ranked on the skills that task needs (web
64
- pages, code, images…) by LMArena's public rankings, fetched once a week. Your models shows each
65
- one's Coding, Web apps and Vision rank.
62
+ - **An orchestrator that hands work out**: with "Pick" set to "an orchestrator hands it out",
63
+ each message starts on a model you choose for that (a quick, cheap one is enough). It answers
64
+ at once when it can ("hi" needs no other model), and otherwise hands the work to whichever of
65
+ your models it thinks suits it. It knows what each one can do and where it stands in LMArena's
66
+ public rankings. Your models shows each model's Coding, Web apps and Vision scores.
66
67
  - **Works with discipline by default**: its rules (from Karpathy's guidelines, Grill Me,
67
68
  Superpowers, Ponytail and Caveman) have it ask before building, find a bug's root cause first,
68
69
  write the least code that works, change only what the task needs, prove it before saying done,
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 (with the user's "best fit" setting: their models ranked for each task, below). 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 orchestrator setting: an orchestrator model first, 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,12 +80,14 @@ 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.
83
+ **Orchestrator** (the user's setting "Pick: an orchestrator hands it out", on Your models in
84
+ `heart settings`; `--model-choice fit` for one run): with `auto`, each message starts on one of the
85
+ models the user chose as orchestrators (none chosen: their first that calls tools). It answers
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.
89
91
 
90
92
  A run picks up settings the user changes meanwhile (`heart settings`, another HeartCode, or
91
93
  `~/.heart` by hand) without being restarted, from its next request: the model order, prompts,
@@ -173,7 +175,7 @@ assumptions, and the user can set it up on the settings page. Models that can't
173
175
  work, in a slower guided mode.
174
176
 
175
177
  The model in use knows the user's other models (what each can do, how often it failed this
176
- 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
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
177
179
  can't do itself (a model that can't see asks one that can about a screenshot: "which tiles show a
178
180
  chair?"), several at once when there are many images or parts, and a helper that fails is handed to
179
181
  the next capable model until one does the job. A helper works until its job is done (no step
@@ -261,8 +263,8 @@ Every `assistant` line's `message.model` is the model that wrote it (`provider/m
261
263
  fallback, the one that took over, not the one the run started with (the `init` line's `model`).
262
264
  `modelUsage` in the `result` has each model that answered.
263
265
 
264
- Not in the stream: HeartCode's own prompts (the system prompt, its nudges), the skill-picking
265
- request of best fit, the review's verdict and the wrap-up. Their tokens are in `usage` and
266
+ Not in the stream: HeartCode's own prompts (the system prompt, its nudges), the review's verdict
267
+ and the wrap-up. An orchestrator's handoffs are in it: `agent` tool calls, with the helper's lines under them. Their tokens are in `usage` and
266
268
  `modelUsage`. Retries and switches to another model go to stderr with `--verbose`.
267
269
 
268
270
  ## Don't
package/bin/heartcode.js CHANGED
@@ -80,7 +80,7 @@ ${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 the best fit for each task
83
+ --model-choice <order|fit> your models' order (#1, then the next), or fit: an orchestrator hands each task out
84
84
  --permission-mode <m> all, commands, ask, plan (or bypassPermissions, acceptEdits, default);
85
85
  --dangerously-skip-permissions = all. Nothing is asked: the rest is declined
86
86
  --session-id <id> start (or continue) the session with this id
@@ -678,7 +678,7 @@ class App {
678
678
  const rotated = rot && rot.at > 0
679
679
  const name = rotated ? c.yellow('↻ ' + now.model) : c.info(now.model)
680
680
  const model =
681
- 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})`)}`
681
+ count === 1 ? name : cfg.session ? `${name} ${c.faint(`(${count} chosen)`)}` : `${c.muted(fitMode(cfg) ? 'orchestrated' : 'auto')} ${c.faint('(')}${name}${c.faint(')')} ${c.faint(`(${count})`)}`
682
682
  const key = `${now.provider}/${now.model}`
683
683
  if (this.profileKey !== key) [this.profileKey, this.profile] = [key, this.s?.profile ?? loadProfile(this.client(now.provider, now.model))]
684
684
  const profile = this.s?.profile ?? this.profile
@@ -777,8 +777,8 @@ class App {
777
777
  Object.assign(this.s, { noFormat: cfg.format === false, noLsp: cfg.lsp === false })
778
778
  Object.assign(this.s, { mcp: this.mcp, memory: this.memory, skills: this.skills, director: this.director })
779
779
  this.s.team = () => this.team() // your other models: a job this one can't do goes to one of them
780
- this.s.allModels = () => this.sessionModels().map((t) => ({ ...t, ...this.abilities(t) })) // all of them, for a best-fit pick
781
- this.s.fitMode = () => fitMode(this.cfg) // models picked by strengths per message, not by the list's order
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
782
  this.s.engineFor = (t) => this.engine(t.provider, t.model, ui, undefined, { quiet: true })
783
783
  // A model's context window, read from its saved profile (no probe, no network): so the agent can
784
784
  // see, before compacting, whether another model in the list has room for the whole conversation.
@@ -808,6 +808,7 @@ class App {
808
808
  .filter((t) => cfg.providers[t.provider] && t.model && !seen.has(`${t.provider}/${t.model}`) && seen.add(`${t.provider}/${t.model}`))
809
809
  .map((t) => ({ ...t, baseUrl: cfg.providers[t.provider].baseUrl, apiKey: cfg.providers[t.provider].apiKey }))
810
810
  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)
811
812
  }
812
813
 
813
814
  async use(name, model) {
@@ -822,13 +823,23 @@ class App {
822
823
  // models.dev: nothing is sent to them to find out.
823
824
  team() {
824
825
  // helpers use this session's models (the set you chose, else your list), minus the one in use —
825
- // so a pinned single model gives no team, and a chosen set keeps helpers within it
826
+ // so a pinned single model gives no team, and a chosen set keeps helpers within it. While one
827
+ // orchestrates: minus the orchestrators too (they only hand work out)
826
828
  const now = this.s?.client.rotation?.list[this.s.client.rotation.at] ?? this.sessionModels()[0]
829
+ const lead = this.s?.orchestrating ? this.orchestrators() : []
827
830
  return this.sessionModels()
828
- .filter((t) => !(t.provider === now?.provider && t.model === now?.model))
831
+ .filter((t) => ![now, ...lead].some((o) => t.provider === o?.provider && t.model === o?.model))
829
832
  .map((t) => ({ ...t, ...this.abilities(t) }))
830
833
  }
831
834
 
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
+
832
843
  // What a model can do, from its saved profile or models.dev (guessed: neither knows it).
833
844
  abilities(t) {
834
845
  const cl = this.client(t.provider, t.model)
@@ -858,7 +869,7 @@ class App {
858
869
  const rot = this.s?.client.rotation
859
870
  if (rot) return rot.list[rot.at]
860
871
  if (this.s) return { provider: this.s.client.provider, model: this.s.client.model }
861
- return this.sessionModels()[0] ?? null
872
+ return (fitMode(cfg) ? this.orchestrators()[0] : null) ?? this.sessionModels()[0] ?? null
862
873
  }
863
874
 
864
875
  // your list has models, but the providers of all of them are switched off
@@ -1176,7 +1187,7 @@ let settingsPage = null
1176
1187
 
1177
1188
  // The browser, with a page. Windows: its URL handler (cmd's start mangles a URL whose arguments
1178
1189
  // it reads as its own, and wants a quoted empty title first).
1179
- // How HeartCode picks your models: "fit" (by strengths, per message) or your order; --model-choice for this run wins.
1190
+ // How HeartCode picks your models: "fit" (an orchestrator hands the work out) or your order; --model-choice for this run wins.
1180
1191
  let modelChoiceFlag
1181
1192
  const fitMode = (cfg) => (modelChoiceFlag ?? cfg.modelChoice) === 'fit'
1182
1193
 
@@ -1200,7 +1211,7 @@ function applySettings(apps, cfg, what) {
1200
1211
  const { ui } = app
1201
1212
  const busy = Boolean(ui.busySince || app.working)
1202
1213
  const now = (fn) => (busy ? app.later.push(fn) : fn())
1203
- 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]
1214
+ if (app.cfg !== cfg) for (const k of ['providers', 'provider', 'model', 'effort', 'theme', 'context', 'autoCompact', 'director', 'format', 'lsp', 'voice', 'rotation', 'statusBar', 'modelChoice', 'orchestrators']) app.cfg[k] = cfg[k]
1204
1215
  // a model pinned in this CLI (/select_model) is a session choice: a model/order change on the
1205
1216
  // settings page leaves it alone (only /select_model auto here returns it to the list)
1206
1217
  if (what === 'model' && !app.cfg.session) {
@@ -1208,8 +1219,8 @@ function applySettings(apps, cfg, what) {
1208
1219
  if (app.s && !(cfg.providers[cfg.provider] && cfg.model)) now(() => ((app.s = null), ui.print(c.dim('settings: no model chosen'))))
1209
1220
  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'))))
1210
1221
  }
1211
- // your model list: into the running session now, its next request goes to the new #1
1212
- if ((what === 'model' || what === 'setting:rotation') && !app.cfg.session && app.s && cfg.providers[cfg.provider] && cfg.model) {
1222
+ // your model list: into the running session now, its next request goes to the new #1 (or orchestrator)
1223
+ if (['model', 'setting:rotation', 'setting:modelChoice', 'setting:orchestrators'].includes(what) && !app.cfg.session && app.s && cfg.providers[cfg.provider] && cfg.model) {
1213
1224
  const was = `${app.s.client.provider} · ${app.s.client.model}`
1214
1225
  app.useRotation()
1215
1226
  const is = `${app.s.client.provider} · ${app.s.client.model}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "heartcode",
3
- "version": "0.1.42",
3
+ "version": "0.1.44",
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",
package/prompts/agent.md CHANGED
@@ -244,20 +244,44 @@ Which of your models does the job (from "Your other models" in the system prompt
244
244
 
245
245
  ## team
246
246
 
247
- <!-- In the system prompt when the user set up other models. {{models}}: one per line with what each can do (and failures this session). {{you}}: what this model can do. {{ranked}}: best fit's rankings are shown. -->
247
+ <!-- In the system prompt when the user set up other models. {{models}}: one per line with what each can do (and failures this session). {{you}}: what this model can do. {{ranked}}: the rankings are shown (with an orchestrator). -->
248
248
  # Your other models
249
249
 
250
250
  Besides you (tool calls, {{you}}), the user set up these models:
251
251
  {{models}}
252
252
 
253
253
  Work with them through the agent tool: "model" picks one, "images" gives it images to look at.
254
- {{#if ranked}}"ranked": its place in public rankings (LMArena) of coding, web apps and vision — #1 is the best of hundreds of models.
254
+ {{#if ranked}}"ranked": its place in public rankings (LMArena) overall, of coding, web apps and vision — #1 is the best of hundreds of models.
255
255
  {{/if}}
256
256
  - Hand a part to the one best at it, independent parts at the same time, while you plan, put it together and check. A small job: do it yourself.
257
257
  - Can't do something (see an image, read more than fits): never decline or guess — ask a model that can, the ability first; not one that keeps failing.
258
258
  - Ask for what you need to act, in the form you need it ("which of tiles 1-9 show a chair? the numbers only"), not for a description. A loop that needs the ability at every step (look, act, look again) goes whole to a model that has it.
259
259
  - Helpers share the browser and MCP servers (they take turns using one); never give two helpers the same files. A helper that fails goes to your next capable model; an answer that doesn't settle it: ask again, sharper. Trust a clear answer; don't redo its work.
260
260
 
261
+ ## orchestrator
262
+
263
+ <!-- The system prompt of the orchestrator (Pick: "an orchestrator hands it out"): it answers or hands the work out, nothing else. {{models}}: the models it hands work to, one per line with what each can do. {{ranked}}: their rankings are shown. -->
264
+ You are HeartCode's orchestrator, in the terminal, in the user's project at {{root}} ({{env}}; today is {{today}}). You don't do the work yourself and you have no tools for it: you talk with the user and hand work to the models below, with the agent tool.
265
+
266
+ The models you hand work to:
267
+ {{models}}
268
+ {{#if ranked}}"ranked": its place in public rankings (LMArena) overall, of coding, web apps and vision — #1 is the best of hundreds of models.
269
+ {{/if}}
270
+ - A greeting, a question you can answer well from what you know or from this conversation: answer it yourself, now. Nothing to hand out.
271
+ - Anything that needs the project's files, commands, the web or real work: hand it to the model that suits it best ("model"). It has every tool but sees only your prompt, not this conversation: give it the whole task, what the user said they want, and what to report back.
272
+ - Independent parts can go to several models at once (several agent calls in one reply). A model that fails is replaced on its own; an answer that doesn't settle it: ask again, sharper, or ask another model.
273
+ - When the work comes back, tell the user what was done, plainly and short. Don't claim more than the reports say.
274
+
275
+ ## tool-hand
276
+
277
+ <!-- The agent tool's description for the orchestrator. -->
278
+ Hand work to one of the models in the system prompt. It works with every tool (files, commands, web) in its own fresh context and sees only your prompt, so say exactly what to do and what to report. Its final reply comes back as the result. description: 3-5 words for the user. Several calls in one reply run at the same time.
279
+
280
+ ## tool-hand-model
281
+
282
+ <!-- The agent tool's "model" for the orchestrator. -->
283
+ Which model does it, as "provider model" from the system prompt's list. Left out: the first of them.
284
+
261
285
  ## you-see
262
286
 
263
287
  <!-- In the system prompt of a model that can see images (models that can often say they can't). -->
@@ -492,19 +516,6 @@ Put them together now: read what they changed, make what's still needed between
492
516
  <!-- Added to the todo tool's result once a message, when a plan has three or more open parts and none runs side by side or on another model. -->
493
517
  (Could any of these parts run side by side, or go to one of your models that's better at it? If so, mark them (parallel, model, files) and save the list again; if not, go on.)
494
518
 
495
- ## pick-skills
496
-
497
- <!-- Its own request at the start of a message, in "best fit" mode: the skills the task needs, so your models can be ranked for it (rankings.js). {{task}}: the user's message; {{choices}}: their answers about how to do it; {{skills}}: the skills to choose from, one per line. -->
498
- Which skills does this coding task need most? The task:
499
- {{task}}
500
- {{#if choices}}How the user wants it: {{choices}}
501
- {{/if}}
502
- The skills:
503
- {{skills}}
504
-
505
- Name the 1 to 3 that matter most for doing it well, most important first. Reply with one line and nothing else:
506
- skills: name, name
507
-
508
519
  ## same-spot
509
520
 
510
521
  <!-- Added to an edit's result when it's the third change to the same spot (the same file, within a few lines) in this message. {{file}}, {{line}}: where. -->
package/src/agent.js CHANGED
@@ -7,8 +7,7 @@ import path from 'node:path'
7
7
  import { est, estMessages, Client, writtenBy, tokensOf, COMPACT_SHARE } from './client.js'
8
8
  import { runGuided } from './guided.js'
9
9
  import { markUsed, removeResearch, findResearch } from './research.js'
10
- import { loadRankings, rankIn } from './rankings.js'
11
- import { pickModels, byPick } from './fit.js'
10
+ import { loadRankings, rankIn, rankings } from './rankings.js'
12
11
  import { TOOL_DEFS, PLAN_HIDDEN, folderView, readOnlyCommand, extraTools, runTool, listFiles, namedFiles, readFileTool, clip, allowed, loadMcpTools, saveOutput, isSavedOutput, runningCall, imageUrl, MAX_IMAGE, failed, noteNamedPaths } from './tools.js'
13
12
  import { serversNote } from './lsp.js'
14
13
  import { newlyEnded, jobLine } from './background.js'
@@ -209,12 +208,16 @@ export class Session {
209
208
  else this.ui.warn(`${this.client.model} can't read images (per its probe); ignoring ${images.length} image(s)`)
210
209
  images = []
211
210
  }
212
- // "best fit": the models that suit this message most, by their strengths (your order breaks ties)
213
- if (!this.isSub && this.fitMode?.()) {
214
- const fit = await pickModels(this, text, signal, { images: images.length, size: this.messages ? size(this.messages) : 0 })
215
- if (fit && this.client.orderBy?.(fit.work)) ui.step('models', `${this.client.model}${fit.why ? ` · picked for: ${fit.why}` : ''}`)
216
- } else if (!this.isSub) this.client.orderBy?.(null) // your order (best fit was switched off)
217
- if (!this.isSub) log('rotate', `this message starts on ${this.client.provider ?? ''} · ${this.client.model}${this.client.rotation ? ` (#${this.client.rotation.at + 1} of ${this.client.rotation.list.length}${this.fitMode?.() ? ', best fit' : ', your order'})` : ''}`)
211
+ // An orchestrator: the message starts on one of the models picked for it, which answers at once
212
+ // or hands the work to your other models (it decides) — only when there are others to hand to.
213
+ if (!this.isSub) {
214
+ const lead = this.fitMode?.() ? (this.orchestrators?.() ?? []) : []
215
+ this.client.orderBy?.(lead.length ? lead.map((t) => `${t.provider} ${t.model}`) : null)
216
+ this.orchestrating = lead.length > 0 // (then team() leaves the orchestrators out)
217
+ if (this.orchestrating && !this.team?.().length) this.orchestrating = false // no one to hand to: it does the work itself
218
+ if (this.orchestrating) rankings().catch(() => {}) // their places, for its list of models: fetched behind (once a week), never waited for
219
+ log('rotate', `this message starts on ${this.client.provider ?? ''} · ${this.client.model}${this.client.rotation ? ` (#${this.client.rotation.at + 1} of ${this.client.rotation.list.length}${this.orchestrating ? ', orchestrating' : ', your order'})` : ''}`)
220
+ }
218
221
  log('task', `${text} (${this.strat.actions} mode, ${images.length} image(s))`)
219
222
  const answer = this.strat.actions === 'tools' ? await runNative(this, text, images, signal) : await runGuided(this, text, images, signal)
220
223
  log('answer', answer) // the conversation's log
@@ -242,10 +245,10 @@ export class Session {
242
245
  }
243
246
  const name = (t) => `${t.provider} ${t.model}`
244
247
  const self = { provider: this.client.provider, model: this.client.model, images: this.strat.vision, tools: this.strat.actions === 'tools', self: true }
245
- const all = [self, ...(this.team?.() ?? [])]
248
+ const all = [...(this.orchestrating ? [] : [self]), ...(this.team?.() ?? [])] // an orchestrator hands work out, never to itself
246
249
  const want = String(args.model ?? '').trim()
247
250
  // only one model available (a pinned model, or you have just one): helpers use it, whatever was asked
248
- const first = !want || all.length === 1 ? self : (all.find((t) => name(t) === want) ?? all.find((t) => t.model === want || want.endsWith(` ${t.model}`)))
251
+ const first = !want || all.length === 1 ? all[0] : (all.find((t) => name(t) === want) ?? all.find((t) => t.model === want || want.endsWith(` ${t.model}`)))
249
252
  if (!first) return `error: no model "${want}". Yours: ${all.map(name).join(', ')}`
250
253
  // the one asked for first (if it can do the job), then the others that can: those that call
251
254
  // tools first, then the ones that failed least this session, in your list's order
@@ -547,6 +550,7 @@ const rootList = (root) => {
547
550
  }
548
551
 
549
552
  const SYSTEM = (s) => {
553
+ if (s.orchestrating) return prompt('agent/orchestrator', { root: s.root, env: envLine(), today: new Date().toISOString().slice(0, 10), ...teamOf(s) })
550
554
  const instructions = userInstructions(s.root)
551
555
  return [
552
556
  prompt('agent/system', { root: s.root, env: envLine(), today: new Date().toISOString().slice(0, 10), rootList: rootList(s.root), servers: serversNote(s.root), files: '', more: '', caller: Boolean(s.appendSystem) }),
@@ -565,11 +569,13 @@ const SYSTEM = (s) => {
565
569
  }
566
570
 
567
571
  // Your other models and what each can do, for the agent tool's model (only when there are any): a
568
- // short line each — in best fit, with its places in the public rankings (rankings.js).
569
- const RANKED_AS = { code: 'text:coding', web: 'webdev:webdev', vision: 'vision:overall' }
572
+ // short line each — with an orchestrator, with its places in the public rankings (rankings.js).
573
+ const RANKED_AS = { overall: 'text:overall', code: 'text:coding', web: 'webdev:webdev', vision: 'vision:overall' }
570
574
  const teamPrompt = (s) => {
571
575
  const team = s.team?.() ?? []
572
- if (!team.length) return ''
576
+ return team.length ? prompt('agent/team', teamOf(s, team)) : ''
577
+ }
578
+ const teamOf = (s, team = s.team?.() ?? []) => {
573
579
  const data = s.fitMode?.() ? loadRankings() : null
574
580
  const ranks = (t) => (data ? Object.entries(RANKED_AS).map(([k, list]) => ((r) => r && `${k} #${r.rank}`)(rankIn(t.model, list, data))).filter(Boolean).join(' ') : '')
575
581
  const line = (t) => {
@@ -578,7 +584,7 @@ const teamPrompt = (s) => {
578
584
  return `- ${t.provider} ${t.model}${facts.length ? `: ${facts.join(', ')}` : ''}`
579
585
  }
580
586
  const you = [s.strat.vision ? 'images' : 'no images', s.strat.thinking && 'thinking', ranks(s.client) && `ranked ${ranks(s.client)}`].filter(Boolean).join(', ')
581
- return prompt('agent/team', { models: team.map(line).join('\n'), you, ranked: Boolean(data) })
587
+ return { models: team.map(line).join('\n'), you, ranked: Boolean(data) }
582
588
  }
583
589
 
584
590
  const sizeOf = (m) =>
@@ -1356,8 +1362,7 @@ export async function review(s, task, answer, signal) {
1356
1362
  const self = { provider: s.client.provider, model: s.client.model, self: true }
1357
1363
  const fails = (t) => s.failures?.[`${t.provider} ${t.model}`] ?? 0
1358
1364
  const team = (s.team?.() ?? []).filter((t) => t.tools !== false && !(t.provider === self.provider && t.model === self.model)).sort((a, b) => fails(a) - fails(b))
1359
- const others = s.fitMode?.() && s.chat.fit?.review?.length ? byPick(team, s.chat.fit.review) : team // best fit: the best at checking code first
1360
- for (const t of [...others.slice(0, 2), self]) {
1365
+ for (const t of [...team.slice(0, 2), ...(s.orchestrating ? [] : [self])]) { // an orchestrator doesn't check the work
1361
1366
  s.ui.spinner(`${t.model} is reviewing the work`)
1362
1367
  try {
1363
1368
  const { client } = t.self ? { client: s.client } : await s.engineFor(t)
package/src/client.js CHANGED
@@ -263,9 +263,9 @@ export class Client {
263
263
  }
264
264
  return i
265
265
  }
266
- // "Best fit": these models first ("provider model", best first), the others after in your list's
267
- // order; this message starts with the first, and a failure goes on to the next best. false: no list.
268
- // null: your order again (best fit switched off).
266
+ // An orchestrator: these models first ("provider model"), the others after in your list's order;
267
+ // this message starts with the first, and a failure goes on to the next. false: no list.
268
+ // null: your order again (switched off).
269
269
  orderBy(names) {
270
270
  const r = this.rotation
271
271
  if (!r) return false
@@ -275,12 +275,12 @@ export class Client {
275
275
  this.#use(r.list[0])
276
276
  return true
277
277
  }
278
- r.base ??= [...r.list] // your order, kept for when best fit is switched off
278
+ r.base ??= [...r.list] // your order, kept for when it's switched off
279
279
  const first = names.map((n) => r.list.find((t) => `${t.provider} ${t.model}` === n)).filter(Boolean)
280
280
  if (!first.length) return false
281
281
  r.list = [...new Set([...first, ...r.base])]
282
282
  r.at = 0
283
- log('rotate', `best fit: ${first.map((t) => t.model).join(', ')} first`)
283
+ log('rotate', `orchestrators: ${first.map((t) => t.model).join(', ')} first`)
284
284
  this.#use(r.list[0])
285
285
  return true
286
286
  }
package/src/config.js CHANGED
@@ -19,7 +19,7 @@ export function projectDir(root, what) {
19
19
  return dir
20
20
  }
21
21
 
22
- const SETTINGS = ['context', 'effort', 'permissions', 'autoCompact', 'director', 'theme', 'format', 'lsp', 'voice', 'queue', 'rotation', 'statusBar', 'log', 'logRequests', 'logDetail', 'logDays', 'telegram', 'search', 'testTimeout', 'updateCheck', 'modelChoice', 'logs', 'replyStart', 'mouse']
22
+ const SETTINGS = ['context', 'effort', 'permissions', 'autoCompact', 'director', 'theme', 'format', 'lsp', 'voice', 'queue', 'rotation', 'statusBar', 'log', 'logRequests', 'logDetail', 'logDays', 'telegram', 'search', 'testTimeout', 'updateCheck', 'modelChoice', 'orchestrators', 'logs', 'replyStart', 'mouse']
23
23
  const LOCAL_NAMES = { 11434: 'ollama', 1234: 'lmstudio', 8080: 'llamacpp' }
24
24
 
25
25
  export function readJson(file, fallback) {
package/src/headless.js CHANGED
@@ -90,7 +90,7 @@ export async function runHeadless(app, opts) {
90
90
  }
91
91
  s.appendSystem = opts.appendSystem || undefined
92
92
  const session_id = app.chat.id
93
- const model = `${app.cfg.provider}/${s.client.model}`
93
+ const model = `${s.client.provider ?? app.cfg.provider}/${s.client.model}`
94
94
 
95
95
  // usage and request count, over everything this message sends (tool loop, compaction, memory)
96
96
  // (also your other models', when this one hands them a job: modelUsage has each)
package/src/rankings.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // What each model is good at, from public rankings (LMArena: people comparing two models' answers
2
- // to the same prompt, by skill): coding, web apps, images, long inputs… Fetched once a week into
3
- // ~/.heart/rankings.json (best fit only); a model is matched to its entry by name.
2
+ // to the same prompt, by skill): overall, coding, web apps, images. Fetched once a week into
3
+ // ~/.heart/rankings.json (with an orchestrator, or Update model info); a model is matched to its entry by name.
4
4
  import path from 'node:path'
5
5
  import { HOME, readJson, writeJson } from './config.js'
6
6
  import { log } from './log.js'
@@ -11,25 +11,8 @@ const WEEK = 7 * 24 * 3600_000
11
11
  const VERSION = 2 // 2: with each model's score; an older file is fetched again
12
12
  const FILES = 'https://huggingface.co/datasets/lmarena-ai/leaderboard-dataset/resolve/main' // one Parquet file per ranking: text, webdev, vision, agent
13
13
 
14
- // The skills a task can need: [ranking, its category, what it's for] (the pick names them).
15
- export const SKILLS = {
16
- coding: ['text', 'coding', 'writing and fixing code'],
17
- webdev: ['webdev', 'webdev', 'building web apps (any stack)'],
18
- 'webdev-html': ['webdev', 'webdev-html', 'plain HTML/CSS/JS pages, canvas and browser games'],
19
- 'webdev-react': ['webdev', 'webdev-react', 'React apps'],
20
- hard: ['text', 'hard_prompts', 'hard, multi-part problems'],
21
- instructions: ['text', 'instruction_following', 'following detailed instructions exactly'],
22
- 'long-input': ['text', 'longer_query', 'long inputs: big files, long specs'],
23
- 'multi-turn': ['text', 'multi_turn', 'long back-and-forth work'],
24
- math: ['text', 'math', 'math and algorithms'],
25
- writing: ['text', 'creative_writing', 'prose, docs, copy'],
26
- software: ['text', 'industry_software_and_it_services', 'software and IT know-how'],
27
- vision: ['vision', 'overall', 'understanding images and screenshots'],
28
- ocr: ['vision', 'ocr', 'reading text in images'],
29
- diagrams: ['vision', 'diagram', 'reading diagrams and charts'],
30
- agent: ['agent', 'overall', 'agent work: tool calls, commands, many steps'],
31
- }
32
- const OVERALL = 'text:overall' // a skill a model isn't ranked on: its overall place stands in
14
+ // The lists kept (ranking:category): shown on Your models and to the orchestrator
15
+ const LISTS = ['text:overall', 'text:coding', 'webdev:webdev', 'vision:overall']
33
16
 
34
17
  export const loadRankings = () => readJson(FILE, null)
35
18
 
@@ -49,7 +32,7 @@ export async function rankings({ signal, onWait, now = false } = {}) {
49
32
  const have = loadRankings()
50
33
  if (have && have.v === VERSION && Date.now() - have.fetched < WEEK && !now) return have
51
34
  refreshing ??= (async () => {
52
- const wanted = new Set([...Object.values(SKILLS).map(([c, k]) => `${c}:${k}`), OVERALL])
35
+ const wanted = new Set(LISTS)
53
36
  const all = Object.assign({}, ...(await Promise.all([...new Set([...wanted].map((p) => p.split(':')[0]))].map((c) => fetchRanking(c, have ? undefined : signal)))))
54
37
  const lists = Object.fromEntries(Object.entries(all).filter(([k]) => wanted.has(k)))
55
38
  const out = { v: VERSION, fetched: Date.now(), source: 'LMArena (huggingface.co/datasets/lmarena-ai/leaderboard-dataset)', lists }
@@ -104,14 +87,6 @@ export function place(model, list) {
104
87
  return at.length ? Math.min(...at.map((e) => e.rank)) / list.length : null
105
88
  }
106
89
 
107
- // A model's score for some skills, 0 (best) to 1: the average of its places; a skill it isn't
108
- // ranked on counts as its overall place. null: not ranked at all.
109
- export function score(model, skills, data) {
110
- const overall = place(model, data?.lists[OVERALL])
111
- const each = skills.map((k) => place(model, data?.lists[SKILLS[k] && `${SKILLS[k][0]}:${SKILLS[k][1]}`]) ?? overall)
112
- return each.every((x) => x == null) ? null : each.reduce((n, x) => n + (x ?? 1), 0) / each.length
113
- }
114
-
115
90
  // A model's place in one list ('text:coding'…), for showing: { rank, of, as, score, votes } (as: its name there); null when not in it
116
91
  export function rankIn(model, key, data) {
117
92
  const list = data?.lists[key]
package/src/settings.html CHANGED
@@ -585,6 +585,12 @@
585
585
  /* a model's tooltip: shown at once on hover (or keyboard focus), next to the row */
586
586
  #tip { position: fixed; z-index: 30; max-width: 380px; padding: 13px 15px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow-pop); font-size: 12.5px; pointer-events: none; opacity: 0; transition: opacity .08s; }
587
587
  #tip.show { opacity: 1; }
588
+ /* every other tooltip (titles): at once, the page's own look */
589
+ #hint { position: fixed; z-index: 31; max-width: 340px; padding: 7px 10px; border-radius: 8px; background: var(--text); color: var(--bg); font-size: 12px; line-height: 1.45; box-shadow: var(--shadow-pop); pointer-events: none; opacity: 0; transition: opacity .06s; white-space: pre-line; }
590
+ #hint.show { opacity: 1; }
591
+ .with-q { display: inline-flex; align-items: center; gap: 5px; }
592
+ .q { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; border: 1px solid var(--line); color: var(--muted); font-size: 11px; font-weight: 700; cursor: help; }
593
+ .q:hover, .q:focus-visible { color: var(--text); border-color: var(--muted); outline: none; }
588
594
  #tip .tid { font-family: var(--mono); font-weight: 700; font-size: 13px; word-break: break-all; }
589
595
  #tip .tname { color: var(--muted); margin-top: 1px; }
590
596
  #tip dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0 0; }
@@ -1295,6 +1301,7 @@ const DOING = {
1295
1301
  '/api/provider/list': 'Saving the model list setting',
1296
1302
  '/api/provider/on': 'Switching the provider',
1297
1303
  '/api/order': 'Saving your models',
1304
+ '/api/orchestrators': 'Saving the orchestrators',
1298
1305
  '/api/mcp/login': 'Signing in — your browser will open',
1299
1306
  '/api/telegram/connect': 'Checking the token with Telegram',
1300
1307
  '/api/telegram/test': 'Sending a test message',
@@ -1820,6 +1827,46 @@ function withTip(el, content) {
1820
1827
  }
1821
1828
  addEventListener('scroll', () => $('tip').classList.remove('show'), true)
1822
1829
 
1830
+ // Every other tooltip (an element's title): shown at once in a box of the page's own, not the
1831
+ // browser's (which waits a second and can't be styled). The title moves to data-tip on first hover,
1832
+ // so the browser's own doesn't show as well; a title set again later is taken in the same way.
1833
+ const hint = h('div', { id: 'hint', role: 'tooltip' })
1834
+ document.body.append(hint)
1835
+ let hintFor = null
1836
+ const tipOf = (el) => {
1837
+ for (; el && el !== document.body; el = el.parentElement) {
1838
+ const title = el.getAttribute('title')
1839
+ if (title !== null) {
1840
+ el.removeAttribute('title') // set again to '' later: no tooltip now
1841
+ if (title) (el.dataset.tip = title), el.getAttribute('aria-label') || el.setAttribute('aria-description', title)
1842
+ else delete el.dataset.tip
1843
+ }
1844
+ if (el.dataset?.tip) return el
1845
+ }
1846
+ return null
1847
+ }
1848
+ const hideHint = () => ((hintFor = null), hint.classList.remove('show'))
1849
+ const showHint = (el) => {
1850
+ hintFor = el
1851
+ hint.textContent = el.dataset.tip
1852
+ hint.classList.add('show')
1853
+ const r = el.getBoundingClientRect()
1854
+ const t = hint.getBoundingClientRect()
1855
+ const below = r.bottom + 8 + t.height < innerHeight
1856
+ hint.style.top = `${below ? r.bottom + 6 : Math.max(8, r.top - t.height - 6)}px`
1857
+ hint.style.left = `${Math.min(Math.max(8, r.left + r.width / 2 - t.width / 2), innerWidth - t.width - 8)}px`
1858
+ }
1859
+ const hintAt = (e) => {
1860
+ const el = document.body.classList.contains('sorting') ? null : tipOf(e.target)
1861
+ if (el === hintFor) return
1862
+ el ? showHint(el) : hideHint()
1863
+ }
1864
+ document.addEventListener('mouseover', hintAt)
1865
+ document.addEventListener('focusin', hintAt)
1866
+ document.addEventListener('focusout', hideHint)
1867
+ document.addEventListener('mousedown', hideHint)
1868
+ addEventListener('scroll', hideHint, true)
1869
+
1823
1870
  function drawProviders(s) {
1824
1871
  const order = s.order
1825
1872
  const none = !s.providers.length
@@ -1835,7 +1882,7 @@ function drawProviders(s) {
1835
1882
  const shown = shownOrder()
1836
1883
  $('p-mine').hidden = !shown.length
1837
1884
  $('p-mine').textContent = `Your models (${shown.length}) →`
1838
- $('p-mine').title = shown.length ? `${S.settings.modelChoice === 'fit' ? 'HeartCode picks the best of them for each task' : `HeartCode uses ${shown[0].provider} · ${shown[0].model}`}. Open the Your models page: the order, tests, and what happens when one fails` : ''
1885
+ $('p-mine').title = shown.length ? `${S.settings.modelChoice === 'fit' ? 'An orchestrator answers each message or hands the work to the others' : `HeartCode uses ${shown[0].provider} · ${shown[0].model}`}. Open the Your models page: the order, tests, and what happens when one fails` : ''
1839
1886
  fillHeight()
1840
1887
 
1841
1888
  // every provider's models, A to Z; one click adds it (the first one becomes #1). Built
@@ -2198,6 +2245,15 @@ function buildCatalog(s) {
2198
2245
  }
2199
2246
  // --- Your models page: the list as a table; sorted by several columns at once (each a tie-break
2200
2247
  // for the ones before it), the sort kept in this browser ---
2248
+ // The orchestrators (Pick: "an orchestrator hands it out"): those picked that call tools; none: your first that does
2249
+ const leads = (s = S) => {
2250
+ const able = s.order.filter((t) => !isOff(t.provider) && can(t).tools)
2251
+ const picked = able.filter((t) => (s.orchestrators ?? []).some((o) => o.provider === t.provider && o.model === t.model))
2252
+ return picked.length ? picked : able.slice(0, 1)
2253
+ }
2254
+ const ORCH_ABOUT = 'Makes the selected models your orchestrators, in place of the ones you have now. Every message then goes to one of them first: it replies on its own when it can (a hello, a quick question), and hands real work to the other models it picks. They only orchestrate and do no work themselves. A model that can\'t call tools is skipped.'
2255
+ const isLead = (t) => leads().some((o) => o.provider === t.provider && o.model === t.model)
2256
+ const setLeads = (list, done) => act('/api/orchestrators', { list: list.map(({ provider, model }) => ({ provider, model })) }, done)
2201
2257
  const can = (t) => ({ tools: t.tested ? t.tested.mode === 'tools' : t.known?.tools !== false, thinking: Boolean(t.tested ? t.tested.thinking : t.known?.thinking), images: Boolean(t.tested ? t.tested.vision : t.known?.images) })
2202
2258
  // Every column sorts by the value it shows: up (↑) smallest first, down (↓) largest first. first: the
2203
2259
  // direction of the first click (the useful one). get: the value; null when there's none (no price, no
@@ -2376,7 +2432,9 @@ function drawMine(s) {
2376
2432
  const order = shownOrder() // a provider switched off: its models aren't shown (nor tested, sorted, ranked)
2377
2433
  $('n-mine').textContent = order.length || ''
2378
2434
  const shown = filtering() ? order.filter((t) => passes(t)) : order
2379
- const view = sorted(shown)
2435
+ // an orchestrator: they come first (they answer first), in your order; the rest as sorted
2436
+ const first = new Set(S.settings.modelChoice === 'fit' ? leads().map(keyOf) : [])
2437
+ const view = ((v) => (first.size ? [...v.filter((t) => first.has(keyOf(t))), ...v.filter((t) => !first.has(keyOf(t)))] : v))(sorted(shown))
2380
2438
  const filtered = shown.length !== order.length
2381
2439
  for (const k of PICKED) if (placeOf(...k.split(/\/(.*)/s)) === undefined) PICKED.delete(k) // gone from the list
2382
2440
  const n = (x) => x.toLocaleString()
@@ -2419,24 +2477,23 @@ function drawMine(s) {
2419
2477
 
2420
2478
  // --- the page's header: how a model is picked (left), what's known about the models (right) ---
2421
2479
  $('mt-lead').textContent = S.settings.modelChoice === 'fit'
2422
- ? 'Each message goes to the models that score best for it. Your order breaks ties, and decides among models with no score. Filter, sort or drag, then Save order.'
2480
+ ? 'An orchestrator answers each message at once, or hands the work to the models it picks from the others. To choose them, select models and press Mark as orchestrators (a quick, cheap model is enough).'
2423
2481
  : 'HeartCode uses #1, and the next one when it fails. Filter, sort or drag, then Save order.'
2424
2482
  const busy = locked()
2425
2483
  $('mt-actions').inert = busy
2426
2484
  put($('mt-actions'),
2427
2485
  ((why) => h('span', { title: why ?? '' }, h('button', { className: 'small', textContent: 'Order providers', disabled: Boolean(why), title: why ? '' : 'drag your providers into order; the Provider column sorts by it', onclick: openRanking })))( // disabled: why, on a span (a disabled button shows no tooltip in every browser)
2428
- S.settings.modelChoice === 'fit' ? 'Not used while Pick is "the best for each task": each message gets the models ranked best for it, whatever their provider. Pick "in your order" to use it'
2429
- : !order.some((t) => t.provider !== order[0]?.provider) ? 'All your models are from one provider: nothing to order' : null),
2430
- h('button', { className: 'small', textContent: 'Update model info', disabled: !order.length, title: `what each model can do (context, tools, thinking, images, price) from models.dev, and its scores in LMArena's public rankings (coding, web apps, vision${S.rankings ? `; scores from ${new Date(S.rankings.fetched).toLocaleDateString()}` : ''}). Best fit also gets the scores again once a week`, onclick: () => lookUp() }))
2486
+ !order.some((t) => t.provider !== order[0]?.provider) ? 'All your models are from one provider: nothing to order' : null),
2487
+ h('button', { className: 'small', textContent: 'Update model info', disabled: !order.length, title: `what each model can do (context, tools, thinking, images, price) from models.dev, and its scores in LMArena's public rankings (coding, web apps, vision${S.rankings ? `; scores from ${new Date(S.rankings.fetched).toLocaleDateString()}` : ''}). With an orchestrator they come again once a week`, onclick: () => lookUp() }))
2431
2488
 
2432
2489
  // --- the list's settings: one line, a short label beside each control ---
2433
2490
  const ro = s.rotation
2434
2491
  const cell = (label, about, ...control) => h('label', { className: 'mt-set', title: about }, h('span', { className: 'mt-setl', textContent: label }), h('span', { className: 'mt-setc' }, ...control))
2435
2492
  const fit = S.settings.modelChoice === 'fit'
2436
2493
  const settings = h('div', { className: 'mt-sets', inert: busy },
2437
- cell('Pick', fit ? 'for each new message, your models ranked by public rankings (LMArena, fetched once a week) on the skills it needs: web pages, code, images…; models not ranked come after, in your order' : 'your order: #1 works, the next takes over when it fails',
2438
- h('select', { onchange: (e) => act('/api/setting', { name: 'modelChoice', value: e.target.value }, e.target.value === 'fit' ? 'models picked for each task by public rankings' : 'models used in your order') },
2439
- [['order', 'in your order'], ['fit', 'the best for each task']].map(([v, t]) => h('option', { value: v, textContent: t, selected: S.settings.modelChoice === v })))),
2494
+ cell('Pick', fit ? "each message starts on an orchestrator: it answers itself (a hello), or hands the work to the models it picks from the others (it sees what each can do, and its place in LMArena's public rankings). It only hands work out; the others do it" : 'your order: #1 works, the next takes over when it fails',
2495
+ h('select', { onchange: (e) => act('/api/setting', { name: 'modelChoice', value: e.target.value }, e.target.value === 'fit' ? 'an orchestrator hands each task out' : 'models used in your order') },
2496
+ [['order', 'in your order'], ['fit', 'an orchestrator hands it out']].map(([v, t]) => h('option', { value: v, textContent: t, selected: S.settings.modelChoice === v })))),
2440
2497
  cell('If one fails', ro.on === 'retries' ? 'a rate limit or outage: that model is tried again that many times first; any other error moves on at once' : "any error moves on at once, to another provider's model first",
2441
2498
  h('select', { onchange: (e) => saveOrder(S.order, 'saved', { on: e.target.value }) },
2442
2499
  [['failure', 'go to the next'], ['retries', 'retry it first']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.on === v }))),
@@ -2447,7 +2504,9 @@ function drawMine(s) {
2447
2504
  if (!(v >= 5 && v <= 600)) return (e.target.value = S.settings.replyStart ?? 60), toast('a whole number of seconds, 5 to 600', true)
2448
2505
  act('/api/setting', { name: 'replyStart', value: v }, `a model that hasn't started answering in ${v}s counts as failed`)
2449
2506
  } }), h('span', { className: 'unit', textContent: 'seconds of silence' })),
2450
- cell('New message to', fit ? 'best fit picks it for each message' : 'the model a new message goes to first',
2507
+ fit ? cell('Orchestrators', 'the models that answer first and hand the work out (the next one when one fails). Select models in the list and press Mark as orchestrators; click a model\'s "orchestrator ✕" tag to unmark it. None chosen: your first model that calls tools',
2508
+ h('span', { className: 'unit', textContent: (S.orchestrators ?? []).length ? leads().map((t) => t.model).join(', ') || 'none that calls tools' : `${leads()[0]?.model ?? 'none'} (your first)` })) : null,
2509
+ cell('New message to', fit ? 'each message starts on an orchestrator' : 'the model a new message goes to first',
2451
2510
  h('select', { disabled: fit, onchange: (e) => saveOrder(S.order, 'saved', { next: e.target.value }) },
2452
2511
  [['first', '#1'], ['stay', 'the last that worked']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.next === v })))),
2453
2512
  cell('Tests wait', 'every model test: Test, Test all, Request',
@@ -2463,7 +2522,7 @@ function drawMine(s) {
2463
2522
  busy ? h('span', { className: 'sort-live', textContent: `${testingAll ? 'testing' : 'updating'}: filters and changes wait until it's done (or Stop)` }) : null,
2464
2523
  filtering() || SORT.length ? h('button', { className: 'small ghost', textContent: 'Clear', title: 'every filter and the sort off: your whole list, in your order', onclick: clearView }) : null,
2465
2524
  h('button', { className: 'small', textContent: filtered ? `Test ${n(shown.length)}` : 'Test all', disabled: testingAll || !shown.length, title: `send ${filtered ? 'the models shown' : 'each model'} a short message to see which really answer`, onclick: () => tryAll(filtered ? shown : order) }),
2466
- h('button', { className: 'small primary', textContent: filtered ? `Use only these ${n(view.length)}` : 'Save order', disabled: !view.length || order.length < 2, title: filtered ? `HeartCode uses only these ${n(view.length)}, in the order shown (the others stay under Providers)` : S.settings.modelChoice === 'fit' ? 'keep the order shown: it breaks ties between equally scored models' : 'HeartCode uses them in the order shown (#1 first)', onclick: saveList }))
2525
+ h('button', { className: 'small primary', textContent: filtered ? `Use only these ${n(view.length)}` : 'Save order', disabled: !view.length || order.length < 2, title: filtered ? `HeartCode uses only these ${n(view.length)}, in the order shown (the others stay under Providers)` : S.settings.modelChoice === 'fit' ? 'keep the order shown: the orchestrator sees the others in this order, and a failed model goes to the next' : 'HeartCode uses them in the order shown (#1 first)', onclick: saveList }))
2467
2526
 
2468
2527
  // --- the table ---
2469
2528
  const all = view.length > 0 && view.every((t) => PICKED.has(keyOf(t)))
@@ -2479,6 +2538,12 @@ function drawMine(s) {
2479
2538
  h('div', { className: 'mt-pickbar' },
2480
2539
  h('b', { textContent: `${n(PICKED.size)} selected` }),
2481
2540
  h('button', { className: 'small', textContent: 'Test', disabled: testingAll, onclick: () => tryAll(pickedList) }),
2541
+ S.settings.modelChoice === 'fit' ? h('span', { className: 'with-q' }, h('button', { className: 'small', textContent: PICKED.size === 1 ? 'Mark as orchestrator' : 'Mark as orchestrators', title: ORCH_ABOUT, onclick: () => {
2542
+ const list = pickedList.filter((t) => can(t).tools)
2543
+ if (!list.length) return toast("none of these can call tools, and an orchestrator hands work out with a tool call", true)
2544
+ PICKED.clear()
2545
+ setLeads(list, `${list.length} orchestrator${list.length === 1 ? '' : 's'}: ${list.map((t) => t.model).join(', ')}`)
2546
+ } }), h('span', { className: 'q', tabIndex: 0, textContent: '?', title: ORCH_ABOUT, 'aria-label': 'what Mark as orchestrator does' })) : null,
2482
2547
  h('button', { className: 'small danger', textContent: 'Remove', onclick: removePicked }),
2483
2548
  h('button', { className: 'small ghost', textContent: 'Invert', title: "select the ones shown that aren't selected, unselect the ones that are", onclick: () => (view.forEach((t) => (PICKED.has(keyOf(t)) ? PICKED.delete(keyOf(t)) : PICKED.add(keyOf(t)))), (lastPicked = null), drawMine(S)) }),
2484
2549
  h('button', { className: 'small ghost', textContent: 'Select none', onclick: () => (PICKED.clear(), drawMine(S)) })))
@@ -2556,13 +2621,16 @@ function tableRow(t, at, pick) {
2556
2621
  const tag = !x ? h('span', { className: 'tag', textContent: '…', title: 'looking it up in models.dev' })
2557
2622
  : x.source === 'assumed' ? h('button', { type: 'button', className: 'tag warn', textContent: 'unknown', title: "models.dev doesn't know it: what it can do is a guess. Click to set it up", onclick: () => openSetup(t) })
2558
2623
  : Object.keys(x.set ?? {}).length ? h('button', { type: 'button', className: 'tag', textContent: 'edited', title: 'what it can do: set by you (click to change)', onclick: () => openSetup(t) }) : null
2624
+ const lead = S.settings.modelChoice === 'fit' && isLead(t) && (S.orchestrators ?? []).length
2625
+ ? h('button', { type: 'button', className: 'tag brand', textContent: 'orchestrator ✕', title: 'An orchestrator: every message goes to it first, and it replies or hands the work out. Click to unmark it (it goes back to being one of the models that do the work)', onclick: () => setLeads(leads().filter((o) => o !== t), `${t.model}: not an orchestrator now`) })
2626
+ : S.settings.modelChoice === 'fit' && isLead(t) ? h('span', { className: 'tag brand', textContent: 'orchestrator', title: 'None are marked, so your first model that calls tools orchestrates. To choose them, select models and press Mark as orchestrators' }) : null
2559
2627
  const going = Boolean(TRIES[keyOf(t)]?.going)
2560
2628
  const busy = locked()
2561
2629
  return h('li', { className: 'in' + (picked ? ' picked' : '') + (isOff(t.provider) ? ' off' : ''), 'data-key': `${t.provider}/${t.model}`, title: isOff(t.provider) ? `${t.provider} is switched off: HeartCode skips this model until it's on` : '' },
2562
2630
  h('span', { className: 'grip', textContent: '⋮⋮', 'aria-hidden': 'true' }),
2563
2631
  h('input', { type: 'checkbox', checked: picked, disabled: busy, 'aria-label': `select ${t.model}`, title: 'select (Shift: and every row up to the last one selected)', onclick: (e) => (e.preventDefault(), pick(e)) }),
2564
2632
  h('span', { className: 'n', textContent: `#${at + 1}`, title: SORT.length || filtering() ? 'its place in your list' : '' }),
2565
- h('span', { className: 'm' }, h('span', { className: 'name', textContent: t.model, title: t.model }), tag),
2633
+ h('span', { className: 'm' }, h('span', { className: 'name', textContent: t.model, title: t.model }), lead, tag),
2566
2634
  h('span', { className: 'p', textContent: isOff(t.provider) ? `${t.provider} · off` : t.provider, title: t.provider }),
2567
2635
  h('span', { className: 'num', textContent: ctx ? `${t.tested?.sure === false ? '~' : ''}${kTok(ctx)}` : '–', title: ctx ? `${ctx.toLocaleString()} tokens${t.tested?.sure === false ? ' (assumed: the server and models.dev don\'t say)' : ''}` : '' }),
2568
2636
  yes(c.tools), yes(c.thinking), yes(c.images),
@@ -2595,8 +2663,8 @@ function markCatalog() {
2595
2663
  function drawUsing(s) {
2596
2664
  const o = s.order.filter((t) => !isOff(t.provider))
2597
2665
  $('using').hidden = page() === 'providers' // there it's on the page itself
2598
- const fit = s.settings.modelChoice === 'fit' // best fit: no one model is "the one"
2599
- put($('using'), o.length && fit ? [h('span', { className: 'k', textContent: 'HeartCode picks' }), h('b', { textContent: 'the best for each task' }), h('span', { className: 'k', textContent: `from your ${o.length.toLocaleString()} model${o.length > 1 ? 's' : ''}` })]
2666
+ const fit = s.settings.modelChoice === 'fit' // an orchestrator: no one model is "the one"
2667
+ put($('using'), o.length && fit ? [h('span', { className: 'k', textContent: 'Orchestrated by' }), h('b', { textContent: leads(s).map((t) => t.model).join(', ') || o[0].model }), h('span', { className: 'k', textContent: `with your ${o.length.toLocaleString()} model${o.length > 1 ? 's' : ''}` })]
2600
2668
  : o.length ? [h('span', { className: 'k', textContent: 'HeartCode uses' }), h('b', { textContent: o[0].model }), h('span', { className: 'k', textContent: `${o[0].provider}${o.length > 1 ? ` · ${o.length - 1} fallback${o.length > 2 ? 's' : ''}` : ''}` })] : s.order.length ? [h('span', { className: 'k', textContent: 'The providers of all your models are switched off' }), h('a', { href: '#providers', textContent: 'Switch one on' })] : [h('span', { className: 'k', textContent: 'No model chosen yet' }), h('a', { href: '#providers', textContent: 'Choose one' })])
2601
2669
  }
2602
2670
 
package/src/settings.js CHANGED
@@ -372,6 +372,7 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
372
372
  update: (({ latest } = {}) => (cfg.updateCheck !== false && latest && newer(latest, VERSION) ? latest : null))(readJson(path.join(HOME, 'update-check.json'), {})), // the day's answer from npm: no request here
373
373
  order: [...(cfg.providers[cfg.provider] && cfg.model ? [{ provider: cfg.provider, model: cfg.model }] : []), ...rotationOf(cfg).then].map((t) => ({ ...t, tested: testedOf(t), known: knownOf(t), price: priceFor(t), ranks: ranksOf(t.model, ranked) })),
374
374
  rankings: ranked && { fetched: ranked.fetched, source: ranked.source },
375
+ orchestrators: cfg.orchestrators ?? [],
375
376
  rotation: (({ then, ...opts }) => opts)(rotationOf(cfg)),
376
377
  settings: { permissions: cfg.permissions ?? 'all', effort: cfg.effort ?? 'default', theme: cfg.theme ?? 'dark', context: cfg.context ?? null, ...Object.fromEntries(Object.keys(TOGGLES).map((k) => [k, cfg[k] !== false])), logs: kindsOn(cfg), logDetail: cfg.logDetail === 'summary' ? 'summary' : 'full', logDays: logDays(cfg), testTimeout: Number(cfg.testTimeout) > 0 ? Number(cfg.testTimeout) : 10, modelChoice: cfg.modelChoice === 'fit' ? 'fit' : 'order', replyStart: Number(cfg.replyStart) > 0 ? Number(cfg.replyStart) : 60 },
377
378
  logs: { runs: tilde(path.join(LOGS, 'runs')), requests: tilde(REQUESTS) },
@@ -555,6 +556,15 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
555
556
  forgetTests()
556
557
  return state()
557
558
  },
559
+ // The models that orchestrate when Pick is "an orchestrator hands it out": [{ provider, model }]
560
+ // (none: your first that calls tools)
561
+ 'POST /api/orchestrators': ({ list }) => {
562
+ if (!Array.isArray(list)) throw new Error('a list of models is needed')
563
+ const clean = list.map((t) => ({ provider: String(t?.provider ?? ''), model: String(t?.model ?? '').trim() })).filter((t) => cfg.providers[t.provider] && t.model)
564
+ cfg.orchestrators = clean.length ? clean : undefined
565
+ save('setting:orchestrators')
566
+ return state()
567
+ },
558
568
  // models.dev again (one model, or all of yours): its list fetched anew, and each model's profile
559
569
  // takes what it says now (one it didn't know before becomes "from models.dev"; your own settings
560
570
  // for it stay above). A running HeartCode takes it at once.
@@ -663,7 +673,7 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
663
673
  if (name === 'testTimeout' && !(Number.isInteger(value) && value >= 1 && value <= 600)) throw new Error('test timeout: a whole number of seconds, 1 to 600')
664
674
  if (name === 'replyStart' && !(Number.isInteger(value) && value >= 5 && value <= 600)) throw new Error('a reply must start within: a whole number of seconds, 5 to 600')
665
675
  if (!['permissions', 'effort', 'theme', 'context', 'logDetail', 'logDays', 'testTimeout', 'modelChoice', 'replyStart', ...Object.keys(TOGGLES)].includes(name)) throw new Error(`no setting "${name}"`)
666
- if (name === 'modelChoice' && !['order', 'fit'].includes(value)) throw new Error('modelChoice: order or fit')
676
+ if (name === 'modelChoice' && !['order', 'fit'].includes(value)) throw new Error('modelChoice: order or fit (an orchestrator)')
667
677
  cfg[name] = name === 'effort' && value === 'default' ? undefined : name === 'context' ? (value === null ? undefined : Number(value)) : value
668
678
  save(`setting:${name}`)
669
679
  if (name === 'logDetail') useRequestLog(cfg) // from the next request (a running HeartCode takes it in too: applySettings)
package/src/tools.js CHANGED
@@ -678,9 +678,9 @@ export function extraTools(s) {
678
678
  }
679
679
  if (!s.isSub && s.subagent) {
680
680
  const team = s.team?.() ?? []
681
- const model = { type: 'string', description: prompt('agent/tool-agent-model') }
681
+ const model = { type: 'string', description: prompt(s.orchestrating ? 'agent/tool-hand-model' : 'agent/tool-agent-model') }
682
682
  const images = { type: 'array', items: str, description: prompt('agent/tool-agent-images') }
683
- out.push({ name: 'agent', description: prompt('agent/tool-agent'), parameters: obj({ description: str, prompt: str, ...(team.length && { model, images }) }, ['description', 'prompt']) })
683
+ out.push({ name: 'agent', description: prompt(s.orchestrating ? 'agent/tool-hand' : 'agent/tool-agent'), parameters: obj({ description: str, prompt: str, ...(team.length && { model, images }) }, ['description', 'prompt']) })
684
684
  }
685
685
  return [...out, ...(s.director && !s.appendSystem ? s.director.toolDefs(s) : [])] // manage (director.js); not when a program gives the instructions (--append-system-prompt)
686
686
  }
@@ -1320,7 +1320,9 @@ function mcpTarget(s, name) {
1320
1320
 
1321
1321
  // Tools the caller allowed (--allowedTools) or took away (--disallowedTools); all by default. An
1322
1322
  // MCP tool goes by its own name, its server's (mcp__server, as in Claude Code) or "mcp" (all of them).
1323
+ // An orchestrator: only handing work out (and asking the user).
1323
1324
  export function allowed(s, name) {
1325
+ if (s.orchestrating && name !== 'agent' && name !== 'ask_user') return false
1324
1326
  const names = name.startsWith('mcp__') ? [name, name.split('__').slice(0, 2).join('__'), 'mcp'] : [name]
1325
1327
  if (names.some((n) => s.denyTools?.has(n))) return false
1326
1328
  if (!s.allowTools) return true
package/src/fit.js DELETED
@@ -1,65 +0,0 @@
1
- // "Best fit" (modelChoice: 'fit'): for each new message, your models ranked by how good each is at
2
- // what this message needs — by public rankings (rankings.js), not by a model's opinion of models.
3
- // One short request names the skills the task needs (web pages, code, images…); the rest is
4
- // arithmetic: who leads the work (and who next when one fails) and who reviews it (not the lead).
5
- // A model the rankings don't know comes after those they do, in your order. A message that only says to go on keeps the last pick.
6
- // "Your order" (the default): none of this — your list as you set it.
7
- import { prompt } from './prompts.js'
8
- import { log } from './log.js'
9
- import { rankings, score, SKILLS } from './rankings.js'
10
-
11
- const name = (t) => `${t.provider} ${t.model}`
12
- const GO_ON = /^\s*(continue|go on|carry on|keep going|resume|proceed|ok(ay)?|yes|do it|go ahead)\W*$/i
13
-
14
- // The skills this task needs, from SKILLS: { work: [...] } — asked of the model in use (naming
15
- // what a task needs is easy; judging models is what the rankings are for). ['coding'] when it can't say.
16
- async function skillsFor(s, task, signal) {
17
- const ask = prompt('agent/pick-skills', { task: task.slice(0, 1500), choices: (s.chat.choices ?? []).join('; '), skills: Object.entries(SKILLS).map(([k, [, , what]]) => `${k}: ${what}`).join('\n') })
18
- const was = s.client.purpose
19
- s.client.purpose = 'pick-skills'
20
- try {
21
- const said = (await s.client.chat({ messages: [{ role: 'user', content: ask }] }, { signal: AbortSignal.any([AbortSignal.timeout(30_000), ...(signal ? [signal] : [])]) })).content
22
- const line = /^\W*skills?\W*:\s*(.+)$/im.exec(said)?.[1] ?? said
23
- const named = Object.keys(SKILLS).filter((k) => new RegExp(`(^|[^\\w-])${k}($|[^\\w-])`, 'i').test(line))
24
- return named.length ? named : ['coding']
25
- } catch (e) {
26
- if (signal?.aborted) throw e
27
- log('fit', `no skills named (${e.message}): coding`)
28
- return ['coding']
29
- } finally {
30
- s.client.purpose = was
31
- }
32
- }
33
-
34
- // { work, review, why } (names, best first), kept in chat.fit; null when there's nothing to choose.
35
- export async function pickModels(s, task, signal, { images = 0, size = 0 } = {}) {
36
- const all = s.allModels?.() ?? []
37
- const can = all.filter((t) => t.tools && (!images || t.images) && (!size || !t.context || t.context > size * 1.2))
38
- if (can.length < 2) return null
39
- if (GO_ON.test(task) && s.chat.fit) return s.chat.fit // the same work: the same models (and the provider's cache still holds)
40
- const data = await rankings({ signal, onWait: () => s.ui.spinner('getting the model rankings (once a week)') })
41
- s.ui.stopSpin()
42
- if (!data) return null
43
- s.ui.spinner('what does this task need')
44
- const skills = await skillsFor(s, task, signal)
45
- s.ui.stopSpin()
46
- if (images && !skills.includes('vision')) skills.push('vision')
47
- // best first by score; not ranked: after, in your order
48
- const ranked = (models, wanted) =>
49
- models
50
- .map((t, i) => ({ t, i, sc: score(t.model, wanted, data) }))
51
- .sort((a, b) => (a.sc ?? 2) - (b.sc ?? 2) || a.i - b.i)
52
- const order = ranked(can, skills)
53
- const lead = name(order[0].t)
54
- const fit = {
55
- work: order.map((x) => name(x.t)),
56
- review: ranked(can, ['coding', 'hard']).filter((x) => x.sc != null).map((x) => name(x.t)).filter((n) => n !== lead).slice(0, 2),
57
- why: skills.join(', '),
58
- }
59
- log('fit', { skills, scores: order.slice(0, 8).map((x) => `${x.t.model} ${x.sc == null ? 'not ranked' : x.sc.toFixed(2)}`), review: fit.review })
60
- s.chat.fit = fit
61
- return fit
62
- }
63
-
64
- // Others (reviewers, page checkers) in the pick's order, the rest after in your list's order.
65
- export const byPick = (models, names = []) => [...models].sort((a, b) => ((names.indexOf(name(a)) + 1 || 1e9) - (names.indexOf(name(b)) + 1 || 1e9)))