ai-agentmanager 1.38.0 → 1.40.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 +15 -0
- package/README.md +5 -1
- package/package.json +1 -1
- package/public/app.js +86 -12
- package/public/index.html +13 -2
- package/public/menu.js +6 -3
- package/public/style.css +10 -1
- package/src/cleanup.js +26 -11
- package/src/cli.js +18 -3
- package/src/engines/codex.js +12 -0
- package/src/limits.js +115 -0
- package/src/manager.js +82 -5
- package/src/reminders.js +2 -2
- package/src/rules.js +52 -7
- package/src/server.js +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.40.0 (2026-11-11)
|
|
4
|
+
|
|
5
|
+
- **A calmer agent list.** No summary line under each name (it's the name's tooltip, and search still finds it); the engine, container, assistant and playbook tags move to the line below. The project name shows where the branch was (the branch is in its tooltip).
|
|
6
|
+
- **Open sessions stand out** with a green background, a little stronger while the agent is working and when selected.
|
|
7
|
+
- **Overview and Questions panels.** In an agent's detail, **Overview** (the AI review, marked *new* until you've seen it) and **Questions** (open questions with their answer buttons, and what you answered) sit next to **Review changes**, each in its own panel, instead of filling the page. Prompts, limits, stuck warnings and overlaps still show on the page.
|
|
8
|
+
|
|
9
|
+
## 1.39.0 (2026-11-11)
|
|
10
|
+
|
|
11
|
+
- **Limits: agents carry on after a usage limit.** When an engine stops at a usage limit or exhausted quota ("5-hour limit reached ∙ resets 3pm", Codex's "try again at 3:05 PM") or a busy or failing service (429, 529 overloaded, 5xx), the inbox shows a **Limit** card with the message and when it resets, read in the time zone it names. A minute after the reset the agent is told to continue (a busy service: after 5 minutes), at most three times an hour; `"limits": { "autoResume": false }` turns that off. **Continue now** does it at once.
|
|
12
|
+
- **Continue on another engine.** From the Limit card, **Continue on Codex** (or any other installed engine), or `agentmgr continue-on <agent> <engine>`: a new agent in the same folder and branch, started with the request, the brief and the end of the conversation. It owns the folder from then on; the old agent is closed, says where the work went, and deleting it leaves the folder.
|
|
13
|
+
- **Approval rules for every repo.** Once you've allowed a command in 2 repos, the inbox offers it for every repo; accepted, agents in any repo stop asking about it.
|
|
14
|
+
- **Read-only commands never ask:** `ls`, `pwd`, `wc`, `git status`, `git diff`, `git log`, `git show`, `git blame`, `git rev-parse`, in every repo (plain commands only; chained or redirected ones still ask). `"rules": { "readOnly": false }` turns it off.
|
|
15
|
+
- **Codex agents learn approval rules too:** their "run the following command?" prompt names the command in the inbox, your yeses count toward a rule, and allowed rules answer them.
|
|
16
|
+
- **Close idle sessions after hours.** Settings → Open agents → "Close sessions idle for N hours" (or `agentmgr cleanup --idle-hours 4`): open sessions quiet that long close on the same rules as the open-agent limit, and resume with their conversation when you open them. Off by default.
|
|
17
|
+
|
|
3
18
|
## 1.38.0 (2026-11-11)
|
|
4
19
|
|
|
5
20
|
- **The top bar fits the window.** View buttons that don't fit go, in order, into a **More ▾** menu at the end of the row (with a dot when one of them has a count); the filter gives up its room first, and below 1100px the title and connection text step aside for the logo and a coloured dot. **+ New agents** and your menu always stay in view.
|
package/README.md
CHANGED
|
@@ -613,7 +613,9 @@ The **Inbox** tab (and `agentmgr inbox`) lists what needs you, across all agents
|
|
|
613
613
|
|
|
614
614
|
Follow-up reminders skip agents that are working or already waiting on you for something else, and agents you closed yourself. Change the timing in config.json: `"reminders": { "quietHours": 2, "recentDays": 3, "laterHours": 4 }`, or turn them off with `"enabled": false`. From the command line: `agentmgr remind <agent> later|dismiss`.
|
|
615
615
|
|
|
616
|
-
**
|
|
616
|
+
**Limits.** When an engine stops at a usage limit ("5-hour limit reached ∙ resets 3pm", Codex's "You've hit your usage limit… try again at 3:05 PM", an exhausted quota) or a busy or failing service (429, 529 overloaded, 5xx), the agent shows **Limit** in the inbox with the message and when it resets. It is told to continue by itself a minute after the reset (a busy service: after 5 minutes), at most three times an hour; `"limits": { "autoResume": false }` in config.json turns that off. **Continue now** does it at once, and **Continue on Codex** (or any other installed engine; `agentmgr continue-on <agent> <engine>`) carries the work on: a new agent in the same folder and branch, started with the request, the brief and the end of the conversation (a conversation can't move between engines). The new agent owns the folder from then on; the old one is closed, and deleting it leaves the folder.
|
|
617
|
+
|
|
618
|
+
**Fewer questions: approval rules.** Each yes you give a permission prompt counts toward the command, per repo (`npm test`, `pytest`, `git status`; an MCP tool; fetching from a site). After 3, the inbox offers to always allow it there. An allowed rule goes to every agent in that repo when it starts (Claude Code's `--allowedTools`), and answers its prompts that are already open, so you aren't asked again. Rules are never offered for commands that chain, redirect or substitute (`&&`, `|`, `>`, `$(…)`), or that delete, escalate, publish or reach the network (`rm`, `sudo`, `git push`, `npm publish`, `curl`…). Settings → Approval rules (or `agentmgr rules`) lists them with how many prompts each answered; **Remove** to be asked again. Stored in `~/.agentmanager/rules.json`; In config.json, `"rules": { "auto": false }` stops rules answering open prompts and `"rules": { "suggestAfter": 5 }` changes the count. Once a rule is allowed in 2 repos, the inbox offers it for every repo. A few commands that only look (`ls`, `pwd`, `wc`, `git status`, `git diff`, `git log`, `git show`, `git blame`, `git rev-parse`) never ask in any repo; `"rules": { "readOnly": false }` turns that off. Claude Code and Codex agents learn rules (Codex from the command its prompt shows).
|
|
617
619
|
|
|
618
620
|
**Questions without stopping.** Task agents are told to write questions that don't block all their work to `QUESTIONS.md` next to their brief, with options and the default they'll assume meanwhile, and then keep going:
|
|
619
621
|
|
|
@@ -1078,6 +1080,8 @@ Agents closed before clean up was turned on count as closed from the first check
|
|
|
1078
1080
|
|
|
1079
1081
|
**A limit on open agents.** Many open sessions slow the machine down. In **☰ → Settings** (or `agentmgr cleanup --max-open 12`), set how many agents may be open at once: above it, the agents idle longest are closed, and they resume when you open them. Never closed for the limit: agents working, waiting for your answer, active in the last 5 minutes, marked **Keep**, or in a team that is still going. Off by default (`--max-open off`).
|
|
1080
1082
|
|
|
1083
|
+
**Closing idle sessions.** In the same place (or `agentmgr cleanup --idle-hours 4`), set how many hours an open session may sit idle: after that it is closed, on the same rules as the limit, and it resumes with its conversation when you open it. Off by default (`--idle-hours off`).
|
|
1084
|
+
|
|
1081
1085
|
## Saving state: flush and restart
|
|
1082
1086
|
|
|
1083
1087
|
- **What's saved immediately.** Agent records (session IDs, settings, links) are written to `state.json` on every change, fsynced, then atomically replaced. Claude writes each conversation to its own transcript as it goes.
|
package/package.json
CHANGED
package/public/app.js
CHANGED
|
@@ -1027,16 +1027,15 @@ function agentItem(a, { project = false } = {}) {
|
|
|
1027
1027
|
const st = statusOf(a);
|
|
1028
1028
|
const idle = !isActive(a);
|
|
1029
1029
|
const p = project && a.projectInfo && !['other', 'general', 'assistant'].includes(a.projectInfo.key) ? a.projectInfo : null;
|
|
1030
|
-
return `<li data-id="${a.id}" ${a.kind === 'general' || a.kind === 'assistant' ? '' : 'draggable="true" '}class="agent pr${a.priority ?? 2} ${a.id === selectedId ? 'selected' : ''} ${idle ? 'idle' : ''}">
|
|
1031
|
-
<div class="line1">${prioChip(a.priority ?? 2)}${a.results?.outcome === 'blocked' ? '<span class="outcome-mark" title="Blocked">⛔</span>' : a.results?.outcome === 'done' ? '<span class="outcome-mark" title="Done">✅</span>' : ''}<span class="name">${esc(a.name)}</span>${flags(a)}<span class="pill ${st}">${pillText(st)}</span></div>
|
|
1032
|
-
<div class="intent" title="${esc(describeTitle(a) ?? '')}">${a.builds ? `<span class="tag assistant" title="Develops the agent ${esc(a.builds.name)} (Built tab)">⚙ builds agent</span> ` : ''}${a.kind === 'general' ? '<span class="tag">general</span> ' : a.kind === 'assistant' ? '<span class="tag assistant">assistant</span> ' : a.startedBy ? '<span class="tag assistant" title="Started by the assistant">🤖 by assistant</span> ' : a.trigger ? `<span class="tag assistant" title="Started from ${a.trigger.source === 'github' ? 'a labeled GitHub issue' : 'the webhook'}${a.trigger.url ? `: ${esc(a.trigger.url)}` : ''}">⚡ ${a.trigger.source === 'github' ? 'GitHub' : 'webhook'}</span> ` : a.playbook ? `<span class="tag assistant" title="Started by the playbook ${esc(a.playbook.name)}">▶ ${esc(a.playbook.name)}</span> ` : ''}${a.engine && a.engine !== 'claude' ? `<span class="tag engine">${esc(ENGINE_LABEL[a.engine] ?? a.engine)}</span> ` : ''}${a.isolation === 'container' ? '<span class="tag engine" title="Runs in its own Docker container: it sees only its own folder">📦 container</span> ' : ''}${esc(describe(a) || (a.kind === 'assistant' ? 'Finds new work and starts agents for it' : 'General session'))}</div>
|
|
1030
|
+
return `<li data-id="${a.id}" ${a.kind === 'general' || a.kind === 'assistant' ? '' : 'draggable="true" '}class="agent pr${a.priority ?? 2} ${a.id === selectedId ? 'selected' : ''} ${idle ? 'idle' : ''} ${a.runtime.running ? `running ${st}` : ''}">
|
|
1031
|
+
<div class="line1">${prioChip(a.priority ?? 2)}${a.results?.outcome === 'blocked' ? '<span class="outcome-mark" title="Blocked">⛔</span>' : a.results?.outcome === 'done' ? '<span class="outcome-mark" title="Done">✅</span>' : ''}<span class="name" title="${esc(describeTitle(a) || (a.kind === 'assistant' ? 'Finds new work and starts agents for it' : 'General session'))}">${esc(a.name)}</span>${flags(a)}<span class="pill ${st}">${pillText(st)}</span></div>
|
|
1033
1032
|
${a.status === 'preparing' && a.progress ? `<div class="progress-line">${esc(progressText(a.progress))}</div>` : ''}
|
|
1034
1033
|
<div class="meta">
|
|
1035
1034
|
<span class="mono">${a.id}</span>
|
|
1036
|
-
${
|
|
1035
|
+
${a.builds ? `<span class="tag assistant" title="Develops the agent ${esc(a.builds.name)} (Built tab)">⚙ builds agent</span> ` : ''}${a.kind === 'general' ? '<span class="tag">general</span> ' : a.kind === 'assistant' ? '<span class="tag assistant">assistant</span> ' : a.startedBy ? '<span class="tag assistant" title="Started by the assistant">🤖 by assistant</span> ' : a.trigger ? `<span class="tag assistant" title="Started from ${a.trigger.source === 'github' ? 'a labeled GitHub issue' : 'the webhook'}${a.trigger.url ? `: ${esc(a.trigger.url)}` : ''}">⚡ ${a.trigger.source === 'github' ? 'GitHub' : 'webhook'}</span> ` : a.playbook ? `<span class="tag assistant" title="Started by the playbook ${esc(a.playbook.name)}">▶ ${esc(a.playbook.name)}</span> ` : ''}${a.engine && a.engine !== 'claude' ? `<span class="tag engine">${esc(ENGINE_LABEL[a.engine] ?? a.engine)}</span> ` : ''}${a.isolation === 'container' ? '<span class="tag engine" title="Runs in its own Docker container: it sees only its own folder">📦 container</span> ' : ''}
|
|
1037
1036
|
${!idle && project && a.activeAt ? `<span title="Last used">${ago(a.activeAt)}</span>` : ''}
|
|
1038
1037
|
${idle && a.activeAt ? `<span title="Idle: no work and no input from you for over a day">💤 ${ago(a.activeAt)}</span>` : ''}
|
|
1039
|
-
${
|
|
1038
|
+
${p ? `<span class="branch proj-name" title="Project: ${esc(p.full || p.name)}${a.git?.branch ? ` · branch ${esc(a.git.branch)}` : ''}">${esc(p.name)}</span>` : ''}
|
|
1040
1039
|
${a.prs.length ? `<span>${a.prs.length} PR</span>` : ''}
|
|
1041
1040
|
${a.bugs.length ? `<span>${a.bugs.length} bug</span>` : ''}
|
|
1042
1041
|
${a.usage?.total ? `<span title="${esc(usageTitle(a.usage))}">${fmtTokens(ioOf(a.usage))} tok</span>` : ''}
|
|
@@ -1385,11 +1384,23 @@ function flags(a) {
|
|
|
1385
1384
|
}
|
|
1386
1385
|
|
|
1387
1386
|
const TRIAGED = { now: 'sent (AI: urgent)', digest: 'held for the digest', skip: 'dropped by the AI judge' };
|
|
1388
|
-
|
|
1387
|
+
// Engines a limited agent can carry on with (installed ones), loaded once when a limit card shows.
|
|
1388
|
+
let limitEngines = null;
|
|
1389
|
+
function loadLimitEngines() {
|
|
1390
|
+
limitEngines = [];
|
|
1391
|
+
api('GET', '/engines')
|
|
1392
|
+
.then((list) => {
|
|
1393
|
+
limitEngines = list;
|
|
1394
|
+
renderInbox();
|
|
1395
|
+
})
|
|
1396
|
+
.catch(() => (limitEngines = null));
|
|
1397
|
+
}
|
|
1398
|
+
const NEED_ORDER = { approval: 0, prompt: 0, limit: 1, waiting: 1, plan: 1, question: 1, team: 1, rule: 2, review: 2, autopilot: 2, stuck: 3, conflict: 4, reminder: 5, close: 5, repeat: 5 };
|
|
1389
1399
|
/** What an agent needs from the user. `both`: overlaps on both agents (detail), else only the one that should rebase (inbox). */
|
|
1390
1400
|
function needsFor(a, { both = false } = {}) {
|
|
1391
1401
|
const items = [];
|
|
1392
1402
|
if (a.runtime.attention) items.push({ a, kind: 'prompt', key: `prompt:${a.id}` });
|
|
1403
|
+
if (a.runtime.limited) items.push({ a, kind: 'limit', key: `limit:${a.id}` });
|
|
1393
1404
|
if (a.runtime.waiting) items.push({ a, kind: 'waiting', key: `waiting:${a.id}` });
|
|
1394
1405
|
if (a.planReview?.status === 'review') items.push({ a, kind: 'plan', key: `plan:${a.id}` });
|
|
1395
1406
|
if (a.aiReview?.verdict && !a.aiReview.seen) items.push({ a, kind: 'review', key: `review:${a.id}` });
|
|
@@ -1411,7 +1422,7 @@ function approvalNeeds() {
|
|
|
1411
1422
|
return builtReports.flatMap((r) => r.pending.map((p) => ({ a: { id: r.key, name: r.title, priority: 1 }, kind: 'approval', key: `approval:${r.key}:${p.id}`, r, p })));
|
|
1412
1423
|
}
|
|
1413
1424
|
/** The repo a rule belongs to, short: its last two path parts. */
|
|
1414
|
-
const repoLabel = (k) => String(k).replace(/^dir:/, '').split('/').filter(Boolean).slice(-2).join('/');
|
|
1425
|
+
const repoLabel = (k) => (k === '*' ? 'every repo' : String(k).replace(/^dir:/, '').split('/').filter(Boolean).slice(-2).join('/'));
|
|
1415
1426
|
/** Commands you keep allowing in a repo, offered as a standing rule. */
|
|
1416
1427
|
function ruleNeeds() {
|
|
1417
1428
|
return rulesState.suggestions.map((r) => ({ a: { id: 'rules', name: repoLabel(r.repo), priority: 2 }, kind: 'rule', key: `rule:${r.repo}:${r.rule}`, r }));
|
|
@@ -1431,7 +1442,7 @@ function inboxItems() {
|
|
|
1431
1442
|
.sort((x, y) => NEED_ORDER[x.kind] - NEED_ORDER[y.kind] || (x.a.priority ?? 2) - (y.a.priority ?? 2));
|
|
1432
1443
|
}
|
|
1433
1444
|
|
|
1434
|
-
const NEED_LABEL = { reminder: 'Follow up', close: 'Close session?', repeat: 'Make it a playbook?', autopilot: 'Autopilot held', rule: 'Always allow?', approval: 'Approval', team: 'Team', prompt: 'Needs input', waiting: 'Waiting on you', plan: 'Plan review', question: 'Question', review: 'AI review', stuck: 'Stuck?', conflict: 'Overlap' };
|
|
1445
|
+
const NEED_LABEL = { limit: 'Limit', reminder: 'Follow up', close: 'Close session?', repeat: 'Make it a playbook?', autopilot: 'Autopilot held', rule: 'Always allow?', approval: 'Approval', team: 'Team', prompt: 'Needs input', waiting: 'Waiting on you', plan: 'Plan review', question: 'Question', review: 'AI review', stuck: 'Stuck?', conflict: 'Overlap' };
|
|
1435
1446
|
/** Why the AI judge thinks so, as a small tag. */
|
|
1436
1447
|
const aiTag = (confidence, what = 'AI') => `<span class="tag ai" title="Judged by a model from the agent's activity; your reactions tune later calls">🤖 ${what}${confidence != null ? ` ${Math.round(confidence * 100)}%` : ''}</span>`;
|
|
1437
1448
|
/** What a permission prompt asks about: the command, file or tool. */
|
|
@@ -1486,7 +1497,10 @@ function needCard(it, { inDetail = false } = {}) {
|
|
|
1486
1497
|
<p class="hint">${esc(it.it.autopilot.note ?? '')}</p>
|
|
1487
1498
|
<div class="need-actions"><button class="small primary" data-ib="ap-review">Review changes</button><button class="small" data-ib="ap-ship" title="Commit, push and open its pull request (and merge it, at the Merge level)">Ship it</button><button class="small" data-ib="ap-reopen">Send back…</button>${improveHtml(agents.get(it.it.agentId)).replace('small primary', 'small')}</div>`;
|
|
1488
1499
|
} else if (it.kind === 'rule') {
|
|
1489
|
-
body =
|
|
1500
|
+
body = it.r.everywhere
|
|
1501
|
+
? `<p class="need-title">You always allow <code>${esc(it.r.label)}</code> in ${it.r.n} repos. Allow it in every repo?</p>
|
|
1502
|
+
<p class="hint">Agents in any repo won't ask about it again. Remove it any time in Settings → Approval rules.</p>`
|
|
1503
|
+
: `<p class="need-title">You've allowed <code>${esc(it.r.label)}</code> ${it.r.n} times in this repo. Always allow it here?</p>
|
|
1490
1504
|
<p class="hint">Agents in ${esc(a.name)} won't ask about it again. Remove it any time in Settings → Approval rules.</p>
|
|
1491
1505
|
<div class="need-actions"><button class="small primary" data-ib="rule-accept">Always allow</button><button class="small" data-ib="rule-dismiss">Not now</button></div>`;
|
|
1492
1506
|
} else if (it.kind === 'prompt') {
|
|
@@ -1497,6 +1511,14 @@ function needCard(it, { inDetail = false } = {}) {
|
|
|
1497
1511
|
<button class="small" data-ib="key" data-key="esc" title="Escape">Esc</button>
|
|
1498
1512
|
<button class="small ghost" data-ib="terminal">Open terminal</button>
|
|
1499
1513
|
</div>`;
|
|
1514
|
+
} else if (it.kind === 'limit') {
|
|
1515
|
+
const l = a.runtime.limited;
|
|
1516
|
+
const when = l.resetAt ? new Date(l.resetAt).toLocaleString([], { weekday: 'short', hour: 'numeric', minute: '2-digit' }) : null;
|
|
1517
|
+
const others = (limitEngines ?? []).filter((e) => e.installed && e.id !== (a.engine ?? 'claude'));
|
|
1518
|
+
if (!limitEngines) loadLimitEngines();
|
|
1519
|
+
body = `<p class="need-title">${esc(l.text)}</p>
|
|
1520
|
+
<p class="hint">${l.resumedAt ? `Told it to continue ${ago(l.resumedAt)}.` : when ? `It continues by itself ${l.kind === 'busy' ? 'at' : 'after the reset,'} ${esc(when)}.` : 'No reset time on screen: continue it yourself, or carry the work on with another engine.'}${others.length ? ' Another engine picks up the same folder and branch, with the request, the brief and the end of the conversation.' : ''}</p>
|
|
1521
|
+
<div class="need-actions"><button class="small" data-ib="limit-resume" title="Type "continue" now">Continue now</button>${others.map((e) => `<button class="small" data-ib="limit-switch" data-engine="${esc(e.id)}">Continue on ${esc(e.label)}</button>`).join('')}<button class="small ghost" data-ib="terminal">Open terminal</button></div>`;
|
|
1500
1522
|
} else if (it.kind === 'waiting') {
|
|
1501
1523
|
const w = a.runtime.waiting;
|
|
1502
1524
|
body = `<p class="need-title">${esc(w.question || w.summary)} ${aiTag(w.confidence, w.state === 'error' ? 'looks like an error' : 'read from its screen')}</p>
|
|
@@ -1684,7 +1706,18 @@ async function onNeed(e) {
|
|
|
1684
1706
|
return act(async () => {
|
|
1685
1707
|
rulesState = await api('POST', `/rules/${accept ? 'accept' : 'dismiss'}`, { repo, rule });
|
|
1686
1708
|
renderInbox();
|
|
1687
|
-
}, accept ? 'Allowed in this repo; agents there won\'t ask again' : 'Won\'t suggest it again');
|
|
1709
|
+
}, accept ? (repo === '*' ? "Allowed in every repo; agents won't ask again" : 'Allowed in this repo; agents there won\'t ask again') : 'Won\'t suggest it again');
|
|
1710
|
+
}
|
|
1711
|
+
case 'limit-resume':
|
|
1712
|
+
return act(async () => upsert(await api('POST', `/agents/${id}/tell`, { text: 'Continue where you left off.' })), 'Told it to continue');
|
|
1713
|
+
case 'limit-switch': {
|
|
1714
|
+
const label = el.textContent.replace(/^Continue on /, '');
|
|
1715
|
+
return act(async () => {
|
|
1716
|
+
const n = await api('POST', `/agents/${id}/continue-on`, { engine: el.dataset.engine });
|
|
1717
|
+
upsert(n);
|
|
1718
|
+
showTab('agents');
|
|
1719
|
+
select(n.id);
|
|
1720
|
+
}, `Continuing on ${label}`);
|
|
1688
1721
|
}
|
|
1689
1722
|
case 'terminal':
|
|
1690
1723
|
showTab('agents');
|
|
@@ -1750,11 +1783,42 @@ async function onNeedSubmit(e) {
|
|
|
1750
1783
|
}
|
|
1751
1784
|
done();
|
|
1752
1785
|
}
|
|
1753
|
-
for (const root of [$('#inbox-view'), $('#detail-body')]) {
|
|
1786
|
+
for (const root of [$('#inbox-view'), $('#detail-body'), $('#needs-body')]) {
|
|
1754
1787
|
root.addEventListener('click', onNeed);
|
|
1755
1788
|
root.addEventListener('submit', onNeedSubmit);
|
|
1756
1789
|
}
|
|
1757
1790
|
|
|
1791
|
+
// ------------------------------------------------------------------ overview and questions panels
|
|
1792
|
+
|
|
1793
|
+
const openQuestions = (a) => (a.questions ?? []).filter((q) => !q.answer).length;
|
|
1794
|
+
let needsOpen = null; // { id, kind: 'overview' | 'questions' }
|
|
1795
|
+
|
|
1796
|
+
function openNeeds(id, kind) {
|
|
1797
|
+
needsOpen = { id, kind };
|
|
1798
|
+
renderNeeds();
|
|
1799
|
+
if (!$('#needs-dialog').open) $('#needs-dialog').showModal();
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
/** The open panel's cards, redrawn as the agent changes (an answer sent, the review marked seen). */
|
|
1803
|
+
function renderNeeds() {
|
|
1804
|
+
if (!needsOpen) return;
|
|
1805
|
+
const a = agents.get(needsOpen.id);
|
|
1806
|
+
if (!a) return $('#needs-dialog').close();
|
|
1807
|
+
$('#needs-title').textContent = `${needsOpen.kind === 'overview' ? 'Overview' : 'Questions'}: ${a.name}`;
|
|
1808
|
+
let html;
|
|
1809
|
+
if (needsOpen.kind === 'overview') {
|
|
1810
|
+
html = a.aiReview?.verdict ? needCard({ a, kind: 'review', key: `review:${a.id}` }, { inDetail: true }) : '<p class="hint">No AI review yet.</p>';
|
|
1811
|
+
} else {
|
|
1812
|
+
const open = (a.questions ?? []).filter((q) => !q.answer);
|
|
1813
|
+
const answered = (a.questions ?? []).filter((q) => q.answer);
|
|
1814
|
+
html = (open.length ? `<div class="needs">${open.map((q) => needCard({ a, kind: 'question', key: `q:${a.id}:${q.id}`, q }, { inDetail: true })).join('')}</div>` : '<p class="hint">No open questions.</p>') +
|
|
1815
|
+
(answered.length ? `<h4>Answered</h4><ul class="answered">${answered.map((q) => `<li><b>${esc(q.question)}</b><br>${esc(q.answer.text ?? q.answer)} <span class="hint">${q.answer.at ? ago(q.answer.at) : ""}</span></li>`).join('')}</ul>` : '');
|
|
1816
|
+
}
|
|
1817
|
+
morph($('#needs-body'), `<div class="needs">${html}</div>`);
|
|
1818
|
+
}
|
|
1819
|
+
$('#needs-close').onclick = () => $('#needs-dialog').close();
|
|
1820
|
+
$('#needs-dialog').addEventListener('close', () => (needsOpen = null));
|
|
1821
|
+
|
|
1758
1822
|
// ------------------------------------------------------------------ checkpoints and forks
|
|
1759
1823
|
|
|
1760
1824
|
function checkpointsCard(a) {
|
|
@@ -2159,6 +2223,7 @@ function bugRow(a, b) {
|
|
|
2159
2223
|
}
|
|
2160
2224
|
|
|
2161
2225
|
function renderDetail() {
|
|
2226
|
+
renderNeeds();
|
|
2162
2227
|
const a = agents.get(selectedId);
|
|
2163
2228
|
$('#placeholder').hidden = Boolean(a);
|
|
2164
2229
|
const body = $('#detail-body');
|
|
@@ -2205,6 +2270,8 @@ function renderDetail() {
|
|
|
2205
2270
|
${(a.engine ?? 'claude') === 'claude' && a.isolation !== 'container' && !a.movedTo && !REMOTE ? `<button data-act="desktop" ${a.sessionId && a.workdir && a.status !== 'preparing' ? '' : 'disabled'} title="Continue this conversation in the Claude desktop app. Its session here closes; Resume here later picks up what was said there">Open in Claude desktop</button>` : ''}
|
|
2206
2271
|
<button data-act="shell" ${a.workdir && a.status !== 'preparing' ? '' : 'disabled'} title="A separate terminal in this agent's folder for running commands by hand">Open shell</button>
|
|
2207
2272
|
${noRepo(a) ? '' : `<button data-act="changes" ${a.workdir && a.status !== 'preparing' ? '' : 'disabled'} title="Read its changes, comment on lines for the agent, commit and open a pull request">Review changes${a.git?.dirtyFiles ? ` <span class="count">${a.git.dirtyFiles}</span>` : ''}</button>`}
|
|
2273
|
+
${a.aiReview?.verdict ? `<button data-act="overview" title="The AI review: what's done, what's missing, the risks">Overview${a.aiReview.seen ? '' : ' <span class="count">new</span>'}</button>` : ''}
|
|
2274
|
+
${a.questions?.length ? `<button data-act="questions" title="What the agent asked you, and your answers">Questions${openQuestions(a) ? ` <span class="count">${openQuestions(a)}</span>` : ''}</button>` : ''}
|
|
2208
2275
|
<button data-act="fork" ${a.workdir && a.git?.branch ? '' : 'disabled'} title="A new agent with this one's code and conversation, in its own worktree, to try another approach">Fork</button>
|
|
2209
2276
|
<button data-act="edit" title="Change its name, request, project, priority, permission mode or model">Edit</button>
|
|
2210
2277
|
<button data-act="refresh" title="Re-scan git, PRs and transcripts">Refresh</button>
|
|
@@ -2222,7 +2289,10 @@ function renderDetail() {
|
|
|
2222
2289
|
${a.desktop && !running ? `<p class="hint">Continued in the <b>Claude desktop app</b> ${ago(a.desktop.at)}. Messages for it wait here; <b>Resume</b> picks up what was said there (close it in the desktop app first).</p>` : ''}
|
|
2223
2290
|
${a.movedTo ? `<p class="hint">Moved to <b>${esc(a.movedTo.machine)}</b> ${ago(a.movedTo.at)}: it continues there with the same conversation and work. This copy stays closed; delete it when you no longer need its folder.</p>` : ''}
|
|
2224
2291
|
${a.movedFrom ? `<p class="hint">Moved here from <b>${esc(a.movedFrom.machine ?? 'another machine')}</b> ${ago(a.movedFrom.at)}, with its conversation and uncommitted work.</p>` : ''}
|
|
2292
|
+
${a.continuedOn ? `<p class="hint">Continued on ${esc(a.continuedOn.label ?? a.continuedOn.engine)} as <a href="#${a.continuedOn.agentId}" data-goto="${a.continuedOn.agentId}">${esc(a.continuedOn.name)}</a> ${ago(a.continuedOn.at)}, in the same folder and branch.</p>` : ''}
|
|
2293
|
+
${a.continuesFrom ? `<p class="hint">Carries on <a href="#${a.continuesFrom.agentId}" data-goto="${a.continuesFrom.agentId}">${esc(a.continuesFrom.name)}</a>'s work (it ran on ${esc(a.continuesFrom.label ?? a.continuesFrom.engine)}), from ${ago(a.continuesFrom.at)}.</p>` : ''}
|
|
2225
2294
|
${!running && a.closedBy === 'cap' ? `<p class="hint">Closed ${ago(a.closedAt)} to stay under the limit on open agents (Settings), as the one idle longest. Resume it any time${a.keep ? '' : ', or mark it Keep'}.</p>` : ''}
|
|
2295
|
+
${!running && a.closedBy === 'idle' ? `<p class="hint">Closed ${ago(a.closedAt)} after a few hours with no activity (Settings). Resume it any time, with its conversation${a.keep ? '' : ', or mark it Keep'}.</p>` : ''}
|
|
2226
2296
|
${!running && a.closedBy === 'cleanup' ? `<p class="hint">Closed by clean up ${ago(a.closedAt)}, after a while with no activity. Resume it any time${a.keep ? '' : ', or mark it Keep'}.</p>` : ''}
|
|
2227
2297
|
${a.status === 'preparing'
|
|
2228
2298
|
? `<div class="progress-box">
|
|
@@ -2245,7 +2315,8 @@ function renderDetail() {
|
|
|
2245
2315
|
${a.builds ? builtUi.panel(a) : ''}
|
|
2246
2316
|
${a.forkOf ? `<div class="bl-banner">⑂ Forked from <a href="#${a.forkOf.agentId}" data-goto="${a.forkOf.agentId}">${esc(a.forkOf.name)}</a>${a.forkOf.checkpoint ? ` at checkpoint ${a.forkOf.checkpoint}` : ''} ${ago(a.forkOf.at)}</div>` : ''}
|
|
2247
2317
|
${(() => {
|
|
2248
|
-
|
|
2318
|
+
// The AI review and the questions have their own panels (Overview, Questions).
|
|
2319
|
+
const items = needsFor(a, { both: true }).filter((it) => it.kind !== 'review' && it.kind !== 'question');
|
|
2249
2320
|
return items.length ? `<div class="needs">${items.map((it) => needCard(it, { inDetail: true })).join('')}</div>` : '';
|
|
2250
2321
|
})()}
|
|
2251
2322
|
${a.outbox ? `<div class="hint outbox-note">✉ ${a.outbox} message${a.outbox > 1 ? 's' : ''} waiting to be typed into the session when the agent is idle</div>` : ''}
|
|
@@ -3792,6 +3863,9 @@ $('#detail-body').addEventListener('click', async (e) => {
|
|
|
3792
3863
|
break;
|
|
3793
3864
|
case 'changes':
|
|
3794
3865
|
return reviewUi.open(a.id);
|
|
3866
|
+
case 'overview':
|
|
3867
|
+
case 'questions':
|
|
3868
|
+
return openNeeds(a.id, btn.dataset.act);
|
|
3795
3869
|
case 'memory':
|
|
3796
3870
|
return openMemory(a);
|
|
3797
3871
|
case 'fork':
|
package/public/index.html
CHANGED
|
@@ -526,6 +526,15 @@
|
|
|
526
526
|
<div id="team-body" class="race-body team-body"></div>
|
|
527
527
|
</dialog>
|
|
528
528
|
|
|
529
|
+
<dialog id="needs-dialog" class="doc-dialog">
|
|
530
|
+
<div class="doc-head">
|
|
531
|
+
<h2 id="needs-title">Overview</h2>
|
|
532
|
+
<span class="spacer"></span>
|
|
533
|
+
<button type="button" id="needs-close" class="small ghost">Close</button>
|
|
534
|
+
</div>
|
|
535
|
+
<div id="needs-body" class="needs-body"></div>
|
|
536
|
+
</dialog>
|
|
537
|
+
|
|
529
538
|
<dialog id="review-dialog" class="doc-dialog review-dialog">
|
|
530
539
|
<div class="doc-head">
|
|
531
540
|
<h2 id="review-title">Review</h2>
|
|
@@ -877,12 +886,14 @@
|
|
|
877
886
|
<fieldset>
|
|
878
887
|
<legend>Open agents</legend>
|
|
879
888
|
<label class="check">Keep at most <input type="number" name="maxRunning" min="1" max="500" placeholder="no limit" class="num" /> agents open at once</label>
|
|
880
|
-
<
|
|
889
|
+
<label class="check">Close sessions idle for <input type="number" name="idleHours" min="1" max="720" placeholder="never" class="num" /> hours</label>
|
|
890
|
+
<p class="hint">Above the limit, the agents idle longest are closed, and so are ones idle that many hours (they resume when you open them, with their conversation), so the machine stays responsive. Never closed: agents working, waiting for your answer, active in the last 5 minutes, marked Keep, or in a team that is still going. <span id="settings-running"></span></p>
|
|
881
891
|
</fieldset>
|
|
882
892
|
<fieldset id="settings-rules">
|
|
883
893
|
<legend>Approval rules</legend>
|
|
884
|
-
<p class="hint">Commands you chose to always allow in a repo. Agents there run them without asking. After you allow the same command 3 times, the inbox offers a rule.</p>
|
|
894
|
+
<p class="hint">Commands you chose to always allow in a repo. Agents there run them without asking. After you allow the same command 3 times, the inbox offers a rule; once it's allowed in 2 repos, it offers it for every repo. Claude Code and Codex agents learn them.</p>
|
|
885
895
|
<ul id="settings-rules-list" class="rules-list"></ul>
|
|
896
|
+
<p class="hint" id="settings-rules-readonly"></p>
|
|
886
897
|
</fieldset>
|
|
887
898
|
<fieldset class="local-only" id="settings-service">
|
|
888
899
|
<legend>Start at login</legend>
|
package/public/menu.js
CHANGED
|
@@ -92,6 +92,7 @@ export function initMenu({ api, esc, toast, $ }) {
|
|
|
92
92
|
try {
|
|
93
93
|
const c = await api('GET', '/cleanup');
|
|
94
94
|
form.maxRunning.value = c.maxRunning ?? '';
|
|
95
|
+
form.idleHours.value = c.idleHours ?? '';
|
|
95
96
|
$('#settings-running').textContent = `Open now: ${c.running}.`;
|
|
96
97
|
service = null;
|
|
97
98
|
showRules(await api('GET', '/rules').catch(() => null));
|
|
@@ -127,8 +128,9 @@ export function initMenu({ api, esc, toast, $ }) {
|
|
|
127
128
|
const showRules = (r) => {
|
|
128
129
|
const list = [...(r?.allowed ?? [])].sort((a, b) => String(b.at).localeCompare(String(a.at)));
|
|
129
130
|
$('#settings-rules-list').innerHTML = list.length
|
|
130
|
-
? list.map((x) => `<li><code>${esc(x.label)}</code> <span class="hint">in ${esc(String(x.repo).replace(/^dir:/, '').split('/').filter(Boolean).slice(-2).join('/'))}${x.uses ? ` · answered ${x.uses} prompt${x.uses === 1 ? '' : 's'}` : ''}</span> <button type="button" class="small ghost" data-rule-remove="${esc(x.rule)}" data-repo="${esc(x.repo)}">Remove</button></li>`).join('')
|
|
131
|
+
? list.map((x) => `<li><code>${esc(x.label)}</code> <span class="hint">in ${x.repo === '*' ? 'every repo' : esc(String(x.repo).replace(/^dir:/, '').split('/').filter(Boolean).slice(-2).join('/'))}${x.uses ? ` · answered ${x.uses} prompt${x.uses === 1 ? '' : 's'}` : ''}</span> <button type="button" class="small ghost" data-rule-remove="${esc(x.rule)}" data-repo="${esc(x.repo)}">Remove</button></li>`).join('')
|
|
131
132
|
: '<li class="hint">None yet.</li>';
|
|
133
|
+
$('#settings-rules-readonly').innerHTML = r?.readOnly?.length ? `Never asked anywhere (they only look): ${r.readOnly.map((c) => `<code>${esc(c)}</code>`).join(' ')}.` : '';
|
|
132
134
|
};
|
|
133
135
|
$('#settings-rules-list').addEventListener('click', async (e) => {
|
|
134
136
|
const b = e.target.closest('[data-rule-remove]');
|
|
@@ -173,7 +175,7 @@ export function initMenu({ api, esc, toast, $ }) {
|
|
|
173
175
|
form.addEventListener('submit', async (e) => {
|
|
174
176
|
e.preventDefault();
|
|
175
177
|
try {
|
|
176
|
-
const c = await api('PUT', '/cleanup', { maxRunning: form.maxRunning.value.trim() || null });
|
|
178
|
+
const c = await api('PUT', '/cleanup', { maxRunning: form.maxRunning.value.trim() || null, idleHours: form.idleHours.value.trim() || null });
|
|
177
179
|
await api('PUT', '/update', { check: form.updateCheck.checked }).catch(() => {});
|
|
178
180
|
if (features) {
|
|
179
181
|
const want = Object.fromEntries(FEATURE_KEYS.map((k) => [k, form[`feat_${k}`].checked]));
|
|
@@ -196,7 +198,8 @@ export function initMenu({ api, esc, toast, $ }) {
|
|
|
196
198
|
toast(s.installed ? `Starts at login from now on${s.note ? `. ${s.note}` : ''}` : 'No longer starts at login', 6000);
|
|
197
199
|
}
|
|
198
200
|
dialog.close();
|
|
199
|
-
|
|
201
|
+
const idle = c.idleHours ? `; sessions idle ${c.idleHours} h close` : '';
|
|
202
|
+
toast(c.maxRunning ? `At most ${c.maxRunning} agents open; the ones idle longest close above that${idle}` : `No limit on open agents${idle}`);
|
|
200
203
|
} catch (err) {
|
|
201
204
|
$('#settings-error').textContent = err.message;
|
|
202
205
|
$('#settings-error').hidden = false;
|
package/public/style.css
CHANGED
|
@@ -223,7 +223,7 @@ body.term-max .layout { grid-template-columns: 1fr; }
|
|
|
223
223
|
#list-order, #list-project { width: auto; flex: none; padding: 1px 4px; font-size: 12px; }
|
|
224
224
|
#list-project { max-width: 160px; }
|
|
225
225
|
#list-project[hidden] { display: none; }
|
|
226
|
-
.agent-list
|
|
226
|
+
.agent-list .meta .proj-name { color: var(--text); font-weight: 500; }
|
|
227
227
|
.agent-list { list-style: none; margin: 0; padding: 0; }
|
|
228
228
|
.agent-list li.project { border-bottom: 1px solid var(--border); }
|
|
229
229
|
.agent-list li.agent[draggable='true'] { cursor: grab; }
|
|
@@ -250,6 +250,11 @@ body.term-max .layout { grid-template-columns: 1fr; }
|
|
|
250
250
|
.agent-list li.agent::before { content: ''; position: absolute; left: 19px; top: 0; bottom: 0; border-left: 1px solid var(--border); }
|
|
251
251
|
.agent-list li.agent:hover { background: var(--panel-2); }
|
|
252
252
|
.agent-list li.agent.selected { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
|
|
253
|
+
/* Open sessions stand out: a green tint, a little stronger while working. */
|
|
254
|
+
.agent-list li.agent.running { background: color-mix(in srgb, var(--green) 8%, var(--panel)); }
|
|
255
|
+
.agent-list li.agent.running.working { background: color-mix(in srgb, var(--green) 14%, var(--panel)); }
|
|
256
|
+
.agent-list li.agent.running:hover { background: color-mix(in srgb, var(--green) 16%, var(--panel)); }
|
|
257
|
+
.agent-list li.agent.running.selected { background: color-mix(in srgb, var(--green) 20%, var(--panel)); }
|
|
253
258
|
.agent-list .line1 { display: flex; align-items: center; gap: 8px; }
|
|
254
259
|
.agent-list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
|
|
255
260
|
.agent-list .intent { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
@@ -722,6 +727,10 @@ pre.diff .meta { color: var(--muted); font-weight: 600; }
|
|
|
722
727
|
/* Review changes */
|
|
723
728
|
.review-dialog { width: min(1400px, calc(100vw - 24px)); height: calc(100vh - 32px); max-height: none; }
|
|
724
729
|
.review-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 8px 18px 14px; }
|
|
730
|
+
.needs-body { flex: 1; min-height: 0; overflow: auto; padding: 0 18px 16px; }
|
|
731
|
+
.needs-body .needs .needs { margin-top: 0; }
|
|
732
|
+
.needs-body h4 { margin: 16px 0 6px; }
|
|
733
|
+
.needs-body .answered { margin: 0; padding-left: 18px; display: grid; gap: 8px; }
|
|
725
734
|
.rv-summary { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 13px; }
|
|
726
735
|
.rv-warn { margin: 0; color: var(--yellow); }
|
|
727
736
|
.rv-add { color: var(--green); font-family: var(--mono); font-size: 12px; }
|
package/src/cleanup.js
CHANGED
|
@@ -7,14 +7,16 @@
|
|
|
7
7
|
// that exists only in their worktree (uncommitted changes or commits on no other branch).
|
|
8
8
|
// Optionally, a cap on open sessions ("maxRunning"): above it, the agents idle longest are closed
|
|
9
9
|
// (they resume when opened), so the machine stays responsive. The same agents are left alone,
|
|
10
|
-
// plus ones waiting for an answer and ones active in the last few minutes.
|
|
10
|
+
// plus ones waiting for an answer and ones active in the last few minutes. And optionally an
|
|
11
|
+
// idle time in hours ("idleHours"): open sessions quiet that long are closed the same way.
|
|
11
12
|
import fs from 'node:fs';
|
|
12
13
|
import * as git from './git.js';
|
|
13
14
|
|
|
14
15
|
export const STRATEGIES = ['close-delete', 'close', 'manual', 'off'];
|
|
15
|
-
export const CLEANUP_DEFAULTS = { strategy: 'close', closeAfterDays: 14, deleteAfterDays: 14, maxRunning: null };
|
|
16
|
+
export const CLEANUP_DEFAULTS = { strategy: 'close', closeAfterDays: 14, deleteAfterDays: 14, maxRunning: null, idleHours: null };
|
|
16
17
|
const CAP_GRACE_MS = 5 * 60_000;
|
|
17
|
-
const
|
|
18
|
+
const HOUR = 3_600_000;
|
|
19
|
+
const DAY = 24 * HOUR;
|
|
18
20
|
const TEAM_DONE = new Set(['done', 'stopped']);
|
|
19
21
|
|
|
20
22
|
const err = (status, message) => Object.assign(new Error(message), { status });
|
|
@@ -29,6 +31,7 @@ export function cleanupSettings(config = {}) {
|
|
|
29
31
|
closeAfterDays: n(c.closeAfterDays, CLEANUP_DEFAULTS.closeAfterDays),
|
|
30
32
|
deleteAfterDays: n(c.deleteAfterDays, CLEANUP_DEFAULTS.deleteAfterDays),
|
|
31
33
|
maxRunning: Number(c.maxRunning) >= 1 ? Math.min(500, Math.floor(Number(c.maxRunning))) : null,
|
|
34
|
+
idleHours: Number(c.idleHours) >= 1 ? Math.min(720, Math.floor(Number(c.idleHours))) : null,
|
|
32
35
|
};
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -63,7 +66,7 @@ export class Cleanup {
|
|
|
63
66
|
this.timer.unref?.();
|
|
64
67
|
// The cap: checked soon after agents change (one starts) and every minute.
|
|
65
68
|
this.onChange = () => {
|
|
66
|
-
if (!this.settings.maxRunning || this.capSoon) return;
|
|
69
|
+
if ((!this.settings.maxRunning && !this.settings.idleHours) || this.capSoon) return;
|
|
67
70
|
this.capSoon = setTimeout(() => {
|
|
68
71
|
this.capSoon = null;
|
|
69
72
|
this.enforceCap().catch((e) => this.log(`cap: ${e.message}`));
|
|
@@ -88,16 +91,24 @@ export class Cleanup {
|
|
|
88
91
|
return this.store.list().filter((a) => a.kind !== 'assistant' && this.manager.runtimes.get(a.id)?.pty);
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Which open agents to close: those idle `idleHours` or more, and, above the cap, the ones idle
|
|
96
|
+
* longest until back under it. Protected and recently active agents are skipped.
|
|
97
|
+
*/
|
|
92
98
|
capPlan(now = Date.now()) {
|
|
93
|
-
const max = this.settings
|
|
99
|
+
const { maxRunning: max, idleHours } = this.settings;
|
|
94
100
|
const running = this.runningAgents();
|
|
95
|
-
|
|
101
|
+
const over = max ? running.length - max : 0;
|
|
102
|
+
if (over <= 0 && !idleHours) return { max, idleHours, running: running.length, close: [] };
|
|
96
103
|
const activeAt = (a) => Date.parse(this.manager.activeAt(a, this.manager.runtimes.get(a.id)) ?? a.createdAt) || now;
|
|
97
104
|
const closable = running
|
|
98
105
|
.filter((a) => !this.protectedBy(a) && !this.manager.runtimes.get(a.id)?.attention && now - activeAt(a) >= (this.config.capGraceMs ?? CAP_GRACE_MS))
|
|
99
106
|
.sort((x, y) => activeAt(x) - activeAt(y));
|
|
100
|
-
|
|
107
|
+
const close = closable
|
|
108
|
+
.map((a, i) => ({ a, why: idleHours && now - activeAt(a) >= idleHours * HOUR ? 'idle' : i < over ? 'cap' : null }))
|
|
109
|
+
.filter((x) => x.why)
|
|
110
|
+
.map(({ a, why }) => ({ id: a.id, name: a.name, idleMin: Math.floor((now - activeAt(a)) / 60_000), why }));
|
|
111
|
+
return { max, idleHours, running: running.length, close };
|
|
101
112
|
}
|
|
102
113
|
|
|
103
114
|
async enforceCap() {
|
|
@@ -110,7 +121,7 @@ export class Cleanup {
|
|
|
110
121
|
for (const row of plan.close) {
|
|
111
122
|
try {
|
|
112
123
|
await this.manager.stop(row.id);
|
|
113
|
-
this.manager.patch(row.id, { closedBy:
|
|
124
|
+
this.manager.patch(row.id, { closedBy: row.why });
|
|
114
125
|
closed.push(row);
|
|
115
126
|
} catch (e) {
|
|
116
127
|
this.log(`cap: couldn't close ${row.name}: ${e.message}`);
|
|
@@ -120,7 +131,7 @@ export class Cleanup {
|
|
|
120
131
|
this.capping = false;
|
|
121
132
|
}
|
|
122
133
|
if (closed.length) {
|
|
123
|
-
this.log(`cap: ${plan.running} open
|
|
134
|
+
this.log(`cap: ${plan.running} open${plan.max ? `, limit ${plan.max}` : ''}${plan.idleHours ? `, close after ${plan.idleHours} h idle` : ''}; closed ${closed.map((r) => `${r.name} (idle ${r.idleMin} min)`).join(', ')}`);
|
|
124
135
|
this.store.data.cleanup.lastCap = { at: new Date().toISOString(), closed };
|
|
125
136
|
this.store.save();
|
|
126
137
|
}
|
|
@@ -141,9 +152,13 @@ export class Cleanup {
|
|
|
141
152
|
if (patch.maxRunning !== undefined && patch.maxRunning !== null && patch.maxRunning !== '' && Number(patch.maxRunning) !== 0 && !(Number(patch.maxRunning) >= 1)) {
|
|
142
153
|
throw err(400, 'maxRunning must be 1 or more, or empty for no cap');
|
|
143
154
|
}
|
|
155
|
+
// idleHours: close open sessions idle this many hours, or empty/null/0 for never.
|
|
156
|
+
if (patch.idleHours !== undefined && patch.idleHours !== null && patch.idleHours !== '' && Number(patch.idleHours) !== 0 && !(Number(patch.idleHours) >= 1)) {
|
|
157
|
+
throw err(400, 'idleHours must be 1 or more, or empty to keep idle sessions open');
|
|
158
|
+
}
|
|
144
159
|
const next = cleanupSettings({ cleanup: { ...this.config.cleanup, ...patch } });
|
|
145
160
|
this.config.cleanup = next;
|
|
146
|
-
if (next.maxRunning) this.onChange?.();
|
|
161
|
+
if (next.maxRunning || next.idleHours) this.onChange?.();
|
|
147
162
|
return next;
|
|
148
163
|
}
|
|
149
164
|
|
package/src/cli.js
CHANGED
|
@@ -1299,11 +1299,12 @@ export async function main(argv) {
|
|
|
1299
1299
|
else if (action) throw new Error('Use: agentmgr rules [allow <n> | no <n> | rm <n>]');
|
|
1300
1300
|
if (r.suggestions.length) {
|
|
1301
1301
|
console.log(bold('Suggested') + dim(` (you allowed these ${r.suggestAfter}+ times; agentmgr rules allow <n> | no <n>)`));
|
|
1302
|
-
r.suggestions.forEach((x, i) => console.log(` ${i + 1}. ${x.label} ${dim(`in ${repoLabel(x.repo)}, allowed ${x.n} times`)}`));
|
|
1302
|
+
r.suggestions.forEach((x, i) => console.log(` ${i + 1}. ${x.label} ${dim(x.everywhere ? `in every repo (allowed in ${x.n} repos)` : `in ${repoLabel(x.repo)}, allowed ${x.n} times`)}`));
|
|
1303
1303
|
}
|
|
1304
1304
|
console.log(bold('Allowed') + dim(' (agents in the repo run these without asking; agentmgr rules rm <n>)'));
|
|
1305
1305
|
if (!r.allowed.length) console.log(dim(' none yet'));
|
|
1306
|
-
r.allowed.forEach((x, i) => console.log(` ${i + 1}. ${x.label} ${dim(`in ${repoLabel(x.repo)}${x.uses ? `, answered ${x.uses} prompts` : ''}`)}`));
|
|
1306
|
+
r.allowed.forEach((x, i) => console.log(` ${i + 1}. ${x.label} ${dim(`in ${x.repo === '*' ? 'every repo' : repoLabel(x.repo)}${x.uses ? `, answered ${x.uses} prompts` : ''}`)}`));
|
|
1307
|
+
if (r.readOnly?.length) console.log(dim(`Never asked anywhere (they only look): ${r.readOnly.join(', ')}`));
|
|
1307
1308
|
});
|
|
1308
1309
|
|
|
1309
1310
|
program
|
|
@@ -1366,6 +1367,18 @@ export async function main(argv) {
|
|
|
1366
1367
|
console.log(`${green('+')} ${bold(f.name)} ${f.id} forked from ${a.name}${opts.checkpoint ? ` at checkpoint ${opts.checkpoint}` : ''} session ${cyan(f.sessionId)}`);
|
|
1367
1368
|
});
|
|
1368
1369
|
|
|
1370
|
+
program
|
|
1371
|
+
.command('continue-on')
|
|
1372
|
+
.description("Carry an agent's work on with another engine (when it hits a limit): a new agent in the same folder and branch")
|
|
1373
|
+
.argument('<agent>')
|
|
1374
|
+
.argument('<engine>', 'codex, antigravity, muse, claude, or an ACP engine (acp-<name>)')
|
|
1375
|
+
.action(async (ref, engine) => {
|
|
1376
|
+
await daemon();
|
|
1377
|
+
const a = await resolveAgent(ref);
|
|
1378
|
+
const n = await api('POST', `/agents/${a.id}/continue-on`, { engine });
|
|
1379
|
+
console.log(`${green('+')} ${bold(n.name)} ${n.id} continues ${a.name} on ${engine}, in ${a.workdir}`);
|
|
1380
|
+
});
|
|
1381
|
+
|
|
1369
1382
|
program
|
|
1370
1383
|
.command('checkpoints')
|
|
1371
1384
|
.description('Checkpoints saved at the end of each turn (fork from one with agentmgr fork -c)')
|
|
@@ -1908,10 +1921,12 @@ export async function main(argv) {
|
|
|
1908
1921
|
.option('--close-after <days>', 'close sessions idle this many days')
|
|
1909
1922
|
.option('--delete-after <days>', 'delete agents closed this many days')
|
|
1910
1923
|
.option('--max-open <n>', 'keep at most this many agents open; the ones idle longest are closed above it ("off": no limit)')
|
|
1924
|
+
.option('--idle-hours <h>', 'close open sessions idle this many hours; they resume when opened ("off": never)')
|
|
1911
1925
|
.action(async (opts) => {
|
|
1912
1926
|
await daemon();
|
|
1913
1927
|
const patch = {
|
|
1914
1928
|
...(opts.maxOpen ? { maxRunning: /^(off|none|0)$/i.test(opts.maxOpen) ? null : Number(opts.maxOpen) } : {}),
|
|
1929
|
+
...(opts.idleHours ? { idleHours: /^(off|none|0)$/i.test(opts.idleHours) ? null : Number(opts.idleHours) } : {}),
|
|
1915
1930
|
...(opts.strategy ? { strategy: opts.strategy } : {}),
|
|
1916
1931
|
...(opts.closeAfter ? { closeAfterDays: Number(opts.closeAfter) } : {}),
|
|
1917
1932
|
...(opts.deleteAfter ? { deleteAfterDays: Number(opts.deleteAfter) } : {}),
|
|
@@ -1928,7 +1943,7 @@ export async function main(argv) {
|
|
|
1928
1943
|
const c = await api('GET', '/cleanup');
|
|
1929
1944
|
const what = { 'close-delete': 'closes and deletes automatically', close: 'closes automatically; delete with --run', manual: 'nothing automatic; use --run', off: 'off' }[c.strategy];
|
|
1930
1945
|
console.log(`${bold('Clean up')}: ${c.strategy} (${what}) · close after ${c.closeAfterDays} days idle · delete ${c.deleteAfterDays} days after closing`);
|
|
1931
|
-
console.log(`${bold('Open agents')}: ${c.running} open · ${c.maxRunning ? `at most ${c.maxRunning} (the ones idle longest close above it)` : 'no limit (set one: --max-open <n>)'}`);
|
|
1946
|
+
console.log(`${bold('Open agents')}: ${c.running} open · ${c.maxRunning ? `at most ${c.maxRunning} (the ones idle longest close above it)` : 'no limit (set one: --max-open <n>)'}${c.idleHours ? ` · close after ${c.idleHours} h idle` : ''}`);
|
|
1932
1947
|
if (c.lastCap) console.log(dim(` last closed for the limit ${new Date(c.lastCap.at).toLocaleString()}: ${c.lastCap.closed.map((x) => x.name).join(', ')}`));
|
|
1933
1948
|
const rows = [
|
|
1934
1949
|
...c.close.map((x) => [yellow('close'), x.name, `idle ${x.idleDays}d`, '']),
|
package/src/engines/codex.js
CHANGED
|
@@ -286,6 +286,18 @@ export default {
|
|
|
286
286
|
[/Wouldyouliketo(run|make|apply|allow|grant)/i, 'Permission prompt'],
|
|
287
287
|
],
|
|
288
288
|
|
|
289
|
+
/** The command a "Would you like to run the following command?" prompt is about, as a Bash call. */
|
|
290
|
+
screenCall(screen) {
|
|
291
|
+
const text = String(screen ?? '')
|
|
292
|
+
.replace(/\x1b\[(\d*)C/g, ' ')
|
|
293
|
+
.replace(ANSI, ' ')
|
|
294
|
+
.replace(/\s+/g, ' ');
|
|
295
|
+
const at = text.lastIndexOf('Would you like to run the following command?');
|
|
296
|
+
if (at < 0) return null;
|
|
297
|
+
const m = /^Would you like to run the following command\?.*?\$ (.+?)\s+(?:›\s*)?1\. /.exec(text.slice(at));
|
|
298
|
+
return m ? { name: 'Bash', input: { command: m[1].trim() } } : null;
|
|
299
|
+
},
|
|
300
|
+
|
|
289
301
|
/** Codex's menus: "› 1. Yes, proceed (y)" ... "3. No, and tell Codex what to do differently (esc)". */
|
|
290
302
|
promptChoices(screen) {
|
|
291
303
|
const text = String(screen ?? '')
|
package/src/limits.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// When an engine stops for a limit: a usage limit or exhausted quota ("Claude usage limit
|
|
2
|
+
// reached… resets 3pm", Codex's "You've hit your usage limit… try again at 3:05 PM"), or a busy or
|
|
3
|
+
// failing service (429, 529 overloaded, 5xx). Read from the end of the agent's screen once a turn
|
|
4
|
+
// ends. The manager shows it, types "continue" when the limit resets (a few minutes later for a
|
|
5
|
+
// busy service), and offers to carry the work on with another engine.
|
|
6
|
+
|
|
7
|
+
// Engines' own words, not an agent talking about rate limits in its code: a limit names your
|
|
8
|
+
// usage, quota or credits; a 429 or an overload has to read as an error.
|
|
9
|
+
const LIMIT = [
|
|
10
|
+
/usage limit (?:reached|hit)|(?:hit|reached) (?:your|the) (?:usage |session |weekly |5-hour |daily )?limit\b/i,
|
|
11
|
+
/\b(?:5-hour|weekly|daily|session|opus|sonnet) limit reached/i,
|
|
12
|
+
/quota (?:exceeded|exhausted)|exceeded your (?:current )?quota|RESOURCE_EXHAUSTED/i,
|
|
13
|
+
/out of (?:credits|extra usage)|credit balance is too low/i,
|
|
14
|
+
];
|
|
15
|
+
const BUSY = [/(?:api error|error|■)[^\n]{0,80}(?:\b429\b|rate limit|\b529\b|overloaded|\b50[0234]\b)/i, /overloaded_error/i];
|
|
16
|
+
// A busy service says nothing about when: try again after this long.
|
|
17
|
+
export const BUSY_RETRY_MS = 5 * 60_000;
|
|
18
|
+
|
|
19
|
+
const MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
|
|
20
|
+
|
|
21
|
+
/** Minutes a time zone is ahead of UTC at `t`, or null for a zone this Node doesn't know. */
|
|
22
|
+
function zoneOffset(zone, t) {
|
|
23
|
+
try {
|
|
24
|
+
const parts = Object.fromEntries(new Intl.DateTimeFormat('en-US', { timeZone: zone, hourCycle: 'h23', year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric' }).formatToParts(t).map((p) => [p.type, p.value]));
|
|
25
|
+
return (Date.UTC(parts.year, parts.month - 1, parts.day, parts.hour, parts.minute) - Math.floor(t / 60_000) * 60_000) / 60_000;
|
|
26
|
+
} catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Wall-clock fields in a zone (or this machine's, without one) as epoch ms. */
|
|
32
|
+
function wallTime(y, mo, d, h, min, zone, near) {
|
|
33
|
+
if (!zone) return new Date(y, mo, d, h, min).getTime();
|
|
34
|
+
const guess = Date.UTC(y, mo, d, h, min);
|
|
35
|
+
const off = zoneOffset(zone, near);
|
|
36
|
+
return off === null ? new Date(y, mo, d, h, min).getTime() : guess - off * 60_000;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Today's date in a zone (or here), as [year, month, day]. */
|
|
40
|
+
function today(zone, now) {
|
|
41
|
+
const off = zone ? zoneOffset(zone, now) : null;
|
|
42
|
+
const d = off === null ? new Date(now) : new Date(now + off * 60_000);
|
|
43
|
+
return off === null ? [d.getFullYear(), d.getMonth(), d.getDate()] : [d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** "3pm", "3:05 PM", "15:00", with an optional "Nov 12" before it and "(Area/City)" after: the next such time. */
|
|
47
|
+
function clockTime(s, now) {
|
|
48
|
+
const m = /(?:\b([a-z]{3})[a-z]*\.? (\d{1,2}),? (?:at )?)?\b(\d{1,2})(?::(\d{2}))?\s*(am|pm)?\b/i.exec(s);
|
|
49
|
+
if (!m) return null;
|
|
50
|
+
let h = Number(m[3]);
|
|
51
|
+
const min = Number(m[4] ?? 0);
|
|
52
|
+
const ampm = m[5]?.toLowerCase();
|
|
53
|
+
if (!ampm && m[4] === undefined) return null; // a bare number isn't a time
|
|
54
|
+
if (h > 23 || min > 59 || (ampm && (h < 1 || h > 12))) return null;
|
|
55
|
+
if (ampm === 'pm' && h < 12) h += 12;
|
|
56
|
+
if (ampm === 'am' && h === 12) h = 0;
|
|
57
|
+
const zone = /\(([A-Za-z_]+\/[A-Za-z_/+-]+|UTC)\)/.exec(s)?.[1] ?? null;
|
|
58
|
+
const [y, mo, d] = today(zone, now);
|
|
59
|
+
const month = m[1] ? MONTHS.indexOf(m[1].toLowerCase()) : -1;
|
|
60
|
+
if (month >= 0) {
|
|
61
|
+
let t = wallTime(y, month, Number(m[2]), h, min, zone, now);
|
|
62
|
+
if (t < now - 86_400_000) t = wallTime(y + 1, month, Number(m[2]), h, min, zone, now);
|
|
63
|
+
return t;
|
|
64
|
+
}
|
|
65
|
+
const t = wallTime(y, mo, d, h, min, zone, now);
|
|
66
|
+
return t > now ? t : wallTime(y, mo, d + 1, h, min, zone, now);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** "in 2h 15m", "in 45 minutes", "in 3 hours": from `now`. */
|
|
70
|
+
function inTime(s, now) {
|
|
71
|
+
const m = /\bin (?:(\d+)\s*(?:h|hr|hrs|hours?))?\s*(?:(\d+)\s*(?:m|min|mins|minutes?))?\b/i.exec(s);
|
|
72
|
+
if (!m || (!m[1] && !m[2])) return null;
|
|
73
|
+
return now + (Number(m[1] ?? 0) * 60 + Number(m[2] ?? 0)) * 60_000;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** When a limit message says it resets, as epoch ms, or null. */
|
|
77
|
+
export function resetTime(text, now = Date.now()) {
|
|
78
|
+
const m = /(?:resets?|reset at|resets at|try again|available again|retry)\b([^\n]{0,60})/i.exec(text);
|
|
79
|
+
if (!m) return null;
|
|
80
|
+
return inTime(m[1], now) ?? clockTime(m[1], now);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A limit at the end of a screen: { kind: 'limit' | 'busy', text, resetAt } (resetAt an ISO time,
|
|
85
|
+
* or null when a usage limit doesn't say), or null. Only the last lines count.
|
|
86
|
+
*/
|
|
87
|
+
export function findLimit(screen, now = Date.now()) {
|
|
88
|
+
const lines = String(screen ?? '')
|
|
89
|
+
.split('\n')
|
|
90
|
+
.map((l) => l.trim())
|
|
91
|
+
.filter(Boolean)
|
|
92
|
+
.slice(-8);
|
|
93
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
94
|
+
const line = lines[i];
|
|
95
|
+
const kind = LIMIT.some((re) => re.test(line)) ? 'limit' : BUSY.some((re) => re.test(line)) ? 'busy' : null;
|
|
96
|
+
if (!kind) continue;
|
|
97
|
+
// The reset time is often on the same line, sometimes on the next.
|
|
98
|
+
const at = kind === 'limit' ? resetTime(lines.slice(i, i + 2).join(' '), now) : now + BUSY_RETRY_MS;
|
|
99
|
+
return { kind, text: line.slice(0, 200), resetAt: at ? new Date(at).toISOString() : null };
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The first message for an agent that carries on another's work with a different engine. */
|
|
105
|
+
export function continuePrompt({ from, engineLabel, limit, intent, branch, brief, digest }) {
|
|
106
|
+
return [
|
|
107
|
+
`Continue this work. ${from} (${engineLabel}) was doing it in this folder${branch ? `, on branch ${branch}` : ''}, and stopped${limit ? ` at a limit ("${limit}")` : ''}.`,
|
|
108
|
+
`The original request:\n${intent}`,
|
|
109
|
+
brief ? `Its brief (what it planned and where it got to):\n${brief.slice(-6000)}` : null,
|
|
110
|
+
digest ? `The end of its conversation:\n${digest.slice(-4000)}` : null,
|
|
111
|
+
"Check `git status` and `git log` to see what is already done, then carry on from there. Don't redo finished work.",
|
|
112
|
+
]
|
|
113
|
+
.filter(Boolean)
|
|
114
|
+
.join('\n\n');
|
|
115
|
+
}
|
package/src/manager.js
CHANGED
|
@@ -126,6 +126,7 @@ import { leadPrompt, subagents, teamDir, teamPrompt } from './teams.js';
|
|
|
126
126
|
import { assistantDir, currentPrompt } from './assistant.js';
|
|
127
127
|
import { learnCommand, memoryKey, memoryPrompt, memoryText } from './memory.js';
|
|
128
128
|
import { Rules, describeTool } from './rules.js';
|
|
129
|
+
import { continuePrompt, findLimit } from './limits.js';
|
|
129
130
|
import { runningClaude, scanClaudeSessions } from './sessions.js';
|
|
130
131
|
import { builderAllowedTools, builderPrompt } from './builder.js';
|
|
131
132
|
import { DRIVE_DOCS, DRIVE_TOOLS, docUrl, driveHtml, drivePrompt, folderUrl, parseDrive } from './drive.js';
|
|
@@ -301,7 +302,7 @@ export class AgentManager extends EventEmitter {
|
|
|
301
302
|
this.stuck = new Map(); // agent id -> [finding]
|
|
302
303
|
this.outbox = new Map(); // agent id -> [message] waiting to be typed into its session
|
|
303
304
|
// The AI judge: rules decide when to look, a model decides what is going on (see judge.js).
|
|
304
|
-
this.rules = new Rules({ suggestAfter: config.rules?.suggestAfter });
|
|
305
|
+
this.rules = new Rules({ suggestAfter: config.rules?.suggestAfter, readOnly: config.rules?.readOnly });
|
|
305
306
|
this.inboxSources = [];
|
|
306
307
|
this.judge = new Judge({ config, call: (agent, prompt, { timeoutMs }) => this.oneShot(agent, prompt, { ...this.judgeModel(agent), timeoutMs }) });
|
|
307
308
|
this.stuckVerdicts = new Map(); // agent id -> Map(finding key -> { at, since, data })
|
|
@@ -390,6 +391,8 @@ export class AgentManager extends EventEmitter {
|
|
|
390
391
|
attention: (rt?.pty && !rt.busy && rt.attention) || null,
|
|
391
392
|
// What the AI judge read on an idle screen no rule matched: a question or an error.
|
|
392
393
|
waiting: (rt?.pty && !rt.busy && !rt.attention && rt.waiting) || null,
|
|
394
|
+
// Stopped at a usage limit or a busy service (limits.js): { kind, text, resetAt, resumedAt }.
|
|
395
|
+
limited: (rt?.pty && !rt.busy && !rt.attention && rt.limited) || null,
|
|
393
396
|
clients: rt?.clients.size ?? 0,
|
|
394
397
|
shell: this.shellNumbers(agent.id).length > 0,
|
|
395
398
|
shells: this.shellNumbers(agent.id),
|
|
@@ -1452,6 +1455,7 @@ export class AgentManager extends EventEmitter {
|
|
|
1452
1455
|
if (!rt.busy) {
|
|
1453
1456
|
rt.busy = true;
|
|
1454
1457
|
rt.waiting = null;
|
|
1458
|
+
rt.limited = null;
|
|
1455
1459
|
rt.screenChecked = false;
|
|
1456
1460
|
const a = this.store.get(agent.id);
|
|
1457
1461
|
if (a) this.changed(a);
|
|
@@ -3293,6 +3297,10 @@ export class AgentManager extends EventEmitter {
|
|
|
3293
3297
|
if (v.runtime.attention) {
|
|
3294
3298
|
items.push({ ...base, kind: 'prompt', key: `prompt:${agent.id}`, title: v.runtime.attention, prompt: v.runtime.prompt, at: v.runtime.lastOutputAt });
|
|
3295
3299
|
}
|
|
3300
|
+
if (v.runtime.limited) {
|
|
3301
|
+
const l = v.runtime.limited;
|
|
3302
|
+
items.push({ ...base, kind: 'limit', key: `limit:${agent.id}`, title: `${engineOf(agent).label} ${l.kind === 'busy' ? 'is busy or failing' : 'hit a limit'}: ${l.text}`, limited: l, at: l.at });
|
|
3303
|
+
}
|
|
3296
3304
|
if (v.runtime.waiting) {
|
|
3297
3305
|
items.push({ ...base, kind: 'waiting', key: `waiting:${agent.id}`, title: v.runtime.waiting.question || v.runtime.waiting.summary, waiting: v.runtime.waiting, at: v.runtime.waiting.at });
|
|
3298
3306
|
}
|
|
@@ -3309,10 +3317,10 @@ export class AgentManager extends EventEmitter {
|
|
|
3309
3317
|
}
|
|
3310
3318
|
}
|
|
3311
3319
|
// Commands you keep allowing in a repo: offer to always allow them there.
|
|
3312
|
-
for (const r of this.rules.view().suggestions) items.push({ kind: 'rule', key: `rule:${r.repo}:${r.rule}`, title: `Always allow ${r.label}?`, priority: 2, ...r });
|
|
3320
|
+
for (const r of this.rules.view().suggestions) items.push({ kind: 'rule', key: `rule:${r.repo}:${r.rule}`, title: `Always allow ${r.label}${r.everywhere ? ' in every repo' : ''}?`, priority: 2, ...r });
|
|
3313
3321
|
// Others' items (autopilot's held backlog work).
|
|
3314
3322
|
for (const source of this.inboxSources) items.push(...source());
|
|
3315
|
-
const order = { prompt: 0, waiting: 1, question: 1, rule: 2, review: 2, autopilot: 2, stuck: 3, conflict: 4, reminder: 5, repeat: 5 };
|
|
3323
|
+
const order = { prompt: 0, limit: 1, waiting: 1, question: 1, rule: 2, review: 2, autopilot: 2, stuck: 3, conflict: 4, reminder: 5, repeat: 5 };
|
|
3316
3324
|
return items.sort((a, b) => order[a.kind] - order[b.kind] || a.priority - b.priority);
|
|
3317
3325
|
}
|
|
3318
3326
|
|
|
@@ -3323,9 +3331,13 @@ export class AgentManager extends EventEmitter {
|
|
|
3323
3331
|
return call ? { ...p, tool: describeTool(call) } : p;
|
|
3324
3332
|
}
|
|
3325
3333
|
|
|
3326
|
-
/**
|
|
3334
|
+
/**
|
|
3335
|
+
* The one tool call a live prompt is waiting on: from the transcript (Claude Code), or from the
|
|
3336
|
+
* prompt on screen for engines that show it there (Codex); null when unsure.
|
|
3337
|
+
*/
|
|
3327
3338
|
pendingCall(agent) {
|
|
3328
3339
|
const engine = engineOf(agent);
|
|
3340
|
+
if (engine.screenCall) return engine.screenCall(this.runtimes.get(agent.id)?.tail ?? '');
|
|
3329
3341
|
if (engine.id !== 'claude' || !agent.workdir || !agent.sessionId) return null;
|
|
3330
3342
|
const key = `${agent.sessionId}:${agent.workdir}`;
|
|
3331
3343
|
const state = this.activity.get(key) ?? {};
|
|
@@ -3470,6 +3482,68 @@ export class AgentManager extends EventEmitter {
|
|
|
3470
3482
|
return { workdir, sourceDir: root, branch, worktree: true, repo: src.repo, baseRef: src.baseRef };
|
|
3471
3483
|
}
|
|
3472
3484
|
|
|
3485
|
+
// ------------------------------------------------------- limits
|
|
3486
|
+
|
|
3487
|
+
/** The limit at the end of an idle agent's screen, keeping when it was first seen and resumed. */
|
|
3488
|
+
limitOf(id, rt, t = Date.now()) {
|
|
3489
|
+
const found = findLimit(this.screenText(rt), t);
|
|
3490
|
+
if (!found) return null;
|
|
3491
|
+
const prev = rt.limited ?? rt.lastLimit;
|
|
3492
|
+
// The same limit seen again before it was resumed (a repaint): keep its times.
|
|
3493
|
+
if (prev && !prev.resumedAt && prev.text === found.text) return (rt.lastLimit = prev);
|
|
3494
|
+
const agent = this.store.get(id);
|
|
3495
|
+
if (agent) console.log(`[agentmgr] ${agent.name}: ${engineOf(agent).label} stopped at a limit (${found.text})${found.resetAt ? `; resets ${found.resetAt}` : ''}`);
|
|
3496
|
+
return (rt.lastLimit = { ...found, at: new Date(t).toISOString(), resumedAt: null });
|
|
3497
|
+
}
|
|
3498
|
+
|
|
3499
|
+
/**
|
|
3500
|
+
* Agents stopped at a limit get "continue" once it resets (a busy service: a few minutes on),
|
|
3501
|
+
* at most three times an hour each. config.json "limits": { "autoResume": false } turns it off.
|
|
3502
|
+
*/
|
|
3503
|
+
resumeLimited(t = Date.now()) {
|
|
3504
|
+
if (this.config.limits?.autoResume === false) return;
|
|
3505
|
+
for (const [id, rt] of this.runtimes) {
|
|
3506
|
+
const l = rt.limited;
|
|
3507
|
+
if (!rt.pty || rt.busy || !l?.resetAt || l.resumedAt || t < Date.parse(l.resetAt) + (l.kind === 'limit' ? 60_000 : 0)) continue;
|
|
3508
|
+
rt.limitResumes = (rt.limitResumes ?? []).filter((x) => t - x < 3_600_000);
|
|
3509
|
+
if (rt.limitResumes.length >= 3) continue;
|
|
3510
|
+
rt.limitResumes.push(t);
|
|
3511
|
+
l.resumedAt = new Date(t).toISOString();
|
|
3512
|
+
try {
|
|
3513
|
+
this.tell(id, 'Continue where you left off.', { source: 'limit' });
|
|
3514
|
+
} catch {}
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
|
|
3518
|
+
/**
|
|
3519
|
+
* Carry an agent's work on with another engine: a new agent in the same folder and branch,
|
|
3520
|
+
* started with the request, the brief and the end of the conversation (a conversation can't
|
|
3521
|
+
* move between engines). The new agent owns the folder from then on; the old one is closed.
|
|
3522
|
+
*/
|
|
3523
|
+
async continueOn(ref, { engine } = {}) {
|
|
3524
|
+
const src = this.mustGet(ref);
|
|
3525
|
+
const target = engineOf(engine);
|
|
3526
|
+
if (target.id === (src.engine ?? DEFAULT_ENGINE)) throw Object.assign(new Error(`${src.name} already runs on ${target.label}`), { status: 400 });
|
|
3527
|
+
if (!installed(target, this.config)) throw Object.assign(new Error(notInstalled(target, this.config)), { status: 409 });
|
|
3528
|
+
if (!src.workdir || src.sharedWith || NO_REPO.has(src.kind)) throw Object.assign(new Error('Only an agent with its own folder can continue on another engine'), { status: 409 });
|
|
3529
|
+
if (this.store.list().some((a) => a.continuesFrom?.agentId === src.id)) {
|
|
3530
|
+
throw Object.assign(new Error(`${src.name} already continues as another agent`), { status: 409 });
|
|
3531
|
+
}
|
|
3532
|
+
const ctx = await this.explainContext(src);
|
|
3533
|
+
const limit = this.runtimes.get(src.id)?.limited?.text ?? null;
|
|
3534
|
+
const intent = continuePrompt({ from: src.name, engineLabel: engineOf(src).label, limit, intent: src.intent, branch: src.branch ?? src.git?.branch, brief: ctx.briefMarkdown, digest: ctx.digest });
|
|
3535
|
+
if (this.runtimes.get(src.id)?.pty) await this.stop(src.id);
|
|
3536
|
+
const ws = { workdir: src.workdir, sourceDir: src.sourceDir, branch: src.branch, worktree: src.worktree, repo: src.repo, baseRef: src.baseRef };
|
|
3537
|
+
const permissionMode = target.permissionModes.includes(src.permissionMode) ? src.permissionMode : undefined;
|
|
3538
|
+
const name = `${src.name.replace(/-(claude|codex|antigravity|muse|acp-[\w-]+)$/, '')}-${target.id}`;
|
|
3539
|
+
const agent = this.create({ intent, name, engine: target.id, permissionMode, project: src.project ?? undefined, priority: src.priority, start: true, workspace: async () => ws });
|
|
3540
|
+
// The folder is the new agent's now: deleting the old one must not take it.
|
|
3541
|
+
this.patch(src.id, { sharedWith: agent.id, worktree: false, continuedOn: { agentId: agent.id, name: agent.name, engine: target.id, label: target.label, at: now() } });
|
|
3542
|
+
this.patch(agent.id, { continuesFrom: { agentId: src.id, name: src.name, engine: engineOf(src).id, label: engineOf(src).label, at: now() } });
|
|
3543
|
+
this.plugins.emit('agent.continued', { from: this.auditView(this.store.get(src.id)), to: this.auditView(this.store.get(agent.id)) });
|
|
3544
|
+
return this.view(this.store.get(agent.id));
|
|
3545
|
+
}
|
|
3546
|
+
|
|
3473
3547
|
tick() {
|
|
3474
3548
|
this.tickCount++;
|
|
3475
3549
|
const t = Date.now();
|
|
@@ -3480,18 +3554,21 @@ export class AgentManager extends EventEmitter {
|
|
|
3480
3554
|
const a0 = this.store.get(id);
|
|
3481
3555
|
rt.attention = (a0 ? engineOf(a0).attention : []).find(([re]) => re.test(screen))?.[1] ?? null;
|
|
3482
3556
|
if (a0 && rt.attention === PERMISSION) this.autoAllow(a0, rt);
|
|
3557
|
+
// Stopped at a usage limit or a busy service: shown, and resumed when it resets.
|
|
3558
|
+
rt.limited = a0 && !rt.attention ? this.limitOf(id, rt, t) : null;
|
|
3483
3559
|
const a = this.store.get(id);
|
|
3484
3560
|
if (a) this.changed(a);
|
|
3485
3561
|
// A turn just ended: remember the code and conversation at this point.
|
|
3486
3562
|
if (a && !rt.planning && !rt.attention) this.checkpoint(id).catch(() => {});
|
|
3487
3563
|
}
|
|
3488
3564
|
}
|
|
3565
|
+
this.resumeLimited(t);
|
|
3489
3566
|
this.deliverOutbox(t);
|
|
3490
3567
|
this.scanSignIns();
|
|
3491
3568
|
if (this.judge.enabled) {
|
|
3492
3569
|
const idleMs = this.judge.settings.idleSec * 1000;
|
|
3493
3570
|
for (const [id, rt] of this.runtimes) {
|
|
3494
|
-
if (!rt.pty || rt.busy || rt.attention || rt.planning || rt.screenChecked || this.outbox.get(id)?.length) continue;
|
|
3571
|
+
if (!rt.pty || rt.busy || rt.attention || rt.limited || rt.planning || rt.screenChecked || this.outbox.get(id)?.length) continue;
|
|
3495
3572
|
// A team member that finished its step is meant to sit idle until its next turn.
|
|
3496
3573
|
if (this.idleExpected?.(id)) continue;
|
|
3497
3574
|
if (!rt.lastOutputAt || t - rt.lastOutputAt < idleMs) continue;
|
package/src/reminders.js
CHANGED
|
@@ -51,8 +51,8 @@ export function reminderFor(v, settings, t = Date.now()) {
|
|
|
51
51
|
return { kind: 'followup', title: `Quiet for ${hours(quiet)} and not finished`, detail, since };
|
|
52
52
|
}
|
|
53
53
|
// Closed: only when it closed by itself or was closed for you (session cap, clean up).
|
|
54
|
-
const byItself = v.status === 'exited' || v.closedBy === 'cap' || v.closedBy === 'cleanup';
|
|
54
|
+
const byItself = v.status === 'exited' || v.closedBy === 'cap' || v.closedBy === 'idle' || v.closedBy === 'cleanup';
|
|
55
55
|
if (done || !byItself || !v.sessionId) return null;
|
|
56
|
-
const how = v.closedBy === 'cap' ? 'closed by the session cap' : v.closedBy === 'cleanup' ? 'closed by clean up' : 'its session ended';
|
|
56
|
+
const how = v.closedBy === 'cap' ? 'closed by the session cap' : v.closedBy === 'idle' ? 'closed after being idle' : v.closedBy === 'cleanup' ? 'closed by clean up' : 'its session ended';
|
|
57
57
|
return { kind: 'followup', title: `Not finished, and ${how}`, detail: outcome === 'blocked' && v.results?.blockers?.[0]?.text ? `Blocked: ${v.results.blockers[0].text}` : null, since, closed: true };
|
|
58
58
|
}
|
package/src/rules.js
CHANGED
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
// ("npm test", three times), the inbox offers to always allow it there. Allowed rules go to every
|
|
3
3
|
// agent in that repo at launch (Claude Code's --allowedTools) and answer its live prompts, so the
|
|
4
4
|
// same question isn't asked again. Kept in ~/.agentmanager/rules.json, per repo (the repo-memory key).
|
|
5
|
+
// A rule allowed in two or more repos is offered for every repo ("*"), and a few read-only
|
|
6
|
+
// commands never ask anywhere (config.json "rules": { "readOnly": false } turns that off).
|
|
5
7
|
import { EventEmitter } from 'node:events';
|
|
6
8
|
import fs from 'node:fs';
|
|
7
9
|
import path from 'node:path';
|
|
8
10
|
import { paths } from './config.js';
|
|
9
11
|
|
|
10
12
|
export const SUGGEST_AFTER = 3;
|
|
13
|
+
export const EVERY_REPO = '*';
|
|
14
|
+
// Repos that allow the same rule before it is offered for every repo.
|
|
15
|
+
const SUGGEST_EVERYWHERE_AFTER = 2;
|
|
16
|
+
// Commands that only look: allowed in every repo from the start.
|
|
17
|
+
export const READ_ONLY = ['ls', 'pwd', 'wc', 'git status', 'git diff', 'git log', 'git show', 'git blame', 'git rev-parse'].map((c) => `Bash(${c}:*)`);
|
|
11
18
|
// Commands whose first words name a subcommand: "npm test" is a rule, "npm" alone would allow anything npm does.
|
|
12
19
|
const SUBCOMMANDS = new Set(['npm', 'pnpm', 'yarn', 'bun', 'npx', 'node', 'deno', 'git', 'gh', 'cargo', 'go', 'make', 'python', 'python3', 'uv', 'pip', 'poetry', 'pytest', 'mvn', 'gradle', './gradlew', 'dotnet', 'swift', 'xcodebuild', 'bundle', 'rake', 'rails', 'mix', 'composer', 'php', 'docker', 'kubectl', 'terraform', 'just', 'task']);
|
|
13
20
|
// Never offered as a standing rule, however often approved: they delete, escalate, publish or reach out.
|
|
@@ -69,16 +76,18 @@ export function describeTool(tool) {
|
|
|
69
76
|
}
|
|
70
77
|
|
|
71
78
|
export class Rules extends EventEmitter {
|
|
72
|
-
constructor({ file = path.join(paths.home, 'rules.json'), suggestAfter = SUGGEST_AFTER } = {}) {
|
|
79
|
+
constructor({ file = path.join(paths.home, 'rules.json'), suggestAfter = SUGGEST_AFTER, readOnly = true } = {}) {
|
|
73
80
|
super();
|
|
74
81
|
this.file = file;
|
|
75
82
|
this.suggestAfter = suggestAfter;
|
|
83
|
+
this.readOnly = readOnly !== false;
|
|
76
84
|
try {
|
|
77
85
|
this.data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
78
86
|
} catch {
|
|
79
87
|
this.data = {};
|
|
80
88
|
}
|
|
81
89
|
this.data.repos ??= {};
|
|
90
|
+
this.data.everywhere ??= { allow: [], dismissed: [] };
|
|
82
91
|
}
|
|
83
92
|
|
|
84
93
|
save() {
|
|
@@ -91,9 +100,16 @@ export class Rules extends EventEmitter {
|
|
|
91
100
|
return (this.data.repos[key] ??= { allow: [], dismissed: [], seen: {} });
|
|
92
101
|
}
|
|
93
102
|
|
|
94
|
-
/**
|
|
103
|
+
/** Where a repo key's rules live: a repo, or every repo. */
|
|
104
|
+
scope(key) {
|
|
105
|
+
return key === EVERY_REPO ? this.data.everywhere : this.data.repos[key];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The rules allowed in a repo (its own, every repo's, the read-only ones), as Claude Code allow rules. */
|
|
95
109
|
allowed(key) {
|
|
96
|
-
|
|
110
|
+
const own = (this.data.repos[key]?.allow ?? []).map((r) => r.rule);
|
|
111
|
+
const all = this.data.everywhere.allow.map((r) => r.rule);
|
|
112
|
+
return [...new Set([...own, ...all, ...(this.readOnly ? READ_ONLY : [])])];
|
|
97
113
|
}
|
|
98
114
|
|
|
99
115
|
/** The allowed rule that covers this call in this repo, if any. */
|
|
@@ -103,7 +119,7 @@ export class Rules extends EventEmitter {
|
|
|
103
119
|
|
|
104
120
|
/** An allowed rule answered a prompt by itself: count it, so the list shows what it saves. */
|
|
105
121
|
used(key, rule) {
|
|
106
|
-
const a = this.data.repos[key]?.allow.find((x) => x.rule === rule);
|
|
122
|
+
const a = this.data.repos[key]?.allow.find((x) => x.rule === rule) ?? this.data.everywhere.allow.find((x) => x.rule === rule);
|
|
107
123
|
if (!a) return;
|
|
108
124
|
a.uses = (a.uses ?? 0) + 1;
|
|
109
125
|
a.lastUsedAt = new Date().toISOString();
|
|
@@ -114,8 +130,8 @@ export class Rules extends EventEmitter {
|
|
|
114
130
|
approved(key, tool) {
|
|
115
131
|
const r = ruleFor(tool);
|
|
116
132
|
if (!r) return null;
|
|
133
|
+
if (this.allowed(key).includes(r.rule)) return null;
|
|
117
134
|
const repo = this.repo(key);
|
|
118
|
-
if (repo.allow.some((x) => x.rule === r.rule)) return null;
|
|
119
135
|
const seen = (repo.seen[r.rule] ??= { label: r.label, n: 0 });
|
|
120
136
|
seen.n++;
|
|
121
137
|
seen.at = new Date().toISOString();
|
|
@@ -124,6 +140,20 @@ export class Rules extends EventEmitter {
|
|
|
124
140
|
}
|
|
125
141
|
|
|
126
142
|
accept(key, rule) {
|
|
143
|
+
if (key === EVERY_REPO) {
|
|
144
|
+
const e = this.data.everywhere;
|
|
145
|
+
const from = Object.values(this.data.repos).flatMap((r) => r.allow).find((x) => x.rule === rule);
|
|
146
|
+
if (!from && !e.allow.some((x) => x.rule === rule)) throw Object.assign(new Error('No such suggestion'), { status: 404 });
|
|
147
|
+
if (!e.allow.some((x) => x.rule === rule)) e.allow.push({ rule, label: from.label, at: new Date().toISOString(), uses: 0 });
|
|
148
|
+
// One rule for every repo replaces the repos' own copies (their uses carry over).
|
|
149
|
+
for (const r of Object.values(this.data.repos)) {
|
|
150
|
+
const own = r.allow.find((x) => x.rule === rule);
|
|
151
|
+
if (own) e.allow.find((x) => x.rule === rule).uses += own.uses ?? 0;
|
|
152
|
+
r.allow = r.allow.filter((x) => x.rule !== rule);
|
|
153
|
+
}
|
|
154
|
+
this.save();
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
127
157
|
const repo = this.data.repos[key];
|
|
128
158
|
const seen = repo?.seen[rule];
|
|
129
159
|
if (!seen && !repo?.allow.some((x) => x.rule === rule)) throw Object.assign(new Error('No such suggestion'), { status: 404 });
|
|
@@ -134,6 +164,12 @@ export class Rules extends EventEmitter {
|
|
|
134
164
|
|
|
135
165
|
/** "Not now": stop suggesting it (it can still be allowed later from the list). */
|
|
136
166
|
dismiss(key, rule) {
|
|
167
|
+
if (key === EVERY_REPO) {
|
|
168
|
+
if (!this.view().suggestions.some((s) => s.repo === EVERY_REPO && s.rule === rule)) throw Object.assign(new Error('No such suggestion'), { status: 404 });
|
|
169
|
+
this.data.everywhere.dismissed.push(rule);
|
|
170
|
+
this.save();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
137
173
|
const repo = this.data.repos[key];
|
|
138
174
|
if (!repo?.seen[rule]) throw Object.assign(new Error('No such suggestion'), { status: 404 });
|
|
139
175
|
if (!repo.dismissed.includes(rule)) repo.dismissed.push(rule);
|
|
@@ -141,7 +177,7 @@ export class Rules extends EventEmitter {
|
|
|
141
177
|
}
|
|
142
178
|
|
|
143
179
|
remove(key, rule) {
|
|
144
|
-
const repo = this.
|
|
180
|
+
const repo = this.scope(key);
|
|
145
181
|
if (!repo?.allow.some((x) => x.rule === rule)) throw Object.assign(new Error('No such rule'), { status: 404 });
|
|
146
182
|
repo.allow = repo.allow.filter((x) => x.rule !== rule);
|
|
147
183
|
repo.dismissed = repo.dismissed.filter((x) => x !== rule);
|
|
@@ -156,6 +192,15 @@ export class Rules extends EventEmitter {
|
|
|
156
192
|
for (const a of r.allow) allowed.push({ repo, ...a });
|
|
157
193
|
for (const [rule, s] of Object.entries(r.seen)) if (s.n >= this.suggestAfter && !r.dismissed.includes(rule)) suggestions.push({ repo, rule, label: s.label, n: s.n, at: s.at });
|
|
158
194
|
}
|
|
159
|
-
|
|
195
|
+
// Allowed in several repos: offer it for every repo.
|
|
196
|
+
const repos = new Map();
|
|
197
|
+
for (const a of allowed) repos.set(a.rule, [...(repos.get(a.rule) ?? []), a]);
|
|
198
|
+
for (const [rule, list] of repos) {
|
|
199
|
+
if (list.length >= SUGGEST_EVERYWHERE_AFTER && !this.data.everywhere.dismissed.includes(rule)) {
|
|
200
|
+
suggestions.push({ repo: EVERY_REPO, rule, label: list[0].label, n: list.length, everywhere: true, at: list.map((x) => x.at).sort().at(-1) });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
for (const a of this.data.everywhere.allow) allowed.push({ repo: EVERY_REPO, ...a });
|
|
204
|
+
return { allowed, suggestions, suggestAfter: this.suggestAfter, readOnly: this.readOnly ? READ_ONLY.map((r) => r.slice(5, -3)) : [] };
|
|
160
205
|
}
|
|
161
206
|
}
|
package/src/server.js
CHANGED
|
@@ -699,6 +699,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
699
699
|
return { url: r.url ?? null, title };
|
|
700
700
|
}));
|
|
701
701
|
api.post('/agents/:id/fork', wrap((req) => manager.fork(req.params.id, req.body ?? {})));
|
|
702
|
+
api.post('/agents/:id/continue-on', wrap((req) => manager.continueOn(req.params.id, { engine: req.body?.engine })));
|
|
702
703
|
|
|
703
704
|
api.get('/races', wrap(() => races.list()));
|
|
704
705
|
// Attachments: copied once to a shared folder and listed in the request every attempt gets.
|