ai-agentmanager 1.62.0 → 1.64.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 +40 -0
- package/README.md +109 -0
- package/package.json +1 -1
- package/public/acceptance.js +194 -0
- package/public/app.js +84 -3
- package/public/attach.js +4 -0
- package/public/autonomy.js +144 -0
- package/public/boardcols.js +1 -0
- package/public/dropzone.js +203 -0
- package/public/groups.js +2 -0
- package/public/index.html +63 -0
- package/public/machine.js +2 -0
- package/public/menu.js +20 -0
- package/public/proof.js +114 -0
- package/public/scorecard.js +1 -1
- package/public/standup.js +1 -0
- package/public/style.css +61 -2
- package/src/acceptance.js +123 -0
- package/src/advisor.js +30 -8
- package/src/autonomy.js +684 -0
- package/src/autopilot.js +9 -1
- package/src/backlog.js +16 -3
- package/src/brief.js +24 -3
- package/src/bughunt.js +1 -0
- package/src/cli.js +171 -3
- package/src/config.js +5 -0
- package/src/decisions.js +5 -1
- package/src/engines/claude.js +4 -2
- package/src/groundrules.js +97 -0
- package/src/inbox.js +48 -0
- package/src/judge.js +1 -1
- package/src/manager.js +184 -7
- package/src/notify.js +16 -0
- package/src/prereview.js +7 -2
- package/src/proof.js +255 -0
- package/src/scorecard.js +40 -10
- package/src/server.js +66 -4
- package/src/service.js +24 -3
- package/src/standup.js +1 -0
package/src/autopilot.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// and stops early once a round no longer raises the score. Anything else ("look at these first"
|
|
11
11
|
// without a target, a failed step, a closed pull request) waits for you in the inbox, with Ship it to
|
|
12
12
|
// go ahead anyway. An item whose pull request merges is done.
|
|
13
|
+
import { autonomySettings, leftOut } from './autonomy.js';
|
|
13
14
|
import { landState } from './tracker.js';
|
|
14
15
|
|
|
15
16
|
export const AUTOPILOT_LEVELS = ['off', 'pr', 'merge'];
|
|
@@ -90,7 +91,8 @@ export class Autopilot {
|
|
|
90
91
|
this.backlog.accept(it.id);
|
|
91
92
|
return;
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
+
// Its own autonomy level when that says "pr" or "merge" (autonomy.js), else its project's.
|
|
95
|
+
const level = ['pr', 'merge'].includes(it.autonomy) ? it.autonomy : this.backlog.autopilotFor(it.projectKey);
|
|
94
96
|
if (level === 'off' && !ap.ship) return;
|
|
95
97
|
if (ap.state === 'held' && ap.round === it.reviewAt) return;
|
|
96
98
|
if (this.manager.view(agent).runtime.busy) return;
|
|
@@ -167,6 +169,12 @@ export class Autopilot {
|
|
|
167
169
|
async land(it, agent, pr) {
|
|
168
170
|
const state = landState(pr);
|
|
169
171
|
if (state === 'ready') {
|
|
172
|
+
// The agent's own confidence in what it built (its brief): a low one is yours to merge.
|
|
173
|
+
const own = this.manager.view(agent).results?.confidence;
|
|
174
|
+
const min = autonomySettings(this.config).minBuildConfidence;
|
|
175
|
+
if (own && own.percent < min) return this.hold(it, `The agent's own confidence in this is ${own.percent}%${own.why ? `: ${own.why}` : ''}. Its pull request is open; merging it is yours.`);
|
|
176
|
+
const left = leftOut(agent, this.manager.view(agent));
|
|
177
|
+
if (left) return this.hold(it, `${left} Its pull request is open; merging it is yours.`);
|
|
170
178
|
this.note(it, { state: 'merging' });
|
|
171
179
|
await this.landing.merge(agent.id, { url: pr.url });
|
|
172
180
|
this.log(`autopilot: merged ${pr.url}`);
|
package/src/backlog.js
CHANGED
|
@@ -47,6 +47,14 @@ export class Backlog extends EventEmitter {
|
|
|
47
47
|
return AUTOPILOT_LEVELS.includes(level) ? level : 'off';
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Autopilot for one item: its own autonomy level when that says "pr" or "merge" (autonomy.js),
|
|
52
|
+
* else its project's.
|
|
53
|
+
*/
|
|
54
|
+
levelFor(it) {
|
|
55
|
+
return ['pr', 'merge'].includes(it?.autonomy) ? it.autonomy : this.autopilotFor(it?.projectKey);
|
|
56
|
+
}
|
|
57
|
+
|
|
50
58
|
/** The score autopilot ships at (50-100), or null: whenever the scorecard says ready. */
|
|
51
59
|
targetFor(projectKey) {
|
|
52
60
|
const n = Number(this.data.targets[projectKey] ?? this.config.autopilot?.target);
|
|
@@ -104,7 +112,7 @@ export class Backlog extends EventEmitter {
|
|
|
104
112
|
// ------------------------------------------------------------ editing
|
|
105
113
|
|
|
106
114
|
/** Queue one item per title. Options are what an agent would take (repo, dir, base, project, ...). */
|
|
107
|
-
add(titles, { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, designDoc, demoPage, benchmarks, engine, attachments, isolation, priority = 2 } = {}) {
|
|
115
|
+
add(titles, { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, acceptance, autonomy, designDoc, demoPage, benchmarks, engine, attachments, isolation, priority = 2 } = {}) {
|
|
108
116
|
const list = titles.map((t) => String(t ?? '').trim()).filter(Boolean);
|
|
109
117
|
if (!list.length) throw err(400, 'At least one item is required');
|
|
110
118
|
const pr = parsePriority(priority);
|
|
@@ -141,6 +149,9 @@ export class Backlog extends EventEmitter {
|
|
|
141
149
|
isolation: isolation === undefined ? undefined : isolation || '',
|
|
142
150
|
plan: Boolean(plan),
|
|
143
151
|
planReview: planReview ?? null,
|
|
152
|
+
acceptance: acceptance ?? null,
|
|
153
|
+
// How far its agent goes without you (autonomy.js): null = the default.
|
|
154
|
+
autonomy: autonomy || null,
|
|
144
155
|
designDoc: designDoc ?? null,
|
|
145
156
|
demoPage: demoPage ?? null,
|
|
146
157
|
benchmarks: benchmarks ?? null,
|
|
@@ -266,6 +277,8 @@ export class Backlog extends EventEmitter {
|
|
|
266
277
|
isolation: it.isolation,
|
|
267
278
|
plan: it.plan,
|
|
268
279
|
planReview: it.planReview ?? undefined,
|
|
280
|
+
acceptance: it.acceptance ?? undefined,
|
|
281
|
+
autonomy: it.autonomy ?? undefined,
|
|
269
282
|
designDoc: it.designDoc ?? undefined,
|
|
270
283
|
demoPage: it.demoPage ?? undefined,
|
|
271
284
|
benchmarks: it.benchmarks ?? undefined,
|
|
@@ -416,8 +429,8 @@ export class Backlog extends EventEmitter {
|
|
|
416
429
|
if (it.status !== 'queued') throw err(409, 'Only queued items can be split');
|
|
417
430
|
const titles = (Array.isArray(parts) ? parts : it.aiSplit?.parts ?? []).map((t) => String(t).trim()).filter(Boolean);
|
|
418
431
|
if (titles.length < 2) throw err(400, 'Give at least two parts');
|
|
419
|
-
const { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, designDoc, demoPage, benchmarks, engine, priority } = it;
|
|
420
|
-
const added = this.add(titles, { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, designDoc, demoPage, benchmarks, engine, priority });
|
|
432
|
+
const { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, acceptance, autonomy, designDoc, demoPage, benchmarks, engine, priority } = it;
|
|
433
|
+
const added = this.add(titles, { repo, dir, base, project, worktree, permissionMode, model, plan, planReview, acceptance, autonomy, designDoc, demoPage, benchmarks, engine, priority });
|
|
421
434
|
this.manager.judge?.feedback('dispatch', { summary: `split "${it.title}"`, verdict: it.aiSplit ? 'split suggested' : 'not suggested', outcome: 'split it' });
|
|
422
435
|
delete this.data.items[id];
|
|
423
436
|
this.changed();
|
package/src/brief.js
CHANGED
|
@@ -29,6 +29,9 @@ export const briefPrompt = (file) =>
|
|
|
29
29
|
'"- Delivered: ..." for each concrete result (PR or commit links, files, documents, answers), and\n' +
|
|
30
30
|
'"- Blocked by: ... (needs: who or what)" for anything blocking progress, and\n' +
|
|
31
31
|
'"- Filed: <issue link> <title>" for each bug or issue you opened (GitHub, Jira, ...). Keep it current; it is what reviewers read first.\n' +
|
|
32
|
+
'Whenever the outcome is partial or done, add one more line under it: "Confidence: <0-100>% - <what you verified that makes you sure, ' +
|
|
33
|
+
'and the one thing you are least sure about>". Give the number honestly: what you ran and saw working counts, what you only read or ' +
|
|
34
|
+
'assumed does not, and anything in the request you did not do lowers it. Update it when you learn more.\n' +
|
|
32
35
|
'Add a fifth section only when the task links Jira issues (or other tickets):\n' +
|
|
33
36
|
'## References\nLook each linked issue up (use your Jira / Atlassian tools if you have them) and list the ' +
|
|
34
37
|
'documents its fields point to, above all its PRD and Tech Spec fields, plus design docs or Confluence pages. ' +
|
|
@@ -73,6 +76,19 @@ function sectionKey(heading) {
|
|
|
73
76
|
const CHECK_STATES = { ' ': 'pending', '~': 'running', x: 'passed', X: 'passed', '!': 'failed' };
|
|
74
77
|
|
|
75
78
|
/** Parse the brief Markdown into its four sections. Unknown sections are ignored. */
|
|
79
|
+
const CONFIDENCE_LINE = /^\s*(?:[-*]\s+)?\**\s*confidence\s*\**\s*:\s*\**\s*(\d{1,3})\s*%?\s*\**\s*(?:[-–—:,;.]\s*)?(.*)$/i;
|
|
80
|
+
|
|
81
|
+
/** The agent's own confidence in what it built, from its Results: { percent, why, level } or null. */
|
|
82
|
+
export function parseConfidence(body) {
|
|
83
|
+
for (const line of String(body ?? '').split('\n')) {
|
|
84
|
+
const m = CONFIDENCE_LINE.exec(line);
|
|
85
|
+
if (!m) continue;
|
|
86
|
+
const percent = Math.max(0, Math.min(100, Number(m[1])));
|
|
87
|
+
return { percent, why: m[2].trim().slice(0, 400), level: percent >= 85 ? 'high' : percent >= 65 ? 'medium' : 'low' };
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
76
92
|
export function parseBrief(markdown) {
|
|
77
93
|
const out = { status: null, problem: '', solution: '', diagram: null, diagramNotes: '', checks: [], references: [], results: null };
|
|
78
94
|
const st = markdown.split(/^##\s/m)[0].match(/^\s*\**status\**\s*:\s*\**\s*(planning|working|blocked|done)\b/im);
|
|
@@ -96,8 +112,13 @@ export function parseBrief(markdown) {
|
|
|
96
112
|
delivered: pick(/^\s*[-*]\s+\**\s*delivered\s*\**\s*:\s*\**\s*(.+)$/i),
|
|
97
113
|
blockers: pick(/^\s*[-*]\s+\**\s*blocked by\s*\**\s*:\s*\**\s*(.+)$/i),
|
|
98
114
|
filed: pick(/^\s*[-*]\s+\**\s*filed\s*\**\s*:\s*\**\s*(.+)$/i),
|
|
115
|
+
// "- Not done: ..." (proof.js): what the request asked that the agent says it left out. "nothing" is none.
|
|
116
|
+
notDone: pick(/^\s*[-*]\s+\**\s*not done\s*\**\s*:\s*\**\s*(.+)$/i).filter((t) => !/^(nothing|none|n\/a|-)\b\.?\**$/i.test(t)),
|
|
117
|
+
notDoneSaid: lines.some((l) => /^\s*[-*]\s+\**\s*not done\s*\**\s*:/i.test(l)),
|
|
118
|
+
// "Confidence: 85% - why": the agent's own, in what it built (null until it says).
|
|
119
|
+
confidence: parseConfidence(body),
|
|
99
120
|
notes: lines
|
|
100
|
-
.filter((l) => !/^\s*\**\s*outcome\s*\**\s*:/i.test(l) && !/^\s*[-*]\s+\**\s*(delivered|blocked by|filed)\s*\**\s*:/i.test(l))
|
|
121
|
+
.filter((l) => !/^\s*\**\s*outcome\s*\**\s*:/i.test(l) && !CONFIDENCE_LINE.test(l) && !/^\s*[-*]\s+\**\s*(delivered|blocked by|filed|not done)\s*\**\s*:/i.test(l))
|
|
101
122
|
.join('\n')
|
|
102
123
|
.trim(),
|
|
103
124
|
};
|
|
@@ -953,14 +974,14 @@ export function intentMarkdown(agent) {
|
|
|
953
974
|
}
|
|
954
975
|
|
|
955
976
|
/** The agent's instructions for SPEC.md and PLAN.md (the plan only when the plan review isn't on). */
|
|
956
|
-
export const specPrompt = (specFile, planFile, { withPlan = true } = {}) =>
|
|
977
|
+
export const specPrompt = (specFile, planFile, { withPlan = true, wait = false } = {}) =>
|
|
957
978
|
`Before you change any code, write a short spec of the task to ${specFile} (Markdown), so reviewers (people and other agents) ` +
|
|
958
979
|
'can check the work against it:\n# Spec: <short name>\n## Requirements\nWhat must be true when it is done, as a list.\n' +
|
|
959
980
|
'## Acceptance criteria\nHow each requirement is checked: a command, a test or an observable behavior.\n## Out of scope\n## Open questions\n' +
|
|
960
981
|
(withPlan
|
|
961
982
|
? `Then write your plan to ${planFile}: "# Plan: <short name>", then "## Steps" as a task list ("- [ ]" to do, "- [x]" done), ` +
|
|
962
983
|
'small enough to check, and "## Files to change". Keep both current: tick steps as you finish them, and update the spec ' +
|
|
963
|
-
|
|
984
|
+
`if the requirements change (say why). ${wait ? '' : 'Do not stop to wait for approval; carry on with the work. '}`
|
|
964
985
|
: 'Keep it current if the requirements change (say why). ') +
|
|
965
986
|
'Both files are outside the repository: never copy them into the repo or commit them.';
|
|
966
987
|
|
package/src/bughunt.js
CHANGED
package/src/cli.js
CHANGED
|
@@ -350,6 +350,8 @@ export async function main(argv) {
|
|
|
350
350
|
.option('--no-container', 'run on this computer even if containers are the default')
|
|
351
351
|
.option('--plan', 'while a repo URL clones, plan the task with Claude (moves into the repo when ready)')
|
|
352
352
|
.option('--no-design-doc', 'no design doc for this agent (on by default: "designDoc" in config.json)')
|
|
353
|
+
.option('--acceptance', 'agree on what done means first: the agent writes its points and waits for "agentmgr acceptance <agent> --agree"')
|
|
354
|
+
.option('--autonomy <level>', 'how far it goes without you: ask (the default), run (you agree on what done means, then routine questions are answered and nudges sent for you), pr (and its pull request is opened), merge (and merged when everything says ready)')
|
|
353
355
|
.option('--demo-page', 'make a sample demo page of the change, published as an Artifact')
|
|
354
356
|
.option('--benchmarks', 'micro benchmarks of the changed code, before and after')
|
|
355
357
|
.option('--no-start', 'create without launching')
|
|
@@ -379,11 +381,16 @@ export async function main(argv) {
|
|
|
379
381
|
start: opts.start,
|
|
380
382
|
plan: opts.plan,
|
|
381
383
|
designDoc: cmd.getOptionValueSource('designDoc') === 'cli' ? opts.designDoc : undefined,
|
|
384
|
+
acceptance: opts.acceptance || undefined,
|
|
385
|
+
autonomy: opts.autonomy || undefined,
|
|
382
386
|
demoPage: opts.demoPage || undefined,
|
|
383
387
|
benchmarks: opts.benchmarks || undefined,
|
|
384
388
|
});
|
|
385
389
|
for (const a of created) console.log(`${green('+')} ${bold(a.name)} ${dim(a.id)} session ${cyan(a.sessionId)}`);
|
|
386
390
|
console.log(dim(`Workspace setup and launch continue in the background. "agentmgr ls" shows status.`));
|
|
391
|
+
if (created.some((a) => a.autonomy && !['auto', 'bypassPermissions'].includes(a.permissionMode ?? ''))) {
|
|
392
|
+
console.log(dim('Without you: it still stops at each permission prompt, which is never answered for you ("agentmgr inbox"). With -p auto, Claude Code approves what it judges safe.'));
|
|
393
|
+
}
|
|
387
394
|
if (opts.attach && created.length === 1) {
|
|
388
395
|
let a = created[0];
|
|
389
396
|
for (let i = 0; i < 600 && a.status === 'preparing' && !a.runtime.running; i++) {
|
|
@@ -578,6 +585,86 @@ export async function main(argv) {
|
|
|
578
585
|
if (d.data.verdict === 'wrong') process.exitCode = 1;
|
|
579
586
|
});
|
|
580
587
|
|
|
588
|
+
program
|
|
589
|
+
.command('proof')
|
|
590
|
+
.description('What an agent ran to verify its work: each check with its command, exit code and output, as the agent recorded them, and what it says it did not do. --run runs the commands again here and says which gave the same result (exit 1 when one differs).')
|
|
591
|
+
.argument('<agent>')
|
|
592
|
+
.option('--run', 'run the recorded commands again in the agent\'s folder (ones that change things are not run)')
|
|
593
|
+
.option('--json', 'print it as JSON')
|
|
594
|
+
.action(async (ref, opts) => {
|
|
595
|
+
await daemon();
|
|
596
|
+
const a = await resolveAgent(ref);
|
|
597
|
+
let v = await api('GET', `/agents/${a.id}/proof`);
|
|
598
|
+
if (opts.run) {
|
|
599
|
+
const n = v.entries.filter((e) => e.runnable).length;
|
|
600
|
+
process.stderr.write(dim(`Running ${n} command${n === 1 ? '' : 's'} again in ${a.workdir ?? 'its folder'}…\n`));
|
|
601
|
+
v = await api('POST', `/agents/${a.id}/proof/run`);
|
|
602
|
+
}
|
|
603
|
+
if (opts.json) console.log(JSON.stringify(v, null, 2));
|
|
604
|
+
else {
|
|
605
|
+
console.log((await api('GET', `/agents/${a.id}/proof?format=md`)).markdown);
|
|
606
|
+
if (v.notDone.length) console.log(`${bold('Not done, as the agent says:')}\n${v.notDone.map((t) => `- ${t}`).join('\n')}\n`);
|
|
607
|
+
if (v.rerun && !v.rerun.stale) console.log(`Run again ${v.rerun.at}: ${green(`${v.rerun.same} same`)}${v.rerun.differs ? `, ${red(`${v.rerun.differs} different`)}` : ''}${v.rerun.skipped ? dim(`, ${v.rerun.skipped} not run`) : ''}`);
|
|
608
|
+
else if (v.counts.commands) console.log(dim(`Run them again: agentmgr proof ${a.id} --run${v.rerun?.stale ? ' (the last run was before the agent changed its proof)' : ''}`));
|
|
609
|
+
}
|
|
610
|
+
if (v.rerun && !v.rerun.stale && v.rerun.differs) process.exitCode = 1;
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
program
|
|
614
|
+
.command('acceptance')
|
|
615
|
+
.description('What done means for an agent: the points its work is checked against. The agent drafts them in its spec; you edit and agree; the review scorecard then reports each one as met, not met or not verified')
|
|
616
|
+
.argument('<agent>')
|
|
617
|
+
.option('--agree', 'agree on the points (as the agent wrote them, or as changed by the options below)')
|
|
618
|
+
.option('--add <text>', 'add a point; repeat for more', collect)
|
|
619
|
+
.option('--remove <n>', 'take out point n; repeat for more', collect)
|
|
620
|
+
.option('--set <n=text>', 'reword point n; repeat for more', collect)
|
|
621
|
+
.option('--skip', 'stop waiting: the agent goes ahead with the criteria in its own spec')
|
|
622
|
+
.option('--check', 'score the work against the agreed points now (a separate model call)')
|
|
623
|
+
.option('--json', 'print it as JSON')
|
|
624
|
+
.action(async (ref, opts) => {
|
|
625
|
+
await daemon();
|
|
626
|
+
const a = await resolveAgent(ref);
|
|
627
|
+
let v = await api('GET', `/agents/${a.id}/acceptance`);
|
|
628
|
+
const edits = opts.add?.length || opts.remove?.length || opts.set?.length;
|
|
629
|
+
if (opts.skip) {
|
|
630
|
+
await api('POST', `/agents/${a.id}/acceptance/skip`);
|
|
631
|
+
return console.log(`${green('✓')} Not waiting any more; ${bold(a.name)} goes ahead with its own criteria`);
|
|
632
|
+
}
|
|
633
|
+
if (edits || opts.agree) {
|
|
634
|
+
const points = (v.status === 'agreed' ? v.points.map((p) => p.text) : v.draft).slice();
|
|
635
|
+
const at = (n) => {
|
|
636
|
+
const i = Number(n) - 1;
|
|
637
|
+
if (!Number.isInteger(i) || i < 0 || i >= points.length) throw new Error(`There is no point ${n} (there are ${points.length})`);
|
|
638
|
+
return i;
|
|
639
|
+
};
|
|
640
|
+
for (const s of opts.set ?? []) {
|
|
641
|
+
const m = /^(\d+)=(.+)$/s.exec(s);
|
|
642
|
+
if (!m) throw new Error('--set takes n=text, e.g. --set "2=The export has a header row"');
|
|
643
|
+
points[at(m[1])] = m[2];
|
|
644
|
+
}
|
|
645
|
+
// Highest first, so the numbers the person gave stay right.
|
|
646
|
+
for (const i of [...new Set((opts.remove ?? []).map(at))].sort((x, y) => y - x)) points.splice(i, 1);
|
|
647
|
+
points.push(...(opts.add ?? []));
|
|
648
|
+
await api('POST', `/agents/${a.id}/acceptance/agree`, { points });
|
|
649
|
+
v = await api('GET', `/agents/${a.id}/acceptance`);
|
|
650
|
+
console.error(`${green('✓')} Agreed on ${v.points.length} point${v.points.length === 1 ? '' : 's'} for ${bold(a.name)}`);
|
|
651
|
+
}
|
|
652
|
+
if (opts.check) {
|
|
653
|
+
if (v.status !== 'agreed') throw new Error('Agree on the points first: agentmgr acceptance <agent> --agree');
|
|
654
|
+
process.stderr.write(dim('Checking… (a separate model call; the agent is not interrupted)\n'));
|
|
655
|
+
await api('POST', `/agents/${a.id}/docs/scorecard`);
|
|
656
|
+
v = await api('GET', `/agents/${a.id}/acceptance`);
|
|
657
|
+
}
|
|
658
|
+
if (opts.json) console.log(JSON.stringify(v, null, 2));
|
|
659
|
+
else {
|
|
660
|
+
const { acceptanceMarkdown } = await import('./acceptance.js');
|
|
661
|
+
process.stdout.write(`${acceptanceMarkdown(v, a.name)}\n`);
|
|
662
|
+
if (v.status === 'review' || (v.status === 'none' && v.draft.length)) console.log(dim(`Agree: agentmgr acceptance ${a.slug ?? a.id} --agree (change them with --set n=text, --remove n, --add text)`));
|
|
663
|
+
}
|
|
664
|
+
// For scripts: an agreed point the work does not meet.
|
|
665
|
+
if (v.counts.notMet) process.exitCode = 1;
|
|
666
|
+
});
|
|
667
|
+
|
|
581
668
|
program
|
|
582
669
|
.command('insights')
|
|
583
670
|
.description('Why / What / How / Now for an agent, three tidy points each (one-off Claude call)')
|
|
@@ -1700,6 +1787,79 @@ export async function main(argv) {
|
|
|
1700
1787
|
if (r.text) console.log(r.text.trimEnd());
|
|
1701
1788
|
});
|
|
1702
1789
|
|
|
1790
|
+
program
|
|
1791
|
+
.command('autonomy')
|
|
1792
|
+
.description('How far agents go without you. Without an agent: the default level and the models used. With one: its level and what was answered, sent or merged for you')
|
|
1793
|
+
.argument('[agent]')
|
|
1794
|
+
.argument('[level]', 'ask, run, pr or merge: set it for this agent')
|
|
1795
|
+
.option('--default <level>', 'the level new agents get when none is named')
|
|
1796
|
+
.option('--models <list>', 'the models its calls run on, best first; the next one is used when a call fails (default: fable,opus,sonnet)')
|
|
1797
|
+
.option('--ok <entry>', 'you have seen an answer given for you (its id from the list; "hold" for a held merge)')
|
|
1798
|
+
.option('--change <entry=answer>', 'your own answer to a question that was answered for you; the agent is told to apply it')
|
|
1799
|
+
.option('--json', 'print as JSON')
|
|
1800
|
+
.action(async (ref, level, o) => {
|
|
1801
|
+
await daemon();
|
|
1802
|
+
const { LEVEL_LABEL, logLine } = await import('./autonomy.js');
|
|
1803
|
+
if (!ref) {
|
|
1804
|
+
const patch = { ...(o.default ? { level: o.default } : {}), ...(o.models ? { models: o.models } : {}) };
|
|
1805
|
+
const s = Object.keys(patch).length ? await api('PUT', '/autonomy', patch) : await api('GET', '/autonomy');
|
|
1806
|
+
if (o.json) return console.log(JSON.stringify(s, null, 2));
|
|
1807
|
+
console.log(`${bold('New agents:')} ${LEVEL_LABEL[s.level]} ${dim(`(${s.level})`)}`);
|
|
1808
|
+
console.log(`${bold('Models, best first:')} ${s.models.map((m) => (typeof m === 'string' ? m : `${m.engine ?? 'claude'}:${m.model}`)).join(' → ')}`);
|
|
1809
|
+
console.log(dim(`${s.agents} agent${s.agents === 1 ? '' : 's'} running without you · ${s.calls} of ${s.dailyCalls} calls today${s.lastModel ? ` · last answered by ${s.lastModel}` : ''}`));
|
|
1810
|
+
if (s.lastError) console.log(dim(`Last failure ${s.lastError.at}: ${s.lastError.message}`));
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
const a = await resolveAgent(ref);
|
|
1814
|
+
let v = a;
|
|
1815
|
+
if (level) v = await api('POST', `/agents/${a.id}/autonomy`, { level });
|
|
1816
|
+
if (o.ok) v = await api('POST', `/agents/${a.id}/autonomy/ack`, { entry: o.ok });
|
|
1817
|
+
if (o.change) {
|
|
1818
|
+
const i = o.change.indexOf('=');
|
|
1819
|
+
if (i < 1 || !o.change.slice(i + 1).trim()) throw new Error('--change takes <entry>=<your answer>');
|
|
1820
|
+
v = await api('POST', `/agents/${a.id}/autonomy/correct`, { entry: o.change.slice(0, i).trim(), text: o.change.slice(i + 1).trim() });
|
|
1821
|
+
}
|
|
1822
|
+
const st = v.autonomy;
|
|
1823
|
+
if (o.json) return console.log(JSON.stringify(st ?? { level: 'ask', log: [] }, null, 2));
|
|
1824
|
+
console.log(`${bold(v.name)}: ${LEVEL_LABEL[st?.level ?? 'ask']} ${dim(`(${st?.level ?? 'ask'})`)}${st?.log?.length ? dim(` · ${logLine(st.log)}`) : ''}`);
|
|
1825
|
+
if (st?.hold && !st.hold.ack) console.log(` ${bold('Not merged:')} ${st.hold.note} ${dim('(--ok hold)')}`);
|
|
1826
|
+
for (const e of st?.log ?? []) {
|
|
1827
|
+
const when = dim(e.at.slice(0, 16).replace('T', ' '));
|
|
1828
|
+
if (e.kind === 'answer') console.log(` ${when} ${dim(e.id)} ${bold('Answered:')} ${e.question}\n → ${e.corrected ? `${dim(e.answer)} → yours: ${e.corrected}` : e.answer}${e.basis ? dim(`\n from: ${e.basis}`) : ''}${dim(` (${e.model ?? (e.via === 'decide' ? 'Decide' : 'model')}, ${Math.round((e.confidence ?? 0) * 100)}%)`)}${e.ack ? '' : dim(' · not seen')}`);
|
|
1829
|
+
else if (e.kind === 'left') console.log(` ${when} ${bold('Left for you:')} ${e.question}${e.why ? dim(`\n ${e.why}`) : ''}`);
|
|
1830
|
+
else console.log(` ${when} ${bold(e.kind === 'nudge' ? 'Nudged:' : e.kind === 'followup' ? 'Told to carry on:' : e.kind === 'plan' ? 'Plan:' : 'Merged:')} ${e.title ?? ''}${e.text ? dim(`\n ${e.text}`) : ''}`);
|
|
1831
|
+
}
|
|
1832
|
+
});
|
|
1833
|
+
|
|
1834
|
+
program
|
|
1835
|
+
.command('ground-rules')
|
|
1836
|
+
.description('Your own rules for every agent, in every repository, next to what is in memory: show them, or change them')
|
|
1837
|
+
.option('--add <rule>', 'add a rule, one short line (repeatable)', collect, [])
|
|
1838
|
+
.option('--remove <n>', 'take out rule n (repeatable)', collect, [])
|
|
1839
|
+
.option('--clear', 'remove them all')
|
|
1840
|
+
.option('--tell', 'also tell the agents running now (others get them when they start)')
|
|
1841
|
+
.option('--json', 'print as JSON')
|
|
1842
|
+
.action(async (o) => {
|
|
1843
|
+
await daemon();
|
|
1844
|
+
let v = await api('GET', '/ground-rules');
|
|
1845
|
+
if (o.clear || o.add.length || o.remove.length) {
|
|
1846
|
+
let rules = o.clear ? [] : v.rules.slice();
|
|
1847
|
+
const drop = new Set();
|
|
1848
|
+
for (const raw of o.remove) {
|
|
1849
|
+
const n = Number(raw);
|
|
1850
|
+
if (!Number.isInteger(n) || n < 1 || n > rules.length) throw new Error(`There is no rule ${raw}: there ${rules.length === 1 ? 'is 1 rule' : `are ${rules.length} rules`}`);
|
|
1851
|
+
drop.add(n - 1);
|
|
1852
|
+
}
|
|
1853
|
+
rules = [...rules.filter((_, i) => !drop.has(i)), ...o.add];
|
|
1854
|
+
v = await api('PUT', '/ground-rules', { rules, tell: Boolean(o.tell) });
|
|
1855
|
+
if (!o.json) console.log(v.changed ? `${green('✓')} ${v.rules.length} ground rule${v.rules.length === 1 ? '' : 's'}; agents get them when they start${v.told ? `, and ${v.told} running now ${v.told === 1 ? 'was' : 'were'} told` : ''}` : dim('Nothing changed.'));
|
|
1856
|
+
}
|
|
1857
|
+
if (o.json) return console.log(JSON.stringify(v, null, 2));
|
|
1858
|
+
if (!v.rules.length) return console.log(dim('No ground rules yet: agentmgr ground-rules --add "Ask before adding a dependency"'));
|
|
1859
|
+
v.rules.forEach((r, i) => console.log(`${dim(`${i + 1}.`)} ${r}`));
|
|
1860
|
+
console.log(dim(v.file));
|
|
1861
|
+
});
|
|
1862
|
+
|
|
1703
1863
|
const pb = program.command('playbook').description('Saved requests you run again, in several projects, by hand or on a schedule');
|
|
1704
1864
|
pb.command('ls', { isDefault: true })
|
|
1705
1865
|
.description('List playbooks')
|
|
@@ -1925,7 +2085,13 @@ export async function main(argv) {
|
|
|
1925
2085
|
console.log(dim(' agentmgr rules'));
|
|
1926
2086
|
continue;
|
|
1927
2087
|
}
|
|
1928
|
-
|
|
2088
|
+
if (it.kind === 'auto') {
|
|
2089
|
+
console.log(`${cyan('done for you')} ${bold(it.agentName)} ${dim(it.agentId)} ${it.title}`);
|
|
2090
|
+
if (it.entry?.answer) console.log(dim(` → ${it.entry.answer}\n agentmgr autonomy ${it.agentId} --ok · agentmgr autonomy ${it.agentId} --change ${it.entry.id}="your answer"`));
|
|
2091
|
+
else console.log(dim(` agentmgr autonomy ${it.agentId} --ok`));
|
|
2092
|
+
continue;
|
|
2093
|
+
}
|
|
2094
|
+
console.log(`${label[it.kind] ?? cyan(it.kind)} ${bold(it.agentName)} ${dim(it.agentId)} ${(it.kind === 'prompt' && it.title === 'Question' && it.prompt?.question) || it.title}`);
|
|
1929
2095
|
if (it.kind === 'prompt') console.log(dim(` ${(it.prompt?.choices ?? []).map((c) => `${c.key}. ${c.label}`).join(' ')} → agentmgr attach ${it.agentId}`));
|
|
1930
2096
|
if (it.kind === 'question') {
|
|
1931
2097
|
if (it.question.options.length) console.log(dim(` options: ${it.question.options.join(' | ')}`));
|
|
@@ -3495,7 +3661,9 @@ export async function main(argv) {
|
|
|
3495
3661
|
if (!gone) throw new Error(`The daemon (pid ${before.pid}) is still shutting down after 5 minutes; check the log`);
|
|
3496
3662
|
}
|
|
3497
3663
|
const st = await svc.status();
|
|
3498
|
-
|
|
3664
|
+
// The login service starts its own daemon: for another home or port, this one is started here.
|
|
3665
|
+
const viaService = st.loaded && st.ours;
|
|
3666
|
+
if (viaService) await svc.kickstart();
|
|
3499
3667
|
else await ensureDaemon({ quiet: true });
|
|
3500
3668
|
const back = async () => {
|
|
3501
3669
|
const h = await health();
|
|
@@ -3504,7 +3672,7 @@ export async function main(argv) {
|
|
|
3504
3672
|
for (let i = 0; i < 150 && !(await back()); i++) await new Promise((res) => setTimeout(res, 200));
|
|
3505
3673
|
if (!(await back())) throw new Error('Daemon did not come back; check the log');
|
|
3506
3674
|
const agents = await api('GET', '/agents');
|
|
3507
|
-
console.log(`${green('✓')} restarted${
|
|
3675
|
+
console.log(`${green('✓')} restarted${viaService ? ' (login service)' : ''}; ${agents.filter((a) => a.desired === 'running').length} agents set to resume`);
|
|
3508
3676
|
});
|
|
3509
3677
|
|
|
3510
3678
|
program
|
package/src/config.js
CHANGED
|
@@ -51,6 +51,8 @@ const DEFAULTS = {
|
|
|
51
51
|
flushSec: 30,
|
|
52
52
|
// Ask task agents to keep a brief (Problem / Solution / Diagram / Checks) for the UI.
|
|
53
53
|
brief: true,
|
|
54
|
+
// With the brief: ask for the proof of its checks (PROOF.md: command, exit code, output) and what it did not do.
|
|
55
|
+
proof: true,
|
|
54
56
|
// Backlog: items worked on at once per project (overridable per project), and overall.
|
|
55
57
|
backlogParallel: 2,
|
|
56
58
|
backlogMaxActive: 4,
|
|
@@ -85,6 +87,9 @@ const DEFAULTS = {
|
|
|
85
87
|
// Local models: servers on this computer (Ollama, LM Studio, llama.cpp, MLX) and their models, for the
|
|
86
88
|
// "Local model" engine; `context` is the room Ollama gives a model for an agent (localmodels.js).
|
|
87
89
|
localModels: { enabled: true, context: 32768 },
|
|
90
|
+
// How far agents go without you (autonomy.js): `level` for new agents (ask, run, pr, merge) and the
|
|
91
|
+
// `models` its decisions run on, best first: { level: 'ask', models: ['fable', 'opus', 'sonnet'] }.
|
|
92
|
+
// Your own rules for every agent are in ~/.agentmanager/ground-rules.md (groundrules.js).
|
|
88
93
|
// Review rounds before a pull request (prereview.js): critics on other models, until they approve.
|
|
89
94
|
preReview: { enabled: true, rounds: 4, critics: 2, openPr: true },
|
|
90
95
|
// Screen (screen.js): this computer's screen in the page, through its own screen sharing on this port.
|
package/src/decisions.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import crypto from 'node:crypto';
|
|
8
8
|
|
|
9
9
|
const MAX = 2000;
|
|
10
|
-
export const DECISION_KINDS = { plan: 'Plan review', answer: 'Your answer', design: 'Design', tradeoff: 'Trade-off', manual: 'Added by you' };
|
|
10
|
+
export const DECISION_KINDS = { plan: 'Plan review', acceptance: 'What done means', answer: 'Your answer', design: 'Design', tradeoff: 'Trade-off', manual: 'Added by you' };
|
|
11
11
|
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
12
12
|
const clip = (s, n) => {
|
|
13
13
|
const t = String(s ?? '').replace(/\s+/g, ' ').trim();
|
|
@@ -94,6 +94,10 @@ export class Decisions {
|
|
|
94
94
|
if (pr?.decidedAt && ['approved', 'changes'].includes(pr.status)) {
|
|
95
95
|
put(`plan:${a.id}:${pr.decidedAt}`, { ...base, kind: 'plan', at: pr.decidedAt, title: `Plan for ${a.name}`, decision: pr.status === 'approved' ? 'Approved' : 'Sent back for changes', why: clip(pr.note, 1000) || null });
|
|
96
96
|
}
|
|
97
|
+
const acc = a.acceptance;
|
|
98
|
+
if (acc?.status === 'agreed') {
|
|
99
|
+
put(`acceptance:${a.id}:${acc.agreedAt}`, { ...base, kind: 'acceptance', at: acc.agreedAt, title: `What done means for ${a.name}`, decision: `Agreed on ${acc.points.length} point${acc.points.length === 1 ? '' : 's'}${acc.yours ? ` (${acc.yours} yours)` : ''}`, why: clip(acc.points.map((p) => `${p.id}: ${p.text}`).join('\n'), 1000) || null });
|
|
100
|
+
}
|
|
97
101
|
const answers = a.answers ?? {};
|
|
98
102
|
if (Object.keys(answers).length) {
|
|
99
103
|
const qs = new Map(this.questions(a).map((q) => [q.id, q]));
|
package/src/engines/claude.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// and how to read them. Other engines implement the same shape (see docs/engines.md).
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { promptChoices } from '../inbox.js';
|
|
5
|
+
import { promptChoices, questionMenu } from '../inbox.js';
|
|
6
6
|
import { scanActivity } from '../stuck.js';
|
|
7
7
|
import { recentSessionFiles, scanTranscript, sessionDigest, subagentTranscripts, transcriptPath } from '../tracker.js';
|
|
8
8
|
import { trustFolder } from '../trust.js';
|
|
@@ -107,8 +107,10 @@ export default {
|
|
|
107
107
|
attention: [
|
|
108
108
|
[/trustthisfolder/i, 'Folder trust prompt'],
|
|
109
109
|
[/Doyouwantto(proceed|make|create|allow|run|overwrite)/i, 'Permission prompt'],
|
|
110
|
+
// The agent's own question, as a menu: a message typed now would pick the highlighted option.
|
|
111
|
+
[/Entertoselect.{0,40}Esctocancel/i, 'Question'],
|
|
110
112
|
],
|
|
111
|
-
promptChoices: (screen) => promptChoices(screen),
|
|
113
|
+
promptChoices: (screen, attention) => (attention === 'Question' && questionMenu(screen)) || promptChoices(screen),
|
|
112
114
|
|
|
113
115
|
/** Lines of Claude Code's own frame (input box, mode and status bar): never a question to the person. */
|
|
114
116
|
screenChrome: [
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Ground rules: the person's own rules for every agent, in every repository and on every engine,
|
|
2
|
+
// given with each session's instructions next to (not instead of) the repository's memory and
|
|
3
|
+
// standards. Memory is what agents learned; standards are per repository; these are how this
|
|
4
|
+
// person wants agents to work anywhere ("ask before adding a dependency", "never force-push").
|
|
5
|
+
// One Markdown file, ~/.agentmanager/ground-rules.md, one rule per line. Only the person sets
|
|
6
|
+
// them: an agent's own calls to change them are refused (server.js).
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { paths } from './config.js';
|
|
10
|
+
|
|
11
|
+
export const MAX_RULES = 40;
|
|
12
|
+
export const MAX_RULE_CHARS = 400;
|
|
13
|
+
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
14
|
+
|
|
15
|
+
export const groundRulesFile = () => path.join(paths.home, 'ground-rules.md');
|
|
16
|
+
|
|
17
|
+
/** The rules in a text: one per line, list marks and numbers dropped, no empty lines, no repeats. */
|
|
18
|
+
export function parseRules(text) {
|
|
19
|
+
const out = [];
|
|
20
|
+
const seen = new Set();
|
|
21
|
+
for (const raw of String(text ?? '').split('\n')) {
|
|
22
|
+
const line = raw.replace(/\s+/g, ' ').replace(/^\s*(?:[-*+]|\d+[.)])\s+/, '').trim();
|
|
23
|
+
if (!line || /^#/.test(line) || seen.has(line.toLowerCase())) continue;
|
|
24
|
+
seen.add(line.toLowerCase());
|
|
25
|
+
out.push(line);
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The rules the person sent, checked: a text or a list. Throws with a status when one is too long or there are too many. */
|
|
31
|
+
export function cleanRules(input) {
|
|
32
|
+
const rules = parseRules(Array.isArray(input) ? input.join('\n') : input);
|
|
33
|
+
const long = rules.find((r) => r.length > MAX_RULE_CHARS);
|
|
34
|
+
if (long) throw err(400, `A ground rule is one short line (${MAX_RULE_CHARS} characters at most): "${long.slice(0, 60)}…"`);
|
|
35
|
+
if (rules.length > MAX_RULES) throw err(400, `At most ${MAX_RULES} ground rules: a long list is not followed, keep the ones that matter`);
|
|
36
|
+
return rules;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** What every session is told, or '' when there are none. */
|
|
40
|
+
export function groundRulesPrompt(rules) {
|
|
41
|
+
if (!rules?.length) return '';
|
|
42
|
+
return [
|
|
43
|
+
'Ground rules from the user, for everything you do in this session. They come before your own preferences and before what the repository\'s memory suggests. ' +
|
|
44
|
+
'If the task cannot be done without breaking one, stop and say which and why (in the brief, or as a question) instead of working around it:',
|
|
45
|
+
...rules.map((r) => `- ${r}`),
|
|
46
|
+
].join('\n');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** For a session that is already running when the rules change. */
|
|
50
|
+
export const groundRulesMessage = (rules) =>
|
|
51
|
+
rules.length
|
|
52
|
+
? `The user changed their ground rules. From now on, these apply to everything you do in this session (they replace any ground rules you were given before):\n${rules.map((r) => `- ${r}`).join('\n')}`
|
|
53
|
+
: 'The user removed their ground rules: the ones you were given at the start no longer apply.';
|
|
54
|
+
|
|
55
|
+
export class GroundRules {
|
|
56
|
+
constructor({ file = groundRulesFile() } = {}) {
|
|
57
|
+
this.file = file;
|
|
58
|
+
this.cache = null; // { mtimeMs, rules }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The rules now (read again when the file changed: it can be edited by hand). */
|
|
62
|
+
list() {
|
|
63
|
+
try {
|
|
64
|
+
const { mtimeMs } = fs.statSync(this.file);
|
|
65
|
+
if (this.cache?.mtimeMs !== mtimeMs) this.cache = { mtimeMs, rules: parseRules(fs.readFileSync(this.file, 'utf8')).slice(0, MAX_RULES) };
|
|
66
|
+
return this.cache.rules;
|
|
67
|
+
} catch {
|
|
68
|
+
this.cache = null;
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
view() {
|
|
74
|
+
const rules = this.list();
|
|
75
|
+
let updatedAt = null;
|
|
76
|
+
try {
|
|
77
|
+
updatedAt = fs.statSync(this.file).mtime.toISOString();
|
|
78
|
+
} catch {}
|
|
79
|
+
return { rules, text: rules.join('\n'), file: this.file, max: MAX_RULES, maxChars: MAX_RULE_CHARS, updatedAt };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Replace the rules. Returns { changed, ...view }. */
|
|
83
|
+
set(input) {
|
|
84
|
+
const rules = cleanRules(input);
|
|
85
|
+
const changed = JSON.stringify(rules) !== JSON.stringify(this.list());
|
|
86
|
+
if (changed) {
|
|
87
|
+
fs.mkdirSync(path.dirname(this.file), { recursive: true });
|
|
88
|
+
fs.writeFileSync(this.file, rules.length ? `${rules.map((r) => `- ${r}`).join('\n')}\n` : '');
|
|
89
|
+
this.cache = null;
|
|
90
|
+
}
|
|
91
|
+
return { changed, ...this.view() };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
prompt() {
|
|
95
|
+
return groundRulesPrompt(this.list());
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/inbox.js
CHANGED
|
@@ -64,6 +64,54 @@ export function loadQuestions(agentId) {
|
|
|
64
64
|
|
|
65
65
|
export const answerMessage = (q, text) => `Answer to your question "${q.question}": ${text}`;
|
|
66
66
|
|
|
67
|
+
/** Menu entries that are not an answer: free text, or talking it over. */
|
|
68
|
+
export const FREE_CHOICE = /^(?:type something|chat about this|other)\b/i;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Claude Code's question menu (the agent asking the person to pick): the question, its numbered
|
|
72
|
+
* options with the line under each, and which one is highlighted. Text sent to the terminal while
|
|
73
|
+
* it is open is not read as a message (Enter picks the highlighted option), so it counts as a
|
|
74
|
+
* prompt. Returns { question, choices: [{ key, label, hint }], selected, multi } or null.
|
|
75
|
+
*/
|
|
76
|
+
export function questionMenu(screen) {
|
|
77
|
+
const text = String(screen ?? '')
|
|
78
|
+
.replace(/\x1b\[(\d*)C/g, (_, n) => ' '.repeat(Math.min(Number(n || 1), 8)))
|
|
79
|
+
.replace(/\x1b\[\d*G/g, ' ')
|
|
80
|
+
.replace(/\x1b\[[0-9;]*[ABEFHJf]/g, '\n')
|
|
81
|
+
.replace(/\x1b\[[0-9;?<>=]*[ -\/]*[@-~]|\x1b\][^\x07\x1b]*(\x07|\x1b\\)/g, '')
|
|
82
|
+
.replace(/\r/g, '\n');
|
|
83
|
+
const lines = text.split('\n').map((l) => l.replace(/\s+/g, ' ').trim());
|
|
84
|
+
const end = lines.findLastIndex((l) => /Enter to select/i.test(l));
|
|
85
|
+
if (end < 0) return null;
|
|
86
|
+
const choices = [];
|
|
87
|
+
let hint = [];
|
|
88
|
+
let selected = null;
|
|
89
|
+
let multi = false;
|
|
90
|
+
let top = -1;
|
|
91
|
+
for (let i = end - 1; i >= 0 && top < 0; i--) {
|
|
92
|
+
const l = lines[i];
|
|
93
|
+
if (!l || /^[─━╌-]+$/.test(l)) continue;
|
|
94
|
+
const m = /^([❯>›]\s*)?(\[[ x✔✓]?\]\s*|[☐☑◻◼]\s*)?(\d)[.)]\s+(.{1,120})$/.exec(l);
|
|
95
|
+
if (!m) {
|
|
96
|
+
if (choices.length) hint.unshift(l);
|
|
97
|
+
else if (!/^(?:\d[.)])?$/.test(l)) hint = [];
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if (choices.some((c) => c.key === m[3])) break; // an older menu above this one
|
|
101
|
+
choices.unshift({ key: m[3], label: m[4].trim(), hint: hint.join(' ').slice(0, 200) });
|
|
102
|
+
hint = [];
|
|
103
|
+
if (m[1]) selected = m[3];
|
|
104
|
+
if (m[2]) multi = true;
|
|
105
|
+
if (m[3] === '1') top = i;
|
|
106
|
+
}
|
|
107
|
+
if (top < 0 || choices.length < 2) return null;
|
|
108
|
+
let question = '';
|
|
109
|
+
for (let i = top - 1; i >= 0 && !question; i--) {
|
|
110
|
+
if (lines[i] && !/^[─━╌-]+$/.test(lines[i])) question = lines[i].slice(0, 300);
|
|
111
|
+
}
|
|
112
|
+
return { question, choices, selected, multi };
|
|
113
|
+
}
|
|
114
|
+
|
|
67
115
|
/**
|
|
68
116
|
* Answer choices visible in a live prompt: numbered menu lines ("❯ 1. Yes", "2. No").
|
|
69
117
|
* `screen` is recent terminal output; cursor moves become spaces before matching.
|
package/src/judge.js
CHANGED
|
@@ -259,7 +259,7 @@ export class Judge {
|
|
|
259
259
|
const u = this.usage();
|
|
260
260
|
if (u.calls >= u.cap) return null;
|
|
261
261
|
this.state.calls++;
|
|
262
|
-
const data = parseJsonReply(await this.call(agent, prompt, { timeoutMs: this.settings.timeoutSec * 1000 }));
|
|
262
|
+
const data = parseJsonReply(await this.call(agent, prompt, { timeoutMs: this.settings.timeoutSec * 1000, kind: key.split(':')[0] }));
|
|
263
263
|
if (!validate(data)) throw new Error('reply did not have the expected shape');
|
|
264
264
|
data.confidence = Math.max(0, Math.min(1, Number(data.confidence) || 0));
|
|
265
265
|
return data;
|