ai-agentmanager 1.42.0 → 1.43.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 +8 -0
- package/README.md +14 -7
- package/docs/plugins.md +1 -1
- package/package.json +1 -1
- package/public/app.js +8 -1
- package/public/index.html +6 -0
- package/public/mcp.js +182 -40
- package/public/style.css +21 -0
- package/public/update.js +106 -18
- package/src/cli.js +36 -6
- package/src/mcp.js +255 -82
- package/src/server.js +9 -1
- package/src/update.js +84 -16
package/public/update.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Updating from the app: a button in the top bar when a newer release is out, and "Update and
|
|
2
2
|
// restart" in About. The daemon installs it (git checkout of the release tag, or npm install -g)
|
|
3
|
-
// and restarts onto it; this page
|
|
3
|
+
// and restarts onto it; this page shows each step, waits for it to come back and reloads. It works the same
|
|
4
4
|
// from a phone over remote access: the install runs on the computer.
|
|
5
5
|
|
|
6
6
|
export function initUpdate({ api, esc, toast, $ }) {
|
|
@@ -17,6 +17,16 @@ export function initUpdate({ api, esc, toast, $ }) {
|
|
|
17
17
|
}
|
|
18
18
|
$('#about-auto').checked = s?.check !== false;
|
|
19
19
|
$('#about-install').hidden = !ready;
|
|
20
|
+
// An update started from another page or device: follow it here too.
|
|
21
|
+
if (s?.updating && s.progress?.step === 'install' && !run) {
|
|
22
|
+
run = { phase: 'install', to: s.progress.to, from: s.progress.from, startedAt: Date.parse(s.progress.startedAt), progress: s.progress };
|
|
23
|
+
api('GET', '/about').then((a) => {
|
|
24
|
+
run.pid = a.daemon.pid;
|
|
25
|
+
draw();
|
|
26
|
+
if (!dialog.open) dialog.showModal();
|
|
27
|
+
follow();
|
|
28
|
+
}, () => (run = null));
|
|
29
|
+
}
|
|
20
30
|
}
|
|
21
31
|
|
|
22
32
|
async function load() {
|
|
@@ -27,40 +37,118 @@ export function initUpdate({ api, esc, toast, $ }) {
|
|
|
27
37
|
}
|
|
28
38
|
}
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
// The update window: asks first, then follows the install on the daemon step by step (what npm
|
|
41
|
+
// is doing, how long it has taken), the restart, and the page's reload; an error stays on screen
|
|
42
|
+
// with the command to run by hand.
|
|
43
|
+
const dialog = $('#update-dialog');
|
|
44
|
+
let run = null; // { to, from, pid, phase: 'ask' | 'install' | 'restart' | 'failed' | 'late', progress, startedAt, error, manual }
|
|
45
|
+
let ticking = null;
|
|
46
|
+
|
|
47
|
+
const took = (since) => {
|
|
48
|
+
const s = Math.max(0, Math.round((Date.now() - since) / 1000));
|
|
49
|
+
return s < 60 ? `${s} s` : `${Math.floor(s / 60)} min ${String(s % 60).padStart(2, '0')} s`;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function draw() {
|
|
53
|
+
if (!run) return;
|
|
54
|
+
const { phase, progress: p } = run;
|
|
55
|
+
$('#update-title').textContent = phase === 'ask' ? `Update to ${run.to}?` : phase === 'failed' ? `Update to ${run.to} failed` : `Updating to ${run.to}`;
|
|
56
|
+
const body = $('#update-body');
|
|
57
|
+
const actions = $('#update-actions');
|
|
58
|
+
if (phase === 'ask') {
|
|
59
|
+
body.innerHTML = `<p>Version ${esc(run.to)} is out (you have ${esc(run.from)}).</p>
|
|
60
|
+
<p class="hint">Running agents are closed and resume on the new version. It usually takes a minute or two, and longer when the update spans several releases or many agents are open. You'll see each step here.</p>`;
|
|
61
|
+
actions.innerHTML = '<button type="button" class="ghost" data-up="cancel">Cancel</button><button type="button" class="primary" data-up="go">Update and restart</button>';
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (phase === 'failed') {
|
|
65
|
+
body.innerHTML = `<p class="error">${esc(run.error)}</p>
|
|
66
|
+
${run.manual ? `<p class="hint">Nothing was changed. You can also install it in a terminal:</p><p><code>${esc(run.manual)}</code></p>` : '<p class="hint">Nothing was restarted.</p>'}`;
|
|
67
|
+
actions.innerHTML = '<button type="button" class="ghost" data-up="cancel">Close</button><button type="button" class="primary" data-up="go">Try again</button>';
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const installing = phase === 'install';
|
|
71
|
+
const fetched = p?.fetched ? `${p.fetched} package${p.fetched === 1 ? '' : 's'} fetched` : '';
|
|
72
|
+
const detail = [fetched, p?.detail].filter(Boolean).join(' · ');
|
|
73
|
+
const step = (state, label, hint = '') => `<li class="${state}"><span>${state === 'done' ? '✓' : state === 'now' ? '●' : '○'}</span><span>${label}</span>${hint ? `<span class="hint">${hint}</span>` : ''}</li>`;
|
|
74
|
+
body.innerHTML = `<div class="update-bar"><span></span></div>
|
|
75
|
+
<ul class="update-steps">
|
|
76
|
+
${step(installing ? 'now' : 'done', `Install ${esc(run.to)}${p?.kind === 'git' ? ' (git checkout)' : ' (npm)'}`, installing ? `${took(run.startedAt)}${detail ? ` · ${esc(detail)}` : ''}` : '')}
|
|
77
|
+
${step(installing ? '' : 'now', 'Restart the daemon', installing ? 'Agents close and resume on the new version' : `${took(run.restartAt)} · closing agents, starting ${esc(run.to)}, resuming them`)}
|
|
78
|
+
${step('', 'Reload this page')}
|
|
79
|
+
</ul>
|
|
80
|
+
${phase === 'late' ? '<p class="error">The daemon has not come back yet. Check <code>~/.agentmanager/daemon.log</code>, or run <code>agentmgr restart</code> in a terminal.</p>' : '<p class="hint">Keep this page open; it reloads by itself. Closing it does not stop the update.</p>'}`;
|
|
81
|
+
actions.innerHTML = '<button type="button" class="ghost" data-up="cancel">Hide</button>';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Follow an update that is running on the daemon until this page reloads on the new version. */
|
|
85
|
+
function follow() {
|
|
86
|
+
clearInterval(ticking);
|
|
87
|
+
let busy = false;
|
|
88
|
+
ticking = setInterval(async () => {
|
|
89
|
+
if (!run || busy) return;
|
|
90
|
+
busy = true;
|
|
33
91
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
92
|
+
if (run.phase === 'install') {
|
|
93
|
+
const s = await api('GET', '/update');
|
|
94
|
+
const p = s.progress;
|
|
95
|
+
if (p) run.progress = p;
|
|
96
|
+
if (p?.step === 'failed') Object.assign(run, { phase: 'failed', error: p.error, manual: p.manual });
|
|
97
|
+
else if (p?.step === 'restart' || (!s.updating && !p)) Object.assign(run, { phase: 'restart', restartAt: Date.now() });
|
|
98
|
+
} else if (run.phase === 'restart' || run.phase === 'late') {
|
|
99
|
+
const a = await api('GET', '/about');
|
|
100
|
+
if (a.daemon.pid !== run.pid) return location.reload();
|
|
101
|
+
if (Date.now() - run.restartAt > 10 * 60_000) run.phase = 'late';
|
|
102
|
+
}
|
|
36
103
|
} catch {
|
|
37
|
-
//
|
|
104
|
+
// No answer: it is restarting.
|
|
105
|
+
if (run.phase === 'install') Object.assign(run, { phase: 'restart', restartAt: Date.now() });
|
|
106
|
+
} finally {
|
|
107
|
+
busy = false;
|
|
38
108
|
}
|
|
39
|
-
|
|
40
|
-
|
|
109
|
+
if (run.phase === 'failed') {
|
|
110
|
+
clearInterval(ticking);
|
|
111
|
+
$('#update-btn').disabled = $('#about-install').disabled = false;
|
|
112
|
+
}
|
|
113
|
+
draw();
|
|
114
|
+
}, 1000);
|
|
41
115
|
}
|
|
42
116
|
|
|
43
|
-
async function
|
|
44
|
-
|
|
45
|
-
if (!confirm(`Update to ${state.latest} and restart?\n\nRunning agents are closed and resume on the new version. This takes a minute or two with many agents.`)) return;
|
|
46
|
-
const before = (await api('GET', '/about')).daemon.pid;
|
|
117
|
+
async function start() {
|
|
118
|
+
Object.assign(run, { phase: 'install', startedAt: Date.now(), progress: null, error: null });
|
|
47
119
|
$('#update-btn').disabled = $('#about-install').disabled = true;
|
|
48
|
-
|
|
120
|
+
draw();
|
|
49
121
|
try {
|
|
122
|
+
run.pid = (await api('GET', '/about')).daemon.pid;
|
|
50
123
|
const r = await api('POST', '/update');
|
|
51
124
|
if (r.upToDate) {
|
|
125
|
+
dialog.close();
|
|
126
|
+
$('#update-btn').disabled = $('#about-install').disabled = false;
|
|
52
127
|
toast(`${r.current} is the newest release`);
|
|
53
128
|
return load();
|
|
54
129
|
}
|
|
55
|
-
|
|
56
|
-
|
|
130
|
+
run.to = r.to;
|
|
131
|
+
follow();
|
|
57
132
|
} catch (err) {
|
|
58
|
-
|
|
59
|
-
} finally {
|
|
133
|
+
Object.assign(run, { phase: 'failed', error: err.message, manual: null });
|
|
60
134
|
$('#update-btn').disabled = $('#about-install').disabled = false;
|
|
135
|
+
draw();
|
|
61
136
|
}
|
|
62
137
|
}
|
|
63
138
|
|
|
139
|
+
function install() {
|
|
140
|
+
if (!state?.newer) return;
|
|
141
|
+
if (!run || run.phase === 'ask' || run.phase === 'failed') run = { phase: 'ask', to: state.latest, from: state.current };
|
|
142
|
+
draw();
|
|
143
|
+
if (!dialog.open) dialog.showModal();
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
dialog.addEventListener('click', (e) => {
|
|
147
|
+
const act = e.target.closest('[data-up]')?.dataset.up;
|
|
148
|
+
if (act === 'cancel') dialog.close();
|
|
149
|
+
else if (act === 'go') start();
|
|
150
|
+
});
|
|
151
|
+
|
|
64
152
|
/** "Check for updates" in About: the daemon's check, and whether it can update itself. */
|
|
65
153
|
async function check() {
|
|
66
154
|
const s = await api('POST', '/update/check');
|
package/src/cli.js
CHANGED
|
@@ -826,7 +826,7 @@ export async function main(argv) {
|
|
|
826
826
|
.command('list', { isDefault: true })
|
|
827
827
|
.description('List the MCP servers, their status and tools')
|
|
828
828
|
.argument('[agent]', "an agent: its folder's servers too (default: your home folder)")
|
|
829
|
-
.option('-r, --refresh', '
|
|
829
|
+
.option('-r, --refresh', "start the folder's MCP session again (reads the configuration again)")
|
|
830
830
|
.option('--json', 'print JSON')
|
|
831
831
|
.action(async (ref, opts) => {
|
|
832
832
|
await daemon();
|
|
@@ -843,19 +843,46 @@ export async function main(argv) {
|
|
|
843
843
|
});
|
|
844
844
|
mcp
|
|
845
845
|
.command('run')
|
|
846
|
-
.description("Run a tool
|
|
846
|
+
.description("Run a tool in the folder's MCP session: JSON arguments (or none) call it directly; plain words go through a one-off Claude Code call allowed only that tool. --session tells the agent to use it")
|
|
847
847
|
.argument('<agent>', 'the agent, or "home" for your home folder')
|
|
848
848
|
.argument('<server>')
|
|
849
849
|
.argument('<tool>')
|
|
850
|
-
.argument('[request...]', 'what it should do
|
|
850
|
+
.argument('[request...]', `its arguments as JSON ('{"query":"x"}'), or what it should do in plain words`)
|
|
851
851
|
.option('-s, --session', 'tell the agent to use it in its session instead')
|
|
852
852
|
.action(async (ref, server, tool, request, opts) => {
|
|
853
853
|
await daemon();
|
|
854
854
|
const agent = ref === 'home' ? 'home' : (await resolveAgent(ref)).id;
|
|
855
|
-
const
|
|
855
|
+
const input = request.join(' ');
|
|
856
|
+
const { parseArgs } = await import('./mcp.js');
|
|
857
|
+
const r = await api('POST', '/mcp/run', { agent, server, tool, input, where: opts.session ? 'session' : parseArgs(input) ? 'direct' : 'workspace' });
|
|
856
858
|
if (r.where === 'session') return console.log(`${green('✓')} asked ${r.agent.name} to use ${r.tool}; its answer is in the session`);
|
|
857
859
|
console.log(r.text);
|
|
858
|
-
console.log(dim(`(${r.tool}, ${(r.ms / 1000).toFixed(1)} s)`));
|
|
860
|
+
console.log(dim(`(${r.tool}, ${(r.ms / 1000).toFixed(1)} s, ${r.where === 'direct' ? 'called directly' : 'through Claude Code'})`));
|
|
861
|
+
if (r.isError) process.exitCode = 1;
|
|
862
|
+
});
|
|
863
|
+
mcp
|
|
864
|
+
.command('signin')
|
|
865
|
+
.description("Sign in to a server that needs it: prints the address to open. Claude Code keeps the sign-in")
|
|
866
|
+
.argument('<agent>', 'the agent, or "home" for your home folder')
|
|
867
|
+
.argument('<server>')
|
|
868
|
+
.action(async (ref, server) => {
|
|
869
|
+
await daemon();
|
|
870
|
+
const agent = ref === 'home' ? 'home' : (await resolveAgent(ref)).id;
|
|
871
|
+
const r = await api('POST', '/mcp/signin', { agent, server });
|
|
872
|
+
if (!r.url) return console.log(`${green('✓')} ${server} is already signed in`);
|
|
873
|
+
console.log(`Open this to sign in to ${bold(server)}:\n${r.url}`);
|
|
874
|
+
console.log(dim(r.callback ? `When you finish there it connects by itself; check with: agentmgr mcp reconnect ${ref} ${server}` : `Then connect it again: agentmgr mcp reconnect ${ref} ${server}`));
|
|
875
|
+
});
|
|
876
|
+
mcp
|
|
877
|
+
.command('reconnect')
|
|
878
|
+
.description('Connect one server again (after signing in, or when it failed) and show its status')
|
|
879
|
+
.argument('<agent>', 'the agent, or "home" for your home folder')
|
|
880
|
+
.argument('<server>')
|
|
881
|
+
.action(async (ref, server) => {
|
|
882
|
+
await daemon();
|
|
883
|
+
const agent = ref === 'home' ? 'home' : (await resolveAgent(ref)).id;
|
|
884
|
+
const s = (await api('POST', '/mcp/reconnect', { agent, server })).servers.find((x) => x.name === server);
|
|
885
|
+
console.log(`${bold(server)} ${s?.status === 'connected' ? green(s.status) : yellow(s?.status ?? 'not listed')}${s ? dim(` ${s.tools.length} tools`) : ''}`);
|
|
859
886
|
});
|
|
860
887
|
|
|
861
888
|
program
|
|
@@ -2734,7 +2761,10 @@ export async function main(argv) {
|
|
|
2734
2761
|
if (!info.newer) return console.log(`${green('✓')} ${info.current} is the newest release`);
|
|
2735
2762
|
if (info.blocker) throw new Error(`${info.latest} is available, but: ${info.blocker}`);
|
|
2736
2763
|
if (opts.check) return console.log(`${yellow(info.latest)} is available (you have ${info.current}); install it: agentmgr update`);
|
|
2737
|
-
|
|
2764
|
+
// A line per package npm fetches, as a count that moves while a long install runs.
|
|
2765
|
+
let fetched = 0;
|
|
2766
|
+
const onLine = (line) => /^npm http /.test(line) && process.stdout.isTTY && process.stdout.write(`\r${dim(` ${++fetched} packages fetched`)}`);
|
|
2767
|
+
const r = await up.installUpdate({ info, log: (m) => console.log(dim(m)), onLine }).finally(() => fetched && process.stdout.write('\n'));
|
|
2738
2768
|
console.log(`${green('✓')} installed ${r.to} (was ${r.from})`);
|
|
2739
2769
|
if (!(await health())) return console.log(dim('The daemon is not running; it starts on the new version next time'));
|
|
2740
2770
|
outliveTerminal();
|