heartcode 0.1.58 → 0.1.59

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/src/settings.html CHANGED
@@ -966,7 +966,7 @@
966
966
  <select id="g-effort"></select>
967
967
  </div>
968
968
  <div class="setting">
969
- <label class="t" for="g-context"><b>Context window</b><span>How many tokens the model can hold. Leave it on auto unless HeartCode gets it wrong.</span></label>
969
+ <label class="t" for="g-context"><b>Context window</b><span>How many tokens the model can hold. Leave it on auto unless HeartCode gets it wrong: a number here is used for every model, over each model's own.</span></label>
970
970
  <input type="number" id="g-context" min="1" placeholder="Auto">
971
971
  </div>
972
972
  </div>
@@ -1125,7 +1125,7 @@
1125
1125
  </dialog>
1126
1126
  <dialog id="h-test" aria-labelledby="h-test-title">
1127
1127
  <h2 id="h-test-title">Test your models first</h2>
1128
- <p class="sub">Helpers are picked from the models that answer a short test. None of yours has been tested yet.</p>
1128
+ <p class="sub">Helpers are picked from the models that answer a short test. None of yours has answered one yet.</p>
1129
1129
  <p class="sub" id="h-test-cost"></p>
1130
1130
  <div class="actions"><span class="spacer"></span><button id="h-test-no" type="button" class="ghost">Cancel</button><button id="h-test-go" type="button" class="primary">Test all, then pick</button></div>
1131
1131
  </dialog>
