ai-agentmanager 1.71.0 → 1.72.0
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 +10 -0
- package/README.md +24 -0
- package/package.json +1 -1
- package/public/app.js +66 -5
- package/public/glance.js +69 -3
- package/public/index.html +15 -1
- package/public/review.js +40 -2
- package/public/style.css +18 -0
- package/public/valuelens.js +19 -4
- package/src/blame.js +146 -0
- package/src/calibration.js +115 -0
- package/src/cli.js +96 -0
- package/src/echo.js +110 -0
- package/src/fence.js +81 -0
- package/src/manager.js +147 -2
- package/src/nightwatch.js +155 -0
- package/src/races.js +54 -0
- package/src/server.js +110 -4
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// Your calibration: before an agent starts you can guess, in one tap each, whether it will finish,
|
|
2
|
+
// how long it will take, and how much reading its work will need. Once the work settles, the guess
|
|
3
|
+
// is set against what happened: the outcome it wrote, the time from start to its finished brief,
|
|
4
|
+
// and the Read first level its work got (readfirst.js). Over weeks this says what you judge well
|
|
5
|
+
// and what you don't, by kind of work, next to how the agents' own confidence held up. It stays on
|
|
6
|
+
// this computer, for you: no one else's numbers, and nothing is sent anywhere.
|
|
7
|
+
import { kindOf, KIND_LABEL } from './record.js';
|
|
8
|
+
|
|
9
|
+
export const REVIEW = ['skim', 'look', 'close'];
|
|
10
|
+
const REVIEW_WORD = { skim: 'skim', look: 'look', close: 'read closely' };
|
|
11
|
+
const HOUR = 3_600_000;
|
|
12
|
+
|
|
13
|
+
/** A guess as given (from the form or the command line), or null when nothing was guessed. */
|
|
14
|
+
export function cleanGuess(g) {
|
|
15
|
+
if (!g || typeof g !== 'object') return null;
|
|
16
|
+
const out = {};
|
|
17
|
+
if (g.finish === true || g.finish === 'yes') out.finish = 'yes';
|
|
18
|
+
else if (g.finish === false || g.finish === 'no') out.finish = 'no';
|
|
19
|
+
const h = Number(g.hours);
|
|
20
|
+
if (g.hours !== undefined && g.hours !== '' && g.hours !== null) {
|
|
21
|
+
if (!Number.isFinite(h) || h <= 0 || h > 24 * 30) throw Object.assign(new Error('hours is a number above 0'), { status: 400 });
|
|
22
|
+
out.hours = h;
|
|
23
|
+
}
|
|
24
|
+
if (g.review) {
|
|
25
|
+
if (!REVIEW.includes(g.review)) throw Object.assign(new Error('review is skim, look or close'), { status: 400 });
|
|
26
|
+
out.review = g.review;
|
|
27
|
+
}
|
|
28
|
+
return Object.keys(out).length ? { ...out, at: new Date().toISOString() } : null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What happened, once the work settled; null before. `a` is the agent's view. */
|
|
32
|
+
export function actualOf(a) {
|
|
33
|
+
const b = a.brief ?? {};
|
|
34
|
+
const outcome = b.results?.outcome ?? null;
|
|
35
|
+
const merged = Object.values(a.prs ?? {}).some((p) => p.state === 'MERGED' && p.source !== 'mentioned');
|
|
36
|
+
// Settled: an outcome it wrote (not "in progress"), a merged pull request, or a brief marked done.
|
|
37
|
+
if (!['done', 'partial', 'blocked'].includes(outcome) && !merged && b.status !== 'done') return null;
|
|
38
|
+
// What it says of its outcome first: "done" with part of it left is not finished.
|
|
39
|
+
const finish = outcome === 'blocked' || outcome === 'partial' ? 'no' : outcome === 'done' || merged || b.status === 'done' ? 'yes' : null;
|
|
40
|
+
const end = Date.parse(b.updatedAt ?? a.activeAt ?? '');
|
|
41
|
+
const start = Date.parse(a.createdAt ?? '');
|
|
42
|
+
const hours = Number.isFinite(end - start) && end > start ? Math.max(0.1, Math.round(((end - start) / HOUR) * 10) / 10) : null;
|
|
43
|
+
const review = a.readFirst?.level ?? a.guess?.actual?.review ?? null;
|
|
44
|
+
return { finish, hours, review };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const median = (xs) => {
|
|
48
|
+
const s = [...xs].sort((x, y) => x - y);
|
|
49
|
+
if (!s.length) return null;
|
|
50
|
+
const m = Math.floor(s.length / 2);
|
|
51
|
+
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
|
|
52
|
+
};
|
|
53
|
+
const round = (x) => Math.round(x * 10) / 10;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Your guesses against what happened: { rows, finish: { right, of }, time: { ratio, of }, review:
|
|
57
|
+
* { right, heavier, lighter, of }, kinds: [{ kind, label, of, missed }], agents: { held, of } }.
|
|
58
|
+
*/
|
|
59
|
+
export function calibration(views) {
|
|
60
|
+
const rows = views
|
|
61
|
+
.filter((a) => a.guess)
|
|
62
|
+
.map((a) => ({ id: a.id, name: a.name, kind: kindOf(a.intent), guess: a.guess, actual: actualOf(a) }))
|
|
63
|
+
.filter((r) => r.actual);
|
|
64
|
+
const pick = (k) => rows.filter((r) => r.guess[k] != null && r.actual[k] != null);
|
|
65
|
+
const fin = pick('finish');
|
|
66
|
+
const time = pick('hours');
|
|
67
|
+
const rev = pick('review');
|
|
68
|
+
const idx = (l) => REVIEW.indexOf(l);
|
|
69
|
+
const missed = (r) =>
|
|
70
|
+
(r.guess.finish && r.actual.finish && r.guess.finish !== r.actual.finish) ||
|
|
71
|
+
(r.guess.review && r.actual.review && r.guess.review !== r.actual.review) ||
|
|
72
|
+
(r.guess.hours && r.actual.hours && (r.actual.hours / r.guess.hours > 2 || r.actual.hours / r.guess.hours < 0.5));
|
|
73
|
+
const kinds = [...new Set(rows.map((r) => r.kind))]
|
|
74
|
+
.map((kind) => {
|
|
75
|
+
const of = rows.filter((r) => r.kind === kind);
|
|
76
|
+
return { kind, label: KIND_LABEL[kind] ?? kind, of: of.length, missed: of.filter(missed).length };
|
|
77
|
+
})
|
|
78
|
+
.sort((x, y) => y.missed / y.of - x.missed / x.of || y.of - x.of);
|
|
79
|
+
// The agents' own confidence, on the same settled work: 80% or more said, and it finished.
|
|
80
|
+
const conf = views.map((a) => ({ c: a.brief?.results?.confidence?.percent, act: actualOf(a) })).filter((x) => Number.isFinite(x.c) && x.c >= 80 && x.act?.finish);
|
|
81
|
+
return {
|
|
82
|
+
rows,
|
|
83
|
+
finish: { right: fin.filter((r) => r.guess.finish === r.actual.finish).length, of: fin.length },
|
|
84
|
+
time: { ratio: time.length ? round(median(time.map((r) => r.actual.hours / r.guess.hours))) : null, of: time.length },
|
|
85
|
+
review: { right: rev.filter((r) => r.guess.review === r.actual.review).length, heavier: rev.filter((r) => idx(r.actual.review) > idx(r.guess.review)).length, lighter: rev.filter((r) => idx(r.actual.review) < idx(r.guess.review)).length, of: rev.length },
|
|
86
|
+
kinds,
|
|
87
|
+
agents: { held: conf.filter((x) => x.act.finish === 'yes').length, of: conf.length },
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The few sentences it comes to. */
|
|
92
|
+
export function calibrationLines(c) {
|
|
93
|
+
if (!c.rows.length) return ['No guess has settled yet. Guess when you start an agent (New agent, Your guess), and come back once its work is done.'];
|
|
94
|
+
const out = [];
|
|
95
|
+
if (c.finish.of) out.push(`Whether it finishes: right ${c.finish.right} of ${c.finish.of} times.`);
|
|
96
|
+
if (c.time.of) {
|
|
97
|
+
const r = c.time.ratio;
|
|
98
|
+
out.push(r >= 1.3 ? `Time: it takes ${r}× what you guess (the middle of ${c.time.of}).` : r <= 0.77 ? `Time: it takes ${r}× what you guess: quicker than you think (the middle of ${c.time.of}).` : `Time: about what you guess (${r}×, the middle of ${c.time.of}).`);
|
|
99
|
+
}
|
|
100
|
+
if (c.review.of) out.push(`Reading it needs: right ${c.review.right} of ${c.review.of}${c.review.heavier ? `; ${c.review.heavier} needed more than you guessed` : ''}${c.review.lighter ? `; ${c.review.lighter} less` : ''}.`);
|
|
101
|
+
const worst = c.kinds.find((k) => k.missed && k.of >= 2);
|
|
102
|
+
if (worst) out.push(`Most often off: ${worst.label.toLowerCase()} (${worst.missed} of ${worst.of}). Spend your attention there, or write those briefs more fully.`);
|
|
103
|
+
if (c.agents.of) out.push(`For comparison, the agents' own confidence of 80% or more held up ${c.agents.held} of ${c.agents.of} times.`);
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function calibrationMarkdown(c) {
|
|
108
|
+
const out = ['# Your calibration', '', ...calibrationLines(c), ''];
|
|
109
|
+
if (c.rows.length) {
|
|
110
|
+
out.push('| Agent | Kind | Finishes | Hours | Reading |', '|---|---|---|---|---|');
|
|
111
|
+
const cell = (g, a, word = (x) => x) => (g == null ? '–' : `${word(g)} → ${a == null ? '?' : word(a)}`);
|
|
112
|
+
for (const r of c.rows) out.push(`| ${r.name} | ${KIND_LABEL[r.kind] ?? r.kind} | ${cell(r.guess.finish, r.actual.finish)} | ${cell(r.guess.hours, r.actual.hours)} | ${cell(r.guess.review, r.actual.review, (x) => REVIEW_WORD[x])} |`);
|
|
113
|
+
}
|
|
114
|
+
return out.join('\n').trimEnd();
|
|
115
|
+
}
|
package/src/cli.js
CHANGED
|
@@ -2560,6 +2560,102 @@ export async function main(argv) {
|
|
|
2560
2560
|
table(cps.map((c) => [`#${c.n}`, c.at.replace('T', ' ').slice(0, 19), c.sha.slice(0, 9), (c.prompt ?? '').slice(0, 60)]), ['N', 'AT', 'SNAPSHOT', 'PROMPT']);
|
|
2561
2561
|
});
|
|
2562
2562
|
|
|
2563
|
+
program
|
|
2564
|
+
.command('guess')
|
|
2565
|
+
.description('Your guess for an agent, kept private and set against what happens (agentmgr calibration): whether it finishes, how many hours it takes, how much reading it needs')
|
|
2566
|
+
.argument('<agent>')
|
|
2567
|
+
.option('--finish <yes|no>', 'whether it finishes')
|
|
2568
|
+
.option('--hours <n>', 'how long it takes, in hours')
|
|
2569
|
+
.option('--review <skim|look|close>', 'how much reading its work needs')
|
|
2570
|
+
.action(async (ref, o) => {
|
|
2571
|
+
await daemon();
|
|
2572
|
+
const a = await resolveAgent(ref);
|
|
2573
|
+
const v = await api('PUT', `/agents/${a.id}/guess`, { finish: o.finish, hours: o.hours, review: o.review });
|
|
2574
|
+
console.log(v.guess ? `${green('✓')} guessed for ${bold(v.name)}: ${[v.guess.finish && `finishes: ${v.guess.finish}`, v.guess.hours && `${v.guess.hours} h`, v.guess.review && `reading: ${v.guess.review}`].filter(Boolean).join(', ')}` : dim('guess cleared'));
|
|
2575
|
+
});
|
|
2576
|
+
program
|
|
2577
|
+
.command('calibration')
|
|
2578
|
+
.description("Your calibration: your guesses when agents started, against what happened (finishing, time, the reading their work needed), by kind of work, next to how the agents' own confidence held up. Private to this computer")
|
|
2579
|
+
.option('--json', 'print JSON')
|
|
2580
|
+
.action(async (o) => {
|
|
2581
|
+
await daemon();
|
|
2582
|
+
const c = await api('GET', '/calibration?format=md');
|
|
2583
|
+
if (o.json) return console.log(JSON.stringify(c, null, 2));
|
|
2584
|
+
console.log(c.markdown);
|
|
2585
|
+
});
|
|
2586
|
+
|
|
2587
|
+
program
|
|
2588
|
+
.command('night-watch')
|
|
2589
|
+
.description("Does merged work still hold on the latest main? For work merged in the last days, the agent's recorded commands are run again against the latest main in a checkout of its own; one that no longer holds names the commits since that changed the same files. Off until turned on (--on); --run runs it now. Exit 1 when something no longer holds")
|
|
2590
|
+
.option('--run', 'run it now (it waits until done)')
|
|
2591
|
+
.option('--on', 'run it every night')
|
|
2592
|
+
.option('--off', 'stop running it at night')
|
|
2593
|
+
.option('--hour <h>', 'the hour it runs at (0-23)')
|
|
2594
|
+
.option('--days <n>', 'how far back merged work is watched')
|
|
2595
|
+
.option('--json', 'print JSON')
|
|
2596
|
+
.action(async (o) => {
|
|
2597
|
+
await daemon();
|
|
2598
|
+
if (o.on || o.off || o.hour || o.days) await api('PUT', '/night-watch', { ...(o.on ? { enabled: true } : o.off ? { enabled: false } : {}), ...(o.hour ? { hour: o.hour } : {}), ...(o.days ? { days: o.days } : {}) });
|
|
2599
|
+
if (o.run) await api('POST', '/night-watch/run', {});
|
|
2600
|
+
const v = await api('GET', '/night-watch?format=md');
|
|
2601
|
+
if (o.json) return console.log(JSON.stringify(v, null, 2));
|
|
2602
|
+
console.log(dim(`${v.settings.enabled ? `On: every night from ${v.settings.hour}:00` : 'Off at night (agentmgr night-watch --on)'}, merged work of the last ${v.settings.days} days`));
|
|
2603
|
+
console.log(v.markdown);
|
|
2604
|
+
if (v.broken) process.exitCode = 1;
|
|
2605
|
+
});
|
|
2606
|
+
|
|
2607
|
+
program
|
|
2608
|
+
.command('fence')
|
|
2609
|
+
.description('Scope fence: the areas of code it changes that what it was asked and planned does not name (tests, docs and config never count). Allow an area, or pull it back. Exit 1 while it drifts')
|
|
2610
|
+
.argument('<agent>')
|
|
2611
|
+
.option('--allow <area>', 'that area belongs to the task: in scope from now on')
|
|
2612
|
+
.option('--pull', 'tell it to stay within its task and undo those changes unless they are needed')
|
|
2613
|
+
.action(async (ref, o) => {
|
|
2614
|
+
await daemon();
|
|
2615
|
+
let a = await resolveAgent(ref);
|
|
2616
|
+
if (o.allow || o.pull) a = await api('POST', `/agents/${a.id}/fence`, o.allow ? { allow: o.allow } : { pull: true });
|
|
2617
|
+
const drift = a.fence?.drift ?? [];
|
|
2618
|
+
if (o.pull) console.log(`${green('✓')} told to stay within its task`);
|
|
2619
|
+
if (!drift.length) return console.log(dim(`${a.name}: nothing outside its task${a.fence?.allowed?.length ? ` (allowed: ${a.fence.allowed.join(', ')})` : ''}`));
|
|
2620
|
+
console.log(`${yellow('Outside its task')} ${bold(a.name)}`);
|
|
2621
|
+
for (const d of drift) console.log(` ${bold(d.area)} ${dim(`${d.files.length} files, ${d.lines} lines: ${d.files.slice(0, 4).join(', ')}`)}`);
|
|
2622
|
+
console.log(dim(` agentmgr fence ${a.id} --allow <area> · agentmgr fence ${a.id} --pull`));
|
|
2623
|
+
process.exitCode = 1;
|
|
2624
|
+
});
|
|
2625
|
+
|
|
2626
|
+
program
|
|
2627
|
+
.command('why')
|
|
2628
|
+
.description("Why is this line here: the moment in the agent's conversation that wrote it (what it was asked, what it said just before, the commands it had just run, and the edit), from its own transcripts")
|
|
2629
|
+
.argument('<agent>')
|
|
2630
|
+
.argument('<place>', 'file:line, a path in its folder')
|
|
2631
|
+
.option('-t, --text <text>', 'the line\'s text instead of a line number')
|
|
2632
|
+
.option('--json', 'print JSON')
|
|
2633
|
+
.action(async (ref, place, o) => {
|
|
2634
|
+
await daemon();
|
|
2635
|
+
const a = await resolveAgent(ref);
|
|
2636
|
+
const m = /^(.+?)(?::(\d+))?$/.exec(place);
|
|
2637
|
+
if (!m[2] && !o.text) throw new Error('Give file:line, or --text');
|
|
2638
|
+
const q = new URLSearchParams({ file: m[1], format: 'md', ...(m[2] ? { line: m[2] } : {}), ...(o.text ? { text: o.text } : {}) });
|
|
2639
|
+
const b = await api('GET', `/agents/${a.id}/why?${q}`);
|
|
2640
|
+
if (o.json) return console.log(JSON.stringify(b, null, 2));
|
|
2641
|
+
console.log(b.markdown);
|
|
2642
|
+
if (!b.found) process.exitCode = 1;
|
|
2643
|
+
});
|
|
2644
|
+
|
|
2645
|
+
program
|
|
2646
|
+
.command('try-path')
|
|
2647
|
+
.description('Try the other path: the agent wrote down the ways it weighed (## Options, the one it takes first). Start path N as a second agent from the same base commit, raced against the first: compare them with agentmgr race show, and keep one with agentmgr race pick')
|
|
2648
|
+
.argument('<agent>')
|
|
2649
|
+
.argument('<path>', 'the number of the path, 2 or more')
|
|
2650
|
+
.action(async (ref, n) => {
|
|
2651
|
+
await daemon();
|
|
2652
|
+
const a = await resolveAgent(ref);
|
|
2653
|
+
const race = await api('POST', `/agents/${a.id}/try-path`, { path: Number(n) });
|
|
2654
|
+
const added = race.rows.at(-1);
|
|
2655
|
+
console.log(`${green('+')} ${bold(added.name)} ${dim(added.id)} takes ${added.variant?.instructions ?? `path ${n}`}`);
|
|
2656
|
+
console.log(dim(` raced against ${a.name} in ${race.id}: agentmgr race show ${race.id}`));
|
|
2657
|
+
});
|
|
2658
|
+
|
|
2563
2659
|
const raceCmd = program.command('race').description('Several agents try the same intent; compare and keep the best');
|
|
2564
2660
|
raceCmd
|
|
2565
2661
|
.command('start')
|
package/src/echo.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Bug echo: one mistake, found in every agent at once. When a lesson is accepted in a repository's
|
|
2
|
+
// standards (often the one proposed from an incident or a revert), later agents are given it, but
|
|
3
|
+
// the ones already at work are not. So each of them with changes in that repository is checked now:
|
|
4
|
+
// a model reads its diff against the lesson and says whether it makes the same mistake, and where.
|
|
5
|
+
// One that does is flagged (Glance: to fix; its Results), and you can tell it, or say it is not
|
|
6
|
+
// the same. A diff already checked against a lesson is not checked again until it changes.
|
|
7
|
+
import crypto from 'node:crypto';
|
|
8
|
+
import { NO_REPO } from './manager.js';
|
|
9
|
+
|
|
10
|
+
const MAX_DIFF = 40_000;
|
|
11
|
+
const clip = (s, n) => String(s ?? '').replace(/\s+/g, ' ').trim().slice(0, n);
|
|
12
|
+
|
|
13
|
+
export function echoPrompt({ lesson, diff, intent }) {
|
|
14
|
+
return [
|
|
15
|
+
'A lesson was learned in this repository from a change that went wrong. Decide whether the diff below makes the same mistake.',
|
|
16
|
+
'Reply with JSON only: {"repeats": true or false, "where": "file:line of the place, or empty", "why": "one sentence: what in the diff repeats it, or why it does not"}.',
|
|
17
|
+
'Say true only when the diff itself does what the lesson warns against; not for code that merely is near the same subject, and not for what the diff does not touch.',
|
|
18
|
+
'',
|
|
19
|
+
`<lesson>${lesson}</lesson>`,
|
|
20
|
+
`<task>${clip(intent, 600)}</task>`,
|
|
21
|
+
'<diff>',
|
|
22
|
+
diff.length > MAX_DIFF ? `${diff.slice(0, MAX_DIFF)}\n[cut: the diff is longer]` : diff,
|
|
23
|
+
'</diff>',
|
|
24
|
+
].join('\n');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The model's answer, or null when it can't be read. */
|
|
28
|
+
export function parseEcho(text) {
|
|
29
|
+
const m = String(text ?? '').match(/\{[\s\S]*\}/);
|
|
30
|
+
if (!m) return null;
|
|
31
|
+
try {
|
|
32
|
+
const j = JSON.parse(m[0]);
|
|
33
|
+
if (typeof j.repeats !== 'boolean') return null;
|
|
34
|
+
return { repeats: j.repeats, where: clip(j.where, 200) || null, why: clip(j.why, 400) || null };
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** What the agent is told when you send it the echo. */
|
|
41
|
+
export const echoMessage = (e) =>
|
|
42
|
+
`A lesson was learned in this repository from a change that went wrong: "${e.lesson}". Your changes look like they repeat it${e.where ? ` at ${e.where}` : ''}${e.why ? `: ${e.why}` : ''}. Check, and fix it if so; if it is not the same, say why in your brief.`;
|
|
43
|
+
|
|
44
|
+
/** Agents whose open work could repeat a lesson: task agents with a folder, not merged yet. */
|
|
45
|
+
export function openWork(agents, except = null) {
|
|
46
|
+
return agents.filter((a) => {
|
|
47
|
+
if (a.id === except || NO_REPO.has(a.kind) || a.kind !== 'task' || a.reviewing || a.hunting || !a.workdir) return false;
|
|
48
|
+
const prs = Object.values(a.prs ?? {}).filter((p) => p.source !== 'mentioned');
|
|
49
|
+
return !prs.some((p) => p.state === 'MERGED' || p.state === 'CLOSED');
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class Echo {
|
|
54
|
+
constructor({ manager, standards, review, log = () => {} }) {
|
|
55
|
+
this.manager = manager;
|
|
56
|
+
this.standards = standards;
|
|
57
|
+
this.review = review;
|
|
58
|
+
this.log = log;
|
|
59
|
+
this.running = new Set();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Check the open work in repository `key` against `lesson` (accepted). Returns how many were checked. */
|
|
63
|
+
async run(key, lesson) {
|
|
64
|
+
if (!lesson?.text || lesson.state !== 'accepted') return 0;
|
|
65
|
+
const agents = openWork(this.standards.agentsOf(key), lesson.source?.agentId ?? null);
|
|
66
|
+
let n = 0;
|
|
67
|
+
for (const a of agents) {
|
|
68
|
+
if (await this.check(a.id, lesson).catch((e) => this.log(`bug echo: ${a.name}: ${e.message}`))) n++;
|
|
69
|
+
}
|
|
70
|
+
return n;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** One agent against one lesson; kept on the agent as echoes[lessonId]. */
|
|
74
|
+
async check(id, lesson) {
|
|
75
|
+
const k = `${id}:${lesson.id}`;
|
|
76
|
+
if (this.running.has(k)) return false;
|
|
77
|
+
this.running.add(k);
|
|
78
|
+
try {
|
|
79
|
+
const { diff } = await this.review.get(id);
|
|
80
|
+
if (!diff?.trim()) return false;
|
|
81
|
+
const hash = crypto.createHash('sha1').update(`${lesson.text}\n${diff}`).digest('hex').slice(0, 12);
|
|
82
|
+
const agent = this.manager.get(id);
|
|
83
|
+
const prev = agent?.echoes?.[lesson.id];
|
|
84
|
+
if (!agent || prev?.hash === hash) return false;
|
|
85
|
+
const r = await this.manager.ladderShot(agent, echoPrompt({ lesson: lesson.text, diff, intent: agent.intent }), { timeoutMs: 180_000 });
|
|
86
|
+
const found = parseEcho(r.text);
|
|
87
|
+
if (!found) return false;
|
|
88
|
+
const now = this.manager.get(id);
|
|
89
|
+
if (!now) return false;
|
|
90
|
+
this.manager.patch(id, { echoes: { ...now.echoes, [lesson.id]: { lesson: lesson.text, ...found, hash, by: r.by ?? null, at: new Date().toISOString(), state: found.repeats ? 'open' : 'clear' } } });
|
|
91
|
+
return true;
|
|
92
|
+
} finally {
|
|
93
|
+
this.running.delete(k);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** You on a flagged one: 'tell' (it is sent the echo) or 'dismiss' (not the same). */
|
|
98
|
+
act(id, lessonId, what) {
|
|
99
|
+
const agent = this.manager.mustGet(id);
|
|
100
|
+
const e = agent.echoes?.[lessonId];
|
|
101
|
+
if (!e || !e.repeats) throw Object.assign(new Error('Nothing flagged for that lesson'), { status: 404 });
|
|
102
|
+
if (what === 'tell') this.manager.tell(id, echoMessage(e), { source: 'echo' });
|
|
103
|
+
else if (what !== 'dismiss') throw Object.assign(new Error('tell or dismiss'), { status: 400 });
|
|
104
|
+
this.manager.patch(id, { echoes: { ...agent.echoes, [lessonId]: { ...e, state: what === 'tell' ? 'told' : 'dismissed', doneAt: new Date().toISOString() } } });
|
|
105
|
+
return this.manager.view(this.manager.get(id));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The flagged ones still to act on, for Glance and the Results. */
|
|
110
|
+
export const openEchoes = (a) => Object.entries(a.echoes ?? {}).filter(([, e]) => e.repeats && e.state === 'open').map(([id, e]) => ({ id, ...e }));
|
package/src/fence.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Scope fence: an agent asked to fix login that starts rewriting payments is not stuck, it is
|
|
2
|
+
// wandering. The areas of the code it changed (a folder such as src/payments) are set against
|
|
3
|
+
// what it was asked and planned (INTENT, SPEC, PLAN, its brief): an area none of them names,
|
|
4
|
+
// changed in more than a line or two, is drift. Tests, docs and config are never drift, and an
|
|
5
|
+
// area the person allowed is in scope from then on. When the intent and plan name no area at all,
|
|
6
|
+
// nothing can be judged and nothing is said. No model is asked: each area is a fact to check.
|
|
7
|
+
|
|
8
|
+
// Folders that hold modules: their area is one level deeper (src/payments, packages/api).
|
|
9
|
+
const CONTAINERS = new Set(['src', 'lib', 'app', 'apps', 'packages', 'services', 'internal', 'pkg', 'cmd', 'modules', 'components', 'server', 'client', 'web', 'api']);
|
|
10
|
+
const MIN_FILES = 2;
|
|
11
|
+
const MIN_LINES = 30;
|
|
12
|
+
|
|
13
|
+
/** The area of a file: its module folder, or "(top)" for a file at the top. */
|
|
14
|
+
export function areaOf(file) {
|
|
15
|
+
const parts = String(file).split('/').filter(Boolean);
|
|
16
|
+
if (parts.length < 2) return '(top)';
|
|
17
|
+
if (CONTAINERS.has(parts[0]) && parts.length > 2) return `${parts[0]}/${parts[1]}`;
|
|
18
|
+
return parts[0];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Tests, docs and config: changed along with any work, never a sign of drift. */
|
|
22
|
+
export function incidental(file) {
|
|
23
|
+
const f = String(file).toLowerCase();
|
|
24
|
+
const base = f.split('/').pop();
|
|
25
|
+
return (
|
|
26
|
+
/(^|\/)(tests?|__tests__|spec|e2e|fixtures|docs?|\.github|\.vscode)\//.test(f) ||
|
|
27
|
+
/\.(test|spec)\.[a-z]+$|_test\.[a-z]+$|\.(md|txt|rst|lock)$/.test(f) ||
|
|
28
|
+
/^(package(-lock)?\.json|yarn\.lock|pnpm-lock\.yaml|tsconfig.*\.json|\.gitignore|\.eslintrc.*|\.prettierrc.*|dockerfile|makefile|readme.*|changelog.*|license.*)$/.test(base) ||
|
|
29
|
+
/\.config\.[a-z]+$/.test(base)
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const words = (s) => new Set(String(s ?? '').toLowerCase().split(/[^a-z0-9_-]+/).filter((w) => w.length >= 3));
|
|
34
|
+
|
|
35
|
+
/** Whether the text names an area: its path, its folder name, or one of its files. */
|
|
36
|
+
function named(area, files, text, ws) {
|
|
37
|
+
if (area === '(top)') return files.some((f) => text.includes(f.toLowerCase()) || ws.has(f.split('/').pop().replace(/\.[^.]+$/, '').toLowerCase()));
|
|
38
|
+
const a = area.toLowerCase();
|
|
39
|
+
const leaf = a.split('/').pop();
|
|
40
|
+
if (text.includes(a) || (leaf.length >= 4 && ws.has(leaf))) return true;
|
|
41
|
+
// A singular or plural of the folder ("payment" for payments).
|
|
42
|
+
if (leaf.length >= 5 && (ws.has(leaf.replace(/s$/, '')) || ws.has(`${leaf}s`))) return true;
|
|
43
|
+
return files.some((f) => {
|
|
44
|
+
const base = f.split('/').pop().toLowerCase();
|
|
45
|
+
const stem = base.replace(/\.[^.]+$/, '');
|
|
46
|
+
return text.includes(f.toLowerCase()) || text.includes(base) || (stem.length >= 4 && ws.has(stem));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The fence: { judged, areas: [{ area, files, lines, inScope, why }], drift: [the out-of-scope
|
|
52
|
+
* areas big enough to mention] }. `files`: { path: { added, removed } } (what it changed so far);
|
|
53
|
+
* `text`: what it was asked and planned; `allowed`: areas the person said are fine.
|
|
54
|
+
*/
|
|
55
|
+
export function fenceOf({ files = {}, text = '', allowed = [] }) {
|
|
56
|
+
const t = String(text).toLowerCase();
|
|
57
|
+
const ws = words(text);
|
|
58
|
+
const by = new Map();
|
|
59
|
+
for (const [f, c] of Object.entries(files)) {
|
|
60
|
+
if (incidental(f)) continue;
|
|
61
|
+
const a = areaOf(f);
|
|
62
|
+
const e = by.get(a) ?? by.set(a, { area: a, files: [], lines: 0 }).get(a);
|
|
63
|
+
e.files.push(f);
|
|
64
|
+
e.lines += (c?.added ?? 0) + (c?.removed ?? 0);
|
|
65
|
+
}
|
|
66
|
+
const areas = [...by.values()].map((e) => {
|
|
67
|
+
const ok = allowed.includes(e.area) ? 'allowed by you' : named(e.area, e.files, t, ws) ? 'named in what it was asked or planned' : null;
|
|
68
|
+
return { ...e, files: e.files.sort(), inScope: Boolean(ok), why: ok ?? 'not named in what it was asked or planned' };
|
|
69
|
+
});
|
|
70
|
+
// Nothing in the intent or plan names any area it changed: a vague task, which can't be fenced.
|
|
71
|
+
const judged = areas.some((a) => a.inScope && a.why !== 'allowed by you');
|
|
72
|
+
const drift = judged ? areas.filter((a) => !a.inScope && (a.files.length >= MIN_FILES || a.lines >= MIN_LINES)).sort((x, y) => y.lines - x.lines) : [];
|
|
73
|
+
return { judged, areas: areas.sort((x, y) => y.lines - x.lines), drift };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** One line for a drift: "src/payments (3 files, 80 lines)". */
|
|
77
|
+
export const driftLine = (d) => `${d.area} (${d.files.length} file${d.files.length === 1 ? '' : 's'}, ${d.lines} line${d.lines === 1 ? '' : 's'})`;
|
|
78
|
+
|
|
79
|
+
/** What the agent is told when the person pulls it back. */
|
|
80
|
+
export const pullBackMessage = (drift) =>
|
|
81
|
+
`You have been changing code outside what you were asked and planned: ${drift.map(driftLine).join('; ')}. Stay within the task. Undo those changes unless the task cannot be done without them; if it cannot, say why in your brief and keep them as small as you can.`;
|
package/src/manager.js
CHANGED
|
@@ -146,6 +146,8 @@ import { PROOF_FILE, proofBlock, proofFacts, proofPrompt } from './proof.js';
|
|
|
146
146
|
import { PRIVATE_MESSAGE, ideaPatch, keptPrivate, mustBeShareable } from './private.js';
|
|
147
147
|
import { awaitsReview, readFirst } from './readfirst.js';
|
|
148
148
|
import { traceOf } from './trace.js';
|
|
149
|
+
import { blameLine, readTranscripts } from './blame.js';
|
|
150
|
+
import { fenceOf, pullBackMessage } from './fence.js';
|
|
149
151
|
import { GroundRules, groundRulesMessage } from './groundrules.js';
|
|
150
152
|
import { autonomySettings, callLadder, eligible as autonomyEligible, levelOf, modelName, parseLevel } from './autonomy.js';
|
|
151
153
|
import { STUCK_DEFAULTS, detectStuck } from './stuck.js';
|
|
@@ -169,7 +171,9 @@ import {
|
|
|
169
171
|
prDetails,
|
|
170
172
|
prFromUrl,
|
|
171
173
|
prsForBranch,
|
|
174
|
+
subagentTranscripts,
|
|
172
175
|
sumUsage,
|
|
176
|
+
transcriptPath,
|
|
173
177
|
} from './tracker.js';
|
|
174
178
|
|
|
175
179
|
// Per-session markers a parent Claude Code session sets. Inherited, they make the
|
|
@@ -331,6 +335,7 @@ export class AgentManager extends EventEmitter {
|
|
|
331
335
|
this.refreshing = new Map(); // agent id -> the refresh in progress
|
|
332
336
|
this.lastPrCheck = new Map();
|
|
333
337
|
this.changeSets = new Map(); // agent id -> { files, baseSha, at }: what its branch changed (conflict radar)
|
|
338
|
+
this.fences = new Map(); // agent id -> { key, value }: its scope fence, kept until its changes or brief change (fence.js)
|
|
334
339
|
this.conflicts = new Map(); // agent id -> [conflict]
|
|
335
340
|
this.activity = new Map(); // session id -> transcript activity window (stuck detection)
|
|
336
341
|
this.stuck = new Map(); // agent id -> [finding]
|
|
@@ -418,6 +423,8 @@ export class AgentManager extends EventEmitter {
|
|
|
418
423
|
keptPrivate: keptPrivate(agent),
|
|
419
424
|
// Finished and waiting for review: how much it needs reading, why, and where to start (readfirst.js).
|
|
420
425
|
readFirst: awaitsReview(agent) ? readFirst(agent, this.traceFor(agent)) : null,
|
|
426
|
+
// Changing code outside what it was asked and planned (fence.js): { drift, allowed }, or null.
|
|
427
|
+
fence: NO_REPO.has(agent.kind) || agent.reviewing || agent.hunting ? null : this.fenceFor(agent),
|
|
421
428
|
priority: agent.priority ?? 2,
|
|
422
429
|
activeAt: this.activeAt(agent, rt),
|
|
423
430
|
projectInfo: this.projectInfo(agent),
|
|
@@ -1943,6 +1950,7 @@ export class AgentManager extends EventEmitter {
|
|
|
1943
1950
|
if (agent.workdir && fs.existsSync(agent.workdir)) await git.deleteRefs(agent.workdir, `refs/agentmgr/${agent.id}/`).catch(() => {});
|
|
1944
1951
|
else if (agent.sourceDir && fs.existsSync(agent.sourceDir)) await git.deleteRefs(agent.sourceDir, `refs/agentmgr/${agent.id}/`).catch(() => {});
|
|
1945
1952
|
this.changeSets.delete(agent.id);
|
|
1953
|
+
this.fences.delete(agent.id);
|
|
1946
1954
|
for (const k of this.clashVerdicts.keys()) if (k.split('|').includes(agent.id)) this.clashVerdicts.delete(k);
|
|
1947
1955
|
this.stuck.delete(agent.id);
|
|
1948
1956
|
this.outbox.delete(agent.id);
|
|
@@ -2087,7 +2095,24 @@ export class AgentManager extends EventEmitter {
|
|
|
2087
2095
|
this.termRuntime(id, kind)?.pty?.write(data);
|
|
2088
2096
|
}
|
|
2089
2097
|
|
|
2090
|
-
/**
|
|
2098
|
+
/**
|
|
2099
|
+
* Text from the box under the terminal, typed and submitted here rather than by the page: the
|
|
2100
|
+
* Enter is pressed once the program has taken the text in, and again if it still sits in the
|
|
2101
|
+
* input box (submitTold). Sent by the page as two keystrokes, a phone's separate requests could
|
|
2102
|
+
* bring the Enter too early, and a long message stayed unsent.
|
|
2103
|
+
*/
|
|
2104
|
+
typeIn(id, text, kind = 'claude') {
|
|
2105
|
+
const rt = this.termRuntime(id, kind);
|
|
2106
|
+
if (!rt?.pty) throw Object.assign(new Error('The session is not running'), { status: 409 });
|
|
2107
|
+
text = String(text ?? '');
|
|
2108
|
+
if (!text.trim()) throw Object.assign(new Error('Message is empty'), { status: 400 });
|
|
2109
|
+
this.inputAt.set(id, Date.now());
|
|
2110
|
+
if (shellNumber(kind)) return rt.pty.write(`${text}\r`);
|
|
2111
|
+
rt.pty.write(text.includes('\n') ? `\x1b[200~${text}\x1b[201~` : text);
|
|
2112
|
+
this.submitTold(rt, text);
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
/** Resize a session; every viewer is sent the size it took. */
|
|
2091
2116
|
resize(id, cols, rows, kind = 'claude') {
|
|
2092
2117
|
const rt = this.termRuntime(id, kind);
|
|
2093
2118
|
if (!rt || !(cols > 0 && rows > 0)) return;
|
|
@@ -2559,6 +2584,93 @@ export class AgentManager extends EventEmitter {
|
|
|
2559
2584
|
}
|
|
2560
2585
|
|
|
2561
2586
|
/** The requirement trace of an agent (trace.js), from its proof as it is on disk. */
|
|
2587
|
+
/**
|
|
2588
|
+
* The scope fence (fence.js), worked out again only when its changes, brief or allowed areas
|
|
2589
|
+
* change: { drift: [{ area, files, lines }], allowed }, or null when there is nothing to say.
|
|
2590
|
+
*/
|
|
2591
|
+
fenceFor(agent) {
|
|
2592
|
+
const cs = this.changeSets.get(agent.id);
|
|
2593
|
+
if (!cs?.files || !Object.keys(cs.files).length) return null;
|
|
2594
|
+
const allowed = agent.scope?.allowed ?? [];
|
|
2595
|
+
const mtime = (f) => {
|
|
2596
|
+
try {
|
|
2597
|
+
return fs.statSync(f(agent.id)).mtimeMs;
|
|
2598
|
+
} catch {
|
|
2599
|
+
return 0;
|
|
2600
|
+
}
|
|
2601
|
+
};
|
|
2602
|
+
const key = `${cs.at}|${agent.brief?.updatedAt}|${allowed.join(',')}|${mtime(intentPath)}|${mtime(specPath)}|${mtime(planPath)}|${agent.acceptance?.points?.length ?? 0}|${agent.intent?.length}`;
|
|
2603
|
+
const hit = this.fences.get(agent.id);
|
|
2604
|
+
if (hit?.key === key) return hit.value;
|
|
2605
|
+
const read = (f) => {
|
|
2606
|
+
try {
|
|
2607
|
+
return fs.readFileSync(f(agent.id), 'utf8');
|
|
2608
|
+
} catch {
|
|
2609
|
+
return '';
|
|
2610
|
+
}
|
|
2611
|
+
};
|
|
2612
|
+
const b = agent.brief ?? {};
|
|
2613
|
+
const text = [agent.intent, read(intentPath), read(specPath), read(planPath), b.problem, b.solution, ...(agent.acceptance?.points ?? []).map((p) => p.text ?? p)].join('\n');
|
|
2614
|
+
const f = fenceOf({ files: cs.files, text, allowed });
|
|
2615
|
+
const value = f.drift.length ? { drift: f.drift.map(({ area, files, lines }) => ({ area, files: files.slice(0, 8), lines })), allowed } : allowed.length ? { drift: [], allowed } : null;
|
|
2616
|
+
this.fences.set(agent.id, { key, value });
|
|
2617
|
+
return value;
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
/** The person on the fence: `allow` an area (in scope from now on), or `pull` it back (it is told). */
|
|
2621
|
+
setFence(ref, { allow, pull } = {}) {
|
|
2622
|
+
const agent = this.mustGet(ref);
|
|
2623
|
+
if (allow) {
|
|
2624
|
+
const area = String(allow).trim();
|
|
2625
|
+
if (!area) throw Object.assign(new Error('Which area?'), { status: 400 });
|
|
2626
|
+
this.patch(agent.id, { scope: { ...agent.scope, allowed: [...new Set([...(agent.scope?.allowed ?? []), area])] } });
|
|
2627
|
+
} else if (pull) {
|
|
2628
|
+
const drift = this.fenceFor(agent)?.drift ?? [];
|
|
2629
|
+
if (!drift.length) throw Object.assign(new Error('It is not changing anything outside its task'), { status: 409 });
|
|
2630
|
+
this.tell(agent.id, pullBackMessage(drift), { source: 'fence' });
|
|
2631
|
+
this.patch(agent.id, { scope: { ...agent.scope, pulledAt: now() } });
|
|
2632
|
+
} else throw Object.assign(new Error('allow (an area) or pull is required'), { status: 400 });
|
|
2633
|
+
return this.view(this.store.get(agent.id));
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
/**
|
|
2637
|
+
* Why is this line here (blame.js): the moment in its conversation that wrote line `lineNo` of
|
|
2638
|
+
* `file` (or the given `text`), from its sessions' transcripts and their subagents'.
|
|
2639
|
+
*/
|
|
2640
|
+
whyLine(ref, { file, line: lineNo, text } = {}) {
|
|
2641
|
+
const agent = this.mustGet(ref);
|
|
2642
|
+
if ((agent.engine ?? DEFAULT_ENGINE) !== 'claude') throw Object.assign(new Error('Only for Claude Code agents for now'), { status: 409 });
|
|
2643
|
+
if (!agent.workdir) throw Object.assign(new Error('It has no folder yet'), { status: 409 });
|
|
2644
|
+
file = String(file ?? '').replace(/^\.?\//, '');
|
|
2645
|
+
const abs = path.resolve(agent.workdir, file);
|
|
2646
|
+
const inside = (p, root) => p.startsWith(`${root}${path.sep}`);
|
|
2647
|
+
if (!file || !inside(abs, path.resolve(agent.workdir))) throw Object.assign(new Error('A file in its folder is required'), { status: 400 });
|
|
2648
|
+
// A link inside its folder that leads out of it is not followed.
|
|
2649
|
+
const root = fs.realpathSync(agent.workdir);
|
|
2650
|
+
let real = path.resolve(root, file);
|
|
2651
|
+
try {
|
|
2652
|
+
real = fs.realpathSync(abs);
|
|
2653
|
+
} catch {}
|
|
2654
|
+
if (!inside(real, root)) throw Object.assign(new Error('A file in its folder is required'), { status: 400 });
|
|
2655
|
+
if (text == null) {
|
|
2656
|
+
const n = Number(lineNo);
|
|
2657
|
+
if (!Number.isInteger(n) || n < 1) throw Object.assign(new Error('line (a number from 1) or text is required'), { status: 400 });
|
|
2658
|
+
let lines;
|
|
2659
|
+
try {
|
|
2660
|
+
lines = fs.readFileSync(abs, 'utf8').split('\n');
|
|
2661
|
+
} catch {
|
|
2662
|
+
throw Object.assign(new Error(`No file ${file} in its folder`), { status: 404 });
|
|
2663
|
+
}
|
|
2664
|
+
if (n > lines.length) throw Object.assign(new Error(`${file} has ${lines.length} lines`), { status: 400 });
|
|
2665
|
+
text = lines[n - 1];
|
|
2666
|
+
}
|
|
2667
|
+
const files = (agent.sessions ?? []).flatMap((s) => [
|
|
2668
|
+
{ session: s.id, file: transcriptPath(agent.workdir, s.id) },
|
|
2669
|
+
...subagentTranscripts(agent.workdir, s.id).map((f) => ({ session: s.id, file: f })),
|
|
2670
|
+
]);
|
|
2671
|
+
return { file, line: lineNo == null ? null : Number(lineNo), text, ...blameLine(readTranscripts(files), { file, line: text, workdir: agent.workdir }) };
|
|
2672
|
+
}
|
|
2673
|
+
|
|
2562
2674
|
traceFor(agent) {
|
|
2563
2675
|
if (!this.proof || (agent.acceptance?.status !== 'agreed' && !agent.docs?.scorecard?.data?.criteria?.length)) return null;
|
|
2564
2676
|
const p = this.proof.forScore(agent);
|
|
@@ -3541,12 +3653,45 @@ export class AgentManager extends EventEmitter {
|
|
|
3541
3653
|
rt.toldAt = t;
|
|
3542
3654
|
// Bracketed paste keeps a multi-line message as one message instead of submitting each line.
|
|
3543
3655
|
rt.pty.write(text.includes('\n') ? `\x1b[200~${text}\x1b[201~` : text);
|
|
3544
|
-
|
|
3656
|
+
this.submitTold(rt, text);
|
|
3545
3657
|
const a = this.store.get(id);
|
|
3546
3658
|
if (a) this.changed(a);
|
|
3547
3659
|
}
|
|
3548
3660
|
}
|
|
3549
3661
|
|
|
3662
|
+
/**
|
|
3663
|
+
* Press Enter on a message just typed, and again if it is still sitting in the input box. A long
|
|
3664
|
+
* message takes the program a moment to take in (Claude Code folds it into "[Pasted text]"), and
|
|
3665
|
+
* an Enter that comes before then is lost or becomes a line break. Still in the box a moment
|
|
3666
|
+
* later, and the agent not working: Enter again (twice at most).
|
|
3667
|
+
*/
|
|
3668
|
+
submitTold(rt, text, { waits = [4500, 8000] } = {}) {
|
|
3669
|
+
// The longer the message, the longer it takes in: 250 ms, up to 1.5 s for a long one.
|
|
3670
|
+
const first = 250 + Math.min(1250, Math.round(text.length / 4));
|
|
3671
|
+
setTimeout(() => rt.pty?.write('\r'), first);
|
|
3672
|
+
// (The box wraps long lines anywhere, so spaces are left out when comparing.)
|
|
3673
|
+
const snippet = text.replace(/\s+/g, '').slice(-24);
|
|
3674
|
+
const unsent = () => {
|
|
3675
|
+
if (!rt.pty || rt.busy || rt.attention) return false;
|
|
3676
|
+
// What is in the input box: after its prompt mark, the last one on the screen ("❯", or
|
|
3677
|
+
// "│ >" in older versions). The message shown anywhere else (sent, in the conversation) is not.
|
|
3678
|
+
const bottom = this.screenText(rt).slice(-600).replace(/\s+/g, '');
|
|
3679
|
+
const box = Math.max(bottom.lastIndexOf('❯'), bottom.lastIndexOf('│>'));
|
|
3680
|
+
if (box < 0) return false;
|
|
3681
|
+
const inBox = bottom.slice(box);
|
|
3682
|
+
return /\[Pastedtext#\d+/.test(inBox) || (snippet.length >= 8 && inBox.includes(snippet));
|
|
3683
|
+
};
|
|
3684
|
+
// (The text's own echo keeps it busy for a few seconds, so the first look is after that. While
|
|
3685
|
+
// pressing again, the next queued message waits.)
|
|
3686
|
+
for (const ms of waits) {
|
|
3687
|
+
setTimeout(() => {
|
|
3688
|
+
if (!unsent()) return;
|
|
3689
|
+
rt.pty.write('\r');
|
|
3690
|
+
rt.toldAt = Date.now();
|
|
3691
|
+
}, first + ms);
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
|
|
3550
3695
|
// ------------------------------------------------------- conflict radar
|
|
3551
3696
|
|
|
3552
3697
|
/** Recompute what an agent's branch changed since it branched (needs a base commit). */
|