ai-agentmanager 1.61.0 → 1.63.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/src/server.js CHANGED
@@ -22,6 +22,7 @@ import { Screen } from './screen.js';
22
22
  import { Awake } from './awake.js';
23
23
  import { Files } from './files.js';
24
24
  import { Announcer } from './announce.js';
25
+ import { Autonomy, LEVELS as AUTONOMY_LEVELS, parseLevel } from './autonomy.js';
25
26
  import { Autopilot } from './autopilot.js';
26
27
  import { Goals, goalMarkdown } from './goals.js';
27
28
  import { Budgets } from './budgets.js';
@@ -124,6 +125,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
124
125
  // ACP agents (Gemini CLI, OpenCode, Goose, … and config's "acp") become engines.
125
126
  registerAcpEngines(config);
126
127
  const manager = new AgentManager({ store, config, plugins });
128
+ manager.setMaxListeners(40); // each feature below listens for changes
127
129
  const localModels = new LocalModels({ config, save: saveConfig });
128
130
  localModels.view().catch(() => {});
129
131
  const backlog = new Backlog({ manager, store, config });
@@ -234,12 +236,20 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
234
236
  manager,
235
237
  config,
236
238
  ship: shipAgent,
237
- managed: (id) => backlog.items().some((it) => it.agentId === id && ['active', 'review'].includes(it.status) && backlog.autopilotFor(it.projectKey) !== 'off'),
239
+ managed: (id) => backlog.items().some((it) => it.agentId === id && ['active', 'review'].includes(it.status) && backlog.levelFor(it) !== 'off'),
238
240
  log: (m) => console.log(`[agentmgr] ${m}`),
239
241
  });
240
242
  // Backlog work the scorecard calls ready goes on to a pull request (and merged) by itself.
241
243
  const autopilot = new Autopilot({ manager, store, backlog, review, landing, config });
242
244
  manager.inboxSources.push(() => autopilot.inbox());
245
+ // Agents that run without you (autonomy.js): routine questions answered from what is decided,
246
+ // nudges and follow-ups sent, and at "merge" the pull request merged when everything says ready.
247
+ const autonomy = new Autonomy({ manager, store, config, review, landing, backlog });
248
+ manager.inboxSources.push(() => autonomy.inbox());
249
+ // How far an agent goes without the person is the person's to set: never an agent's own call.
250
+ const yourLevel = (req) => {
251
+ if (req.headers['x-agentmgr-agent']) throw fail(403, 'How far an agent goes without the person is set by the person, not by an agent');
252
+ };
243
253
  // Daily or weekly goals across projects, planned into backlog tasks and seen through (goals.js).
244
254
  const goals = new Goals({ manager, store, backlog, config });
245
255
  // What agents got done, appended to a CSV for reviews (worklog.js).
@@ -278,7 +288,11 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
278
288
  const cur = store.get(id);
279
289
  if (!cur?.docs?.update?.markdown) return;
280
290
  manager.patch(id, { announce: { ...cur.announce, auto: { milestone, at: new Date().toISOString() }, sent: {}, dismissedAt: null } });
281
- notifier.send('announce', manager.get(id), `${milestone === 'done' ? 'is finished' : 'opened a pull request'}: an update for the people who asked is ready for you to send`);
291
+ // Its statements are checked against the work before you are told it is ready (claims.js).
292
+ if (config.claims?.auto !== false) await manager.summarize(id, 'claims').catch((e) => console.log(`[agentmgr] claims check for ${cur.name}: ${e.message.slice(0, 160)}`));
293
+ const checked = store.get(id)?.docs?.claims?.data?.texts.find((t) => t.key === 'update' && t.at === store.get(id).docs.update?.at && !t.error);
294
+ const doubt = checked ? checked.counts.contradicted + checked.counts.not_backed + checked.missing.length : 0;
295
+ notifier.send('announce', manager.get(id), `${milestone === 'done' ? 'is finished' : 'opened a pull request'}: an update for the people who asked is ready for you to send${doubt ? ` (${doubt} of its statements ${doubt === 1 ? 'is' : 'are'} not backed by the work: see Claims)` : ''}`);
282
296
  },
283
297
  });
284
298
  // Awake (awake.js): the computer kept from sleeping, always or while an agent works.