@@ -2594,11 +2594,11 @@ function drawMine(s) {
2594
2594
  const secsCell = (label, name, about, unit, said) => cell(label, about, num(name, label, said), h('span', { className: 'unit', textContent: unit }))
2595
2595
  const settings = h('div', { className: 'mt-sets', inert: busy },
2596
2596
  h('div', { className: 'mt-mode-sets' },
2597
- 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 the next model (another provider's first)",
2597
+ cell('If one fails', ro.on === 'retries' ? 'a rate limit or outage: that model gets that many tries in all before the next one; any other error moves on at once' : "any error moves on at once, to the next model (after an error from its provider: another provider's first)",
2598
2598
  h('select', { onchange: (e) => saveOrder(S.order, 'saved', { on: e.target.value }) },
2599
2599
  [['failure', 'go to the next'], ['retries', 'retry it first']].map(([v, t]) => h('option', { value: v, textContent: t, selected: ro.on === v }))),
2600
2600
  ro.on === 'retries' ? h('input', { type: 'number', className: 'tries', 'aria-label': 'tries', title: 'tries of the same model first (rate limits, outages)', min: 1, max: 20, value: ro.retries, onchange: (e) => saveOrder(S.order, 'saved', { retries: Number(e.target.value) }) }) : null),
2601
- secsCell('Give up after', 'replyStart', "a model that hasn't started answering (text, thinking or a tool call) in this many seconds counts as failed", 'sec', (v) => `a model that hasn't started answering in ${v}s counts as failed`),
2601
+ secsCell('Give up after', 'replyStart', "a model that hasn't started answering (text, thinking or a tool call) in this many seconds counts as failed (a streamed reply: a model set up without streaming waits for its whole reply)", 'sec', (v) => `a model that hasn't started answering in ${v}s counts as failed`),
2602
2602
  secsCell('Stalled after', 'replyIdle', 'a reply that stops sending anything for this many seconds is stalled: tried again, or the next model', 'sec', (v) => `a reply silent for ${v}s counts as stalled`),
2603
2603
  cell('Tests wait', 'how long a test waits for each answer',
2604
2604
  h('input', { type: 'number', className: 'tries', min: 1, max: 600, step: 1, value: S.settings.testTimeout ?? 10, 'aria-label': 'Test timeout in seconds', onchange: (e) => {
@@ -2620,7 +2620,7 @@ function drawMine(s) {
2620
2620
  order.length > 1 ? drawHelperBar() : null,
2621
2621
  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, and how fast`, onclick: () => tryAll(filtered ? shown : order) }),
2622
2622
  // not on the helpers' view: they're not a list to keep only
2623
- filtered && FILTER.helpers ? null : h('button', { className: 'small primary', textContent: filtered ? `Use only these ${n(view.length)}` : 'Save list', 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' : 'save your list as shown: HeartCode uses them in this order (#1 first)', onclick: saveList }))
2623
+ filtered && FILTER.helpers ? null : h('button', { className: 'small primary', textContent: filtered ? `Use only these ${n(view.length)}` : 'Save list', disabled: !view.length || order.length < 2, title: filtered ? `HeartCode uses only these ${n(view.length)}, in the order shown (the others stay under Providers)` : 'save your list as shown: HeartCode uses them in this order (#1 first)', onclick: saveList }))
2624
2624
 
2625
2625
  // --- the table ---
2626
2626
  const all = view.length > 0 && view.every((t) => PICKED.has(keyOf(t)))
@@ -2777,7 +2777,7 @@ function helperCell(t, at) {
2777
2777
  const sug = HSUG?.[k] ?? []
2778
2778
  const busy = locked()
2779
2779
  return h('span', { className: 'hp' + (jobs ? '' : ' off') },
2780
- h('span', { className: SAVING.has(`${k}|on`) ? 'saving' : '', title: jobs ? 'a helper: #1 can start it for side jobs (click: not a helper)' : 'not a helper (click: #1 can start it for side jobs)' },
2780
+ h('span', { className: SAVING.has(`${k}|on`) ? 'saving' : '', title: jobs ? 'a helper: #1 can start it for side jobs (click: not a helper)' : Object.keys(helpers()).length ? 'not a helper (click: #1 can start it for side jobs)' : 'no helpers ticked: #1 can start any of your models (click: only the ones you tick)' },
2781
2781
  sw({ checked: Boolean(jobs), disabled: busy, 'aria-label': `${t.model} is a helper`, onchange: (e) => setHelper(k, e.target.checked ? (jobs ?? []) : null, 'on') })),
2782
2782
  Object.entries(S.jobs ?? {}).map(([j, [label, , covers]]) => {
2783
2783
  const has = Boolean(jobs?.includes(j))
@@ -2789,13 +2789,13 @@ function helperCell(t, at) {
2789
2789
  h('div', { className: 'tjob', textContent: label }),
2790
2790
  h('div', { className: 'tcover', textContent: covers }),
2791
2791
  sugd ? h('div', { className: 'tcover', textContent: `Suggested from ${SUGGEST_WHY[j]}.` }) : null,
2792
- S.helpersAuto && has ? h('div', { className: 'tcover', textContent: 'Picked for you, from the rankings, tests and prices.' }) : null,
2792
+ S.helpersAuto && has ? h('div', { className: 'tcover', textContent: 'Picked for you, from the rankings and the tests.' }) : null,
2793
2793
  h('div', { className: 'thint', textContent: (has ? `Click: ${t.model} isn't picked for this any more` : `Click: #1 gives these jobs to ${t.model}${jobs ? '' : ' (it becomes a helper)'}`) + (S.helpersAuto ? ' · from then on, you pick' : '') }),
2794
2794
  ])
2795
2795
  }))
2796
2796
  }
2797
2797
  // what each pill's suggestions go by (said in its tooltip)
2798
- const SUGGEST_WHY = { ui: 'its place in the top half of the web-app ranking (LMArena)', code: 'its place in the top half of the coding ranking (LMArena)', hard: 'it thinks with a context of 128k or more, or its place in the top half of the ranking for long real tasks or the hardest prompts (LMArena)', quick: 'its test: faster than most of yours (or nothing else fits it)' }
2798
+ const SUGGEST_WHY = { ui: 'its place in the top half of the web-app ranking (LMArena)', code: 'its place in the top half of the coding ranking (LMArena)', hard: 'it thinks with a context of 128k or more, or its place in the top half of the ranking for long real tasks or the hardest prompts (LMArena)', quick: 'its test: as fast as the middle one of yours or faster (or nothing else fits it)' }
2799
2799
  // Helpers are picked from the models that answered their test: how many did
2800
2800
  const working = () => S.order.filter((t) => TRIES[keyOf(t)]?.ok && !TRIES[keyOf(t)].going).length
2801
2801
  // No test yet: ask before testing them all (each gets a short message, which a paid model charges for);
@@ -2805,7 +2805,7 @@ function testFirst(then) {
2805
2805
  const n = (x) => x.toLocaleString()
2806
2806
  const paid = S.order.filter((t) => t.price && (t.price.input > 0 || t.price.output > 0)).length
2807
2807
  const unknown = S.order.filter((t) => !t.price).length
2808
- $('h-test-cost').textContent = `Test all sends each of your ${n(S.order.length)} models a short message. ${paid ? `${n(paid)} of them aren't free: each charges for its few tokens. ` : ''}${unknown ? `${n(unknown)} have no price we know of, and may charge too. ` : ''}When it's done, helpers are picked from the ones that worked.`
2808
+ $('h-test-cost').textContent = `Test all sends each of your ${n(S.order.length)} models a short message. ${paid ? `${n(paid)} of them aren't free: each charges for its few tokens. ` : ''}${unknown ? `${n(unknown)} have no price we know of, and may charge too. ` : ''}When it's done, helpers are ${then === 'suggest' ? 'suggested' : 'picked'} from the ones that worked.`
2809
2809
  $('h-test-go').onclick = () => {
2810
2810
  $('h-test').close()
2811
2811
  afterTests = then
@@ -2860,11 +2860,11 @@ function drawHelperBar() {
2860
2860
  saveHelpers(next, [], `${took.length} model${took.length === 1 ? ' is a helper' : 's are helpers'} now`).then(() => drawMine(S))
2861
2861
  } }),
2862
2862
  h('button', { className: 'small ghost', textContent: 'Dismiss', onclick: () => ((HSUG = null), drawMine(S)) })) : null,
2863
- !HSUG && !S.helpersAuto ? h('button', { className: 'small', title: working() ? `suggest all ${working()} models that answered their test as helpers, each with what it's good at (from the rankings, its test, thinking and context): you see them first, then take them or not` : 'suggest helpers: your models are tested first (helpers are picked from the ones that answer)', onclick: (e) => (working() ? suggestNow(e.currentTarget) : testFirst('suggest')) }, ic('sparkles'), 'Suggest helpers') : null,
2864
- !HSUG && n ? h('button', { className: 'small ghost', textContent: 'Clear helpers', title: `none of your models a helper (${n} now): helpers run on the model that answers`, onclick: (e) => {
2865
- if (!confirm(`Clear your ${n} helper${n === 1 ? '' : 's'}? Helpers then run on the model that answers.`)) return
2863
+ !HSUG && !S.helpersAuto ? h('button', { className: 'small', title: working() ? `suggest helpers from the ${working()} models that answered their test (their provider switched on), each with what it's good at that it doesn't have yet (from the rankings, its test, thinking and context): you see them first, then take them or not` : 'suggest helpers: your models are tested first (helpers are picked from the ones that answer)', onclick: (e) => (working() ? suggestNow(e.currentTarget) : testFirst('suggest')) }, ic('sparkles'), 'Suggest helpers') : null,
2864
+ !HSUG && n ? h('button', { className: 'small ghost', textContent: 'Clear helpers', title: `none of your models a helper (${n} now): #1 can then start any of your models again, as before`, onclick: (e) => {
2865
+ if (!confirm(`Clear your ${n} helper${n === 1 ? '' : 's'}? #1 can then start any of your models again, as before.`)) return
2866
2866
  busy(e.currentTarget)
2867
- saveHelpers({}, [], 'no helpers: they run on the model that answers').then(() => (FILTER.helpers ? setFilter({ helpers: false }) : drawMine(S))) // no helpers left to show only
2867
+ saveHelpers({}, [], 'no helpers: #1 can start any of your models again').then(() => (FILTER.helpers ? setFilter({ helpers: false }) : drawMine(S))) // no helpers left to show only
2868
2868
  } }) : null)
2869
2869
  return helperBar
2870
2870
  }
package/src/settings.js CHANGED
@@ -55,7 +55,7 @@ const DETAILS = ['full', 'summary']
55
55
  const FILES = [
56
56
  ['mcp.json', 'MCP servers: programs that give the model more tools', true, '{\n "mcpServers": {\n "github": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-github"] },\n "docs": { "url": "https://mcp.example.com/mcp" }\n }\n}'],
57
57
  ['hooks.json', 'Your commands, run before or after the model uses a tool (one can block it)', true, '{\n "hooks": {\n "PreToolUse": [\n { "matcher": "run_command", "hooks": [{ "type": "command", "command": "./check-command.sh" }] }\n ]\n }\n}'],
58
- ['keybindings.json', 'Your own keys: an action, or a /command to send', true, '{\n "alt+o": "cycle_permissions",\n "alt+g": "/toggle_thinking"\n}'],
58
+ ['keybindings.json', 'Your own keys: an action, or a /command to send', true, '{\n "alt+g": "cycle_permissions",\n "alt+r": "/rewind"\n}'],
59
59
  ['theme.json', 'Your own colors, on top of the theme you chose', true, '{\n "brand": "#ff6b9d",\n "background": "#101014"\n}'],
60
60
  ['format.json', 'The formatter to run on each kind of file HeartCode writes', true, '{\n ".go": "gofmt -w {file}",\n ".py": "ruff format {file}"\n}'],
61
61
  ['HEARTCODE.md', 'Your instructions for every project (like AGENTS.md, for all of them)', false, '- Answer briefly.\n- Use pnpm, not npm.'],
@@ -675,7 +675,11 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
675
675
  // for it stay above). A running HeartCode takes it at once.
676
676
  // Test: one short message to the model, to see that it answers (key, access, name, the server
677
677
  // itself). In the requests log as a model test. Never throws: { ok, ms, reply } or { ok: false, error }.
678
- 'POST /api/try': ({ provider, model } = {}) => testOne({ provider, model: String(model ?? '') }),
678
+ 'POST /api/try': async ({ provider, model } = {}) => {
679
+ const r = await testOne({ provider, model: String(model ?? '') })
680
+ if (autoPick()) emit('helpers', { helpers: helpersOf(cfg.helpers) }) // picked for you: what this test found counts
681
+ return r
682
+ },
679
683
  // Test, on a model's row: one "Hello" to it, and exactly what was sent and what came back (the
680
684
  // key masked), for the page to show. Not streamed, so the answer is the provider's own JSON.
681
685
  'POST /api/hello': async ({ provider, model }) => {
@@ -748,6 +752,7 @@ export function startSettings({ cfg, apply = () => {}, port = 0, root = process.
748
752
  writeJson(profilePath(c), p)
749
753
  changed('profile')
750
754
  testNews(`${provider}/${t.model}`, t)
755
+ autoPick() // picked for you: what it can do now counts (thinking, context)
751
756
  return state()
752
757
  },
753
758
  // Measure a tested model's window: one oversized request (client.measureContext); the limit the
package/src/tabs.js CHANGED
@@ -139,7 +139,10 @@ export class Tabs {
139
139
  bottom += (on ? c.brand(`╯${' '.repeat(w)}╰`) : c.ghost(`┴${'─'.repeat(w)}┴`)) + c.ghost('─')
140
140
  })
141
141
  // the keys that fit whole, the rest left out (never one cut in the middle)
142
- const hints = this.list.length > 1 ? ['Alt+T open a tab', 'Alt+W close this one', 'Alt+N/P switch tabs'] : ['Alt+T open a new tab']
142
+ // as keybindings.json has them now (one moved or turned off: said so, or left out)
143
+ const k = (a) => this.at?.ui.keyFor?.(a)
144
+ const sw = [k('next_tab'), k('prev_tab')].filter(Boolean).join('/')
145
+ const hints = (this.list.length > 1 ? [k('new_tab') && `${k('new_tab')} open a tab`, k('close_tab') && `${k('close_tab')} close this one`, sw && `${sw} switch tabs`] : [k('new_tab') && `${k('new_tab')} open a new tab`]).filter(Boolean)
143
146
  let hint = ''
144
147
  for (const h of hints) if (width(mid.replace(/\x1b\[[0-9;]*m/g, '')) + 1 + width(hint ? `${hint} · ${h}` : h) <= cols - 1) hint = hint ? `${hint} · ${h}` : h
145
148
  if (hint) mid += ` ${c.faint(hint)}`
package/src/tools.js CHANGED
@@ -466,7 +466,7 @@ export function searchesOutside(cmd, root) {
466
466
  // Waited on for `wait` seconds (the model's choice): finished by then, its exit code and output;
467
467
  // still running, it carries on in the background, and the model checks on it when it likes.
468
468
  export async function runConfirmed(s, cmd, signal, background = false, wait) {
469
- s.ui.step(background ? 'run in background' : 'run', cmd)
469
+ s.ui.step(background ? 'run in background' : 'run', cmd, s.client?.model)
470
470
  if (s.ui.permission === 'plan' && !readOnlyCommand(cmd)) {
471
471
  s.ui.result('not run: plan mode')
472
472
  return prompt('agent/plan-refused', { command: true })
@@ -609,22 +609,23 @@ export function writeResult(rel, r) {
609
609
  const str = { type: 'string' }
610
610
  const int = { type: 'integer' }
611
611
  const obj = (properties, required = []) => ({ type: 'object', properties, required })
612
+ // (descriptions read each time: a project's own prompts and the settings page's edits apply at once)
612
613
  export const TOOL_DEFS = [
613
- { name: 'read_file', description: prompt('agent/tool-read_file'), parameters: obj({ path: str, start_line: int, end_line: int }, ['path']) },
614
- { name: 'search', description: prompt('agent/tool-search'), parameters: obj({ query: str, path: str }, ['query']) },
615
- { name: 'changes', description: prompt('agent/tool-changes'), parameters: obj({ path: str, all: { type: 'boolean' } }) },
616
- { name: 'list_files', description: prompt('agent/tool-list_files'), parameters: obj({ path: str, filter: str }) },
617
- { name: 'find_command', description: prompt('agent/tool-find_command'), parameters: obj({ names: { type: 'array', items: str } }, ['names']) },
618
- { name: 'lsp', description: prompt('agent/tool-lsp'), parameters: obj({ server: str, language: str, action: { type: 'string', enum: ['definition', 'references', 'hover', 'errors'] }, file: str, line: int, column: int, name: str }, ['server', 'language', 'action', 'file']) },
614
+ { name: 'read_file', get description() { return prompt('agent/tool-read_file') }, parameters: obj({ path: str, start_line: int, end_line: int }, ['path']) },
615
+ { name: 'search', get description() { return prompt('agent/tool-search') }, parameters: obj({ query: str, path: str }, ['query']) },
616
+ { name: 'changes', get description() { return prompt('agent/tool-changes') }, parameters: obj({ path: str, all: { type: 'boolean' } }) },
617
+ { name: 'list_files', get description() { return prompt('agent/tool-list_files') }, parameters: obj({ path: str, filter: str }) },
618
+ { name: 'find_command', get description() { return prompt('agent/tool-find_command') }, parameters: obj({ names: { type: 'array', items: str } }, ['names']) },
619
+ { name: 'lsp', get description() { return prompt('agent/tool-lsp') }, parameters: obj({ server: str, language: str, action: { type: 'string', enum: ['definition', 'references', 'hover', 'errors'] }, file: str, line: int, column: int, name: str }, ['server', 'language', 'action', 'file']) },
619
620
  // One edit per call: a list of edits per call measured 2–6 malformed calls per benchmark run vs 0.
620
- { name: 'edit_file', description: prompt('agent/tool-edit_file'), parameters: obj({ path: str, search: str, replace: str, start_line: int, end_line: int }, ['path', 'replace']) },
621
- { name: 'write_file', description: prompt('agent/tool-write_file'), parameters: obj({ path: str, content: str, append: { type: 'boolean' } }, ['path', 'content']) },
622
- { name: 'run_command', description: prompt('agent/tool-run_command'), parameters: obj({ command: str, wait: int, background: { type: 'boolean' } }, ['command']) },
623
- { name: 'background', description: prompt('agent/tool-background'), parameters: obj({ action: { type: 'string', enum: ['output', 'list', 'stop'] }, id: int, wait: int }, ['action']) },
624
- { name: 'todo', description: prompt('agent/tool-todo'), parameters: obj({ todos: { type: 'array', items: obj({ content: str, status: { type: 'string', enum: ['pending', 'in_progress', 'completed'] }, parallel: { type: 'boolean' }, model: str, files: { type: 'array', items: str } }, ['content', 'status']) } }, ['todos']) },
625
- { name: 'web_search', description: prompt('agent/tool-web_search'), parameters: obj({ query: str, fresh: { type: 'boolean' } }, ['query']) },
626
- { name: 'web_fetch', description: prompt('agent/tool-web_fetch'), parameters: obj({ url: str, look_for: str, start: int }, ['url']) },
627
- { name: 'ask_user', description: prompt('agent/tool-ask_user'), parameters: obj({ question: str, header: str, options: { type: 'array', items: str }, multiple: { type: 'boolean' }, emphasis: { type: 'boolean' } }, ['question', 'options']) }, // one question a call (small models manage that); several calls in one reply are one dialog (agent.js)
621
+ { name: 'edit_file', get description() { return prompt('agent/tool-edit_file') }, parameters: obj({ path: str, search: str, replace: str, start_line: int, end_line: int }, ['path', 'replace']) },
622
+ { name: 'write_file', get description() { return prompt('agent/tool-write_file') }, parameters: obj({ path: str, content: str, append: { type: 'boolean' } }, ['path', 'content']) },
623
+ { name: 'run_command', get description() { return prompt('agent/tool-run_command') }, parameters: obj({ command: str, wait: int, background: { type: 'boolean' } }, ['command']) },
624
+ { name: 'background', get description() { return prompt('agent/tool-background') }, parameters: obj({ action: { type: 'string', enum: ['output', 'list', 'stop'] }, id: int, wait: int }, ['action']) },
625
+ { name: 'todo', get description() { return prompt('agent/tool-todo') }, parameters: obj({ todos: { type: 'array', items: obj({ content: str, status: { type: 'string', enum: ['pending', 'in_progress', 'completed'] }, parallel: { type: 'boolean' }, model: str, files: { type: 'array', items: str } }, ['content', 'status']) } }, ['todos']) },
626
+ { name: 'web_search', get description() { return prompt('agent/tool-web_search') }, parameters: obj({ query: str, fresh: { type: 'boolean' } }, ['query']) },
627
+ { name: 'web_fetch', get description() { return prompt('agent/tool-web_fetch') }, parameters: obj({ url: str, look_for: str, start: int }, ['url']) },
628
+ { name: 'ask_user', get description() { return prompt('agent/tool-ask_user') }, parameters: obj({ question: str, header: str, options: { type: 'array', items: str }, multiple: { type: 'boolean' }, emphasis: { type: 'boolean' } }, ['question', 'options']) }, // one question a call (small models manage that); several calls in one reply are one dialog (agent.js)
628
629
  ]
629
630
 
630
631
  // Plan mode (permission "plan"): looking around is fine, changing things isn't. Edits are refused,
@@ -699,7 +700,7 @@ export function extraTools(s) {
699
700
  const team = s.team?.() ?? []
700
701
  const model = { type: 'string', description: team.some((t) => t.jobs) ? 'Which helper does the job ("provider model" from "Your helpers"). Left out: the first helper.' : 'Which of your models does the job ("provider model" from "Your other models"). Left out: yours, or with images you can\'t see, the first of yours that can.' }
701
702
  const images = { type: 'array', items: str, description: 'Image paths or URLs for the helper to look at. Needs a model that sees images.' }
702
- out.push({ name: 'agent', description: prompt('agent/tool-agent'), parameters: obj({ description: str, prompt: str, ...(team.length && { model, images }) }, ['description', 'prompt']) })
703
+ out.push({ name: 'agent', get description() { return prompt('agent/tool-agent') }, parameters: obj({ description: str, prompt: str, ...(team.length && { model, images }) }, ['description', 'prompt']) })
703
704
  }
704
705
  return [...out, ...(s.director && !s.appendSystem ? s.director.toolDefs(s) : [])] // manage (director.js); not when a program gives the instructions (--append-system-prompt)
705
706
  }
@@ -709,13 +710,22 @@ export function extraTools(s) {
709
710
  const MARK = { pending: '☐', in_progress: '◐', completed: '☑' }
710
711
  // In the conversation: the whole plan when it's new (or its steps changed), else only the steps whose
711
712
  // status changed, on one line; the whole of it stays in sight under the spinner (full screen).
713
+ // the plan for a program reading HeartCode (headless stream-json): its steps, and who's doing a part
714
+ export const sendTodos = (s) => !s.isSub && s.ui.event?.({ subtype: 'todos', todos: (s.chat.todos ?? []).map(({ content, status, by, byProvider }) => ({ content, status, ...(by && { by: byProvider ? `${byProvider}/${by}` : by }) })) })
712
715
  function showTodos(s, before, todos) {
713
716
  const paint = { pending: c.muted, in_progress: (x) => c.info(c.bold(x)), completed: (x) => c.faint(x) }
714
- const item = (t) => paint[t.status](`${MARK[t.status]} ${t.content}`)
715
- const same = s.ui.full && before?.length === todos.length && before.every((t, i) => t.content === todos[i].content)
716
- if (!same) return s.ui.print(todos.map((t) => ` ${item(t)}`).join('\n') || c.faint(' (todo list cleared)'))
717
- const moved = todos.filter((t, i) => t.status !== before[i].status)
718
- if (moved.length) s.ui.print(` ${moved.map(item).join(c.faint(' · '))}`)
717
+ const item = (t) => paint[t.status](`${MARK[t.status]} ${t.content}`) + (t.by ? c.faint(` · ${t.by}`) : '')
718
+ // full screen, the same plan changed (most of its steps still in it): only what changed, on one line
719
+ // (steps added, taken out, or whose status moved); the whole plan is pinned under the spinner
720
+ const was = new Map((before ?? []).map((t) => [t.content, t.status]))
721
+ const kept = todos.filter((t) => was.has(t.content)).length
722
+ if (!s.ui.full || !before?.length || kept < Math.max(1, todos.length / 2)) return s.ui.print(todos.map((t) => ` ${item(t)}`).join('\n') || c.faint(' (todo list cleared)'))
723
+ const now = new Set(todos.map((t) => t.content))
724
+ const changes = [
725
+ ...todos.filter((t) => was.get(t.content) !== t.status).map((t) => (was.has(t.content) ? item(t) : `${c.faint('+')} ${item(t)}`)),
726
+ ...(before ?? []).filter((t) => !now.has(t.content)).map((t) => c.faint(`− ${t.content}`)),
727
+ ]
728
+ if (changes.length) s.ui.print(` ${changes.join(c.faint(' · '))}`)
719
729
  }
720
730
  async function todoTool(s, args, signal, id) {
721
731
  let list = args.todos ?? args.items ?? args
@@ -731,8 +741,10 @@ async function todoTool(s, args, signal, id) {
731
741
  .map((t) => (typeof t === 'string' ? { content: t, status: 'pending' } : { content: String(t?.content ?? t?.task ?? t?.title ?? ''), status: String(t?.status ?? 'pending'), ...(t?.model && { model: String(t.model) }), ...((t?.parallel === true || t?.parallel === 'true') && { parallel: true }), ...([t?.files ?? []].flat().filter(Boolean).length && { files: [t.files].flat().map(String) }) }))
732
742
  .filter((t) => t.content.trim())
733
743
  .map((t) => ({ ...t, status: /done|complete/i.test(t.status) ? 'completed' : /progress|doing|active/i.test(t.status) ? 'in_progress' : 'pending' }))
744
+ for (const t of todos) Object.assign(t, ((x) => (x?.by && !t.by ? { by: x.by, byProvider: x.byProvider } : {}))(s.chat.todos?.find((x) => x.content === t.content))) // the model a part was given to: kept when the plan is written again
734
745
  showTodos(s, s.chat.todos, todos)
735
746
  s.chat.todos = todos
747
+ sendTodos(s)
736
748
  s.todoTouched = true
737
749
  const parts = await runParts(s, todos, signal, id)
738
750
  const done = todos.filter((t) => t.status === 'completed').length
@@ -755,7 +767,8 @@ async function runParts(s, todos, signal, id) {
755
767
  const parts = todos.filter((t) => t.status === 'pending' && (t.parallel || t.model))
756
768
  if (!parts.length || s.isSub || !s.subagent || s.ui.permission === 'plan') return ''
757
769
  // a model that isn't one of yours (a name made up, the product's own name): the part runs on this one
758
- const yours = [{ provider: s.client?.provider, model: s.client?.model }, ...(s.team?.() ?? [])]
770
+ const team = s.team?.() ?? []
771
+ const yours = [{ provider: s.client?.provider, model: s.client?.model }, ...(team.some((t) => t.jobs) ? team.filter((t) => t.jobs) : team)] // with helpers ticked: those (only they can be started)
759
772
  const known = (m) => yours.some((y) => `${y.provider} ${y.model}` === m || y.model === m || m.endsWith(` ${y.model}`))
760
773
  const unknown = [...new Set(parts.filter((t) => t.model && !known(t.model)).map((t) => t.model))]
761
774
  for (const t of parts) if (t.model && !known(t.model)) delete t.model
@@ -770,7 +783,7 @@ async function runParts(s, todos, signal, id) {
770
783
  const brief = prompt('agent/part', { task: s.task ?? '', plan, part: t.content, files: (t.files ?? []).join(', '), choices })
771
784
  let out
772
785
  try {
773
- out = await s.subagent({ prompt: brief, model: t.model, description: clip(t.content, 40), ownFiles: t.files }, signal, id)
786
+ out = await s.subagent({ prompt: brief, model: t.model, description: clip(t.content, 40), ownFiles: t.files, part: t }, signal, id) // part: its model is noted on it (by)
774
787
  } catch (e) {
775
788
  if (e.name === 'AbortError' || signal?.aborted) throw e
776
789
  out = `error: ${e.message}`
@@ -781,6 +794,7 @@ async function runParts(s, todos, signal, id) {
781
794
  )
782
795
  s.chat.todos = todos
783
796
  showTodos(s, shown, todos)
797
+ sendTodos(s)
784
798
  return prompt('agent/parts-done', { reports: reports.join('\n\n'), unknown: unknown.join(', '), models: yours.map((y) => `${y.provider} ${y.model}`).join(', ') })
785
799
  }
786
800
 
@@ -1403,7 +1417,7 @@ async function toolRun(name, args, s, signal, id) {
1403
1417
  const notMine = !pre.block && s.ownFiles && partPaths(name, args).find((f) => !s.ownFiles.includes(path.resolve(s.root, f)))
1404
1418
  const stop = pre.block ? prompt('agent/hook', { reason: pre.block, blocked: true }) : notMine ? prompt('agent/part-files', { file: notMine, files: s.ownFiles.map((f) => path.relative(s.root, f)).join(', ') }) : null
1405
1419
  if (stop && name === 'run_command') {
1406
- s.ui.step('run', String(args?.command ?? '')) // a command's lines are shown where it runs, which this one never reaches
1420
+ s.ui.step('run', String(args?.command ?? ''), s.client?.model) // a command's lines are shown where it runs, which this one never reaches
1407
1421
  s.ui.result(refusal(stop))
1408
1422
  }
1409
1423
  if (stop) return stop
@@ -1468,7 +1482,8 @@ async function tool(name, args, s, signal, id) {
1468
1482
  const v = folderView(root, String(args.path))
1469
1483
  return v.error ? `error: ${v.error}` : v.entries.join('\n') + (v.more ? `\n… ${v.more} more` : '') || '(empty folder)'
1470
1484
  }
1471
- const files = listFiles(root).filter((f) => !args.filter || f.includes(args.filter))
1485
+ const under = String(args.path ?? '').replace(/^\.?\/+|\/+$/g, '') // with a filter too: the files under that folder that match
1486
+ const files = listFiles(root).filter((f) => (!under || under === '.' || f === under || f.startsWith(`${under}/`)) && (!args.filter || f.includes(args.filter)))
1472
1487
  return files.slice(0, 500).join('\n') + (files.length > 500 ? `\n… ${files.length - 500} more` : '') || 'no files'
1473
1488
  }
1474
1489
  case 'search':