teapot-coding-agent 0.37.5 → 0.37.7
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/dist/agent/agent.js +135 -203
- package/dist/agent/mcp-registry.js +1 -3
- package/dist/agent/tools.js +37 -40
- package/dist/master.js +55 -57
- package/dist/server/api.js +22 -26
- package/package.json +1 -1
- package/public/assets/index-B2q72L0W.css +1 -0
- package/public/assets/{index-6dJv64ix.js → index-DtB2apsx.js} +22 -22
- package/public/assets/index-DtB2apsx.js.map +1 -0
- package/public/assets/{shiki-QfOW42YC.js → shiki-DvEZl-OK.js} +2 -2
- package/public/assets/{shiki-QfOW42YC.js.map → shiki-DvEZl-OK.js.map} +1 -1
- package/public/index.html +2 -2
- package/public/assets/index-6dJv64ix.js.map +0 -1
- package/public/assets/index-UPEwVQvq.css +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The MCP server registry
|
|
2
|
+
* The MCP server registry: connections, tool discovery, dispatch, and the OAuth
|
|
3
3
|
* flow's plumbing.
|
|
4
4
|
*
|
|
5
5
|
* Why a registry instead of connecting per agent: several agents usually want the same
|
|
@@ -150,7 +150,6 @@ export class McpRegistry {
|
|
|
150
150
|
// The SDK reports a missing grant as an HTTP error carrying the STATUS. Reading
|
|
151
151
|
// `status` is reliable; matching the message text is not, because the SDK's message
|
|
152
152
|
// is just "Error POSTing to endpoint: <body>" and a server may send an empty body —
|
|
153
|
-
// MEASURED with a bare 401, which produced no "401" anywhere in the text.
|
|
154
153
|
const status = err.status;
|
|
155
154
|
const msg = err.message ?? "";
|
|
156
155
|
const needsAuth = status === 401 ||
|
|
@@ -323,7 +322,6 @@ export class McpRegistry {
|
|
|
323
322
|
* accept such responses". We accept them, using the issuer we recorded BEFORE sending the
|
|
324
323
|
* browser out, because that is the value the mix-up check needs.
|
|
325
324
|
*
|
|
326
|
-
* MEASURED against the real SDK with this machine's stored grant:
|
|
327
325
|
* no iss -> IssuerMismatchError "received undefined" (the reported failure)
|
|
328
326
|
* correct iss -> the token endpoint is reached (invalid_grant for a dummy code)
|
|
329
327
|
* wrong iss -> IssuerMismatchError "received https://evil.example"
|
package/dist/agent/tools.js
CHANGED
|
@@ -76,7 +76,7 @@ export function applyEol(content, eol) {
|
|
|
76
76
|
return content.replace(/\r\n|\r|\n/g, eol);
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
-
* Optimistic-concurrency guard
|
|
79
|
+
* Optimistic-concurrency guard. The model reads a file, thinks, then
|
|
80
80
|
* writes — and in between, a sub-agent, a background job or the operator may
|
|
81
81
|
* have changed it. Anchored edits usually fail safe (old_text is gone, so the
|
|
82
82
|
* call errors), but two paths silently clobber work nobody looked at:
|
|
@@ -122,7 +122,7 @@ export function safeJoin(cwd, p) {
|
|
|
122
122
|
// symlinks inside the workspace can point anywhere — resolve the real target
|
|
123
123
|
// and confine THAT too (path.resolve alone doesn't follow links)
|
|
124
124
|
//
|
|
125
|
-
//
|
|
125
|
+
// the old code resolved `abs` and swallowed a throw, treating failure as
|
|
126
126
|
// "fine". That is exactly backwards, and the failure is the NORMAL case:
|
|
127
127
|
// `realpathSync` throws ENOENT for a file that does not exist yet, which is
|
|
128
128
|
// every write_file creating something new. So `real` stayed as the LEXICAL
|
|
@@ -202,7 +202,7 @@ function bgMapFor(cwd) {
|
|
|
202
202
|
*
|
|
203
203
|
* `PWD` is deliberately removed: the server's own PWD would contradict the
|
|
204
204
|
* `cwd` we spawn with, so a command trusting `$PWD` would act on the wrong
|
|
205
|
-
* directory
|
|
205
|
+
* directory. `bash` re-creates PWD from its actual cwd.
|
|
206
206
|
*/
|
|
207
207
|
function shellEnv() {
|
|
208
208
|
const { PWD: _pwd, ...rest } = process.env;
|
|
@@ -246,7 +246,7 @@ function toolShell() {
|
|
|
246
246
|
}
|
|
247
247
|
/**
|
|
248
248
|
* Human-readable elapsed-time suffix appended to a shell result so the MODEL
|
|
249
|
-
* sees how long a command actually took
|
|
249
|
+
* sees how long a command actually took. Only the operator saw it — the
|
|
250
250
|
* model happily re-issued commands that ran for tens of minutes.
|
|
251
251
|
*
|
|
252
252
|
* Kept terse and single-line: it rides along with the tool output, and mirrors
|
|
@@ -264,7 +264,7 @@ function startBackgroundShell(cmd, ctx) {
|
|
|
264
264
|
}
|
|
265
265
|
const id = `bg${++bgSeq}`;
|
|
266
266
|
// plain `-c`, not `-lc`: a login shell sources ~/.bash_profile, whose `cd`
|
|
267
|
-
// would move background jobs out of the workspace
|
|
267
|
+
// would move background jobs out of the workspace
|
|
268
268
|
const shellSpec = toolShell();
|
|
269
269
|
const child = spawn(shellSpec.file, shellSpec.args(cmd), {
|
|
270
270
|
cwd: ctx.cwd,
|
|
@@ -293,7 +293,7 @@ function startBackgroundShell(cmd, ctx) {
|
|
|
293
293
|
// the exit state off "close" alone left such jobs marked running FOREVER:
|
|
294
294
|
// hasRunningBgShells() said yes, the auto-continue loop kept breaking out on
|
|
295
295
|
// "background job still running", and the agent sat in "running" with the
|
|
296
|
-
// job long dead and no notification ever delivered
|
|
296
|
+
// job long dead and no notification ever delivered.
|
|
297
297
|
//
|
|
298
298
|
// So: "exit" is authoritative for state and for the completion
|
|
299
299
|
// notification; "close" only means "output finally drained" and is used to
|
|
@@ -331,7 +331,7 @@ export function isContextOverflow(err) {
|
|
|
331
331
|
const msg = String(err?.message ?? "").toLowerCase();
|
|
332
332
|
return (/context (length|window|limit)|too many tokens|prompt is too long|max.{0,12}tokens.{0,20}(exceed|surpass)|request too large|payload too large|exceeds.{0,20}limit/.test(msg) ||
|
|
333
333
|
/\b(400|413)\b.*token/.test(msg) ||
|
|
334
|
-
//
|
|
334
|
+
// some gateways answer an over-long request with HTTP 200 and put the
|
|
335
335
|
// real diagnosis in the body, which llm.ts now surfaces after the "no
|
|
336
336
|
// choices" prefix. Without this the compact-and-retry recovery never
|
|
337
337
|
// recognised it and the turn simply failed.
|
|
@@ -363,7 +363,6 @@ export function hasRunningBgShells(cwd) {
|
|
|
363
363
|
* `hasRunningBgShells(cwd)` answers for a DIRECTORY, which is the right question for
|
|
364
364
|
* `killBgShells` and the wrong one for "is this agent busy". Sub-agents inherit their parent's
|
|
365
365
|
* workspace, so a shared directory made every sibling of a busy agent report `live: true` —
|
|
366
|
-
* MEASURED: four STOPPED sub-agents showed `· ▶4` because the parent had background jobs, and
|
|
367
366
|
* their stop buttons offered to stop work that was already gone.
|
|
368
367
|
*
|
|
369
368
|
* An empty owner means a job started before owners were recorded; those are treated as
|
|
@@ -382,7 +381,7 @@ export function hasRunningBgShellsFor(cwd, owner) {
|
|
|
382
381
|
return false;
|
|
383
382
|
}
|
|
384
383
|
/**
|
|
385
|
-
* Kill every background shell for one workspace and forget the jobs
|
|
384
|
+
* Kill every background shell for one workspace and forget the jobs.
|
|
386
385
|
*
|
|
387
386
|
* `stop()` left these running. They are spawned `detached: true` for group-killing
|
|
388
387
|
* and are NOT covered by `toolAbort` (that signal only reaches a tool that is
|
|
@@ -390,7 +389,6 @@ export function hasRunningBgShellsFor(cwd, owner) {
|
|
|
390
389
|
* a background job killed nothing: the loop sat in its deliberate "wait for the
|
|
391
390
|
* job" idle state while the job kept burning CPU, and no control could end it.
|
|
392
391
|
*
|
|
393
|
-
* MEASURED: `sleep 300` outlived both `stop()` and `dispose()`.
|
|
394
392
|
*
|
|
395
393
|
* Returns how many were actually killed, so a caller can report it.
|
|
396
394
|
*/
|
|
@@ -415,7 +413,7 @@ function runShell(cmd, ctx, timeoutMs) {
|
|
|
415
413
|
const t0 = Date.now();
|
|
416
414
|
// `bash -l` sources /etc/profile + ~/.bash_profile, either of which may
|
|
417
415
|
// `cd` somewhere — which silently moved every later relative path out of
|
|
418
|
-
// the workspace
|
|
416
|
+
// the workspace. Plain `-c` starts in ctx.cwd and stays there.
|
|
419
417
|
const sh = toolShell();
|
|
420
418
|
const child = spawn(sh.file, sh.args(cmd), {
|
|
421
419
|
cwd: ctx.cwd,
|
|
@@ -432,7 +430,7 @@ function runShell(cmd, ctx, timeoutMs) {
|
|
|
432
430
|
};
|
|
433
431
|
child.stdout.on("data", collect);
|
|
434
432
|
child.stderr.on("data", collect);
|
|
435
|
-
//
|
|
433
|
+
// the kill REPORTS whether it worked. It used to swallow every failure
|
|
436
434
|
// as "already gone", and on Windows a group kill throws ALWAYS — so a timeout
|
|
437
435
|
// would report `TIMEOUT after …ms` for a process that was still running, and
|
|
438
436
|
// shutdown would leave it alive. A timeout that claims success is worse than
|
|
@@ -477,7 +475,7 @@ function runShell(cmd, ctx, timeoutMs) {
|
|
|
477
475
|
result: (code === 0 ? "" : `exit=${code}${signal ? ` signal=${signal}` : ""}\n`) +
|
|
478
476
|
clip(out.trim() || "(no output)", ctx.maxOutputBytes) +
|
|
479
477
|
// the model, not just the operator, needs to know a command was slow —
|
|
480
|
-
// otherwise it happily re-issues something that takes 40 minutes
|
|
478
|
+
// otherwise it happily re-issues something that takes 40 minutes
|
|
481
479
|
elapsed(t0),
|
|
482
480
|
});
|
|
483
481
|
});
|
|
@@ -527,7 +525,6 @@ function trailingWsMatches(srcLines, patLines) {
|
|
|
527
525
|
* once tolerance is applied? If that region is more than twice the anchor's own line count, the
|
|
528
526
|
* anchor is not specific enough and the edit would rewrite something unintended.
|
|
529
527
|
*
|
|
530
|
-
* MEASURED basis (#83): `old_text not found` is 117 of 168 edit failures, and the near-miss
|
|
531
528
|
* cases are exactly the ones where tolerance decides what matched. Being wrong there is silent.
|
|
532
529
|
*/
|
|
533
530
|
export function disproportionateSpan(text, anchor) {
|
|
@@ -588,7 +585,7 @@ function clipText(s, max) {
|
|
|
588
585
|
return s.length <= n ? s : `${s.slice(0, n)}\n… [truncated, ${s.length} chars total]`;
|
|
589
586
|
}
|
|
590
587
|
/**
|
|
591
|
-
* Patterns that backtrack catastrophically
|
|
588
|
+
* Patterns that backtrack catastrophically.
|
|
592
589
|
*
|
|
593
590
|
* A nested quantifier — a quantified group whose body is itself quantified, or
|
|
594
591
|
* alternation that can match the same text more than one way — makes the engine
|
|
@@ -1005,7 +1002,7 @@ const HASH_BLANK = " "; // 4 spaces: reserved, cannot collide with a hex hash
|
|
|
1005
1002
|
// A real hash is 4 HEX chars, but the shape also accepts other 4-8 char
|
|
1006
1003
|
// alphanumerics: a model that mistypes or invents an anchor is common enough
|
|
1007
1004
|
// that we should still recognise the SHAPE and say "that anchor is malformed"
|
|
1008
|
-
// rather than falling through to "no similar text found"
|
|
1005
|
+
// rather than falling through to "no similar text found".
|
|
1009
1006
|
const ANCHOR_RE = /^\s*(\d+):([0-9a-z]{4,8}| {4})\|/;
|
|
1010
1007
|
/** 4-char content hash (FNV-1a 32-bit → hex), of the STRIPPED line */
|
|
1011
1008
|
export function hashLine(content) {
|
|
@@ -1021,7 +1018,7 @@ export function hashLine(content) {
|
|
|
1021
1018
|
}
|
|
1022
1019
|
/** `LINE:HASH| content` for each line, 1-indexed */
|
|
1023
1020
|
export function renderHashlines(lines, startLine = 1) {
|
|
1024
|
-
// same trailing-newline rule as renderGutter
|
|
1021
|
+
// same trailing-newline rule as renderGutter: a file ending in "\n"
|
|
1025
1022
|
// splits into a final "" that is not a line, and an anchor for it is a lie
|
|
1026
1023
|
// the model can copy into an edit that then never verifies
|
|
1027
1024
|
const body = lines.length && lines[lines.length - 1] === "" ? lines.slice(0, -1) : lines;
|
|
@@ -1032,7 +1029,7 @@ export function renderHashlines(lines, startLine = 1) {
|
|
|
1032
1029
|
/**
|
|
1033
1030
|
* Width of the `N| ` gutter for a page, so every line in it lines up.
|
|
1034
1031
|
*
|
|
1035
|
-
*
|
|
1032
|
+
* the prefix had no padding, so the gutter silently widened at line 1000
|
|
1036
1033
|
* and the whole block jumped sideways mid-file — the exact "unfriendly line
|
|
1037
1034
|
* numbers" complaint. Padding to the widest number IN THE PAGE is enough: a
|
|
1038
1035
|
* page is a bounded window, and aligning to the file's total length would
|
|
@@ -1083,7 +1080,7 @@ export function resolveAnchor(lines, anchor) {
|
|
|
1083
1080
|
error: /^[0-9a-f]{4}$/.test(anchor.hash) || anchor.hash === HASH_BLANK
|
|
1084
1081
|
? `no line matches hash ${anchor.hash} — the file changed since you read it (re-read it)`
|
|
1085
1082
|
: // distinguish "you invented/mistyped this anchor" from "the file moved",
|
|
1086
|
-
// which sends the agent to fix the right thing
|
|
1083
|
+
// which sends the agent to fix the right thing
|
|
1087
1084
|
`hash ${JSON.stringify(anchor.hash)} is not a valid anchor (expected 4 hex chars) — re-read the file and copy the anchor verbatim`,
|
|
1088
1085
|
};
|
|
1089
1086
|
if (hits.length === 1)
|
|
@@ -1181,7 +1178,7 @@ export const TOOLS = [
|
|
|
1181
1178
|
required: ["path"],
|
|
1182
1179
|
},
|
|
1183
1180
|
async run(args, ctx) {
|
|
1184
|
-
//
|
|
1181
|
+
// MULTI-FILE and FUZZY reads.
|
|
1185
1182
|
//
|
|
1186
1183
|
// Both are opt-in and handled HERE rather than by restructuring this
|
|
1187
1184
|
// tool: `paths` re-enters executeTool once per file, and `fuzzy` locates
|
|
@@ -1218,7 +1215,7 @@ export const TOOLS = [
|
|
|
1218
1215
|
catch (err) {
|
|
1219
1216
|
// name the file, not just the errno: a multi-file read reports each bad
|
|
1220
1217
|
// path inline, and "ENOENT … /tmp/xyz/nope.ts" leaves the model to work
|
|
1221
|
-
// out which of the paths it asked for
|
|
1218
|
+
// out which of the paths it asked for
|
|
1222
1219
|
const code = err.code;
|
|
1223
1220
|
return {
|
|
1224
1221
|
ok: false,
|
|
@@ -1226,7 +1223,7 @@ export const TOOLS = [
|
|
|
1226
1223
|
};
|
|
1227
1224
|
}
|
|
1228
1225
|
ctx.onFileRead?.(str(args.path));
|
|
1229
|
-
//
|
|
1226
|
+
// split on ALL THREE line endings. A CR-only (old-Mac) file used to
|
|
1230
1227
|
// come back as a single line, so the model could not address lines 2..n at
|
|
1231
1228
|
// all — and a CRLF file left a trailing "\r" on every line, which then
|
|
1232
1229
|
// had to be stripped again by every consumer.
|
|
@@ -1344,7 +1341,7 @@ export const TOOLS = [
|
|
|
1344
1341
|
if (stale)
|
|
1345
1342
|
return stale;
|
|
1346
1343
|
await fs.mkdir(path.dirname(p), { recursive: true });
|
|
1347
|
-
//
|
|
1344
|
+
// a file's line endings belong to the FILE. Writing the model's
|
|
1348
1345
|
// content verbatim silently converted a CRLF (or CR) file to LF whenever
|
|
1349
1346
|
// the model rewrote it — the model never emits \r — so one logical edit
|
|
1350
1347
|
// produced a whole-file diff, and any tool that normalises on EOL (git,
|
|
@@ -1354,7 +1351,7 @@ export const TOOLS = [
|
|
|
1354
1351
|
// for a mixed file, which is left untouched on purpose: choosing a winner
|
|
1355
1352
|
// there would itself be the silent whole-file rewrite this prevents.
|
|
1356
1353
|
//
|
|
1357
|
-
//
|
|
1354
|
+
// when the file CANNOT answer — it is new, or its EOL is mixed — ask
|
|
1358
1355
|
// `.editorconfig` before falling back to LF. The order is deliberate: the
|
|
1359
1356
|
// file's own bytes outrank configuration, which outranks the default. A
|
|
1360
1357
|
// `end_of_line = crlf` in a repo whose files are all LF must not convert
|
|
@@ -1401,7 +1398,7 @@ export const TOOLS = [
|
|
|
1401
1398
|
return stale;
|
|
1402
1399
|
let oldText = str(args.old_text);
|
|
1403
1400
|
const newText = str(args.new_text);
|
|
1404
|
-
//
|
|
1401
|
+
// the single most common edit_file failure in the real logs (22
|
|
1405
1402
|
// occurrences) said only "old_text is required", while the tool's own
|
|
1406
1403
|
// schema already documents the better form. Name it and say what to do —
|
|
1407
1404
|
// the pattern master.ts uses for "not your sub-agent" (its
|
|
@@ -1445,7 +1442,7 @@ export const TOOLS = [
|
|
|
1445
1442
|
*
|
|
1446
1443
|
* Below this, an anchor cannot identify anything: " }" or "\n\n" appear everywhere, and
|
|
1447
1444
|
* any tolerant matching on them either fails ambiguously or picks a wrong span. MEASURED
|
|
1448
|
-
* across every session
|
|
1445
|
+
* across every session: `old_text not found` is 117 of 168 edit failures, and a
|
|
1449
1446
|
* large share of those are anchors too short to be unique, sent by a model that believed
|
|
1450
1447
|
* them specific.
|
|
1451
1448
|
*
|
|
@@ -1480,7 +1477,7 @@ export const TOOLS = [
|
|
|
1480
1477
|
const patLines = oldText.replace(/\r\n/g, "\n").split("\n");
|
|
1481
1478
|
const hits = trailingWsMatches(srcLines, patLines);
|
|
1482
1479
|
if (hits.length === 1 && patLines.length > 0) {
|
|
1483
|
-
//
|
|
1480
|
+
// same detection as the hashline path — CR-only files are detected
|
|
1484
1481
|
// too, and a MIXED file yields null and is left as-is rather than
|
|
1485
1482
|
// homogenised. The old `includes("\r\n")` test called a CR-only file
|
|
1486
1483
|
// "\n", so an edit to one silently converted its line endings.
|
|
@@ -1512,7 +1509,7 @@ export const TOOLS = [
|
|
|
1512
1509
|
ok: false,
|
|
1513
1510
|
// a hashline block that did not resolve gets ITS reason — the generic
|
|
1514
1511
|
// "not found" would send the model hunting for a whitespace problem
|
|
1515
|
-
// when the real issue is a stale read
|
|
1512
|
+
// when the real issue is a stale read
|
|
1516
1513
|
result: hashNote
|
|
1517
1514
|
? `old_text is a hashline block but did not resolve: ${hashNote}.`
|
|
1518
1515
|
: `old_text not found in file. ${hint} Watch indentation/trailing spaces and drop the \`N| \` line-number prefixes.`,
|
|
@@ -1540,7 +1537,7 @@ export const TOOLS = [
|
|
|
1540
1537
|
// A verified hashline block is addressed BY LINE INDEX: the anchors
|
|
1541
1538
|
// already proved which lines it means, so a block whose content occurs
|
|
1542
1539
|
// twice must still edit the anchored occurrence rather than fail the
|
|
1543
|
-
// uniqueness check
|
|
1540
|
+
// uniqueness check.
|
|
1544
1541
|
// The hashline path splits on "\n" to index by resolved line number, which
|
|
1545
1542
|
// leaves a trailing "\r" on every line of a CRLF file. Rejoining with
|
|
1546
1543
|
// "\n" then DROPS all of them, so a single edit silently rewrote a
|
|
@@ -1676,7 +1673,7 @@ export const TOOLS = [
|
|
|
1676
1673
|
`jobs are per-workspace and forgotten on harness restart`,
|
|
1677
1674
|
};
|
|
1678
1675
|
if (str(args.action) === "kill") {
|
|
1679
|
-
//
|
|
1676
|
+
// same swallowed-kill bug — this reported "killed" and dropped the
|
|
1680
1677
|
// job from the map while the process kept running, now untrackable.
|
|
1681
1678
|
const note = sh.exited ? "(already exited)" : describeKill(killTree(sh.child));
|
|
1682
1679
|
map.delete(sh.id);
|
|
@@ -1782,7 +1779,7 @@ export const TOOLS = [
|
|
|
1782
1779
|
task: { type: "string", description: "self-contained instructions for the sub-agent" },
|
|
1783
1780
|
context: { type: "string", enum: ["none", "fork"], description: "default none" },
|
|
1784
1781
|
name: { type: "string", description: "optional short name fragment for the id" },
|
|
1785
|
-
//
|
|
1782
|
+
// reasoning effort for THIS sub-agent, overriding both the
|
|
1786
1783
|
// configured subagent default and the parent's inherited value.
|
|
1787
1784
|
//
|
|
1788
1785
|
// Precedence mirrors OpenAI Codex (codex-rs/core/src/agent/child_config.rs):
|
|
@@ -1812,7 +1809,7 @@ export const TOOLS = [
|
|
|
1812
1809
|
return { ok: false, result: "task required" };
|
|
1813
1810
|
const context = args.context === "fork" ? "fork" : "none";
|
|
1814
1811
|
try {
|
|
1815
|
-
//
|
|
1812
|
+
// validate like the per-agent setter does, so a typo cannot reach
|
|
1816
1813
|
// the provider as an unrecognised effort value.
|
|
1817
1814
|
const effort = str(args.reasoning_effort).trim();
|
|
1818
1815
|
if (effort && !isReasoningEffort(effort))
|
|
@@ -1897,7 +1894,7 @@ export const TOOLS = [
|
|
|
1897
1894
|
return { ok: false, result: "sub-agents are not available here" };
|
|
1898
1895
|
const ids = Array.isArray(args.ids) ? args.ids.map(String) : undefined;
|
|
1899
1896
|
const ms = Math.min(Math.max(num(args.timeout_ms, 300_000), 1_000), 3_600_000);
|
|
1900
|
-
//
|
|
1897
|
+
// a prompt ALREADY in the queue must be consumed FIRST. The
|
|
1901
1898
|
// enqueue-time wake only fires for prompts arriving DURING the park —
|
|
1902
1899
|
// one queued before the park is invisible to it, and parking over it
|
|
1903
1900
|
// strands the operator's message ("idle" display, nothing processed)
|
|
@@ -1971,7 +1968,7 @@ export const TOOLS = [
|
|
|
1971
1968
|
name: "load_skill",
|
|
1972
1969
|
description: "Load a skill's full instructions by name. Use when the system prompt's skill list " +
|
|
1973
1970
|
"matches your current task; follow the loaded playbook. " +
|
|
1974
|
-
//
|
|
1971
|
+
// the instruction used to need a SECOND, separately-queued message that
|
|
1975
1972
|
// only arrived at the next turn boundary. Passing `instructions` delivers it
|
|
1976
1973
|
// in the SAME turn as the playbook, so "load X and do Y" costs one round-trip.
|
|
1977
1974
|
"Pass `instructions` with what you want done with it to receive both at once.",
|
|
@@ -2014,7 +2011,7 @@ export const TOOLS = [
|
|
|
2014
2011
|
listed.map((f) => `- ${f}`).join("\n") +
|
|
2015
2012
|
`\nRun scripts with bash (chmod +x first if needed).`;
|
|
2016
2013
|
}
|
|
2017
|
-
//
|
|
2014
|
+
// deliver the caller's instructions in THIS result, so the model does
|
|
2018
2015
|
// not have to queue a second message that only lands next turn.
|
|
2019
2016
|
const instructions = str(args.instructions).trim();
|
|
2020
2017
|
if (instructions)
|
|
@@ -2157,7 +2154,7 @@ export function fuzzyPathMatch(needle, hay) {
|
|
|
2157
2154
|
return false;
|
|
2158
2155
|
}
|
|
2159
2156
|
/**
|
|
2160
|
-
* Locate a file by a loose name and read it
|
|
2157
|
+
* Locate a file by a loose name and read it.
|
|
2161
2158
|
*
|
|
2162
2159
|
* Walks the workspace (skipping .git, node_modules and build noise) and ranks
|
|
2163
2160
|
* matches: exact path, exact basename, ends-with, then subsequence. When
|
|
@@ -2331,7 +2328,7 @@ export function repairToolInput(name, rawArgs) {
|
|
|
2331
2328
|
const bare = rawArgs?.trim().replace(/^[`*\s]+|[`*\s]+$/g, "");
|
|
2332
2329
|
const primary = PRIMARY_STRING_ARG[name];
|
|
2333
2330
|
// a bare number/boolean is never a path or a command — refusing is far
|
|
2334
|
-
// better than inventing one
|
|
2331
|
+
// better than inventing one
|
|
2335
2332
|
const isScalarish = bare !== "" && /^(true|false|null|-?\d+(\.\d+)?)$/i.test(bare);
|
|
2336
2333
|
if (bare && primary && !isScalarish && !bare.startsWith("{") && !bare.startsWith("[")) {
|
|
2337
2334
|
notes.push(`wrapped a bare string as {"${primary}": …}`);
|
|
@@ -2355,7 +2352,7 @@ export function repairToolInput(name, rawArgs) {
|
|
|
2355
2352
|
return { args: {}, notes, error: "arguments were empty" };
|
|
2356
2353
|
// An ARRAY is a legitimate value for a path-ish argument, but only for the
|
|
2357
2354
|
// tools that actually take one — inventing {path:[…]} for apply_patch would
|
|
2358
|
-
// hand the tool a key it has never heard of
|
|
2355
|
+
// hand the tool a key it has never heard of.
|
|
2359
2356
|
if (Array.isArray(parsed) && name === "read_file") {
|
|
2360
2357
|
notes.push("kept the array as a paths list");
|
|
2361
2358
|
return { args: { paths: parsed }, notes };
|
|
@@ -2383,7 +2380,7 @@ export function repairToolInput(name, rawArgs) {
|
|
|
2383
2380
|
}
|
|
2384
2381
|
else {
|
|
2385
2382
|
// both present: the schema key wins and the stray alias is DROPPED, not
|
|
2386
|
-
// left behind as an unknown argument the tool would ignore
|
|
2383
|
+
// left behind as an unknown argument the tool would ignore
|
|
2387
2384
|
notes.push(`dropped "${from}" — "${to}" was also given and wins`);
|
|
2388
2385
|
}
|
|
2389
2386
|
delete args[from];
|
|
@@ -2478,7 +2475,7 @@ export async function executeTool(name, rawArgs, ctx) {
|
|
|
2478
2475
|
// read-only personas (researcher/reviewer) are enforced, not just asked
|
|
2479
2476
|
if (ctx.readOnly && MUTATING_TOOLS.has(name))
|
|
2480
2477
|
return { ok: false, result: `${name} is blocked: this agent runs with read-only tools` };
|
|
2481
|
-
//
|
|
2478
|
+
// repair the call before handing it to the tool. A model that sends
|
|
2482
2479
|
// {"cmd":"ls"} or {"limit":"100"} should get the work done, not a generic parse
|
|
2483
2480
|
// failure and a wasted turn. Unrepairable calls say what to send instead.
|
|
2484
2481
|
const repaired = repairToolInput(name, rawArgs);
|