@@ -352,7 +366,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
352
366
  return {
353
367
  working: views.filter((v) => ['planning', 'working', 'blocked'].includes(v.brief?.status) || (v.runtime.running && v.brief?.status !== 'done')),
354
368
  backlog: backlog.view().items.filter((it) => it.projectKey === p.key && ['queued', 'active', 'review', 'blocked'].includes(it.status)),
355
- waiting: views.filter((v) => v.runtime.attention || v.runtime.waiting || v.planReview?.status === 'review' || (v.questions ?? []).some((q) => !q.answer)),
369
+ waiting: views.filter((v) => v.runtime.attention || v.runtime.waiting || v.planReview?.status === 'review' || (v.acceptance?.status === 'review' && v.acceptance.wait) || (v.questions ?? []).some((q) => !q.answer)),
356
370
  prs,
357
371
  failing: prs.filter((x) => x.checks?.state === 'failed'),
358
372
  bugs: openFindings(p).filter((f) => ['critical', 'high'].includes(f.severity)),
@@ -385,6 +399,11 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
385
399
  questions: (a) => (NO_REPO.has(a.kind) ? [] : loadQuestions(a.id)),
386
400
  bugs: (key) => hunts.list().findings.filter((f) => ['open', 'fixing', 'pr'].includes(f.status) && ['critical', 'high'].includes(f.severity) && manager.resolveProject(f.project)?.key === key).length,
387
401
  enabled: () => config.decide?.enabled !== false,
402
+ // Agents that run without you (autonomy.js): "most things" may be decided for them, never what cannot be taken back.
403
+ autonomous: (id) => autonomy.autonomous(id),
404
+ guard: (item) => (autonomy.autonomous(item.agentId) ? autonomy.guard(item) : null),
405
+ context: (item) => autonomy.briefContext(item),
406
+ onAuto: (h) => autonomy.decided(h),
388
407
  onChange: () => pushAdvisor(),
389
408
  notify: async (text, plain) => {
390
409
  const n = loadNotify();
@@ -581,6 +600,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
581
600
  wrap((req) => {
582
601
  const { intents, intent, startedBy, ...opts } = req.body ?? {};
583
602
  if (opts.kind === 'assistant') throw fail(400, 'Start the assistant with POST /assistant/start');
603
+ if (opts.autonomy) yourLevel(req);
584
604
  const list = (Array.isArray(intents) ? intents : [intent]).map((i) => String(i ?? '').trim()).filter(Boolean);
585
605
  // Agents the assistant's own session starts: its limits apply, and they are marked as its.
586
606
  const extra = assistant.admit(req.headers['x-agentmgr-agent'], list, opts);
@@ -623,6 +643,14 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
623
643
  saveNotify({ announce: { webhookUrl: url || null } });
624
644
  return announceView();
625
645
  }));
646
+ // Claims check: whether an update written by itself is checked by itself too.
647
+ api.get('/claims/settings', wrap(() => ({ auto: config.claims?.auto !== false })));
648
+ api.put('/claims/settings', wrap((req) => {
649
+ if (typeof req.body?.auto !== 'boolean') throw fail(400, 'auto is true or false');
650
+ config.claims = { ...config.claims, auto: req.body.auto };
651
+ saveConfig({ claims: config.claims });
652
+ return { auto: config.claims.auto };
653
+ }));
626
654
  api.put('/agents/:id/announce', wrap((req) => manager.updateState(req.params.id, req.body ?? {})));
627
655
  api.post('/agents/:id/announce/publish', wrap((req) => manager.publishUpdate(req.params.id)));
628
656
  api.post('/agents/:id/announce/slack', wrap(async (req) => {
@@ -660,6 +688,32 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
660
688
  api.post('/agents/:id/plan/approve', wrap((req) => manager.approvePlan(req.params.id, req.body?.note)));
661
689
  api.post('/agents/:id/plan/changes', wrap((req) => manager.requestPlanChanges(req.params.id, req.body?.note)));
662
690
  api.post('/agents/:id/plan/review', wrap((req) => manager.setPlanReview(req.params.id, req.body?.on === true)));
691
+ // Acceptance: what done means, agreed with the person; the scorecard checks each point (acceptance.js).
692
+ api.get('/agents/:id/acceptance', wrap((req) => manager.acceptanceOf(req.params.id)));
693
+ // The points are the person's to agree on: an agent's own calls can read them, not set or skip them.
694
+ const person = (req) => {
695
+ if (req.headers['x-agentmgr-agent']) throw fail(403, 'What done means is agreed by the person, not by an agent');
696
+ };
697
+ api.post('/agents/:id/acceptance/agree', wrap((req) => (person(req), manager.agreeAcceptance(req.params.id, req.body?.points))));
698
+ api.post('/agents/:id/acceptance/skip', wrap((req) => (person(req), manager.skipAcceptance(req.params.id))));
699
+ // Autonomy (autonomy.js): the default level and the models its calls run on; one agent's level;
700
+ // and what was done for the person: seen ("ack"), or an answer changed to their own ("correct").
701
+ api.get('/autonomy', wrap(() => autonomy.status()));
702
+ api.put('/autonomy', wrap((req) => {
703
+ yourLevel(req);
704
+ saveConfig({ autonomy: autonomy.change(req.body ?? {}) });
705
+ return autonomy.status();
706
+ }));
707
+ api.post('/agents/:id/autonomy', wrap((req) => (yourLevel(req), autonomy.setLevel(req.params.id, req.body?.level))));
708
+ api.post('/agents/:id/autonomy/ack', wrap((req) => (yourLevel(req), autonomy.ack(req.params.id, String(req.body?.entry ?? '')))));
709
+ api.post('/agents/:id/autonomy/correct', wrap((req) => (yourLevel(req), autonomy.correct(req.params.id, String(req.body?.entry ?? ''), req.body?.text))));
710
+ // Ground rules: the person's own rules for every session (groundrules.js). Agents can read them, not change them.
711
+ api.get('/ground-rules', wrap(() => manager.groundRules.view()));
712
+ api.put('/ground-rules', wrap((req) => {
713
+ if (req.headers['x-agentmgr-agent']) throw fail(403, 'Ground rules are set by the person, not by an agent');
714
+ const b = req.body ?? {};
715
+ return manager.setGroundRules(b.rules ?? b.text ?? '', { tell: b.tell === true });
716
+ }));
663
717
  api.post('/agents/:id/handoff', wrap((req) => manager.maybeHandoff(manager.mustGet(req.params.id).id, { force: true })));
664
718
  // ---------------------------------------------------------- studio: files and editor
665
719
  api.get('/agents/:id/files', wrap((req) => studio.list(req.params.id, req.query.dir ?? '')));
@@ -730,7 +784,10 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
730
784
  return agent;
731
785
  }),
732
786
  );
733
- api.patch('/agents/:id', wrap((req) => manager.update(req.params.id, req.body ?? {})));
787
+ api.patch('/agents/:id', wrap((req) => {
788
+ if ('autonomy' in (req.body ?? {})) yourLevel(req);
789
+ return manager.update(req.params.id, req.body ?? {});
790
+ }));
734
791
  api.post('/agents/:id/browsers', wrap((req) => manager.addBrowser(req.params.id, req.body?.url, { mode: req.body?.mode })));
735
792
  api.patch(
736
793
  '/agents/:id/browsers/:n',
@@ -887,6 +944,11 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
887
944
  '/backlog',
888
945
  wrap((req) => {
889
946
  const { items, item, ...opts } = req.body ?? {};
947
+ if (opts.autonomy) {
948
+ yourLevel(req);
949
+ opts.autonomy = parseLevel(opts.autonomy);
950
+ if (!opts.autonomy) throw fail(400, `autonomy is one of ${AUTONOMY_LEVELS.join(', ')}`);
951
+ }
890
952
  const added = backlog.add(Array.isArray(items) ? items : [item], opts);
891
953
  repeats.record(added.map((it) => ({ text: it.title, projectKey: it.projectKey })));
892
954
  return added;
@@ -2005,6 +2067,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
2005
2067
  benches.close();
2006
2068
  evals.close();
2007
2069
  autopilot.close();
2070
+ autonomy.close();
2008
2071
  goals.close();
2009
2072
  worklog.close();
2010
2073
  triggers.close();
package/src/standup.js CHANGED
@@ -28,6 +28,7 @@ export function needsOf(v) {
28
28
  if (rt.attention) out.push({ kind: 'prompt', text: clip(rt.prompt?.tool?.text ? `${rt.prompt.tool.name} ${rt.prompt.tool.text}` : rt.prompt?.question || rt.attention) });
29
29
  if (rt.waiting) out.push({ kind: 'waiting', text: clip(rt.waiting.summary) });
30
30
  if (v.planReview?.status === 'review') out.push({ kind: 'plan', text: 'its plan is waiting for your review' });
31
+ if (v.acceptance?.status === 'review' && v.acceptance.wait) out.push({ kind: 'acceptance', text: 'what done means is waiting for you to agree' });
31
32
  for (const q of v.questions ?? []) if (!q.answer) out.push({ kind: 'question', text: clip(q.question) });
32
33
  for (const f of v.stuck ?? []) out.push({ kind: 'stuck', text: clip(f.title) });
33
34
  for (const g of v.conflicts ?? []) if (g.mergeFirst !== v.id) out.push({ kind: 'conflict', text: `changes the same files as ${g.agent?.name ?? 'another agent'}` });