@jossuealcala/madre 1.1.2 → 1.1.4

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.
Files changed (166) hide show
  1. package/CHANGELOG.en.md +40 -1
  2. package/CHANGELOG.md +40 -1
  3. package/README.en.md +3 -3
  4. package/README.md +3 -3
  5. package/SECURITY.md +11 -6
  6. package/TRADEMARKS.md +6 -2
  7. package/bin/madre.mjs +76 -11
  8. package/docs/REFERENCE.md +16 -10
  9. package/docs/SDK.md +36 -9
  10. package/docs/en/REFERENCE.md +12 -8
  11. package/docs/en/SDK.md +34 -8
  12. package/docs/en/training/README.md +1 -1
  13. package/docs/sdk/connector-module.mjs +1 -1
  14. package/docs/sdk/hello-module.mjs +39 -4
  15. package/docs/training/README.md +1 -1
  16. package/docs/training/train.sh +3 -0
  17. package/habilidades/explicamelo-facil/HABILIDAD.md +19 -0
  18. package/habilidades/hojas-de-calculo/HABILIDAD.md +18 -0
  19. package/habilidades/mensajes-a-clientes/HABILIDAD.md +19 -0
  20. package/habilidades/publicaciones-para-redes/HABILIDAD.md +19 -0
  21. package/habilidades/resumen-y-pendientes/HABILIDAD.md +18 -0
  22. package/habilidades/tu-pagina-paso-a-paso/HABILIDAD.md +19 -0
  23. package/package.json +7 -4
  24. package/public/activity.js +66 -22
  25. package/public/app.js +4947 -894
  26. package/public/assets/brand/OFL-SpaceGrotesk.txt +93 -0
  27. package/public/assets/brand/SpaceGrotesk-latin-ext.woff2 +0 -0
  28. package/public/assets/brand/SpaceGrotesk-latin.woff2 +0 -0
  29. package/public/assets/brand/madre-app-180.png +0 -0
  30. package/public/assets/brand/madre-app-192.png +0 -0
  31. package/public/assets/brand/madre-app-512.png +0 -0
  32. package/public/assets/brand/madre-app.svg +1 -1
  33. package/public/assets/brand/madre-favicon.svg +1 -1
  34. package/public/attribution.js +29 -19
  35. package/public/auto-open.js +102 -0
  36. package/public/brands.js +36 -19
  37. package/public/changes.js +63 -0
  38. package/public/en.js +1085 -102
  39. package/public/es.js +2940 -1656
  40. package/public/i18n.js +11 -0
  41. package/public/index.html +31 -27
  42. package/public/loader.js +322 -117
  43. package/public/macroverso.js +57 -355
  44. package/public/manual-content.js +69 -9
  45. package/public/manual.js +21 -6
  46. package/public/market-view.js +298 -84
  47. package/public/market.js +25 -2
  48. package/public/mcp-catalog.js +7 -2
  49. package/public/missions.js +169 -0
  50. package/public/news-scenes.js +292 -0
  51. package/public/nostromo-engine.js +935 -654
  52. package/public/notices.js +78 -0
  53. package/public/notifications.js +119 -0
  54. package/public/power.js +1 -1
  55. package/public/provider-marks.js +170 -0
  56. package/public/provider-pick.js +147 -0
  57. package/public/resay.js +4 -0
  58. package/public/review-ask.js +16 -13
  59. package/public/routing.js +29 -3
  60. package/public/salas-mac.css +467 -47
  61. package/public/salas-mac.html +8 -5
  62. package/public/salas-mac.js +805 -109
  63. package/public/salas.css +2 -2
  64. package/public/salas.html +2 -2
  65. package/public/salas.js +1 -1
  66. package/public/starters.js +128 -0
  67. package/public/styles.css +3036 -340
  68. package/public/subscription.js +303 -0
  69. package/public/terms-field.js +170 -0
  70. package/public/terms.js +117 -19
  71. package/public/tips.js +158 -0
  72. package/public/tour-chapters.js +88 -88
  73. package/public/tour.js +364 -46
  74. package/public/troubleshooting.js +313 -27
  75. package/public/welcome-scene.js +446 -0
  76. package/public/welcome.js +827 -282
  77. package/src/adapters/claude.mjs +2 -1
  78. package/src/adapters/codex.mjs +2 -1
  79. package/src/adapters/cursor.mjs +9 -6
  80. package/src/adapters/gemini-rest.mjs +236 -0
  81. package/src/adapters/gemini.mjs +13 -7
  82. package/src/adapters/grok.mjs +290 -0
  83. package/src/adapters/madre.mjs +71 -23
  84. package/src/adapters/opencode.mjs +15 -2
  85. package/src/adapters/process.mjs +14 -3
  86. package/src/adapters/steps.mjs +176 -0
  87. package/src/app-invite.mjs +90 -0
  88. package/src/auth-probe.mjs +32 -0
  89. package/src/billing-key.mjs +8 -0
  90. package/src/billing.mjs +317 -0
  91. package/src/bridge/policy.mjs +1 -1
  92. package/src/capabilities.mjs +46 -10
  93. package/src/chats.mjs +44 -2
  94. package/src/checkpoint.mjs +119 -1
  95. package/src/codex-route.mjs +113 -0
  96. package/src/commands.mjs +5 -2
  97. package/src/credentials.mjs +46 -8
  98. package/src/dataset.mjs +18 -7
  99. package/src/directives.mjs +1 -0
  100. package/src/event-store.mjs +25 -2
  101. package/src/extensions.mjs +5 -1
  102. package/src/ficha.mjs +158 -0
  103. package/src/files.mjs +36 -2
  104. package/src/image-studio.mjs +13 -3
  105. package/src/install-metrics.mjs +9 -3
  106. package/src/lease.mjs +6 -1
  107. package/src/looks.mjs +4 -1
  108. package/src/market-check.mjs +1 -1
  109. package/src/market-remote.mjs +135 -1
  110. package/src/mcp/image-server.mjs +59 -90
  111. package/src/mcp/memory-server.mjs +10 -0
  112. package/src/memory-tools.mjs +3 -0
  113. package/src/memory.mjs +29 -4
  114. package/src/models.mjs +21 -3
  115. package/src/modules/ahp.mjs +10 -4
  116. package/src/modules/bishop-exam.mjs +41 -12
  117. package/src/modules/bishop.mjs +2 -2
  118. package/src/modules/choices.mjs +12 -10
  119. package/src/modules/fetch-alone.mjs +7 -0
  120. package/src/modules/github.mjs +6 -2
  121. package/src/modules/helpers.mjs +23 -5
  122. package/src/modules/image-providers.mjs +281 -0
  123. package/src/modules/image-studio.mjs +106 -39
  124. package/src/modules/index.mjs +61 -12
  125. package/src/modules/intents-observe.mjs +3 -1
  126. package/src/modules/isolated.mjs +160 -0
  127. package/src/modules/ollama.mjs +35 -6
  128. package/src/modules/playwright.mjs +78 -20
  129. package/src/modules/reminders.mjs +42 -2
  130. package/src/modules/ripley.mjs +2 -1
  131. package/src/modules/run-alone.mjs +122 -0
  132. package/src/modules/runs.mjs +11 -8
  133. package/src/modules/sdk.mjs +10 -3
  134. package/src/notices-key.mjs +8 -0
  135. package/src/notices.mjs +185 -0
  136. package/src/ollama.mjs +57 -15
  137. package/src/opencode-health.mjs +1 -1
  138. package/src/outbound.mjs +124 -13
  139. package/src/quota-sources.mjs +148 -3
  140. package/src/review-ask.mjs +55 -31
  141. package/src/room/archivist.mjs +30 -5
  142. package/src/room/busy.mjs +16 -0
  143. package/src/room/changes.mjs +79 -0
  144. package/src/room/control.mjs +36 -6
  145. package/src/room/economy.mjs +1 -1
  146. package/src/room/guard.mjs +39 -2
  147. package/src/room/prompt.mjs +49 -6
  148. package/src/room/vectors.mjs +7 -1
  149. package/src/room.mjs +181 -49
  150. package/src/router.mjs +1 -1
  151. package/src/runs.mjs +39 -0
  152. package/src/runtime-detection.mjs +46 -6
  153. package/src/salas.mjs +181 -18
  154. package/src/server.mjs +1101 -118
  155. package/src/service.mjs +116 -0
  156. package/src/setup-trouble.mjs +20 -1
  157. package/src/setup.mjs +1 -1
  158. package/src/skill-check.mjs +269 -0
  159. package/src/skills-import.mjs +128 -0
  160. package/src/skills.mjs +502 -0
  161. package/src/terms.mjs +23 -5
  162. package/src/tour.mjs +31 -5
  163. package/src/updates.mjs +47 -4
  164. package/src/web-preview.mjs +181 -0
  165. package/src/whats-new.mjs +121 -1
  166. package/src/rumbo.mjs +0 -337
