@jossuealcala/madre 1.0.4 → 1.1.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/ADDITIONAL-TERMS.md +7 -2
- package/CHANGELOG.en.md +152 -1
- package/CHANGELOG.md +152 -1
- package/CONTRIBUTING.md +2 -2
- package/LICENSE +111 -661
- package/NOTICE +59 -24
- package/README.en.md +36 -204
- package/README.md +36 -210
- package/SECURITY.md +1 -0
- package/TRADEMARKS.en.md +13 -14
- package/TRADEMARKS.md +42 -26
- package/bin/madre.cjs +2 -2
- package/bin/madre.mjs +114 -42
- package/docs/REFERENCE.md +53 -6
- package/docs/SDK.md +44 -5
- package/docs/en/REFERENCE.md +53 -6
- package/docs/en/SDK.md +43 -4
- package/docs/madre-banner.png +0 -0
- package/docs/sdk/hello-module.mjs +3 -0
- package/package.json +3 -2
- package/public/abduction.js +6 -6
- package/public/activity.js +425 -0
- package/public/app.js +3519 -647
- package/public/assets/abduction-cat-blink.webp +0 -0
- package/public/assets/abduction-cat-control-left.webp +0 -0
- package/public/assets/abduction-cat-control-right.webp +0 -0
- package/public/assets/abduction-cat.webp +0 -0
- package/public/assets/manual/shots/en-agents.webp +0 -0
- package/public/assets/manual/shots/en-chats.webp +0 -0
- package/public/assets/manual/shots/en-code.webp +0 -0
- package/public/assets/manual/shots/en-composer.webp +0 -0
- package/public/assets/manual/shots/en-connectors.webp +0 -0
- package/public/assets/manual/shots/en-continuity.webp +0 -0
- package/public/assets/manual/shots/en-coordinator.webp +0 -0
- package/public/assets/manual/shots/en-copilot.webp +0 -0
- package/public/assets/manual/shots/en-diagnostics.webp +0 -0
- package/public/assets/manual/shots/en-home.webp +0 -0
- package/public/assets/manual/shots/en-local.webp +0 -0
- package/public/assets/manual/shots/en-market.webp +0 -0
- package/public/assets/manual/shots/en-memory.webp +0 -0
- package/public/assets/manual/shots/en-modes.webp +0 -0
- package/public/assets/manual/shots/en-notes.webp +0 -0
- package/public/assets/manual/shots/en-settings.webp +0 -0
- package/public/assets/manual/shots/en-welcome.webp +0 -0
- package/public/assets/manual/shots/en-windows.webp +0 -0
- package/public/assets/manual/shots/es-agents.webp +0 -0
- package/public/assets/manual/shots/es-chats.webp +0 -0
- package/public/assets/manual/shots/es-code.webp +0 -0
- package/public/assets/manual/shots/es-composer.webp +0 -0
- package/public/assets/manual/shots/es-connectors.webp +0 -0
- package/public/assets/manual/shots/es-continuity.webp +0 -0
- package/public/assets/manual/shots/es-coordinator.webp +0 -0
- package/public/assets/manual/shots/es-copilot.webp +0 -0
- package/public/assets/manual/shots/es-diagnostics.webp +0 -0
- package/public/assets/manual/shots/es-home.webp +0 -0
- package/public/assets/manual/shots/es-local.webp +0 -0
- package/public/assets/manual/shots/es-market.webp +0 -0
- package/public/assets/manual/shots/es-memory.webp +0 -0
- package/public/assets/manual/shots/es-modes.webp +0 -0
- package/public/assets/manual/shots/es-notes.webp +0 -0
- package/public/assets/manual/shots/es-settings.webp +0 -0
- package/public/assets/manual/shots/es-welcome.webp +0 -0
- package/public/assets/manual/shots/es-windows.webp +0 -0
- package/public/assets/news/1.1/en/chats.webp +0 -0
- package/public/assets/news/1.1/en/home.webp +0 -0
- package/public/assets/news/1.1/en/maps.webp +0 -0
- package/public/assets/news/1.1/en/market.webp +0 -0
- package/public/assets/news/1.1/en/permissions.webp +0 -0
- package/public/assets/news/1.1/en/privacy.webp +0 -0
- package/public/assets/news/1.1/en/welcome.webp +0 -0
- package/public/assets/news/1.1/es/chats.webp +0 -0
- package/public/assets/news/1.1/es/home.webp +0 -0
- package/public/assets/news/1.1/es/maps.webp +0 -0
- package/public/assets/news/1.1/es/market.webp +0 -0
- package/public/assets/news/1.1/es/permissions.webp +0 -0
- package/public/assets/news/1.1/es/privacy.webp +0 -0
- package/public/assets/news/1.1/es/welcome.webp +0 -0
- package/public/attribution.js +15 -16
- package/public/brands.js +2 -2
- package/public/code-tools.js +2 -2
- package/public/editor.js +13 -13
- package/public/en.js +483 -0
- package/public/es.js +1817 -598
- package/public/hardware.js +2 -2
- package/public/i18n.js +47 -9
- package/public/icons.js +158 -0
- package/public/index.html +68 -51
- package/public/inquiry.js +2 -2
- package/public/loader.js +271 -2
- package/public/macroverso.js +60 -21
- package/public/manual-content.js +900 -0
- package/public/manual-shots.js +47 -0
- package/public/manual.css +246 -0
- package/public/manual.html +15 -0
- package/public/manual.js +427 -0
- package/public/market-art.js +99 -41
- package/public/market-view.js +243 -47
- package/public/market.js +139 -26
- package/public/mcp-catalog.js +62 -0
- package/public/neural.js +64 -8
- package/public/nostromo-engine.js +709 -40
- package/public/page-errors.js +29 -0
- package/public/power.js +350 -11
- package/public/remedy.js +89 -0
- package/public/resay.js +4 -2
- package/public/review-ask.js +12 -7
- package/public/routing.js +3 -3
- package/public/salas-mac.css +875 -48
- package/public/salas-mac.html +27 -15
- package/public/salas-mac.js +1668 -338
- package/public/salas.css +2 -2
- package/public/salas.html +3 -3
- package/public/salas.js +3 -3
- package/public/styles.css +2694 -323
- package/public/syntax.js +2 -2
- package/public/terms.js +152 -0
- package/public/touch.js +2 -2
- package/public/tour-chapters.js +100 -92
- package/public/tour.js +118 -28
- package/public/troubleshooting.js +327 -21
- package/public/wallpaper.js +4 -3
- package/public/welcome.js +923 -0
- package/src/activity.mjs +85 -0
- package/src/adapters/claude.mjs +61 -35
- package/src/adapters/codex.mjs +18 -5
- package/src/adapters/cursor.mjs +60 -9
- package/src/adapters/gemini.mjs +17 -4
- package/src/adapters/madre.mjs +30 -9
- package/src/adapters/opencode.mjs +73 -10
- package/src/adapters/process.mjs +19 -15
- package/src/adapters/subagents.mjs +159 -0
- package/src/asking.mjs +8 -2
- package/src/auth-probe.mjs +47 -11
- package/src/bridge/devices.mjs +2 -2
- package/src/bridge/handoff.mjs +2 -2
- package/src/bridge/host.mjs +2 -2
- package/src/bridge/network.mjs +2 -2
- package/src/bridge/policy.mjs +3 -3
- package/src/bridge/qr.mjs +2 -2
- package/src/bridge/server.mjs +3 -3
- package/src/builtin-updates.mjs +87 -0
- package/src/capabilities.mjs +5 -5
- package/src/chats.mjs +51 -2
- package/src/checkpoint.mjs +67 -9
- package/src/choices.mjs +2 -2
- package/src/cli-args.mjs +2 -2
- package/src/cold.mjs +2 -2
- package/src/commands.mjs +2 -2
- package/src/config.mjs +2 -2
- package/src/conversation-context.mjs +2 -2
- package/src/credentials.mjs +80 -18
- package/src/dataset.mjs +2 -2
- package/src/directives.mjs +2 -2
- package/src/distiller.mjs +2 -2
- package/src/embeddings.mjs +2 -2
- package/src/enlaces.mjs +2 -2
- package/src/environment.mjs +147 -0
- package/src/event-store.mjs +2 -2
- package/src/exam.mjs +2 -2
- package/src/extensions.mjs +2 -2
- package/src/eyecat-watch.mjs +2 -2
- package/src/eyecat.mjs +2 -2
- package/src/file-ops.mjs +2 -2
- package/src/files.mjs +2 -2
- package/src/github.mjs +2 -2
- package/src/heartbeat.mjs +2 -2
- package/src/history.mjs +76 -0
- package/src/i18n.mjs +32 -3
- package/src/image-studio.mjs +2 -2
- package/src/install-metrics.mjs +109 -0
- package/src/json-file.mjs +2 -2
- package/src/launch.mjs +2 -2
- package/src/lease.mjs +15 -4
- package/src/lobby-work.mjs +11 -4
- package/src/local-ai.mjs +12 -4
- package/src/looks.mjs +19 -7
- package/src/market-check.mjs +165 -0
- package/src/market-key.mjs +10 -2
- package/src/market-license.mjs +104 -0
- package/src/market-remote.mjs +71 -13
- package/src/maturity.mjs +2 -2
- package/src/mcp/connect.mjs +2 -2
- package/src/mcp/github-server.mjs +2 -2
- package/src/mcp/image-server.mjs +2 -2
- package/src/mcp/memory-server.mjs +2 -2
- package/src/mcp/proxy.mjs +16 -5
- package/src/mcp/smtp-server.mjs +2 -2
- package/src/memory-dashboard.mjs +2 -2
- package/src/memory-tools.mjs +2 -2
- package/src/memory.mjs +2 -2
- package/src/models.mjs +115 -12
- package/src/module-scope.mjs +2 -2
- package/src/modules/ahp.mjs +2 -2
- package/src/modules/ash-policy.mjs +2 -2
- package/src/modules/ash.mjs +2 -2
- package/src/modules/bishop-exam.mjs +2 -2
- package/src/modules/bishop-plan.mjs +2 -2
- package/src/modules/bishop.mjs +9 -3
- package/src/modules/choices.mjs +2 -2
- package/src/modules/correo.mjs +2 -2
- package/src/modules/enlaces.mjs +2 -2
- package/src/modules/git-pulse.mjs +2 -2
- package/src/modules/github.mjs +2 -2
- package/src/modules/helpers.mjs +2 -2
- package/src/modules/image-studio.mjs +2 -2
- package/src/modules/index.mjs +92 -5
- package/src/modules/intents-calibration.mjs +2 -2
- package/src/modules/intents-desk.mjs +4 -3
- package/src/modules/intents-observe.mjs +2 -2
- package/src/modules/intents-policy.mjs +2 -2
- package/src/modules/intents-try.mjs +2 -2
- package/src/modules/intents.mjs +2 -2
- package/src/modules/local-models.mjs +41 -10
- package/src/modules/mcp-connect.mjs +2 -2
- package/src/modules/notes.mjs +281 -0
- package/src/modules/ollama.mjs +48 -13
- package/src/modules/playwright.mjs +16 -5
- package/src/modules/reminders.mjs +664 -0
- package/src/modules/ripley.mjs +3 -3
- package/src/modules/runs.mjs +2 -2
- package/src/modules/sdk.mjs +57 -9
- package/src/modules/updates.mjs +2 -2
- package/src/mother.mjs +13 -3
- package/src/npm-launch.mjs +2 -2
- package/src/ollama.mjs +8 -6
- package/src/opencode-health.mjs +83 -0
- package/src/outbound.mjs +35 -3
- package/src/override.mjs +27 -22
- package/src/ports.mjs +2 -2
- package/src/prices.mjs +2 -2
- package/src/privacy.mjs +2 -2
- package/src/quota-monitor.mjs +2 -2
- package/src/quota-sources.mjs +2 -2
- package/src/request-guard.mjs +2 -2
- package/src/review-ask.mjs +4 -3
- package/src/room/archivist.mjs +2 -2
- package/src/room/attachments.mjs +2 -2
- package/src/room/budget.mjs +2 -2
- package/src/room/context.mjs +2 -2
- package/src/room/control.mjs +2 -2
- package/src/room/copilot.mjs +2 -2
- package/src/room/economy.mjs +2 -2
- package/src/room/escalation.mjs +2 -2
- package/src/room/ghost.mjs +2 -2
- package/src/room/guard.mjs +6 -4
- package/src/room/prompt.mjs +3 -3
- package/src/room/returns.mjs +2 -2
- package/src/room/runs.mjs +6 -4
- package/src/room/vectors.mjs +2 -2
- package/src/room.mjs +144 -36
- package/src/router.mjs +2 -2
- package/src/runs.mjs +2 -2
- package/src/runtime-detection.mjs +36 -6
- package/src/salas.mjs +31 -6
- package/src/sentinel-errors.mjs +17 -7
- package/src/server-sentinel.mjs +2 -2
- package/src/server.mjs +980 -139
- package/src/setup-trouble.mjs +33 -0
- package/src/setup.mjs +4 -4
- package/src/smtp.mjs +2 -2
- package/src/telemetry.mjs +266 -0
- package/src/terms.mjs +43 -0
- package/src/tour.mjs +60 -7
- package/src/uninstall.mjs +225 -0
- package/src/updates.mjs +2 -2
- package/src/usage-sentinel.mjs +2 -2
- package/src/vault.mjs +2 -2
- package/src/verdict.mjs +13 -10
- package/src/whats-new.mjs +97 -3
- package/public/assets/abduction-cat-blink.png +0 -0
- package/public/assets/abduction-cat-control-left.png +0 -0
- package/public/assets/abduction-cat-control-right.png +0 -0
- package/public/assets/abduction-cat.png +0 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// «En marcha» (2026-10-30): a key on the bar with how many things MADRE is doing, and under it a
|
|
4
|
+
// panel with each one — the agents answering, the plans, the commands and servers, an install —
|
|
5
|
+
// in every project open on this computer, what ended a moment ago, and the reminders coming. A
|
|
6
|
+
// person sees and stops it all from there, without a terminal. The server says it (src/activity.mjs,
|
|
7
|
+
// GET /api/activity?everywhere=1); a project's page and Home's mount the same panel.
|
|
8
|
+
import { language, t } from './i18n.js';
|
|
9
|
+
import { brandOf } from './brands.js';
|
|
10
|
+
import { trazo } from './icons.js';
|
|
11
|
+
|
|
12
|
+
// How often it asks: often while the panel is open, seldom for the number on the key, never while
|
|
13
|
+
// the page is out of sight.
|
|
14
|
+
const OPEN_EVERY_MS = 1500;
|
|
15
|
+
const CLOSED_EVERY_MS = 5000;
|
|
16
|
+
|
|
17
|
+
const el = (tag, cls, text) => {
|
|
18
|
+
const node = document.createElement(tag);
|
|
19
|
+
if (cls) node.className = cls;
|
|
20
|
+
if (text != null) node.textContent = text;
|
|
21
|
+
return node;
|
|
22
|
+
};
|
|
23
|
+
const clock = (ms) => {
|
|
24
|
+
const s = Math.max(0, Math.round(ms / 1000));
|
|
25
|
+
const h = Math.floor(s / 3600);
|
|
26
|
+
const m = Math.floor((s % 3600) / 60);
|
|
27
|
+
return h ? `${h}:${String(m).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}` : `${m}:${String(s % 60).padStart(2, '0')}`;
|
|
28
|
+
};
|
|
29
|
+
function ago(at, now = Date.now()) {
|
|
30
|
+
const minutes = Math.round((Date.parse(at) - now) / 60000);
|
|
31
|
+
if (Math.abs(minutes) < 1) return t('just now');
|
|
32
|
+
const words = new Intl.RelativeTimeFormat(language() === 'en' ? 'en' : 'es-MX', { numeric: 'auto', style: 'short' });
|
|
33
|
+
return Math.abs(minutes) < 60 ? words.format(minutes, 'minute') : words.format(Math.round(minutes / 60), 'hour');
|
|
34
|
+
}
|
|
35
|
+
// What a project is called in the panel: its folder's name, or the Coordinator for Home's own chats.
|
|
36
|
+
const whereOf = (project) => (project.home ? t('Coordinator') : project.name ?? project.room);
|
|
37
|
+
// What runs, counted for the key: a plan once (its steps are inside it), never an outdated project.
|
|
38
|
+
const counted = (one) => one.kind !== 'turn' || !one.planId;
|
|
39
|
+
|
|
40
|
+
function avatar(agent, { busy = false } = {}) {
|
|
41
|
+
const brand = brandOf(agent);
|
|
42
|
+
const face = el('span', `ap-av${busy ? ' busy' : ''}`);
|
|
43
|
+
face.style.setProperty('--ap-c', brand.color);
|
|
44
|
+
face.style.color = brand.ink;
|
|
45
|
+
face.innerHTML = brand.mark(); // trusted: the brands' own SVG
|
|
46
|
+
face.title = brand.label;
|
|
47
|
+
return face;
|
|
48
|
+
}
|
|
49
|
+
function sysAvatar(icon, { busy = false } = {}) {
|
|
50
|
+
const face = el('span', `ap-av sys${busy ? ' busy' : ''}`);
|
|
51
|
+
face.innerHTML = trazo(icon); // trusted: our own SVG
|
|
52
|
+
return face;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Mounts «En marcha» on a key of the bar.
|
|
57
|
+
* key: the button; badge: where the number goes; openChat({ project, chat, messageId }) opens a
|
|
58
|
+
* conversation of THIS page's project (a project elsewhere opens in its own tab); toast(words).
|
|
59
|
+
*/
|
|
60
|
+
export function mountActivity({ key, badge, openChat, toast = () => {} }) {
|
|
61
|
+
if (!key) return null;
|
|
62
|
+
const state = { data: null, said: '', open: false, timer: 0, ticking: 0, opened: new Set(), confirmAll: 0, failing: 0, pressing: false, stale: false };
|
|
63
|
+
const panel = el('div', 'activity-panel');
|
|
64
|
+
panel.setAttribute('role', 'dialog');
|
|
65
|
+
panel.setAttribute('aria-label', t('Running now'));
|
|
66
|
+
panel.hidden = true;
|
|
67
|
+
document.body.append(panel);
|
|
68
|
+
key.setAttribute('aria-haspopup', 'dialog');
|
|
69
|
+
key.setAttribute('aria-expanded', 'false');
|
|
70
|
+
|
|
71
|
+
async function load() {
|
|
72
|
+
try {
|
|
73
|
+
const response = await fetch('/api/activity?everywhere=1', { cache: 'no-store' });
|
|
74
|
+
if (!response.ok) throw new Error(String(response.status));
|
|
75
|
+
const answer = await response.json();
|
|
76
|
+
// Drawn again only when something changed: a panel rebuilt every second and a half swallowed
|
|
77
|
+
// the click that landed between two drawings, and took the keyboard's place away. The clocks
|
|
78
|
+
// move on their own (the tickers).
|
|
79
|
+
const said = JSON.stringify({ projects: answer.projects, soon: answer.soon });
|
|
80
|
+
const changed = said !== state.said || state.failing > 0;
|
|
81
|
+
state.data = { ...answer, received: Date.now() };
|
|
82
|
+
state.said = said;
|
|
83
|
+
state.failing = 0;
|
|
84
|
+
paintKey();
|
|
85
|
+
if (state.open && changed) repaint();
|
|
86
|
+
return;
|
|
87
|
+
} catch {
|
|
88
|
+
state.failing += 1;
|
|
89
|
+
}
|
|
90
|
+
paintKey();
|
|
91
|
+
if (state.open) repaint();
|
|
92
|
+
}
|
|
93
|
+
// Never under a finger: what changed while the person presses waits until they let go.
|
|
94
|
+
function repaint() {
|
|
95
|
+
if (state.pressing) { state.stale = true; return; }
|
|
96
|
+
paint();
|
|
97
|
+
}
|
|
98
|
+
panel.addEventListener('pointerdown', () => { state.pressing = true; });
|
|
99
|
+
const letGo = () => { if (!state.pressing) return; state.pressing = false; if (state.stale) { state.stale = false; setTimeout(() => { if (state.open) paint(); }, 0); } };
|
|
100
|
+
document.addEventListener?.('pointerup', letGo, true);
|
|
101
|
+
document.addEventListener?.('pointercancel', letGo, true);
|
|
102
|
+
function schedule() {
|
|
103
|
+
clearTimeout(state.timer);
|
|
104
|
+
if (document.visibilityState === 'hidden') return;
|
|
105
|
+
state.timer = setTimeout(async () => { await load(); schedule(); }, state.open ? OPEN_EVERY_MS : CLOSED_EVERY_MS);
|
|
106
|
+
// Where timers can hold a process open (the tests run this page in Node), this one never does.
|
|
107
|
+
state.timer?.unref?.();
|
|
108
|
+
}
|
|
109
|
+
document.addEventListener?.('visibilitychange', () => { if (document.visibilityState === 'visible') { void load(); schedule(); } else clearTimeout(state.timer); });
|
|
110
|
+
|
|
111
|
+
const projects = () => (state.data?.projects ?? []).filter((one) => !one.outdated);
|
|
112
|
+
const running = () => projects().flatMap((project) => (project.now ?? []).filter(counted).map((one) => ({ project, one })));
|
|
113
|
+
|
|
114
|
+
function paintKey() {
|
|
115
|
+
const n = running().length;
|
|
116
|
+
key.classList.toggle('working', n > 0);
|
|
117
|
+
key.title = n ? t('Running now · {n}', { n }) : t('Running now · nothing at the moment');
|
|
118
|
+
key.setAttribute('aria-label', key.title);
|
|
119
|
+
if (badge) { badge.hidden = !n; badge.textContent = n ? String(n) : ''; }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Where an action goes: the project it belongs to, through this page's own server.
|
|
123
|
+
async function stop(project, item) {
|
|
124
|
+
const body = { room: project.here ? null : project.room, kind: item.kind, chat: item.chat ?? null, messageId: item.messageId, planId: item.planId, id: item.id };
|
|
125
|
+
const response = await fetch('/api/activity/stop', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) }).catch(() => null);
|
|
126
|
+
const answer = await response?.json().catch(() => ({}));
|
|
127
|
+
if (!response?.ok) toast(answer?.error ?? t('It could not be stopped. Try again.'));
|
|
128
|
+
await load();
|
|
129
|
+
}
|
|
130
|
+
async function stopAll() {
|
|
131
|
+
const response = await fetch('/api/activity/stop-all', { method: 'POST', headers: { 'content-type': 'application/json' }, body: '{}' }).catch(() => null);
|
|
132
|
+
if (!response?.ok) toast(t('It could not be stopped. Try again.'));
|
|
133
|
+
state.confirmAll = 0;
|
|
134
|
+
await load();
|
|
135
|
+
}
|
|
136
|
+
function goTo(project, chat, messageId) {
|
|
137
|
+
if (!chat) return;
|
|
138
|
+
if (project.here) { close(); openChat?.({ chat, messageId }); return; }
|
|
139
|
+
window.open(`http://127.0.0.1:${project.port}/#chat=${encodeURIComponent(chat)}${messageId ? `:${encodeURIComponent(messageId)}` : ''}`, '_blank', 'noopener');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// One line of the panel, folded or open: what it is, where, how long, and what can be done.
|
|
143
|
+
function row({ id, face, title, sub, time, timeTone = '', progress = null, more = null, tint = null }) {
|
|
144
|
+
const open = state.opened.has(id);
|
|
145
|
+
const box = el('div', `ap-row${open ? ' open' : ''}`);
|
|
146
|
+
if (tint) box.style.setProperty('--ap-c', tint);
|
|
147
|
+
const line = el('button', 'ap-line');
|
|
148
|
+
line.type = 'button';
|
|
149
|
+
line.setAttribute('aria-expanded', String(open));
|
|
150
|
+
const words = el('span', 'ap-words');
|
|
151
|
+
words.append(el('b', null, title), el('span', null, sub));
|
|
152
|
+
const when = el('span', `ap-time${timeTone ? ` ${timeTone}` : ''}`);
|
|
153
|
+
if (typeof time === 'function') { when.dataset.tick = '1'; when.textContent = time(); state.tickers.push(() => { when.textContent = time(); }); } else when.textContent = time ?? '';
|
|
154
|
+
const chev = el('span', 'ap-chev');
|
|
155
|
+
chev.innerHTML = trazo('next'); // trusted: our own SVG
|
|
156
|
+
line.append(face, words, when, chev);
|
|
157
|
+
if (progress) {
|
|
158
|
+
const bar = el('span', 'ap-bar');
|
|
159
|
+
const fill = el('i');
|
|
160
|
+
const set = () => { fill.style.width = `${Math.round(Math.min(1, Math.max(0, progress())) * 100)}%`; };
|
|
161
|
+
set();
|
|
162
|
+
state.tickers.push(set);
|
|
163
|
+
bar.append(fill);
|
|
164
|
+
line.append(bar);
|
|
165
|
+
}
|
|
166
|
+
line.addEventListener('click', () => { if (state.opened.has(id)) state.opened.delete(id); else state.opened.add(id); paint(); });
|
|
167
|
+
box.append(line);
|
|
168
|
+
if (open && more) {
|
|
169
|
+
const inside = el('div', 'ap-more');
|
|
170
|
+
more(inside);
|
|
171
|
+
box.append(inside);
|
|
172
|
+
}
|
|
173
|
+
return box;
|
|
174
|
+
}
|
|
175
|
+
const actions = (...buttons) => {
|
|
176
|
+
const bar = el('div', 'ap-acts');
|
|
177
|
+
for (const [words, tone, act] of buttons) {
|
|
178
|
+
const button = el('button', tone || null, words);
|
|
179
|
+
button.type = 'button';
|
|
180
|
+
button.addEventListener('click', async (event) => {
|
|
181
|
+
event.stopPropagation();
|
|
182
|
+
button.disabled = true;
|
|
183
|
+
try { await act(); } finally { button.disabled = false; }
|
|
184
|
+
});
|
|
185
|
+
bar.append(button);
|
|
186
|
+
}
|
|
187
|
+
return bar;
|
|
188
|
+
};
|
|
189
|
+
const skew = () => (state.data?.at ? Date.parse(state.data.at) - (state.data.received ?? Date.now()) : 0);
|
|
190
|
+
const since = (at) => () => Date.now() + skew() - at;
|
|
191
|
+
|
|
192
|
+
// An AI's own subagents, one chip each: what it was given, and whether it is still at it.
|
|
193
|
+
function subChips(helpers) {
|
|
194
|
+
const chips = el('div', 'ap-subs');
|
|
195
|
+
for (const one of helpers) {
|
|
196
|
+
const chip = el('span', `ap-sub ${one.status}`);
|
|
197
|
+
chip.append(el('i'), el('b', null, one.kind ?? t('subagent')), document.createTextNode(` ${one.task ?? ''}`));
|
|
198
|
+
if (Number.isFinite(one.seconds)) chip.append(el('em', null, clock(one.seconds * 1000)));
|
|
199
|
+
chips.append(chip);
|
|
200
|
+
}
|
|
201
|
+
return chips;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function nowRow(project, item, steps) {
|
|
205
|
+
const where = [whereOf(project), item.chatTitle].filter(Boolean).join(' · ');
|
|
206
|
+
const uid = `${project.room}:${item.kind}:${item.messageId ?? item.planId ?? item.id ?? item.what}`;
|
|
207
|
+
if (item.kind === 'turn') {
|
|
208
|
+
const helpers = item.subagents ?? [];
|
|
209
|
+
const busy = helpers.filter((one) => one.status === 'running').length;
|
|
210
|
+
const doing = busy ? t('{n} subagents at work', { n: busy }) : t('Working on it…');
|
|
211
|
+
return row({
|
|
212
|
+
id: uid, face: avatar(item.agent, { busy: true }), tint: brandOf(item.agent).color,
|
|
213
|
+
title: item.text || t('A turn of {agent}', { agent: brandOf(item.agent).label }),
|
|
214
|
+
sub: `${where} · ${doing}`,
|
|
215
|
+
time: item.timeoutMs ? () => t('{now} of {limit}', { now: clock(since(item.startedAt)()), limit: clock(item.timeoutMs) }) : () => clock(since(item.startedAt)()),
|
|
216
|
+
progress: item.timeoutMs ? () => since(item.startedAt)() / item.timeoutMs : null,
|
|
217
|
+
more: (inside) => {
|
|
218
|
+
if (helpers.length) inside.append(subChips(helpers));
|
|
219
|
+
inside.append(el('p', 'ap-meta', item.timeoutMs ? t('With your permission #{mode} · the limit counts from when it started', { mode: item.mode ?? 1 }) : t('With your permission #{mode}', { mode: item.mode ?? 1 })));
|
|
220
|
+
inside.append(actions([t('Go to the chat'), 'go', () => goTo(project, item.chat, item.messageId)], [t('Stop'), 'stop', () => stop(project, item)]));
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (item.kind === 'plan') {
|
|
225
|
+
return row({
|
|
226
|
+
id: uid, face: avatar(item.orchestrator, { busy: true }), tint: brandOf(item.orchestrator).color,
|
|
227
|
+
title: t('Plan by {agent} · {n} steps', { agent: brandOf(item.orchestrator).label, n: item.total }),
|
|
228
|
+
sub: `${where} · ${t('Step {step} of {total}', { step: Math.max(1, item.step), total: item.total })}${steps.length ? ` · ${t('{agent} is answering', { agent: brandOf(steps[0].agent).label })}` : ''}`,
|
|
229
|
+
time: () => clock(since(item.startedAt)()),
|
|
230
|
+
progress: () => Math.max(0, item.step - 1) / Math.max(1, item.total),
|
|
231
|
+
more: (inside) => {
|
|
232
|
+
const list = el('ol', 'ap-steps');
|
|
233
|
+
(item.steps ?? []).forEach((step, index) => {
|
|
234
|
+
const li = el('li', index + 1 < item.step ? 'done' : index + 1 === item.step ? 'now' : '');
|
|
235
|
+
li.append(el('b', null, brandOf(step.agent).label), document.createTextNode(` ${step.text}`));
|
|
236
|
+
list.append(li);
|
|
237
|
+
});
|
|
238
|
+
// The last step is the one who made the plan reading the answers: counted, so it is listed.
|
|
239
|
+
const listed = item.steps?.length ?? 0;
|
|
240
|
+
if (item.total > listed) {
|
|
241
|
+
const li = el('li', item.step > listed ? 'now' : '');
|
|
242
|
+
li.append(el('b', null, brandOf(item.orchestrator).label), document.createTextNode(` ${t('reads the answers and closes the plan')}`));
|
|
243
|
+
list.append(li);
|
|
244
|
+
}
|
|
245
|
+
inside.append(list);
|
|
246
|
+
for (const turn of steps) {
|
|
247
|
+
const said = el('p', 'ap-meta', t('{agent} is answering step {step} · {time}', { agent: brandOf(turn.agent).label, step: item.step, time: clock(since(turn.startedAt)()) }));
|
|
248
|
+
state.tickers.push(() => { said.textContent = t('{agent} is answering step {step} · {time}', { agent: brandOf(turn.agent).label, step: item.step, time: clock(since(turn.startedAt)()) }); });
|
|
249
|
+
inside.append(said);
|
|
250
|
+
if (turn.subagents?.length) inside.append(subChips(turn.subagents));
|
|
251
|
+
}
|
|
252
|
+
inside.append(actions([t('Go to the chat'), 'go', () => goTo(project, item.chat)], [t('Stop the plan'), 'stop', () => stop(project, item)]));
|
|
253
|
+
},
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (item.kind === 'run') {
|
|
257
|
+
const serving = item.serving;
|
|
258
|
+
const host = serving ? (serving.host === '0.0.0.0' || serving.host === '::' ? '127.0.0.1' : serving.host) : null;
|
|
259
|
+
return row({
|
|
260
|
+
id: uid, face: sysAvatar(serving ? 'server' : 'mod-runs', { busy: !serving }),
|
|
261
|
+
title: `$ ${item.line ?? ''}`,
|
|
262
|
+
sub: `${where} · ${serving ? t('Listening on {host}:{port}', { host, port: serving.port }) : t('Running…')}`,
|
|
263
|
+
time: () => clock(since(item.startedAt)()),
|
|
264
|
+
more: (inside) => {
|
|
265
|
+
if (item.agent) inside.append(el('p', 'ap-meta', t('Asked by {agent}', { agent: brandOf(item.agent).label })));
|
|
266
|
+
const keys = [];
|
|
267
|
+
if (serving) keys.push([t('Open'), 'go', () => { window.open(`http://${host.includes(':') ? `[${host}]` : host}:${serving.port}/`, '_blank', 'noopener'); }]);
|
|
268
|
+
keys.push([t('Go to the chat'), '', () => goTo(project, item.chat, item.responseMessageId)]);
|
|
269
|
+
keys.push([serving ? t('Stop the server') : t('Stop'), 'stop', () => stop(project, item)]);
|
|
270
|
+
inside.append(actions(...keys));
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
// An install: an agent's program, Ollama or a model it downloads, or a module.
|
|
275
|
+
const what = String(item.what ?? '');
|
|
276
|
+
const title = what.startsWith('agent:') ? t('Installing {name}', { name: brandOf(what.slice(6)).label })
|
|
277
|
+
: what === 'ollama' ? (item.model ? t('Downloading {name}', { name: item.model }) : t('Installing {name}', { name: 'Ollama' }))
|
|
278
|
+
: t('Installing the module {name}', { name: what });
|
|
279
|
+
return row({
|
|
280
|
+
id: uid, face: sysAvatar('download', { busy: true }), title,
|
|
281
|
+
sub: `${project.home ? t('Home') : whereOf(project)} · ${t('It ends on its own; you can keep working.')}`,
|
|
282
|
+
time: item.startedAt ? () => clock(since(item.startedAt)()) : '',
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
function doneRow(project, item) {
|
|
287
|
+
const where = [whereOf(project), item.chatTitle].filter(Boolean).join(' · ');
|
|
288
|
+
const said = item.state === 'ok' ? (item.tookMs != null ? t('Answered in {time}', { time: clock(item.tookMs) }) : t('Answered'))
|
|
289
|
+
: item.state === 'stopped' ? t('You stopped it')
|
|
290
|
+
: item.timeout ? t('Ran out of time') : t('Could not answer');
|
|
291
|
+
const mark = { ok: '✓', failed: '✕', stopped: '■' }[item.state];
|
|
292
|
+
const face = avatar(item.agent);
|
|
293
|
+
face.classList.add('still');
|
|
294
|
+
return row({
|
|
295
|
+
id: `${project.room}:done:${item.messageId}:${item.at}`, face,
|
|
296
|
+
title: item.closing ? `${brandOf(item.agent).label} ${t('reads the answers and closes the plan')}` : item.text || t('A turn of {agent}', { agent: brandOf(item.agent).label }),
|
|
297
|
+
sub: `${where} · ${said}`,
|
|
298
|
+
time: `${mark} ${ago(item.at)}`,
|
|
299
|
+
timeTone: item.state === 'ok' ? 'ok' : item.state === 'failed' ? 'fail' : '',
|
|
300
|
+
more: (inside) => {
|
|
301
|
+
if (item.error) inside.append(el('pre', 'ap-out', item.error));
|
|
302
|
+
inside.append(actions([t('Go to the chat'), 'go', () => goTo(project, item.chat, item.messageId)]));
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function section(title, rows, { quiet = false } = {}) {
|
|
308
|
+
if (!rows.length) return null;
|
|
309
|
+
const box = el('section', 'ap-sec');
|
|
310
|
+
box.append(el('h4', quiet ? 'quiet' : null, title));
|
|
311
|
+
box.append(...rows);
|
|
312
|
+
return box;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function paint() {
|
|
316
|
+
state.tickers = [];
|
|
317
|
+
// The key the keyboard was on comes back after the drawing, found by what it says and where.
|
|
318
|
+
const focused = panel.contains(document.activeElement) ? [...panel.querySelectorAll('button')].indexOf(document.activeElement) : -1;
|
|
319
|
+
const focusedWords = focused >= 0 ? document.activeElement.textContent : null;
|
|
320
|
+
const scroll = panel.querySelector('.ap-scroll');
|
|
321
|
+
const kept = scroll?.scrollTop ?? 0;
|
|
322
|
+
panel.replaceChildren();
|
|
323
|
+
const head = el('header', 'ap-head');
|
|
324
|
+
const name = el('h3', null, t('Running now'));
|
|
325
|
+
const count = running().length;
|
|
326
|
+
const shut = el('button', 'ap-x');
|
|
327
|
+
shut.type = 'button';
|
|
328
|
+
shut.setAttribute('aria-label', t('Close'));
|
|
329
|
+
shut.innerHTML = trazo('close'); // trusted: our own SVG
|
|
330
|
+
shut.addEventListener('click', close);
|
|
331
|
+
head.append(name, el('small', null, count ? t('{n} now', { n: count }) : ''), el('span', 'ap-grow'), shut);
|
|
332
|
+
panel.append(head);
|
|
333
|
+
const body = el('div', 'ap-scroll');
|
|
334
|
+
if (!state.data) {
|
|
335
|
+
body.append(el('p', 'ap-wait', state.failing ? t('MADRE did not answer. Trying again…') : t('Asking every open project…')));
|
|
336
|
+
} else {
|
|
337
|
+
const now = [];
|
|
338
|
+
const done = [];
|
|
339
|
+
const outdated = [];
|
|
340
|
+
for (const project of state.data.projects ?? []) {
|
|
341
|
+
if (project.outdated) { outdated.push(project); continue; }
|
|
342
|
+
const items = project.now ?? [];
|
|
343
|
+
for (const item of items.filter(counted)) now.push(nowRow(project, item, item.kind === 'plan' ? items.filter((one) => one.kind === 'turn' && one.planId === item.planId) : []));
|
|
344
|
+
for (const item of project.done ?? []) done.push({ at: item.at, node: () => doneRow(project, item) });
|
|
345
|
+
}
|
|
346
|
+
const soon = (state.data.soon ?? []).map((one) => row({
|
|
347
|
+
id: `soon:${one.id}`, face: sysAvatar('mod-reminders'), title: one.text,
|
|
348
|
+
sub: [one.project ?? t('Home'), new Intl.DateTimeFormat(language() === 'en' ? 'en-US' : 'es-MX', { hour: 'numeric', minute: '2-digit' }).format(new Date(one.due))].join(' · '),
|
|
349
|
+
time: ago(one.due),
|
|
350
|
+
}));
|
|
351
|
+
if (!now.length) {
|
|
352
|
+
const calm = el('div', 'ap-calm');
|
|
353
|
+
calm.innerHTML = trazo('check'); // trusted: our own SVG
|
|
354
|
+
calm.append(el('b', null, t('Nothing running')), el('span', null, t('When an agent answers, a command runs or something installs, you will see it here and can stop it.')));
|
|
355
|
+
body.append(calm);
|
|
356
|
+
}
|
|
357
|
+
for (const part of [
|
|
358
|
+
section(t('Now'), now),
|
|
359
|
+
section(t('Ended a moment ago'), done.sort((a, b) => String(b.at).localeCompare(String(a.at))).slice(0, 8).map((one) => one.node()), { quiet: true }),
|
|
360
|
+
section(t('Reminders coming up'), soon, { quiet: true }),
|
|
361
|
+
]) if (part) body.append(part);
|
|
362
|
+
for (const project of outdated) body.append(el('p', 'ap-meta ap-old', t('{name} runs an older MADRE: update it to see here what it does.', { name: whereOf(project) })));
|
|
363
|
+
}
|
|
364
|
+
panel.append(body);
|
|
365
|
+
body.scrollTop = kept;
|
|
366
|
+
if (count) {
|
|
367
|
+
const foot = el('footer', 'ap-foot');
|
|
368
|
+
const places = new Set(running().map(({ project }) => project.room)).size;
|
|
369
|
+
foot.append(el('span', null, places > 1 ? t('In {n} projects', { n: places }) : ''));
|
|
370
|
+
const all = el('button', 'stop', state.confirmAll > Date.now() ? t('Stop everything? Yes') : t('Stop everything'));
|
|
371
|
+
all.type = 'button';
|
|
372
|
+
all.addEventListener('click', () => {
|
|
373
|
+
if (state.confirmAll > Date.now()) { void stopAll(); return; }
|
|
374
|
+
state.confirmAll = Date.now() + 4000;
|
|
375
|
+
paint();
|
|
376
|
+
setTimeout(() => { if (state.confirmAll && state.confirmAll <= Date.now()) { state.confirmAll = 0; if (state.open) paint(); } }, 4100);
|
|
377
|
+
});
|
|
378
|
+
foot.append(all);
|
|
379
|
+
panel.append(foot);
|
|
380
|
+
}
|
|
381
|
+
place();
|
|
382
|
+
if (focused >= 0) {
|
|
383
|
+
const buttons = [...panel.querySelectorAll('button')];
|
|
384
|
+
(buttons.find((one) => one.textContent === focusedWords) ?? buttons[Math.min(focused, buttons.length - 1)])?.focus({ preventScroll: true });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Under its key on a wide window; a sheet from the bottom on a narrow one (styles.css).
|
|
389
|
+
function place() {
|
|
390
|
+
const box = key.getBoundingClientRect();
|
|
391
|
+
panel.style.setProperty('--ap-top', `${Math.round(box.bottom + 8)}px`);
|
|
392
|
+
panel.style.setProperty('--ap-right', `${Math.max(12, Math.round(window.innerWidth - box.right - 8))}px`);
|
|
393
|
+
}
|
|
394
|
+
function openPanel() {
|
|
395
|
+
state.open = true;
|
|
396
|
+
panel.hidden = false;
|
|
397
|
+
key.classList.add('on');
|
|
398
|
+
key.setAttribute('aria-expanded', 'true');
|
|
399
|
+
paint();
|
|
400
|
+
void load();
|
|
401
|
+
schedule();
|
|
402
|
+
clearInterval(state.ticking);
|
|
403
|
+
state.ticking = setInterval(() => { for (const tick of state.tickers ?? []) tick(); }, 1000);
|
|
404
|
+
state.ticking?.unref?.();
|
|
405
|
+
requestAnimationFrame(() => panel.classList.add('shown'));
|
|
406
|
+
}
|
|
407
|
+
function close() {
|
|
408
|
+
if (!state.open) return;
|
|
409
|
+
state.open = false;
|
|
410
|
+
panel.classList.remove('shown');
|
|
411
|
+
panel.hidden = true;
|
|
412
|
+
key.classList.remove('on');
|
|
413
|
+
key.setAttribute('aria-expanded', 'false');
|
|
414
|
+
clearInterval(state.ticking);
|
|
415
|
+
schedule();
|
|
416
|
+
}
|
|
417
|
+
key.addEventListener('click', () => (state.open ? close() : openPanel()));
|
|
418
|
+
document.addEventListener?.('keydown', (event) => { if (event.key === 'Escape' && state.open) { close(); key.focus(); } });
|
|
419
|
+
document.addEventListener?.('pointerdown', (event) => { if (state.open && !panel.contains(event.target) && !key.contains(event.target)) close(); }, true);
|
|
420
|
+
globalThis.addEventListener?.('resize', () => { if (state.open) place(); });
|
|
421
|
+
|
|
422
|
+
void load();
|
|
423
|
+
schedule();
|
|
424
|
+
return { open: openPanel, close, refresh: load };
|
|
425
|
+
}
|