@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,147 @@
1
+ // SPDX-License-Identifier: BUSL-1.1
2
+ // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
+ // CHOOSING ONE OF OPENCODE'S PROVIDERS (2026-11-10, asked by the author). OpenCode knows more than two
4
+ // hundred, and a plain list began at «302.AI». Now a key that shows the one chosen, with its mark, and
5
+ // opens a list with a search on top: the best known pinned first, then all of them by name. The arrows
6
+ // move, Enter chooses, Esc closes. Home's Settings and a project's both use it.
7
+ //
8
+ // `providers` as /api/agents/opencode/providers gives them ({ id, label }).
9
+
10
+ import { t } from './i18n.js';
11
+ import { trazo } from './icons.js';
12
+
13
+ // The best known, pinned above the rest in this order; any other the server marks as popular follows.
14
+ const PINNED = ['anthropic', 'openai', 'google', 'openrouter', 'xai', 'deepseek', 'mistral', 'groq'];
15
+
16
+ const el = (tag, className = null, text = null) => {
17
+ const node = document.createElement(tag);
18
+ if (className) node.className = className;
19
+ if (text !== null && text !== undefined) node.textContent = text;
20
+ return node;
21
+ };
22
+ const fold = (text) => String(text ?? '').normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
23
+
24
+ let marks = null;
25
+ const loadMarks = () => (marks ??= import('./provider-marks.js').then((module) => module.providerMark).catch(() => () => null));
26
+
27
+ // Its mark, or its initial on a soft square while the marks load or when it has none.
28
+ function markOf(provider, draw) {
29
+ const node = el('span', 'pp-mark');
30
+ node.setAttribute('aria-hidden', 'true');
31
+ const svg = draw?.(provider.id);
32
+ if (svg) node.innerHTML = svg; // trusted: our own SVG strings (provider-marks.js)
33
+ else { node.classList.add('initial'); node.textContent = String(provider.label ?? provider.id).replace(/^[^\p{L}\p{N}]+/u, '').charAt(0).toUpperCase(); }
34
+ return node;
35
+ }
36
+
37
+ export function providerPick({ providers = [], value = null, onChange = null, label = t('Provider') } = {}) {
38
+ const known = PINNED.map((id) => providers.find((one) => one.id === id)).filter(Boolean);
39
+ const rest = providers.filter((one) => !known.includes(one)).sort((a, b) => a.label.localeCompare(b.label));
40
+ let current = providers.find((one) => one.id === value) ?? known[0] ?? rest[0] ?? null;
41
+ let draw = null;
42
+ let open = false;
43
+ let at = 0; // the row the arrows are on
44
+ let rows = []; // what the list shows now, in order
45
+
46
+ const node = el('div', 'pp');
47
+ const key = el('button', 'pp-key');
48
+ key.type = 'button';
49
+ key.setAttribute('aria-haspopup', 'listbox');
50
+ key.setAttribute('aria-expanded', 'false');
51
+ key.setAttribute('aria-label', label);
52
+ const chevron = el('span', 'pp-chevron');
53
+ chevron.innerHTML = trazo('chevron'); // trusted: our own SVG string
54
+ const panel = el('div', 'pp-panel');
55
+ panel.hidden = true;
56
+ const search = el('input', 'pp-search');
57
+ search.type = 'search';
58
+ search.autocomplete = 'off';
59
+ search.spellcheck = false;
60
+ search.placeholder = t('Search a provider…');
61
+ search.setAttribute('aria-label', t('Search a provider…'));
62
+ const list = el('div', 'pp-list');
63
+ list.setAttribute('role', 'listbox');
64
+ list.setAttribute('aria-label', label);
65
+ panel.append(search, list);
66
+ node.append(key, panel);
67
+
68
+ const paintKey = () => {
69
+ key.replaceChildren();
70
+ if (!current) { key.append(el('span', 'pp-name', t('No provider')), chevron); return; }
71
+ key.append(markOf(current, draw), el('span', 'pp-name', current.label), chevron);
72
+ };
73
+ const choose = (provider) => {
74
+ current = provider;
75
+ paintKey();
76
+ close();
77
+ key.focus();
78
+ onChange?.(provider.id);
79
+ };
80
+ const mark = () => {
81
+ rows.forEach((row, index) => row.setAttribute('aria-selected', String(index === at)));
82
+ rows[at]?.scrollIntoView({ block: 'nearest' });
83
+ };
84
+ const paintList = () => {
85
+ const words = fold(search.value.trim());
86
+ const fits = (one) => !words || fold(one.label).includes(words) || fold(one.id).includes(words);
87
+ const groups = words ? [[null, [...known, ...rest].filter(fits)]] : [[t('Best known'), known], [t('All providers'), rest]];
88
+ list.replaceChildren();
89
+ rows = [];
90
+ for (const [title, members] of groups) {
91
+ if (!members.length) continue;
92
+ if (title) list.append(el('p', 'pp-group', title));
93
+ for (const provider of members) {
94
+ const row = el('button', 'pp-row');
95
+ row.type = 'button';
96
+ row.tabIndex = -1;
97
+ row.setAttribute('role', 'option');
98
+ if (provider.id === current?.id) row.classList.add('chosen');
99
+ row.append(markOf(provider, draw), el('span', 'pp-name', provider.label));
100
+ const index = rows.length;
101
+ row.addEventListener('pointermove', () => { if (at !== index) { at = index; mark(); } });
102
+ row.addEventListener('click', () => choose(provider));
103
+ rows.push(row);
104
+ list.append(row);
105
+ }
106
+ }
107
+ if (!rows.length) list.append(el('p', 'pp-none', t('No provider matches «{query}».', { query: search.value.trim() })));
108
+ at = Math.max(0, rows.findIndex((row) => row.classList.contains('chosen')));
109
+ if (words) at = 0;
110
+ mark();
111
+ };
112
+ const outside = (event) => { if (!node.contains(event.target)) close(); };
113
+ function close() {
114
+ if (!open) return;
115
+ open = false;
116
+ panel.hidden = true;
117
+ key.setAttribute('aria-expanded', 'false');
118
+ document.removeEventListener('pointerdown', outside, true);
119
+ }
120
+ const show = () => {
121
+ open = true;
122
+ search.value = '';
123
+ panel.hidden = false;
124
+ key.setAttribute('aria-expanded', 'true');
125
+ paintList();
126
+ search.focus();
127
+ document.addEventListener('pointerdown', outside, true);
128
+ };
129
+ key.addEventListener('click', () => (open ? close() : show()));
130
+ key.addEventListener('keydown', (event) => { if (event.key === 'ArrowDown' || event.key === 'ArrowUp') { event.preventDefault(); show(); } });
131
+ search.addEventListener('input', paintList);
132
+ panel.addEventListener('keydown', (event) => {
133
+ if (event.key === 'ArrowDown') { event.preventDefault(); at = Math.min(rows.length - 1, at + 1); mark(); }
134
+ else if (event.key === 'ArrowUp') { event.preventDefault(); at = Math.max(0, at - 1); mark(); }
135
+ else if (event.key === 'Enter') { event.preventDefault(); rows[at]?.click(); }
136
+ else if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); close(); key.focus(); }
137
+ else if (event.key === 'Tab') close();
138
+ });
139
+
140
+ paintKey();
141
+ void loadMarks().then((found) => { draw = found; paintKey(); if (open) paintList(); });
142
+ return {
143
+ node,
144
+ get value() { return current?.id ?? ''; },
145
+ focus: () => key.focus(),
146
+ };
147
+ }
package/public/resay.js CHANGED
@@ -32,8 +32,11 @@ const SAID = [
32
32
  '{label} was interrupted before it started: {why}.',
33
33
  '{label} was interrupted: {why}.',
34
34
  '{label} did not respond before the timeout ({seconds}s).',
35
+ 'This computer does not have git, which MADRE needs to take the restore point before @{agent} writes, so nothing was changed. Install git and send it again.',
36
+ '{label} closed the connection before answering ({code}). Check in Settings › Local AI that Ollama is still running.',
35
37
  '{label} exited with code {code}.',
36
38
  ' Last output: {output}',
39
+ ' (also tried {model})',
37
40
  'MADRE is shutting down',
38
41
  'STOPALL by the human',
39
42
  '{label} does not know the model `{model}`.',
@@ -57,6 +60,7 @@ const SAID = [
57
60
  '@{agent} is capped at #{n} {label}; raise its max mode to #{wanted} in Settings › Permissions to arm {mode}.',
58
61
  '@{agent} is capped at #{n} {label}; raise its MAX MODE to #{wanted} in CONNECTIONS to unlock {mode}.',
59
62
  '@{agent} is capped at #{n} {label}; raise its MAX MODE to #{wanted} in CONNECTIONS to arm {mode}.',
63
+ '@{agent} is already using #{n} {label} in this project, and only one AI can at a time. Wait for it to finish, or press Stop all to take it back.',
60
64
  '@{agent} already holds {mode} of this project; one holder at a time. STOPALL revokes it.',
61
65
  '@{agent} left the project: Ollama is not running. Start Ollama, or open Local AI in Modules.',
62
66
  '@{agent} left the project: Ollama is not running. Start Ollama, or set up Local AI in Settings.',
@@ -1,12 +1,13 @@
1
1
  // SPDX-License-Identifier: BUSL-1.1
2
2
  // MADRE · © 2026 Jossue Alcalá · Business Source License 1.1: LICENSE
3
3
  // Asking for a star or a review (2026-10-10), in the room and in Home: the server keeps when to
4
- // ask (src/review-ask.mjs); this page says once a minute that it is in view, and when a moment is
5
- // due it asks — only when nothing is going on: no turn running, nothing half written, no other
6
- // window open. Otherwise it waits for the next minute. The sheet is the room's question
7
- // (styles.css, dialog.room-ask): a star on GitHub, a review on madre.run, a donation on GitHub
8
- // Sponsors (2026-10-30), not now, or never again. The links open in the person's browser; MADRE
9
- // itself sends nothing.
4
+ // ask (src/review-ask.mjs); this page says once a minute that it is in view and whether an AI is at
5
+ // work in it (`using`), and when a moment is due it asks — only when nothing is going on: no turn
6
+ // running, nothing half written, no other window open. Otherwise it waits for the next minute. The
7
+ // sheet is the room's question (styles.css, dialog.room-ask). Where it sends depends on how MADRE
8
+ // came (2026-11-18): from the desktop app, a review on madre.run; from npm or the source, a star on
9
+ // GitHub, since npm keeps no reviews. Then a donation on GitHub Sponsors (2026-10-30), not now, or
10
+ // never again. The links open in the person's browser; MADRE itself sends nothing.
10
11
 
11
12
  import { language, t } from './i18n.js';
12
13
  import { trazo } from './icons.js';
@@ -21,16 +22,17 @@ const STAR = trazo('star');
21
22
  const post = (url, payload) => fetch(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(payload ?? {}) })
22
23
  .then((response) => (response.ok ? response.json() : null)).catch(() => null);
23
24
 
24
- export function startReviewAsk({ busy = () => false } = {}) {
25
+ export function startReviewAsk({ busy = () => false, using = () => false } = {}) {
25
26
  if (typeof document === 'undefined' || typeof setInterval !== 'function') return null;
26
27
  let dialog = null;
27
28
  async function tick() {
28
29
  if (document.hidden || dialog?.open) return;
29
- const answer = await post('/api/review-ask/tick');
30
+ const answer = await post('/api/review-ask/tick', { using: Boolean(using()) });
30
31
  if (!answer?.due || document.hidden || busy() || document.querySelector('dialog[open], .reload-curtain')) return;
31
- ask(answer.due);
32
+ ask(answer.due, answer.via);
32
33
  }
33
- function ask(moment) {
34
+ function ask(moment, via = 'npm') {
35
+ const app = via === 'app';
34
36
  dialog?.remove();
35
37
  dialog = document.createElement('dialog');
36
38
  dialog.className = 'room-ask review-ask';
@@ -47,7 +49,9 @@ export function startReviewAsk({ busy = () => false } = {}) {
47
49
  title.textContent = t('Are you enjoying MADRE?');
48
50
  const body = document.createElement('p');
49
51
  body.className = 'room-ask-body';
50
- body.textContent = t('If MADRE saves you work, a star on GitHub or a few words about it help more people find it. And if you can, a donation keeps it going: MADRE is made by one person.');
52
+ body.textContent = app
53
+ ? t('If MADRE saves you work, a few words about it help more people find it. And if you can, a donation keeps it going: MADRE is made by one person.')
54
+ : t('If MADRE saves you work, a star on GitHub helps more people find it. And if you can, a donation keeps it going: MADRE is made by one person.');
51
55
  const actions = document.createElement('div');
52
56
  actions.className = 'room-ask-actions review-ask-actions';
53
57
  const choice = (words, tone, answer, href = null) => {
@@ -62,8 +66,7 @@ export function startReviewAsk({ busy = () => false } = {}) {
62
66
  quiet.className = 'review-ask-quiet';
63
67
  quiet.append(choice(t('Not now'), 'quiet', 'later'), choice(t('Don\'t ask again'), 'quiet', 'never'));
64
68
  actions.append(
65
- choice(t('Write a review'), null, 'review', REVIEW_URLS[language()] ?? REVIEW_URLS.es),
66
- choice(t('Give it a star on GitHub'), 'primary', 'star', STAR_URL),
69
+ app ? choice(t('Write a review'), 'primary', 'review', REVIEW_URLS[language()] ?? REVIEW_URLS.es) : choice(t('Give it a star on GitHub'), 'primary', 'star', STAR_URL),
67
70
  choice(t('Donate on GitHub'), 'give', 'donate', SPONSORS_URL),
68
71
  );
69
72
  const note = document.createElement('p');
package/public/routing.js CHANGED
@@ -58,7 +58,31 @@ export function archiveQuestion(text = '') {
58
58
  //
59
59
  // It costs nothing in any prompt. And it never grants: #3 and #4 still open the ceremony where
60
60
  // the human types the project designation, exactly as if they had chosen it themselves.
61
- const NEEDS = /(necesit|requier|hace falta|no alcanza|insuficiente|permiso|conced|eleva|sub[ei]r|needs?|requires?|not enough|insufficient|permission|grant|raise|escalat)/i;
61
+ //
62
+ // Narrower since 2026-11-15 (the author's plan in contapp): asked what they can do, three AIs each
63
+ // described the ladder — «Con permiso #4 puedo correr comandos», «requiere permiso #2 o #3», «Con
64
+ // **#4** ejecuto tests» — and each answer grew a card «pide el permiso #4» nobody had asked for.
65
+ // Three things made a description read as a request: the word «permiso» alone counted as need, a
66
+ // rung named beside another («#2 o #3») counted as wanted, and a need word in the sentence before
67
+ // the number counted for it. Now the need is a verb of need or a plea to the person, in the same
68
+ // sentence as the number, the rung stands alone, and «que necesita #4» said of the work in general
69
+ // is not this turn asking.
70
+ const NEEDS = /(necesit|requier|hace falta|no alcanza|insuficiente|\bp[ií]do\b|solicito|conc[eé]deme|\bd[aá]me\b|s[uú]beme|el[eé]vame|\bneeds?\b|\brequires?\b|not enough|insufficient|\bgrant me\b|\bgive me\b|\bplease (?:grant|give|raise|allow)\b|escalat)/i;
71
+ // A rung beside another is the ladder being described: «#2 o #3», «#3/#4», «**#2** (crear) o **#3**».
72
+ const JOINED_BEFORE = /#[0-4]\**\s*(?:\([^)\n]{0,40}\))?\s*(?:o|u|y|e|or|and|a|to|,|\/|-|–)\s*\**$/i;
73
+ const JOINED_AFTER = /^#[0-4]\**\s*(?:\([^)\n]{0,40}\))?\s*(?:o|u|y|e|or|and|a|to|,|\/|-|–)\s*\**#[0-4]/i;
74
+ // Said of the work in general, not of this turn: «escribir código, que necesita #3».
75
+ const GENERAL = /\b(?:que|which|that)\s+(?:necesita|requiere|needs|requires)\b/gi;
76
+ // The sentence a rung stands in, at most 90 characters to each side: up to the last full stop, line
77
+ // break or list item before it, and to the first one after it.
78
+ function sentenceAround(reply, at) {
79
+ const left = reply.slice(Math.max(0, at - 90), at);
80
+ let start = left.lastIndexOf('\n') + 1;
81
+ for (const stop of left.matchAll(/[.!?](?=\s)/g)) start = Math.max(start, stop.index + 1);
82
+ const right = reply.slice(at, at + 90);
83
+ const end = right.slice(2).search(/\n|[.!?](?=\s|$)/);
84
+ return left.slice(start) + (end < 0 ? right : right.slice(0, end + 2));
85
+ }
62
86
 
63
87
  export function modeAsked(text = '', { ran = 1 } = {}) {
64
88
  return modeAskedWithTime(text, { ran })?.mode ?? null;
@@ -74,8 +98,10 @@ export function modeAskedWithTime(text = '', { ran = 1 } = {}) {
74
98
  for (const match of reply.matchAll(/#([2-4])\b/g)) {
75
99
  const mode = Number(match[1]);
76
100
  if (mode <= ran) continue;
77
- // The word of need has to sit beside the number, not anywhere in a long answer.
78
- const around = reply.slice(Math.max(0, match.index - 90), match.index + 90);
101
+ // A rung named beside another describes the ladder; it does not ask for a step of it.
102
+ if (JOINED_BEFORE.test(reply.slice(Math.max(0, match.index - 60), match.index)) || JOINED_AFTER.test(reply.slice(match.index, match.index + 60))) continue;
103
+ // The word of need has to sit beside the number, in its sentence, not anywhere in a long answer.
104
+ const around = sentenceAround(reply, match.index).replace(GENERAL, '');
79
105
  if (!NEEDS.test(around)) continue;
80
106
  if (wanted === null || mode > wanted.mode) {
81
107
  const after = reply.slice(match.index, match.index + 60).match(TIME);