ai-agentmanager 1.38.0 → 1.39.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 +9 -0
- package/README.md +5 -1
- package/package.json +1 -1
- package/public/app.js +42 -5
- package/public/index.html +4 -2
- package/public/menu.js +6 -3
- 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,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.39.0 (2026-11-11)
|
|
4
|
+
|
|
5
|
+
- **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.
|
|
6
|
+
- **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.
|
|
7
|
+
- **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.
|
|
8
|
+
- **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.
|
|
9
|
+
- **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.
|
|
10
|
+
- **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.
|
|
11
|
+
|
|
3
12
|
## 1.38.0 (2026-11-11)
|
|
4
13
|
|
|
5
14
|
- **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
|
@@ -1385,11 +1385,23 @@ function flags(a) {
|
|
|
1385
1385
|
}
|
|
1386
1386
|
|
|
1387
1387
|
const TRIAGED = { now: 'sent (AI: urgent)', digest: 'held for the digest', skip: 'dropped by the AI judge' };
|
|
1388
|
-
|
|
1388
|
+
// Engines a limited agent can carry on with (installed ones), loaded once when a limit card shows.
|
|
1389
|
+
let limitEngines = null;
|
|
1390
|
+
function loadLimitEngines() {
|
|
1391
|
+
limitEngines = [];
|
|
1392
|
+
api('GET', '/engines')
|
|
1393
|
+
.then((list) => {
|
|
1394
|
+
limitEngines = list;
|
|
1395
|
+
renderInbox();
|
|
1396
|
+
})
|
|
1397
|
+
.catch(() => (limitEngines = null));
|
|
1398
|
+
}
|
|
1399
|
+
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
1400
|
/** What an agent needs from the user. `both`: overlaps on both agents (detail), else only the one that should rebase (inbox). */
|
|
1390
1401
|
function needsFor(a, { both = false } = {}) {
|
|
1391
1402
|
const items = [];
|
|
1392
1403
|
if (a.runtime.attention) items.push({ a, kind: 'prompt', key: `prompt:${a.id}` });
|
|
1404
|
+
if (a.runtime.limited) items.push({ a, kind: 'limit', key: `limit:${a.id}` });
|
|
1393
1405
|
if (a.runtime.waiting) items.push({ a, kind: 'waiting', key: `waiting:${a.id}` });
|
|
1394
1406
|
if (a.planReview?.status === 'review') items.push({ a, kind: 'plan', key: `plan:${a.id}` });
|
|
1395
1407
|
if (a.aiReview?.verdict && !a.aiReview.seen) items.push({ a, kind: 'review', key: `review:${a.id}` });
|
|
@@ -1411,7 +1423,7 @@ function approvalNeeds() {
|
|
|
1411
1423
|
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
1424
|
}
|
|
1413
1425
|
/** 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('/');
|
|
1426
|
+
const repoLabel = (k) => (k === '*' ? 'every repo' : String(k).replace(/^dir:/, '').split('/').filter(Boolean).slice(-2).join('/'));
|
|
1415
1427
|
/** Commands you keep allowing in a repo, offered as a standing rule. */
|
|
1416
1428
|
function ruleNeeds() {
|
|
1417
1429
|
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 +1443,7 @@ function inboxItems() {
|
|
|
1431
1443
|
.sort((x, y) => NEED_ORDER[x.kind] - NEED_ORDER[y.kind] || (x.a.priority ?? 2) - (y.a.priority ?? 2));
|
|
1432
1444
|
}
|
|
1433
1445
|
|
|
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' };
|
|
1446
|
+
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
1447
|
/** Why the AI judge thinks so, as a small tag. */
|
|
1436
1448
|
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
1449
|
/** What a permission prompt asks about: the command, file or tool. */
|
|
@@ -1486,7 +1498,10 @@ function needCard(it, { inDetail = false } = {}) {
|
|
|
1486
1498
|
<p class="hint">${esc(it.it.autopilot.note ?? '')}</p>
|
|
1487
1499
|
<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
1500
|
} else if (it.kind === 'rule') {
|
|
1489
|
-
body =
|
|
1501
|
+
body = it.r.everywhere
|
|
1502
|
+
? `<p class="need-title">You always allow <code>${esc(it.r.label)}</code> in ${it.r.n} repos. Allow it in every repo?</p>
|
|
1503
|
+
<p class="hint">Agents in any repo won't ask about it again. Remove it any time in Settings → Approval rules.</p>`
|
|
1504
|
+
: `<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
1505
|
<p class="hint">Agents in ${esc(a.name)} won't ask about it again. Remove it any time in Settings → Approval rules.</p>
|
|
1491
1506
|
<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
1507
|
} else if (it.kind === 'prompt') {
|
|
@@ -1497,6 +1512,14 @@ function needCard(it, { inDetail = false } = {}) {
|
|
|
1497
1512
|
<button class="small" data-ib="key" data-key="esc" title="Escape">Esc</button>
|
|
1498
1513
|
<button class="small ghost" data-ib="terminal">Open terminal</button>
|
|
1499
1514
|
</div>`;
|
|
1515
|
+
} else if (it.kind === 'limit') {
|
|
1516
|
+
const l = a.runtime.limited;
|
|
1517
|
+
const when = l.resetAt ? new Date(l.resetAt).toLocaleString([], { weekday: 'short', hour: 'numeric', minute: '2-digit' }) : null;
|
|
1518
|
+
const others = (limitEngines ?? []).filter((e) => e.installed && e.id !== (a.engine ?? 'claude'));
|
|
1519
|
+
if (!limitEngines) loadLimitEngines();
|
|
1520
|
+
body = `<p class="need-title">${esc(l.text)}</p>
|
|
1521
|
+
<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>
|
|
1522
|
+
<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
1523
|
} else if (it.kind === 'waiting') {
|
|
1501
1524
|
const w = a.runtime.waiting;
|
|
1502
1525
|
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 +1707,18 @@ async function onNeed(e) {
|
|
|
1684
1707
|
return act(async () => {
|
|
1685
1708
|
rulesState = await api('POST', `/rules/${accept ? 'accept' : 'dismiss'}`, { repo, rule });
|
|
1686
1709
|
renderInbox();
|
|
1687
|
-
}, accept ? 'Allowed in this repo; agents there won\'t ask again' : 'Won\'t suggest it again');
|
|
1710
|
+
}, 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');
|
|
1711
|
+
}
|
|
1712
|
+
case 'limit-resume':
|
|
1713
|
+
return act(async () => upsert(await api('POST', `/agents/${id}/tell`, { text: 'Continue where you left off.' })), 'Told it to continue');
|
|
1714
|
+
case 'limit-switch': {
|
|
1715
|
+
const label = el.textContent.replace(/^Continue on /, '');
|
|
1716
|
+
return act(async () => {
|
|
1717
|
+
const n = await api('POST', `/agents/${id}/continue-on`, { engine: el.dataset.engine });
|
|
1718
|
+
upsert(n);
|
|
1719
|
+
showTab('agents');
|
|
1720
|
+
select(n.id);
|
|
1721
|
+
}, `Continuing on ${label}`);
|
|
1688
1722
|
}
|
|
1689
1723
|
case 'terminal':
|
|
1690
1724
|
showTab('agents');
|
|
@@ -2222,7 +2256,10 @@ function renderDetail() {
|
|
|
2222
2256
|
${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
2257
|
${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
2258
|
${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>` : ''}
|
|
2259
|
+
${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>` : ''}
|
|
2260
|
+
${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
2261
|
${!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>` : ''}
|
|
2262
|
+
${!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
2263
|
${!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
2264
|
${a.status === 'preparing'
|
|
2228
2265
|
? `<div class="progress-box">
|
package/public/index.html
CHANGED
|
@@ -877,12 +877,14 @@
|
|
|
877
877
|
<fieldset>
|
|
878
878
|
<legend>Open agents</legend>
|
|
879
879
|
<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
|
-
<
|
|
880
|
+
<label class="check">Close sessions idle for <input type="number" name="idleHours" min="1" max="720" placeholder="never" class="num" /> hours</label>
|
|
881
|
+
<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
882
|
</fieldset>
|
|
882
883
|
<fieldset id="settings-rules">
|
|
883
884
|
<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>
|
|
885
|
+
<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
886
|
<ul id="settings-rules-list" class="rules-list"></ul>
|
|
887
|
+
<p class="hint" id="settings-rules-readonly"></p>
|
|
886
888
|
</fieldset>
|
|
887
889
|
<fieldset class="local-only" id="settings-service">
|
|
888
890
|
<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/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.
|