@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,33 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// Why an install or a sign-in went wrong, in one word (2026-10-28, docs/private/BIENVENIDA-1.0.6.md).
|
|
4
|
+
// Home threw these failures away: the person pressed Install, nothing happened, and no screen said
|
|
5
|
+
// why. The word is read from what the program itself printed; the page turns it into plain words and
|
|
6
|
+
// a way out (salas-mac.js, TROUBLE_WORDS). A failure nothing here recognises is `unknown`, and the
|
|
7
|
+
// page shows its last line as it was said rather than guess.
|
|
8
|
+
|
|
9
|
+
const NETWORK = /ENOTFOUND|EAI_AGAIN|ECONNREFUSED|ECONNRESET|ETIMEDOUT|ENETUNREACH|getaddrinfo|socket hang up|network (is )?unreachable|unable to get local issuer|self[- ]signed certificate|request to https?:\/\/\S+ failed/i;
|
|
10
|
+
const PERMISSION = /EACCES|EPERM|permission denied|operation not permitted|access is denied/i;
|
|
11
|
+
const DISK = /ENOSPC|no space left/i;
|
|
12
|
+
const NO_NPM = /spawn npm(\.cmd)? ENOENT|npm(\.cmd)?: (command )?not found|'npm' is not recognized|command not found: npm/i;
|
|
13
|
+
const TIMEOUT = /timed out|timeout|ETIMEDOUT after|SIGTERM/i;
|
|
14
|
+
const CANCELLED = /cancell?ed|aborted by the user/i;
|
|
15
|
+
|
|
16
|
+
export function installTrouble(text = '') {
|
|
17
|
+
const said = String(text);
|
|
18
|
+
if (NO_NPM.test(said)) return 'npm-missing';
|
|
19
|
+
if (DISK.test(said)) return 'disk';
|
|
20
|
+
if (NETWORK.test(said)) return 'network';
|
|
21
|
+
if (PERMISSION.test(said)) return 'permission';
|
|
22
|
+
if (TIMEOUT.test(said)) return 'timeout';
|
|
23
|
+
return 'unknown';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function loginTrouble({ refused = false, text = '' } = {}) {
|
|
27
|
+
if (refused) return 'refused-account';
|
|
28
|
+
const said = String(text);
|
|
29
|
+
if (CANCELLED.test(said)) return 'cancelled';
|
|
30
|
+
if (NETWORK.test(said)) return 'network';
|
|
31
|
+
if (TIMEOUT.test(said)) return 'timeout';
|
|
32
|
+
return 'unknown';
|
|
33
|
+
}
|
package/src/setup.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
4
|
import { createInterface } from 'node:readline/promises';
|
|
5
5
|
import { stdin, stdout } from 'node:process';
|
|
@@ -107,7 +107,7 @@ export function renderReport({ agents, probes, projectRoot, config = {}, palette
|
|
|
107
107
|
: local ? 'NO CLI ONLINE · @MADRE (LOCAL) IS. THE ROOM CAN OPEN WITH MEMORY ALONE; CONNECT A CLI TO WORK ON FILES.'
|
|
108
108
|
: `NO AGENT ONLINE. THE ROOM OPENS ANYWAY AND WALKS YOU THROUGH CONNECTING ONE.`;
|
|
109
109
|
lines.push('');
|
|
110
|
-
lines.push(` ${p.phosphor('
|
|
110
|
+
lines.push(` ${p.phosphor('MADRE')}${p.dim(' ›')} ${p.bold(verdict)}`);
|
|
111
111
|
return lines.join('\n');
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -158,7 +158,7 @@ export async function runSetup({ projectRoot, stateRoot, interactive = stdin.isT
|
|
|
158
158
|
if (answer === 'q') return { action: 'quit', agents, probes };
|
|
159
159
|
if (answer === 's') {
|
|
160
160
|
if (!anyoneOnline()) {
|
|
161
|
-
log(` ${p.warn('
|
|
161
|
+
log(` ${p.warn('MADRE ›')} no agent online; the room would open empty. Configure one first or press s again to open anyway.`);
|
|
162
162
|
const again = (await ask('start anyway? [y/N]')).trim().toLowerCase();
|
|
163
163
|
if (again !== 'y') continue;
|
|
164
164
|
}
|
package/src/smtp.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// SMTP, enough of it to send one message over TLS. No dependencies, by the same rule as the rest
|
|
4
4
|
// of MADRE: a library that handles the human's mail password is a library somebody has to read.
|
|
5
5
|
//
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// ANONYMOUS DIAGNOSTICS (2026-10-28): what goes wrong in every copy of MADRE, and how much of it is
|
|
4
|
+
// used, told to its author on madre.run without asking the person anything.
|
|
5
|
+
//
|
|
6
|
+
// Two kinds of thing are kept, here, in ~/.pulse/telemetry/, one file per day:
|
|
7
|
+
// · errors — every failure a room or the page meets, the ones Diagnostics knows (with their MU
|
|
8
|
+
// code) and the ones it does not, crashes of the process, routes that broke, installs that
|
|
9
|
+
// failed: the message redacted by the sentinel's own rules (no home, no user name, no key, no
|
|
10
|
+
// email), the first lines of MADRE's own code it went through, and a fingerprint so the same
|
|
11
|
+
// failure in a thousand copies is one row;
|
|
12
|
+
// · counts — how many turns went to which agent and at which mode, which features ran, which of
|
|
13
|
+
// MADRE's modules are on: numbers and names of MADRE's own parts, never anything a person wrote,
|
|
14
|
+
// no project, no path, no file name.
|
|
15
|
+
// Once a day (with the «still in use» notice), and an hour after a failure never seen before, what
|
|
16
|
+
// is kept goes to madre.run/api/telemetry with this copy's random install id, its version, its
|
|
17
|
+
// system and Node's major version — the four things the notice already says — and is then deleted
|
|
18
|
+
// here. Offline it waits; MADRE never waits on it.
|
|
19
|
+
//
|
|
20
|
+
// It is on unless the person turns it off (Settings › Version and reports › «Send anonymous
|
|
21
|
+
// diagnostics», or PULSE_TELEMETRY=0): the author's decision, 2026-10-28. The exact batch that would
|
|
22
|
+
// go next can be read in the same place (`preview`). docs/REFERENCE.md › «Lo que sale de la máquina».
|
|
23
|
+
|
|
24
|
+
import { createHash } from 'node:crypto';
|
|
25
|
+
import { appendFile, mkdir, readdir, readFile, rename, rm, rmdir, stat } from 'node:fs/promises';
|
|
26
|
+
import { arch } from 'node:os';
|
|
27
|
+
import { join } from 'node:path';
|
|
28
|
+
import { installId } from './heartbeat.mjs';
|
|
29
|
+
import { redact } from './sentinel-errors.mjs';
|
|
30
|
+
|
|
31
|
+
export const TELEMETRY_URL = 'https://madre.run/api/telemetry';
|
|
32
|
+
export const TELEMETRY_VERSION = 1;
|
|
33
|
+
// What one copy keeps and sends at most: enough to read a fault, never a flood.
|
|
34
|
+
const MAX_MESSAGE = 600;
|
|
35
|
+
const MAX_FRAMES = 6;
|
|
36
|
+
const MAX_ERRORS = 60;
|
|
37
|
+
const MAX_COUNTS = 160;
|
|
38
|
+
const MAX_DAYS = 14;
|
|
39
|
+
const SOON_MS = 60 * 60 * 1000;
|
|
40
|
+
// A send waits at most 8 s for madre.run: a lock this old was left behind.
|
|
41
|
+
const STALE_LOCK_MS = 2 * 60 * 1000;
|
|
42
|
+
const KINDS = new Set(['agent', 'crash', 'route', 'page', 'install', 'model', 'startup', 'other']);
|
|
43
|
+
const KEY = /^[a-z0-9][a-z0-9._:-]{0,47}$/;
|
|
44
|
+
const AGENT = /^[a-z][a-z0-9-]{0,23}$/;
|
|
45
|
+
const CODE = /^MU-\d{3}$/;
|
|
46
|
+
// A day's file, and one set aside while it travels (kept if the send failed, sent with the next).
|
|
47
|
+
const FILE = /^\d{4}-\d{2}-\d{2}\.jsonl(?:\.[a-z0-9]+\.out)?$/;
|
|
48
|
+
|
|
49
|
+
const dayOf = (date) => date.toISOString().slice(0, 10);
|
|
50
|
+
export const telemetryDir = (root) => join(root, 'telemetry');
|
|
51
|
+
|
|
52
|
+
// Whether this copy tells: on unless the person or the environment said no.
|
|
53
|
+
export function telemetryOn(config = {}, env = process.env) {
|
|
54
|
+
if (env.PULSE_TELEMETRY === '0') return false;
|
|
55
|
+
return config?.telemetry?.diagnostics !== false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// MADRE's own frames of a stack, as places in its code: «src/server.mjs:1204», never a path of the
|
|
59
|
+
// machine, never a frame of Node or of a dependency.
|
|
60
|
+
export function ownFrames(stack) {
|
|
61
|
+
const frames = [];
|
|
62
|
+
for (const line of String(stack ?? '').split('\n')) {
|
|
63
|
+
// In the server's own files, or in a page's scripts as the browser names them (its address).
|
|
64
|
+
const place = line.match(/(?:\/|\\|\()((?:src|public|bin)[/\\][\w./\\-]+\.(?:m?js|cjs)):(\d+)(?::\d+)?/)
|
|
65
|
+
?? line.match(/https?:\/\/(?:127\.0\.0\.1|localhost|\[::1\])(?::\d+)?\/()([\w.-]+\.js):(\d+)(?::\d+)?/);
|
|
66
|
+
if (!place) continue;
|
|
67
|
+
const file = place[1] || (place[2] ? `public/${place[2]}` : '');
|
|
68
|
+
const at = `${file.replace(/\\/g, '/')}:${place[3] ?? place[2]}`;
|
|
69
|
+
if (!frames.includes(at)) frames.push(at);
|
|
70
|
+
if (frames.length >= MAX_FRAMES) break;
|
|
71
|
+
}
|
|
72
|
+
return frames;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Every path in a message is a place of the person's (a project, a folder, a file name): it leaves as
|
|
76
|
+
// «<path>», keeping only its extension; a place in MADRE's own code keeps its name inside the code.
|
|
77
|
+
export function placesOut(text) {
|
|
78
|
+
return String(text ?? '')
|
|
79
|
+
.replace(/(?:[A-Za-z]:\\|~[\\/]|(?<![:\w/.])\.{0,2}\/)[^\s"'`,;)]*[\\/][^\s"'`,;)]*/g, (path) => {
|
|
80
|
+
const own = path.replace(/\\/g, '/').match(/(?:^|\/)((?:src|public|bin)\/[\w./-]+\.(?:m?js|cjs))(?::\d+)*$/);
|
|
81
|
+
if (own && /(?:^|\/)(?:madre|pulse)\/|node_modules\/(?:@[^/]+\/)?madre\//.test(path.replace(/\\/g, '/'))) return own[1];
|
|
82
|
+
const ext = path.match(/\.([a-z0-9]{1,6})$/i);
|
|
83
|
+
return ext ? `<path>.${ext[1].toLowerCase()}` : '<path>';
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// One failure, in the shape that leaves: everything that could name the person or the machine out.
|
|
88
|
+
export function errorEntry({ kind = 'other', code = null, agent = null, agentVersion = null, message = '', stack = null, where = null } = {}, { home, user } = {}) {
|
|
89
|
+
// What an agent quotes in its error («…», "…") is often the person's own text: it leaves as «…».
|
|
90
|
+
const first = placesOut(redact(String(message ?? '').split('\n')[0] || String(message ?? ''), { home, user })).replace(/\s+/g, ' ').trim();
|
|
91
|
+
const said = (kind === 'agent' ? first.replace(/"[^"]{1,}"|«[^»]{1,}»|“[^”]{1,}”/g, '«…»') : first).slice(0, MAX_MESSAGE);
|
|
92
|
+
const frames = ownFrames(stack ?? message);
|
|
93
|
+
const safeKind = KINDS.has(kind) ? kind : 'other';
|
|
94
|
+
const safeAgent = typeof agent === 'string' && AGENT.test(agent) ? agent : null;
|
|
95
|
+
const safeCode = typeof code === 'string' && CODE.test(code) ? code : null;
|
|
96
|
+
// The same failure everywhere is one fingerprint: numbers, quoted words and ids do not count.
|
|
97
|
+
const shape = said.toLowerCase().replace(/["'«][^"'»]*["'»]/g, 'Q').replace(/[0-9a-f]{8,}/g, 'H').replace(/\d+/g, '#');
|
|
98
|
+
const fp = createHash('sha1').update(`${safeKind}|${safeCode ?? ''}|${safeAgent ?? ''}|${shape}|${frames[0] ?? ''}`).digest('hex').slice(0, 16);
|
|
99
|
+
return {
|
|
100
|
+
fp, kind: safeKind, code: safeCode, agent: safeAgent,
|
|
101
|
+
agentVersion: typeof agentVersion === 'string' ? agentVersion.slice(0, 24) : null,
|
|
102
|
+
where: typeof where === 'string' ? redact(where).slice(0, 80) : null,
|
|
103
|
+
message: said, frames,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export class Telemetry {
|
|
108
|
+
#root;
|
|
109
|
+
#version;
|
|
110
|
+
#enabled;
|
|
111
|
+
#now;
|
|
112
|
+
#home;
|
|
113
|
+
#user;
|
|
114
|
+
#seen = new Set(); // fingerprints already kept today by this process
|
|
115
|
+
#lastSent = 0;
|
|
116
|
+
#soon = null;
|
|
117
|
+
#send = null;
|
|
118
|
+
#chain = Promise.resolve();
|
|
119
|
+
|
|
120
|
+
constructor({ root, version = 'dev', enabled = () => true, now = () => new Date(), home, user } = {}) {
|
|
121
|
+
this.#root = root;
|
|
122
|
+
this.#version = version;
|
|
123
|
+
this.#enabled = enabled;
|
|
124
|
+
this.#now = now;
|
|
125
|
+
this.#home = home;
|
|
126
|
+
this.#user = user;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Wired by the server: how to send, once a failure never seen before asks for it soon.
|
|
130
|
+
onSoon(send) { this.#send = send; }
|
|
131
|
+
|
|
132
|
+
// One write after another, in the order they were asked: «the last value wins» needs the order.
|
|
133
|
+
#keep(line) {
|
|
134
|
+
const at = dayOf(this.#now());
|
|
135
|
+
this.#chain = this.#chain.then(async () => {
|
|
136
|
+
if (!this.#root || !(await this.#enabled())) return;
|
|
137
|
+
const dir = telemetryDir(this.#root);
|
|
138
|
+
await mkdir(dir, { recursive: true });
|
|
139
|
+
await appendFile(join(dir, `${at}.jsonl`), `${JSON.stringify(line)}\n`);
|
|
140
|
+
}).catch(() => null);
|
|
141
|
+
return this.#chain;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Once what was asked to be kept is on disk (a send, and the tests, wait for it).
|
|
145
|
+
async settled() { await this.#chain; }
|
|
146
|
+
|
|
147
|
+
// A turn, a feature, a module: one more of it today.
|
|
148
|
+
count(key, n = 1) {
|
|
149
|
+
if (!KEY.test(String(key)) || !Number.isFinite(n) || n <= 0) return;
|
|
150
|
+
void this.#keep({ t: 'c', k: key, n: Math.min(1e6, Math.round(n)) });
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// How something stands today (how many projects, whether the local AI is on): the last value wins.
|
|
154
|
+
gauge(key, value) {
|
|
155
|
+
if (!KEY.test(String(key)) || !Number.isFinite(value)) return;
|
|
156
|
+
void this.#keep({ t: 'g', k: key, v: Math.round(value) });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// A failure. Kept at once; a fingerprint this process has not seen today asks for a send soon.
|
|
160
|
+
error(input) {
|
|
161
|
+
const entry = errorEntry(input, { home: this.#home, user: this.#user });
|
|
162
|
+
const at = this.#now().toISOString();
|
|
163
|
+
void this.#keep({ t: 'e', at, ...entry });
|
|
164
|
+
if (!this.#seen.has(entry.fp)) {
|
|
165
|
+
this.#seen.add(entry.fp);
|
|
166
|
+
if (this.#send && !this.#soon && Date.now() - this.#lastSent > SOON_MS / 4) {
|
|
167
|
+
this.#soon = setTimeout(() => { this.#soon = null; void this.#send?.(); }, SOON_MS);
|
|
168
|
+
this.#soon.unref?.();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return entry;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// What would go next, read from what is kept: the days, counted, and the failures, one row each.
|
|
175
|
+
// `only`: the files to read (a send reads the ones it set aside); otherwise all that are kept.
|
|
176
|
+
async batch({ only = null } = {}) {
|
|
177
|
+
const dir = telemetryDir(this.#root);
|
|
178
|
+
const names = only ?? (await readdir(dir).catch(() => [])).filter((name) => FILE.test(name));
|
|
179
|
+
const byDay = new Map();
|
|
180
|
+
const errors = new Map();
|
|
181
|
+
for (const name of names.sort()) {
|
|
182
|
+
const day = name.slice(0, 10);
|
|
183
|
+
const into = byDay.get(day) ?? { counts: {}, gauges: {} };
|
|
184
|
+
byDay.set(day, into);
|
|
185
|
+
const text = await readFile(join(dir, name), 'utf8').catch(() => '');
|
|
186
|
+
for (const raw of text.split('\n')) {
|
|
187
|
+
if (!raw.trim()) continue;
|
|
188
|
+
let line;
|
|
189
|
+
try { line = JSON.parse(raw); } catch { continue; }
|
|
190
|
+
if (line.t === 'c' && KEY.test(line.k)) into.counts[line.k] = (into.counts[line.k] ?? 0) + (Number(line.n) || 0);
|
|
191
|
+
else if (line.t === 'g' && KEY.test(line.k)) into.gauges[line.k] = Number(line.v) || 0;
|
|
192
|
+
else if (line.t === 'e' && line.fp) {
|
|
193
|
+
const kept = errors.get(line.fp);
|
|
194
|
+
if (kept) { kept.count += 1; kept.last = line.at; }
|
|
195
|
+
else errors.set(line.fp, { fp: line.fp, kind: line.kind, code: line.code ?? null, agent: line.agent ?? null, agentVersion: line.agentVersion ?? null, where: line.where ?? null, message: line.message ?? '', frames: Array.isArray(line.frames) ? line.frames.slice(0, MAX_FRAMES) : [], count: 1, first: line.at, last: line.at });
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const trim = (all) => Object.fromEntries(Object.entries(all).sort((a, b) => b[1] - a[1]).slice(0, MAX_COUNTS));
|
|
200
|
+
const days = [...byDay.entries()].sort(([a], [b]) => a.localeCompare(b)).slice(-MAX_DAYS)
|
|
201
|
+
.map(([day, { counts, gauges }]) => ({ day, counts: trim(counts), gauges: trim(gauges) }))
|
|
202
|
+
.filter((one) => Object.keys(one.counts).length || Object.keys(one.gauges).length);
|
|
203
|
+
return { names, days, errors: [...errors.values()].sort((a, b) => b.count - a.count).slice(0, MAX_ERRORS) };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// The body, exactly as it leaves: built here, in one place, so a test and the person can read it.
|
|
207
|
+
async preview({ only = null } = {}) {
|
|
208
|
+
const { days, errors } = await this.batch({ only });
|
|
209
|
+
return {
|
|
210
|
+
v: TELEMETRY_VERSION,
|
|
211
|
+
id: await installId(this.#root),
|
|
212
|
+
version: this.#version,
|
|
213
|
+
os: ['darwin', 'linux', 'win32'].includes(process.platform) ? process.platform : 'other',
|
|
214
|
+
wsl: Boolean(process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP),
|
|
215
|
+
arch: ['arm64', 'x64'].includes(arch()) ? arch() : 'other',
|
|
216
|
+
node: process.versions.node.split('.')[0],
|
|
217
|
+
days,
|
|
218
|
+
errors,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Sends what is kept and forgets it. Several processes of one copy may try at once: the first to
|
|
223
|
+
// make the lock sends, the others leave it. What is sent is first set aside (renamed, at once), so
|
|
224
|
+
// what is written while it travels starts a new file and is neither lost nor sent twice.
|
|
225
|
+
async flush({ fetchImpl = globalThis.fetch, url = process.env.PULSE_TELEMETRY_URL ?? TELEMETRY_URL } = {}) {
|
|
226
|
+
if (!this.#root || !(await this.#enabled())) return { sent: false, reason: 'off' };
|
|
227
|
+
const dir = telemetryDir(this.#root);
|
|
228
|
+
const lock = join(dir, '.sending');
|
|
229
|
+
await this.settled();
|
|
230
|
+
// A lock older than any send can last was left by a process that ended mid-way (Ctrl+C, «Turn
|
|
231
|
+
// MADRE off», a restart): it is taken back, or this copy would never send again.
|
|
232
|
+
const take = async () => { await mkdir(dir, { recursive: true }); await mkdir(lock); };
|
|
233
|
+
try { await take(); } catch {
|
|
234
|
+
const left = await stat(lock).catch(() => null);
|
|
235
|
+
if (!left || Date.now() - left.mtimeMs < STALE_LOCK_MS) return { sent: false, reason: 'busy' };
|
|
236
|
+
await rmdir(lock).catch(() => null);
|
|
237
|
+
try { await take(); } catch { return { sent: false, reason: 'busy' }; }
|
|
238
|
+
}
|
|
239
|
+
const aside = [];
|
|
240
|
+
try {
|
|
241
|
+
for (const name of (await readdir(dir)).filter((one) => FILE.test(one))) {
|
|
242
|
+
const out = name.endsWith('.out') ? name : `${name}.${Date.now().toString(36)}.out`;
|
|
243
|
+
if (out !== name) await rename(join(dir, name), join(dir, out));
|
|
244
|
+
aside.push(out);
|
|
245
|
+
}
|
|
246
|
+
if (!aside.length) return { sent: false, reason: 'empty' };
|
|
247
|
+
const body = await this.preview({ only: aside });
|
|
248
|
+
if (!body.days.length && !body.errors.length) { for (const name of aside) await rm(join(dir, name), { force: true }); return { sent: false, reason: 'empty' }; }
|
|
249
|
+
const response = await fetchImpl(url, { method: 'POST', headers: { 'content-type': 'application/json', 'user-agent': `madre/${this.#version}` }, body: JSON.stringify(body), signal: AbortSignal.timeout(8000) });
|
|
250
|
+
if (!response.ok) return { sent: false, reason: `HTTP ${response.status}` };
|
|
251
|
+
for (const name of aside) await rm(join(dir, name), { force: true });
|
|
252
|
+
this.#lastSent = Date.now();
|
|
253
|
+
return { sent: true, days: body.days.length, errors: body.errors.length };
|
|
254
|
+
} catch (error) {
|
|
255
|
+
return { sent: false, reason: error?.message ?? 'unreachable' };
|
|
256
|
+
} finally {
|
|
257
|
+
await rmdir(lock).catch(() => null);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Turned off: what was kept goes too, nothing waits to be sent.
|
|
262
|
+
async forget() {
|
|
263
|
+
await this.settled();
|
|
264
|
+
await rm(telemetryDir(this.#root), { recursive: true, force: true }).catch(() => null);
|
|
265
|
+
}
|
|
266
|
+
}
|
package/src/terms.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
|
+
// ACCEPTING MADRE'S LICENSE AND PRIVACY NOTICE (2026-10-30). Before MADRE can be used, the person
|
|
4
|
+
// accepts its license (LICENSE, the Business Source License 1.1: free for individuals and teams of
|
|
5
|
+
// up to ten) and its privacy notice, once per version of their text (TERMS_VERSION), on this computer.
|
|
6
|
+
// Whoever came from a MADRE before 1.1.0 is told what changed. The anonymous diagnostics are not a
|
|
7
|
+
// condition: they come on, said in plain words, and can be turned off right there or later.
|
|
8
|
+
//
|
|
9
|
+
// Kept in ~/.pulse/terms.json: the version accepted and when. Tests and automation (screenshots, QA
|
|
10
|
+
// houses) skip it with PULSE_TERMS=accepted; the test mode never asks.
|
|
11
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
12
|
+
import { join } from 'node:path';
|
|
13
|
+
|
|
14
|
+
// A new text (Pro and paid modules in 1.1.1) is a new version, and the person is asked again.
|
|
15
|
+
export const TERMS_VERSION = '2026-10-30';
|
|
16
|
+
export const TERMS_LINKS = {
|
|
17
|
+
license: { es: 'https://github.com/jossuealcacao-exe/madre/blob/main/LICENSE', en: 'https://github.com/jossuealcacao-exe/madre/blob/main/LICENSE' },
|
|
18
|
+
privacy: { es: 'https://madre.run/privacidad/', en: 'https://madre.run/en/privacy/' },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const termsWaived = (env = process.env) => env.PULSE_TEST_MODE === '1' || env.PULSE_TERMS === 'accepted';
|
|
22
|
+
|
|
23
|
+
export async function readTerms(root, { env = process.env } = {}) {
|
|
24
|
+
if (termsWaived(env)) return { accepted: true, version: TERMS_VERSION, at: null, waived: true };
|
|
25
|
+
try {
|
|
26
|
+
const kept = JSON.parse(await readFile(join(root, 'terms.json'), 'utf8'));
|
|
27
|
+
return { accepted: kept?.version === TERMS_VERSION, version: TERMS_VERSION, at: typeof kept?.at === 'string' ? kept.at : null, previous: kept?.version ?? null };
|
|
28
|
+
} catch {
|
|
29
|
+
return { accepted: false, version: TERMS_VERSION, at: null, previous: null };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function acceptTerms(root, { now = new Date() } = {}) {
|
|
34
|
+
const kept = { version: TERMS_VERSION, at: now.toISOString() };
|
|
35
|
+
await writeFile(join(root, 'terms.json'), `${JSON.stringify(kept)}\n`);
|
|
36
|
+
return { accepted: true, ...kept };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Whether this copy was in use before 1.1.0 (src/install-metrics.mjs, lifecycle.json `before`): it
|
|
40
|
+
// is told what changed instead of being welcomed as new.
|
|
41
|
+
export async function cameFromBefore(root) {
|
|
42
|
+
try { return JSON.parse(await readFile(join(root, 'lifecycle.json'), 'utf8'))?.before === true; } catch { return false; }
|
|
43
|
+
}
|
package/src/tour.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
// MADRE · © 2026 Jossue Alcalá ·
|
|
1
|
+
// SPDX-License-Identifier: BUSL-1.1
|
|
2
|
+
// MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
|
|
3
3
|
// The welcome of MADRE 1.0 (2026-10-11): one bonjour per person and per major version, then the
|
|
4
4
|
// chapters that tell everything new, at the person's own pace (docs: the «Recorrido de MADRE 1.0»
|
|
5
5
|
// decision, option B with two pieces of C — the one-line hints and the sheet of gestures).
|
|
@@ -32,14 +32,42 @@ export const TOUR_VERSION = '1.1';
|
|
|
32
32
|
export const CHAPTERS = ['moved', 'home', 'renamed', 'board', 'widgets', 'project', 'talk', 'modes', 'coordinator', 'links', 'maps', 'settings', 'modules', 'local', 'phone', 'gestures'];
|
|
33
33
|
// The places that confuse most, each told once in one line (from option C); then, from 1.1, what
|
|
34
34
|
// each key of Home's bar opens, the first time it opens, and what each widget of Home shows. (A
|
|
35
|
-
// project's bar says it with its own first-touch cards, public/app.js, FIRST_TOUCH
|
|
35
|
+
// project's bar says it with its own first-touch cards, public/app.js, FIRST_TOUCH, and its news
|
|
36
|
+
// with NEW_HINTS: both kept here too, `touch-<id>` and `new-<id>`. Kept in the page they lived in
|
|
37
|
+
// one port, and a project takes the first free port when it opens: the cards came back whenever it
|
|
38
|
+
// got another one, and the project that got the old port inherited them (2026-10-19).)
|
|
36
39
|
export const HINTS = ['switch', 'links', 'key4',
|
|
37
|
-
'home-links', 'home-map', 'home-settings', 'home-add',
|
|
38
|
-
'w-system', 'w-servers', 'w-memory', 'w-coordinator', 'w-models', 'w-usage'
|
|
40
|
+
'home-links', 'home-map', 'home-settings', 'home-add', 'new-add-widgets',
|
|
41
|
+
'w-system', 'w-servers', 'w-memory', 'w-coordinator', 'w-models', 'w-usage', 'w-agenda',
|
|
42
|
+
// The author's own widgets (2026-10-30): their first-time card came back on every start, never kept.
|
|
43
|
+
'w-errors', 'w-live', 'w-installs', 'w-environments',
|
|
44
|
+
'touch-settings', 'touch-modules', 'touch-market', 'touch-mother', 'touch-memory', 'touch-crew', 'touch-steps', 'touch-browser', 'touch-tree', 'touch-chats', 'touch-code', 'touch-mcp',
|
|
45
|
+
'new-copilot', 'new-mcp', 'new-finder', 'new-memory-access', 'new-dots',
|
|
46
|
+
// 1.0.5: the way in for whoever is new (the box, the agent, the permission; Home's first step),
|
|
47
|
+
// and what is new for whoever met MADRE before it.
|
|
48
|
+
'guide-talk', 'guide-agent', 'guide-mode', 'home-start',
|
|
49
|
+
// The short walks of 1.0.5 (2026-10-21): Home's Coordinator and where the manual is, in Home and
|
|
50
|
+
// in a project, and Code, for whoever is new.
|
|
51
|
+
'guide-code', 'guide-manual', 'home-coordinator', 'home-manual',
|
|
52
|
+
'new-code-ask', 'new-notes', 'new-connectors', 'new-manual',
|
|
53
|
+
// The two drawings of a map, planets and neurons (2026-10-28): said once, by the key that switches them.
|
|
54
|
+
'map-views'];
|
|
39
55
|
const PATHS = ['new', 'back', 'since'];
|
|
56
|
+
// The news this code knows (2026-10-21): written on the bonjour as the version a person MET MADRE
|
|
57
|
+
// with (`met`). The cards of what is new are for whoever met it before a version; someone who meets
|
|
58
|
+
// it here is shown the way in instead — the box, the agent, the permission. A tour.json from before
|
|
59
|
+
// this has no `met`: that person met MADRE before 1.0.5.
|
|
60
|
+
export const NEWS_LEVEL = '1.0.5';
|
|
61
|
+
const LEVEL = /^\d+\.\d+\.\d+$/;
|
|
40
62
|
const BEFORE = ['1.0'];
|
|
41
63
|
|
|
42
|
-
|
|
64
|
+
// The welcome of 1.0.6 (2026-10-28, docs/private/BIENVENIDA-1.0.6.md): the steps that leave MADRE
|
|
65
|
+
// ready after `npx madre` — agents, local AI, memory, the first project — in their order. Where the
|
|
66
|
+
// person is, what they finished and what they left for later are kept here too, so closing the page
|
|
67
|
+
// halfway brings them back to the same step, from whichever project or port they open next.
|
|
68
|
+
export const WELCOME_STEPS = ['hello', 'machine', 'agents', 'ai', 'memory', 'project', 'ready'];
|
|
69
|
+
const freshWelcome = () => ({ at: null, done: [], skipped: [], finished: null });
|
|
70
|
+
const fresh = (before = null) => ({ version: TOUR_VERSION, path: null, bonjourAt: null, done: [], at: null, closed: false, finished: null, hints: {}, held: null, before, met: null, welcome: freshWelcome() });
|
|
43
71
|
// A tab that shows the bonjour or the chapters says so every few seconds; another tab that finds it
|
|
44
72
|
// said within this long tells the person it is open there, instead of a second bonjour.
|
|
45
73
|
export const HELD_MS = 45 * 1000;
|
|
@@ -66,6 +94,13 @@ export async function readTour(stateRoot) {
|
|
|
66
94
|
hints: Object.fromEntries(HINTS.filter((id) => iso(raw.hints?.[id])).map((id) => [id, raw.hints[id]])),
|
|
67
95
|
held: raw.held && TAB.test(String(raw.held.by ?? '')) && iso(raw.held.at) ? { by: raw.held.by, at: raw.held.at } : null,
|
|
68
96
|
before: BEFORE.includes(raw.before) ? raw.before : null,
|
|
97
|
+
met: LEVEL.test(String(raw.met ?? '')) ? raw.met : null,
|
|
98
|
+
welcome: {
|
|
99
|
+
at: WELCOME_STEPS.includes(raw.welcome?.at) ? raw.welcome.at : null,
|
|
100
|
+
done: Array.isArray(raw.welcome?.done) ? WELCOME_STEPS.filter((id) => raw.welcome.done.includes(id)) : [],
|
|
101
|
+
skipped: Array.isArray(raw.welcome?.skipped) ? WELCOME_STEPS.filter((id) => raw.welcome.skipped.includes(id)) : [],
|
|
102
|
+
finished: iso(raw.welcome?.finished),
|
|
103
|
+
},
|
|
69
104
|
};
|
|
70
105
|
}
|
|
71
106
|
|
|
@@ -91,7 +126,7 @@ async function applyChange(stateRoot, change, now) {
|
|
|
91
126
|
if (!PATHS.includes(change.path)) return { error: 'path' };
|
|
92
127
|
state.path = change.path;
|
|
93
128
|
}
|
|
94
|
-
if (change.bonjour === true) state.bonjourAt
|
|
129
|
+
if (change.bonjour === true && !state.bonjourAt) { state.bonjourAt = at; state.met = NEWS_LEVEL; }
|
|
95
130
|
if (change.chapter !== undefined) {
|
|
96
131
|
if (!CHAPTERS.includes(change.chapter)) return { error: 'chapter' };
|
|
97
132
|
if (!state.done.includes(change.chapter)) state.done = CHAPTERS.filter((id) => id === change.chapter || state.done.includes(id));
|
|
@@ -113,6 +148,24 @@ async function applyChange(stateRoot, change, now) {
|
|
|
113
148
|
if (!HINTS.includes(change.hint)) return { error: 'hint' };
|
|
114
149
|
state.hints[change.hint] ??= at;
|
|
115
150
|
}
|
|
151
|
+
// The welcome: where the person is, a step done or left for later (one undoes the other), done
|
|
152
|
+
// with it, or from the start again (Settings › «See the welcome again»).
|
|
153
|
+
if (change.welcome !== undefined) {
|
|
154
|
+
const said = change.welcome;
|
|
155
|
+
if (!said || typeof said !== 'object') return { error: 'welcome' };
|
|
156
|
+
if (said.reset === true) state.welcome = freshWelcome();
|
|
157
|
+
const step = (id) => id === undefined || WELCOME_STEPS.includes(id);
|
|
158
|
+
if (!step(said.at) && said.at !== null) return { error: 'step' };
|
|
159
|
+
if (!step(said.done) || !step(said.skipped)) return { error: 'step' };
|
|
160
|
+
if (said.at !== undefined) state.welcome.at = said.at;
|
|
161
|
+
const mark = (into, other, id) => {
|
|
162
|
+
state.welcome[other] = state.welcome[other].filter((one) => one !== id);
|
|
163
|
+
state.welcome[into] = WELCOME_STEPS.filter((one) => one === id || state.welcome[into].includes(one));
|
|
164
|
+
};
|
|
165
|
+
if (said.done !== undefined) mark('done', 'skipped', said.done);
|
|
166
|
+
if (said.skipped !== undefined) mark('skipped', 'done', said.skipped);
|
|
167
|
+
if (said.finished === true) state.welcome.finished ??= at;
|
|
168
|
+
}
|
|
116
169
|
return writeTour(stateRoot, state);
|
|
117
170
|
}
|
|
118
171
|
|