ai-agentmanager 1.42.0 → 1.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/README.md +15 -8
- package/docs/plugins.md +1 -1
- package/package.json +1 -1
- package/public/actions.js +14 -4
- package/public/app.js +22 -6
- package/public/index.html +7 -0
- package/public/mcp.js +182 -40
- package/public/style.css +28 -0
- package/public/update.js +106 -18
- package/src/actions.js +6 -0
- package/src/cli.js +43 -10
- package/src/mcp.js +255 -82
- package/src/server.js +9 -1
- package/src/today.js +11 -2
- package/src/update.js +84 -16
package/public/mcp.js
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
// MCP: the MCP servers Claude Code has in an agent's folder (or the home folder), each with its
|
|
2
|
-
// status, where it comes from and its tools
|
|
3
|
-
//
|
|
2
|
+
// status, where it comes from and its tools. Each folder has its own MCP session on the daemon
|
|
3
|
+
// (apart from any agent's), where a server is signed in to, connected again and its tools are
|
|
4
|
+
// called directly; a tool can also run through Claude Code from plain words, or in the agent's
|
|
5
|
+
// session. The window also opens on its own (#mcp or #mcp/<agent>).
|
|
4
6
|
|
|
5
7
|
const SOURCE = { project: 'Project (.mcp.json)', user: 'User', local: 'Local', claudeai: 'claude.ai connector', dynamic: 'Added at launch', enterprise: 'Managed' };
|
|
6
8
|
const STATUS = { connected: 'mcp-ok', pending: 'mcp-wait', failed: 'fail', 'needs-auth': 'mcp-wait', disabled: '' };
|
|
9
|
+
const STATUS_LABEL = { 'needs-auth': 'needs sign-in' };
|
|
10
|
+
const RAN = { direct: 'called directly', workspace: 'through Claude Code', session: 'in the session' };
|
|
11
|
+
const SIGN_IN_WAIT_MS = 5 * 60_000;
|
|
12
|
+
|
|
13
|
+
/** Arguments typed for a tool: nothing or a JSON object is a direct call; anything else is plain words. */
|
|
14
|
+
export function directArgs(input) {
|
|
15
|
+
const text = String(input ?? '').trim();
|
|
16
|
+
if (!text) return true;
|
|
17
|
+
if (!text.startsWith('{')) return false;
|
|
18
|
+
try {
|
|
19
|
+
const v = JSON.parse(text);
|
|
20
|
+
return Boolean(v) && typeof v === 'object' && !Array.isArray(v);
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
7
25
|
|
|
8
26
|
export function initMcp({ api, $, esc, ago, md, toast, agents }) {
|
|
9
27
|
const dialog = $('#mcp-dialog');
|
|
@@ -12,33 +30,63 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
|
|
|
12
30
|
let data = null;
|
|
13
31
|
let loading = false;
|
|
14
32
|
let query = '';
|
|
15
|
-
const results = new Map(); // "<where>:<tool id>" ->
|
|
33
|
+
const results = new Map(); // "<where>:<tool id>" -> a run | { error } | { running } | { told }
|
|
16
34
|
const forms = new Set(); // tool ids with their run form open
|
|
17
35
|
const sure = new Set(); // destructive tools waiting for a second click
|
|
36
|
+
const signIns = new Map(); // "<where>:<server>" -> { url, callback, local, since, error, busy }
|
|
37
|
+
const reconnecting = new Set(); // "<where>:<server>"
|
|
38
|
+
let watching = null;
|
|
18
39
|
|
|
19
40
|
const sourceOf = (s) => SOURCE[s.source] ?? (String(s.source ?? '').startsWith('plugin') ? `Plugin${s.source.includes(':') ? `: ${s.source.split(':').slice(1).join(':')}` : ''}` : s.source ?? s.scope ?? '');
|
|
20
41
|
|
|
21
|
-
async function load(refresh = false) {
|
|
22
|
-
|
|
23
|
-
|
|
42
|
+
async function load({ refresh = false, quiet = false } = {}) {
|
|
43
|
+
if (!quiet) {
|
|
44
|
+
loading = true;
|
|
45
|
+
render();
|
|
46
|
+
}
|
|
47
|
+
const at = where;
|
|
24
48
|
try {
|
|
25
|
-
|
|
49
|
+
const next = await api('GET', `/mcp?agent=${encodeURIComponent(at)}${refresh ? '&refresh=1' : ''}`);
|
|
50
|
+
if (at !== where) return;
|
|
51
|
+
data = next;
|
|
26
52
|
} catch (e) {
|
|
27
|
-
|
|
53
|
+
if (at !== where) return;
|
|
54
|
+
data = { servers: [], runs: [], error: e.message };
|
|
28
55
|
} finally {
|
|
29
56
|
loading = false;
|
|
30
57
|
}
|
|
58
|
+
// A sign-in is over once its server is connected.
|
|
59
|
+
for (const s of data.servers ?? []) if (s.status === 'connected' && signIns.delete(`${where}:${s.name}`)) toast(`Signed in to ${s.name}`);
|
|
31
60
|
render();
|
|
32
61
|
}
|
|
33
62
|
|
|
63
|
+
/** While a sign-in is open, look again every few seconds: the server connects by itself when it's done. */
|
|
64
|
+
function watch() {
|
|
65
|
+
clearInterval(watching);
|
|
66
|
+
watching = setInterval(() => {
|
|
67
|
+
for (const [k, v] of signIns) if (Date.now() - v.since > SIGN_IN_WAIT_MS) signIns.delete(k);
|
|
68
|
+
if (!signIns.size || !dialog.open) return clearInterval(watching);
|
|
69
|
+
if ([...signIns.keys()].some((k) => k.startsWith(`${where}:`))) load({ quiet: true });
|
|
70
|
+
}, 3000);
|
|
71
|
+
}
|
|
72
|
+
|
|
34
73
|
function picker() {
|
|
35
74
|
const list = agents().filter((a) => a.workdir && a.status !== 'preparing');
|
|
36
|
-
return `<select id="mcp-where" title="Whose folder: an agent's workspace has its project's servers too">
|
|
75
|
+
return `<select id="mcp-where" title="Whose folder: an agent's workspace has its project's servers too. Each folder has its own MCP session">
|
|
37
76
|
<option value="home" ${where === 'home' ? 'selected' : ''}>Home folder (your servers and connectors)</option>
|
|
38
77
|
${list.map((a) => `<option value="${esc(a.id)}" ${where === a.id ? 'selected' : ''}>${esc(a.name)}</option>`).join('')}
|
|
39
78
|
</select>`;
|
|
40
79
|
}
|
|
41
80
|
|
|
81
|
+
const resultHtml = (r) =>
|
|
82
|
+
r?.error
|
|
83
|
+
? `<p class="error">${esc(r.error)}</p>`
|
|
84
|
+
: r?.text
|
|
85
|
+
? `<div class="mcp-result ${r.isError ? 'failed' : ''}"><p class="hint">${r.isError ? 'The tool reported an error · ' : ''}Ran ${ago(r.at)} in ${(r.ms / 1000).toFixed(1)} s, ${RAN[r.where] ?? ''}</p><div class="md">${md(r.text)}</div></div>`
|
|
86
|
+
: r?.told
|
|
87
|
+
? `<p class="hint">Sent to ${esc(r.told)}. Its answer is in the session.</p>`
|
|
88
|
+
: '';
|
|
89
|
+
|
|
42
90
|
function toolHtml(s, t) {
|
|
43
91
|
const key = `${where}:${t.id}`;
|
|
44
92
|
const r = results.get(key);
|
|
@@ -48,65 +96,95 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
|
|
|
48
96
|
const tags = `${t.readOnly ? '<span class="tag mcp-ok" title="The server says it only reads">read-only</span>' : ''}${t.destructive ? '<span class="tag fail" title="The server says it may change or delete things">destructive</span>' : ''}`;
|
|
49
97
|
const form = open
|
|
50
98
|
? `<div class="mcp-form">
|
|
51
|
-
<textarea data-mcp-input="${esc(t.id)}" rows="2" placeholder=
|
|
99
|
+
<textarea data-mcp-input="${esc(t.id)}" rows="2" placeholder='Its arguments as JSON, like {"query": "…"}, or nothing: called directly, no model. Or say what it should do in plain words: Claude Code works out the arguments.'></textarea>
|
|
52
100
|
${sure.has(t.id) ? `<p class="hint error">${esc(t.name)} may change or delete things. Click again to run it.</p>` : ''}
|
|
53
101
|
<div class="mcp-actions">
|
|
54
|
-
${agent ? `<button type="button" class="small" data-mcp-run="session" data-server="${esc(s.name)}" data-tool="${esc(t.name)}" ${canSession ? '' : 'disabled'} title="${canSession ? `Tell ${esc(agent.name)} to use it, with its conversation and context${agent.running ? '' : ' (resumes the session)'}` : 'Works for Claude Code agents'}">Run in session</button>` : ''}
|
|
55
|
-
<button type="button" class="small primary" data-mcp-run="
|
|
102
|
+
${agent ? `<button type="button" class="small" data-mcp-run="session" data-server="${esc(s.name)}" data-tool="${esc(t.name)}" ${canSession ? '' : 'disabled'} title="${canSession ? `Tell ${esc(agent.name)} to use it, with its conversation and context${agent.running ? '' : ' (resumes the session)'}` : 'Works for Claude Code agents'}">Run in agent session</button>` : ''}
|
|
103
|
+
<button type="button" class="small primary" data-mcp-run="here" data-server="${esc(s.name)}" data-tool="${esc(t.name)}" ${r?.running ? 'disabled' : ''} title="In this folder's MCP session, apart from the agent's: JSON arguments (or none) call the tool directly; plain words go through a one-off Claude Code call that may use only this tool">${r?.running ? 'Running…' : 'Run'}</button>
|
|
56
104
|
</div>
|
|
57
105
|
</div>`
|
|
58
106
|
: '';
|
|
59
|
-
const out = r?.error
|
|
60
|
-
? `<p class="error">${esc(r.error)}</p>`
|
|
61
|
-
: r?.text
|
|
62
|
-
? `<div class="mcp-result"><p class="hint">Ran ${ago(r.at)} in ${(r.ms / 1000).toFixed(1)} s</p><div class="md">${md(r.text)}</div></div>`
|
|
63
|
-
: r?.told
|
|
64
|
-
? `<p class="hint">Sent to ${esc(r.told)}. Its answer is in the session.</p>`
|
|
65
|
-
: '';
|
|
66
107
|
return `<li class="mcp-tool">
|
|
67
108
|
<div class="mcp-tool-row"><code title="${esc(t.id)}">${esc(t.name)}</code>${t.title ? ` <span class="hint">${esc(t.title)}</span>` : ''} ${tags}
|
|
68
109
|
<span class="spacer"></span>${s.status === 'connected' ? `<button type="button" class="small ghost" data-mcp-form="${esc(t.id)}">${open ? 'Hide' : 'Run…'}</button>` : ''}</div>
|
|
69
|
-
${form}${
|
|
110
|
+
${form}${resultHtml(r)}
|
|
70
111
|
</li>`;
|
|
71
112
|
}
|
|
72
113
|
|
|
114
|
+
function signInHtml(s) {
|
|
115
|
+
const si = signIns.get(`${where}:${s.name}`);
|
|
116
|
+
if (!si) return s.status === 'needs-auth' ? '<p class="hint">Sign in to use its tools. Claude Code keeps the sign-in; this app never sees it.</p>' : '';
|
|
117
|
+
if (si.busy) return '<p class="hint">Getting the sign-in page…</p>';
|
|
118
|
+
if (si.error) return `<p class="error">${esc(si.error)}</p>`;
|
|
119
|
+
return `<div class="mcp-signin">
|
|
120
|
+
<p><a href="${esc(si.url)}" target="_blank" rel="noopener">Open the sign-in page ↗</a> <span class="hint">${si.callback ? 'When you finish there, this server connects by itself.' : 'When you have connected it there, press ↻ here.'}</span></p>
|
|
121
|
+
${si.callback ? `<details data-keep="cb:${esc(s.name)}"><summary class="hint">Signing in on another device, or the page at the end doesn't load?</summary>
|
|
122
|
+
<p class="hint">The sign-in ends on an address on this computer (localhost). Copy that address from the browser and paste it here.</p>
|
|
123
|
+
<div class="mcp-paste"><input type="text" data-mcp-callback="${esc(s.name)}" placeholder="http://localhost:…/callback?code=…" /><button type="button" class="small" data-mcp-callback-send="${esc(s.name)}">Finish sign-in</button></div>
|
|
124
|
+
</details>` : ''}
|
|
125
|
+
</div>`;
|
|
126
|
+
}
|
|
127
|
+
|
|
73
128
|
function serverHtml(s) {
|
|
74
129
|
const q = query.toLowerCase();
|
|
75
130
|
const tools = s.tools.filter((t) => !q || s.name.toLowerCase().includes(q) || t.name.toLowerCase().includes(q) || (t.title ?? '').toLowerCase().includes(q));
|
|
76
|
-
if (q && !tools.length) return '';
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
131
|
+
if (q && !tools.length && !s.name.toLowerCase().includes(q)) return '';
|
|
132
|
+
const busy = reconnecting.has(`${where}:${s.name}`);
|
|
133
|
+
const needs = s.status === 'needs-auth';
|
|
134
|
+
return `<details class="mcp-server" data-keep="srv:${esc(s.name)}" ${q || s.tools.length <= 12 ? 'open' : ''}>
|
|
135
|
+
<summary><b>${esc(s.name)}</b> <span class="tag ${STATUS[s.status] ?? ''}">${esc(STATUS_LABEL[s.status] ?? s.status)}</span> <span class="tag">${esc(sourceOf(s))}</span>
|
|
136
|
+
<span class="hint">${s.tools.length} tool${s.tools.length === 1 ? '' : 's'}</span><span class="spacer"></span>
|
|
137
|
+
${needs && s.canSignIn ? `<button type="button" class="small primary" data-mcp-signin="${esc(s.name)}" title="Open ${esc(s.name)}'s sign-in page">Sign in</button>` : ''}
|
|
138
|
+
${s.status === 'disabled' ? '' : `<button type="button" class="small ghost mcp-again" data-mcp-reconnect="${esc(s.name)}" ${busy ? 'disabled' : ''} title="Connect ${esc(s.name)} again and list its tools${needs ? ' (after signing in)' : ''}" aria-label="Refresh ${esc(s.name)}">${busy ? '…' : '↻'}</button>`}</summary>
|
|
80
139
|
${s.target ? `<p class="hint mcp-target" title="${esc(s.transport ?? '')}">${esc(s.target)}</p>` : ''}
|
|
81
140
|
${s.error ? `<p class="error">${esc(s.error)}</p>` : ''}
|
|
82
|
-
${s
|
|
141
|
+
${signInHtml(s)}
|
|
83
142
|
${tools.length ? `<ul class="mcp-tools">${tools.map((t) => toolHtml(s, t)).join('')}</ul>` : s.status === 'connected' ? '<p class="hint">No tools.</p>' : ''}
|
|
84
143
|
</details>`;
|
|
85
144
|
}
|
|
86
145
|
|
|
146
|
+
function runsHtml() {
|
|
147
|
+
const runs = data.runs ?? [];
|
|
148
|
+
if (!runs.length) return '';
|
|
149
|
+
return `<details class="mcp-runs" data-keep="runs"><summary><b>Runs in this MCP session</b> <span class="hint">${runs.length}, newest first</span></summary>
|
|
150
|
+
<ul class="mcp-tools">${runs.map((r) => `<li class="mcp-tool"><details data-keep="run:${esc(r.at)}"><summary><code>${esc(r.server)}: ${esc(r.name)}</code> ${r.isError ? '<span class="tag fail">error</span>' : ''} <span class="hint">${ago(r.at)} · ${(r.ms / 1000).toFixed(1)} s · ${RAN[r.where] ?? ''}</span></summary>
|
|
151
|
+
${r.input ? `<p class="hint mcp-target">${esc(r.input)}</p>` : ''}<div class="mcp-result ${r.isError ? 'failed' : ''}"><div class="md">${md(r.text)}</div></div></details></li>`).join('')}</ul>
|
|
152
|
+
</details>`;
|
|
153
|
+
}
|
|
154
|
+
|
|
87
155
|
function render() {
|
|
88
156
|
if (!dialog.open) return;
|
|
89
|
-
|
|
90
|
-
const
|
|
157
|
+
// What was typed, where the cursor is and what was folded all survive a redraw.
|
|
158
|
+
const boxKey = (t) => (t?.dataset?.mcpInput ? `in:${t.dataset.mcpInput}` : t?.dataset?.mcpCallback ? `cb:${t.dataset.mcpCallback}` : null);
|
|
159
|
+
const boxes = () => [...body.querySelectorAll('[data-mcp-input], [data-mcp-callback]')];
|
|
160
|
+
const active = document.activeElement;
|
|
161
|
+
const focus = boxKey(active) && { key: boxKey(active), from: active.selectionStart, to: active.selectionEnd };
|
|
162
|
+
const typed = new Map(boxes().map((t) => [boxKey(t), t.value]));
|
|
163
|
+
const folded = new Map([...body.querySelectorAll('details[data-keep]')].map((d) => [d.dataset.keep, d.open]));
|
|
91
164
|
const n = data?.servers?.reduce((k, s) => k + s.tools.length, 0) ?? 0;
|
|
92
165
|
$('#mcp-head').innerHTML = `${picker()}<input id="mcp-filter" type="search" placeholder="Filter servers and tools" value="${esc(query)}" />
|
|
93
|
-
<button type="button" class="small" id="mcp-refresh" ${loading ? 'disabled' : ''} title="
|
|
166
|
+
<button type="button" class="small" id="mcp-refresh" ${loading ? 'disabled' : ''} title="Start this folder's MCP session again: it reads the configuration again and connects to every server">${loading ? 'Listing…' : 'Refresh all'}</button>
|
|
167
|
+
${window.name === 'agentmgr-mcp' ? '' : '<button type="button" class="small ghost" id="mcp-window" title="Open this in its own window">↗ Window</button>'}`;
|
|
94
168
|
body.innerHTML = loading && !data
|
|
95
|
-
? '<p class="hint">
|
|
169
|
+
? '<p class="hint">Starting the MCP session here and asking Claude Code for its servers (it connects to each one)…</p>'
|
|
96
170
|
: !data
|
|
97
171
|
? ''
|
|
98
|
-
: `<p class="hint">${data.servers.length} server${data.servers.length === 1 ? '' : 's'}, ${n} tool${n === 1 ? '' : 's'}${data.at ? `, listed ${ago(data.at)}` : ''}${data.dir ? ` in <code>${esc(data.dir)}</code>` : ''}. The same servers Claude Code has there: your own, the project's .mcp.json, claude.ai connectors and plugins
|
|
172
|
+
: `<p class="hint">${data.servers.length} server${data.servers.length === 1 ? '' : 's'}, ${n} tool${n === 1 ? '' : 's'}${data.at ? `, listed ${ago(data.at)}` : ''}${data.dir ? ` in <code>${esc(data.dir)}</code>` : ''}. The same servers Claude Code has there: your own, the project's .mcp.json, claude.ai connectors and plugins. ${data.session ? `This folder's MCP session has been up since ${ago(data.session.startedAt)}; it is separate from any agent's session.` : ''}</p>
|
|
99
173
|
${data.error ? `<p class="error">${esc(data.error)}</p>` : ''}
|
|
100
|
-
${data.servers.map(serverHtml).join('') || (data.error ? '' : '<p class="hint">No MCP servers here. Add one with <code>claude mcp add</code>, or a .mcp.json in the project.</p>')}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
174
|
+
${data.servers.map(serverHtml).join('') || (data.error ? '' : '<p class="hint">No MCP servers here. Add one with <code>claude mcp add</code>, or a .mcp.json in the project.</p>')}
|
|
175
|
+
${runsHtml()}`;
|
|
176
|
+
for (const box of boxes()) {
|
|
177
|
+
const key = boxKey(box);
|
|
178
|
+
if (typed.has(key)) box.value = typed.get(key);
|
|
179
|
+
if (focus?.key === key) {
|
|
180
|
+
box.focus();
|
|
181
|
+
box.setSelectionRange(focus.from, focus.to);
|
|
182
|
+
}
|
|
104
183
|
}
|
|
105
|
-
|
|
184
|
+
for (const d of body.querySelectorAll('details[data-keep]')) if (folded.has(d.dataset.keep)) d.open = folded.get(d.dataset.keep);
|
|
106
185
|
}
|
|
107
186
|
|
|
108
187
|
async function run(btn) {
|
|
109
|
-
const how = btn.dataset.mcpRun;
|
|
110
188
|
const server = btn.dataset.server;
|
|
111
189
|
const tool = btn.dataset.tool;
|
|
112
190
|
const t = data.servers.find((s) => s.name === server)?.tools.find((x) => x.name === tool);
|
|
@@ -118,7 +196,7 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
|
|
|
118
196
|
sure.delete(t.id);
|
|
119
197
|
const input = body.querySelector(`[data-mcp-input="${CSS.escape(t.id)}"]`)?.value ?? '';
|
|
120
198
|
const key = `${where}:${t.id}`;
|
|
121
|
-
if (
|
|
199
|
+
if (btn.dataset.mcpRun === 'session') {
|
|
122
200
|
try {
|
|
123
201
|
await api('POST', '/mcp/run', { agent: where, server, tool, input, where: 'session' });
|
|
124
202
|
results.set(key, { told: data.agent.name });
|
|
@@ -131,18 +209,82 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
|
|
|
131
209
|
results.set(key, { running: true });
|
|
132
210
|
render();
|
|
133
211
|
try {
|
|
134
|
-
|
|
212
|
+
const r = await api('POST', '/mcp/run', { agent: where, server, tool, input, where: directArgs(input) ? 'direct' : 'workspace' });
|
|
213
|
+
results.set(key, r);
|
|
214
|
+
data.runs = [r, ...(data.runs ?? [])].slice(0, 30);
|
|
135
215
|
} catch (e) {
|
|
136
216
|
results.set(key, { error: e.message });
|
|
137
217
|
}
|
|
138
218
|
render();
|
|
139
219
|
}
|
|
140
220
|
|
|
221
|
+
/** Sign in: the page opens in a new tab at once (so the browser doesn't block it), then goes to the address. */
|
|
222
|
+
async function signIn(name) {
|
|
223
|
+
const key = `${where}:${name}`;
|
|
224
|
+
const tab = window.open('', '_blank');
|
|
225
|
+
signIns.set(key, { busy: true, since: Date.now() });
|
|
226
|
+
render();
|
|
227
|
+
try {
|
|
228
|
+
const r = await api('POST', '/mcp/signin', { agent: where, server: name });
|
|
229
|
+
if (!r.url) {
|
|
230
|
+
tab?.close();
|
|
231
|
+
signIns.delete(key);
|
|
232
|
+
toast(`${name} is already signed in`);
|
|
233
|
+
return load({ quiet: true });
|
|
234
|
+
}
|
|
235
|
+
signIns.set(key, { url: r.url, callback: r.callback, local: r.local, since: Date.now() });
|
|
236
|
+
if (tab) tab.location = r.url;
|
|
237
|
+
watch();
|
|
238
|
+
} catch (e) {
|
|
239
|
+
tab?.close();
|
|
240
|
+
signIns.set(key, { error: e.message, since: Date.now() });
|
|
241
|
+
}
|
|
242
|
+
render();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function reconnect(name) {
|
|
246
|
+
const key = `${where}:${name}`;
|
|
247
|
+
reconnecting.add(key);
|
|
248
|
+
render();
|
|
249
|
+
try {
|
|
250
|
+
data = await api('POST', '/mcp/reconnect', { agent: where, server: name });
|
|
251
|
+
const s = data.servers.find((x) => x.name === name);
|
|
252
|
+
if (s?.status === 'connected') signIns.delete(key);
|
|
253
|
+
toast(`${name}: ${STATUS_LABEL[s?.status] ?? s?.status ?? 'not listed'}${s?.status === 'connected' ? `, ${s.tools.length} tool${s.tools.length === 1 ? '' : 's'}` : ''}`);
|
|
254
|
+
} catch (e) {
|
|
255
|
+
toast(`${name}: ${e.message}`, 6000);
|
|
256
|
+
} finally {
|
|
257
|
+
reconnecting.delete(key);
|
|
258
|
+
}
|
|
259
|
+
render();
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async function finishSignIn(name) {
|
|
263
|
+
const url = body.querySelector(`[data-mcp-callback="${CSS.escape(name)}"]`)?.value.trim();
|
|
264
|
+
if (!url) return;
|
|
265
|
+
try {
|
|
266
|
+
data = await api('POST', '/mcp/signin/callback', { agent: where, server: name, url });
|
|
267
|
+
if (data.servers.find((x) => x.name === name)?.status === 'connected') {
|
|
268
|
+
signIns.delete(`${where}:${name}`);
|
|
269
|
+
toast(`Signed in to ${name}`);
|
|
270
|
+
}
|
|
271
|
+
} catch (e) {
|
|
272
|
+
toast(e.message, 8000);
|
|
273
|
+
}
|
|
274
|
+
render();
|
|
275
|
+
}
|
|
276
|
+
|
|
141
277
|
dialog.addEventListener('click', (e) => {
|
|
142
278
|
const b = e.target.closest('button');
|
|
143
279
|
if (!b) return;
|
|
280
|
+
// Buttons in a server's heading don't fold it.
|
|
281
|
+
if (b.closest('summary')) e.preventDefault();
|
|
144
282
|
if (b.id === 'mcp-close') return dialog.close();
|
|
145
|
-
if (b.id === 'mcp-refresh') return load(true);
|
|
283
|
+
if (b.id === 'mcp-refresh') return load({ refresh: true });
|
|
284
|
+
if (b.id === 'mcp-window') return void window.open(`/#mcp${where === 'home' ? '' : `/${where}`}`, 'agentmgr-mcp', 'width=1040,height=820');
|
|
285
|
+
if (b.dataset.mcpSignin) return signIn(b.dataset.mcpSignin);
|
|
286
|
+
if (b.dataset.mcpReconnect) return reconnect(b.dataset.mcpReconnect);
|
|
287
|
+
if (b.dataset.mcpCallbackSend) return finishSignIn(b.dataset.mcpCallbackSend);
|
|
146
288
|
if (b.dataset.mcpForm) {
|
|
147
289
|
if (forms.has(b.dataset.mcpForm)) forms.delete(b.dataset.mcpForm);
|
|
148
290
|
else forms.add(b.dataset.mcpForm);
|
|
@@ -177,7 +319,7 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
|
|
|
177
319
|
data = null;
|
|
178
320
|
forms.clear();
|
|
179
321
|
}
|
|
180
|
-
dialog.showModal();
|
|
322
|
+
if (!dialog.open) dialog.showModal();
|
|
181
323
|
render();
|
|
182
324
|
load();
|
|
183
325
|
},
|
package/public/style.css
CHANGED
|
@@ -181,6 +181,10 @@ body.term-max .topbar, body.term-max .sidebar, body.term-max .split-side,
|
|
|
181
181
|
body.term-max #detail-body, body.term-max .split-term, body.term-max #placeholder { display: none !important; }
|
|
182
182
|
body.term-max .layout { grid-template-columns: 1fr; }
|
|
183
183
|
.term-wrap:fullscreen { width: 100vw; height: 100vh; }
|
|
184
|
+
/* The agent's name in the terminal bar, only when the detail with its name is out of view. */
|
|
185
|
+
.term-agent { display: none; flex-shrink: 0; max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: #e6edf3; padding-right: 8px; border-right: 1px solid #30363d; }
|
|
186
|
+
body.term-max .term-agent, .term-wrap:fullscreen .term-agent { display: inline-block; }
|
|
187
|
+
.term-agent:empty { display: none !important; }
|
|
184
188
|
.term-bar button.on { background: #262c38; border-color: #58a6ff; }
|
|
185
189
|
.sidebar { border-right: 1px solid var(--border); overflow-y: auto; background: var(--panel); }
|
|
186
190
|
.side-tabs { display: flex; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 2; }
|
|
@@ -512,6 +516,19 @@ dialog::backdrop { background: rgba(0, 0, 0, .45); }
|
|
|
512
516
|
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
|
|
513
517
|
.error { color: var(--red); margin: 0; font-size: 13px; }
|
|
514
518
|
|
|
519
|
+
.update-dialog { width: min(520px, calc(100vw - 32px)); padding: 20px; }
|
|
520
|
+
.update-dialog h2 { margin: 0 0 8px; font-size: 17px; }
|
|
521
|
+
.update-dialog p { margin: 6px 0; font-size: 13px; }
|
|
522
|
+
.update-steps { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 8px; }
|
|
523
|
+
.update-steps li { display: grid; grid-template-columns: 22px 1fr; gap: 4px 6px; align-items: baseline; color: var(--muted); }
|
|
524
|
+
.update-steps li.now { color: var(--text); font-weight: 600; }
|
|
525
|
+
.update-steps li.done { color: var(--text); }
|
|
526
|
+
.update-steps li .hint { grid-column: 2; font-weight: 400; word-break: break-word; }
|
|
527
|
+
.update-bar { height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; margin: 4px 0 10px; }
|
|
528
|
+
.update-bar span { display: block; height: 100%; width: 35%; background: var(--accent); border-radius: 2px; animation: update-slide 1.4s ease-in-out infinite; }
|
|
529
|
+
@keyframes update-slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
|
|
530
|
+
@media (prefers-reduced-motion: reduce) { .update-bar span { animation: none; width: 100%; opacity: 0.5; } }
|
|
531
|
+
|
|
515
532
|
.toast button { margin-left: 8px; }
|
|
516
533
|
.toast {
|
|
517
534
|
position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
|
|
@@ -532,6 +549,7 @@ dialog::backdrop { background: rgba(0, 0, 0, .45); }
|
|
|
532
549
|
/* On a phone the terminal takes the whole screen; "Hide terminal" goes back. */
|
|
533
550
|
.detail.with-term .term-wrap { position: fixed; inset: 0; z-index: 5; min-height: 0; padding-top: env(safe-area-inset-top); }
|
|
534
551
|
.term-bar #term-title { display: none; }
|
|
552
|
+
.detail.with-term .term-agent { display: inline-block; max-width: 45vw; }
|
|
535
553
|
/* The tabs get a row of their own, so + Shell and + Browser aren't squeezed out of view. */
|
|
536
554
|
.term-bar { flex-wrap: wrap; row-gap: 6px; }
|
|
537
555
|
.term-bar > .term-tabs { flex: 1 0 100%; }
|
|
@@ -746,6 +764,14 @@ pre.diff .meta { color: var(--muted); font-weight: 600; }
|
|
|
746
764
|
.mcp-form textarea { width: 100%; box-sizing: border-box; }
|
|
747
765
|
.mcp-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
|
|
748
766
|
.mcp-result { border-left: 3px solid var(--border); padding-left: 10px; margin: 6px 0; max-height: 320px; overflow: auto; }
|
|
767
|
+
.mcp-server summary .spacer { flex: 1; }
|
|
768
|
+
.mcp-again { min-width: 28px; font-size: 15px; line-height: 1; }
|
|
769
|
+
.mcp-signin p { margin: 6px 0; }
|
|
770
|
+
.mcp-paste { display: flex; gap: 6px; margin: 6px 0; }
|
|
771
|
+
.mcp-paste input { flex: 1; min-width: 0; }
|
|
772
|
+
.mcp-result.failed { border-left-color: var(--red); }
|
|
773
|
+
.mcp-runs { margin: 14px 0 0; padding: 6px 10px; border: 1px dashed var(--border); border-radius: 6px; }
|
|
774
|
+
.mcp-runs summary { cursor: pointer; }
|
|
749
775
|
.tag.mcp-ok { color: var(--green); }
|
|
750
776
|
.tag.mcp-wait { color: var(--yellow); }
|
|
751
777
|
.rv-summary { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 13px; }
|
|
@@ -1426,6 +1452,8 @@ table.issues tr.kb-on td:first-child { box-shadow: inset 3px 0 0 var(--accent);
|
|
|
1426
1452
|
.actions-table .action-text { font-weight: 600; color: var(--text); }
|
|
1427
1453
|
.actions-table .action-meta { margin-top: 3px; }
|
|
1428
1454
|
.actions-table .action-due { color: var(--yellow); font-weight: 600; }
|
|
1455
|
+
.actions-table .action-due.late { color: var(--red); }
|
|
1456
|
+
.issues-head .chip.late:not(.active) { border-color: var(--red); color: var(--red); }
|
|
1429
1457
|
.actions-table tr.action-skip td:not(.issue-action), .actions-table tr.action-remove td:not(.issue-action), .actions-table tr.action-done td:not(.issue-action) { opacity: 0.65; }
|
|
1430
1458
|
|
|
1431
1459
|
/* Report a problem or idea */
|
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/actions.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// is ever sent to Slack or anywhere else from here.
|
|
8
8
|
|
|
9
9
|
import crypto from 'node:crypto';
|
|
10
|
+
import { actionDue, dueWords } from './today.js';
|
|
10
11
|
|
|
11
12
|
export const ACTION_SOURCES = { slack: 'Slack', gemini: 'Meeting notes', other: 'Other' };
|
|
12
13
|
export const ACTION_STATES = ['open', 'assign', 'skip', 'snooze', 'done', 'remove'];
|
|
@@ -126,8 +127,10 @@ export class MyActions {
|
|
|
126
127
|
rows() {
|
|
127
128
|
const order = Object.fromEntries(Object.values(GROUP).map((g, i) => [g, i]));
|
|
128
129
|
this.wake();
|
|
130
|
+
const now = new Date();
|
|
129
131
|
return this.all
|
|
130
132
|
.map((a) => {
|
|
133
|
+
const due = actionDue(a, now);
|
|
131
134
|
const agent = a.agentId ? this.manager.store?.get?.(a.agentId) ?? null : null;
|
|
132
135
|
const talk = a.discussId ? this.manager.store?.get?.(a.discussId) ?? null : null;
|
|
133
136
|
return {
|
|
@@ -139,6 +142,9 @@ export class MyActions {
|
|
|
139
142
|
from: a.from,
|
|
140
143
|
when: a.when,
|
|
141
144
|
due: a.due,
|
|
145
|
+
// The due date as a time, and in words ("overdue 2 days", "due Friday"), when it can be told.
|
|
146
|
+
dueAt: due?.toISOString() ?? null,
|
|
147
|
+
dueWords: dueWords(due, now),
|
|
142
148
|
context: a.context,
|
|
143
149
|
status: a.status,
|
|
144
150
|
group: GROUP[a.status] ?? 'open',
|