heartcode 0.1.59 → 0.1.60
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 +28 -0
- package/README.md +14 -7
- package/SKILL.md +2 -1
- package/bin/heart.js +1 -1
- package/bin/heartcode.js +62 -48
- package/package.json +1 -1
- package/prompts/agent.md +50 -6
- package/src/acp.js +3 -3
- package/src/agent.js +116 -16
- package/src/capabilities.js +1 -1
- package/src/client.js +29 -7
- package/src/config.js +1 -1
- package/src/context.js +1 -1
- package/src/headless.js +3 -2
- package/src/importer.js +7 -7
- package/src/log.js +2 -2
- package/src/mcp.js +1 -1
- package/src/memory.js +1 -1
- package/src/oauth.js +1 -1
- package/src/probe.js +14 -4
- package/src/reset.js +2 -2
- package/src/sessions.js +2 -2
- package/src/settings.html +202 -158
- package/src/settings.js +43 -19
- package/src/telegram.js +1 -1
- package/src/tools.js +67 -13
- package/src/tree.js +1 -1
- package/src/ui.js +8 -8
- package/src/usage.js +9 -0
- package/src/voice.js +1 -1
- package/src/web.js +1 -1
package/prompts/agent.md
CHANGED
|
@@ -62,7 +62,7 @@ Stop looking once you have what the task needs.
|
|
|
62
62
|
6. You made something that runs: end with the exact command to run it from the project folder, and the URL to open.
|
|
63
63
|
|
|
64
64
|
## 6. Keep going
|
|
65
|
-
Finish the whole request, not the easy part. A step fails: find why and try another way. Never repeat a failing call. Truly blocked: say exactly what blocks you. Don't stop to ask "want me to continue?". Ask the user only for their choices or credentials, all in one numbered message. Say only what you checked, and say when something isn't verified.
|
|
65
|
+
Finish the whole request, not the easy part. A step fails: find why and try another way. Never repeat a failing call. Struggling (tried twice, still failing, or going round): mark that todo stuck with why; don't hide it. Truly blocked: say exactly what blocks you. Don't stop to ask "want me to continue?". Ask the user only for their choices or credentials, all in one numbered message. Say only what you checked, and say when something isn't verified.
|
|
66
66
|
|
|
67
67
|
## 7. Answers
|
|
68
68
|
1. Answer first, then the reason, then the next step. No greeting, recap, "Let me" or "Hope this helps".
|
|
@@ -220,7 +220,8 @@ Files of this skill (read one with the skill tool: name "{{name}}", file "<path>
|
|
|
220
220
|
## tool-todo
|
|
221
221
|
|
|
222
222
|
<!-- The todo tool: the model's checklist, shown to the user. -->
|
|
223
|
-
Your todo list for a task with several steps. Send the whole list each time: content and status (pending, in_progress or
|
|
223
|
+
Your todo list for a task with several steps. Send the whole list each time: content and status (pending, in_progress, completed or stuck). One item in_progress at a time; mark it completed as soon as it's done. A small task: one item (changing files needs a plan first).
|
|
224
|
+
Stuck: you've tried a step twice and it still doesn't work, or you don't know how to go on. Mark it stuck at once, with why (what you tried, what happened). It gets you help: a new approach, a second opinion, then another model. Saying so is expected and useful; claiming it works when it doesn't wastes the user's time.
|
|
224
225
|
A part that stands alone (needs no other part's result, touches no file another part touches) can run at the same time on another of your models: parallel: true, model ("provider model" from "Your helpers" or "Your other models"; left out: your first helper, or yours when you have none), files (the files only it changes). HeartCode starts the pending ones as helpers when you save the list (not in plan mode, not from a helper) and gives you what each did; you combine and check. Parts that build on each other, one file, a small fix: do them yourself.
|
|
225
226
|
|
|
226
227
|
## tool-web_search
|
|
@@ -273,6 +274,11 @@ Use them with the agent tool ("model" picks one, "images" gives it images):
|
|
|
273
274
|
{{files}}
|
|
274
275
|
To act on them, ask a model that can see: the agent tool with these in "images" and a precise question.){{else}}(The images from the tool calls above. Also saved, to give to a helper (agent tool, "images"): {{files}}){{/if}}
|
|
275
276
|
|
|
277
|
+
## describe-screenshot
|
|
278
|
+
|
|
279
|
+
<!-- To a model that sees images, for a helper that can't: a screenshot a tool (a browser) returned while it works. {{task}}: the helper's job. -->
|
|
280
|
+
This screenshot came from a tool while an agent that can't see does this job: "{{task}}". Describe what it needs to act on: the text, the controls (buttons, inputs) with their labels, and every item of a grid or list by its place (row and column, from the top left) and what it shows. Exact, short; no advice.
|
|
281
|
+
|
|
276
282
|
## images-described
|
|
277
283
|
|
|
278
284
|
<!-- Added to the user's message when this model can't see images and another of the user's models described them. {{model}}: that model. {{descriptions}}: what it saw. -->
|
|
@@ -326,7 +332,7 @@ Do them. If one is no longer needed, update the list and say why.){{/if}}
|
|
|
326
332
|
|
|
327
333
|
<!-- A check before a task is called done, in a request of its own (your next models when there are any). {{request}}: the user's messages; {{plan}}: the todo list; {{answer}}: the agent's final reply; {{changes}}: the diffs; {{ran}}: commands run (newest last) and how they ended; {{emphasis}}: what the user said about how they want it (may be empty). -->
|
|
328
334
|
You check a coding agent's work before the user gets it. Judge it strictly against what the user asked:
|
|
329
|
-
1. Complete: every part, every item of "all" or "every".
|
|
335
|
+
1. Complete: every part, every item of "all" or "every". Done, not described: steps for the user to do themselves, or "I can't", isn't doing it.
|
|
330
336
|
2. Correct: it would work. No bug, wrong API, placeholder or TODO.
|
|
331
337
|
3. Checked: what it ran shows it working.
|
|
332
338
|
4. Clean: no scratch files it made by hand left in the project (experiments, copies, test pages). Tool caches and build output (node_modules, .pytest_cache) are fine.
|
|
@@ -412,6 +418,43 @@ Use that; calling it again gives the same.{{#if circling}} You keep repeating ca
|
|
|
412
418
|
<!-- Added to a tool's result when the model goes round. {{n}}: how many. {{failed}}: set for {{n}} commands failing in a row (at 8 the next model takes over); else the same call {{n}} times in a row (at 5). -->
|
|
413
419
|
{{#if failed}}({{n}} commands in a row failed. Stop and think: is this needed for the task? If it is, read the error and find why it fails. Don't try variations.){{else}}(You made exactly this call {{n}} times in a row. Again won't change anything: try another way, or say what blocks you.){{/if}}
|
|
414
420
|
|
|
421
|
+
## you-can
|
|
422
|
+
|
|
423
|
+
<!-- Sent when the model said it can't do something (browse, run, see…) without trying a tool. {{mcp}}: the MCP servers connected (may be empty). -->
|
|
424
|
+
(You can. Your tools: run_command runs any shell command; web_fetch and web_search read the web; read_file, edit_file and write_file work on files{{#if mcp}}; the mcp tool drives these servers: {{mcp}} (a browser: open pages, click, type, take screenshots){{/if}}. Use them and do the task. If one really fails, say what you tried and what happened.)
|
|
425
|
+
|
|
426
|
+
## stuck
|
|
427
|
+
|
|
428
|
+
<!-- The todo tool's result when the model marks a step stuck, and what it's told when its final answer says it didn't manage. One of these is set: {{plain}} (1st time: its reason is {{why}}), {{answer}} (1st time, from its answer: {{why}} is the answer's start), {{advice}} (2nd time: a second opinion from {{adviser}}), {{last}} (the 3rd time with no model left to take over, or two took over already this message). At the 3rd the next model takes over. -->
|
|
429
|
+
{{#if plain}}(Noted: stuck because {{why}}. Don't try a variation of what failed. Find out why it fails first (read the error, look at the page, check your assumption), then take a different approach. When it works, mark it completed; still stuck, mark it stuck again with what happened.){{/if}}{{#if answer}}(Your answer says it isn't done: "{{why}}". If it is done after all, reply with just the result. If not, don't stop here, and don't try a variation of what failed. Find out why it fails first (read the error, look at the page, check your assumption), then take a different approach.){{/if}}{{#if advice}}(You're stuck again. {{adviser}} looked into it:
|
|
430
|
+
|
|
431
|
+
{{advice}}
|
|
432
|
+
|
|
433
|
+
Weigh it against what you know and try what it suggests, or say why it's wrong.){{/if}}{{#if last}}(Still stuck, and no other model is left to try. If it can't be done here, stop and tell the user plainly: what blocks it, what was tried, and what they could do about it.){{/if}}
|
|
434
|
+
|
|
435
|
+
## second-opinion
|
|
436
|
+
|
|
437
|
+
<!-- A helper's job when the main model is stuck the second time. {{task}}: the user's request. {{step}}: the stuck step. {{why}}: its reason. {{tried}}: its recent commands and checks (may be empty). -->
|
|
438
|
+
Another agent is stuck and needs a second opinion. Don't change any files: investigate (read the code, look at the page, run read-only checks) and reply with what's really going wrong and one concrete approach that's different from what it tried.
|
|
439
|
+
|
|
440
|
+
The user's request: {{task}}
|
|
441
|
+
The step it's stuck on: {{step}}
|
|
442
|
+
Why, in its words: {{why}}
|
|
443
|
+
{{#if tried}}What it ran recently:
|
|
444
|
+
{{tried}}{{/if}}
|
|
445
|
+
|
|
446
|
+
## taken-over
|
|
447
|
+
|
|
448
|
+
<!-- Sent to the next model when the one before went round in circles or said it was stuck. {{was}}: that model. {{why}}: what happened. {{plan}}: the steps not done (may be empty). -->
|
|
449
|
+
(You're taking over from {{was}}, which {{why}}. The conversation above is what it did. Don't repeat the approach that failed: find why it failed, then do the rest in a different way.{{#if plan}}
|
|
450
|
+
Steps not done:
|
|
451
|
+
{{plan}}{{/if}})
|
|
452
|
+
|
|
453
|
+
## same-tool-failing
|
|
454
|
+
|
|
455
|
+
<!-- Added to a tool's result when the same tool failed three times in a row (not commands: those have "repeating"). {{tool}}: the tool. -->
|
|
456
|
+
({{tool}} failed three times in a row. Don't try it again with other values (a longer wait, another selector): find out why it fails, and look at what's there now. If you're stuck, mark that todo stuck with why.)
|
|
457
|
+
|
|
415
458
|
## same-spot
|
|
416
459
|
|
|
417
460
|
<!-- Added to an edit's result at the third change to the same spot (same file, within a few lines) in this message. {{file}}, {{line}}: where. -->
|
|
@@ -424,9 +467,10 @@ Use that; calling it again gives the same.{{#if circling}} You keep repeating ca
|
|
|
424
467
|
|
|
425
468
|
## lesson
|
|
426
469
|
|
|
427
|
-
<!-- Turns a mistake that was caught and fixed into one rule to save in memory. {{error}}: what went wrong. -->
|
|
428
|
-
This mistake was caught and fixed: "{{error}}".
|
|
429
|
-
|
|
470
|
+
<!-- Turns a mistake that was caught and fixed (or, with {{unsolved}}, what blocked a task that wasn't done) into one rule to save in memory. {{error}}: what went wrong. {{task}}: the task (may be empty). -->
|
|
471
|
+
{{#if unsolved}}This blocked a task and it wasn't solved: "{{error}}".{{else}}This mistake was caught and fixed: "{{error}}".{{/if}}{{#if task}} The task: "{{task}}".{{/if}}
|
|
472
|
+
Reply in exactly two lines:
|
|
473
|
+
1. ONE short sentence. {{#if unsolved}}What to check first next time a task like this comes, to find the real cause fast (or what's needed from the user), from what actually happened. Not a workaround a review rejected, not a guess.{{else}}The rule that avoids it next time: what to do, not "give up" or "explain instead".{{/if}} Name the technology or site.
|
|
430
474
|
2. "scope: project" if the rule holds only for this project (its paths, devices, versions, setup), else "scope: global".
|
|
431
475
|
Nothing else.
|
|
432
476
|
|
package/src/acp.js
CHANGED
|
@@ -89,7 +89,7 @@ export async function runAcp({ makeApp, version, permission = 'ask', input = pro
|
|
|
89
89
|
if (chat) app.setChat(chat)
|
|
90
90
|
ui.sessionId = app.chat.id
|
|
91
91
|
const s = await app.session()
|
|
92
|
-
if (!s) throw Object.assign(new Error(app.allOff() ? 'the providers of all
|
|
92
|
+
if (!s) throw Object.assign(new Error(app.allOff() ? 'the providers of all the models are switched off: switch one on in heart settings' : 'no model set up: run heart settings to add a provider and choose a model'), { code: -32000 })
|
|
93
93
|
s.onEvent = (e) => events(ui, s, e)
|
|
94
94
|
sessions.set(ui.sessionId, { app, ui, ctl: null })
|
|
95
95
|
return { app, ui }
|
|
@@ -134,7 +134,7 @@ export async function runAcp({ makeApp, version, permission = 'ask', input = pro
|
|
|
134
134
|
app.working = true // settings changed meanwhile: MCP servers and skills wait for the end of it
|
|
135
135
|
try {
|
|
136
136
|
const s = app.s ?? (await app.session()) // a model chosen again on the settings page
|
|
137
|
-
if (!s) throw Object.assign(new Error(app.allOff() ? 'the providers of all
|
|
137
|
+
if (!s) throw Object.assign(new Error(app.allOff() ? 'the providers of all the models are switched off: switch one on in heart settings' : 'no model set up: run heart settings to add a provider and choose a model'), { code: -32000 })
|
|
138
138
|
s.onEvent ??= (e) => events(it.ui, s, e)
|
|
139
139
|
const k = /^\/(\S+)\s*([\s\S]*)$/.exec(text)
|
|
140
140
|
const skill = k && app.skills.get(k[1].replace(/^skill:/, '')) // /name or /skill:name, as in the full screen
|
|
@@ -219,7 +219,7 @@ function events(ui, s, e) {
|
|
|
219
219
|
ui.calls = ui.calls.filter((id) => id !== e.id)
|
|
220
220
|
const failed = toolFailed(e.output)
|
|
221
221
|
ui.update({ sessionUpdate: 'tool_call_update', toolCallId: e.id, status: failed ? 'failed' : 'completed', content: [{ type: 'content', content: { type: 'text', text: clip(plain(e.output), 4000) } }] })
|
|
222
|
-
if (e.name === 'todo') ui.update({ sessionUpdate: 'plan', entries: (s.chat.todos ?? []).map((t) => ({ content: t.content, priority: 'medium', status: t.status })) })
|
|
222
|
+
if (e.name === 'todo') ui.update({ sessionUpdate: 'plan', entries: (s.chat.todos ?? []).map((t) => ({ content: t.content, priority: 'medium', status: t.status === 'stuck' ? 'in_progress' : t.status })) }) // ACP has no stuck
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
|
package/src/agent.js
CHANGED
|
@@ -8,7 +8,7 @@ import path from 'node:path'
|
|
|
8
8
|
import { est, estMessages, Client, tokensOf, COMPACT_SHARE } from './client.js'
|
|
9
9
|
import { runGuided } from './guided.js'
|
|
10
10
|
import { markUsed, removeResearch, findResearch } from './research.js'
|
|
11
|
-
import { TOOL_DEFS, PLAN_HIDDEN, folderView, readOnlyCommand, searchesOutside, extraTools, runTool, listFiles, namedFiles, readFileTool, clip, allowed, loadMcpTools, saveOutput, isSavedOutput, runningCall, imageUrl, MAX_IMAGE, failed, refusal, noteNamedPaths, sendTodos } from './tools.js'
|
|
11
|
+
import { TOOL_DEFS, PLAN_HIDDEN, folderView, readOnlyCommand, searchesOutside, extraTools, runTool, listFiles, namedFiles, readFileTool, clip, allowed, loadMcpTools, saveOutput, isSavedOutput, runningCall, imageUrl, MAX_IMAGE, failed, refusal, noteNamedPaths, sendTodos, stuckSaid } from './tools.js'
|
|
12
12
|
import { serversNote } from './lsp.js'
|
|
13
13
|
import { newlyEnded, jobLine } from './background.js'
|
|
14
14
|
import { loadHooks, runHooks } from './hooks.js'
|
|
@@ -239,12 +239,17 @@ export class Session {
|
|
|
239
239
|
async subagent(args, signal, id) {
|
|
240
240
|
const task = String(args.prompt ?? args.task ?? '').trim()
|
|
241
241
|
if (!task) return 'error: give the helper its job in "prompt"'
|
|
242
|
+
// an image named in the job but not given in "images" (a screenshot's path): given, so a model
|
|
243
|
+
// that can see takes the job; one that can't would answer without looking
|
|
244
|
+
const named = [...task.matchAll(/(?:^|[\s"'`(])((?:~|\/|\.{0,2}\/)?[\w./-]+\.(?:png|jpe?g|webp|gif))\b/gi)].map((m) => m[1]).filter((f) => fs.existsSync(path.resolve(this.root, f.replace(/^~(?=\/)/, os.homedir()))))
|
|
245
|
+
const given = [].concat(args.images ?? []).filter(Boolean)
|
|
242
246
|
let images
|
|
243
247
|
try {
|
|
244
|
-
images = await loadImages(args.images, this, signal)
|
|
248
|
+
images = await loadImages(given.length || !named.length ? args.images : [...new Set(named)], this, signal)
|
|
245
249
|
} catch (e) {
|
|
246
250
|
if (e.name === 'AbortError') throw e
|
|
247
|
-
return `error: ${e.message}`
|
|
251
|
+
if (given.length || !named.length) return `error: ${e.message}`
|
|
252
|
+
images = [] // only named in the job (one it may not send): the job as it was
|
|
248
253
|
}
|
|
249
254
|
const name = (t) => `${t.provider} ${t.model}`
|
|
250
255
|
const { order, first, all, helpers } = this.helperModels(args, images.length > 0)
|
|
@@ -302,6 +307,10 @@ export class Session {
|
|
|
302
307
|
if (ownFiles?.length) helper.ownFiles = ownFiles.map((f) => path.resolve(this.root, f)) // a part of the plan: changes only its own files
|
|
303
308
|
Object.assign(helper, { isSub: true, research: this.research, ran: this.ran, noResearch: this.noResearch, mcp: this.mcp, skills: this.skills, hooks: this.hooks, allowTools: this.allowTools, denyTools: this.denyTools, maxTurns: this.maxTurns, autoCompact: this.autoCompact, appendSystem: this.appendSystem, fileCache: this.fileCache, noFormat: this.noFormat, noLsp: this.noLsp })
|
|
304
309
|
helper.track = (rel, before) => this.track(rel, before)
|
|
310
|
+
// a helper that can't see, given screenshots by a tool (a browser): one of your models that can
|
|
311
|
+
// describes them for its job (it has no helpers of its own to ask)
|
|
312
|
+
const seers = strat.vision ? [] : (this.team?.() ?? []).filter((x) => x.images)
|
|
313
|
+
if (seers.length && this.engineFor) helper.describeFor = async (files) => (await this.describeImages(files.map((f) => imageUrl(f)), seers, task, signal, () => prompt('agent/describe-screenshot', { task: clip(task, 1500) }))).trim()
|
|
305
314
|
helper.mcpGate = async () => (await this.#gate(helper), () => {})
|
|
306
315
|
if (this.onEvent) helper.onEvent = (e) => this.onEvent({ ...e, parent: id, helper: label })
|
|
307
316
|
log('agent', `helper "${label}" (${images.length} image(s)): ${task}`)
|
|
@@ -350,7 +359,8 @@ export class Session {
|
|
|
350
359
|
|
|
351
360
|
// Images for a model that can't see them: your models that can describe each, for the task (the
|
|
352
361
|
// next one when one fails).
|
|
353
|
-
|
|
362
|
+
// ask: the request for each (default: an image the user attached).
|
|
363
|
+
async describeImages(images, seers, task, signal, ask = () => prompt('guided/describe-image', { task })) {
|
|
354
364
|
const out = []
|
|
355
365
|
let by = ''
|
|
356
366
|
for (const [i, url] of images.entries()) {
|
|
@@ -360,7 +370,7 @@ export class Session {
|
|
|
360
370
|
try {
|
|
361
371
|
const { client } = await this.engineFor(seer)
|
|
362
372
|
client.retryIf = (e, attempt) => attempt < 3 && !e.notStarted
|
|
363
|
-
said = (await client.chat({ messages: [{ role: 'user', content: [{ type: 'text', text:
|
|
373
|
+
said = (await client.chat({ messages: [{ role: 'user', content: [{ type: 'text', text: ask() }, { type: 'image_url', image_url: { url } }] }] }, { signal })).content.trim()
|
|
364
374
|
} catch (e) {
|
|
365
375
|
if (e.name === 'AbortError' || signal?.aborted) throw e
|
|
366
376
|
this.ui.warn(`${seer.model} couldn't look at image ${i + 1}: ${clip(e.message, 120)}`)
|
|
@@ -460,7 +470,7 @@ export class Session {
|
|
|
460
470
|
// It runs after the answer is back (wrapUpLater), beside whatever you do next: its own connection,
|
|
461
471
|
// one wrap-up at a time; what it needs is taken from the task first, before the next one changes it.
|
|
462
472
|
wrapUpLater(task, answer) {
|
|
463
|
-
const at = { research: this.research, turn: this.chat.turns.at(-1), dirsBefore: this.dirsBefore, ran: this.ran, runs: this.runs }
|
|
473
|
+
const at = { research: this.research, turn: this.chat.turns.at(-1), dirsBefore: this.dirsBefore, ran: this.ran, runs: this.runs, troubles: this.troubles?.splice(0) ?? [], stuckLeft: (this.chat.todos ?? []).some((t) => t.status === 'stuck'), review: this.lastReview, model: this.client.model, unstuckLearned: this.unstuckLearned }
|
|
464
474
|
const job = (this.wrapping ?? Promise.resolve())
|
|
465
475
|
.then(() => this.wrapUp(task, answer, undefined, at))
|
|
466
476
|
.catch((e) => log('wrapup', `failed: ${e.message}`))
|
|
@@ -471,6 +481,16 @@ export class Session {
|
|
|
471
481
|
// at: the task's own state (wrapUpLater), else this message's
|
|
472
482
|
async wrapUp(task, answer, signal, at = { research: this.research, turn: this.chat.turns.at(-1), dirsBefore: this.dirsBefore, ran: this.ran, runs: this.runs }) {
|
|
473
483
|
if (this.isSub || !this.memory || this.ui.permission === 'plan') return
|
|
484
|
+
// it struggled (said it was stuck, gave up, was handed over): what blocked it is learned, so the
|
|
485
|
+
// next task like this starts knowing it. Solved: what got it out; not: what to know or try first
|
|
486
|
+
// What it learns from: how it ended (the answer, the review's points), not the excuses given on the
|
|
487
|
+
// way ("I can't browse" would teach giving up); the steps it said it was stuck on, with why.
|
|
488
|
+
const unsolved = Boolean(at.stuckLeft || at.review?.verdict === 'no' || SAYS_FAILED.test(String(answer ?? '').slice(0, 400)))
|
|
489
|
+
if (at.troubles?.length && (unsolved || !at.unstuckLearned)) { // solved, and what got it out learned already: not again
|
|
490
|
+
const steps = [...new Set(at.troubles.filter((t) => t.step !== 'the task' && t.step !== 'handed over').map((t) => `${t.step}: ${t.why}`))].slice(-2)
|
|
491
|
+
const what = [`${unsolved ? 'Not done' : `Done by ${at.model} after other tries failed`}. Its answer: ${clip(String(answer ?? '').replace(/\s+/g, ' '), 400)}`, at.review?.verdict === 'no' && `The review said: ${clip(at.review.issues.replace(/\s+/g, ' '), 300)}`, steps.length && `Stuck on: ${steps.join(' / ')}`].filter(Boolean).join('\n')
|
|
492
|
+
await learnFromFixes(this, [{ error: what, context: 'general' }], signal, { unsolved, task }).catch((e) => log('learn', `troubles: ${e.message}`))
|
|
493
|
+
}
|
|
474
494
|
const pages = at.research ?? []
|
|
475
495
|
const turn = at.turn
|
|
476
496
|
const made = Object.entries(turn?.files ?? {}).filter(([rel, before]) => before === null && fs.existsSync(path.join(this.root, rel))).map(([rel]) => rel)
|
|
@@ -877,9 +897,11 @@ async function runNative(s, task, images, signal) {
|
|
|
877
897
|
s.splitAsked = false // asked whether a plan's parts could run side by side, this message
|
|
878
898
|
s.lookedUp = s.researchAsked = false // searched or read the web this message / asked whether the plan needs it
|
|
879
899
|
// what changed and when it was last checked, this message: a change not run/tested since isn't done
|
|
880
|
-
Object.assign(s, { changed: new Set(), seq: 0, lastChangeAt: -1, lastCheckAt: -1, reviewedAt: -1, checksSince: 0, spots: new Map() })
|
|
900
|
+
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 })
|
|
881
901
|
|
|
882
902
|
let empty = 0 // replies in a row with neither text nor tool calls
|
|
903
|
+
let lastFinal = '' // the last answer it gave (a next one the same, after being told it isn't done: it's stuck)
|
|
904
|
+
let refusedCan = 0 // replies saying it can't (browse, run…) before trying a tool, this message
|
|
883
905
|
let looping = 0 // replies cut for going into a loop, this message
|
|
884
906
|
let stuck = null // why it's going round in circles (then the next model takes over; nothing stops but Esc)
|
|
885
907
|
// Going round in circles: the next of your models carries on (a different model often gets out of
|
|
@@ -888,7 +910,14 @@ async function runNative(s, task, images, signal) {
|
|
|
888
910
|
// the job goes to your next model.
|
|
889
911
|
const handOver = (why) => {
|
|
890
912
|
const was = client.model
|
|
891
|
-
|
|
913
|
+
s.gaveUp.add(`${client.provider}/${was}`) // not gone back to this message, nor asked for a second opinion
|
|
914
|
+
if (client.moveOn?.(`${was} ${why}`, s.gaveUp)) {
|
|
915
|
+
ui.warn(`${was} ${why}; handing over to ${client.model}`)
|
|
916
|
+
// the next model sees the whole conversation: told it's taking over, and not to repeat what didn't work
|
|
917
|
+
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') }) })
|
|
918
|
+
s.stuckReports = 0
|
|
919
|
+
s.troubles?.push({ model: was, step: 'handed over', why })
|
|
920
|
+
}
|
|
892
921
|
else if (s.isSub) throw Object.assign(new Error(`${was} ${why}`), { stuck: true })
|
|
893
922
|
else ui.warn(`${was} ${why} — it carries on, told so; Esc stops it`)
|
|
894
923
|
}
|
|
@@ -1061,6 +1090,45 @@ async function runNative(s, task, images, signal) {
|
|
|
1061
1090
|
return finalAnswer(s, signal)
|
|
1062
1091
|
}
|
|
1063
1092
|
empty = 0
|
|
1093
|
+
// "I can't browse / run / see…" with no tool tried this message: it has tools for that. Told what
|
|
1094
|
+
// it has, once; said again without trying, the next of your models takes the task
|
|
1095
|
+
if (!res.toolCalls.length && !s.acted && !s.isSub && CANT.test(res.content)) {
|
|
1096
|
+
log('task', `${client.model} said it can't, without trying a tool (${++refusedCan})`)
|
|
1097
|
+
if (refusedCan === 1) {
|
|
1098
|
+
s.messages.push({ role: 'user', content: prompt('agent/you-can', { mcp: (s.mcp?.names ?? []).join(', ') }) })
|
|
1099
|
+
continue
|
|
1100
|
+
}
|
|
1101
|
+
if (refusedCan === 2) {
|
|
1102
|
+
const was = client.model
|
|
1103
|
+
handOver(`said it can't do it, without trying its tools`)
|
|
1104
|
+
if (client.model !== was) refusedCan = 0 // the next model: told once too
|
|
1105
|
+
continue
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
// its answer says it didn't manage ("couldn't", "still not loading", "unable to"): taken as saying
|
|
1109
|
+
// it's stuck: told to change approach, then a second opinion, then the next model (stuckSaid);
|
|
1110
|
+
// after two models took over, its plain account of what blocks it is the answer
|
|
1111
|
+
const sameAfterNo = s.lastReview?.verdict === 'no' && lastFinal && res.content.replace(/\s+/g, ' ').trim().slice(0, 300) === lastFinal.replace(/\s+/g, ' ').trim().slice(0, 300) // a review said no, and it gives the same answer again
|
|
1112
|
+
if (!res.toolCalls.length && s.acted && !s.isSub && !s.toldLast && (sameAfterNo || SAYS_FAILED.test(res.content.slice(0, 400)))) { // told to say plainly what blocks it: that answer is the answer
|
|
1113
|
+
const why = clip(res.content.replace(/\s+/g, ' ').trim(), 200)
|
|
1114
|
+
s.messages.push({ role: 'user', content: await stuckSaid(s, 'the task', why, signal, undefined, true) })
|
|
1115
|
+
if (s.stuckSelf) {
|
|
1116
|
+
handOver(s.stuckSelf)
|
|
1117
|
+
s.stuckSelf = null
|
|
1118
|
+
s.stuckHandovers++
|
|
1119
|
+
}
|
|
1120
|
+
continue
|
|
1121
|
+
}
|
|
1122
|
+
// told it isn't done (open todos, a review's no, its own "couldn't"), and it answers again without
|
|
1123
|
+
// doing anything: the same answer, or one that only promises: the next of your models takes the task
|
|
1124
|
+
const same = (a, b) => a && b && a.replace(/\s+/g, ' ').trim().slice(0, 300) === b.replace(/\s+/g, ' ').trim().slice(0, 300)
|
|
1125
|
+
if (!res.toolCalls.length && !sinceNudge && nudged && !s.isSub && client.rotation && (s.stuckHandovers ?? 0) < 2 && (same(res.content, lastFinal) || PROMISED_MORE.test(res.content) || SAYS_FAILED.test(res.content.slice(0, 400)))) {
|
|
1126
|
+
handOver(`was told it isn't done and answered again without doing anything`)
|
|
1127
|
+
s.stuckHandovers++
|
|
1128
|
+
sinceNudge = true
|
|
1129
|
+
continue
|
|
1130
|
+
}
|
|
1131
|
+
if (!res.toolCalls.length) lastFinal = res.content
|
|
1064
1132
|
if (!res.toolCalls.length) {
|
|
1065
1133
|
const more = sinceNudge && ((await notDone(s, signal, nudged > 0, res.content)) ?? (await review(s, task, res.content, signal)))
|
|
1066
1134
|
showHeld(res.content) // after the review's line
|
|
@@ -1142,6 +1210,7 @@ async function runNative(s, task, images, signal) {
|
|
|
1142
1210
|
let out = refused ?? (askedWith.has(call.id) ? 'Asked together with the first ask_user call of this reply: its result has this answer too.' : pre ? await pre.running : together.has(call.id) ? await together.get(call.id) : !allowed(s, name) ? `error: the tool ${name} is not allowed here` : args ? await runTool(name, args, s, signal, call.id) : 'error: the tool arguments were not valid JSON')
|
|
1143
1211
|
if (!refused && args) out += guard.after(name, args, out)
|
|
1144
1212
|
if (guard.stuck) stuck ??= guard.stuck
|
|
1213
|
+
if (s.stuckSelf) (stuck ??= s.stuckSelf), (s.stuckSelf = null), s.stuckHandovers++ // it said so itself (todo stuck, a third time)
|
|
1145
1214
|
if (args && !refused) {
|
|
1146
1215
|
s.seq++
|
|
1147
1216
|
if (EDITS.has(name) && !failed(out)) {
|
|
@@ -1167,6 +1236,13 @@ async function runNative(s, task, images, signal) {
|
|
|
1167
1236
|
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
|
|
1168
1237
|
if (checked) s.ran?.push({ command: checked, result: clip(String(out).split('\n').filter((l) => l.trim()).slice(0, 2).join(' · '), 160) })
|
|
1169
1238
|
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
|
|
1239
|
+
// a step it said it was stuck on, now done: what got it out is a lesson
|
|
1240
|
+
if (!s.isSub && s.memory && s.unstuck?.length) {
|
|
1241
|
+
const out = s.unstuck.splice(0)
|
|
1242
|
+
s.troubles = s.troubles.filter((t) => !out.some((u) => u.step === t.step)) // learned here: not again at the wrap-up
|
|
1243
|
+
s.unstuckLearned = true
|
|
1244
|
+
await learnFromFixes(s, out.map((u) => ({ error: `stuck on "${u.step}": ${u.why}`, context: 'general' })), signal, { task: s.task ?? '' }).catch((e) => log('learn', `unstuck: ${e.message}`))
|
|
1245
|
+
}
|
|
1170
1246
|
// the same call again and again in a row (a weak model going round): told at the third, stopped at the fifth
|
|
1171
1247
|
const sig = `${name} ${call.function.arguments}`
|
|
1172
1248
|
inRow = sig === lastCall ? inRow + 1 : 1
|
|
@@ -1254,8 +1330,17 @@ export function newGuard() {
|
|
|
1254
1330
|
if (repeats >= 10) g.stuck = 'kept making calls it had already made (10 repeats)' // going round, not finding anything new
|
|
1255
1331
|
return prompt('agent/already-done', { result: was.out, circling: repeats >= 3 })
|
|
1256
1332
|
}
|
|
1333
|
+
let sameTool = null // the tool (an MCP server's own tool by name) whose calls failed in a row
|
|
1334
|
+
let sameFails = 0
|
|
1257
1335
|
g.after = (name, a, out) => {
|
|
1258
1336
|
let note = ''
|
|
1337
|
+
// any other tool (a browser's wait, click…) failing again and again: told at the third to stop and think
|
|
1338
|
+
const tool = name === 'mcp' ? `${a.server} · ${a.tool}` : name
|
|
1339
|
+
if (name !== 'run_command') {
|
|
1340
|
+
sameFails = failed(out) ? (tool === sameTool ? sameFails + 1 : 1) : 0
|
|
1341
|
+
sameTool = tool
|
|
1342
|
+
if (sameFails === 3) note += `\n\n${prompt('agent/same-tool-failing', { tool })}`
|
|
1343
|
+
}
|
|
1259
1344
|
if (name === 'run_command') {
|
|
1260
1345
|
const code = Number(/^exit code (-?\d+)/.exec(out)?.[1] ?? 0)
|
|
1261
1346
|
failing = code ? failing + 1 : 0
|
|
@@ -1304,7 +1389,8 @@ async function noteRun(s, name, args, out, signal) {
|
|
|
1304
1389
|
// Turn each fixed mistake into one reusable rule and save it (global memory, tagged by the tool it came from). The
|
|
1305
1390
|
// model writes the rule from the error; a near-duplicate lesson is skipped. Recall is automatic
|
|
1306
1391
|
// (memory.relevant attaches matching notes to a later message).
|
|
1307
|
-
|
|
1392
|
+
// unsolved: it blocked a task that wasn't done (the rule: what to know or try first); task: what was asked (found by it later).
|
|
1393
|
+
async function learnFromFixes(s, fixed, signal, { unsolved = false, task = '' } = {}) {
|
|
1308
1394
|
for (const { error, context } of fixed.slice(0, 5)) {
|
|
1309
1395
|
const tags = [runTool_(context ?? error) || 'general'] // the tool it came from (npm, python3, cargo…)
|
|
1310
1396
|
const near = s.memory.search(`tag:lesson ${tags.join(' ')}`).find((n) => n.body.toLowerCase().includes(error.replace(/^[^:]*:\s*/, '').toLowerCase().slice(0, 30)))
|
|
@@ -1316,7 +1402,7 @@ async function learnFromFixes(s, fixed, signal) {
|
|
|
1316
1402
|
s.client.purpose = 'lesson'
|
|
1317
1403
|
let reply
|
|
1318
1404
|
try {
|
|
1319
|
-
reply = await s.client.chat({ messages: [{ role: 'user', content: prompt('agent/lesson', { error }) }] }, { signal })
|
|
1405
|
+
reply = await s.client.chat({ messages: [{ role: 'user', content: prompt('agent/lesson', { error, unsolved, task: clip(task, 300) }) }] }, { signal })
|
|
1320
1406
|
} finally {
|
|
1321
1407
|
s.client.purpose = was
|
|
1322
1408
|
}
|
|
@@ -1327,7 +1413,7 @@ async function learnFromFixes(s, fixed, signal) {
|
|
|
1327
1413
|
if (e.name === 'AbortError') throw e
|
|
1328
1414
|
}
|
|
1329
1415
|
if (!rule || rule.length < 10) rule = error.replace(/^[^:]*:\s*/, '') // the model couldn't phrase it: keep the error's own wording
|
|
1330
|
-
const name = s.memory.write({ description: rule, type: 'reference', tags: ['lesson', ...tags], content: `${rule}\n\nLearned on ${new Date().toISOString().slice(0, 10)} after this was caught and fixed while building: ${error}`, scope })
|
|
1416
|
+
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 })
|
|
1331
1417
|
s.ui.step('learned', `${rule.slice(0, 90)}${scope === 'project' ? ' (this project)' : ''}`)
|
|
1332
1418
|
log('learn', `saved lesson [[${name}]] (${scope}, #${tags.join(' #')}): ${rule}`)
|
|
1333
1419
|
}
|
|
@@ -1339,7 +1425,14 @@ async function learnFromFixes(s, fixed, signal) {
|
|
|
1339
1425
|
// The model said it would do something but stopped without doing it ("let me rewrite…", "I'll fix…"):
|
|
1340
1426
|
// a next action named, then no tool call. Not matched by explanations ("let me explain", "you can run").
|
|
1341
1427
|
const PROMISED_MORE =
|
|
1342
|
-
/\b(?:let me|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)\b/i
|
|
1428
|
+
/\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
|
|
1429
|
+
|
|
1430
|
+
// The start of a final answer saying it didn't manage: "I couldn't…", "unable to…", "still showing…".
|
|
1431
|
+
const SAYS_FAILED = /\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))/i
|
|
1432
|
+
|
|
1433
|
+
// "I can't browse the web", "I'm unable to run commands", "I don't have access to…": a model
|
|
1434
|
+
// saying it lacks an ability (it has tools for it).
|
|
1435
|
+
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|access|open|visit|view|see|interact|click|navigate|run|execute|take|solve|use|control))|\bas an ai\b/i
|
|
1343
1436
|
|
|
1344
1437
|
// Is the task really done, or did the model stop early? Open todo items, or (after it did real work)
|
|
1345
1438
|
// a reply that only promises more, get one nudge to keep going. Then any Stop hook. null = truly done.
|
|
@@ -1443,8 +1536,12 @@ const isEmptyDir = (abs) => {
|
|
|
1443
1536
|
// a NO goes back to the model to fix. Asked again only once files changed since its last look.
|
|
1444
1537
|
// Returns what to tell the model, or null.
|
|
1445
1538
|
export async function review(s, task, answer, signal) {
|
|
1446
|
-
|
|
1539
|
+
// no files changed, but it ran things to do the task (a browser, commands, helpers): its answer is
|
|
1540
|
+
// checked against the request too (once per new batch of them)
|
|
1541
|
+
const acted = !s.changed?.size && (s.ran?.length ?? 0) > (s.reviewedRan ?? 0)
|
|
1542
|
+
if (s.isSub || s.ui.permission === 'plan' || (!acted && (!s.changed?.size || s.lastChangeAt <= s.reviewedAt))) return null
|
|
1447
1543
|
s.reviewedAt = s.lastChangeAt
|
|
1544
|
+
s.reviewedRan = s.ran?.length ?? 0
|
|
1448
1545
|
const turn = s.chat.turns.at(-1)
|
|
1449
1546
|
const diffs = []
|
|
1450
1547
|
let room = 16_000
|
|
@@ -1465,7 +1562,8 @@ export async function review(s, task, answer, signal) {
|
|
|
1465
1562
|
break
|
|
1466
1563
|
}
|
|
1467
1564
|
}
|
|
1468
|
-
if (!diffs.length) return null
|
|
1565
|
+
if (!diffs.length && !acted) return null
|
|
1566
|
+
if (!diffs.length) diffs.push('(no files changed)')
|
|
1469
1567
|
const plan = (s.chat.todos ?? []).map((t) => `- [${t.status === 'completed' ? 'x' : ' '}] ${t.content}`).join('\n')
|
|
1470
1568
|
const ran = (s.ran ?? []).slice(-15).map((r) => `- ${clip(r.command.replace(/\s+/g, ' '), 160)} → ${r.result}`).join('\n')
|
|
1471
1569
|
const ask = prompt('agent/review', { request: requestsOf(s.chat, 1200), emphasis: (s.chat?.choices ?? []).join('; '), plan: plan || '(none)', answer: clip(String(answer ?? ''), 3000), changes: diffs.join('\n\n'), ran: ran || '(nothing)' })
|
|
@@ -1489,12 +1587,14 @@ export async function review(s, task, answer, signal) {
|
|
|
1489
1587
|
s.ui.stopSpin()
|
|
1490
1588
|
log('review', `${t.model}: ${said}`)
|
|
1491
1589
|
if (/^\W*yes\b/i.test(said)) {
|
|
1590
|
+
s.lastReview = { verdict: 'yes' }
|
|
1492
1591
|
s.ui.event?.({ subtype: 'review', model: `${t.provider}/${t.model}`, verdict: 'yes', issues: '' })
|
|
1493
1592
|
s.ui.step('review', `${t.model}: looks right`)
|
|
1494
1593
|
return null
|
|
1495
1594
|
}
|
|
1496
1595
|
if (/^\W*no\b/i.test(said)) {
|
|
1497
1596
|
const issues = said.replace(/^\W*no\b[\s.:—-]*/i, '').trim()
|
|
1597
|
+
s.lastReview = { verdict: 'no', issues }
|
|
1498
1598
|
s.ui.event?.({ subtype: 'review', model: `${t.provider}/${t.model}`, verdict: 'no', issues })
|
|
1499
1599
|
s.ui.step('review', `${t.model}: ${clip(issues.split('\n').find((l) => l.trim()) ?? 'problems found', 90)}`)
|
|
1500
1600
|
return prompt('agent/review-failed', { model: t.model, issues: issues || '(no details given)' })
|
|
@@ -1706,14 +1806,14 @@ export function contextReport(s) {
|
|
|
1706
1806
|
const text = typeof m.content === 'string' ? m.content : (m.content ?? []).map((p) => p.text ?? '').join(' ')
|
|
1707
1807
|
const yours = tasks.some((t) => text.startsWith(t))
|
|
1708
1808
|
yours ? (parts.you += n) : (parts.notes += n)
|
|
1709
|
-
pieces.push({ tokens: n, what: yours ? `
|
|
1809
|
+
pieces.push({ tokens: n, what: yours ? `a typed message "${clip(text.split('\n')[0], 50)}"` : `a note to the model "${clip(text.split('\n')[0], 50)}"`, ago })
|
|
1710
1810
|
}
|
|
1711
1811
|
})
|
|
1712
1812
|
const toolTokens = tok(tools.map((f) => ({ type: 'function', function: f })))
|
|
1713
1813
|
const list = [
|
|
1714
1814
|
{ name: 'system prompt', tokens: parts.system },
|
|
1715
1815
|
{ name: `tools (${tools.length})`, tokens: toolTokens },
|
|
1716
|
-
{ name: '
|
|
1816
|
+
{ name: 'typed messages', tokens: parts.you },
|
|
1717
1817
|
{ name: 'notes to the model', tokens: parts.notes, note: 'summaries, guides, reminders, saved notes found' },
|
|
1718
1818
|
{ name: 'model replies', tokens: parts.replies },
|
|
1719
1819
|
{ name: 'tool results', tokens: parts.results, note: `${whole} whole` },
|
package/src/capabilities.js
CHANGED
|
@@ -33,7 +33,7 @@ export function capabilities(cfg = {}) {
|
|
|
33
33
|
else if (/whisper-cli/.test(vp)) need = 'whisper (whisper-cli) and a model — or a transcription provider'
|
|
34
34
|
else need = 'a whisper model — or a transcription provider'
|
|
35
35
|
}
|
|
36
|
-
caps.push({ id: 'voice', name: 'Voice input', what: 'Dictate
|
|
36
|
+
caps.push({ id: 'voice', name: 'Voice input', what: 'Dictate a message — Space in an empty box, or /voice.', ok: !vp, need })
|
|
37
37
|
const chrome = chromeHere()
|
|
38
38
|
const npx = onPath('npx')
|
|
39
39
|
caps.push({
|
package/src/client.js
CHANGED
|
@@ -175,6 +175,13 @@ export function fitFor(messages, can, model) {
|
|
|
175
175
|
// usage in a stream, the thinking sent back, the tools' full schemas, images.
|
|
176
176
|
export const QUIRKS = ['noTemperature', 'noEffort', 'noThoughts', 'noStreamUsage', 'noReasoningBack', 'simpleSchemas', 'noImages', 'noParallel']
|
|
177
177
|
|
|
178
|
+
// A model's name without its version: its date, "latest", "preview" ("mistral-large-2411" → "mistral-large").
|
|
179
|
+
export const family = (m) => {
|
|
180
|
+
let f = String(m).split('/').pop().toLowerCase()
|
|
181
|
+
for (let was; was !== f; ) (was = f), (f = f.replace(/[-_:@.]?(latest|preview|exp|\d{4}(-\d{2}){0,2}|\d{6,8})$/, ''))
|
|
182
|
+
return f
|
|
183
|
+
}
|
|
184
|
+
|
|
178
185
|
export class Client {
|
|
179
186
|
constructor({ baseUrl, apiKey, model, provider, timeout = 600_000 } = {}) {
|
|
180
187
|
this.provider = provider // its name in config.json, for the requests log
|
|
@@ -220,9 +227,24 @@ export class Client {
|
|
|
220
227
|
}
|
|
221
228
|
// The model in use answers but gives nothing usable (agent.js: empty replies, again and again):
|
|
222
229
|
// the next one in the list takes over. False when there's no list.
|
|
223
|
-
|
|
230
|
+
// Another version of the same model (voxtral-small-latest → voxtral-small-2507) would likely do the
|
|
231
|
+
// same: skipped for the next one in your order, while there is one.
|
|
232
|
+
// avoid: models ("provider/model") given up on already (this message): not gone back to; false when
|
|
233
|
+
// every other model is one of them.
|
|
234
|
+
moveOn(why, avoid = new Set()) {
|
|
224
235
|
if (!this.rotation) return false
|
|
225
|
-
this
|
|
236
|
+
const r = this.rotation
|
|
237
|
+
const n = r.list.length
|
|
238
|
+
const was = family(r.list[r.at].model)
|
|
239
|
+
const ok = (t) => !avoid.has(`${t.provider}/${t.model}`) && t !== r.list[r.at]
|
|
240
|
+
let k = 1
|
|
241
|
+
while (k < n && (family(r.list[(r.at + k) % n].model) === was || !ok(r.list[(r.at + k) % n]))) k++
|
|
242
|
+
if (k === n) { // only versions of this model (or ones given up on) left: the first of those not given up on
|
|
243
|
+
k = 1
|
|
244
|
+
while (k < n && !ok(r.list[(r.at + k) % n])) k++
|
|
245
|
+
if (k === n) return false
|
|
246
|
+
}
|
|
247
|
+
this.#next(why, () => (r.at + k) % n)
|
|
226
248
|
return true
|
|
227
249
|
}
|
|
228
250
|
#next(why, pick) {
|
|
@@ -353,15 +375,15 @@ export class Client {
|
|
|
353
375
|
return (await this.#fetch(url, init, { timeout })).json()
|
|
354
376
|
}
|
|
355
377
|
|
|
356
|
-
async listModels(timeout =
|
|
378
|
+
async listModels(timeout = 60_000) {
|
|
357
379
|
return (await this.modelEntries(timeout)).map((m) => m.id ?? m.name)
|
|
358
380
|
}
|
|
359
381
|
// The server's own entries for its models ({ id, owned_by, context_length, pricing… }, as it sends them).
|
|
360
|
-
async modelEntries(timeout =
|
|
382
|
+
async modelEntries(timeout = 60_000) {
|
|
361
383
|
const data = await this.#json(this.baseUrl + '/models', undefined, timeout)
|
|
362
384
|
// { result: [...] } (Cloudflare's shape): there the id is an internal one and the name is the model's
|
|
363
385
|
if (Array.isArray(data.result)) return data.result.filter((m) => m?.name).map((m) => ({ ...m, id: m.name }))
|
|
364
|
-
return (data.data ?? data.models ?? []).filter((m) => m && (m.id ?? m.name))
|
|
386
|
+
return (Array.isArray(data) ? data : (data.data ?? data.models ?? [])).filter((m) => m && (m.id ?? m.name)) // a bare list too (Typhoon)
|
|
365
387
|
}
|
|
366
388
|
|
|
367
389
|
// Best effort: asks the server how big the loaded context window is.
|
|
@@ -397,7 +419,7 @@ export class Client {
|
|
|
397
419
|
},
|
|
398
420
|
async () => {
|
|
399
421
|
const d = await this.#json(this.baseUrl + '/models')
|
|
400
|
-
const m = (d.data ?? d.models ?? []).find((x) => x.id === this.model || x.name === this.model)
|
|
422
|
+
const m = (Array.isArray(d) ? d : (d.data ?? d.models ?? [])).find((x) => x.id === this.model || x.name === this.model)
|
|
401
423
|
return { size: n(windowOf(m)), server: m?.owned_by === 'vllm' || m?.max_model_len ? 'vllm' : null }
|
|
402
424
|
},
|
|
403
425
|
async () => ({ size: n(windowOf(await this.#json(`${this.baseUrl}/models/${encodeURIComponent(this.model)}`))), server: null }),
|
|
@@ -444,7 +466,7 @@ export class Client {
|
|
|
444
466
|
return text
|
|
445
467
|
}
|
|
446
468
|
})()
|
|
447
|
-
return { error: `${res.status}: ${String(why).slice(0, 300)}${said?.rate ? ' (a per-minute cap on
|
|
469
|
+
return { error: `${res.status}: ${String(why).slice(0, 300)}${said?.rate ? ' (a per-minute cap on the account, not the window)' : ''}` }
|
|
448
470
|
}
|
|
449
471
|
|
|
450
472
|
// Returns { content, reasoning, toolCalls, usage, finishReason, thinking }.
|
package/src/config.js
CHANGED
|
@@ -31,7 +31,7 @@ export function speedOf(cfg) {
|
|
|
31
31
|
// what the pill covers (its tooltip)]
|
|
32
32
|
export const HELPER_JOBS = {
|
|
33
33
|
ui: ['UI & visuals', 'websites, app screens, games, animation, 3D, charts', 'Websites and landing pages, app screens, games and animation, 3D, charts and SVG: anything people look at.'],
|
|
34
|
-
code: ['Code & logic', 'backend, APIs, scripts, automation, fixing bugs, tests, reviewing changes', 'Backend and APIs, scripts and automation, fixing bugs, tests and refactoring. Reviews of the work go to these first, then to
|
|
34
|
+
code: ['Code & logic', 'backend, APIs, scripts, automation, fixing bugs, tests, reviewing changes', 'Backend and APIs, scripts and automation, fixing bugs, tests and refactoring. Reviews of the work go to these first, then to the other models.'],
|
|
35
35
|
hard: ['Big & hard', 'hard thinking, planning, long tasks with many steps, huge files', 'Planning and architecture, tricky logic, long tasks with many steps, huge files or whole folders.'],
|
|
36
36
|
quick: ['Quick & cheap', 'small jobs: searching and reading code, lookups, small edits', 'Searching and reading code, looking things up, small edits: simple jobs, on a model that answered fast.'],
|
|
37
37
|
}
|
package/src/context.js
CHANGED
|
@@ -85,7 +85,7 @@ export function contextSource(p, cfg = {}) {
|
|
|
85
85
|
if (from === 'server') return `reported by the server${p.server ? ` (${p.server})` : ''}`
|
|
86
86
|
if (from === 'models.dev') return "models.dev's published limit for this model"
|
|
87
87
|
if (from === 'learned') return 'learned from the server refusing or cutting a bigger request'
|
|
88
|
-
if (from === 'rate') return `
|
|
88
|
+
if (from === 'rate') return `the account's per-minute token cap at this provider, until ${new Date(p.rateCap.until).toLocaleString()}`
|
|
89
89
|
if (LOCAL_SERVERS.includes(p.server)) return `the ${p.server} server doesn't say; assumed`
|
|
90
90
|
return `the server doesn't say; assumed${p.largestAccepted ? `, and seen working up to ${p.largestAccepted} tokens` : ''} (grows as bigger requests work)`
|
|
91
91
|
}
|
package/src/headless.js
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
// stdout: {"type":"system","subtype":"init",…}, {"type":"assistant",…}, {"type":"user",…}
|
|
10
10
|
// (tool results), {"type":"result",…} after each message; and what the full screen
|
|
11
11
|
// shows besides, as {"type":"system","subtype":…}: "todos" (the plan: content, status,
|
|
12
|
-
// by: the model a part went to), "
|
|
12
|
+
// why: a stuck step's reason, by: the model a part went to), "stuck" (the model says it's
|
|
13
|
+
// stuck: step, why, count, model), "helper" (one at work: tool_use_id, label, model, status;
|
|
13
14
|
// "done" at its end), "review" (model, verdict yes/no, issues), "model_switch" (from, to,
|
|
14
15
|
// reason), "warning" (message), "retry" (attempt, delay_ms, error), "status" (what it's
|
|
15
16
|
// doing now, as the spinner says it: a running command's latest output line too)
|
|
@@ -149,7 +150,7 @@ export async function runHeadless(app, opts) {
|
|
|
149
150
|
const emit = (obj) => process.stdout.write(JSON.stringify(obj) + '\n')
|
|
150
151
|
const s = await app.session()
|
|
151
152
|
if (!s) {
|
|
152
|
-
const error = app.allOff() ? "the providers of all
|
|
153
|
+
const error = app.allOff() ? "the providers of all the models are switched off: switch one on (heart settings), or pass --model" : 'no model set up: add a provider and choose a model (heart settings), or pass --base-url and --model'
|
|
153
154
|
if (out === 'text') process.stderr.write(`heartcode: ${error}\n`)
|
|
154
155
|
else emit({ type: 'result', subtype: 'error_during_execution', is_error: true, result: error, num_turns: 0, session_id: app.chat.id })
|
|
155
156
|
return 1
|