ai-agentmanager 1.63.0 → 1.65.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 +37 -0
- package/README.md +168 -3
- package/package.json +1 -1
- package/public/app.js +48 -4
- package/public/autonomy.js +4 -0
- package/public/groups.js +2 -0
- package/public/index.html +7 -0
- package/public/machine.js +2 -0
- package/public/proof.js +194 -0
- package/public/quality.js +81 -3
- package/public/style.css +54 -1
- package/public/valuelens.js +114 -0
- package/src/autonomy.js +81 -10
- package/src/autopilot.js +3 -1
- package/src/brief.js +73 -6
- package/src/cli.js +101 -5
- package/src/config.js +8 -0
- package/src/engines/claude.js +7 -2
- package/src/inbox.js +60 -6
- package/src/manager.js +44 -4
- package/src/mutate.js +456 -0
- package/src/private.js +52 -0
- package/src/proof.js +255 -0
- package/src/quality.js +16 -2
- package/src/record.js +147 -0
- package/src/scorecard.js +40 -2
- package/src/server.js +53 -2
- package/src/service.js +24 -3
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.
|
|
@@ -71,7 +119,10 @@ export const answerMessage = (q, text) => `Answer to your question "${q.question
|
|
|
71
119
|
export function promptChoices(screen) {
|
|
72
120
|
const text = String(screen ?? '')
|
|
73
121
|
.replace(/\x1b\[(\d*)C/g, (_, n) => ' '.repeat(Math.min(Number(n || 1), 8)))
|
|
74
|
-
|
|
122
|
+
// A jump along the line is a gap, not a new line. Claude Code redraws only the cells that
|
|
123
|
+
// changed, so a prompt can arrive as "pro" + jump + "eed?" and "❯ 1" + jump + "Yes".
|
|
124
|
+
.replace(/\x1b\[\d*G/g, ' ')
|
|
125
|
+
.replace(/\x1b\[[0-9;]*[ABDHJKfm]/g, '\n')
|
|
75
126
|
.replace(/\x1b\[[0-9;?<>=]*[ -\/]*[@-~]|\x1b\][^\x07\x1b]*(\x07|\x1b\\)/g, '')
|
|
76
127
|
.replace(/\r/g, '\n');
|
|
77
128
|
const lines = text.split('\n').map((l) => l.replace(/\s+/g, ' ').trim());
|
|
@@ -79,9 +130,11 @@ export function promptChoices(screen) {
|
|
|
79
130
|
const choices = new Map();
|
|
80
131
|
let question = '';
|
|
81
132
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
82
|
-
|
|
133
|
+
// The highlighted choice can lose its dot to a redraw ("❯ 1 Yes"): the pointer marks it as one.
|
|
134
|
+
const m = /^(?:[❯>›]\s*(\d)[.)]?|(\d)[.)])\s+(.{1,80})$/.exec(lines[i]);
|
|
83
135
|
if (m) {
|
|
84
|
-
|
|
136
|
+
const key = m[1] ?? m[2];
|
|
137
|
+
if (!choices.has(key)) choices.set(key, m[3].replace(/\s*·.*$/, '').trim());
|
|
85
138
|
} else if (choices.size && lines[i]) {
|
|
86
139
|
question = lines[i].slice(0, 200);
|
|
87
140
|
break;
|
|
@@ -91,13 +144,14 @@ export function promptChoices(screen) {
|
|
|
91
144
|
// and switch to auto mode 3. No Esc to cancel"): read the flattened screen after the last question.
|
|
92
145
|
if (!choices.size) {
|
|
93
146
|
const flat = lines.join(' ').replace(/\s+/g, ' ');
|
|
94
|
-
const at = flat.search(/\?\s*(?:[❯>›]\s*)
|
|
147
|
+
const at = flat.search(/\?\s*(?:[❯>›]\s*1[.)]?|1[.)])\s*\S[^?]*$/);
|
|
95
148
|
if (at >= 0) {
|
|
96
149
|
const head = flat.slice(0, at + 1);
|
|
97
150
|
// Drop what's left of the box around it (╌ ─ │ and stray letters before them).
|
|
98
151
|
question = (/([^.?!│]*\?)$/.exec(head)?.[1] ?? '').replace(/^.*[╌─│━]+\s*/, '').trim().slice(-200);
|
|
99
|
-
for (const m of flat.slice(at + 1).matchAll(/(?:[❯>›]\s*)
|
|
100
|
-
|
|
152
|
+
for (const m of flat.slice(at + 1).matchAll(/(?:[❯>›]\s*(\d)[.)]?|\b(\d)[.)])\s*(.+?)(?=\s+(?:[❯>›]\s*)?\d[.)]\s|\s+Esc to cancel|\s+Enter to|$)/g)) {
|
|
153
|
+
const key = m[1] ?? m[2];
|
|
154
|
+
if (!choices.has(key)) choices.set(key, m[3].replace(/\s*·.*$/, '').trim().slice(0, 80));
|
|
101
155
|
}
|
|
102
156
|
}
|
|
103
157
|
}
|
package/src/manager.js
CHANGED
|
@@ -56,6 +56,8 @@ import {
|
|
|
56
56
|
demoPagePrompt,
|
|
57
57
|
benchPath,
|
|
58
58
|
benchmarksPrompt,
|
|
59
|
+
RISKS_PROMPT,
|
|
60
|
+
OPTIONS_PROMPT,
|
|
59
61
|
} from './brief.js';
|
|
60
62
|
|
|
61
63
|
// One-off summaries / documents built from an agent's live context.
|
|
@@ -136,6 +138,8 @@ import { CLAIM_TEXTS, claimsMarkdown, claimsPrompt, combineClaims, parseClaims,
|
|
|
136
138
|
import { CONTAINER_ENGINES, claudeToken, containerName, containerRunning, engineMounts, gitCommonDir, removeContainer, runArgs, stopContainer } from './container.js';
|
|
137
139
|
import { conflictMessage, findConflicts, related, repoKey, summarize as summarizeConflicts } from './conflicts.js';
|
|
138
140
|
import { answerMessage, loadQuestions, questionsPath, questionsPrompt } from './inbox.js';
|
|
141
|
+
import { PROOF_FILE, proofBlock, proofFacts, proofPrompt } from './proof.js';
|
|
142
|
+
import { PRIVATE_MESSAGE, ideaPatch, keptPrivate, mustBeShareable } from './private.js';
|
|
139
143
|
import { GroundRules, groundRulesMessage } from './groundrules.js';
|
|
140
144
|
import { autonomySettings, callLadder, eligible as autonomyEligible, levelOf, modelName, parseLevel } from './autonomy.js';
|
|
141
145
|
import { STUCK_DEFAULTS, detectStuck } from './stuck.js';
|
|
@@ -404,6 +408,8 @@ export class AgentManager extends EventEmitter {
|
|
|
404
408
|
// Intent, spec and plan files that exist, with when each changed (task agents).
|
|
405
409
|
...(NO_REPO.has(agent.kind) ? {} : { specDocs: specDocsInfo(agent.id) }),
|
|
406
410
|
results: this.results(agent, rt, prs),
|
|
411
|
+
// Why its work is not sent outside this computer (private.js), or null.
|
|
412
|
+
keptPrivate: keptPrivate(agent),
|
|
407
413
|
priority: agent.priority ?? 2,
|
|
408
414
|
activeAt: this.activeAt(agent, rt),
|
|
409
415
|
projectInfo: this.projectInfo(agent),
|
|
@@ -482,7 +488,7 @@ export class AgentManager extends EventEmitter {
|
|
|
482
488
|
else if (agent.brief?.status || rt?.pty || agent.status === 'preparing') outcome = 'in progress';
|
|
483
489
|
}
|
|
484
490
|
if (!outcome && !delivered.length && !blockers.length) return null;
|
|
485
|
-
return { outcome: outcome ?? 'in progress', delivered, blockers, notes: r?.notes ?? '', confidence: r?.confidence ?? null, fromAgent: Boolean(r) };
|
|
491
|
+
return { outcome: outcome ?? 'in progress', delivered, blockers, notes: r?.notes ?? '', confidence: r?.confidence ?? null, notDone: r?.notDone ?? [], notDoneSaid: Boolean(r?.notDoneSaid), fromAgent: Boolean(r) };
|
|
486
492
|
}
|
|
487
493
|
|
|
488
494
|
changed(agent) {
|
|
@@ -783,6 +789,12 @@ export class AgentManager extends EventEmitter {
|
|
|
783
789
|
...(team ? { team } : {}),
|
|
784
790
|
...(imported ? { imported } : {}),
|
|
785
791
|
};
|
|
792
|
+
// A project with a level of its own (autonomy.js, set from its track record): its new agents get it when none is named.
|
|
793
|
+
const own = plainTask && !asked ? autonomySettings(this.config).projects[projectOf(agent).name] : null;
|
|
794
|
+
if (own && own !== level) {
|
|
795
|
+
agent.autonomy = own !== 'ask' ? { level: own, log: [], seen: {} } : null;
|
|
796
|
+
if (acceptance === undefined || acceptance === null) agent.acceptance = (own !== 'ask' ? true : this.config.acceptance) ? { status: 'writing', wait: true, points: [] } : null;
|
|
797
|
+
}
|
|
786
798
|
// The PR a reviewer reviews isn't its own: it stays "mentioned", so landing and the rest leave it alone.
|
|
787
799
|
for (const pr of refs.prs) agent.prs[pr.url] = { ...pr, source: pr.url === agent.reviewing?.url ? 'mentioned' : 'intent' };
|
|
788
800
|
for (const bug of refs.bugs) agent.bugs[bug.key] = { ...bug, source: 'intent' };
|
|
@@ -1394,6 +1406,12 @@ export class AgentManager extends EventEmitter {
|
|
|
1394
1406
|
const dir = fs.realpathSync(briefDir(agent.id));
|
|
1395
1407
|
writableDir = dir;
|
|
1396
1408
|
prompts.push(briefPrompt(path.join(dir, path.basename(briefPath(agent.id)))));
|
|
1409
|
+
// What it ran to verify, kept so it can be checked, and what it left out (proof.js).
|
|
1410
|
+
if (this.config.proof !== false) prompts.push(proofPrompt(path.join(dir, PROOF_FILE)));
|
|
1411
|
+
// The pre-mortem: how this could go wrong, named before it starts and marked at the end (brief.js).
|
|
1412
|
+
if (this.config.premortem !== false) prompts.push(RISKS_PROMPT);
|
|
1413
|
+
// Value and paths: more than one way is a decision, listed with what each is worth now and later (brief.js).
|
|
1414
|
+
if (this.config.valueLens !== false) prompts.push(OPTIONS_PROMPT);
|
|
1397
1415
|
if (this.config.inbox !== false) prompts.push(questionsPrompt(path.join(dir, path.basename(questionsPath(agent.id)))));
|
|
1398
1416
|
}
|
|
1399
1417
|
// SPEC.md before changing code, and PLAN.md kept as it goes (unless the plan review asks for the plan).
|
|
@@ -2529,11 +2547,25 @@ export class AgentManager extends EventEmitter {
|
|
|
2529
2547
|
return true;
|
|
2530
2548
|
}
|
|
2531
2549
|
|
|
2550
|
+
/**
|
|
2551
|
+
* Keep an agent's work private, allow sharing it, or go back to what was read (private.js). The
|
|
2552
|
+
* person's call. When it becomes private from outside its session, the agent is told.
|
|
2553
|
+
*/
|
|
2554
|
+
setPrivate(ref, { private: keep = null, note = '' } = {}) {
|
|
2555
|
+
const agent = this.mustGet(ref);
|
|
2556
|
+
const before = keptPrivate(agent);
|
|
2557
|
+
this.patch(agent.id, ideaPatch(agent, { private: keep, note }));
|
|
2558
|
+
const cur = this.store.get(agent.id);
|
|
2559
|
+
if (keep === true && !before && this.runtimes.get(agent.id)?.pty) this.tell(agent.id, PRIVATE_MESSAGE);
|
|
2560
|
+
return this.view(cur);
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2532
2563
|
/** Pick up changes to the agent's brief file. */
|
|
2533
2564
|
reloadBrief(id) {
|
|
2534
2565
|
const agent = this.store.get(id);
|
|
2535
2566
|
if (!agent) return;
|
|
2536
2567
|
const before = agent.brief; // patch() below changes agent.brief in place
|
|
2568
|
+
this.proof?.reload(id);
|
|
2537
2569
|
const brief = loadBrief(id, before);
|
|
2538
2570
|
if (brief) {
|
|
2539
2571
|
this.patch(id, { brief });
|
|
@@ -2845,6 +2877,9 @@ export class AgentManager extends EventEmitter {
|
|
|
2845
2877
|
}
|
|
2846
2878
|
// The spec and plan go along with the brief: what done means, and how it gets there.
|
|
2847
2879
|
const extra = ['spec', 'plan'].map((n) => readSpecDoc(agent.id, n)?.markdown.trim()).filter(Boolean);
|
|
2880
|
+
// And its proof (proof.js): what it recorded of its checks, and what the app saw when it ran them again.
|
|
2881
|
+
const proof = this.proof?.forScore(agent);
|
|
2882
|
+
if (proof?.entries.length) extra.push(['# Proof of its checks, as the agent recorded it', ...proofFacts(proof.doc, proof.rerun), '', proofBlock(proof.entries, 4000)].join('\n'));
|
|
2848
2883
|
return { intent: agent.intent, status, digest, repo, briefMarkdown: [briefMarkdown, ...extra].filter(Boolean).join('\n\n') };
|
|
2849
2884
|
}
|
|
2850
2885
|
|
|
@@ -2958,9 +2993,11 @@ export class AgentManager extends EventEmitter {
|
|
|
2958
2993
|
const doc = (n) => readSpecDoc(agent.id, n)?.markdown ?? '';
|
|
2959
2994
|
// The repository's standards: its bar is run here, by the app, before the model is asked.
|
|
2960
2995
|
const standards = (await this.standards?.assess(agent.id, data)) ?? null;
|
|
2961
|
-
const
|
|
2996
|
+
const proof = this.proof?.forScore(cur0) ?? null;
|
|
2997
|
+
const breaks = this.mutate?.forScore(cur0, data.diffHash) ?? null;
|
|
2998
|
+
const f = scoreFacts({ files: data.files, prs: Object.values(cur0.prs ?? {}), brief: cur0.brief, plan: doc('plan'), spec: doc('spec'), standards, agreed: cur0.acceptance?.status === 'agreed' ? cur0.acceptance.points : null, proof, breaks });
|
|
2962
2999
|
const writer = this.writerFor(agent);
|
|
2963
|
-
const prompt = scorecardPrompt({ ...ctx, briefMarkdown: this.briefFile(agent.id).markdown ?? '', intentDoc: doc('intent'), specDoc: doc('spec'), planDoc: doc('plan'), hunks, facts: f, lessons: standards?.lessons ?? [] });
|
|
3000
|
+
const prompt = scorecardPrompt({ ...ctx, briefMarkdown: this.briefFile(agent.id).markdown ?? '', intentDoc: doc('intent'), specDoc: doc('spec'), planDoc: doc('plan'), proofDoc: proof?.entries?.length ? proofBlock(proof.entries) : '', hunks, facts: f, lessons: standards?.lessons ?? [] });
|
|
2964
3001
|
const sc = combine(parseJsonReply(await this.oneShot(agent, prompt, writer)), f, hunks, { lessons: standards?.lessons ?? [], bar: standards?.bar ?? null });
|
|
2965
3002
|
const cur = this.store.get(agent.id);
|
|
2966
3003
|
if (!cur) return null;
|
|
@@ -3104,6 +3141,7 @@ export class AgentManager extends EventEmitter {
|
|
|
3104
3141
|
*/
|
|
3105
3142
|
publishToDrive(ref) {
|
|
3106
3143
|
const agent = this.mustGet(ref);
|
|
3144
|
+
mustBeShareable(agent, 'Publishing to Google Drive');
|
|
3107
3145
|
if (NO_REPO.has(agent.kind)) throw Object.assign(new Error('Only task agents have documents to publish'), { status: 400 });
|
|
3108
3146
|
if (agent.drive?.pending) return this.view(agent);
|
|
3109
3147
|
const docs = this.driveDocuments(agent);
|
|
@@ -3196,6 +3234,7 @@ export class AgentManager extends EventEmitter {
|
|
|
3196
3234
|
/** The update's details as one Google Doc, through the Drive connector; its link then goes under both messages. */
|
|
3197
3235
|
publishUpdate(ref) {
|
|
3198
3236
|
const agent = this.mustGet(ref);
|
|
3237
|
+
mustBeShareable(agent, 'Publishing the update');
|
|
3199
3238
|
const markdown = agent.docs?.update?.markdown;
|
|
3200
3239
|
if (!markdown) throw Object.assign(new Error('Write the update first'), { status: 409 });
|
|
3201
3240
|
if (agent.announce?.publishing) return this.view(agent);
|
|
@@ -3433,6 +3472,7 @@ export class AgentManager extends EventEmitter {
|
|
|
3433
3472
|
continue;
|
|
3434
3473
|
}
|
|
3435
3474
|
// Idle, no prompt open, and not right after our last message (give it time to react).
|
|
3475
|
+
if (this.mutate?.holds(id)) continue; // its files are changed for a moment (mutate.js)
|
|
3436
3476
|
if (!rt?.pty || rt.busy || rt.attention || rt.planning || t - (rt.startedAt ?? 0) < 2500 || t - (rt.toldAt ?? 0) < 8000) continue;
|
|
3437
3477
|
const { text } = queue.shift();
|
|
3438
3478
|
rt.toldAt = t;
|
|
@@ -3884,7 +3924,7 @@ export class AgentManager extends EventEmitter {
|
|
|
3884
3924
|
|
|
3885
3925
|
/** A live prompt's question and choices, and the tool call it asks about when the transcript says. */
|
|
3886
3926
|
promptView(agent, rt) {
|
|
3887
|
-
const p = engineOf(agent).promptChoices(rt.tail);
|
|
3927
|
+
const p = engineOf(agent).promptChoices(rt.tail, rt.attention);
|
|
3888
3928
|
const call = rt.attention === PERMISSION ? this.pendingCall(agent) : null;
|
|
3889
3929
|
return call ? { ...p, tool: describeTool(call) } : p;
|
|
3890
3930
|
}
|