ai-agentmanager 1.57.3 → 1.59.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 +21 -0
- package/README.md +53 -4
- package/docs/architecture.md +4 -1
- package/package.json +1 -1
- package/public/announce.js +134 -0
- package/public/app.js +98 -11
- package/public/files.js +105 -0
- package/public/index.html +45 -3
- package/public/keys.js +1 -0
- package/public/palette.js +122 -0
- package/public/screen.js +231 -13
- package/public/setup.js +1 -1
- package/public/style.css +42 -0
- package/src/announce.js +140 -0
- package/src/awake.js +75 -0
- package/src/cli.js +77 -2
- package/src/files.js +80 -0
- package/src/manager.js +72 -0
- package/src/notify.js +90 -8
- package/src/screen.js +60 -3
- package/src/server.js +101 -12
package/src/server.js
CHANGED
|
@@ -19,6 +19,9 @@ import { Cleanup } from './cleanup.js';
|
|
|
19
19
|
import { Landing } from './landing.js';
|
|
20
20
|
import { PreReview } from './prereview.js';
|
|
21
21
|
import { Screen } from './screen.js';
|
|
22
|
+
import { Awake } from './awake.js';
|
|
23
|
+
import { Files } from './files.js';
|
|
24
|
+
import { Announcer } from './announce.js';
|
|
22
25
|
import { Autopilot } from './autopilot.js';
|
|
23
26
|
import { Goals, goalMarkdown } from './goals.js';
|
|
24
27
|
import { Budgets } from './budgets.js';
|
|
@@ -37,7 +40,7 @@ import { installed, listEngines, localEngineId, registerAcpEngines, registerEngi
|
|
|
37
40
|
import { LOCAL_ENGINES } from './engines/local.js';
|
|
38
41
|
import { Plugins, pluginSpecs } from './plugins.js';
|
|
39
42
|
import { HubLink, linkUrls } from './hublink.js';
|
|
40
|
-
import { Notifier, isWorkflowUrl, loadNotify, publicNotify, saveNotify, sendSlack } from './notify.js';
|
|
43
|
+
import { Notifier, isWorkflowUrl, loadNotify, newTopic, publicNotify, saveNotify, sendAlert, sendSlack, announceSlack } from './notify.js';
|
|
41
44
|
import { Previews, parseUrl } from './preview.js';
|
|
42
45
|
import { LiveBrowser } from './livebrowser.js';
|
|
43
46
|
import * as remote from './remote.js';
|
|
@@ -105,7 +108,7 @@ function isAllowedOrigin(origin, port) {
|
|
|
105
108
|
const PUBLIC_REMOTE_API = new Set(['POST /api/login', 'GET /api/session']);
|
|
106
109
|
// Updates are not here: a signed-in device (a phone) can install the newest release too. It only
|
|
107
110
|
// ever installs an official release from where this copy came from (git tag or npm) and restarts.
|
|
108
|
-
const LOCAL_ONLY_API = /^\/api\/(remote(\/|$)|notify(\/|$)|hub(\/|$)|triggers(\/|$)|service$|jira(\/check)?$|isolation\/|screen\/settings$|editors$|agentkit\/connect$|agents\/[\w-]+\/open-in$|local-models\/settings$|shutdown$)/;
|
|
111
|
+
const LOCAL_ONLY_API = /^\/api\/(remote(\/|$)|notify(\/|$)|hub(\/|$)|triggers(\/|$)|service$|jira(\/check)?$|isolation\/|screen\/settings$|announce\/slack$|editors$|agentkit\/connect$|agents\/[\w-]+\/open-in$|local-models\/settings$|shutdown$)/;
|
|
109
112
|
const HOOK_PATH = '/api/hooks/agents';
|
|
110
113
|
const REPORT_PATH = '/api/agentkit/report';
|
|
111
114
|
const NO_REPO_KINDS = new Set(['general', 'assistant']);
|
|
@@ -262,6 +265,22 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
262
265
|
return `${kind ? (/^[AEIOU]/i.test(kind) ? `an ${kind}` : `a ${kind}`) : 'a signed-in device'}${req.device?.ip ? ` (${String(req.device.ip).replace(/^::ffff:/, '')})` : ''}`;
|
|
263
266
|
};
|
|
264
267
|
const screen = new Screen({ config, onChange: (viewers) => pushScreen(viewers), log: (m) => console.log(`[agentmgr] ${m}`) });
|
|
268
|
+
// Announce (announce.js): when an agent finishes or opens a pull request, what to tell the people
|
|
269
|
+
// who asked is written and waits for you to send; the alert says it is ready.
|
|
270
|
+
const announcer = new Announcer({
|
|
271
|
+
manager,
|
|
272
|
+
config,
|
|
273
|
+
log: (m) => console.log(`[agentmgr] ${m}`),
|
|
274
|
+
prepare: async (id, milestone) => {
|
|
275
|
+
await manager.summarize(id, 'update');
|
|
276
|
+
const cur = store.get(id);
|
|
277
|
+
if (!cur?.docs?.update?.markdown) return;
|
|
278
|
+
manager.patch(id, { announce: { ...cur.announce, auto: { milestone, at: new Date().toISOString() }, sent: {}, dismissedAt: null } });
|
|
279
|
+
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`);
|
|
280
|
+
},
|
|
281
|
+
});
|
|
282
|
+
// Awake (awake.js): the computer kept from sleeping, always or while an agent works.
|
|
283
|
+
const awake = new Awake({ config, working: () => manager.list().some((a) => a.runtime?.busy), log: (m) => console.log(`[agentmgr] ${m}`) });
|
|
265
284
|
const standup = new Standup({
|
|
266
285
|
manager,
|
|
267
286
|
store,
|
|
@@ -274,7 +293,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
274
293
|
const link = `${phone ? phone.url : `http://127.0.0.1:${port}/`}#standup`;
|
|
275
294
|
const need = latest.items.filter((i) => i.needs).length;
|
|
276
295
|
const what = `${latest.items.length} agent${latest.items.length === 1 ? '' : 's'} with news${need ? `, ${need} need you` : ''}`;
|
|
277
|
-
|
|
296
|
+
sendAlert(`:sunrise: *Standup ready*: ${what}\n<${link}|Play it>`, n, `Standup ready: ${what}\nPlay it: ${link}`).catch(() => {});
|
|
278
297
|
},
|
|
279
298
|
});
|
|
280
299
|
// Value: what delivered work is worth, by day, week, month and quarter, with scheduled reports (value.js).
|
|
@@ -287,11 +306,11 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
287
306
|
onChange: () => pushValue(),
|
|
288
307
|
notify: async (period, s) => {
|
|
289
308
|
const n = loadNotify();
|
|
290
|
-
if (!n.enabled || !n.events.value) throw new Error('
|
|
309
|
+
if (!n.enabled || !n.events.value) throw new Error('Alerts are off');
|
|
291
310
|
const phone = remoteServer ? remote.remoteUrls(remotePort).find((u) => !u.vpn) : null;
|
|
292
311
|
const link = `${phone ? phone.url : `http://127.0.0.1:${port}/`}#value`;
|
|
293
312
|
const msg = valueSlack(period, s, link);
|
|
294
|
-
await
|
|
313
|
+
await sendAlert(msg.text, n, msg.plain);
|
|
295
314
|
},
|
|
296
315
|
publishDrive: async (title, markdown) => {
|
|
297
316
|
const st = store.data.value;
|
|
@@ -335,7 +354,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
335
354
|
notify: async (text, plain) => {
|
|
336
355
|
const n = loadNotify();
|
|
337
356
|
if (!n.enabled || !n.events.milestone) return;
|
|
338
|
-
await
|
|
357
|
+
await sendAlert(text, n, plain);
|
|
339
358
|
},
|
|
340
359
|
});
|
|
341
360
|
const decisions = new Decisions({
|
|
@@ -363,7 +382,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
363
382
|
notify: async (text, plain) => {
|
|
364
383
|
const n = loadNotify();
|
|
365
384
|
if (!n.enabled || !n.events.decided) return;
|
|
366
|
-
await
|
|
385
|
+
await sendAlert(text, n, plain);
|
|
367
386
|
},
|
|
368
387
|
});
|
|
369
388
|
// Usage: each engine's plan limits, used and left (usage.js).
|
|
@@ -378,7 +397,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
378
397
|
notify: async (text, plain) => {
|
|
379
398
|
const n = loadNotify();
|
|
380
399
|
if (!n.enabled || !n.events.usage) return;
|
|
381
|
-
await
|
|
400
|
+
await sendAlert(text, n, plain);
|
|
382
401
|
},
|
|
383
402
|
});
|
|
384
403
|
manager.on('usage', ({ engine, limits, at }) => engine === 'codex' && usage.record('codex', codexWindows(limits, Date.parse(at) || Date.now()), { at: at ?? undefined, source: 'Codex session log' }));
|
|
@@ -583,6 +602,29 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
583
602
|
return manager.document(req.params.id, req.params.kind);
|
|
584
603
|
}),
|
|
585
604
|
);
|
|
605
|
+
// An update for the people who asked: its link and recipients, what was sent, and the posting itself.
|
|
606
|
+
const announceView = () => ({ ...announcer.settings, slack: announceSlack()?.where ?? null, webhookUrl: publicNotify().announce.webhookUrl });
|
|
607
|
+
api.get('/announce/settings', wrap(() => announceView()));
|
|
608
|
+
api.put('/announce/settings', wrap((req) => {
|
|
609
|
+
saveConfig({ announce: announcer.change(req.body ?? {}) });
|
|
610
|
+
return announceView();
|
|
611
|
+
}));
|
|
612
|
+
// Where they are posted is a way out of this computer: set here only (local only, like the alerts).
|
|
613
|
+
api.put('/announce/slack', wrap((req) => {
|
|
614
|
+
const url = String(req.body?.webhookUrl ?? '').trim();
|
|
615
|
+
if (url && !okUrl(url)) throw fail(400, 'The webhook URL must be https://…');
|
|
616
|
+
saveNotify({ announce: { webhookUrl: url || null } });
|
|
617
|
+
return announceView();
|
|
618
|
+
}));
|
|
619
|
+
api.put('/agents/:id/announce', wrap((req) => manager.updateState(req.params.id, req.body ?? {})));
|
|
620
|
+
api.post('/agents/:id/announce/publish', wrap((req) => manager.publishUpdate(req.params.id)));
|
|
621
|
+
api.post('/agents/:id/announce/slack', wrap(async (req) => {
|
|
622
|
+
const to = announceSlack();
|
|
623
|
+
if (!to) throw fail(409, 'Slack is not set up: give a webhook for updates (agentmgr announce --webhook <url>), or set up Slack alerts');
|
|
624
|
+
const text = manager.updateSlackText(req.params.id, req.body?.text ?? null);
|
|
625
|
+
await sendSlack(text, to, text);
|
|
626
|
+
return { ...manager.updateState(req.params.id, { sent: 'slack' }), postedTo: to.where };
|
|
627
|
+
}));
|
|
586
628
|
api.get('/agents/:id/specs/:name', wrap((req) => manager.specDoc(req.params.id, req.params.name)));
|
|
587
629
|
// The agent's demo page, sandboxed: no access to this page's origin, and nothing loaded from elsewhere.
|
|
588
630
|
api.get('/agents/:id/demo', (req, res) => {
|
|
@@ -624,6 +666,29 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
624
666
|
// Opening VS Code or Cursor happens on this computer, so only from it.
|
|
625
667
|
api.get('/editors', wrap(() => studio.editors()));
|
|
626
668
|
api.post('/agents/:id/open-in', wrap((req) => studio.openIn(req.params.id, req.body?.editor, req.body?.path ?? null)));
|
|
669
|
+
// Files (files.js): this computer's folders, to send it a file and fetch one. As far as its
|
|
670
|
+
// terminal reaches, and allowed where that is.
|
|
671
|
+
const files = new Files();
|
|
672
|
+
const filesAllowed = () => manager.plugins.check('terminal.open', { agent: null, kind: 'machine' });
|
|
673
|
+
api.get('/machine/files', wrap((req) => (filesAllowed(), files.list(req.query.dir, { hidden: req.query.hidden === '1' }))));
|
|
674
|
+
api.post(
|
|
675
|
+
'/machine/files',
|
|
676
|
+
express.raw({ type: () => true, limit: '250mb' }),
|
|
677
|
+
wrap((req) => {
|
|
678
|
+
filesAllowed();
|
|
679
|
+
if (!Buffer.isBuffer(req.body) || !req.body.length) throw fail(400, 'Empty file');
|
|
680
|
+
return files.save(req.query.name, req.body, req.query.dir || null);
|
|
681
|
+
}),
|
|
682
|
+
);
|
|
683
|
+
api.get('/machine/file', async (req, res) => {
|
|
684
|
+
try {
|
|
685
|
+
filesAllowed();
|
|
686
|
+
const f = await files.file(req.query.path);
|
|
687
|
+
res.download(f.path, f.name, { dotfiles: 'allow' });
|
|
688
|
+
} catch (err) {
|
|
689
|
+
res.status(err.status || 500).json({ error: err.message });
|
|
690
|
+
}
|
|
691
|
+
});
|
|
627
692
|
// The machine terminal: shells in the home folder, not tied to an agent (Open Terminal).
|
|
628
693
|
api.get('/machine/shells', wrap(() => ({ shells: manager.shellNumbers(MACHINE), home: os.homedir() })));
|
|
629
694
|
api.post('/machine/shell/new', wrap(() => ({ n: manager.nextShellNumber(MACHINE) })));
|
|
@@ -754,7 +819,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
754
819
|
api.delete('/agents/:id/links', wrap((req) => manager.removeLink(req.params.id, req.query)));
|
|
755
820
|
api.post('/flush', wrap(() => manager.flush()));
|
|
756
821
|
|
|
757
|
-
// ---------------------------------------------------------- Slack
|
|
822
|
+
// ---------------------------------------------------------- alerts: Slack, and the phone through ntfy (local only)
|
|
758
823
|
const okUrl = (u) => /^https:\/\/[\w.-]+\//.test(u) || /^http:\/\/(127\.0\.0\.1|localhost)(:\d+)?\//.test(u);
|
|
759
824
|
api.get('/notify', wrap(() => ({ ...publicNotify(), workflow: isWorkflowUrl(loadNotify().slack.webhookUrl), recent: notifier.log, judge: judgeAlerts() })));
|
|
760
825
|
const judgeAlerts = () => (manager.judge.enabled ? { digestMin: manager.judge.settings.digestMin, pending: notifier.digest.length } : null);
|
|
@@ -770,19 +835,35 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
770
835
|
if (b.botToken !== undefined) slack.botToken = b.botToken || null;
|
|
771
836
|
if (b.channel !== undefined) slack.channel = b.channel || null;
|
|
772
837
|
const patch = { slack };
|
|
838
|
+
// The phone, through ntfy: `create` makes a topic nobody can guess; an empty topic turns it off.
|
|
839
|
+
const p = b.phone && typeof b.phone === 'object' ? b.phone : null;
|
|
840
|
+
if (p) {
|
|
841
|
+
patch.phone = {};
|
|
842
|
+
if (p.server !== undefined) {
|
|
843
|
+
const server = String(p.server || 'https://ntfy.sh').replace(/\/+$/, '');
|
|
844
|
+
if (!/^https:\/\/[\w.-]+(:\d+)?(\/|$)/.test(server) && !okUrl(`${server}/`)) throw fail(400, 'The ntfy server must be https://…');
|
|
845
|
+
patch.phone.server = server;
|
|
846
|
+
}
|
|
847
|
+
if (p.topic !== undefined) {
|
|
848
|
+
if (p.topic && !/^[\w-]{1,64}$/.test(p.topic)) throw fail(400, 'A topic is up to 64 letters, digits, - and _');
|
|
849
|
+
patch.phone.topic = p.topic || null;
|
|
850
|
+
}
|
|
851
|
+
if (p.token !== undefined) patch.phone.token = p.token || null;
|
|
852
|
+
if (p.create && !patch.phone.topic) patch.phone.topic = loadNotify().phone.topic ?? newTopic();
|
|
853
|
+
}
|
|
773
854
|
for (const k of ['enabled', 'skipWhenWatching', 'includeIntent']) if (typeof b[k] === 'boolean') patch[k] = b[k];
|
|
774
855
|
for (const k of ['needsInputDelaySec', 'waitingDelaySec']) if (Number(b[k]) >= 0) patch[k] = Number(b[k]);
|
|
775
856
|
if (b.events && typeof b.events === 'object') patch.events = b.events;
|
|
776
857
|
const next = saveNotify(patch);
|
|
777
|
-
// Configuring Slack for the first time turns alerts on.
|
|
778
|
-
if (b.enabled === undefined && (slack.webhookUrl || (slack.botToken && (b.channel ?? next.slack.channel)))) saveNotify({ enabled: true });
|
|
858
|
+
// Configuring Slack or the phone for the first time turns alerts on.
|
|
859
|
+
if (b.enabled === undefined && (slack.webhookUrl || (slack.botToken && (b.channel ?? next.slack.channel)) || patch.phone?.topic)) saveNotify({ enabled: true });
|
|
779
860
|
return { ...publicNotify(), recent: notifier.log };
|
|
780
861
|
}),
|
|
781
862
|
);
|
|
782
863
|
api.post(
|
|
783
864
|
'/notify/test',
|
|
784
865
|
wrap(async () => {
|
|
785
|
-
await
|
|
866
|
+
await sendAlert(':wave: Test from AI Agent Manager: alerts will arrive here when an agent needs you.', loadNotify());
|
|
786
867
|
return { ok: true };
|
|
787
868
|
}),
|
|
788
869
|
);
|
|
@@ -1681,6 +1762,13 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
1681
1762
|
screen.close(id, 'The page closed it');
|
|
1682
1763
|
});
|
|
1683
1764
|
});
|
|
1765
|
+
api.get('/screen/clipboard', wrap(() => screen.clipboard()));
|
|
1766
|
+
api.put('/screen/clipboard', wrap((req) => screen.setClipboard(req.body?.text)));
|
|
1767
|
+
api.get('/awake', wrap(() => awake.status()));
|
|
1768
|
+
api.put('/awake', wrap((req) => {
|
|
1769
|
+
saveConfig({ awake: awake.change(req.body ?? {}) });
|
|
1770
|
+
return awake.status();
|
|
1771
|
+
}));
|
|
1684
1772
|
api.post('/screen/input', wrap((req) => {
|
|
1685
1773
|
if (typeof req.body?.id !== 'string' || typeof req.body?.d !== 'string') throw fail(400, 'id and d (base64) are required');
|
|
1686
1774
|
screen.write(req.body.id, Buffer.from(req.body.d, 'base64'));
|
|
@@ -1895,6 +1983,7 @@ export async function startServer({ port = PORT, host = HOST, evalTimer = true }
|
|
|
1895
1983
|
mcp.close();
|
|
1896
1984
|
assistant.close();
|
|
1897
1985
|
screen.closeAll('AI Agent Manager is shutting down');
|
|
1986
|
+
awake.stop();
|
|
1898
1987
|
console.log(`[agentmgr] shutting down (${reason}); closing agents so their sessions are saved`);
|
|
1899
1988
|
builder.stopAll();
|
|
1900
1989
|
await manager.stopAll({ final: true });
|