heartcode 0.1.69 → 0.1.101
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 +313 -0
- package/README.md +13 -8
- package/SKILL.md +5 -5
- package/bin/heartcode.js +88 -57
- package/package.json +1 -1
- package/prompts/README.md +1 -0
- package/prompts/agent.md +20 -9
- package/prompts/guides.md +168 -0
- package/src/acp.js +1 -1
- package/src/agent.js +156 -67
- package/src/background.js +4 -2
- package/src/capabilities.js +2 -3
- package/src/client.js +21 -3
- package/src/clis.js +601 -0
- package/src/config.js +15 -20
- package/src/edit.js +4 -1
- package/src/guard.js +88 -0
- package/src/guided.js +12 -7
- package/src/guides.js +73 -0
- package/src/headless.js +5 -2
- package/src/hooks.js +3 -2
- package/src/http.js +4 -2
- package/src/importer.js +12 -1
- package/src/mcp.js +12 -2
- package/src/probe.js +5 -1
- package/src/prompts.js +2 -1
- package/src/rankings.js +14 -4
- package/src/record.js +8 -0
- package/src/settings.html +464 -232
- package/src/settings.js +133 -54
- package/src/skills.js +2 -0
- package/src/tabs.js +1 -0
- package/src/tools.js +78 -38
- package/src/trust.js +49 -0
- package/src/ui.js +250 -144
- package/src/update.js +13 -9
- package/src/usage.js +13 -5
- package/src/voice.js +61 -13
- package/src/web.js +26 -4
package/src/agent.js
CHANGED
|
@@ -17,8 +17,9 @@ import { serversNote } from './lsp.js'
|
|
|
17
17
|
import { newlyEnded, jobLine } from './background.js'
|
|
18
18
|
import { loadHooks, runHooks } from './hooks.js'
|
|
19
19
|
import { takeConfigErrors, HELPER_JOBS } from './config.js'
|
|
20
|
-
import { c,
|
|
20
|
+
import { c, Block, Markdown, color, diffLines, renderDiff, STEP_NAMES } from './ui.js'
|
|
21
21
|
import { fetch } from './http.js' // not the built-in one: see http.js
|
|
22
|
+
import { detect, guideText, guideVars } from './guides.js'
|
|
22
23
|
|
|
23
24
|
// Images for a helper (the agent tool's "images"), as data: URLs: image URLs (fetched), data: URLs,
|
|
24
25
|
// or files: in the project, saved screenshots (OUTPUTS), or a path the user gave in a message.
|
|
@@ -277,7 +278,7 @@ export class Session {
|
|
|
277
278
|
record({ provider: t.provider ?? this.client.provider, model: t.model ?? this.client.model }, answer ? 'helped' : 'helper-failed') // its track record (record.js)
|
|
278
279
|
if (answer) return t === first ? answer : `(Answered by ${name(t)}, not ${name(first)}${failed.length ? `: ${failed.join('; ')}` : ''})\n\n${answer}`
|
|
279
280
|
if (failed.length < i + 1) failed.push(`${t.model}: no reply`)
|
|
280
|
-
if (order[i + 1]) this.ui.
|
|
281
|
+
if (order[i + 1]) this.ui.handover(order[i + 1].model, `${t.model} couldn't do it (${failed.at(-1).slice(t.model.length + 2)})`)
|
|
281
282
|
}
|
|
282
283
|
return `error: none of your models that can do it managed: ${failed.join('; ')}`
|
|
283
284
|
}
|
|
@@ -403,7 +404,7 @@ export class Session {
|
|
|
403
404
|
}
|
|
404
405
|
if (said) {
|
|
405
406
|
by = seer.model
|
|
406
|
-
this.ui.step('image', `${seer.model} described image ${i + 1}
|
|
407
|
+
this.ui.step('image', `${seer.model} described image ${i + 1}`, '', { note: true })
|
|
407
408
|
break
|
|
408
409
|
}
|
|
409
410
|
}
|
|
@@ -482,7 +483,7 @@ export class Session {
|
|
|
482
483
|
args = JSON.parse(call.function.arguments || '{}')
|
|
483
484
|
} catch {}
|
|
484
485
|
const out = (await extra?.run(call.function.name, args)) ?? (call.function.name === 'memory' ? await runTool('memory', args, this, signal) : `error: there is no tool named ${call.function.name}`)
|
|
485
|
-
if (call.function.name === 'memory' && (args.action === 'write' || args.action === 'delete') && !failed(out)) this.ui.step('memory', `${args.action === 'write' ? 'saved' : 'deleted'} ${out.match(/\[\[[^\]]+\]\]/)?.[0] ?? ''}${args.scope === 'global' ? ' (global)' : ''}
|
|
486
|
+
if (call.function.name === 'memory' && (args.action === 'write' || args.action === 'delete') && !failed(out)) this.ui.step('memory', `${args.action === 'write' ? 'saved' : 'deleted'} ${out.match(/\[\[[^\]]+\]\]/)?.[0] ?? ''}${args.scope === 'global' ? ' (global)' : ''}`, '', { note: true })
|
|
486
487
|
messages.push({ role: 'tool', tool_call_id: call.id, content: out })
|
|
487
488
|
}
|
|
488
489
|
}
|
|
@@ -563,7 +564,7 @@ export class Session {
|
|
|
563
564
|
} else fs.rmSync(path.join(this.root, rel), { force: true })
|
|
564
565
|
scratch.delete(rel)
|
|
565
566
|
removed.push(rel)
|
|
566
|
-
this.ui.step('cleanup', `removed ${rel}
|
|
567
|
+
this.ui.step('cleanup', `removed ${rel}`, '', { note: true })
|
|
567
568
|
return `Deleted ${rel}.`
|
|
568
569
|
}
|
|
569
570
|
}
|
|
@@ -572,7 +573,7 @@ export class Session {
|
|
|
572
573
|
const { client } = this.engineFor ? await this.engineFor(own) : { client: this.client }
|
|
573
574
|
const said = await this.memoryTask(prompt('agent/wrapup'), request, signal, { defs, run, client, purpose: 'wrapup' })
|
|
574
575
|
log('wrapup', `${said} | pages kept ${kept.length}, deleted ${dropped.length}; files removed ${removed.length}`)
|
|
575
|
-
if (kept.length || dropped.length) this.ui.step('research', `kept ${kept.length} page${kept.length === 1 ? '' : 's'}${dropped.length ? `, deleted ${dropped.length} as junk` : ''}
|
|
576
|
+
if (kept.length || dropped.length) this.ui.step('research', `kept ${kept.length} page${kept.length === 1 ? '' : 's'}${dropped.length ? `, deleted ${dropped.length} as junk` : ''}`, '', { note: true })
|
|
576
577
|
} catch (e) {
|
|
577
578
|
if (e.name === 'AbortError' || signal?.aborted) throw e
|
|
578
579
|
log('wrapup', `failed: ${e.message}`)
|
|
@@ -628,7 +629,7 @@ const SYSTEM = (s) => {
|
|
|
628
629
|
if (s.ownSystem) return [s.ownSystem, s.appendSystem].filter(Boolean).join('\n\n') // --system-prompt: only the program's
|
|
629
630
|
const instructions = userInstructions(s.root)
|
|
630
631
|
return [
|
|
631
|
-
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), see: Boolean(s.strat.vision), noUser: Boolean(s.ui.noUser || s.isSub), memory: Boolean(s.memory) && !s.isSub }), // models that can see often say they can't: told they can
|
|
632
|
+
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), see: Boolean(s.strat.vision), noUser: Boolean(s.ui.noUser || s.isSub), memory: Boolean(s.memory) && !s.isSub, doneFirst: !s.isSub && !s.ui.noUser && s.ui.permission !== 'plan' ? 'call done, then ' : '' }), // the done tool's there (askDone) // models that can see often say they can't: told they can
|
|
632
633
|
instructions && prompt('agent/instructions', { instructions }),
|
|
633
634
|
...[...(s.skills?.values() ?? [])].filter((k) => k.use === 'always').map(alwaysSkill), // skills that say how to work (use: always), with the files they bring
|
|
634
635
|
!s.isSub && teamPrompt(s),
|
|
@@ -938,7 +939,8 @@ async function runNative(s, task, images, signal) {
|
|
|
938
939
|
const said = ui.permission === 'plan' && !s.isSub ? `${text}\n\n${prompt('agent/plan-mode')}` : text
|
|
939
940
|
const content = images.length ? [{ type: 'text', text: said }, ...images.map((url) => ({ type: 'image_url', image_url: { url } }))] : said
|
|
940
941
|
s.messages.push({ role: 'user', content })
|
|
941
|
-
|
|
942
|
+
s.domainGuides = detect(s.root, task) // the guides for this kind of work, added once it starts on it (guidesFor)
|
|
943
|
+
if (!s.client.cli) attachNamed(s, task) // files the message names: as if already read (saves a round trip each); a coding CLI reads them itself
|
|
942
944
|
// the tools: built again each step (the model answering may change; client.js leaves them out for
|
|
943
945
|
// one that can't call tools; plan mode may be left mid-message)
|
|
944
946
|
const toolList = () => [...TOOL_DEFS, ...extraTools(s)].filter((f) => allowed(s, f.name) && !(ui.permission === 'plan' && PLAN_HIDDEN.has(f.name)) && !(f.name === 'ask_user' && (ui.noUser || s.isSub)) && !(f.name === 'done' && !askDone())).map((f) => ({ type: 'function', function: f })) // ask_user: not headless, nor a helper (it reports to the main agent, which asks)
|
|
@@ -968,7 +970,7 @@ async function runNative(s, task, images, signal) {
|
|
|
968
970
|
s.split = undefined // the user's answer this message: 'several' agents at once, or 'one' (tools.js)
|
|
969
971
|
s.lookedUp = s.researchAsked = false // searched or read the web this message / asked whether the plan needs it
|
|
970
972
|
// what changed and when it was last checked, this message: a change not run/tested since isn't done
|
|
971
|
-
Object.assign(s, { changed: new Set(), seq: 0, lastChangeAt: -1, lastCheckAt: -1, reviewedAt: -1, checksSince: 0, spots: new Map(), stuckReports: 0, stuckSelf: null, stuckHandovers: 0, troubles: [], unstuck: [], reviewedRan: 0, lastReview: null, gaveUp: new Set(), toldLast: false, unstuckLearned: false, provedAt: -1, proofFails: 0, shrunkTold: false, proofShots: [] })
|
|
973
|
+
Object.assign(s, { systemKey: null, changed: new Set(), seq: 0, lastChangeAt: -1, lastCheckAt: -1, reviewedAt: -1, checksSince: 0, spots: new Map(), stuckReports: 0, stuckSelf: null, stuckHandovers: 0, troubles: [], unstuck: [], reviewedRan: 0, lastReview: null, gaveUp: new Set(), toldLast: false, unstuckLearned: false, provedAt: -1, proofFails: 0, shrunkTold: false, proofShots: [] })
|
|
972
974
|
|
|
973
975
|
let empty = 0 // replies in a row with neither text nor tool calls
|
|
974
976
|
let lastFinal = '' // the last answer it gave (a next one the same, after being told it isn't done: it's stuck)
|
|
@@ -984,7 +986,7 @@ async function runNative(s, task, images, signal) {
|
|
|
984
986
|
record(client, 'handover') // its track record (record.js)
|
|
985
987
|
s.gaveUp.add(`${client.provider}/${was}`) // not gone back to this message, nor asked for a second opinion
|
|
986
988
|
if (strongest(s, client, `${was} ${why}`) || client.moveOn?.(`${was} ${why}`, s.gaveUp)) {
|
|
987
|
-
ui.
|
|
989
|
+
ui.handover(client.model, `${was} ${why}`)
|
|
988
990
|
// the next model sees the whole conversation: told it's taking over, and not to repeat what didn't work
|
|
989
991
|
s.messages.push({ role: 'user', content: prompt('agent/taken-over', { was, why, plan: (s.chat.todos ?? []).filter((t) => t.status !== 'completed').map((t) => `- ${t.content}${t.why ? ` (stuck: ${t.why})` : ''}`).join('\n') }) })
|
|
990
992
|
s.stuckReports = 0
|
|
@@ -1000,7 +1002,7 @@ async function runNative(s, task, images, signal) {
|
|
|
1000
1002
|
let refitted = false // this step's conversation was just compacted for a smaller model the list moved on to
|
|
1001
1003
|
// No step limit (helpers too): a long fix takes many steps, and Esc stops it. A caller can set one (--max-turns).
|
|
1002
1004
|
for (let step = 0; ; step++) {
|
|
1003
|
-
if (step && !s.isSub) s.onTurn?.() // saved
|
|
1005
|
+
if (step && !s.isSub && Date.now() - (s.savedAt ?? 0) > 5000) (s.savedAt = Date.now()), s.onTurn?.() // saved as it goes (every few seconds: a long chat is a big file): a quit, crash or kill mid-task loses little
|
|
1004
1006
|
const tools = toolList()
|
|
1005
1007
|
s.lastTools = tools // what the requests carry: the findings note before compacting sends the same (compact)
|
|
1006
1008
|
if (s.maxTurns && step >= s.maxTurns) {
|
|
@@ -1020,9 +1022,16 @@ async function runNative(s, task, images, signal) {
|
|
|
1020
1022
|
},
|
|
1021
1023
|
)
|
|
1022
1024
|
}
|
|
1023
|
-
// the
|
|
1024
|
-
|
|
1025
|
-
|
|
1025
|
+
// the system prompt: built once a message, and again when another model answers (your model list)
|
|
1026
|
+
// or the prompts changed. Not every step: a change mid-task (a new file at the root, a model's
|
|
1027
|
+
// track record) makes the provider read the whole conversation again (its cache is of the start)
|
|
1028
|
+
const sysKey = `${client.provider}/${client.model}`
|
|
1029
|
+
if (s.systemKey !== sysKey || s.refreshSystem) {
|
|
1030
|
+
s.systemKey = sysKey
|
|
1031
|
+
s.refreshSystem = false
|
|
1032
|
+
const now = SYSTEM(s)
|
|
1033
|
+
if (s.messages[0]?.content !== now && s.messages[0]?.role === 'system') s.messages[0] = { ...s.messages[0], content: now }
|
|
1034
|
+
}
|
|
1026
1035
|
pairTools(s.messages)
|
|
1027
1036
|
ui.spinner('thinking')
|
|
1028
1037
|
// named by the model that answers: opened at its first word (a failed one moves the list on
|
|
@@ -1031,7 +1040,8 @@ async function runNative(s, task, images, signal) {
|
|
|
1031
1040
|
const reply = () => (live ??= ui.response(client.model))
|
|
1032
1041
|
// a reply that may be the answer, with a review to come (files changed since the last one): its
|
|
1033
1042
|
// text is held and shown after the review's line, so the answer is what's last on screen
|
|
1034
|
-
|
|
1043
|
+
// (after being sent back: held too, so the same answer again isn't printed twice)
|
|
1044
|
+
const hold = !s.isSub && ((sinceNudge && s.changed?.size > 0 && s.lastChangeAt > (s.reviewedAt ?? 0) && ui.permission !== 'plan') || s.undeclaredSent || (!sinceNudge && nudged > 0))
|
|
1035
1045
|
const out = { think: (t) => reply().think(t), text: hold ? (t) => t?.trim() && ui.spinner('writing the answer') : (t) => reply().text(t), end: () => reply().end() }
|
|
1036
1046
|
const showHeld = (text) => {
|
|
1037
1047
|
if (!hold || !text?.trim()) return
|
|
@@ -1043,15 +1053,14 @@ async function runNative(s, task, images, signal) {
|
|
|
1043
1053
|
// A long tool call (a whole file) streams in silently: say what's being written.
|
|
1044
1054
|
const onToolDelta = (name, args) => {
|
|
1045
1055
|
const file = /"path"\s*:\s*"([^"]+)"/.exec(args)?.[1]
|
|
1046
|
-
const what = name === 'run_command' ? '
|
|
1047
|
-
ui.spinner(`${what}
|
|
1056
|
+
const what = name === 'run_command' ? 'writing a command' : EDITS.has(name) && file ? `writing ${file}` : `${{ read_file: 'reading', search: 'searching', list_files: 'listing', web_fetch: 'fetching', web_search: 'searching the web', todo: 'planning', agent: 'briefing a helper' }[name] ?? 'preparing'}${file ? ` ${file}` : ''}` // only an edit is "writing" a file
|
|
1057
|
+
ui.spinner(`${what}${args.length >= 2000 ? ` · ${(args.length / 1000).toFixed(1)}k characters` : '…'}`)
|
|
1048
1058
|
}
|
|
1049
|
-
// the prompts or HEARTCODE.md changed meanwhile (applySettings): the system prompt again, now
|
|
1050
|
-
if (s.refreshSystem && s.messages[0]?.role === 'system') s.messages[0] = { ...s.messages[0], content: SYSTEM(s) }
|
|
1051
|
-
s.refreshSystem = false
|
|
1052
1059
|
let res
|
|
1053
1060
|
try {
|
|
1054
|
-
|
|
1061
|
+
// a coding CLI (clis.js) works on the message itself: its steps shown as they come, each after the words before it
|
|
1062
|
+
const cliStep = (name, detail) => (live && (live.end(), (live = null)), ui.step(name, detail, '', {}))
|
|
1063
|
+
res = await client.chat({ messages: s.messages, tools, stream }, { signal, onToken: out.text, onReasoning: out.think, onToolDelta, fit: s.autoCompact && !refitted, agent: true, cwd: s.root, permission: ui.permission, confirm: (q, kind) => ui.confirm(q, kind), onStep: cliStep, onStepFailed: () => ui.result('failed', { ok: false }) })
|
|
1055
1064
|
} catch (e) {
|
|
1056
1065
|
if (!e.tooBig) {
|
|
1057
1066
|
ui.stopSpin()
|
|
@@ -1132,6 +1141,12 @@ async function runNative(s, task, images, signal) {
|
|
|
1132
1141
|
}
|
|
1133
1142
|
s.lastStop = res.finishReason // why the last reply ended (headless: its stop_reason)
|
|
1134
1143
|
s.onEvent?.({ type: 'assistant', model: `${client.provider}/${client.model}`, content: res.content, reasoning: res.reasoning, toolCalls: res.toolCalls, stop: res.finishReason }) // headless output
|
|
1144
|
+
// a coding CLI did the work itself, with its own tools and checks: its answer is the answer
|
|
1145
|
+
if (res.cli) {
|
|
1146
|
+
ui.finishSteps?.('') // headless and editors (ACP) have no steps on screen
|
|
1147
|
+
showHeld(res.content)
|
|
1148
|
+
return res.content
|
|
1149
|
+
}
|
|
1135
1150
|
// An answer cut off (its provider's output limit: no max_tokens is sent, so each has its own; or a
|
|
1136
1151
|
// connection that ended early): the model goes on where it stopped (3 times in a row at most); the
|
|
1137
1152
|
// answer is the pieces together. Still cut after that: it stays cut, and says so (stop_reason).
|
|
@@ -1146,7 +1161,7 @@ async function runNative(s, task, images, signal) {
|
|
|
1146
1161
|
if (!res.toolCalls.length || res.finishReason !== 'length') [cut, cuts] = ['', 0]
|
|
1147
1162
|
if (!res.toolCalls.length && !res.content?.trim()) {
|
|
1148
1163
|
// Nothing at all (seen after a failed tool call): not an answer. The same request again
|
|
1149
|
-
// first (often fine the second time), then asked to go on;
|
|
1164
|
+
// first (often fine the second time), then asked to go on; after four in a row the next model goes on.
|
|
1150
1165
|
s.messages.pop() // some APIs reject an empty assistant message
|
|
1151
1166
|
if (empty++ < 3) {
|
|
1152
1167
|
log('task', `empty reply ${empty}; ${empty === 1 ? 'asking again' : 'asking the model to continue'}`)
|
|
@@ -1158,7 +1173,7 @@ async function runNative(s, task, images, signal) {
|
|
|
1158
1173
|
if (movedOn < (client.rotation?.list.length ?? 1) - 1 && client.moveOn(`${was}: ${empty} empty replies in a row`)) {
|
|
1159
1174
|
movedOn++
|
|
1160
1175
|
empty = 0
|
|
1161
|
-
ui.
|
|
1176
|
+
ui.handover(client.model, `${was} keeps replying with nothing`)
|
|
1162
1177
|
continue
|
|
1163
1178
|
}
|
|
1164
1179
|
return finalAnswer(s, signal)
|
|
@@ -1207,6 +1222,7 @@ async function runNative(s, task, images, signal) {
|
|
|
1207
1222
|
sinceNudge = true
|
|
1208
1223
|
continue
|
|
1209
1224
|
}
|
|
1225
|
+
const before = lastFinal
|
|
1210
1226
|
if (!res.toolCalls.length) lastFinal = res.content
|
|
1211
1227
|
// its page is still broken in HeartCode's check and nobody's left to take over: said, not hidden behind "done"
|
|
1212
1228
|
if (!res.toolCalls.length && !sinceNudge && s.proofFails > 0 && !s.isSub) ui.warn(`HeartCode's own check: the page still doesn't work (errors, or nothing shown or drawn); this answer isn't proven`)
|
|
@@ -1214,19 +1230,21 @@ async function runNative(s, task, images, signal) {
|
|
|
1214
1230
|
// worked on the task (changed or ran something) and stopped without saying it's finished: asked
|
|
1215
1231
|
// whether every part is done and checked, with the request. No cap: it ends when it calls done,
|
|
1216
1232
|
// or answers again without doing anything (sinceNudge), or Esc
|
|
1217
|
-
const undeclared = sinceNudge && askDone() && !s.saidDone && (s
|
|
1233
|
+
const undeclared = sinceNudge && askDone() && !s.saidDone && worked(s) ? prompt('agent/not-done', { undeclared: true, request: clip(task, 3000) }) : null
|
|
1234
|
+
const afterAsk = s.undeclaredSent // the answer after "is every part done?": the final one, checked like any
|
|
1218
1235
|
s.undeclaredSent = Boolean(undeclared) // answering that again with nothing done isn't a handover
|
|
1219
1236
|
if (undeclared) log('task', 'stopped without calling done; asked whether it is finished')
|
|
1220
|
-
const more = sinceNudge && (undeclared ?? (s.saidDone?.waiting ? null : (await notDone(s, signal, nudged > 0, res.content)) ?? (await review(s, task, res.content, signal))))
|
|
1221
|
-
showHeld(res.content) // after the review's line
|
|
1237
|
+
const more = (sinceNudge || afterAsk) && (undeclared ?? (s.saidDone?.waiting ? null : (await notDone(s, signal, nudged > 0, res.content)) ?? (await review(s, task, res.content, signal))))
|
|
1238
|
+
if (!((afterAsk || (!sinceNudge && nudged > 0)) && same(res.content, before))) showHeld(res.content) // after the review's line; the same answer again: not twice
|
|
1222
1239
|
if (!more) {
|
|
1223
|
-
if (!s.isSub && (s
|
|
1240
|
+
if (!s.isSub && worked(s) && !s.saidDone?.waiting && (s.saidDone || !askDone() || afterAsk)) record(client, s.proofFails > 0 ? 'not-proven' : 'done') // work done (not a chat answer): its track record (record.js)
|
|
1224
1241
|
s.wrapUpLater?.(task, res.content) // after the answer, beside what comes next
|
|
1225
1242
|
return res.content
|
|
1226
1243
|
}
|
|
1244
|
+
if (!s.isSub) ui.print(c.faint(c.italic(`✻ ${undeclared ? 'HeartCode asked whether every part is done and checked' : 'not finished yet: HeartCode asked it to go on'}`))) // the next answer isn't a mystery
|
|
1227
1245
|
nudged++
|
|
1228
1246
|
sinceNudge = false
|
|
1229
|
-
|
|
1247
|
+
// sent back: what it said with done stands (it isn't asked to call done again, only to finish)
|
|
1230
1248
|
s.messages.push({ role: 'user', content: more })
|
|
1231
1249
|
// said done twice and its page is still broken in HeartCode's own check: the best-ranked model takes over
|
|
1232
1250
|
if (s.proofFails >= 2 && !s.isSub && client.rotation) {
|
|
@@ -1294,8 +1312,11 @@ async function runNative(s, task, images, signal) {
|
|
|
1294
1312
|
? `${args.waiting ? 'waiting for you: ' : ''}${String(args.checked ?? '').split('\n').find((l) => l.trim()) ?? ''}`
|
|
1295
1313
|
: name === 'todo' || name === 'ask_user'
|
|
1296
1314
|
? ''
|
|
1297
|
-
:
|
|
1298
|
-
|
|
1315
|
+
: name === 'search'
|
|
1316
|
+
? `"${clip(String(args.query ?? ''), 50)}"${args.path ? ` in ${args.path}` : ''}`
|
|
1317
|
+
: (args.path ?? args.url ?? args.query ?? args.filter ?? args.name ?? '')
|
|
1318
|
+
const shown = name !== 'run_command' && !together.has(call.id) && !askedWith.has(call.id) // its step is on screen (its result goes on that line)
|
|
1319
|
+
if (shown) ui.step(name, name === 'agent' && args ? helperLine(args) : clip(detail, 80), name === 'agent' ? '' : client.model) // asked together: shown once, with the first; named by the model that made the call (an agent line names the helper's)
|
|
1299
1320
|
const pre = early.get(call.id)
|
|
1300
1321
|
// the first changes to the files with no plan yet (this message, or still open from an earlier one):
|
|
1301
1322
|
// not made — the plan first, then the changes again. Every change in that reply (one made beside a
|
|
@@ -1311,6 +1332,7 @@ async function runNative(s, task, images, signal) {
|
|
|
1311
1332
|
s.seq++
|
|
1312
1333
|
if (EDITS.has(name) && !failed(out)) {
|
|
1313
1334
|
s.lastChangeAt = s.seq
|
|
1335
|
+
s.workBy = { provider: client.provider, model: client.model } // whose changes a review judges
|
|
1314
1336
|
s.checksSince = 0
|
|
1315
1337
|
// the same spot changed again and again (and what it checks still comes out the same): told
|
|
1316
1338
|
// at the third time that the cause is likely elsewhere
|
|
@@ -1330,7 +1352,7 @@ async function runNative(s, task, images, signal) {
|
|
|
1330
1352
|
}
|
|
1331
1353
|
// what was run or checked, for the review and the wrap-up: commands, MCP tools (a browser), helpers, the language server
|
|
1332
1354
|
const checked = !args || refused ? null : name === 'run_command' ? String(args.command ?? '') : name === 'mcp' ? `${args.server} · ${args.tool}` : name === 'agent' ? `helper: ${args.description ?? clip(String(args.prompt ?? ''), 60)}` : name === 'lsp' ? `language server: ${args.action} ${args.file ?? ''}` : null
|
|
1333
|
-
if (checked) s.ran?.push({ command: checked, result: clip(String(out).split('\n').filter((l) => l.trim()).slice(0, 2).join(' · '), 160) })
|
|
1355
|
+
if (checked) s.ran?.push({ command: checked, result: clip(String(out).split('\n').filter((l) => l.trim()).slice(0, 2).join(' · '), 160), look: name === 'run_command' && readOnlyCommand(checked) }) // look: it only read (git log, ls, grep): a question being answered, not work
|
|
1334
1356
|
if (!s.isSub && s.memory && !refused && args) await noteRun(s, name, args, out, signal).catch((e) => log('learn', `run note: ${e.message}`)) // learn from any run that failed then passed
|
|
1335
1357
|
// a step it said it was stuck on, now done: what got it out is a lesson
|
|
1336
1358
|
if (!s.isSub && s.memory && s.unstuck?.length) {
|
|
@@ -1348,10 +1370,12 @@ async function runNative(s, task, images, signal) {
|
|
|
1348
1370
|
const no = refusal(out) // refused, held, declined: said so, not left looking done
|
|
1349
1371
|
if (no) {
|
|
1350
1372
|
if (name === 'run_command' && refused) ui.step('run', clip(String(args.command ?? ''), 80)) // a command shows itself where it runs, which this one never reached
|
|
1351
|
-
if (name !== 'run_command' || refused) ui.result(no) // a command's own refusals are shown there too
|
|
1352
|
-
} else if (
|
|
1353
|
-
|
|
1354
|
-
|
|
1373
|
+
if (name !== 'run_command' || refused) ui.result(no, { refused: true }) // a command's own refusals are shown there too
|
|
1374
|
+
} else if (shown) {
|
|
1375
|
+
const r = outcomeOf(name, args ?? {}, out)
|
|
1376
|
+
if (name === 'agent' && r.ok !== false) r.text = s.ui.permission === 'plan' ? 'planned' : 'done' // its reply is shown above, under its name
|
|
1377
|
+
ui.result(r.text, r)
|
|
1378
|
+
}
|
|
1355
1379
|
client.refresh?.() // a setting changed while the tool ran (the window): its result is cut by the new one
|
|
1356
1380
|
// every sizable result is saved as it comes (a web page already is, in research): later it can
|
|
1357
1381
|
// become a pointer to its file in the conversation without anything being lost
|
|
@@ -1369,7 +1393,7 @@ async function runNative(s, task, images, signal) {
|
|
|
1369
1393
|
trimOldResults(s)
|
|
1370
1394
|
const ended = newlyEnded(s.root) // background commands that exited meanwhile: the model hears it now
|
|
1371
1395
|
if (ended.length) {
|
|
1372
|
-
for (const j of ended) ui.step('background', `#${j.id} ${clip(j.command, 60)} exited with ${j.code}
|
|
1396
|
+
for (const j of ended) ui.step('background', `#${j.id} ${clip(j.command, 60)} exited with ${j.code}`, '', { note: true })
|
|
1373
1397
|
s.messages.push({ role: 'user', content: prompt('agent/background-ended', { jobs: ended.map(jobLine).join('\n') }) })
|
|
1374
1398
|
}
|
|
1375
1399
|
if (stuck) {
|
|
@@ -1399,12 +1423,18 @@ const EDITS = new Set(['edit_file', 'write_file', 'append_file', 'apply_patch'])
|
|
|
1399
1423
|
// compacting or going back, which drop it). Not with --system-prompt (the program's workflow), and
|
|
1400
1424
|
// not after read_file (a file read again replaces its earlier copy, and what came with it).
|
|
1401
1425
|
const GUIDES = { list_files: ['find'], search: ['find'], lsp: ['find'], find_command: ['find'], todo: ['code', 'parts'], edit_file: ['code', 'check'], write_file: ['code', 'check'], append_file: ['code', 'check'], apply_patch: ['code', 'check'], run_command: ['check'], web_search: ['research'], web_fetch: ['research'] }
|
|
1426
|
+
// The guide for the kind of work (guides.js: a web app, a game, a scraper…) comes the same way, with the
|
|
1427
|
+
// first plan or change of a message whose words or project show that kind: not for a question
|
|
1428
|
+
// answered by looking. Once per conversation each, and not when the model already read it (guide tool).
|
|
1429
|
+
const STARTS_WORK = new Set(['todo', 'edit_file', 'write_file', 'append_file', 'apply_patch'])
|
|
1402
1430
|
function guidesFor(s, name) {
|
|
1403
|
-
if (s.ownSystem
|
|
1431
|
+
if (s.ownSystem) return ''
|
|
1404
1432
|
const sent = (s.chat.sentNotes ??= [])
|
|
1405
|
-
const due = GUIDES[name].filter((k) => !sent.includes(`guide:${k}`) && (k !== 'parts' || (!s.isSub && s.subagent && s.team?.().length))) // parts: only with other models to give them to
|
|
1433
|
+
const due = (GUIDES[name] ?? []).filter((k) => !sent.includes(`guide:${k}`) && (k !== 'parts' || (!s.isSub && s.subagent && s.team?.().length))) // parts: only with other models to give them to
|
|
1406
1434
|
sent.push(...due.map((k) => `guide:${k}`))
|
|
1407
|
-
|
|
1435
|
+
const kinds = STARTS_WORK.has(name) ? (s.domainGuides ?? []).filter((g) => !sent.includes(`domain:${g}`)) : []
|
|
1436
|
+
sent.push(...kinds.map((g) => `domain:${g}`))
|
|
1437
|
+
return [...due.map((k) => prompt(`agent/guide-${k}`, guideVars(s))), ...kinds.map((g) => guideText(s, g))].map((t) => `\n\n${t}`).join('')
|
|
1408
1438
|
}
|
|
1409
1439
|
// Tools that run or look at what was made (a command, a test, a browser, a helper): a check after a change.
|
|
1410
1440
|
const CHECKS = new Set(['run_command', 'mcp', 'agent', 'lsp'])
|
|
@@ -1482,7 +1512,7 @@ async function noteRun(s, name, args, out, signal) {
|
|
|
1482
1512
|
const tool = runTool_(args.command)
|
|
1483
1513
|
if (!tool) return
|
|
1484
1514
|
const code = Number(/^exit code (-?\d+)/.exec(out)?.[1] ?? (failed(out) ? 1 : 0))
|
|
1485
|
-
const bad = code !== 0
|
|
1515
|
+
const bad = code !== 0 // what it printed ("0 failed", "undefined") says nothing; its exit code does
|
|
1486
1516
|
if (bad) {
|
|
1487
1517
|
const line = out.split('\n').find((l) => /\b(error|traceback|exception|failed|cannot|not found)\b/i.test(l)) ?? out.split('\n').find((l) => l.trim()) ?? ''
|
|
1488
1518
|
s.runFails.set(tool, { error: `${args.command.split(/\s+/)[0]}: ${line.trim().slice(0, 160)}`, atEdits: s.edits, cmd: args.command })
|
|
@@ -1508,23 +1538,25 @@ async function learnFromFixes(s, fixed, signal, { unsolved = false, task = '' }
|
|
|
1508
1538
|
let rule = ''
|
|
1509
1539
|
let scope = 'global'
|
|
1510
1540
|
try {
|
|
1511
|
-
|
|
1512
|
-
s.client.
|
|
1541
|
+
// a client of its own (the same model): not the one the task is using, its state stays the task's
|
|
1542
|
+
const { client } = s.engineFor ? await s.engineFor({ provider: s.client.provider, model: s.client.model }) : { client: s.client }
|
|
1543
|
+
const was = client.purpose
|
|
1544
|
+
client.purpose = 'lesson'
|
|
1513
1545
|
let reply
|
|
1514
1546
|
try {
|
|
1515
|
-
reply = await
|
|
1547
|
+
reply = await client.chat({ messages: [{ role: 'user', content: prompt('agent/lesson', { error, unsolved, task: clip(task, 300) }) }] }, { signal })
|
|
1516
1548
|
} finally {
|
|
1517
|
-
|
|
1549
|
+
client.purpose = was
|
|
1518
1550
|
}
|
|
1519
|
-
|
|
1551
|
+
if (/^\W*none\b/i.test(reply.content.trim())) continue // not a lesson worth keeping
|
|
1520
1552
|
rule = (said.find((l) => !/^\s*\W*scope\s*:/i.test(l)) ?? '').replace(/^\s*(?:\d+[.)]|[-*])\s*/, '').replace(/^["'\s-]+|["']+$/g, '').slice(0, 200)
|
|
1521
1553
|
if (/scope\s*:\W*project/i.test(said.join('\n'))) scope = 'project'
|
|
1522
1554
|
} catch (e) {
|
|
1523
1555
|
if (e.name === 'AbortError') throw e
|
|
1524
1556
|
}
|
|
1525
|
-
if (!rule || rule.length < 10)
|
|
1557
|
+
if (!rule || rule.length < 10) continue // the model couldn't phrase it: an error's own wording isn't a rule
|
|
1526
1558
|
const name = s.memory.write({ description: rule, type: 'reference', tags: ['lesson', ...tags], content: `${rule}\n\nLearned on ${new Date().toISOString().slice(0, 10)} ${unsolved ? 'after this blocked a task that was not done' : 'after this was caught and fixed'}${task ? ` (the task: ${clip(task, 200)})` : ' while building'}: ${error}`, scope })
|
|
1527
|
-
s.ui.step('learned', `${rule.slice(0, 90)}${scope === 'project' ? ' (this project)' : ''}
|
|
1559
|
+
s.ui.step('learned', `${rule.slice(0, 90)}${scope === 'project' ? ' (this project)' : ''}`, '', { note: true })
|
|
1528
1560
|
log('learn', `saved lesson [[${name}]] (${scope}, #${tags.join(' #')}): ${rule}`)
|
|
1529
1561
|
}
|
|
1530
1562
|
}
|
|
@@ -1534,19 +1566,24 @@ async function learnFromFixes(s, fixed, signal, { unsolved = false, task = '' }
|
|
|
1534
1566
|
// most (the caller counts), so a model that can't finish still ends.
|
|
1535
1567
|
// The model said it would do something but stopped without doing it ("let me rewrite…", "I'll fix…"):
|
|
1536
1568
|
// a next action named, then no tool call. Not matched by explanations ("let me explain", "you can run").
|
|
1537
|
-
const
|
|
1538
|
-
/\b(?:let me|let['’]?s|let us|i['’]?ll|i will|i['’]?m going to|i am going to|i need to|i['’]?m about to|next,? i['’]?ll|now,? i['’]?ll)\b[^.!?\n]{0,70}\b(?:do|make|create|add|fix|write|update|change|implement|build|run|rewrite|replace|edit|install|set ?up|finish|continue|proceed|start|redo|retry|try|hand|pass|send|give|use|open|navigate|click|solve)\b/i
|
|
1569
|
+
const PROMISED_RE =
|
|
1570
|
+
/\b(?:let me(?! know)|let['’]?s|let us|i['’]?ll|i will|i['’]?m going to|i am going to|i need to|i['’]?m about to|next,? i['’]?ll|now,? i['’]?ll)\b[^.!?\n]{0,70}\b(?:do|make|create|add|fix|write|update|change|implement|build|run|rewrite|replace|edit|install|set ?up|finish|continue|proceed|start|redo|retry|try|hand|pass|send|give|use|open|navigate|click|solve)\b/i
|
|
1571
|
+
// …in a sentence of its own: not an offer ("Let me know if you want me to add tests", "Would you like me to…")
|
|
1572
|
+
const OFFER = /\b(?:if you(?:['’]d)? (?:want|like|need|prefer)|would you like|want me to|like me to|let me know|shall i|should i|do you want)\b/i
|
|
1573
|
+
const PROMISED_MORE = { test: (text) => String(text).split(/(?<=[.!?])\s+|\n+/).some((x) => PROMISED_RE.test(x) && !OFFER.test(x)) }
|
|
1539
1574
|
|
|
1540
1575
|
// The start of a final answer saying it didn't manage: "I couldn't…", "unable to…", "still showing…".
|
|
1541
1576
|
const FAILED_WORDS = /\b(?:could ?n['’]?t|could not|was(?: not|n['’]?t) able to|(?:am|was|i['’]m) unable to|failed to|did(?: not|n['’]?t) (?:manage|succeed|work|load|pass)|not (?:yet )?(?:complete[d]?|finished|solved|possible|loaded)|still (?:in progress|pending|blocked|loading|stuck|showing|failing|not)|has not (?:yet )?(?:complet|finish|load|pass))/gi
|
|
1542
1577
|
// An answer that says it didn't manage: those words, not in a condition or a "what if" ("without which
|
|
1543
1578
|
// the test could not pass", "otherwise it would fail", "if it couldn't connect")
|
|
1544
1579
|
const CONDITIONAL = /\b(?:without (?:which|it|this|that)|otherwise|or else|would(?:n['’]?t)?|if|unless|so (?:that )?it)\b(?:[^.;!?\n]|\.(?!\s))*$/i // within the same sentence (a dot in a file name isn't its end)
|
|
1545
|
-
|
|
1580
|
+
// …and not one it got past in the same sentence ("I couldn't find existing tests, so I added some")
|
|
1581
|
+
const GOT_PAST = /^[^.;!?\n]*\b(?:so|instead|but|then)\b[^.;!?\n]*\b(?:i|we)\b/i
|
|
1582
|
+
const SAYS_FAILED = { test: (text) => [...String(text).matchAll(FAILED_WORDS)].some((m) => !CONDITIONAL.test(text.slice(Math.max(0, m.index - 40), m.index)) && !GOT_PAST.test(text.slice(m.index + m[0].length))) }
|
|
1546
1583
|
|
|
1547
1584
|
// "I can't browse the web", "I'm unable to run commands", "I don't have access to…": a model
|
|
1548
1585
|
// saying it lacks an ability (it has tools for it).
|
|
1549
|
-
const CANT = /\b(?:i\s*(?:['’]m|am)\s*(?:unable|not able)\s*to|i\s*(?:can(?:['’]?t| ?not)|do(?:n['’]?t| not))\s*(?:directly\s*)?(?:have\s*(?:the\s*)?(?:ability|access|capabilit|tools?)|browse
|
|
1586
|
+
const CANT = /\b(?:i\s*(?:['’]m|am)\s*(?:unable|not able)\s*to|i\s*(?:can(?:['’]?t| ?not)|do(?:n['’]?t| not))\s*(?:directly\s*)?(?:have\s*(?:the\s*)?(?:ability|access|capabilit|tools?)|browse(?: the web)?|access (?:the (?:web|internet)|files|your)|visit|interact|click|navigate|run (?:commands|code|scripts|programs)|execute|control))|\bas an ai\b/i // an ability, not what it looked at ("I can't see any errors")
|
|
1550
1587
|
|
|
1551
1588
|
// Is the task really done, or did the model stop early? Open todo items, or (after it did real work)
|
|
1552
1589
|
// a reply that only promises more, get one nudge to keep going. Then any Stop hook. null = truly done.
|
|
@@ -1620,7 +1657,7 @@ export async function notDone(s, signal, again, reply = '') {
|
|
|
1620
1657
|
s.ui.stopSpin()
|
|
1621
1658
|
if (!r) continue
|
|
1622
1659
|
s.ran?.push({ command: `HeartCode opened ${page} in a browser`, result: clip(r.report.split('\n')[0], 300) }) // the review sees it
|
|
1623
|
-
s.ui.step('check', `${page} in a browser: ${r.broken ? 'broken' : 'works'}
|
|
1660
|
+
s.ui.step('check', `${page} in a browser: ${r.broken ? 'broken' : 'works'}`, '', { note: true, ok: !r.broken })
|
|
1624
1661
|
if (!r.broken) {
|
|
1625
1662
|
s.proofShots = (r.shots ?? []).filter((f) => /desktop/.test(f)) // the review looks at it (reviewers that can see)
|
|
1626
1663
|
continue
|
|
@@ -1701,10 +1738,15 @@ const isEmptyDir = (abs) => {
|
|
|
1701
1738
|
// answer, the changes and what was run since. It answers YES (done right) or NO with what's wrong;
|
|
1702
1739
|
// a NO goes back to the model to fix. Asked again only once files changed since its last look.
|
|
1703
1740
|
// Returns what to tell the model, or null.
|
|
1741
|
+
// Work was done this message: files changed, or something run that does more than look (a build, a
|
|
1742
|
+
// server, a browser, a helper). Not a question answered by looking around (git log, ls, grep): that
|
|
1743
|
+
// gets no "is every part done?" and no review.
|
|
1744
|
+
const worked = (s) => Boolean(s.changed?.size || (s.ran ?? []).some((r) => !r.look))
|
|
1745
|
+
|
|
1704
1746
|
export async function review(s, task, answer, signal) {
|
|
1705
1747
|
// no files changed, but it ran things to do the task (a browser, commands, helpers): its answer is
|
|
1706
1748
|
// checked against the request too (once per new batch of them)
|
|
1707
|
-
const acted = !s.changed?.size && (s.ran
|
|
1749
|
+
const acted = !s.changed?.size && (s.ran ?? []).slice(s.reviewedRan ?? 0).some((r) => !r.look) // only looked (a question answered with git log, ls…): nothing to review
|
|
1708
1750
|
if (s.isSub || s.ui.permission === 'plan' || (!acted && (!s.changed?.size || s.lastChangeAt <= s.reviewedAt))) return null
|
|
1709
1751
|
s.reviewedAt = s.lastChangeAt
|
|
1710
1752
|
s.reviewedRan = s.ran?.length ?? 0
|
|
@@ -1730,9 +1772,10 @@ export async function review(s, task, answer, signal) {
|
|
|
1730
1772
|
}
|
|
1731
1773
|
if (!diffs.length && !acted) return null
|
|
1732
1774
|
if (!diffs.length) diffs.push('(no files changed)')
|
|
1733
|
-
const plan = (s.chat.todos ?? []).map((t) => `- [${t.status === 'completed' ? 'x' : ' '}] ${t.content}`).join('\n')
|
|
1775
|
+
const plan = s.todoTouched ? (s.chat.todos ?? []).map((t) => `- [${t.status === 'completed' ? 'x' : ' '}] ${t.content}`).join('\n') : '' // a plan from an earlier message isn't this one's
|
|
1734
1776
|
const ran = (s.ran ?? []).slice(-15).map((r) => `- ${clip(r.command.replace(/\s+/g, ' '), 160)} → ${r.result}`).join('\n')
|
|
1735
|
-
const
|
|
1777
|
+
const earlier = requestsOf({ turns: s.chat.turns.slice(0, -1) }, 800)
|
|
1778
|
+
const vars = { request: clip(String(task ?? ''), 3000), earlier, emphasis: (s.chat?.choices ?? []).join('; '), plan: plan || '(none)', answer: clip(String(answer ?? ''), 3000), changes: diffs.join('\n\n'), ran: ran || '(nothing)', shrunk: shrunkNote(s, [...(s.changed ?? [])]) }
|
|
1736
1779
|
// the page's screenshot from HeartCode's browser check, for a reviewer that can see: what the user gets
|
|
1737
1780
|
const shots = (s.proofShots ?? []).flatMap((f) => {
|
|
1738
1781
|
try {
|
|
@@ -1764,15 +1807,15 @@ export async function review(s, task, answer, signal) {
|
|
|
1764
1807
|
if (/^\W*yes\b/i.test(said)) {
|
|
1765
1808
|
s.lastReview = { verdict: 'yes' }
|
|
1766
1809
|
s.ui.event?.({ subtype: 'review', model: `${t.provider}/${t.model}`, verdict: 'yes', issues: '' })
|
|
1767
|
-
s.ui.step('review', `${t.model}: looks right
|
|
1810
|
+
s.ui.step('review', `${t.model}: looks right`, '', { note: true })
|
|
1768
1811
|
return null
|
|
1769
1812
|
}
|
|
1770
1813
|
if (/^\W*no\b/i.test(said)) {
|
|
1771
1814
|
const issues = said.replace(/^\W*no\b[\s.:—-]*/i, '').trim()
|
|
1772
1815
|
s.lastReview = { verdict: 'no', issues }
|
|
1773
|
-
record(s.client, 'review-no') // the
|
|
1816
|
+
record(s.workBy ?? s.client, 'review-no') // the model that made the changes (another may answer now): its track record (record.js)
|
|
1774
1817
|
s.ui.event?.({ subtype: 'review', model: `${t.provider}/${t.model}`, verdict: 'no', issues })
|
|
1775
|
-
s.ui.step('review', `${t.model}: ${clip(issues.split('\n').find((l) => l.trim()) ?? 'problems found', 90)}
|
|
1818
|
+
s.ui.step('review', `${t.model}: ${clip(issues.split('\n').find((l) => l.trim()) ?? 'problems found', 90)}`, '', { note: true, ok: false })
|
|
1776
1819
|
return prompt('agent/review-failed', { model: t.model, issues: issues || '(no details given)' })
|
|
1777
1820
|
}
|
|
1778
1821
|
log('review', `${t.model} didn't answer YES or NO; trying another`)
|
|
@@ -1786,6 +1829,54 @@ export async function review(s, task, answer, signal) {
|
|
|
1786
1829
|
}
|
|
1787
1830
|
|
|
1788
1831
|
// "3 lines" for a result; an empty last line isn't one (a file ends with a newline, and read_file numbers the empty line after it)
|
|
1832
|
+
// How a tool call went, for its step's line (ui.result): { text, ok, none, n, unit, files }.
|
|
1833
|
+
export function outcomeOf(name, args, out) {
|
|
1834
|
+
const o = String(out)
|
|
1835
|
+
if (failed(o)) {
|
|
1836
|
+
const why = o.replace(/^error: /, '').split('\n')[0]
|
|
1837
|
+
return { ok: false, text: /\b(does not exist|doesn't exist|no such file|ENOENT)\b/i.test(why) ? 'not found' : clip(why.replace(/\. .*$/, ''), 90) }
|
|
1838
|
+
}
|
|
1839
|
+
const count = (n, one, many) => `${n} ${n === 1 ? one : many}`
|
|
1840
|
+
switch (name) {
|
|
1841
|
+
case 'read_file': {
|
|
1842
|
+
if (o.startsWith('data:')) return { text: 'an image' }
|
|
1843
|
+
const nums = [...o.matchAll(/^(\d+)\| /gm)].map((m) => Number(m[1]))
|
|
1844
|
+
if (!nums.length) return { text: clip(o.split('\n')[0], 60), none: !o.trim() }
|
|
1845
|
+
const total = Number(/\((\d+) lines total;/.exec(o)?.[1]) || null
|
|
1846
|
+
const [a, b] = [nums[0], nums.at(-1)]
|
|
1847
|
+
return { text: a === 1 && !total ? count(b, 'line', 'lines') : `lines ${a}–${b}${total ? ` of ${total}` : ''}`, n: b - a + 1, unit: 'lines' }
|
|
1848
|
+
}
|
|
1849
|
+
case 'search': {
|
|
1850
|
+
if (/^(no matches|nothing was searched)/.test(o)) return { none: true, text: 'no matches' }
|
|
1851
|
+
const hits = o.split('\n').filter((l) => /^[^\n:]+:\d+: /.test(l))
|
|
1852
|
+
const files = [...new Set(hits.map((l) => l.slice(0, l.search(/:\d+: /))))]
|
|
1853
|
+
const more = /\(stopped at \d+ matches\)/.test(o) ? '+' : ''
|
|
1854
|
+
return { text: `${count(hits.length, 'match', 'matches')}${more} in ${count(files.length, 'file', 'files')}`, n: hits.length, unit: 'matches', files }
|
|
1855
|
+
}
|
|
1856
|
+
case 'list_files': {
|
|
1857
|
+
if (/^(\(empty folder\)|no files)$/.test(o.trim())) return { none: true, text: 'empty' }
|
|
1858
|
+
const lines = o.split('\n').filter((l) => l.trim())
|
|
1859
|
+
const n = lines.filter((l) => !/^… \d+ more$/.test(l)).length + Number(/^… (\d+) more$/m.exec(o)?.[1] ?? 0)
|
|
1860
|
+
return { text: count(n, 'entry', 'entries'), n, unit: 'entries' }
|
|
1861
|
+
}
|
|
1862
|
+
case 'web_fetch': {
|
|
1863
|
+
const kb = Math.max(1, Math.round(o.length / 1000))
|
|
1864
|
+
return { text: `${kb} KB`, n: kb, unit: 'KB' }
|
|
1865
|
+
}
|
|
1866
|
+
case 'web_search': {
|
|
1867
|
+
if (/^no results/.test(o)) return { none: true, text: 'no results' }
|
|
1868
|
+
const n = new Set(o.match(/https?:\/\/\S+/g) ?? []).size
|
|
1869
|
+
return n ? { text: count(n, 'result', 'results'), n, unit: 'results' } : { text: '' }
|
|
1870
|
+
}
|
|
1871
|
+
case 'changes':
|
|
1872
|
+
return { text: lineCount(o) }
|
|
1873
|
+
case 'agent':
|
|
1874
|
+
return { text: '' }
|
|
1875
|
+
default:
|
|
1876
|
+
return { text: '' }
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1789
1880
|
const lineCount = (out) => {
|
|
1790
1881
|
const n = String(out).replace(/\n\s*(\d+\|)?\s*$/, '').split('\n').length
|
|
1791
1882
|
return `${n} line${n === 1 ? '' : 's'}`
|
|
@@ -1803,7 +1894,6 @@ function helperUI(ui, label, model) {
|
|
|
1803
1894
|
// conversation's; with other helpers replying at the
|
|
1804
1895
|
// same time, held until its reply ends, then printed at once (two streams would interleave).
|
|
1805
1896
|
const response = () => {
|
|
1806
|
-
const t0 = Date.now()
|
|
1807
1897
|
let thought = ''
|
|
1808
1898
|
let said = ''
|
|
1809
1899
|
const alone = !streaming.get(ui)
|
|
@@ -1815,7 +1905,7 @@ function helperUI(ui, label, model) {
|
|
|
1815
1905
|
end() {
|
|
1816
1906
|
streaming.set(ui, streaming.get(ui) - 1)
|
|
1817
1907
|
if (live) live.end()
|
|
1818
|
-
else if (thought.trim()) ui.print(c.faint(c.italic(` ✻ ${label}
|
|
1908
|
+
else if (thought.trim()) ui.print(c.faint(c.italic(` ✻ ${label} thinking`)) + `\n${c.think(c.italic(thought.trim().replace(/^/gm, ' ')))}`)
|
|
1819
1909
|
if (!said.trim()) return
|
|
1820
1910
|
ui.print(` ${c.bright(c.bold('●'))} ${c.bold(label)}`)
|
|
1821
1911
|
let block = new Block((x) => ui.write(x), { marker: ' ', style: c.text })
|
|
@@ -1838,13 +1928,11 @@ function helperUI(ui, label, model) {
|
|
|
1838
1928
|
}
|
|
1839
1929
|
const own = {
|
|
1840
1930
|
// its steps one level in, under the agent line
|
|
1841
|
-
step: (name, detail = '') => {
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
ui.print(` ${c.accent('●')} ${c.accent(c.bold(`${label} › ${name}`))} ${c.info(detail)}${model ? c.faint(` · ${model}`) : ''}`)
|
|
1845
|
-
status(`${name} ${detail}`)
|
|
1931
|
+
step: (name, detail = '', _who, opts) => {
|
|
1932
|
+
ui.step(name, detail, model, { ...opts, sub: label })
|
|
1933
|
+
status(`${(STEP_NAMES[name] ?? name).toLowerCase()} ${detail}`)
|
|
1846
1934
|
},
|
|
1847
|
-
result: (text) => ui.
|
|
1935
|
+
result: (text, opts) => ui.result(text, { ...opts, sub: label }),
|
|
1848
1936
|
response,
|
|
1849
1937
|
spinner: (text) => {
|
|
1850
1938
|
status(typeof text === 'function' ? text() : text)
|
|
@@ -1949,7 +2037,8 @@ function attachNamed(s, task) {
|
|
|
1949
2037
|
replaceCopy(s, f, msg)
|
|
1950
2038
|
results.push(msg)
|
|
1951
2039
|
s.ui.step('read_file', f)
|
|
1952
|
-
|
|
2040
|
+
const r = outcomeOf('read_file', { path: f }, body)
|
|
2041
|
+
s.ui.result(r.text, r)
|
|
1953
2042
|
}
|
|
1954
2043
|
if (calls.length) s.messages.push({ role: 'assistant', content: '', tool_calls: calls }, ...results)
|
|
1955
2044
|
}
|
package/src/background.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// background tool (and /background) reads what it printed since, waits on it, lists them, stops
|
|
4
4
|
// one. Each runs in its own process group, its output going to a file; all of them are stopped when
|
|
5
5
|
// HeartCode exits.
|
|
6
|
+
import { guarded } from './guard.js'
|
|
6
7
|
import fs from 'node:fs'
|
|
7
8
|
import path from 'node:path'
|
|
8
9
|
import { spawn } from 'node:child_process'
|
|
@@ -14,7 +15,7 @@ const DIR = path.join(HOME, 'outputs', 'background')
|
|
|
14
15
|
const jobs = new Map() // id → { id, command, root, pid, file, started, code, read, exited }
|
|
15
16
|
let made = 0
|
|
16
17
|
|
|
17
|
-
const plain = (t) => t.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '').replace(/\r(?!\n)/g, '\n')
|
|
18
|
+
const plain = (t) => t.replace(/\x1b\][\s\S]*?(?:\x07|\x1b\\)/g, '').replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '').replace(/\r(?!\n)/g, '\n').replace(/\x1b|[\x00-\x08\x0b\x0c\x0e-\x1f\x7f\x9b]/g, '')
|
|
18
19
|
const group = process.platform !== 'win32'
|
|
19
20
|
const kill = (job, sig) => killTree(job.pid, sig, group)
|
|
20
21
|
|
|
@@ -24,7 +25,8 @@ export function startJob(root, command) {
|
|
|
24
25
|
const id = ++made
|
|
25
26
|
const file = path.join(DIR, `${process.pid}-${id}.log`)
|
|
26
27
|
const fd = fs.openSync(file, 'w')
|
|
27
|
-
const
|
|
28
|
+
const safe = guarded(command, { ...process.env, CI: '1', FORCE_COLOR: '0', NO_COLOR: '1' }) // it can't stop HeartCode (guard.js)
|
|
29
|
+
const child = spawn(safe.command, { cwd: root, shell: true, detached: group, stdio: ['ignore', fd, fd], env: safe.env })
|
|
28
30
|
fs.closeSync(fd)
|
|
29
31
|
const job = { id, command, root, pid: child.pid, file, started: Date.now(), code: null, read: 0, exited: false, told: false }
|
|
30
32
|
jobs.set(id, job)
|
package/src/capabilities.js
CHANGED
|
@@ -29,9 +29,8 @@ export function capabilities(cfg = {}) {
|
|
|
29
29
|
const vp = voiceProblem(cfg.voice ?? {}, cfg.providers ?? {})
|
|
30
30
|
let need = ''
|
|
31
31
|
if (vp) {
|
|
32
|
-
if (/ffmpeg/.test(vp)) need = 'ffmpeg, and
|
|
33
|
-
else
|
|
34
|
-
else need = 'a whisper model — or a transcription provider'
|
|
32
|
+
if (/ffmpeg/.test(vp)) need = 'ffmpeg, and Hex or whisper-cli (or OpenAI)'
|
|
33
|
+
else need = vp.replace(/^voice (input )?/, '') // what it says is missing: Hex's Labs switch, a whisper model, an OpenAI provider
|
|
35
34
|
}
|
|
36
35
|
caps.push({ id: 'voice', name: 'Voice input', what: 'Dictate a message — Space in an empty box, or /voice.', ok: !vp, need })
|
|
37
36
|
const chrome = chromeHere()
|