@@ -0,0 +1,303 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
+ // MADRE App's subscription, on the page (src/billing.mjs, docs/private/SUSCRIPCION.md). Nothing here
4
+ // draws unless the server says this copy runs inside the app with the author's switch on: MADRE from
5
+ // npm or from source never shows a price. Home and every project draw the same things from here:
6
+ // Settings › Subscription, the moments told once (the trial begins, two days left, the last day, the
7
+ // trial over, paid), and the card a limit shows instead of an error.
8
+
9
+ import { language, t } from './i18n.js';
10
+
11
+ const el = (tag, className = null, text = null) => {
12
+ const node = document.createElement(tag);
13
+ if (className) node.className = className;
14
+ if (text !== null && text !== undefined) node.textContent = text;
15
+ return node;
16
+ };
17
+ const button = (className, text, run) => {
18
+ const node = el('button', className, text);
19
+ node.type = 'button';
20
+ node.addEventListener('click', run);
21
+ return node;
22
+ };
23
+ const post = (path, payload = {}) => fetch(path, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(payload) })
24
+ .then(async (response) => ({ ok: response.ok, status: response.status, body: await response.json().catch(() => ({})) }))
25
+ .catch(() => ({ ok: false, status: 0, body: { error: t('Could not reach MADRE.') } }));
26
+ const locale = () => (language() === 'en' ? 'en-US' : 'es-MX');
27
+ export const money = (mxn) => new Intl.NumberFormat(locale(), { style: 'currency', currency: 'MXN', maximumFractionDigits: 0 }).format(mxn);
28
+ const dayWords = (iso) => new Date(iso).toLocaleDateString(locale(), { day: 'numeric', month: 'long' });
29
+ const perMonth = (info) => t('{price} a month', { price: money(info.price?.mxn ?? 109) });
30
+
31
+ // What the subscription gives, and what stays without it: the same lines everywhere.
32
+ const GIVES = () => [t('All your projects at once'), t('Plans among several AIs'), t('The Coordinator, across your projects'), t('Updates and fixes, always')];
33
+ const KEEPS = () => [t('One project takes messages; the others stay, to read'), t('Chat with all your AIs'), t('Updates and fixes, always')];
34
+
35
+ let info = { state: 'off' };
36
+ let openSettingsHere = () => {};
37
+ const listeners = new Set();
38
+ export const subscriptionInfo = () => info;
39
+ export const subscriptionShown = () => info.state && info.state !== 'off';
40
+ export function onSubscription(listener) { listeners.add(listener); return () => listeners.delete(listener); }
41
+ function took(next) {
42
+ if (!next || typeof next.state !== 'string') return info;
43
+ const changed = JSON.stringify(next) !== JSON.stringify(info);
44
+ info = next;
45
+ if (changed) for (const listener of listeners) { try { listener(info); } catch { /* one page part failing never stops the others */ } }
46
+ return info;
47
+ }
48
+ export async function readSubscription() {
49
+ const answer = await fetch('/api/subscription', { cache: 'no-store' }).then((response) => (response.ok ? response.json() : null)).catch(() => null);
50
+ return took(answer);
51
+ }
52
+
53
+ // Paying: madre.run's page opens in the browser, and this page asks every few seconds until the key
54
+ // is here (the server asks madre.run meanwhile). Nothing to copy or paste on this computer.
55
+ let waiting = null;
56
+ export async function subscribe() {
57
+ const answer = await post('/api/subscription/subscribe');
58
+ if (!answer.ok || !answer.body.url) return { error: answer.body.error ?? t('The payment page did not open. Try again in a moment.') };
59
+ window.open(answer.body.url, '_blank', 'noopener');
60
+ await readSubscription();
61
+ if (!waiting) {
62
+ const started = Date.now();
63
+ waiting = setInterval(async () => {
64
+ const now = await readSubscription();
65
+ if (now.state === 'active' || Date.now() - started > 30 * 60 * 1000) { clearInterval(waiting); waiting = null; }
66
+ }, 3000);
67
+ }
68
+ return { ok: true };
69
+ }
70
+ async function manage() {
71
+ const answer = await post('/api/subscription/manage');
72
+ if (answer.ok && answer.body.url) window.open(answer.body.url, '_blank', 'noopener');
73
+ return answer.ok ? { ok: true } : { error: answer.body.error };
74
+ }
75
+
76
+ // Turning it on with the email of the payment: the server asks madre.run every few seconds for half
77
+ // an hour, and this page reads it until the subscription is on here.
78
+ let recovering = null;
79
+ async function recover(email) {
80
+ const answer = await post('/api/subscription/recover', { email });
81
+ if (!answer.ok) return { error: answer.body.error ?? t('madre.run did not answer. Try again in a moment.') };
82
+ took(answer.body);
83
+ if (!recovering) {
84
+ const started = Date.now();
85
+ recovering = setInterval(async () => {
86
+ const now = await readSubscription();
87
+ if (now.state === 'active' || !now.recovering || Date.now() - started > 31 * 60 * 1000) { clearInterval(recovering); recovering = null; }
88
+ }, 3000);
89
+ }
90
+ return { ok: true };
91
+ }
92
+
93
+ function lists(host) {
94
+ const both = el('div', 'madre-sub-lists');
95
+ for (const [title, lines, kind] of [[t('With the subscription'), GIVES(), 'gives'], [t('In the limited mode'), KEEPS(), 'keeps']]) {
96
+ const column = el('div', `madre-sub-list is-${kind}`);
97
+ const list = el('ul');
98
+ for (const line of lines) list.append(el('li', null, line));
99
+ column.append(el('b', null, title), list);
100
+ both.append(column);
101
+ }
102
+ host.append(both);
103
+ return both;
104
+ }
105
+
106
+ // ---- Settings › Subscription ---------------------------------------------------------------------
107
+
108
+ // The line on its card and at the top of its page.
109
+ export function subscriptionLine(now = info) {
110
+ if (now.state === 'trial') return now.daysLeft === 1 ? t('Free trial · last day') : t('Free trial · {n} days left', { n: now.daysLeft });
111
+ if (now.state === 'active') return t('Active · renews on {day}', { day: dayWords(now.until) });
112
+ if (now.state === 'limited') return t('Limited mode');
113
+ return '';
114
+ }
115
+
116
+ export function drawSubscription(host, { projectPage = false } = {}) {
117
+ if (!host) return null;
118
+ const block = el('section', 'sx-block madre-sub-settings');
119
+ const draw = () => {
120
+ block.replaceChildren();
121
+ const head = el('header', 'sx-head');
122
+ const words = el('div', 'sx-words');
123
+ const lead = {
124
+ trial: t('Until {day} you have all of MADRE App. Then it is {price}, or you go on free in the limited mode. Nothing of yours is deleted.', { day: dayWords(info.trialEnds), price: perMonth(info) }),
125
+ active: t('Thank you. It renews each month on its own, and you can cancel whenever you want.'),
126
+ limited: t('Your projects, memories and files are all here. With the subscription, everything comes back.'),
127
+ }[info.state] ?? '';
128
+ words.append(el('h3', null, t('Subscription')), el('p', null, lead));
129
+ head.append(words);
130
+ const rows = el('div', 'sx-rows');
131
+ const said = el('p', 'sx-foot madre-sub-said');
132
+ const row = (title, hint, control) => {
133
+ const line = el('div', 'sx-row');
134
+ const text = el('div', 'sx-words');
135
+ text.append(el('b', null, title));
136
+ if (hint) text.append(el('span', 'sx-hint', hint));
137
+ const box = el('div', 'sx-control');
138
+ if (control) box.append(control);
139
+ line.append(text, box);
140
+ rows.append(line);
141
+ return line;
142
+ };
143
+ if (info.state === 'active') {
144
+ row(`MADRE App · ${perMonth(info)}`, t('Cancel, change your card or see your invoices.'), button('sx-btn', t('Manage'), async (event) => {
145
+ event.currentTarget.disabled = true;
146
+ const done = await manage();
147
+ event.currentTarget.disabled = false;
148
+ said.textContent = done.error ?? '';
149
+ }));
150
+ } else {
151
+ row(`MADRE App · ${perMonth(info)}`, t('VAT included. Cancel whenever you want.'), button('sx-btn primary', info.waiting ? t('Open the payment again') : t('Subscribe'), async (event) => {
152
+ event.currentTarget.disabled = true;
153
+ const done = await subscribe();
154
+ event.currentTarget.disabled = false;
155
+ said.textContent = done.error ?? t('The payment opened in your browser. When you finish, it turns on here by itself.');
156
+ }));
157
+ if (info.waiting) row(t('Waiting for your payment'), t('It turns on by itself as soon as you finish in the browser.'), el('span', 'madre-sub-spin'));
158
+ }
159
+ if (info.state === 'limited' && projectPage && info.project) {
160
+ const here = info.active?.room === info.project.room;
161
+ row(t('The project that takes messages'), info.active?.name ? (here ? t('This one: {name}', { name: info.active.name }) : info.active.name) : t('The first one you write in'), here ? null : button('sx-btn', t('Use this project'), async (event) => {
162
+ event.currentTarget.disabled = true;
163
+ const answer = await post('/api/subscription/project');
164
+ event.currentTarget.disabled = false;
165
+ if (answer.ok) took(answer.body); else said.textContent = answer.body.error ?? '';
166
+ }));
167
+ }
168
+ // Already subscribed (2026-11-18): the email of the payment gets a button, and this computer turns
169
+ // on by itself once it is pressed, wherever the email was opened. Nothing to copy or paste.
170
+ if (info.state !== 'active' && info.recovering) {
171
+ row(t('Check your email'), t('Open the email from MADRE and press its button: this computer turns on by itself. If it does not arrive in a few minutes, look in spam, or check it is the email you paid with.'), button('sx-btn', t('Cancel'), async (event) => {
172
+ event.currentTarget.disabled = true;
173
+ const answer = await post('/api/subscription/recover/stop');
174
+ if (answer.ok) took(answer.body);
175
+ }));
176
+ } else if (info.state !== 'active') {
177
+ const have = el('details', 'madre-sub-paste');
178
+ have.append(el('summary', null, t('I already have a subscription')));
179
+ const form = el('form', 'madre-sub-key');
180
+ const input = el('input');
181
+ input.type = 'email';
182
+ input.autocomplete = 'email';
183
+ input.required = true;
184
+ input.placeholder = t('The email you paid with');
185
+ input.setAttribute('aria-label', t('The email you paid with'));
186
+ form.append(el('p', 'sx-hint', t('We send a button to that email. Press it and this computer turns on by itself. A subscription works on up to two computers.')), input, el('button', 'sx-btn', t('Send me the email')));
187
+ form.addEventListener('submit', async (event) => {
188
+ event.preventDefault();
189
+ const sending = form.querySelector('button');
190
+ sending.disabled = true;
191
+ const done = await recover(input.value);
192
+ sending.disabled = false;
193
+ said.textContent = done.error ?? '';
194
+ });
195
+ have.append(form);
196
+ rows.append(have);
197
+ }
198
+ lists(rows);
199
+ rows.append(said);
200
+ block.append(head, rows);
201
+ };
202
+ draw();
203
+ const stop = onSubscription(() => { if (block.isConnected) draw(); else stop(); });
204
+ host.append(block);
205
+ return block;
206
+ }
207
+
208
+ // ---- The moments, told once ----------------------------------------------------------------------
209
+
210
+ function seen(moment) { void post('/api/subscription/seen', { moment }).then((answer) => { if (answer.ok) took(answer.body); }); }
211
+
212
+ // A sheet for the two that change what MADRE does (the trial begins, the trial is over); a short card
213
+ // in the corner for the rest. Calm: no countdown, no red, and closing it is always one press.
214
+ function sheet(moment) {
215
+ const dialog = el('dialog', 'madre-sub-sheet');
216
+ dialog.setAttribute('aria-labelledby', 'madre-sub-title');
217
+ const kicker = el('small', 'madre-sub-kicker', 'MADRE App');
218
+ const title = el('h2', null, moment === 'intro'
219
+ ? t('You have {n} days with all of MADRE App', { n: info.trialDays })
220
+ : t('Your free trial is over'));
221
+ title.id = 'madre-sub-title';
222
+ const body = el('p', 'madre-sub-body', moment === 'intro'
223
+ ? t('From now on, MADRE App is a subscription of {price}. These {n} days are free, with no card. When they end you choose: subscribe, or go on free in the limited mode. Nothing of yours is deleted.', { price: perMonth(info), n: info.trialDays })
224
+ : t('MADRE keeps working in the limited mode. Your projects, memories and files are all here.'));
225
+ dialog.append(kicker, title, body);
226
+ lists(dialog);
227
+ const said = el('p', 'madre-sub-said');
228
+ const actions = el('div', 'madre-sub-actions');
229
+ const close = () => { seen(moment); dialog.close(); dialog.remove(); };
230
+ if (moment === 'intro') {
231
+ actions.append(
232
+ button('madre-sub-btn primary', t('Start my {n} days', { n: info.trialDays }), close),
233
+ button('madre-sub-btn', t('Subscribe now'), async () => { const done = await subscribe(); if (done.error) said.textContent = done.error; else close(); }),
234
+ );
235
+ } else {
236
+ actions.append(
237
+ button('madre-sub-btn primary', t('Subscribe · {price}', { price: perMonth(info) }), async () => { const done = await subscribe(); if (done.error) said.textContent = done.error; else close(); }),
238
+ button('madre-sub-btn', t('Go on in the limited mode'), close),
239
+ );
240
+ }
241
+ dialog.append(actions, said);
242
+ dialog.addEventListener('cancel', (event) => { event.preventDefault(); close(); });
243
+ document.body.append(dialog);
244
+ dialog.showModal();
245
+ }
246
+ function corner(moment) {
247
+ const card = el('section', 'madre-sub-toast');
248
+ card.setAttribute('role', 'status');
249
+ const words = {
250
+ soon: t('Two days left of your MADRE App trial.'),
251
+ last: t('Today is the last day of your MADRE App trial.'),
252
+ paid: t('Done: your subscription is on. Thank you for keeping MADRE going.'),
253
+ moved: t('Your subscription was turned on in two other computers, so this one is back in the limited mode. To use it here again, turn it on from Settings › Subscription.'),
254
+ }[moment];
255
+ card.append(el('p', null, words));
256
+ const actions = el('div', 'madre-sub-actions');
257
+ const close = () => { seen(moment); card.remove(); };
258
+ if (moment !== 'paid') actions.append(button('madre-sub-btn primary', t('See the plan'), () => { close(); openSettingsHere(); }));
259
+ actions.append(button('madre-sub-btn', t('Got it'), close));
260
+ card.append(actions);
261
+ document.body.append(card);
262
+ }
263
+ let told = null;
264
+ function tell(now) {
265
+ if (!now.moment || told === now.moment || document.querySelector('.madre-sub-sheet[open], .madre-sub-toast')) return;
266
+ told = now.moment;
267
+ if (now.moment === 'intro' || now.moment === 'limited') sheet(now.moment); else corner(now.moment);
268
+ }
269
+
270
+ // ---- A limit, said where the message was refused -------------------------------------------------
271
+
272
+ // The server answered 402 with `subscription`: a card instead of a red line, with the way out.
273
+ export function showLimit(result) {
274
+ document.querySelector('.madre-sub-toast.is-limit')?.remove();
275
+ const card = el('section', 'madre-sub-toast is-limit');
276
+ card.setAttribute('role', 'alert');
277
+ card.append(el('small', 'madre-sub-kicker', t('Comes with the subscription')), el('p', null, result.error ?? ''));
278
+ const actions = el('div', 'madre-sub-actions');
279
+ const said = el('p', 'madre-sub-said');
280
+ actions.append(button('madre-sub-btn primary', t('Subscribe'), async () => { const done = await subscribe(); if (done.error) said.textContent = done.error; else card.remove(); }));
281
+ if (result.subscription?.limit === 'project') {
282
+ actions.append(button('madre-sub-btn', t('Use this project'), async () => {
283
+ const answer = await post('/api/subscription/project');
284
+ if (answer.ok) { took(answer.body); card.remove(); } else said.textContent = answer.body.error ?? '';
285
+ }));
286
+ }
287
+ actions.append(button('madre-sub-btn', t('Close'), () => card.remove()));
288
+ card.append(actions, said);
289
+ document.body.append(card);
290
+ return card;
291
+ }
292
+
293
+ // Read when the page opens, when it comes back to the front, and every ten minutes: the author's
294
+ // switch reaches a copy the next time the person opens it.
295
+ export function mountSubscription({ openSettings = () => {} } = {}) {
296
+ openSettingsHere = openSettings;
297
+ const ask = async () => { if (!document.hidden) tell(await readSubscription()); };
298
+ void ask();
299
+ setInterval(() => void ask(), 10 * 60 * 1000);
300
+ document.addEventListener('visibilitychange', () => { if (!document.hidden) void ask(); });
301
+ onSubscription((now) => tell(now));
302
+ return ask;
303
+ }
@@ -0,0 +1,170 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
+ // THE FIELD BEHIND «BEFORE YOU START» — THE ANTEROOM (2026-11-13, the author: «only the spheres of smoke
4
+ // in the colours, very subtle, floating over the whole screen, beautiful, never taking the person's
5
+ // attention; when they accept, the opening condenses them and begins»). The same six colours the opening
6
+ // blends (loader.js, playOpening), each a soft sphere drifting slowly across the whole window; nothing
7
+ // else. `smoke()` says where each one is at that moment, so the opening starts from exactly there. It
8
+ // follows the look on (light or dark), stops when the gate goes, and a person who asked for less motion
9
+ // gets one still frame.
10
+ //
11
+ // THE PRELUDE (2026-11-13, the author: «a micro animation before "Before you start" that begins to tell
12
+ // the story»): `start({ prelude: true })` lets the smoke be born. Six points of light, one per AI, each
13
+ // in its colour and each on its own, come one after another, beat once, and open into the spheres the
14
+ // anteroom keeps — the smoke is the AIs; the opening later condenses it into MADRE.
15
+
16
+ const clamp01 = (x) => Math.max(0, Math.min(1, x));
17
+ const hash = (n) => { const s = Math.sin(n * 127.1 + 311.7) * 43758.5453; return s - Math.floor(s); };
18
+ const rgba = (hex, a) => { const v = Number.parseInt(hex.slice(1), 16); return `rgba(${(v >> 16) & 255},${(v >> 8) & 255},${v & 255},${clamp01(a)})`; };
19
+ // The AIs' own colours, as brands.js has them (ChatGPT's Codex, Claude, Gemini, Grok, OpenCode, Cursor),
20
+ // the same the opening blends; the grey ones (Grok, Cursor) quieter, so the room stays colour and not grey.
21
+ const COLOURS = {
22
+ dark: ['#10A37F', '#D97757', '#8E75E8', '#E6E6E6', '#F2C94C', '#D9DEE5'],
23
+ light: ['#0B7A5F', '#B85C3C', '#5B45B8', '#262626', '#9A7A12', '#3A3F47'],
24
+ };
25
+ const GREY = [false, false, false, true, false, true];
26
+ // Faint: the card is what is read; the smoke is only there.
27
+ const LOOKS = {
28
+ dark: { alpha: 0.15, blend: 'screen' },
29
+ light: { alpha: 0.135, blend: 'source-over' },
30
+ };
31
+ // Where each sphere floats, as a share of the window: spread round the card, never all on one side.
32
+ const HOMES = [[0.16, 0.22], [0.84, 0.2], [0.1, 0.7], [0.9, 0.74], [0.52, 0.08], [0.5, 0.94]];
33
+ // The prelude, in seconds: when each point comes, when they open into smoke, and when it is over.
34
+ export const PRELUDE = { first: 0.25, step: 0.14, open: 1.35, done: 2.8 };
35
+ const easeOut = (x) => 1 - (1 - clamp01(x)) ** 3;
36
+ const easeInOut = (x) => { const v = clamp01(x); return v < 0.5 ? 4 * v * v * v : 1 - ((-2 * v + 2) ** 3) / 2; };
37
+
38
+ export function createTermsField({ still = globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false } = {}) {
39
+ const canvas = document.createElement('canvas');
40
+ canvas.className = 'terms-field';
41
+ canvas.setAttribute('aria-hidden', 'true');
42
+ const ctx = canvas.getContext?.('2d') ?? null;
43
+ let w = 0;
44
+ let h = 0;
45
+ let dpr = 1;
46
+ let frame = 0;
47
+ let last = 0;
48
+ let begun = 0;
49
+ let stopped = false;
50
+ let scheme = 'dark';
51
+ let prelude = false;
52
+ // Each colour on its own slow orbit round the dot, at its own distance, breathing at its own pace.
53
+ const fields = COLOURS.dark.map((_, i) => ({
54
+ home: HOMES[i],
55
+ drift: 0.05 + hash(i + 7) * 0.04,
56
+ speed: 0.05 + hash(i + 13) * 0.04,
57
+ phase: hash(i + 3) * 6.28,
58
+ breath: 6 + hash(i + 19) * 5,
59
+ size: 0.85 + hash(i + 29) * 0.35,
60
+ }));
61
+ let now = 8;
62
+
63
+ const readLook = () => { scheme = document.documentElement.dataset.scheme === 'light' ? 'light' : 'dark'; };
64
+ readLook();
65
+ const watcher = typeof MutationObserver === 'function' ? new MutationObserver(() => { readLook(); if (still) draw(8); }) : null;
66
+ watcher?.observe(document.documentElement, { attributes: true, attributeFilter: ['data-scheme'] });
67
+
68
+ function fit() {
69
+ const box = canvas.getBoundingClientRect();
70
+ if (!box.width || !ctx) return;
71
+ dpr = Math.min(2, globalThis.devicePixelRatio || 1);
72
+ w = box.width;
73
+ h = box.height;
74
+ canvas.width = Math.round(w * dpr);
75
+ canvas.height = Math.round(h * dpr);
76
+ ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
77
+ if (still) draw(8);
78
+ }
79
+ const resizer = typeof ResizeObserver === 'function' ? new ResizeObserver(fit) : null;
80
+ resizer?.observe(canvas);
81
+
82
+ const glow = (x, y, radius, hex, alpha) => {
83
+ if (alpha <= 0.002 || radius <= 0) return;
84
+ const fill = ctx.createRadialGradient(x, y, 0, x, y, radius);
85
+ fill.addColorStop(0, rgba(hex, alpha));
86
+ fill.addColorStop(0.55, rgba(hex, alpha * 0.45));
87
+ fill.addColorStop(1, rgba(hex, 0));
88
+ ctx.fillStyle = fill;
89
+ ctx.beginPath();
90
+ ctx.arc(x, y, radius, 0, Math.PI * 2);
91
+ ctx.fill();
92
+ };
93
+
94
+ // Each sphere at a moment: where it is, how large, its colour and how strong (window pixels).
95
+ const spheres = (t) => {
96
+ const look = LOOKS[scheme];
97
+ const colours = COLOURS[scheme];
98
+ const reach = Math.min(w, h);
99
+ return fields.map((one, i) => {
100
+ const x = (one.home[0] + Math.sin(t * one.speed + one.phase) * one.drift) * w;
101
+ const y = (one.home[1] + Math.cos(t * one.speed * 0.8 + one.phase) * one.drift) * h;
102
+ const breathe = 0.85 + 0.15 * Math.sin((t / one.breath) * Math.PI * 2);
103
+ return { x, y, r: reach * 0.42 * one.size, hex: colours[i], alpha: look.alpha * (GREY[i] ? 0.5 : 1) * breathe };
104
+ });
105
+ };
106
+
107
+ function draw(t) {
108
+ now = t;
109
+ if (!ctx || !w) return;
110
+ ctx.clearRect(0, 0, w, h);
111
+ ctx.globalCompositeOperation = LOOKS[scheme].blend;
112
+ const since = t - 8;
113
+ if (prelude && since < PRELUDE.done) drawBirth(since, spheres(t));
114
+ else for (const one of spheres(t)) glow(one.x, one.y, one.r, one.hex, one.alpha);
115
+ ctx.globalCompositeOperation = 'source-over';
116
+ }
117
+
118
+ // The smoke being born: each AI a point of its own round the middle, apart from the others, which
119
+ // beats once as it comes; then each opens into its sphere, travelling to where the sphere floats now.
120
+ function drawBirth(since, smoke) {
121
+ const reach = Math.min(w, h);
122
+ const open = easeInOut((since - PRELUDE.open) / (PRELUDE.done - PRELUDE.open));
123
+ smoke.forEach((one, i) => {
124
+ const at = PRELUDE.first + i * PRELUDE.step;
125
+ const come = easeOut((since - at) / 0.35);
126
+ if (come <= 0) return;
127
+ const angle = -Math.PI / 2 + (i * Math.PI * 2) / smoke.length;
128
+ const px = w / 2 + Math.cos(angle) * reach * 0.26;
129
+ const py = h / 2 + Math.sin(angle) * reach * 0.17;
130
+ const beat = 1 + 0.55 * Math.exp(-(((since - at - 0.2) / 0.11) ** 2));
131
+ const x = px + (one.x - px) * open;
132
+ const y = py + (one.y - py) * open;
133
+ // The halo grows into the sphere; the bright core goes as it opens.
134
+ glow(x, y, (22 * beat) + (one.r - 22 * beat) * open, one.hex, (0.38 + (one.alpha - 0.38) * open) * come);
135
+ glow(x, y, 5.5 * beat * (1 - open * 0.6), one.hex, 0.95 * come * (1 - open));
136
+ });
137
+ }
138
+
139
+ function loop(now) {
140
+ if (stopped) return;
141
+ frame = requestAnimationFrame(loop);
142
+ // About thirty frames a second: it moves slowly, and the card over it stays the busy part.
143
+ if (now - last < 32) return;
144
+ last = now;
145
+ if (!begun) begun = now;
146
+ draw((now - begun) / 1000 + 8);
147
+ }
148
+
149
+ return {
150
+ node: canvas,
151
+ // Where the smoke is right now, for the opening to begin from it.
152
+ smoke: () => (w ? spheres(now) : null),
153
+ start({ prelude: born = false } = {}) {
154
+ fit();
155
+ if (still || !ctx) { draw(8); canvas.classList.add('on'); return false; }
156
+ prelude = born;
157
+ if (prelude) canvas.classList.add('on', 'born');
158
+ frame = requestAnimationFrame(loop);
159
+ requestAnimationFrame(() => canvas.classList.add('on'));
160
+ // Whether the prelude plays (the gate waits for it before showing its card).
161
+ return prelude;
162
+ },
163
+ stop() {
164
+ stopped = true;
165
+ cancelAnimationFrame(frame);
166
+ resizer?.disconnect();
167
+ watcher?.disconnect();
168
+ },
169
+ };
170
+ }