@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,923 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// THE WELCOME of 1.0.6 (2026-10-28, docs/private/BIENVENIDA-1.0.6.md): after `npx madre`, the
|
|
4
|
+
// person never needs the terminal again. Seven steps leave MADRE ready — the agents, an AI on the
|
|
5
|
+
// computer when it can carry one, the memory's search and the first project — each adapted to where
|
|
6
|
+
// MADRE runs (src/environment.mjs: macOS, Linux, WSL, a virtual machine, SSH) and to what the
|
|
7
|
+
// computer can do (src/modules/local-models.mjs). Every step can be left for later and says what is
|
|
8
|
+
// lost; a failure is said in the same step, in plain words, with the way out.
|
|
9
|
+
//
|
|
10
|
+
// Where the person is lives in ~/.pulse/tour.json (src/tour.mjs, `welcome`), not in the browser:
|
|
11
|
+
// closing the page halfway brings them back to the same step, from any project or port.
|
|
12
|
+
//
|
|
13
|
+
// The host page hands in what only it can do: `agentsPanel(options)` and `projectPicker(options)`
|
|
14
|
+
// (Home's own), `mark(id, size)`, `closeKey(onClick)`, `projects()`, `openProject(room)`,
|
|
15
|
+
// `setLanguage(code)`, `agentState(agent, answer)`, `openLinks()`, `openMarket()`, `saved(welcome)`
|
|
16
|
+
// and `closed()`.
|
|
17
|
+
|
|
18
|
+
import { t, language } from './i18n.js';
|
|
19
|
+
import { platformOf, remedyKey } from './remedy.js';
|
|
20
|
+
import { MADRE_LOGO as BRAND_LOGO, playOpening } from './loader.js';
|
|
21
|
+
import { trazo } from './icons.js';
|
|
22
|
+
|
|
23
|
+
const el = (tag, className = null, text = null) => {
|
|
24
|
+
const node = document.createElement(tag);
|
|
25
|
+
if (className) node.className = className;
|
|
26
|
+
if (text !== null && text !== undefined) node.textContent = text;
|
|
27
|
+
return node;
|
|
28
|
+
};
|
|
29
|
+
const button = (className, text, onClick) => {
|
|
30
|
+
const node = el('button', className, text);
|
|
31
|
+
node.type = 'button';
|
|
32
|
+
if (onClick) node.addEventListener('click', onClick);
|
|
33
|
+
return node;
|
|
34
|
+
};
|
|
35
|
+
const post = async (url, payload = {}) => {
|
|
36
|
+
try {
|
|
37
|
+
const response = await fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(payload) });
|
|
38
|
+
const body = await response.json().catch(() => ({}));
|
|
39
|
+
if (typeof body.error === 'string') body.error = t(body.error);
|
|
40
|
+
return { ok: response.ok, status: response.status, body };
|
|
41
|
+
} catch { return { ok: false, status: 0, body: { error: t('MADRE did not answer. Check that it is still open.') } }; }
|
|
42
|
+
};
|
|
43
|
+
const getJson = (url) => fetch(url, { cache: 'no-store' }).then((response) => (response.ok ? response.json() : null)).catch(() => null);
|
|
44
|
+
const number = (value) => new Intl.NumberFormat(language(), { maximumFractionDigits: 1 }).format(value);
|
|
45
|
+
|
|
46
|
+
export const WELCOME_STEPS = ['hello', 'machine', 'agents', 'ai', 'memory', 'project', 'ready'];
|
|
47
|
+
const STEP_NAMES = {
|
|
48
|
+
hello: () => t('Hello'), machine: () => t('Your computer'), agents: () => t('Your agents'), ai: () => t('AI on your computer'),
|
|
49
|
+
memory: () => t('Memory'), project: () => t('Your project'), ready: () => t('Ready'),
|
|
50
|
+
};
|
|
51
|
+
// Ollama's own installer for Linux, shown to copy where it asks for the administrator's password: MADRE
|
|
52
|
+
// never asks for a password nor keeps one (src/modules/ollama.mjs, NEEDS_PASSWORD).
|
|
53
|
+
const OLLAMA_SCRIPT = 'curl -fsSL https://ollama.com/install.sh | sh';
|
|
54
|
+
const OLLAMA_DOWNLOAD = 'https://ollama.com/download';
|
|
55
|
+
// The memory's model for search by meaning (src/ollama.mjs, RECOMMENDED.embed), and what it weighs.
|
|
56
|
+
const EMBED_MODEL = 'nomic-embed-text';
|
|
57
|
+
const EMBED_MB = 274;
|
|
58
|
+
const EMBEDDING = /embed|minilm|bge|nomic/i;
|
|
59
|
+
const TICK = trazo('check');
|
|
60
|
+
|
|
61
|
+
// What a failed install or download said, in one word (src/setup-trouble.mjs), in plain words.
|
|
62
|
+
const TROUBLE = {
|
|
63
|
+
network: () => t('It could not download: there is no internet connection, or something on this network blocked it. Check your connection and try again.'),
|
|
64
|
+
disk: () => t('There is not enough free space on this computer. Free up some space or choose a smaller model.'),
|
|
65
|
+
permission: () => t('This computer did not let MADRE install it. Copy the line below into a terminal, once.'),
|
|
66
|
+
timeout: () => t('It took too long and was stopped. Try again.'),
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// The card of Diagnostics that explains each of those, with its steps for this system (remedy.js).
|
|
70
|
+
const TROUBLE_CARD = { network: 'install-offline', disk: 'disk-full', permission: 'install-needs-admin', timeout: 'install-offline', 'npm-missing': 'node-missing' };
|
|
71
|
+
|
|
72
|
+
// Ollama prints each piece it downloads as «pulling <digest> · 45%» (src/ollama.mjs, pullModel). The
|
|
73
|
+
// first piece is the model itself, by far the heaviest: its share is the download's.
|
|
74
|
+
const PULL_LINE = /^pulling ([0-9a-f]{6,})\b.*?(\d{1,3})%\s*$/;
|
|
75
|
+
|
|
76
|
+
// THE OPENING plays before the first step (loader.js, shared with the projects).
|
|
77
|
+
|
|
78
|
+
let current = null;
|
|
79
|
+
export const welcomeOpen = () => Boolean(current);
|
|
80
|
+
|
|
81
|
+
export function openWelcome({ at = null, then = null, host = {} } = {}) {
|
|
82
|
+
if (current) { if (at) current.go(at); return current; }
|
|
83
|
+
const dialog = el('dialog', 'wl');
|
|
84
|
+
dialog.setAttribute('aria-label', t('Welcome to MADRE'));
|
|
85
|
+
const shell = el('div', 'wl-window');
|
|
86
|
+
const rail = el('nav', 'wl-rail');
|
|
87
|
+
rail.setAttribute('aria-label', t('Steps'));
|
|
88
|
+
const main = el('section', 'wl-main');
|
|
89
|
+
const content = el('div', 'wl-content');
|
|
90
|
+
const actions = el('div', 'wl-actions');
|
|
91
|
+
const close = host.closeKey?.(() => dialog.close()) ?? button('wl-close', '×', () => dialog.close());
|
|
92
|
+
close.classList.add('wl-close');
|
|
93
|
+
main.append(close, content, actions);
|
|
94
|
+
shell.append(rail, main);
|
|
95
|
+
dialog.append(shell);
|
|
96
|
+
document.body.append(dialog);
|
|
97
|
+
|
|
98
|
+
// Everything the steps decide on, read once when it opens and again when it changes.
|
|
99
|
+
const s = {
|
|
100
|
+
step: 0,
|
|
101
|
+
progress: { at: null, done: [], skipped: [], finished: null },
|
|
102
|
+
env: null, hardware: null, geminiKey: false, memory: null,
|
|
103
|
+
ollama: null, recommended: null,
|
|
104
|
+
choice: null, // the AI step: here · windows · remote · skip
|
|
105
|
+
model: null, // the model chosen for this computer (a rung of the Qwen2.5 ladder)
|
|
106
|
+
pulls: new Map(), // model → { pct, first, phase, error, trouble, running }
|
|
107
|
+
install: null, // Ollama's own install, while it runs: { lines, error, trouble, running }
|
|
108
|
+
tried: null, // «try it»: { said, answer, error, busy }
|
|
109
|
+
address: null, // the AI of another computer: { host, busy, error, ok }
|
|
110
|
+
memoryChoice: null, // local · gemini · off
|
|
111
|
+
agents: null, // /api/settings, as the agents panel last read it
|
|
112
|
+
ready: 0, // agents connected
|
|
113
|
+
added: [], // the projects added while the welcome was open
|
|
114
|
+
};
|
|
115
|
+
let leave = null; // what the step on screen stops when another one comes
|
|
116
|
+
let pollTimer = 0;
|
|
117
|
+
let stream = null;
|
|
118
|
+
let finished = false;
|
|
119
|
+
const stepId = () => WELCOME_STEPS[s.step];
|
|
120
|
+
|
|
121
|
+
// ---- Where the person is, kept in ~/.pulse (src/tour.mjs).
|
|
122
|
+
const save = async (change) => {
|
|
123
|
+
const answer = await post('/api/tour', { welcome: change });
|
|
124
|
+
if (answer.ok && answer.body?.state?.welcome) { s.progress = answer.body.state.welcome; host.saved?.(s.progress); }
|
|
125
|
+
paintRail();
|
|
126
|
+
};
|
|
127
|
+
const go = (to, mark = null) => {
|
|
128
|
+
const id = stepId();
|
|
129
|
+
const next = Math.max(0, Math.min(WELCOME_STEPS.length - 1, typeof to === 'string' ? WELCOME_STEPS.indexOf(to) : to));
|
|
130
|
+
if (mark === 'done') { s.progress.done = [...new Set([...s.progress.done, id])]; s.progress.skipped = s.progress.skipped.filter((one) => one !== id); }
|
|
131
|
+
if (mark === 'skip') { s.progress.skipped = [...new Set([...s.progress.skipped, id])]; s.progress.done = s.progress.done.filter((one) => one !== id); }
|
|
132
|
+
s.step = next;
|
|
133
|
+
void save({ at: WELCOME_STEPS[next], ...(mark === 'done' ? { done: id } : mark === 'skip' ? { skipped: id } : {}) });
|
|
134
|
+
show();
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// ---- What Ollama and the computer say, asked again whenever something may have changed.
|
|
138
|
+
const readOllama = async ({ probe = false } = {}) => {
|
|
139
|
+
const answer = probe ? (await post('/api/ollama/probe')).body : await getJson('/api/ollama');
|
|
140
|
+
if (answer?.ollama) { s.ollama = answer.ollama; s.recommended = answer.recommended ?? s.recommended; }
|
|
141
|
+
return s.ollama;
|
|
142
|
+
};
|
|
143
|
+
const chatModels = () => (s.ollama?.models ?? []).filter((model) => !EMBEDDING.test(model.name) && !EMBEDDING.test(model.family ?? ''));
|
|
144
|
+
const hasModel = (name) => (s.ollama?.models ?? []).some((model) => model.name === name || model.name === `${name}:latest` || model.name.replace(/:latest$/, '') === name);
|
|
145
|
+
const localHost = (address) => /^https?:\/\/(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/i.test(String(address ?? ''));
|
|
146
|
+
const fit = () => s.hardware ?? null;
|
|
147
|
+
const facts = () => fit()?.hardware ?? {};
|
|
148
|
+
// What the computer can carry: well, slowly (no graphics card), or not at all.
|
|
149
|
+
const canCarry = () => {
|
|
150
|
+
const best = fit()?.recommended?.run;
|
|
151
|
+
if (!best) return 'no';
|
|
152
|
+
return fit().accelerated ? 'yes' : 'slow';
|
|
153
|
+
};
|
|
154
|
+
// The model offered first: the one MADRE recommends here, or the one the person stepped down to.
|
|
155
|
+
const offered = () => s.model ?? fit()?.recommended?.run ?? null;
|
|
156
|
+
const smaller = () => {
|
|
157
|
+
const rungs = (fit()?.models ?? []).filter((model) => model.run !== 'no');
|
|
158
|
+
const now = offered();
|
|
159
|
+
const at = rungs.findIndex((model) => model.id === now?.id);
|
|
160
|
+
return at > 0 ? rungs[at - 1] : null;
|
|
161
|
+
};
|
|
162
|
+
const roomFor = (gb) => (s.env?.disk?.freeGb == null ? true : s.env.disk.freeGb >= gb + 2);
|
|
163
|
+
|
|
164
|
+
// ---- The rail: the seven steps, where the person is, what is done and what was left for later.
|
|
165
|
+
// The logo draws itself in once, when the welcome opens, and stays in the rail from then on: the
|
|
166
|
+
// steps are repainted under it, never the logo, or its drawing started over with every step.
|
|
167
|
+
const brand = el('div', 'wl-brand');
|
|
168
|
+
brand.setAttribute('aria-label', 'MADRE');
|
|
169
|
+
brand.innerHTML = BRAND_LOGO; // trusted: our own SVG string
|
|
170
|
+
const railBody = el('div', 'wl-rail-body');
|
|
171
|
+
rail.append(brand, railBody);
|
|
172
|
+
function paintRail() {
|
|
173
|
+
const list = el('ol', 'wl-steps');
|
|
174
|
+
WELCOME_STEPS.forEach((id, index) => {
|
|
175
|
+
const done = s.progress.done.includes(id);
|
|
176
|
+
const skipped = s.progress.skipped.includes(id);
|
|
177
|
+
const item = el('li');
|
|
178
|
+
const key = button(`wl-step${done ? ' done' : ''}${skipped ? ' skipped' : ''}`, null, () => { s.step = index; void save({ at: id }); show(); });
|
|
179
|
+
if (index === s.step) key.setAttribute('aria-current', 'step');
|
|
180
|
+
const dot = el('i');
|
|
181
|
+
if (done) dot.innerHTML = TICK; // trusted: our own SVG string
|
|
182
|
+
else dot.textContent = skipped ? '–' : String(index + 1);
|
|
183
|
+
key.append(dot, el('span', null, STEP_NAMES[id]()));
|
|
184
|
+
if (skipped) key.title = t('Left for later');
|
|
185
|
+
item.append(key);
|
|
186
|
+
list.append(item);
|
|
187
|
+
});
|
|
188
|
+
railBody.replaceChildren(list, el('p', 'wl-rail-foot', t('Anything you leave for later can be done afterwards in Settings.')));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ---- The parts every step is made of.
|
|
192
|
+
const head = (title, lead) => {
|
|
193
|
+
const nodes = [el('p', 'wl-eyebrow', s.step ? t('Step {n} of {total}', { n: s.step + 1, total: WELCOME_STEPS.length }) : t('Welcome')), el('h2', 'wl-title', title)];
|
|
194
|
+
if (lead) nodes.push(el('p', 'wl-lead', lead));
|
|
195
|
+
return nodes;
|
|
196
|
+
};
|
|
197
|
+
const note = (tone, ...children) => {
|
|
198
|
+
const box = el('div', `wl-note${tone ? ` ${tone}` : ''}`);
|
|
199
|
+
box.append(...children.filter(Boolean).map((child) => (typeof child === 'string' ? el('p', null, child) : child)));
|
|
200
|
+
return box;
|
|
201
|
+
};
|
|
202
|
+
// «See how to fix it», under what went wrong: the card of Diagnostics for it, for this system.
|
|
203
|
+
const fix = (id) => (id ? remedyKey(id, { platform: platformOf(s.env) }) : null);
|
|
204
|
+
const chip = (tone, words) => { const node = el('span', `wl-chip${tone ? ` ${tone}` : ''}`); node.append(el('i'), el('span', null, words)); return node; };
|
|
205
|
+
const copyLine = (line) => {
|
|
206
|
+
const box = el('div', 'wl-copyline');
|
|
207
|
+
const copy = button('wl-btn small', t('Copy'), async () => {
|
|
208
|
+
try { await navigator.clipboard.writeText(line); copy.textContent = t('Copied'); setTimeout(() => { copy.textContent = t('Copy'); }, 1500); } catch { copy.textContent = t('Select it'); }
|
|
209
|
+
});
|
|
210
|
+
box.append(el('code', null, line), copy);
|
|
211
|
+
return box;
|
|
212
|
+
};
|
|
213
|
+
const bar = (pct) => { const track = el('div', 'wl-bar'); const fill = el('i'); fill.style.width = `${Math.max(0, Math.min(100, pct))}%`; track.append(fill); track.setAttribute('role', 'progressbar'); track.setAttribute('aria-valuenow', String(Math.round(pct))); track.setAttribute('aria-valuemin', '0'); track.setAttribute('aria-valuemax', '100'); return track; };
|
|
214
|
+
// A choice among a few, each with a line that says what it does.
|
|
215
|
+
const choice = (name, value, current, title, sub, onPick, { badge = null, disabled = false } = {}) => {
|
|
216
|
+
const option = button('wl-path', null, () => { if (!disabled) onPick(value); });
|
|
217
|
+
option.setAttribute('role', 'radio');
|
|
218
|
+
option.setAttribute('aria-checked', String(current === value));
|
|
219
|
+
option.dataset.choice = `${name}:${value}`;
|
|
220
|
+
if (disabled) option.setAttribute('aria-disabled', 'true');
|
|
221
|
+
const words = el('span', 'wl-path-words');
|
|
222
|
+
const line = el('b', null, title);
|
|
223
|
+
if (badge) line.append(el('span', 'wl-badge', badge));
|
|
224
|
+
words.append(line, el('small', null, sub));
|
|
225
|
+
option.append(el('span', 'wl-radio'), words);
|
|
226
|
+
return option;
|
|
227
|
+
};
|
|
228
|
+
const choices = (label, ...options) => { const group = el('div', 'wl-paths'); group.setAttribute('role', 'radiogroup'); group.setAttribute('aria-label', label); group.append(...options); return group; };
|
|
229
|
+
// The keys under every step: back, what leaving it for later costs, and on.
|
|
230
|
+
const footer = ({ next = t('Continue'), onNext = () => go(s.step + 1, 'done'), nextOff = false, skip = null, back = true, extra = null } = {}) => {
|
|
231
|
+
const backKey = back && s.step > 0 ? button('wl-btn ghost', t('Back'), () => go(s.step - 1)) : el('span');
|
|
232
|
+
const parts = [backKey, el('span', 'wl-grow')];
|
|
233
|
+
if (skip) {
|
|
234
|
+
const away = button('wl-btn', skip.label ?? t('Skip for now'), () => go(s.step + 1, 'skip'));
|
|
235
|
+
away.dataset.skip = '';
|
|
236
|
+
parts.push(el('span', 'wl-skipnote', skip.note), away);
|
|
237
|
+
}
|
|
238
|
+
if (extra) parts.push(extra);
|
|
239
|
+
const primary = button('wl-btn primary', next, async () => { primary.disabled = true; try { await onNext(); } finally { if (primary.isConnected) primary.disabled = false; } });
|
|
240
|
+
primary.disabled = nextOff;
|
|
241
|
+
primary.dataset.next = '';
|
|
242
|
+
parts.push(primary);
|
|
243
|
+
actions.replaceChildren(...parts);
|
|
244
|
+
return primary;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// ---- 1 · HELLO: the language, what gets ready and how long it takes.
|
|
248
|
+
function hello() {
|
|
249
|
+
const seg = el('div', 'wl-seg');
|
|
250
|
+
seg.setAttribute('role', 'radiogroup');
|
|
251
|
+
seg.setAttribute('aria-label', 'Idioma · Language');
|
|
252
|
+
for (const [code, words] of [['es', 'Español'], ['en', 'English']]) {
|
|
253
|
+
const option = button(null, words, async () => {
|
|
254
|
+
if (code === language()) return;
|
|
255
|
+
await host.setLanguage?.(code);
|
|
256
|
+
dialog.setAttribute('aria-label', t('Welcome to MADRE'));
|
|
257
|
+
paintRail();
|
|
258
|
+
show();
|
|
259
|
+
});
|
|
260
|
+
option.setAttribute('role', 'radio');
|
|
261
|
+
option.setAttribute('aria-checked', String(code === language()));
|
|
262
|
+
seg.append(option);
|
|
263
|
+
}
|
|
264
|
+
const lang = el('div', 'wl-row');
|
|
265
|
+
lang.append(el('span', 'wl-muted', t('Language')), seg);
|
|
266
|
+
const list = el('div', 'wl-card wl-checks');
|
|
267
|
+
for (const [title, sub] of [
|
|
268
|
+
[t('Your agents'), t('The AIs that work in your projects (Claude, Codex, Gemini…). We install and connect them here.')],
|
|
269
|
+
[t('AI on your computer'), t('If your computer can carry it, a free and private AI that works without internet.')],
|
|
270
|
+
[t('Memory'), t('So MADRE finds what it remembers even when you ask in other words.')],
|
|
271
|
+
[t('Your first project'), t('A folder you work in. It is ready when we finish.')],
|
|
272
|
+
]) {
|
|
273
|
+
const row = el('div', 'wl-check');
|
|
274
|
+
const tick = el('span', 'wl-tick');
|
|
275
|
+
tick.innerHTML = TICK; // trusted: our own SVG string
|
|
276
|
+
const words = el('div');
|
|
277
|
+
words.append(el('b', null, title), el('small', null, sub));
|
|
278
|
+
row.append(tick, words);
|
|
279
|
+
list.append(row);
|
|
280
|
+
}
|
|
281
|
+
content.replaceChildren(...head(t('Hi. Let\'s get MADRE ready.'), t('It takes about 10 minutes, plus the download if you choose an AI on your computer. You will not need the terminal.')), lang, list);
|
|
282
|
+
footer({ next: t('Start'), back: false });
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// ---- 2 · YOUR COMPUTER: what MADRE found, in plain words, and what it means for the next steps.
|
|
286
|
+
function placeWords() {
|
|
287
|
+
const env = s.env ?? {};
|
|
288
|
+
if (env.place === 'ssh') return t('You\'re connected from another computer (SSH)');
|
|
289
|
+
if (env.place === 'wsl') return env.wsl?.distro ? t('Linux inside Windows (WSL · {distro})', { distro: env.wsl.distro }) : t('Linux inside Windows (WSL)');
|
|
290
|
+
if (env.place === 'vm') return t('A virtual machine ({vm})', { vm: env.vm });
|
|
291
|
+
if (env.place === 'container') return t('Inside a container');
|
|
292
|
+
return t('On this computer');
|
|
293
|
+
}
|
|
294
|
+
function graphicsWords() {
|
|
295
|
+
const hw = facts();
|
|
296
|
+
if (hw.accelerator === 'apple') return t('Apple chip: the AI uses the computer\'s memory');
|
|
297
|
+
if (hw.accelerator === 'nvidia') return `${hw.gpus?.[0]?.name ?? 'NVIDIA'} · ${number(hw.acceleratorGb)} GB`;
|
|
298
|
+
return t('None the AI can use');
|
|
299
|
+
}
|
|
300
|
+
function machine() {
|
|
301
|
+
const env = s.env ?? {};
|
|
302
|
+
const hw = facts();
|
|
303
|
+
const grid = el('div', 'wl-facts');
|
|
304
|
+
const fact = (label, value) => { if (!value) return; const box = el('div', 'wl-fact'); box.append(el('small', null, label), el('b', null, value)); grid.append(box); };
|
|
305
|
+
fact(t('Where MADRE runs'), placeWords());
|
|
306
|
+
fact(t('System'), env.name ?? (env.os === 'macos' ? 'macOS' : env.os === 'linux' ? 'Linux' : env.os ?? null));
|
|
307
|
+
fact(t('Processor'), hw.chip ?? (hw.cores ? t('{n} cores', { n: hw.cores }) : null));
|
|
308
|
+
fact(t('Memory'), hw.memoryGb ? `${number(hw.memoryGb)} GB` : null);
|
|
309
|
+
fact(t('Graphics card'), graphicsWords());
|
|
310
|
+
fact(t('Free space'), env.disk ? t('{n} GB free', { n: number(env.disk.freeGb) }) : null);
|
|
311
|
+
const notes = [];
|
|
312
|
+
const carry = canCarry();
|
|
313
|
+
if (carry === 'yes') notes.push(note('ok', t('Your computer can run its own AI. We recommend a model in step 4.')));
|
|
314
|
+
else if (carry === 'slow') notes.push(note('warn', t('Your computer can run a small AI, but slowly: it has no graphics card the AI can use.')));
|
|
315
|
+
else notes.push(note('warn', t('This computer does not have enough memory for an AI of its own. MADRE works just the same with your agents.')));
|
|
316
|
+
if (env.place === 'wsl') notes.push(note('', t('MADRE runs here on Linux, inside Windows (WSL). Your Windows browser opens it directly.')));
|
|
317
|
+
// On Windows itself (docs/WINDOWS.md, D-001): from 1.1.0 MADRE runs inside WSL2, not on Windows directly.
|
|
318
|
+
if (env.os === 'windows') notes.push(note('warn', t('On Windows, MADRE runs inside WSL2, the Linux that comes with Windows 10 and 11. It does not run on Windows directly.'), fix('windows-use-wsl')));
|
|
319
|
+
// A virtual machine reached over SSH is both (Carlos, 2026-10-28): each is said.
|
|
320
|
+
if (env.vm && env.vm !== 'macOS') notes.push(note('warn', t('MADRE runs in a virtual machine: an AI here runs slower than on the computer itself. If that computer runs Windows, MADRE works better in WSL.')));
|
|
321
|
+
if (env.place === 'ssh') notes.push(note('', t('You\'re connected from another computer. Some agents connect with a code instead of opening a page; each one says so.'), fix('ssh-tunnel')));
|
|
322
|
+
if (env.place === 'container') notes.push(note('', t('MADRE runs inside a container: what it installs stays in that container.')));
|
|
323
|
+
if (env.disk && env.disk.freeGb < 10) notes.push(note('warn', t('Only {n} GB free. Agents fit, but an AI of its own needs more room: free some up before step 4.', { n: number(env.disk.freeGb) })));
|
|
324
|
+
content.replaceChildren(...head(t('Here is what we found'), t('We use it to recommend what works best on your computer. It never leaves your computer.')), grid, ...notes);
|
|
325
|
+
footer();
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// ---- 3 · YOUR AGENTS: Home's own panel, with what each one needs said first.
|
|
329
|
+
function explainAgent(agent, state) {
|
|
330
|
+
const env = s.env ?? {};
|
|
331
|
+
if (agent.id === 'gemini' && !state.ok) return el('p', 'wl-agent-why', t('Gemini no longer works with personal Google accounts: it needs an access key (API key) from Google AI Studio. You pay for what you use, usually very little. «Where do I get one?» opens the page that gives it.'));
|
|
332
|
+
if (agent.id === 'cursor' && !agent.detected) return el('p', 'wl-agent-why', t('Cursor installs with its own installer. For your safety MADRE does not run installers downloaded from the internet: copy the line below into a terminal (the window where you type commands), once, then press «I did it». Or skip it: it is optional.'));
|
|
333
|
+
if (env.place === 'ssh' && agent.detected && !state.ok && (agent.login?.methods ?? []).some((method) => method.id === 'device')) return el('p', 'wl-agent-why', t('You\'re connected from another computer: choose «With a code», and type the code on the page from any device.'));
|
|
334
|
+
if (env.place === 'ssh' && agent.detected && !state.ok) return el('p', 'wl-agent-why', t('You\'re connected from another computer: open the page it gives you on your own computer, and paste back here the code it shows.'));
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
function agents() {
|
|
338
|
+
const panel = host.agentsPanel?.({
|
|
339
|
+
compact: true,
|
|
340
|
+
explain: explainAgent,
|
|
341
|
+
onPaint: (ready, answer) => {
|
|
342
|
+
s.ready = ready;
|
|
343
|
+
s.agents = answer;
|
|
344
|
+
paintAgentKeys();
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
content.replaceChildren(...head(t('Connect your agents'), t('Agents are the AIs that read and write in your projects. Each one is connected once, and every project uses it. One is enough to start.')));
|
|
348
|
+
if (panel) {
|
|
349
|
+
content.append(panel.node);
|
|
350
|
+
void panel.paint().then(() => panel.live());
|
|
351
|
+
leave = () => panel.stop();
|
|
352
|
+
}
|
|
353
|
+
footer({ nextOff: !s.ready, skip: { note: t('Without agents, MADRE cannot work for you.') } });
|
|
354
|
+
paintAgentKeys();
|
|
355
|
+
}
|
|
356
|
+
// With one agent connected the step is done: leaving it for later is no longer offered.
|
|
357
|
+
function paintAgentKeys() {
|
|
358
|
+
const next = actions.querySelector('[data-next]');
|
|
359
|
+
if (next) next.disabled = !s.ready;
|
|
360
|
+
for (const node of actions.querySelectorAll('.wl-skipnote, [data-skip]')) node.hidden = Boolean(s.ready);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// ---- 4 · AI ON YOUR COMPUTER: install Ollama, download the model, try it — or use another
|
|
364
|
+
// computer's, or leave it for later.
|
|
365
|
+
function aiChoices() {
|
|
366
|
+
const env = s.env ?? {};
|
|
367
|
+
const carry = canCarry();
|
|
368
|
+
const model = offered();
|
|
369
|
+
const pick = (value) => {
|
|
370
|
+
s.choice = value;
|
|
371
|
+
// Back to this computer's Ollama after pointing at another one.
|
|
372
|
+
if (value === 'here' && s.ollama?.host && !localHost(s.ollama.host)) void post('/api/local-ai/host', { host: null }).then(() => readOllama({ probe: true })).then(() => paintAi());
|
|
373
|
+
paintAi();
|
|
374
|
+
};
|
|
375
|
+
const options = [];
|
|
376
|
+
if (model) {
|
|
377
|
+
const sub = carry === 'yes'
|
|
378
|
+
? t('The one that fits your computer best. A {size} GB download.', { size: number(model.sizeGb ?? 0) })
|
|
379
|
+
: t('The one that fits your computer. A {size} GB download; it will answer slowly.', { size: number(model.sizeGb ?? 0) });
|
|
380
|
+
options.push(choice('ai', 'here', s.choice, t('Install it here · {model}', { model: model.label }), sub, pick, { badge: carry === 'yes' ? t('Recommended') : null }));
|
|
381
|
+
}
|
|
382
|
+
if (env.place === 'wsl') options.push(choice('ai', 'windows', s.choice, t('Use the Ollama on Windows'), t('If Ollama is already installed on Windows, MADRE connects to it.'), pick));
|
|
383
|
+
if (env.vm || env.place === 'wsl' || env.place === 'ssh' || carry !== 'yes') options.push(choice('ai', 'remote', s.choice, t('Use another computer\'s AI'), t('A computer on your network with Ollama and a graphics card.'), pick));
|
|
384
|
+
options.push(choice('ai', 'skip', s.choice, t('Not now'), t('MADRE works just the same with your agents. You can turn it on later in Settings › Local AI.'), pick));
|
|
385
|
+
return choices(t('AI on your computer'), ...options);
|
|
386
|
+
}
|
|
387
|
+
let aiBody = null;
|
|
388
|
+
function ai() {
|
|
389
|
+
const carry = canCarry();
|
|
390
|
+
const intro = carry === 'yes' ? note('ok', t('Your computer can run its own AI: free, private and offline. It powers @madre, the archivist and the search in your memory.'))
|
|
391
|
+
: carry === 'slow' ? note('warn', t('Your computer can, but it will be slow ({gb} GB, no graphics card the AI can use). We recommend a small model.', { gb: number(facts().memoryGb ?? 0) }))
|
|
392
|
+
: note('warn', t('This computer does not have enough memory for an AI of its own: here it would be too slow. MADRE works just the same with your agents.'));
|
|
393
|
+
// Chosen before: what is already there says which way this goes.
|
|
394
|
+
if (!s.choice && s.ollama?.running && chatModels().length) s.choice = localHost(s.ollama.host) ? 'here' : (s.env?.place === 'wsl' ? 'windows' : 'remote');
|
|
395
|
+
aiBody = el('div', 'wl-ai');
|
|
396
|
+
content.replaceChildren(...head(t('AI on your computer'), t('Ollama is the app that runs AI on your computer. A bigger model is smarter and heavier; we suggest the one that fits yours best.')), intro, aiBody);
|
|
397
|
+
paintAi();
|
|
398
|
+
// While Ollama is not there yet, MADRE looks every few seconds: «I did it» is a courtesy.
|
|
399
|
+
clearInterval(pollTimer);
|
|
400
|
+
pollTimer = setInterval(() => {
|
|
401
|
+
if (document.hidden || !['here', 'windows', 'remote'].includes(s.choice) || s.ollama?.running) return;
|
|
402
|
+
if (s.choice !== 'here') return;
|
|
403
|
+
void readOllama({ probe: true }).then(() => { if (stepId() === 'ai') paintAi(); });
|
|
404
|
+
}, 5000);
|
|
405
|
+
leave = () => { clearInterval(pollTimer); pollTimer = 0; };
|
|
406
|
+
}
|
|
407
|
+
function paintAi() {
|
|
408
|
+
if (!aiBody?.isConnected) return;
|
|
409
|
+
const blocks = [aiChoices()];
|
|
410
|
+
if (s.choice === 'here') blocks.push(installFlow());
|
|
411
|
+
if (s.choice === 'windows' || s.choice === 'remote') blocks.push(addressFlow());
|
|
412
|
+
aiBody.replaceChildren(...blocks);
|
|
413
|
+
const ready = s.ollama?.running && chatModels().length > 0;
|
|
414
|
+
// «Not now» is one of the choices: no second key to leave it for later.
|
|
415
|
+
footer({
|
|
416
|
+
nextOff: s.choice === null || (s.choice !== 'skip' && !ready),
|
|
417
|
+
onNext: async () => {
|
|
418
|
+
if (s.choice === 'skip') { go(s.step + 1, 'skip'); return; }
|
|
419
|
+
await enableLocal();
|
|
420
|
+
go(s.step + 1, 'done');
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
// On for every project, and every open project told (Home › Settings › Local AI does the same).
|
|
425
|
+
async function enableLocal() {
|
|
426
|
+
await post('/api/ollama/settings', { enabled: true, embeddings: true });
|
|
427
|
+
await post('/api/salas/local-ai', {});
|
|
428
|
+
}
|
|
429
|
+
function installFlow() {
|
|
430
|
+
const env = s.env ?? {};
|
|
431
|
+
const box = el('div', 'wl-card wl-flow');
|
|
432
|
+
const info = s.ollama ?? {};
|
|
433
|
+
// 1 · Ollama itself.
|
|
434
|
+
box.append(el('b', 'wl-flow-title', t('1 · Install Ollama')));
|
|
435
|
+
if (info.running) box.append(chip('ok', info.version ? t('Installed and open · {version}', { version: info.version }) : t('Installed and open')));
|
|
436
|
+
else if (info.binary) {
|
|
437
|
+
box.append(el('p', 'wl-muted', env.os === 'macos' ? t('Ollama is installed but not open. MADRE opens it; if it does not answer, open the Ollama app yourself.') : t('Ollama is installed but not running. MADRE starts it.')));
|
|
438
|
+
const start = button('wl-btn primary small', t('Open Ollama'), async () => {
|
|
439
|
+
start.disabled = true;
|
|
440
|
+
const answer = await post('/api/ollama/start');
|
|
441
|
+
await readOllama({ probe: true });
|
|
442
|
+
if (!answer.ok) s.install = { error: answer.body?.error ?? t('Ollama did not answer.'), card: 'ollama-not-starting' };
|
|
443
|
+
paintAi();
|
|
444
|
+
});
|
|
445
|
+
box.append(start);
|
|
446
|
+
} else if (env.os === 'macos') {
|
|
447
|
+
box.append(el('p', 'wl-muted', t('Download the official Ollama app, open it once, and come back here. It then opens by itself every time you turn on your Mac.')));
|
|
448
|
+
const row = el('div', 'wl-row');
|
|
449
|
+
const get = el('a', 'wl-btn primary small', t('Download Ollama ↗'));
|
|
450
|
+
get.href = OLLAMA_DOWNLOAD;
|
|
451
|
+
get.target = '_blank';
|
|
452
|
+
get.rel = 'noopener';
|
|
453
|
+
row.append(get, checkKey(), el('small', 'wl-tiny', t('MADRE checks on its own.')));
|
|
454
|
+
box.append(row);
|
|
455
|
+
} else if (info.install?.command && !s.install?.manual) {
|
|
456
|
+
box.append(el('p', 'wl-muted', t('MADRE installs it with Ollama\'s own installer, from ollama.com. It takes a few minutes.')));
|
|
457
|
+
if (s.install?.running) {
|
|
458
|
+
box.append(el('p', 'wl-tiny wl-live', s.install.lines?.at(-1) ?? t('Installing…')));
|
|
459
|
+
} else {
|
|
460
|
+
const run = button('wl-btn primary small', s.install?.error ? t('Try again') : t('Install Ollama'), async () => {
|
|
461
|
+
run.disabled = true;
|
|
462
|
+
const answer = await post('/api/ollama/install');
|
|
463
|
+
if (answer.ok) s.install = { running: true, lines: [] };
|
|
464
|
+
else if (answer.status === 412 && answer.body?.manual) s.install = { manual: true };
|
|
465
|
+
else s.install = { error: answer.body?.error ?? t('It did not install.') };
|
|
466
|
+
paintAi();
|
|
467
|
+
});
|
|
468
|
+
box.append(run);
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
const why = env.place === 'wsl'
|
|
472
|
+
? t('It installs inside Linux (WSL). Linux asks for your Linux user\'s password to install programs; MADRE never asks for it or keeps it. Copy this line into the Ubuntu terminal, once.')
|
|
473
|
+
: t('To install programs, Linux asks for your password. MADRE never asks for it or keeps it: copy this line into a terminal (the window where you type commands) on this computer, once.');
|
|
474
|
+
box.append(el('p', 'wl-muted', why), copyLine(OLLAMA_SCRIPT));
|
|
475
|
+
const row = el('div', 'wl-row');
|
|
476
|
+
row.append(checkKey(), el('small', 'wl-tiny', t('MADRE checks on its own.')));
|
|
477
|
+
box.append(row);
|
|
478
|
+
}
|
|
479
|
+
if (s.install?.error && !info.running) box.append(note('bad', s.install.trouble && TROUBLE[s.install.trouble] ? TROUBLE[s.install.trouble]() : s.install.error, fix(s.install.card ?? (s.install.trouble === 'permission' ? 'ollama' : TROUBLE_CARD[s.install.trouble]) ?? 'ollama')));
|
|
480
|
+
// 2 · The model, and 3 · trying it, once Ollama answers.
|
|
481
|
+
if (info.running) box.append(...modelFlow());
|
|
482
|
+
return box;
|
|
483
|
+
}
|
|
484
|
+
const checkKey = () => {
|
|
485
|
+
const key = button('wl-btn small', t('I did it'), async () => {
|
|
486
|
+
key.disabled = true;
|
|
487
|
+
key.textContent = t('Checking…');
|
|
488
|
+
await readOllama({ probe: true });
|
|
489
|
+
if (s.ollama?.binary && !s.ollama.running) await post('/api/ollama/start').then(() => readOllama({ probe: true }));
|
|
490
|
+
if (!s.ollama?.running) s.install = s.ollama?.binary ? { error: t('Ollama is installed but did not answer. Open the Ollama app, then press «I did it» again.'), card: 'ollama-not-starting' } : { error: t('Ollama is not on this computer yet. Install it, then press «I did it» again.'), card: 'ollama' };
|
|
491
|
+
else s.install = null;
|
|
492
|
+
paintAi();
|
|
493
|
+
});
|
|
494
|
+
return key;
|
|
495
|
+
};
|
|
496
|
+
// The model, downloaded with its real share, and a first word with it.
|
|
497
|
+
function modelFlow() {
|
|
498
|
+
const parts = [];
|
|
499
|
+
const have = chatModels();
|
|
500
|
+
const model = offered();
|
|
501
|
+
const using = have[0]?.name ?? null;
|
|
502
|
+
if (have.length && (!model || !s.pulls.get(model.ollama)?.running)) {
|
|
503
|
+
parts.push(el('b', 'wl-flow-title', t('2 · The model')));
|
|
504
|
+
parts.push(chip('ok', t('Ready · {model}', { model: s.ollama?.chatModel ?? using })));
|
|
505
|
+
parts.push(...tryFlow());
|
|
506
|
+
return parts;
|
|
507
|
+
}
|
|
508
|
+
if (!model) {
|
|
509
|
+
parts.push(el('b', 'wl-flow-title', t('2 · The model')), el('p', 'wl-muted', t('This computer cannot carry a model. Use another computer\'s AI, or leave it for later.')));
|
|
510
|
+
return parts;
|
|
511
|
+
}
|
|
512
|
+
parts.push(el('b', 'wl-flow-title', t('2 · Download {model}', { model: model.label })));
|
|
513
|
+
const pull = s.pulls.get(model.ollama);
|
|
514
|
+
if (pull?.running) {
|
|
515
|
+
const pct = pull.pct ?? 0;
|
|
516
|
+
const got = ((model.sizeGb ?? 0) * pct) / 100;
|
|
517
|
+
const line = el('div', 'wl-row wl-pull-line');
|
|
518
|
+
line.append(el('small', 'wl-tiny', pull.phase === 'verify' ? t('Checking the download…') : t('{pct} % · {got} of {size} GB', { pct: Math.round(pct), got: number(got), size: number(model.sizeGb ?? 0) })), el('span', 'wl-grow'), cancelKey(model.ollama, pull));
|
|
519
|
+
parts.push(bar(pct), line);
|
|
520
|
+
return parts;
|
|
521
|
+
}
|
|
522
|
+
if (pull?.cancelled) parts.push(note('', t('You cancelled the download. What already arrived stays in Ollama: download it again and it picks up from there.')));
|
|
523
|
+
if (pull?.error) {
|
|
524
|
+
parts.push(note('bad', pull.trouble && TROUBLE[pull.trouble] ? TROUBLE[pull.trouble]() : t('The download stopped: {error}', { error: pull.error }), fix(pull.trouble === 'disk' ? 'disk-full' : 'model-download')));
|
|
525
|
+
}
|
|
526
|
+
if (!roomFor(model.sizeGb ?? 0)) parts.push(note('warn', t('There are {free} GB free and this model needs {size} GB plus some room. Free up space or choose a smaller model.', { free: number(s.env.disk.freeGb), size: number(model.sizeGb ?? 0) }), fix('disk-full')));
|
|
527
|
+
const row = el('div', 'wl-row');
|
|
528
|
+
const get = button('wl-btn primary small', pull?.error ? t('Try again') : pull?.cancelled ? t('Continue the download') : t('Download · {size} GB', { size: number(model.sizeGb ?? 0) }), () => void startPull(model.ollama));
|
|
529
|
+
get.disabled = !roomFor(model.sizeGb ?? 0) && !pull?.error;
|
|
530
|
+
row.append(get);
|
|
531
|
+
const down = smaller();
|
|
532
|
+
if (down) row.append(button('wl-btn ghost small', t('Choose a smaller one · {model}', { model: down.label }), () => { s.model = down; paintAi(); }));
|
|
533
|
+
parts.push(row, el('small', 'wl-tiny', t('It downloads once and stays in Ollama.')));
|
|
534
|
+
return parts;
|
|
535
|
+
}
|
|
536
|
+
// Stopping a download halfway: the server stops asking Ollama for it (/api/ollama/pull/cancel).
|
|
537
|
+
const cancelKey = (model, pull) => {
|
|
538
|
+
const key = button('wl-btn ghost small', pull.cancelling ? t('Cancelling…') : t('Cancel'), async () => {
|
|
539
|
+
pull.cancelling = true;
|
|
540
|
+
key.disabled = true;
|
|
541
|
+
key.textContent = t('Cancelling…');
|
|
542
|
+
const answer = await post('/api/ollama/pull/cancel', { model });
|
|
543
|
+
if (!answer.ok) { pull.cancelling = false; key.disabled = false; key.textContent = t('Cancel'); }
|
|
544
|
+
});
|
|
545
|
+
key.disabled = Boolean(pull.cancelling);
|
|
546
|
+
return key;
|
|
547
|
+
};
|
|
548
|
+
async function startPull(model) {
|
|
549
|
+
s.pulls.set(model, { running: true, pct: 0, first: null, phase: 'pull' });
|
|
550
|
+
repaint();
|
|
551
|
+
const answer = await post('/api/ollama/pull', { model });
|
|
552
|
+
if (!answer.ok) s.pulls.set(model, { error: answer.body?.error ?? t('Home did not answer.') });
|
|
553
|
+
repaint();
|
|
554
|
+
}
|
|
555
|
+
// «Try it» (2026-10-28): a talk with @madre, not a form. It greets first as soon as its model is
|
|
556
|
+
// there, answers as it writes (the server streams what Ollama says), and keeps the turns before, so
|
|
557
|
+
// the person can go on. Built once per step and kept: the download's events repaint the step, and a
|
|
558
|
+
// talk being written must not be rebuilt under the person.
|
|
559
|
+
const GREETING = () => t('Introduce yourself in one short, warm sentence: you are @madre, the AI on this computer, and you are ready to help.');
|
|
560
|
+
const SUGGESTIONS = () => [t('What can you do for me?'), t('Explain what MADRE is in one line'), t('Tell me something fun in one line')];
|
|
561
|
+
function tryFlow() {
|
|
562
|
+
s.talk ??= { messages: [], busy: false, error: null, node: null, greeted: false };
|
|
563
|
+
if (!s.talk.node) s.talk.node = talkNode();
|
|
564
|
+
if (!s.talk.greeted) { s.talk.greeted = true; void say(GREETING(), { hidden: true }); }
|
|
565
|
+
return [el('b', 'wl-flow-title', t('3 · Talk to it')), s.talk.node];
|
|
566
|
+
}
|
|
567
|
+
function talkNode() {
|
|
568
|
+
const box = el('div', 'wl-talk-card');
|
|
569
|
+
const list = el('div', 'wl-talk');
|
|
570
|
+
list.setAttribute('aria-live', 'polite');
|
|
571
|
+
const chips = el('div', 'wl-chips');
|
|
572
|
+
for (const words of SUGGESTIONS()) chips.append(button('wl-chip-key', words, () => void say(words)));
|
|
573
|
+
const form = el('form', 'wl-try wl-talk-form');
|
|
574
|
+
const input = el('input', 'wl-field');
|
|
575
|
+
input.placeholder = t('Write to @madre…');
|
|
576
|
+
input.setAttribute('aria-label', t('Write to the AI on your computer'));
|
|
577
|
+
const send = el('button', 'wl-btn primary small', t('Send'));
|
|
578
|
+
send.type = 'submit';
|
|
579
|
+
form.append(input, send);
|
|
580
|
+
form.addEventListener('submit', (event) => { event.preventDefault(); const words = input.value.trim(); if (!words) return; input.value = ''; void say(words); });
|
|
581
|
+
const where = localHost(s.ollama?.host) ? t('It runs on this computer: nothing you write here leaves it.') : t('It runs on the other computer you chose, on your network.');
|
|
582
|
+
box.append(list, chips, form, el('small', 'wl-tiny', where));
|
|
583
|
+
box.refs = { list, chips, input, send };
|
|
584
|
+
return box;
|
|
585
|
+
}
|
|
586
|
+
async function say(words, { hidden = false } = {}) {
|
|
587
|
+
const talk = s.talk;
|
|
588
|
+
const { list, chips, input, send } = talk.node.refs;
|
|
589
|
+
if (talk.busy) return;
|
|
590
|
+
talk.busy = true;
|
|
591
|
+
talk.error = null;
|
|
592
|
+
send.disabled = true;
|
|
593
|
+
chips.hidden = true;
|
|
594
|
+
talk.node.querySelector('.wl-talk-error')?.remove();
|
|
595
|
+
talk.messages.push({ role: 'user', content: words });
|
|
596
|
+
if (!hidden) list.append(el('p', 'wl-bubble me', words));
|
|
597
|
+
// @madre's turn: its mark, three dots while it thinks, then its words as they come.
|
|
598
|
+
const row = el('div', 'wl-msg');
|
|
599
|
+
const face = host.mark?.('madre', 26) ?? el('span', 'wl-msg-face');
|
|
600
|
+
const bubble = el('p', 'wl-bubble wl-typing');
|
|
601
|
+
bubble.append(el('i'), el('i'), el('i'));
|
|
602
|
+
row.append(face, bubble);
|
|
603
|
+
list.append(row);
|
|
604
|
+
list.scrollTop = list.scrollHeight;
|
|
605
|
+
let text = '';
|
|
606
|
+
try {
|
|
607
|
+
const response = await fetch('/api/local-ai/try', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ messages: talk.messages }) });
|
|
608
|
+
if (!response.ok) throw new Error((await response.json().catch(() => ({}))).error ?? t('Home did not answer.'));
|
|
609
|
+
const reader = response.body.getReader();
|
|
610
|
+
const decoder = new TextDecoder();
|
|
611
|
+
for (;;) {
|
|
612
|
+
const { value, done } = await reader.read();
|
|
613
|
+
if (done) break;
|
|
614
|
+
text += decoder.decode(value, { stream: true });
|
|
615
|
+
if (text) { bubble.classList.remove('wl-typing'); bubble.classList.add('wl-writing'); bubble.textContent = text; list.scrollTop = list.scrollHeight; }
|
|
616
|
+
}
|
|
617
|
+
if (!text.trim()) throw new Error(t('The local AI did not answer.'));
|
|
618
|
+
talk.messages.push({ role: 'assistant', content: text.trim() });
|
|
619
|
+
} catch (error) {
|
|
620
|
+
row.remove();
|
|
621
|
+
talk.messages.pop();
|
|
622
|
+
talk.error = error.name === 'TypeError' ? t('MADRE did not answer. Check that it is still open.') : error.message;
|
|
623
|
+
const wrong = note('bad', talk.error, fix('ollama-not-starting'));
|
|
624
|
+
wrong.classList.add('wl-talk-error');
|
|
625
|
+
list.after(wrong);
|
|
626
|
+
} finally {
|
|
627
|
+
bubble.classList.remove('wl-writing');
|
|
628
|
+
talk.busy = false;
|
|
629
|
+
send.disabled = false;
|
|
630
|
+
chips.hidden = talk.messages.filter((one) => one.role === 'user').length > 2;
|
|
631
|
+
if (!hidden && document.activeElement === document.body) input.focus({ preventScroll: true });
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
// The AI of another computer, or of Windows from inside WSL: its address, tried before it is kept.
|
|
635
|
+
function addressFlow() {
|
|
636
|
+
const env = s.env ?? {};
|
|
637
|
+
const box = el('div', 'wl-card wl-flow');
|
|
638
|
+
const windows = s.choice === 'windows';
|
|
639
|
+
box.append(el('b', 'wl-flow-title', windows ? t('Ollama on Windows') : t('The other computer\'s address')));
|
|
640
|
+
box.append(el('p', 'wl-muted', windows
|
|
641
|
+
? t('Install Ollama on Windows from ollama.com and open it. In its settings, turn on «Expose Ollama to the network» so Linux can reach it.')
|
|
642
|
+
: t('On that computer, Ollama must accept connections from your network: in the Ollama app, turn on «Expose Ollama to the network» in its settings.')));
|
|
643
|
+
const suggested = windows ? `http://${env.wsl?.windowsHost ?? 'localhost'}:11434` : '';
|
|
644
|
+
const form = el('form', 'wl-try');
|
|
645
|
+
const input = el('input', 'wl-field');
|
|
646
|
+
input.value = s.address?.host ?? (s.ollama?.host && !localHost(s.ollama.host) ? s.ollama.host : suggested);
|
|
647
|
+
input.placeholder = 'http://192.168.1.40:11434';
|
|
648
|
+
input.setAttribute('aria-label', t('Ollama address'));
|
|
649
|
+
input.spellcheck = false;
|
|
650
|
+
const test = el('button', 'wl-btn primary small', s.address?.busy ? t('Checking…') : t('Test'));
|
|
651
|
+
test.type = 'submit';
|
|
652
|
+
test.disabled = Boolean(s.address?.busy);
|
|
653
|
+
form.append(input, test);
|
|
654
|
+
form.addEventListener('submit', async (event) => {
|
|
655
|
+
event.preventDefault();
|
|
656
|
+
s.address = { host: input.value.trim(), busy: true };
|
|
657
|
+
paintAi();
|
|
658
|
+
const answer = await post('/api/local-ai/host', { host: s.address.host });
|
|
659
|
+
if (answer.ok) { s.address = { host: answer.body.host, ok: true }; await readOllama(); }
|
|
660
|
+
else s.address = { host: s.address.host, error: answer.body?.error ?? t('Home did not answer.') };
|
|
661
|
+
paintAi();
|
|
662
|
+
});
|
|
663
|
+
box.append(form);
|
|
664
|
+
const connected = s.ollama?.running && !localHost(s.ollama.host);
|
|
665
|
+
if (s.address?.error) box.append(note('bad', s.address.error, fix('ollama-remote')));
|
|
666
|
+
else if (connected) box.append(chip('ok', t('Connected · {host}', { host: s.ollama.host })));
|
|
667
|
+
box.append(el('small', 'wl-tiny', t('It is kept in Settings › Local AI › Ollama address.')));
|
|
668
|
+
if (connected) box.append(...modelFlow());
|
|
669
|
+
return box;
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// ---- 5 · MEMORY: search by meaning on this computer, with Gemini, or exact words.
|
|
673
|
+
let memoryBody = null;
|
|
674
|
+
function memoryStep() {
|
|
675
|
+
memoryBody = el('div', 'wl-memory');
|
|
676
|
+
content.replaceChildren(...head(t('Memory'), t('MADRE remembers what you decide in each project. With search by meaning it finds it even when you ask in other words.')), memoryBody);
|
|
677
|
+
paintMemory();
|
|
678
|
+
// A Gemini key pasted in step 3 counts here: asked again, not the one read when the welcome opened.
|
|
679
|
+
void getJson('/api/environment').then((environment) => {
|
|
680
|
+
if (!environment) return;
|
|
681
|
+
const had = s.geminiKey;
|
|
682
|
+
s.geminiKey = Boolean(environment.geminiKey);
|
|
683
|
+
s.memory = environment.memory ?? s.memory;
|
|
684
|
+
if (had !== s.geminiKey) paintMemory();
|
|
685
|
+
});
|
|
686
|
+
// With the AI of step 4 there, its memory model comes on its own: nothing to press — unless
|
|
687
|
+
// another download is still running (step 4's model): Ollama takes one at a time.
|
|
688
|
+
const busy = [...s.pulls.values()].some((one) => one.running);
|
|
689
|
+
if (s.memoryChoice === 'local' && !hasModel(EMBED_MODEL) && !s.pulls.has(EMBED_MODEL) && !busy) void startPull(EMBED_MODEL);
|
|
690
|
+
}
|
|
691
|
+
function paintMemory() {
|
|
692
|
+
if (!memoryBody?.isConnected) return;
|
|
693
|
+
const local = Boolean(s.ollama?.running);
|
|
694
|
+
const said = s.memory?.embedProvider;
|
|
695
|
+
s.memoryChoice ??= said === 'ollama' && local ? 'local' : said === 'gemini' ? 'gemini' : said === 'off' ? 'off' : local ? 'local' : s.geminiKey ? 'gemini' : 'off';
|
|
696
|
+
if (s.memoryChoice === 'local' && !local) s.memoryChoice = s.geminiKey ? 'gemini' : 'off';
|
|
697
|
+
const pick = (value) => { s.memoryChoice = value; if (value === 'local' && !hasModel(EMBED_MODEL) && !s.pulls.get(EMBED_MODEL)?.running) void startPull(EMBED_MODEL); paintMemory(); };
|
|
698
|
+
const embedReady = hasModel(EMBED_MODEL);
|
|
699
|
+
const group = choices(t('Memory'),
|
|
700
|
+
choice('memory', 'local', s.memoryChoice, s.ollama?.host && !localHost(s.ollama.host) ? t('With your Ollama') : t('On your computer'), local ? (embedReady ? (s.ollama?.host && !localHost(s.ollama.host) ? t('With the Ollama of the other computer, on your network. Its memory model is already there. Free and private.') : t('With Ollama. Its memory model is already here. Free and private.')) : t('With Ollama. Downloads a memory model of {mb} MB. Free and private.', { mb: EMBED_MB })) : t('Needs the AI on your computer (step 4).'), pick, { badge: local ? t('Recommended') : null, disabled: !local }),
|
|
701
|
+
choice('memory', 'gemini', s.memoryChoice, t('With Gemini'), s.geminiKey ? t('Uses your Gemini key, already on this computer. Paid per use, very little. What it searches is sent to Google.') : t('Needs your Gemini key: paste it in step 3, in Gemini.'), pick, { badge: !local && s.geminiKey ? t('Recommended') : null }),
|
|
702
|
+
choice('memory', 'off', s.memoryChoice, t('Exact words only'), t('Nothing extra. It finds what you ask for with the same words.'), pick),
|
|
703
|
+
);
|
|
704
|
+
const parts = [group];
|
|
705
|
+
if (s.memoryChoice === 'local') {
|
|
706
|
+
const pull = s.pulls.get(EMBED_MODEL);
|
|
707
|
+
if (embedReady) parts.push(chip('ok', t('Memory model ready · {model}', { model: EMBED_MODEL })));
|
|
708
|
+
else if (pull?.running) {
|
|
709
|
+
const line = el('div', 'wl-row wl-pull-line');
|
|
710
|
+
line.append(el('small', 'wl-tiny', t('{pct} % · {mb} MB', { pct: Math.round(pull.pct ?? 0), mb: EMBED_MB })), el('span', 'wl-grow'), cancelKey(EMBED_MODEL, pull));
|
|
711
|
+
parts.push(bar(pull.pct ?? 0), line);
|
|
712
|
+
} else if (pull?.cancelled) parts.push(note('', t('You cancelled the download. What already arrived stays in Ollama: download it again and it picks up from there.')), button('wl-btn primary small', t('Continue the download'), () => void startPull(EMBED_MODEL)));
|
|
713
|
+
else if (pull?.error) parts.push(note('bad', pull.trouble && TROUBLE[pull.trouble] ? TROUBLE[pull.trouble]() : t('The download stopped: {error}', { error: pull.error }), fix(pull.trouble === 'disk' ? 'disk-full' : 'model-download')), button('wl-btn small', t('Try again'), () => void startPull(EMBED_MODEL)));
|
|
714
|
+
else parts.push(button('wl-btn primary small', t('Download the memory model · {mb} MB', { mb: EMBED_MB }), () => void startPull(EMBED_MODEL)));
|
|
715
|
+
}
|
|
716
|
+
if (s.memoryChoice === 'gemini' && !s.geminiKey) parts.push(button('wl-btn small', t('Go to step 3'), () => go('agents')));
|
|
717
|
+
memoryBody.replaceChildren(...parts);
|
|
718
|
+
const blocked = (s.memoryChoice === 'local' && !embedReady) || (s.memoryChoice === 'gemini' && !s.geminiKey);
|
|
719
|
+
footer({
|
|
720
|
+
nextOff: blocked,
|
|
721
|
+
onNext: async () => {
|
|
722
|
+
const provider = { local: 'ollama', gemini: 'gemini', off: 'off' }[s.memoryChoice];
|
|
723
|
+
const answer = await post('/api/settings', { memory: { embedProvider: provider } });
|
|
724
|
+
if (answer.ok) s.memory = { ...(s.memory ?? {}), embedProvider: provider };
|
|
725
|
+
go(s.step + 1, s.memoryChoice === 'off' ? 'skip' : 'done');
|
|
726
|
+
},
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// ---- 6 · YOUR PROJECT: a new one or a folder that already is one.
|
|
731
|
+
function project() {
|
|
732
|
+
const had = host.projects?.() ?? [];
|
|
733
|
+
const lead = t('A project is a folder you work in: a store, a website, your documents. Each one has its own conversations and its own memory.');
|
|
734
|
+
const parts = [...head(t('Your first project'), lead)];
|
|
735
|
+
if (had.length) parts.push(note('ok', had.length === 1 ? t('You already have a project in Home: {name}. Add another one, or continue.', { name: had[0].name }) : t('You already have {n} projects in Home. Add another one, or continue.', { n: had.length })));
|
|
736
|
+
if (s.env?.place === 'wsl') parts.push(note('warn', t('Keep your projects inside Linux (your folder in /home). A Windows folder (/mnt/c/…) makes MADRE slower and protects your files less.'), fix('wsl-windows-folder')));
|
|
737
|
+
let picker = null;
|
|
738
|
+
const primary = () => actions.querySelector('[data-next]');
|
|
739
|
+
picker = host.projectPicker?.({
|
|
740
|
+
withAdd: false,
|
|
741
|
+
onChange: (n) => { const key = primary(); if (key) { key.textContent = n ? t('Add and continue') : t('Continue'); key.disabled = !n && !(host.projects?.() ?? []).length; } },
|
|
742
|
+
// A project made new here does not drop the folders already chosen (QA 1.1.0, NUE-08): they
|
|
743
|
+
// are added too, and only then the step is done.
|
|
744
|
+
onAdded: (added) => {
|
|
745
|
+
s.added = [...s.added, ...(added ?? [])];
|
|
746
|
+
if (stepId() !== 'project') return;
|
|
747
|
+
if (picker?.count()) { void picker.add(); return; }
|
|
748
|
+
go(s.step + 1, 'done');
|
|
749
|
+
},
|
|
750
|
+
});
|
|
751
|
+
if (picker) parts.push(picker.node);
|
|
752
|
+
content.replaceChildren(...parts);
|
|
753
|
+
footer({
|
|
754
|
+
nextOff: !had.length,
|
|
755
|
+
onNext: async () => {
|
|
756
|
+
if (picker?.count()) { await picker.add(); return; }
|
|
757
|
+
go(s.step + 1, 'done');
|
|
758
|
+
},
|
|
759
|
+
skip: had.length ? null : { note: t('You can add it from Home.') },
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// ---- 7 · READY: what is set, what was left for later with its key, and what comes next.
|
|
764
|
+
async function ready() {
|
|
765
|
+
content.replaceChildren(...head(t('MADRE is ready'), t('Here is what is ready. Anything you left for later has its button.')), el('p', 'wl-muted', t('Reading…')));
|
|
766
|
+
actions.replaceChildren();
|
|
767
|
+
const settings = s.agents ?? await getJson('/api/settings');
|
|
768
|
+
await readOllama();
|
|
769
|
+
if (stepId() !== 'ready') return;
|
|
770
|
+
const connected = (settings?.agents ?? []).filter((agent) => agent.id !== 'madre' && host.agentState?.(agent, settings)?.ok).map((agent) => agent.label ?? agent.id);
|
|
771
|
+
const rooms = host.projects?.() ?? [];
|
|
772
|
+
const added = s.added.map((one) => rooms.find((room) => room.root === one.root || room.name === one.name)).filter(Boolean);
|
|
773
|
+
const room = added[0] ?? rooms[0] ?? null;
|
|
774
|
+
const aiOn = s.ollama?.running && chatModels().length > 0;
|
|
775
|
+
const provider = s.memory?.embedProvider;
|
|
776
|
+
const rows = [
|
|
777
|
+
[t('Agents'), connected.length ? new Intl.ListFormat(language(), { type: 'conjunction' }).format(connected) : t('None connected yet'), connected.length > 0, 'agents'],
|
|
778
|
+
[t('AI on your computer'), aiOn ? `${s.ollama.chatModel ?? chatModels()[0].name}${localHost(s.ollama.host) ? '' : ` · ${t('on another computer')}`}` : t('For later'), aiOn, 'ai'],
|
|
779
|
+
[t('Memory'), provider === 'ollama' ? (s.ollama?.host && !localHost(s.ollama.host) ? t('Search by meaning, on the other computer') : t('Search by meaning, on your computer')) : provider === 'gemini' ? t('Search by meaning, with Gemini') : t('Exact words'), provider === 'ollama' || provider === 'gemini', 'memory'],
|
|
780
|
+
[t('Project'), room ? room.name : t('None yet'), Boolean(room), 'project'],
|
|
781
|
+
];
|
|
782
|
+
const summary = el('div', 'wl-card wl-checks');
|
|
783
|
+
for (const [title, sub, ok, id] of rows) {
|
|
784
|
+
const row = el('div', `wl-check${ok ? '' : ' later'}`);
|
|
785
|
+
const tick = el('span', 'wl-tick');
|
|
786
|
+
if (ok) tick.innerHTML = TICK; // trusted: our own SVG string
|
|
787
|
+
else tick.textContent = '–';
|
|
788
|
+
const words = el('div');
|
|
789
|
+
words.append(el('b', null, title), el('small', null, sub));
|
|
790
|
+
row.append(tick, words);
|
|
791
|
+
if (!ok) row.append(button('wl-btn small', t('Do it now'), () => go(id)));
|
|
792
|
+
summary.append(row);
|
|
793
|
+
}
|
|
794
|
+
const nextCards = el('div', 'wl-split');
|
|
795
|
+
const card = (title, sub, onClick) => { const node = button('wl-card wl-next', null, onClick); node.append(el('b', null, title), el('small', null, sub)); return node; };
|
|
796
|
+
nextCards.append(
|
|
797
|
+
card(t('Connect your projects'), t('So one can look up what another knows.'), () => { finish(); host.openLinks?.(); }),
|
|
798
|
+
card(t('Module Market'), t('Images, reminders, GitHub and more.'), () => { finish(); host.openMarket?.(); }),
|
|
799
|
+
);
|
|
800
|
+
// Training (B-7): ready here, switched on in a project's Settings.
|
|
801
|
+
const fitNow = fit();
|
|
802
|
+
const train = fitNow?.recommended?.train ?? null;
|
|
803
|
+
const trainCard = el('div', 'wl-card wl-train');
|
|
804
|
+
trainCard.append(el('b', null, t('Train your own AI')));
|
|
805
|
+
if (train) {
|
|
806
|
+
trainCard.append(el('p', 'wl-muted', t('Your computer can train its own AI with what your project knows, up to {model}. Everything is ready: you turn it on in your project\'s Settings › Memory › Train your own AI.', { model: train.label })));
|
|
807
|
+
const reqs = el('ul', 'wl-reqs');
|
|
808
|
+
reqs.append(el('li', null, facts().accelerator === 'apple' ? t('Apple chip with 12 GB of memory or more') : t('NVIDIA card with 9 GB or more and CUDA 12 (experimental)')));
|
|
809
|
+
reqs.append(el('li', null, t('About {gb} GB free while it trains', { gb: Math.ceil(train.params * 5.5) + 2 })));
|
|
810
|
+
trainCard.append(reqs);
|
|
811
|
+
// How it is done, step by step, in the manual (2026-10-28).
|
|
812
|
+
trainCard.append(button('wl-btn ghost small', t('How it is trained'), () => window.open(`/manual?lang=${language()}#entrena`, '_blank', 'noopener')));
|
|
813
|
+
} else {
|
|
814
|
+
trainCard.append(el('p', 'wl-muted', t('This computer cannot train. It takes a Mac with an Apple chip and 12 GB of memory, or an NVIDIA card with 9 GB or more.')));
|
|
815
|
+
}
|
|
816
|
+
content.replaceChildren(...head(t('MADRE is ready'), t('Here is what is ready. Anything you left for later has its button.')), summary, el('p', 'wl-eyebrow wl-gap', t('What comes next')), nextCards, trainCard);
|
|
817
|
+
const learn = button('wl-btn', t('Get to know MADRE'), () => { const after = then ?? host.chapters; finish(); after?.(); });
|
|
818
|
+
// Home first (2026-10-30): its first-time cards walk the person to their project; the project's
|
|
819
|
+
// own cards come when they open it. Going straight into the project skipped Home's.
|
|
820
|
+
footer({
|
|
821
|
+
next: t('Go to Home'),
|
|
822
|
+
onNext: () => finish(),
|
|
823
|
+
extra: learn,
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// ---- The events of this page's MADRE: Ollama's install and downloads, as they go.
|
|
828
|
+
function listen() {
|
|
829
|
+
try {
|
|
830
|
+
stream = new EventSource('/api/events');
|
|
831
|
+
stream.onmessage = (message) => {
|
|
832
|
+
let event = null;
|
|
833
|
+
try { event = JSON.parse(message.data); } catch { return; }
|
|
834
|
+
if (event?.payload?.id !== 'ollama') return;
|
|
835
|
+
if (event.type === 'extension.install.output') {
|
|
836
|
+
const lines = event.payload.lines ?? [];
|
|
837
|
+
const pull = [...s.pulls.values()].find((one) => one.running);
|
|
838
|
+
if (pull) {
|
|
839
|
+
for (const line of lines) {
|
|
840
|
+
const match = PULL_LINE.exec(line);
|
|
841
|
+
if (match) { pull.first ??= match[1]; if (match[1] === pull.first) pull.pct = Number(match[2]); }
|
|
842
|
+
else if (/verifying|writing manifest|success/.test(line)) { pull.pct = 100; pull.phase = 'verify'; }
|
|
843
|
+
}
|
|
844
|
+
} else if (s.install?.running) s.install.lines = [...(s.install.lines ?? []), ...lines].slice(-20);
|
|
845
|
+
repaint();
|
|
846
|
+
}
|
|
847
|
+
if (event.type === 'extension.install.finished') {
|
|
848
|
+
const model = event.payload.model ?? null;
|
|
849
|
+
const pull = model ? s.pulls.get(model) : [...s.pulls.values()].find((one) => one.running);
|
|
850
|
+
if (pull) {
|
|
851
|
+
if (event.payload.ok) { pull.running = false; pull.pct = 100; }
|
|
852
|
+
else if (event.payload.cancelled) Object.assign(pull, { running: false, cancelled: true, cancelling: false, error: null });
|
|
853
|
+
else Object.assign(pull, { running: false, error: event.payload.detail ?? t('It did not finish.'), trouble: event.payload.trouble ?? null });
|
|
854
|
+
} else if (s.install?.running) {
|
|
855
|
+
s.install = event.payload.ok ? null : { error: event.payload.detail ?? t('It did not install.'), trouble: event.payload.trouble ?? null, manual: event.payload.trouble === 'permission' };
|
|
856
|
+
}
|
|
857
|
+
void readOllama({ probe: true }).then(repaint);
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
} catch { /* no stream: «I did it» and the probe keep it current */ }
|
|
861
|
+
}
|
|
862
|
+
const repaint = () => { if (stepId() === 'ai') paintAi(); else if (stepId() === 'memory') paintMemory(); };
|
|
863
|
+
|
|
864
|
+
function show() {
|
|
865
|
+
leave?.();
|
|
866
|
+
leave = null;
|
|
867
|
+
paintRail();
|
|
868
|
+
content.scrollTop = 0;
|
|
869
|
+
const id = stepId();
|
|
870
|
+
if (id === 'hello') hello();
|
|
871
|
+
else if (id === 'machine') machine();
|
|
872
|
+
else if (id === 'agents') agents();
|
|
873
|
+
else if (id === 'ai') ai();
|
|
874
|
+
else if (id === 'memory') memoryStep();
|
|
875
|
+
else if (id === 'project') project();
|
|
876
|
+
else void ready();
|
|
877
|
+
// The key just pressed left with the step it was on: the keyboard and a screen reader start
|
|
878
|
+
// again at the new step's title, not at the top of the page.
|
|
879
|
+
if (dialog.open && !dialog.classList.contains('intro')) {
|
|
880
|
+
const title = content.querySelector('.wl-title');
|
|
881
|
+
if (title) { title.tabIndex = -1; title.focus({ preventScroll: true }); }
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
function finish() {
|
|
885
|
+
if (finished) return;
|
|
886
|
+
finished = true;
|
|
887
|
+
void save({ finished: true, done: 'ready', at: 'ready' });
|
|
888
|
+
dialog.close();
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
dialog.addEventListener('close', () => {
|
|
892
|
+
leave?.();
|
|
893
|
+
stream?.close();
|
|
894
|
+
clearInterval(pollTimer);
|
|
895
|
+
current = null;
|
|
896
|
+
dialog.remove();
|
|
897
|
+
host.closed?.();
|
|
898
|
+
});
|
|
899
|
+
// Hidden until it is known where the person is: the first step opens with the opening (loader.js),
|
|
900
|
+
// any other straight away.
|
|
901
|
+
dialog.classList.add('waiting');
|
|
902
|
+
dialog.showModal();
|
|
903
|
+
content.append(el('p', 'wl-muted', t('Reading…')));
|
|
904
|
+
|
|
905
|
+
current = { go: (to) => { s.step = Math.max(0, WELCOME_STEPS.indexOf(to)); show(); }, close: () => dialog.close(), node: dialog };
|
|
906
|
+
void Promise.all([getJson('/api/tour'), getJson('/api/environment'), readOllama()]).then(([tour, environment]) => {
|
|
907
|
+
if (!current) return;
|
|
908
|
+
s.progress = tour?.state?.welcome ?? s.progress;
|
|
909
|
+
s.env = environment?.environment ?? null;
|
|
910
|
+
s.hardware = environment?.hardware ?? null;
|
|
911
|
+
s.geminiKey = Boolean(environment?.geminiKey);
|
|
912
|
+
s.memory = environment?.memory ?? null;
|
|
913
|
+
const from = at ?? s.progress.at ?? 'hello';
|
|
914
|
+
s.step = Math.max(0, WELCOME_STEPS.indexOf(from));
|
|
915
|
+
listen();
|
|
916
|
+
show();
|
|
917
|
+
if (!s.progress.at) void save({ at: WELCOME_STEPS[s.step] });
|
|
918
|
+
// The opening plays on the first step; after it the rail's logo is already drawn, and stays still.
|
|
919
|
+
dialog.classList.remove('waiting');
|
|
920
|
+
if (WELCOME_STEPS[s.step] === 'hello') void playOpening(dialog, { skipLabel: t('Skip') }).then((played) => { if (played) brand.classList.add('still'); });
|
|
921
|
+
});
|
|
922
|
+
return current;
|
|
923
|
+
}
|